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.

550 lines
18 KiB

++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
14 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
5 years ago
14 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) 2015 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright (C) 2007-2021 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <bitmaps.h>
  26. #include <board.h>
  27. #include <footprint.h>
  28. #include <common.h>
  29. #include <confirm.h>
  30. #include <cvpcb_settings.h>
  31. #include <footprint_editor_settings.h>
  32. #include <fp_lib_table.h>
  33. #include <id.h>
  34. #include <kiface_base.h>
  35. #include <lib_id.h>
  36. #include <macros.h>
  37. #include <widgets/msgpanel.h>
  38. #include <pcb_draw_panel_gal.h>
  39. #include <pcb_painter.h>
  40. #include <pgm_base.h>
  41. #include <reporter.h>
  42. #include <settings/settings_manager.h>
  43. #include <tool/action_toolbar.h>
  44. #include <tool/common_tools.h>
  45. #include <tool/tool_dispatcher.h>
  46. #include <tool/tool_manager.h>
  47. #include <tool/zoom_tool.h>
  48. #include <cvpcb_mainframe.h>
  49. #include <display_footprints_frame.h>
  50. #include <tools/cvpcb_actions.h>
  51. #include <tools/pcb_actions.h>
  52. #include <tools/pcb_editor_conditions.h> // Shared conditions with other Pcbnew frames
  53. #include <tools/pcb_viewer_tools.h> // shared tools with other Pcbnew frames
  54. #include <tools/cvpcb_fpviewer_selection_tool.h>
  55. #include <widgets/infobar.h>
  56. #include <wx/choice.h>
  57. #include <wx/debug.h>
  58. BEGIN_EVENT_TABLE( DISPLAY_FOOTPRINTS_FRAME, PCB_BASE_FRAME )
  59. EVT_CLOSE( DISPLAY_FOOTPRINTS_FRAME::OnCloseWindow )
  60. EVT_CHOICE( ID_ON_ZOOM_SELECT, DISPLAY_FOOTPRINTS_FRAME::OnSelectZoom )
  61. EVT_CHOICE( ID_ON_GRID_SELECT, DISPLAY_FOOTPRINTS_FRAME::OnSelectGrid )
  62. END_EVENT_TABLE()
  63. DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
  64. PCB_BASE_FRAME( aKiway, aParent, FRAME_CVPCB_DISPLAY, _( "Footprint Viewer" ),
  65. wxDefaultPosition, wxDefaultSize,
  66. KICAD_DEFAULT_DRAWFRAME_STYLE, FOOTPRINTVIEWER_FRAME_NAME )
  67. {
  68. // Give an icon
  69. wxIcon icon;
  70. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_cvpcb ) );
  71. SetIcon( icon );
  72. SetBoard( new BOARD() );
  73. // This board will only be used to hold a footprint for viewing
  74. GetBoard()->SetBoardUse( BOARD_USE::FPHOLDER );
  75. SetScreen( new PCB_SCREEN( GetPageSizeIU() ) );
  76. // Create GAL canvas before loading settings
  77. auto* gal_drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize,
  78. GetGalDisplayOptions(),
  79. EDA_DRAW_PANEL_GAL::GAL_FALLBACK );
  80. SetCanvas( gal_drawPanel );
  81. // Don't show the default board solder mask clearance. Only the
  82. // footprint or pad clearance setting should be shown if it is not 0.
  83. GetBoard()->GetDesignSettings().m_SolderMaskMargin = 0;
  84. LoadSettings( config() );
  85. // Initialize some display options
  86. auto displ_opts = GetDisplayOptions();
  87. displ_opts.m_DisplayPadClearance = false; // Pad clearance has no meaning here
  88. // Track and via clearance has no meaning here.
  89. displ_opts.m_ShowTrackClearanceMode = PCB_DISPLAY_OPTIONS::DO_NOT_SHOW_CLEARANCE;
  90. SetDisplayOptions( displ_opts );
  91. // Create the manager and dispatcher & route draw panel events to the dispatcher
  92. m_toolManager = new TOOL_MANAGER;
  93. m_toolManager->SetEnvironment( GetBoard(), gal_drawPanel->GetView(),
  94. gal_drawPanel->GetViewControls(), config(), this );
  95. m_actions = new CVPCB_ACTIONS();
  96. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
  97. gal_drawPanel->SetEventDispatcher( m_toolDispatcher );
  98. m_toolManager->RegisterTool( new COMMON_TOOLS );
  99. m_toolManager->RegisterTool( new ZOOM_TOOL );
  100. m_toolManager->RegisterTool( new CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL );
  101. m_toolManager->RegisterTool( new PCB_VIEWER_TOOLS );
  102. m_toolManager->GetTool<PCB_VIEWER_TOOLS>()->SetFootprintFrame( true );
  103. m_toolManager->InitTools();
  104. setupUIConditions();
  105. // Run the control tool, it is supposed to be always active
  106. m_toolManager->InvokeTool( "cvpcb.FootprintViewerInteractiveSelection" );
  107. ReCreateHToolbar();
  108. ReCreateVToolbar();
  109. ReCreateOptToolbar();
  110. m_auimgr.SetManagedWindow( this );
  111. CreateInfoBar();
  112. m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" )
  113. .Top().Layer( 6 ) );
  114. m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" )
  115. .Left().Layer( 3 ) );
  116. m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" )
  117. .Center() );
  118. m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" )
  119. .Bottom().Layer( 6 ) );
  120. FinishAUIInitialization();
  121. auto& galOpts = GetGalDisplayOptions();
  122. galOpts.m_axesEnabled = true;
  123. ActivateGalCanvas();
  124. setupUnits( config() );
  125. // Restore last zoom. (If auto-zooming we'll adjust when we load the footprint.)
  126. CVPCB_SETTINGS* cfg = dynamic_cast<CVPCB_SETTINGS*>( config() );
  127. if( cfg )
  128. GetCanvas()->GetView()->SetScale( cfg->m_FootprintViewerZoom );
  129. updateView();
  130. Show( true );
  131. // Register a call to update the toolbar sizes. It can't be done immediately because
  132. // it seems to require some sizes calculated that aren't yet (at least on GTK).
  133. CallAfter( [&]()
  134. {
  135. // Ensure the controls on the toolbars all are correctly sized
  136. UpdateToolbarControlSizes();
  137. } );
  138. }
  139. DISPLAY_FOOTPRINTS_FRAME::~DISPLAY_FOOTPRINTS_FRAME()
  140. {
  141. // Shutdown all running tools
  142. if( m_toolManager )
  143. m_toolManager->ShutdownAllTools();
  144. GetBoard()->DeleteAllFootprints();
  145. GetCanvas()->StopDrawing();
  146. GetCanvas()->GetView()->Clear();
  147. // Be sure any event cannot be fired after frame deletion:
  148. GetCanvas()->SetEvtHandlerEnabled( false );
  149. delete GetScreen();
  150. SetScreen( nullptr ); // Be sure there is no double deletion
  151. }
  152. void DISPLAY_FOOTPRINTS_FRAME::setupUIConditions()
  153. {
  154. PCB_BASE_FRAME::setupUIConditions();
  155. ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
  156. PCB_EDITOR_CONDITIONS cond( this );
  157. wxASSERT( mgr );
  158. #define CHECK( x ) ACTION_CONDITIONS().Check( x )
  159. mgr->SetConditions( ACTIONS::zoomTool,
  160. CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) );
  161. mgr->SetConditions( ACTIONS::selectionTool,
  162. CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) );
  163. mgr->SetConditions( ACTIONS::measureTool,
  164. CHECK( cond.CurrentTool( ACTIONS::measureTool ) ) );
  165. mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) );
  166. mgr->SetConditions( ACTIONS::toggleCursorStyle, CHECK( cond.FullscreenCursor() ) );
  167. mgr->SetConditions( ACTIONS::millimetersUnits, CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) );
  168. mgr->SetConditions( ACTIONS::inchesUnits, CHECK( cond.Units( EDA_UNITS::INCHES ) ) );
  169. mgr->SetConditions( ACTIONS::milsUnits, CHECK( cond.Units( EDA_UNITS::MILS ) ) );
  170. mgr->SetConditions( PCB_ACTIONS::showPadNumbers,
  171. CHECK( cond.PadNumbersDisplay() ) );
  172. mgr->SetConditions( PCB_ACTIONS::padDisplayMode, CHECK( !cond.PadFillDisplay() ) );
  173. mgr->SetConditions( PCB_ACTIONS::textOutlines, CHECK( !cond.TextFillDisplay() ) );
  174. mgr->SetConditions( PCB_ACTIONS::graphicsOutlines,
  175. CHECK( !cond.GraphicsFillDisplay() ) );
  176. #undef CHECK
  177. }
  178. void DISPLAY_FOOTPRINTS_FRAME::doCloseWindow()
  179. {
  180. Destroy();
  181. }
  182. void DISPLAY_FOOTPRINTS_FRAME::ReCreateVToolbar()
  183. {
  184. // Currently, no vertical right toolbar.
  185. }
  186. void DISPLAY_FOOTPRINTS_FRAME::ReCreateOptToolbar()
  187. {
  188. if( m_optionsToolBar )
  189. {
  190. m_optionsToolBar->ClearToolbar();
  191. }
  192. else
  193. {
  194. m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition,
  195. wxDefaultSize,
  196. KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
  197. m_optionsToolBar->SetAuiManager( &m_auimgr );
  198. }
  199. m_optionsToolBar->Add( ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE );
  200. m_optionsToolBar->Add( ACTIONS::measureTool, ACTION_TOOLBAR::TOGGLE );
  201. m_optionsToolBar->AddScaledSeparator( this );
  202. m_optionsToolBar->Add( ACTIONS::toggleGrid, ACTION_TOOLBAR::TOGGLE );
  203. m_optionsToolBar->Add( ACTIONS::togglePolarCoords, ACTION_TOOLBAR::TOGGLE );
  204. m_optionsToolBar->Add( ACTIONS::inchesUnits, ACTION_TOOLBAR::TOGGLE );
  205. m_optionsToolBar->Add( ACTIONS::milsUnits, ACTION_TOOLBAR::TOGGLE );
  206. m_optionsToolBar->Add( ACTIONS::millimetersUnits, ACTION_TOOLBAR::TOGGLE );
  207. m_optionsToolBar->Add( ACTIONS::toggleCursorStyle, ACTION_TOOLBAR::TOGGLE );
  208. m_optionsToolBar->AddScaledSeparator( this );
  209. m_optionsToolBar->Add( PCB_ACTIONS::showPadNumbers, ACTION_TOOLBAR::TOGGLE );
  210. m_optionsToolBar->Add( PCB_ACTIONS::padDisplayMode, ACTION_TOOLBAR::TOGGLE );
  211. m_optionsToolBar->Add( PCB_ACTIONS::textOutlines, ACTION_TOOLBAR::TOGGLE );
  212. m_optionsToolBar->Add( PCB_ACTIONS::graphicsOutlines, ACTION_TOOLBAR::TOGGLE );
  213. m_optionsToolBar->Realize();
  214. }
  215. void DISPLAY_FOOTPRINTS_FRAME::ReCreateHToolbar()
  216. {
  217. // Note:
  218. // To rebuild the aui toolbar, the more easy way is to clear ( calling m_mainToolBar.Clear() )
  219. // all wxAuiToolBarItems.
  220. // However the wxAuiToolBarItems are not the owners of controls managed by
  221. // them ( m_zoomSelectBox and m_gridSelectBox ), and therefore do not delete them
  222. // So we do not recreate them after clearing the tools.
  223. if( m_mainToolBar )
  224. {
  225. m_mainToolBar->ClearToolbar();
  226. }
  227. else
  228. {
  229. m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  230. KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
  231. m_mainToolBar->SetAuiManager( &m_auimgr );
  232. }
  233. m_mainToolBar->Add( ACTIONS::zoomRedraw );
  234. m_mainToolBar->Add( ACTIONS::zoomInCenter );
  235. m_mainToolBar->Add( ACTIONS::zoomOutCenter );
  236. m_mainToolBar->Add( ACTIONS::zoomFitScreen );
  237. m_mainToolBar->Add( ACTIONS::zoomTool, ACTION_TOOLBAR::TOGGLE, ACTION_TOOLBAR::CANCEL );
  238. m_mainToolBar->AddScaledSeparator( this );
  239. m_mainToolBar->Add( ACTIONS::show3DViewer );
  240. m_mainToolBar->AddScaledSeparator( this );
  241. // Grid selection choice box.
  242. if( !m_gridSelectBox )
  243. m_gridSelectBox = new wxChoice( m_mainToolBar, ID_ON_GRID_SELECT );
  244. UpdateGridSelectBox();
  245. m_mainToolBar->AddControl( m_gridSelectBox );
  246. m_mainToolBar->AddScaledSeparator( this );
  247. // Zoom selection choice box.
  248. if( !m_zoomSelectBox )
  249. m_zoomSelectBox = new wxChoice( m_mainToolBar, ID_ON_ZOOM_SELECT );
  250. UpdateZoomSelectBox();
  251. m_mainToolBar->AddControl( m_zoomSelectBox );
  252. m_mainToolBar->UpdateControlWidth( ID_ON_GRID_SELECT );
  253. m_mainToolBar->UpdateControlWidth( ID_ON_ZOOM_SELECT );
  254. // after adding the buttons to the toolbar, must call Realize() to reflect the changes
  255. m_mainToolBar->Realize();
  256. }
  257. void DISPLAY_FOOTPRINTS_FRAME::UpdateToolbarControlSizes()
  258. {
  259. if( m_mainToolBar )
  260. {
  261. // Update the item widths
  262. m_mainToolBar->UpdateControlWidth( ID_ON_GRID_SELECT );
  263. m_mainToolBar->UpdateControlWidth( ID_ON_ZOOM_SELECT );
  264. }
  265. }
  266. void DISPLAY_FOOTPRINTS_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  267. {
  268. auto cfg = dynamic_cast<CVPCB_SETTINGS*>( aCfg );
  269. wxCHECK( cfg, /* void */ );
  270. // We don't allow people to change this right now, so make sure it's on
  271. GetWindowSettings( cfg )->cursor.always_show_cursor = true;
  272. PCB_BASE_FRAME::LoadSettings( cfg );
  273. SetDisplayOptions( cfg->m_FootprintViewerDisplayOptions );
  274. }
  275. void DISPLAY_FOOTPRINTS_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  276. {
  277. CVPCB_SETTINGS* cfg = dynamic_cast<CVPCB_SETTINGS*>( aCfg );
  278. wxCHECK( cfg, /* void */ );
  279. PCB_BASE_FRAME::SaveSettings( cfg );
  280. cfg->m_FootprintViewerDisplayOptions = GetDisplayOptions();
  281. cfg->m_FootprintViewerZoom = GetCanvas()->GetView()->GetScale();
  282. }
  283. WINDOW_SETTINGS* DISPLAY_FOOTPRINTS_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg )
  284. {
  285. CVPCB_SETTINGS* cfg = dynamic_cast<CVPCB_SETTINGS*>( aCfg );
  286. wxCHECK( cfg, nullptr );
  287. return &cfg->m_FootprintViewer;
  288. }
  289. MAGNETIC_SETTINGS* DISPLAY_FOOTPRINTS_FRAME::GetMagneticItemsSettings()
  290. {
  291. CVPCB_SETTINGS* cfg = dynamic_cast<CVPCB_SETTINGS*>( Kiface().KifaceSettings() );
  292. wxCHECK( cfg, nullptr );
  293. return &cfg->m_FootprintViewerMagneticSettings;
  294. }
  295. COLOR4D DISPLAY_FOOTPRINTS_FRAME::GetGridColor()
  296. {
  297. return COLOR4D( DARKGRAY );
  298. }
  299. FOOTPRINT* DISPLAY_FOOTPRINTS_FRAME::GetFootprint( const wxString& aFootprintName,
  300. REPORTER& aReporter )
  301. {
  302. FOOTPRINT* footprint = nullptr;
  303. LIB_ID fpid;
  304. if( fpid.Parse( aFootprintName ) >= 0 )
  305. {
  306. aReporter.Report( wxString::Format( _( "Footprint ID '%s' is not valid." ),
  307. aFootprintName ),
  308. RPT_SEVERITY_ERROR );
  309. return nullptr;
  310. }
  311. wxString libNickname = FROM_UTF8( fpid.GetLibNickname().c_str() );
  312. wxString fpName = FROM_UTF8( fpid.GetLibItemName().c_str() );
  313. FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
  314. wxASSERT( fpTable );
  315. // See if the library requested is in the library table
  316. if( !fpTable->HasLibrary( libNickname ) )
  317. {
  318. aReporter.Report( wxString::Format( _( "Library '%s' is not in the footprint library table." ),
  319. libNickname ),
  320. RPT_SEVERITY_ERROR );
  321. return nullptr;
  322. }
  323. // See if the footprint requested is in the library
  324. if( !fpTable->FootprintExists( libNickname, fpName ) )
  325. {
  326. aReporter.Report( wxString::Format( _( "Footprint '%s' not found." ), aFootprintName ),
  327. RPT_SEVERITY_ERROR );
  328. return nullptr;
  329. }
  330. try
  331. {
  332. const FOOTPRINT* fp = fpTable->GetEnumeratedFootprint( libNickname, fpName );
  333. if( fp )
  334. footprint = static_cast<FOOTPRINT*>( fp->Duplicate() );
  335. }
  336. catch( const IO_ERROR& ioe )
  337. {
  338. DisplayError( this, ioe.What() );
  339. return nullptr;
  340. }
  341. if( footprint )
  342. {
  343. footprint->SetParent( (EDA_ITEM*) GetBoard() );
  344. footprint->SetPosition( wxPoint( 0, 0 ) );
  345. return footprint;
  346. }
  347. aReporter.Report( wxString::Format( _( "Footprint '%s' not found." ), aFootprintName ),
  348. RPT_SEVERITY_ERROR );
  349. return nullptr;
  350. }
  351. void DISPLAY_FOOTPRINTS_FRAME::InitDisplay()
  352. {
  353. CVPCB_MAINFRAME* parentframe = (CVPCB_MAINFRAME *) GetParent();
  354. FOOTPRINT* footprint = nullptr;
  355. const FOOTPRINT_INFO* fpInfo = nullptr;
  356. GetBoard()->DeleteAllFootprints();
  357. GetCanvas()->GetView()->Clear();
  358. wxString footprintName = parentframe->GetSelectedFootprint();
  359. if( footprintName.IsEmpty() )
  360. {
  361. COMPONENT* comp = parentframe->GetSelectedComponent();
  362. if( comp )
  363. footprintName = comp->GetFPID().GetUniStringLibId();
  364. }
  365. INFOBAR_REPORTER infoReporter( m_infoBar );
  366. m_infoBar->Dismiss();
  367. if( !footprintName.IsEmpty() )
  368. {
  369. SetTitle( wxString::Format( _( "Footprint: %s" ), footprintName ) );
  370. footprint = GetFootprint( footprintName, infoReporter );
  371. fpInfo = parentframe->m_FootprintsList->GetFootprintInfo( footprintName );
  372. }
  373. if( footprint )
  374. GetBoard()->Add( footprint );
  375. if( fpInfo )
  376. SetStatusText( wxString::Format( _( "Lib: %s" ), fpInfo->GetLibNickname() ), 0 );
  377. else
  378. SetStatusText( wxEmptyString, 0 );
  379. infoReporter.Finalize();
  380. updateView();
  381. UpdateStatusBar();
  382. GetCanvas()->Refresh();
  383. Update3DView( true, true );
  384. }
  385. void DISPLAY_FOOTPRINTS_FRAME::updateView()
  386. {
  387. PCB_DRAW_PANEL_GAL* dp = static_cast<PCB_DRAW_PANEL_GAL*>( GetCanvas() );
  388. dp->UpdateColors();
  389. dp->DisplayBoard( GetBoard() );
  390. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  391. if( m_zoomSelectBox->GetSelection() == 0 )
  392. m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
  393. else
  394. m_toolManager->RunAction( ACTIONS::centerContents, true );
  395. UpdateMsgPanel();
  396. }
  397. void DISPLAY_FOOTPRINTS_FRAME::UpdateMsgPanel()
  398. {
  399. FOOTPRINT* footprint = GetBoard()->GetFirstFootprint();
  400. std::vector<MSG_PANEL_ITEM> items;
  401. if( footprint )
  402. footprint->GetMsgPanelInfo( this, items );
  403. SetMsgPanel( items );
  404. }
  405. COLOR_SETTINGS* DISPLAY_FOOTPRINTS_FRAME::GetColorSettings() const
  406. {
  407. auto* settings = Pgm().GetSettingsManager().GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>();
  408. if( settings )
  409. return Pgm().GetSettingsManager().GetColorSettings( settings->m_ColorTheme );
  410. else
  411. return Pgm().GetSettingsManager().GetColorSettings();
  412. }
  413. BOARD_ITEM_CONTAINER* DISPLAY_FOOTPRINTS_FRAME::GetModel() const
  414. {
  415. return GetBoard()->GetFirstFootprint();
  416. }
  417. SELECTION& DISPLAY_FOOTPRINTS_FRAME::GetCurrentSelection()
  418. {
  419. return m_toolManager->GetTool<CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL>()->GetSelection();
  420. }