KiCad PCB EDA Suite
footprint_edit_frame.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2015 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2015-2016 Wayne Stambaugh <stambaughw@gmail.com>
7  * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software: you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by the
11  * Free Software Foundation, either version 3 of the License, or (at your
12  * option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "tools/drawing_tool.h"
24 #include "tools/edit_tool.h"
26 #include "tools/pad_tool.h"
27 #include "tools/pcb_actions.h"
28 #include "tools/pcbnew_control.h"
30 #include "tools/placement_tool.h"
31 #include "tools/point_editor.h"
32 #include "tools/selection_tool.h"
34 #include <bitmaps.h>
35 #include <class_board.h>
36 #include <class_module.h>
37 #include <confirm.h>
42 #include <fctsys.h>
43 #include <footprint_edit_frame.h>
45 #include <footprint_info_impl.h>
46 #include <footprint_tree_pane.h>
47 #include <footprint_viewer_frame.h>
48 #include <fp_lib_table.h>
49 #include <kicad_plugin.h>
50 #include <kiface_i.h>
51 #include <kiway.h>
52 #include <panel_hotkeys_editor.h>
53 #include <pcb_draw_panel_gal.h>
54 #include <pcb_edit_frame.h>
55 #include <pcb_layer_widget.h>
56 #include <pcbnew.h>
57 #include <pcbnew_id.h>
58 #include <pgm_base.h>
59 #include <project.h>
61 #include <tool/action_toolbar.h>
62 #include <tool/common_control.h>
63 #include <tool/common_tools.h>
64 #include <tool/tool_dispatcher.h>
65 #include <tool/tool_manager.h>
66 #include <tool/zoom_tool.h>
67 #include <tools/pcb_viewer_tools.h>
69 #include <widgets/infobar.h>
70 #include <widgets/lib_tree.h>
71 #include <widgets/paged_dialog.h>
74 
75 
76 BEGIN_EVENT_TABLE( FOOTPRINT_EDIT_FRAME, PCB_BASE_FRAME )
78  EVT_MENU( wxID_CLOSE, FOOTPRINT_EDIT_FRAME::CloseModuleEditor )
79  EVT_MENU( wxID_EXIT, FOOTPRINT_EDIT_FRAME::OnExitKiCad )
80 
82 
85 
87 
91 
92  // Horizontal toolbar
95 
96  // UI update events.
103 
104 END_EVENT_TABLE()
105 
106 
107 FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent,
108  EDA_DRAW_PANEL_GAL::GAL_TYPE aBackend ) :
109  PCB_BASE_EDIT_FRAME( aKiway, aParent, FRAME_FOOTPRINT_EDITOR, wxEmptyString,
110  wxDefaultPosition, wxDefaultSize,
111  KICAD_DEFAULT_DRAWFRAME_STYLE, GetFootprintEditorFrameName() )
112 {
113  m_showBorderAndTitleBlock = false; // true to show the frame references
114  m_canvasType = aBackend;
115  m_AboutTitle = "ModEdit";
116  m_selLayerBox = nullptr;
117  m_settings = nullptr;
118 
119  // Give an icon
120  wxIcon icon;
121  icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) );
122  SetIcon( icon );
123 
124  // Create GAL canvas
125  if( aBackend == EDA_DRAW_PANEL_GAL::GAL_TYPE_UNKNOWN )
126  m_canvasType = LoadCanvasTypeSetting();
127  else
128  m_canvasType = aBackend;
129 
130  PCB_DRAW_PANEL_GAL* drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize,
131  GetGalDisplayOptions(), m_canvasType );
132  SetCanvas( drawPanel );
133  SetBoard( new BOARD() );
134 
135  m_Layers = new PCB_LAYER_WIDGET( this, GetCanvas(), true );
136 
137  // LoadSettings() *after* creating m_LayersManager, because LoadSettings() initialize
138  // parameters in m_LayersManager
139  // NOTE: KifaceSettings() will return PCBNEW_SETTINGS if we started from pcbnew
140  LoadSettings( GetSettings() );
141 
142  // In modedit, the default net clearance is not known (it depends on the actual board).
143  // So we do not show the default clearance, by setting it to 0.
144  // The footprint or pad specific clearance will be shown.
146 
147  // Don't show the default board solder mask clearance in the footprint editor. Only the
148  // footprint or pad clearance setting should be shown if it is not 0.
150 
151  // restore the last footprint from the project, if any
152  restoreLastFootprint();
153 
154  // Ensure all layers and items are visible:
155  // In footprint editor, some layers have no meaning or cannot be used, but we show all of
156  // them, at least to be able to edit a bad layer
158 
159  // However the "no net" mark on pads is useless, because there are no nets in footprint
160  // editor: make it non visible.
162 
163  // Must be set after calling LoadSettings() to be sure these parameters are not dependent
164  // on what is read in stored settings. Enable one internal layer, because footprints
165  // support keepout areas that can be on internal layers only (therefore on the first internal
166  // layer). This is needed to handle these keepout in internal layers only.
168  GetBoard()->SetEnabledLayers( GetBoard()->GetEnabledLayers().set( In1_Cu ) );
169  GetBoard()->SetVisibleLayers( GetBoard()->GetEnabledLayers() );
170  GetBoard()->SetLayerName( In1_Cu, _( "Inner layers" ) );
171 
172  GetGalDisplayOptions().m_axesEnabled = true;
173 
174  // In modedit, set the default paper size to A4 for plot/print
175  SetPageSettings( PAGE_INFO( PAGE_INFO::A4 ) );
176  SetScreen( new PCB_SCREEN( GetPageSettings().GetSizeIU() ) );
177  GetScreen()->SetMaxUndoItems( m_UndoRedoCountMax );
178 
179  // Create the manager and dispatcher & route draw panel events to the dispatcher
180  setupTools();
181 
182  initLibraryTree();
183  m_treePane = new FOOTPRINT_TREE_PANE( this );
184 
185  ReCreateMenuBar();
186  ReCreateHToolbar();
187  ReCreateVToolbar();
188  ReCreateOptToolbar();
189 
190  m_Layers->ReFill();
191  m_Layers->ReFillRender();
192 
193  GetScreen()->m_Active_Layer = F_SilkS;
194  m_Layers->SelectLayer( F_SilkS );
195  m_Layers->OnLayerSelected();
196 
197  // Create the infobar
198  m_infoBar = new WX_INFOBAR( this, &m_auimgr );
199 
200  m_auimgr.SetManagedWindow( this );
201 
202  // Horizontal items; layers 4 - 6
203  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
204  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
205  m_auimgr.AddPane( m_infoBar,
206  EDA_PANE().InfoBar().Name( "InfoBar" ).Top().Layer(1) );
207 
208  // Vertical items; layers 1 - 3
209  m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" ).Left().Layer(3) );
210  m_auimgr.AddPane( m_treePane, EDA_PANE().Palette().Name( "Footprints" ).Left().Layer(2)
211  .Caption( _( "Libraries" ) ).MinSize( 250, 400 )
212  .BestSize( m_defaultLibWidth, -1 ) );
213 
214  m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" ).Right().Layer(2) );
215  m_auimgr.AddPane( m_Layers, EDA_PANE().Palette().Name( "LayersManager" ).Right().Layer(3)
216  .Caption( _( "Layers Manager" ) ).PaneBorder( false )
217  .MinSize( 80, -1 ).BestSize( m_Layers->GetBestSize() ) );
218 
219  m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
220 
221  ActivateGalCanvas();
222 
223  // Call Update() to fix all pane default sizes, especially the "InfoBar" pane before
224  // hidding it.
225  m_auimgr.Update();
226 
227  // We don't want the infobar displayed right away
228  m_auimgr.GetPane( "InfoBar" ).Hide();
229  m_auimgr.Update();
230 
231  GetToolManager()->RunAction( ACTIONS::zoomFitScreen, false );
232  updateTitle();
233  InitExitKey();
234 
235  // Default shutdown reason until a file is loaded
236  SetShutdownBlockReason( _( "Footprint changes are unsaved" ) );
237 
238  // Ensure the window is on top
239  Raise();
240  Show( true );
241 }
242 
243 
245 {
246  // Shutdown all running tools
247  if( m_toolManager )
249 
250  // save the footprint in the PROJECT
252 
253  delete m_Layers;
254 }
255 
256 
258 {
259  return GetScreen() && GetScreen()->IsModify() && GetBoard() && GetBoard()->GetFirstModule();
260 }
261 
262 
264 {
265  // switches currently used canvas (Cairo / OpenGL).
266  PCB_BASE_FRAME::SwitchCanvas( aCanvasType );
267 
268  GetCanvas()->GetGAL()->SetAxesEnabled( true );
269 
270  // The base class method *does not reinit* the layers manager. We must upate the layer
271  // widget to match board visibility states, both layers and render columns, and and some
272  // settings dependent on the canvas.
274 }
275 
276 
278 {
279  SyncLibraryTree( true );
280  GetCanvas()->ForceRefresh();
281 }
282 
283 
285 {
286  wxAuiPaneInfo& treePane = m_auimgr.GetPane( m_treePane );
287  treePane.Show( !IsSearchTreeShown() );
288  m_auimgr.Update();
289 }
290 
291 
293 {
294  return m_auimgr.GetPane( m_treePane ).IsShown();
295 }
296 
297 
299 {
300  return GetBoard()->GetFirstModule();
301 }
302 
303 
305 {
307 }
308 
309 
311 {
313 }
314 
315 
317 {
318  LIB_ID id = GetTreeFPID();
319 
320  if( id.GetLibNickname().empty() )
321  return GetLoadedFPID();
322 
323  return id;
324 }
325 
326 
328 {
329  MODULE* module = GetBoard()->GetFirstModule();
330 
331  if( module )
333  else
334  return LIB_ID();
335 }
336 
337 
339 {
340  MODULE* module = GetBoard()->GetFirstModule();
341 
342  return ( module && module->GetLink() != niluuid );
343 }
344 
345 
347 {
348  LIB_ID id = GetLoadedFPID();
349 
350  if( id.IsValid() )
351  {
353  Prj().SetRString( PROJECT::PCB_FOOTPRINT_EDITOR_FP_NAME, id.GetLibItemName() );
354  }
355 }
356 
357 
359 {
360  const wxString& footprintName = Prj().GetRString( PROJECT::PCB_FOOTPRINT_EDITOR_FP_NAME );
361  const wxString& libNickname = Prj().GetRString( PROJECT::PCB_FOOTPRINT_EDITOR_LIB_NICKNAME );
362 
363  if( libNickname.Length() && footprintName.Length() )
364  {
365  LIB_ID id;
366  id.SetLibNickname( libNickname );
367  id.SetLibItemName( footprintName );
368 
369  MODULE* module = loadFootprint( id );
370 
371  if( module )
372  AddModuleToBoard( module );
373  }
374 }
375 
376 
378 {
379  m_revertModule.reset( (MODULE*) aFootprint->Clone() );
380 
382 
383  // Pads are always editable in Footprint Editor
384  aFootprint->SetPadsLocked( false );
385 
387 
388  UpdateMsgPanel();
389 }
390 
391 
393 {
395 }
396 
397 
399 {
400  return GetBoard()->GetDesignSettings();
401 }
402 
403 
405 {
406  wxFAIL_MSG( "Plotting not supported in Footprint Editor" );
407 
409 }
410 
411 
413 {
414  wxFAIL_MSG( "Plotting not supported in Footprint Editor" );
415 }
416 
417 
419 {
420  if( !m_settings )
421  m_settings = Pgm().GetSettingsManager().GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>();
422 
423  return m_settings;
424 }
425 
426 
428 {
429  // aCfg will be the PCBNEW_SETTINGS
431 
433 
435 
438 }
439 
440 
442 {
443  // aCfg will be the PCBNEW_SETTINGS
444  auto cfg = GetSettings();
445 
447 
448  cfg->m_DesignSettings = GetDesignSettings();
449  cfg->m_Display = m_DisplayOptions;
450  cfg->m_LibWidth = m_treePane->GetSize().x;
451 }
452 
453 
455 {
456  return Pgm().GetSettingsManager().GetColorSettings(
457  GetFootprintEditorSettings()->m_ColorTheme );
458 }
459 
460 
462 {
463  // Get the actual frame settings for magnetic items
465  wxCHECK( cfg, nullptr );
466  return &cfg->m_MagneticItems;
467 }
468 
469 
471 {
472  MODULE* module = GetBoard()->GetFirstModule();
473 
474  if( module )
475  {
476  bool hasGraphicalItem = module->Pads().size() || module->Zones().size();
477 
478  if( !hasGraphicalItem )
479  {
480  for( const BOARD_ITEM* item : module->GraphicalItems() )
481  {
482  if( item->Type() == PCB_MODULE_TEXT_T )
483  continue;
484 
485  hasGraphicalItem = true;
486  break;
487  }
488  }
489 
490  if( hasGraphicalItem )
491  {
492  return module->GetFootprintRect();
493  }
494  else
495  {
496  BOX2I newModuleBB( { 0, 0 }, { 0, 0 } );
497  newModuleBB.Inflate( Millimeter2iu( 12 ) );
498  return newModuleBB;
499  }
500  }
501 
502  return GetBoardBoundingBox( false );
503 }
504 
505 
506 void FOOTPRINT_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent )
507 {
508  if( IsContentModified() )
509  {
510  // Shutdown blocks must be determined and vetoed as early as possible
511  if( SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION )
512  {
513  aEvent.Veto();
514  return;
515  }
516 
517  wxString footprintName = GetBoard()->GetFirstModule()->GetFPID().GetLibItemName();
518  wxString msg = _( "Save changes to \"%s\" before closing?" );
519 
520  if( !HandleUnsavedChanges( this, wxString::Format( msg, footprintName ),
521  [&]() -> bool { return SaveFootprint( GetBoard()->GetFirstModule() ); } ) )
522  {
523  aEvent.Veto();
524  return;
525  }
526  }
527 
529  GetCanvas()->StopDrawing();
530 
531  // Do not show the layer manager during closing to avoid flicker
532  // on some platforms (Windows) that generate useless redraw of items in
533  // the Layer Manger
534  m_auimgr.GetPane( "LayersManager" ).Show( false );
535 
536  Pgm().GetSettingsManager().FlushAndRelease( GetSettings() );
537 
538  Clear_Pcb( false );
539 
540  // Close the editor
541  aEvent.Skip();
542 }
543 
544 
545 void FOOTPRINT_EDIT_FRAME::OnExitKiCad( wxCommandEvent& event )
546 {
547  Kiway().OnKiCadExit();
548 }
549 
550 
551 void FOOTPRINT_EDIT_FRAME::CloseModuleEditor( wxCommandEvent& Event )
552 {
553  Close();
554 }
555 
556 
557 void FOOTPRINT_EDIT_FRAME::OnUpdateModuleSelected( wxUpdateUIEvent& aEvent )
558 {
559  aEvent.Enable( GetBoard()->GetFirstModule() != NULL );
560 }
561 
562 
564 {
566 
567  aEvent.Enable( frame && frame->GetBoard()->GetFirstModule() != NULL );
568 }
569 
570 
572 {
574 
575  MODULE* module_in_edit = GetBoard()->GetFirstModule();
576  bool canInsert = frame && module_in_edit && module_in_edit->GetLink() == niluuid;
577 
578  // If the source was deleted, the module can inserted but not updated in the board.
579  if( frame && module_in_edit && module_in_edit->GetLink() != niluuid ) // this is not a new module
580  {
581  BOARD* mainpcb = frame->GetBoard();
582  canInsert = true;
583 
584  // search if the source module was not deleted:
585  for( auto source_module : mainpcb->Modules() )
586  {
587  if( module_in_edit->GetLink() == source_module->m_Uuid )
588  {
589  canInsert = false;
590  break;
591  }
592  }
593  }
594 
595  aEvent.Enable( canInsert );
596 }
597 
598 
600 {
601 
602  m_Layers->Freeze();
603  m_Layers->ReFill();
604  m_Layers->Thaw();
605 
606  wxAuiPaneInfo& lyrs = m_auimgr.GetPane( m_Layers );
607 
608  wxSize bestz = m_Layers->GetBestSize();
609 
610  lyrs.MinSize( bestz );
611  lyrs.BestSize( bestz );
612  lyrs.FloatingSize( bestz );
613 
614  if( lyrs.IsDocked() )
615  m_auimgr.Update();
616  else
617  m_Layers->SetSize( bestz );
618 }
619 
620 
622 {
623  // call my base class
625 
626  // We have 2 panes to update.
627  // For some obscure reason, the AUI manager hides the first modified pane.
628  // So force show panes
629  wxAuiPaneInfo& tree_pane_info = m_auimgr.GetPane( m_treePane );
630  bool tree_shown = tree_pane_info.IsShown();
631  tree_pane_info.Caption( _( "Libraries" ) );
632 
633  wxAuiPaneInfo& lm_pane_info = m_auimgr.GetPane( m_Layers );
634  bool lm_shown = lm_pane_info.IsShown();
635  lm_pane_info.Caption( _( "Layers Manager" ) );
636 
637  // update the layer manager
640 
641  // Now restore the visibility:
642  lm_pane_info.Show( lm_shown );
643  tree_pane_info.Show( tree_shown );
644  m_auimgr.Update();
645 }
646 
647 
649 {
651  Update3DView( false );
653 }
654 
655 
657 {
658  wxString title = _( "Footprint Editor" );
659  LIB_ID fpid = GetLoadedFPID();
660  bool writable = true;
661 
662  if( IsCurrentFPFromBoard() )
663  {
664  title += wxString::Format( wxT( " \u2014 %s [from %s.%s]" ),
665  GetBoard()->GetFirstModule()->GetReference(), Prj().GetProjectName(),
667  }
668  else if( fpid.IsValid() )
669  {
670  try
671  {
672  writable = Prj().PcbFootprintLibs()->IsFootprintLibWritable( fpid.GetLibNickname() );
673  }
674  catch( const IO_ERROR& )
675  {
676  // best efforts...
677  }
678 
679  // Note: don't used GetLoadedFPID(); footprint name may have been edited
680  title += wxString::Format( wxT( " \u2014 %s %s" ),
681  FROM_UTF8( GetBoard()->GetFirstModule()->GetFPID().Format().c_str() ),
682  writable ? wxString( wxEmptyString ) : _( "[Read Only]" ) );
683  }
684  else if( !fpid.GetLibItemName().empty() )
685  {
686  // Note: don't used GetLoadedFPID(); footprint name may have been edited
687  title += wxString::Format( wxT( " \u2014 %s %s" ),
688  FROM_UTF8( GetBoard()->GetFirstModule()->GetFPID().GetLibItemName().c_str() ),
689  _( "[Unsaved]" ) );
690  }
691 
692  SetTitle( title );
693 }
694 
695 
697 {
698  // Update the layer manager and other widgets from the board setup
699  // (layer and items visibility, colors ...)
700 
701  // Update the layer manager
702  m_Layers->Freeze();
705 
706  // update the layer widget to match board visibility states.
711 
712  m_Layers->Thaw();
713 }
714 
715 
717 {
718  GetCanvas()->UpdateColors();
722  updateTitle();
723 }
724 
725 
727 {
728  FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
729 
730  WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 );
731  GFootprintList.ReadFootprintFiles( fpTable, NULL, &progressReporter );
732  progressReporter.Show( false );
733 
736 
738  auto adapter = static_cast<FP_TREE_SYNCHRONIZING_ADAPTER*>( m_adapter.get() );
739 
740  adapter->AddLibraries();
741 }
742 
743 
745 {
746  FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
747  auto adapter = static_cast<FP_TREE_SYNCHRONIZING_ADAPTER*>( m_adapter.get() );
748  LIB_ID target = GetTargetFPID();
749  bool targetSelected = ( target == m_treePane->GetLibTree()->GetSelectedLibId() );
750 
751  // Sync FOOTPRINT_INFO list to the libraries on disk
752  if( aProgress )
753  {
754  WX_PROGRESS_REPORTER progressReporter( this, _( "Updating Footprint Libraries" ), 2 );
755  GFootprintList.ReadFootprintFiles( fpTable, NULL, &progressReporter );
756  progressReporter.Show( false );
757  }
758  else
759  {
761  }
762 
763  // Sync the LIB_TREE to the FOOTPRINT_INFO list
764  adapter->Sync();
765 
767  m_treePane->GetLibTree()->Regenerate( true );
768 
769  if( target.IsValid() )
770  {
771  if( adapter->FindItem( target ) )
772  {
773  if( targetSelected )
774  m_treePane->GetLibTree()->SelectLibId( target );
775  else
776  m_treePane->GetLibTree()->CenterLibId( target );
777  }
778  else
779  {
780  // Try to focus on parent
781  target.SetLibItemName( wxEmptyString );
782  m_treePane->GetLibTree()->CenterLibId( target );
783  }
784  }
785 }
786 
787 
789 {
790  LIB_ID target = GetTargetFPID();
791 
792  m_treePane->GetLibTree()->Regenerate( true );
793 
794  if( target.IsValid() )
795  m_treePane->GetLibTree()->CenterLibId( target );
796 }
797 
798 
800 {
801  m_treePane->GetLibTree()->SelectLibId( aLibID );
802 }
803 
804 
806 {
807  return GetBoard()->IsElementVisible( aElement );
808 }
809 
810 
812 {
813  GetCanvas()->GetView()->SetLayerVisible( aElement , aNewState );
814  GetBoard()->SetElementVisibility( aElement, aNewState );
815  m_Layers->SetRenderState( aElement, aNewState );
816 }
817 
818 
820 {
822 }
823 
824 
826  PANEL_HOTKEYS_EDITOR* aHotkeysPanel )
827 {
828  wxTreebook* book = aParent->GetTreebook();
829 
830  book->AddPage( new wxPanel( book ), _( "Footprint Editor" ) );
831  book->AddSubPage( new PANEL_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) );
832  book->AddSubPage( new PANEL_MODEDIT_COLOR_SETTINGS( this, book ), _( "Colors" ) );
833  book->AddSubPage( new PANEL_EDIT_OPTIONS( this, aParent ), _( "Editing Options" ) );
834  book->AddSubPage( new PANEL_MODEDIT_DEFAULTS( this, aParent ), _( "Default Values" ) );
835 
836  aHotkeysPanel->AddHotKeys( GetToolManager() );
837 }
838 
839 
841 {
842  // Create the manager and dispatcher & route draw panel events to the dispatcher
845  GetCanvas()->GetViewControls(), config(), this );
846  m_actions = new PCB_ACTIONS();
848 
850 
859  m_toolManager->RegisterTool( new PCBNEW_CONTROL ); // copy/paste
865 
866  m_toolManager->GetTool<SELECTION_TOOL>()->SetEditModules( true );
867  m_toolManager->GetTool<EDIT_TOOL>()->SetEditModules( true );
868  m_toolManager->GetTool<PAD_TOOL>()->SetEditModules( true );
869  m_toolManager->GetTool<DRAWING_TOOL>()->SetEditModules( true );
870  m_toolManager->GetTool<POINT_EDITOR>()->SetEditModules( true );
871  m_toolManager->GetTool<PCBNEW_CONTROL>()->SetEditModules( true );
872  m_toolManager->GetTool<PCBNEW_PICKER_TOOL>()->SetEditModules( true );
873  m_toolManager->GetTool<POSITION_RELATIVE_TOOL>()->SetEditModules( true );
874 
875  m_toolManager->GetTool<PCB_VIEWER_TOOLS>()->SetFootprintFrame( true );
877 
878  m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
879 }
880 
881 
883 {
885 
886  // Be sure the axis are enabled
887  GetCanvas()->GetGAL()->SetAxesEnabled( true );
888 
889  updateView();
890 
891  // Ensure the m_Layers settings are using the canvas type:
893 }
894 
895 
897 {
899 
900  if( aEnvVarsChanged )
901  SyncLibraryTree( true );
902 
903  Layout();
904  SendSizeEvent();
905 }
906 
907 
908 void FOOTPRINT_EDIT_FRAME::OnSaveFootprintAsPng( wxCommandEvent& event )
909 {
910  wxString fullFileName;
911 
912  LIB_ID id = GetLoadedFPID();
913 
914  if( id.empty() )
915  {
916  wxMessageBox( _( "No footprint selected." ) );
917  return;
918  }
919 
920  wxFileName fn( id.GetLibItemName() );
921  fn.SetExt( "png" );
922 
923  wxString projectPath = wxPathOnly( Prj().GetProjectFullName() );
924 
925  wxFileDialog dlg( this, _( "Footprint Image File Name" ), projectPath,
926  fn.GetFullName(), PngFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
927 
928  if( dlg.ShowModal() == wxID_CANCEL || dlg.GetPath().IsEmpty() )
929  return;
930 
931  // calling wxYield is mandatory under Linux, after closing the file selector dialog
932  // to refresh the screen before creating the PNG or JPEG image from screen
933  wxYield();
934  SaveCanvasImageToFile( this, dlg.GetPath() );
935 }
936 
937 
void ShutdownAllTools()
Shutdown all tools with a currently registered event loop in this tool manager by waking them up with...
POSITION_RELATIVE_TOOL.
int m_SolderMaskMargin
Solder mask margin.
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
Definition: confirm.cpp:201
wxSize GetBestSize() const
Function GetBestSize returns the preferred minimum size, taking into consideration the dynamic conten...
bool IsFootprintLibWritable(const wxString &aNickname)
Function IsFootprintLibWritable.
show a marker on pads with no nets
virtual void ShowChangedLanguage() override
Redraw the menus and what not in current language.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
void OnKiCadExit()
Definition: kiway.cpp:523
EVT_UPDATE_UI(ID_MODEDIT_LOAD_MODULE_FROM_BOARD, FOOTPRINT_EDIT_FRAME::OnUpdateLoadModuleFromBoard) EVT_UPDATE_UI(ID_ADD_FOOTPRINT_TO_BOARD
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_holder.h:56
void ForceRefresh()
Function ForceRefresh() Forces a redraw.
void OnExitKiCad(wxCommandEvent &aEvent)
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
void SetElementVisibility(GAL_LAYER_ID aLayer, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:114
void ActivateGalCanvas() override
FOOTPRINT_EDITOR_TOOLS.
void OnUpdateLayerAlpha(wxUpdateUIEvent &aEvent) override
BOARD_DESIGN_SETTINGS & GetDesignSettings() const override
Returns the BOARD_DESIGN_SETTINGS for the open project Overloaded in FOOTPRINT_EDIT_FRAME.
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
const BOX2I GetDocumentExtents() const override
virtual void AddModuleToBoard(MODULE *module)
Adds the given module to the board.
bool SaveCanvasImageToFile(EDA_DRAW_FRAME *aFrame, const wxString &aFileName, wxBitmapType aBitmapType)
Save the current view as an image file.
Definition: bitmap.cpp:177
Model changes (required full reload)
Definition: tool_base.h:82
This file is part of the common library.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void CommonSettingsChanged(bool aEnvVarsChanged) override
Called after the preferences dialog is run.
PCB_LAYER_WIDGET is here to implement the abstract functions of LAYER_WIDGET so they may be tied into...
FOOTPRINT_EDITOR_SETTINGS * GetFootprintEditorSettings()
SELECTION_TOOL.
void initLibraryTree()
Make sure the footprint info list is loaded (with a progress dialog) and then initialize the footprin...
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void CommonSettingsChanged(bool aEnvVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
void DisplayErrors(wxTopLevelWindow *aCaller=NULL)
PADS & Pads()
Definition: class_module.h:169
void OnCloseWindow(wxCloseEvent &Event) override
PAD_TOOL.
Definition: pad_tool.h:37
static TOOL_ACTION zoomFitScreen
Definition: actions.h:93
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
void SetCopperLayerCount(int aCount)
void ActivateGalCanvas() override
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:140
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:551
EDA_RECT GetFootprintRect() const
Function GetFootprintRect() Returns the area of the module footprint excluding any text.
void UpdateUserInterface()
Update the layer manager and other widgets from the board setup (layer and items visibility,...
void AddHotKeys(TOOL_MANAGER *aToolMgr)
void SetVisibleAlls()
Function SetVisibleAlls changes the bit-mask of visible element categories and layers.
bool OnLayerSelected()
Function OnLayerSelected ensure the active layer is visible, and other layers not visible when m_alwa...
const LIB_ID & GetFPID() const
Definition: class_module.h:215
wxAuiManager m_auimgr
DRAWINGS & GraphicalItems()
Definition: class_module.h:179
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void OnUpdateLoadModuleFromBoard(wxUpdateUIEvent &aEvent)
bool IsValid() const
Definition: lib_id.h:171
virtual const PCB_PLOT_PARAMS & GetPlotSettings() const
Function GetPlotSettings returns the PCB_PLOT_PARAMS for the BOARD owned by this frame.
not specified: a GAL engine must be set by the client
bool InvokeTool(TOOL_ID aToolId)
Function InvokeTool() Calls a tool by sending a tool activation event to tool of given ID.
void SetLayersManagerTabsText()
Function SetLayersManagerTabsText Update the layer manager tabs labels Useful when changing Language ...
PCBNEW_CONTROL.
bool IsContentModified() override
Get if any footprints or libraries have been modified but not saved.
wxTreebook * GetTreebook()
Definition: paged_dialog.h:45
virtual PCB_LAYER_ID GetActiveLayer() const
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
TOOL_MANAGER.
Definition: tool_manager.h:51
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
void SyncLibraryTree(bool aProgress)
Synchronize the footprint library tree to the current state of the footprint library table.
void RegenerateLibraryTree()
Filter, sort, and redisplay the library tree.
std::unique_ptr< MODULE > m_revertModule
bool Clear_Pcb(bool aQuery)
Delete all and reinitialize the current board.
Definition: initpcb.cpp:94
Generic tool for picking a point.
void HardRedraw() override
Refresh the library tree and redraw the window.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:91
#define NULL
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:342
LIB_TREE_NODE * GetCurrentTreeNode() const
Definition: lib_tree.cpp:166
MODULES & Modules()
Definition: class_board.h:266
void OnModify() override
Must be called after a footprint change in order to set the "modify" flag of the current screen and p...
void DisplayBoard(BOARD *aBoard)
Function DisplayBoard adds all items from the current board to the VIEW, so they can be displayed by ...
DRAWING_TOOL.
Definition: drawing_tool.h:50
void SetClearance(int aClearance)
Definition: netclass.h:166
void FocusOnLibID(const LIB_ID &aLibID)
void SetVisibleLayers(LSET aLayerMask)
Function SetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
PAGE_INFO describes the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:54
LIB_ID GetTargetFPID() const
Return the LIB_ID of the part selected in the footprint tree, or the loaded part if there is no selec...
KIID niluuid(0)
void SetElementVisibility(GAL_LAYER_ID aElement, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
For multi-unit components, if the user selects the component itself rather than picking an individual...
Definition: lib_tree.cpp:148
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Function SetLayerName changes the name of the layer given by aLayer.
void ReFillRender()
Function ReFillRender rebuilds Render for instance after the config is read.
PCB_LAYER_WIDGET * m_Layers
Layer manager. It is the responsibility of the child frames to instantiate this.
ACTIONS * m_actions
Definition: tools_holder.h:49
MODULE * GetFirstModule() const
Gets the first module in the list (used in footprint viewer/editor) or NULL if none.
Definition: class_board.h:330
void Regenerate(bool aKeepState)
Regenerates the tree.
Definition: lib_tree.cpp:200
Definition of file extensions used in Kicad.
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition: lib_tree.cpp:189
FOOTPRINT_EDITOR_SETTINGS * m_settings
#define FOOTPRINT_EDIT_FRAME_NAME
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Function ResetTools() Resets all tools (i.e.
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
EDA_RECT GetBoardBoundingBox(bool aBoardEdgesOnly=false) const
Function GetBoardBoundingBox calculates the bounding box containing all board items (or board edge se...
static const wxChar A4[]
Definition: page_info.h:64
virtual void OnSize(wxSizeEvent &event)
Recalculate the size of toolbars and display panel when the frame size changes.
void SetLayerVisible(int aLayer, bool aVisible=true)
Function SetLayerVisible() Controls the visibility of a particular layer.
Definition: view.h:399
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves common frame parameters to a configuration data file.
#define KICAD_DEFAULT_DRAWFRAME_STYLE
void SetPadsLocked(bool aPadsLocked)
Definition: class_module.h:335
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
bool IsModify() const
Definition: base_screen.h:187
#define PcbFileExtension
Footprint Editor pane with footprint library tree.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
void SyncLayersVisibility(const BOARD *aBoard)
Function SyncLayersVisibility Updates "visibility" property of each layer of a given BOARD.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
PCB_PLOT_PARAMS handles plot parameters and options when plotting/printing a board.
COMMON_CONTROL.
void RefreshLibTree()
Refreshes the tree (mainly to update highlighting and asterisking)
Definition: lib_tree.cpp:218
void SetAxesEnabled(bool aAxesEnabled)
Enables drawing the axes.
LIB_TREE * GetLibTree() const
EDIT_TOOL.
Definition: edit_tool.h:67
virtual KIGFX::PCB_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
Specialization of the wxAuiPaneInfo class for KiCad panels.
LIB_TREE_NODE * GetCurrentTreeNode() const
const MODULE_ZONE_CONTAINERS & Zones() const
Definition: class_module.h:184
const PCB_PLOT_PARAMS & GetPlotSettings() const override
Function GetPlotSettings returns the PCB_PLOT_PARAMS for the BOARD owned by this frame.
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:50
void SyncLayerAlphaIndicators()
Function SyncLayerAlphaIndicators updates each "Layer"s alpha indicator to show if the board is curre...
COMMON_TOOLS.
Definition: common_tools.h:38
void UpdateColors()
Updates the color settings in the painter and GAL.
TOOL_DISPATCHER.
void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType) override
switches currently used canvas (Cairo / OpenGL).
wxString PngFileWildcard()
PCB_DISPLAY_OPTIONS m_DisplayOptions
const BITMAP_OPAQUE icon_modedit_xpm[1]
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves common frame parameters to a configuration data file.
VTBL_ENTRY void SetRString(RSTRING_T aStringId, const wxString &aString)
Function SetRString stores a "retained string", which is any session and project specific string iden...
Definition: project.cpp:206
BOARD * GetBoard()
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:284
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:193
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Function IsElementVisible tests whether a given element category is visible.
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
bool SupportsShutdownBlockReason()
Whether or not the window supports setting a shutdown block reason.
void InstallPreferences(PAGED_DIALOG *aParent, PANEL_HOTKEYS_EDITOR *aHotkeysPanel) override
Allows Modedit to install its preferences panel into the preferences dialog.
void Process_Special_Functions(wxCommandEvent &event)
void updateTitle()
Updates window title according to getLibNickName().
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:68
virtual void OnModify()
Function OnModify Must be called after a change in order to set the "modify" flag of the current scre...
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:301
VTBL_ENTRY const wxString & GetRString(RSTRING_T aStringId)
Function GetRString returns a "retained string", which is any session and project specific string ide...
Definition: project.cpp:221
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
PCB_ACTIONS.
Definition: pcb_actions.h:51
void SyncLayerVisibilities()
Function SyncLayerVisibilities updates each "Layer" checkbox in this layer widget according to each l...
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:48
see class PGM_BASE
void SetPlotSettings(const PCB_PLOT_PARAMS &aSettings) override
void LoadModuleFromBoard(wxCommandEvent &event)
Called from the main toolbar to load a footprint from board mainly to edit it.
void OnSelectGrid(wxCommandEvent &event)
Command event handler for selecting grid sizes.
Declaration of the eda_3d_viewer class.
Common, abstract interface for edit frames.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
virtual void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Changes the current rendering backend.
LIB_ID GetLoadedFPID() const
Return the LIB_ID of the part being edited.
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Sets the work environment (model, view, view controls and the parent window).
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Function SetEventDispatcher() Sets a dispatcher that processes events and forwards them to tools.
#define _(s)
Definition: 3d_actions.cpp:33
COLOR_SETTINGS * GetColorSettings() override
Helper to retrieve the current color settings.
void OnUpdateInsertModuleInBoard(wxUpdateUIEvent &aEvent)
BOARD_ITEM_CONTAINER * GetModel() const override
void updateView()
Reloads displayed items and sets view.
bool SaveFootprint(MODULE *aModule)
Save in an existing library a given footprint.
NETCLASS * GetDefault() const
Function GetDefault.
PCB_EDIT_FRAME is the main frame for Pcbnew.
FOOTPRINT_TREE_PANE * m_treePane
POINT_EDITOR.
Definition: point_editor.h:43
static bool empty(const wxTextEntryBase *aCtrl)
unsigned GetErrorCount() const
MAGNETIC_SETTINGS * GetMagneticItemsSettings() override
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
KIID GetLink() const
Definition: class_module.h:546
PCB_VIEWER_TOOLS.
bool ReadFootprintFiles(FP_LIB_TABLE *aTable, const wxString *aNickname=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr) override
Read all the footprints provided by the combination of aTable and aNickname.
void ShowChangedLanguage() override
Update visible items after a language change.
Color settings are a bit different than most of the settings objects in that there can be more than o...
FOOTPRINT_EDITOR_SETTINGS * GetSettings()
static PTR Create(FOOTPRINT_EDIT_FRAME *aFrame, FP_LIB_TABLE *aLibs)
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:74
void OnGridSettings(wxCommandEvent &event)
void AddModuleToBoard(MODULE *module) override
Override from PCB_BASE_EDIT_FRAME which adds a module to the editor's dummy board,...
void CloseModuleEditor(wxCommandEvent &Event)
void InitTools()
Function InitTools() Initializes all registered tools.
Abstract interface for BOARD_ITEMs capable of storing other items inside.
BOARD * GetBoard() const
void OnUpdateModuleSelected(wxUpdateUIEvent &aEvent)
BOARD_DESIGN_SETTINGS m_DesignSettings
Only some of these settings are actually used for footprint editing.
virtual void Update3DView(bool aForceReload, const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
void SetRenderState(int aId, bool isSet)
Function SetRenderState sets the state of the checkbox associated with aId within the Render tab grou...
void SelectLayer(LAYER_NUM aLayer)
Function SelectLayer changes the row selection in the layer list to aLayer provided.
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
void OnUpdateLayerSelectBox(wxUpdateUIEvent &aEvent)
MODULE * loadFootprint(const LIB_ID &aFootprintId)
Function loadFootprint attempts to load aFootprintId from the footprint library table.
void SetEnabledLayers(LSET aLayerMask)
Function SetEnabledLayers is a proxy function that calls the correspondent function in m_BoardSetting...
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
void StopDrawing()
Function StopDrawing() Prevents the GAL canvas from further drawing till it is recreated or StartDraw...
LIB_ID GetTreeFPID() const
Return the LIB_ID of the part or library selected in the footprint tree.
static const wxChar * GetFootprintEditorFrameName()
Function GetFootprintEditorFrameName (static)
virtual void OnSelectZoom(wxCommandEvent &event)
Set the zoom factor when selected by the zoom list box in the main tool bar.
void RegisterTool(TOOL_BASE *aTool)
Function RegisterTool() Adds a tool to the manager set and sets it up.
void CenterLibId(const LIB_ID &aLibId)
Ensure that an item is visible (preferrably centered).
Definition: lib_tree.cpp:183
void OnSaveFootprintAsPng(wxCommandEvent &event)
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition: lib_tree.cpp:177
bool empty() const
Definition: utf8.h:108
virtual void UpdateMsgPanel()
Redraw the message panel.
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
bool IsElementVisible(GAL_LAYER_ID aElement) const
Test whether a given element category is visible.