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.

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