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-2022 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>
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/picker_tool.h>
65#include <tool/selection.h>
67#include <tool/tool_manager.h>
68#include <tool/zoom_tool.h>
69#include <tools/ee_actions.h>
74#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>
88
91
92
93BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME )
96
97 EVT_SIZE( SCH_EDIT_FRAME::OnSize )
98
101
104
105 EVT_MENU( wxID_EXIT, SCH_EDIT_FRAME::OnExit )
106 EVT_MENU( wxID_CLOSE, SCH_EDIT_FRAME::OnExit )
107
109
110 // Drop files event
111 EVT_DROP_FILES( SCH_EDIT_FRAME::OnDropFiles )
112END_EVENT_TABLE()
113
114
115SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
116 SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH, wxT( "Eeschema" ), wxDefaultPosition,
118 m_highlightedConn( nullptr )
119{
120 m_maximizeByDefault = true;
121 m_schematic = new SCHEMATIC( nullptr );
122
123 m_showBorderAndTitleBlock = true; // true to show sheet references
124 m_supportsAutoSave = true;
125 m_syncingPcbToSchSelection = false;
126 m_aboutTitle = _( "KiCad Schematic Editor" );
127
128 m_findReplaceDialog = nullptr;
129
130 m_findReplaceData = std::make_unique<SCH_SEARCH_DATA>();
131
132 // Give an icon
133 wxIcon icon;
134 wxIconBundle icon_bundle;
135
136 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema ) );
137 icon_bundle.AddIcon( icon );
138 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema_32 ) );
139 icon_bundle.AddIcon( icon );
140 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema_16 ) );
141 icon_bundle.AddIcon( icon );
142
143 SetIcons( icon_bundle );
144
145 LoadSettings( eeconfig() );
146
147 // NB: also links the schematic to the loaded project
148 CreateScreens();
149
150 setupTools();
151 setupUIConditions();
152 ReCreateMenuBar();
153 ReCreateHToolbar();
154 ReCreateVToolbar();
155 ReCreateOptToolbar();
156
157 m_hierarchy = new HIERARCHY_NAVIG_PANEL( this );
158
159 // Initialize common print setup dialog settings.
160 m_pageSetupData.GetPrintData().SetPrintMode( wxPRINT_MODE_PRINTER );
161 m_pageSetupData.GetPrintData().SetQuality( wxPRINT_QUALITY_MEDIUM );
162 m_pageSetupData.GetPrintData().SetBin( wxPRINTBIN_AUTO );
163 m_pageSetupData.GetPrintData().SetNoCopies( 1 );
164
165 m_auimgr.SetManagedWindow( this );
166
167 CreateInfoBar();
168
169 // Rows; layers 4 - 6
170 m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" )
171 .Top().Layer( 6 ) );
172
173 m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" )
174 .Bottom().Layer( 6 ) );
175
176 // Columns; layers 1 - 3
177 m_auimgr.AddPane( m_hierarchy, EDA_PANE().Palette().Name( SchematicHierarchyPaneName() )
178 .Caption( _( "Schematic Hierarchy" ) )
179 .Left().Layer( 3 )
180 .TopDockable( false )
181 .BottomDockable( false )
182 .CloseButton( true )
183 .MinSize( 120, 60 )
184 .BestSize( 200, 200 )
185 .FloatingSize( 200, 200 )
186 .Show( false ) );
187 m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" )
188 .Left().Layer( 2 ) );
189
190 m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" )
191 .Right().Layer( 2 ) );
192
193 // Center
194 m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" )
195 .Center() );
196
197 FinishAUIInitialization();
198
199 resolveCanvasType();
200 SwitchCanvas( m_canvasType );
201
202 GetCanvas()->GetGAL()->SetAxesEnabled( false );
203
204 KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
205 static_cast<KIGFX::SCH_PAINTER*>( view->GetPainter() )->SetSchematic( m_schematic );
206
207 wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
209
210 hierarchy_pane.Show( cfg->m_AuiPanels.show_schematic_hierarchy );
211
214 {
215 // Show at end, after positioning
216 hierarchy_pane.FloatingSize( cfg->m_AuiPanels.hierarchy_panel_float_width,
218 }
219
221 hierarchy_pane.Float();
222
224 {
225 SetAuiPaneSize( m_auimgr, hierarchy_pane,
227
228 // wxAUI hack: force width by setting MinSize() and then Fixed()
229 // thanks to ZenJu http://trac.wxwidgets.org/ticket/13180
230 hierarchy_pane.MinSize( cfg->m_AuiPanels.hierarchy_panel_docked_width, -1 );
231 hierarchy_pane.Fixed();
232 m_auimgr.Update();
233
234 // now make it resizable again
235 hierarchy_pane.Resizable();
236 m_auimgr.Update();
237
238 // Note: DO NOT call m_auimgr.Update() anywhere after this; it will nuke the size
239 // back to minimum.
240 hierarchy_pane.MinSize( 120, 60 );
241 }
242 else
243 {
244 m_auimgr.Update();
245 }
246
247 LoadProjectSettings();
248
249 initScreenZoom();
250
251 m_hierarchy->Connect( wxEVT_SIZE,
252 wxSizeEventHandler( SCH_EDIT_FRAME::OnResizeHierarchyNavigator ),
253 NULL, this );
254
255
256 // This is used temporarily to fix a client size issue on GTK that causes zoom to fit
257 // to calculate the wrong zoom size. See SCH_EDIT_FRAME::onSize().
258 Bind( wxEVT_SIZE, &SCH_EDIT_FRAME::onSize, this );
259
260 setupUnits( eeconfig() );
261
262 // Net list generator
263 DefaultExecFlags();
264
265 UpdateTitle();
266 m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->ResetHistory();
267
268 // Default shutdown reason until a file is loaded
269 KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New schematic file is unsaved" ) );
270
271 // Init for dropping files
272 m_acceptedExts.emplace( KiCadSchematicFileExtension, &EE_ACTIONS::ddAppendFile );
273 DragAcceptFiles( true );
274
275 // Ensure the window is on top
276 Raise();
277
278 // Now that all sizes are fixed, set the initial hierarchy_pane floating position to the
279 // top-left corner of the canvas
280 wxPoint canvas_pos = GetCanvas()->GetScreenPosition();
281 hierarchy_pane.FloatingPosition( canvas_pos.x + 10, canvas_pos.y + 10 );
282}
283
284
286{
287 m_hierarchy->Disconnect( wxEVT_SIZE,
288 wxSizeEventHandler( SCH_EDIT_FRAME::OnResizeHierarchyNavigator ),
289 NULL, this );
290 // Ensure m_canvasType is up to date, to save it in config
292
293 // Close modeless dialogs
294 wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_ERC_WINDOW_NAME );
295
296 if( open_dlg )
297 open_dlg->Close( true );
298
299 // Shutdown all running tools
300 if( m_toolManager )
301 {
303 delete m_toolManager;
304 m_toolManager = nullptr;
305 }
306
307 SetScreen( nullptr );
308
309 delete m_schematic;
310 m_schematic = nullptr;
311
312 // Close the project if we are standalone, so it gets cleaned up properly
313 if( Kiface().IsSingle() )
314 {
315 try
316 {
317 GetSettingsManager()->UnloadProject( &Prj(), false );
318 }
319 catch( const nlohmann::detail::type_error& exc )
320 {
321 // This may be overkill and could be an assertion but we are more likely to
322 // find any settings manager errors this way.
323 wxLogError( wxT( "Settings exception '%s' occurred." ), exc.what() );
324 }
325 }
326
327 delete m_hierarchy;
328}
329
330
332{
333 aEvent.Skip();
334
335 // Called when resizing the Hierarchy Navigator panel
336 // Store the current pane size
337 // It allows to retrieve the last defined pane size when switching between
338 // docked and floating pane state
339 // Note: *DO NOT* call m_auimgr.Update() here: it crashes Kicad at least on Windows
340
341 EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
342 wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
343
344 if( cfg && m_hierarchy->IsShown() )
345 {
346 cfg->m_AuiPanels.hierarchy_panel_float_width = hierarchy_pane.floating_size.x;
347 cfg->m_AuiPanels.hierarchy_panel_float_height = hierarchy_pane.floating_size.y;
348
349 // initialize hierarchy_panel_docked_width and best size only if the hierarchy_pane
350 // width is > 0 (i.e. if its size is already set and has meaning)
351 // if it is floating, its size is not initialized (only floating_size is initialized)
352 // initializing hierarchy_pane.best_size is useful when switching to float pane and
353 // after switching to the docked pane, to retrieve the last docked pane width
354 if( hierarchy_pane.rect.width > 50 ) // 50 is a good margin
355 {
356 cfg->m_AuiPanels.hierarchy_panel_docked_width = hierarchy_pane.rect.width;
357 hierarchy_pane.best_size.x = hierarchy_pane.rect.width;
358 }
359 }
360}
361
362
364{
365 // Create the manager and dispatcher & route draw panel events to the dispatcher
368 GetCanvas()->GetViewControls(), config(), this );
369 m_actions = new EE_ACTIONS();
371
372 // Register tools
387
388 // Run the selection tool, it is supposed to be always active
390
392}
393
394
396{
398
400 SCH_EDITOR_CONDITIONS cond( this );
401
402 wxASSERT( mgr );
403
404 auto hasElements =
405 [ this ] ( const SELECTION& aSel )
406 {
407 return GetScreen() &&
408 ( !GetScreen()->Items().empty() || !SELECTION_CONDITIONS::Idle( aSel ) );
409 };
410
411 auto hierarchyNavigatorCond =
412 [ this ] ( const SELECTION& aSel )
413 {
414 return m_auimgr.GetPane( SchematicHierarchyPaneName() ).IsShown();
415 };
416
417
418#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
419#define CHECK( x ) ACTION_CONDITIONS().Check( x )
420
424
425 mgr->SetConditions( EE_ACTIONS::showHierarchy, CHECK( hierarchyNavigatorCond ) );
426
433
437
438 mgr->SetConditions( ACTIONS::cut, ENABLE( hasElements ) );
439 mgr->SetConditions( ACTIONS::copy, ENABLE( hasElements ) );
442 mgr->SetConditions( ACTIONS::doDelete, ENABLE( hasElements ) );
443 mgr->SetConditions( ACTIONS::duplicate, ENABLE( hasElements ) );
444 mgr->SetConditions( ACTIONS::selectAll, ENABLE( hasElements ) );
445
446 mgr->SetConditions( EE_ACTIONS::rotateCW, ENABLE( hasElements ) );
447 mgr->SetConditions( EE_ACTIONS::rotateCCW, ENABLE( hasElements ) );
448 mgr->SetConditions( EE_ACTIONS::mirrorH, ENABLE( hasElements ) );
449 mgr->SetConditions( EE_ACTIONS::mirrorV, ENABLE( hasElements ) );
450
455
456 if( SCRIPTING::IsWxAvailable() )
457 {
459 CHECK( cond.ScriptingConsoleVisible() ) );
460 }
461
462 auto showHiddenPinsCond =
463 [this]( const SELECTION& )
464 {
465 return GetShowAllPins();
466 };
467
468 auto showHiddenFieldsCond =
469 [this]( const SELECTION& )
470 {
472 return cfg && cfg->m_Appearance.show_hidden_fields;
473 };
474
475 auto showERCErrorsCond =
476 [this]( const SELECTION& )
477 {
479 return cfg && cfg->m_Appearance.show_erc_errors;
480 };
481
482 auto showERCWarningsCond =
483 [this]( const SELECTION& )
484 {
486 return cfg && cfg->m_Appearance.show_erc_warnings;
487 };
488
489 auto showERCExclusionsCond =
490 [this]( const SELECTION& )
491 {
493 return cfg && cfg->m_Appearance.show_erc_exclusions;
494 };
495
496 auto showAnnotateAutomaticallyCond =
497 [this]( const SELECTION& )
498 {
500 return cfg && cfg->m_AnnotatePanel.automatic;
501 };
502
503 auto remapSymbolsCondition =
504 [&]( const SELECTION& aSel )
505 {
506 SCH_SCREENS schematic( Schematic().Root() );
507
508 // The remapping can only be performed on legacy projects.
509 return schematic.HasNoFullyDefinedLibIds();
510 };
511
512 auto belowRootSheetCondition =
513 [this]( const SELECTION& aSel )
514 {
515 return m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CanGoUp();
516 };
517
518 auto navHistoryHasForward =
519 [this]( const SELECTION& aSel )
520 {
521 return m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CanGoForward();
522 };
523
524 auto navHistoryHasBackward =
525 [this]( const SELECTION& aSel )
526 {
527 return m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CanGoBack();
528 };
529
530 auto navSchematicHasPreviousSheet =
531 [this]( const SELECTION& aSel )
532 {
533 return m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CanGoPrevious();
534 };
535
536 auto navSchematicHasNextSheet =
537 [this]( const SELECTION& aSel )
538 {
539 return m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CanGoNext();
540 };
541
542 mgr->SetConditions( EE_ACTIONS::leaveSheet, ENABLE( belowRootSheetCondition ) );
543 mgr->SetConditions( EE_ACTIONS::navigateUp, ENABLE( belowRootSheetCondition ) );
544 mgr->SetConditions( EE_ACTIONS::navigateForward, ENABLE( navHistoryHasForward ) );
545 mgr->SetConditions( EE_ACTIONS::navigateBack, ENABLE( navHistoryHasBackward ) );
546 mgr->SetConditions( EE_ACTIONS::navigatePrevious, ENABLE( navSchematicHasPreviousSheet ) );
547 mgr->SetConditions( EE_ACTIONS::navigateNext, ENABLE( navSchematicHasNextSheet ) );
548 mgr->SetConditions( EE_ACTIONS::remapSymbols, ENABLE( remapSymbolsCondition ) );
549 mgr->SetConditions( EE_ACTIONS::toggleHiddenPins, CHECK( showHiddenPinsCond ) );
550 mgr->SetConditions( EE_ACTIONS::toggleHiddenFields, CHECK( showHiddenFieldsCond ) );
551 mgr->SetConditions( EE_ACTIONS::toggleERCErrors, CHECK( showERCErrorsCond ) );
552 mgr->SetConditions( EE_ACTIONS::toggleERCWarnings, CHECK( showERCWarningsCond ) );
553 mgr->SetConditions( EE_ACTIONS::toggleERCExclusions, CHECK( showERCExclusionsCond ) );
554 mgr->SetConditions( EE_ACTIONS::toggleAnnotateAuto, CHECK( showAnnotateAutomaticallyCond ) );
556
557
558#define CURRENT_TOOL( action ) mgr->SetConditions( action, CHECK( cond.CurrentTool( action ) ) )
559
582
583#undef CURRENT_TOOL
584#undef CHECK
585#undef ENABLE
586}
587
588
590{
591 // we cannot store a pointer to an item in the display list here since
592 // that item may be deleted, such as part of a line concatenation or other.
593 // So simply always keep a copy of the object which is to be repeated.
594
595 if( aItem )
596 {
597 m_items_to_repeat.clear();
598
599 AddCopyForRepeatItem( aItem );
600 }
601}
602
603
605{
606 // we cannot store a pointer to an item in the display list here since
607 // that item may be deleted, such as part of a line concatenation or other.
608 // So simply always keep a copy of the object which is to be repeated.
609
610 if( aItem )
611 {
612 std::unique_ptr<SCH_ITEM> repeatItem( static_cast<SCH_ITEM*>( aItem->Clone() ) );
613
614 // Clone() preserves the flags, we want 'em cleared.
615 repeatItem->ClearFlags();
616
617 m_items_to_repeat.emplace_back( std::move( repeatItem ) );
618 }
619}
620
621
623{
624 return Schematic().GetSheets().GetItem( aId );
625}
626
627
629{
631}
632
633
635{
636 return GetCurrentSheet().LastScreen();
637}
638
639
641{
642 return *m_schematic;
643}
644
645
647{
648 wxString s = GetCurrentSheet().PathHumanReadable();
649
650 return s;
651}
652
653
655{
658
659 SCH_SHEET* rootSheet = new SCH_SHEET( m_schematic );
660 m_schematic->SetRoot( rootSheet );
661
662 SCH_SCREEN* rootScreen = new SCH_SCREEN( m_schematic );
663 const_cast<KIID&>( rootSheet->m_Uuid ) = rootScreen->GetUuid();
664 m_schematic->Root().SetScreen( rootScreen );
665 SetScreen( Schematic().RootScreen() );
666
667
668 m_schematic->RootScreen()->SetFileName( wxEmptyString );
669
670 // Don't leave root page number empty
671 SCH_SHEET_PATH rootSheetPath;
672
673 rootSheetPath.push_back( rootSheet );
674 m_schematic->RootScreen()->SetPageNumber( wxT( "1" ) );
675 rootSheetPath.SetPageNumber( wxT( "1" ) );
676
677 if( GetScreen() == nullptr )
678 {
679 SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
680 SetScreen( screen );
681 }
682}
683
684
686{
687 return m_schematic->CurrentSheet();
688}
689
690
692{
693 if( aSheet != GetCurrentSheet() )
694 {
695 FocusOnItem( nullptr );
696
697 Schematic().SetCurrentSheet( aSheet );
698 GetCanvas()->DisplaySheet( aSheet.LastScreen() );
699 }
700}
701
702
704{
706
707 for( SCH_ITEM* item : screen->Items() )
708 item->ClearCaches();
709
710 for( std::pair<const wxString, LIB_SYMBOL*>& libSymbol : screen->GetLibSymbols() )
711 {
712 wxCHECK2( libSymbol.second, continue );
713 libSymbol.second->ClearCaches();
714 }
715
717
718 FocusOnItem( nullptr );
719
720 GetCanvas()->DisplaySheet( GetCurrentSheet().LastScreen() );
722}
723
724
725bool SCH_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
726{
727 // Exit interactive editing
728 // Note this this will commit *some* pending changes. For instance, the EE_POINT_EDITOR
729 // will cancel any drag currently in progress, but commit all changes from previous drags.
730 if( m_toolManager )
732
733 // Shutdown blocks must be determined and vetoed as early as possible
734 if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION
735 && Schematic().GetSheets().IsModified() )
736 {
737 return false;
738 }
739
740 if( Kiface().IsSingle() )
741 {
742 auto* symbolEditor = (SYMBOL_EDIT_FRAME*) Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
743
744 if( symbolEditor && !symbolEditor->Close() ) // Can close symbol editor?
745 return false;
746
747 auto* symbolViewer = (SYMBOL_VIEWER_FRAME*) Kiway().Player( FRAME_SCH_VIEWER, false );
748
749 if( symbolViewer && !symbolViewer->Close() ) // Can close symbol viewer?
750 return false;
751
752 symbolViewer = (SYMBOL_VIEWER_FRAME*) Kiway().Player( FRAME_SCH_VIEWER_MODAL, false );
753
754 if( symbolViewer && !symbolViewer->Close() ) // Can close modal symbol viewer?
755 return false;
756 }
757 else
758 {
759 auto* symbolEditor = (SYMBOL_EDIT_FRAME*) Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
760
761 if( symbolEditor && symbolEditor->IsSymbolFromSchematic() )
762 {
763 if( !symbolEditor->CanCloseSymbolFromSchematic( true ) )
764 return false;
765 }
766 }
767
768 SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) Kiway().Player( FRAME_SIMULATOR, false );
769
770 if( simFrame && !simFrame->Close() ) // Can close the simulator?
771 return false;
772
773 // We may have gotten multiple events; don't clean up twice
774 if( !Schematic().IsValid() )
775 return false;
776
777 SCH_SHEET_LIST sheetlist = Schematic().GetSheets();
778
779 if( sheetlist.IsModified() )
780 {
781 wxFileName fileName = Schematic().RootScreen()->GetFileName();
782 wxString msg = _( "Save changes to '%s' before closing?" );
783
784 if( !HandleUnsavedChanges( this, wxString::Format( msg, fileName.GetFullName() ),
785 [&]() -> bool
786 {
787 return SaveProject();
788 } ) )
789 {
790 return false;
791 }
792 }
793
794 // Close modeless dialogs. They're trouble when they get destroyed after the frame and/or
795 // board.
796 wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_ERC_WINDOW_NAME );
797
798 if( open_dlg )
799 open_dlg->Close( true );
800
801 return true;
802}
803
804
806{
807 SCH_SHEET_LIST sheetlist = Schematic().GetSheets();
808
809 // Shutdown all running tools
810 if( m_toolManager )
812
814
815 // Close the find dialog and preserve its setting if it is displayed.
817 {
820
821 m_findReplaceDialog->Destroy();
822 m_findReplaceDialog = nullptr;
823 }
824
825 wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
826
827 if( hierarchy_pane.IsShown() && hierarchy_pane.IsFloating() )
828 {
829 hierarchy_pane.Show( false );
830 m_auimgr.Update();
831 }
832
833 if( Kiway().Player( FRAME_SIMULATOR, false ) )
835
836 SCH_SCREENS screens( Schematic().Root() );
837 wxFileName fn;
838
839 for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
840 {
841 fn = Prj().AbsolutePath( screen->GetFileName() );
842
843 // Auto save file name is the normal file name prepended with GetAutoSaveFilePrefix().
844 fn.SetName( GetAutoSaveFilePrefix() + fn.GetName() );
845
846 if( fn.IsFileWritable() )
847 wxRemoveFile( fn.GetFullPath() );
848 }
849
850 wxFileName tmpFn = Prj().GetProjectFullName();
851 wxFileName autoSaveFileName( tmpFn.GetPath(), getAutoSaveFileName() );
852
853 if( autoSaveFileName.IsFileWritable() )
854 wxRemoveFile( autoSaveFileName.GetFullPath() );
855
856 sheetlist.ClearModifyStatus();
857
858 wxString fileName = Prj().AbsolutePath( Schematic().RootScreen()->GetFileName() );
859
860 if( !Schematic().GetFileName().IsEmpty() && !Schematic().RootScreen()->IsEmpty() )
861 UpdateFileHistory( fileName );
862
863 // Make sure local settings are persisted
865
867
868 // all sub sheets are deleted, only the main sheet is usable
870
871 // Clear view before destroying schematic as repaints depend on schematic being valid
872 SetScreen( nullptr );
873
874 Schematic().Reset();
875
876 Destroy();
877}
878
879
881{
882 SCH_SHEET_LIST sheetList = Schematic().GetSheets();
883 ERC_SETTINGS& ercSettings = Schematic().ErcSettings();
884
885 ercSettings.m_ErcExclusions.clear();
886
887 for( unsigned i = 0; i < sheetList.size(); i++ )
888 {
889 for( SCH_ITEM* item : sheetList[i].LastScreen()->Items().OfType( SCH_MARKER_T ) )
890 {
891 SCH_MARKER* marker = static_cast<SCH_MARKER*>( item );
892
893 if( marker->IsExcluded() )
894 ercSettings.m_ErcExclusions.insert( marker->Serialize() );
895 }
896 }
897}
898
899
901{
902 SCH_SHEET_LIST sheetList = Schematic().GetSheets();
903
904 for( SCH_MARKER* marker : Schematic().ResolveERCExclusions() )
905 {
906 SCH_SHEET_PATH errorPath;
907 ignore_unused( sheetList.GetItem( marker->GetRCItem()->GetMainItemID(), &errorPath ) );
908
909 if( errorPath.LastScreen() )
910 errorPath.LastScreen()->Append( marker );
911 else
912 Schematic().RootScreen()->Append( marker );
913 }
914}
915
916
918{
919 return Schematic().ErcSettings().GetSeverity( aErrorCode );
920}
921
922
924{
926
927 wxASSERT( GetScreen() );
928
929 if( !GetScreen() )
930 return;
931
933 m_autoSaveRequired = true;
934
935 if( ADVANCED_CFG::GetCfg().m_RealTimeConnectivity && CONNECTION_GRAPH::m_allowRealTime )
937 else
939
940 GetCanvas()->Refresh();
942
943 if( !GetTitle().StartsWith( "*" ) )
944 UpdateTitle();
945}
946
947
948void SCH_EDIT_FRAME::OnUpdatePCB( wxCommandEvent& event )
949{
950 if( Kiface().IsSingle() )
951 {
952 DisplayError( this, _( "Cannot update the PCB, because the Schematic Editor is opened"
953 " in stand-alone mode. In order to create/update PCBs from"
954 " schematics, launch the KiCad shell and create a project." ) );
955 return;
956 }
957
958 KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_EDITOR, false );
959
960 if( !frame )
961 {
962 wxFileName fn = Prj().GetProjectFullName();
963 fn.SetExt( PcbFileExtension );
964
965 frame = Kiway().Player( FRAME_PCB_EDITOR, true );
966
967 // If Kiway() cannot create the Pcbnew frame, it shows a error message, and
968 // frame is null
969 if( !frame )
970 return;
971
972 frame->OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ) );
973 }
974
975 if( !frame->IsVisible() )
976 frame->Show( true );
977
978 // On Windows, Raise() does not bring the window on screen, when iconized
979 if( frame->IsIconized() )
980 frame->Iconize( false );
981
982 frame->Raise();
983
984 std::string payload;
986}
987
988
990{
991 m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CleanHistory();
993}
994
995
997{
999}
1000
1001
1003{
1004 wxString findString;
1005
1006 EE_SELECTION& selection = m_toolManager->GetTool<EE_SELECTION_TOOL>()->GetSelection();
1007
1008 if( selection.Size() == 1 )
1009 {
1010 EDA_ITEM* front = selection.Front();
1011
1012 switch( front->Type() )
1013 {
1014 case SCH_SYMBOL_T:
1015 findString = static_cast<SCH_SYMBOL*>( front )->GetValueFieldText( true );
1016 break;
1017
1018 case SCH_FIELD_T:
1019 findString = static_cast<SCH_FIELD*>( front )->GetShownText();
1020 break;
1021
1022 case SCH_LABEL_T:
1023 case SCH_GLOBAL_LABEL_T:
1024 case SCH_HIER_LABEL_T:
1025 case SCH_SHEET_PIN_T:
1026 findString = static_cast<SCH_LABEL_BASE*>( front )->GetShownText();
1027 break;
1028
1029 case SCH_TEXT_T:
1030 findString = static_cast<SCH_TEXT*>( front )->GetShownText();
1031
1032 if( findString.Contains( wxT( "\n" ) ) )
1033 findString = findString.Before( '\n' );
1034
1035 break;
1036
1037 default:
1038 break;
1039 }
1040 }
1041
1043 m_findReplaceDialog->Destroy();
1044
1046 this, static_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() ), wxDefaultPosition,
1047 wxDefaultSize, aReplace ? wxFR_REPLACEDIALOG : 0 );
1048
1051 m_findReplaceDialog->Show( true );
1052}
1053
1054
1055void SCH_EDIT_FRAME::ShowFindReplaceStatus( const wxString& aMsg, int aStatusTime )
1056{
1057 // Prepare the infobar, since we don't know its state
1060
1061 m_infoBar->ShowMessageFor( aMsg, aStatusTime, wxICON_INFORMATION );
1062}
1063
1064
1066{
1067 m_infoBar->Dismiss();
1068}
1069
1070
1072{
1075
1076 m_findReplaceDialog->Destroy();
1077 m_findReplaceDialog = nullptr;
1078
1080}
1081
1082
1083void SCH_EDIT_FRAME::OnLoadFile( wxCommandEvent& event )
1084{
1085 wxString fn = GetFileFromHistory( event.GetId(), _( "Schematic" ) );
1086
1087 if( fn.size() )
1088 OpenProjectFiles( std::vector<wxString>( 1, fn ) );
1089}
1090
1091
1092void SCH_EDIT_FRAME::OnClearFileHistory( wxCommandEvent& aEvent )
1093{
1095}
1096
1097
1099{
1100 wxString pro_dir = m_mruPath;
1101
1102 wxFileDialog dlg( this, _( "New Schematic" ), pro_dir, wxEmptyString,
1103 KiCadSchematicFileWildcard(), wxFD_SAVE );
1104
1105 if( dlg.ShowModal() != wxID_CANCEL )
1106 {
1107 // Enforce the extension, wxFileDialog is inept.
1108 wxFileName create_me = dlg.GetPath();
1109 create_me.SetExt( KiCadSchematicFileExtension );
1110
1111 if( create_me.FileExists() )
1112 {
1113 wxString msg;
1114 msg.Printf( _( "Schematic file '%s' already exists." ), create_me.GetFullName() );
1115 DisplayError( this, msg );
1116 return ;
1117 }
1118
1119 // OpenProjectFiles() requires absolute
1120 wxASSERT_MSG( create_me.IsAbsolute(), "wxFileDialog returned non-absolute path" );
1121
1122 OpenProjectFiles( std::vector<wxString>( 1, create_me.GetFullPath() ), KICTL_CREATE );
1123 m_mruPath = create_me.GetPath();
1124 }
1125}
1126
1127
1129{
1130 wxString pro_dir = m_mruPath;
1131 wxString wildcards = AllSchematicFilesWildcard()
1134
1135 wxFileDialog dlg( this, _( "Open Schematic" ), pro_dir, wxEmptyString,
1136 wildcards, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
1137
1138 if( dlg.ShowModal() != wxID_CANCEL )
1139 {
1140 OpenProjectFiles( std::vector<wxString>( 1, dlg.GetPath() ) );
1142 }
1143}
1144
1145
1146void SCH_EDIT_FRAME::OnOpenPcbnew( wxCommandEvent& event )
1147{
1148 wxFileName kicad_board = Prj().AbsolutePath( Schematic().GetFileName() );
1149
1150 if( kicad_board.IsOk() && !Schematic().GetFileName().IsEmpty() )
1151 {
1152 kicad_board.SetExt( PcbFileExtension );
1153 wxFileName legacy_board( kicad_board );
1154 legacy_board.SetExt( LegacyPcbFileExtension );
1155 wxFileName& boardfn = legacy_board;
1156
1157 if( !legacy_board.FileExists() || kicad_board.FileExists() )
1158 boardfn = kicad_board;
1159
1160 if( Kiface().IsSingle() )
1161 {
1162 ExecuteFile( PCBNEW_EXE, boardfn.GetFullPath() );
1163 }
1164 else
1165 {
1166 KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_EDITOR, false );
1167
1168 if( !frame )
1169 {
1170 frame = Kiway().Player( FRAME_PCB_EDITOR, true );
1171
1172 // frame can be null if Cvpcb cannot be run. No need to show a warning
1173 // Kiway() generates the error messages
1174 if( !frame )
1175 return;
1176
1177 frame->OpenProjectFiles( std::vector<wxString>( 1, boardfn.GetFullPath() ) );
1178 }
1179
1180 if( !frame->IsVisible() )
1181 frame->Show( true );
1182
1183 // On Windows, Raise() does not bring the window on screen, when iconized
1184 if( frame->IsIconized() )
1185 frame->Iconize( false );
1186
1187 frame->Raise();
1188 }
1189 }
1190 else
1191 {
1192 // If we are running inside a project, it should be impossible for this case to happen
1193 wxASSERT( Kiface().IsSingle() );
1195 }
1196}
1197
1198
1199void SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event )
1200{
1201 wxFileName fn = Prj().AbsolutePath( Schematic().GetFileName() );
1202 fn.SetExt( NetlistFileExtension );
1203
1204 if( !ReadyToNetlist( _( "Assigning footprints requires a fully annotated schematic." ) ) )
1205 return;
1206
1207 try
1208 {
1209 KIWAY_PLAYER* player = Kiway().Player( FRAME_CVPCB, false ); // test open already.
1210
1211 if( !player )
1212 {
1213 player = Kiway().Player( FRAME_CVPCB, true );
1214
1215 // player can be null if Cvpcb cannot be run. No need to show a warning
1216 // Kiway() generates the error messages
1217 if( !player )
1218 return;
1219
1220 player->Show( true );
1221 }
1222
1224
1225 player->Raise();
1226 }
1227 catch( const IO_ERROR& )
1228 {
1229 DisplayError( this, _( "Could not open CvPcb" ) );
1230 }
1231}
1232
1233
1234void SCH_EDIT_FRAME::OnExit( wxCommandEvent& event )
1235{
1236 if( event.GetId() == wxID_EXIT )
1237 Kiway().OnKiCadExit();
1238
1239 if( event.GetId() == wxID_CLOSE || Kiface().IsSingle() )
1240 Close( false );
1241}
1242
1243
1245{
1246 wxString fileName = Prj().AbsolutePath( GetScreen()->GetFileName() );
1247
1248 const wxBrush& brush =
1249 wxBrush( GetColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND ).ToColour() );
1250 aSettings->GetPrintDC()->SetBackground( brush );
1251 aSettings->GetPrintDC()->Clear();
1252
1253 aSettings->GetPrintDC()->SetLogicalFunction( wxCOPY );
1254 GetScreen()->Print( aSettings );
1255 PrintDrawingSheet( aSettings, GetScreen(), Schematic().GetProperties(), schIUScale.IU_PER_MILS,
1256 fileName );
1257}
1258
1259
1261{
1262 if( aItem->IsType( { SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T } ) )
1263 {
1264 auto label = static_cast<SCH_LABEL_BASE*>( aItem );
1265 if( label->AutoRotateOnPlacement() )
1266 {
1267 auto textSpin = aScreen->GetLabelOrientationForPoint(
1268 label->GetPosition(), label->GetTextSpinStyle(), &GetCurrentSheet() );
1269 if( textSpin != label->GetTextSpinStyle() )
1270 {
1271 label->SetTextSpinStyle( textSpin );
1272 for( SCH_ITEM* item : aScreen->Items().OfType( SCH_GLOBAL_LABEL_T ) )
1273 {
1274 SCH_LABEL_BASE* otherLabel = static_cast<SCH_LABEL_BASE*>( item );
1275 if( otherLabel != label && otherLabel->GetText() == label->GetText() )
1276 {
1277 otherLabel->AutoplaceFields( aScreen, false );
1278 }
1279 }
1280 }
1281 }
1282 }
1283}
1284
1285
1287 bool aUndoAppend )
1288{
1289 wxCHECK_RET( aItem != nullptr, wxT( "Cannot add null item to list." ) );
1290
1291 SCH_SHEET* parentSheet = nullptr;
1292 SCH_SYMBOL* parentSymbol = nullptr;
1293 SCH_ITEM* undoItem = aItem;
1294
1295 if( aItem->Type() == SCH_SHEET_PIN_T )
1296 {
1297 parentSheet = (SCH_SHEET*) aItem->GetParent();
1298
1299 wxCHECK_RET( parentSheet && parentSheet->Type() == SCH_SHEET_T,
1300 wxT( "Cannot place sheet pin in invalid schematic sheet." ) );
1301
1302 undoItem = parentSheet;
1303 }
1304
1305 else if( aItem->Type() == SCH_FIELD_T )
1306 {
1307 parentSymbol = (SCH_SYMBOL*) aItem->GetParent();
1308
1309 wxCHECK_RET( parentSymbol && parentSymbol->Type() == SCH_SYMBOL_T,
1310 wxT( "Cannot place field in invalid schematic symbol." ) );
1311
1312 undoItem = parentSymbol;
1313 }
1314
1315 if( aItem->IsNew() )
1316 {
1317 if( aItem->Type() == SCH_SHEET_PIN_T )
1318 {
1319 // Sheet pins are owned by their parent sheet.
1320 SaveCopyInUndoList( aScreen, undoItem, UNDO_REDO::CHANGED, aUndoAppend );
1321
1322 parentSheet->AddPin( (SCH_SHEET_PIN*) aItem );
1323 }
1324 else if( aItem->Type() == SCH_FIELD_T )
1325 {
1326 // Symbol fields are also owned by their parent, but new symbol fields are
1327 // handled elsewhere.
1328 wxLogMessage( wxT( "addCurrentItemToScreen: unexpected new SCH_FIELD" ) );
1329 }
1330 else
1331 {
1332 if( !aScreen->CheckIfOnDrawList( aItem ) ) // don't want a loop!
1333 AddToScreen( aItem, aScreen );
1334
1335 SaveCopyForRepeatItem( aItem );
1336 SaveCopyInUndoList( aScreen, undoItem, UNDO_REDO::NEWITEM, aUndoAppend );
1337 }
1338
1339 // Update connectivity info for new item
1340 if( !aItem->IsMoving() )
1342 }
1343
1344 aItem->ClearFlags( IS_NEW );
1345
1346 aScreen->SetContentModified();
1347 UpdateItem( aItem );
1348
1349 if( !aItem->IsMoving() && aItem->IsConnectable() )
1350 {
1351 std::vector<VECTOR2I> pts = aItem->GetConnectionPoints();
1352
1353 bool connected = true;
1354 for( auto i = pts.begin(); i != pts.end(); i++ )
1355 {
1356 for( auto j = i + 1; j != pts.end(); j++ )
1357 TrimWire( *i, *j );
1358
1359 if( aScreen->IsExplicitJunctionNeeded( *i ) )
1360 {
1361 AddJunction( aScreen, *i, true, false );
1362 connected = true;
1363 }
1364 }
1365
1366 if( connected )
1367 {
1368 AutoRotateItem( aScreen, aItem );
1369 }
1370
1372
1373 for( SCH_ITEM* item : aItem->ConnectedItems( GetCurrentSheet() ) )
1374 UpdateItem( item );
1375 }
1376
1377 aItem->ClearEditFlags();
1378 GetCanvas()->Refresh();
1379}
1380
1381
1383{
1384 SCH_SCREEN* screen = GetScreen();
1385
1386 wxCHECK( screen, /* void */ );
1387
1388 wxString title;
1389
1390 if( !screen->GetFileName().IsEmpty() )
1391 {
1392 wxFileName fn( Prj().AbsolutePath( screen->GetFileName() ) );
1393 bool readOnly = false;
1394 bool unsaved = false;
1395
1396 if( fn.IsOk() && screen->FileExists() )
1397 readOnly = screen->IsReadOnly();
1398 else
1399 unsaved = true;
1400
1401 if( IsContentModified() )
1402 title = wxT( "*" );
1403
1404 title += fn.GetName();
1405 title += wxString::Format( wxT( " [%s]" ), GetCurrentSheet().PathHumanReadable( false ) );
1406
1407 if( readOnly )
1408 title += wxS( " " ) + _( "[Read Only]" );
1409
1410 if( unsaved )
1411 title += wxS( " " ) + _( "[Unsaved]" );
1412 }
1413 else
1414 {
1415 title = _( "[no schematic loaded]" );
1416 }
1417
1418 title += wxT( " \u2014 " ) + _( "Schematic Editor" );
1419
1420 SetTitle( title );
1421}
1422
1423
1425{
1427 GetScreen()->m_zoomInitialized = true;
1428}
1429
1430
1432{
1433 const SCH_CONNECTION* highlight = GetHighlightedConnection();
1434 SCH_ITEM* highlightedItem = highlight ? highlight->Parent() : nullptr;
1435 SCH_SHEET_PATH highlightPath;
1436
1437 if( highlight )
1438 highlightPath = highlight->LocalSheet();
1439
1440 SCHEMATIC_SETTINGS& settings = Schematic().Settings();
1442#ifdef PROFILE
1443 PROF_TIMER timer;
1444#endif
1445
1446 // Ensure schematic graph is accurate
1447 if( aCleanupFlags == LOCAL_CLEANUP )
1448 {
1450 }
1451 else if( aCleanupFlags == GLOBAL_CLEANUP )
1452 {
1453 for( const SCH_SHEET_PATH& sheet : list )
1454 SchematicCleanUp( sheet.LastScreen() );
1455 }
1456
1457#ifdef PROFILE
1458 timer.Stop();
1459 wxLogTrace( "CONN_PROFILE", "SchematicCleanUp() %0.4f ms", timer.msecs() );
1460#endif
1461
1462 if( settings.m_IntersheetRefsShow )
1464
1465 std::function<void( SCH_ITEM* )> changeHandler =
1466 [&]( SCH_ITEM* aChangedItem ) -> void
1467 {
1468 GetCanvas()->GetView()->Update( aChangedItem, KIGFX::REPAINT );
1469 };
1470
1471 Schematic().ConnectionGraph()->Recalculate( list, true, &changeHandler );
1472
1474 []( KIGFX::VIEW_ITEM* aItem ) -> int
1475 {
1476 SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem );
1477 SCH_CONNECTION* connection = item ? item->Connection() : nullptr;
1478
1479 if( connection && connection->HasDriverChanged() )
1480 {
1481 connection->ClearDriverChanged();
1482 return KIGFX::REPAINT;
1483 }
1484
1485 EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
1486
1487 if( text && text->HasTextVars() )
1488 {
1489 text->ClearRenderCache();
1490 text->ClearBoundingBoxCache();
1492 }
1493
1494 return 0;
1495 } );
1496
1497 if( highlightedItem )
1498 SetHighlightedConnection( highlightedItem->Connection( &highlightPath ) );
1499}
1500
1501
1503{
1505 {
1506 for( SCH_FIELD& field : label->GetFields() )
1507 field.ClearBoundingBoxCache();
1508
1509 label->ClearBoundingBoxCache();
1510 GetCanvas()->GetView()->Update( label );
1511 } );
1512}
1513
1514
1516{
1518
1520}
1521
1522
1523void SCH_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
1524{
1525 SCHEMATIC_SETTINGS& settings = Schematic().Settings();
1526
1527 SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
1529
1531
1532 EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
1535
1536 KIGFX::VIEW* view = GetCanvas()->GetView();
1540
1542
1543 for( SCH_ITEM* item : screen->Items() )
1544 item->ClearCaches();
1545
1546 for( std::pair<const wxString, LIB_SYMBOL*>& libSymbol : screen->GetLibSymbols() )
1547 libSymbol.second->ClearCaches();
1548
1550
1552 Layout();
1553 SendSizeEvent();
1554}
1555
1556
1558{
1559 // Store the current zoom level into the current screen before calling
1560 // DisplayCurrentSheet() that set the zoom to GetScreen()->m_LastZoomLevel
1562 // Rebuild the sheet view (draw area and any other items):
1564}
1565
1566
1568{
1569 // call my base class
1571
1572 // tooltips in toolbars
1574
1575 // status bar
1577
1578 UpdateTitle();
1579
1580 // This ugly hack is to fix an option(left) toolbar update bug that seems to only affect
1581 // windows. See https://bugs.launchpad.net/kicad/+bug/1816492. For some reason, calling
1582 // wxWindow::Refresh() does not resolve the issue. Only a resize event seems to force the
1583 // toolbar to update correctly.
1584#if defined( __WXMSW__ )
1585 PostSizeEvent();
1586#endif
1587}
1588
1589
1591{
1592 if( const SCH_CONNECTION* conn = GetHighlightedConnection() )
1593 {
1594 SetStatusText( wxString::Format( _( "Highlighted net: %s" ),
1595 UnescapeString( conn->Name() ) ) );
1596 }
1597 else
1598 {
1599 SetStatusText( wxT( "" ) );
1600 }
1601}
1602
1603
1605{
1606 if( m_toolManager )
1608
1609 SCH_BASE_FRAME::SetScreen( aScreen );
1610 GetCanvas()->DisplaySheet( static_cast<SCH_SCREEN*>( aScreen ) );
1611}
1612
1613
1614const BOX2I SCH_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
1615{
1616 BOX2I bBoxDoc;
1617
1618 if( aIncludeAllVisible )
1619 {
1620 // Get the whole page size and return that
1623 bBoxDoc = BOX2I( VECTOR2I( 0, 0 ), VECTOR2I( sizeX, sizeY ) );
1624 }
1625 else
1626 {
1627 // Get current drawing-sheet in a form we can compare to an EDA_ITEM
1629 EDA_ITEM* dsAsItem = static_cast<EDA_ITEM*>( ds );
1630
1631 // Calc the bounding box of all items on screen except the page border
1632 for( EDA_ITEM* item : GetScreen()->Items() )
1633 {
1634 if( item != dsAsItem ) // Ignore the drawing-sheet itself
1635 bBoxDoc.Merge( item->GetBoundingBox() );
1636 }
1637 }
1638
1639 return bBoxDoc;
1640}
1641
1642
1644{
1645 // Save the current sheet, to retrieve it later
1646 SCH_SHEET_PATH oldsheetpath = GetCurrentSheet();
1647
1648 SCH_SHEET_LIST sheetList = Schematic().GetSheets();
1649
1650 for( const SCH_SHEET_PATH& sheet : sheetList )
1651 {
1652 size_t num_undos = m_undoList.m_CommandsList.size();
1653
1654 // We require a set here to avoid adding multiple junctions to the same spot
1655 std::set<wxPoint> junctions;
1656
1657 SetCurrentSheet( sheet );
1659
1661
1662 EE_SELECTION allItems;
1663
1664 for( auto item : screen->Items() )
1665 allItems.Add( item );
1666
1668
1669 // Check if we modified anything during this routine
1670 // Needs to happen for every sheet to set the proper modified flag
1671 if( m_undoList.m_CommandsList.size() > num_undos )
1672 OnModify();
1673 }
1674
1675 // Reselect the initial sheet:
1676 SetCurrentSheet( oldsheetpath );
1678 SetScreen( GetCurrentSheet().LastScreen() );
1679}
1680
1681
1683{
1684 return Schematic().GetSheets().IsModified();
1685}
1686
1687
1689{
1690 EESCHEMA_SETTINGS* cfg = eeconfig();
1691 return cfg && cfg->m_Appearance.show_hidden_pins;
1692}
1693
1694
1696{
1697 static KIID lastBrightenedItemID( niluuid );
1698
1699 SCH_SHEET_LIST sheetList = Schematic().GetSheets();
1701 SCH_ITEM* lastItem = sheetList.GetItem( lastBrightenedItemID, &dummy );
1702
1703 if( lastItem && lastItem != aItem )
1704 {
1705 lastItem->ClearBrightened();
1706
1707 UpdateItem( lastItem );
1708 lastBrightenedItemID = niluuid;
1709 }
1710
1711 if( aItem )
1712 {
1713 if( !aItem->IsBrightened() )
1714 {
1715 aItem->SetBrightened();
1716
1717 UpdateItem( aItem );
1718 lastBrightenedItemID = aItem->m_Uuid;
1719 }
1720
1722 }
1723}
1724
1725
1727{
1728 return Schematic().GetFileName();
1729}
1730
1731
1733{
1734 return m_toolManager->GetTool<EE_SELECTION_TOOL>()->GetSelection();
1735}
1736
1737
1738void SCH_EDIT_FRAME::onSize( wxSizeEvent& aEvent )
1739{
1740 if( IsShown() )
1741 {
1742 // We only need this until the frame is done resizing and the final client size is
1743 // established.
1744 Unbind( wxEVT_SIZE, &SCH_EDIT_FRAME::onSize, this );
1746 }
1747
1748 // Skip() is called in the base class.
1749 EDA_DRAW_FRAME::OnSize( aEvent );
1750}
1751
1752
1754 const KIID& aSchematicSymbolUUID )
1755{
1756 bool appendToUndo = false;
1757
1758 SCH_SHEET_PATH sheetPath;
1759 SCH_ITEM* item = Schematic().GetSheets().GetItem( aSchematicSymbolUUID, &sheetPath );
1760
1761 if( item )
1762 {
1763 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
1764
1765 wxCHECK( symbol, /* void */ );
1766
1767 // This needs to be done before the LIB_SYMBOL is changed to prevent stale library
1768 // symbols in the schematic file.
1769 sheetPath.LastScreen()->Remove( symbol );
1770
1771 if( !symbol->IsNew() )
1772 {
1773 SaveCopyInUndoList( sheetPath.LastScreen(), symbol, UNDO_REDO::CHANGED, appendToUndo );
1774 appendToUndo = true;
1775 }
1776
1777 symbol->SetLibSymbol( aSymbol.Flatten().release() );
1778 symbol->UpdateFields( &GetCurrentSheet(),
1779 true, /* update style */
1780 true, /* update ref */
1781 true, /* update other fields */
1782 false, /* reset ref */
1783 false /* reset other fields */ );
1784
1785 sheetPath.LastScreen()->Append( symbol );
1786 GetCanvas()->GetView()->Update( symbol );
1787 }
1788
1789 GetCanvas()->Refresh();
1790 OnModify();
1791}
1792
1793
1794void SCH_EDIT_FRAME::UpdateItem( EDA_ITEM* aItem, bool isAddOrDelete, bool aUpdateRtree )
1795{
1796 SCH_BASE_FRAME::UpdateItem( aItem, isAddOrDelete, aUpdateRtree );
1797
1798 if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
1799 sch_item->ClearCaches();
1800}
1801
1802
1804{
1808
1809 wxASSERT( screen );
1810
1811 SetScreen( screen );
1812
1813 // update the References
1816
1817 if( !screen->m_zoomInitialized )
1818 {
1820 }
1821 else
1822 {
1823 // Set zoom to last used in this screen
1824 GetCanvas()->GetView()->SetScale( GetScreen()->m_LastZoomLevel );
1825 RedrawScreen( (wxPoint) GetScreen()->m_ScrollCenter, false );
1826 }
1827
1828 UpdateTitle();
1829
1830 HardRedraw(); // Ensure all items are redrawn (especially the drawing-sheet items)
1831
1834 editTool->UpdateNetHighlighting( dummy );
1835
1837}
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
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
@ icon_eeschema
@ icon_eeschema_16
@ icon_eeschema_32
BOX2< VECTOR2I > BOX2I
Definition: box2.h:847
static TOOL_ACTION toggleGrid
Definition: actions.h:143
static TOOL_ACTION paste
Definition: actions.h:69
static TOOL_ACTION cancelInteractive
Definition: actions.h:63
static TOOL_ACTION millimetersUnits
Definition: actions.h:149
static TOOL_ACTION copy
Definition: actions.h:68
static TOOL_ACTION updateFind
Definition: actions.h:84
static TOOL_ACTION pasteSpecial
Definition: actions.h:70
static TOOL_ACTION milsUnits
Definition: actions.h:148
static TOOL_ACTION toggleBoundingBoxes
Definition: actions.h:107
static TOOL_ACTION undo
Definition: actions.h:65
static TOOL_ACTION duplicate
Definition: actions.h:72
static TOOL_ACTION inchesUnits
Definition: actions.h:147
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:104
static TOOL_ACTION doDelete
Definition: actions.h:73
static TOOL_ACTION selectionTool
Definition: actions.h:156
static TOOL_ACTION save
Definition: actions.h:51
static TOOL_ACTION zoomFitScreen
Definition: actions.h:98
static TOOL_ACTION redo
Definition: actions.h:66
static TOOL_ACTION deleteTool
Definition: actions.h:74
static TOOL_ACTION zoomTool
Definition: actions.h:101
static TOOL_ACTION cut
Definition: actions.h:67
static TOOL_ACTION selectAll
Definition: actions.h:71
Manage TOOL_ACTION objects.
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 const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
WINDOW_SETTINGS m_Window
Definition: app_settings.h:193
Handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:41
void SetPageNumber(const wxString &aPageNumber)
Definition: base_screen.h:79
void SetContentModified(bool aModified=true)
Definition: base_screen.h:59
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:588
Handle actions that are shared between different applications.
Handles action that are shared between different applications.
Definition: common_tools.h:38
static bool m_allowRealTime
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.
wxArrayString GetFindEntries() const
wxArrayString GetReplaceEntries() const
void SetReplaceEntries(const wxArrayString &aEntries)
void SetFindEntries(const wxArrayString &aEntries, const wxString &aFindString)
bool Show(bool show) override
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
UNDO_REDO_CONTAINER m_undoList
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
SETTINGS_MANAGER * GetSettingsManager() const
virtual void OnModify()
Must be called after a model change in order to set the "modify" flag and do other frame-specific pro...
WX_INFOBAR * m_infoBar
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
wxAuiManager m_auimgr
void ClearFileHistory(FILE_HISTORY *aFileHistory=nullptr)
Removes all files from the file history.
virtual void OnDropFiles(wxDropFilesEvent &aEvent)
Handles event fired when a file is dropped to the window.
wxString GetFileFromHistory(int cmdId, const wxString &type, FILE_HISTORY *aFileHistory=nullptr)
Fetches the file name from the file history list.
static wxString GetAutoSaveFilePrefix()
wxString m_mruPath
The base class for create windows for drawing purpose.
wxArrayString m_replaceStringHistoryList
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
virtual void OnSize(wxSizeEvent &event) override
Recalculate the size of toolbars and display panel when the frame size changes.
void FocusOnLocation(const VECTOR2I &aPos)
Useful to focus on a particular location, in find functions.
virtual void SetScreen(BASE_SCREEN *aScreen)
void RecreateToolbars()
Rebuild all toolbars, and update the checked state of check tools.
virtual void UpdateMsgPanel()
Redraw the message panel.
void OnGridSettings(wxCommandEvent &event)
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
void PrintDrawingSheet(const RENDER_SETTINGS *aSettings, BASE_SCREEN *aScreen, const std::map< wxString, wxString > *aProperties, double aMils2Iu, const wxString &aFilename, const wxString &aSheetLayer=wxEmptyString)
Prints the drawing-sheet (frame and title block).
wxArrayString m_findStringHistoryList
std::unique_ptr< EDA_SEARCH_DATA > m_findReplaceData
GAL_TYPE GetBackend() const
Return the type of backend currently used by GAL canvas.
void ForceRefresh()
Force a redraw.
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...
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
virtual const VECTOR2I GetFocusPosition() const
Similar to GetPosition, but allows items to return their visual center rather than their anchor.
Definition: eda_item.h:258
const KIID m_Uuid
Definition: eda_item.h:494
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:143
void ClearBrightened()
Definition: eda_item.h:122
void SetBrightened()
Definition: eda_item.h:119
EDA_ITEM * GetParent() const
Definition: eda_item.h:99
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:82
bool IsBrightened() const
Definition: eda_item.h:110
void ClearEditFlags()
Definition: eda_item.h:160
bool IsMoving() const
Definition: eda_item.h:104
bool IsNew() const
Definition: eda_item.h:103
Specialization of the wxAuiPaneInfo class for KiCad panels.
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:72
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
virtual void ClearBoundingBoxCache()
Definition: eda_text.cpp:444
SELECTION_CONDITION BoundingBoxes()
SELECTION_CONDITION RedoAvailable()
Create a functor that tests if there are any items in the redo queue.
SELECTION_CONDITION CurrentTool(const TOOL_ACTION &aTool)
Create a functor testing if the specified tool is the current active tool in the frame.
SELECTION_CONDITION UndoAvailable()
Create a functor that tests if there are any items in the undo queue.
SELECTION_CONDITION ScriptingConsoleVisible()
Create a functor testing if the python scripting console window is visible.
SELECTION_CONDITION Units(EDA_UNITS aUnit)
Create a functor that tests if the frame has the specified units.
SELECTION_CONDITION GridVisible()
Create a functor testing if the grid is visible in a frame.
SELECTION_CONDITION FullscreenCursor()
Create a functor testing if the cursor is full screen in a frame.
PANEL_ANNOTATE m_AnnotatePanel
Gather all the actions that are shared by tools.
Definition: ee_actions.h:39
static TOOL_ACTION mirrorV
Definition: ee_actions.h:128
static TOOL_ACTION remapSymbols
Definition: ee_actions.h:170
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: ee_actions.h:46
static TOOL_ACTION toggleAnnotateAuto
Definition: ee_actions.h:244
static TOOL_ACTION lineMode90
Definition: ee_actions.h:239
static TOOL_ACTION toggleHiddenPins
Definition: ee_actions.h:216
static TOOL_ACTION navigateForward
Definition: ee_actions.h:204
static TOOL_ACTION placeSymbol
Definition: ee_actions.h:81
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
static TOOL_ACTION navigateBack
Definition: ee_actions.h:205
static TOOL_ACTION showPythonConsole
Definition: ee_actions.h:234
static TOOL_ACTION toggleERCWarnings
Definition: ee_actions.h:218
static TOOL_ACTION toggleERCExclusions
Definition: ee_actions.h:220
static TOOL_ACTION placeClassLabel
Definition: ee_actions.h:90
static TOOL_ACTION drawWire
Definition: ee_actions.h:83
static TOOL_ACTION drawCircle
Definition: ee_actions.h:99
static TOOL_ACTION rotateCCW
Definition: ee_actions.h:127
static TOOL_ACTION lineModeFree
Definition: ee_actions.h:238
static TOOL_ACTION drawBus
Definition: ee_actions.h:84
static TOOL_ACTION toggleERCErrors
Definition: ee_actions.h:219
static TOOL_ACTION placePower
Definition: ee_actions.h:82
static TOOL_ACTION drawLines
Definition: ee_actions.h:101
static TOOL_ACTION mirrorH
Definition: ee_actions.h:129
static TOOL_ACTION highlightNetTool
Definition: ee_actions.h:255
static TOOL_ACTION rotateCW
Definition: ee_actions.h:126
static TOOL_ACTION importSheetPin
Definition: ee_actions.h:95
static TOOL_ACTION leaveSheet
Definition: ee_actions.h:202
static TOOL_ACTION toggleHiddenFields
Definition: ee_actions.h:217
static TOOL_ACTION placeGlobalLabel
Definition: ee_actions.h:91
static TOOL_ACTION ddAppendFile
Definition: ee_actions.h:258
static TOOL_ACTION placeHierLabel
Definition: ee_actions.h:92
static TOOL_ACTION drawTextBox
Definition: ee_actions.h:97
static TOOL_ACTION drawRectangle
Definition: ee_actions.h:98
static TOOL_ACTION placeImage
Definition: ee_actions.h:102
static TOOL_ACTION showHierarchy
Definition: ee_actions.h:208
static TOOL_ACTION placeSchematicText
Definition: ee_actions.h:96
static TOOL_ACTION addNeededJunctions
Definition: ee_actions.h:78
static TOOL_ACTION drawArc
Definition: ee_actions.h:100
static TOOL_ACTION lineMode45
Definition: ee_actions.h:240
static TOOL_ACTION drawSheet
Definition: ee_actions.h:93
static TOOL_ACTION navigateNext
Definition: ee_actions.h:207
static TOOL_ACTION navigateUp
Definition: ee_actions.h:203
static TOOL_ACTION placeLabel
Definition: ee_actions.h:89
static TOOL_ACTION placeBusWireEntry
Definition: ee_actions.h:88
static TOOL_ACTION placeJunction
Definition: ee_actions.h:87
static TOOL_ACTION navigatePrevious
Definition: ee_actions.h:206
static TOOL_ACTION placeNoConnect
Definition: ee_actions.h:86
Tool that displays edit points allowing to modify items by dragging the points.
bool empty() const
Definition: sch_rtree.h:176
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:238
Container for ERC settings.
Definition: erc_settings.h:114
SEVERITY GetSeverity(int aErrorCode) const
std::set< wxString > m_ErcExclusions
Definition: erc_settings.h:174
void UpdateHierarchyTree()
Update the hierarchical tree of the schematic.
Definition: hierarch.cpp:207
void UpdateHierarchySelection()
Updates the tree's selection to match current page.
Definition: hierarch.cpp:140
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:93
void ReadWindowSettings(WINDOW_SETTINGS &aCfg)
Read GAL config options from application-level config.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void SetDefaultFont(const wxString &aFont)
wxDC * GetPrintDC() const
Contains methods for drawing schematic-specific items.
Definition: sch_painter.h:134
DS_PROXY_VIEW_ITEM * GetDrawingSheet() const
Definition: sch_view.h:100
void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 }) override
Set the scaling factor, zooming around a given anchor point.
Definition: sch_view.cpp:73
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:77
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:69
double GetScale() const
Definition: view.h:269
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:1586
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition: view.h:393
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:213
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:1489
Definition: kiid.h:48
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:66
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
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
void OnSockRequestServer(wxSocketEvent &evt)
Definition: eda_dde.cpp:99
void OnSockRequest(wxSocketEvent &evt)
Definition: eda_dde.cpp:69
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:273
void OnKiCadExit()
Definition: kiway.cpp:665
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:394
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:488
Define a library symbol object.
Definition: lib_symbol.h:98
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Definition: lib_symbol.cpp:460
bool IsExcluded() const
Definition: marker_base.h:97
int GetHeightIU(double aIUScale) const
Gets the page height in IU.
Definition: page_info.h:153
int GetWidthIU(double aIUScale) const
Gets the page width in IU.
Definition: page_info.h:144
A small class to help profiling.
Definition: profile.h:47
void Stop()
Save the time when this function was called, and set the counter stane to stop.
Definition: profile.h:86
double msecs(bool aSinceLast=false)
Definition: profile.h:147
SCHEMATIC_SETTINGS * m_SchematicSettings
Definition: project_file.h:130
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition: project.cpp:120
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:126
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:149
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:305
These settings were stored in SCH_BASE_FRAME previously.
std::shared_ptr< NGSPICE_SIMULATOR_SETTINGS > m_NgspiceSimulatorSettings
Ngspice simulator settings.
Holds all the data relating to one schematic.
Definition: schematic.h:61
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
Definition: schematic.cpp:51
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:120
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:166
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:172
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:130
void SetCurrentSheet(const SCH_SHEET_PATH &aPath) override
Definition: schematic.h:125
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:86
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
Definition: schematic.cpp:104
void SetProject(PROJECT *aPrj)
Definition: schematic.cpp:76
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:117
void RecomputeIntersheetRefs(const std::function< void(SCH_GLOBALLABEL *)> &aItemCallback)
Update the schematic's page reference map for all global labels, and refresh the labels so that they ...
Definition: schematic.cpp:502
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:107
SCH_SHEET & Root() const
Definition: schematic.h:91
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
Definition: schematic.cpp:473
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:179
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
virtual void RedrawScreen(const VECTOR2I &aCenterPoint, bool aWarpPointer)
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
EESCHEMA_SETTINGS * eeconfig() const
KIGFX::SCH_RENDER_SETTINGS * GetRenderSettings()
virtual void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false)
Mark an item for refresh.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
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,...
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
SCH_SHEET_PATH LocalSheet() const
SCH_ITEM * Parent() const
bool HasDriverChanged() const
Tool responsible for drawing/placing items (symbols, wires, buses, labels, etc.).
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void DisplaySheet(SCH_SCREEN *aScreen)
Group generic conditions for PCB editor states.
SELECTION_CONDITION LineMode(LINE_MODE aMode)
Create a functor that tests if the frame is in the specified line drawing mode.
Handle actions specific to the schematic editor.
int UpdateNetHighlighting(const TOOL_EVENT &aEvent)
Launch a tool to highlight nets.
Schematic editor (Eeschema) main window.
HIERARCHY_NAVIG_PANEL * m_hierarchy
bool SchematicCleanUp(SCH_SCREEN *aScreen=nullptr)
Perform routine schematic cleaning including breaking wire and buses and deleting identical objects s...
bool IsContentModified() const override
Get if the current schematic has been modified but not saved.
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
EDA_ITEM * GetItem(const KIID &aId) const override
Fetch an item by KIID.
const wxString & getAutoSaveFileName() const
std::vector< std::unique_ptr< SCH_ITEM > > m_items_to_repeat
For the repeat-last-item cmd.
const SCH_CONNECTION * GetHighlightedConnection() const
bool TrimWire(const VECTOR2I &aStart, const VECTOR2I &aEnd)
If any single wire passes through both points, remove the portion between the two points,...
void SaveProjectSettings() override
Save changes to the project settings to the project (.pro) file.
void OnOpenCvpcb(wxCommandEvent &event)
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag and update other data struc...
void ShowAllIntersheetRefs(bool aShow)
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
Open a project or set of files given by aFileList.
void UpdateTitle()
Set the main window title bar text.
void doCloseWindow() override
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.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
bool ReadyToNetlist(const wxString &aAnnotateMessage)
Check if we are ready to write a netlist file for the current schematic.
void ShowFindReplaceDialog(bool aReplace)
Run the Find or Find & Replace dialog.
void UpdateHierarchySelection()
Update the hierarchy navigation tree selection (cross-probe from schematic to hierarchy pane).
void SetScreen(BASE_SCREEN *aScreen) override
void OnFindDialogClose()
Notification that the Find dialog has closed.
void SaveSymbolToSchematic(const LIB_SYMBOL &aSymbol, const KIID &aSchematicSymbolUUID)
Update a schematic symbol from a LIB_SYMBOL.
void onSize(wxSizeEvent &aEvent)
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
void ShowChangedLanguage() override
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend, bool aDirtyConnectivity=true)
Create a copy of the current schematic item, and put it in the undo list.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Called after the preferences dialog is run.
void HardRedraw() override
Rebuild the GAL and redraw the screen.
void OnClearFileHistory(wxCommandEvent &aEvent)
bool GetShowAllPins() const override
Allow edit frame to show/hide hidden pins.
void OnAppendProject(wxCommandEvent &event)
SCHEMATIC * m_schematic
The currently loaded schematic.
void ClearFindReplaceStatus()
SCH_SHEET_PATH & GetCurrentSheet() const
void OnLoadFile(wxCommandEvent &event)
SCHEMATIC & Schematic() const
bool canCloseWindow(wxCloseEvent &aCloseEvent) override
void OnUpdatePCB(wxCommandEvent &event)
void RecomputeIntersheetRefs()
Update the schematic's page reference map for all global labels, and refresh the labels so that they ...
void sendNetlistToCvpcb()
Send the KiCad netlist over to CVPCB.
void OnOpenPcbnew(wxCommandEvent &event)
void RecalculateConnections(SCH_CLEANUP_FLAGS aCleanupFlags)
Generate the connection data for the entire schematic hierarchy.
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
void OnPageSettingsChange() override
Called when modifying the page settings.
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Returns bbox of document with option to not include some items.
void initScreenZoom()
Initialize the zoom value of the current screen and mark the screen as zoom-initialized.
void OnImportProject(wxCommandEvent &event)
static const wxString SchematicHierarchyPaneName()
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
void ShowFindReplaceStatus(const wxString &aMsg, int aStatusTime)
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
void SetHighlightedConnection(const SCH_CONNECTION *aConnection)
virtual void PrintPage(const RENDER_SETTINGS *aSettings) override
Plot or print the current sheet to the clipboard.
int GetSchematicJunctionSize()
void DisplayCurrentSheet()
Draw the current sheet on the display.
void ResolveERCExclusions()
Update markers to match recorded exclusions.
~SCH_EDIT_FRAME() override
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false) override
Mark an item for refresh.
void UpdateNetHighlightStatus()
wxString GetScreenDesc() const override
Return a human-readable description of the current screen.
DIALOG_SCH_FIND * m_findReplaceDialog
void UpdateHierarchyNavigator()
Update the hierarchy navigation tree and history.
void AddCopyForRepeatItem(const SCH_ITEM *aItem)
void OnResizeHierarchyNavigator(wxSizeEvent &aEvent)
wxString GetCurrentFileName() const override
Get the full filename + path of the currently opened file in the frame.
SCH_JUNCTION * AddJunction(SCH_SCREEN *aScreen, const VECTOR2I &aPos, bool aAppendToUndo, bool aFinal=true)
void TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
void OnExit(wxCommandEvent &event)
void AutoRotateItem(SCH_SCREEN *aScreen, SCH_ITEM *aItem)
Automatically set the rotation of an item (if the item supports it)
SEVERITY GetSeverity(int aErrorCode) const override
void FocusOnItem(SCH_ITEM *aItem)
void SaveCopyForRepeatItem(const SCH_ITEM *aItem)
Clone aItem and owns that clone in this container.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:50
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
virtual bool IsConnectable() const
Definition: sch_item.h:349
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:187
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:146
virtual std::vector< VECTOR2I > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
Definition: sch_item.h:364
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition: sch_item.h:162
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Definition: sch_label.cpp:376
std::vector< SCH_FIELD > & GetFields()
Definition: sch_label.h:90
Tool responsible for drawing/placing items (symbols, wires, buses, labels, etc.)
wxString Serialize() const
Definition: sch_marker.cpp:73
Handle actions specific to the schematic editor.
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:619
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
bool HasNoFullyDefinedLibIds()
Test all of the schematic symbols to see if all LIB_ID objects library nickname is not set.
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:131
std::map< wxString, LIB_SYMBOL * > & GetLibSymbols()
Fetch a list of unique LIB_SYMBOL object pointers required to properly render each SCH_SYMBOL in this...
Definition: sch_screen.h:454
void Clear(bool aFree=true)
Delete all draw items and clears the project settings.
Definition: sch_screen.cpp:227
bool Remove(SCH_ITEM *aItem)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:272
double m_LastZoomLevel
last value for the zoom level, useful in Eeschema when changing the current displayed sheet to reuse ...
Definition: sch_screen.h:543
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:109
void Print(const RENDER_SETTINGS *aSettings)
Print all the items in the screen to aDC.
const wxString & GetFileName() const
Definition: sch_screen.h:144
const KIID & GetUuid() const
Definition: sch_screen.h:499
bool IsReadOnly() const
Definition: sch_screen.h:147
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Definition: sch_screen.cpp:110
bool IsExplicitJunctionNeeded(const VECTOR2I &aPosition) const
Indicates that a junction dot is necessary at the given location, and does not yet exist.
Definition: sch_screen.cpp:443
void SetConnectivityDirty()
bool m_zoomInitialized
Definition: sch_screen.h:568
bool FileExists() const
Definition: sch_screen.h:150
TEXT_SPIN_STYLE GetLabelOrientationForPoint(const VECTOR2I &aPosition, TEXT_SPIN_STYLE aDefaultOrientation, const SCH_SHEET_PATH *aSheet) const
Definition: sch_screen.cpp:452
bool CheckIfOnDrawList(const SCH_ITEM *aItem) const
Definition: sch_screen.cpp:335
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:145
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr) const
Fetch a SCH_ITEM by ID.
bool IsModified() const
Check the entire hierarchy for any modifications.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void UpdateAllScreenReferences() const
Update all the symbol references for this sheet path.
SCH_SCREEN * LastScreen()
wxString PathHumanReadable(bool aUseShortRootName=true) const
Return the sheet path in a human readable form made from the sheet names.
void SetPageNumber(const wxString &aPageNumber)
Set the sheet instance user definable page number.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
void clear()
Forwarded method from std::vector.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:66
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:55
void AddPin(SCH_SHEET_PIN *aSheetPin)
Add aSheetPin to the sheet.
Definition: sch_sheet.cpp:353
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:162
Schematic symbol object.
Definition: sch_symbol.h:80
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:900
void SetLibSymbol(LIB_SYMBOL *aLibSymbol)
Set this schematic symbol library symbol reference to aLibSymbol.
Definition: sch_symbol.cpp:295
static bool Idle(const SELECTION &aSelection)
Test if there no items selected or being edited.
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:32
EDA_ITEM * Front() const
Definition: selection.h:206
int Size() const
Returns the number of selected parts.
Definition: selection.h:113
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Saves, unloads and unregisters the given PROJECT.
Implementing SIM_PLOT_FRAME_BASE.
The symbol library editor main window.
Symbol library viewer main window.
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:170
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:172
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
ACTIONS * m_actions
Definition: tools_holder.h:171
Generic, UI-independent tool event.
Definition: tool_event.h:156
Master controller class:
Definition: tool_manager.h:55
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
ACTION_MANAGER * GetActionManager() const
Definition: tool_manager.h:196
void RegisterTool(TOOL_BASE *aTool)
Add a tool to the manager set and sets it up.
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 InitTools()
Initializes all registered tools.
void ShutdownAllTools()
Shutdown all tools with a currently registered event loop in this tool manager by waking them up with...
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: infobar.cpp:286
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
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: infobar.cpp:175
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
Definition: infobar.cpp:276
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:280
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:240
This file is part of the common library.
#define DIALOG_ERC_WINDOW_NAME
Definition: dialog_erc.h:37
Subclass of DIALOG_SCH_FIND_BASE, which is generated by wxFormBuilder.
#define _(s)
#define KICAD_DEFAULT_DRAWFRAME_STYLE
#define SCH_EDIT_FRAME_NAME
#define IS_NEW
New item, just created.
@ ID_IMPORT_NON_KICAD_SCH
Definition: eeschema_id.h:63
@ LINE_MODE_90
@ LINE_MODE_45
@ LINE_MODE_FREE
EVT_MENU_RANGE(ID_GERBVIEW_DRILL_FILE1, ID_GERBVIEW_DRILL_FILEMAX, GERBVIEW_FRAME::OnDrlFileHistory) EVT_MENU_RANGE(ID_GERBVIEW_ZIP_FILE1
KiCad executable names.
const wxString PCBNEW_EXE
@ FRAME_PCB_EDITOR
Definition: frame_type.h:40
@ FRAME_SCH_SYMBOL_EDITOR
Definition: frame_type.h:35
@ FRAME_SCH_VIEWER
Definition: frame_type.h:36
@ FRAME_SCH
Definition: frame_type.h:34
@ FRAME_SCH_VIEWER_MODAL
Definition: frame_type.h:37
@ FRAME_SIMULATOR
Definition: frame_type.h:38
@ FRAME_CVPCB
Definition: frame_type.h:48
int ExecuteFile(const wxString &aEditorName, const wxString &aFileName, wxProcess *aCallback)
Call the executable file aEditorName with the parameter aFileName.
Definition: gestfich.cpp:115
const std::string LegacyPcbFileExtension
#define PcbFileExtension
const std::string NetlistFileExtension
const std::string KiCadSchematicFileExtension
wxString KiCadSchematicFileWildcard()
wxString LegacySchematicFileWildcard()
wxString AllSchematicFilesWildcard()
@ ID_FILE_LIST_CLEAR
Definition: id.h:87
@ ID_EDA_SOCKET_EVENT
Definition: id.h:164
@ ID_EDA_SOCKET_EVENT_SERV
Definition: id.h:163
@ ID_FILEMAX
Definition: id.h:85
@ ID_FILE1
Definition: id.h:84
@ ID_GRID_SETTINGS
Definition: id.h:146
@ ID_APPEND_PROJECT
Definition: id.h:74
void ignore_unused(const T &)
Definition: ignore.h:24
KIID niluuid(0)
#define KICTL_CREATE
caller thinks requested project files may not exist.
Definition: kiway_player.h:82
@ LAYER_ERC_WARN
Definition: layer_ids.h:369
@ LAYER_ERC_EXCLUSION
Definition: layer_ids.h:371
@ LAYER_ERC_ERR
Definition: layer_ids.h:370
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:376
@ LAYER_INTERSHEET_REFS
Definition: layer_ids.h:355
@ MAIL_PCB_UPDATE
Definition: mail_type.h:46
EESCHEMA_SETTINGS * eeconfig()
Definition: sch_painter.cpp:71
@ REPAINT
Item needs to be redrawn.
Definition: view_item.h:52
@ GEOMETRY
Position or shape has changed.
Definition: view_item.h:49
void SetShutdownBlockReason(wxWindow *aWindow, const wxString &aReason)
Sets the block reason why the window/application is preventing OS shutdown.
Definition: gtk/app.cpp:83
bool SupportsShutdownBlockReason()
Whether or not the window supports setting a shutdown block reason.
Definition: gtk/app.cpp:72
see class PGM_BASE
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
SEVERITY
#define CHECK(x)
#define CURRENT_TOOL(action)
#define ENABLE(x)
SCH_CLEANUP_FLAGS
@ LOCAL_CLEANUP
@ NO_CLEANUP
@ GLOBAL_CLEANUP
Subclass of SIM_PLOT_FRAME_BASE, which is generated by wxFormBuilder.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
std::vector< FAB_LAYER_COLOR > dummy
wxString UnescapeString(const wxString &aSource)
const double IU_PER_MILS
Definition: base_units.h:78
Definition for symbol library class.
@ SCH_SYMBOL_T
Definition: typeinfo.h:156
@ SCH_FIELD_T
Definition: typeinfo.h:155
@ SCH_LABEL_T
Definition: typeinfo.h:151
@ SCH_SHEET_T
Definition: typeinfo.h:158
@ SCH_MARKER_T
Definition: typeinfo.h:141
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:153
@ SCH_SHEET_PIN_T
Definition: typeinfo.h:157
@ SCH_TEXT_T
Definition: typeinfo.h:150
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:152
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618
Definition of file extensions used in Kicad.
void SetAuiPaneSize(wxAuiManager &aManager, wxAuiPaneInfo &aPane, int aWidth, int aHeight)
Sets the size of an AUI pane, working around http://trac.wxwidgets.org/ticket/13180.