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 <fctsys.h>
24 #include <kiface_i.h>
25 #include <kiway.h>
26 #include <project.h>
27 #include <kicad_plugin.h>
28 #include <pcb_draw_panel_gal.h>
29 #include <confirm.h>
30 #include <pcb_edit_frame.h>
32 #include <fp_lib_table.h>
33 #include <bitmaps.h>
34 #include <class_board.h>
35 #include <class_module.h>
36 #include <pcbnew.h>
37 #include <pcbnew_id.h>
38 #include <footprint_edit_frame.h>
39 #include <footprint_viewer_frame.h>
41 #include <pcb_layer_widget.h>
42 #include <tool/tool_manager.h>
43 #include <tool/common_control.h>
44 #include <tool/common_tools.h>
45 #include <tool/tool_dispatcher.h>
46 #include <tool/action_toolbar.h>
47 #include <tool/zoom_tool.h>
48 #include <footprint_tree_pane.h>
49 #include <widgets/lib_tree.h>
50 #include <footprint_info_impl.h>
51 #include <widgets/paged_dialog.h>
55 #include <panel_hotkeys_editor.h>
58 #include "tools/selection_tool.h"
59 #include "tools/edit_tool.h"
60 #include "tools/drawing_tool.h"
61 #include "tools/point_editor.h"
62 #include "tools/pcbnew_control.h"
64 #include "tools/placement_tool.h"
66 #include "tools/pad_tool.h"
67 #include "tools/pcb_actions.h"
68 
69 
70 BEGIN_EVENT_TABLE( FOOTPRINT_EDIT_FRAME, PCB_BASE_FRAME )
72  EVT_MENU( wxID_CLOSE, FOOTPRINT_EDIT_FRAME::CloseModuleEditor )
73  EVT_MENU( wxID_EXIT, FOOTPRINT_EDIT_FRAME::OnExitKiCad )
74 
76 
79 
81 
85 
86  // Horizontal toolbar
89 
90  // UI update events.
97 
98 END_EVENT_TABLE()
99 
100 static const wxChar defaultLibWidthEntry[] = wxT( "ModeditLibWidth" );
101 
102 FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent,
103  EDA_DRAW_PANEL_GAL::GAL_TYPE aBackend ) :
104  PCB_BASE_EDIT_FRAME( aKiway, aParent, FRAME_FOOTPRINT_EDITOR, wxEmptyString,
105  wxDefaultPosition, wxDefaultSize,
106  KICAD_DEFAULT_DRAWFRAME_STYLE, GetFootprintEditorFrameName() )
107 {
108  m_showBorderAndTitleBlock = false; // true to show the frame references
109  m_FrameSize = ConvertDialogToPixels( wxSize( 500, 350 ) ); // default in case of no prefs
110  m_canvasType = aBackend;
111  m_AboutTitle = "ModEdit";
112  m_selLayerBox = nullptr;
113 
114  // Give an icon
115  wxIcon icon;
116  icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) );
117  SetIcon( icon );
118 
119  // Create GAL canvas
120  if( aBackend == EDA_DRAW_PANEL_GAL::GAL_TYPE_UNKNOWN )
121  m_canvasType = LoadCanvasTypeSetting();
122  else
123  m_canvasType = aBackend;
124 
125  PCB_DRAW_PANEL_GAL* drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize,
126  GetGalDisplayOptions(), m_canvasType );
127  SetCanvas( drawPanel );
128 
129  SetBoard( new BOARD() );
130 
131  // Enable one internal layer, because footprints support keepout areas that
132  // can be on internal layers only (therefore on the first internal layer)
133  // This is needed to handle these keepout in internal layers only
134  GetBoard()->SetEnabledLayers( GetBoard()->GetEnabledLayers().set( In1_Cu ) );
135  GetBoard()->SetVisibleLayers( GetBoard()->GetEnabledLayers() );
136  GetBoard()->SetLayerName( In1_Cu, _( "Inner layers" ) );
137 
138  // In modedit, the default net clearance is not known.
139  // (it depends on the actual board)
140  // So we do not show the default clearance, by setting it to 0
141  // The footprint or pad specific clearance will be shown
142  GetBoard()->GetDesignSettings().GetDefault()->SetClearance( 0 );
143 
144  // Don't show the default board solder mask clearance in the footprint editor. Only the
145  // footprint or pad clearance setting should be shown if it is not 0.
147 
148  // restore the last footprint from the project, if any
149  restoreLastFootprint();
150 
151  // Ensure all layers and items are visible:
152  // In footprint editor, some layers have no meaning or
153  // cannot be used, but we show all of them, at least to be able
154  // to edit a bad layer
156 
157  // However the "no net" mark on pads is useless, because there is
158  // no net in footprint editor: make it non visible
160 
161  m_Layers = new PCB_LAYER_WIDGET( this, GetCanvas(), true );
162 
163  // LoadSettings() *after* creating m_LayersManager, because LoadSettings()
164  // initialize parameters in m_LayersManager
165  LoadSettings( config() );
166  GetGalDisplayOptions().m_axesEnabled = true;
167 
168  SetScreen( new PCB_SCREEN( GetPageSettings().GetSizeIU() ) );
169  GetScreen()->SetMaxUndoItems( m_UndoRedoCountMax );
170 
171  GetScreen()->AddGrid( m_UserGridSize, EDA_UNITS::UNSCALED, ID_POPUP_GRID_USER );
172  GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
173 
174  // In modedit, set the default paper size to A4:
175  // this should be OK for all footprint to plot/print
176  SetPageSettings( PAGE_INFO( PAGE_INFO::A4 ) );
177 
178  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
179 
180  // Create the manager and dispatcher & route draw panel events to the dispatcher
181  setupTools();
182 
183  initLibraryTree();
184  m_treePane = new FOOTPRINT_TREE_PANE( this );
185 
186  ReCreateMenuBar();
187  ReCreateHToolbar();
188  ReCreateVToolbar();
189  ReCreateOptToolbar();
190 
191  m_Layers->ReFill();
192  m_Layers->ReFillRender();
193 
194  GetScreen()->m_Active_Layer = F_SilkS;
195  m_Layers->SelectLayer( F_SilkS );
196  m_Layers->OnLayerSelected();
197 
198  m_auimgr.SetManagedWindow( this );
199 
200  // Horizontal items; layers 4 - 6
201  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
202  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
203 
204  // Vertical items; layers 1 - 3
205  m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" ).Left().Layer(3) );
206  m_auimgr.AddPane( m_treePane, EDA_PANE().Palette().Name( "Footprints" ).Left().Layer(1)
207  .Caption( _( "Libraries" ) ).MinSize( 250, 400 )
208  .BestSize( m_defaultLibWidth, -1 ) );
209 
210  m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" ).Right().Layer(1) );
211  m_auimgr.AddPane( m_Layers, EDA_PANE().Palette().Name( "LayersManager" ).Right().Layer(3)
212  .Caption( _( "Layers Manager" ) ).PaneBorder( false )
213  .MinSize( 80, -1 ).BestSize( m_Layers->GetBestSize() ) );
214 
215  m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
216 
217  GetCanvas()->GetView()->SetScale( GetZoomLevelCoeff() / GetScreen()->GetZoom() );
218  ActivateGalCanvas();
219 
220  m_auimgr.Update();
221  GetToolManager()->RunAction( ACTIONS::gridPreset, true, m_LastGridSizeId );
222  GetToolManager()->RunAction( ACTIONS::zoomFitScreen, false );
223  updateTitle();
224  InitExitKey();
225 
226  // Default shutdown reason until a file is loaded
227  SetShutdownBlockReason( _( "Footprint changes are unsaved" ) );
228 
229  Raise(); // On some window managers, this is needed
230  Show( true );
231 }
232 
233 
235 {
236  // save the footprint in the PROJECT
238 
239  delete m_Layers;
240 }
241 
242 
244 {
245  return GetScreen() && GetScreen()->IsModify() && GetBoard() && GetBoard()->GetFirstModule();
246 }
247 
248 
250 {
251  // switches currently used canvas (Cairo / OpenGL).
252  PCB_BASE_FRAME::SwitchCanvas( aCanvasType );
253 
254  GetCanvas()->GetGAL()->SetAxesEnabled( true );
255  GetCanvas()->GetGAL()->SetGridSize( VECTOR2D( GetScreen()->GetGridSize() ) );
256 
257  // The base class method *does not reinit* the layers manager. We must upate the layer
258  // widget to match board visibility states, both layers and render columns, and and some
259  // settings dependent on the canvas.
261 }
262 
263 
265 {
266  SyncLibraryTree( true );
267  GetCanvas()->ForceRefresh();
268 }
269 
270 
272 {
273  auto& treePane = m_auimgr.GetPane( m_treePane );
274  treePane.Show( !IsSearchTreeShown() );
275  m_auimgr.Update();
276 }
277 
278 
280 {
281  return m_auimgr.GetPane( m_treePane ).IsShown();
282 }
283 
284 
286 {
287  return GetBoard()->GetFirstModule();
288 }
289 
290 
292 {
294 }
295 
296 
298 {
299  LIB_ID id = GetTreeFPID();
300 
301  if( id.GetLibNickname().empty() )
302  return GetLoadedFPID();
303 
304  return id;
305 }
306 
307 
309 {
310  MODULE* module = GetBoard()->GetFirstModule();
311 
312  if( module )
314  else
315  return LIB_ID();
316 }
317 
318 
320 {
321  MODULE* module = GetBoard()->GetFirstModule();
322 
323  return ( module && module->GetLink() > 0 );
324 }
325 
326 
328 {
329  LIB_ID id = GetLoadedFPID();
330 
331  if( id.IsValid() )
332  {
333  Prj().SetRString( PROJECT::PCB_FOOTPRINT_EDITOR_NICKNAME, id.GetLibNickname() );
334  Prj().SetRString( PROJECT::PCB_FOOTPRINT_EDITOR_FPNAME, id.GetLibItemName() );
335  }
336 }
337 
338 
340 {
341  const wxString& curFootprintName = Prj().GetRString( PROJECT::PCB_FOOTPRINT_EDITOR_FPNAME );
342  const wxString& curNickname = Prj().GetRString( PROJECT::PCB_FOOTPRINT_EDITOR_NICKNAME );
343 
344  if( curNickname.Length() && curFootprintName.Length() )
345  {
346  LIB_ID id;
347  id.SetLibNickname( curNickname );
348  id.SetLibItemName( curFootprintName );
349 
350  MODULE* module = loadFootprint( id );
351 
352  if( module )
353  AddModuleToBoard( module );
354  }
355 }
356 
357 
359 {
360  m_revertModule.reset( (MODULE*) aFootprint->Clone() );
361 
363 
364  // Pads are always editable in Footprint Editor
365  aFootprint->SetPadsLocked( false );
366 
368 
369  UpdateMsgPanel();
370 }
371 
372 
374 {
376 }
377 
378 
380 {
381  return GetBoard()->GetDesignSettings();
382 }
383 
384 
386 {
387  GetBoard()->SetDesignSettings( aSettings );
388 }
389 
390 
392 {
393  // get the settings from the parent editor, not our BOARD.
394  PCB_BASE_FRAME* parentFrame = (PCB_BASE_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, true );
395  wxASSERT( parentFrame );
396 
397  return parentFrame->GetPlotSettings();
398 }
399 
400 
402 {
403  // set the settings into parent editor, not our BOARD.
404  PCB_BASE_FRAME* parentFrame = (PCB_BASE_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, true );
405  wxASSERT( parentFrame );
406 
407  parentFrame->SetPlotSettings( aSettings );
408 }
409 
410 
411 void FOOTPRINT_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg )
412 {
415 
416  m_configSettings.Load( aCfg ); // mainly, load the color config
417 
418  // Ensure some params are valid
420 
421  // Usually, graphic items are drawn on F_SilkS or F_Fab layer
422  // Force these layers if not default
423  if( ( settings.m_RefDefaultlayer != F_SilkS ) && ( settings.m_RefDefaultlayer != F_Fab ) )
424  settings.m_RefDefaultlayer = F_SilkS;
425 
426  if( ( settings.m_ValueDefaultlayer != F_SilkS ) && ( settings.m_ValueDefaultlayer != F_Fab ) )
427  settings.m_ValueDefaultlayer = F_Fab;
428 
429  aCfg->Read( defaultLibWidthEntry, &m_defaultLibWidth, 250 );
430 }
431 
432 
433 void FOOTPRINT_EDIT_FRAME::SaveSettings( wxConfigBase* aCfg )
434 {
435  m_configSettings.Save( aCfg );
436 
439 
440  aCfg->Write( defaultLibWidthEntry, m_treePane->GetSize().x );
441 }
442 
443 
445 {
446  MODULE* module = GetBoard()->GetFirstModule();
447 
448  if( module )
449  return module->GetFootprintRect();
450  else
451  return GetBoardBoundingBox( false );
452 }
453 
454 
455 void FOOTPRINT_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent )
456 {
457  if( IsContentModified() )
458  {
459  // Shutdown blocks must be determined and vetoed as early as possible
460  if( SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION )
461  {
462  aEvent.Veto();
463  return;
464  }
465 
466  wxString footprintName = GetBoard()->GetFirstModule()->GetFPID().GetLibItemName();
467  wxString msg = _( "Save changes to \"%s\" before closing?" );
468 
469  if( !HandleUnsavedChanges( this, wxString::Format( msg, footprintName ),
470  [&]() -> bool { return SaveFootprint( GetBoard()->GetFirstModule() ); } ) )
471  {
472  aEvent.Veto();
473  return;
474  }
475  }
476 
478  GetCanvas()->StopDrawing();
479 
480  // Do not show the layer manager during closing to avoid flicker
481  // on some platforms (Windows) that generate useless redraw of items in
482  // the Layer Manger
483  m_auimgr.GetPane( "LayersManager" ).Show( false );
484 
485  Clear_Pcb( false );
486 
487  // Close the editor
488  aEvent.Skip();
489 }
490 
491 
492 void FOOTPRINT_EDIT_FRAME::OnExitKiCad( wxCommandEvent& event )
493 {
494  Kiway().OnKiCadExit();
495 }
496 
497 
498 void FOOTPRINT_EDIT_FRAME::CloseModuleEditor( wxCommandEvent& Event )
499 {
500  Close();
501 }
502 
503 
504 void FOOTPRINT_EDIT_FRAME::OnUpdateModuleSelected( wxUpdateUIEvent& aEvent )
505 {
506  aEvent.Enable( GetBoard()->GetFirstModule() != NULL );
507 }
508 
509 
511 {
513 
514  aEvent.Enable( frame && frame->GetBoard()->GetFirstModule() != NULL );
515 }
516 
517 
519 {
521 
522  MODULE* module_in_edit = GetBoard()->GetFirstModule();
523  bool canInsert = frame && module_in_edit && !module_in_edit->GetLink();
524 
525  // If the source was deleted, the module can inserted but not updated in the board.
526  if( frame && module_in_edit && module_in_edit->GetLink() ) // this is not a new module
527  {
528  BOARD* mainpcb = frame->GetBoard();
529  canInsert = true;
530 
531  // search if the source module was not deleted:
532  for( auto source_module : mainpcb->Modules() )
533  {
534  if( module_in_edit->GetLink() == source_module->GetTimeStamp() )
535  {
536  canInsert = false;
537  break;
538  }
539  }
540  }
541 
542  aEvent.Enable( canInsert );
543 }
544 
545 
547 {
548 
549  m_Layers->Freeze();
550  m_Layers->ReFill();
551  m_Layers->Thaw();
552 
553  wxAuiPaneInfo& lyrs = m_auimgr.GetPane( m_Layers );
554 
555  wxSize bestz = m_Layers->GetBestSize();
556 
557  lyrs.MinSize( bestz );
558  lyrs.BestSize( bestz );
559  lyrs.FloatingSize( bestz );
560 
561  if( lyrs.IsDocked() )
562  m_auimgr.Update();
563  else
564  m_Layers->SetSize( bestz );
565 }
566 
567 
569 {
570  // call my base class
572 
573  // We have 2 panes to update.
574  // For some obscure reason, the AUI manager hides the first modified pane.
575  // So force show panes
576  wxAuiPaneInfo& tree_pane_info = m_auimgr.GetPane( m_treePane );
577  bool tree_shown = tree_pane_info.IsShown();
578  tree_pane_info.Caption( _( "Libraries" ) );
579 
580  wxAuiPaneInfo& lm_pane_info = m_auimgr.GetPane( m_Layers );
581  bool lm_shown = lm_pane_info.IsShown();
582  lm_pane_info.Caption( _( "Layers Manager" ) );
583 
584  // update the layer manager
587 
588  // Now restore the visibility:
589  lm_pane_info.Show( lm_shown );
590  tree_pane_info.Show( tree_shown );
591  m_auimgr.Update();
592 }
593 
594 
596 {
598  Update3DView( false );
600 }
601 
602 
604 {
605  wxString title = _( "Footprint Editor" );
606  LIB_ID fpid = GetLoadedFPID();
607  bool writable = true;
608 
609  if( IsCurrentFPFromBoard() )
610  {
611  title += wxString::Format( wxT( " \u2014 %s [from %s.%s]" ),
612  GetBoard()->GetFirstModule()->GetReference(), Prj().GetProjectName(),
614  }
615  else if( fpid.IsValid() )
616  {
617  try
618  {
619  writable = Prj().PcbFootprintLibs()->IsFootprintLibWritable( fpid.GetLibNickname() );
620  }
621  catch( const IO_ERROR& )
622  {
623  // best efforts...
624  }
625 
626  // Note: don't used GetLoadedFPID(); footprint name may have been edited
627  title += wxString::Format( wxT( " \u2014 %s %s" ),
628  FROM_UTF8( GetBoard()->GetFirstModule()->GetFPID().Format().c_str() ),
629  writable ? wxString( wxEmptyString ) : _( "[Read Only]" ) );
630  }
631  else if( !fpid.GetLibItemName().empty() )
632  {
633  // Note: don't used GetLoadedFPID(); footprint name may have been edited
634  title += wxString::Format( wxT( " \u2014 %s %s" ),
635  FROM_UTF8( GetBoard()->GetFirstModule()->GetFPID().GetLibItemName().c_str() ),
636  _( "[Unsaved]" ) );
637  }
638 
639  SetTitle( title );
640 }
641 
642 
644 {
645  // Update the layer manager and other widgets from the board setup
646  // (layer and items visibility, colors ...)
647 
648  // Update the layer manager
649  m_Layers->Freeze();
652 
653  // update the layer widget to match board visibility states.
658 
659  m_Layers->Thaw();
660 }
661 
662 
664 {
665  GetCanvas()->UseColorScheme( &Settings().Colors() );
669  updateTitle();
670 }
671 
672 
674 {
675  FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
676 
677  WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 );
678  GFootprintList.ReadFootprintFiles( fpTable, NULL, &progressReporter );
679  progressReporter.Show( false );
680 
683 
685  auto adapter = static_cast<FP_TREE_SYNCHRONIZING_ADAPTER*>( m_adapter.get() );
686 
687  adapter->AddLibraries();
688 }
689 
690 
692 {
693  FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
694  auto adapter = static_cast<FP_TREE_SYNCHRONIZING_ADAPTER*>( m_adapter.get() );
695  LIB_ID target = GetTargetFPID();
696  bool targetSelected = ( target == m_treePane->GetLibTree()->GetSelectedLibId() );
697 
698  // Sync FOOTPRINT_INFO list to the libraries on disk
699  if( aProgress )
700  {
701  WX_PROGRESS_REPORTER progressReporter( this, _( "Updating Footprint Libraries" ), 2 );
702  GFootprintList.ReadFootprintFiles( fpTable, NULL, &progressReporter );
703  progressReporter.Show( false );
704  }
705  else
706  {
708  }
709 
710  // Sync the LIB_TREE to the FOOTPRINT_INFO list
711  adapter->Sync();
712 
715 
716  if( target.IsValid() )
717  {
718  if( adapter->FindItem( target ) )
719  {
720  if( targetSelected )
721  m_treePane->GetLibTree()->SelectLibId( target );
722  else
723  m_treePane->GetLibTree()->CenterLibId( target );
724  }
725  else
726  {
727  // Try to focus on parent
728  target.SetLibItemName( wxEmptyString );
729  m_treePane->GetLibTree()->CenterLibId( target );
730  }
731  }
732 }
733 
734 
736 {
737  m_treePane->GetLibTree()->SelectLibId( aLibID );
738 }
739 
740 
742 {
743  return GetBoard()->IsElementVisible( aElement );
744 }
745 
746 
748 {
749  GetCanvas()->GetView()->SetLayerVisible( aElement , aNewState );
750  GetBoard()->SetElementVisibility( aElement, aNewState );
751  m_Layers->SetRenderState( aElement, aNewState );
752 }
753 
754 
756 {
758 }
759 
760 
762  PANEL_HOTKEYS_EDITOR* aHotkeysPanel )
763 {
764  wxTreebook* book = aParent->GetTreebook();
765 
766  book->AddPage( new wxPanel( book ), _( "Footprint Editor" ) );
767  book->AddSubPage( new PANEL_MODEDIT_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) );
768  book->AddSubPage( new PANEL_MODEDIT_SETTINGS( this, aParent ), _( "Editing Options" ) );
769  book->AddSubPage( new PANEL_MODEDIT_DEFAULTS( this, aParent ), _( "Default Values" ) );
770 
771  aHotkeysPanel->AddHotKeys( GetToolManager() );
772 }
773 
774 
776 {
777  // Create the manager and dispatcher & route draw panel events to the dispatcher
780  GetCanvas()->GetViewControls(), this );
781  m_actions = new PCB_ACTIONS();
783 
785 
799 
800  m_toolManager->GetTool<PCBNEW_PICKER_TOOL>()->SetEditModules( true );
801  m_toolManager->GetTool<PCBNEW_CONTROL>()->SetEditModules( true );
802  m_toolManager->GetTool<PAD_TOOL>()->SetEditModules( true );
803  m_toolManager->GetTool<SELECTION_TOOL>()->SetEditModules( true );
804  m_toolManager->GetTool<EDIT_TOOL>()->SetEditModules( true );
805  m_toolManager->GetTool<DRAWING_TOOL>()->SetEditModules( true );
806  m_toolManager->GetTool<POINT_EDITOR>()->SetEditModules( true );
807 
809 
810  m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
811 }
812 
813 
815 {
817 
818  // Be sure the axis are enabled
819  GetCanvas()->GetGAL()->SetAxesEnabled( true );
820 
821  updateView();
822 
823  // Ensure the m_Layers settings are using the canvas type:
825 }
826 
827 
829 {
831 
832  if( aEnvVarsChanged )
833  SyncLibraryTree( true );
834 
835  Layout();
836  SendSizeEvent();
837 }
838 
839 
840 void FOOTPRINT_EDIT_FRAME::OnSaveFootprintAsPng( wxCommandEvent& event )
841 {
842  wxString fullFileName;
843 
844  LIB_ID id = GetLoadedFPID();
845 
846  if( id.empty() )
847  {
848  wxMessageBox( _( "No footprint selected." ) );
849  return;
850  }
851 
852  wxFileName fn( id.GetLibItemName() );
853  fn.SetExt( "png" );
854 
855  wxString projectPath = wxPathOnly( Prj().GetProjectFullName() );
856 
857  wxFileDialog dlg( this, _( "Footprint Image File Name" ), projectPath,
858  fn.GetFullName(), PngFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
859 
860  if( dlg.ShowModal() == wxID_CANCEL || dlg.GetPath().IsEmpty() )
861  return;
862 
863  // calling wxYield is mandatory under Linux, after closing the file selector dialog
864  // to refresh the screen before creating the PNG or JPEG image from screen
865  wxYield();
866  SaveCanvasImageToFile( this, dlg.GetPath() );
867 }
868 
869 
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)
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:82
This file is part of the common library.
TOOL_DISPATCHER * m_toolDispatcher
void Load(wxConfigBase *aCfg) override
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...
void wxConfigLoadSetups(wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList)
Function wxConfigLoadSetups uses aList of PARAM_CFG to load configuration values from aCfg.
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:109
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
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...
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 wxConfigSaveSetups(wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList)
Function wxConfigSaveSetups writes aList of PARAM_CFG to save configuration values to aCfg.
void SetLayersManagerTabsText()
Function SetLayersManagerTabsText Update the layer manager tabs labels Useful when changing Language ...
timestamp_t GetLink() const
Definition: class_module.h:549
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:79
void SyncLibraryTree(bool aProgress)
Synchronize the footprint library tree to the current state of the footprint library table.
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 Regenerate()
Updates the footprint tree
void HardRedraw() override
Refresh the library tree and redraw the window.
static TOOL_ACTION gridPreset
Definition: actions.h:131
#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
MODULES & Modules()
Definition: class_board.h:226
void OnModify() override
Must be called after a footprint change in order to set the "modify" flag of the current screen and p...
void LoadSettings(wxConfigBase *aCfg) override
Load common frame parameters from a configuration file.
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...
PCB_GENERAL_SETTINGS & Settings()
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...
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:145
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:275
Definition of file extensions used in Kicad.
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition: lib_tree.cpp:175
#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:274
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:540
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
#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
PCB_GENERAL_SETTINGS m_configSettings
Footprint Editor pane with footprint library tree.
void SyncLayersVisibility(const BOARD *aBoard)
Function SyncLayersVisibility Updates "visibility" property of each layer of a given BOARD.
void SaveSettings(wxConfigBase *aCfg) override
Saves common frame parameters to a configuration data 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:204
void SetAxesEnabled(bool aAxesEnabled)
Enables drawing the axes.
LIB_TREE * GetLibTree() const
EDIT_TOOL.
Definition: edit_tool.h:66
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.
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...
void UseColorScheme(const COLORS_DESIGN_SETTINGS *aSettings)
Function UseColorScheme Applies layer color settings.
COMMON_TOOLS.
Definition: common_tools.h:38
TOOL_DISPATCHER.
void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType) override
switches currently used canvas (Cairo / OpenGL).
wxString PngFileWildcard()
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:171
BOARD * GetBoard()
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:400
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...
void SaveSettings(wxConfigBase *aCfg) override
Saves common frame parameters to a configuration data file.
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:186
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...
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:160
static FOOTPRINT_EDIT_FRAME::OnUpdateInsertModuleInBoard const wxChar defaultLibWidthEntry[]
MODULE_EDITOR_TOOLS.
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Function SetEventDispatcher() Sets a dispatcher that processes events and forwards them to tools.
void LoadSettings(wxConfigBase *aCfg) override
Load common frame parameters from a configuration file.
#define _(s)
Definition: 3d_actions.cpp:31
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.
std::vector< PARAM_CFG * > & GetConfigurationSettings()
Return the footprint editor settings list.
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.
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.
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 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...
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:169
void OnSaveFootprintAsPng(wxCommandEvent &event)
void Save(wxConfigBase *aCfg) override
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition: lib_tree.cpp:163
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.