KiCad PCB EDA Suite
pcb_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) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>
7  * Copyright (C) 2013-2021 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 <advanced_config.h>
24 #include <kiface_i.h>
25 #include <kiway.h>
26 #include <pgm_base.h>
27 #include <pcb_edit_frame.h>
29 #include <fp_lib_table.h>
30 #include <bitmaps.h>
31 #include <trace_helpers.h>
32 #include <pcbnew_id.h>
33 #include <pcbnew_settings.h>
34 #include <pcb_layer_box_selector.h>
35 #include <footprint_edit_frame.h>
36 #include <dialog_plot.h>
39 #include <dialog_board_setup.h>
40 #include <convert_to_biu.h>
41 #include <invoke_pcb_dialog.h>
42 #include <board.h>
43 #include <footprint.h>
47 #include <pcb_draw_panel_gal.h>
48 #include <functional>
49 #include <project/project_file.h>
51 #include <project/net_settings.h>
54 #include <tool/tool_manager.h>
55 #include <tool/tool_dispatcher.h>
56 #include <tool/action_toolbar.h>
57 #include <tool/common_control.h>
58 #include <tool/common_tools.h>
59 #include <tool/selection.h>
60 #include <tool/zoom_tool.h>
62 #include <tools/pcb_picker_tool.h>
63 #include <tools/pcb_point_editor.h>
64 #include <tools/edit_tool.h>
65 #include <tools/group_tool.h>
66 #include <tools/drc_tool.h>
67 #include <tools/global_edit_tool.h>
68 #include <tools/convert_tool.h>
69 #include <tools/drawing_tool.h>
70 #include <tools/pcb_control.h>
74 #include <tools/pcb_viewer_tools.h>
76 #include <tools/placement_tool.h>
77 #include <tools/pad_tool.h>
80 #include <tools/zone_filler_tool.h>
81 #include <tools/pcb_actions.h>
82 #include <router/router_tool.h>
85 #include <gestfich.h>
86 #include <executable_names.h>
90 #include <wx/wupdlock.h>
91 #include <dialog_drc.h> // for DIALOG_DRC_WINDOW_NAME definition
95 #include <kiplatform/app.h>
96 
97 
98 #include <widgets/infobar.h>
99 
100 #if defined(KICAD_SCRIPTING) || defined(KICAD_SCRIPTING_WXPYTHON)
101 #include <python_scripting.h>
102 #if defined(KICAD_SCRIPTING_ACTION_MENU)
103 #include <action_plugin.h>
104 #endif
105 #endif
106 
107 
108 using namespace std::placeholders;
109 
110 
111 BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME )
114 
117 
118  EVT_SIZE( PCB_EDIT_FRAME::OnSize )
119 
121 
122  // Menu Files:
124 
128 
134 
137 
138  EVT_MENU( wxID_EXIT, PCB_EDIT_FRAME::OnQuit )
139  EVT_MENU( wxID_CLOSE, PCB_EDIT_FRAME::OnQuit )
140 
141  // menu Config
143 
144  // menu Postprocess
146 
147  // Horizontal toolbar
153 
154 
155 #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
156  EVT_TOOL( ID_TOOLBARH_PCB_ACTION_PLUGIN_REFRESH, PCB_EDIT_FRAME::OnActionPluginRefresh )
157  EVT_TOOL( ID_TOOLBARH_PCB_ACTION_PLUGIN_SHOW_FOLDER, PCB_EDIT_FRAME::OnActionPluginShowFolder )
158 #endif
159 
160  // Tracks and vias sizes general options
163 
164  // User interface update event handlers.
170  PCB_EDIT_FRAME::OnUpdateSelectTrackWidth )
172  PCB_EDIT_FRAME::OnUpdateSelectViaSize )
173 END_EVENT_TABLE()
174 
175 
176 PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
177  PCB_BASE_EDIT_FRAME( aKiway, aParent, FRAME_PCB_EDITOR, wxT( "PCB Editor" ), wxDefaultPosition,
179  m_exportNetlistAction( nullptr )
180 {
181  m_maximizeByDefault = true;
182  m_showBorderAndTitleBlock = true; // true to display sheet references
183  m_SelTrackWidthBox = NULL;
184  m_SelViaSizeBox = NULL;
185  m_SelLayerBox = NULL;
186  m_show_layer_manager_tools = true;
187  m_hasAutoSave = true;
188 
189  // We don't know what state board was in when it was last saved, so we have to
190  // assume dirty
191  m_ZoneFillsDirty = true;
192 
193  m_rotationAngle = 900;
194  m_aboutTitle = _( "KiCad PCB Editor" );
195 
196  // Must be created before the menus are created.
197  if( ADVANCED_CFG::GetCfg().m_ShowPcbnewExportNetlist )
198  m_exportNetlistAction = new TOOL_ACTION( "pcbnew.EditorControl.exportNetlist",
199  AS_GLOBAL, 0, "", _( "Netlist..." ),
200  _( "Export netlist used to update schematics" ) );
201 
202  // Create GAL canvas
203  auto canvas = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize,
204  GetGalDisplayOptions(),
206 
207  SetCanvas( canvas );
208 
209  SetBoard( new BOARD() );
210 
211  wxIcon icon;
212  wxIconBundle icon_bundle;
213 
214  icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbnew ) );
215  icon_bundle.AddIcon( icon );
216  icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbnew_32 ) );
217  icon_bundle.AddIcon( icon );
218  icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbnew_16 ) );
219  icon_bundle.AddIcon( icon );
220 
221  SetIcons( icon_bundle );
222 
223  // LoadSettings() *after* creating m_LayersManager, because LoadSettings()
224  // initialize parameters in m_LayersManager
225  LoadSettings( config() );
226 
227  SetScreen( new PCB_SCREEN( GetPageSettings().GetSizeIU() ) );
228 
229  // PCB drawings start in the upper left corner.
230  GetScreen()->m_Center = false;
231 
232  setupTools();
233  setupUIConditions();
234 
235  ReCreateMenuBar();
236  ReCreateHToolbar();
237  ReCreateAuxiliaryToolbar();
238  ReCreateVToolbar();
239  ReCreateOptToolbar();
240 
241  m_selectionFilterPanel = new PANEL_SELECTION_FILTER( this );
242 
243  m_appearancePanel = new APPEARANCE_CONTROLS( this, GetCanvas() );
244 
245  m_auimgr.SetManagedWindow( this );
246 
247  CreateInfoBar();
248 
249  unsigned int auiFlags = wxAUI_MGR_DEFAULT;
250 #if !defined( _WIN32 )
251  // Windows cannot redraw the UI fast enough during a live resize and may lead to all kinds
252  // of graphical glitches.
253  auiFlags |= wxAUI_MGR_LIVE_RESIZE;
254 #endif
255  m_auimgr.SetFlags( auiFlags );
256 
257  // Rows; layers 4 - 6
258  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" )
259  .Top().Layer( 6 ) );
260  m_auimgr.AddPane( m_auxiliaryToolBar, EDA_PANE().HToolbar().Name( "AuxToolbar" )
261  .Top().Layer( 5 ) );
262  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" )
263  .Bottom().Layer( 6 ) );
264 
265  // Columns; layers 1 - 3
266  m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" )
267  .Left().Layer( 3 ) );
268 
269  m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" )
270  .Right().Layer( 3 ) );
271 
272  m_auimgr.AddPane( m_appearancePanel, EDA_PANE().Name( "LayersManager" )
273  .Right().Layer( 4 )
274  .Caption( _( "Appearance" ) ).PaneBorder( false )
275  .MinSize( 180, -1 ).BestSize( 180, -1 ) );
276 
277  m_auimgr.AddPane( m_selectionFilterPanel, EDA_PANE().Name( "SelectionFilter" )
278  .Right().Layer( 4 ).Position( 2 )
279  .Caption( _( "Selection Filter" ) ).PaneBorder( false )
280  .MinSize( 180, -1 ).BestSize( 180, -1 ) );
281 
282  // Center
283  m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" )
284  .Center() );
285 
286  m_auimgr.GetPane( "LayersManager" ).Show( m_show_layer_manager_tools );
287  m_auimgr.GetPane( "SelectionFilter" ).Show( m_show_layer_manager_tools );
288 
289  // The selection filter doesn't need to grow in the vertical direction when docked
290  m_auimgr.GetPane( "SelectionFilter" ).dock_proportion = 0;
291 
292  FinishAUIInitialization();
293 
294  if( PCBNEW_SETTINGS* settings = dynamic_cast<PCBNEW_SETTINGS*>( config() ) )
295  {
296  if( settings->m_AuiPanels.right_panel_width > 0 )
297  {
298  wxAuiPaneInfo& layersManager = m_auimgr.GetPane( "LayersManager" );
299 
300  // wxAUI hack: force width by setting MinSize() and then Fixed()
301  // thanks to ZenJu http://trac.wxwidgets.org/ticket/13180
302  layersManager.MinSize( settings->m_AuiPanels.right_panel_width, -1 );
303  layersManager.Fixed();
304  m_auimgr.Update();
305 
306  // now make it resizable again
307  layersManager.MinSize( 180, -1 );
308  layersManager.Resizable();
309  m_auimgr.Update();
310  }
311 
312  m_appearancePanel->SetTabIndex( settings->m_AuiPanels.appearance_panel_tab );
313  }
314 
315  GetToolManager()->RunAction( ACTIONS::zoomFitScreen, false );
316 
317  // This is used temporarily to fix a client size issue on GTK that causes zoom to fit
318  // to calculate the wrong zoom size. See PCB_EDIT_FRAME::onSize().
319  Bind( wxEVT_SIZE, &PCB_EDIT_FRAME::onSize, this );
320 
321  resolveCanvasType();
322 
323  setupUnits( config() );
324 
325  // Ensure the Python interpreter is up to date with its environment variables
326  PythonSyncEnvironmentVariables();
327  PythonSyncProjectName();
328 
329  GetCanvas()->SwitchBackend( m_canvasType );
330  ActivateGalCanvas();
331 
332  // Default shutdown reason until a file is loaded
333  KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New PCB file is unsaved" ) );
334 
335  // disable Export STEP item if kicad2step does not exist
336  wxString strK2S = Pgm().GetExecutablePath();
337 
338 #ifdef __WXMAC__
339  if( strK2S.Find( "pcbnew.app" ) != wxNOT_FOUND )
340  {
341  // On macOS, we have standalone applications inside the main bundle, so we handle that here:
342  strK2S += "../../";
343  }
344 
345  strK2S += "Contents/MacOS/";
346 #endif
347 
348  wxFileName appK2S( strK2S, "kicad2step" );
349 
350  #ifdef _WIN32
351  appK2S.SetExt( "exe" );
352  #endif
353 
354  // Ensure the window is on top
355  Raise();
356 
357 // if( !appK2S.FileExists() )
358  // GetMenuBar()->FindItem( ID_GEN_EXPORT_FILE_STEP )->Enable( false );
359 
360  // AUI doesn't refresh properly on wxMac after changes in eb7dc6dd, so force it to
361 #ifdef __WXMAC__
362  if( Kiface().IsSingle() )
363  {
364  CallAfter( [&]()
365  {
366  m_appearancePanel->OnBoardChanged();
367  } );
368  }
369 #endif
370 
371  // Register a call to update the toolbar sizes. It can't be done immediately because
372  // it seems to require some sizes calculated that aren't yet (at least on GTK).
373  CallAfter( [&]()
374  {
375  // Ensure the controls on the toolbars all are correctly sized
376  UpdateToolbarControlSizes();
377  } );
378 }
379 
380 
382 {
383  // Close modeless dialogs
384  wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_DRC_WINDOW_NAME );
385 
386  if( open_dlg )
387  open_dlg->Close( true );
388 
389  // Shutdown all running tools
390  if( m_toolManager )
391  m_toolManager->ShutdownAllTools();
392 
393  if( GetBoard() )
394  GetBoard()->RemoveListener( m_appearancePanel );
395 
396  delete m_selectionFilterPanel;
397  delete m_appearancePanel;
398  delete m_exportNetlistAction;
399 }
400 
401 
403 {
404  if( m_pcb )
405  m_pcb->ClearProject();
406 
408 
409  aBoard->SetProject( &Prj() );
410  aBoard->GetConnectivity()->Build( aBoard );
411 
412  // reload the drawing-sheet
413  SetPageSettings( aBoard->GetPageSettings() );
414 }
415 
416 
418 {
419  return m_pcb;
420 }
421 
422 
423 void PCB_EDIT_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
424 {
425  PCB_BASE_FRAME::SetPageSettings( aPageSettings );
426 
427  // Prepare drawing-sheet template
429  &m_pcb->GetPageSettings(),
430  m_pcb->GetProject(),
431  &m_pcb->GetTitleBlock() );
432  drawingSheet->SetSheetName( std::string( GetScreenDesc().mb_str() ) );
433 
434  BASE_SCREEN* screen = GetScreen();
435 
436  if( screen != NULL )
437  {
438  drawingSheet->SetPageNumber(TO_UTF8( screen->GetPageNumber() ) );
439  drawingSheet->SetSheetCount( screen->GetPageCount() );
440  }
441 
442  if( BOARD* board = GetBoard() )
443  drawingSheet->SetFileName( TO_UTF8( board->GetFileName() ) );
444 
445  // PCB_DRAW_PANEL_GAL takes ownership of the drawing-sheet
446  GetCanvas()->SetDrawingSheet( drawingSheet );
447 }
448 
449 
451 {
452  return GetScreen() && GetScreen()->IsModify();
453 }
454 
455 
457 {
458  if( GetScreen() )
459  return GetScreen()->IsSave();
460 
461  return false;
462 }
463 
464 
466 {
467  return m_toolManager->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
468 }
469 
470 
472 {
473  // Create the manager and dispatcher & route draw panel events to the dispatcher
474  m_toolManager = new TOOL_MANAGER;
475  m_toolManager->SetEnvironment( m_pcb, GetCanvas()->GetView(),
476  GetCanvas()->GetViewControls(), config(), this );
477  m_actions = new PCB_ACTIONS();
478  m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
479 
480  // Register tools
481  m_toolManager->RegisterTool( new COMMON_CONTROL );
482  m_toolManager->RegisterTool( new COMMON_TOOLS );
483  m_toolManager->RegisterTool( new PCB_SELECTION_TOOL );
484  m_toolManager->RegisterTool( new ZOOM_TOOL );
485  m_toolManager->RegisterTool( new PCB_PICKER_TOOL );
486  m_toolManager->RegisterTool( new ROUTER_TOOL );
487  m_toolManager->RegisterTool( new LENGTH_TUNER_TOOL );
488  m_toolManager->RegisterTool( new EDIT_TOOL );
489  m_toolManager->RegisterTool( new GLOBAL_EDIT_TOOL );
490  m_toolManager->RegisterTool( new PAD_TOOL );
491  m_toolManager->RegisterTool( new DRAWING_TOOL );
492  m_toolManager->RegisterTool( new PCB_POINT_EDITOR );
493  m_toolManager->RegisterTool( new PCB_CONTROL );
494  m_toolManager->RegisterTool( new BOARD_EDITOR_CONTROL );
495  m_toolManager->RegisterTool( new BOARD_INSPECTION_TOOL );
496  m_toolManager->RegisterTool( new BOARD_REANNOTATE_TOOL );
497  m_toolManager->RegisterTool( new ALIGN_DISTRIBUTE_TOOL );
498  m_toolManager->RegisterTool( new MICROWAVE_TOOL );
499  m_toolManager->RegisterTool( new POSITION_RELATIVE_TOOL );
500  m_toolManager->RegisterTool( new ZONE_FILLER_TOOL );
501  m_toolManager->RegisterTool( new AUTOPLACE_TOOL );
502  m_toolManager->RegisterTool( new DRC_TOOL );
503  m_toolManager->RegisterTool( new PCB_VIEWER_TOOLS );
504  m_toolManager->RegisterTool( new CONVERT_TOOL );
505  m_toolManager->RegisterTool( new GROUP_TOOL );
506  m_toolManager->InitTools();
507 
508  // Run the selection tool, it is supposed to be always active
509  m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
510 }
511 
512 
514 {
516 
517  ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
518  PCB_EDITOR_CONDITIONS cond( this );
519 
520  wxASSERT( mgr );
521 
522 #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
523 #define CHECK( x ) ACTION_CONDITIONS().Check( x )
524 
526  mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) );
527  mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
528 
535 
536  mgr->SetConditions( ACTIONS::cut, ENABLE( cond.HasItems() ) );
537  mgr->SetConditions( ACTIONS::copy, ENABLE( cond.HasItems() ) );
542  mgr->SetConditions( ACTIONS::selectAll, ENABLE( cond.HasItems() ) );
543  mgr->SetConditions( ACTIONS::doDelete, ENABLE( cond.HasItems() ) );
544  mgr->SetConditions( ACTIONS::duplicate, ENABLE( cond.HasItems() ) );
545 
550  mgr->SetConditions( PCB_ACTIONS::lock, ENABLE( cond.HasItems() ) );
552 
556 
557 
558 #if defined( KICAD_SCRIPTING_WXPYTHON )
559  auto pythonConsoleCond =
560  [] ( const SELECTION& )
561  {
562  if( IsWxPythonLoaded() )
563  {
564  wxWindow* console = PCB_EDIT_FRAME::findPythonConsole();
565  return console && console->IsShown();
566  }
567 
568  return false;
569  };
570 
571  mgr->SetConditions( PCB_ACTIONS::showPythonConsole, CHECK( pythonConsoleCond ) );
572 #endif
573 
574  auto enableZoneControlConition =
575  [this] ( const SELECTION& )
576  {
578  && GetDisplayOptions().m_ZoneOpacity > 0.0;
579  };
580 
582  ENABLE( enableZoneControlConition ).Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_FILLED ) ) );
584  ENABLE( enableZoneControlConition ).Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_ZONE_OUTLINE ) ) );
586  ENABLE( enableZoneControlConition ).Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_FILLED_OUTLINE ) ) );
587 
588  auto enableBoardSetupCondition =
589  [this] ( const SELECTION& )
590  {
591  if( DRC_TOOL* tool = m_toolManager->GetTool<DRC_TOOL>() )
592  return !tool->IsDRCDialogShown();
593 
594  return true;
595  };
596 
597  auto boardFlippedCond =
598  [this]( const SELECTION& )
599  {
600  return GetCanvas()->GetView()->IsMirroredX();
601  };
602 
603  auto layerManagerCond =
604  [this] ( const SELECTION& )
605  {
606  return LayerManagerShown();
607  };
608 
609  auto highContrastCond =
610  [this] ( const SELECTION& )
611  {
612  return GetDisplayOptions().m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL;
613  };
614 
615  auto globalRatsnestCond =
616  [this] (const SELECTION& )
617  {
618  return GetDisplayOptions().m_ShowGlobalRatsnest;
619  };
620 
621  auto curvedRatsnestCond =
622  [this] (const SELECTION& )
623  {
624  return GetDisplayOptions().m_DisplayRatsnestLinesCurved;
625  };
626 
627  mgr->SetConditions( ACTIONS::highContrastMode, CHECK( highContrastCond ) );
628  mgr->SetConditions( PCB_ACTIONS::flipBoard, CHECK( boardFlippedCond ) );
629  mgr->SetConditions( PCB_ACTIONS::showLayersManager, CHECK( layerManagerCond ) );
630  mgr->SetConditions( PCB_ACTIONS::showRatsnest, CHECK( globalRatsnestCond ) );
631  mgr->SetConditions( PCB_ACTIONS::ratsnestLineMode, CHECK( curvedRatsnestCond ) );
632  mgr->SetConditions( PCB_ACTIONS::boardSetup , ENABLE( enableBoardSetupCondition ) );
633 
634 
635  auto isHighlightMode =
636  [this]( const SELECTION& )
637  {
638  ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
639  return tool->GetRouterMode() == PNS::RM_MarkObstacles;
640  };
641 
642  auto isShoveMode =
643  [this]( const SELECTION& )
644  {
645  ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
646  return tool->GetRouterMode() == PNS::RM_Shove;
647  };
648 
649  auto isWalkaroundMode =
650  [this]( const SELECTION& )
651  {
652  ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
653  return tool->GetRouterMode() == PNS::RM_Walkaround;
654  };
655 
656  mgr->SetConditions( PCB_ACTIONS::routerHighlightMode, CHECK( isHighlightMode ) );
657  mgr->SetConditions( PCB_ACTIONS::routerShoveMode, CHECK( isShoveMode ) );
658  mgr->SetConditions( PCB_ACTIONS::routerWalkaroundMode, CHECK( isWalkaroundMode ) );
659 
660  auto haveNetCond =
661  [] ( const SELECTION& aSel )
662  {
663  for( EDA_ITEM* item : aSel )
664  {
665  if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
666  {
667  if( bci->GetNetCode() > 0 )
668  return true;
669  }
670  }
671 
672  return false;
673  };
674 
675  mgr->SetConditions( PCB_ACTIONS::showNet, ENABLE( haveNetCond ) );
676  mgr->SetConditions( PCB_ACTIONS::hideNet, ENABLE( haveNetCond ) );
677  mgr->SetConditions( PCB_ACTIONS::highlightNet, ENABLE( haveNetCond ) );
678 
685 
686 
687  SELECTION_CONDITION singleZoneCond = SELECTION_CONDITIONS::Count( 1 ) &&
689 
693 
694  mgr->SetConditions( PCB_ACTIONS::zoneDuplicate, ENABLE( singleZoneCond ) );
695  mgr->SetConditions( PCB_ACTIONS::drawZoneCutout, ENABLE( singleZoneCond ) );
696  mgr->SetConditions( PCB_ACTIONS::drawSimilarZone, ENABLE( singleZoneCond ) );
697  mgr->SetConditions( PCB_ACTIONS::zoneMerge, ENABLE( zoneMergeCond ) );
700 
702 
703 #define CURRENT_TOOL( action ) mgr->SetConditions( action, CHECK( cond.CurrentTool( action ) ) )
704 
705  // These tools can be used at any time to inspect the board
711 
712 
713  auto isDrcRunning =
714  [this] ( const SELECTION& )
715  {
716  DRC_TOOL* tool = m_toolManager->GetTool<DRC_TOOL>();
717  return !tool->IsDRCRunning();
718  };
719 
720 #define CURRENT_EDIT_TOOL( action ) mgr->SetConditions( action, ACTION_CONDITIONS().Check( cond.CurrentTool( action ) ).Enable( isDrcRunning ) )
721 
722  // These tools edit the board, so they must be disabled during some operations
746 
752 
753 #undef CURRENT_TOOL
754 #undef CURRENT_EDIT_TOOL
755 #undef ENABLE
756 #undef CHECK
757 }
758 
759 
760 void PCB_EDIT_FRAME::OnQuit( wxCommandEvent& event )
761 {
762  if( event.GetId() == wxID_EXIT )
763  Kiway().OnKiCadExit();
764 
765  if( event.GetId() == wxID_CLOSE || Kiface().IsSingle() )
766  Close( false );
767 }
768 
769 
771 {
773  bds.m_DrcExclusions.clear();
774 
775  for( PCB_MARKER* marker : GetBoard()->Markers() )
776  {
777  if( marker->IsExcluded() )
778  bds.m_DrcExclusions.insert( marker->Serialize() );
779  }
780 }
781 
782 
784 {
785  BOARD_COMMIT commit( this );
786 
787  for( PCB_MARKER* marker : GetBoard()->ResolveDRCExclusions() )
788  commit.Add( marker );
789 
790  commit.Push( wxEmptyString, false, false );
791 
792  for( PCB_MARKER* marker : GetBoard()->Markers() )
793  {
794  if( marker->IsExcluded() )
795  {
796  GetCanvas()->GetView()->Remove( marker );
797  GetCanvas()->GetView()->Add( marker );
798  }
799  }
800 }
801 
802 
803 bool PCB_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
804 {
805  // Shutdown blocks must be determined and vetoed as early as possible
806  if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION
807  && IsContentModified() )
808  {
809  return false;
810  }
811 
812  if( IsContentModified() )
813  {
814  wxFileName fileName = GetBoard()->GetFileName();
815  wxString msg = _( "Save changes to \"%s\" before closing?" );
816 
817  if( !HandleUnsavedChanges( this, wxString::Format( msg, fileName.GetFullName() ),
818  [&]() -> bool
819  {
820  return Files_io_from_id( ID_SAVE_BOARD );
821  } ) )
822  {
823  return false;
824  }
825  }
826 
827  // Close modeless dialogs. They're trouble when they get destroyed after the frame and/or
828  // board.
829  wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_DRC_WINDOW_NAME );
830 
831  if( open_dlg )
832  open_dlg->Close( true );
833 
834  return true;
835 }
836 
837 
839 {
840  // On Windows 7 / 32 bits, on OpenGL mode only, Pcbnew crashes
841  // when closing this frame if a footprint was selected, and the footprint editor called
842  // to edit this footprint, and when closing pcbnew if this footprint is still selected
843  // See https://bugs.launchpad.net/kicad/+bug/1655858
844  // I think this is certainly a OpenGL event fired after frame deletion, so this workaround
845  // avoid the crash (JPC)
846  GetCanvas()->SetEvtHandlerEnabled( false );
847 
848  GetCanvas()->StopDrawing();
849 
850  // Delete the auto save file if it exists.
851  wxFileName fn = GetBoard()->GetFileName();
852 
853  // Auto save file name is the normal file name prefixed with 'GetAutoSaveFilePrefix()'.
854  fn.SetName( GetAutoSaveFilePrefix() + fn.GetName() );
855 
856  // When the auto save feature does not have write access to the board file path, it falls
857  // back to a platform specific user temporary file path.
858  if( !fn.IsOk() || !fn.IsDirWritable() )
859  fn.SetPath( wxFileName::GetTempDir() );
860 
861  wxLogTrace( traceAutoSave, "Deleting auto save file <" + fn.GetFullPath() + ">" );
862 
863  // Remove the auto save file on a normal close of Pcbnew.
864  if( fn.FileExists() && !wxRemoveFile( fn.GetFullPath() ) )
865  {
866  wxString msg = wxString::Format( _( "The auto save file \"%s\" could not be removed!" ),
867  fn.GetFullPath() );
868  wxMessageBox( msg, Pgm().App().GetAppName(), wxOK | wxICON_ERROR, this );
869  }
870 
871  // Make sure local settings are persisted
872  SaveProjectSettings();
873 
874  // Do not show the layer manager during closing to avoid flicker
875  // on some platforms (Windows) that generate useless redraw of items in
876  // the Layer Manger
877  if( m_show_layer_manager_tools )
878  m_auimgr.GetPane( "LayersManager" ).Show( false );
879 
880  // Unlink the old project if needed
881  GetBoard()->ClearProject();
882 
883  // Delete board structs and undo/redo lists, to avoid crash on exit
884  // when deleting some structs (mainly in undo/redo lists) too late
885  Clear_Pcb( false, true );
886 
887  // do not show the window because ScreenPcb will be deleted and we do not
888  // want any paint event
889  Show( false );
890 
892 }
893 
894 
896 {
898  GetCanvas()->UpdateColors();
899  GetCanvas()->Refresh();
900 }
901 
902 
903 void PCB_EDIT_FRAME::ShowBoardSetupDialog( const wxString& aInitialPage )
904 {
905  // Make sure everything's up-to-date
907 
908  DIALOG_BOARD_SETUP dlg( this );
909 
910  if( !aInitialPage.IsEmpty() )
911  dlg.SetInitialPage( aInitialPage, wxEmptyString );
912 
913  if( dlg.ShowQuasiModal() == wxID_OK )
914  {
916 
918  SaveProjectSettings();
919 
920  Kiway().CommonSettingsChanged( false, true );
921 
922  const PCB_DISPLAY_OPTIONS& opts = GetDisplayOptions();
923 
925  {
926  // Update clearance outlines
927  GetCanvas()->GetView()->UpdateAllItemsConditionally( KIGFX::REPAINT,
928  [&]( KIGFX::VIEW_ITEM* aItem ) -> bool
929  {
930  TRACK* track = dynamic_cast<TRACK*>( aItem );
931  PAD* pad = dynamic_cast<PAD*>( aItem );
932 
933  // TRACK is the base class of VIA and ARC so we don't need to
934  // check them independently
935 
936  return ( track && opts.m_ShowTrackClearanceMode )
937  || ( pad && opts.m_DisplayPadClearance );
938  } );
939  }
940 
941  GetCanvas()->Refresh();
942 
944  ReCreateAuxiliaryToolbar();
945  m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
946 
947  //this event causes the routing tool to reload its design rules information
949  toolEvent.SetHasPosition( false );
950  m_toolManager->ProcessEvent( toolEvent );
951  }
952 
953  GetCanvas()->SetFocus();
954 }
955 
956 
958 {
960 
961  PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
962  wxASSERT( cfg );
963 
964  if( cfg )
965  {
966  m_rotationAngle = cfg->m_RotationAngle;
967  m_show_layer_manager_tools = cfg->m_AuiPanels.show_layer_manager;
968  m_showPageLimits = cfg->m_ShowPageLimits;
969  }
970 }
971 
972 
974 {
976 
977  auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
978  wxASSERT( cfg );
979 
980  if( cfg )
981  {
982  cfg->m_RotationAngle = m_rotationAngle;
983  cfg->m_AuiPanels.show_layer_manager = m_show_layer_manager_tools;
984  cfg->m_AuiPanels.right_panel_width = m_appearancePanel->GetSize().x;
985  cfg->m_AuiPanels.appearance_panel_tab = m_appearancePanel->GetTabIndex();
986  cfg->m_ShowPageLimits = m_showPageLimits;
987  }
988 
989  GetSettingsManager()->SaveColorSettings( GetColorSettings(), "board" );
990 }
991 
992 
994 {
995  return GetColorSettings()->GetColor( LAYER_GRID );
996 }
997 
998 
1000 {
1001 
1002  GetColorSettings()->SetColor( LAYER_GRID, aColor );
1003  GetCanvas()->GetGAL()->SetGridColor( aColor );
1004 }
1005 
1006 
1008 {
1009  PCB_LAYER_ID oldLayer = GetActiveLayer();
1010 
1011  if( oldLayer == aLayer )
1012  return;
1013 
1015 
1016  m_appearancePanel->OnLayerChanged();
1017 
1018  m_toolManager->RunAction( PCB_ACTIONS::layerChanged ); // notify other tools
1019  GetCanvas()->SetFocus(); // allow capture of hotkeys
1020  GetCanvas()->SetHighContrastLayer( aLayer );
1021 
1022  GetCanvas()->GetView()->UpdateAllItemsConditionally( KIGFX::REPAINT,
1023  [&]( KIGFX::VIEW_ITEM* aItem ) -> bool
1024  {
1025  if( VIA* via = dynamic_cast<VIA*>( aItem ) )
1026  {
1027  // Vias on a restricted layer set must be redrawn when the active layer
1028  // is changed
1029  return ( via->GetViaType() == VIATYPE::BLIND_BURIED ||
1030  via->GetViaType() == VIATYPE::MICROVIA );
1031  }
1032  else if( PAD* pad = dynamic_cast<PAD*>( aItem ) )
1033  {
1034  // Clearances could be layer-dependent so redraw them when the active layer
1035  // is changed
1036  if( GetDisplayOptions().m_DisplayPadClearance )
1037  {
1038  // Round-corner rects are expensive to draw, but are mostly found on
1039  // SMD pads which only need redrawing on an active-to-not-active
1040  // switch.
1041  if( pad->GetAttribute() == PAD_ATTRIB::SMD )
1042  {
1043  if( ( oldLayer == F_Cu || aLayer == F_Cu ) && pad->IsOnLayer( F_Cu ) )
1044  return true;
1045 
1046  if( ( oldLayer == B_Cu || aLayer == B_Cu ) && pad->IsOnLayer( B_Cu ) )
1047  return true;
1048  }
1049 
1050  return true;
1051  }
1052  }
1053  else if( TRACK* track = dynamic_cast<TRACK*>( aItem ) )
1054  {
1055  // Clearances could be layer-dependent so redraw them when the active layer
1056  // is changed
1057  if( GetDisplayOptions().m_ShowTrackClearanceMode )
1058  {
1059  // Tracks aren't particularly expensive to draw, but it's an easy check.
1060  return track->IsOnLayer( oldLayer ) || track->IsOnLayer( aLayer );
1061  }
1062  }
1063 
1064  return false;
1065  } );
1066 
1067  GetCanvas()->Refresh();
1068 }
1069 
1070 
1072 {
1073  DRC_TOOL* drcTool = m_toolManager->GetTool<DRC_TOOL>();
1074 
1075  try
1076  {
1077  drcTool->GetDRCEngine()->InitEngine( GetDesignRulesPath() );
1078  }
1079  catch( PARSE_ERROR& )
1080  {
1081  // Not sure this is the best place to tell the user their rules are buggy, so
1082  // we'll stay quiet for now. Feel free to revisit this decision....
1083  }
1084 
1085  UpdateTitle();
1086 
1087  wxFileName fn = GetBoard()->GetFileName();
1088 
1089  // Display a warning that the file is read only
1090  if( fn.FileExists() && !fn.IsFileWritable() )
1091  {
1092  m_infoBar->RemoveAllButtons();
1093  m_infoBar->AddCloseButton();
1094  m_infoBar->ShowMessage( _( "Board file is read only." ), wxICON_WARNING );
1095  }
1096 
1097  ReCreateLayerBox();
1098 
1099  // Sync layer and item visibility
1100  GetCanvas()->SyncLayersVisibility( m_pcb );
1101 
1102  SetElementVisibility( LAYER_RATSNEST, GetDisplayOptions().m_ShowGlobalRatsnest );
1103 
1104  m_appearancePanel->OnBoardChanged();
1105 
1106  // Apply saved display state to the appearance panel after it has been set up
1107  PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
1108 
1109  m_appearancePanel->ApplyLayerPreset( localSettings.m_ActiveLayerPreset );
1110 
1111  if( GetBoard()->GetDesignSettings().IsLayerEnabled( localSettings.m_ActiveLayer ) )
1112  SetActiveLayer( localSettings.m_ActiveLayer );
1113 
1114  // Updates any auto dimensions and the auxiliary toolbar tracks/via sizes
1115  unitsChangeRefresh();
1116 
1117  // Display the loaded board:
1118  Zoom_Automatique( false );
1119 
1120  // Invalidate painting as loading the DRC engine will cause clearances to become valid
1121  GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL );
1122 
1123  Refresh();
1124 
1125  SetMsgPanel( GetBoard() );
1126  SetStatusText( wxEmptyString );
1127 
1128  KIPLATFORM::APP::SetShutdownBlockReason( this, _( "PCB file changes are unsaved" ) );
1129 }
1130 
1131 
1133 {
1134  m_appearancePanel->UpdateDisplayOptions();
1135 }
1136 
1137 
1139 {
1140  return GetBoard()->IsElementVisible( aElement );
1141 }
1142 
1143 
1144 void PCB_EDIT_FRAME::SetElementVisibility( GAL_LAYER_ID aElement, bool aNewState )
1145 {
1146  // Force the RATSNEST visible
1147  if( aElement == LAYER_RATSNEST )
1148  GetCanvas()->GetView()->SetLayerVisible( aElement, true );
1149  else
1150  GetCanvas()->GetView()->SetLayerVisible( aElement , aNewState );
1151 
1152  GetBoard()->SetElementVisibility( aElement, aNewState );
1153 }
1154 
1155 
1157 {
1158  // call my base class
1160 
1161  wxAuiPaneInfo& pane_info = m_auimgr.GetPane( m_appearancePanel );
1162  pane_info.Caption( _( "Appearance" ) );
1163  m_auimgr.Update();
1164 
1165  m_appearancePanel->OnBoardChanged();
1166 }
1167 
1168 
1170 {
1172 
1173  if( project.m_PcbLastPath[ aType ].IsEmpty() )
1174  return wxEmptyString;
1175 
1176  wxFileName absoluteFileName = project.m_PcbLastPath[ aType ];
1177  wxFileName pcbFileName = GetBoard()->GetFileName();
1178 
1179  absoluteFileName.MakeAbsolute( pcbFileName.GetPath() );
1180  return absoluteFileName.GetFullPath();
1181 }
1182 
1183 
1184 void PCB_EDIT_FRAME::SetLastPath( LAST_PATH_TYPE aType, const wxString& aLastPath )
1185 {
1187 
1188  wxFileName relativeFileName = aLastPath;
1189  wxFileName pcbFileName = GetBoard()->GetFileName();
1190 
1191  relativeFileName.MakeRelativeTo( pcbFileName.GetPath() );
1192 
1193  if( relativeFileName.GetFullPath() != project.m_PcbLastPath[ aType ] )
1194  {
1195  project.m_PcbLastPath[ aType ] = relativeFileName.GetFullPath();
1196  SaveProjectSettings();
1197  }
1198 }
1199 
1200 
1202 {
1204 
1205  Update3DView( true, GetDisplayOptions().m_Live3DRefresh );
1206 
1207  if( !GetTitle().StartsWith( "*" ) )
1208  UpdateTitle();
1209 
1210  m_ZoneFillsDirty = true;
1211 }
1212 
1213 
1215 {
1216  Update3DView( true, true );
1217 }
1218 
1219 
1220 void PCB_EDIT_FRAME::ExportSVG( wxCommandEvent& event )
1221 {
1222  InvokeExportSVG( this, GetBoard() );
1223 }
1224 
1225 
1227 {
1228  wxFileName fn = GetBoard()->GetFileName();
1229  bool readOnly = false;
1230  bool unsaved = false;
1231 
1232  if( fn.IsOk() && fn.FileExists() )
1233  readOnly = !fn.IsFileWritable();
1234  else
1235  unsaved = true;
1236 
1237  SetTitle( wxString::Format( wxT( "%s%s %s%s\u2014 " ) + _( "PCB Editor" ),
1238  IsContentModified() ? "*" : "",
1239  fn.GetName(),
1240  readOnly ? _( "[Read Only]" ) + wxS( " " ) : "",
1241  unsaved ? _( "[Unsaved]" ) + wxS( " " ) : "" ) );
1242 }
1243 
1244 
1246 {
1247  // Update the layer manager and other widgets from the board setup
1248  // (layer and items visibility, colors ...)
1249 
1250  // Rebuild list of nets (full ratsnest rebuild)
1252  Compile_Ratsnest( true );
1253 
1254  // Update info shown by the horizontal toolbars
1255  ReCreateLayerBox();
1256 
1257  LSET activeLayers = GetBoard()->GetEnabledLayers();
1258 
1259  if( !activeLayers.test( GetActiveLayer() ) )
1260  SetActiveLayer( activeLayers.Seq().front() );
1261 
1262  m_SelLayerBox->SetLayerSelection( GetActiveLayer() );
1263 
1265 
1266  layerEnum.Choices().Clear();
1267  layerEnum.Undefined( UNDEFINED_LAYER );
1268 
1269  for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
1270  {
1271  // Canonical name
1272  layerEnum.Map( *seq, LSET::Name( *seq ) );
1273  // User name
1274  layerEnum.Map( *seq, GetBoard()->GetLayerName( *seq ) );
1275  }
1276 
1277  // Sync visibility with canvas
1278  KIGFX::VIEW* view = GetCanvas()->GetView();
1279  LSET visible = GetBoard()->GetVisibleLayers();
1280 
1281  for( PCB_LAYER_ID layer : LSET::AllLayersMask().Seq() )
1282  view->SetLayerVisible( layer, visible.Contains( layer ) );
1283 
1284  // Stackup and/or color theme may have changed
1285  m_appearancePanel->OnBoardChanged();
1286 }
1287 
1288 
1289 #if defined( KICAD_SCRIPTING_WXPYTHON )
1290 
1291 void PCB_EDIT_FRAME::ScriptingConsoleEnableDisable()
1292 {
1293  wxWindow * pythonPanelFrame = findPythonConsole();
1294  bool pythonPanelShown = true;
1295 
1296  if( pythonPanelFrame == NULL )
1297  pythonPanelFrame = CreatePythonShellWindow( this, pythonConsoleNameId() );
1298  else
1299  pythonPanelShown = ! pythonPanelFrame->IsShown();
1300 
1301  if( pythonPanelFrame )
1302  pythonPanelFrame->Show( pythonPanelShown );
1303  else
1304  wxMessageBox( wxT( "Error: unable to create the Python Console" ) );
1305 }
1306 #endif
1307 
1308 
1310 {
1311  // switches currently used canvas (Cairo / OpenGL).
1312  PCB_BASE_FRAME::SwitchCanvas( aCanvasType );
1313 }
1314 
1315 
1317 {
1318  PCB_PLOT_PARAMS plotSettings = GetPlotSettings();
1319 
1320  switch( aID )
1321  {
1322  case ID_GEN_PLOT_GERBER:
1323  plotSettings.SetFormat( PLOT_FORMAT::GERBER );
1324  break;
1325  case ID_GEN_PLOT_DXF:
1326  plotSettings.SetFormat( PLOT_FORMAT::DXF );
1327  break;
1328  case ID_GEN_PLOT_HPGL:
1329  plotSettings.SetFormat( PLOT_FORMAT::HPGL );
1330  break;
1331  case ID_GEN_PLOT_PDF:
1332  plotSettings.SetFormat( PLOT_FORMAT::PDF );
1333  break;
1334  case ID_GEN_PLOT_PS:
1335  plotSettings.SetFormat( PLOT_FORMAT::POST );
1336  break;
1337  case ID_GEN_PLOT: /* keep the previous setup */ break;
1338  default:
1339  wxFAIL_MSG( "ToPlotter(): unexpected plot type" ); break;
1340  break;
1341  }
1342 
1343  SetPlotSettings( plotSettings );
1344 
1345  // Force rebuild the dialog if currently open because the old dialog can be not up to date
1346  // if the board (or units) has changed
1347  wxWindow* dlg = wxWindow::FindWindowByName( DLG_WINDOW_NAME );
1348 
1349  if( dlg )
1350  dlg->Destroy();
1351 
1352  dlg = new DIALOG_PLOT( this );
1353  dlg->Show( true );
1354 }
1355 
1356 
1358 {
1359  if( Kiface().IsSingle() )
1360  return false;
1361 
1362  // Update PCB requires a netlist. Therefore the schematic editor must be running
1363  // If this is not the case, open the schematic editor
1364  KIWAY_PLAYER* frame = Kiway().Player( FRAME_SCH, true );
1365 
1366  if( !frame->IsShown() )
1367  {
1368  wxFileName fn( Prj().GetProjectPath(), Prj().GetProjectName(),
1370 
1371  // Maybe the file hasn't been converted to the new s-expression file format so
1372  // see if the legacy schematic file is still in play.
1373  if( !fn.FileExists() )
1374  {
1375  fn.SetExt( LegacySchematicFileExtension );
1376 
1377  if( !fn.FileExists() )
1378  {
1379  DisplayError( this, _( "The schematic for this board cannot be found." ) );
1380  return false;
1381  }
1382  }
1383 
1384  frame->OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ) );
1385 
1386  // we show the schematic editor frame, because do not show is seen as
1387  // a not yet opened schematic by Kicad manager, which is not the case
1388  frame->Show( true );
1389 
1390  // bring ourselves back to the front
1391  Raise();
1392  }
1393 
1394  return true; //Success!
1395 }
1396 
1397 
1399  const wxString& aAnnotateMessage )
1400 {
1401  if( !TestStandalone() )
1402  {
1403  DisplayErrorMessage( this, _( "Cannot update the PCB because PCB editor is opened in "
1404  "stand-alone mode. In order to create or update PCBs from "
1405  "schematics, you must launch the KiCad project manager and "
1406  "create a project." ) );
1407  return false; // Not in standalone mode
1408  }
1409 
1410  Raise(); // Show
1411 
1412  std::string payload( aAnnotateMessage );
1413 
1414  Kiway().ExpressMail( FRAME_SCH, MAIL_SCH_GET_NETLIST, payload, this );
1415 
1416  if( payload == aAnnotateMessage )
1417  {
1418  Raise();
1419  DisplayErrorMessage( this, aAnnotateMessage );
1420  return false;
1421  }
1422 
1423  try
1424  {
1425  auto lineReader = new STRING_LINE_READER( payload, _( "Eeschema netlist" ) );
1426  KICAD_NETLIST_READER netlistReader( lineReader, &aNetlist );
1427  netlistReader.LoadNetlist();
1428  }
1429  catch( const IO_ERROR& )
1430  {
1431  Raise();
1432  assert( false ); // should never happen
1433  return false;
1434  }
1435 
1436  return true;
1437 }
1438 
1439 
1441 {
1442  wxString msg;
1443  wxFileName schematic( Prj().GetProjectPath(), Prj().GetProjectName(),
1445 
1446  if( !schematic.FileExists() )
1447  {
1448  wxFileName legacySchematic( Prj().GetProjectPath(), Prj().GetProjectName(),
1450 
1451  if( legacySchematic.FileExists() )
1452  {
1453  schematic = legacySchematic;
1454  }
1455  else
1456  {
1457  msg.Printf( _( "Schematic file \"%s\" not found." ), schematic.GetFullPath() );
1458  wxMessageBox( msg, _( "KiCad Error" ), wxOK | wxICON_ERROR, this );
1459  return;
1460  }
1461  }
1462 
1463  if( Kiface().IsSingle() )
1464  {
1465  wxString filename = wxT( "\"" ) + schematic.GetFullPath( wxPATH_NATIVE ) + wxT( "\"" );
1466  ExecuteFile( this, EESCHEMA_EXE, filename );
1467  }
1468  else
1469  {
1470  KIWAY_PLAYER* frame = Kiway().Player( FRAME_SCH, false );
1471 
1472  // Please: note: DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::initBuffers() calls
1473  // Kiway.Player( FRAME_SCH, true )
1474  // therefore, the schematic editor is sometimes running, but the schematic project
1475  // is not loaded, if the library editor was called, and the dialog field editor was used.
1476  // On Linux, it happens the first time the schematic editor is launched, if
1477  // library editor was running, and the dialog field editor was open
1478  // On Windows, it happens always after the library editor was called,
1479  // and the dialog field editor was used
1480  if( !frame )
1481  {
1482  try
1483  {
1484  frame = Kiway().Player( FRAME_SCH, true );
1485  }
1486  catch( const IO_ERROR& err )
1487  {
1488  wxMessageBox( _( "Eeschema failed to load:\n" ) + err.What(),
1489  _( "KiCad Error" ), wxOK | wxICON_ERROR, this );
1490  return;
1491  }
1492  }
1493 
1494  if( !frame->IsShown() ) // the frame exists, (created by the dialog field editor)
1495  // but no project loaded.
1496  {
1497  frame->OpenProjectFiles( std::vector<wxString>( 1, schematic.GetFullPath() ) );
1498  frame->Show( true );
1499  }
1500 
1501  // On Windows, Raise() does not bring the window on screen, when iconized or not shown
1502  // On Linux, Raise() brings the window on screen, but this code works fine
1503  if( frame->IsIconized() )
1504  {
1505  frame->Iconize( false );
1506  // If an iconized frame was created by Pcbnew, Iconize( false ) is not enough
1507  // to show the frame at its normal size: Maximize should be called.
1508  frame->Maximize( false );
1509  }
1510 
1511  frame->Raise();
1512  }
1513 }
1514 
1515 
1517 {
1518  // Reload Python plugins if they are newer than the already loaded, and load new plugins
1519 #if defined(KICAD_SCRIPTING)
1520 #if defined(KICAD_SCRIPTING_ACTION_MENU)
1521  // Remove all action plugins so that we don't keep references to old versions
1523 #endif
1524 
1525  // Reload plugin list: reload Python plugins if they are newer than the already loaded,
1526  // and load new plugins
1528 
1529 #if defined(KICAD_SCRIPTING_ACTION_MENU)
1530  // Action plugins can be modified, therefore the plugins menu must be updated:
1531  ReCreateMenuBar();
1532  // Recreate top toolbar to add action plugin buttons
1533  ReCreateHToolbar();
1534 #endif
1535 #endif
1536 }
1537 
1538 
1540 {
1541 #if defined(KICAD_SCRIPTING)
1542 #ifdef __WXMAC__
1543  wxString msg;
1544 
1545  // Quote in case there are spaces in the path.
1546  msg.Printf( "open \"%s\"", PyPluginsPath( true ) );
1547 
1548  system( msg.c_str() );
1549 #else
1550  wxString pypath( PyPluginsPath( true ) );
1551 
1552  // Quote in case there are spaces in the path.
1553  AddDelimiterString( pypath );
1554 
1555  wxLaunchDefaultApplication( pypath );
1556 #endif
1557 #endif
1558 }
1559 
1560 
1562 {
1563 #if defined( KICAD_SCRIPTING )
1564  const ENV_VAR_MAP& vars = Pgm().GetLocalEnvVariables();
1565 
1566  // Set the environment variables for python scripts
1567  // note: the string will be encoded UTF8 for python env
1568  for( auto& var : vars )
1569  pcbnewUpdatePythonEnvVar( var.first, var.second.GetValue() );
1570 
1571  // Because the env vars can de modified by the python scripts (rewritten in UTF8),
1572  // regenerate them (in Unicode) for our normal environment
1573  for( auto& var : vars )
1574  wxSetEnv( var.first, var.second.GetValue() );
1575 #endif
1576 }
1577 
1578 
1580 {
1581 #if defined( KICAD_SCRIPTING )
1582  wxString evValue;
1583  wxGetEnv( PROJECT_VAR_NAME, &evValue );
1584  pcbnewUpdatePythonEnvVar( wxString( PROJECT_VAR_NAME ).ToStdString(), evValue );
1585 
1586  // Because PROJECT_VAR_NAME can be modified by the python scripts (rewritten in UTF8),
1587  // regenerate it (in Unicode) for our normal environment
1588  wxSetEnv( PROJECT_VAR_NAME, evValue );
1589 #endif
1590 }
1591 
1592 
1594 {
1595  if( aFootprint == NULL )
1596  return;
1597 
1598  DIALOG_FOOTPRINT_PROPERTIES dlg( this, aFootprint );
1599 
1600  // We use quasi modal to allow displaying help dialogs.
1601  dlg.ShowQuasiModal();
1603  /*
1604  * retvalue =
1605  * FP_PROPS_UPDATE_FP to show Update Footprints dialog
1606  * FP_PROPS_CHANGE_FP to show Change Footprints dialog
1607  * FP_PROPS_OK for normal edit
1608  * FP_PROPS_CANCEL if aborted
1609  * FP_PROPS_EDIT_BOARD_FP to load board footprint into Footprint Editor
1610  * FP_PROPS_EDIT_LIBRARY_FP to load library footprint into Footprint Editor
1611  */
1612 
1614  {
1615  // If something edited, push a refresh request
1616  GetCanvas()->Refresh();
1617  }
1619  {
1621 
1622  editor->LoadFootprintFromBoard( aFootprint );
1623 
1624  editor->Show( true );
1625  editor->Raise(); // Iconize( false );
1626  }
1627 
1629  {
1631 
1632  editor->LoadFootprintFromLibrary( aFootprint->GetFPID() );
1633 
1634  editor->Show( true );
1635  editor->Raise(); // Iconize( false );
1636  }
1637 
1639  {
1640  ShowExchangeFootprintsDialog( aFootprint, true, true );
1641  }
1642 
1644  {
1645  ShowExchangeFootprintsDialog( aFootprint, false, true );
1646  }
1647 }
1648 
1649 
1650 int PCB_EDIT_FRAME::ShowExchangeFootprintsDialog( FOOTPRINT* aFootprint, bool aUpdateMode,
1651  bool aSelectedMode )
1652 {
1653  DIALOG_EXCHANGE_FOOTPRINTS dialog( this, aFootprint, aUpdateMode, aSelectedMode );
1654 
1655  return dialog.ShowQuasiModal();
1656 }
1657 
1658 
1659 void PCB_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
1660 {
1661  PCB_BASE_EDIT_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
1662 
1663  GetAppearancePanel()->OnColorThemeChanged();
1664 
1665  // Netclass definitions could have changed, either by us or by Eeschema
1666  DRC_TOOL* drcTool = m_toolManager->GetTool<DRC_TOOL>();
1667  WX_INFOBAR* infobar = GetInfoBar();
1668 
1669  try
1670  {
1671  drcTool->GetDRCEngine()->InitEngine( GetDesignRulesPath() );
1672  infobar->Hide();
1673  }
1674  catch( PARSE_ERROR& )
1675  {
1676  wxHyperlinkCtrl* button = new wxHyperlinkCtrl( infobar, wxID_ANY, _( "Edit design rules" ),
1677  wxEmptyString );
1678 
1679  button->Bind( wxEVT_COMMAND_HYPERLINK, std::function<void( wxHyperlinkEvent& aEvent )>(
1680  [&]( wxHyperlinkEvent& aEvent )
1681  {
1682  ShowBoardSetupDialog( _( "Custom Rules" ) );
1683  } ) );
1684 
1685  infobar->RemoveAllButtons();
1686  infobar->AddButton( button );
1687  infobar->AddCloseButton();
1688  infobar->ShowMessage( _( "Could not compile custom design rules." ), wxICON_ERROR );
1689  }
1690 
1691  // Update the environment variables in the Python interpreter
1692  if( aEnvVarsChanged )
1693  PythonSyncEnvironmentVariables();
1694 
1695  Layout();
1696  SendSizeEvent();
1697 }
1698 
1699 
1701 {
1703 
1704  PythonPluginsReload();
1705 }
1706 
1707 
1709 {
1710  PythonSyncProjectName();
1711 }
1712 
1713 
1714 bool ExportBoardToHyperlynx( BOARD* aBoard, const wxFileName& aPath );
1715 
1716 
1717 void PCB_EDIT_FRAME::OnExportHyperlynx( wxCommandEvent& event )
1718 {
1719  wxString wildcard = wxT( "*.hyp" );
1720  wxFileName fn = GetBoard()->GetFileName();
1721 
1722  fn.SetExt( wxT("hyp") );
1723 
1724  wxFileDialog dlg( this, _( "Export Hyperlynx Layout" ), fn.GetPath(), fn.GetFullName(),
1725  wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
1726 
1727  if( dlg.ShowModal() != wxID_OK )
1728  return;
1729 
1730  fn = dlg.GetPath();
1731 
1732  // always enforce filename extension, user may not have entered it.
1733  fn.SetExt( wxT( "hyp" ) );
1734 
1736 }
1737 
1738 
1740 {
1741  return GetBoard()->GetFileName();
1742 }
1743 
1744 
1746 {
1747  return m_auimgr.GetPane( "LayersManager" ).IsShown();
1748 }
1749 
1750 
1751 void PCB_EDIT_FRAME::onSize( wxSizeEvent& aEvent )
1752 {
1753  if( IsShown() )
1754  {
1755  // We only need this until the frame is done resizing and the final client size is
1756  // established.
1757  Unbind( wxEVT_SIZE, &PCB_EDIT_FRAME::onSize, this );
1758  GetToolManager()->RunAction( ACTIONS::zoomFitScreen, true );
1759  }
1760 
1761  // Skip() is called in the base class.
1762  EDA_DRAW_FRAME::OnSize( aEvent );
1763 }
void UpdateUserInterface()
Update the layer manager and other widgets from the board setup (layer and items visibility,...
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:252
void UpdateTitle()
Set the main window title bar text.
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
The interactive edit tool.
static TOOL_ACTION drawLine
Definition: pcb_actions.h:146
virtual bool OpenProjectFiles(const std::vector< wxString > &aFileList, int aCtl=0)
Open a project or set of files given by aFileList.
Definition: kiway_player.h:115
Filled polygons are shown.
static TOOL_ACTION drawCenterDimension
Definition: pcb_actions.h:153
void BuildListOfNets()
Definition: board.h:735
void OnModify() override
Must be called after a board change to set the modified flag.
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:207
#define CURRENT_EDIT_TOOL(action)
Definition: track.h:343
void SetPageSettings(const PAGE_INFO &aPageSettings) override
void RecreateCmpFileFromBoard(wxCommandEvent &aEvent)
Recreates a .cmp file from the current loaded board.
KiCad executable names.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:61
virtual void ShowChangedLanguage() override
Redraw the menus and what not in current language.
const PAGE_INFO & GetPageSettings() const
Definition: board.h:608
void SetElementVisibility(GAL_LAYER_ID aElement, bool aNewState)
Change the visibility of an element category.
void OnExportIDF3(wxCommandEvent &event)
Export the current BOARD to a IDFv3 board and lib files.
void OnKiCadExit()
Definition: kiway.cpp:610
static TOOL_ACTION unlock
Definition: pcb_actions.h:424
PNS::PNS_MODE GetRouterMode()
void SetElementVisibility(GAL_LAYER_ID aLayer, bool aNewState)
Change the visibility of an element category.
Definition: board.cpp:513
static const KICAD_T Tracks[]
A scan list for only TRACKs.
Definition: collectors.h:299
void ActivateGalCanvas() override
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
void OnExportHyperlynx(wxCommandEvent &event)
Export the current BOARD to a Hyperlynx HYP file.
KICAD_NETLIST_READER read the new s-expression based KiCad netlist format.
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:265
This file is part of the common library TODO brief description.
const wxChar *const traceAutoSave
Flag to enable auto save feature debug tracing.
Model changes (required full reload)
Definition: tool_base.h:81
static TOOL_ACTION drawSimilarZone
Definition: pcb_actions.h:160
static TOOL_ACTION drillOrigin
Definition: pcb_actions.h:437
SELECTION_CONDITION HasItems()
Create a functor that tests if there are items in the board.
static TOOL_ACTION lock
Definition: pcb_actions.h:423
static TOOL_ACTION doDelete
Definition: actions.h:75
void HardRedraw() override
Rebuild the GAL and redraws the screen.
static TOOL_ACTION drawArc
Definition: pcb_actions.h:150
SELECTION_CONDITION TrackFillDisplay()
Create a functor that tests if the frame fills tracks.
void ToPlotter(int aID)
Open a dialog frame to create plot and drill files relative to the current board.
static TOOL_ACTION hideNet
Definition: pcb_actions.h:455
SELECTION_CONDITION FullscreenCursor()
Create a functor testing if the cursor is full screen in a frame.
Definition: id.h:87
static SELECTION_CONDITION MoreThan(int aNumber)
Create a functor that tests if the number of selected items is greater than the value given as parame...
static TOOL_ACTION microwaveCreateStubArc
Definition: pcb_actions.h:415
void OnSockRequestServer(wxSocketEvent &evt)
Definition: eda_dde.cpp:102
COMMIT & Add(EDA_ITEM *aItem)
Notify observers that aItem has been added.
Definition: commit.h:78
Outlines of filled polygons are shown.
void SetInitialPage(const wxString &aPage, const wxString &aParentPage=wxEmptyString)
void doCloseWindow() override
static TOOL_ACTION ratsnestLineMode
Definition: pcb_actions.h:246
static TOOL_ACTION zoomTool
Definition: actions.h:102
void pcbnewUpdatePythonEnvVar(const wxString &aVar, const wxString &aValue)
Set an environment variable in the current Python interpreter.
EVT_UPDATE_UI(ID_LOAD_FOOTPRINT_FROM_BOARD, FOOTPRINT_EDIT_FRAME::OnUpdateLoadFootprintFromBoard) EVT_UPDATE_UI(ID_ADD_FOOTPRINT_TO_BOARD
static bool Idle(const SELECTION &aSelection)
Test if there no items selected or being edited.
ENUM_MAP & Undefined(T aValue)
Definition: property.h:523
PROJECT & Prj()
Definition: kicad.cpp:403
static SELECTION_CONDITION OnlyTypes(const KICAD_T aTypes[])
Create a functor that tests if the selected items are only of given types.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
static TOOL_ACTION zoneDisplayOutlines
Definition: pcb_actions.h:252
Control for copper zone opacity/visibility (color ignored)
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:145
void ActivateGalCanvas() override
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
Tool responsible for adding microwave features to PCBs.
void OnUpdateLayerSelectBox(wxUpdateUIEvent &aEvent)
void OnExportSTEP(wxCommandEvent &event)
Export the current BOARD to a STEP assembly.
void ResolveDRCExclusions()
Update markers to match recorded exclusions.
static TOOL_ACTION toggleLine45degMode
Toggle 45 degree line drawing mode.
Definition: pcb_actions.h:171
static TOOL_ACTION selectNet
Select all connections belonging to a single net.
Definition: pcb_actions.h:81
bool Contains(PCB_LAYER_ID aLayer)
See if the layer set contains a PCB layer.
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:38
void SetFileName(const std::string &aFileName)
Set the file name displayed in the title block.
Smd pad, appears on the solder paste layer (default)
static TOOL_ACTION routerTuneDiffPair
Activation of the Push and Shove router (diff pair tuning mode)
Definition: pcb_actions.h:194
static TOOL_ACTION drawAlignedDimension
Definition: pcb_actions.h:152
static constexpr GAL_TYPE GAL_FALLBACK
static TOOL_ACTION zoneDisplayDisable
Definition: pcb_actions.h:251
Tool relating to pads and pad settings.
Definition: pad_tool.h:35
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
static TOOL_ACTION drawOrthogonalDimension
Definition: pcb_actions.h:154
static TOOL_ACTION zoomFitScreen
Definition: actions.h:99
static TOOL_ACTION millimetersUnits
Definition: actions.h:149
static ENUM_MAP< T > & Instance()
Definition: property.h:510
The project local settings are things that are attached to a particular project, but also might be pa...
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
int GetPageCount() const
Definition: base_screen.h:76
LSET GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings Returns a bit-mask of all t...
Definition: board.cpp:461
static TOOL_ACTION drawPolygon
Definition: pcb_actions.h:147
#define ENABLE(x)
static TOOL_ACTION routerHighlightMode
Actions to enable switching modes via hotkey assignments.
Definition: pcb_actions.h:207
static TOOL_ACTION microwaveCreateLine
Definition: pcb_actions.h:419
BOARD_NETLIST_UPDATER class definition.
bool canCloseWindow(wxCloseEvent &aCloseEvent) override
NET_SETTINGS & NetSettings()
Definition: project_file.h:94
static TOOL_ACTION showPythonConsole
Definition: pcb_actions.h:349
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:368
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:462
void ExportToGenCAD(wxCommandEvent &event)
Create a file in GenCAD 1.4 format from the current board.
static TOOL_ACTION showLayersManager
Definition: pcb_actions.h:348
static TOOL_ACTION group
Definition: pcb_actions.h:427
void SetGridColor(COLOR4D aColor) override
void SetSheetCount(int aSheetCount)
Changes the sheet-count number displayed in the title block.
SELECTION_CONDITION RedoAvailable()
Create a functor that tests if there are any items in the redo queue.
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings Returns a bit-mask of all t...
Definition: board.cpp:447
bool FetchNetlistFromSchematic(NETLIST &aNetlist, const wxString &aAnnotateMessage)
PCB_LAYER_ID m_ActiveLayer
The current (active) board layer for editing.
SELECTION_CONDITION Line45degMode()
Create a functor that tests whether only 45 degree graphic lines should be drawn.
Manage TOOL_ACTION objects.
static TOOL_ACTION ungroup
Definition: pcb_actions.h:428
wxPGChoices & Choices()
Definition: property.h:559
static TOOL_ACTION localRatsnestTool
Definition: pcb_actions.h:459
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:81
static SELECTION_CONDITION Count(int aNumber)
Create a functor that tests if the number of selected items is equal to the value given as parameter.
void RecordDRCExclusions()
Scan existing markers and record data from any that are Excluded.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
All except INITIAL_ADD.
Definition: view_item.h:58
int ShowExchangeFootprintsDialog(FOOTPRINT *aFootprint, bool aUpdateMode, bool aSelectedMode)
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
const wxString & GetFileName() const
Definition: board.h:300
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
void SetSheetName(const std::string &aSheetName)
Set the sheet name displayed in the title block.
static wxWindow * findPythonConsole()
static SELECTION_CONDITION SameLayer()
Creates a functor that tests if selection contains items that belong exclusively to the same layer.
static TOOL_ACTION placeText
Definition: pcb_actions.h:151
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:64
static TOOL_ACTION zoneFill
Definition: pcb_actions.h:309
SELECTION_CONDITION PadFillDisplay()
Create a functor that tests if the frame fills the pads.
wxString GetLastPath(LAST_PATH_TYPE aType)
Get the last path for a particular type.
static void UnloadAll()
Unloads (deregisters) all action plugins.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Called after the preferences dialog is run.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
TRACE_CLEARANCE_DISPLAY_MODE_T m_ShowTrackClearanceMode
How trace clearances are displayed.
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition: project.h:151
static TOOL_ACTION routerTuneDiffPairSkew
Activation of the Push and Shove router (skew tuning mode)
Definition: pcb_actions.h:197
const wxString & GetPageNumber() const
Definition: base_screen.cpp:78
void ShowFootprintPropertiesDialog(FOOTPRINT *aFootprint)
bool isAutoSaveRequired() const override
Return true if the board has been modified.
void doCloseWindow() override
bool TestStandalone(void)
Test if standalone mode.
void SetShutdownBlockReason(wxWindow *aWindow, const wxString &aReason)
Sets the block reason why the window/application is preventing OS shutdown.
Definition: gtk/app.cpp:76
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
static TOOL_ACTION highlightNetTool
Definition: pcb_actions.h:452
Master controller class:
Definition: tool_manager.h:52
void SynchronizeNetsAndNetClasses()
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition: board.cpp:1436
void OnClearFileHistory(wxCommandEvent &aEvent)
static TOOL_ACTION measureTool
Definition: actions.h:157
static TOOL_ACTION copy
Definition: actions.h:70
EVT_MENU_RANGE(ID_POPUP_PCB_SELECT_WIDTH_START_RANGE, ID_POPUP_PCB_SELECT_WIDTH_END_RANGE, PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event) EVT_UPDATE_UI_RANGE(ID_POPUP_PCB_SELECT_WIDTH1
virtual void LoadNetlist() override
Function LoadNetlist loads the contents of the netlist file into aNetlist.
Container for display options like enable/disable some optional drawings.
PCB_LAYER_ID
A quick note on layer IDs:
void Tracks_and_Vias_Size_Event(wxCommandEvent &event)
Handle actions specific to filling copper zones.
All active tools.
Definition: tool_event.h:150
bool ExportBoardToHyperlynx(BOARD *aBoard, const wxFileName &aPath)
static TOOL_ACTION rotateCw
Rotation of selected objects.
Definition: pcb_actions.h:105
Item needs to be redrawn.
Definition: view_item.h:57
const wxString EESCHEMA_EXE
LSET is a set of PCB_LAYER_IDs.
void ShowBoardSetupDialog(const wxString &aInitialPage=wxEmptyString)
void ProjectChanged() override
Notification event that the project has changed.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
Definition: pcb_netlist.h:205
SELECTION_CONDITION GridVisible()
Create a functor testing if the grid is visible in a frame.
#define NULL
bool IsSingle() const
Is this KIFACE_I running under single_top?
Definition: kiface_i.h:104
bool IsContentModified() override
Get if the current board has been modified but not saved.
BOARD_ITEM_CONTAINER * GetModel() const override
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
SELECTION_CONDITION Units(EDA_UNITS aUnit)
Create a functor that tests if the frame has the specified units.
void RemoveListener(BOARD_LISTENER *aListener)
Remove the specified listener.
Definition: board.cpp:2023
wxString m_ActiveLayerPreset
The name of a LAYER_PRESET that is currently activated (or blank if none)
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:82
Tool responsible for drawing graphical elements like lines, arcs, circles, etc.
Definition: drawing_tool.h:50
static TOOL_ACTION toggleGrid
Definition: actions.h:143
Handle actions that are shared between different frames in PcbNew.
Definition: pcb_control.h:45
void onBoardLoaded()
Update the state of the GUI after a new board is loaded or created.
GAL_SET GetVisibleElements() const
Returns a set of all the element categories that are visible.
Definition: board.cpp:501
int ShowQuasiModal()
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:53
static TOOL_ACTION inchesUnits
Definition: actions.h:147
Handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:40
void ResolveNetClassAssignments(bool aRebuildFromScratch=false)
Explodes the list of netclass assignments to include atomic members of composite labels (buses).
static TOOL_ACTION save
Definition: actions.h:54
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Generic, UI-independent tool event.
Definition: tool_event.h:173
Inactive layers are shown normally (no high-contrast mode)
void ExportSVG(wxCommandEvent &event)
Show the Export to SVG file dialog.
wxString PyPluginsPath(bool aUserPath)
static TOOL_ACTION zoneMerge
Definition: pcb_actions.h:313
static TOOL_ACTION togglePolarCoords
Definition: actions.h:152
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:416
virtual ~PCB_EDIT_FRAME()
static TOOL_ACTION cut
Definition: actions.h:69
Handle actions specific to the board editor in PcbNew.
Definition of file extensions used in Kicad.
static const KICAD_T Zones[]
A scan list for zones outlines only.
Definition: collectors.h:273
void OnUpdateSelectAutoWidth(wxUpdateUIEvent &aEvent)
#define DIALOG_DRC_WINDOW_NAME
Definition: dialog_drc.h:41
static TOOL_ACTION showRatsnest
Definition: pcb_actions.h:245
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
COLOR4D GetGridColor() override
static TOOL_ACTION drawRectangle
Definition: pcb_actions.h:148
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
static TOOL_ACTION microwaveCreateGap
Definition: pcb_actions.h:411
wxLogTrace helper definitions.
static LSET AllLayersMask()
Definition: lset.cpp:787
void AddDelimiterString(wxString &string)
Add un " to the start and the end of string (if not already done).
Definition: gestfich.cpp:42
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)
Control the visibility of a particular layer.
Definition: view.h:387
static TOOL_ACTION drawVia
Definition: pcb_actions.h:157
bool SupportsShutdownBlockReason()
Whether or not the window supports setting a shutdown block reason.
Definition: gtk/app.cpp:65
const LIB_ID & GetFPID() const
Definition: footprint.h:190
#define KICAD_DEFAULT_DRAWFRAME_STYLE
std::function< bool(const SELECTION &)> SELECTION_CONDITION
< Functor type that checks a specific condition for selected items.
void BuildConnectivity()
Builds or rebuilds the board connectivity database for the board, especially the list of connected it...
Definition: board.cpp:133
void OnQuit(wxCommandEvent &event)
void UpdateUserInterface()
Update the layer manager and other widgets from the board setup (layer and items visibility,...
void PythonPluginsShowFolder()
Open the plugins folder in the default system file browser.
void PythonSyncEnvironmentVariables()
Synchronize the environment variables from KiCad's environment into the Python interpreter.
virtual void SetActiveLayer(PCB_LAYER_ID aLayer)
void SetFormat(PLOT_FORMAT aFormat)
std::shared_ptr< DRC_ENGINE > GetDRCEngine()
Definition: drc_tool.h:90
Global action (toolbar/main menu event, global shortcut)
Definition: tool_event.h:151
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104
PCB_PLOT_PARAMS handles plot parameters and options when plotting/printing a board.
static TOOL_ACTION drawZoneCutout
Definition: pcb_actions.h:159
Handle actions that are shared between different applications.
static TOOL_ACTION routerWalkaroundMode
Definition: pcb_actions.h:209
LAST_PATH_TYPE
For storing PcbNew MRU paths of various types.
Definition: project_file.h:46
The interactive edit tool.
Definition: edit_tool.h:64
static TOOL_ACTION placeTarget
Definition: pcb_actions.h:162
SELECTION_CONDITION ZoneDisplayMode(ZONE_DISPLAY_MODE aMode)
Create a functor that tests the current zone display mode in the frame.
Specialization of the wxAuiPaneInfo class for KiCad panels.
const std::string LegacySchematicFileExtension
SETTINGS_MANAGER * GetSettingsManager()
SELECTION_CONDITION PolarCoordinates()
Create a functor testing if polar coordinates are current being used.
void SetConditions(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions)
Set the conditions the UI elements for activating a specific tool action should use for determining t...
static TOOL_ACTION milsUnits
Definition: actions.h:148
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
static TOOL_ACTION boardSetup
Definition: pcb_actions.h:319
Handles action that are shared between different applications.
Definition: common_tools.h:37
void ClearProject()
Definition: board.cpp:169
bool IsDRCRunning() const
Check to see if the DRC engine is running the tests.
Definition: drc_tool.h:83
Generic tool for picking an item.
DIALOG_PLOT is the dialog to set the plot options, and create plot files in various formats.
Definition: dialog_plot.h:40
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
SELECTION_CONDITION NoActiveTool()
Create a functor testing if there are no tools active in the frame.
static TOOL_ACTION microwaveCreateStub
Definition: pcb_actions.h:413
static TOOL_ACTION zoneUnfill
Definition: pcb_actions.h:311
BOARD * GetBoard()
static TOOL_ACTION pasteSpecial
Definition: actions.h:72
#define CHECK(x)
static TOOL_ACTION padDisplayMode
Definition: pcb_actions.h:248
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition: board.cpp:507
static TOOL_ACTION rotateCcw
Definition: pcb_actions.h:106
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
static TOOL_ACTION drawCircle
Definition: pcb_actions.h:149
static TOOL_ACTION viaDisplayMode
Definition: pcb_actions.h:249
void SetProject(PROJECT *aProject)
Links a board to a given project.
Definition: board.cpp:139
static TOOL_ACTION zoneDuplicate
Duplicate zone onto another layer.
Definition: pcb_actions.h:316
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:73
void PythonPluginsReloadBase()
Helper function PythonPluginsReloadBase Reload Python plugins if they are newer than the already load...
Definition: pcbnew.cpp:310
void OnSockRequest(wxSocketEvent &evt)
Definition: eda_dde.cpp:70
static TOOL_ACTION redo
Definition: actions.h:68
virtual void OnModify()
Must be called after a change in order to set the "modify" flag of the current screen and update the ...
static TOOL_ACTION microwaveCreateFunctionShape
Definition: pcb_actions.h:417
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:296
virtual void ThemeChanged()
Process light/dark theme change.
Gather all the actions that are shared by tools.
Definition: pcb_actions.h:52
void OnFileHistory(wxCommandEvent &event)
static TOOL_ACTION placeFootprint
Definition: pcb_actions.h:164
static TOOL_ACTION showNet
Definition: pcb_actions.h:456
static TOOL_ACTION drawLeader
Definition: pcb_actions.h:155
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:118
Class PCBNEW_ACTION_PLUGINS.
static TOOL_ACTION drawRuleArea
Definition: pcb_actions.h:158
Ignore collisions, mark obstacles.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
see class PGM_BASE
Tool that displays edit points allowing to modify items by dragging the points.
void OnSelectGrid(wxCommandEvent &event)
Command event handler for selecting grid sizes.
void SetBoard(BOARD *aBoard) override
Declaration of the eda_3d_viewer class.
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
void PythonSyncProjectName()
Synchronize the project name from KiCad's environment into the Python interpreter.
static TOOL_ACTION highlightNet
Definition: pcb_actions.h:450
#define CURRENT_TOOL(action)
Common, abstract interface for edit frames.
void Process_Special_Functions(wxCommandEvent &event)
Definition: edit.cpp:47
virtual void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Changes the current rendering backend.
Only the zone outline is shown.
PCB_EDIT_FRAME::OnUpdateSelectTrackWidth EVT_UPDATE_UI_RANGE(ID_POPUP_PCB_SELECT_VIASIZE1, ID_POPUP_PCB_SELECT_VIASIZE8, PCB_EDIT_FRAME::OnUpdateSelectViaSize) PCB_EDIT_FRAME
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Set the work environment (model, view, view controls and the parent window).
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
void Files_io(wxCommandEvent &event)
Call Files_io_from_id with the wxCommandEvent id.
static TOOL_ACTION routeSingleTrack
Activation of the Push and Shove router.
Definition: pcb_actions.h:185
#define _(s)
Definition: 3d_actions.cpp:33
SELECTION_CONDITION UndoAvailable()
Create a functor that tests if there are any items in the undo queue.
virtual void SetBoard(BOARD *aBoard) override
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
void OnExportVRML(wxCommandEvent &event)
Export the current BOARD to a VRML file.
void OnUpdateSelectViaSize(wxUpdateUIEvent &aEvent)
Represent a single user action.
Definition: tool_action.h:49
static SELECTION_CONDITION OnlyType(KICAD_T aType)
Create a functor that tests if the selected items are only of given type.
const std::string KiCadSchematicFileExtension
The main frame for Pcbnew.
AUI_PANELS m_AuiPanels
void SaveColorSettings(COLOR_SETTINGS *aSettings, const std::string &aNamespace="")
Safely saves a COLOR_SETTINGS to disk, preserving any changes outside the given namespace.
The selection tool: currently supports:
#define IU_PER_MILS
Definition: plotter.cpp:137
SELECTION_CONDITION ViaFillDisplay()
Create a functor that tests if the frame fills vias.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:150
Only walk around.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Revert the commit by restoring the modified items state.
Tool useful for viewing footprints.
static TOOL_ACTION deselectNet
Remove all connections belonging to a single net from the active selection.
Definition: pcb_actions.h:84
bool InvokeExportSVG(PCB_EDIT_FRAME *aCaller, BOARD *aBoard)
Function InvokeExportSVG shows the Export SVG dialog.
virtual void SetPageSettings(const PAGE_INFO &aPageSettings) override
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:538
Definition: id.h:96
static TOOL_ACTION deleteTool
Definition: actions.h:76
void SetPageNumber(const std::string &aPageNumber)
Changes the page number displayed in the title block.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void onSize(wxSizeEvent &aEvent)
Definition: id.h:86
static SELECTION_CONDITION SameNet(bool aAllowUnconnected=false)
Create a functor that tests if selection contains items belonging to the same net or are unconnected ...
void OnUpdateSelectTrackWidth(wxUpdateUIEvent &aEvent)
static TOOL_ACTION undo
Definition: actions.h:67
#define PCB_EDIT_FRAME_NAME
void OnGridSettings(wxCommandEvent &event)
bool IsWxPythonLoaded()
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:105
static TOOL_ACTION flipBoard
Definition: pcb_actions.h:298
GERBVIEW_FRAME::OnZipFileHistory GERBVIEW_FRAME::OnSelectDisplayMode EVT_CHOICE(ID_GBR_AUX_TOOLBAR_PCB_APERATTRIBUTES_CHOICE, GERBVIEW_FRAME::OnSelectHighlightChoice) EVT_UPDATE_UI(ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER
Abstract interface for BOARD_ITEMs capable of storing other items inside.
static TOOL_ACTION gridSetOrigin
Definition: actions.h:140
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
bool IsElementVisible(GAL_LAYER_ID aElement) const
Test whether a given element category is visible.
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition: property.h:516
enum FP_PROPS_RETVALUE GetReturnValue()
Definition: pad.h:60
void ThemeChanged() override
Called when light/dark theme is changed.
std::set< wxString > m_DrcExclusions
void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType) override
Switch currently used canvas (Cairo / OpenGL).
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:237
ID_POPUP_PCB_SELECT_WIDTH8
wxString GetCurrentFileName() const override
Get the full filename + path of the currently opened file in the frame.
int ExecuteFile(wxWindow *frame, const wxString &ExecFile, const wxString &param, wxProcess *callback)
Call the executable file ExecFile with the command line parameters param.
Definition: gestfich.cpp:165
Group generic conditions for PCB editor states.
static TOOL_ACTION routerShoveMode
Definition: pcb_actions.h:208
static TOOL_ACTION highContrastMode
Definition: actions.h:106
void PythonPluginsReload()
Reload the Python plugins if they are newer than the already loaded, and load new plugins if any.
void OnDisplayOptionsChanged() override
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
static TOOL_ACTION selectAll
Definition: actions.h:73
void SetActiveLayer(PCB_LAYER_ID aLayer) override
Change the currently active layer to aLayer and also update the APPEARANCE_CONTROLS.
static TOOL_ACTION paste
Definition: actions.h:71
static TOOL_ACTION drawZone
Definition: pcb_actions.h:156
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
#define DLG_WINDOW_NAME
static TOOL_ACTION duplicate
Definition: actions.h:74
static TOOL_ACTION trackDisplayMode
Definition: pcb_actions.h:247
Definition: track.h:83
static TOOL_ACTION selectionTool
Definition: actions.h:156
void SetHasPosition(bool aHasPosition)
Returns if the action associated with this event should be treated as immediate regardless of the cur...
Definition: tool_event.h:262
virtual void OnSelectZoom(wxCommandEvent &event)
Set the zoom factor when selected by the zoom list box in the main tool bar.
void SetLastPath(LAST_PATH_TYPE aType, const wxString &aLastPath)
Set the path of the last file successfully read.
Tool responsible for automagic placement of components.
static TOOL_ACTION selectSameSheet
Select all components on the same sheet as the selected footprint.
Definition: pcb_actions.h:90
Container for design settings for a BOARD object.
KIWAY Kiway
Tool for pcb inspection.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98
static TOOL_ACTION zoneDisplayEnable
Definition: pcb_actions.h:250
static TOOL_ACTION routerTuneSingleTrace
Activation of the Push and Shove router (tune single line mode)
Definition: pcb_actions.h:191
static TOOL_ACTION routeDiffPair
Activation of the Push and Shove router (differential pair mode)
Definition: pcb_actions.h:188
bool Contains(GAL_LAYER_ID aPos)