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 <[email protected]>
6  * Copyright (C) 2013 Wayne Stambaugh <[email protected]>
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 #include <profile.h>
106 #include <view/wx_view_controls.h>
107 #include <footprint_viewer_frame.h>
108 
109 #include <action_plugin.h>
110 #include "../scripting/python_scripting.h"
111 
112 #include <wx/filedlg.h>
113 
114 
115 using namespace std::placeholders;
116 
117 
118 BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME )
121 
124 
125  EVT_SIZE( PCB_EDIT_FRAME::OnSize )
126 
128 
129  // Menu Files:
131 
135 
141 
144 
145  EVT_MENU( wxID_EXIT, PCB_EDIT_FRAME::OnQuit )
146  EVT_MENU( wxID_CLOSE, PCB_EDIT_FRAME::OnQuit )
147 
148  // menu Config
150 
151  // menu Postprocess
153 
154  // Horizontal toolbar
160 
161  // Tracks and vias sizes general options
164 
165  // User interface update event handlers.
171  PCB_EDIT_FRAME::OnUpdateSelectTrackWidth )
173  PCB_EDIT_FRAME::OnUpdateSelectViaSize )
174 END_EVENT_TABLE()
175 
176 
177 PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
178  PCB_BASE_EDIT_FRAME( aKiway, aParent, FRAME_PCB_EDITOR, _( "PCB Editor" ), wxDefaultPosition,
180  m_exportNetlistAction( nullptr ), m_findDialog( nullptr )
181 {
182  m_maximizeByDefault = true;
183  m_showBorderAndTitleBlock = true; // true to display sheet references
184  m_SelTrackWidthBox = nullptr;
185  m_SelViaSizeBox = nullptr;
186  m_SelLayerBox = nullptr;
187  m_show_layer_manager_tools = true;
188  m_hasAutoSave = true;
189 
190  // We don't know what state board was in when it was last saved, so we have to
191  // assume dirty
192  m_ZoneFillsDirty = true;
193 
194  m_rotationAngle = 900;
195  m_aboutTitle = _( "KiCad PCB Editor" );
196 
197  // Must be created before the menus are created.
198  if( ADVANCED_CFG::GetCfg().m_ShowPcbnewExportNetlist )
199  m_exportNetlistAction = new TOOL_ACTION( "pcbnew.EditorControl.exportNetlist",
200  AS_GLOBAL, 0, "", _( "Netlist..." ),
201  _( "Export netlist used to update schematics" ) );
202 
203  // Create GAL canvas
204  auto canvas = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize,
205  GetGalDisplayOptions(),
207 
208  SetCanvas( canvas );
209 
210  SetBoard( new BOARD() );
211 
212  wxIcon icon;
213  wxIconBundle icon_bundle;
214 
215  icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbnew ) );
216  icon_bundle.AddIcon( icon );
217  icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbnew_32 ) );
218  icon_bundle.AddIcon( icon );
219  icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbnew_16 ) );
220  icon_bundle.AddIcon( icon );
221 
222  SetIcons( icon_bundle );
223 
224  // LoadSettings() *after* creating m_LayersManager, because LoadSettings()
225  // initialize parameters in m_LayersManager
226  LoadSettings( config() );
227 
228  SetScreen( new PCB_SCREEN( GetPageSettings().GetSizeIU() ) );
229 
230  // PCB drawings start in the upper left corner.
231  GetScreen()->m_Center = false;
232 
233  setupTools();
234  setupUIConditions();
235 
236  ReCreateMenuBar();
237  ReCreateHToolbar();
238  ReCreateAuxiliaryToolbar();
239  ReCreateVToolbar();
240  ReCreateOptToolbar();
241 
242  m_selectionFilterPanel = new PANEL_SELECTION_FILTER( this );
243 
244  m_appearancePanel = new APPEARANCE_CONTROLS( this, GetCanvas() );
245 
246  m_auimgr.SetManagedWindow( this );
247 
248  CreateInfoBar();
249 
250  unsigned int auiFlags = wxAUI_MGR_DEFAULT;
251 #if !defined( _WIN32 )
252  // Windows cannot redraw the UI fast enough during a live resize and may lead to all kinds
253  // of graphical glitches.
254  auiFlags |= wxAUI_MGR_LIVE_RESIZE;
255 #endif
256  m_auimgr.SetFlags( auiFlags );
257 
258  // Rows; layers 4 - 6
259  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" )
260  .Top().Layer( 6 ) );
261  m_auimgr.AddPane( m_auxiliaryToolBar, EDA_PANE().HToolbar().Name( "AuxToolbar" )
262  .Top().Layer( 5 ) );
263  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" )
264  .Bottom().Layer( 6 ) );
265 
266  // Columns; layers 1 - 3
267  m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" )
268  .Left().Layer( 3 ) );
269 
270  m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" )
271  .Right().Layer( 3 ) );
272 
273  m_auimgr.AddPane( m_appearancePanel, EDA_PANE().Name( "LayersManager" )
274  .Right().Layer( 4 )
275  .Caption( _( "Appearance" ) ).PaneBorder( false )
276  .MinSize( 180, -1 ).BestSize( 180, -1 ) );
277 
278  m_auimgr.AddPane( m_selectionFilterPanel, EDA_PANE().Name( "SelectionFilter" )
279  .Right().Layer( 4 ).Position( 2 )
280  .Caption( _( "Selection Filter" ) ).PaneBorder( false )
281  .MinSize( 180, -1 ).BestSize( 180, -1 ) );
282 
283  // Center
284  m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" )
285  .Center() );
286 
287  m_auimgr.GetPane( "LayersManager" ).Show( m_show_layer_manager_tools );
288  m_auimgr.GetPane( "SelectionFilter" ).Show( m_show_layer_manager_tools );
289 
290  // The selection filter doesn't need to grow in the vertical direction when docked
291  m_auimgr.GetPane( "SelectionFilter" ).dock_proportion = 0;
292 
293  FinishAUIInitialization();
294 
295  if( PCBNEW_SETTINGS* settings = dynamic_cast<PCBNEW_SETTINGS*>( config() ) )
296  {
297  if( settings->m_AuiPanels.right_panel_width > 0 )
298  {
299  wxAuiPaneInfo& layersManager = m_auimgr.GetPane( "LayersManager" );
300  SetAuiPaneSize( m_auimgr, layersManager, settings->m_AuiPanels.right_panel_width, -1 );
301  }
302 
303  m_appearancePanel->SetTabIndex( settings->m_AuiPanels.appearance_panel_tab );
304  }
305 
306  GetToolManager()->RunAction( ACTIONS::zoomFitScreen, false );
307 
308  // This is used temporarily to fix a client size issue on GTK that causes zoom to fit
309  // to calculate the wrong zoom size. See PCB_EDIT_FRAME::onSize().
310  Bind( wxEVT_SIZE, &PCB_EDIT_FRAME::onSize, this );
311 
312  resolveCanvasType();
313 
314  setupUnits( config() );
315 
316  // Ensure the Python interpreter is up to date with its environment variables
317  PythonSyncEnvironmentVariables();
318  PythonSyncProjectName();
319 
320  // Sync action plugins in case they changed since the last time the frame opened
321  GetToolManager()->RunAction( PCB_ACTIONS::pluginsReload, true );
322 
323  GetCanvas()->SwitchBackend( m_canvasType );
324  ActivateGalCanvas();
325 
326  // Default shutdown reason until a file is loaded
327  KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New PCB file is unsaved" ) );
328 
329  // disable Export STEP item if kicad2step does not exist
330  wxString strK2S = Pgm().GetExecutablePath();
331 
332 #ifdef __WXMAC__
333  if( strK2S.Find( wxT( "pcbnew.app" ) ) != wxNOT_FOUND )
334  {
335  // On macOS, we have standalone applications inside the main bundle, so we handle that here:
336  strK2S += wxT( "../../" );
337  }
338 
339  strK2S += wxT( "Contents/MacOS/" );
340 #endif
341 
342  wxFileName appK2S( strK2S, wxT( "kicad2step" ) );
343 
344  #ifdef _WIN32
345  appK2S.SetExt( wxT( "exe" ) );
346  #endif
347 
348  // Ensure the window is on top
349  Raise();
350 
351 // if( !appK2S.FileExists() )
352  // GetMenuBar()->FindItem( ID_GEN_EXPORT_FILE_STEP )->Enable( false );
353 
354  // AUI doesn't refresh properly on wxMac after changes in eb7dc6dd, so force it to
355 #ifdef __WXMAC__
356  if( Kiface().IsSingle() )
357  {
358  CallAfter( [&]()
359  {
360  m_appearancePanel->OnBoardChanged();
361  } );
362  }
363 #endif
364 
365  // Register a call to update the toolbar sizes. It can't be done immediately because
366  // it seems to require some sizes calculated that aren't yet (at least on GTK).
367  CallAfter( [&]()
368  {
369  // Ensure the controls on the toolbars all are correctly sized
370  UpdateToolbarControlSizes();
371  } );
372 
374  {
375  m_eventCounterTimer = new wxTimer( this );
376 
377  Bind( wxEVT_TIMER,
378  [&]( wxTimerEvent& aEvent )
379  {
380  GetCanvas()->m_PaintEventCounter->Show();
381  GetCanvas()->m_PaintEventCounter->Reset();
382 
384  static_cast<KIGFX::WX_VIEW_CONTROLS*>( GetCanvas()->GetViewControls() );
385  vc->m_MotionEventCounter->Show();
386  vc->m_MotionEventCounter->Reset();
387 
388  },
389  m_eventCounterTimer->GetId() );
390 
391  m_eventCounterTimer->Start( 1000 );
392  }
393 }
394 
395 
397 {
398  if( ADVANCED_CFG::GetCfg().m_ShowEventCounters )
399  {
400  // Stop the timer during destruction early to avoid potential event race conditions (that do happen on windows)
401  m_eventCounterTimer->Stop();
402  delete m_eventCounterTimer;
403  }
404 
405  // Close modeless dialogs
406  wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_DRC_WINDOW_NAME );
407 
408  if( open_dlg )
409  open_dlg->Close( true );
410 
411  // Shutdown all running tools
412  if( m_toolManager )
413  m_toolManager->ShutdownAllTools();
414 
415  if( GetBoard() )
416  GetBoard()->RemoveListener( m_appearancePanel );
417 
418  delete m_selectionFilterPanel;
419  delete m_appearancePanel;
420  delete m_exportNetlistAction;
421 }
422 
423 
424 void PCB_EDIT_FRAME::SetBoard( BOARD* aBoard, bool aBuildConnectivity,
425  PROGRESS_REPORTER* aReporter )
426 {
427  if( m_pcb )
428  m_pcb->ClearProject();
429 
430  PCB_BASE_EDIT_FRAME::SetBoard( aBoard, aReporter );
431 
432  aBoard->SetProject( &Prj() );
433 
434  if( aBuildConnectivity )
435  aBoard->GetConnectivity()->Build( aBoard );
436 
437  // reload the drawing-sheet
438  SetPageSettings( aBoard->GetPageSettings() );
439 }
440 
441 
443 {
444  return m_pcb;
445 }
446 
447 
448 void PCB_EDIT_FRAME::SetPageSettings( const PAGE_INFO& aPageSettings )
449 {
450  PCB_BASE_FRAME::SetPageSettings( aPageSettings );
451 
452  // Prepare drawing-sheet template
454  &m_pcb->GetPageSettings(),
455  m_pcb->GetProject(),
456  &m_pcb->GetTitleBlock() );
457  drawingSheet->SetSheetName( std::string( GetScreenDesc().mb_str() ) );
458 
459  BASE_SCREEN* screen = GetScreen();
460 
461  if( screen != nullptr )
462  {
463  drawingSheet->SetPageNumber(TO_UTF8( screen->GetPageNumber() ) );
464  drawingSheet->SetSheetCount( screen->GetPageCount() );
465  }
466 
467  if( BOARD* board = GetBoard() )
468  drawingSheet->SetFileName( TO_UTF8( board->GetFileName() ) );
469 
470  // PCB_DRAW_PANEL_GAL takes ownership of the drawing-sheet
471  GetCanvas()->SetDrawingSheet( drawingSheet );
472 }
473 
474 
476 {
477  return GetScreen() && GetScreen()->IsContentModified();
478 }
479 
480 
482 {
483  if( GetScreen() )
484  return GetScreen()->IsContentModified();
485 
486  return false;
487 }
488 
489 
491 {
492  return m_toolManager->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
493 }
494 
495 
497 {
498  // Create the manager and dispatcher & route draw panel events to the dispatcher
499  m_toolManager = new TOOL_MANAGER;
500  m_toolManager->SetEnvironment( m_pcb, GetCanvas()->GetView(),
501  GetCanvas()->GetViewControls(), config(), this );
502  m_actions = new PCB_ACTIONS();
503  m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
504 
505  // Register tools
506  m_toolManager->RegisterTool( new COMMON_CONTROL );
507  m_toolManager->RegisterTool( new COMMON_TOOLS );
508  m_toolManager->RegisterTool( new PCB_SELECTION_TOOL );
509  m_toolManager->RegisterTool( new ZOOM_TOOL );
510  m_toolManager->RegisterTool( new PCB_PICKER_TOOL );
511  m_toolManager->RegisterTool( new ROUTER_TOOL );
512  m_toolManager->RegisterTool( new LENGTH_TUNER_TOOL );
513  m_toolManager->RegisterTool( new EDIT_TOOL );
514  m_toolManager->RegisterTool( new GLOBAL_EDIT_TOOL );
515  m_toolManager->RegisterTool( new PAD_TOOL );
516  m_toolManager->RegisterTool( new DRAWING_TOOL );
517  m_toolManager->RegisterTool( new PCB_POINT_EDITOR );
518  m_toolManager->RegisterTool( new PCB_CONTROL );
519  m_toolManager->RegisterTool( new BOARD_EDITOR_CONTROL );
520  m_toolManager->RegisterTool( new BOARD_INSPECTION_TOOL );
521  m_toolManager->RegisterTool( new BOARD_REANNOTATE_TOOL );
522  m_toolManager->RegisterTool( new ALIGN_DISTRIBUTE_TOOL );
523  m_toolManager->RegisterTool( new MICROWAVE_TOOL );
524  m_toolManager->RegisterTool( new POSITION_RELATIVE_TOOL );
525  m_toolManager->RegisterTool( new ZONE_FILLER_TOOL );
526  m_toolManager->RegisterTool( new AUTOPLACE_TOOL );
527  m_toolManager->RegisterTool( new DRC_TOOL );
528  m_toolManager->RegisterTool( new PCB_VIEWER_TOOLS );
529  m_toolManager->RegisterTool( new CONVERT_TOOL );
530  m_toolManager->RegisterTool( new GROUP_TOOL );
531  m_toolManager->RegisterTool( new SCRIPTING_TOOL );
532  m_toolManager->InitTools();
533 
534  // Run the selection tool, it is supposed to be always active
535  m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
536 }
537 
538 
540 {
542 
543  ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
544  PCB_EDITOR_CONDITIONS cond( this );
545 
546  wxASSERT( mgr );
547 
548 #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
549 #define CHECK( x ) ACTION_CONDITIONS().Check( x )
550 
552  mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) );
553  mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
554 
561 
562  mgr->SetConditions( ACTIONS::cut, ENABLE( cond.HasItems() ) );
563  mgr->SetConditions( ACTIONS::copy, ENABLE( cond.HasItems() ) );
568  mgr->SetConditions( ACTIONS::selectAll, ENABLE( cond.HasItems() ) );
569  mgr->SetConditions( ACTIONS::doDelete, ENABLE( cond.HasItems() ) );
570  mgr->SetConditions( ACTIONS::duplicate, ENABLE( cond.HasItems() ) );
571 
572  auto haveAtLeastOneGroupCond =
573  []( const SELECTION& aSel )
574  {
575  for( EDA_ITEM* item : aSel )
576  {
577  if( item->Type() == PCB_GROUP_T )
578  return true;
579  }
580 
581  return false;
582  };
583 
585  mgr->SetConditions( PCB_ACTIONS::ungroup, ENABLE( haveAtLeastOneGroupCond ) );
586  mgr->SetConditions( PCB_ACTIONS::lock, ENABLE( cond.HasItems() ) );
588 
592 
593  if( SCRIPTING::IsWxAvailable() )
595 
596  auto enableZoneControlConition =
597  [this] ( const SELECTION& )
598  {
600  && GetDisplayOptions().m_ZoneOpacity > 0.0;
601  };
602 
604  ENABLE( enableZoneControlConition ).Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_FILLED ) ) );
606  ENABLE( enableZoneControlConition ).Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_ZONE_OUTLINE ) ) );
608  ENABLE( enableZoneControlConition ).Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_FRACTURE_BORDERS ) ) );
610  ENABLE( enableZoneControlConition ).Check( cond.ZoneDisplayMode( ZONE_DISPLAY_MODE::SHOW_TRIANGULATION ) ) );
611 
612  auto enableBoardSetupCondition =
613  [this] ( const SELECTION& )
614  {
615  if( DRC_TOOL* tool = m_toolManager->GetTool<DRC_TOOL>() )
616  return !tool->IsDRCDialogShown();
617 
618  return true;
619  };
620 
621  auto boardFlippedCond =
622  [this]( const SELECTION& )
623  {
624  return GetCanvas()->GetView()->IsMirroredX();
625  };
626 
627  auto layerManagerCond =
628  [this] ( const SELECTION& )
629  {
630  return LayerManagerShown();
631  };
632 
633  auto highContrastCond =
634  [this] ( const SELECTION& )
635  {
636  return GetDisplayOptions().m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL;
637  };
638 
639  auto globalRatsnestCond =
640  [this] (const SELECTION& )
641  {
642  return GetDisplayOptions().m_ShowGlobalRatsnest;
643  };
644 
645  auto curvedRatsnestCond =
646  [this] (const SELECTION& )
647  {
648  return GetDisplayOptions().m_DisplayRatsnestLinesCurved;
649  };
650 
651  auto netHighlightCond =
652  [this]( const SELECTION& )
653  {
654  KIGFX::RENDER_SETTINGS* settings = GetCanvas()->GetView()->GetPainter()->GetSettings();
655  return !settings->GetHighlightNetCodes().empty();
656  };
657 
658  auto enableNetHighlightCond =
659  [this]( const SELECTION& )
660  {
661  BOARD_INSPECTION_TOOL* tool = m_toolManager->GetTool<BOARD_INSPECTION_TOOL>();
662  return tool->IsNetHighlightSet();
663  };
664 
665  mgr->SetConditions( ACTIONS::highContrastMode, CHECK( highContrastCond ) );
666  mgr->SetConditions( PCB_ACTIONS::flipBoard, CHECK( boardFlippedCond ) );
667  mgr->SetConditions( PCB_ACTIONS::showLayersManager, CHECK( layerManagerCond ) );
668  mgr->SetConditions( PCB_ACTIONS::showRatsnest, CHECK( globalRatsnestCond ) );
669  mgr->SetConditions( PCB_ACTIONS::ratsnestLineMode, CHECK( curvedRatsnestCond ) );
671  CHECK( netHighlightCond ).Enable( enableNetHighlightCond ) );
672  mgr->SetConditions( PCB_ACTIONS::boardSetup , ENABLE( enableBoardSetupCondition ) );
673 
674 
675  auto isHighlightMode =
676  [this]( const SELECTION& )
677  {
678  ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
679  return tool->GetRouterMode() == PNS::RM_MarkObstacles;
680  };
681 
682  auto isShoveMode =
683  [this]( const SELECTION& )
684  {
685  ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
686  return tool->GetRouterMode() == PNS::RM_Shove;
687  };
688 
689  auto isWalkaroundMode =
690  [this]( const SELECTION& )
691  {
692  ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
693  return tool->GetRouterMode() == PNS::RM_Walkaround;
694  };
695 
696  mgr->SetConditions( PCB_ACTIONS::routerHighlightMode, CHECK( isHighlightMode ) );
697  mgr->SetConditions( PCB_ACTIONS::routerShoveMode, CHECK( isShoveMode ) );
698  mgr->SetConditions( PCB_ACTIONS::routerWalkaroundMode, CHECK( isWalkaroundMode ) );
699 
700  auto haveNetCond =
701  [] ( const SELECTION& aSel )
702  {
703  for( EDA_ITEM* item : aSel )
704  {
705  if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
706  {
707  if( bci->GetNetCode() > 0 )
708  return true;
709  }
710  }
711 
712  return false;
713  };
714 
715  mgr->SetConditions( PCB_ACTIONS::showNet, ENABLE( haveNetCond ) );
716  mgr->SetConditions( PCB_ACTIONS::hideNet, ENABLE( haveNetCond ) );
717  mgr->SetConditions( PCB_ACTIONS::highlightNet, ENABLE( haveNetCond ) );
718 
725 
726 
729 
732 
733  mgr->SetConditions( PCB_ACTIONS::zoneDuplicate, ENABLE( singleZoneCond ) );
734  mgr->SetConditions( PCB_ACTIONS::drawZoneCutout, ENABLE( singleZoneCond ) );
735  mgr->SetConditions( PCB_ACTIONS::drawSimilarZone, ENABLE( singleZoneCond ) );
736  mgr->SetConditions( PCB_ACTIONS::zoneMerge, ENABLE( zoneMergeCond ) );
739 
741 
742 #define CURRENT_TOOL( action ) mgr->SetConditions( action, CHECK( cond.CurrentTool( action ) ) )
743 
744  // These tools can be used at any time to inspect the board
749 
750 
751  auto isDrcRunning =
752  [this] ( const SELECTION& )
753  {
754  DRC_TOOL* tool = m_toolManager->GetTool<DRC_TOOL>();
755  return !tool->IsDRCRunning();
756  };
757 
758 #define CURRENT_EDIT_TOOL( action ) mgr->SetConditions( action, ACTION_CONDITIONS().Check( cond.CurrentTool( action ) ).Enable( isDrcRunning ) )
759 
760  // These tools edit the board, so they must be disabled during some operations
784 
790 
791 #undef CURRENT_TOOL
792 #undef CURRENT_EDIT_TOOL
793 #undef ENABLE
794 #undef CHECK
795 }
796 
797 
798 void PCB_EDIT_FRAME::OnQuit( wxCommandEvent& event )
799 {
800  if( event.GetId() == wxID_EXIT )
801  Kiway().OnKiCadExit();
802 
803  if( event.GetId() == wxID_CLOSE || Kiface().IsSingle() )
804  Close( false );
805 }
806 
807 
809 {
811  bds.m_DrcExclusions.clear();
812 
813  for( PCB_MARKER* marker : GetBoard()->Markers() )
814  {
815  if( marker->IsExcluded() )
816  bds.m_DrcExclusions.insert( marker->Serialize() );
817  }
818 }
819 
820 
822 {
823  BOARD_COMMIT commit( this );
824 
825  for( PCB_MARKER* marker : GetBoard()->ResolveDRCExclusions() )
826  commit.Add( marker );
827 
828  commit.Push( wxEmptyString, false, false );
829 
830  for( PCB_MARKER* marker : GetBoard()->Markers() )
831  {
832  if( marker->IsExcluded() )
833  {
834  GetCanvas()->GetView()->Remove( marker );
835  GetCanvas()->GetView()->Add( marker );
836  }
837  }
838 }
839 
840 
841 bool PCB_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
842 {
843  // Shutdown blocks must be determined and vetoed as early as possible
844  if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION
845  && IsContentModified() )
846  {
847  return false;
848  }
849 
850  if( Kiface().IsSingle() )
851  {
852  auto* fpEditor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, false );
853 
854  if( fpEditor && !fpEditor->Close() ) // Can close footprint editor?
855  return false;
856 
857  auto* fpViewer = (FOOTPRINT_VIEWER_FRAME*) Kiway().Player( FRAME_FOOTPRINT_VIEWER, false );
858 
859  if( fpViewer && !fpViewer->Close() ) // Can close footprint viewer?
860  return false;
861 
863 
864  if( fpViewer && !fpViewer->Close() ) // Can close modal footprint viewer?
865  return false;
866  }
867  else
868  {
869  auto* fpEditor = (FOOTPRINT_EDIT_FRAME*) Kiway().Player( FRAME_FOOTPRINT_EDITOR, false );
870 
871  if( fpEditor && fpEditor->IsCurrentFPFromBoard() )
872  {
873  if( !fpEditor->CanCloseFPFromBoard( true ) )
874  return false;
875  }
876  }
877 
878  if( IsContentModified() )
879  {
880  wxFileName fileName = GetBoard()->GetFileName();
881  wxString msg = _( "Save changes to '%s' before closing?" );
882 
883  if( !HandleUnsavedChanges( this, wxString::Format( msg, fileName.GetFullName() ),
884  [&]() -> bool
885  {
886  return Files_io_from_id( ID_SAVE_BOARD );
887  } ) )
888  {
889  return false;
890  }
891  }
892 
893  // Close modeless dialogs. They're trouble when they get destroyed after the frame and/or
894  // board.
895  wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_DRC_WINDOW_NAME );
896 
897  if( open_dlg )
898  open_dlg->Close( true );
899 
900  return PCB_BASE_EDIT_FRAME::canCloseWindow( aEvent );
901 }
902 
903 
905 {
906  // On Windows 7 / 32 bits, on OpenGL mode only, Pcbnew crashes
907  // when closing this frame if a footprint was selected, and the footprint editor called
908  // to edit this footprint, and when closing pcbnew if this footprint is still selected
909  // See https://bugs.launchpad.net/kicad/+bug/1655858
910  // I think this is certainly a OpenGL event fired after frame deletion, so this workaround
911  // avoid the crash (JPC)
912  GetCanvas()->SetEvtHandlerEnabled( false );
913 
914  GetCanvas()->StopDrawing();
915 
916  // Delete the auto save file if it exists.
917  wxFileName fn = GetBoard()->GetFileName();
918 
919  // Auto save file name is the normal file name prefixed with 'GetAutoSaveFilePrefix()'.
920  fn.SetName( GetAutoSaveFilePrefix() + fn.GetName() );
921 
922  // When the auto save feature does not have write access to the board file path, it falls
923  // back to a platform specific user temporary file path.
924  if( !fn.IsOk() || !fn.IsDirWritable() )
925  fn.SetPath( wxFileName::GetTempDir() );
926 
927  wxLogTrace( traceAutoSave, wxT( "Deleting auto save file <" ) + fn.GetFullPath() + wxT( ">" ) );
928 
929  // Remove the auto save file on a normal close of Pcbnew.
930  if( fn.FileExists() && !wxRemoveFile( fn.GetFullPath() ) )
931  {
932  wxString msg = wxString::Format( _( "The auto save file '%s' could not be removed!" ),
933  fn.GetFullPath() );
934  wxMessageBox( msg, Pgm().App().GetAppName(), wxOK | wxICON_ERROR, this );
935  }
936 
937  // Make sure local settings are persisted
938  SaveProjectSettings();
939 
940  // Do not show the layer manager during closing to avoid flicker
941  // on some platforms (Windows) that generate useless redraw of items in
942  // the Layer Manager
943  if( m_show_layer_manager_tools )
944  m_auimgr.GetPane( "LayersManager" ).Show( false );
945 
946  // Unlink the old project if needed
947  GetBoard()->ClearProject();
948 
949  // Delete board structs and undo/redo lists, to avoid crash on exit
950  // when deleting some structs (mainly in undo/redo lists) too late
951  Clear_Pcb( false, true );
952 
953  // do not show the window because ScreenPcb will be deleted and we do not
954  // want any paint event
955  Show( false );
956 
958 }
959 
960 
962 {
964  GetCanvas()->UpdateColors();
965  GetCanvas()->Refresh();
966 }
967 
968 
969 void PCB_EDIT_FRAME::ShowBoardSetupDialog( const wxString& aInitialPage )
970 {
971  // Make sure everything's up-to-date
973 
974  DIALOG_BOARD_SETUP dlg( this );
975 
976  if( !aInitialPage.IsEmpty() )
977  dlg.SetInitialPage( aInitialPage, wxEmptyString );
978 
979  if( dlg.ShowQuasiModal() == wxID_OK )
980  {
982 
984  SaveProjectSettings();
985 
986  Kiway().CommonSettingsChanged( false, true );
987 
988  static LSET maskAndPasteLayers = LSET( 4, F_Mask, F_Paste, B_Mask, B_Paste );
989 
990  bool maskOrPasteVisible = ( GetBoard()->GetVisibleLayers() & maskAndPasteLayers ).any();
991  bool padClearancesVisible = GetDisplayOptions().m_DisplayPadClearance;
992  bool trackClearancesVisible = GetDisplayOptions().m_ShowTrackClearanceMode
994 
995  GetCanvas()->GetView()->UpdateAllItemsConditionally( KIGFX::REPAINT,
996  [&]( KIGFX::VIEW_ITEM* aItem ) -> bool
997  {
998  if( dynamic_cast<PCB_TRACK*>( aItem ) )
999  {
1000  return trackClearancesVisible;
1001  }
1002  else if( dynamic_cast<PAD*>( aItem ) )
1003  {
1004  return padClearancesVisible || maskOrPasteVisible;
1005  }
1006  else if( dynamic_cast<EDA_TEXT*>( aItem ) )
1007  {
1008  EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
1009 
1010  return text->HasTextVars();
1011  }
1012 
1013  return false;
1014  } );
1015 
1016  GetCanvas()->Refresh();
1017 
1019  ReCreateAuxiliaryToolbar();
1020  m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
1021 
1022  //this event causes the routing tool to reload its design rules information
1024  toolEvent.SetHasPosition( false );
1025  m_toolManager->ProcessEvent( toolEvent );
1026  }
1027 
1028  GetCanvas()->SetFocus();
1029 }
1030 
1031 
1033 {
1035 
1036  PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
1037  wxASSERT( cfg );
1038 
1039  if( cfg )
1040  {
1041  m_rotationAngle = cfg->m_RotationAngle;
1042  m_show_layer_manager_tools = cfg->m_AuiPanels.show_layer_manager;
1043  m_showPageLimits = cfg->m_ShowPageLimits;
1044  }
1045 }
1046 
1047 
1049 {
1051 
1052  auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
1053  wxASSERT( cfg );
1054 
1055  if( cfg )
1056  {
1057  cfg->m_RotationAngle = m_rotationAngle;
1058  cfg->m_AuiPanels.show_layer_manager = m_show_layer_manager_tools;
1059  cfg->m_AuiPanels.right_panel_width = m_appearancePanel->GetSize().x;
1060  cfg->m_AuiPanels.appearance_panel_tab = m_appearancePanel->GetTabIndex();
1061  cfg->m_ShowPageLimits = m_showPageLimits;
1062  }
1063 
1064  if( GetSettingsManager() )
1065  GetSettingsManager()->SaveColorSettings( GetColorSettings(), "board" );
1066 }
1067 
1068 
1070 {
1071  return GetColorSettings()->GetColor( LAYER_GRID );
1072 }
1073 
1074 
1076 {
1077 
1078  GetColorSettings()->SetColor( LAYER_GRID, aColor );
1079  GetCanvas()->GetGAL()->SetGridColor( aColor );
1080 }
1081 
1082 
1084 {
1085  PCB_LAYER_ID oldLayer = GetActiveLayer();
1086 
1087  if( oldLayer == aLayer )
1088  return;
1089 
1091 
1092  m_appearancePanel->OnLayerChanged();
1093 
1094  m_toolManager->RunAction( PCB_ACTIONS::layerChanged ); // notify other tools
1095  GetCanvas()->SetFocus(); // allow capture of hotkeys
1096  GetCanvas()->SetHighContrastLayer( aLayer );
1097 
1098  GetCanvas()->GetView()->UpdateAllItemsConditionally( KIGFX::REPAINT,
1099  [&]( KIGFX::VIEW_ITEM* aItem ) -> bool
1100  {
1101  if( PCB_VIA* via = dynamic_cast<PCB_VIA*>( aItem ) )
1102  {
1103  // Vias on a restricted layer set must be redrawn when the active layer
1104  // is changed
1105  return ( via->GetViaType() == VIATYPE::BLIND_BURIED ||
1106  via->GetViaType() == VIATYPE::MICROVIA );
1107  }
1108  else if( PAD* pad = dynamic_cast<PAD*>( aItem ) )
1109  {
1110  // Clearances could be layer-dependent so redraw them when the active layer
1111  // is changed
1112  if( GetDisplayOptions().m_DisplayPadClearance )
1113  {
1114  // Round-corner rects are expensive to draw, but are mostly found on
1115  // SMD pads which only need redrawing on an active-to-not-active
1116  // switch.
1117  if( pad->GetAttribute() == PAD_ATTRIB::SMD )
1118  {
1119  if( ( oldLayer == F_Cu || aLayer == F_Cu ) && pad->IsOnLayer( F_Cu ) )
1120  return true;
1121 
1122  if( ( oldLayer == B_Cu || aLayer == B_Cu ) && pad->IsOnLayer( B_Cu ) )
1123  return true;
1124  }
1125 
1126  return true;
1127  }
1128  }
1129  else if( PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( aItem ) )
1130  {
1131  // Clearances could be layer-dependent so redraw them when the active layer
1132  // is changed
1133  if( GetDisplayOptions().m_ShowTrackClearanceMode )
1134  {
1135  // Tracks aren't particularly expensive to draw, but it's an easy check.
1136  return track->IsOnLayer( oldLayer ) || track->IsOnLayer( aLayer );
1137  }
1138  }
1139 
1140  return false;
1141  } );
1142 
1143  GetCanvas()->Refresh();
1144 }
1145 
1146 
1148 {
1149  // JEY TODO: move this global to the board
1151 
1152  layerEnum.Choices().Clear();
1153  layerEnum.Undefined( UNDEFINED_LAYER );
1154 
1155  for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
1156  {
1157  // Canonical name
1158  layerEnum.Map( *seq, LSET::Name( *seq ) );
1159 
1160  // User name
1161  layerEnum.Map( *seq, GetBoard()->GetLayerName( *seq ) );
1162  }
1163 
1164  DRC_TOOL* drcTool = m_toolManager->GetTool<DRC_TOOL>();
1165 
1166  try
1167  {
1168  drcTool->GetDRCEngine()->InitEngine( GetDesignRulesPath() );
1169  }
1170  catch( PARSE_ERROR& )
1171  {
1172  // Not sure this is the best place to tell the user their rules are buggy, so
1173  // we'll stay quiet for now. Feel free to revisit this decision....
1174  }
1175 
1176  UpdateTitle();
1177 
1178  wxFileName fn = GetBoard()->GetFileName();
1179 
1180  // Display a warning that the file is read only
1181  if( fn.FileExists() && !fn.IsFileWritable() )
1182  {
1183  m_infoBar->RemoveAllButtons();
1184  m_infoBar->AddCloseButton();
1185  m_infoBar->ShowMessage( _( "Board file is read only." ), wxICON_WARNING );
1186  }
1187 
1188  ReCreateLayerBox();
1189 
1190  // Sync layer and item visibility
1191  GetCanvas()->SyncLayersVisibility( m_pcb );
1192 
1193  SetElementVisibility( LAYER_RATSNEST, GetDisplayOptions().m_ShowGlobalRatsnest );
1194 
1195  m_appearancePanel->OnBoardChanged();
1196 
1197  // Apply saved display state to the appearance panel after it has been set up
1198  PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
1199 
1200  m_appearancePanel->ApplyLayerPreset( localSettings.m_ActiveLayerPreset );
1201 
1202  if( GetBoard()->GetDesignSettings().IsLayerEnabled( localSettings.m_ActiveLayer ) )
1203  SetActiveLayer( localSettings.m_ActiveLayer );
1204 
1205  // Updates any auto dimensions and the auxiliary toolbar tracks/via sizes
1206  unitsChangeRefresh();
1207 
1208  // Display the loaded board:
1209  Zoom_Automatique( false );
1210 
1211  // Invalidate painting as loading the DRC engine will cause clearances to become valid
1212  GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL );
1213 
1214  Refresh();
1215 
1216  SetMsgPanel( GetBoard() );
1217  SetStatusText( wxEmptyString );
1218 
1219  KIPLATFORM::APP::SetShutdownBlockReason( this, _( "PCB file changes are unsaved" ) );
1220 }
1221 
1222 
1224 {
1225  m_appearancePanel->UpdateDisplayOptions();
1226 }
1227 
1228 
1230 {
1231  return GetBoard()->IsElementVisible( aElement );
1232 }
1233 
1234 
1235 void PCB_EDIT_FRAME::SetElementVisibility( GAL_LAYER_ID aElement, bool aNewState )
1236 {
1237  // Force the RATSNEST visible
1238  if( aElement == LAYER_RATSNEST )
1239  GetCanvas()->GetView()->SetLayerVisible( aElement, true );
1240  else
1241  GetCanvas()->GetView()->SetLayerVisible( aElement , aNewState );
1242 
1243  GetBoard()->SetElementVisibility( aElement, aNewState );
1244 }
1245 
1246 
1248 {
1249  // call my base class
1251 
1252  wxAuiPaneInfo& ap_pane_info = m_auimgr.GetPane( m_appearancePanel );
1253  ap_pane_info.Caption( _( "Appearance" ) );
1254  wxAuiPaneInfo& sf_pane_info = m_auimgr.GetPane( m_selectionFilterPanel );
1255  sf_pane_info.Caption( _( "Selection Filter" ) );
1256  m_auimgr.Update();
1257 
1258  m_appearancePanel->OnLanguageChanged();
1259  m_selectionFilterPanel->OnLanguageChanged();
1260 
1261  UpdateTitle();
1262 }
1263 
1264 
1266 {
1268 
1269  if( project.m_PcbLastPath[ aType ].IsEmpty() )
1270  return wxEmptyString;
1271 
1272  wxFileName absoluteFileName = project.m_PcbLastPath[ aType ];
1273  wxFileName pcbFileName = GetBoard()->GetFileName();
1274 
1275  absoluteFileName.MakeAbsolute( pcbFileName.GetPath() );
1276  return absoluteFileName.GetFullPath();
1277 }
1278 
1279 
1280 void PCB_EDIT_FRAME::SetLastPath( LAST_PATH_TYPE aType, const wxString& aLastPath )
1281 {
1283 
1284  wxFileName relativeFileName = aLastPath;
1285  wxFileName pcbFileName = GetBoard()->GetFileName();
1286 
1287  relativeFileName.MakeRelativeTo( pcbFileName.GetPath() );
1288 
1289  if( relativeFileName.GetFullPath() != project.m_PcbLastPath[ aType ] )
1290  {
1291  project.m_PcbLastPath[ aType ] = relativeFileName.GetFullPath();
1292  SaveProjectSettings();
1293  }
1294 }
1295 
1296 
1298 {
1300 
1301  Update3DView( true, GetDisplayOptions().m_Live3DRefresh );
1302 
1303  if( !GetTitle().StartsWith( wxT( "*" ) ) )
1304  UpdateTitle();
1305 
1306  m_ZoneFillsDirty = true;
1307 }
1308 
1309 
1311 {
1312  Update3DView( true, true );
1313 }
1314 
1315 
1316 void PCB_EDIT_FRAME::ExportSVG( wxCommandEvent& event )
1317 {
1318  InvokeExportSVG( this, GetBoard() );
1319 }
1320 
1321 
1323 {
1324  wxFileName fn = GetBoard()->GetFileName();
1325  bool readOnly = false;
1326  bool unsaved = false;
1327 
1328  if( fn.IsOk() && fn.FileExists() )
1329  readOnly = !fn.IsFileWritable();
1330  else
1331  unsaved = true;
1332 
1333  wxString title;
1334 
1335  if( IsContentModified() )
1336  title = wxT( "*" );
1337 
1338  title += fn.GetName();
1339 
1340  if( readOnly )
1341  title += wxS( " " ) + _( "[Read Only]" );
1342 
1343  if( unsaved )
1344  title += wxS( " " ) + _( "[Unsaved]" );
1345 
1346  title += wxT( " \u2014 " ) + _( "PCB Editor" );
1347 
1348  SetTitle( title );
1349 }
1350 
1351 
1353 {
1354  // Update the layer manager and other widgets from the board setup
1355  // (layer and items visibility, colors ...)
1356 
1357  // Rebuild list of nets (full ratsnest rebuild)
1359  Compile_Ratsnest( true );
1360 
1361  // Update info shown by the horizontal toolbars
1362  ReCreateLayerBox();
1363 
1364  LSET activeLayers = GetBoard()->GetEnabledLayers();
1365 
1366  if( !activeLayers.test( GetActiveLayer() ) )
1367  SetActiveLayer( activeLayers.Seq().front() );
1368 
1369  m_SelLayerBox->SetLayerSelection( GetActiveLayer() );
1370 
1372 
1373  layerEnum.Choices().Clear();
1374  layerEnum.Undefined( UNDEFINED_LAYER );
1375 
1376  for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
1377  {
1378  // Canonical name
1379  layerEnum.Map( *seq, LSET::Name( *seq ) );
1380 
1381  // User name
1382  layerEnum.Map( *seq, GetBoard()->GetLayerName( *seq ) );
1383  }
1384 
1385  // Sync visibility with canvas
1386  KIGFX::VIEW* view = GetCanvas()->GetView();
1387  LSET visible = GetBoard()->GetVisibleLayers();
1388 
1389  for( PCB_LAYER_ID layer : LSET::AllLayersMask().Seq() )
1390  view->SetLayerVisible( layer, visible.Contains( layer ) );
1391 
1392  // Stackup and/or color theme may have changed
1393  m_appearancePanel->OnBoardChanged();
1394 }
1395 
1396 
1398 {
1399  // switches currently used canvas (Cairo / OpenGL).
1400  PCB_BASE_FRAME::SwitchCanvas( aCanvasType );
1401 }
1402 
1403 
1405 {
1406  if( !m_findDialog )
1407  {
1408  m_findDialog = new DIALOG_FIND( this );
1409  m_findDialog->SetCallback( std::bind( &PCB_SELECTION_TOOL::FindItem,
1410  m_toolManager->GetTool<PCB_SELECTION_TOOL>(), _1 ) );
1411  }
1412 
1413  m_findDialog->Show( true );
1414 }
1415 
1416 
1418 {
1419  if( !m_findDialog )
1420  {
1421  m_findDialog = new DIALOG_FIND( this );
1422  m_findDialog->SetCallback( std::bind( &PCB_SELECTION_TOOL::FindItem,
1423  m_toolManager->GetTool<PCB_SELECTION_TOOL>(), _1 ) );
1424  }
1425 
1426  m_findDialog->FindNext();
1427 }
1428 
1429 
1431 {
1432  PCB_PLOT_PARAMS plotSettings = GetPlotSettings();
1433 
1434  switch( aID )
1435  {
1436  case ID_GEN_PLOT_GERBER:
1437  plotSettings.SetFormat( PLOT_FORMAT::GERBER );
1438  break;
1439  case ID_GEN_PLOT_DXF:
1440  plotSettings.SetFormat( PLOT_FORMAT::DXF );
1441  break;
1442  case ID_GEN_PLOT_HPGL:
1443  plotSettings.SetFormat( PLOT_FORMAT::HPGL );
1444  break;
1445  case ID_GEN_PLOT_PDF:
1446  plotSettings.SetFormat( PLOT_FORMAT::PDF );
1447  break;
1448  case ID_GEN_PLOT_PS:
1449  plotSettings.SetFormat( PLOT_FORMAT::POST );
1450  break;
1451  case ID_GEN_PLOT:
1452  /* keep the previous setup */
1453  break;
1454  default:
1455  wxFAIL_MSG( wxT( "ToPlotter(): unexpected plot type" ) ); break;
1456  break;
1457  }
1458 
1459  SetPlotSettings( plotSettings );
1460 
1461  DIALOG_PLOT dlg( this );
1462  dlg.ShowQuasiModal( );
1463 }
1464 
1465 
1467 {
1468  if( Kiface().IsSingle() )
1469  return false;
1470 
1471  // Update PCB requires a netlist. Therefore the schematic editor must be running
1472  // If this is not the case, open the schematic editor
1473  KIWAY_PLAYER* frame = Kiway().Player( FRAME_SCH, true );
1474 
1475  if( !frame->IsShown() )
1476  {
1477  wxFileName fn( Prj().GetProjectPath(), Prj().GetProjectName(),
1479 
1480  // Maybe the file hasn't been converted to the new s-expression file format so
1481  // see if the legacy schematic file is still in play.
1482  if( !fn.FileExists() )
1483  {
1484  fn.SetExt( LegacySchematicFileExtension );
1485 
1486  if( !fn.FileExists() )
1487  {
1488  DisplayError( this, _( "The schematic for this board cannot be found." ) );
1489  return false;
1490  }
1491  }
1492 
1493  frame->OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ) );
1494 
1495  // we show the schematic editor frame, because do not show is seen as
1496  // a not yet opened schematic by Kicad manager, which is not the case
1497  frame->Show( true );
1498 
1499  // bring ourselves back to the front
1500  Raise();
1501  }
1502 
1503  return true; //Success!
1504 }
1505 
1506 
1508  const wxString& aAnnotateMessage )
1509 {
1510  if( !TestStandalone() )
1511  {
1512  DisplayErrorMessage( this, _( "Cannot update the PCB because PCB editor is opened in "
1513  "stand-alone mode. In order to create or update PCBs from "
1514  "schematics, you must launch the KiCad project manager and "
1515  "create a project." ) );
1516  return false; // Not in standalone mode
1517  }
1518 
1519  Raise(); // Show
1520 
1521  std::string payload( aAnnotateMessage );
1522 
1523  Kiway().ExpressMail( FRAME_SCH, MAIL_SCH_GET_NETLIST, payload, this );
1524 
1525  if( payload == aAnnotateMessage )
1526  {
1527  Raise();
1528  DisplayErrorMessage( this, aAnnotateMessage );
1529  return false;
1530  }
1531 
1532  try
1533  {
1534  auto lineReader = new STRING_LINE_READER( payload, _( "Eeschema netlist" ) );
1535  KICAD_NETLIST_READER netlistReader( lineReader, &aNetlist );
1536  netlistReader.LoadNetlist();
1537  }
1538  catch( const IO_ERROR& e )
1539  {
1540  Raise();
1541 
1542  // Do not translate extra_info strings. These are for developers
1543  wxString extra_info = e.Problem() + wxT( " : " ) + e.What() + wxT( " at " ) + e.Where();
1544 
1545  DisplayErrorMessage( this, _( "Received an error while reading netlist. Please "
1546  "report this issue to the KiCad team using the menu "
1547  "Help->Report Bug."), extra_info );
1548  return false;
1549  }
1550 
1551  return true;
1552 }
1553 
1554 
1556 {
1557  wxString msg;
1558  wxFileName schematic( Prj().GetProjectPath(), Prj().GetProjectName(),
1560 
1561  if( !schematic.FileExists() )
1562  {
1563  wxFileName legacySchematic( Prj().GetProjectPath(), Prj().GetProjectName(),
1565 
1566  if( legacySchematic.FileExists() )
1567  {
1568  schematic = legacySchematic;
1569  }
1570  else
1571  {
1572  msg.Printf( _( "Schematic file '%s' not found." ), schematic.GetFullPath() );
1573  wxMessageBox( msg, _( "KiCad Error" ), wxOK | wxICON_ERROR, this );
1574  return;
1575  }
1576  }
1577 
1578  if( Kiface().IsSingle() )
1579  {
1580  ExecuteFile( EESCHEMA_EXE, schematic.GetFullPath() );
1581  }
1582  else
1583  {
1584  KIWAY_PLAYER* frame = Kiway().Player( FRAME_SCH, false );
1585 
1586  // Please: note: DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::initBuffers() calls
1587  // Kiway.Player( FRAME_SCH, true )
1588  // therefore, the schematic editor is sometimes running, but the schematic project
1589  // is not loaded, if the library editor was called, and the dialog field editor was used.
1590  // On Linux, it happens the first time the schematic editor is launched, if
1591  // library editor was running, and the dialog field editor was open
1592  // On Windows, it happens always after the library editor was called,
1593  // and the dialog field editor was used
1594  if( !frame )
1595  {
1596  try
1597  {
1598  frame = Kiway().Player( FRAME_SCH, true );
1599  }
1600  catch( const IO_ERROR& err )
1601  {
1602  wxMessageBox( _( "Eeschema failed to load." ) + wxS( "\n" ) + err.What(),
1603  _( "KiCad Error" ), wxOK | wxICON_ERROR, this );
1604  return;
1605  }
1606  }
1607 
1608  if( !frame->IsShown() ) // the frame exists, (created by the dialog field editor)
1609  // but no project loaded.
1610  {
1611  frame->OpenProjectFiles( std::vector<wxString>( 1, schematic.GetFullPath() ) );
1612  frame->Show( true );
1613  }
1614 
1615  // On Windows, Raise() does not bring the window on screen, when iconized or not shown
1616  // On Linux, Raise() brings the window on screen, but this code works fine
1617  if( frame->IsIconized() )
1618  {
1619  frame->Iconize( false );
1620  // If an iconized frame was created by Pcbnew, Iconize( false ) is not enough
1621  // to show the frame at its normal size: Maximize should be called.
1622  frame->Maximize( false );
1623  }
1624 
1625  frame->Raise();
1626  }
1627 }
1628 
1629 
1631 {
1632  const ENV_VAR_MAP& vars = Pgm().GetLocalEnvVariables();
1633 
1634  // Set the environment variables for python scripts
1635  // note: the string will be encoded UTF8 for python env
1636  for( auto& var : vars )
1637  UpdatePythonEnvVar( var.first, var.second.GetValue() );
1638 
1639  // Because the env vars can be modified by the python scripts (rewritten in UTF8),
1640  // regenerate them (in Unicode) for our normal environment
1641  for( auto& var : vars )
1642  wxSetEnv( var.first, var.second.GetValue() );
1643 }
1644 
1645 
1647 {
1648  wxString evValue;
1649  wxGetEnv( PROJECT_VAR_NAME, &evValue );
1650  UpdatePythonEnvVar( wxString( PROJECT_VAR_NAME ).ToStdString(), evValue );
1651 
1652  // Because PROJECT_VAR_NAME can be modified by the python scripts (rewritten in UTF8),
1653  // regenerate it (in Unicode) for our normal environment
1654  wxSetEnv( PROJECT_VAR_NAME, evValue );
1655 }
1656 
1657 
1659 {
1660  if( aFootprint == nullptr )
1661  return;
1662 
1664 
1665  /*
1666  * Make sure dlg is destroyed before GetCanvas->Refresh is called
1667  * later or the refresh will try to modify its properties since
1668  * they share a GL context.
1669  */
1670  {
1671  DIALOG_FOOTPRINT_PROPERTIES dlg( this, aFootprint );
1672 
1673  // We use quasi modal to allow displaying help dialogs.
1674  dlg.ShowQuasiModal();
1675  retvalue = dlg.GetReturnValue();
1676  }
1677 
1678  /*
1679  * retvalue =
1680  * FP_PROPS_UPDATE_FP to show Update Footprints dialog
1681  * FP_PROPS_CHANGE_FP to show Change Footprints dialog
1682  * FP_PROPS_OK for normal edit
1683  * FP_PROPS_CANCEL if aborted
1684  * FP_PROPS_EDIT_BOARD_FP to load board footprint into Footprint Editor
1685  * FP_PROPS_EDIT_LIBRARY_FP to load library footprint into Footprint Editor
1686  */
1687 
1689  {
1690  // If something edited, push a refresh request
1691  GetCanvas()->Refresh();
1692  }
1694  {
1696 
1697  editor->LoadFootprintFromBoard( aFootprint );
1698 
1699  editor->Show( true );
1700  editor->Raise(); // Iconize( false );
1701  }
1702 
1704  {
1706 
1707  editor->LoadFootprintFromLibrary( aFootprint->GetFPID() );
1708 
1709  editor->Show( true );
1710  editor->Raise(); // Iconize( false );
1711  }
1712 
1714  {
1715  ShowExchangeFootprintsDialog( aFootprint, true, true );
1716  }
1717 
1719  {
1720  ShowExchangeFootprintsDialog( aFootprint, false, true );
1721  }
1722 }
1723 
1724 
1725 int PCB_EDIT_FRAME::ShowExchangeFootprintsDialog( FOOTPRINT* aFootprint, bool aUpdateMode,
1726  bool aSelectedMode )
1727 {
1728  DIALOG_EXCHANGE_FOOTPRINTS dialog( this, aFootprint, aUpdateMode, aSelectedMode );
1729 
1730  return dialog.ShowQuasiModal();
1731 }
1732 
1733 
1734 void PCB_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
1735 {
1736  PCB_BASE_EDIT_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
1737 
1738  GetAppearancePanel()->OnColorThemeChanged();
1739 
1740  // Netclass definitions could have changed, either by us or by Eeschema
1741  DRC_TOOL* drcTool = m_toolManager->GetTool<DRC_TOOL>();
1742  WX_INFOBAR* infobar = GetInfoBar();
1743 
1744  try
1745  {
1746  drcTool->GetDRCEngine()->InitEngine( GetDesignRulesPath() );
1747 
1748  if( infobar->GetMessageType() == WX_INFOBAR::MESSAGE_TYPE::DRC_RULES_ERROR )
1749  infobar->Dismiss();
1750  }
1751  catch( PARSE_ERROR& )
1752  {
1753  wxHyperlinkCtrl* button = new wxHyperlinkCtrl( infobar, wxID_ANY, _( "Edit design rules" ),
1754  wxEmptyString );
1755 
1756  button->Bind( wxEVT_COMMAND_HYPERLINK, std::function<void( wxHyperlinkEvent& aEvent )>(
1757  [&]( wxHyperlinkEvent& aEvent )
1758  {
1759  ShowBoardSetupDialog( _( "Custom Rules" ) );
1760  } ) );
1761 
1762  infobar->RemoveAllButtons();
1763  infobar->AddButton( button );
1764  infobar->AddCloseButton();
1765  infobar->ShowMessage( _( "Could not compile custom design rules." ), wxICON_ERROR,
1767  }
1768 
1769  // Update the environment variables in the Python interpreter
1770  if( aEnvVarsChanged )
1771  PythonSyncEnvironmentVariables();
1772 
1773  Layout();
1774  SendSizeEvent();
1775 }
1776 
1777 
1779 {
1781 }
1782 
1783 
1785 {
1786  PythonSyncProjectName();
1787 }
1788 
1789 
1790 bool ExportBoardToHyperlynx( BOARD* aBoard, const wxFileName& aPath );
1791 
1792 
1793 void PCB_EDIT_FRAME::OnExportHyperlynx( wxCommandEvent& event )
1794 {
1795  wxString wildcard = wxT( "*.hyp" );
1796  wxFileName fn = GetBoard()->GetFileName();
1797 
1798  fn.SetExt( wxT("hyp") );
1799 
1800  wxFileDialog dlg( this, _( "Export Hyperlynx Layout" ), fn.GetPath(), fn.GetFullName(),
1801  wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
1802 
1803  if( dlg.ShowModal() != wxID_OK )
1804  return;
1805 
1806  fn = dlg.GetPath();
1807 
1808  // always enforce filename extension, user may not have entered it.
1809  fn.SetExt( wxT( "hyp" ) );
1810 
1812 }
1813 
1814 
1816 {
1817  return GetBoard()->GetFileName();
1818 }
1819 
1820 
1822 {
1823  return m_auimgr.GetPane( "LayersManager" ).IsShown();
1824 }
1825 
1826 
1827 void PCB_EDIT_FRAME::onSize( wxSizeEvent& aEvent )
1828 {
1829  if( IsShown() )
1830  {
1831  // We only need this until the frame is done resizing and the final client size is
1832  // established.
1833  Unbind( wxEVT_SIZE, &PCB_EDIT_FRAME::onSize, this );
1834  GetToolManager()->RunAction( ACTIONS::zoomFitScreen, true );
1835  }
1836 
1837  // Skip() is called in the base class.
1838  EDA_DRAW_FRAME::OnSize( aEvent );
1839 }
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:139
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:146
void BuildListOfNets()
Definition: board.h:659
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:536
bool m_ShowEventCounters
Shows debugging event counters in various places.
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:636
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:153
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:143
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
An implementation of class VIEW_CONTROLS for wxWidgets library.
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:237
static TOOL_ACTION zoomTool
Definition: actions.h:99
A progress reporter interface for use in multi-threaded environments.
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.
virtual void SetBoard(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr) override
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
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)
static TOOL_ACTION pluginsReload
Scripting Actions.
Definition: pcb_actions.h:312
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:196
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:587
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:38
Component library viewer main window.
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:184
static TOOL_ACTION drawAlignedDimension
Definition: pcb_actions.h:145
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:147
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:140
#define ENABLE(x)
static TOOL_ACTION routerHighlightMode
Actions to enable switching modes via hotkey assignments.
Definition: pcb_actions.h:197
static TOOL_ACTION microwaveCreateLine
Definition: pcb_actions.h:418
bool canCloseWindow(wxCloseEvent &aCloseEvent) override
NET_SETTINGS & NetSettings()
Definition: project_file.h:96
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:393
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:487
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:243
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:229
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:115
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 TOOL_ACTION placeText
Definition: pcb_actions.h:144
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:64
static TOOL_ACTION zoneFill
Definition: pcb_actions.h:302
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.
WX_VIEW_CONTROLS class definition.
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:238
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:187
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.
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:140
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:1394
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:245
void Tracks_and_Vias_Size_Event(wxCommandEvent &event)
Handle actions specific to filling copper zones.
bool ExportBoardToHyperlynx(BOARD *aBoard, const wxFileName &aPath)
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:516
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:1922
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
void SetBoard(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr) override
Set the #m_Pcb member in such as way as to ensure deleting any previous BOARD.
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:306
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:345
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:236
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
COLOR4D GetGridColor() override
static TOOL_ACTION drawRectangle
Definition: pcb_actions.h:141
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:796
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:150
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:195
#define KICAD_DEFAULT_DRAWFRAME_STYLE
std::function< bool(const SELECTION &)> SELECTION_CONDITION
< Functor type that checks a specific condition for selected items.
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:246
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:152
Handle actions that are shared between different applications.
static TOOL_ACTION routerWalkaroundMode
Definition: pcb_actions.h:199
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:155
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:477
static TOOL_ACTION boardSetup
Definition: pcb_actions.h:316
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:244
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:304
BOARD * GetBoard()
static TOOL_ACTION pasteSpecial
Definition: actions.h:69
#define CHECK(x)
static TOOL_ACTION padDisplayMode
Definition: pcb_actions.h:241
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Test whether a given element category is visible.
Definition: board.cpp:533
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:142
static TOOL_ACTION viaDisplayMode
Definition: pcb_actions.h:242
void BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
Definition: board.cpp:137
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:309
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
std::unique_ptr< PROF_COUNTER > m_MotionEventCounter
static TOOL_ACTION layerChanged
Definition: pcb_actions.h:289
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:157
static TOOL_ACTION showNet
Definition: pcb_actions.h:457
static TOOL_ACTION drawLeader
Definition: pcb_actions.h:148
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:151
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.
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:191
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:175
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.
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:130
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:99
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:564
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
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:291
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:198
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:149
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.
static TOOL_ACTION duplicate
Definition: actions.h:71
static TOOL_ACTION trackDisplayMode
Definition: pcb_actions.h:240
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:181
static TOOL_ACTION routeDiffPair
Activation of the Push and Shove router (differential pair mode)
Definition: pcb_actions.h:178
bool Contains(GAL_LAYER_ID aPos)
Definition: layer_ids.h:324