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.

649 lines
22 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 (C) 2004-2023 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 <python/scripting/pcb_scripting_tool.h>
  56. BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, PCB_BASE_EDIT_FRAME )
  57. // Window events
  58. EVT_SIZE( FOOTPRINT_WIZARD_FRAME::OnSize )
  59. EVT_ACTIVATE( FOOTPRINT_WIZARD_FRAME::OnActivate )
  60. // Toolbar events
  61. EVT_TOOL( ID_FOOTPRINT_WIZARD_SELECT_WIZARD, FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard )
  62. EVT_TOOL( ID_FOOTPRINT_WIZARD_RESET_TO_DEFAULT, FOOTPRINT_WIZARD_FRAME::DefaultParameters )
  63. EVT_TOOL( ID_FOOTPRINT_WIZARD_NEXT, FOOTPRINT_WIZARD_FRAME::Process_Special_Functions )
  64. EVT_TOOL( ID_FOOTPRINT_WIZARD_PREVIOUS, FOOTPRINT_WIZARD_FRAME::Process_Special_Functions )
  65. EVT_TOOL( ID_FOOTPRINT_WIZARD_DONE, FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint )
  66. // listbox events
  67. EVT_LISTBOX( ID_FOOTPRINT_WIZARD_PAGE_LIST, FOOTPRINT_WIZARD_FRAME::ClickOnPageList )
  68. EVT_GRID_CMD_CELL_CHANGED( ID_FOOTPRINT_WIZARD_PARAMETER_LIST,
  69. FOOTPRINT_WIZARD_FRAME::ParametersUpdated )
  70. END_EVENT_TABLE()
  71. // Note: our FOOTPRINT_WIZARD_FRAME is always modal.
  72. FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( KIWAY* aKiway, wxWindow* aParent,
  73. FRAME_T aFrameType ) :
  74. PCB_BASE_EDIT_FRAME( aKiway, aParent, aFrameType, _( "Footprint Wizard" ),
  75. wxDefaultPosition, wxDefaultSize,
  76. aParent ? KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT
  77. : KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP,
  78. FOOTPRINT_WIZARD_FRAME_NAME ),
  79. m_wizardListShown( false )
  80. {
  81. wxASSERT( aFrameType == FRAME_FOOTPRINT_WIZARD );
  82. // This frame is always show modal:
  83. SetModal( true );
  84. // Give an icon
  85. wxIcon icon;
  86. icon.CopyFromBitmap( KiBitmap( BITMAPS::module_wizard ) );
  87. SetIcon( icon );
  88. m_wizardName.Empty();
  89. // Create the GAL canvas.
  90. // Must be created before calling LoadSettings() that needs a valid GAL canvas
  91. PCB_DRAW_PANEL_GAL* gal_drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ),
  92. m_frameSize,
  93. GetGalDisplayOptions(),
  94. EDA_DRAW_PANEL_GAL::GAL_FALLBACK );
  95. SetCanvas( gal_drawPanel );
  96. SetBoard( new BOARD() );
  97. // Ensure all layers and items are visible:
  98. GetBoard()->SetVisibleAlls();
  99. SetScreen( new PCB_SCREEN( GetPageSizeIU() ) );
  100. GetScreen()->m_Center = true; // Center coordinate origins on screen.
  101. LoadSettings( config() );
  102. SetSize( m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
  103. // Set some display options here, because the FOOTPRINT_WIZARD_FRAME
  104. // does not have a config menu to do that:
  105. // the footprint wizard frame has no config menu. so use some settings
  106. // from the caller, or force some options:
  107. PCB_BASE_FRAME* caller = dynamic_cast<PCB_BASE_FRAME*>( aParent );
  108. if( caller )
  109. SetUserUnits( caller->GetUserUnits() );
  110. // In viewer, the default net clearance is not known (it depends on the actual board).
  111. // So we do not show the default clearance, by setting it to 0
  112. // The footprint or pad specific clearance will be shown
  113. GetBoard()->GetDesignSettings().m_NetSettings->m_DefaultNetClass->SetClearance( 0 );
  114. // Create the manager and dispatcher & route draw panel events to the dispatcher
  115. m_toolManager = new TOOL_MANAGER;
  116. m_toolManager->SetEnvironment( GetBoard(), gal_drawPanel->GetView(),
  117. gal_drawPanel->GetViewControls(), config(), this );
  118. m_actions = new PCB_ACTIONS();
  119. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
  120. gal_drawPanel->SetEventDispatcher( m_toolDispatcher );
  121. m_toolManager->RegisterTool( new PCB_CONTROL );
  122. m_toolManager->RegisterTool( new PCB_SELECTION_TOOL ); // for std context menus (zoom & grid)
  123. m_toolManager->RegisterTool( new SCRIPTING_TOOL );
  124. m_toolManager->RegisterTool( new COMMON_TOOLS );
  125. m_toolManager->InitTools();
  126. // Run the control tool, it is supposed to be always active
  127. m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
  128. // Create the toolbars
  129. ReCreateHToolbar();
  130. ReCreateVToolbar();
  131. // Create the parameters panel
  132. m_parametersPanel = new wxPanel( this, wxID_ANY );
  133. m_pageList = new wxListBox( m_parametersPanel, ID_FOOTPRINT_WIZARD_PAGE_LIST,
  134. wxDefaultPosition, wxDefaultSize, 0, nullptr,
  135. wxLB_HSCROLL | wxNO_BORDER );
  136. auto divider = new wxStaticLine( m_parametersPanel, wxID_ANY,
  137. wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL );
  138. m_parameterGrid = new WX_GRID( m_parametersPanel, ID_FOOTPRINT_WIZARD_PARAMETER_LIST );
  139. initParameterGrid();
  140. m_parameterGrid->PushEventHandler( new GRID_TRICKS( m_parameterGrid ) );
  141. ReCreatePageList();
  142. wxBoxSizer* parametersSizer = new wxBoxSizer( wxHORIZONTAL );
  143. parametersSizer->Add( m_pageList, 0, wxEXPAND, 5 );
  144. parametersSizer->Add( divider, 0, wxEXPAND, 5 );
  145. parametersSizer->Add( m_parameterGrid, 1, wxEXPAND, 5 );
  146. m_parametersPanel->SetSizer( parametersSizer );
  147. m_parametersPanel->Layout();
  148. // Create the build message box
  149. m_buildMessageBox = new wxTextCtrl( this, wxID_ANY, wxEmptyString,
  150. wxDefaultPosition, wxDefaultSize,
  151. wxTE_MULTILINE | wxTE_READONLY | wxNO_BORDER );
  152. DisplayWizardInfos();
  153. m_auimgr.SetManagedWindow( this );
  154. m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
  155. m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6)
  156. .BestSize( -1, m_msgFrameHeight ) );
  157. m_auimgr.AddPane( m_parametersPanel, EDA_PANE().Palette().Name( "Params" ).Left().Position(0)
  158. .Caption( _( "Parameters" ) ).MinSize( 360, 180 ) );
  159. m_auimgr.AddPane( m_buildMessageBox, EDA_PANE().Palette().Name( "Output" ).Left().Position(1)
  160. .CaptionVisible( false ).MinSize( 360, -1 ) );
  161. m_auimgr.AddPane( GetCanvas(), wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() );
  162. auto& galOpts = GetGalDisplayOptions();
  163. galOpts.m_fullscreenCursor = true;
  164. galOpts.m_forceDisplayCursor = true;
  165. galOpts.m_axesEnabled = true;
  166. ActivateGalCanvas();
  167. updateView();
  168. SetActiveLayer( F_Cu );
  169. GetToolManager()->RunAction( ACTIONS::zoomFitScreen, false );
  170. // Do not Run a dialog here: on some Window Managers, it creates issues.
  171. // Reason: the FOOTPRINT_WIZARD_FRAME is run as modal;
  172. // It means the call to FOOTPRINT_WIZARD_FRAME::ShowModal will change the
  173. // Event Loop Manager, and stop the one created by the dialog.
  174. // It does not happen on all W.M., perhaps due to the way the order events are called
  175. // See the call in onActivate instead
  176. }
  177. FOOTPRINT_WIZARD_FRAME::~FOOTPRINT_WIZARD_FRAME()
  178. {
  179. // Delete the GRID_TRICKS.
  180. m_parameterGrid->PopEventHandler( true );
  181. GetCanvas()->StopDrawing();
  182. // Be sure any event cannot be fired after frame deletion:
  183. GetCanvas()->SetEvtHandlerEnabled( false );
  184. // Be sure a active tool (if exists) is deactivated:
  185. if( m_toolManager )
  186. m_toolManager->DeactivateTool();
  187. EDA_3D_VIEWER_FRAME* draw3DFrame = Get3DViewerFrame();
  188. if( draw3DFrame )
  189. draw3DFrame->Destroy();
  190. // Now this frame can be deleted
  191. }
  192. void FOOTPRINT_WIZARD_FRAME::doCloseWindow()
  193. {
  194. SaveSettings( config() );
  195. if( IsModal() )
  196. {
  197. // Only dismiss a modal frame once, so that the return values set by
  198. // the prior DismissModal() are not bashed for ShowModal().
  199. if( !IsDismissed() )
  200. DismissModal( false );
  201. }
  202. }
  203. void FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint( wxCommandEvent& aEvent )
  204. {
  205. DismissModal( true );
  206. Close();
  207. }
  208. void FOOTPRINT_WIZARD_FRAME::OnGridSize( wxSizeEvent& aSizeEvent )
  209. {
  210. // Resize the parameter columns
  211. ResizeParamColumns();
  212. aSizeEvent.Skip();
  213. }
  214. void FOOTPRINT_WIZARD_FRAME::OnSize( wxSizeEvent& SizeEv )
  215. {
  216. if( m_auimgr.GetManagedWindow() )
  217. m_auimgr.Update();
  218. SizeEv.Skip();
  219. }
  220. COLOR_SETTINGS* FOOTPRINT_WIZARD_FRAME::GetColorSettings( bool aForceRefresh ) const
  221. {
  222. wxString currentTheme = GetFootprintEditorSettings()->m_ColorTheme;
  223. return Pgm().GetSettingsManager().GetColorSettings( currentTheme );
  224. }
  225. void FOOTPRINT_WIZARD_FRAME::updateView()
  226. {
  227. GetCanvas()->UpdateColors();
  228. GetCanvas()->DisplayBoard( GetBoard() );
  229. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  230. m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
  231. UpdateMsgPanel();
  232. }
  233. void FOOTPRINT_WIZARD_FRAME::UpdateMsgPanel()
  234. {
  235. BOARD_ITEM* footprint = GetBoard()->GetFirstFootprint();
  236. if( footprint )
  237. {
  238. std::vector<MSG_PANEL_ITEM> items;
  239. footprint->GetMsgPanelInfo( this, items );
  240. SetMsgPanel( items );
  241. }
  242. else
  243. {
  244. ClearMsgPanel();
  245. }
  246. }
  247. void FOOTPRINT_WIZARD_FRAME::initParameterGrid()
  248. {
  249. m_parameterGridPage = -1;
  250. // Prepare the grid where parameters are displayed
  251. m_parameterGrid->CreateGrid( 0, 3 );
  252. m_parameterGrid->SetColLabelValue( WIZ_COL_NAME, _( "Parameter" ) );
  253. m_parameterGrid->SetColLabelValue( WIZ_COL_VALUE, _( "Value" ) );
  254. m_parameterGrid->SetColLabelValue( WIZ_COL_UNITS, _( "Units" ) );
  255. m_parameterGrid->SetColLabelSize( 22 );
  256. m_parameterGrid->SetColLabelAlignment( wxALIGN_LEFT, wxALIGN_CENTRE );
  257. m_parameterGrid->AutoSizeColumns();
  258. m_parameterGrid->AutoSizeRows();
  259. m_parameterGrid->SetRowLabelSize( 0 );
  260. m_parameterGrid->DisableDragGridSize();
  261. m_parameterGrid->DisableDragColSize();
  262. m_parameterGrid->Connect( wxEVT_SIZE,
  263. wxSizeEventHandler( FOOTPRINT_WIZARD_FRAME::OnGridSize ),
  264. nullptr, this );
  265. }
  266. void FOOTPRINT_WIZARD_FRAME::ReCreatePageList()
  267. {
  268. if( m_pageList == nullptr )
  269. return;
  270. FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
  271. if( !footprintWizard )
  272. return;
  273. m_pageList->Clear();
  274. int max_page = footprintWizard->GetNumParameterPages();
  275. for( int i = 0; i < max_page; i++ )
  276. {
  277. wxString name = footprintWizard->GetParameterPageName( i );
  278. m_pageList->Append( name );
  279. }
  280. m_pageList->SetSelection( 0, true );
  281. ReCreateParameterList();
  282. ReCreateHToolbar();
  283. DisplayWizardInfos();
  284. GetCanvas()->Refresh();
  285. }
  286. void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList()
  287. {
  288. if( m_parameterGrid == nullptr )
  289. return;
  290. FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
  291. if( footprintWizard == nullptr )
  292. return;
  293. m_parameterGrid->Freeze();
  294. m_parameterGrid->ClearGrid();
  295. m_parameterGridPage = m_pageList->GetSelection();
  296. if( m_parameterGridPage < 0 ) // Should not happen
  297. return;
  298. // Get the list of names, values, types, hints and designators
  299. wxArrayString designatorsList = footprintWizard->GetParameterDesignators( m_parameterGridPage );
  300. wxArrayString namesList = footprintWizard->GetParameterNames( m_parameterGridPage );
  301. wxArrayString valuesList = footprintWizard->GetParameterValues( m_parameterGridPage );
  302. wxArrayString typesList = footprintWizard->GetParameterTypes( m_parameterGridPage );
  303. wxArrayString hintsList = footprintWizard->GetParameterHints( m_parameterGridPage );
  304. // Dimension the wxGrid
  305. m_parameterGrid->ClearRows();
  306. m_parameterGrid->AppendRows( namesList.size() );
  307. wxString designator, name, value, units, hint;
  308. for( unsigned int i = 0; i < namesList.size(); i++ )
  309. {
  310. designator = designatorsList[i];
  311. name = namesList[i];
  312. value = valuesList[i];
  313. units = typesList[i];
  314. hint = hintsList[i];
  315. m_parameterGrid->SetRowLabelValue( i, designator );
  316. // Set the 'Name'
  317. m_parameterGrid->SetCellValue( i, WIZ_COL_NAME, name );
  318. m_parameterGrid->SetReadOnly( i, WIZ_COL_NAME );
  319. // Boolean parameters are displayed using a checkbox
  320. if( units == WIZARD_PARAM_UNITS_BOOL )
  321. {
  322. // Set to ReadOnly as we delegate interactivity to GRID_TRICKS
  323. m_parameterGrid->SetReadOnly( i, WIZ_COL_VALUE );
  324. m_parameterGrid->SetCellRenderer( i, WIZ_COL_VALUE, new wxGridCellBoolRenderer );
  325. }
  326. // Parameters that can be selected from a list of multiple options
  327. else if( units.Contains( wxT( "," ) ) ) // Indicates list of available options
  328. {
  329. wxStringTokenizer tokenizer( units, wxT( "," ) );
  330. wxArrayString options;
  331. while( tokenizer.HasMoreTokens() )
  332. {
  333. options.Add( tokenizer.GetNextToken() );
  334. }
  335. m_parameterGrid->SetCellEditor( i, WIZ_COL_VALUE,
  336. new wxGridCellChoiceEditor( options ) );
  337. units = wxT( "" );
  338. }
  339. else if( units == WIZARD_PARAM_UNITS_INTEGER ) // Integer parameters
  340. {
  341. m_parameterGrid->SetCellEditor( i, WIZ_COL_VALUE, new wxGridCellNumberEditor );
  342. }
  343. else if( ( units == WIZARD_PARAM_UNITS_MM ) ||
  344. ( units == WIZARD_PARAM_UNITS_MILS ) ||
  345. ( units == WIZARD_PARAM_UNITS_FLOAT ) ||
  346. ( units == WIZARD_PARAM_UNITS_RADIANS ) ||
  347. ( units == WIZARD_PARAM_UNITS_DEGREES ) ||
  348. ( units == WIZARD_PARAM_UNITS_PERCENT ) )
  349. {
  350. // Non-integer numerical parameters
  351. m_parameterGrid->SetCellEditor( i, WIZ_COL_VALUE, new wxGridCellFloatEditor );
  352. // Convert separators to the locale-specific character
  353. value.Replace( ",", wxNumberFormatter::GetDecimalSeparator() );
  354. value.Replace( ".", wxNumberFormatter::GetDecimalSeparator() );
  355. }
  356. // Set the 'Units'
  357. m_parameterGrid->SetCellValue( i, WIZ_COL_UNITS, units );
  358. m_parameterGrid->SetReadOnly( i, WIZ_COL_UNITS );
  359. // Set the 'Value'
  360. m_parameterGrid->SetCellValue( i, WIZ_COL_VALUE, value );
  361. }
  362. ResizeParamColumns();
  363. m_parameterGrid->Thaw();
  364. }
  365. void FOOTPRINT_WIZARD_FRAME::ResizeParamColumns()
  366. {
  367. // Parameter grid is not yet configured
  368. if( ( m_parameterGrid == nullptr ) || ( m_parameterGrid->GetNumberCols() == 0 ) )
  369. return;
  370. // first auto-size the columns to ensure enough space around text
  371. m_parameterGrid->AutoSizeColumns();
  372. // Auto-size the value column
  373. int width = m_parameterGrid->GetClientSize().GetWidth() -
  374. m_parameterGrid->GetRowLabelSize() -
  375. m_parameterGrid->GetColSize( WIZ_COL_NAME ) -
  376. m_parameterGrid->GetColSize( WIZ_COL_UNITS );
  377. if( width > m_parameterGrid->GetColMinimalAcceptableWidth() )
  378. {
  379. m_parameterGrid->SetColSize( WIZ_COL_VALUE, width );
  380. }
  381. }
  382. void FOOTPRINT_WIZARD_FRAME::ClickOnPageList( wxCommandEvent& event )
  383. {
  384. if( m_pageList->GetSelection() >= 0 )
  385. {
  386. ReCreateParameterList();
  387. GetCanvas()->Refresh();
  388. DisplayWizardInfos();
  389. }
  390. }
  391. void FOOTPRINT_WIZARD_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  392. {
  393. PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
  394. wxCHECK( cfg, /*void*/ );
  395. PCB_BASE_FRAME::LoadSettings( cfg );
  396. m_auiPerspective = cfg->m_FootprintViewer.perspective;
  397. }
  398. void FOOTPRINT_WIZARD_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  399. {
  400. PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
  401. wxCHECK( cfg, /*void*/ );
  402. PCB_BASE_FRAME::SaveSettings( cfg );
  403. cfg->m_FootprintViewer.perspective = m_auimgr.SavePerspective().ToStdString();
  404. }
  405. WINDOW_SETTINGS* FOOTPRINT_WIZARD_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg )
  406. {
  407. auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
  408. wxASSERT( cfg );
  409. return cfg ? &cfg->m_FootprintWizard : nullptr;
  410. }
  411. void FOOTPRINT_WIZARD_FRAME::OnActivate( wxActivateEvent& event )
  412. {
  413. // Ensure we do not have old selection:
  414. if( !event.GetActive() )
  415. return;
  416. if( !m_wizardListShown )
  417. {
  418. m_wizardListShown = true;
  419. wxPostEvent( this, wxCommandEvent( wxEVT_TOOL, ID_FOOTPRINT_WIZARD_SELECT_WIZARD ) );
  420. }
  421. #if 0
  422. // Currently, we do not have a way to see if a Python wizard has changed,
  423. // therefore the lists of parameters and option has to be rebuilt
  424. // This code could be enabled when this way exists
  425. bool footprintWizardsChanged = false;
  426. if( footprintWizardsChanged )
  427. {
  428. // If we are here, the library list has changed, rebuild it
  429. ReCreatePageList();
  430. DisplayWizardInfos();
  431. }
  432. #endif
  433. }
  434. void FOOTPRINT_WIZARD_FRAME::Update3DView( bool aMarkDirty, bool aRefresh, const wxString* aTitle )
  435. {
  436. wxString frm3Dtitle;
  437. frm3Dtitle.Printf( _( "ModView: 3D Viewer [%s]" ), m_wizardName );
  438. PCB_BASE_FRAME::Update3DView( aMarkDirty, aRefresh, &frm3Dtitle );
  439. }
  440. void FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar()
  441. {
  442. if( m_mainToolBar )
  443. {
  444. m_mainToolBar->ClearToolbar();
  445. }
  446. else
  447. {
  448. m_mainToolBar = new ACTION_TOOLBAR( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
  449. KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
  450. m_mainToolBar->SetAuiManager( &m_auimgr );
  451. }
  452. // Set up toolbar
  453. m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_SELECT_WIZARD, wxEmptyString,
  454. KiBitmap( BITMAPS::module_wizard ),
  455. _( "Select wizard script to run" ) );
  456. m_mainToolBar->AddScaledSeparator( this );
  457. m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_RESET_TO_DEFAULT, wxEmptyString,
  458. KiBitmap( BITMAPS::reload ),
  459. _( "Reset wizard parameters to default") );
  460. m_mainToolBar->AddScaledSeparator( this );
  461. m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_PREVIOUS, wxEmptyString,
  462. KiBitmap( BITMAPS::lib_previous ),
  463. _( "Select previous parameters page" ) );
  464. m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_NEXT, wxEmptyString,
  465. KiBitmap( BITMAPS::lib_next ),
  466. _( "Select next parameters page" ) );
  467. #if 0 // Currently: the 3D viewer is not useful
  468. m_mainToolBar->AddScaledSeparator( this );
  469. m_mainToolBar->Add( ACTIONS::show3DViewer );
  470. #endif
  471. m_mainToolBar->AddScaledSeparator( this );
  472. m_mainToolBar->Add( ACTIONS::zoomRedraw );
  473. m_mainToolBar->Add( ACTIONS::zoomInCenter );
  474. m_mainToolBar->Add( ACTIONS::zoomOutCenter );
  475. m_mainToolBar->Add( ACTIONS::zoomFitScreen );
  476. // The footprint wizard always can export the current footprint
  477. m_mainToolBar->AddScaledSeparator( this );
  478. m_mainToolBar->AddTool( ID_FOOTPRINT_WIZARD_DONE,
  479. wxEmptyString, KiBitmap( BITMAPS::export_footprint_names ),
  480. _( "Export footprint to editor" ) );
  481. // after adding the buttons to the toolbar, must call Realize() to
  482. // reflect the changes
  483. m_mainToolBar->Realize();
  484. }
  485. BOARD_ITEM_CONTAINER* FOOTPRINT_WIZARD_FRAME::GetModel() const
  486. {
  487. return GetBoard()->GetFirstFootprint();
  488. }
  489. void FOOTPRINT_WIZARD_FRAME::ReCreateVToolbar()
  490. {
  491. // Currently, there is no vertical toolbar
  492. }
  493. void FOOTPRINT_WIZARD_FRAME::PythonPluginsReload()
  494. {
  495. // Reload the Python plugins
  496. // Because the board editor has also a plugin python menu,
  497. // call the PCB_EDIT_FRAME RunAction() if the board editor is running
  498. // Otherwise run the current RunAction().
  499. PCB_EDIT_FRAME* pcbframe = static_cast<PCB_EDIT_FRAME*>( Kiway().Player( FRAME_PCB_EDITOR, false ) );
  500. if( pcbframe )
  501. pcbframe->GetToolManager()->RunAction( PCB_ACTIONS::pluginsReload, true );
  502. else
  503. GetToolManager()->RunAction( PCB_ACTIONS::pluginsReload, true );
  504. }