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.

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