KiCad PCB EDA Suite
sch_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) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <base_units.h>
26 #include <bitmaps.h>
27 #include <symbol_library.h>
28 #include <confirm.h>
29 #include <connection_graph.h>
31 #include <eeschema_id.h>
32 #include <executable_names.h>
33 #include <gestfich.h>
34 #include <hierarch.h>
36 #include <ignore.h>
37 #include <invoke_sch_dialog.h>
38 #include <string_utils.h>
39 #include <kiface_base.h>
40 #include <kiplatform/app.h>
41 #include <kiway.h>
42 #include <symbol_edit_frame.h>
43 #include <symbol_viewer_frame.h>
44 #include <pgm_base.h>
45 #include <profile.h>
46 #include <project.h>
47 #include <project/project_file.h>
48 #include <project/net_settings.h>
49 #include <dialog_erc.h>
50 #include <python_scripting.h>
51 #include <sch_edit_frame.h>
52 #include <sch_painter.h>
53 #include <sch_sheet.h>
54 #include <sch_marker.h>
55 #include <schematic.h>
57 #include <advanced_config.h>
58 #include <sim/sim_plot_frame.h>
59 #include <sim/spice_settings.h>
60 #include <tool/action_manager.h>
61 #include <tool/action_toolbar.h>
62 #include <tool/common_control.h>
63 #include <tool/common_tools.h>
64 #include <tool/editor_conditions.h>
65 #include <tool/picker_tool.h>
66 #include <tool/selection.h>
67 #include <tool/tool_dispatcher.h>
68 #include <tool/tool_manager.h>
69 #include <tool/zoom_tool.h>
70 #include <tools/ee_actions.h>
72 #include <tools/ee_point_editor.h>
75 #include <tools/sch_edit_tool.h>
78 #include <tools/sch_move_tool.h>
80 #include <view/view_controls.h>
81 #include <widgets/infobar.h>
83 #include <wx/cmdline.h>
84 #include <wx/app.h>
85 #include <wx/filedlg.h>
86 #include <wx/socket.h>
87 
90 
91 // non-member so it can be moved easily, and kept REALLY private.
92 // Do NOT Clear() in here.
93 static void add_search_paths( SEARCH_STACK* aDst, const SEARCH_STACK& aSrc, int aIndex )
94 {
95  for( unsigned i=0; i<aSrc.GetCount(); ++i )
96  aDst->AddPaths( aSrc[i], aIndex );
97 }
98 
99 
100 SEARCH_STACK* PROJECT::SchSearchS()
101 {
103 
104  wxASSERT( !ss || dynamic_cast<SEARCH_STACK*>( GetElem( PROJECT::ELEM_SCH_SEARCH_STACK ) ) );
105 
106  if( !ss )
107  {
108  ss = new SEARCH_STACK();
109 
110  // Make PROJECT the new SEARCH_STACK owner.
112 
113  // to the empty SEARCH_STACK for SchSearchS(), add project dir as first
114  ss->AddPaths( m_project_name.GetPath() );
115 
116  // next add the paths found in *.pro, variable "LibDir"
117  wxString libDir;
118 
119  try
120  {
121  SYMBOL_LIBS::LibNamesAndPaths( this, false, &libDir );
122  }
123  catch( const IO_ERROR& )
124  {
125  }
126 
127  if( !!libDir )
128  {
129  wxArrayString paths;
130 
131  SEARCH_STACK::Split( &paths, libDir );
132 
133  for( unsigned i =0; i<paths.GetCount(); ++i )
134  {
135  wxString path = AbsolutePath( paths[i] );
136 
137  ss->AddPaths( path ); // at the end
138  }
139  }
140 
141  // append all paths from aSList
142  add_search_paths( ss, Kiface().KifaceSearch(), -1 );
143  }
144 
145  return ss;
146 }
147 
148 
149 SYMBOL_LIBS* PROJECT::SchLibs()
150 {
152 
153  wxASSERT( !libs || libs->Type() == SYMBOL_LIBS_T );
154 
155  if( !libs )
156  {
157  libs = new SYMBOL_LIBS();
158 
159  // Make PROJECT the new SYMBOL_LIBS owner.
161 
162  try
163  {
164  libs->LoadAllLibraries( this );
165  }
166  catch( const PARSE_ERROR& pe )
167  {
168  wxString lib_list = UTF8( pe.inputLine );
169  wxWindow* parent = Pgm().App().GetTopWindow();
170 
171  // parent of this dialog cannot be NULL since that breaks the Kiway() chain.
172  HTML_MESSAGE_BOX dlg( parent, _( "Not Found" ) );
173 
174  dlg.MessageSet( _( "The following libraries were not found:" ) );
175 
176  dlg.ListSet( lib_list );
177 
178  dlg.Layout();
179 
180  dlg.ShowModal();
181  }
182  catch( const IO_ERROR& ioe )
183  {
184  wxWindow* parent = Pgm().App().GetTopWindow();
185 
186  DisplayError( parent, ioe.What() );
187  }
188  }
189 
190  return libs;
191 }
192 
193 
194 BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME )
197 
198  EVT_SIZE( SCH_EDIT_FRAME::OnSize )
199 
202 
205 
206  EVT_MENU( wxID_EXIT, SCH_EDIT_FRAME::OnExit )
207  EVT_MENU( wxID_CLOSE, SCH_EDIT_FRAME::OnExit )
208 
210 END_EVENT_TABLE()
211 
212 
213 SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
214  SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH, wxT( "Eeschema" ), wxDefaultPosition,
216  m_highlightedConn( nullptr ),
217  m_item_to_repeat( nullptr )
218 {
219  m_maximizeByDefault = true;
220  m_schematic = new SCHEMATIC( nullptr );
221 
222  m_showBorderAndTitleBlock = true; // true to show sheet references
223  m_hasAutoSave = true;
224  m_aboutTitle = _( "KiCad Schematic Editor" );
225 
226  m_findReplaceDialog = nullptr;
227 
228  // Give an icon
229  wxIcon icon;
230  wxIconBundle icon_bundle;
231 
232  icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema ) );
233  icon_bundle.AddIcon( icon );
234  icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema_32 ) );
235  icon_bundle.AddIcon( icon );
236  icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema_16 ) );
237  icon_bundle.AddIcon( icon );
238 
239  SetIcons( icon_bundle );
240 
241  LoadSettings( eeconfig() );
242 
243  // NB: also links the schematic to the loaded project
244  CreateScreens();
245 
246  setupTools();
247  setupUIConditions();
248  ReCreateMenuBar();
249  ReCreateHToolbar();
250  ReCreateVToolbar();
251  ReCreateOptToolbar();
252 
253  // Initialize common print setup dialog settings.
254  m_pageSetupData.GetPrintData().SetPrintMode( wxPRINT_MODE_PRINTER );
255  m_pageSetupData.GetPrintData().SetQuality( wxPRINT_QUALITY_MEDIUM );
256  m_pageSetupData.GetPrintData().SetBin( wxPRINTBIN_AUTO );
257  m_pageSetupData.GetPrintData().SetNoCopies( 1 );
258 
259  m_auimgr.SetManagedWindow( this );
260 
261  CreateInfoBar();
262  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" )
263  .Top().Layer( 6 ) );
264  m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" )
265  .Left().Layer( 3 ) );
266  m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" )
267  .Right().Layer( 2 ) );
268  m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" )
269  .Center() );
270  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" )
271  .Bottom().Layer( 6 ) );
272 
273  FinishAUIInitialization();
274 
275  resolveCanvasType();
276  SwitchCanvas( m_canvasType );
277 
278  LoadProjectSettings();
279 
280  initScreenZoom();
281 
282  // This is used temporarily to fix a client size issue on GTK that causes zoom to fit
283  // to calculate the wrong zoom size. See SCH_EDIT_FRAME::onSize().
284  Bind( wxEVT_SIZE, &SCH_EDIT_FRAME::onSize, this );
285 
286  if( GetCanvas() )
287  {
288  GetCanvas()->GetGAL()->SetAxesEnabled( false );
289 
290  if( auto p = dynamic_cast<KIGFX::SCH_PAINTER*>( GetCanvas()->GetView()->GetPainter() ) )
291  p->SetSchematic( m_schematic );
292  }
293 
294  setupUnits( eeconfig() );
295 
296  // Net list generator
297  DefaultExecFlags();
298 
299  UpdateTitle();
300 
301  // Default shutdown reason until a file is loaded
302  KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New schematic file is unsaved" ) );
303 
304  // Ensure the window is on top
305  Raise();
306 }
307 
308 
310 {
311  // Ensure m_canvasType is up to date, to save it in config
313 
314  // Close modeless dialogs
315  wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_ERC_WINDOW_NAME );
316 
317  if( open_dlg )
318  open_dlg->Close( true );
319 
320  // Shutdown all running tools
321  if( m_toolManager )
322  {
324  delete m_toolManager;
325  m_toolManager = nullptr;
326  }
327 
328  delete m_item_to_repeat; // we own the cloned object, see this->SaveCopyForRepeatItem()
329 
330  SetScreen( nullptr );
331 
332  delete m_schematic;
333  m_schematic = nullptr;
334 
335  // Close the project if we are standalone, so it gets cleaned up properly
336  if( Kiface().IsSingle() )
337  {
338  try
339  {
340  GetSettingsManager()->UnloadProject( &Prj(), false );
341  }
342  catch( const nlohmann::detail::type_error& exc )
343  {
344  // This may be overkill and could be an assertion but we are more likely to
345  // find any settings manager errors this way.
346  wxLogError( wxT( "Settings exception '%s' occurred." ), exc.what() );
347  }
348  }
349 }
350 
351 
353 {
354  // Create the manager and dispatcher & route draw panel events to the dispatcher
356  m_toolManager->SetEnvironment( &Schematic(), GetCanvas()->GetView(),
357  GetCanvas()->GetViewControls(), config(), this );
358  m_actions = new EE_ACTIONS();
360 
361  // Register tools
376 
377  // Run the selection tool, it is supposed to be always active
379 
381 }
382 
383 
385 {
387 
389  EDITOR_CONDITIONS cond( this );
390 
391  wxASSERT( mgr );
392 
393  auto hasElements =
394  [ this ] ( const SELECTION& aSel )
395  {
396  return GetScreen() &&
397  ( !GetScreen()->Items().empty() || !SELECTION_CONDITIONS::Idle( aSel ) );
398  };
399 
400 #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
401 #define CHECK( x ) ACTION_CONDITIONS().Check( x )
402 
404  mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) );
405  mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
406 
410  CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) );
413 
414  mgr->SetConditions( ACTIONS::cut, ENABLE( hasElements ) );
415  mgr->SetConditions( ACTIONS::copy, ENABLE( hasElements ) );
418  mgr->SetConditions( ACTIONS::doDelete, ENABLE( hasElements ) );
419  mgr->SetConditions( ACTIONS::duplicate, ENABLE( hasElements ) );
420  mgr->SetConditions( ACTIONS::selectAll, ENABLE( hasElements ) );
421 
422  mgr->SetConditions( EE_ACTIONS::rotateCW, ENABLE( hasElements ) );
423  mgr->SetConditions( EE_ACTIONS::rotateCCW, ENABLE( hasElements ) );
424  mgr->SetConditions( EE_ACTIONS::mirrorH, ENABLE( hasElements ) );
425  mgr->SetConditions( EE_ACTIONS::mirrorV, ENABLE( hasElements ) );
426 
428  CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) );
431 
432  if( SCRIPTING::IsWxAvailable() )
434  CHECK( cond.ScriptingConsoleVisible() ) );
435 
436  auto showHiddenPinsCond =
437  [this] ( const SELECTION& )
438  {
439  return GetShowAllPins();
440  };
441 
442  auto forceHVCond =
443  [this] ( const SELECTION& )
444  {
445  EESCHEMA_SETTINGS* cfg = eeconfig();
446  return cfg && cfg->m_Drawing.hv_lines_only;
447  };
448 
449  auto remapSymbolsCondition =
450  [&]( const SELECTION& aSel )
451  {
452  SCH_SCREENS schematic( Schematic().Root() );
453 
454  // The remapping can only be performed on legacy projects.
455  return schematic.HasNoFullyDefinedLibIds();
456  };
457 
458  auto belowRootSheetCondition =
459  [this]( const SELECTION& aSel )
460  {
461  return GetCurrentSheet().Last() != &Schematic().Root();
462  };
463 
464  mgr->SetConditions( EE_ACTIONS::leaveSheet, ENABLE( belowRootSheetCondition ) );
465  mgr->SetConditions( EE_ACTIONS::remapSymbols, ENABLE( remapSymbolsCondition ) );
466  mgr->SetConditions( EE_ACTIONS::toggleHiddenPins, CHECK( showHiddenPinsCond ) );
467  mgr->SetConditions( EE_ACTIONS::toggleForceHV, CHECK( forceHVCond ) );
468 
469 
470 #define CURRENT_TOOL( action ) mgr->SetConditions( action, CHECK( cond.CurrentTool( action ) ) )
471 
489 
490 #undef CURRENT_TOOL
491 #undef CHECK
492 #undef ENABLE
493 }
494 
495 
497 {
498  // we cannot store a pointer to an item in the display list here since
499  // that item may be deleted, such as part of a line concatenation or other.
500  // So simply always keep a copy of the object which is to be repeated.
501 
502  if( aItem )
503  {
504  delete m_item_to_repeat;
505 
506  m_item_to_repeat = (SCH_ITEM*) aItem->Clone();
507 
508  // Clone() preserves the flags, we want 'em cleared.
510  }
511 }
512 
513 
515 {
516  return Schematic().GetSheets().GetItem( aId );
517 }
518 
519 
521 {
522  SCH_SCREEN* screen;
523  SCH_SCREENS s_list( Schematic().Root() );
524 
525  // Set the sheet count, and the sheet number (1 for root sheet)
526  int sheet_count = Schematic().Root().CountSheets();
527  int sheet_number = 1;
528  const KIID_PATH& current_sheetpath = GetCurrentSheet().Path();
529 
530  // @todo Remove all pseudo page number system is left over from prior to real page number
531  // implementation.
532  for( const SCH_SHEET_PATH& sheet : Schematic().GetSheets() )
533  {
534  if( sheet.Path() == current_sheetpath ) // Current sheet path found
535  break;
536 
537  sheet_number++; // Not found, increment before this current path
538  }
539 
540  for( screen = s_list.GetFirst(); screen != nullptr; screen = s_list.GetNext() )
541  screen->SetPageCount( sheet_count );
542 
543  GetCurrentSheet().SetVirtualPageNumber( sheet_number );
544  GetScreen()->SetVirtualPageNumber( sheet_number );
545  GetScreen()->SetPageNumber( GetCurrentSheet().GetPageNumber() );
546 }
547 
548 
550 {
551  return GetCurrentSheet().LastScreen();
552 }
553 
554 
556 {
557  return *m_schematic;
558 }
559 
560 
562 {
563  wxString s = GetCurrentSheet().PathHumanReadable();
564 
565  return s;
566 }
567 
568 
570 {
571  m_schematic->Reset();
572  m_schematic->SetProject( &Prj() );
573 
575 
576  SCH_SCREEN* rootScreen = new SCH_SCREEN( m_schematic );
577  m_schematic->Root().SetScreen( rootScreen );
578  SetScreen( Schematic().RootScreen() );
579 
580  m_schematic->RootScreen()->SetFileName( wxEmptyString );
581 
582  // Don't leave root page number empty
583  SCH_SHEET_PATH rootSheetPath;
584  rootSheetPath.push_back( &m_schematic->Root() );
585  m_schematic->RootScreen()->SetPageNumber( wxT( "1" ) );
586  m_schematic->Root().AddInstance( rootSheetPath );
587  m_schematic->Root().SetPageNumber( rootSheetPath, wxT( "1" ) );
588 
589  if( GetScreen() == nullptr )
590  {
591  SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
592  SetScreen( screen );
593  }
594 }
595 
596 
598 {
599  return m_schematic->CurrentSheet();
600 }
601 
602 
604 {
605  if( aSheet != GetCurrentSheet() )
606  {
607  FocusOnItem( nullptr );
608 
609  Schematic().SetCurrentSheet( aSheet );
610  GetCanvas()->DisplaySheet( aSheet.LastScreen() );
611  }
612 }
613 
614 
616 {
618 
619  FocusOnItem( nullptr );
620 
621  GetCanvas()->DisplaySheet( GetCurrentSheet().LastScreen() );
622  GetCanvas()->ForceRefresh();
623 }
624 
625 
626 bool SCH_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
627 {
628  // Exit interactive editing
629  // Note this this will commit *some* pending changes. For instance, the EE_POINT_EDITOR
630  // will cancel any drag currently in progress, but commit all changes from previous drags.
631  if( m_toolManager )
633 
634  // Shutdown blocks must be determined and vetoed as early as possible
635  if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION
636  && Schematic().GetSheets().IsModified() )
637  {
638  return false;
639  }
640 
641  if( Kiface().IsSingle() )
642  {
643  auto* symbolEditor = (SYMBOL_EDIT_FRAME*) Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
644 
645  if( symbolEditor && !symbolEditor->Close() ) // Can close symbol editor?
646  return false;
647 
648  auto* symbolViewer = (SYMBOL_VIEWER_FRAME*) Kiway().Player( FRAME_SCH_VIEWER, false );
649 
650  if( symbolViewer && !symbolViewer->Close() ) // Can close symbol viewer?
651  return false;
652 
653  symbolViewer = (SYMBOL_VIEWER_FRAME*) Kiway().Player( FRAME_SCH_VIEWER_MODAL, false );
654 
655  if( symbolViewer && !symbolViewer->Close() ) // Can close modal symbol viewer?
656  return false;
657  }
658  else
659  {
660  auto* symbolEditor = (SYMBOL_EDIT_FRAME*) Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
661 
662  if( symbolEditor && symbolEditor->IsSymbolFromSchematic() )
663  {
664  if( !symbolEditor->CanCloseSymbolFromSchematic( true ) )
665  return false;
666  }
667  }
668 
669  SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) Kiway().Player( FRAME_SIMULATOR, false );
670 
671  if( simFrame && !simFrame->Close() ) // Can close the simulator?
672  return false;
673 
674  // We may have gotten multiple events; don't clean up twice
675  if( !Schematic().IsValid() )
676  return false;
677 
678  SCH_SHEET_LIST sheetlist = Schematic().GetSheets();
679 
680  if( sheetlist.IsModified() )
681  {
682  wxFileName fileName = Schematic().RootScreen()->GetFileName();
683  wxString msg = _( "Save changes to '%s' before closing?" );
684 
685  if( !HandleUnsavedChanges( this, wxString::Format( msg, fileName.GetFullName() ),
686  [&]() -> bool
687  {
688  return SaveProject();
689  } ) )
690  {
691  return false;
692  }
693  }
694 
695  // Close modeless dialogs. They're trouble when they get destroyed after the frame and/or
696  // board.
697  wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_ERC_WINDOW_NAME );
698 
699  if( open_dlg )
700  open_dlg->Close( true );
701 
702  return true;
703 }
704 
705 
707 {
708  SCH_SHEET_LIST sheetlist = Schematic().GetSheets();
709 
710  // Shutdown all running tools
711  if( m_toolManager )
713 
715 
716  // Close the find dialog and preserve its setting if it is displayed.
717  if( m_findReplaceDialog )
718  {
721 
722  m_findReplaceDialog->Destroy();
723  m_findReplaceDialog = nullptr;
724  }
725 
726  if( FindHierarchyNavigator() )
727  FindHierarchyNavigator()->Close( true );
728 
729  if( Kiway().Player( FRAME_SIMULATOR, false ) )
731 
732  SCH_SCREENS screens( Schematic().Root() );
733  wxFileName fn;
734 
735  for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
736  {
737  fn = Prj().AbsolutePath( screen->GetFileName() );
738 
739  // Auto save file name is the normal file name prepended with GetAutoSaveFilePrefix().
740  fn.SetName( GetAutoSaveFilePrefix() + fn.GetName() );
741 
742  if( fn.IsFileWritable() )
743  wxRemoveFile( fn.GetFullPath() );
744  }
745 
746  wxFileName tmpFn = Prj().GetProjectFullName();
747  wxFileName autoSaveFileName( tmpFn.GetPath(), getAutoSaveFileName() );
748 
749  if( autoSaveFileName.IsFileWritable() )
750  wxRemoveFile( autoSaveFileName.GetFullPath() );
751 
752  sheetlist.ClearModifyStatus();
753 
754  wxString fileName = Prj().AbsolutePath( Schematic().RootScreen()->GetFileName() );
755 
756  if( !Schematic().GetFileName().IsEmpty() && !Schematic().RootScreen()->IsEmpty() )
757  UpdateFileHistory( fileName );
758 
759  Schematic().RootScreen()->Clear();
760 
761  // all sub sheets are deleted, only the main sheet is usable
763 
764  // Clear view before destroying schematic as repaints depend on schematic being valid
765  SetScreen( nullptr );
766 
767  Schematic().Reset();
768 
769  Destroy();
770 }
771 
772 
774 {
775  SCH_SHEET_LIST sheetList = Schematic().GetSheets();
776  ERC_SETTINGS& ercSettings = Schematic().ErcSettings();
777 
778  ercSettings.m_ErcExclusions.clear();
779 
780  for( unsigned i = 0; i < sheetList.size(); i++ )
781  {
782  for( SCH_ITEM* item : sheetList[i].LastScreen()->Items().OfType( SCH_MARKER_T ) )
783  {
784  SCH_MARKER* marker = static_cast<SCH_MARKER*>( item );
785 
786  if( marker->IsExcluded() )
787  ercSettings.m_ErcExclusions.insert( marker->Serialize() );
788  }
789  }
790 }
791 
792 
794 {
795  SCH_SHEET_LIST sheetList = Schematic().GetSheets();
796 
797  for( SCH_MARKER* marker : Schematic().ResolveERCExclusions() )
798  {
799  SCH_SHEET_PATH errorPath;
800  ignore_unused( sheetList.GetItem( marker->GetRCItem()->GetMainItemID(), &errorPath ) );
801 
802  if( errorPath.LastScreen() )
803  errorPath.LastScreen()->Append( marker );
804  else
805  Schematic().RootScreen()->Append( marker );
806  }
807 }
808 
809 
810 SEVERITY SCH_EDIT_FRAME::GetSeverity( int aErrorCode ) const
811 {
812  return Schematic().ErcSettings().GetSeverity( aErrorCode );
813 }
814 
815 
817 {
818  // Filename is rootSheetName-sheetName-...-sheetName
819  // Note that we need to fetch the rootSheetName out of its filename, as the root SCH_SHEET's
820  // name is just a timestamp.
821 
822  wxFileName rootFn( GetCurrentSheet().at( 0 )->GetFileName() );
823  wxString filename = rootFn.GetName();
824 
825  for( unsigned i = 1; i < GetCurrentSheet().size(); i++ )
826  filename += wxT( "-" ) + GetCurrentSheet().at( i )->GetName();
827 
828  return filename;
829 }
830 
831 
833 {
834  wxASSERT( GetScreen() );
835 
836  if( !GetScreen() )
837  return;
838 
840 
841  if( ADVANCED_CFG::GetCfg().m_RealTimeConnectivity && CONNECTION_GRAPH::m_allowRealTime )
843  else
845 
846  GetCanvas()->Refresh();
848 
849  if( !GetTitle().StartsWith( "*" ) )
850  UpdateTitle();
851 }
852 
853 
854 void SCH_EDIT_FRAME::OnUpdatePCB( wxCommandEvent& event )
855 {
856  if( Kiface().IsSingle() )
857  {
858  DisplayError( this, _( "Cannot update the PCB, because the Schematic Editor is opened"
859  " in stand-alone mode. In order to create/update PCBs from"
860  " schematics, launch the KiCad shell and create a project." ) );
861  return;
862  }
863 
864  KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_EDITOR, false );
865 
866  if( !frame )
867  {
868  wxFileName fn = Prj().GetProjectFullName();
869  fn.SetExt( PcbFileExtension );
870 
871  frame = Kiway().Player( FRAME_PCB_EDITOR, true );
872  frame->OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ) );
873  }
874 
875  if( !frame->IsVisible() )
876  frame->Show( true );
877 
878  // On Windows, Raise() does not bring the window on screen, when iconized
879  if( frame->IsIconized() )
880  frame->Iconize( false );
881 
882  frame->Raise();
883 
884  std::string payload;
885  Kiway().ExpressMail( FRAME_PCB_EDITOR, MAIL_PCB_UPDATE, payload, this );
886 }
887 
888 
890 {
891  wxWindow* navigator = wxWindow::FindWindowByName( HIERARCHY_NAVIG_DLG_WNAME );
892 
893  return static_cast< HIERARCHY_NAVIG_DLG* >( navigator );
894 }
895 
896 
898 {
899  if( aForceUpdate )
900  {
901  if( FindHierarchyNavigator() )
902  FindHierarchyNavigator()->Close();
903 
904  HIERARCHY_NAVIG_DLG* hierarchyDialog = new HIERARCHY_NAVIG_DLG( this );
905 
906  hierarchyDialog->Show( true );
907  }
908  else
909  {
910  if( FindHierarchyNavigator() )
912  }
913 }
914 
915 
917 {
918  if( m_findReplaceDialog )
919  m_findReplaceDialog->Destroy();
920 
921  m_findReplaceDialog= new DIALOG_SCH_FIND( this, m_findReplaceData, wxDefaultPosition,
922  wxDefaultSize, aReplace ? wxFR_REPLACEDIALOG : 0 );
923 
926  m_findReplaceDialog->Show( true );
927 }
928 
929 
930 void SCH_EDIT_FRAME::ShowFindReplaceStatus( const wxString& aMsg, int aStatusTime )
931 {
932  // Prepare the infobar, since we don't know its state
935 
936  m_infoBar->ShowMessageFor( aMsg, aStatusTime, wxICON_INFORMATION );
937 }
938 
939 
941 {
942  m_infoBar->Dismiss();
943 }
944 
945 
947 {
950 
951  m_findReplaceDialog->Destroy();
952  m_findReplaceDialog = nullptr;
953 
955 }
956 
957 
958 void SCH_EDIT_FRAME::OnLoadFile( wxCommandEvent& event )
959 {
960  wxString fn = GetFileFromHistory( event.GetId(), _( "Schematic" ) );
961 
962  if( fn.size() )
963  OpenProjectFiles( std::vector<wxString>( 1, fn ) );
964 }
965 
966 
967 void SCH_EDIT_FRAME::OnClearFileHistory( wxCommandEvent& aEvent )
968 {
970 }
971 
972 
974 {
975  wxString pro_dir = m_mruPath;
976 
977  wxFileDialog dlg( this, _( "New Schematic" ), pro_dir, wxEmptyString,
978  KiCadSchematicFileWildcard(), wxFD_SAVE );
979 
980  if( dlg.ShowModal() != wxID_CANCEL )
981  {
982  // Enforce the extension, wxFileDialog is inept.
983  wxFileName create_me = dlg.GetPath();
984  create_me.SetExt( KiCadSchematicFileExtension );
985 
986  if( create_me.FileExists() )
987  {
988  wxString msg;
989  msg.Printf( _( "Schematic file '%s' already exists." ), create_me.GetFullName() );
990  DisplayError( this, msg );
991  return ;
992  }
993 
994  // OpenProjectFiles() requires absolute
995  wxASSERT_MSG( create_me.IsAbsolute(), "wxFileDialog returned non-absolute path" );
996 
997  OpenProjectFiles( std::vector<wxString>( 1, create_me.GetFullPath() ), KICTL_CREATE );
998  m_mruPath = create_me.GetPath();
999  }
1000 }
1001 
1002 
1004 {
1005  wxString pro_dir = m_mruPath;
1006  wxString wildcards = AllSchematicFilesWildcard()
1007  + "|" + KiCadSchematicFileWildcard()
1008  + "|" + LegacySchematicFileWildcard();
1009 
1010  wxFileDialog dlg( this, _( "Open Schematic" ), pro_dir, wxEmptyString,
1011  wildcards, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
1012 
1013  if( dlg.ShowModal() != wxID_CANCEL )
1014  {
1015  OpenProjectFiles( std::vector<wxString>( 1, dlg.GetPath() ) );
1017  }
1018 }
1019 
1020 
1021 void SCH_EDIT_FRAME::OnOpenPcbnew( wxCommandEvent& event )
1022 {
1023  wxFileName kicad_board = Prj().AbsolutePath( Schematic().GetFileName() );
1024 
1025  if( kicad_board.IsOk() && !Schematic().GetFileName().IsEmpty() )
1026  {
1027  kicad_board.SetExt( PcbFileExtension );
1028  wxFileName legacy_board( kicad_board );
1029  legacy_board.SetExt( LegacyPcbFileExtension );
1030  wxFileName& boardfn = legacy_board;
1031 
1032  if( !legacy_board.FileExists() || kicad_board.FileExists() )
1033  boardfn = kicad_board;
1034 
1035  if( Kiface().IsSingle() )
1036  {
1037  ExecuteFile( PCBNEW_EXE, boardfn.GetFullPath() );
1038  }
1039  else
1040  {
1041  KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_EDITOR, false );
1042 
1043  if( !frame )
1044  {
1045  frame = Kiway().Player( FRAME_PCB_EDITOR, true );
1046  frame->OpenProjectFiles( std::vector<wxString>( 1, boardfn.GetFullPath() ) );
1047  }
1048 
1049  if( !frame->IsVisible() )
1050  frame->Show( true );
1051 
1052  // On Windows, Raise() does not bring the window on screen, when iconized
1053  if( frame->IsIconized() )
1054  frame->Iconize( false );
1055 
1056  frame->Raise();
1057  }
1058  }
1059  else
1060  {
1061  // If we are running inside a project, it should be impossible for this case to happen
1062  wxASSERT( Kiface().IsSingle() );
1064  }
1065 }
1066 
1067 
1068 void SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event )
1069 {
1070  wxFileName fn = Prj().AbsolutePath( Schematic().GetFileName() );
1071  fn.SetExt( NetlistFileExtension );
1072 
1073  if( !ReadyToNetlist( _( "Assigning footprints requires a fully annotated schematic." ) ) )
1074  return;
1075 
1076  try
1077  {
1078  KIWAY_PLAYER* player = Kiway().Player( FRAME_CVPCB, false ); // test open already.
1079 
1080  if( !player )
1081  {
1082  player = Kiway().Player( FRAME_CVPCB, true );
1083  player->Show( true );
1084  }
1085 
1087 
1088  player->Raise();
1089  }
1090  catch( const IO_ERROR& )
1091  {
1092  DisplayError( this, _( "Could not open CvPcb" ) );
1093  }
1094 }
1095 
1096 
1097 void SCH_EDIT_FRAME::OnExit( wxCommandEvent& event )
1098 {
1099  if( event.GetId() == wxID_EXIT )
1100  Kiway().OnKiCadExit();
1101 
1102  if( event.GetId() == wxID_CLOSE || Kiface().IsSingle() )
1103  Close( false );
1104 }
1105 
1106 
1108 {
1109  wxString fileName = Prj().AbsolutePath( GetScreen()->GetFileName() );
1110 
1111  const wxBrush& brush =
1112  wxBrush( GetColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND ).ToColour() );
1113  aSettings->GetPrintDC()->SetBackground( brush );
1114  aSettings->GetPrintDC()->Clear();
1115 
1116  aSettings->GetPrintDC()->SetLogicalFunction( wxCOPY );
1117  GetScreen()->Print( aSettings );
1118  PrintDrawingSheet( aSettings, GetScreen(), IU_PER_MILS, fileName );
1119 }
1120 
1121 
1123 {
1124  // In case this event happens before g_RootSheet is initialized which does happen
1125  // on mingw64 builds.
1126 
1127  if( Schematic().IsValid() )
1128  {
1129  return IsContentModified();
1130  }
1131 
1132  return false;
1133 }
1134 
1135 
1136 static void inheritNetclass( const SCH_SHEET_PATH& aSheetPath, SCH_TEXT* aItem )
1137 {
1138  // Netclasses are assigned to subgraphs by association with their netname. However, when
1139  // a new label is attached to an existing subgraph (with an existing netclass association),
1140  // the association will be lost as the label will drive its name on to the graph.
1141  //
1142  // Here we find the previous driver of the subgraph and if it had a netclass we associate
1143  // the new netname with that netclass as well.
1144  //
1145  SCHEMATIC* schematic = aItem->Schematic();
1146  CONNECTION_SUBGRAPH* subgraph = schematic->ConnectionGraph()->GetSubgraphForItem( aItem );
1147 
1148  std::map<wxString, wxString>& netclassAssignments =
1150 
1151  if( subgraph )
1152  {
1153  SCH_ITEM* previousDriver = nullptr;
1155 
1156  for( SCH_ITEM* item : subgraph->m_drivers )
1157  {
1158  if( item == aItem )
1159  continue;
1160 
1162 
1163  if( p > priority )
1164  {
1165  priority = p;
1166  previousDriver = item;
1167  }
1168  }
1169 
1170  if( previousDriver )
1171  {
1172  wxString path = aSheetPath.PathHumanReadable();
1173  wxString oldDrivenName = path + subgraph->GetNameForDriver( previousDriver );
1174  wxString drivenName = path + subgraph->GetNameForDriver( aItem );
1175 
1176  if( netclassAssignments.count( oldDrivenName ) )
1177  netclassAssignments[ drivenName ] = netclassAssignments[ oldDrivenName ];
1178  }
1179  }
1180 }
1181 
1182 
1184  bool aUndoAppend )
1185 {
1186  wxCHECK_RET( aItem != nullptr, wxT( "Cannot add null item to list." ) );
1187 
1188  SCH_SHEET* parentSheet = nullptr;
1189  SCH_SYMBOL* parentSymbol = nullptr;
1190  SCH_ITEM* undoItem = aItem;
1191 
1192  if( aItem->Type() == SCH_SHEET_PIN_T )
1193  {
1194  parentSheet = (SCH_SHEET*) aItem->GetParent();
1195 
1196  wxCHECK_RET( parentSheet && parentSheet->Type() == SCH_SHEET_T,
1197  wxT( "Cannot place sheet pin in invalid schematic sheet." ) );
1198 
1199  undoItem = parentSheet;
1200  }
1201 
1202  else if( aItem->Type() == SCH_FIELD_T )
1203  {
1204  parentSymbol = (SCH_SYMBOL*) aItem->GetParent();
1205 
1206  wxCHECK_RET( parentSymbol && parentSymbol->Type() == SCH_SYMBOL_T,
1207  wxT( "Cannot place field in invalid schematic symbol." ) );
1208 
1209  undoItem = parentSymbol;
1210  }
1211 
1212  if( aItem->IsNew() )
1213  {
1214  if( aItem->Type() == SCH_SHEET_PIN_T )
1215  {
1216  // Sheet pins are owned by their parent sheet.
1217  SaveCopyInUndoList( aScreen, undoItem, UNDO_REDO::CHANGED, aUndoAppend );
1218 
1219  parentSheet->AddPin( (SCH_SHEET_PIN*) aItem );
1220  }
1221  else if( aItem->Type() == SCH_FIELD_T )
1222  {
1223  // Symbol fields are also owned by their parent, but new symbol fields are
1224  // handled elsewhere.
1225  wxLogMessage( wxT( "addCurrentItemToScreen: unexpected new SCH_FIELD" ) );
1226  }
1227  else
1228  {
1229  if( !aScreen->CheckIfOnDrawList( aItem ) ) // don't want a loop!
1230  AddToScreen( aItem, aScreen );
1231 
1232  SaveCopyForRepeatItem( aItem );
1233  SaveCopyInUndoList( aScreen, undoItem, UNDO_REDO::NEWITEM, aUndoAppend );
1234  }
1235 
1236  // Update connectivity info for new item
1237  if( !aItem->IsMoving() )
1238  {
1240 
1241  if( SCH_TEXT* textItem = dynamic_cast<SCH_TEXT*>( aItem ) )
1242  inheritNetclass( GetCurrentSheet(), textItem );
1243  }
1244  }
1245 
1246  aItem->ClearFlags( IS_NEW );
1247 
1248  aScreen->SetContentModified();
1249  UpdateItem( aItem );
1250 
1251  if( !aItem->IsMoving() && aItem->IsConnectable() )
1252  {
1253  std::vector< wxPoint > pts = aItem->GetConnectionPoints();
1254 
1255  for( auto i = pts.begin(); i != pts.end(); i++ )
1256  {
1257  for( auto j = i + 1; j != pts.end(); j++ )
1258  TrimWire( *i, *j );
1259 
1260  if( aScreen->IsExplicitJunctionNeeded( *i ) )
1261  AddJunction( aScreen, *i, true, false );
1262  }
1263 
1264  TestDanglingEnds();
1265 
1266  for( SCH_ITEM* item : aItem->ConnectedItems( GetCurrentSheet() ) )
1267  UpdateItem( item );
1268  }
1269 
1270  aItem->ClearEditFlags();
1271  GetCanvas()->Refresh();
1272 }
1273 
1274 
1276 {
1277  SCH_SCREEN* screen = GetScreen();
1278 
1279  wxCHECK( screen, /* void */ );
1280 
1281  wxString title;
1282 
1283  if( !screen->GetFileName().IsEmpty() )
1284  {
1285  wxFileName fn( Prj().AbsolutePath( screen->GetFileName() ) );
1286  bool readOnly = false;
1287  bool unsaved = false;
1288 
1289  if( fn.IsOk() && screen->FileExists() )
1290  readOnly = screen->IsReadOnly();
1291  else
1292  unsaved = true;
1293 
1294  if( IsContentModified() )
1295  title = wxT( "*" );
1296 
1297  title += fn.GetName();
1298  title += wxString::Format( wxT( " [%s]" ), GetCurrentSheet().PathHumanReadable( false ) );
1299 
1300  if( readOnly )
1301  title += wxS( " " ) + _( "[Read Only]" );
1302 
1303  if( unsaved )
1304  title += wxS( " " ) + _( "[Unsaved]" );
1305  }
1306  else
1307  {
1308  title = _( "[no schematic loaded]" );
1309  }
1310 
1311  title += wxT( " \u2014 " ) + _( "Schematic Editor" );
1312 
1313  SetTitle( title );
1314 }
1315 
1316 
1318 {
1320  GetScreen()->m_zoomInitialized = true;
1321 }
1322 
1323 
1325 {
1326  const SCH_CONNECTION* highlight = GetHighlightedConnection();
1327  SCH_ITEM* highlightedItem = highlight ? highlight->Parent() : nullptr;
1328  SCH_SHEET_PATH highlightPath;
1329 
1330  if( highlight )
1331  highlightPath = highlight->LocalSheet();
1332 
1333  SCHEMATIC_SETTINGS& settings = Schematic().Settings();
1334  SCH_SHEET_LIST list = Schematic().GetSheets();
1335 #ifdef PROFILE
1336  PROF_COUNTER timer;
1337 #endif
1338 
1339  // Ensure schematic graph is accurate
1340  if( aCleanupFlags == LOCAL_CLEANUP )
1341  {
1343  }
1344  else if( aCleanupFlags == GLOBAL_CLEANUP )
1345  {
1346  for( const SCH_SHEET_PATH& sheet : list )
1347  SchematicCleanUp( sheet.LastScreen() );
1348  }
1349 
1350 #ifdef PROFILE
1351  timer.Stop();
1352  wxLogTrace( "CONN_PROFILE", "SchematicCleanUp() %0.4f ms", timer.msecs() );
1353 #endif
1354 
1355  if( settings.m_IntersheetRefsShow )
1357 
1358  std::function<void( SCH_ITEM* )> changeHandler =
1359  [&]( SCH_ITEM* aChangedItem ) -> void
1360  {
1361  GetCanvas()->GetView()->Update( aChangedItem, KIGFX::REPAINT );
1362  };
1363 
1364  Schematic().ConnectionGraph()->Recalculate( list, true, &changeHandler );
1365 
1367  []( KIGFX::VIEW_ITEM* aItem )
1368  {
1369  SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem );
1370  SCH_CONNECTION* connection = item ? item->Connection() : nullptr;
1371 
1372  if( connection && connection->HasDriverChanged() )
1373  {
1374  connection->ClearDriverChanged();
1375  return true;
1376  }
1377 
1378  EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
1379 
1380  if( text && text->HasTextVars() )
1381  return true;
1382 
1383  return false;
1384  } );
1385 
1386  if( highlightedItem )
1387  SetHighlightedConnection( highlightedItem->Connection( &highlightPath ) );
1388 }
1389 
1390 
1392 {
1393  std::map<wxString, std::set<wxString>>& pageRefsMap = Schematic().GetPageRefsMap();
1394 
1395  pageRefsMap.clear();
1396 
1397  SCH_SCREENS screens( Schematic().Root() );
1398  std::vector<wxString> pageNumbers;
1399 
1400  /* Iterate over screens */
1401  for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
1402  {
1403  pageNumbers.clear();
1404 
1405  /* Find in which sheets this screen is used */
1406  for( const SCH_SHEET_PATH& sheet : Schematic().GetSheets() )
1407  {
1408  if( sheet.LastScreen() == screen )
1409  pageNumbers.push_back( sheet.GetPageNumber() );
1410  }
1411 
1412  for( SCH_ITEM* item : screen->Items() )
1413  {
1414  if( item->Type() == SCH_GLOBAL_LABEL_T )
1415  {
1416  SCH_GLOBALLABEL* globalLabel = static_cast<SCH_GLOBALLABEL*>( item );
1417  std::set<wxString>& pageList = pageRefsMap[ globalLabel->GetText() ];
1418 
1419  for( const wxString& pageNo : pageNumbers )
1420  pageList.insert( pageNo );
1421  }
1422  }
1423  }
1424 
1425  bool show = Schematic().Settings().m_IntersheetRefsShow;
1426 
1427  // Refresh all global labels. Note that we have to collect them first as the
1428  // SCH_SCREEN::Update() call is going to invalidate the RTree iterator.
1429 
1430  std::vector<SCH_GLOBALLABEL*> globalLabels;
1431 
1432  for( EDA_ITEM* item : GetScreen()->Items().OfType( SCH_GLOBAL_LABEL_T ) )
1433  globalLabels.push_back( static_cast<SCH_GLOBALLABEL*>( item ) );
1434 
1435  for( SCH_GLOBALLABEL* globalLabel : globalLabels )
1436  {
1437  globalLabel->GetIntersheetRefs()->SetVisible( show );
1438 
1439  if( show )
1440  {
1441  GetScreen()->Update( globalLabel );
1442  GetCanvas()->GetView()->Update( globalLabel );
1443  }
1444  }
1445 }
1446 
1447 
1449 {
1450  if( aShow )
1452 
1453  SCH_SCREENS screens( Schematic().Root() );
1454 
1455  for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
1456  {
1457  for( SCH_ITEM* item : screen->Items().OfType( SCH_GLOBAL_LABEL_T ) )
1458  {
1459  SCH_GLOBALLABEL* gLabel = (SCH_GLOBALLABEL*)( item );
1460  SCH_FIELD* intersheetRef = gLabel->GetIntersheetRefs();
1461 
1462  intersheetRef->SetVisible( aShow );
1463  UpdateItem( intersheetRef, true );
1464  }
1465  }
1466 }
1467 
1468 
1469 void SCH_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
1470 {
1471  SCHEMATIC_SETTINGS& settings = Schematic().Settings();
1472 
1473  SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
1475 
1477 
1478  RecreateToolbars();
1479  Layout();
1480  SendSizeEvent();
1481 }
1482 
1483 
1485 {
1486  // Store the current zoom level into the current screen before calling
1487  // DisplayCurrentSheet() that set the zoom to GetScreen()->m_LastZoomLevel
1489  // Rebuild the sheet view (draw area and any other items):
1491 }
1492 
1493 
1495 {
1496  // call my base class
1498 
1499  // tooltips in toolbars
1500  RecreateToolbars();
1501 
1502  // status bar
1503  UpdateMsgPanel();
1504 
1505  // This ugly hack is to fix an option(left) toolbar update bug that seems to only affect
1506  // windows. See https://bugs.launchpad.net/kicad/+bug/1816492. For some reason, calling
1507  // wxWindow::Refresh() does not resolve the issue. Only a resize event seems to force the
1508  // toolbar to update correctly.
1509 #if defined( __WXMSW__ )
1510  PostSizeEvent();
1511 #endif
1512 }
1513 
1514 
1516 {
1517  if( const SCH_CONNECTION* conn = GetHighlightedConnection() )
1518  {
1519  SetStatusText( wxString::Format( _( "Highlighted net: %s" ),
1520  UnescapeString( conn->Name() ) ) );
1521  }
1522  else
1523  {
1524  SetStatusText( wxT( "" ) );
1525  }
1526 }
1527 
1528 
1530 {
1531  if( m_toolManager )
1533 
1534  SCH_BASE_FRAME::SetScreen( aScreen );
1535  GetCanvas()->DisplaySheet( static_cast<SCH_SCREEN*>( aScreen ) );
1536 }
1537 
1538 
1539 const BOX2I SCH_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
1540 {
1541  BOX2I bBoxDoc;
1542 
1543  if( aIncludeAllVisible )
1544  {
1545  // Get the whole page size and return that
1546  int sizeX = GetScreen()->GetPageSettings().GetWidthIU();
1547  int sizeY = GetScreen()->GetPageSettings().GetHeightIU();
1548  bBoxDoc = BOX2I( VECTOR2I( 0, 0 ), VECTOR2I( sizeX, sizeY ) );
1549  }
1550  else
1551  {
1552  // Get current drawing-sheet in a form we can compare to an EDA_ITEM
1554  EDA_ITEM* dsAsItem = static_cast<EDA_ITEM*>( ds );
1555 
1556  // Need an EDA_RECT so the first ".Merge" sees it's uninitialized
1557  EDA_RECT bBoxItems;
1558 
1559  // Calc the bounding box of all items on screen except the page border
1560  for( EDA_ITEM* item : GetScreen()->Items() )
1561  {
1562  if( item != dsAsItem ) // Ignore the drawing-sheet itself
1563  bBoxItems.Merge( item->GetBoundingBox() );
1564 
1565  bBoxDoc = bBoxItems;
1566  }
1567  }
1568  return bBoxDoc;
1569 }
1570 
1571 
1573 {
1574  // Save the current sheet, to retrieve it later
1575  SCH_SHEET_PATH oldsheetpath = GetCurrentSheet();
1576 
1577  SCH_SHEET_LIST sheetList = Schematic().GetSheets();
1578 
1579  for( const SCH_SHEET_PATH& sheet : sheetList )
1580  {
1581  size_t num_undos = m_undoList.m_CommandsList.size();
1582 
1583  // We require a set here to avoid adding multiple junctions to the same spot
1584  std::set<wxPoint> junctions;
1585 
1586  SetCurrentSheet( sheet );
1588 
1589  SCH_SCREEN* screen = GetCurrentSheet().LastScreen();
1590 
1591  EE_SELECTION allItems;
1592 
1593  for( auto item : screen->Items() )
1594  allItems.Add( item );
1595 
1597 
1598  // Check if we modified anything during this routine
1599  // Needs to happen for every sheet to set the proper modified flag
1600  if( m_undoList.m_CommandsList.size() > num_undos )
1601  OnModify();
1602  }
1603 
1604  // Reselect the initial sheet:
1605  SetCurrentSheet( oldsheetpath );
1607  SetScreen( GetCurrentSheet().LastScreen() );
1608 }
1609 
1610 
1612 {
1613  return Schematic().GetSheets().IsModified();
1614 }
1615 
1616 
1618 {
1619  EESCHEMA_SETTINGS* cfg = eeconfig();
1620  return cfg && cfg->m_Appearance.show_hidden_pins;
1621 }
1622 
1623 
1625 {
1626  static KIID lastBrightenedItemID( niluuid );
1627 
1628  SCH_SHEET_LIST sheetList = Schematic().GetSheets();
1630  SCH_ITEM* lastItem = sheetList.GetItem( lastBrightenedItemID, &dummy );
1631 
1632  if( lastItem && lastItem != aItem )
1633  {
1634  lastItem->ClearBrightened();
1635 
1636  UpdateItem( lastItem );
1637  lastBrightenedItemID = niluuid;
1638  }
1639 
1640  if( aItem )
1641  {
1642  aItem->SetBrightened();
1643 
1644  UpdateItem( aItem );
1645  lastBrightenedItemID = aItem->m_Uuid;
1646 
1647  FocusOnLocation( aItem->GetFocusPosition() );
1648  }
1649 }
1650 
1651 
1653 {
1654  return Schematic().GetFileName();
1655 }
1656 
1657 
1659 {
1660  return m_toolManager->GetTool<EE_SELECTION_TOOL>()->GetSelection();
1661 }
1662 
1663 
1664 void SCH_EDIT_FRAME::onSize( wxSizeEvent& aEvent )
1665 {
1666  if( IsShown() )
1667  {
1668  // We only need this until the frame is done resizing and the final client size is
1669  // established.
1670  Unbind( wxEVT_SIZE, &SCH_EDIT_FRAME::onSize, this );
1672  }
1673 
1674  // Skip() is called in the base class.
1675  EDA_DRAW_FRAME::OnSize( aEvent );
1676 }
1677 
1678 
1680  const KIID& aSchematicSymbolUUID )
1681 {
1682  wxString msg;
1683  bool appendToUndo = false;
1684 
1685  SCH_SHEET_PATH sheetPath;
1686  SCH_ITEM* item = Schematic().GetSheets().GetItem( aSchematicSymbolUUID, &sheetPath );
1687 
1688  if( item )
1689  {
1690  SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
1691 
1692  wxCHECK( symbol, /* void */ );
1693 
1694  // This needs to be done before the LIB_SYMBOL is changed to prevent stale library
1695  // symbols in the schematic file.
1696  sheetPath.LastScreen()->Remove( symbol );
1697 
1698  if( !symbol->IsNew() )
1699  {
1700  SaveCopyInUndoList( sheetPath.LastScreen(), symbol, UNDO_REDO::CHANGED, appendToUndo );
1701  appendToUndo = true;
1702  }
1703 
1704  symbol->SetLibSymbol( aSymbol.Flatten().release() );
1705  symbol->UpdateFields( &GetCurrentSheet(),
1706  true, /* update style */
1707  true, /* update ref */
1708  true, /* update other fields */
1709  false, /* reset ref */
1710  false /* reset other fields */ );
1711 
1712  sheetPath.LastScreen()->Append( symbol );
1713  GetCanvas()->GetView()->Update( symbol );
1714  }
1715 
1716  GetCanvas()->Refresh();
1717  OnModify();
1718 }
void ShutdownAllTools()
Shutdown all tools with a currently registered event loop in this tool manager by waking them up with...
const std::string NetlistFileExtension
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
bool ReadyToNetlist(const wxString &aAnnotateMessage)
Check if we are ready to write a netlist file for the current schematic.
void UpdateFields(const SCH_SHEET_PATH *aPath, bool aUpdateStyle, bool aUpdateRef, bool aUpdateOtherFields, bool aResetRef, bool aResetOtherFields)
Restore fields to the original library values.
Definition: sch_symbol.cpp:759
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:279
bool empty() const
Definition: sch_rtree.h:177
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
const wxString & getAutoSaveFileName() const
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:70
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void ShowFindReplaceStatus(const wxString &aMsg, int aStatusTime)
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
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:49
SEVERITY GetSeverity(int aErrorCode) const override
void OnOpenCvpcb(wxCommandEvent &event)
void onSize(wxSizeEvent &aEvent)
std::map< wxString, wxString > m_NetClassAssignments
Definition: net_settings.h:44
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
bool SchematicCleanUp(SCH_SCREEN *aScreen=nullptr)
Perform routine schematic cleaning including breaking wire and buses and deleting identical objects s...
SCHEMATIC * m_schematic
The currently loaded schematic.
const wxString & GetFileName() const
Definition: sch_screen.h:145
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
BOX2< VECTOR2I > BOX2I
Definition: box2.h:506
wxString LegacySchematicFileWildcard()
bool Remove(SCH_ITEM *aItem)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:273
SCH_SCREEN * GetNext()
void OnKiCadExit()
Definition: kiway.cpp:626
void UpdateNetHighlightStatus()
virtual bool IsConnectable() const
Definition: sch_item.h:349
HIERARCHY_NAVIG_DLG * FindHierarchyNavigator()
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
Open a project or set of files given by aFileList.
void ForceRefresh()
Force a redraw.
KIID niluuid(0)
void OnLoadFile(wxCommandEvent &event)
void Merge(const EDA_RECT &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: eda_rect.cpp:432
wxString m_mruPath
void SetPageNumber(const wxString &aPageNumber)
Definition: base_screen.h:79
void UpdateAllItemsConditionally(int aUpdateFlags, std::function< bool(VIEW_ITEM *)> aCondition)
Update items in the view according to the given flags and condition.
Definition: view.cpp:1492
void SetVirtualPageNumber(int aPageNumber)
Definition: base_screen.h:76
wxArrayString GetFindEntries() const
virtual std::vector< wxPoint > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
Definition: sch_item.h:364
SETTINGS_MANAGER * GetSettingsManager() const
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
void RecalculateConnections(SCH_CLEANUP_FLAGS aCleanupFlags)
Generate the connection data for the entire schematic hierarchy.
virtual void PrintPage(const RENDER_SETTINGS *aSettings) override
Plot or print the current sheet to the clipboard.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Holds all the data relating to one schematic.
Definition: schematic.h:59
#define IS_NEW
New item, just created.
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:131
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
Implementation of conversion functions that require both schematic and board internal units.
This file is part of the common library.
static TOOL_ACTION doDelete
Definition: actions.h:72
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:32
Tool responsible for drawing/placing items (symbols, wires, buses, labels, etc.).
static void add_search_paths(SEARCH_STACK *aDst, const SEARCH_STACK &aSrc, int aIndex)
bool IsModified() const
Check the entire hierarchy for any modifications.
SELECTION_CONDITION FullscreenCursor()
Create a functor testing if the cursor is full screen in a frame.
const wxString PCBNEW_EXE
Definition: id.h:87
const std::string LegacyPcbFileExtension
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
void SetScreen(BASE_SCREEN *aScreen) override
const SCH_CONNECTION * GetHighlightedConnection() const
virtual void SetScreen(BASE_SCREEN *aScreen)
UNDO_REDO_CONTAINER m_undoList
static TOOL_ACTION zoomTool
Definition: actions.h:99
static bool Idle(const SELECTION &aSelection)
Test if there no items selected or being edited.
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType
bool IsReadOnly() const
Definition: sch_screen.h:148
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
wxString PathHumanReadable(bool aUseShortRootName=true) const
Return the sheet path in a human readable form made from the sheet names.
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:145
#define KICTL_CREATE
caller thinks requested project files may not exist.
Definition: kiway_player.h:82
Handle actions specific to the schematic editor.
bool IsMoving() const
Definition: eda_item.h:119
static void LibNamesAndPaths(PROJECT *aProject, bool doSave, wxString *aPaths, wxArrayString *aNames=nullptr)
Save or load the names of the currently configured symbol libraries (without paths).
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:167
static TOOL_ACTION placeHierLabel
Definition: ee_actions.h:87
double m_LastZoomLevel
last value for the zoom level, useful in Eeschema when changing the current displayed sheet to reuse ...
Definition: sch_screen.h:508
static TOOL_ACTION placeJunction
Definition: ee_actions.h:83
virtual const wxPoint GetFocusPosition() const
Similar to GetPosition, but allows items to return their visual center rather than their anchor.
Definition: eda_item.h:258
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:172
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Returns bbox of document with option to not include some items.
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:108
static TOOL_ACTION cancelInteractive
Definition: actions.h:62
wxString KiCadSchematicFileWildcard()
SELECTION_CONDITION CurrentTool(const TOOL_ACTION &aTool)
Create a functor testing if the specified tool is the current active tool in the frame.
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:104
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
void SetBrightened()
Definition: eda_item.h:129
static TOOL_ACTION remapSymbols
Definition: ee_actions.h:158
void ResolveERCExclusions()
Update markers to match recorded exclusions.
static TOOL_ACTION zoomFitScreen
Definition: actions.h:96
static TOOL_ACTION millimetersUnits
Definition: actions.h:146
void RecreateToolbars()
Rebuild all toolbars, and update the checked state of check tools.
void SetConnectivityDirty()
Definition: sch_screen.cpp:790
wxArrayString m_findStringHistoryList
void UpdateTitle()
Set the main window title bar text.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
void OnAppendProject(wxCommandEvent &event)
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
NET_SETTINGS & NetSettings()
Definition: project_file.h:96
Symbol library viewer main window.
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:383
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:477
int GetSchematicJunctionSize()
SCH_CLEANUP_FLAGS
Schematic editor (Eeschema) main window.
void Recalculate(const SCH_SHEET_LIST &aSheetList, bool aUnconditional=false, std::function< void(SCH_ITEM *)> *aChangedItemHandler=nullptr)
Updates the connection graph for the given list of sheets.
Look for files in a number of paths.
Definition: search_stack.h:41
static TOOL_ACTION placeBusWireEntry
Definition: ee_actions.h:84
SELECTION_CONDITION RedoAvailable()
Create a functor that tests if there are any items in the redo queue.
void OnPageSettingsChange() override
Called when modifying the page settings.
void ShowMessageFor(const wxString &aMessage, int aTime, int aFlags=wxICON_INFORMATION, MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the infobar with the provided message and icon for a specific period of time.
Definition: infobar.cpp:128
Manage TOOL_ACTION objects.
virtual _ELEM * GetElem(ELEM_T aIndex)
Get and set the elements for this project.
Definition: project.cpp:246
void DisplayCurrentSheet()
Draw the current sheet on the display.
Definition: hierarch.cpp:285
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:76
static TOOL_ACTION mirrorH
Definition: ee_actions.h:119
void UpdateAllScreenReferences()
Update all the symbol references for this sheet path.
The base class for create windows for drawing purpose.
void OnFindDialogClose()
Notification that the Find dialog has closed.
bool HasDriverChanged() const
VECTOR2< int > VECTOR2I
Definition: vector2d.h:622
Define a library symbol object.
Definition: lib_symbol.h:96
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
bool canCloseWindow(wxCloseEvent &aCloseEvent) override
A thread-safe event counter.
Definition: profile.h:225
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:132
std::shared_ptr< NGSPICE_SIMULATOR_SETTINGS > m_NgspiceSimulatorSettings
Ngspice simulator settings.
EESCHEMA_SETTINGS * eeconfig()
int ExecuteFile(const wxString &aEditorName, const wxString &aFileName, wxProcess *aCallback)
Call the executable file aEditorName with the parameter aFileName.
Definition: gestfich.cpp:115
void SetLibSymbol(LIB_SYMBOL *aLibSymbol)
Set this schematic symbol library symbol reference to aLibSymbol.
Definition: sch_symbol.cpp:259
A subgraph is a set of items that are electrically connected on a single sheet.
void AddPin(SCH_SHEET_PIN *aSheetPin)
Add aSheetPin to the sheet.
Definition: sch_sheet.cpp:315
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:122
Class that groups generic conditions for editor states.
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Definition: lib_symbol.cpp:365
bool IsContentModified() const override
Get if the current schematic has been modified but not saved.
void SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1183
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
std::set< wxString > m_ErcExclusions
Definition: erc_settings.h:167
void LoadAllLibraries(PROJECT *aProject, bool aShowProgress=true)
Load all of the project's libraries into this container, which should be cleared before calling it.
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:83
static TOOL_ACTION mirrorV
Definition: ee_actions.h:118
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
Definition: project.cpp:269
static TOOL_ACTION rotateCW
Definition: ee_actions.h:116
#define DIALOG_ERC_WINDOW_NAME
Definition: dialog_erc.h:37
void Clear(bool aFree=true)
Delete all draw items and clears the project settings.
Definition: sch_screen.cpp:228
bool IsNew() const
Definition: eda_item.h:118
SCH_SHEET_PATH LocalSheet() const
void OnImportProject(wxCommandEvent &event)
SCH_JUNCTION * AddJunction(SCH_SCREEN *aScreen, const wxPoint &aPos, bool aAppendToUndo, bool aFinal=true)
static TOOL_ACTION leaveSheet
Definition: ee_actions.h:185
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:258
void ClearBrightened()
Definition: eda_item.h:132
wxString GetFileFromHistory(int cmdId, const wxString &type, FILE_HISTORY *aFileHistory=nullptr)
Fetches the file name from the file history list.
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:138
bool SaveProject(bool aSaveAs=false)
Save the currently-open schematic (including its hierarchy) and associated project.
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:140
static TOOL_ACTION updateFind
Definition: actions.h:82
EESCHEMA_SETTINGS * eeconfig() const
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
void SetShutdownBlockReason(wxWindow *aWindow, const wxString &aReason)
Sets the block reason why the window/application is preventing OS shutdown.
Definition: gtk/app.cpp:83
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
Definition: schematic.cpp:104
wxString GetScreenDesc() const override
Return a human-readable description of the current screen.
Handle actions specific to the schematic editor.
KICAD_T Type() override
static TOOL_ACTION drawSheet
Definition: ee_actions.h:88
Master controller class:
Definition: tool_manager.h:54
void ShowChangedLanguage() override
void OnClearFileHistory(wxCommandEvent &aEvent)
virtual void SetVisible(bool aVisible)
Definition: eda_text.h:206
EVT_MENU_RANGE(ID_GERBVIEW_DRILL_FILE1, ID_GERBVIEW_DRILL_FILEMAX, GERBVIEW_FRAME::OnDrlFileHistory) EVT_MENU_RANGE(ID_GERBVIEW_ZIP_FILE1
Definition: kiid.h:44
static TOOL_ACTION copy
Definition: actions.h:67
void doCloseWindow() override
static TOOL_ACTION rotateCCW
Definition: ee_actions.h:117
wxArrayString GetReplaceEntries() const
static TOOL_ACTION highlightNetTool
Definition: ee_actions.h:222
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: infobar.cpp:175
Item needs to be redrawn.
Definition: view_item.h:52
static TOOL_ACTION placePower
Definition: ee_actions.h:78
void DisplaySheet(SCH_SCREEN *aScreen)
const wxString & GetNameForDriver(SCH_ITEM *aItem)
Returns the candidate net name for a driver.
SELECTION_CONDITION GridVisible()
Create a functor testing if the grid is visible in a frame.
#define SCH_EDIT_FRAME_NAME
wxString GetName() const
Definition: sch_sheet.h:103
void TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
wxArrayString m_replaceStringHistoryList
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
SELECTION_CONDITION Units(EDA_UNITS aUnit)
Create a functor that tests if the frame has the specified units.
void UpdateHierarchyTree()
Update the hierarchical tree of the schematic.
Definition: hierarch.cpp:208
static TOOL_ACTION drawWire
Definition: ee_actions.h:79
size_t size() const
Forwarded method from std::vector.
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
Tool responsible for drawing/placing items (symbols, wires, buses, labels, etc.)
wxFileName m_project_name
<fullpath>/<basename>.pro
Definition: project.h:342
void HardRedraw() override
Rebuild the GAL and redraw the screen.
static TOOL_ACTION toggleGrid
Definition: actions.h:140
void SetVirtualPageNumber(int aPageNumber)
Set the sheet instance virtual page number.
virtual void OnSize(wxSizeEvent &event) override
Recalculate the size of toolbars and display panel when the frame size changes.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
static int Split(wxArrayString *aResult, const wxString &aPathString)
Separate aPathString into individual paths.
static void inheritNetclass(const SCH_SHEET_PATH &aSheetPath, SCH_TEXT *aItem)
static TOOL_ACTION inchesUnits
Definition: actions.h:144
Subclass of DIALOG_SCH_FIND_BASE, which is generated by wxFormBuilder.
Handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:40
bool FileExists() const
Definition: sch_screen.h:151
static TOOL_ACTION save
Definition: actions.h:51
static TOOL_ACTION placeSchematicText
Definition: ee_actions.h:90
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SaveCopyForRepeatItem(const SCH_ITEM *aItem)
Clone aItem and owns that clone in this container.
void initScreenZoom()
Initialize the zoom value of the current screen and mark the screen as zoom-initialized.
static TOOL_ACTION placeImage
Definition: ee_actions.h:92
SELECTION_CONDITION ScriptingConsoleVisible()
Create a functor testing if the python scripting console window is visible.
void ShowAllIntersheetRefs(bool aShow)
void OnSockRequest(wxSocketEvent &evt)
Definition: eda_dde.cpp:63
ACTIONS * m_actions
Definition: tools_holder.h:159
static TOOL_ACTION cut
Definition: actions.h:66
SCHEMATIC & Schematic() const
void UpdateHierarchyNavigator(bool aForceUpdate=false)
Run the Hierarchy Navigator dialog.
Definition of file extensions used in Kicad.
static TOOL_ACTION showPythonConsole
Definition: ee_actions.h:210
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
Definition for symbol library class.
EDA_ITEM * GetParent() const
Definition: eda_item.h:114
SCH_ITEM * m_item_to_repeat
Last item to insert by the repeat command.
#define _(s)
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false)
Mark an item for refresh.
DIALOG_SCH_FIND * m_findReplaceDialog
Subclass of SIM_PLOT_FRAME_BASE, which is generated by wxFormBuilder.
#define HIERARCHY_NAVIG_DLG_WNAME
Definition: hierarch.h:36
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:153
bool IsExcluded() const
Definition: marker_base.h:95
std::vector< SCH_ITEM * > m_drivers
wxDC * GetPrintDC() const
bool SupportsShutdownBlockReason()
Whether or not the window supports setting a shutdown block reason.
Definition: gtk/app.cpp:72
#define KICAD_DEFAULT_DRAWFRAME_STYLE
#define PcbFileExtension
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: ee_actions.h:46
SCHEMATIC_SETTINGS * m_SchematicSettings
Definition: project_file.h:130
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:65
bool HasNoFullyDefinedLibIds()
Test all of the schematic symbols to see if all LIB_ID objects library nickname is not set.
static TOOL_ACTION importSheetPin
Definition: ee_actions.h:89
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
static TOOL_ACTION placeSymbol
Definition: ee_actions.h:77
bool isAutoSaveRequired() const override
Return true if the schematic has been modified.
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:161
Container for ERC settings.
Definition: erc_settings.h:106
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition: project.cpp:116
SEVERITY
void PrintDrawingSheet(const RENDER_SETTINGS *aSettings, BASE_SCREEN *aScreen, double aMils2Iu, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString)
Prints the drawing-sheet (frame and title block).
static TOOL_ACTION addNeededJunctions
Definition: ee_actions.h:75
void SetReplaceEntries(const wxArrayString &aEntries)
wxString Serialize() const
Definition: sch_marker.cpp:66
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
void SetProject(PROJECT *aPrj)
Definition: schematic.cpp:76
Handle actions that are shared between different applications.
void OnUpdatePCB(wxCommandEvent &event)
COLOR_SETTINGS * GetColorSettings() const override
Returns a pointer to the active color theme settings.
void clear()
Forwarded method from std::vector.
void SetFindEntries(const wxArrayString &aEntries)
Specialization of the wxAuiPaneInfo class for KiCad panels.
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...
void SaveSymbolToSchematic(const LIB_SYMBOL &aSymbol, const KIID &aSchematicSymbolUUID)
Update a schematic symbol from a LIB_SYMBOL.
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: infobar.cpp:286
static TOOL_ACTION milsUnits
Definition: actions.h:145
bool Show(bool show) override
wxString UnescapeString(const wxString &aSource)
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:160
Gather all the actions that are shared by tools.
Definition: ee_actions.h:38
Handles action that are shared between different applications.
Definition: common_tools.h:37
static TOOL_ACTION drawBus
Definition: ee_actions.h:80
Implementing SIM_PLOT_FRAME_BASE.
void OnSockRequestServer(wxSocketEvent &evt)
Definition: eda_dde.cpp:93
A collection of SYMBOL_LIB objects.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
static TOOL_ACTION pasteSpecial
Definition: actions.h:69
const KIID m_Uuid
Definition: eda_item.h:474
void ClearFileHistory(FILE_HISTORY *aFileHistory=nullptr)
Removes all files from the file history.
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
void SetContentModified(bool aModified=true)
Definition: base_screen.h:59
static bool m_allowRealTime
bool IsExplicitJunctionNeeded(const wxPoint &aPosition) const
Indicates that a junction dot is necessary at the given location, and does not yet exist.
Definition: sch_screen.cpp:423
static TOOL_ACTION placeLabel
Definition: ee_actions.h:85
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr) const
Fetch a SCH_ITEM by ID.
static wxString GetAutoSaveFilePrefix()
SCH_FIELD * GetIntersheetRefs()
Definition: sch_text.h:415
int CountSheets() const
Count the number of sheets found in "this" sheet including all of the subsheets.
Definition: sch_sheet.cpp:728
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
Definition: schematic.cpp:51
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:87
static TOOL_ACTION redo
Definition: actions.h:65
void ClearFindReplaceStatus()
void SetHighlightedConnection(const SCH_CONNECTION *aConnection)
SCH_SHEET & Root() const
Definition: schematic.h:92
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:118
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:158
see class PGM_BASE
void AddItemToScreenAndUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItem, bool aUndoAppend)
Add an item to the schematic and adds the changes to the undo/redo container.
Schematic symbol object.
Definition: sch_symbol.h:78
void OnExit(wxCommandEvent &event)
SCH_SCREEN * LastScreen()
void Print(const RENDER_SETTINGS *aSettings)
Print all the items in the screen to aDC.
Definition: sch_screen.cpp:797
void AddToScreen(EDA_ITEM *aItem, SCH_SCREEN *aScreen)
Add an item to the screen (and view) aScreen is the screen the item is located on,...
bool m_zoomInitialized
Definition: sch_screen.h:543
SCH_ITEM_SET & ConnectedItems(const SCH_SHEET_PATH &aPath)
Retrieve the set of items connected to this item on the given sheet.
Definition: sch_item.cpp:177
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:146
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
static TOOL_ACTION toggleHiddenPins
Definition: ee_actions.h:195
wxString AllSchematicFilesWildcard()
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).
WX_INFOBAR * m_infoBar
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend)
Create a copy of the current schematic item, and put it in the undo list.
Tool that displays edit points allowing to modify items by dragging the points.
SELECTION_CONDITION UndoAvailable()
Create a functor that tests if there are any items in the undo queue.
void RecomputeIntersheetRefs()
Update the schematic's page reference map for all global labels, and refresh the labels so that they ...
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Saves, unloads and unregisters the given PROJECT.
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:110
SCH_SHEET * at(size_t aIndex) const
Forwarded method from std::vector.
static TOOL_ACTION placeNoConnect
Definition: ee_actions.h:82
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
Handle the component boundary box.
Definition: eda_rect.h:42
const std::string KiCadSchematicFileExtension
void ShowFindReplaceDialog(bool aReplace)
Run the Find or Find & Replace dialog.
void OnOpenPcbnew(wxCommandEvent &event)
#define IU_PER_MILS
Definition: plotter.cpp:136
void SetCurrentSheet(const SCH_SHEET_PATH &aPath) override
Definition: schematic.h:126
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
wxString GetCurrentFileName() const override
Get the full filename + path of the currently opened file in the frame.
SCH_ITEM * Parent() const
void ignore_unused(const T &)
Definition: ignore.h:24
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
These settings were stored in SCH_BASE_FRAME previously.
~SCH_EDIT_FRAME() override
wxString GetUniqueFilenameForCurrentSheet()
#define CURRENT_TOOL(action)
wxFindReplaceData * m_findReplaceData
ACTION_MANAGER * GetActionManager() const
Definition: tool_manager.h:199
std::map< wxString, std::set< wxString > > & GetPageRefsMap()
Definition: schematic.h:162
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
#define CHECK(x)
SCH_SHEET_PATH & GetCurrentSheet() const
static TOOL_ACTION deleteTool
Definition: actions.h:73
bool TrimWire(const wxPoint &aStart, const wxPoint &aEnd)
If any single wire passes through both points, remove the portion between the two points,...
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
Definition: id.h:86
void FocusOnItem(SCH_ITEM *aItem)
static TOOL_ACTION undo
Definition: actions.h:64
SCH_SCREEN * GetFirst()
EDA_ITEM * GetItem(const KIID &aId) const override
Fetch an item by KIID.
static TOOL_ACTION drawLines
Definition: ee_actions.h:91
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
CONNECTION_SUBGRAPH * GetSubgraphForItem(SCH_ITEM *aItem)
void OnGridSettings(wxCommandEvent &event)
GAL_TYPE GetBackend() const
Return the type of backend currently used by GAL canvas.
DS_PROXY_VIEW_ITEM * GetDrawingSheet() const
Definition: sch_view.h:98
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:102
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current screen and u...
void Update(SCH_ITEM *aItem)
Update aItem's bounding box in the tree.
Definition: sch_screen.cpp:266
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:174
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Definition: sch_screen.cpp:110
void InitTools()
Initializes all registered tools.
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:117
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:121
static TOOL_ACTION placeGlobalLabel
Definition: ee_actions.h:86
double GetScale() const
Definition: view.h:264
void ClearEditFlags()
Definition: eda_item.h:171
static TOOL_ACTION toggleForceHV
Definition: ee_actions.h:206
void FocusOnLocation(const wxPoint &aPos)
Useful to focus on a particular location, in find functions.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Called after the preferences dialog is run.
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
std::string inputLine
problem line of input [say, from a LINE_READER].
Definition: ki_exception.h:127
void SetPageCount(int aPageCount)
Definition: base_screen.cpp:63
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
static TOOL_ACTION selectAll
Definition: actions.h:70
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:154
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
static TOOL_ACTION paste
Definition: actions.h:68
#define ENABLE(x)
bool IsSingle() const
Is this KIFACE running under single_top?
Definition: kiface_base.h:104
void AddPaths(const wxString &aPaths, int aIndex=-1)
Insert or append path(s).
bool GetShowAllPins() const override
Allow edit frame to show/hide hidden pins.
static TOOL_ACTION duplicate
Definition: actions.h:71
PRIORITY GetDriverPriority()
static TOOL_ACTION selectionTool
Definition: actions.h:153
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:593
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1570
void RegisterTool(TOOL_BASE *aTool)
Add a tool to the manager set and sets it up.
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
bool AddInstance(const SCH_SHEET_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1138
void sendNetlistToCvpcb()
Send the KiCad netlist over to CVPCB.
virtual void UpdateMsgPanel()
Redraw the message panel.
bool CheckIfOnDrawList(const SCH_ITEM *aItem) const
Definition: sch_screen.cpp:336
SEVERITY GetSeverity(int aErrorCode) const
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
Definition: infobar.cpp:276
The symbol library editor main window.