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.

670 lines
22 KiB

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