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