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>
41 #include <fctsys.h>
42 #include <footprint_edit_frame.h>
44 #include <footprint_info_impl.h>
45 #include <footprint_tree_pane.h>
46 #include <footprint_viewer_frame.h>
47 #include <fp_lib_table.h>
48 #include <kicad_plugin.h>
49 #include <kiface_i.h>
50 #include <kiway.h>
51 #include <panel_hotkeys_editor.h>
52 #include <pcb_draw_panel_gal.h>
53 #include <pcb_edit_frame.h>
54 #include <pcb_layer_widget.h>
55 #include <pcbnew.h>
56 #include <pcbnew_id.h>
57 #include <pgm_base.h>
58 #include <project.h>
60 #include <tool/action_toolbar.h>
61 #include <tool/common_control.h>
62 #include <tool/common_tools.h>
63 #include <tool/tool_dispatcher.h>
64 #include <tool/tool_manager.h>
65 #include <tool/zoom_tool.h>
67 #include <widgets/lib_tree.h>
68 #include <widgets/paged_dialog.h>
71 
72 
73 BEGIN_EVENT_TABLE( FOOTPRINT_EDIT_FRAME, PCB_BASE_FRAME )
75  EVT_MENU( wxID_CLOSE, FOOTPRINT_EDIT_FRAME::CloseModuleEditor )
76  EVT_MENU( wxID_EXIT, FOOTPRINT_EDIT_FRAME::OnExitKiCad )
77 
79 
82 
84 
88 
89  // Horizontal toolbar
92 
93  // UI update events.
100 
101 END_EVENT_TABLE()
102 
103 
104 FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent,
105  EDA_DRAW_PANEL_GAL::GAL_TYPE aBackend ) :
106  PCB_BASE_EDIT_FRAME( aKiway, aParent, FRAME_FOOTPRINT_EDITOR, wxEmptyString,
107  wxDefaultPosition, wxDefaultSize,
108  KICAD_DEFAULT_DRAWFRAME_STYLE, GetFootprintEditorFrameName() )
109 {
110  m_showBorderAndTitleBlock = false; // true to show the frame references
111  m_FrameSize = ConvertDialogToPixels( wxSize( 500, 350 ) ); // default in case of no prefs
112  m_canvasType = aBackend;
113  m_AboutTitle = "ModEdit";
114  m_selLayerBox = nullptr;
115  m_settings = nullptr;
116 
117  // Give an icon
118  wxIcon icon;
119  icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) );
120  SetIcon( icon );
121 
122  // Create GAL canvas
123  if( aBackend == EDA_DRAW_PANEL_GAL::GAL_TYPE_UNKNOWN )
124  m_canvasType = LoadCanvasTypeSetting();
125  else
126  m_canvasType = aBackend;
127 
128  PCB_DRAW_PANEL_GAL* drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize,
129  GetGalDisplayOptions(), m_canvasType );
130  SetCanvas( drawPanel );
131 
132  SetBoard( new BOARD() );
133 
134  // Enable one internal layer, because footprints support keepout areas that
135  // can be on internal layers only (therefore on the first internal layer)
136  // This is needed to handle these keepout in internal layers only
137  GetBoard()->SetEnabledLayers( GetBoard()->GetEnabledLayers().set( In1_Cu ) );
138  GetBoard()->SetVisibleLayers( GetBoard()->GetEnabledLayers() );
139  GetBoard()->SetLayerName( In1_Cu, _( "Inner layers" ) );
140 
141  // In modedit, the default net clearance is not known.
142  // (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
145  GetBoard()->GetDesignSettings().GetDefault()->SetClearance( 0 );
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
156  // cannot be used, but we show all of them, at least to be able
157  // to edit a bad layer
159 
160  // However the "no net" mark on pads is useless, because there is
161  // no net in footprint editor: make it non visible
163 
164  m_Layers = new PCB_LAYER_WIDGET( this, GetCanvas(), true );
165 
166  // LoadSettings() *after* creating m_LayersManager, because LoadSettings()
167  // initialize parameters in m_LayersManager
168  // NOTE: KifaceSettings() will return PCBNEW_SETTINGS if we started from pcbnew
169  LoadSettings( GetSettings() );
170  GetGalDisplayOptions().m_axesEnabled = true;
171 
172  SetScreen( new PCB_SCREEN( GetPageSettings().GetSizeIU() ) );
173  GetScreen()->SetMaxUndoItems( m_UndoRedoCountMax );
174 
175  GetScreen()->AddGrid( m_UserGridSize, EDA_UNITS::UNSCALED, ID_POPUP_GRID_USER );
176  GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
177 
178  // In modedit, set the default paper size to A4:
179  // this should be OK for all footprint to plot/print
180  SetPageSettings( PAGE_INFO( PAGE_INFO::A4 ) );
181 
182  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
183 
184  // Create the manager and dispatcher & route draw panel events to the dispatcher
185  setupTools();
186 
187  initLibraryTree();
188  m_treePane = new FOOTPRINT_TREE_PANE( this );
189 
190  ReCreateMenuBar();
191  ReCreateHToolbar();
192  ReCreateVToolbar();
193  ReCreateOptToolbar();
194 
195  m_Layers->ReFill();
196  m_Layers->ReFillRender();
197 
198  GetScreen()->m_Active_Layer = F_SilkS;
199  m_Layers->SelectLayer( F_SilkS );
200  m_Layers->OnLayerSelected();
201 
202  m_auimgr.SetManagedWindow( this );
203 
204  // Horizontal items; layers 4 - 6
205  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
206  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
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(1)
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(1) );
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  GetCanvas()->GetView()->SetScale( GetZoomLevelCoeff() / GetScreen()->GetZoom() );
222  ActivateGalCanvas();
223 
224  m_auimgr.Update();
225  GetToolManager()->RunAction( ACTIONS::gridPreset, true, m_LastGridSizeId );
226  GetToolManager()->RunAction( ACTIONS::zoomFitScreen, false );
227  updateTitle();
228  InitExitKey();
229 
230  // Default shutdown reason until a file is loaded
231  SetShutdownBlockReason( _( "Footprint changes are unsaved" ) );
232 
233  Raise(); // On some window managers, this is needed
234  Show( true );
235 }
236 
237 
239 {
240  // Shutdown all running tools
241  if( m_toolManager )
243 
244  // save the footprint in the PROJECT
246 
247  delete m_Layers;
248 }
249 
250 
252 {
253  return GetScreen() && GetScreen()->IsModify() && GetBoard() && GetBoard()->GetFirstModule();
254 }
255 
256 
258 {
259  // switches currently used canvas (Cairo / OpenGL).
260  PCB_BASE_FRAME::SwitchCanvas( aCanvasType );
261 
262  GetCanvas()->GetGAL()->SetAxesEnabled( true );
263  GetCanvas()->GetGAL()->SetGridSize( VECTOR2D( GetScreen()->GetGridSize() ) );
264 
265  // The base class method *does not reinit* the layers manager. We must upate the layer
266  // widget to match board visibility states, both layers and render columns, and and some
267  // settings dependent on the canvas.
269 }
270 
271 
273 {
274  SyncLibraryTree( true );
275  GetCanvas()->ForceRefresh();
276 }
277 
278 
280 {
281  auto& treePane = m_auimgr.GetPane( m_treePane );
282  treePane.Show( !IsSearchTreeShown() );
283  m_auimgr.Update();
284 }
285 
286 
288 {
289  return m_auimgr.GetPane( m_treePane ).IsShown();
290 }
291 
292 
294 {
295  return GetBoard()->GetFirstModule();
296 }
297 
298 
300 {
302 }
303 
304 
306 {
308 }
309 
310 
312 {
313  LIB_ID id = GetTreeFPID();
314 
315  if( id.GetLibNickname().empty() )
316  return GetLoadedFPID();
317 
318  return id;
319 }
320 
321 
323 {
324  MODULE* module = GetBoard()->GetFirstModule();
325 
326  if( module )
328  else
329  return LIB_ID();
330 }
331 
332 
334 {
335  MODULE* module = GetBoard()->GetFirstModule();
336 
337  return ( module && module->GetLink() != niluuid );
338 }
339 
340 
342 {
343  LIB_ID id = GetLoadedFPID();
344 
345  if( id.IsValid() )
346  {
347  Prj().SetRString( PROJECT::PCB_FOOTPRINT_EDITOR_NICKNAME, id.GetLibNickname() );
348  Prj().SetRString( PROJECT::PCB_FOOTPRINT_EDITOR_FPNAME, id.GetLibItemName() );
349  }
350 }
351 
352 
354 {
355  const wxString& curFootprintName = Prj().GetRString( PROJECT::PCB_FOOTPRINT_EDITOR_FPNAME );
356  const wxString& curNickname = Prj().GetRString( PROJECT::PCB_FOOTPRINT_EDITOR_NICKNAME );
357 
358  if( curNickname.Length() && curFootprintName.Length() )
359  {
360  LIB_ID id;
361  id.SetLibNickname( curNickname );
362  id.SetLibItemName( curFootprintName );
363 
364  MODULE* module = loadFootprint( id );
365 
366  if( module )
367  AddModuleToBoard( module );
368  }
369 }
370 
371 
373 {
374  m_revertModule.reset( (MODULE*) aFootprint->Clone() );
375 
377 
378  // Pads are always editable in Footprint Editor
379  aFootprint->SetPadsLocked( false );
380 
382 
383  UpdateMsgPanel();
384 }
385 
386 
388 {
390 }
391 
392 
394 {
395  return GetBoard()->GetDesignSettings();
396 }
397 
398 
400 {
401  GetBoard()->SetDesignSettings( aSettings );
402 }
403 
404 
406 {
407  // get the settings from the parent editor, not our BOARD.
408  PCB_BASE_FRAME* parentFrame = (PCB_BASE_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, true );
409  wxASSERT( parentFrame );
410 
411  return parentFrame->GetPlotSettings();
412 }
413 
414 
416 {
417  // set the settings into parent editor, not our BOARD.
418  PCB_BASE_FRAME* parentFrame = (PCB_BASE_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, true );
419  wxASSERT( parentFrame );
420 
421  parentFrame->SetPlotSettings( aSettings );
422 }
423 
424 
426 {
427  if( !m_settings )
428  m_settings = Pgm().GetSettingsManager().GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>();
429 
430  return m_settings;
431 }
432 
433 
435 {
436  // aCfg will be the PCBNEW_SETTINGS
437  auto cfg = GetSettings();
438 
440 
441  // TODO(JE) remove once color themes exist
444  cs->Load();
445 
446  // Ensure some params are valid
448 
449  settings = cfg->m_DesignSettings;
450 
451  // Usually, graphic items are drawn on F_SilkS or F_Fab layer
452  // Force these layers if not default
453  if( ( settings.m_RefDefaultlayer != F_SilkS ) && ( settings.m_RefDefaultlayer != F_Fab ) )
454  settings.m_RefDefaultlayer = F_SilkS;
455 
456  if( ( settings.m_ValueDefaultlayer != F_SilkS ) && ( settings.m_ValueDefaultlayer != F_Fab ) )
457  settings.m_ValueDefaultlayer = F_Fab;
458 
459  m_DisplayOptions = cfg->m_Display;
460  m_defaultLibWidth = cfg->m_LibWidth;
461 }
462 
463 
465 {
466  // aCfg will be the PCBNEW_SETTINGS
467  auto cfg = GetSettings();
468 
470 
471  cfg->m_DesignSettings = GetDesignSettings();
472  cfg->m_Display = m_DisplayOptions;
473  cfg->m_LibWidth = m_treePane->GetSize().x;
474 
475  // TODO(JE) remove once color themes exist
476  // Ensure footprint editor color settings get flushed to disk before context is changed
479  Pgm().GetSettingsManager().SaveColorSettings( cs, "fpedit" );
480 }
481 
482 
484 {
485  MODULE* module = GetBoard()->GetFirstModule();
486 
487  if( module )
488  return module->GetFootprintRect();
489  else
490  return GetBoardBoundingBox( false );
491 }
492 
493 
494 void FOOTPRINT_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent )
495 {
496  if( IsContentModified() )
497  {
498  // Shutdown blocks must be determined and vetoed as early as possible
499  if( SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION )
500  {
501  aEvent.Veto();
502  return;
503  }
504 
505  wxString footprintName = GetBoard()->GetFirstModule()->GetFPID().GetLibItemName();
506  wxString msg = _( "Save changes to \"%s\" before closing?" );
507 
508  if( !HandleUnsavedChanges( this, wxString::Format( msg, footprintName ),
509  [&]() -> bool { return SaveFootprint( GetBoard()->GetFirstModule() ); } ) )
510  {
511  aEvent.Veto();
512  return;
513  }
514  }
515 
517  GetCanvas()->StopDrawing();
518 
519  // Do not show the layer manager during closing to avoid flicker
520  // on some platforms (Windows) that generate useless redraw of items in
521  // the Layer Manger
522  m_auimgr.GetPane( "LayersManager" ).Show( false );
523 
524  Clear_Pcb( false );
525 
526  // Close the editor
527  aEvent.Skip();
528 }
529 
530 
531 void FOOTPRINT_EDIT_FRAME::OnExitKiCad( wxCommandEvent& event )
532 {
533  Kiway().OnKiCadExit();
534 }
535 
536 
537 void FOOTPRINT_EDIT_FRAME::CloseModuleEditor( wxCommandEvent& Event )
538 {
539  Close();
540 }
541 
542 
543 void FOOTPRINT_EDIT_FRAME::OnUpdateModuleSelected( wxUpdateUIEvent& aEvent )
544 {
545  aEvent.Enable( GetBoard()->GetFirstModule() != NULL );
546 }
547 
548 
550 {
552 
553  aEvent.Enable( frame && frame->GetBoard()->GetFirstModule() != NULL );
554 }
555 
556 
558 {
560 
561  MODULE* module_in_edit = GetBoard()->GetFirstModule();
562  bool canInsert = frame && module_in_edit && module_in_edit->GetLink() == niluuid;
563 
564  // If the source was deleted, the module can inserted but not updated in the board.
565  if( frame && module_in_edit && module_in_edit->GetLink() != niluuid ) // this is not a new module
566  {
567  BOARD* mainpcb = frame->GetBoard();
568  canInsert = true;
569 
570  // search if the source module was not deleted:
571  for( auto source_module : mainpcb->Modules() )
572  {
573  if( module_in_edit->GetLink() == source_module->m_Uuid )
574  {
575  canInsert = false;
576  break;
577  }
578  }
579  }
580 
581  aEvent.Enable( canInsert );
582 }
583 
584 
586 {
587 
588  m_Layers->Freeze();
589  m_Layers->ReFill();
590  m_Layers->Thaw();
591 
592  wxAuiPaneInfo& lyrs = m_auimgr.GetPane( m_Layers );
593 
594  wxSize bestz = m_Layers->GetBestSize();
595 
596  lyrs.MinSize( bestz );
597  lyrs.BestSize( bestz );
598  lyrs.FloatingSize( bestz );
599 
600  if( lyrs.IsDocked() )
601  m_auimgr.Update();
602  else
603  m_Layers->SetSize( bestz );
604 }
605 
606 
608 {
609  // call my base class
611 
612  // We have 2 panes to update.
613  // For some obscure reason, the AUI manager hides the first modified pane.
614  // So force show panes
615  wxAuiPaneInfo& tree_pane_info = m_auimgr.GetPane( m_treePane );
616  bool tree_shown = tree_pane_info.IsShown();
617  tree_pane_info.Caption( _( "Libraries" ) );
618 
619  wxAuiPaneInfo& lm_pane_info = m_auimgr.GetPane( m_Layers );
620  bool lm_shown = lm_pane_info.IsShown();
621  lm_pane_info.Caption( _( "Layers Manager" ) );
622 
623  // update the layer manager
626 
627  // Now restore the visibility:
628  lm_pane_info.Show( lm_shown );
629  tree_pane_info.Show( tree_shown );
630  m_auimgr.Update();
631 }
632 
633 
635 {
637  Update3DView( false );
639 }
640 
641 
643 {
644  wxString title = _( "Footprint Editor" );
645  LIB_ID fpid = GetLoadedFPID();
646  bool writable = true;
647 
648  if( IsCurrentFPFromBoard() )
649  {
650  title += wxString::Format( wxT( " \u2014 %s [from %s.%s]" ),
651  GetBoard()->GetFirstModule()->GetReference(), Prj().GetProjectName(),
653  }
654  else if( fpid.IsValid() )
655  {
656  try
657  {
658  writable = Prj().PcbFootprintLibs()->IsFootprintLibWritable( fpid.GetLibNickname() );
659  }
660  catch( const IO_ERROR& )
661  {
662  // best efforts...
663  }
664 
665  // Note: don't used GetLoadedFPID(); footprint name may have been edited
666  title += wxString::Format( wxT( " \u2014 %s %s" ),
667  FROM_UTF8( GetBoard()->GetFirstModule()->GetFPID().Format().c_str() ),
668  writable ? wxString( wxEmptyString ) : _( "[Read Only]" ) );
669  }
670  else if( !fpid.GetLibItemName().empty() )
671  {
672  // Note: don't used GetLoadedFPID(); footprint name may have been edited
673  title += wxString::Format( wxT( " \u2014 %s %s" ),
674  FROM_UTF8( GetBoard()->GetFirstModule()->GetFPID().GetLibItemName().c_str() ),
675  _( "[Unsaved]" ) );
676  }
677 
678  SetTitle( title );
679 }
680 
681 
683 {
684  // Update the layer manager and other widgets from the board setup
685  // (layer and items visibility, colors ...)
686 
687  // Update the layer manager
688  m_Layers->Freeze();
691 
692  // update the layer widget to match board visibility states.
697 
698  m_Layers->Thaw();
699 }
700 
701 
703 {
704  GetCanvas()->UpdateColors();
708  updateTitle();
709 }
710 
711 
713 {
714  FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
715 
716  WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 );
717  GFootprintList.ReadFootprintFiles( fpTable, NULL, &progressReporter );
718  progressReporter.Show( false );
719 
722 
724  auto adapter = static_cast<FP_TREE_SYNCHRONIZING_ADAPTER*>( m_adapter.get() );
725 
726  adapter->AddLibraries();
727 }
728 
729 
731 {
732  FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
733  auto adapter = static_cast<FP_TREE_SYNCHRONIZING_ADAPTER*>( m_adapter.get() );
734  LIB_ID target = GetTargetFPID();
735  bool targetSelected = ( target == m_treePane->GetLibTree()->GetSelectedLibId() );
736 
737  // Sync FOOTPRINT_INFO list to the libraries on disk
738  if( aProgress )
739  {
740  WX_PROGRESS_REPORTER progressReporter( this, _( "Updating Footprint Libraries" ), 2 );
741  GFootprintList.ReadFootprintFiles( fpTable, NULL, &progressReporter );
742  progressReporter.Show( false );
743  }
744  else
745  {
747  }
748 
749  // Sync the LIB_TREE to the FOOTPRINT_INFO list
750  adapter->Sync();
751 
753  m_treePane->GetLibTree()->Regenerate( true );
754 
755  if( target.IsValid() )
756  {
757  if( adapter->FindItem( target ) )
758  {
759  if( targetSelected )
760  m_treePane->GetLibTree()->SelectLibId( target );
761  else
762  m_treePane->GetLibTree()->CenterLibId( target );
763  }
764  else
765  {
766  // Try to focus on parent
767  target.SetLibItemName( wxEmptyString );
768  m_treePane->GetLibTree()->CenterLibId( target );
769  }
770  }
771 }
772 
773 
775 {
776  LIB_ID target = GetTargetFPID();
777 
778  m_treePane->GetLibTree()->Regenerate( true );
779 
780  if( target.IsValid() )
781  m_treePane->GetLibTree()->CenterLibId( target );
782 }
783 
784 
786 {
787  m_treePane->GetLibTree()->SelectLibId( aLibID );
788 }
789 
790 
792 {
793  return GetBoard()->IsElementVisible( aElement );
794 }
795 
796 
798 {
799  GetCanvas()->GetView()->SetLayerVisible( aElement , aNewState );
800  GetBoard()->SetElementVisibility( aElement, aNewState );
801  m_Layers->SetRenderState( aElement, aNewState );
802 }
803 
804 
806 {
808 }
809 
810 
812  PANEL_HOTKEYS_EDITOR* aHotkeysPanel )
813 {
814  wxTreebook* book = aParent->GetTreebook();
815 
816  book->AddPage( new wxPanel( book ), _( "Footprint Editor" ) );
817  book->AddSubPage( new PANEL_MODEDIT_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) );
818  book->AddSubPage( new PANEL_MODEDIT_SETTINGS( this, aParent ), _( "Editing Options" ) );
819  book->AddSubPage( new PANEL_MODEDIT_DEFAULTS( this, aParent ), _( "Default Values" ) );
820 
821  aHotkeysPanel->AddHotKeys( GetToolManager() );
822 }
823 
824 
826 {
827  // Create the manager and dispatcher & route draw panel events to the dispatcher
830  GetCanvas()->GetViewControls(), this );
831  m_actions = new PCB_ACTIONS();
833 
835 
849 
850  m_toolManager->GetTool<SELECTION_TOOL>()->SetEditModules( true );
851  m_toolManager->GetTool<EDIT_TOOL>()->SetEditModules( true );
852  m_toolManager->GetTool<PAD_TOOL>()->SetEditModules( true );
853  m_toolManager->GetTool<DRAWING_TOOL>()->SetEditModules( true );
854  m_toolManager->GetTool<POINT_EDITOR>()->SetEditModules( true );
855  m_toolManager->GetTool<PCBNEW_CONTROL>()->SetEditModules( true );
856  m_toolManager->GetTool<PCBNEW_PICKER_TOOL>()->SetEditModules( true );
857  m_toolManager->GetTool<POSITION_RELATIVE_TOOL>()->SetEditModules( true );
858 
860 
861  m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
862 }
863 
864 
866 {
868 
869  // Be sure the axis are enabled
870  GetCanvas()->GetGAL()->SetAxesEnabled( true );
871 
872  updateView();
873 
874  // Ensure the m_Layers settings are using the canvas type:
876 }
877 
878 
880 {
882 
883  if( aEnvVarsChanged )
884  SyncLibraryTree( true );
885 
886  Layout();
887  SendSizeEvent();
888 }
889 
890 
891 void FOOTPRINT_EDIT_FRAME::OnSaveFootprintAsPng( wxCommandEvent& event )
892 {
893  wxString fullFileName;
894 
895  LIB_ID id = GetLoadedFPID();
896 
897  if( id.empty() )
898  {
899  wxMessageBox( _( "No footprint selected." ) );
900  return;
901  }
902 
903  wxFileName fn( id.GetLibItemName() );
904  fn.SetExt( "png" );
905 
906  wxString projectPath = wxPathOnly( Prj().GetProjectFullName() );
907 
908  wxFileDialog dlg( this, _( "Footprint Image File Name" ), projectPath,
909  fn.GetFullName(), PngFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
910 
911  if( dlg.ShowModal() == wxID_CANCEL || dlg.GetPath().IsEmpty() )
912  return;
913 
914  // calling wxYield is mandatory under Linux, after closing the file selector dialog
915  // to refresh the screen before creating the PNG or JPEG image from screen
916  wxYield();
917  SaveCanvasImageToFile( this, dlg.GetPath() );
918 }
919 
920 
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:522
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
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
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:103
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:62
void ActivateGalCanvas() override
void OnUpdateLayerAlpha(wxUpdateUIEvent &aEvent) override
BOARD_DESIGN_SETTINGS & GetDesignSettings() const override
Function GetDesignSettings returns the BOARD_DESIGN_SETTINGS for the BOARD owned by this 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:195
Model changes (required full reload)
Definition: tool_base.h:81
This file is part of the common library.
TOOL_DISPATCHER * m_toolDispatcher
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...
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)
ACTIONS * m_actions
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 ActivateGalCanvas() override
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:139
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:512
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.
void SetColorContext(COLOR_CONTEXT aContext=COLOR_CONTEXT::PCB)
bool OnLayerSelected()
Function OnLayerSelected ensure the active layer is visible, and other layers not visible when m_alwa...
int m_ValueDefaultlayer
Default value text layer on fp creation.
const LIB_ID & GetFPID() const
Definition: class_module.h:219
wxAuiManager m_auimgr
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
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:43
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
TOOL_MANAGER.
Definition: tool_manager.h:50
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:98
Generic tool for picking a point.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves common frame parameters to a configuration data file.
void HardRedraw() override
Refresh the library tree and redraw the window.
static TOOL_ACTION gridPreset
Definition: actions.h:134
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:75
#define NULL
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
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:341
LIB_TREE_NODE * GetCurrentTreeNode() const
Definition: lib_tree.cpp:165
MODULES & Modules()
Definition: class_board.h:229
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:49
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
COLOR_SETTINGS * ColorSettings()
Helper to retrieve the current color settings.
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:147
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.
MODULE * GetFirstModule() const
Gets the first module in the list (used in footprint viewer/editor) or NULL if none.
Definition: class_board.h:283
void Regenerate(bool aKeepState)
Regenerates the tree.
Definition: lib_tree.cpp:199
Definition of file extensions used in Kicad.
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition: lib_tree.cpp:188
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
virtual void SetPlotSettings(const PCB_PLOT_PARAMS &aSettings)
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
void SetDesignSettings(const BOARD_DESIGN_SETTINGS &aDesignSettings)
Function SetDesignSettings.
Definition: class_board.h:522
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:339
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:228
#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:217
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.
void SetGridSize(const VECTOR2D &aGridSize)
Set the grid size.
LIB_TREE_NODE * GetCurrentTreeNode() const
const PCB_PLOT_PARAMS & GetPlotSettings() const override
Function GetPlotSettings returns the PCB_PLOT_PARAMS for the BOARD owned by this frame.
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]
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:198
BOARD * GetBoard()
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:427
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.
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 SetDesignSettings(const BOARD_DESIGN_SETTINGS &aSettings) override
void updateTitle()
Updates window title according to getLibNickName().
virtual void OnModify()
Function OnModify Virtual Must be called after a change in order to set the "modify" flag of the curr...
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:213
LIB_TREE_MODEL_ADAPTER::PTR m_adapter
PCB_ACTIONS.
Definition: pcb_actions.h:62
void SyncLayerVisibilities()
Function SyncLayerVisibilities updates each "Layer" checkbox in this layer widget according to each l...
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.
virtual 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.
NETCLASSPTR GetDefault() const
Function GetDefault.
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:163
MODULE_EDITOR_TOOLS.
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
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.
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
int m_RefDefaultlayer
Default ref text layer on fp creation.
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, EDA_BASE_FRAME *aFrame)
Sets the work environment (model, view, view controls and the parent window).
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
KIID GetLink() const
Definition: class_module.h:549
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.
FOOTPRINT_EDITOR_SETTINGS * GetSettings()
static PTR Create(FOOTPRINT_EDIT_FRAME *aFrame, FP_LIB_TABLE *aLibs)
TOOL_MANAGER * m_toolManager
void OnGridSettings(wxCommandEvent &aEvent) override
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)
Module description (excepted pads)
void InitTools()
Function InitTools() Initializes all registered tools.
Abstract interface for BOARD_ITEMs capable of storing other items inside.
BOARD * GetBoard() const
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void OnUpdateModuleSelected(wxUpdateUIEvent &aEvent)
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...
virtual void Load()
Updates the parameters of this object based on the current JSON document contents.
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:182
void OnSaveFootprintAsPng(wxCommandEvent &event)
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition: lib_tree.cpp:176
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.