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.

1143 lines
35 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 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
18 years ago
18 years ago
18 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
7 years ago
18 years ago
18 years ago
5 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 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
7 years ago
7 years ago
18 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
* 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
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <bitmaps.h>
  26. #include <confirm.h>
  27. #include <eda_dde.h>
  28. #include <fp_lib_table.h>
  29. #include <kiface_i.h>
  30. #include <kiplatform/app.h>
  31. #include <kiway_express.h>
  32. #include <macros.h>
  33. #include <netlist_reader/netlist_reader.h>
  34. #include <numeric>
  35. #include <tool/action_manager.h>
  36. #include <tool/action_toolbar.h>
  37. #include <tool/common_control.h>
  38. #include <tool/editor_conditions.h>
  39. #include <tool/tool_dispatcher.h>
  40. #include <tool/tool_manager.h>
  41. #include <widgets/progress_reporter.h>
  42. #include <wx/statline.h>
  43. #include <wx/stattext.h>
  44. #include <cvpcb_association.h>
  45. #include <cvpcb_id.h>
  46. #include <cvpcb_mainframe.h>
  47. #include <cvpcb_settings.h>
  48. #include <display_footprints_frame.h>
  49. #include <kiplatform/ui.h>
  50. #include <listboxes.h>
  51. #include <tools/cvpcb_actions.h>
  52. #include <tools/cvpcb_association_tool.h>
  53. #include <tools/cvpcb_control.h>
  54. #include <wx/button.h>
  55. #include <wx/settings.h>
  56. #define CVPCB_MAINFRAME_NAME wxT( "CvpcbFrame" )
  57. CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) :
  58. KIWAY_PLAYER( aKiway, aParent, FRAME_CVPCB, _( "Assign Footprints" ), wxDefaultPosition,
  59. wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, CVPCB_MAINFRAME_NAME )
  60. {
  61. m_symbolsListBox = NULL;
  62. m_footprintListBox = NULL;
  63. m_librariesListBox = NULL;
  64. m_mainToolBar = NULL;
  65. m_modified = false;
  66. m_skipComponentSelect = false;
  67. m_filteringOptions = FOOTPRINTS_LISTBOX::UNFILTERED_FP_LIST;
  68. m_tcFilterString = NULL;
  69. m_FootprintsList = FOOTPRINT_LIST::GetInstance( Kiway() );
  70. m_initialized = false;
  71. m_aboutTitle = "CvPcb";
  72. // Give an icon
  73. wxIcon icon;
  74. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_cvpcb ) );
  75. SetIcon( icon );
  76. SetAutoLayout( true );
  77. LoadSettings( config() );
  78. setupTools();
  79. setupUIConditions();
  80. ReCreateMenuBar();
  81. ReCreateHToolbar();
  82. // Create list of available footprints and symbols of the schematic
  83. BuildSymbolsListBox();
  84. BuildFootprintsListBox();
  85. BuildLibrariesListBox();
  86. m_auimgr.SetManagedWindow( this );
  87. m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
  88. m_auimgr.AddPane( m_librariesListBox, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(1)
  89. .Caption( _( "Footprint Libraries" ) )
  90. .BestSize((int) ( m_frameSize.x * 0.20 ), m_frameSize.y ) );
  91. m_auimgr.AddPane( m_symbolsListBox, EDA_PANE().Palette().Name( "Symbols" ).Center().Layer(0)
  92. .Caption( _( "Symbol : Footprint Assignments" ) ) );
  93. m_auimgr.AddPane( m_footprintListBox, EDA_PANE().Palette().Name( "Footprints" ).Right().Layer(1)
  94. .Caption( _( "Filtered Footprints" ) )
  95. .BestSize((int) ( m_frameSize.x * 0.30 ), m_frameSize.y ) );
  96. // Build the bottom panel, to display 2 status texts and the buttons:
  97. auto bottomPanel = new wxPanel( this );
  98. auto panelSizer = new wxBoxSizer( wxVERTICAL );
  99. wxFlexGridSizer* fgSizerStatus = new wxFlexGridSizer( 3, 1, 0, 0 );
  100. fgSizerStatus->SetFlexibleDirection( wxBOTH );
  101. fgSizerStatus->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
  102. m_statusLine1 = new wxStaticText( bottomPanel, wxID_ANY, wxEmptyString );
  103. fgSizerStatus->Add( m_statusLine1, 0, 0, 5 );
  104. m_statusLine2 = new wxStaticText( bottomPanel, wxID_ANY, wxEmptyString );
  105. fgSizerStatus->Add( m_statusLine2, 0, 0, 5 );
  106. m_statusLine3 = new wxStaticText( bottomPanel, wxID_ANY, wxEmptyString );
  107. fgSizerStatus->Add( m_statusLine3, 0, wxBOTTOM, 3 );
  108. panelSizer->Add( fgSizerStatus, 1, wxEXPAND|wxLEFT, 2 );
  109. wxStaticLine* staticline1 = new wxStaticLine( bottomPanel );
  110. panelSizer->Add( staticline1, 0, wxEXPAND, 5 );
  111. wxFont statusFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
  112. statusFont.SetSymbolicSize( wxFONTSIZE_SMALL );
  113. m_statusLine1->SetFont( statusFont );
  114. m_statusLine2->SetFont( statusFont );
  115. m_statusLine3->SetFont( statusFont );
  116. // Add buttons:
  117. auto buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
  118. auto sdbSizer = new wxStdDialogButtonSizer();
  119. m_saveAndContinue = new wxButton( bottomPanel, wxID_ANY,
  120. _( "Apply, Save Schematic && Continue" ) );
  121. buttonsSizer->Add( m_saveAndContinue, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 20 );
  122. auto sdbSizerOK = new wxButton( bottomPanel, wxID_OK );
  123. sdbSizer->AddButton( sdbSizerOK );
  124. auto sdbSizerCancel = new wxButton( bottomPanel, wxID_CANCEL );
  125. sdbSizer->AddButton( sdbSizerCancel );
  126. sdbSizer->Realize();
  127. buttonsSizer->Add( sdbSizer, 0, 0, 5 );
  128. panelSizer->Add( buttonsSizer, 0, wxALIGN_RIGHT|wxALL, 5 );
  129. bottomPanel->SetSizer( panelSizer );
  130. bottomPanel->Fit();
  131. sdbSizerOK->SetDefault();
  132. KIPLATFORM::UI::FixupCancelButtonCmdKeyCollision( this );
  133. m_auimgr.AddPane( bottomPanel, EDA_PANE().HToolbar().Name( "Buttons" ).Bottom().Layer(6) );
  134. m_auimgr.Update();
  135. m_initialized = true;
  136. if( CVPCB_SETTINGS* cfg = dynamic_cast<CVPCB_SETTINGS*>( config() ) )
  137. {
  138. if( cfg->m_LibrariesWidth > 0 )
  139. {
  140. wxAuiPaneInfo& librariesPane = m_auimgr.GetPane( "Libraries" );
  141. // wxAUI hack: force width by setting MinSize() and then Fixed()
  142. // thanks to ZenJu http://trac.wxwidgets.org/ticket/13180
  143. librariesPane.MinSize( cfg->m_LibrariesWidth, -1 );
  144. librariesPane.BestSize( cfg->m_LibrariesWidth, -1 );
  145. librariesPane.MaxSize( cfg->m_LibrariesWidth, -1 );
  146. librariesPane.Fixed();
  147. m_auimgr.Update();
  148. // now make it resizable again
  149. librariesPane.MinSize( 20, -1 );
  150. librariesPane.Resizable();
  151. m_auimgr.Update();
  152. }
  153. if( cfg->m_FootprintsWidth > 0 )
  154. {
  155. wxAuiPaneInfo& footprintsPane = m_auimgr.GetPane( "Footprints" );
  156. // wxAUI hack: force width by setting MinSize() and then Fixed()
  157. // thanks to ZenJu http://trac.wxwidgets.org/ticket/13180
  158. footprintsPane.MinSize( cfg->m_FootprintsWidth, -1 );
  159. footprintsPane.BestSize( cfg->m_FootprintsWidth, -1 );
  160. footprintsPane.MaxSize( cfg->m_FootprintsWidth, -1 );
  161. footprintsPane.Fixed();
  162. m_auimgr.Update();
  163. // now make it resizable again
  164. footprintsPane.MinSize( 20, -1 );
  165. footprintsPane.Resizable();
  166. m_auimgr.Update();
  167. }
  168. }
  169. // Connect Events
  170. setupEventHandlers();
  171. // Start the main processing loop
  172. m_toolManager->InvokeTool( "cvpcb.Control" );
  173. KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Symbol to footprint changes are unsaved" ) );
  174. }
  175. CVPCB_MAINFRAME::~CVPCB_MAINFRAME()
  176. {
  177. // Shutdown all running tools
  178. if( m_toolManager )
  179. m_toolManager->ShutdownAllTools();
  180. // Clean up the tool infrastructure
  181. delete m_actions;
  182. delete m_toolManager;
  183. delete m_toolDispatcher;
  184. m_auimgr.UnInit();
  185. }
  186. void CVPCB_MAINFRAME::setupTools()
  187. {
  188. // Create the manager
  189. m_actions = new CVPCB_ACTIONS();
  190. m_toolManager = new TOOL_MANAGER;
  191. m_toolManager->SetEnvironment( nullptr, nullptr, nullptr, config(), this );
  192. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
  193. // Register tools
  194. m_toolManager->RegisterTool( new COMMON_CONTROL );
  195. m_toolManager->RegisterTool( new CVPCB_CONTROL );
  196. m_toolManager->RegisterTool( new CVPCB_ASSOCIATION_TOOL );
  197. m_toolManager->InitTools();
  198. CVPCB_CONTROL* tool = m_toolManager->GetTool<CVPCB_CONTROL>();
  199. // Even though these menus will open with the right-click, we treat them as a normal
  200. // menu instead of a context menu because we don't care about their position and want
  201. // to be able to tell the difference between a menu click and a hotkey activation.
  202. // Create the context menu for the symbols list box
  203. m_symbolsContextMenu = new ACTION_MENU( false, tool );
  204. m_symbolsContextMenu->Add( CVPCB_ACTIONS::showFootprintViewer );
  205. m_symbolsContextMenu->AppendSeparator();
  206. m_symbolsContextMenu->Add( ACTIONS::cut );
  207. m_symbolsContextMenu->Add( ACTIONS::copy );
  208. m_symbolsContextMenu->Add( ACTIONS::paste );
  209. m_symbolsContextMenu->AppendSeparator();
  210. m_symbolsContextMenu->Add( CVPCB_ACTIONS::deleteAssoc );
  211. // Create the context menu for the footprint list box
  212. m_footprintContextMenu = new ACTION_MENU( false, tool );
  213. m_footprintContextMenu->Add( CVPCB_ACTIONS::showFootprintViewer );
  214. }
  215. void CVPCB_MAINFRAME::setupUIConditions()
  216. {
  217. EDA_BASE_FRAME::setupUIConditions();
  218. ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
  219. EDITOR_CONDITIONS cond( this );
  220. wxASSERT( mgr );
  221. #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
  222. #define CHECK( x ) ACTION_CONDITIONS().Check( x )
  223. mgr->SetConditions( CVPCB_ACTIONS::saveAssociations, ENABLE( cond.ContentModified() ) );
  224. mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) );
  225. mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
  226. auto compFilter =
  227. [this] ( const SELECTION& )
  228. {
  229. return m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_COMPONENT_FP_FILTERS;
  230. };
  231. auto libFilter =
  232. [this] ( const SELECTION& )
  233. {
  234. return m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_LIBRARY;
  235. };
  236. auto pinFilter =
  237. [this] ( const SELECTION& )
  238. {
  239. return m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_PIN_COUNT;
  240. };
  241. mgr->SetConditions( CVPCB_ACTIONS::FilterFPbyFPFilters, CHECK( compFilter ) );
  242. mgr->SetConditions( CVPCB_ACTIONS::FilterFPbyLibrary, CHECK( libFilter ) );
  243. mgr->SetConditions( CVPCB_ACTIONS::filterFPbyPin, CHECK( pinFilter ) );
  244. #undef CHECK
  245. #undef ENABLE
  246. }
  247. void CVPCB_MAINFRAME::setupEventHandlers()
  248. {
  249. // Connect the handlers to launch the context menus in the listboxes
  250. m_footprintListBox->Bind( wxEVT_RIGHT_DOWN,
  251. [this]( wxMouseEvent& )
  252. {
  253. PopupMenu( m_footprintContextMenu );
  254. } );
  255. m_symbolsListBox->Bind( wxEVT_RIGHT_DOWN,
  256. [this]( wxMouseEvent& )
  257. {
  258. PopupMenu( m_symbolsContextMenu );
  259. } );
  260. // Connect the handler for the save button
  261. m_saveAndContinue->Bind( wxEVT_COMMAND_BUTTON_CLICKED,
  262. [this]( wxCommandEvent& )
  263. {
  264. // saveAssociations must be run immediately
  265. GetToolManager()->RunAction( CVPCB_ACTIONS::saveAssociations, true );
  266. } );
  267. // Connect the handlers for the ok/cancel buttons
  268. Bind( wxEVT_BUTTON,
  269. [this]( wxCommandEvent& )
  270. {
  271. // saveAssociations must be run immediately, before running Close( true )
  272. GetToolManager()->RunAction( CVPCB_ACTIONS::saveAssociations, true );
  273. Close( true );
  274. }, wxID_OK );
  275. Bind( wxEVT_BUTTON,
  276. [this]( wxCommandEvent& )
  277. {
  278. Close( false );
  279. }, wxID_CANCEL );
  280. // Connect the handlers for the close events
  281. Bind( wxEVT_MENU,
  282. [this]( wxCommandEvent& )
  283. {
  284. Close( false );
  285. }, wxID_CLOSE );
  286. Bind( wxEVT_MENU,
  287. [this]( wxCommandEvent& )
  288. {
  289. Close( false );
  290. }, wxID_EXIT );
  291. // Toolbar events
  292. Bind( wxEVT_TEXT, &CVPCB_MAINFRAME::OnEnterFilteringText, this, ID_CVPCB_FILTER_TEXT_EDIT );
  293. // Just skip the resize events
  294. Bind( wxEVT_SIZE,
  295. []( wxSizeEvent& aEvent )
  296. {
  297. aEvent.Skip();
  298. } );
  299. // Attach the events to the tool dispatcher
  300. Bind( wxEVT_CHAR, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher );
  301. Bind( wxEVT_CHAR_HOOK, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher );
  302. }
  303. bool CVPCB_MAINFRAME::canCloseWindow( wxCloseEvent& aEvent )
  304. {
  305. if( m_modified )
  306. {
  307. // Shutdown blocks must be determined and vetoed as early as possible
  308. if( KIPLATFORM::APP::SupportsShutdownBlockReason()
  309. && aEvent.GetId() == wxEVT_QUERY_END_SESSION )
  310. {
  311. return false;
  312. }
  313. if( !HandleUnsavedChanges( this, _( "Symbol to Footprint links have been modified. "
  314. "Save changes?" ),
  315. [&]() -> bool
  316. {
  317. return SaveFootprintAssociation( false );
  318. } ) )
  319. {
  320. return false;
  321. }
  322. }
  323. return true;
  324. }
  325. void CVPCB_MAINFRAME::doCloseWindow()
  326. {
  327. if( GetFootprintViewerFrame() )
  328. GetFootprintViewerFrame()->Close( true );
  329. m_modified = false;
  330. // clear highlight symbol in schematic:
  331. SendMessageToEESCHEMA( true );
  332. }
  333. void CVPCB_MAINFRAME::OnEnterFilteringText( wxCommandEvent& aEvent )
  334. {
  335. // Called when changing the filter string in main toolbar.
  336. // If the option FOOTPRINTS_LISTBOX::FILTERING_BY_TEXT_PATTERN is set, update the list
  337. // of available footprints which match the filter
  338. wxListEvent l_event;
  339. OnSelectComponent( l_event );
  340. }
  341. void CVPCB_MAINFRAME::OnSelectComponent( wxListEvent& event )
  342. {
  343. if( m_skipComponentSelect )
  344. return;
  345. wxString libraryName;
  346. COMPONENT* symbol = GetSelectedComponent();
  347. libraryName = m_librariesListBox->GetSelectedLibrary();
  348. m_footprintListBox->SetFootprints( *m_FootprintsList, libraryName, symbol,
  349. m_tcFilterString->GetValue(), m_filteringOptions );
  350. if( symbol && symbol->GetFPID().IsValid() )
  351. m_footprintListBox->SetSelectedFootprint( symbol->GetFPID() );
  352. else
  353. m_footprintListBox->SetSelection( m_footprintListBox->GetSelection(), false );
  354. refreshAfterSymbolSearch( symbol );
  355. }
  356. void CVPCB_MAINFRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  357. {
  358. EDA_BASE_FRAME::LoadSettings( aCfg );
  359. CVPCB_SETTINGS* cfg = static_cast<CVPCB_SETTINGS*>( aCfg );
  360. m_filteringOptions = cfg->m_FilterFootprint;
  361. }
  362. void CVPCB_MAINFRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  363. {
  364. EDA_BASE_FRAME::SaveSettings( aCfg );
  365. CVPCB_SETTINGS* cfg = static_cast<CVPCB_SETTINGS*>( aCfg );
  366. cfg->m_FilterFootprint = m_filteringOptions;
  367. cfg->m_LibrariesWidth = m_librariesListBox->GetSize().x;
  368. cfg->m_FootprintsWidth = m_footprintListBox->GetSize().x;
  369. }
  370. void CVPCB_MAINFRAME::UndoAssociation()
  371. {
  372. if( m_undoList.size() == 0 )
  373. return;
  374. CVPCB_UNDO_REDO_ENTRIES redoEntries;
  375. CVPCB_UNDO_REDO_ENTRIES curEntry = m_undoList.back();
  376. m_undoList.pop_back();
  377. // Iterate over the entries to undo
  378. for( const auto& assoc : curEntry )
  379. {
  380. AssociateFootprint( assoc, true, false );
  381. redoEntries.emplace_back( assoc.Reverse() );
  382. }
  383. // Add the redo entries to the redo stack
  384. m_redoList.emplace_back( redoEntries );
  385. }
  386. void CVPCB_MAINFRAME::RedoAssociation()
  387. {
  388. if( m_redoList.size() == 0 )
  389. return;
  390. CVPCB_UNDO_REDO_ENTRIES curEntry = m_redoList.back();
  391. m_redoList.pop_back();
  392. // Iterate over the entries to undo
  393. bool firstAssoc = true;
  394. for( const auto& assoc : curEntry )
  395. {
  396. AssociateFootprint( assoc, firstAssoc );
  397. firstAssoc = false;
  398. }
  399. }
  400. void CVPCB_MAINFRAME::AssociateFootprint( const CVPCB_ASSOCIATION& aAssociation,
  401. bool aNewEntry, bool aAddUndoItem )
  402. {
  403. if( m_netlist.IsEmpty() )
  404. return;
  405. COMPONENT* symbol = m_netlist.GetComponent( aAssociation.GetComponentIndex() );
  406. if( symbol == NULL )
  407. return;
  408. LIB_ID fpid = aAssociation.GetNewFootprint();
  409. LIB_ID oldFpid = symbol->GetFPID();
  410. // Test for validity of the requested footprint
  411. if( !fpid.empty() && !fpid.IsValid() )
  412. {
  413. wxString msg = wxString::Format( _( "\"%s\" is not a valid footprint." ),
  414. fpid.Format().wx_str() );
  415. DisplayErrorMessage( this, msg );
  416. return;
  417. }
  418. const KIID& id = symbol->GetKIIDs().front();
  419. // Set new footprint to all instances of the selected symbol
  420. for( unsigned int idx : GetComponentIndices() )
  421. {
  422. COMPONENT* candidate = m_netlist.GetComponent( idx );
  423. const std::vector<KIID>& kiids = candidate->GetKIIDs();
  424. if( std::find( kiids.begin(), kiids.end(), id ) != kiids.end() )
  425. {
  426. // Set the new footprint
  427. candidate->SetFPID( fpid );
  428. // create the new symbol description and set it
  429. wxString description = wxString::Format( CMP_FORMAT,
  430. idx + 1,
  431. candidate->GetReference(),
  432. candidate->GetValue(),
  433. candidate->GetFPID().Format().wx_str() );
  434. m_symbolsListBox->SetString( idx, description );
  435. }
  436. }
  437. // Mark the data as being modified
  438. m_modified = true;
  439. // Update the statusbar and refresh the list
  440. DisplayStatus();
  441. m_symbolsListBox->Refresh();
  442. if( !aAddUndoItem )
  443. return;
  444. // Update the undo list
  445. if ( aNewEntry )
  446. {
  447. // Create a new entry for this association
  448. CVPCB_UNDO_REDO_ENTRIES newEntry;
  449. newEntry.emplace_back( CVPCB_ASSOCIATION( aAssociation.GetComponentIndex(), oldFpid,
  450. aAssociation.GetNewFootprint() ) );
  451. m_undoList.emplace_back( newEntry );
  452. // Clear the redo list
  453. m_redoList.clear();
  454. }
  455. else
  456. {
  457. m_undoList.back().emplace_back( CVPCB_ASSOCIATION( aAssociation.GetComponentIndex(),
  458. oldFpid,
  459. aAssociation.GetNewFootprint() ) );
  460. }
  461. }
  462. bool CVPCB_MAINFRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
  463. {
  464. return true;
  465. }
  466. void CVPCB_MAINFRAME::refreshAfterSymbolSearch( COMPONENT* aSymbol )
  467. {
  468. // Tell AuiMgr that objects are changed !
  469. if( m_auimgr.GetManagedWindow() ) // Be sure Aui Manager is initialized
  470. m_auimgr.Update(); // (could be not the case when starting CvPcb)
  471. if( aSymbol == NULL )
  472. {
  473. DisplayStatus();
  474. return;
  475. }
  476. // Preview of the already assigned footprint.
  477. // Find the footprint that was already chosen for this aSymbol and select it,
  478. // but only if the selection is made from the aSymbol list or the library list.
  479. // If the selection is made from the footprint list, do not change the current
  480. // selected footprint.
  481. if( FindFocus() == m_symbolsListBox || FindFocus() == m_librariesListBox )
  482. {
  483. wxString footprintName = FROM_UTF8( aSymbol->GetFPID().Format().c_str() );
  484. m_footprintListBox->SetSelection( m_footprintListBox->GetSelection(), false );
  485. for( int ii = 0; ii < m_footprintListBox->GetCount(); ii++ )
  486. {
  487. wxString candidateName;
  488. wxString msg = m_footprintListBox->OnGetItemText( ii, 0 );
  489. msg.Trim( true );
  490. msg.Trim( false );
  491. candidateName = msg.AfterFirst( wxChar( ' ' ) );
  492. if( footprintName.Cmp( candidateName ) == 0 )
  493. {
  494. m_footprintListBox->SetSelection( ii, true );
  495. break;
  496. }
  497. }
  498. if( GetFootprintViewerFrame() )
  499. m_toolManager->RunAction( CVPCB_ACTIONS::showFootprintViewer, true );
  500. }
  501. SendMessageToEESCHEMA();
  502. DisplayStatus();
  503. }
  504. void CVPCB_MAINFRAME::SetFootprintFilter( FOOTPRINTS_LISTBOX::FP_FILTER_T aFilter,
  505. CVPCB_MAINFRAME::CVPCB_FILTER_ACTION aAction )
  506. {
  507. int option = aFilter;
  508. // Apply the filter accordingly
  509. switch( aAction )
  510. {
  511. case CVPCB_MAINFRAME::FILTER_DISABLE: m_filteringOptions &= ~option; break;
  512. case CVPCB_MAINFRAME::FILTER_ENABLE: m_filteringOptions |= option; break;
  513. case CVPCB_MAINFRAME::FILTER_TOGGLE: m_filteringOptions ^= option; break;
  514. }
  515. wxListEvent l_event;
  516. OnSelectComponent( l_event );
  517. }
  518. void CVPCB_MAINFRAME::DisplayStatus()
  519. {
  520. if( !m_initialized )
  521. return;
  522. wxString filters, msg;
  523. COMPONENT* symbol = GetSelectedComponent();
  524. if( ( m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_COMPONENT_FP_FILTERS ) )
  525. {
  526. msg.Empty();
  527. if( symbol )
  528. {
  529. for( unsigned ii = 0; ii < symbol->GetFootprintFilters().GetCount(); ii++ )
  530. {
  531. if( msg.IsEmpty() )
  532. msg += symbol->GetFootprintFilters()[ii];
  533. else
  534. msg += wxT( ", " ) + symbol->GetFootprintFilters()[ii];
  535. }
  536. }
  537. filters += _( "Keywords" );
  538. if( !msg.IsEmpty() )
  539. filters += wxString::Format( wxT( " (%s)" ), msg );
  540. }
  541. if( ( m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_PIN_COUNT ) )
  542. {
  543. msg.Empty();
  544. if( symbol )
  545. msg = wxString::Format( wxT( "%i" ), symbol->GetPinCount() );
  546. if( !filters.IsEmpty() )
  547. filters += wxT( ", " );
  548. filters += _( "Pin Count" );
  549. if( !msg.IsEmpty() )
  550. filters += wxString::Format( wxT( " (%s)" ), msg );
  551. }
  552. if( ( m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_LIBRARY ) )
  553. {
  554. msg = m_librariesListBox->GetSelectedLibrary();
  555. if( !filters.IsEmpty() )
  556. filters += wxT( ", " );
  557. filters += _( "Library" );
  558. if( !msg.IsEmpty() )
  559. filters += wxString::Format( wxT( " (%s)" ), msg );
  560. }
  561. wxString textFilter = m_tcFilterString->GetValue();
  562. if( !textFilter.IsEmpty() )
  563. {
  564. if( !filters.IsEmpty() )
  565. filters += wxT( ", " );
  566. filters += _( "Search Text" ) + wxString::Format( wxT( " (%s)" ), textFilter );
  567. }
  568. if( filters.IsEmpty() )
  569. msg = _( "No Filtering" );
  570. else
  571. msg.Printf( _( "Filtered by %s" ), filters );
  572. msg << wxT( ": " ) << m_footprintListBox->GetCount();
  573. SetStatusText( msg );
  574. msg.Empty();
  575. wxString footprintName = GetSelectedFootprint();
  576. FOOTPRINT_INFO* fp = m_FootprintsList->GetFootprintInfo( footprintName );
  577. if( fp ) // can be NULL if no netlist loaded
  578. {
  579. msg = wxString::Format( _( "Description: %s; Keywords: %s" ),
  580. fp->GetDescription(),
  581. fp->GetKeywords() );
  582. }
  583. SetStatusText( msg, 1 );
  584. msg.Empty();
  585. wxString lib;
  586. // Choose the footprint to get the information on
  587. if( fp )
  588. {
  589. // Use the footprint in the footprint viewer
  590. lib = fp->GetLibNickname();
  591. }
  592. else if( GetFocusedControl() == CVPCB_MAINFRAME::CONTROL_COMPONENT )
  593. {
  594. // Use the footprint of the selected symbol
  595. if( symbol )
  596. lib = symbol->GetFPID().GetLibNickname();
  597. }
  598. else if( GetFocusedControl() == CVPCB_MAINFRAME::CONTROL_LIBRARY )
  599. {
  600. // Use the library that is selected
  601. lib = m_librariesListBox->GetSelectedLibrary();
  602. }
  603. // Extract the library information
  604. FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs( Kiway() );
  605. if( fptbl->HasLibrary( lib ) )
  606. msg = wxString::Format( _( "Library location: %s" ), fptbl->GetFullURI( lib ) );
  607. else
  608. msg = wxString::Format( _( "Library location: unknown" ) );
  609. SetStatusText( msg, 2 );
  610. }
  611. bool CVPCB_MAINFRAME::LoadFootprintFiles()
  612. {
  613. FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs( Kiway() );
  614. // Check if there are footprint libraries in the footprint library table.
  615. if( !fptbl || !fptbl->GetLogicalLibs().size() )
  616. {
  617. wxMessageBox( _( "No PCB footprint libraries are listed in the current footprint "
  618. "library table." ), _( "Configuration Error" ), wxOK | wxICON_ERROR );
  619. return false;
  620. }
  621. WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 );
  622. m_FootprintsList->ReadFootprintFiles( fptbl, nullptr, &progressReporter );
  623. if( m_FootprintsList->GetErrorCount() )
  624. {
  625. m_FootprintsList->DisplayErrors( this );
  626. }
  627. return true;
  628. }
  629. void CVPCB_MAINFRAME::SendMessageToEESCHEMA( bool aClearHighligntOnly )
  630. {
  631. if( m_netlist.IsEmpty() )
  632. return;
  633. // clear highlight of previously selected symbols (if any):
  634. // Selecting a non existing symbol clears any previously highlighted symbols
  635. std::string packet = "$CLEAR: \"HIGHLIGHTED\"";
  636. if( Kiface().IsSingle() )
  637. SendCommand( MSG_TO_SCH, packet );
  638. else
  639. Kiway().ExpressMail( FRAME_SCH, MAIL_CROSS_PROBE, packet, this );
  640. if( aClearHighligntOnly )
  641. return;
  642. int selection = m_symbolsListBox->GetSelection();
  643. if ( selection < 0 ) // Nothing selected
  644. return;
  645. if( m_netlist.GetComponent( selection ) == NULL )
  646. return;
  647. // Now highlight the selected symbol:
  648. COMPONENT* symbol = m_netlist.GetComponent( selection );
  649. packet = StrPrintf( "$PART: \"%s\"", TO_UTF8( symbol->GetReference() ) );
  650. if( Kiface().IsSingle() )
  651. SendCommand( MSG_TO_SCH, packet );
  652. else
  653. Kiway().ExpressMail( FRAME_SCH, MAIL_CROSS_PROBE, packet, this );
  654. }
  655. int CVPCB_MAINFRAME::ReadSchematicNetlist( const std::string& aNetlist )
  656. {
  657. STRING_LINE_READER* strrdr = new STRING_LINE_READER( aNetlist, "Eeschema via Kiway" );
  658. KICAD_NETLIST_READER netrdr( strrdr, &m_netlist );
  659. m_netlist.Clear();
  660. try
  661. {
  662. netrdr.LoadNetlist();
  663. }
  664. catch( const IO_ERROR& ioe )
  665. {
  666. wxString msg = wxString::Format( _( "Error loading schematic.\n%s" ),
  667. ioe.What().GetData() );
  668. wxMessageBox( msg, _( "Load Error" ), wxOK | wxICON_ERROR );
  669. return 1;
  670. }
  671. // We also remove footprint name if it is "$noname" because this is a dummy name,
  672. // not the actual name of the footprint.
  673. for( unsigned ii = 0; ii < m_netlist.GetCount(); ii++ )
  674. {
  675. if( m_netlist.GetComponent( ii )->GetFPID().GetLibItemName() == std::string( "$noname" ) )
  676. m_netlist.GetComponent( ii )->SetFPID( LIB_ID() );
  677. }
  678. // Sort symbols by reference:
  679. m_netlist.SortByReference();
  680. return 0;
  681. }
  682. void CVPCB_MAINFRAME::BuildFootprintsListBox()
  683. {
  684. wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
  685. if( m_footprintListBox == NULL )
  686. {
  687. m_footprintListBox = new FOOTPRINTS_LISTBOX( this, ID_CVPCB_FOOTPRINT_LIST );
  688. m_footprintListBox->SetFont( wxFont( guiFont.GetPointSize(), wxFONTFAMILY_MODERN,
  689. wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) );
  690. }
  691. m_footprintListBox->SetFootprints( *m_FootprintsList, wxEmptyString, NULL, wxEmptyString,
  692. FOOTPRINTS_LISTBOX::UNFILTERED_FP_LIST );
  693. DisplayStatus();
  694. }
  695. void CVPCB_MAINFRAME::BuildSymbolsListBox()
  696. {
  697. wxString msg;
  698. COMPONENT* symbol;
  699. wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
  700. if( m_symbolsListBox == NULL )
  701. {
  702. m_symbolsListBox = new COMPONENTS_LISTBOX( this, ID_CVPCB_COMPONENT_LIST );
  703. m_symbolsListBox->SetFont( wxFont( guiFont.GetPointSize(), wxFONTFAMILY_MODERN,
  704. wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) );
  705. }
  706. m_symbolsListBox->m_ComponentList.Clear();
  707. for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
  708. {
  709. symbol = m_netlist.GetComponent( i );
  710. msg.Printf( CMP_FORMAT,
  711. m_symbolsListBox->GetCount() + 1,
  712. symbol->GetReference(),
  713. symbol->GetValue(),
  714. symbol->GetFPID().Format().wx_str() );
  715. m_symbolsListBox->m_ComponentList.Add( msg );
  716. }
  717. if( m_symbolsListBox->m_ComponentList.Count() )
  718. {
  719. m_symbolsListBox->SetItemCount( m_symbolsListBox->m_ComponentList.Count() );
  720. m_symbolsListBox->SetSelection( 0, true );
  721. m_symbolsListBox->RefreshItems( 0L, m_symbolsListBox->m_ComponentList.Count() - 1 );
  722. m_symbolsListBox->UpdateWidth();
  723. }
  724. }
  725. void CVPCB_MAINFRAME::BuildLibrariesListBox()
  726. {
  727. wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
  728. if( m_librariesListBox == NULL )
  729. {
  730. m_librariesListBox = new LIBRARY_LISTBOX( this, ID_CVPCB_LIBRARY_LIST );
  731. m_librariesListBox->SetFont( wxFont( guiFont.GetPointSize(), wxFONTFAMILY_MODERN,
  732. wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL ) );
  733. }
  734. FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs( Kiway() );
  735. if( tbl )
  736. {
  737. wxArrayString libNames;
  738. std::vector< wxString > libNickNames = tbl->GetLogicalLibs();
  739. for( const wxString& libNickName : libNickNames )
  740. libNames.Add( libNickName );
  741. m_librariesListBox->SetLibraryList( libNames );
  742. }
  743. }
  744. COMPONENT* CVPCB_MAINFRAME::GetSelectedComponent()
  745. {
  746. int selection = m_symbolsListBox->GetSelection();
  747. if( selection >= 0 && selection < (int) m_netlist.GetCount() )
  748. return m_netlist.GetComponent( selection );
  749. return NULL;
  750. }
  751. void CVPCB_MAINFRAME::SetSelectedComponent( int aIndex, bool aSkipUpdate )
  752. {
  753. m_skipComponentSelect = aSkipUpdate;
  754. if( aIndex < 0 )
  755. {
  756. m_symbolsListBox->DeselectAll();
  757. }
  758. else if( aIndex < m_symbolsListBox->GetCount() )
  759. {
  760. m_symbolsListBox->DeselectAll();
  761. m_symbolsListBox->SetSelection( aIndex );
  762. SendMessageToEESCHEMA();
  763. }
  764. m_skipComponentSelect = false;
  765. }
  766. std::vector<unsigned int> CVPCB_MAINFRAME::GetComponentIndices(
  767. CVPCB_MAINFRAME::CRITERIA aCriteria )
  768. {
  769. std::vector<unsigned int> idx;
  770. int lastIdx;
  771. // Make sure a netlist has been loaded and the box has contents
  772. if( m_netlist.IsEmpty() || m_symbolsListBox->GetCount() == 0 )
  773. return idx;
  774. switch( aCriteria )
  775. {
  776. case CVPCB_MAINFRAME::ALL_COMPONENTS:
  777. idx.resize( m_netlist.GetCount() );
  778. std::iota( idx.begin(), idx.end(), 0 );
  779. break;
  780. case CVPCB_MAINFRAME::SEL_COMPONENTS:
  781. // Check to see if anything is selected
  782. if( m_symbolsListBox->GetSelectedItemCount() < 1 )
  783. break;
  784. // Get the symbols
  785. lastIdx = m_symbolsListBox->GetFirstSelected();
  786. idx.emplace_back( lastIdx );
  787. lastIdx = m_symbolsListBox->GetNextSelected( lastIdx );
  788. while( lastIdx > 0 )
  789. {
  790. idx.emplace_back( lastIdx );
  791. lastIdx = m_symbolsListBox->GetNextSelected( lastIdx );
  792. }
  793. break;
  794. case CVPCB_MAINFRAME::NA_COMPONENTS:
  795. for( unsigned int i = 0; i < m_netlist.GetCount(); i++ )
  796. {
  797. if( m_netlist.GetComponent( i )->GetFPID().empty() )
  798. idx.emplace_back( i );
  799. }
  800. break;
  801. case CVPCB_MAINFRAME::ASSOC_COMPONENTS:
  802. for( unsigned int i = 0; i < m_netlist.GetCount(); i++ )
  803. {
  804. if( !m_netlist.GetComponent( i )->GetFPID().empty() )
  805. idx.emplace_back( i );
  806. }
  807. break;
  808. default:
  809. wxASSERT_MSG( false, "Invalid symbol selection criteria" );
  810. }
  811. return idx;
  812. }
  813. DISPLAY_FOOTPRINTS_FRAME* CVPCB_MAINFRAME::GetFootprintViewerFrame() const
  814. {
  815. // returns the Footprint Viewer frame, if exists, or NULL
  816. wxWindow* window = wxWindow::FindWindowByName( FOOTPRINTVIEWER_FRAME_NAME );
  817. return dynamic_cast<DISPLAY_FOOTPRINTS_FRAME*>( window );
  818. }
  819. wxWindow* CVPCB_MAINFRAME::GetToolCanvas() const
  820. {
  821. return GetFootprintViewerFrame();
  822. }
  823. CVPCB_MAINFRAME::CONTROL_TYPE CVPCB_MAINFRAME::GetFocusedControl() const
  824. {
  825. if( m_librariesListBox->HasFocus() )
  826. return CVPCB_MAINFRAME::CONTROL_LIBRARY;
  827. else if( m_symbolsListBox->HasFocus() )
  828. return CVPCB_MAINFRAME::CONTROL_COMPONENT;
  829. else if( m_footprintListBox->HasFocus() )
  830. return CVPCB_MAINFRAME::CONTROL_FOOTPRINT;
  831. return CVPCB_MAINFRAME::CONTROL_NONE;
  832. }
  833. wxControl* CVPCB_MAINFRAME::GetFocusedControlObject() const
  834. {
  835. if( m_librariesListBox->HasFocus() )
  836. return m_librariesListBox;
  837. else if( m_symbolsListBox->HasFocus() )
  838. return m_symbolsListBox;
  839. else if( m_footprintListBox->HasFocus() )
  840. return m_footprintListBox;
  841. return nullptr;
  842. }
  843. void CVPCB_MAINFRAME::SetFocusedControl( CVPCB_MAINFRAME::CONTROL_TYPE aLB )
  844. {
  845. switch( aLB )
  846. {
  847. case CVPCB_MAINFRAME::CONTROL_LIBRARY: m_librariesListBox->SetFocus(); break;
  848. case CVPCB_MAINFRAME::CONTROL_COMPONENT: m_symbolsListBox->SetFocus(); break;
  849. case CVPCB_MAINFRAME::CONTROL_FOOTPRINT: m_footprintListBox->SetFocus(); break;
  850. default: break;
  851. }
  852. }
  853. wxString CVPCB_MAINFRAME::GetSelectedFootprint()
  854. {
  855. // returns the LIB_ID of the selected footprint in footprint listview
  856. // or a empty string
  857. return m_footprintListBox->GetSelectedFootprint();
  858. }
  859. void CVPCB_MAINFRAME::SetStatusText( const wxString& aText, int aNumber )
  860. {
  861. switch( aNumber )
  862. {
  863. case 0: m_statusLine1->SetLabel( aText ); break;
  864. case 1: m_statusLine2->SetLabel( aText ); break;
  865. case 2: m_statusLine3->SetLabel( aText ); break;
  866. default: wxFAIL_MSG( "Invalid status row number" ); break;
  867. }
  868. }
  869. void CVPCB_MAINFRAME::ShowChangedLanguage()
  870. {
  871. EDA_BASE_FRAME::ShowChangedLanguage();
  872. ReCreateHToolbar();
  873. DisplayStatus();
  874. }
  875. void CVPCB_MAINFRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
  876. {
  877. const std::string& payload = mail.GetPayload();
  878. switch( mail.Command() )
  879. {
  880. case MAIL_EESCHEMA_NETLIST:
  881. ReadNetListAndFpFiles( payload );
  882. /* @todo
  883. Go into SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) and trim GNL_ALL down.
  884. */
  885. break;
  886. default:
  887. ; // ignore most
  888. }
  889. }