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
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-2020 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 <class_board.h>
  27. #include <class_module.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_i.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/debug.h>
  57. BEGIN_EVENT_TABLE( DISPLAY_FOOTPRINTS_FRAME, PCB_BASE_FRAME )
  58. EVT_CLOSE( DISPLAY_FOOTPRINTS_FRAME::OnCloseWindow )
  59. EVT_CHOICE( ID_ON_ZOOM_SELECT, DISPLAY_FOOTPRINTS_FRAME::OnSelectZoom )
  60. EVT_CHOICE( ID_ON_GRID_SELECT, DISPLAY_FOOTPRINTS_FRAME::OnSelectGrid )
  61. END_EVENT_TABLE()
  62. DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
  63. PCB_BASE_FRAME( aKiway, aParent, FRAME_CVPCB_DISPLAY, _( "Footprint Viewer" ),
  64. wxDefaultPosition, wxDefaultSize,
  65. KICAD_DEFAULT_DRAWFRAME_STYLE, FOOTPRINTVIEWER_FRAME_NAME )
  66. {
  67. // Give an icon
  68. wxIcon icon;
  69. icon.CopyFromBitmap( KiBitmap( icon_cvpcb_xpm ) );
  70. SetIcon( icon );
  71. SetBoard( new BOARD() );
  72. // This board will only be used to hold a footprint for viewing
  73. GetBoard()->SetBoardUse( BOARD_USE::FPHOLDER );
  74. SetScreen( new PCB_SCREEN( GetPageSizeIU() ) );
  75. // Create GAL canvas before loading settings
  76. auto* gal_drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize,
  77. GetGalDisplayOptions(),
  78. EDA_DRAW_PANEL_GAL::GAL_FALLBACK );
  79. SetCanvas( gal_drawPanel );
  80. // Don't show the default board solder mask clearance. Only the
  81. // footprint or pad clearance setting should be shown if it is not 0.
  82. GetBoard()->GetDesignSettings().m_SolderMaskMargin = 0;
  83. LoadSettings( config() );
  84. // Initialize some display options
  85. auto displ_opts = GetDisplayOptions();
  86. displ_opts.m_DisplayPadIsol = false; // Pad clearance has no meaning here
  87. // Track and via clearance has no meaning here.
  88. displ_opts.m_ShowTrackClearanceMode = PCB_DISPLAY_OPTIONS::DO_NOT_SHOW_CLEARANCE;
  89. SetDisplayOptions( displ_opts );
  90. // Create the manager and dispatcher & route draw panel events to the dispatcher
  91. m_toolManager = new TOOL_MANAGER;
  92. m_toolManager->SetEnvironment( GetBoard(), gal_drawPanel->GetView(),
  93. gal_drawPanel->GetViewControls(), config(), this );
  94. m_actions = new CVPCB_ACTIONS();
  95. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions );
  96. gal_drawPanel->SetEventDispatcher( m_toolDispatcher );
  97. m_toolManager->RegisterTool( new COMMON_TOOLS );
  98. m_toolManager->RegisterTool( new ZOOM_TOOL );
  99. m_toolManager->RegisterTool( new CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL );
  100. m_toolManager->RegisterTool( new PCB_VIEWER_TOOLS );
  101. m_toolManager->GetTool<PCB_VIEWER_TOOLS>()->SetFootprintFrame( true );
  102. m_toolManager->InitTools();
  103. setupUIConditions();
  104. // Run the control tool, it is supposed to be always active
  105. m_toolManager->InvokeTool( "cvpcb.FootprintViewerInteractiveSelection" );
  106. ReCreateHToolbar();
  107. ReCreateVToolbar();
  108. ReCreateOptToolbar();
  109. // Create the infobar
  110. m_infoBar = new WX_INFOBAR( this, &m_auimgr );
  111. m_auimgr.SetManagedWindow( this );
  112. m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
  113. m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" ).Left().Layer(3) );
  114. m_auimgr.AddPane( m_infoBar, EDA_PANE().InfoBar().Name( "InfoBar" ).Top().Layer(1) );
  115. m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
  116. m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
  117. // Call Update() to fix all pane default sizes, especially the "InfoBar" pane before
  118. // hidding it.
  119. m_auimgr.Update();
  120. // We don't want the infobar displayed right away
  121. m_auimgr.GetPane( "InfoBar" ).Hide();
  122. m_auimgr.Update();
  123. auto& galOpts = GetGalDisplayOptions();
  124. galOpts.m_axesEnabled = true;
  125. ActivateGalCanvas();
  126. setupUnits( config() );
  127. // Restore last zoom. (If auto-zooming we'll adjust when we load the footprint.)
  128. CVPCB_SETTINGS* cfg = dynamic_cast<CVPCB_SETTINGS*>( config() );
  129. if( cfg )
  130. GetCanvas()->GetView()->SetScale( cfg->m_FootprintViewerZoom );
  131. updateView();
  132. Show( true );
  133. }
  134. DISPLAY_FOOTPRINTS_FRAME::~DISPLAY_FOOTPRINTS_FRAME()
  135. {
  136. // Shutdown all running tools
  137. if( m_toolManager )
  138. m_toolManager->ShutdownAllTools();
  139. GetBoard()->DeleteAllModules();
  140. GetCanvas()->StopDrawing();
  141. GetCanvas()->GetView()->Clear();
  142. // Be sure any event cannot be fired after frame deletion:
  143. GetCanvas()->SetEvtHandlerEnabled( false );
  144. delete GetScreen();
  145. SetScreen( NULL ); // Be sure there is no double deletion
  146. }
  147. void DISPLAY_FOOTPRINTS_FRAME::setupUIConditions()
  148. {
  149. PCB_BASE_FRAME::setupUIConditions();
  150. ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
  151. PCB_EDITOR_CONDITIONS cond( this );
  152. wxASSERT( mgr );
  153. #define CHECK( x ) ACTION_CONDITIONS().Check( x )
  154. mgr->SetConditions( ACTIONS::zoomTool, CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) );
  155. mgr->SetConditions( ACTIONS::selectionTool, CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) );
  156. mgr->SetConditions( ACTIONS::measureTool, CHECK( cond.CurrentTool( ACTIONS::measureTool ) ) );
  157. mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) );
  158. mgr->SetConditions( ACTIONS::toggleCursorStyle, CHECK( cond.FullscreenCursor() ) );
  159. mgr->SetConditions( ACTIONS::millimetersUnits, CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) );
  160. mgr->SetConditions( ACTIONS::inchesUnits, CHECK( cond.Units( EDA_UNITS::INCHES ) ) );
  161. mgr->SetConditions( ACTIONS::milsUnits, CHECK( cond.Units( EDA_UNITS::MILS ) ) );
  162. auto autoZoomCond =
  163. [this] ( const SELECTION& aSel )
  164. {
  165. return GetAutoZoom();
  166. };
  167. mgr->SetConditions( PCB_ACTIONS::zoomFootprintAutomatically, CHECK( autoZoomCond ) );
  168. mgr->SetConditions( PCB_ACTIONS::showPadNumbers, CHECK( cond.PadNumbersDisplay() ) );
  169. mgr->SetConditions( PCB_ACTIONS::padDisplayMode, CHECK( !cond.PadFillDisplay() ) );
  170. mgr->SetConditions( PCB_ACTIONS::textOutlines, CHECK( !cond.TextFillDisplay() ) );
  171. mgr->SetConditions( PCB_ACTIONS::graphicsOutlines, CHECK( !cond.GraphicsFillDisplay() ) );
  172. #undef CHECK
  173. }
  174. void DISPLAY_FOOTPRINTS_FRAME::doCloseWindow()
  175. {
  176. Destroy();
  177. }
  178. void DISPLAY_FOOTPRINTS_FRAME::ReCreateVToolbar()
  179. {
  180. // Currently, no vertical right toolbar.
  181. }
  182. void DISPLAY_FOOTPRINTS_FRAME::ReCreateOptToolbar()
  183. {
  184. if( m_optionsToolBar )
  185. {
  186. m_optionsToolBar->ClearToolbar();
  187. }
  188. else
  189. {
  190. m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  191. KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
  192. m_optionsToolBar->SetAuiManager( &m_auimgr );
  193. }
  194. m_optionsToolBar->Add( ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE );
  195. m_optionsToolBar->Add( ACTIONS::measureTool, ACTION_TOOLBAR::TOGGLE );
  196. m_optionsToolBar->AddScaledSeparator( this );
  197. m_optionsToolBar->Add( ACTIONS::toggleGrid, ACTION_TOOLBAR::TOGGLE );
  198. m_optionsToolBar->Add( ACTIONS::togglePolarCoords, ACTION_TOOLBAR::TOGGLE );
  199. m_optionsToolBar->Add( ACTIONS::inchesUnits, ACTION_TOOLBAR::TOGGLE );
  200. m_optionsToolBar->Add( ACTIONS::milsUnits, ACTION_TOOLBAR::TOGGLE );
  201. m_optionsToolBar->Add( ACTIONS::millimetersUnits, ACTION_TOOLBAR::TOGGLE );
  202. m_optionsToolBar->Add( ACTIONS::toggleCursorStyle, ACTION_TOOLBAR::TOGGLE );
  203. m_optionsToolBar->AddScaledSeparator( this );
  204. m_optionsToolBar->Add( PCB_ACTIONS::showPadNumbers, ACTION_TOOLBAR::TOGGLE );
  205. m_optionsToolBar->Add( PCB_ACTIONS::padDisplayMode, ACTION_TOOLBAR::TOGGLE );
  206. m_optionsToolBar->Add( PCB_ACTIONS::textOutlines, ACTION_TOOLBAR::TOGGLE );
  207. m_optionsToolBar->Add( PCB_ACTIONS::graphicsOutlines, ACTION_TOOLBAR::TOGGLE );
  208. m_optionsToolBar->Realize();
  209. }
  210. void DISPLAY_FOOTPRINTS_FRAME::ReCreateHToolbar()
  211. {
  212. // Note:
  213. // To rebuild the aui toolbar, the more easy way is to clear ( calling m_mainToolBar.Clear() )
  214. // all wxAuiToolBarItems.
  215. // However the wxAuiToolBarItems are not the owners of controls managed by
  216. // them ( m_zoomSelectBox and m_gridSelectBox ), and therefore do not delete them
  217. // So we do not recreate them after clearing the tools.
  218. if( m_mainToolBar )
  219. {
  220. m_mainToolBar->ClearToolbar();
  221. }
  222. else
  223. {
  224. m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  225. KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
  226. m_mainToolBar->SetAuiManager( &m_auimgr );
  227. }
  228. m_mainToolBar->Add( ACTIONS::zoomRedraw );
  229. m_mainToolBar->Add( ACTIONS::zoomInCenter );
  230. m_mainToolBar->Add( ACTIONS::zoomOutCenter );
  231. m_mainToolBar->Add( ACTIONS::zoomFitScreen );
  232. m_mainToolBar->Add( ACTIONS::zoomTool, ACTION_TOOLBAR::TOGGLE, ACTION_TOOLBAR::CANCEL );
  233. m_mainToolBar->Add( PCB_ACTIONS::zoomFootprintAutomatically, ACTION_TOOLBAR::TOGGLE );
  234. m_mainToolBar->AddScaledSeparator( this );
  235. m_mainToolBar->Add( ACTIONS::show3DViewer );
  236. m_mainToolBar->AddScaledSeparator( this );
  237. // Grid selection choice box.
  238. if( !m_gridSelectBox )
  239. m_gridSelectBox = new wxChoice( m_mainToolBar, ID_ON_GRID_SELECT,
  240. wxDefaultPosition, wxDefaultSize, 0, NULL );
  241. UpdateGridSelectBox();
  242. m_mainToolBar->AddControl( m_gridSelectBox );
  243. m_mainToolBar->AddScaledSeparator( this );
  244. // Zoom selection choice box.
  245. if( !m_zoomSelectBox )
  246. m_zoomSelectBox = new wxChoice( m_mainToolBar, ID_ON_ZOOM_SELECT,
  247. wxDefaultPosition, wxDefaultSize, 0, NULL );
  248. UpdateZoomSelectBox();
  249. m_mainToolBar->AddControl( m_zoomSelectBox );
  250. // after adding the buttons to the toolbar, must call Realize() to reflect
  251. // the changes
  252. m_mainToolBar->Realize();
  253. }
  254. void DISPLAY_FOOTPRINTS_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  255. {
  256. auto cfg = dynamic_cast<CVPCB_SETTINGS*>( aCfg );
  257. wxCHECK( cfg, /* void */ );
  258. // We don't allow people to change this right now, so make sure it's on
  259. GetWindowSettings( cfg )->cursor.always_show_cursor = true;
  260. PCB_BASE_FRAME::LoadSettings( cfg );
  261. SetDisplayOptions( cfg->m_FootprintViewerDisplayOptions );
  262. }
  263. void DISPLAY_FOOTPRINTS_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  264. {
  265. auto cfg = dynamic_cast<CVPCB_SETTINGS*>( aCfg );
  266. wxCHECK( cfg, /* void */ );
  267. PCB_BASE_FRAME::SaveSettings( cfg );
  268. cfg->m_FootprintViewerDisplayOptions = GetDisplayOptions();
  269. cfg->m_FootprintViewerZoom = GetCanvas()->GetView()->GetScale();
  270. }
  271. WINDOW_SETTINGS* DISPLAY_FOOTPRINTS_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg )
  272. {
  273. auto cfg = dynamic_cast<CVPCB_SETTINGS*>( aCfg );
  274. wxCHECK( cfg, nullptr );
  275. return &cfg->m_FootprintViewer;
  276. }
  277. MAGNETIC_SETTINGS* DISPLAY_FOOTPRINTS_FRAME::GetMagneticItemsSettings()
  278. {
  279. auto cfg = dynamic_cast<CVPCB_SETTINGS*>( Kiface().KifaceSettings() );
  280. wxCHECK( cfg, nullptr );
  281. return &cfg->m_FootprintViewerMagneticSettings;
  282. }
  283. COLOR4D DISPLAY_FOOTPRINTS_FRAME::GetGridColor()
  284. {
  285. return COLOR4D( DARKGRAY );
  286. }
  287. MODULE* DISPLAY_FOOTPRINTS_FRAME::GetModule( const wxString& aFootprintName, REPORTER& aReporter )
  288. {
  289. MODULE* footprint = NULL;
  290. LIB_ID fpid;
  291. if( fpid.Parse( aFootprintName, LIB_ID::ID_PCB ) >= 0 )
  292. {
  293. aReporter.Report( wxString::Format( _( "Footprint ID \"%s\" is not valid." ),
  294. aFootprintName ),
  295. RPT_SEVERITY_ERROR );
  296. return NULL;
  297. }
  298. wxString libNickname = FROM_UTF8( fpid.GetLibNickname().c_str() );
  299. wxString fpName = FROM_UTF8( fpid.GetLibItemName().c_str() );
  300. FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs( Kiway() );
  301. wxASSERT( fpTable );
  302. // See if the library requested is in the library table
  303. if( !fpTable->HasLibrary( libNickname ) )
  304. {
  305. aReporter.Report( wxString::Format( _( "Library \"%s\" is not in the footprint library table." ),
  306. libNickname ),
  307. RPT_SEVERITY_ERROR );
  308. return NULL;
  309. }
  310. // See if the footprint requested is in the library
  311. if( !fpTable->FootprintExists( libNickname, fpName ) )
  312. {
  313. aReporter.Report( wxString::Format( _( "Footprint \"%s\" not found." ), aFootprintName ),
  314. RPT_SEVERITY_ERROR );
  315. return NULL;
  316. }
  317. try
  318. {
  319. footprint = fpTable->FootprintLoad( libNickname, fpName );
  320. }
  321. catch( const IO_ERROR& ioe )
  322. {
  323. DisplayError( this, ioe.What() );
  324. return NULL;
  325. }
  326. if( footprint )
  327. {
  328. footprint->SetParent( (EDA_ITEM*) GetBoard() );
  329. footprint->SetPosition( wxPoint( 0, 0 ) );
  330. return footprint;
  331. }
  332. aReporter.Report( wxString::Format( _( "Footprint \"%s\" not found." ), aFootprintName ),
  333. RPT_SEVERITY_ERROR );
  334. return NULL;
  335. }
  336. void DISPLAY_FOOTPRINTS_FRAME::InitDisplay()
  337. {
  338. CVPCB_MAINFRAME* parentframe = (CVPCB_MAINFRAME *) GetParent();
  339. MODULE* module = nullptr;
  340. const FOOTPRINT_INFO* module_info = nullptr;
  341. GetBoard()->DeleteAllModules();
  342. GetCanvas()->GetView()->Clear();
  343. wxString footprintName = parentframe->GetSelectedFootprint();
  344. if( footprintName.IsEmpty() )
  345. {
  346. COMPONENT* comp = parentframe->GetSelectedComponent();
  347. if( comp )
  348. footprintName = comp->GetFPID().GetUniStringLibId();
  349. }
  350. INFOBAR_REPORTER infoReporter( m_infoBar );
  351. m_infoBar->Dismiss();
  352. if( !footprintName.IsEmpty() )
  353. {
  354. SetTitle( wxString::Format( _( "Footprint: %s" ), footprintName ) );
  355. module = GetModule( footprintName, infoReporter );
  356. module_info = parentframe->m_FootprintsList->GetModuleInfo( footprintName );
  357. }
  358. if( module )
  359. GetBoard()->Add( module );
  360. if( module_info )
  361. SetStatusText( wxString::Format( _( "Lib: %s" ), module_info->GetLibNickname() ), 0 );
  362. else
  363. SetStatusText( wxEmptyString, 0 );
  364. infoReporter.Finalize();
  365. updateView();
  366. UpdateStatusBar();
  367. GetCanvas()->Refresh();
  368. Update3DView( true );
  369. }
  370. void DISPLAY_FOOTPRINTS_FRAME::updateView()
  371. {
  372. PCB_DRAW_PANEL_GAL* dp = static_cast<PCB_DRAW_PANEL_GAL*>( GetCanvas() );
  373. dp->UpdateColors();
  374. dp->DisplayBoard( GetBoard() );
  375. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  376. if( GetAutoZoom() )
  377. m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
  378. else
  379. m_toolManager->RunAction( ACTIONS::centerContents, true );
  380. UpdateMsgPanel();
  381. }
  382. void DISPLAY_FOOTPRINTS_FRAME::UpdateMsgPanel()
  383. {
  384. MODULE* footprint = GetBoard()->GetFirstModule();
  385. MSG_PANEL_ITEMS items;
  386. if( footprint )
  387. footprint->GetMsgPanelInfo( this, items );
  388. SetMsgPanel( items );
  389. }
  390. COLOR_SETTINGS* DISPLAY_FOOTPRINTS_FRAME::GetColorSettings()
  391. {
  392. auto* settings = Pgm().GetSettingsManager().GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>();
  393. if( settings )
  394. return Pgm().GetSettingsManager().GetColorSettings( settings->m_ColorTheme );
  395. else
  396. return Pgm().GetSettingsManager().GetColorSettings();
  397. }
  398. BOARD_ITEM_CONTAINER* DISPLAY_FOOTPRINTS_FRAME::GetModel() const
  399. {
  400. return GetBoard()->GetFirstModule();
  401. }
  402. void DISPLAY_FOOTPRINTS_FRAME::SetAutoZoom( bool aAutoZoom )
  403. {
  404. CVPCB_SETTINGS* cfg = dynamic_cast<CVPCB_SETTINGS*>( config() );
  405. wxCHECK( cfg, /* void */ );
  406. cfg->m_FootprintViewerAutoZoom = aAutoZoom;
  407. }
  408. bool DISPLAY_FOOTPRINTS_FRAME::GetAutoZoom()
  409. {
  410. CVPCB_SETTINGS* cfg = dynamic_cast<CVPCB_SETTINGS*>( config() );
  411. wxCHECK( cfg, false );
  412. return cfg->m_FootprintViewerAutoZoom;
  413. }
  414. SELECTION& DISPLAY_FOOTPRINTS_FRAME::GetCurrentSelection()
  415. {
  416. return m_toolManager->GetTool<CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL>()->GetSelection();
  417. }