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_base.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 <confirm.h>
32 #include <trace_helpers.h>
33 #include <pcbnew_id.h>
34 #include <pcbnew_settings.h>
35 #include <pcb_layer_box_selector.h>
36 #include <footprint_edit_frame.h>
37 #include <dialog_plot.h>
38 #include <dialog_find.h>
41 #include <dialog_board_setup.h>
42 #include <convert_to_biu.h>
43 #include <invoke_pcb_dialog.h>
44 #include <board.h>
45 #include <board_design_settings.h>
46 #include <footprint.h>
50 #include <pcb_draw_panel_gal.h>
51 #include <functional>
52 #include <pcb_painter.h>
53 #include <project/project_file.h>
55 #include <project/net_settings.h>
56 #include <python_scripting.h>
59 #include <tool/tool_manager.h>
60 #include <tool/tool_dispatcher.h>
61 #include <tool/action_toolbar.h>
62 #include <tool/common_control.h>
63 #include <tool/common_tools.h>
64 #include <tool/selection.h>
65 #include <tool/zoom_tool.h>
67 #include <tools/pcb_picker_tool.h>
68 #include <tools/pcb_point_editor.h>
69 #include <tools/edit_tool.h>
70 #include <tools/group_tool.h>
71 #include <tools/drc_tool.h>
72 #include <tools/global_edit_tool.h>
73 #include <tools/convert_tool.h>
74 #include <tools/drawing_tool.h>
75 #include <tools/pcb_control.h>
79 #include <tools/pcb_viewer_tools.h>
81 #include <tools/placement_tool.h>
82 #include <tools/pad_tool.h>
85 #include <tools/zone_filler_tool.h>
86 #include <tools/pcb_actions.h>
87 #include <router/router_tool.h>
91 #include <gestfich.h>
92 #include <executable_names.h>
96 #include <wx/socket.h>
97 #include <wx/wupdlock.h>
98 #include <dialog_drc.h> // for DIALOG_DRC_WINDOW_NAME definition
101 #include <widgets/infobar.h>
103 #include <widgets/wx_aui_utils.h>
104 #include <kiplatform/app.h>
105 
106 #include <action_plugin.h>
107 #include "../scripting/python_scripting.h"
108 
109 #include <wx/filedlg.h>
110 
111 
112 using namespace std::placeholders;
113 
114 
115 BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME )
118 
121 
122  EVT_SIZE( PCB_EDIT_FRAME::OnSize )
123 
125 
126  // Menu Files:
128 
132 
138 
141 
142  EVT_MENU( wxID_EXIT, PCB_EDIT_FRAME::OnQuit )
143  EVT_MENU( wxID_CLOSE, PCB_EDIT_FRAME::OnQuit )
144 
145  // menu Config
147 
148  // menu Postprocess
150 
151  // Horizontal toolbar
157 
158  // Tracks and vias sizes general options
161 
162  // User interface update event handlers.
168  PCB_EDIT_FRAME::OnUpdateSelectTrackWidth )
170  PCB_EDIT_FRAME::OnUpdateSelectViaSize )
171 END_EVENT_TABLE()
172 
173 
174 PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
175  PCB_BASE_EDIT_FRAME( aKiway, aParent, FRAME_PCB_EDITOR, wxT( "PCB Editor" ), wxDefaultPosition,
177  m_exportNetlistAction( nullptr ), m_findDialog( nullptr )
178 {
179  m_maximizeByDefault = true;
180  m_showBorderAndTitleBlock = true; // true to display sheet references
181  m_SelTrackWidthBox = nullptr;
182  m_SelViaSizeBox = nullptr;
183  m_SelLayerBox = nullptr;
184  m_show_layer_manager_tools = true;
185  m_hasAutoSave = true;
186 
187  // We don't know what state board was in when it was last saved, so we have to
188  // assume dirty
189  m_ZoneFillsDirty = true;
190 
191  m_rotationAngle = 900;
192  m_aboutTitle = _( "KiCad PCB Editor" );
193 
194  // Must be created before the menus are created.
195  if( ADVANCED_CFG::GetCfg().m_ShowPcbnewExportNetlist )
196  m_exportNetlistAction = new TOOL_ACTION( "pcbnew.EditorControl.exportNetlist",
197  AS_GLOBAL, 0, "", _( "Netlist..." ),
198  _( "Export netlist used to update schematics" ) );
199 
200  // Create GAL canvas
201  auto canvas = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize,
202  GetGalDisplayOptions(),
204 
205  SetCanvas( canvas );
206 
207  SetBoard( new BOARD() );
208 
209  wxIcon icon;
210  wxIconBundle icon_bundle;
211 
212  icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbnew ) );
213  icon_bundle.AddIcon( icon );
214  icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbnew_32 ) );
215  icon_bundle.AddIcon( icon );
216  icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbnew_16 ) );
217  icon_bundle.AddIcon( icon );
218 
219  SetIcons( icon_bundle );
220 
221  // LoadSettings() *after* creating m_LayersManager, because LoadSettings()
222  // initialize parameters in m_LayersManager
223  LoadSettings( config() );
224 
225  SetScreen( new PCB_SCREEN( GetPageSettings().GetSizeIU() ) );
226 
227  // PCB drawings start in the upper left corner.
228  GetScreen()->m_Center = false;
229 
230  setupTools();
231  setupUIConditions();
232 
233  ReCreateMenuBar();
234  ReCreateHToolbar();
235  ReCreateAuxiliaryToolbar();
236  ReCreateVToolbar();
237  ReCreateOptToolbar();
238 
239  m_selectionFilterPanel = new PANEL_SELECTION_FILTER( this );
240 
241  m_appearancePanel = new APPEARANCE_CONTROLS( this, GetCanvas() );
242 
243  m_auimgr.SetManagedWindow( this );
244 
245  CreateInfoBar();
246 
247  unsigned int auiFlags = wxAUI_MGR_DEFAULT;
248 #if !defined( _WIN32 )
249  // Windows cannot redraw the UI fast enough during a live resize and may lead to all kinds
250  // of graphical glitches.
251  auiFlags |= wxAUI_MGR_LIVE_RESIZE;
252 #endif
253  m_auimgr.SetFlags( auiFlags );
254 
255  // Rows; layers 4 - 6
256  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" )
257  .Top().Layer( 6 ) );
258  m_auimgr.AddPane( m_auxiliaryToolBar, EDA_PANE().HToolbar().Name( "AuxToolbar" )
259  .Top().Layer( 5 ) );
260  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" )
261  .Bottom().Layer( 6 ) );
262 
263  // Columns; layers 1 - 3
264  m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" )
265  .Left().Layer( 3 ) );
266 
267  m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" )
268  .Right().Layer( 3 ) );
269 
270  m_auimgr.AddPane( m_appearancePanel, EDA_PANE().Name( "LayersManager" )
271  .Right().Layer( 4 )
272  .Caption( _( "Appearance" ) ).PaneBorder( false )
273  .MinSize( 180, -1 ).BestSize( 180, -1 ) );
274 
275  m_auimgr.AddPane( m_selectionFilterPanel, EDA_PANE().Name( "SelectionFilter" )
276  .Right().Layer( 4 ).Position( 2 )
277  .Caption( _( "Selection Filter" ) ).PaneBorder( false )
278  .MinSize( 180, -1 ).BestSize( 180, -1 ) );
279 
280  // Center
281  m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" )
282  .Center() );
283 
284  m_auimgr.GetPane( "LayersManager" ).Show( m_show_layer_manager_tools );
285  m_auimgr.GetPane( "SelectionFilter" ).Show( m_show_layer_manager_tools );
286 
287  // The selection filter doesn't need to grow in the vertical direction when docked
288  m_auimgr.GetPane( "SelectionFilter" ).dock_proportion = 0;
289 
290  FinishAUIInitialization();
291 
292  if( PCBNEW_SETTINGS* settings = dynamic_cast<PCBNEW_SETTINGS*>( config() ) )
293  {
294  if( settings->m_AuiPanels.right_panel_width > 0 )
295  {
296  wxAuiPaneInfo& layersManager = m_auimgr.GetPane( "LayersManager" );
297  SetAuiPaneSize( m_auimgr, layersManager, settings->m_AuiPanels.right_panel_width, -1 );
298  }
299 
300  m_appearancePanel->SetTabIndex( settings->m_AuiPanels.appearance_panel_tab );
301  }
302 
303  GetToolManager()->RunAction( ACTIONS::zoomFitScreen, false );
304 
305  // This is used temporarily to fix a client size issue on GTK that causes zoom to fit
306  // to calculate the wrong zoom size. See PCB_EDIT_FRAME::onSize().
307  Bind( wxEVT_SIZE, &PCB_EDIT_FRAME::onSize, this );
308 
309  resolveCanvasType();
310 
311  setupUnits( config() );
312 
313  // Ensure the Python interpreter is up to date with its environment variables
314  PythonSyncEnvironmentVariables();
315  PythonSyncProjectName();
316 
317  GetCanvas()->SwitchBackend( m_canvasType );
318  ActivateGalCanvas();
319 
320  // Default shutdown reason until a file is loaded
321  KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New PCB file is unsaved" ) );
322 
323  // disable Export STEP item if kicad2step does not exist
324  wxString strK2S = Pgm().GetExecutablePath();
325 
326 #ifdef __WXMAC__
327  if( strK2S.Find( "pcbnew.app" ) != wxNOT_FOUND )
328  {
329  // On macOS, we have standalone applications inside the main bundle, so we handle that here:
330  strK2S += "../../";
331  }
332 
333  strK2S += "Contents/MacOS/";
334 #endif
335 
336  wxFileName appK2S( strK2S, "kicad2step" );
337 
338  #ifdef _WIN32
339  appK2S.SetExt( "exe" );
340  #endif
341 
342  // Ensure the window is on top
343  Raise();
344 
345 // if( !appK2S.FileExists() )
346  // GetMenuBar()->FindItem( ID_GEN_EXPORT_FILE_STEP )->Enable( false );
347 
348  // AUI doesn't refresh properly on wxMac after changes in eb7dc6dd, so force it to
349 #ifdef __WXMAC__
350  if( Kiface().IsSingle() )
351  {
352  CallAfter( [&]()
353  {
354  m_appearancePanel->OnBoardChanged();
355  } );
356  }
357 #endif
358 
359  // Register a call to update the toolbar sizes. It can't be done immediately because
360  // it seems to require some sizes calculated that aren't yet (at least on GTK).
361  CallAfter( [&]()
362  {
363  // Ensure the controls on the toolbars all are correctly sized
364  UpdateToolbarControlSizes();
365  } );
366 }
367 
368 
370 {
371  // Close modeless dialogs
372  wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_DRC_WINDOW_NAME );
373 
374  if( open_dlg )
375  open_dlg->Close( true );
376 
377  // Shutdown all running tools
378  if( m_toolManager )
379  m_toolManager->ShutdownAllTools();
380 
381  if( GetBoard() )
382  GetBoard()->RemoveListener( m_appearancePanel );
383 
384  delete m_selectionFilterPanel;
385  delete m_appearancePanel;
386  delete m_exportNetlistAction;
387 }
388 
389 
391 {
392  if( m_pcb )
393  m_pcb->ClearProject();
394 
396 
397  aBoard->SetProject( &Prj() );
398  aBoard->GetConnectivity()->Build( aBoard );
399 
400  // reload the drawing-sheet
401  SetPageSettings( aBoard->GetPageSettings() );
402 }
403 
404 
406 {
407  return m_pcb;
408 }
409 
410 
411 void PCB_EDIT_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
412 {
413  PCB_BASE_FRAME::SetPageSettings( aPageSettings );
414 
415  // Prepare drawing-sheet template
417  &m_pcb->GetPageSettings(),
418  m_pcb->GetProject(),
419  &m_pcb->GetTitleBlock() );
420  drawingSheet->SetSheetName( std::string( GetScreenDesc().mb_str() ) );
421 
422  BASE_SCREEN* screen = GetScreen();
423 
424  if( screen != nullptr )
425  {
426  drawingSheet->SetPageNumber(TO_UTF8( screen->GetPageNumber() ) );
427  drawingSheet->SetSheetCount( screen->GetPageCount() );
428  }
429 
430  if( BOARD* board = GetBoard() )
431  drawingSheet->SetFileName( TO_UTF8( board->GetFileName() ) );
432 
433  // PCB_DRAW_PANEL_GAL takes ownership of the drawing-sheet
434  GetCanvas()->SetDrawingSheet( drawingSheet );
435 }
436 
437 
439 {
440  return GetScreen() && GetScreen()->IsContentModified();
441 }
442 
443 
445 {
446  if( GetScreen() )
447  return GetScreen()->IsContentModified();
448 
449  return false;
450 }
451 
452 
454 {
455  return m_toolManager->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
456 }
457 
458 
460 {
461  // Create the manager and dispatcher & route draw panel events to the dispatcher
462  m_toolManager = new TOOL_MANAGER;
463  m_toolManager->SetEnvironment( m_pcb, GetCanvas()->GetView(),
464  GetCanvas()->GetViewControls(), config(), this );
465  m_actions = new PCB_ACTIONS();
466  m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
467 
468  // Register tools
469  m_toolManager->RegisterTool( new COMMON_CONTROL );
470  m_toolManager->RegisterTool( new COMMON_TOOLS );
471  m_toolManager->RegisterTool( new PCB_SELECTION_TOOL );
472  m_toolManager->RegisterTool( new ZOOM_TOOL );
473  m_toolManager->RegisterTool( new PCB_PICKER_TOOL );
474  m_toolManager->RegisterTool( new ROUTER_TOOL );
475  m_toolManager->RegisterTool( new LENGTH_TUNER_TOOL );
476  m_toolManager->RegisterTool( new EDIT_TOOL );
477  m_toolManager->RegisterTool( new GLOBAL_EDIT_TOOL );
478  m_toolManager->RegisterTool( new PAD_TOOL );
479  m_toolManager->RegisterTool( new DRAWING_TOOL );
480  m_toolManager->RegisterTool( new PCB_POINT_EDITOR );
481  m_toolManager->RegisterTool( new PCB_CONTROL );
482  m_toolManager->RegisterTool( new BOARD_EDITOR_CONTROL );
483  m_toolManager->RegisterTool( new BOARD_INSPECTION_TOOL );
484  m_toolManager->RegisterTool( new BOARD_REANNOTATE_TOOL );
485  m_toolManager->RegisterTool( new ALIGN_DISTRIBUTE_TOOL );
486  m_toolManager->RegisterTool( new MICROWAVE_TOOL );
487  m_toolManager->RegisterTool( new POSITION_RELATIVE_TOOL );
488  m_toolManager->RegisterTool( new ZONE_FILLER_TOOL );
489  m_toolManager->RegisterTool( new AUTOPLACE_TOOL );
490  m_toolManager->RegisterTool( new DRC_TOOL );
491  m_toolManager->RegisterTool( new PCB_VIEWER_TOOLS );
492  m_toolManager->RegisterTool( new CONVERT_TOOL );
493  m_toolManager->RegisterTool( new GROUP_TOOL );
494  m_toolManager->RegisterTool( new SCRIPTING_TOOL );
495  m_toolManager->InitTools();
496 
497  // Run the selection tool, it is supposed to be always active
498  m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
499 }
500 
501 
503 {
505 
506  ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
507  PCB_EDITOR_CONDITIONS cond( this );
508 
509  wxASSERT( mgr );
510 
511 #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
512 #define CHECK( x ) ACTION_CONDITIONS().Check( x )
513 
515  mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) );
516  mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
517 
524 
525  mgr->SetConditions( ACTIONS::cut, ENABLE( cond.HasItems() ) );
526  mgr->SetConditions( ACTIONS::copy, ENABLE( cond.HasItems() ) );
531  mgr->SetConditions( ACTIONS::selectAll, ENABLE( cond.HasItems() ) );
532  mgr->SetConditions( ACTIONS::doDelete, ENABLE( cond.HasItems() ) );
533  mgr->SetConditions( ACTIONS::duplicate, ENABLE( cond.HasItems() ) );
534 
535  auto haveAtLeastOneGroupCond =
536  []( const SELECTION& aSel )
537  {
538  for( EDA_ITEM* item : aSel )
539  {
540  if( item->Type() == PCB_GROUP_T )
541  return true;
542  }
543 
544  return false;
545  };
546 
550  mgr->SetConditions( PCB_ACTIONS::ungroup, ENABLE( haveAtLeastOneGroupCond ) );
551  mgr->SetConditions( PCB_ACTIONS::lock, ENABLE( cond.HasItems() ) );
553 
557 
558  if( SCRIPTING::IsWxAvailable() )
560 
561  auto enableZoneControlConition =
562  [this] ( const SELECTION& )
563  {
565  && GetDisplayOptions().m_ZoneOpacity > 0.0;
566  };
567 
569  ENABLE( enableZoneControlConition ).Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_FILLED ) ) );
571  ENABLE( enableZoneControlConition ).Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_ZONE_OUTLINE ) ) );
573  ENABLE( enableZoneControlConition ).Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_FRACTURE_BORDERS ) ) );
575  ENABLE( enableZoneControlConition ).Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_TRIANGULATION ) ) );
576 
577  auto enableBoardSetupCondition =
578  [this] ( const SELECTION& )
579  {
580  if( DRC_TOOL* tool = m_toolManager->GetTool<DRC_TOOL>() )
581  return !tool->IsDRCDialogShown();
582 
583  return true;
584  };
585 
586  auto boardFlippedCond =
587  [this]( const SELECTION& )
588  {
589  return GetCanvas()->GetView()->IsMirroredX();
590  };
591 
592  auto layerManagerCond =
593  [this] ( const SELECTION& )
594  {
595  return LayerManagerShown();
596  };
597 
598  auto highContrastCond =
599  [this] ( const SELECTION& )
600  {
601  return GetDisplayOptions().m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL;
602  };
603 
604  auto globalRatsnestCond =
605  [this] (const SELECTION& )
606  {
607  return GetDisplayOptions().m_ShowGlobalRatsnest;
608  };
609 
610  auto curvedRatsnestCond =
611  [this] (const SELECTION& )
612  {
613  return GetDisplayOptions().m_DisplayRatsnestLinesCurved;
614  };
615 
616  auto netHighlightCond =
617  [this]( const SELECTION& )
618  {
619  KIGFX::RENDER_SETTINGS* settings = GetCanvas()->GetView()->GetPainter()->GetSettings();
620  return !settings->GetHighlightNetCodes().empty();
621  };
622 
623  auto enableNetHighlightCond =
624  [this]( const SELECTION& )
625  {
626  BOARD_INSPECTION_TOOL* tool = m_toolManager->GetTool<BOARD_INSPECTION_TOOL>();
627  return tool->IsNetHighlightSet();
628  };
629 
630  mgr->SetConditions( ACTIONS::highContrastMode, CHECK( highContrastCond ) );
631  mgr->SetConditions( PCB_ACTIONS::flipBoard, CHECK( boardFlippedCond ) );
632  mgr->SetConditions( PCB_ACTIONS::showLayersManager, CHECK( layerManagerCond ) );
633  mgr->SetConditions( PCB_ACTIONS::showRatsnest, CHECK( globalRatsnestCond ) );
634  mgr->SetConditions( PCB_ACTIONS::ratsnestLineMode, CHECK( curvedRatsnestCond ) );
636  CHECK( netHighlightCond ).Enable( enableNetHighlightCond ) );
637  mgr->SetConditions( PCB_ACTIONS::boardSetup , ENABLE( enableBoardSetupCondition ) );
638 
639 
640  auto isHighlightMode =
641  [this]( const SELECTION& )
642  {
643  ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
644  return tool->GetRouterMode() == PNS::RM_MarkObstacles;
645  };
646 
647  auto isShoveMode =
648  [this]( const SELECTION& )
649  {
650  ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
651  return tool->GetRouterMode() == PNS::RM_Shove;
652  };
653 
654  auto isWalkaroundMode =
655  [this]( const SELECTION& )
656  {
657  ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
658  return tool->GetRouterMode() == PNS::RM_Walkaround;
659  };
660 
661  mgr->SetConditions( PCB_ACTIONS::routerHighlightMode, CHECK( isHighlightMode ) );
662  mgr->SetConditions( PCB_ACTIONS::routerShoveMode, CHECK( isShoveMode ) );
663  mgr->SetConditions( PCB_ACTIONS::routerWalkaroundMode, CHECK( isWalkaroundMode ) );
664 
665  auto haveNetCond =
666  [] ( const SELECTION& aSel )
667  {
668  for( EDA_ITEM* item : aSel )
669  {
670  if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
671  {
672  if( bci->GetNetCode() > 0 )
673  return true;
674  }
675  }
676 
677  return false;
678  };
679 
680  mgr->SetConditions( PCB_ACTIONS::showNet, ENABLE( haveNetCond ) );
681  mgr->SetConditions( PCB_ACTIONS::hideNet, ENABLE( haveNetCond ) );
682  mgr->SetConditions( PCB_ACTIONS::highlightNet, ENABLE( haveNetCond ) );
683 
690 
691 
692  SELECTION_CONDITION singleZoneCond = SELECTION_CONDITIONS::Count( 1 ) &&
694 
698 
699  mgr->SetConditions( PCB_ACTIONS::zoneDuplicate, ENABLE( singleZoneCond ) );
700  mgr->SetConditions( PCB_ACTIONS::drawZoneCutout, ENABLE( singleZoneCond ) );
701  mgr->SetConditions( PCB_ACTIONS::drawSimilarZone, ENABLE( singleZoneCond ) );
702  mgr->SetConditions( PCB_ACTIONS::zoneMerge, ENABLE( zoneMergeCond ) );
705 
707 
708 #define CURRENT_TOOL( action ) mgr->SetConditions( action, CHECK( cond.CurrentTool( action ) ) )
709 
710  // These tools can be used at any time to inspect the board
715 
716 
717  auto isDrcRunning =
718  [this] ( const SELECTION& )
719  {
720  DRC_TOOL* tool = m_toolManager->GetTool<DRC_TOOL>();
721  return !tool->IsDRCRunning();
722  };
723 
724 #define CURRENT_EDIT_TOOL( action ) mgr->SetConditions( action, ACTION_CONDITIONS().Check( cond.CurrentTool( action ) ).Enable( isDrcRunning ) )
725 
726  // These tools edit the board, so they must be disabled during some operations
750 
756 
757 #undef CURRENT_TOOL
758 #undef CURRENT_EDIT_TOOL
759 #undef ENABLE
760 #undef CHECK
761 }
762 
763 
764 void PCB_EDIT_FRAME::OnQuit( wxCommandEvent& event )
765 {
766  if( event.GetId() == wxID_EXIT )
767  Kiway().OnKiCadExit();
768 
769  if( event.GetId() == wxID_CLOSE || Kiface().IsSingle() )
770  Close( false );
771 }
772 
773 
775 {
777  bds.m_DrcExclusions.clear();
778 
779  for( PCB_MARKER* marker : GetBoard()->Markers() )
780  {
781  if( marker->IsExcluded() )
782  bds.m_DrcExclusions.insert( marker->Serialize() );
783  }
784 }
785 
786 
788 {
789  BOARD_COMMIT commit( this );
790 
791  for( PCB_MARKER* marker : GetBoard()->ResolveDRCExclusions() )
792  commit.Add( marker );
793 
794  commit.Push( wxEmptyString, false, false );
795 
796  for( PCB_MARKER* marker : GetBoard()->Markers() )
797  {
798  if( marker->IsExcluded() )
799  {
800  GetCanvas()->GetView()->Remove( marker );
801  GetCanvas()->GetView()->Add( marker );
802  }
803  }
804 }
805 
806 
807 bool PCB_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
808 {
809  // Shutdown blocks must be determined and vetoed as early as possible
810  if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION
811  && IsContentModified() )
812  {
813  return false;
814  }
815 
816  if( IsContentModified() )
817  {
818  wxFileName fileName = GetBoard()->GetFileName();
819  wxString msg = _( "Save changes to '%s' before closing?" );
820 
821  if( !HandleUnsavedChanges( this, wxString::Format( msg, fileName.GetFullName() ),
822  [&]() -> bool
823  {
824  return Files_io_from_id( ID_SAVE_BOARD );
825  } ) )
826  {
827  return false;
828  }
829  }
830 
831  // Close modeless dialogs. They're trouble when they get destroyed after the frame and/or
832  // board.
833  wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_DRC_WINDOW_NAME );
834 
835  if( open_dlg )
836  open_dlg->Close( true );
837 
838  return PCB_BASE_EDIT_FRAME::canCloseWindow( aEvent );
839 }
840 
841 
843 {
844  // On Windows 7 / 32 bits, on OpenGL mode only, Pcbnew crashes
845  // when closing this frame if a footprint was selected, and the footprint editor called
846  // to edit this footprint, and when closing pcbnew if this footprint is still selected
847  // See https://bugs.launchpad.net/kicad/+bug/1655858
848  // I think this is certainly a OpenGL event fired after frame deletion, so this workaround
849  // avoid the crash (JPC)
850  GetCanvas()->SetEvtHandlerEnabled( false );
851 
852  GetCanvas()->StopDrawing();
853 
854  // Delete the auto save file if it exists.
855  wxFileName fn = GetBoard()->GetFileName();
856 
857  // Auto save file name is the normal file name prefixed with 'GetAutoSaveFilePrefix()'.
858  fn.SetName( GetAutoSaveFilePrefix() + fn.GetName() );
859 
860  // When the auto save feature does not have write access to the board file path, it falls
861  // back to a platform specific user temporary file path.
862  if( !fn.IsOk() || !fn.IsDirWritable() )
863  fn.SetPath( wxFileName::GetTempDir() );
864 
865  wxLogTrace( traceAutoSave, "Deleting auto save file <" + fn.GetFullPath() + ">" );
866 
867  // Remove the auto save file on a normal close of Pcbnew.
868  if( fn.FileExists() && !wxRemoveFile( fn.GetFullPath() ) )
869  {
870  wxString msg = wxString::Format( _( "The auto save file '%s' could not be removed!" ),
871  fn.GetFullPath() );
872  wxMessageBox( msg, Pgm().App().GetAppName(), wxOK | wxICON_ERROR, this );
873  }
874 
875  // Make sure local settings are persisted
876  SaveProjectSettings();
877 
878  // Do not show the layer manager during closing to avoid flicker
879  // on some platforms (Windows) that generate useless redraw of items in
880  // the Layer Manager
881  if( m_show_layer_manager_tools )
882  m_auimgr.GetPane( "LayersManager" ).Show( false );
883 
884  // Unlink the old project if needed
885  GetBoard()->ClearProject();
886 
887  // Delete board structs and undo/redo lists, to avoid crash on exit
888  // when deleting some structs (mainly in undo/redo lists) too late
889  Clear_Pcb( false, true );
890 
891  // do not show the window because ScreenPcb will be deleted and we do not
892  // want any paint event
893  Show( false );
894 
896 }
897 
898 
900 {
902  GetCanvas()->UpdateColors();
903  GetCanvas()->Refresh();
904 }
905 
906 
907 void PCB_EDIT_FRAME::ShowBoardSetupDialog( const wxString& aInitialPage )
908 {
909  // Make sure everything's up-to-date
911 
912  DIALOG_BOARD_SETUP dlg( this );
913 
914  if( !aInitialPage.IsEmpty() )
915  dlg.SetInitialPage( aInitialPage, wxEmptyString );
916 
917  if( dlg.ShowQuasiModal() == wxID_OK )
918  {
920 
922  SaveProjectSettings();
923 
924  Kiway().CommonSettingsChanged( false, true );
925 
926  const PCB_DISPLAY_OPTIONS& opts = GetDisplayOptions();
927 
929  {
930  // Update clearance outlines
931  GetCanvas()->GetView()->UpdateAllItemsConditionally( KIGFX::REPAINT,
932  [&]( KIGFX::VIEW_ITEM* aItem ) -> bool
933  {
934  PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( aItem );
935  PAD* pad = dynamic_cast<PAD*>( aItem );
936 
937  // PCB_TRACK is the base class of PCB_VIA and PCB_ARC so we don't need
938  // to check them independently
939 
940  return ( track && opts.m_ShowTrackClearanceMode )
941  || ( pad && opts.m_DisplayPadClearance );
942  } );
943  }
944 
945  GetCanvas()->Refresh();
946 
948  ReCreateAuxiliaryToolbar();
949  m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
950 
951  //this event causes the routing tool to reload its design rules information
953  toolEvent.SetHasPosition( false );
954  m_toolManager->ProcessEvent( toolEvent );
955  }
956 
957  GetCanvas()->SetFocus();
958 }
959 
960 
962 {
964 
965  PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
966  wxASSERT( cfg );
967 
968  if( cfg )
969  {
970  m_rotationAngle = cfg->m_RotationAngle;
971  m_show_layer_manager_tools = cfg->m_AuiPanels.show_layer_manager;
972  m_showPageLimits = cfg->m_ShowPageLimits;
973  }
974 }
975 
976 
978 {
980 
981  auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
982  wxASSERT( cfg );
983 
984  if( cfg )
985  {
986  cfg->m_RotationAngle = m_rotationAngle;
987  cfg->m_AuiPanels.show_layer_manager = m_show_layer_manager_tools;
988  cfg->m_AuiPanels.right_panel_width = m_appearancePanel->GetSize().x;
989  cfg->m_AuiPanels.appearance_panel_tab = m_appearancePanel->GetTabIndex();
990  cfg->m_ShowPageLimits = m_showPageLimits;
991  }
992 
993  GetSettingsManager()->SaveColorSettings( GetColorSettings(), "board" );
994 }
995 
996 
998 {
999  return GetColorSettings()->GetColor( LAYER_GRID );
1000 }
1001 
1002 
1004 {
1005 
1006  GetColorSettings()->SetColor( LAYER_GRID, aColor );
1007  GetCanvas()->GetGAL()->SetGridColor( aColor );
1008 }
1009 
1010 
1012 {
1013  PCB_LAYER_ID oldLayer = GetActiveLayer();
1014 
1015  if( oldLayer == aLayer )
1016  return;
1017 
1019 
1020  m_appearancePanel->OnLayerChanged();
1021 
1022  m_toolManager->RunAction( PCB_ACTIONS::layerChanged ); // notify other tools
1023  GetCanvas()->SetFocus(); // allow capture of hotkeys
1024  GetCanvas()->SetHighContrastLayer( aLayer );
1025 
1026  GetCanvas()->GetView()->UpdateAllItemsConditionally( KIGFX::REPAINT,
1027  [&]( KIGFX::VIEW_ITEM* aItem ) -> bool
1028  {
1029  if( PCB_VIA* via = dynamic_cast<PCB_VIA*>( aItem ) )
1030  {
1031  // Vias on a restricted layer set must be redrawn when the active layer
1032  // is changed
1033  return ( via->GetViaType() == VIATYPE::BLIND_BURIED ||
1034  via->GetViaType() == VIATYPE::MICROVIA );
1035  }
1036  else if( PAD* pad = dynamic_cast<PAD*>( aItem ) )
1037  {
1038  // Clearances could be layer-dependent so redraw them when the active layer
1039  // is changed
1040  if( GetDisplayOptions().m_DisplayPadClearance )
1041  {
1042  // Round-corner rects are expensive to draw, but are mostly found on
1043  // SMD pads which only need redrawing on an active-to-not-active
1044  // switch.
1045  if( pad->GetAttribute() == PAD_ATTRIB::SMD )
1046  {
1047  if( ( oldLayer == F_Cu || aLayer == F_Cu ) && pad->IsOnLayer( F_Cu ) )
1048  return true;
1049 
1050  if( ( oldLayer == B_Cu || aLayer == B_Cu ) && pad->IsOnLayer( B_Cu ) )
1051  return true;
1052  }
1053 
1054  return true;
1055  }
1056  }
1057  else if( PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( aItem ) )
1058  {
1059  // Clearances could be layer-dependent so redraw them when the active layer
1060  // is changed
1061  if( GetDisplayOptions().m_ShowTrackClearanceMode )
1062  {
1063  // Tracks aren't particularly expensive to draw, but it's an easy check.
1064  return track->IsOnLayer( oldLayer ) || track->IsOnLayer( aLayer );
1065  }
1066  }
1067 
1068  return false;
1069  } );
1070 
1071  GetCanvas()->Refresh();
1072 }
1073 
1074 
1076 {
1077  // JEY TODO: move this global to the board
1079 
1080  layerEnum.Choices().Clear();
1081  layerEnum.Undefined( UNDEFINED_LAYER );
1082 
1083  for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
1084  {
1085  // Canonical name
1086  layerEnum.Map( *seq, LSET::Name( *seq ) );
1087 
1088  // User name
1089  layerEnum.Map( *seq, GetBoard()->GetLayerName( *seq ) );
1090  }
1091 
1092  DRC_TOOL* drcTool = m_toolManager->GetTool<DRC_TOOL>();
1093 
1094  try
1095  {
1096  drcTool->GetDRCEngine()->InitEngine( GetDesignRulesPath() );
1097  }
1098  catch( PARSE_ERROR& )
1099  {
1100  // Not sure this is the best place to tell the user their rules are buggy, so
1101  // we'll stay quiet for now. Feel free to revisit this decision....
1102  }
1103 
1104  UpdateTitle();
1105 
1106  wxFileName fn = GetBoard()->GetFileName();
1107 
1108  // Display a warning that the file is read only
1109  if( fn.FileExists() && !fn.IsFileWritable() )
1110  {
1111  m_infoBar->RemoveAllButtons();
1112  m_infoBar->AddCloseButton();
1113  m_infoBar->ShowMessage( _( "Board file is read only." ), wxICON_WARNING );
1114  }
1115 
1116  ReCreateLayerBox();
1117 
1118  // Sync layer and item visibility
1119  GetCanvas()->SyncLayersVisibility( m_pcb );
1120 
1121  SetElementVisibility( LAYER_RATSNEST, GetDisplayOptions().m_ShowGlobalRatsnest );
1122 
1123  m_appearancePanel->OnBoardChanged();
1124 
1125  // Apply saved display state to the appearance panel after it has been set up
1126  PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
1127 
1128  m_appearancePanel->ApplyLayerPreset( localSettings.m_ActiveLayerPreset );
1129 
1130  if( GetBoard()->GetDesignSettings().IsLayerEnabled( localSettings.m_ActiveLayer ) )
1131  SetActiveLayer( localSettings.m_ActiveLayer );
1132 
1133  // Updates any auto dimensions and the auxiliary toolbar tracks/via sizes
1134  unitsChangeRefresh();
1135 
1136  // Display the loaded board:
1137  Zoom_Automatique( false );
1138 
1139  // Invalidate painting as loading the DRC engine will cause clearances to become valid
1140  GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL );
1141 
1142  Refresh();
1143 
1144  SetMsgPanel( GetBoard() );
1145  SetStatusText( wxEmptyString );
1146 
1147  KIPLATFORM::APP::SetShutdownBlockReason( this, _( "PCB file changes are unsaved" ) );
1148 }
1149 
1150 
1152 {
1153  m_appearancePanel->UpdateDisplayOptions();
1154 }
1155 
1156 
1158 {
1159  return GetBoard()->IsElementVisible( aElement );
1160 }
1161 
1162 
1163 void PCB_EDIT_FRAME::SetElementVisibility( GAL_LAYER_ID aElement, bool aNewState )
1164 {
1165  // Force the RATSNEST visible
1166  if( aElement == LAYER_RATSNEST )
1167  GetCanvas()->GetView()->SetLayerVisible( aElement, true );
1168  else
1169  GetCanvas()->GetView()->SetLayerVisible( aElement , aNewState );
1170 
1171  GetBoard()->SetElementVisibility( aElement, aNewState );
1172 }
1173 
1174 
1176 {
1177  // call my base class
1179 
1180  wxAuiPaneInfo& pane_info = m_auimgr.GetPane( m_appearancePanel );
1181  pane_info.Caption( _( "Appearance" ) );
1182  m_auimgr.Update();
1183 
1184  m_appearancePanel->OnBoardChanged();
1185 }
1186 
1187 
1189 {
1191 
1192  if( project.m_PcbLastPath[ aType ].IsEmpty() )
1193  return wxEmptyString;
1194 
1195  wxFileName absoluteFileName = project.m_PcbLastPath[ aType ];
1196  wxFileName pcbFileName = GetBoard()->GetFileName();
1197 
1198  absoluteFileName.MakeAbsolute( pcbFileName.GetPath() );
1199  return absoluteFileName.GetFullPath();
1200 }
1201 
1202 
1203 void PCB_EDIT_FRAME::SetLastPath( LAST_PATH_TYPE aType, const wxString& aLastPath )
1204 {
1206 
1207  wxFileName relativeFileName = aLastPath;
1208  wxFileName pcbFileName = GetBoard()->GetFileName();
1209 
1210  relativeFileName.MakeRelativeTo( pcbFileName.GetPath() );
1211 
1212  if( relativeFileName.GetFullPath() != project.m_PcbLastPath[ aType ] )
1213  {
1214  project.m_PcbLastPath[ aType ] = relativeFileName.GetFullPath();
1215  SaveProjectSettings();
1216  }
1217 }
1218 
1219 
1221 {
1223 
1224  Update3DView( true, GetDisplayOptions().m_Live3DRefresh );
1225 
1226  if( !GetTitle().StartsWith( "*" ) )
1227  UpdateTitle();
1228 
1229  m_ZoneFillsDirty = true;
1230 }
1231 
1232 
1234 {
1235  Update3DView( true, true );
1236 }
1237 
1238 
1239 void PCB_EDIT_FRAME::ExportSVG( wxCommandEvent& event )
1240 {
1241  InvokeExportSVG( this, GetBoard() );
1242 }
1243 
1244 
1246 {
1247  wxFileName fn = GetBoard()->GetFileName();
1248  bool readOnly = false;
1249  bool unsaved = false;
1250 
1251  if( fn.IsOk() && fn.FileExists() )
1252  readOnly = !fn.IsFileWritable();
1253  else
1254  unsaved = true;
1255 
1256  wxString title;
1257 
1258  if( IsContentModified() )
1259  title = wxT( "*" );
1260 
1261  title += fn.GetName();
1262 
1263  if( readOnly )
1264  title += wxS( " " ) + _( "[Read Only]" );
1265 
1266  if( unsaved )
1267  title += wxS( " " ) + _( "[Unsaved]" );
1268 
1269  title += wxT( " \u2014 " ) + _( "PCB Editor" );
1270 
1271  SetTitle( title );
1272 }
1273 
1274 
1276 {
1277  // Update the layer manager and other widgets from the board setup
1278  // (layer and items visibility, colors ...)
1279 
1280  // Rebuild list of nets (full ratsnest rebuild)
1282  Compile_Ratsnest( true );
1283 
1284  // Update info shown by the horizontal toolbars
1285  ReCreateLayerBox();
1286 
1287  LSET activeLayers = GetBoard()->GetEnabledLayers();
1288 
1289  if( !activeLayers.test( GetActiveLayer() ) )
1290  SetActiveLayer( activeLayers.Seq().front() );
1291 
1292  m_SelLayerBox->SetLayerSelection( GetActiveLayer() );
1293 
1295 
1296  layerEnum.Choices().Clear();
1297  layerEnum.Undefined( UNDEFINED_LAYER );
1298 
1299  for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
1300  {
1301  // Canonical name
1302  layerEnum.Map( *seq, LSET::Name( *seq ) );
1303 
1304  // User name
1305  layerEnum.Map( *seq, GetBoard()->GetLayerName( *seq ) );
1306  }
1307 
1308  // Sync visibility with canvas
1309  KIGFX::VIEW* view = GetCanvas()->GetView();
1310  LSET visible = GetBoard()->GetVisibleLayers();
1311 
1312  for( PCB_LAYER_ID layer : LSET::AllLayersMask().Seq() )
1313  view->SetLayerVisible( layer, visible.Contains( layer ) );
1314 
1315  // Stackup and/or color theme may have changed
1316  m_appearancePanel->OnBoardChanged();
1317 }
1318 
1319 
1321 {
1322  // switches currently used canvas (Cairo / OpenGL).
1323  PCB_BASE_FRAME::SwitchCanvas( aCanvasType );
1324 }
1325 
1326 
1328 {
1329  if( !m_findDialog )
1330  {
1331  m_findDialog = new DIALOG_FIND( this );
1332  m_findDialog->SetCallback( std::bind( &PCB_SELECTION_TOOL::FindItem,
1333  m_toolManager->GetTool<PCB_SELECTION_TOOL>(), _1 ) );
1334  }
1335 
1336  m_findDialog->Show( true );
1337 }
1338 
1339 
1341 {
1342  if( !m_findDialog )
1343  {
1344  m_findDialog = new DIALOG_FIND( this );
1345  m_findDialog->SetCallback( std::bind( &PCB_SELECTION_TOOL::FindItem,
1346  m_toolManager->GetTool<PCB_SELECTION_TOOL>(), _1 ) );
1347  }
1348 
1349  m_findDialog->FindNext();
1350 }
1351 
1352 
1354 {
1355  PCB_PLOT_PARAMS plotSettings = GetPlotSettings();
1356 
1357  switch( aID )
1358  {
1359  case ID_GEN_PLOT_GERBER:
1360  plotSettings.SetFormat( PLOT_FORMAT::GERBER );
1361  break;
1362  case ID_GEN_PLOT_DXF:
1363  plotSettings.SetFormat( PLOT_FORMAT::DXF );
1364  break;
1365  case ID_GEN_PLOT_HPGL:
1366  plotSettings.SetFormat( PLOT_FORMAT::HPGL );
1367  break;
1368  case ID_GEN_PLOT_PDF:
1369  plotSettings.SetFormat( PLOT_FORMAT::PDF );
1370  break;
1371  case ID_GEN_PLOT_PS:
1372  plotSettings.SetFormat( PLOT_FORMAT::POST );
1373  break;
1374  case ID_GEN_PLOT: /* keep the previous setup */ break;
1375  default:
1376  wxFAIL_MSG( "ToPlotter(): unexpected plot type" ); break;
1377  break;
1378  }
1379 
1380  SetPlotSettings( plotSettings );
1381 
1382  // Force rebuild the dialog if currently open because the old dialog can be not up to date
1383  // if the board (or units) has changed
1384  wxWindow* dlg = wxWindow::FindWindowByName( DLG_WINDOW_NAME );
1385 
1386  if( dlg )
1387  dlg->Destroy();
1388 
1389  dlg = new DIALOG_PLOT( this );
1390  dlg->Show( true );
1391 }
1392 
1393 
1395 {
1396  if( Kiface().IsSingle() )
1397  return false;
1398 
1399  // Update PCB requires a netlist. Therefore the schematic editor must be running
1400  // If this is not the case, open the schematic editor
1401  KIWAY_PLAYER* frame = Kiway().Player( FRAME_SCH, true );
1402 
1403  if( !frame->IsShown() )
1404  {
1405  wxFileName fn( Prj().GetProjectPath(), Prj().GetProjectName(),
1407 
1408  // Maybe the file hasn't been converted to the new s-expression file format so
1409  // see if the legacy schematic file is still in play.
1410  if( !fn.FileExists() )
1411  {
1412  fn.SetExt( LegacySchematicFileExtension );
1413 
1414  if( !fn.FileExists() )
1415  {
1416  DisplayError( this, _( "The schematic for this board cannot be found." ) );
1417  return false;
1418  }
1419  }
1420 
1421  frame->OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ) );
1422 
1423  // we show the schematic editor frame, because do not show is seen as
1424  // a not yet opened schematic by Kicad manager, which is not the case
1425  frame->Show( true );
1426 
1427  // bring ourselves back to the front
1428  Raise();
1429  }
1430 
1431  return true; //Success!
1432 }
1433 
1434 
1436  const wxString& aAnnotateMessage )
1437 {
1438  if( !TestStandalone() )
1439  {
1440  DisplayErrorMessage( this, _( "Cannot update the PCB because PCB editor is opened in "
1441  "stand-alone mode. In order to create or update PCBs from "
1442  "schematics, you must launch the KiCad project manager and "
1443  "create a project." ) );
1444  return false; // Not in standalone mode
1445  }
1446 
1447  Raise(); // Show
1448 
1449  std::string payload( aAnnotateMessage );
1450 
1451  Kiway().ExpressMail( FRAME_SCH, MAIL_SCH_GET_NETLIST, payload, this );
1452 
1453  if( payload == aAnnotateMessage )
1454  {
1455  Raise();
1456  DisplayErrorMessage( this, aAnnotateMessage );
1457  return false;
1458  }
1459 
1460  try
1461  {
1462  auto lineReader = new STRING_LINE_READER( payload, _( "Eeschema netlist" ) );
1463  KICAD_NETLIST_READER netlistReader( lineReader, &aNetlist );
1464  netlistReader.LoadNetlist();
1465  }
1466  catch( const IO_ERROR& e )
1467  {
1468  Raise();
1469 
1470  // Do not translate extra_info strings. These are for developers
1471  wxString extra_info = e.Problem() + " : " + e.What() + " at " + e.Where();
1472 
1473  DisplayErrorMessage( this, _( "Received an error while reading netlist. Please "
1474  "report this issue to the KiCad team using the menu "
1475  "Help->Report Bug."), extra_info );
1476  return false;
1477  }
1478 
1479  return true;
1480 }
1481 
1482 
1484 {
1485  wxString msg;
1486  wxFileName schematic( Prj().GetProjectPath(), Prj().GetProjectName(),
1488 
1489  if( !schematic.FileExists() )
1490  {
1491  wxFileName legacySchematic( Prj().GetProjectPath(), Prj().GetProjectName(),
1493 
1494  if( legacySchematic.FileExists() )
1495  {
1496  schematic = legacySchematic;
1497  }
1498  else
1499  {
1500  msg.Printf( _( "Schematic file '%s' not found." ), schematic.GetFullPath() );
1501  wxMessageBox( msg, _( "KiCad Error" ), wxOK | wxICON_ERROR, this );
1502  return;
1503  }
1504  }
1505 
1506  if( Kiface().IsSingle() )
1507  {
1508  ExecuteFile( EESCHEMA_EXE, schematic.GetFullPath() );
1509  }
1510  else
1511  {
1512  KIWAY_PLAYER* frame = Kiway().Player( FRAME_SCH, false );
1513 
1514  // Please: note: DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::initBuffers() calls
1515  // Kiway.Player( FRAME_SCH, true )
1516  // therefore, the schematic editor is sometimes running, but the schematic project
1517  // is not loaded, if the library editor was called, and the dialog field editor was used.
1518  // On Linux, it happens the first time the schematic editor is launched, if
1519  // library editor was running, and the dialog field editor was open
1520  // On Windows, it happens always after the library editor was called,
1521  // and the dialog field editor was used
1522  if( !frame )
1523  {
1524  try
1525  {
1526  frame = Kiway().Player( FRAME_SCH, true );
1527  }
1528  catch( const IO_ERROR& err )
1529  {
1530  wxMessageBox( _( "Eeschema failed to load." ) + wxS( "\n" ) + err.What(),
1531  _( "KiCad Error" ), wxOK | wxICON_ERROR, this );
1532  return;
1533  }
1534  }
1535 
1536  if( !frame->IsShown() ) // the frame exists, (created by the dialog field editor)
1537  // but no project loaded.
1538  {
1539  frame->OpenProjectFiles( std::vector<wxString>( 1, schematic.GetFullPath() ) );
1540  frame->Show( true );
1541  }
1542 
1543  // On Windows, Raise() does not bring the window on screen, when iconized or not shown
1544  // On Linux, Raise() brings the window on screen, but this code works fine
1545  if( frame->IsIconized() )
1546  {
1547  frame->Iconize( false );
1548  // If an iconized frame was created by Pcbnew, Iconize( false ) is not enough
1549  // to show the frame at its normal size: Maximize should be called.
1550  frame->Maximize( false );
1551  }
1552 
1553  frame->Raise();
1554  }
1555 }
1556 
1557 
1559 {
1560  const ENV_VAR_MAP& vars = Pgm().GetLocalEnvVariables();
1561 
1562  // Set the environment variables for python scripts
1563  // note: the string will be encoded UTF8 for python env
1564  for( auto& var : vars )
1565  UpdatePythonEnvVar( var.first, var.second.GetValue() );
1566 
1567  // Because the env vars can be modified by the python scripts (rewritten in UTF8),
1568  // regenerate them (in Unicode) for our normal environment
1569  for( auto& var : vars )
1570  wxSetEnv( var.first, var.second.GetValue() );
1571 }
1572 
1573 
1575 {
1576  wxString evValue;
1577  wxGetEnv( PROJECT_VAR_NAME, &evValue );
1578  UpdatePythonEnvVar( wxString( PROJECT_VAR_NAME ).ToStdString(), evValue );
1579 
1580  // Because PROJECT_VAR_NAME can be modified by the python scripts (rewritten in UTF8),
1581  // regenerate it (in Unicode) for our normal environment
1582  wxSetEnv( PROJECT_VAR_NAME, evValue );
1583 }
1584 
1585 
1587 {
1588  if( aFootprint == nullptr )
1589  return;
1590 
1592 
1593  /*
1594  * Make sure dlg is destroyed before GetCanvas->Refresh is called
1595  * later or the refresh will try to modify its properties since
1596  * they share a GL context.
1597  */
1598  {
1599  DIALOG_FOOTPRINT_PROPERTIES dlg( this, aFootprint );
1600 
1601  // We use quasi modal to allow displaying help dialogs.
1602  dlg.ShowQuasiModal();
1603  retvalue = dlg.GetReturnValue();
1604  }
1605 
1606  /*
1607  * retvalue =
1608  * FP_PROPS_UPDATE_FP to show Update Footprints dialog
1609  * FP_PROPS_CHANGE_FP to show Change Footprints dialog
1610  * FP_PROPS_OK for normal edit
1611  * FP_PROPS_CANCEL if aborted
1612  * FP_PROPS_EDIT_BOARD_FP to load board footprint into Footprint Editor
1613  * FP_PROPS_EDIT_LIBRARY_FP to load library footprint into Footprint Editor
1614  */
1615 
1617  {
1618  // If something edited, push a refresh request
1619  GetCanvas()->Refresh();
1620  }
1622  {
1624 
1625  editor->LoadFootprintFromBoard( aFootprint );
1626 
1627  editor->Show( true );
1628  editor->Raise(); // Iconize( false );
1629  }
1630 
1632  {
1634 
1635  editor->LoadFootprintFromLibrary( aFootprint->GetFPID() );
1636 
1637  editor->Show( true );
1638  editor->Raise(); // Iconize( false );
1639  }
1640 
1642  {
1643  ShowExchangeFootprintsDialog( aFootprint, true, true );
1644  }
1645 
1647  {
1648  ShowExchangeFootprintsDialog( aFootprint, false, true );
1649  }
1650 }
1651 
1652 
1653 int PCB_EDIT_FRAME::ShowExchangeFootprintsDialog( FOOTPRINT* aFootprint, bool aUpdateMode,
1654  bool aSelectedMode )
1655 {
1656  DIALOG_EXCHANGE_FOOTPRINTS dialog( this, aFootprint, aUpdateMode, aSelectedMode );
1657 
1658  return dialog.ShowQuasiModal();
1659 }
1660 
1661 
1662 void PCB_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
1663 {
1664  PCB_BASE_EDIT_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
1665 
1666  GetAppearancePanel()->OnColorThemeChanged();
1667 
1668  // Netclass definitions could have changed, either by us or by Eeschema
1669  DRC_TOOL* drcTool = m_toolManager->GetTool<DRC_TOOL>();
1670  WX_INFOBAR* infobar = GetInfoBar();
1671 
1672  try
1673  {
1674  drcTool->GetDRCEngine()->InitEngine( GetDesignRulesPath() );
1675 
1676  if( infobar->GetMessageType() == WX_INFOBAR::MESSAGE_TYPE::DRC_RULES_ERROR )
1677  infobar->Dismiss();
1678  }
1679  catch( PARSE_ERROR& )
1680  {
1681  wxHyperlinkCtrl* button = new wxHyperlinkCtrl( infobar, wxID_ANY, _( "Edit design rules" ),
1682  wxEmptyString );
1683 
1684  button->Bind( wxEVT_COMMAND_HYPERLINK, std::function<void( wxHyperlinkEvent& aEvent )>(
1685  [&]( wxHyperlinkEvent& aEvent )
1686  {
1687  ShowBoardSetupDialog( _( "Custom Rules" ) );
1688  } ) );
1689 
1690  infobar->RemoveAllButtons();
1691  infobar->AddButton( button );
1692  infobar->AddCloseButton();
1693  infobar->ShowMessage( _( "Could not compile custom design rules." ), wxICON_ERROR,
1695  }
1696 
1697  // Update the environment variables in the Python interpreter
1698  if( aEnvVarsChanged )
1699  PythonSyncEnvironmentVariables();
1700 
1701  Layout();
1702  SendSizeEvent();
1703 }
1704 
1705 
1707 {
1709 }
1710 
1711 
1713 {
1714  PythonSyncProjectName();
1715 }
1716 
1717 
1718 bool ExportBoardToHyperlynx( BOARD* aBoard, const wxFileName& aPath );
1719 
1720 
1721 void PCB_EDIT_FRAME::OnExportHyperlynx( wxCommandEvent& event )
1722 {
1723  wxString wildcard = wxT( "*.hyp" );
1724  wxFileName fn = GetBoard()->GetFileName();
1725 
1726  fn.SetExt( wxT("hyp") );
1727 
1728  wxFileDialog dlg( this, _( "Export Hyperlynx Layout" ), fn.GetPath(), fn.GetFullName(),
1729  wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
1730 
1731  if( dlg.ShowModal() != wxID_OK )
1732  return;
1733 
1734  fn = dlg.GetPath();
1735 
1736  // always enforce filename extension, user may not have entered it.
1737  fn.SetExt( wxT( "hyp" ) );
1738 
1740 }
1741 
1742 
1744 {
1745  return GetBoard()->GetFileName();
1746 }
1747 
1748 
1750 {
1751  return m_auimgr.GetPane( "LayersManager" ).IsShown();
1752 }
1753 
1754 
1755 void PCB_EDIT_FRAME::onSize( wxSizeEvent& aEvent )
1756 {
1757  if( IsShown() )
1758  {
1759  // We only need this until the frame is done resizing and the final client size is
1760  // established.
1761  Unbind( wxEVT_SIZE, &PCB_EDIT_FRAME::onSize, this );
1762  GetToolManager()->RunAction( ACTIONS::zoomFitScreen, true );
1763  }
1764 
1765  // Skip() is called in the base class.
1766  EDA_DRAW_FRAME::OnSize( aEvent );
1767 }
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:279
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:142
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:118
static TOOL_ACTION drawCenterDimension
Definition: pcb_actions.h:149
void BuildListOfNets()
Definition: board.h:658
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:239
#define CURRENT_EDIT_TOOL(action)
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:64
virtual void ShowChangedLanguage() override
Redraw the menus and what not in current language.
const PAGE_INFO & GetPageSettings() const
Definition: board.h:535
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:626
static TOOL_ACTION unlock
Definition: pcb_actions.h:425
PNS::PNS_MODE GetRouterMode()
void SetElementVisibility(GAL_LAYER_ID aLayer, bool aNewState)
Change the visibility of an element category.
Definition: board.cpp:539
static const KICAD_T Tracks[]
A scan list for only TRACKs.
Definition: collectors.h:298
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.
Read the new s-expression based KiCad netlist format.
bool canCloseWindow(wxCloseEvent &aCloseEvent) override
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
bool IsContentModified() const override
Get if the current board has been modified but not saved.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:292
const wxChar *const traceAutoSave
Flag to enable auto save feature debug tracing.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void SetAuiPaneSize(wxAuiManager &aManager, wxAuiPaneInfo &aPane, int aWidth, int aHeight)
Sets the size of an AUI pane, working around http://trac.wxwidgets.org/ticket/13180.
Model changes (required full reload)
Definition: tool_base.h:80
static TOOL_ACTION drawSimilarZone
Definition: pcb_actions.h:156
static TOOL_ACTION drillOrigin
Definition: pcb_actions.h:438
SELECTION_CONDITION HasItems()
Create a functor that tests if there are items in the board.
static TOOL_ACTION lock
Definition: pcb_actions.h:424
This file is part of the common library.
static TOOL_ACTION doDelete
Definition: actions.h:72
void HardRedraw() override
Rebuild the GAL and redraws the screen.
static TOOL_ACTION drawArc
Definition: pcb_actions.h:146
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.
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
static TOOL_ACTION hideNet
Definition: pcb_actions.h:456
SELECTION_CONDITION FullscreenCursor()
Create a functor testing if the cursor is full screen in a frame.
Definition: id.h:87
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
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:414
COMMIT & Add(EDA_ITEM *aItem)
Notify observers that aItem has been added.
Definition: commit.h:78
void SetInitialPage(const wxString &aPage, const wxString &aParentPage=wxEmptyString)
void doCloseWindow() override
static TOOL_ACTION ratsnestLineMode
Definition: pcb_actions.h:239
static TOOL_ACTION zoomTool
Definition: actions.h:99
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.
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.
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
Definition: layer_ids.h:185
void ResolveDRCExclusions()
Update markers to match recorded exclusions.
static TOOL_ACTION selectNet
Select all connections belonging to a single net.
Definition: pcb_actions.h:77
bool Contains(PCB_LAYER_ID aLayer)
See if the layer set contains a PCB layer.
Definition: layer_ids.h:575
#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:187
static TOOL_ACTION drawAlignedDimension
Definition: pcb_actions.h:148
static constexpr GAL_TYPE GAL_FALLBACK
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:150
static TOOL_ACTION zoomFitScreen
Definition: actions.h:96
static TOOL_ACTION millimetersUnits
Definition: actions.h:146
The project local settings are things that are attached to a particular project, but also might be pa...
static ENUM_MAP< T > & Instance()
Definition: property.h:510
int GetPageCount() const
Definition: base_screen.h:72
LSET GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
Definition: board.cpp:481
static TOOL_ACTION drawPolygon
Definition: pcb_actions.h:143
#define ENABLE(x)
static TOOL_ACTION routerHighlightMode
Actions to enable switching modes via hotkey assignments.
Definition: pcb_actions.h:200
static TOOL_ACTION microwaveCreateLine
Definition: pcb_actions.h:418
bool canCloseWindow(wxCloseEvent &aCloseEvent) override
NET_SETTINGS & NetSettings()
Definition: project_file.h:94
static TOOL_ACTION showPythonConsole
Definition: pcb_actions.h:348
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:383
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:477
void ExportToGenCAD(wxCommandEvent &event)
Create a file in GenCAD 1.4 format from the current board.
static TOOL_ACTION showLayersManager
Definition: pcb_actions.h:347
static TOOL_ACTION group
Definition: pcb_actions.h:428
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.
Definition: board.cpp:467
bool FetchNetlistFromSchematic(NETLIST &aNetlist, const wxString &aAnnotateMessage)
PCB_LAYER_ID m_ActiveLayer
The current (active) board layer for editing.
Manage TOOL_ACTION objects.
void RebuildNetClassAssignments()
Rebuild netclass assignments from the netclass membership lists.
static TOOL_ACTION ungroup
Definition: pcb_actions.h:429
void FindItem(BOARD_ITEM *aItem)
Handle finding an item.
wxPGChoices & Choices()
Definition: property.h:559
static TOOL_ACTION localRatsnestTool
Definition: pcb_actions.h:460
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:76
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:53
static TOOL_ACTION zoneDisplayFilled
Definition: pcb_actions.h:245
int ShowExchangeFootprintsDialog(FOOTPRINT *aFootprint, bool aUpdateMode, bool aSelectedMode)
Tool relating to pads and pad settings.
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:228
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual const wxString Problem() const
what was the problem?
Definition: exceptions.cpp:46
int ExecuteFile(const wxString &aEditorName, const wxString &aFileName, wxProcess *aCallback)
Call the executable file aEditorName with the parameter aFileName.
Definition: gestfich.cpp:114
void SetSheetName(const std::string &aSheetName)
Set the sheet name displayed in the title block.
virtual const wxString Where() const
where did the Problem() occur?
Definition: exceptions.cpp:40
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
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:147
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:64
static TOOL_ACTION zoneFill
Definition: pcb_actions.h:304
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.
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.
Control for copper zone opacity/visibility (color ignored)
Definition: layer_ids.h:227
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:190
static TOOL_ACTION toggleNetHighlight
Definition: pcb_actions.h:453
const wxString & GetPageNumber() const
Definition: base_screen.cpp:71
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:83
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
void SetGridColor(const COLOR4D &aColor) override
Master controller class:
Definition: tool_manager.h:54
void SynchronizeNetsAndNetClasses()
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition: board.cpp:1391
void OnClearFileHistory(wxCommandEvent &aEvent)
static TOOL_ACTION measureTool
Definition: actions.h:154
static TOOL_ACTION copy
Definition: actions.h:67
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
Load the contents of the netlist file into aNetlist.
static TOOL_ACTION zoneDisplayFractured
Definition: pcb_actions.h:247
Container for display options like enable/disable some optional drawings.
void Tracks_and_Vias_Size_Event(wxCommandEvent &event)
Handle actions specific to filling copper zones.
bool ExportBoardToHyperlynx(BOARD *aBoard, const wxFileName &aPath)
static TOOL_ACTION rotateCw
Rotation of selected objects.
Definition: pcb_actions.h:101
Item needs to be redrawn.
Definition: view_item.h:52
const wxString EESCHEMA_EXE
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:504
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:206
SELECTION_CONDITION GridVisible()
Create a functor testing if the grid is visible in a frame.
BOARD_ITEM_CONTAINER * GetModel() const override
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
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:1967
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
SELECTION_CONDITION Get45degMode()
Create a functor that tests whether only 45 degree lines should be allowed.
static TOOL_ACTION toggleGrid
Definition: actions.h:140
Handle actions that are shared between different frames in PcbNew.
Definition: pcb_control.h:46
void onBoardLoaded()
Update the state of the GUI after a new board is loaded or created.
GAL_SET GetVisibleElements() const
Return a set of all the element categories that are visible.
Definition: board.cpp:527
virtual void OnSize(wxSizeEvent &event) override
Recalculate the size of toolbars and display panel when the frame size changes.
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:144
Handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:40
static TOOL_ACTION save
Definition: actions.h:51
Generic, UI-independent tool event.
Definition: tool_event.h:152
Inactive layers are shown normally (no high-contrast mode)
void ExportSVG(wxCommandEvent &event)
Show the Export to SVG file dialog.
static TOOL_ACTION zoneMerge
Definition: pcb_actions.h:308
SELECTION_CONDITION ScriptingConsoleVisible()
Create a functor testing if the python scripting console window is visible.
static TOOL_ACTION togglePolarCoords
Definition: actions.h:149
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:344
virtual ~PCB_EDIT_FRAME()
void OnSockRequest(wxSocketEvent &evt)
Definition: eda_dde.cpp:63
static TOOL_ACTION cut
Definition: actions.h:66
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:272
void OnUpdateSelectAutoWidth(wxUpdateUIEvent &aEvent)
#define DIALOG_DRC_WINDOW_NAME
Definition: dialog_drc.h:41
static TOOL_ACTION showRatsnest
Definition: pcb_actions.h:238
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
COLOR4D GetGridColor() override
static TOOL_ACTION drawRectangle
Definition: pcb_actions.h:144
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
#define _(s)
static TOOL_ACTION microwaveCreateGap
Definition: pcb_actions.h:410
wxLogTrace helper definitions.
static LSET AllLayersMask()
Definition: lset.cpp:787
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition: view.h:388
static TOOL_ACTION drawVia
Definition: pcb_actions.h:153
bool SupportsShutdownBlockReason()
Whether or not the window supports setting a shutdown block reason.
Definition: gtk/app.cpp:72
const LIB_ID & GetFPID() const
Definition: footprint.h:194
#define KICAD_DEFAULT_DRAWFRAME_STYLE
std::function< bool(const SELECTION &)> SELECTION_CONDITION
< Functor type that checks a specific condition for selected items.
void BuildConnectivity()
Build or rebuild the board connectivity database for the board, especially the list of connected item...
Definition: board.cpp:137
void OnQuit(wxCommandEvent &event)
void UpdateUserInterface()
Update the layer manager and other widgets from the board setup (layer and items visibility,...
void PythonSyncEnvironmentVariables()
Synchronize the environment variables from KiCad's environment into the Python interpreter.
virtual void SetActiveLayer(PCB_LAYER_ID aLayer)
static TOOL_ACTION zoneDisplayTriangulated
Definition: pcb_actions.h:248
void SetFormat(PLOT_FORMAT aFormat)
std::shared_ptr< DRC_ENGINE > GetDRCEngine()
Definition: drc_tool.h:78
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:105
Parameters and options when plotting/printing a board.
static TOOL_ACTION drawZoneCutout
Definition: pcb_actions.h:155
Handle actions that are shared between different applications.
static TOOL_ACTION routerWalkaroundMode
Definition: pcb_actions.h:202
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:158
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:145
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: layer_ids.h:465
static TOOL_ACTION boardSetup
Definition: pcb_actions.h:318
Handles action that are shared between different applications.
Definition: common_tools.h:37
void ClearProject()
Definition: board.cpp:173
bool IsDRCRunning() const
Check to see if the DRC engine is running the tests.
Definition: drc_tool.h:71
Generic tool for picking an item.
A dialog to set the plot options and create plot files in various formats.
Definition: dialog_plot.h:39
void OnSockRequestServer(wxSocketEvent &evt)
Definition: eda_dde.cpp:93
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
static TOOL_ACTION zoneDisplayOutline
Definition: pcb_actions.h:246
SELECTION_CONDITION NoActiveTool()
Create a functor testing if there are no tools active in the frame.
static TOOL_ACTION microwaveCreateStub
Definition: pcb_actions.h:412
static TOOL_ACTION zoneUnfill
Definition: pcb_actions.h:306
BOARD * GetBoard()
static TOOL_ACTION pasteSpecial
Definition: actions.h:69
#define CHECK(x)
static TOOL_ACTION padDisplayMode
Definition: pcb_actions.h:243
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition: board.cpp:533
static TOOL_ACTION rotateCcw
Definition: pcb_actions.h:102
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:145
static TOOL_ACTION viaDisplayMode
Definition: pcb_actions.h:244
void SetProject(PROJECT *aProject)
Link a board to a given project.
Definition: board.cpp:143
static TOOL_ACTION zoneDuplicate
Duplicate zone onto another layer.
Definition: pcb_actions.h:311
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:73
static TOOL_ACTION redo
Definition: actions.h:65
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:416
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:291
virtual void ThemeChanged()
Process light/dark theme change.
Gather all the actions that are shared by tools.
Definition: pcb_actions.h:48
void OnFileHistory(wxCommandEvent &event)
static TOOL_ACTION placeFootprint
Definition: pcb_actions.h:160
static TOOL_ACTION showNet
Definition: pcb_actions.h:457
static TOOL_ACTION drawLeader
Definition: pcb_actions.h:151
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:154
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
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:451
#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.
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
Global action (toolbar/main menu event, global shortcut)
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:178
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
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.
Definition: layer_ids.h:71
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:67
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:136
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:100
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:80
bool InvokeExportSVG(PCB_EDIT_FRAME *aCaller, BOARD *aBoard)
Function InvokeExportSVG shows the Export SVG dialog.
virtual void SetPageSettings(const PAGE_INFO &aPageSettings) override
void ShowFindDialog()
Show the Find dialog.
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Call CommonSettingsChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:554
Definition: id.h:96
static TOOL_ACTION deleteTool
Definition: actions.h:73
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 FindNext()
Find the next item using our existing search parameters.
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:64
#define PCB_EDIT_FRAME_NAME
void OnGridSettings(wxCommandEvent &event)
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:102
const std::set< int > & GetHighlightNetCodes() const
Return the netcode of currently highlighted net.
static TOOL_ACTION flipBoard
Definition: pcb_actions.h:293
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:137
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
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:57
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:240
ID_POPUP_PCB_SELECT_WIDTH8
wxString GetCurrentFileName() const override
Get the full filename + path of the currently opened file in the frame.
Group generic conditions for PCB editor states.
static TOOL_ACTION routerShoveMode
Definition: pcb_actions.h:201
static TOOL_ACTION highContrastMode
Definition: actions.h:103
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:70
static TOOL_ACTION toggle45
Definition: pcb_actions.h:420
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:68
static TOOL_ACTION drawZone
Definition: pcb_actions.h:152
bool IsSingle() const
Is this KIFACE running under single_top?
Definition: kiface_base.h:104
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
#define DLG_WINDOW_NAME
static TOOL_ACTION duplicate
Definition: actions.h:71
static TOOL_ACTION trackDisplayMode
Definition: pcb_actions.h:242
static TOOL_ACTION selectionTool
Definition: actions.h:153
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:241
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:86
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:103
static TOOL_ACTION routerTuneSingleTrace
Activation of the Push and Shove router (tune single line mode)
Definition: pcb_actions.h:184
static TOOL_ACTION routeDiffPair
Activation of the Push and Shove router (differential pair mode)
Definition: pcb_actions.h:181
bool Contains(GAL_LAYER_ID aPos)
Definition: layer_ids.h:313