You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

592 lines
20 KiB

Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012-2015 Miguel Angel Ajo Pelayo <miguelangel@nbee.es>
  5. * Copyright (C) 2012-2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
  6. * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
  7. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #include <kiface_base.h>
  27. #include <pcb_draw_panel_gal.h>
  28. #include <pcb_edit_frame.h>
  29. #include <3d_viewer/eda_3d_viewer_frame.h>
  30. #include <widgets/msgpanel.h>
  31. #include <bitmaps.h>
  32. #include <grid_tricks.h>
  33. #include <board.h>
  34. #include <footprint_edit_frame.h>
  35. #include <footprint_editor_settings.h>
  36. #include <pcbnew_id.h>
  37. #include <pcbnew_settings.h>
  38. #include "footprint_wizard_frame.h"
  39. #include <wx/listbox.h>
  40. #include <wx/statline.h>
  41. #include <wx/tokenzr.h>
  42. #include <wx/numformatter.h>
  43. #include <wildcards_and_files_ext.h>
  44. #include <base_units.h>
  45. #include <pgm_base.h>
  46. #include <settings/color_settings.h>
  47. #include <settings/settings_manager.h>
  48. #include <tool/tool_manager.h>
  49. #include <tool/tool_dispatcher.h>
  50. #include <tool/action_toolbar.h>
  51. #include <tool/common_tools.h>
  52. #include "tools/pcb_selection_tool.h"
  53. #include "tools/pcb_control.h"
  54. #include "tools/pcb_actions.h"
  55. #include <toolbars_footprint_wizard.h>
  56. #include <python/scripting/pcb_scripting_tool.h>
  57. BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, PCB_BASE_EDIT_FRAME )
  58. // Window events
  59. EVT_SIZE( FOOTPRINT_WIZARD_FRAME::OnSize )
  60. EVT_ACTIVATE( FOOTPRINT_WIZARD_FRAME::OnActivate )
  61. // Toolbar events
  62. EVT_TOOL( ID_FOOTPRINT_WIZARD_SELECT_WIZARD, FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard )
  63. EVT_TOOL( ID_FOOTPRINT_WIZARD_RESET_TO_DEFAULT, FOOTPRINT_WIZARD_FRAME::DefaultParameters )
  64. EVT_TOOL( ID_FOOTPRINT_WIZARD_NEXT, FOOTPRINT_WIZARD_FRAME::Process_Special_Functions )
  65. EVT_TOOL( ID_FOOTPRINT_WIZARD_PREVIOUS, FOOTPRINT_WIZARD_FRAME::Process_Special_Functions )
  66. EVT_TOOL( ID_FOOTPRINT_WIZARD_DONE, FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint )
  67. // listbox events
  68. EVT_LISTBOX( ID_FOOTPRINT_WIZARD_PAGE_LIST, FOOTPRINT_WIZARD_FRAME::ClickOnPageList )
  69. EVT_GRID_CMD_CELL_CHANGED( ID_FOOTPRINT_WIZARD_PARAMETER_LIST,
  70. FOOTPRINT_WIZARD_FRAME::ParametersUpdated )
  71. END_EVENT_TABLE()
  72. // Note: our FOOTPRINT_WIZARD_FRAME is always modal.
  73. FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( KIWAY* aKiway, wxWindow* aParent,
  74. FRAME_T aFrameType ) :
  75. PCB_BASE_EDIT_FRAME( aKiway, aParent, aFrameType, _( "Footprint Wizard" ),
  76. wxDefaultPosition, wxDefaultSize,
  77. aParent ? KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT
  78. : KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP,
  79. FOOTPRINT_WIZARD_FRAME_NAME ),
  80. m_wizardListShown( false )
  81. {
  82. wxASSERT( aFrameType == FRAME_FOOTPRINT_WIZARD );
  83. // This frame is always show modal:
  84. SetModal( true );
  85. // Give an icon
  86. wxIcon icon;
  87. icon.CopyFromBitmap( KiBitmap( BITMAPS::module_wizard ) );
  88. SetIcon( icon );
  89. m_wizardName.Empty();
  90. // Create the GAL canvas.
  91. // Must be created before calling LoadSettings() that needs a valid GAL canvas
  92. PCB_DRAW_PANEL_GAL* gal_drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ),
  93. m_frameSize,
  94. GetGalDisplayOptions(),
  95. EDA_DRAW_PANEL_GAL::GAL_FALLBACK );
  96. SetCanvas( gal_drawPanel );
  97. SetBoard( new BOARD() );
  98. // Ensure all layers and items are visible:
  99. GetBoard()->SetVisibleAlls();
  100. SetScreen( new PCB_SCREEN( GetPageSizeIU() ) );
  101. GetScreen()->m_Center = true; // Center coordinate origins on screen.
  102. LoadSettings( config() );
  103. SetSize( m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
  104. // Set some display options here, because the FOOTPRINT_WIZARD_FRAME
  105. // does not have a config menu to do that:
  106. // the footprint wizard frame has no config menu. so use some settings
  107. // from the caller, or force some options:
  108. PCB_BASE_FRAME* caller = dynamic_cast<PCB_BASE_FRAME*>( aParent );
  109. if( caller )
  110. SetUserUnits( caller->GetUserUnits() );
  111. // In viewer, the default net clearance is not known (it depends on the actual board).
  112. // So we do not show the default clearance, by setting it to 0
  113. // The footprint or pad specific clearance will be shown
  114. GetBoard()->GetDesignSettings().m_NetSettings->GetDefaultNetclass()->SetClearance( 0 );
  115. // Create the manager and dispatcher & route draw panel events to the dispatcher
  116. m_toolManager = new TOOL_MANAGER;
  117. m_toolManager->SetEnvironment( GetBoard(), gal_drawPanel->GetView(),
  118. gal_drawPanel->GetViewControls(), config(), this );
  119. m_actions = new PCB_ACTIONS();
  120. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
  121. gal_drawPanel->SetEventDispatcher( m_toolDispatcher );
  122. m_toolManager->RegisterTool( new PCB_CONTROL );
  123. m_toolManager->RegisterTool( new PCB_SELECTION_TOOL ); // for std context menus (zoom & grid)
  124. m_toolManager->RegisterTool( new SCRIPTING_TOOL );
  125. m_toolManager->RegisterTool( new COMMON_TOOLS );
  126. m_toolManager->InitTools();
  127. // Run the control tool, it is supposed to be always active
  128. m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
  129. // Create the toolbars
  130. m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings<FOOTPRINT_WIZARD_TOOLBAR_SETTINGS>( "fpwizard-toolbars" );
  131. configureToolbars();
  132. RecreateToolbars();
  133. // Create the parameters panel
  134. m_parametersPanel = new wxPanel( this, wxID_ANY );
  135. m_pageList = new wxListBox( m_parametersPanel, ID_FOOTPRINT_WIZARD_PAGE_LIST,
  136. wxDefaultPosition, wxDefaultSize, 0, nullptr,
  137. wxLB_HSCROLL | wxNO_BORDER );
  138. auto divider = new wxStaticLine( m_parametersPanel, wxID_ANY,
  139. wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL );
  140. m_parameterGrid = new WX_GRID( m_parametersPanel, ID_FOOTPRINT_WIZARD_PARAMETER_LIST );
  141. initParameterGrid();
  142. m_parameterGrid->PushEventHandler( new GRID_TRICKS( m_parameterGrid ) );
  143. ReCreatePageList();
  144. wxBoxSizer* parametersSizer = new wxBoxSizer( wxHORIZONTAL );
  145. parametersSizer->Add( m_pageList, 0, wxEXPAND, 5 );
  146. parametersSizer->Add( divider, 0, wxEXPAND, 5 );
  147. parametersSizer->Add( m_parameterGrid, 1, wxEXPAND, 5 );
  148. m_parametersPanel->SetSizer( parametersSizer );
  149. m_parametersPanel->Layout();
  150. // Create the build message box
  151. m_buildMessageBox = new wxTextCtrl( this, wxID_ANY, wxEmptyString,
  152. wxDefaultPosition, wxDefaultSize,
  153. wxTE_MULTILINE | wxTE_READONLY | wxNO_BORDER );
  154. DisplayWizardInfos();
  155. m_auimgr.SetManagedWindow( this );
  156. m_auimgr.AddPane( m_tbTopMain, EDA_PANE().HToolbar().Name( "TopMainToolbar" ).Top().Layer(6) );
  157. m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6)
  158. .BestSize( -1, m_msgFrameHeight ) );
  159. m_auimgr.AddPane( m_parametersPanel, EDA_PANE().Palette().Name( "Params" ).Left().Position(0)
  160. .Caption( _( "Parameters" ) ).MinSize( 360, 180 ) );
  161. m_auimgr.AddPane( m_buildMessageBox, EDA_PANE().Palette().Name( "Output" ).Left().Position(1)
  162. .CaptionVisible( false ).MinSize( 360, -1 ) );
  163. m_auimgr.AddPane( GetCanvas(), wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() );
  164. auto& galOpts = GetGalDisplayOptions();
  165. galOpts.m_fullscreenCursor = true;
  166. galOpts.m_forceDisplayCursor = true;
  167. galOpts.m_axesEnabled = true;
  168. ActivateGalCanvas();
  169. updateView();
  170. SetActiveLayer( F_Cu );
  171. GetToolManager()->PostAction( ACTIONS::zoomFitScreen );
  172. // Do not Run a dialog here: on some Window Managers, it creates issues.
  173. // Reason: the FOOTPRINT_WIZARD_FRAME is run as modal;
  174. // It means the call to FOOTPRINT_WIZARD_FRAME::ShowModal will change the
  175. // Event Loop Manager, and stop the one created by the dialog.
  176. // It does not happen on all W.M., perhaps due to the way the order events are called
  177. // See the call in onActivate instead
  178. }
  179. FOOTPRINT_WIZARD_FRAME::~FOOTPRINT_WIZARD_FRAME()
  180. {
  181. // Delete the GRID_TRICKS.
  182. m_parameterGrid->PopEventHandler( true );
  183. GetCanvas()->StopDrawing();
  184. // Be sure any event cannot be fired after frame deletion:
  185. GetCanvas()->SetEvtHandlerEnabled( false );
  186. // Be sure a active tool (if exists) is deactivated:
  187. if( m_toolManager )
  188. m_toolManager->DeactivateTool();
  189. EDA_3D_VIEWER_FRAME* draw3DFrame = Get3DViewerFrame();
  190. if( draw3DFrame )
  191. draw3DFrame->Destroy();
  192. // Now this frame can be deleted
  193. }
  194. void FOOTPRINT_WIZARD_FRAME::doCloseWindow()
  195. {
  196. SaveSettings( config() );
  197. if( IsModal() )
  198. {
  199. // Only dismiss a modal frame once, so that the return values set by
  200. // the prior DismissModal() are not bashed for ShowModal().
  201. if( !IsDismissed() )
  202. DismissModal( false );
  203. }
  204. }
  205. void FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint( wxCommandEvent& aEvent )
  206. {
  207. DismissModal( true );
  208. Close();
  209. }
  210. void FOOTPRINT_WIZARD_FRAME::OnGridSize( wxSizeEvent& aSizeEvent )
  211. {
  212. // Resize the parameter columns
  213. ResizeParamColumns();
  214. aSizeEvent.Skip();
  215. }
  216. void FOOTPRINT_WIZARD_FRAME::OnSize( wxSizeEvent& SizeEv )
  217. {
  218. if( m_auimgr.GetManagedWindow() )
  219. m_auimgr.Update();
  220. SizeEv.Skip();
  221. }
  222. COLOR_SETTINGS* FOOTPRINT_WIZARD_FRAME::GetColorSettings( bool aForceRefresh ) const
  223. {
  224. wxString currentTheme = GetFootprintEditorSettings()->m_ColorTheme;
  225. return Pgm().GetSettingsManager().GetColorSettings( currentTheme );
  226. }
  227. void FOOTPRINT_WIZARD_FRAME::updateView()
  228. {
  229. GetCanvas()->UpdateColors();
  230. GetCanvas()->DisplayBoard( GetBoard() );
  231. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  232. m_toolManager->RunAction( ACTIONS::zoomFitScreen );
  233. UpdateMsgPanel();
  234. }
  235. void FOOTPRINT_WIZARD_FRAME::UpdateMsgPanel()
  236. {
  237. BOARD_ITEM* footprint = GetBoard()->GetFirstFootprint();
  238. if( footprint )
  239. {
  240. std::vector<MSG_PANEL_ITEM> items;
  241. footprint->GetMsgPanelInfo( this, items );
  242. SetMsgPanel( items );
  243. }
  244. else
  245. {
  246. ClearMsgPanel();
  247. }
  248. }
  249. void FOOTPRINT_WIZARD_FRAME::initParameterGrid()
  250. {
  251. m_parameterGridPage = -1;
  252. // Prepare the grid where parameters are displayed
  253. m_parameterGrid->CreateGrid( 0, 3 );
  254. m_parameterGrid->SetColLabelValue( WIZ_COL_NAME, _( "Parameter" ) );
  255. m_parameterGrid->SetColLabelValue( WIZ_COL_VALUE, _( "Value" ) );
  256. m_parameterGrid->SetColLabelValue( WIZ_COL_UNITS, _( "Units" ) );
  257. m_parameterGrid->SetColLabelSize( 22 );
  258. m_parameterGrid->SetColLabelAlignment( wxALIGN_LEFT, wxALIGN_CENTRE );
  259. m_parameterGrid->AutoSizeColumns();
  260. m_parameterGrid->AutoSizeRows();
  261. m_parameterGrid->SetRowLabelSize( 0 );
  262. m_parameterGrid->DisableDragGridSize();
  263. m_parameterGrid->DisableDragColSize();
  264. m_parameterGrid->Connect( wxEVT_SIZE,
  265. wxSizeEventHandler( FOOTPRINT_WIZARD_FRAME::OnGridSize ),
  266. nullptr, this );
  267. }
  268. void FOOTPRINT_WIZARD_FRAME::ReCreatePageList()
  269. {
  270. if( m_pageList == nullptr )
  271. return;
  272. FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
  273. if( !footprintWizard )
  274. return;
  275. m_pageList->Clear();
  276. int max_page = footprintWizard->GetNumParameterPages();
  277. for( int i = 0; i < max_page; i++ )
  278. {
  279. wxString name = footprintWizard->GetParameterPageName( i );
  280. m_pageList->Append( name );
  281. }
  282. m_pageList->SetSelection( 0, true );
  283. ReCreateParameterList();
  284. ReCreateHToolbar();
  285. DisplayWizardInfos();
  286. GetCanvas()->Refresh();
  287. }
  288. void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList()
  289. {
  290. if( m_parameterGrid == nullptr )
  291. return;
  292. FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
  293. if( footprintWizard == nullptr )
  294. return;
  295. m_parameterGrid->Freeze();
  296. m_parameterGrid->ClearGrid();
  297. m_parameterGridPage = m_pageList->GetSelection();
  298. if( m_parameterGridPage < 0 ) // Should not happen
  299. return;
  300. // Get the list of names, values, types, hints and designators
  301. wxArrayString designatorsList = footprintWizard->GetParameterDesignators( m_parameterGridPage );
  302. wxArrayString namesList = footprintWizard->GetParameterNames( m_parameterGridPage );
  303. wxArrayString valuesList = footprintWizard->GetParameterValues( m_parameterGridPage );
  304. wxArrayString typesList = footprintWizard->GetParameterTypes( m_parameterGridPage );
  305. wxArrayString hintsList = footprintWizard->GetParameterHints( m_parameterGridPage );
  306. // Dimension the wxGrid
  307. m_parameterGrid->ClearRows();
  308. m_parameterGrid->AppendRows( namesList.size() );
  309. wxString designator, name, value, units, hint;
  310. for( unsigned int i = 0; i < namesList.size(); i++ )
  311. {
  312. designator = designatorsList[i];
  313. name = namesList[i];
  314. value = valuesList[i];
  315. units = typesList[i];
  316. hint = hintsList[i];
  317. m_parameterGrid->SetRowLabelValue( i, designator );
  318. // Set the 'Name'
  319. m_parameterGrid->SetCellValue( i, WIZ_COL_NAME, name );
  320. m_parameterGrid->SetReadOnly( i, WIZ_COL_NAME );
  321. // Boolean parameters are displayed using a checkbox
  322. if( units == WIZARD_PARAM_UNITS_BOOL )
  323. {
  324. // Set to ReadOnly as we delegate interactivity to GRID_TRICKS
  325. m_parameterGrid->SetReadOnly( i, WIZ_COL_VALUE );
  326. m_parameterGrid->SetCellRenderer( i, WIZ_COL_VALUE, new wxGridCellBoolRenderer );
  327. }
  328. // Parameters that can be selected from a list of multiple options
  329. else if( units.Contains( wxT( "," ) ) ) // Indicates list of available options
  330. {
  331. wxStringTokenizer tokenizer( units, wxT( "," ) );
  332. wxArrayString options;
  333. while( tokenizer.HasMoreTokens() )
  334. {
  335. options.Add( tokenizer.GetNextToken() );
  336. }
  337. m_parameterGrid->SetCellEditor( i, WIZ_COL_VALUE,
  338. new wxGridCellChoiceEditor( options ) );
  339. units = wxT( "" );
  340. }
  341. else if( units == WIZARD_PARAM_UNITS_INTEGER ) // Integer parameters
  342. {
  343. m_parameterGrid->SetCellEditor( i, WIZ_COL_VALUE, new wxGridCellNumberEditor );
  344. }
  345. else if( ( units == WIZARD_PARAM_UNITS_MM ) ||
  346. ( units == WIZARD_PARAM_UNITS_MILS ) ||
  347. ( units == WIZARD_PARAM_UNITS_FLOAT ) ||
  348. ( units == WIZARD_PARAM_UNITS_RADIANS ) ||
  349. ( units == WIZARD_PARAM_UNITS_DEGREES ) ||
  350. ( units == WIZARD_PARAM_UNITS_PERCENT ) )
  351. {
  352. // Non-integer numerical parameters
  353. m_parameterGrid->SetCellEditor( i, WIZ_COL_VALUE, new wxGridCellFloatEditor );
  354. // Convert separators to the locale-specific character
  355. value.Replace( ",", wxNumberFormatter::GetDecimalSeparator() );
  356. value.Replace( ".", wxNumberFormatter::GetDecimalSeparator() );
  357. }
  358. // Set the 'Units'
  359. m_parameterGrid->SetCellValue( i, WIZ_COL_UNITS, units );
  360. m_parameterGrid->SetReadOnly( i, WIZ_COL_UNITS );
  361. // Set the 'Value'
  362. m_parameterGrid->SetCellValue( i, WIZ_COL_VALUE, value );
  363. }
  364. ResizeParamColumns();
  365. m_parameterGrid->Thaw();
  366. }
  367. void FOOTPRINT_WIZARD_FRAME::ResizeParamColumns()
  368. {
  369. // Parameter grid is not yet configured
  370. if( ( m_parameterGrid == nullptr ) || ( m_parameterGrid->GetNumberCols() == 0 ) )
  371. return;
  372. // first auto-size the columns to ensure enough space around text
  373. m_parameterGrid->AutoSizeColumns();
  374. // Auto-size the value column
  375. int width = m_parameterGrid->GetClientSize().GetWidth() -
  376. m_parameterGrid->GetRowLabelSize() -
  377. m_parameterGrid->GetColSize( WIZ_COL_NAME ) -
  378. m_parameterGrid->GetColSize( WIZ_COL_UNITS );
  379. if( width > m_parameterGrid->GetColMinimalAcceptableWidth() )
  380. {
  381. m_parameterGrid->SetColSize( WIZ_COL_VALUE, width );
  382. }
  383. }
  384. void FOOTPRINT_WIZARD_FRAME::ClickOnPageList( wxCommandEvent& event )
  385. {
  386. if( m_pageList->GetSelection() >= 0 )
  387. {
  388. ReCreateParameterList();
  389. GetCanvas()->Refresh();
  390. DisplayWizardInfos();
  391. }
  392. }
  393. void FOOTPRINT_WIZARD_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  394. {
  395. PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
  396. wxCHECK( cfg, /*void*/ );
  397. PCB_BASE_FRAME::LoadSettings( cfg );
  398. m_auiPerspective = cfg->m_FootprintViewer.perspective;
  399. }
  400. void FOOTPRINT_WIZARD_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  401. {
  402. PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
  403. wxCHECK( cfg, /*void*/ );
  404. PCB_BASE_FRAME::SaveSettings( cfg );
  405. cfg->m_FootprintViewer.perspective = m_auimgr.SavePerspective().ToStdString();
  406. }
  407. WINDOW_SETTINGS* FOOTPRINT_WIZARD_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg )
  408. {
  409. auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
  410. wxASSERT( cfg );
  411. return cfg ? &cfg->m_FootprintWizard : nullptr;
  412. }
  413. void FOOTPRINT_WIZARD_FRAME::OnActivate( wxActivateEvent& event )
  414. {
  415. // Ensure we do not have old selection:
  416. if( !event.GetActive() )
  417. return;
  418. if( !m_wizardListShown )
  419. {
  420. m_wizardListShown = true;
  421. wxPostEvent( this, wxCommandEvent( wxEVT_TOOL, ID_FOOTPRINT_WIZARD_SELECT_WIZARD ) );
  422. }
  423. #if 0
  424. // Currently, we do not have a way to see if a Python wizard has changed,
  425. // therefore the lists of parameters and option has to be rebuilt
  426. // This code could be enabled when this way exists
  427. bool footprintWizardsChanged = false;
  428. if( footprintWizardsChanged )
  429. {
  430. // If we are here, the library list has changed, rebuild it
  431. ReCreatePageList();
  432. DisplayWizardInfos();
  433. }
  434. #endif
  435. }
  436. void FOOTPRINT_WIZARD_FRAME::Update3DView( bool aMarkDirty, bool aRefresh, const wxString* aTitle )
  437. {
  438. wxString frm3Dtitle;
  439. frm3Dtitle.Printf( _( "ModView: 3D Viewer [%s]" ), m_wizardName );
  440. PCB_BASE_FRAME::Update3DView( aMarkDirty, aRefresh, &frm3Dtitle );
  441. }
  442. BOARD_ITEM_CONTAINER* FOOTPRINT_WIZARD_FRAME::GetModel() const
  443. {
  444. return GetBoard()->GetFirstFootprint();
  445. }
  446. void FOOTPRINT_WIZARD_FRAME::PythonPluginsReload()
  447. {
  448. // Reload the Python plugins
  449. // Because the board editor has also a plugin python menu,
  450. // call the PCB_EDIT_FRAME RunAction() if the board editor is running
  451. // Otherwise run the current RunAction().
  452. PCB_EDIT_FRAME* pcbframe = static_cast<PCB_EDIT_FRAME*>( Kiway().Player( FRAME_PCB_EDITOR, false ) );
  453. if( pcbframe )
  454. pcbframe->GetToolManager()->RunAction( ACTIONS::pluginsReload );
  455. else
  456. GetToolManager()->RunAction( ACTIONS::pluginsReload );
  457. }