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.

1090 lines
33 KiB

Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
2 years ago
2 years ago
5 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
4 months ago
2 years ago
2 years ago
2 years ago
7 months ago
2 years ago
2 years ago
4 months ago
5 years ago
5 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
5 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
5 years ago
5 years ago
5 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2008-2016 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 <3d_viewer/eda_3d_viewer_frame.h>
  26. #include <bitmaps.h>
  27. #include <board_commit.h>
  28. #include <board.h>
  29. #include <footprint.h>
  30. #include <confirm.h>
  31. #include <eda_pattern_match.h>
  32. #include <footprint_info.h>
  33. #include <footprint_viewer_frame.h>
  34. #include <fp_lib_table.h>
  35. #include <kiway.h>
  36. #include <kiway_express.h>
  37. #include <netlist_reader/pcb_netlist.h>
  38. #include <widgets/msgpanel.h>
  39. #include <widgets/wx_listbox.h>
  40. #include <widgets/wx_aui_utils.h>
  41. #include <gal/graphics_abstraction_layer.h>
  42. #include <pcb_draw_panel_gal.h>
  43. #include <pcb_painter.h>
  44. #include <pcbnew_id.h>
  45. #include <footprint_editor_settings.h>
  46. #include <pgm_base.h>
  47. #include <pcbnew_settings.h>
  48. #include <project_pcb.h>
  49. #include <project/project_file.h>
  50. #include <settings/settings_manager.h>
  51. #include <toolbars_footprint_viewer.h>
  52. #include <tool/action_toolbar.h>
  53. #include <tool/common_control.h>
  54. #include <tool/common_tools.h>
  55. #include <tool/selection.h>
  56. #include <tool/tool_dispatcher.h>
  57. #include <tool/tool_manager.h>
  58. #include <tool/zoom_tool.h>
  59. #include <tools/pcb_viewer_tools.h>
  60. #include <tools/pcb_actions.h>
  61. #include <tools/pcb_editor_conditions.h>
  62. #include <tools/pcb_control.h>
  63. #include <tools/pcb_picker_tool.h>
  64. #include <tools/pcb_selection_tool.h>
  65. #include <tools/board_editor_control.h>
  66. #include <wildcards_and_files_ext.h>
  67. #include <lib_tree_model_adapter.h>
  68. #include <wx/srchctrl.h>
  69. #include <wx/tokenzr.h>
  70. #include <wx/choice.h>
  71. #include <wx/hyperlink.h>
  72. #include "invoke_pcb_dialog.h"
  73. using namespace std::placeholders;
  74. BEGIN_EVENT_TABLE( FOOTPRINT_VIEWER_FRAME, PCB_BASE_FRAME )
  75. // Window events
  76. EVT_SIZE( FOOTPRINT_VIEWER_FRAME::OnSize )
  77. EVT_ACTIVATE( FOOTPRINT_VIEWER_FRAME::OnActivate )
  78. EVT_MENU( wxID_EXIT, FOOTPRINT_VIEWER_FRAME::OnExitKiCad )
  79. EVT_MENU( wxID_CLOSE, FOOTPRINT_VIEWER_FRAME::CloseFootprintViewer )
  80. // Toolbar events
  81. EVT_CHOICE( ID_ON_ZOOM_SELECT, FOOTPRINT_VIEWER_FRAME::OnSelectZoom )
  82. EVT_CHOICE( ID_ON_GRID_SELECT, FOOTPRINT_VIEWER_FRAME::OnSelectGrid )
  83. EVT_TEXT( ID_MODVIEW_LIB_FILTER, FOOTPRINT_VIEWER_FRAME::OnLibFilter )
  84. EVT_TEXT( ID_MODVIEW_FOOTPRINT_FILTER, FOOTPRINT_VIEWER_FRAME::OnFPFilter )
  85. // listbox events
  86. EVT_LISTBOX( ID_MODVIEW_LIB_LIST, FOOTPRINT_VIEWER_FRAME::ClickOnLibList )
  87. EVT_LISTBOX( ID_MODVIEW_FOOTPRINT_LIST, FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList )
  88. END_EVENT_TABLE()
  89. FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
  90. PCB_BASE_FRAME( aKiway, aParent, FRAME_FOOTPRINT_VIEWER, _( "Footprint Library Browser" ),
  91. wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE,
  92. FOOTPRINT_VIEWER_FRAME_NAME ),
  93. m_comp( LIB_ID(), wxEmptyString, wxEmptyString, KIID_PATH(), {} )
  94. {
  95. m_aboutTitle = _HKI( "KiCad Footprint Library Browser" );
  96. // Force the items to always snap
  97. m_magneticItems.pads = MAGNETIC_OPTIONS::CAPTURE_ALWAYS;
  98. m_magneticItems.tracks = MAGNETIC_OPTIONS::CAPTURE_ALWAYS;
  99. m_magneticItems.graphics = true;
  100. // Force the frame name used in config. the footprint viewer frame has a name
  101. // depending on aFrameType (needed to identify the frame by wxWidgets),
  102. // but only one configuration is preferable.
  103. m_configName = FOOTPRINT_VIEWER_FRAME_NAME;
  104. // Give an icon
  105. wxIcon icon;
  106. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_footprint_browser ) );
  107. SetIcon( icon );
  108. m_libListWidth = 200;
  109. m_fpListWidth = 300;
  110. wxPanel* libPanel = new wxPanel( this );
  111. wxSizer* libSizer = new wxBoxSizer( wxVERTICAL );
  112. m_libFilter = new wxSearchCtrl( libPanel, ID_MODVIEW_LIB_FILTER, wxEmptyString,
  113. wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
  114. m_libFilter->SetDescriptiveText( _( "Filter" ) );
  115. libSizer->Add( m_libFilter, 0, wxEXPAND, 5 );
  116. m_libList = new WX_LISTBOX( libPanel, ID_MODVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize,
  117. 0, nullptr, wxLB_HSCROLL | wxNO_BORDER );
  118. libSizer->Add( m_libList, 1, wxEXPAND, 5 );
  119. libPanel->SetSizer( libSizer );
  120. libPanel->Fit();
  121. wxPanel* fpPanel = new wxPanel( this );
  122. wxSizer* fpSizer = new wxBoxSizer( wxVERTICAL );
  123. m_fpFilter = new wxSearchCtrl( fpPanel, ID_MODVIEW_FOOTPRINT_FILTER, wxEmptyString,
  124. wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
  125. m_fpFilter->SetDescriptiveText( _( "Filter" ) );
  126. m_fpFilter->SetToolTip(
  127. _( "Filter on footprint name, keywords, description and pad count.\n"
  128. "Search terms are separated by spaces. All search terms must match.\n"
  129. "A term which is a number will also match against the pad count." ) );
  130. fpSizer->Add( m_fpFilter, 0, wxEXPAND, 5 );
  131. #ifdef __WXGTK__
  132. // wxSearchCtrl vertical height is not calculated correctly on some GTK setups
  133. // See https://gitlab.com/kicad/code/kicad/-/issues/9019
  134. m_libFilter->SetMinSize( wxSize( -1, GetTextExtent( wxT( "qb" ) ).y + 10 ) );
  135. m_fpFilter->SetMinSize( wxSize( -1, GetTextExtent( wxT( "qb" ) ).y + 10 ) );
  136. #endif
  137. m_fpList = new WX_LISTBOX( fpPanel, ID_MODVIEW_FOOTPRINT_LIST, wxDefaultPosition, wxDefaultSize,
  138. 0, nullptr, wxLB_HSCROLL | wxNO_BORDER );
  139. m_fpList->Connect( wxEVT_LEFT_DCLICK,
  140. wxMouseEventHandler( FOOTPRINT_VIEWER_FRAME::DClickOnFootprintList ),
  141. nullptr, this );
  142. fpSizer->Add( m_fpList, 1, wxEXPAND, 5 );
  143. fpPanel->SetSizer( fpSizer );
  144. fpPanel->Fit();
  145. // Create GAL canvas
  146. m_canvasType = loadCanvasTypeSetting();
  147. PCB_DRAW_PANEL_GAL* drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize,
  148. GetGalDisplayOptions(), m_canvasType );
  149. SetCanvas( drawPanel );
  150. SetBoard( new BOARD() );
  151. // This board will only be used to hold a footprint for viewing
  152. GetBoard()->SetBoardUse( BOARD_USE::FPHOLDER );
  153. // In viewer, the default net clearance is not known (it depends on the actual board).
  154. // So we do not show the default clearance, by setting it to 0
  155. // The footprint or pad specific clearance will be shown
  156. GetBoard()->GetDesignSettings().m_NetSettings->GetDefaultNetclass()->SetClearance( 0 );
  157. // Don't show the default board solder mask clearance in the footprint viewer. Only the
  158. // footprint or pad clearance setting should be shown if it is not 0.
  159. GetBoard()->GetDesignSettings().m_SolderMaskExpansion = 0;
  160. // Ensure all layers and items are visible:
  161. GetBoard()->SetVisibleAlls();
  162. SetScreen( new PCB_SCREEN( GetPageSizeIU() ) );
  163. GetScreen()->m_Center = true; // Center coordinate origins on screen.
  164. LoadSettings( config() );
  165. GetGalDisplayOptions().m_axesEnabled = true;
  166. // Create the manager and dispatcher & route draw panel events to the dispatcher
  167. m_toolManager = new TOOL_MANAGER;
  168. m_toolManager->SetEnvironment( GetBoard(), drawPanel->GetView(),
  169. drawPanel->GetViewControls(), config(), this );
  170. m_actions = new PCB_ACTIONS();
  171. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
  172. drawPanel->SetEventDispatcher( m_toolDispatcher );
  173. m_toolManager->RegisterTool( new PCB_CONTROL );
  174. m_toolManager->RegisterTool( new PCB_SELECTION_TOOL );
  175. m_toolManager->RegisterTool( new COMMON_TOOLS ); // for std context menus (zoom & grid)
  176. m_toolManager->RegisterTool( new COMMON_CONTROL );
  177. m_toolManager->RegisterTool( new PCB_PICKER_TOOL ); // for setting grid origin
  178. m_toolManager->RegisterTool( new ZOOM_TOOL );
  179. m_toolManager->RegisterTool( new PCB_VIEWER_TOOLS );
  180. m_toolManager->GetTool<PCB_VIEWER_TOOLS>()->SetFootprintFrame( true );
  181. m_toolManager->InitTools();
  182. m_toolManager->InvokeTool( "common.InteractiveSelection" );
  183. setupUIConditions();
  184. m_toolbarSettings = GetToolbarSettings<FOOTPRINT_VIEWER_TOOLBAR_SETTINGS>( "fpviewer-toolbars" );
  185. configureToolbars();
  186. RecreateToolbars();
  187. ReCreateMenuBar();
  188. ReCreateLibraryList();
  189. UpdateTitle();
  190. // Call resolveCanvasType after loading settings:
  191. resolveCanvasType();
  192. // If a footprint was previously loaded, reload it
  193. if( getCurNickname().size() && getCurFootprintName().size() )
  194. {
  195. LIB_ID id;
  196. id.SetLibNickname( getCurNickname() );
  197. id.SetLibItemName( getCurFootprintName() );
  198. FOOTPRINT* footprint = loadFootprint( id );
  199. if( footprint )
  200. {
  201. GetBoard()->Add( footprint );
  202. setFPWatcher( footprint );
  203. m_toolManager->RunAction( PCB_ACTIONS::rehatchShapes );
  204. }
  205. }
  206. drawPanel->DisplayBoard( m_pcb );
  207. m_auimgr.SetManagedWindow( this );
  208. // Horizontal items; layers 4 - 6
  209. m_auimgr.AddPane( m_tbTopMain, EDA_PANE().VToolbar().Name( "TopMainToolbar" ).Top().Layer(6) );
  210. m_auimgr.AddPane( m_tbLeft, EDA_PANE().VToolbar().Name( "LeftToolbar" ).Left().Layer(3) );
  211. m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
  212. // Vertical items; layers 1 - 3
  213. m_auimgr.AddPane( libPanel, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(2)
  214. .CaptionVisible( false ).MinSize( 100, -1 ).BestSize( 200, -1 ) );
  215. m_auimgr.AddPane( fpPanel, EDA_PANE().Palette().Name( "Footprints" ).Left().Layer(1)
  216. .CaptionVisible( false ).MinSize( 100, -1 ).BestSize( 300, -1 ) );
  217. m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
  218. // after changing something to the aui manager call Update() to reflect the changes
  219. m_auimgr.Update();
  220. if( m_libListWidth > 0 )
  221. SetAuiPaneSize( m_auimgr, m_auimgr.GetPane( "Libraries" ), m_libListWidth, -1 );
  222. if( m_fpListWidth > 0 )
  223. SetAuiPaneSize( m_auimgr, m_auimgr.GetPane( "Footprints" ), m_fpListWidth, -1 );
  224. // The canvas should not steal the focus from the list boxes
  225. GetCanvas()->SetCanFocus( false );
  226. GetCanvas()->GetGAL()->SetAxesEnabled( true );
  227. ActivateGalCanvas();
  228. // Restore last zoom and auto zoom option. (If auto-zooming we'll adjust when we load the footprint.)
  229. if( PCBNEW_SETTINGS* cfg = GetPcbNewSettings() )
  230. GetCanvas()->GetView()->SetScale( cfg->m_FootprintViewerZoom );
  231. updateView();
  232. setupUnits( config() );
  233. ReCreateFootprintList();
  234. Raise(); // On some window managers, this is needed
  235. Show( true );
  236. }
  237. FOOTPRINT_VIEWER_FRAME::~FOOTPRINT_VIEWER_FRAME()
  238. {
  239. // Shutdown all running tools
  240. if( m_toolManager )
  241. m_toolManager->ShutdownAllTools();
  242. GetCanvas()->StopDrawing();
  243. GetCanvas()->GetView()->Clear();
  244. // Be sure any event cannot be fired after frame deletion:
  245. GetCanvas()->SetEvtHandlerEnabled( false );
  246. m_fpList->Disconnect( wxEVT_LEFT_DCLICK,
  247. wxMouseEventHandler( FOOTPRINT_VIEWER_FRAME::DClickOnFootprintList ),
  248. nullptr, this );
  249. setFPWatcher( nullptr );
  250. }
  251. SELECTION& FOOTPRINT_VIEWER_FRAME::GetCurrentSelection()
  252. {
  253. return m_toolManager->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
  254. }
  255. void FOOTPRINT_VIEWER_FRAME::UpdateMsgPanel()
  256. {
  257. EDA_DRAW_FRAME::UpdateMsgPanel();
  258. if( FOOTPRINT* fp = static_cast<FOOTPRINT*>( GetModel() ) )
  259. {
  260. std::vector<MSG_PANEL_ITEM> msgItems;
  261. fp->GetMsgPanelInfo( this, msgItems );
  262. SetMsgPanel( msgItems );
  263. }
  264. }
  265. void FOOTPRINT_VIEWER_FRAME::setupUIConditions()
  266. {
  267. PCB_BASE_FRAME::setupUIConditions();
  268. ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
  269. PCB_EDITOR_CONDITIONS cond( this );
  270. wxASSERT( mgr );
  271. auto addToBoardCond =
  272. [this]( const SELECTION& )
  273. {
  274. return ( GetBoard()->GetFirstFootprint() != nullptr );
  275. };
  276. #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
  277. #define CHECK( x ) ACTION_CONDITIONS().Check( x )
  278. mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) );
  279. mgr->SetConditions( ACTIONS::toggleCursorStyle, CHECK( cond.FullscreenCursor() ) );
  280. mgr->SetConditions( ACTIONS::millimetersUnits, CHECK( cond.Units( EDA_UNITS::MM ) ) );
  281. mgr->SetConditions( ACTIONS::inchesUnits, CHECK( cond.Units( EDA_UNITS::INCH ) ) );
  282. mgr->SetConditions( ACTIONS::milsUnits, CHECK( cond.Units( EDA_UNITS::MILS ) ) );
  283. mgr->SetConditions( PCB_ACTIONS::saveFpToBoard, ENABLE( addToBoardCond ) );
  284. mgr->SetConditions( ACTIONS::zoomTool,
  285. CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) );
  286. mgr->SetConditions( ACTIONS::measureTool,
  287. CHECK( cond.CurrentTool( ACTIONS::measureTool ) ) );
  288. mgr->SetConditions( ACTIONS::selectionTool,
  289. CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) );
  290. mgr->SetConditions( PCB_ACTIONS::showPadNumbers, CHECK( cond.PadNumbersDisplay() ) );
  291. mgr->SetConditions( PCB_ACTIONS::padDisplayMode, CHECK( !cond.PadFillDisplay() ) );
  292. mgr->SetConditions( PCB_ACTIONS::textOutlines, CHECK( !cond.TextFillDisplay() ) );
  293. mgr->SetConditions( PCB_ACTIONS::graphicsOutlines, CHECK( !cond.GraphicsFillDisplay() ) );
  294. mgr->SetConditions( ACTIONS::toggleBoundingBoxes, CHECK( cond.BoundingBoxes() ) );
  295. mgr->SetConditions( PCB_ACTIONS::fpAutoZoom, CHECK( cond.FootprintViewerAutoZoom() ) );
  296. #undef ENABLE
  297. #undef CHECK
  298. }
  299. void FOOTPRINT_VIEWER_FRAME::doCloseWindow()
  300. {
  301. // A workaround to avoid flicker, in modal mode when modview frame is destroyed,
  302. // when the aui toolbar is not docked (i.e. shown in a miniframe)
  303. // (useful on windows only)
  304. m_tbTopMain->SetFocus();
  305. GetCanvas()->StopDrawing();
  306. Destroy();
  307. }
  308. void FOOTPRINT_VIEWER_FRAME::OnSize( wxSizeEvent& SizeEv )
  309. {
  310. if( m_auimgr.GetManagedWindow() )
  311. m_auimgr.Update();
  312. SizeEv.Skip();
  313. }
  314. void FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList()
  315. {
  316. m_libList->Clear();
  317. COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
  318. PROJECT_FILE& project = Kiway().Prj().GetProjectFile();
  319. std::vector<wxString> nicknames = PROJECT_PCB::PcbFootprintLibs( &Prj() )->GetLogicalLibs();
  320. std::vector<wxString> pinnedMatches;
  321. std::vector<wxString> otherMatches;
  322. auto process =
  323. [&]( const wxString& aNickname )
  324. {
  325. if( alg::contains( project.m_PinnedFootprintLibs, aNickname )
  326. || alg::contains( cfg->m_Session.pinned_fp_libs, aNickname ) )
  327. {
  328. pinnedMatches.push_back( aNickname );
  329. }
  330. else
  331. {
  332. otherMatches.push_back( aNickname );
  333. }
  334. };
  335. if( m_libFilter->GetValue().IsEmpty() )
  336. {
  337. for( const wxString& nickname : nicknames )
  338. process( nickname );
  339. }
  340. else
  341. {
  342. wxStringTokenizer tokenizer( m_libFilter->GetValue() );
  343. while( tokenizer.HasMoreTokens() )
  344. {
  345. const wxString term = tokenizer.GetNextToken().Lower();
  346. EDA_COMBINED_MATCHER matcher( term, CTX_LIBITEM );
  347. for( const wxString& nickname : nicknames )
  348. {
  349. if( matcher.Find( nickname.Lower() ) )
  350. process( nickname );
  351. }
  352. }
  353. }
  354. for( const wxString& nickname : pinnedMatches )
  355. m_libList->Append( LIB_TREE_MODEL_ADAPTER::GetPinningSymbol() + nickname );
  356. for( const wxString& nickname : otherMatches )
  357. m_libList->Append( nickname );
  358. // Search for a previous selection:
  359. int index = m_libList->FindString( getCurNickname(), true );
  360. if( index == wxNOT_FOUND )
  361. {
  362. if( m_libList->GetCount() > 0 )
  363. {
  364. m_libList->SetSelection( 0 );
  365. wxCommandEvent dummy;
  366. ClickOnLibList( dummy );
  367. }
  368. else
  369. {
  370. setCurNickname( wxEmptyString );
  371. setCurFootprintName( wxEmptyString );
  372. }
  373. }
  374. else
  375. {
  376. m_libList->SetSelection( index, true );
  377. wxCommandEvent dummy;
  378. ClickOnLibList( dummy );
  379. }
  380. GetCanvas()->Refresh();
  381. }
  382. void FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList()
  383. {
  384. m_fpList->Clear();
  385. if( !getCurNickname() )
  386. setCurFootprintName( wxEmptyString );
  387. auto fp_info_list = FOOTPRINT_LIST::GetInstance( Kiway() );
  388. wxString nickname = getCurNickname();
  389. fp_info_list->ReadFootprintFiles( PROJECT_PCB::PcbFootprintLibs( &Prj() ), !nickname ? nullptr : &nickname );
  390. if( fp_info_list->GetErrorCount() )
  391. {
  392. fp_info_list->DisplayErrors( this );
  393. // For footprint libraries that support one footprint per file, there may have been
  394. // valid footprints read so show the footprints that loaded properly.
  395. if( fp_info_list->GetList().empty() )
  396. return;
  397. }
  398. std::set<wxString> excludes;
  399. if( !m_fpFilter->GetValue().IsEmpty() )
  400. {
  401. wxStringTokenizer tokenizer( m_fpFilter->GetValue() );
  402. while( tokenizer.HasMoreTokens() )
  403. {
  404. const wxString filterTerm = tokenizer.GetNextToken().Lower();
  405. EDA_COMBINED_MATCHER matcher( filterTerm, CTX_LIBITEM );
  406. for( const std::unique_ptr<FOOTPRINT_INFO>& footprint : fp_info_list->GetList() )
  407. {
  408. std::vector<SEARCH_TERM> searchTerms = footprint->GetSearchTerms();
  409. int matched = matcher.ScoreTerms( searchTerms );
  410. if( filterTerm.IsNumber() && wxAtoi( filterTerm ) == (int)footprint->GetPadCount() )
  411. matched++;
  412. if( !matched )
  413. excludes.insert( footprint->GetFootprintName() );
  414. }
  415. }
  416. }
  417. for( const std::unique_ptr<FOOTPRINT_INFO>& footprint : fp_info_list->GetList() )
  418. {
  419. if( !excludes.count( footprint->GetFootprintName() ) )
  420. m_fpList->Append( footprint->GetFootprintName() );
  421. }
  422. int index = m_fpList->FindString( getCurFootprintName(), true );
  423. if( index == wxNOT_FOUND )
  424. {
  425. if( m_fpList->GetCount() > 0 )
  426. {
  427. m_fpList->SetSelection( 0 );
  428. m_fpList->EnsureVisible( 0 );
  429. wxCommandEvent dummy;
  430. ClickOnFootprintList( dummy );
  431. }
  432. else
  433. {
  434. setCurFootprintName( wxEmptyString );
  435. }
  436. }
  437. else
  438. {
  439. m_fpList->SetSelection( index, true );
  440. m_fpList->EnsureVisible( index );
  441. }
  442. }
  443. void FOOTPRINT_VIEWER_FRAME::OnLibFilter( wxCommandEvent& aEvent )
  444. {
  445. ReCreateLibraryList();
  446. // Required to avoid interaction with SetHint()
  447. // See documentation for wxTextEntry::SetHint
  448. aEvent.Skip();
  449. }
  450. void FOOTPRINT_VIEWER_FRAME::OnFPFilter( wxCommandEvent& aEvent )
  451. {
  452. ReCreateFootprintList();
  453. // Required to avoid interaction with SetHint()
  454. // See documentation for wxTextEntry::SetHint
  455. aEvent.Skip();
  456. }
  457. void FOOTPRINT_VIEWER_FRAME::OnCharHook( wxKeyEvent& aEvent )
  458. {
  459. if( aEvent.GetKeyCode() == WXK_UP )
  460. {
  461. if( m_libFilter->HasFocus() || m_libList->HasFocus() )
  462. selectPrev( m_libList );
  463. else
  464. selectPrev( m_fpList );
  465. }
  466. else if( aEvent.GetKeyCode() == WXK_DOWN )
  467. {
  468. if( m_libFilter->HasFocus() || m_libList->HasFocus() )
  469. selectNext( m_libList );
  470. else
  471. selectNext( m_fpList );
  472. }
  473. else if( aEvent.GetKeyCode() == WXK_TAB && m_libFilter->HasFocus() )
  474. {
  475. if( !aEvent.ShiftDown() )
  476. m_fpFilter->SetFocus();
  477. else
  478. aEvent.Skip();
  479. }
  480. else if( aEvent.GetKeyCode() == WXK_TAB && m_fpFilter->HasFocus() )
  481. {
  482. if( aEvent.ShiftDown() )
  483. m_libFilter->SetFocus();
  484. else
  485. aEvent.Skip();
  486. }
  487. else if( ( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER )
  488. && m_fpList->GetSelection() >= 0 )
  489. {
  490. AddFootprintToPCB();
  491. }
  492. else
  493. {
  494. aEvent.Skip();
  495. }
  496. }
  497. void FOOTPRINT_VIEWER_FRAME::selectPrev( WX_LISTBOX* aListBox )
  498. {
  499. int prev = aListBox->GetSelection() - 1;
  500. if( prev >= 0 )
  501. {
  502. aListBox->SetSelection( prev );
  503. aListBox->EnsureVisible( prev );
  504. wxCommandEvent dummy;
  505. if( aListBox == m_libList )
  506. ClickOnLibList( dummy );
  507. else
  508. ClickOnFootprintList( dummy );
  509. }
  510. }
  511. void FOOTPRINT_VIEWER_FRAME::selectNext( WX_LISTBOX* aListBox )
  512. {
  513. int next = aListBox->GetSelection() + 1;
  514. if( next < (int)aListBox->GetCount() )
  515. {
  516. aListBox->SetSelection( next );
  517. aListBox->EnsureVisible( next );
  518. wxCommandEvent dummy;
  519. if( aListBox == m_libList )
  520. ClickOnLibList( dummy );
  521. else
  522. ClickOnFootprintList( dummy );
  523. }
  524. }
  525. void FOOTPRINT_VIEWER_FRAME::ClickOnLibList( wxCommandEvent& aEvent )
  526. {
  527. int ii = m_libList->GetSelection();
  528. if( ii < 0 )
  529. return;
  530. wxString name = m_libList->GetBaseString( ii );
  531. if( getCurNickname() == name )
  532. return;
  533. setCurNickname( name );
  534. // Ensure the displayed footprint is loade/reloaded from the new library
  535. setCurFootprintName( wxEmptyString );
  536. ReCreateFootprintList();
  537. UpdateTitle();
  538. }
  539. void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& aEvent )
  540. {
  541. if( m_fpList->GetCount() == 0 )
  542. return;
  543. int ii = m_fpList->GetSelection();
  544. if( ii < 0 )
  545. return;
  546. wxString name = m_fpList->GetBaseString( ii );
  547. if( getCurFootprintName().CmpNoCase( name ) != 0 )
  548. {
  549. setCurFootprintName( name );
  550. SelectAndViewFootprint( FPVIEWER_CONSTANTS::NEW_PART );
  551. }
  552. }
  553. void FOOTPRINT_VIEWER_FRAME::displayFootprint( FOOTPRINT* aFootprint )
  554. {
  555. for( PAD* pad : aFootprint->Pads() )
  556. {
  557. const COMPONENT_NET& net = m_comp.GetNet( pad->GetNumber() );
  558. if( !net.GetPinFunction().IsEmpty() )
  559. {
  560. NETINFO_ITEM* netinfo = new NETINFO_ITEM( GetBoard() );
  561. netinfo->SetNetname( net.GetPinFunction() );
  562. GetBoard()->Add( netinfo );
  563. pad->SetNet( netinfo );
  564. }
  565. }
  566. GetBoard()->Add( aFootprint );
  567. m_toolManager->RunAction( PCB_ACTIONS::rehatchShapes );
  568. }
  569. void FOOTPRINT_VIEWER_FRAME::DClickOnFootprintList( wxMouseEvent& aEvent )
  570. {
  571. AddFootprintToPCB();
  572. }
  573. void FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB()
  574. {
  575. if( GetBoard()->GetFirstFootprint() )
  576. {
  577. PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false );
  578. if( pcbframe == nullptr ) // happens when the board editor is not active (or closed)
  579. {
  580. DisplayErrorMessage( this, _( "No board currently open." ) );
  581. return;
  582. }
  583. PCBNEW_SETTINGS* cfg = pcbframe->GetPcbNewSettings();
  584. TOOL_MANAGER* toolMgr = pcbframe->GetToolManager();
  585. if( toolMgr->GetTool<BOARD_EDITOR_CONTROL>()->PlacingFootprint() )
  586. {
  587. DisplayError( this, _( "Previous footprint placement still in progress." ) );
  588. return;
  589. }
  590. wxWindow* blocking_dialog = pcbframe->Kiway().GetBlockingDialog();
  591. if( blocking_dialog )
  592. blocking_dialog->Close( true );
  593. toolMgr->RunAction( ACTIONS::selectionClear );
  594. BOARD_COMMIT commit( pcbframe );
  595. // Create the "new" footprint
  596. FOOTPRINT* newFootprint = (FOOTPRINT*) GetBoard()->GetFirstFootprint()->Duplicate( IGNORE_PARENT_GROUP );
  597. newFootprint->SetParent( pcbframe->GetBoard() );
  598. newFootprint->SetLink( niluuid );
  599. newFootprint->SetFlags(IS_NEW ); // whatever
  600. for( PAD* pad : newFootprint->Pads() )
  601. {
  602. // Set the pads ratsnest settings to the global settings
  603. pad->SetLocalRatsnestVisible( cfg->m_Display.m_ShowGlobalRatsnest );
  604. // Pads in the library all have orphaned nets. Replace with Default.
  605. pad->SetNetCode( 0 );
  606. }
  607. // Put it on FRONT layer,
  608. // (Can be stored flipped if the lib is an archive built from a board)
  609. if( newFootprint->IsFlipped() )
  610. newFootprint->Flip( newFootprint->GetPosition(), cfg->m_FlipDirection );
  611. KIGFX::VIEW_CONTROLS* viewControls = pcbframe->GetCanvas()->GetViewControls();
  612. VECTOR2D cursorPos = viewControls->GetCursorPosition();
  613. commit.Add( newFootprint );
  614. viewControls->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
  615. pcbframe->PlaceFootprint( newFootprint );
  616. newFootprint->SetPosition( VECTOR2I( 0, 0 ) );
  617. viewControls->SetCrossHairCursorPosition( cursorPos, false );
  618. commit.Push( _( "Insert Footprint" ) );
  619. pcbframe->Raise();
  620. toolMgr->PostAction( PCB_ACTIONS::placeFootprint, newFootprint );
  621. newFootprint->ClearFlags();
  622. }
  623. }
  624. void FOOTPRINT_VIEWER_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  625. {
  626. if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg ) )
  627. {
  628. // We don't allow people to change this right now, so make sure it's on
  629. GetWindowSettings( cfg )->cursor.always_show_cursor = true;
  630. PCB_BASE_FRAME::LoadSettings( aCfg );
  631. // Fetch display and grid settings from Footprint Editor
  632. if( FOOTPRINT_EDITOR_SETTINGS* fpedit = GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>( "fpedit" ) )
  633. {
  634. m_displayOptions = fpedit->m_Display;
  635. GetGalDisplayOptions().ReadWindowSettings( fpedit->m_Window );
  636. }
  637. m_libListWidth = cfg->m_FootprintViewerLibListWidth;
  638. m_fpListWidth = cfg->m_FootprintViewerFPListWidth;
  639. // Set parameters to a reasonable value.
  640. int maxWidth = cfg->m_FootprintViewer.state.size_x - 80;
  641. if( m_libListWidth + m_fpListWidth > maxWidth )
  642. {
  643. m_libListWidth = maxWidth * ( m_libListWidth / ( m_libListWidth + m_fpListWidth ) );
  644. m_fpListWidth = maxWidth - m_libListWidth;
  645. }
  646. }
  647. }
  648. void FOOTPRINT_VIEWER_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  649. {
  650. PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
  651. wxCHECK( cfg, /*void*/ );
  652. GetGalDisplayOptions().m_axesEnabled = true;
  653. // We don't want to store anything other than the window settings
  654. PCB_BASE_FRAME::SaveSettings( cfg );
  655. if( GetCanvas() && GetCanvas()->GetView() )
  656. cfg->m_FootprintViewerZoom = GetCanvas()->GetView()->GetScale();
  657. cfg->m_FootprintViewerLibListWidth = m_libList->GetSize().x;
  658. cfg->m_FootprintViewerFPListWidth = m_fpList->GetSize().x;
  659. }
  660. WINDOW_SETTINGS* FOOTPRINT_VIEWER_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg )
  661. {
  662. PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
  663. wxCHECK_MSG( cfg, nullptr, wxT( "config not existing" ) );
  664. return &cfg->m_FootprintViewer;
  665. }
  666. COLOR_SETTINGS* FOOTPRINT_VIEWER_FRAME::GetColorSettings( bool aForceRefresh ) const
  667. {
  668. FOOTPRINT_EDITOR_SETTINGS* cfg = GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>( "fpedit" );
  669. return ::GetColorSettings( cfg ? cfg->m_ColorTheme : DEFAULT_THEME );
  670. }
  671. void FOOTPRINT_VIEWER_FRAME::CommonSettingsChanged( int aFlags )
  672. {
  673. PCB_BASE_FRAME::CommonSettingsChanged( aFlags );
  674. GetCanvas()->ForceRefresh();
  675. if( aFlags & ENVVARS_CHANGED )
  676. ReCreateLibraryList();
  677. }
  678. const wxString FOOTPRINT_VIEWER_FRAME::getCurNickname()
  679. {
  680. return Prj().GetRString( PROJECT::PCB_FOOTPRINT_VIEWER_LIB_NICKNAME );
  681. }
  682. void FOOTPRINT_VIEWER_FRAME::setCurNickname( const wxString& aNickname )
  683. {
  684. Prj().SetRString( PROJECT::PCB_FOOTPRINT_VIEWER_LIB_NICKNAME, aNickname );
  685. }
  686. const wxString FOOTPRINT_VIEWER_FRAME::getCurFootprintName()
  687. {
  688. return Prj().GetRString( PROJECT::PCB_FOOTPRINT_VIEWER_FP_NAME );
  689. }
  690. void FOOTPRINT_VIEWER_FRAME::setCurFootprintName( const wxString& aName )
  691. {
  692. Prj().SetRString( PROJECT::PCB_FOOTPRINT_VIEWER_FP_NAME, aName );
  693. }
  694. void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
  695. {
  696. if( event.GetActive() )
  697. {
  698. // Ensure we have the right library list:
  699. std::vector< wxString > libNicknames = PROJECT_PCB::PcbFootprintLibs( &Prj() )->GetLogicalLibs();
  700. bool stale = false;
  701. if( libNicknames.size() != m_libList->GetCount() )
  702. stale = true;
  703. else
  704. {
  705. for( unsigned ii = 0; ii < libNicknames.size(); ii++ )
  706. {
  707. if( libNicknames[ii] != m_libList->GetBaseString( ii ) )
  708. {
  709. stale = true;
  710. break;
  711. }
  712. }
  713. }
  714. if( stale )
  715. {
  716. ReCreateLibraryList();
  717. UpdateTitle();
  718. }
  719. }
  720. event.Skip(); // required under wxMAC
  721. }
  722. void FOOTPRINT_VIEWER_FRAME::ReloadFootprint( FOOTPRINT* aFootprint )
  723. {
  724. setCurNickname( aFootprint->GetFPID().GetLibNickname() );
  725. setCurFootprintName( aFootprint->GetFPID().GetLibItemName() );
  726. SelectAndViewFootprint( FPVIEWER_CONSTANTS::RELOAD_PART );
  727. }
  728. void FOOTPRINT_VIEWER_FRAME::HardRedraw()
  729. {
  730. ReCreateLibraryList();
  731. ReCreateFootprintList();
  732. ReloadFootprint( GetBoard()->GetFirstFootprint() );
  733. }
  734. void FOOTPRINT_VIEWER_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
  735. {
  736. switch( mail.Command() )
  737. {
  738. case MAIL_RELOAD_LIB:
  739. ReCreateLibraryList();
  740. break;
  741. default:
  742. break;
  743. }
  744. }
  745. void FOOTPRINT_VIEWER_FRAME::Update3DView( bool aMarkDirty, bool aRefresh, const wxString* aTitle )
  746. {
  747. wxString title = _( "3D Viewer" ) + wxT( " \u2014 " ) + getCurFootprintName();
  748. PCB_BASE_FRAME::Update3DView( aMarkDirty, aRefresh, &title );
  749. }
  750. COLOR4D FOOTPRINT_VIEWER_FRAME::GetGridColor()
  751. {
  752. return GetColorSettings()->GetColor( LAYER_GRID );
  753. }
  754. void FOOTPRINT_VIEWER_FRAME::UpdateTitle()
  755. {
  756. wxString title;
  757. if( !getCurNickname().IsEmpty() )
  758. {
  759. try
  760. {
  761. FP_LIB_TABLE* libtable = PROJECT_PCB::PcbFootprintLibs( &Prj() );
  762. const LIB_TABLE_ROW* row = libtable->FindRow( getCurNickname() );
  763. title = getCurNickname() + wxT( " \u2014 " ) + row->GetFullURI( true );
  764. }
  765. catch( ... )
  766. {
  767. title = _( "[no library selected]" );
  768. }
  769. }
  770. else
  771. {
  772. title = _( "[no library selected]" );
  773. }
  774. title += wxT( " \u2014 " ) + _( "Footprint Library Browser" );
  775. SetTitle( title );
  776. }
  777. void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( FPVIEWER_CONSTANTS aMode )
  778. {
  779. if( !getCurNickname() )
  780. return;
  781. int selection = m_fpList->FindString( getCurFootprintName(), true );
  782. if( aMode == FPVIEWER_CONSTANTS::NEXT_PART )
  783. {
  784. if( selection != wxNOT_FOUND && selection < (int)m_fpList->GetCount() - 1 )
  785. selection++;
  786. }
  787. if( aMode == FPVIEWER_CONSTANTS::PREVIOUS_PART )
  788. {
  789. if( selection != wxNOT_FOUND && selection > 0 )
  790. selection--;
  791. }
  792. if( selection != wxNOT_FOUND )
  793. {
  794. m_fpList->SetSelection( selection );
  795. m_fpList->EnsureVisible( selection );
  796. setCurFootprintName( m_fpList->GetBaseString( selection ) );
  797. // Delete the current footprint
  798. if( PCB_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<PCB_SELECTION_TOOL>() )
  799. selectionTool->ClearSelection( true /* quiet mode */ );
  800. GetBoard()->DeleteAllFootprints();
  801. GetBoard()->RemoveUnusedNets( nullptr );
  802. FOOTPRINT* footprint = PROJECT_PCB::PcbFootprintLibs( &Prj() )->FootprintLoad( getCurNickname(),
  803. getCurFootprintName() );
  804. if( footprint )
  805. displayFootprint( footprint );
  806. if( aMode != FPVIEWER_CONSTANTS::RELOAD_PART )
  807. setFPWatcher( footprint );
  808. Update3DView( true, true );
  809. updateView();
  810. }
  811. UpdateTitle();
  812. GetCanvas()->Refresh();
  813. }
  814. void FOOTPRINT_VIEWER_FRAME::updateView()
  815. {
  816. GetCanvas()->UpdateColors();
  817. GetCanvas()->DisplayBoard( GetBoard() );
  818. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  819. PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( config() );
  820. wxCHECK( cfg, /* void */ );
  821. if( cfg->m_FootprintViewerAutoZoomOnSelect )
  822. m_toolManager->RunAction( ACTIONS::zoomFitScreen );
  823. else
  824. m_toolManager->RunAction( ACTIONS::centerContents );
  825. UpdateMsgPanel();
  826. }
  827. void FOOTPRINT_VIEWER_FRAME::OnExitKiCad( wxCommandEvent& event )
  828. {
  829. Kiway().OnKiCadExit();
  830. }
  831. void FOOTPRINT_VIEWER_FRAME::CloseFootprintViewer( wxCommandEvent& event )
  832. {
  833. Close( false );
  834. }
  835. BOARD_ITEM_CONTAINER* FOOTPRINT_VIEWER_FRAME::GetModel() const
  836. {
  837. return GetBoard()->GetFirstFootprint();
  838. }