KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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 <algorithm>
26#include <api/api_handler_sch.h>
27#include <api/api_server.h>
28#include <base_units.h>
29#include <bitmaps.h>
30#include <confirm.h>
31#include <connection_graph.h>
32#include <dialogs/dialog_erc.h>
36#include <wx/srchctrl.h>
37#include <mail_type.h>
38#include <wx/clntdata.h>
39#include <wx/panel.h>
40#include <wx/sizer.h>
41#include <wx/menu.h>
42#include <local_history.h>
43#include <eeschema_id.h>
44#include <executable_names.h>
47#include <gestfich.h>
49#include <string_utils.h>
50#include <kiface_base.h>
51#include <kiplatform/app.h>
52#include <kiway.h>
53#include <symbol_edit_frame.h>
54#include <symbol_viewer_frame.h>
55#include <pgm_base.h>
56#include <core/profile.h>
59#include <python_scripting.h>
60#include <sch_edit_frame.h>
62#include <sch_painter.h>
63#include <sch_marker.h>
64#include <sch_sheet_pin.h>
65#include <sch_commit.h>
66#include <sch_rule_area.h>
68#include <advanced_config.h>
69#include <sim/simulator_frame.h>
70#include <tool/action_manager.h>
71#include <tool/action_toolbar.h>
72#include <tool/common_control.h>
73#include <tool/common_tools.h>
74#include <tool/embed_tool.h>
75#include <tool/picker_tool.h>
77#include <tool/selection.h>
79#include <tool/tool_manager.h>
80#include <tool/zoom_tool.h>
81#include <tools/sch_actions.h>
87#include <sch_io/sch_io_mgr.h>
88#include <sch_io/sch_io.h>
90#include <tools/sch_edit_tool.h>
96#include <tools/sch_move_tool.h>
99#include <trace_helpers.h>
100#include <unordered_set>
101#include <view/view_controls.h>
102#include <widgets/wx_infobar.h>
108#include <wx/cmdline.h>
109#include <wx/app.h>
110#include <wx/filedlg.h>
111#include <wx/socket.h>
112#include <wx/debug.h>
114#include <widgets/wx_aui_utils.h>
117#include <toolbars_sch_editor.h>
118#include <wx/log.h>
119#include <wx/choicdlg.h>
120#include <wx/textdlg.h>
121
122
123#ifdef KICAD_IPC_API
125#include <api/api_utils.h>
126#endif
127
129
130
131#define DIFF_SYMBOLS_DIALOG_NAME wxT( "DiffSymbolsDialog" )
132
133
134BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, SCH_BASE_FRAME )
137
138 EVT_SIZE( SCH_EDIT_FRAME::OnSize )
139
142
144
145 EVT_MENU( wxID_EXIT, SCH_EDIT_FRAME::OnExit )
146 EVT_MENU( wxID_CLOSE, SCH_EDIT_FRAME::OnExit )
147
148 // Drop files event
149 EVT_DROP_FILES( SCH_EDIT_FRAME::OnDropFiles )
150END_EVENT_TABLE()
151
152
153wxDEFINE_EVENT( EDA_EVT_SCHEMATIC_CHANGING, wxCommandEvent );
154wxDEFINE_EVENT( EDA_EVT_SCHEMATIC_CHANGED, wxCommandEvent );
155
156
157SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
158 SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH, wxT( "Eeschema" ), wxDefaultPosition,
160 m_ercDialog( nullptr ),
161 m_diffSymbolDialog( nullptr ),
162 m_symbolFieldsTableDialog( nullptr ),
163 m_netNavigator( nullptr ),
164 m_netNavigatorFilter( nullptr ),
168 m_designBlocksPane( nullptr )
169{
170 m_maximizeByDefault = true;
171 m_schematic = new SCHEMATIC( &Prj() );
172 m_schematic->SetSchematicHolder( this );
174
175 m_showBorderAndTitleBlock = true; // true to show sheet references
176 m_supportsAutoSave = true;
178 m_aboutTitle = _HKI( "KiCad Schematic Editor" );
179 m_show_search = false;
180 // Ensure timer has an owner before binding so it generates events.
181 m_crossProbeFlashTimer.SetOwner( this );
182 Bind( wxEVT_TIMER, &SCH_EDIT_FRAME::OnCrossProbeFlashTimer, this, m_crossProbeFlashTimer.GetId() );
183
184 // Give an icon
185 wxIcon icon;
186 wxIconBundle icon_bundle;
187
188 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema, 48 ) );
189 icon_bundle.AddIcon( icon );
190 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema, 128 ) );
191 icon_bundle.AddIcon( icon );
192 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema, 256 ) );
193 icon_bundle.AddIcon( icon );
194 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema_32 ) );
195 icon_bundle.AddIcon( icon );
196 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_eeschema_16 ) );
197 icon_bundle.AddIcon( icon );
198
199 SetIcons( icon_bundle );
200
202
203 setupTools();
206
210
211 // Ensure the "Line modes" toolbar group shows the current angle mode on startup
212 if( GetToolManager() )
214
215#ifdef KICAD_IPC_API
216 wxTheApp->Bind( EDA_EVT_PLUGIN_AVAILABILITY_CHANGED, &SCH_EDIT_FRAME::onPluginAvailabilityChanged, this );
217#endif
218
219 m_hierarchy = new HIERARCHY_PANE( this );
220
221 // Initialize common print setup dialog settings.
222 m_pageSetupData.GetPrintData().SetPrintMode( wxPRINT_MODE_PRINTER );
223 m_pageSetupData.GetPrintData().SetQuality( wxPRINT_QUALITY_MEDIUM );
224 m_pageSetupData.GetPrintData().SetBin( wxPRINTBIN_AUTO );
225 m_pageSetupData.GetPrintData().SetNoCopies( 1 );
226
227 m_searchPane = new SCH_SEARCH_PANE( this );
228 m_propertiesPanel = new SCH_PROPERTIES_PANEL( this, this );
229
230 m_propertiesPanel->SetSplitterProportion( eeconfig()->m_AuiPanels.properties_splitter );
231
234
235 m_auimgr.SetManagedWindow( this );
236
238
239 // Fetch a COPY of the config as a lot of these initializations are going to overwrite our
240 // data.
241 EESCHEMA_SETTINGS::AUI_PANELS aui_cfg = eeconfig()->m_AuiPanels;
242 EESCHEMA_SETTINGS::APPEARANCE appearance_cfg = eeconfig()->m_Appearance;
243
244 // Rows; layers 4 - 6
245 m_auimgr.AddPane( m_tbTopMain, EDA_PANE().HToolbar().Name( wxS( "TopMainToolbar" ) )
246 .Top().Layer( 6 ) );
247
248 m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( wxS( "MsgPanel" ) )
249 .Bottom().Layer( 6 ) );
250
251 // Columns; layers 1 - 3
252 m_auimgr.AddPane( m_hierarchy, EDA_PANE().Palette().Name( SchematicHierarchyPaneName() )
253 .Caption( _( "Schematic Hierarchy" ) )
254 .Left().Layer( 3 ).Position( 1 )
255 .TopDockable( false )
256 .BottomDockable( false )
257 .CloseButton( true )
258 .MinSize( FromDIP( wxSize( 120, 60 ) ) )
259 .BestSize( FromDIP( wxSize( 200, 200 ) ) )
260 .FloatingSize( FromDIP( wxSize( 200, 200 ) ) )
261 .FloatingPosition( FromDIP( wxPoint( 50, 50 ) ) )
262 .Show( false ) );
263
266
268
270
271 m_auimgr.AddPane( m_tbLeft, EDA_PANE().VToolbar().Name( wxS( "LeftToolbar" ) )
272 .Left().Layer( 2 ) );
273
274 m_auimgr.AddPane( m_tbRight, EDA_PANE().VToolbar().Name( wxS( "RightToolbar" ) )
275 .Right().Layer( 2 ) );
276
277 // Center
278 m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( wxS( "DrawFrame" ) )
279 .Center() );
280
281 m_auimgr.AddPane( m_searchPane, EDA_PANE()
282 .Name( SearchPaneName() )
283 .Bottom()
284 .Caption( _( "Search" ) )
285 .PaneBorder( false )
286 .MinSize( FromDIP( wxSize( 180, 60 ) ) )
287 .BestSize( FromDIP( wxSize( 180, 100 ) ) )
288 .FloatingSize( FromDIP( wxSize( 480, 200 ) ) )
289 .CloseButton( true )
290 .DestroyOnClose( false )
291 .Show( m_show_search ) );
292
295
296 wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
297 wxAuiPaneInfo& netNavigatorPane = m_auimgr.GetPane( NetNavigatorPaneName() );
298 wxAuiPaneInfo& propertiesPane = m_auimgr.GetPane( PropertiesPaneName() );
299 wxAuiPaneInfo& selectionFilterPane = m_auimgr.GetPane( wxS( "SelectionFilter" ) );
300 wxAuiPaneInfo& designBlocksPane = m_auimgr.GetPane( DesignBlocksPaneName() );
301
302 hierarchy_pane.Show( aui_cfg.show_schematic_hierarchy );
303 netNavigatorPane.Show( aui_cfg.show_net_nav_panel );
304 propertiesPane.Show( aui_cfg.show_properties );
305 designBlocksPane.Show( aui_cfg.design_blocks_show );
307
308 // The selection filter doesn't need to grow in the vertical direction when docked
309 selectionFilterPane.dock_proportion = 0;
310
311 if( aui_cfg.hierarchy_panel_float_width > 0 && aui_cfg.hierarchy_panel_float_height > 0 )
312 {
313 // Show at end, after positioning
314 hierarchy_pane.FloatingSize( aui_cfg.hierarchy_panel_float_width,
316 }
317
318 if( aui_cfg.net_nav_panel_float_size.GetWidth() > 0
319 && aui_cfg.net_nav_panel_float_size.GetHeight() > 0 )
320 {
321 netNavigatorPane.FloatingSize( aui_cfg.net_nav_panel_float_size );
322 netNavigatorPane.FloatingPosition( aui_cfg.net_nav_panel_float_pos );
323 }
324
325 if( aui_cfg.properties_panel_width > 0 )
326 SetAuiPaneSize( m_auimgr, propertiesPane, aui_cfg.properties_panel_width, -1 );
327
328 if( aui_cfg.schematic_hierarchy_float )
329 hierarchy_pane.Float();
330
331 if( aui_cfg.search_panel_height > 0
332 && ( aui_cfg.search_panel_dock_direction == wxAUI_DOCK_TOP
333 || aui_cfg.search_panel_dock_direction == wxAUI_DOCK_BOTTOM ) )
334 {
335 wxAuiPaneInfo& searchPane = m_auimgr.GetPane( SearchPaneName() );
336 searchPane.Direction( aui_cfg.search_panel_dock_direction );
337 SetAuiPaneSize( m_auimgr, searchPane, -1, aui_cfg.search_panel_height );
338 }
339
340 else if( aui_cfg.search_panel_width > 0
341 && ( aui_cfg.search_panel_dock_direction == wxAUI_DOCK_LEFT
342 || aui_cfg.search_panel_dock_direction == wxAUI_DOCK_RIGHT ) )
343 {
344 wxAuiPaneInfo& searchPane = m_auimgr.GetPane( SearchPaneName() );
345 searchPane.Direction( aui_cfg.search_panel_dock_direction );
346 SetAuiPaneSize( m_auimgr, searchPane, aui_cfg.search_panel_width, -1 );
347 }
348
349 if( aui_cfg.float_net_nav_panel )
350 netNavigatorPane.Float();
351
352 if( aui_cfg.design_blocks_show )
353 SetAuiPaneSize( m_auimgr, designBlocksPane, aui_cfg.design_blocks_panel_docked_width, -1 );
354
355 if( aui_cfg.hierarchy_panel_docked_width > 0 )
356 {
357 // If the net navigator is not show, let the hierarchy navigator take all of the vertical
358 // space.
359 if( !aui_cfg.show_net_nav_panel )
360 {
361 SetAuiPaneSize( m_auimgr, hierarchy_pane, aui_cfg.hierarchy_panel_docked_width, -1 );
362 }
363 else
364 {
365 SetAuiPaneSize( m_auimgr, hierarchy_pane,
368
369 SetAuiPaneSize( m_auimgr, netNavigatorPane,
370 aui_cfg.net_nav_panel_docked_size.GetWidth(),
371 aui_cfg.net_nav_panel_docked_size.GetHeight() );
372 }
373
374 // wxAUI hack: force width by setting MinSize() and then Fixed()
375 // thanks to ZenJu https://github.com/wxWidgets/wxWidgets/issues/13180
376 hierarchy_pane.MinSize( aui_cfg.hierarchy_panel_docked_width, 60 );
377 hierarchy_pane.Fixed();
378 netNavigatorPane.MinSize( aui_cfg.net_nav_panel_docked_size.GetWidth(), 60 );
379 netNavigatorPane.Fixed();
380 m_auimgr.Update();
381
382 // now make it resizable again
383 hierarchy_pane.Resizable();
384 netNavigatorPane.Resizable();
385 m_auimgr.Update();
386
387 // Note: DO NOT call m_auimgr.Update() anywhere after this; it will nuke the size
388 // back to minimum.
389 hierarchy_pane.MinSize( FromDIP( wxSize( 120, 60 ) ) );
390 netNavigatorPane.MinSize( FromDIP( wxSize( 120, 60 ) ) );
391 }
392 else
393 {
394 m_auimgr.Update();
395 }
396
399
400 GetCanvas()->GetGAL()->SetAxesEnabled( false );
401
402 KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
403 static_cast<KIGFX::SCH_PAINTER*>( view->GetPainter() )->SetSchematic( m_schematic );
404
407
408 view->SetLayerVisible( LAYER_ERC_ERR, appearance_cfg.show_erc_errors );
409 view->SetLayerVisible( LAYER_ERC_WARN, appearance_cfg.show_erc_warnings );
411 view->SetLayerVisible( LAYER_OP_VOLTAGES, appearance_cfg.show_op_voltages );
412 view->SetLayerVisible( LAYER_OP_CURRENTS, appearance_cfg.show_op_currents );
413
415
417 m_netNavigator->Bind( wxEVT_TREE_SEL_CHANGING, &SCH_EDIT_FRAME::onNetNavigatorSelChanging, this );
418 m_netNavigator->Bind( wxEVT_TREE_SEL_CHANGED, &SCH_EDIT_FRAME::onNetNavigatorSelection, this );
419 m_netNavigator->Bind( wxEVT_SIZE, &SCH_EDIT_FRAME::onResizeNetNavigator, this );
420
421 // This is used temporarily to fix a client size issue on GTK that causes zoom to fit
422 // to calculate the wrong zoom size. See SCH_EDIT_FRAME::onSize().
423 Bind( wxEVT_SIZE, &SCH_EDIT_FRAME::onSize, this );
424
425 setupUnits( eeconfig() );
426
427 // Net list generator
429
430 updateTitle();
431 m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->ResetHistory();
432
433#ifdef KICAD_IPC_API
434 m_apiHandler = std::make_unique<API_HANDLER_SCH>( this );
435 Pgm().GetApiServer().RegisterHandler( m_apiHandler.get() );
436#endif
437
438 // Default shutdown reason until a file is loaded
439 KIPLATFORM::APP::SetShutdownBlockReason( this, _( "New schematic file is unsaved" ) );
440
441 // Init for dropping files
445 m_acceptedExts.emplace( wxS( "jpeg" ), &SCH_ACTIONS::ddAddImage );
446 m_acceptedExts.emplace( wxS( "dxf" ), &SCH_ACTIONS::ddImportGraphics );
448 DragAcceptFiles( true );
449
450 // Ensure the window is on top
451 Raise();
452
453 // Now that all sizes are fixed, set the initial hierarchy_pane floating position to the
454 // top-left corner of the canvas
455 wxPoint canvas_pos = GetCanvas()->GetScreenPosition();
456 hierarchy_pane.FloatingPosition( canvas_pos.x + 10, canvas_pos.y + 10 );
457
458 Bind( EDA_EVT_CLOSE_DIALOG_BOOK_REPORTER, &SCH_EDIT_FRAME::onCloseSymbolDiffDialog, this );
459 Bind( EDA_EVT_CLOSE_ERC_DIALOG, &SCH_EDIT_FRAME::onCloseErcDialog, this );
460 Bind( EDA_EVT_CLOSE_DIALOG_SYMBOL_FIELDS_TABLE, &SCH_EDIT_FRAME::onCloseSymbolFieldsTableDialog, this );
461}
462
463void SCH_EDIT_FRAME::StartCrossProbeFlash( const std::vector<SCH_ITEM*>& aItems )
464{
465 if( !eeconfig()->m_CrossProbing.flash_selection )
466 {
467 wxLogTrace( traceCrossProbeFlash, "StartCrossProbeFlash: aborted (setting disabled) items=%zu", aItems.size() );
468 return;
469 }
470 if( aItems.empty() )
471 {
472 wxLogTrace( traceCrossProbeFlash, "StartCrossProbeFlash: aborted (no items)" );
473 return;
474 }
475
477 {
478 wxLogTrace( traceCrossProbeFlash, "StartCrossProbeFlash: restarting existing flash (phase=%d)",
481 }
482
483 wxLogTrace( traceCrossProbeFlash, "StartCrossProbeFlash: starting with %zu items", aItems.size() );
485
486 for( SCH_ITEM* it : aItems )
487 m_crossProbeFlashItems.push_back( it->m_Uuid );
488
491
492 if( !m_crossProbeFlashTimer.GetOwner() )
493 m_crossProbeFlashTimer.SetOwner( this );
494
495 bool started = m_crossProbeFlashTimer.Start( 500, wxTIMER_CONTINUOUS );
496 wxLogTrace( traceCrossProbeFlash, "StartCrossProbeFlash: timer start=%d id=%d", (int) started,
497 m_crossProbeFlashTimer.GetId() );
498}
499
500
501void SCH_EDIT_FRAME::OnCrossProbeFlashTimer( wxTimerEvent& aEvent )
502{
503 wxLogTrace( traceCrossProbeFlash, "Timer(SCH) fired: phase=%d running=%d items=%zu", m_crossProbeFlashPhase,
505
507 {
508 wxLogTrace( traceCrossProbeFlash, "Timer fired but not flashing (ignored)" );
509 return;
510 }
511
513
514 if( !selTool )
515 return;
516
517 bool prevGuard = m_syncingPcbToSchSelection;
519
520 if( m_crossProbeFlashPhase % 2 == 0 )
521 {
522 selTool->ClearSelection( true );
523 wxLogTrace( traceCrossProbeFlash, "Phase %d: cleared selection", m_crossProbeFlashPhase );
524 }
525 else
526 {
527 for( const KIID& id : m_crossProbeFlashItems )
528 {
529 if( SCH_ITEM* item = Schematic().ResolveItem( id, nullptr, true ) )
530 selTool->AddItemToSel( item, true );
531 }
532
533 wxLogTrace( traceCrossProbeFlash, "Phase %d: restored %zu items", m_crossProbeFlashPhase,
534 m_crossProbeFlashItems.size() );
535 }
536
537 if( GetCanvas() )
538 {
540 wxLogTrace( traceCrossProbeFlash, "Phase %d: forced canvas refresh", m_crossProbeFlashPhase );
541 }
542
543 m_syncingPcbToSchSelection = prevGuard;
545
546 if( m_crossProbeFlashPhase > 6 )
547 {
548 for( const KIID& id : m_crossProbeFlashItems )
549 {
550 if( SCH_ITEM* item = Schematic().ResolveItem( id, nullptr, true ) )
551 selTool->AddItemToSel( item, true );
552 }
553
554 m_crossProbeFlashing = false;
556 wxLogTrace( traceCrossProbeFlash, "Flashing complete. Final selection size=%zu",
557 m_crossProbeFlashItems.size() );
558 }
559}
560
561
563{
564 m_hierarchy->Unbind( wxEVT_SIZE, &SCH_EDIT_FRAME::OnResizeHierarchyNavigator, this );
565
566 // Ensure m_canvasType is up to date, to save it in config
568
569 SetScreen( nullptr );
570
571 if( m_schematic )
572 m_schematic->RemoveAllListeners();
573
574 // Delete all items not in draw list before deleting schematic
575 // to avoid dangling pointers stored in these items
578
579 delete m_schematic;
580 m_schematic = nullptr;
581
582 // Close the project if we are standalone, so it gets cleaned up properly
583 if( Kiface().IsSingle() )
584 {
585 try
586 {
587 GetSettingsManager()->UnloadProject( &Prj(), false );
588 }
589 catch( const std::runtime_error& e )
590 {
591 wxFAIL_MSG( wxString::Format( wxT( "Settings exception occurred: %s" ), e.what() ) );
592 }
593 }
594
595 // We passed ownership of these to wxAuiManager.
596 // delete m_hierarchy;
597 // delete m_selectionFilterPanel;
598}
599
600
602{
603 aEvent.Skip();
604
605 // 1st Call: Handle the size update during the first resize event.
607
608 // Defer the second size capture
609 CallAfter( [this]()
610 {
612 } );
613}
614
615
617{
618 // Called when resizing the Hierarchy Navigator panel
619 // Store the current pane size
620 // It allows to retrieve the last defined pane size when switching between
621 // docked and floating pane state
622 // Note: *DO NOT* call m_auimgr.Update() here: it crashes KiCad at least on Windows
623
624 EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
625 wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
626
627 if( cfg && m_hierarchy->IsShownOnScreen() )
628 {
629 cfg->m_AuiPanels.hierarchy_panel_float_width = hierarchy_pane.floating_size.x;
630 cfg->m_AuiPanels.hierarchy_panel_float_height = hierarchy_pane.floating_size.y;
631
632 // initialize hierarchy_panel_docked_width and best size only if the hierarchy_pane
633 // width is > 0 (i.e. if its size is already set and has meaning)
634 // if it is floating, its size is not initialized (only floating_size is initialized)
635 // initializing hierarchy_pane.best_size is useful when switching to float pane and
636 // after switching to the docked pane, to retrieve the last docked pane width
637 if( hierarchy_pane.rect.width > 50 ) // 50 is a good margin
638 {
639 cfg->m_AuiPanels.hierarchy_panel_docked_width = hierarchy_pane.rect.width;
640 hierarchy_pane.best_size.x = hierarchy_pane.rect.width;
641 }
642 }
643}
644
645
647{
648 // Create the manager and dispatcher & route draw panel events to the dispatcher
650 m_toolManager->SetEnvironment( &Schematic(), GetCanvas()->GetView(),
651 GetCanvas()->GetViewControls(), config(), this );
652 m_actions = new SCH_ACTIONS();
654
655 // Register tools
656 m_toolManager->RegisterTool( new COMMON_CONTROL );
657 m_toolManager->RegisterTool( new COMMON_TOOLS );
658 m_toolManager->RegisterTool( new ZOOM_TOOL );
659 m_toolManager->RegisterTool( new SCH_SELECTION_TOOL );
660 m_toolManager->RegisterTool( new PICKER_TOOL );
661 m_toolManager->RegisterTool( new SCH_DRAWING_TOOLS );
662 m_toolManager->RegisterTool( new SCH_LINE_WIRE_BUS_TOOL );
663 m_toolManager->RegisterTool( new SCH_MOVE_TOOL );
664 m_toolManager->RegisterTool( new SCH_ALIGN_TOOL );
665 m_toolManager->RegisterTool( new SCH_EDIT_TOOL );
666 m_toolManager->RegisterTool( new SCH_EDIT_TABLE_TOOL );
667 m_toolManager->RegisterTool( new SCH_GROUP_TOOL );
668 m_toolManager->RegisterTool( new SCH_INSPECTION_TOOL );
669 m_toolManager->RegisterTool( new SCH_DESIGN_BLOCK_CONTROL );
670 m_toolManager->RegisterTool( new SCH_EDITOR_CONTROL );
671 m_toolManager->RegisterTool( new SCH_FIND_REPLACE_TOOL );
672 m_toolManager->RegisterTool( new SCH_POINT_EDITOR );
673 m_toolManager->RegisterTool( new SCH_NAVIGATE_TOOL );
674 m_toolManager->RegisterTool( new PROPERTIES_TOOL );
675 m_toolManager->RegisterTool( new EMBED_TOOL );
676 m_toolManager->InitTools();
677
678 // Run the selection tool, it is supposed to be always active
680
682}
683
684
686{
688
689 ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
690 SCH_EDITOR_CONDITIONS cond( this );
691
692 wxASSERT( mgr );
693
694 auto hasElements =
695 [ this ] ( const SELECTION& aSel )
696 {
697 return GetScreen() &&
698 ( !GetScreen()->Items().empty() || !SELECTION_CONDITIONS::Idle( aSel ) );
699 };
700
701 auto searchPaneCond =
702 [this] ( const SELECTION& )
703 {
704 return m_auimgr.GetPane( SearchPaneName() ).IsShown();
705 };
706
707 auto propertiesCond =
708 [this] ( const SELECTION& )
709 {
710 return m_auimgr.GetPane( PropertiesPaneName() ).IsShown();
711 };
712
713 auto hierarchyNavigatorCond =
714 [ this ] ( const SELECTION& aSel )
715 {
716 return m_auimgr.GetPane( SchematicHierarchyPaneName() ).IsShown();
717 };
718
719 auto netNavigatorCond =
720 [ this ] (const SELECTION& aSel )
721 {
722 return m_auimgr.GetPane( NetNavigatorPaneName() ).IsShown();
723 };
724
725 auto designBlockCond =
726 [ this ] (const SELECTION& aSel )
727 {
728 return m_auimgr.GetPane( DesignBlocksPaneName() ).IsShown();
729 };
730
731 auto undoCond =
732 [ this ] (const SELECTION& aSel )
733 {
735 return true;
736
737 return GetUndoCommandCount() > 0;
738 };
739
740 auto groupWithDesignBlockLink =
741 [] ( const SELECTION& aSel )
742 {
743 if( aSel.Size() != 1 )
744 return false;
745
746 if( aSel[0]->Type() != SCH_GROUP_T )
747 return false;
748
749 SCH_GROUP* group = static_cast<SCH_GROUP*>( aSel.GetItem( 0 ) );
750
751 return group->HasDesignBlockLink();
752 };
753
754#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
755#define CHECK( x ) ACTION_CONDITIONS().Check( x )
756
758 mgr->SetConditions( ACTIONS::undo, ENABLE( undoCond ) );
760
761 mgr->SetConditions( SCH_ACTIONS::showSearch, CHECK( searchPaneCond ) );
762 mgr->SetConditions( SCH_ACTIONS::showHierarchy, CHECK( hierarchyNavigatorCond ) );
763 mgr->SetConditions( SCH_ACTIONS::showNetNavigator, CHECK( netNavigatorCond ) );
764 mgr->SetConditions( ACTIONS::showProperties, CHECK( propertiesCond ) );
765 mgr->SetConditions( SCH_ACTIONS::showDesignBlockPanel, CHECK( designBlockCond ) );
768
769 mgr->SetConditions( ACTIONS::cut, ENABLE( hasElements ) );
770 mgr->SetConditions( ACTIONS::copy, ENABLE( hasElements ) );
771 mgr->SetConditions( ACTIONS::copyAsText, ENABLE( hasElements ) );
774 mgr->SetConditions( ACTIONS::doDelete, ENABLE( hasElements ) );
775 mgr->SetConditions( ACTIONS::duplicate, ENABLE( hasElements ) );
782 mgr->SetConditions( ACTIONS::selectAll, ENABLE( hasElements ) );
783 mgr->SetConditions( ACTIONS::unselectAll, ENABLE( hasElements ) );
784
785 mgr->SetConditions( SCH_ACTIONS::rotateCW, ENABLE( hasElements ) );
786 mgr->SetConditions( SCH_ACTIONS::rotateCCW, ENABLE( hasElements ) );
787 mgr->SetConditions( SCH_ACTIONS::mirrorH, ENABLE( hasElements ) );
788 mgr->SetConditions( SCH_ACTIONS::mirrorV, ENABLE( hasElements ) );
791
792 mgr->SetConditions( SCH_ACTIONS::placeLinkedDesignBlock, ENABLE( groupWithDesignBlockLink ) );
793 mgr->SetConditions( SCH_ACTIONS::saveToLinkedDesignBlock, ENABLE( groupWithDesignBlockLink ) );
794
797
798 auto showHiddenPinsCond =
799 [this]( const SELECTION& )
800 {
801 return GetShowAllPins();
802 };
803
804 auto showHiddenFieldsCond =
805 [this]( const SELECTION& )
806 {
808 return cfg && cfg->m_Appearance.show_hidden_fields;
809 };
810
811 auto showDirectiveLabelsCond =
812 [this]( const SELECTION& )
813 {
815 return cfg && cfg->m_Appearance.show_directive_labels;
816 };
817
818 auto showERCErrorsCond =
819 [this]( const SELECTION& )
820 {
822 return cfg && cfg->m_Appearance.show_erc_errors;
823 };
824
825 auto showERCWarningsCond =
826 [this]( const SELECTION& )
827 {
829 return cfg && cfg->m_Appearance.show_erc_warnings;
830 };
831
832 auto showERCExclusionsCond =
833 [this]( const SELECTION& )
834 {
836 return cfg && cfg->m_Appearance.show_erc_exclusions;
837 };
838
839 auto markSimExclusionsCond =
840 [this]( const SELECTION& )
841 {
843 return cfg && cfg->m_Appearance.mark_sim_exclusions;
844 };
845
846 auto showOPVoltagesCond =
847 [this]( const SELECTION& )
848 {
850 return cfg && cfg->m_Appearance.show_op_voltages;
851 };
852
853 auto showOPCurrentsCond =
854 [this]( const SELECTION& )
855 {
857 return cfg && cfg->m_Appearance.show_op_currents;
858 };
859
860 auto showPinAltModeIconsCond =
861 [this]( const SELECTION& )
862 {
864 return cfg && cfg->m_Appearance.show_pin_alt_icons;
865 };
866
867 auto showAnnotateAutomaticallyCond =
868 [this]( const SELECTION& )
869 {
871 };
872
873 auto remapSymbolsCondition =
874 [&]( const SELECTION& aSel )
875 {
876 SCH_SCREENS schematic( Schematic().Root() );
877
878 // The remapping can only be performed on legacy projects.
879 return schematic.HasNoFullyDefinedLibIds();
880 };
881
882 auto belowRootSheetCondition =
883 [this]( const SELECTION& aSel )
884 {
885 SCH_NAVIGATE_TOOL* navigateTool = m_toolManager->GetTool<SCH_NAVIGATE_TOOL>();
886 return navigateTool && navigateTool->CanGoUp();
887 };
888
889 mgr->SetConditions( SCH_ACTIONS::leaveSheet, ENABLE( belowRootSheetCondition ) );
890
891 /* Some of these are bound by default to arrow keys which will get a different action if we
892 * disable the buttons. So always leave them enabled so the action is consistent.
893 * https://gitlab.com/kicad/code/kicad/-/issues/14783
894 mgr->SetConditions( SCH_ACTIONS::navigateUp, ENABLE( belowRootSheetCondition ) );
895 mgr->SetConditions( SCH_ACTIONS::navigateForward, ENABLE( navHistoryHasForward ) );
896 mgr->SetConditions( SCH_ACTIONS::navigateBack, ENABLE( navHistoryHsBackward ) );
897 */
898
899 mgr->SetConditions( SCH_ACTIONS::remapSymbols, ENABLE( remapSymbolsCondition ) );
900 mgr->SetConditions( SCH_ACTIONS::toggleHiddenPins, CHECK( showHiddenPinsCond ) );
901 mgr->SetConditions( SCH_ACTIONS::toggleHiddenFields, CHECK( showHiddenFieldsCond ) );
902 mgr->SetConditions( SCH_ACTIONS::toggleDirectiveLabels, CHECK( showDirectiveLabelsCond ) );
903 mgr->SetConditions( SCH_ACTIONS::toggleERCErrors, CHECK( showERCErrorsCond ) );
904 mgr->SetConditions( SCH_ACTIONS::toggleERCWarnings, CHECK( showERCWarningsCond ) );
905 mgr->SetConditions( SCH_ACTIONS::toggleERCExclusions, CHECK( showERCExclusionsCond ) );
906 mgr->SetConditions( SCH_ACTIONS::markSimExclusions, CHECK( markSimExclusionsCond ) );
907 mgr->SetConditions( SCH_ACTIONS::toggleOPVoltages, CHECK( showOPVoltagesCond ) );
908 mgr->SetConditions( SCH_ACTIONS::toggleOPCurrents, CHECK( showOPCurrentsCond ) );
909 mgr->SetConditions( SCH_ACTIONS::togglePinAltIcons, CHECK( showPinAltModeIconsCond ) );
910 mgr->SetConditions( SCH_ACTIONS::toggleAnnotateAuto, CHECK( showAnnotateAutomaticallyCond ) );
912
915
916#define CURRENT_TOOL( action ) mgr->SetConditions( action, CHECK( cond.CurrentTool( action ) ) )
917
947
948#undef CURRENT_TOOL
949#undef CHECK
950#undef ENABLE
951}
952
953
955{
956 // we cannot store a pointer to an item in the display list here since
957 // that item may be deleted, such as part of a line concatenation or other.
958 // So simply always keep a copy of the object which is to be repeated.
959
960 if( aItem )
961 {
962 m_items_to_repeat.clear();
963
964 AddCopyForRepeatItem( aItem );
965 }
966}
967
968
970{
971 // we cannot store a pointer to an item in the display list here since
972 // that item may be deleted, such as part of a line concatenation or other.
973 // So simply always keep a copy of the object which is to be repeated.
974
975 if( aItem )
976 {
977 std::unique_ptr<SCH_ITEM> repeatItem( static_cast<SCH_ITEM*>( aItem->Duplicate( IGNORE_PARENT_GROUP ) ) );
978
979 // Clone() preserves the flags & parent, we want 'em cleared.
980 repeatItem->ClearFlags();
981 repeatItem->SetParent( nullptr );
982
983 m_items_to_repeat.emplace_back( std::move( repeatItem ) );
984 }
985}
986
987
988EDA_ITEM* SCH_EDIT_FRAME::ResolveItem( const KIID& aId, bool aAllowNullptrReturn ) const
989{
990 return Schematic().ResolveItem( aId, nullptr, aAllowNullptrReturn );
991}
992
993
998
999
1004
1005
1007{
1008 return *m_schematic;
1009}
1010
1011
1013{
1014 return GetCurrentSheet().Last()->GetName();
1015}
1016
1017
1019{
1021}
1022
1023
1025{
1026 m_schematic->CreateDefaultScreens();
1027 SetScreen( Schematic().RootScreen() );
1028
1029 if( GetScreen() == nullptr )
1030 {
1031 SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
1032 SetScreen( screen );
1033 }
1034}
1035
1036
1038{
1039 return m_schematic->CurrentSheet();
1040}
1041
1042
1044{
1045 if( aSheet != GetCurrentSheet() )
1046 {
1047 ClearFocus();
1048
1049 wxLogTrace( traceSchCurrentSheet,
1050 "SCH_EDIT_FRAME::SetCurrentSheet: Changing from path='%s' (size=%zu) to path='%s' (size=%zu)",
1051 GetCurrentSheet().Path().AsString(),
1052 GetCurrentSheet().size(),
1053 aSheet.Path().AsString(),
1054 aSheet.size() );
1055
1056 Schematic().SetCurrentSheet( aSheet );
1057 GetCanvas()->DisplaySheet( aSheet.LastScreen() );
1058 }
1059}
1060
1061
1063{
1065
1066 for( SCH_ITEM* item : screen->Items() )
1067 item->ClearCaches();
1068
1069 for( const std::pair<const wxString, LIB_SYMBOL*>& libSymbol : screen->GetLibSymbols() )
1070 {
1071 wxCHECK2( libSymbol.second, continue );
1072 libSymbol.second->ClearCaches();
1073 }
1074
1075 if( Schematic().Settings().m_IntersheetRefsShow )
1077
1078 ClearFocus();
1079
1080 GetCanvas()->DisplaySheet( GetCurrentSheet().LastScreen() );
1081
1082 if( SCH_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<SCH_SELECTION_TOOL>() )
1083 selectionTool->Reset( TOOL_BASE::REDRAW );
1084
1086}
1087
1088
1089bool SCH_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
1090{
1091 // Exit interactive editing
1092 // Note this this will commit *some* pending changes. For instance, the SCH_POINT_EDITOR
1093 // will cancel any drag currently in progress, but commit all changes from previous drags.
1094 if( m_toolManager )
1096
1097 // Shutdown blocks must be determined and vetoed as early as possible
1098 if( KIPLATFORM::APP::SupportsShutdownBlockReason() && aEvent.GetId() == wxEVT_QUERY_END_SESSION
1099 && IsContentModified() )
1100 {
1101 return false;
1102 }
1103
1104 if( Kiface().IsSingle() )
1105 {
1106 auto* symbolEditor = (SYMBOL_EDIT_FRAME*) Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
1107
1108 if( symbolEditor && !symbolEditor->Close() ) // Can close symbol editor?
1109 return false;
1110
1111 auto* symbolViewer = (SYMBOL_VIEWER_FRAME*) Kiway().Player( FRAME_SCH_VIEWER, false );
1112
1113 if( symbolViewer && !symbolViewer->Close() ) // Can close symbol viewer?
1114 return false;
1115
1116 // SYMBOL_CHOOSER_FRAME is always modal so this shouldn't come up, but better safe than
1117 // sorry.
1118 auto* chooser = (SYMBOL_CHOOSER_FRAME*) Kiway().Player( FRAME_SYMBOL_CHOOSER, false );
1119
1120 if( chooser && !chooser->Close() ) // Can close symbol chooser?
1121 return false;
1122 }
1123 else
1124 {
1125 auto* symbolEditor = (SYMBOL_EDIT_FRAME*) Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
1126
1127 if( symbolEditor && symbolEditor->IsSymbolFromSchematic() )
1128 {
1129 if( !symbolEditor->CanCloseSymbolFromSchematic( true ) )
1130 return false;
1131 }
1132 }
1133
1134 if( !Kiway().PlayerClose( FRAME_SIMULATOR, false ) ) // Can close the simulator?
1135 return false;
1136
1138 && !m_symbolFieldsTableDialog->Close( false ) ) // Can close the symbol fields table?
1139 {
1140 return false;
1141 }
1142
1143 // We may have gotten multiple events; don't clean up twice
1144 if( !Schematic().IsValid() )
1145 return false;
1146
1147 if( IsContentModified() )
1148 {
1149 wxFileName fileName = Schematic().RootScreen()->GetFileName();
1150 wxString msg = _( "Save changes to '%s' before closing?" );
1151
1152 if( !HandleUnsavedChanges( this, wxString::Format( msg, fileName.GetFullName() ),
1153 [&]() -> bool
1154 {
1155 return SaveProject();
1156 } ) )
1157 {
1158 return false;
1159 }
1160
1161 // If user selected 'No' (discard), create duplicate commit of last saved state and
1162 // move Last_Save tag forward so history shows an explicit discard event.
1163 if( GetLastUnsavedChangesResponse() == wxID_NO )
1164 {
1165 wxString projPath = Prj().GetProjectPath();
1166 if( !projPath.IsEmpty() && Kiway().LocalHistory().HistoryExists( projPath ) )
1167 {
1168 Kiway().LocalHistory().CommitDuplicateOfLastSave( projPath, wxS("Schematic"),
1169 wxS("Discard unsaved schematic changes") );
1170 }
1171 }
1172 }
1173
1174 return true;
1175}
1176
1177
1179{
1181
1182 SCH_SHEET_LIST sheetlist = Schematic().Hierarchy();
1183
1184#ifdef KICAD_IPC_API
1185 Pgm().GetApiServer().DeregisterHandler( m_apiHandler.get() );
1186 wxTheApp->Unbind( EDA_EVT_PLUGIN_AVAILABILITY_CHANGED, &SCH_EDIT_FRAME::onPluginAvailabilityChanged, this );
1187#endif
1188
1189 // Close modeless dialogs. They're trouble when they get destroyed after the frame.
1190 Unbind( EDA_EVT_CLOSE_DIALOG_BOOK_REPORTER, &SCH_EDIT_FRAME::onCloseSymbolDiffDialog, this );
1191 Unbind( EDA_EVT_CLOSE_ERC_DIALOG, &SCH_EDIT_FRAME::onCloseErcDialog, this );
1192 Unbind( EDA_EVT_CLOSE_DIALOG_SYMBOL_FIELDS_TABLE, &SCH_EDIT_FRAME::onCloseSymbolFieldsTableDialog, this );
1193 m_netNavigator->Unbind( wxEVT_TREE_SEL_CHANGING, &SCH_EDIT_FRAME::onNetNavigatorSelChanging, this );
1194 m_netNavigator->Unbind( wxEVT_TREE_SEL_CHANGED, &SCH_EDIT_FRAME::onNetNavigatorSelection, this );
1195
1196 if( m_diffSymbolDialog )
1197 {
1198 m_diffSymbolDialog->Destroy();
1199 m_diffSymbolDialog = nullptr;
1200 }
1201
1202 if( m_ercDialog )
1203 {
1204 m_ercDialog->Destroy();
1205 m_ercDialog = nullptr;
1206 }
1207
1209 {
1210 m_symbolFieldsTableDialog->Destroy();
1211 m_symbolFieldsTableDialog = nullptr;
1212 }
1213
1214 // Make sure local settings are persisted
1215 if( Prj().GetLocalSettings().ShouldAutoSave() )
1217
1218 delete m_toolManager;
1219 m_toolManager = nullptr;
1220
1221 wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
1222
1223 if( hierarchy_pane.IsShown() && hierarchy_pane.IsFloating() )
1224 {
1225 hierarchy_pane.Show( false );
1226 m_auimgr.Update();
1227 }
1228
1229 sheetlist.ClearModifyStatus();
1230
1231 wxString fileName = Prj().AbsolutePath( Schematic().RootScreen()->GetFileName() );
1232
1233 if( !Schematic().GetFileName().IsEmpty() && !Schematic().RootScreen()->IsEmpty() )
1234 UpdateFileHistory( fileName );
1235
1236 Schematic().RootScreen()->Clear( true );
1237
1238 // all sub sheets are deleted, only the main sheet is usable
1240
1241 // Clear view before destroying schematic as repaints depend on schematic being valid
1242 SetScreen( nullptr );
1243
1244 Schematic().Reset();
1245
1246 // Prevents any rogue events from continuing (i.e. search panel tries to redraw)
1247 Show( false );
1248
1249 Destroy();
1250}
1251
1252
1254{
1255 m_searchPane->FocusSearch();
1256}
1257
1258
1260{
1261 return Schematic().ErcSettings().GetSeverity( aErrorCode );
1262}
1263
1264
1266{
1268
1269 if( GetScreen() )
1270 {
1272 Kiway().LocalHistory().NoteFileChange( GetScreen()->GetFileName() );
1273 }
1274
1275 if( m_isClosing )
1276 return;
1277
1278 if( GetCanvas() )
1279 GetCanvas()->Refresh();
1280
1281 if( !GetTitle().StartsWith( wxS( "*" ) ) )
1282 updateTitle();
1283}
1284
1285
1287{
1288 if( Kiface().IsSingle() )
1289 {
1290 DisplayError( this, _( "Cannot update the PCB, because the Schematic Editor is opened"
1291 " in stand-alone mode. In order to create/update PCBs from"
1292 " schematics, launch the KiCad shell and create a project." ) );
1293 return;
1294 }
1295
1296 KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_EDITOR, false );
1297 wxEventBlocker blocker( this );
1298
1299 if( !frame )
1300 {
1301 wxFileName fn = Prj().GetProjectFullName();
1302 fn.SetExt( FILEEXT::PcbFileExtension );
1303
1304 frame = Kiway().Player( FRAME_PCB_EDITOR, true );
1305
1306 // If Kiway() cannot create the Pcbnew frame, it shows a error message, and
1307 // frame is null
1308 if( !frame )
1309 return;
1310
1311 frame->OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ) );
1312 }
1313
1314 if( !frame->IsVisible() )
1315 frame->Show( true );
1316
1317 // On Windows, Raise() does not bring the window on screen, when iconized
1318 if( frame->IsIconized() )
1319 frame->Iconize( false );
1320
1321 frame->Raise();
1322
1323 std::string payload;
1325}
1326
1327
1328void SCH_EDIT_FRAME::UpdateHierarchyNavigator( bool aRefreshNetNavigator, bool aClear )
1329{
1330 m_toolManager->GetTool<SCH_NAVIGATE_TOOL>()->CleanHistory();
1331 m_hierarchy->UpdateHierarchyTree( aClear );
1332
1333 if( aRefreshNetNavigator )
1335}
1336
1337
1339{
1340 // Update only the hierarchy navigation tree labels.
1341 // The tree list is expected to be up to date
1342 m_hierarchy->UpdateLabelsHierarchyTree();
1343}
1344
1345
1347{
1348 m_hierarchy->UpdateHierarchySelection();
1349}
1350
1351
1352void SCH_EDIT_FRAME::OnLoadFile( wxCommandEvent& event )
1353{
1354 wxString fn = GetFileFromHistory( event.GetId(), _( "Schematic" ) );
1355
1356 if( fn.size() )
1357 OpenProjectFiles( std::vector<wxString>( 1, fn ) );
1358}
1359
1360
1361void SCH_EDIT_FRAME::OnClearFileHistory( wxCommandEvent& aEvent )
1362{
1364}
1365
1366
1368{
1369 // Only standalone mode can directly load a new document
1370 if( !Kiface().IsSingle() )
1371 return;
1372
1373 wxString pro_dir = m_mruPath;
1374
1375 wxFileDialog dlg( this, _( "New Schematic" ), pro_dir, wxEmptyString,
1377
1378 if( dlg.ShowModal() != wxID_CANCEL )
1379 {
1380 // Enforce the extension, wxFileDialog is inept.
1381 wxFileName create_me =
1383
1384 if( create_me.FileExists() )
1385 {
1386 wxString msg;
1387 msg.Printf( _( "Schematic file '%s' already exists." ), create_me.GetFullName() );
1388 DisplayError( this, msg );
1389 return ;
1390 }
1391
1392 // OpenProjectFiles() requires absolute
1393 wxASSERT_MSG( create_me.IsAbsolute(), wxS( "wxFileDialog returned non-absolute path" ) );
1394
1395 OpenProjectFiles( std::vector<wxString>( 1, create_me.GetFullPath() ), KICTL_CREATE );
1396 m_mruPath = create_me.GetPath();
1397 }
1398}
1399
1400
1402{
1403 // Only standalone mode can directly load a new document
1404 if( !Kiface().IsSingle() )
1405 return;
1406
1407 wxString pro_dir = m_mruPath;
1408 wxString wildcards = FILEEXT::AllSchematicFilesWildcard()
1410 + wxS( "|" ) + FILEEXT::LegacySchematicFileWildcard();
1411
1412 wxFileDialog dlg( this, _( "Open Schematic" ), pro_dir, wxEmptyString,
1413 wildcards, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
1414
1415 if( dlg.ShowModal() != wxID_CANCEL )
1416 {
1417 OpenProjectFiles( std::vector<wxString>( 1, dlg.GetPath() ) );
1419 }
1420
1421 // Since we know we're single-top here: trigger library reload
1422 CallAfter( [&]()
1423 {
1424 KIFACE *schface = Kiway().KiFACE( KIWAY::FACE_SCH );
1425 schface->PreloadLibraries( &Kiway() );
1426 } );
1427}
1428
1429
1431{
1433
1434 // Register schematic saver for autosave history
1436 [this]( const wxString& aProjectPath, std::vector<wxString>& aFiles )
1437 {
1438 m_schematic->SaveToHistory( aProjectPath, aFiles );
1439 } );
1440
1441}
1442
1443
1445{
1446 wxFileName kicad_board = Prj().AbsolutePath( Schematic().GetFileName() );
1447
1448 if( kicad_board.IsOk() && !Schematic().GetFileName().IsEmpty() )
1449 {
1450 kicad_board.SetExt( FILEEXT::PcbFileExtension );
1451 wxFileName legacy_board( kicad_board );
1452 legacy_board.SetExt( FILEEXT::LegacyPcbFileExtension );
1453 wxFileName& boardfn = legacy_board;
1454
1455 if( !legacy_board.FileExists() || kicad_board.FileExists() )
1456 boardfn = kicad_board;
1457
1458 if( Kiface().IsSingle() )
1459 {
1460 ExecuteFile( PCBNEW_EXE, boardfn.GetFullPath() );
1461 }
1462 else
1463 {
1464 wxEventBlocker blocker(this);
1465 KIWAY_PLAYER* frame = Kiway().Player( FRAME_PCB_EDITOR, false );
1466
1467 if( !frame )
1468 {
1469 frame = Kiway().Player( FRAME_PCB_EDITOR, true );
1470
1471 // frame can be null if Cvpcb cannot be run. No need to show a warning
1472 // Kiway() generates the error messages
1473 if( !frame )
1474 return;
1475
1476 frame->OpenProjectFiles( std::vector<wxString>( 1, boardfn.GetFullPath() ) );
1477 }
1478
1479 if( !frame->IsVisible() )
1480 frame->Show( true );
1481
1482 // On Windows, Raise() does not bring the window on screen, when iconized
1483 if( frame->IsIconized() )
1484 frame->Iconize( false );
1485
1486 frame->Raise();
1487 }
1488 }
1489 else
1490 {
1492 }
1493}
1494
1495
1497{
1498 wxFileName fn = Prj().AbsolutePath( Schematic().GetFileName() );
1499 fn.SetExt( FILEEXT::NetlistFileExtension );
1500
1501 if( !ReadyToNetlist( _( "Assigning footprints requires a fully annotated schematic." ) ) )
1502 return;
1503
1504 try
1505 {
1506 KIWAY_PLAYER* player = Kiway().Player( FRAME_CVPCB, false ); // test open already.
1507
1508 if( !player )
1509 {
1510 player = Kiway().Player( FRAME_CVPCB, true );
1511
1512 // player can be null if Cvpcb cannot be run. No need to show a warning
1513 // Kiway() generates the error messages
1514 if( !player )
1515 return;
1516
1517 player->Show( true );
1518 }
1519
1520 // Ensure the netlist (mainly info about symbols) is up to date
1523
1524 player->Raise();
1525 }
1526 catch( const IO_ERROR& )
1527 {
1528 DisplayError( this, _( "Could not open CvPcb" ) );
1529 }
1530}
1531
1532
1533void SCH_EDIT_FRAME::OnExit( wxCommandEvent& event )
1534{
1535 if( event.GetId() == wxID_EXIT )
1536 Kiway().OnKiCadExit();
1537
1538 if( event.GetId() == wxID_CLOSE || Kiface().IsSingle() )
1539 Close( false );
1540}
1541
1542
1544{
1545 SCHEMATIC_SETTINGS& settings = m_schematic->Settings();
1546 SIM_LIB_MGR simLibMgr( &Prj() );
1547 NULL_REPORTER devnull;
1548
1549 // Patch for bug early in V7.99 dev
1550 if( settings.m_OPO_VRange.EndsWith( 'A' ) )
1551 settings.m_OPO_VRange[ settings.m_OPO_VRange.Length() - 1 ] = 'V';
1552
1553 // Update items which may have ${OP} text variables
1554 //
1556 [&]( KIGFX::VIEW_ITEM* aItem ) -> int
1557 {
1558 int flags = 0;
1559
1560 auto invalidateTextVars =
1561 [&flags]( EDA_TEXT* text )
1562 {
1563 if( text->HasTextVars() )
1564 {
1565 text->ClearRenderCache();
1566 text->ClearBoundingBoxCache();
1568 }
1569 };
1570
1571 if( SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem ) )
1572 {
1573 item->RunOnChildren(
1574 [&invalidateTextVars]( SCH_ITEM* aChild )
1575 {
1576 if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aChild ) )
1577 invalidateTextVars( text );
1578 },
1580 }
1581
1582 if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem ) )
1583 invalidateTextVars( text );
1584
1585 return flags;
1586 } );
1587
1588 // Update OP overlay items
1589 //
1590 for( SCH_ITEM* item : GetScreen()->Items() )
1591 {
1592 if( GetCurrentSheet().GetExcludedFromSim() )
1593 continue;
1594
1595 if( item->Type() == SCH_LINE_T )
1596 {
1597 SCH_LINE* line = static_cast<SCH_LINE*>( item );
1598
1599 if( !line->GetOperatingPoint().IsEmpty() )
1600 GetCanvas()->GetView()->Update( line );
1601
1602 line->SetOperatingPoint( wxEmptyString );
1603
1604 // update value from netlist, below
1605 }
1606 else if( item->Type() == SCH_SYMBOL_T )
1607 {
1608 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1609 wxString ref = symbol->GetRef( &GetCurrentSheet() );
1610 std::vector<SCH_PIN*> pins = symbol->GetPins( &GetCurrentSheet() );
1611
1612 // Power symbols and other symbols which have the reference starting with "#" are
1613 // not included in simulation
1614 if( ref.StartsWith( '#' ) || symbol->ResolveExcludedFromSim() )
1615 continue;
1616
1617 for( SCH_PIN* pin : pins )
1618 {
1619 if( !pin->GetOperatingPoint().IsEmpty() )
1620 GetCanvas()->GetView()->Update( pin );
1621
1622 pin->SetOperatingPoint( wxEmptyString );
1623 }
1624
1625 if( pins.size() == 2 )
1626 {
1627 wxString op = m_schematic->GetOperatingPoint( ref, settings.m_OPO_IPrecision,
1628 settings.m_OPO_IRange );
1629
1630 if( !op.IsEmpty() && op != wxS( "--" ) && op != wxS( "?" ) )
1631 {
1632 pins[0]->SetOperatingPoint( op );
1633 GetCanvas()->GetView()->Update( symbol );
1634 }
1635 }
1636 else
1637 {
1638 std::vector<EMBEDDED_FILES*> embeddedFilesStack;
1639 embeddedFilesStack.push_back( m_schematic->GetEmbeddedFiles() );
1640
1641 if( EMBEDDED_FILES* symbolEmbeddedFiles = symbol->GetEmbeddedFiles() )
1642 embeddedFilesStack.push_back( symbolEmbeddedFiles );
1643
1644 simLibMgr.SetFilesStack( std::move( embeddedFilesStack ) );
1645
1646 SIM_MODEL& model = simLibMgr.CreateModel( &GetCurrentSheet(), *symbol, true, 0, devnull ).model;
1647
1648 SPICE_ITEM spiceItem;
1649 spiceItem.refName = ref;
1650 ref = model.SpiceGenerator().ItemName( spiceItem );
1651
1652 for( const auto& modelPin : model.GetPins() )
1653 {
1654 SCH_PIN* symbolPin = symbol->GetPin( modelPin.get().symbolPinNumber );
1655 wxString signalName = ref + wxS( ":" ) + modelPin.get().modelPinName;
1656 wxString op = m_schematic->GetOperatingPoint( signalName,
1657 settings.m_OPO_IPrecision,
1658 settings.m_OPO_IRange );
1659
1660 if( symbolPin && !op.IsEmpty() && op != wxS( "--" ) && op != wxS( "?" ) )
1661 {
1662 symbolPin->SetOperatingPoint( op );
1663 GetCanvas()->GetView()->Update( symbol );
1664 }
1665 }
1666 }
1667 }
1668 }
1669
1670 for( const auto& [ key, subgraphList ] : m_schematic->m_connectionGraph->GetNetMap() )
1671 {
1672 wxString op = m_schematic->GetOperatingPoint( key.Name, settings.m_OPO_VPrecision,
1673 settings.m_OPO_VRange );
1674
1675 if( !op.IsEmpty() && op != wxS( "--" ) && op != wxS( "?" ) )
1676 {
1677 for( CONNECTION_SUBGRAPH* subgraph : subgraphList )
1678 {
1679 SCH_LINE* longestWire = nullptr;
1680 double length = 0.0;
1681
1682 if( subgraph->GetSheet().GetExcludedFromSim() )
1683 continue;
1684
1685 for( SCH_ITEM* item : subgraph->GetItems() )
1686 {
1687 if( item->Type() == SCH_LINE_T )
1688 {
1689 SCH_LINE* line = static_cast<SCH_LINE*>( item );
1690
1691 if( line->IsWire() && line->GetLength() > length )
1692 {
1693 longestWire = line;
1694 length = line->GetLength();
1695 }
1696 }
1697 }
1698
1699 if( longestWire )
1700 {
1701 longestWire->SetOperatingPoint( op );
1702 GetCanvas()->GetView()->Update( longestWire );
1703 }
1704 }
1705 }
1706 }
1707}
1708
1709
1711{
1712 if( aItem->Type() == SCH_GLOBAL_LABEL_T || aItem->Type() == SCH_HIER_LABEL_T )
1713 {
1714 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( aItem );
1715
1716 if( label->AutoRotateOnPlacement() )
1717 {
1718 SPIN_STYLE spin = aScreen->GetLabelOrientationForPoint( label->GetPosition(),
1719 label->GetSpinStyle(),
1720 &GetCurrentSheet() );
1721
1722 if( spin != label->GetSpinStyle() )
1723 {
1724 label->SetSpinStyle( spin );
1725
1726 for( SCH_ITEM* item : aScreen->Items().OfType( SCH_GLOBAL_LABEL_T ) )
1727 {
1728 SCH_LABEL_BASE* otherLabel = static_cast<SCH_LABEL_BASE*>( item );
1729
1730 if( otherLabel != label && otherLabel->GetText() == label->GetText() )
1731 otherLabel->AutoplaceFields( aScreen, AUTOPLACE_AUTO );
1732 }
1733 }
1734 }
1735 }
1736}
1737
1738
1740{
1741 SCH_SCREEN* screen = GetScreen();
1742
1743 wxCHECK( screen, /* void */ );
1744
1745 wxString title;
1746
1747 if( !screen->GetFileName().IsEmpty() )
1748 {
1749 wxFileName fn( Prj().AbsolutePath( screen->GetFileName() ) );
1750 bool readOnly = false;
1751 bool unsaved = false;
1752
1753 if( fn.IsOk() && screen->FileExists() )
1754 readOnly = screen->IsReadOnly();
1755 else
1756 unsaved = true;
1757
1758 if( IsContentModified() )
1759 title = wxT( "*" );
1760
1761 title += fn.GetName();
1762
1763 wxString sheetPath = GetCurrentSheet().PathHumanReadable( false, true );
1764
1765 if( sheetPath != title )
1766 title += wxString::Format( wxT( " [%s]" ), sheetPath );
1767
1768 if( readOnly )
1769 title += wxS( " " ) + _( "[Read Only]" );
1770
1771 if( unsaved )
1772 title += wxS( " " ) + _( "[Unsaved]" );
1773 }
1774 else
1775 {
1776 title = _( "[no schematic loaded]" );
1777 }
1778
1779 title += wxT( " \u2014 " ) + _( "Schematic Editor" );
1780
1781 SetTitle( title );
1782}
1783
1784
1786{
1788
1789 if( GetScreen() )
1790 GetScreen()->m_zoomInitialized = true;
1791}
1792
1793
1795 PROGRESS_REPORTER* aProgressReporter )
1796{
1797 wxString highlightedConn = GetHighlightedConnection();
1798 bool hasHighlightedConn = !highlightedConn.IsEmpty();
1799
1800 std::function<void( SCH_ITEM* )> changeHandler =
1801 [&]( SCH_ITEM* aChangedItem ) -> void
1802 {
1803 GetCanvas()->GetView()->Update( aChangedItem, KIGFX::REPAINT );
1804
1805 SCH_CONNECTION* connection = aChangedItem->Connection();
1806
1808 return;
1809
1810 if( !hasHighlightedConn )
1811 {
1812 // No highlighted connection, but connectivity has changed, so refresh
1813 // the list of all nets
1815 }
1816 else if( connection
1817 && ( connection->Name() == highlightedConn
1818 || connection->HasDriverChanged() ) )
1819 {
1821 }
1822 };
1823
1824 Schematic().RecalculateConnections( aCommit, aCleanupFlags,
1826 aProgressReporter,
1827 GetCanvas()->GetView(),
1828 &changeHandler,
1829 m_undoList.m_CommandsList.empty() ? nullptr
1830 : m_undoList.m_CommandsList.back() );
1831
1833 [&]( KIGFX::VIEW_ITEM* aItem ) -> int
1834 {
1835 int flags = 0;
1836 SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem );
1837 SCH_CONNECTION* connection = item ? item->Connection() : nullptr;
1838
1839 auto invalidateTextVars =
1840 [&flags]( EDA_TEXT* text )
1841 {
1842 if( text->HasTextVars() )
1843 {
1844 text->ClearRenderCache();
1845 text->ClearBoundingBoxCache();
1847 }
1848 };
1849
1850 if( connection && connection->HasDriverChanged() )
1851 {
1852 connection->ClearDriverChanged();
1853 flags |= KIGFX::REPAINT;
1854 }
1855
1856 if( item )
1857 {
1858 item->RunOnChildren(
1859 [&invalidateTextVars]( SCH_ITEM* aChild )
1860 {
1861 if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aChild ) )
1862 invalidateTextVars( text );
1863 },
1865
1866 if( flags & KIGFX::GEOMETRY )
1867 GetScreen()->Update( item, false ); // Refresh RTree
1868 }
1869
1870 if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem ) )
1871 invalidateTextVars( text );
1872
1873 return flags;
1874 } );
1875
1877 || !Schematic().ConnectionGraph()->FindFirstSubgraphByName( highlightedConn ) )
1878 {
1882 }
1883}
1884
1885
1890
1891
1893{
1894 GetCanvas()->GetView()->Update( aItem );
1895}
1896
1897
1904
1905
1906std::unique_ptr<GRID_HELPER> SCH_EDIT_FRAME::MakeGridHelper()
1907{
1908 return std::make_unique<EE_GRID_HELPER>( m_toolManager );
1909}
1910
1911
1913{
1915
1916 SCHEMATIC_SETTINGS& settings = Schematic().Settings();
1917
1920
1922
1923 if( EESCHEMA_SETTINGS* cfg = GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" ) )
1924 {
1925 GetGalDisplayOptions().ReadWindowSettings( cfg->m_Window );
1926 GetRenderSettings()->SetDefaultFont( cfg->m_Appearance.default_font );
1927
1928 KIGFX::VIEW* view = GetCanvas()->GetView();
1929 view->SetLayerVisible( LAYER_ERC_ERR, cfg->m_Appearance.show_erc_errors );
1930 view->SetLayerVisible( LAYER_ERC_WARN, cfg->m_Appearance.show_erc_warnings );
1931 view->SetLayerVisible( LAYER_ERC_EXCLUSION, cfg->m_Appearance.show_erc_exclusions );
1932 view->SetLayerVisible( LAYER_OP_VOLTAGES, cfg->m_Appearance.show_op_voltages );
1933 view->SetLayerVisible( LAYER_OP_CURRENTS, cfg->m_Appearance.show_op_currents );
1934
1935 GetRenderSettings()->m_ShowPinAltIcons = cfg->m_Appearance.show_pin_alt_icons;
1936
1938
1939 settings.m_TemplateFieldNames.DeleteAllFieldNameTemplates( true /* global */ );
1940
1941 if( !cfg->m_Drawing.field_names.IsEmpty() )
1942 settings.m_TemplateFieldNames.AddTemplateFieldNames( cfg->m_Drawing.field_names );
1943 }
1944
1946
1947 for( SCH_ITEM* item : screen->Items() )
1948 {
1949 item->ClearCaches();
1950
1951 if( item->Type() == SCH_LINE_T )
1952 {
1953 SCH_LINE* line = static_cast<SCH_LINE*>( item );
1954
1955 if( line->IsWire() )
1956 UpdateHopOveredWires( line );
1957 }
1958 }
1959
1960 for( const auto& [ libItemName, libSymbol ] : screen->GetLibSymbols() )
1961 libSymbol->ClearCaches();
1962
1964
1966 Layout();
1967 SendSizeEvent();
1968}
1969
1970
1972{
1973 // Store the current zoom level into the current screen before calling
1974 // DisplayCurrentSheet() that set the zoom to GetScreen()->m_LastZoomLevel
1976
1977 // Rebuild the sheet view (draw area and any other items):
1979}
1980
1981
1983{
1984 // call my base class
1986
1987 // tooltips in toolbars
1989
1990 // For some obscure reason, the AUI manager hides the first modified pane.
1991 // So force show panes
1992 wxAuiPaneInfo& design_blocks_pane_info = m_auimgr.GetPane( m_designBlocksPane );
1993 bool panel_shown = design_blocks_pane_info.IsShown();
1994 design_blocks_pane_info.Caption( _( "Design Blocks" ) );
1995 design_blocks_pane_info.Show( panel_shown );
1996
1997 m_auimgr.GetPane( m_hierarchy ).Caption( _( "Schematic Hierarchy" ) );
1998 m_auimgr.GetPane( m_selectionFilterPanel ).Caption( _( "Selection Filter" ) );
1999 m_auimgr.GetPane( m_propertiesPanel ).Caption( _( "Properties" ) );
2000 m_auimgr.GetPane( m_designBlocksPane ).Caption( _( "Design Blocks" ) );
2001 m_auimgr.Update();
2002 m_hierarchy->UpdateHierarchyTree();
2003
2004 // status bar
2006
2007 updateTitle();
2008
2009 // This ugly hack is to fix an option(left) toolbar update bug that seems to only affect
2010 // windows. See https://bugs.launchpad.net/kicad/+bug/1816492. For some reason, calling
2011 // wxWindow::Refresh() does not resolve the issue. Only a resize event seems to force the
2012 // toolbar to update correctly.
2013#if defined( __WXMSW__ )
2014 PostSizeEvent();
2015#endif
2016}
2017
2018
2020{
2021 if( !GetHighlightedConnection().IsEmpty() )
2022 {
2023 SetStatusText( wxString::Format( _( "Highlighted net: %s" ),
2025 }
2026 else
2027 {
2028 SetStatusText( wxT( "" ) );
2029 }
2030}
2031
2032
2034{
2035 if( m_toolManager )
2037
2038 SCH_BASE_FRAME::SetScreen( aScreen );
2039 GetCanvas()->DisplaySheet( static_cast<SCH_SCREEN*>( aScreen ) );
2040
2041 if( m_toolManager )
2043}
2044
2045
2046const BOX2I SCH_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
2047{
2048 BOX2I bBoxDoc;
2049
2050 if( !GetScreen() )
2051 return bBoxDoc;
2052
2053 if( aIncludeAllVisible )
2054 {
2055 // Get the whole page size and return that
2056 int sizeX = GetScreen()->GetPageSettings().GetWidthIU( schIUScale.IU_PER_MILS );
2057 int sizeY = GetScreen()->GetPageSettings().GetHeightIU( schIUScale.IU_PER_MILS );
2058 bBoxDoc = BOX2I( VECTOR2I( 0, 0 ), VECTOR2I( sizeX, sizeY ) );
2059 }
2060 else
2061 {
2062 // Get current drawing-sheet in a form we can compare to an EDA_ITEM
2064 EDA_ITEM* dsAsItem = static_cast<EDA_ITEM*>( ds );
2065
2066 // Calc the bounding box of all items on screen except the page border
2067 for( EDA_ITEM* item : GetScreen()->Items() )
2068 {
2069 if( item != dsAsItem ) // Ignore the drawing-sheet itself
2070 bBoxDoc.Merge( item->GetBoundingBox() );
2071 }
2072 }
2073
2074 return bBoxDoc;
2075}
2076
2077
2079{
2080 return Schematic().Hierarchy().IsModified();
2081}
2082
2083
2085{
2086 EESCHEMA_SETTINGS* cfg = eeconfig();
2087 return cfg && cfg->m_Appearance.show_hidden_pins;
2088}
2089
2090
2091void SCH_EDIT_FRAME::FocusOnItem( EDA_ITEM* aItem, bool aAllowScroll )
2092{
2093 // nullptr will clear the current focus
2094 if( aItem != nullptr && !aItem->IsSCH_ITEM() )
2095 return;
2096
2097 static KIID lastBrightenedItemID( niluuid );
2098
2099 SCH_ITEM* lastItem = Schematic().ResolveItem( lastBrightenedItemID, nullptr, true );
2100
2101 if( lastItem && lastItem != aItem )
2102 {
2103 lastItem->ClearBrightened();
2104
2105 UpdateItem( lastItem );
2106 lastBrightenedItemID = niluuid;
2107 }
2108
2109 if( aItem )
2110 {
2111 if( !aItem->IsBrightened() )
2112 {
2113 aItem->SetBrightened();
2114
2115 UpdateItem( aItem );
2116 lastBrightenedItemID = aItem->m_Uuid;
2117 }
2118
2119 FocusOnLocation( aItem->GetFocusPosition(), aAllowScroll );
2120 }
2121}
2122
2123
2125{
2126 return Schematic().GetFileName();
2127}
2128
2129
2131{
2132 return m_toolManager->GetTool<SCH_SELECTION_TOOL>()->GetSelection();
2133}
2134
2135void SCH_EDIT_FRAME::onSize( wxSizeEvent& aEvent )
2136{
2137 if( IsShown() )
2138 {
2139 // We only need this until the frame is done resizing and the final client size is
2140 // established.
2141 Unbind( wxEVT_SIZE, &SCH_EDIT_FRAME::onSize, this );
2143 }
2144
2145 // Skip() is called in the base class.
2146 EDA_DRAW_FRAME::OnSize( aEvent );
2147}
2148
2149
2151 const KIID& aSchematicSymbolUUID )
2152{
2153 SCH_SHEET_PATH principalPath;
2154 SCH_SHEET_LIST sheets = Schematic().Hierarchy();
2155 SCH_ITEM* item = sheets.ResolveItem( aSchematicSymbolUUID, &principalPath, true );
2156 SCH_SYMBOL* principalSymbol = dynamic_cast<SCH_SYMBOL*>( item );
2157 SCH_COMMIT commit( m_toolManager );
2158
2159 if( !principalSymbol )
2160 return;
2161
2162 wxString principalRef;
2163
2164 if( principalSymbol->IsAnnotated( &principalPath ) )
2165 principalRef = principalSymbol->GetRef( &principalPath, false );
2166
2167 std::vector< std::pair<SCH_SYMBOL*, SCH_SHEET_PATH> > allUnits;
2168
2169 for( const SCH_SHEET_PATH& path : sheets )
2170 {
2171 for( SCH_ITEM* candidate : path.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
2172 {
2173 SCH_SYMBOL* candidateSymbol = static_cast<SCH_SYMBOL*>( candidate );
2174
2175 if( candidateSymbol == principalSymbol
2176 || ( candidateSymbol->IsAnnotated( &path )
2177 && candidateSymbol->GetRef( &path, false ) == principalRef ) )
2178 {
2179 allUnits.emplace_back( candidateSymbol, path );
2180 }
2181 }
2182 }
2183
2184 for( auto& [ unit, path ] : allUnits )
2185 {
2186 // This needs to be done before the LIB_SYMBOL is changed to prevent stale
2187 // library symbols in the schematic file.
2188 path.LastScreen()->Remove( unit );
2189
2190 if( !unit->IsNew() )
2191 commit.Modify( unit, path.LastScreen() );
2192
2193 unit->SetLibSymbol( aSymbol.Flatten().release() );
2194 unit->UpdateFields( &GetCurrentSheet(),
2195 true, /* update style */
2196 true, /* update ref */
2197 true, /* update other fields */
2198 false, /* reset ref */
2199 false /* reset other fields */ );
2200
2201 path.LastScreen()->Append( unit );
2202 GetCanvas()->GetView()->Update( unit );
2203 }
2204
2205 // Clear any orphaned alternate pins.
2206 for( SCH_PIN* pin : principalSymbol->GetPins() )
2207 {
2208 wxString altName = pin->GetAlt();
2209
2210 if( altName.IsEmpty() )
2211 continue;
2212
2213 if( pin->GetAlternates().count( altName ) == 0 )
2214 pin->SetAlt( wxEmptyString );
2215 }
2216
2217 if( !commit.Empty() )
2218 commit.Push( _( "Save Symbol to Schematic" ) );
2219}
2220
2221
2222void SCH_EDIT_FRAME::UpdateItem( EDA_ITEM* aItem, bool isAddOrDelete, bool aUpdateRtree )
2223{
2224 SCH_BASE_FRAME::UpdateItem( aItem, isAddOrDelete, aUpdateRtree );
2225
2226 if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( aItem ) )
2227 sch_item->ClearCaches();
2228}
2229
2230
2232{
2233 wxCHECK( m_toolManager, /* void */ );
2234
2238
2239 wxCHECK( screen, /* void */ );
2240
2242
2243 SCH_BASE_FRAME::SetScreen( screen );
2244
2245 SetSheetNumberAndCount(); // will also update CurrentScreen()'s sheet number info
2246
2248
2249 // update the references, units, and intersheet-refs
2251
2252 // dangling state can also have changed if different units with different pin locations are
2253 // used
2256
2257 SCH_SELECTION_TOOL* selectionTool = m_toolManager->GetTool<SCH_SELECTION_TOOL>();
2258
2259 wxCHECK( selectionTool, /* void */ );
2260
2261 auto visit =
2262 [&]( EDA_ITEM* item )
2263 {
2265 && !m_findReplaceData->findString.IsEmpty()
2266 && item->Matches( *m_findReplaceData, &GetCurrentSheet() ) )
2267 {
2268 item->SetForceVisible( true );
2269 selectionTool->BrightenItem( item );
2270 }
2271 else if( item->IsBrightened() )
2272 {
2273 item->SetForceVisible( false );
2274 selectionTool->UnbrightenItem( item );
2275 }
2276 };
2277
2278 for( SCH_ITEM* item : screen->Items() )
2279 {
2280 visit( item );
2281
2282 item->RunOnChildren(
2283 [&]( SCH_ITEM* aChild )
2284 {
2285 visit( aChild );
2286 },
2288 }
2289
2290 if( !screen->m_zoomInitialized )
2291 {
2293 }
2294 else
2295 {
2296 // Set zoom to last used in this screen
2297 GetCanvas()->GetView()->SetScale( GetScreen()->m_LastZoomLevel );
2298 GetCanvas()->GetView()->SetCenter( GetScreen()->m_ScrollCenter );
2299 }
2300
2301 updateTitle();
2302
2303 HardRedraw(); // Ensure all items are redrawn (especially the drawing-sheet items)
2304
2305 // Allow tools to re-add their VIEW_ITEMs after the last call to Clear in HardRedraw
2307
2308 SCH_EDITOR_CONTROL* editTool = m_toolManager->GetTool<SCH_EDITOR_CONTROL>();
2309
2310 wxCHECK( editTool, /* void */ );
2311
2313 editTool->UpdateNetHighlighting( dummy );
2314
2315 m_hierarchy->UpdateHierarchySelection();
2316
2317 m_schematic->OnSchSheetChanged();
2318}
2319
2320
2322{
2323 if( !m_diffSymbolDialog )
2324 {
2326 _( "Compare Symbol with Library" ) );
2327
2328 m_diffSymbolDialog->m_sdbSizerApply->SetLabel( _( "Update Symbol from Library..." ) );
2329 m_diffSymbolDialog->m_sdbSizerApply->Show();
2330 }
2331
2332 return m_diffSymbolDialog;
2333}
2334
2335
2336void SCH_EDIT_FRAME::onCloseSymbolDiffDialog( wxCommandEvent& aEvent )
2337{
2338 if( m_diffSymbolDialog && aEvent.GetString() == DIFF_SYMBOLS_DIALOG_NAME )
2339 {
2340 if( aEvent.GetId() == wxID_APPLY )
2341 {
2342 KIID symbolUUID = m_diffSymbolDialog->GetUserItemID();
2343
2344 CallAfter(
2345 [this, symbolUUID]()
2346 {
2347 EDA_ITEM* item = ResolveItem( symbolUUID );
2348
2349 if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item ) )
2350 {
2351 m_toolManager->RunAction<EDA_ITEM*>( ACTIONS::selectItem, symbol );
2352
2354 dlg.ShowQuasiModal();
2355 }
2356 } );
2357 }
2358
2359 m_diffSymbolDialog->Destroy();
2360 m_diffSymbolDialog = nullptr;
2361 }
2362}
2363
2364
2366{
2367 if( !m_ercDialog )
2368 m_ercDialog = new DIALOG_ERC( this );
2369
2370 return m_ercDialog;
2371}
2372
2373
2374void SCH_EDIT_FRAME::onCloseErcDialog( wxCommandEvent& aEvent )
2375{
2376 if( m_ercDialog )
2377 {
2378 m_ercDialog->Destroy();
2379 m_ercDialog = nullptr;
2380 }
2381}
2382
2383
2391
2392
2394{
2396 {
2397 m_symbolFieldsTableDialog->Destroy();
2398 m_symbolFieldsTableDialog = nullptr;
2399 }
2400}
2401
2402
2403void SCH_EDIT_FRAME::AddSchematicChangeListener( wxEvtHandler* aListener )
2404{
2405 auto it = std::find( m_schematicChangeListeners.begin(), m_schematicChangeListeners.end(), aListener );
2406
2407 // Don't add duplicate listeners.
2408 if( it == m_schematicChangeListeners.end() )
2409 m_schematicChangeListeners.push_back( aListener );
2410}
2411
2412
2414{
2415 auto it = std::find( m_schematicChangeListeners.begin(), m_schematicChangeListeners.end(), aListener );
2416
2417 // Don't add duplicate listeners.
2418 if( it != m_schematicChangeListeners.end() )
2419 m_schematicChangeListeners.erase( it );
2420}
2421
2422
2424{
2425 wxPanel* panel = new wxPanel( this );
2426
2427 wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
2428
2429 // Create horizontal sizer for search control and gear button
2430 wxBoxSizer* searchSizer = new wxBoxSizer( wxHORIZONTAL );
2431
2432 m_netNavigatorFilter = new wxSearchCtrl( panel, wxID_ANY );
2433 m_netNavigatorFilter->SetDescriptiveText( _( "Filter nets" ) );
2434 m_netNavigatorFilter->ShowCancelButton( false );
2435 searchSizer->Add( m_netNavigatorFilter, 1, wxEXPAND | wxRIGHT, FromDIP( 2 ) );
2436
2437 m_netNavigatorMenuButton = new BITMAP_BUTTON( panel, wxID_ANY );
2439 m_netNavigatorMenuButton->SetPadding( FromDIP( 2 ) );
2440 searchSizer->Add( m_netNavigatorMenuButton, 0, wxALIGN_CENTER_VERTICAL );
2441
2442 sizer->Add( searchSizer, 0, wxEXPAND | wxALL, FromDIP( 2 ) );
2443
2444 m_netNavigator = new wxTreeCtrl( panel, wxID_ANY, wxPoint( 0, 0 ), FromDIP( wxSize( 160, 250 ) ),
2445 wxTR_DEFAULT_STYLE | wxNO_BORDER );
2446 sizer->Add( m_netNavigator, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP( 2 ) );
2447
2448 panel->SetSizer( sizer );
2449
2450 m_netNavigatorFilter->Bind( wxEVT_COMMAND_TEXT_UPDATED,
2452 m_netNavigatorFilter->Bind( wxEVT_KEY_DOWN, &SCH_EDIT_FRAME::onNetNavigatorKey, this );
2453 m_netNavigator->Bind( wxEVT_KEY_DOWN, &SCH_EDIT_FRAME::onNetNavigatorKey, this );
2454 m_netNavigator->Bind( wxEVT_TREE_ITEM_MENU, &SCH_EDIT_FRAME::onNetNavigatorItemMenu, this );
2455 m_netNavigator->Bind( wxEVT_CONTEXT_MENU, &SCH_EDIT_FRAME::onNetNavigatorContextMenu, this );
2456
2457 m_netNavigatorMenuButton->Bind( wxEVT_LEFT_DOWN,
2458 [this]( wxMouseEvent& event )
2459 {
2460 wxMenu menu;
2461 wxMenuItem* wildcardItem = menu.AppendRadioItem( ID_NET_NAVIGATOR_SEARCH_WILDCARD,
2462 _( "Wildcard Search" ) );
2463 wxMenuItem* regexItem = menu.AppendRadioItem( ID_NET_NAVIGATOR_SEARCH_REGEX,
2464 _( "Regex Search" ) );
2465
2466 EESCHEMA_SETTINGS* cfg = eeconfig();
2467
2469 wildcardItem->Check();
2470 else
2471 regexItem->Check();
2472
2473 PopupMenu( &menu );
2474 } );
2475
2481
2482 return panel;
2483}
2484
2485
2486void SCH_EDIT_FRAME::SetHighlightedConnection( const wxString& aConnection,
2487 const NET_NAVIGATOR_ITEM_DATA* aSelection )
2488{
2489 bool refreshNetNavigator = aConnection != m_highlightedConn;
2490
2491 m_highlightedConn = aConnection;
2492
2493 if( refreshNetNavigator )
2494 RefreshNetNavigator( aSelection );
2495}
2496
2497
2499{
2500 if( m_netNavigator )
2501 {
2502 NET_NAVIGATOR_ITEM_DATA itemData;
2503 wxTreeItemId selection = m_netNavigator->GetSelection();
2504 bool refreshSelection = selection.IsOk() && ( selection != m_netNavigator->GetRootItem() );
2505
2506 if( refreshSelection )
2507 {
2509 dynamic_cast<NET_NAVIGATOR_ITEM_DATA*>( m_netNavigator->GetItemData( selection ) );
2510
2511 wxCHECK( tmp, /* void */ );
2512 itemData = *tmp;
2513 }
2514
2515 m_netNavigator->DeleteAllItems();
2516 RefreshNetNavigator( refreshSelection ? &itemData : nullptr );
2517 }
2518
2520}
2521
2522
2524{
2525 if( !m_netNavigator )
2526 return;
2527
2528 wxString newFilter = m_netNavigatorFilter ? m_netNavigatorFilter->GetValue() : wxString();
2529
2530 if( newFilter == m_netNavigatorFilterValue )
2531 return;
2532
2533 m_netNavigatorFilterValue = newFilter;
2534
2535 NET_NAVIGATOR_ITEM_DATA selectionData;
2536 NET_NAVIGATOR_ITEM_DATA* selectionPtr = nullptr;
2537
2538 wxTreeItemId selection = m_netNavigator->GetSelection();
2539
2540 if( selection.IsOk() )
2541 {
2542 if( NET_NAVIGATOR_ITEM_DATA* tmp =
2543 dynamic_cast<NET_NAVIGATOR_ITEM_DATA*>( m_netNavigator->GetItemData( selection ) ) )
2544 {
2545 selectionData = *tmp;
2546 selectionPtr = &selectionData;
2547 }
2548 }
2549
2550 RefreshNetNavigator( selectionPtr );
2551
2552 aEvent.Skip();
2553}
2554
2555
2556void SCH_EDIT_FRAME::onNetNavigatorKey( wxKeyEvent& aEvent )
2557{
2558 if( aEvent.GetKeyCode() == WXK_ESCAPE )
2559 {
2560 // Clear the search string and refresh
2562 m_netNavigatorFilter->SetValue( wxEmptyString );
2563
2564 m_netNavigatorFilterValue = wxEmptyString;
2565
2567
2568 // Don't skip the event - we handled it
2569 return;
2570 }
2571
2572 aEvent.Skip();
2573}
2574
2575
2576
2578{
2579 showNetNavigatorMenu( aEvent.GetItem() );
2580}
2581
2582
2583void SCH_EDIT_FRAME::onNetNavigatorContextMenu( wxContextMenuEvent& aEvent )
2584{
2585 if( !m_netNavigator )
2586 return;
2587
2588 wxPoint screenPos = aEvent.GetPosition();
2589
2590 if( screenPos == wxDefaultPosition )
2591 screenPos = wxGetMousePosition();
2592
2593 wxPoint clientPos = m_netNavigator->ScreenToClient( screenPos );
2594 int flags = 0;
2595 wxTreeItemId item = m_netNavigator->HitTest( clientPos, flags );
2596
2597 showNetNavigatorMenu( item );
2598}
2599
2600
2601void SCH_EDIT_FRAME::showNetNavigatorMenu( const wxTreeItemId& aItem )
2602{
2603 if( !m_netNavigator )
2604 return;
2605
2606 wxMenu menu;
2607
2608 menu.Append( ID_NET_NAVIGATOR_EXPAND_ALL, _( "Expand All" ) );
2609 menu.Append( ID_NET_NAVIGATOR_COLLAPSE_ALL, _( "Collapse All" ) );
2610
2611 wxMenuItem* findInInspector = new wxMenuItem( &menu, ID_NET_NAVIGATOR_FIND_IN_INSPECTOR,
2612 _( "Find in Net Inspector" ) );
2613 menu.Append( findInInspector );
2614
2615 wxString netName;
2616
2617 if( aItem.IsOk() )
2618 {
2619 wxTreeItemId netItem = aItem;
2620
2621 if( m_netNavigator->GetItemParent( netItem ) != m_netNavigator->GetRootItem() )
2622 {
2623 wxTreeItemId parent = m_netNavigator->GetItemParent( netItem );
2624
2625 while( parent.IsOk() && parent != m_netNavigator->GetRootItem() )
2626 {
2627 netItem = parent;
2628 parent = m_netNavigator->GetItemParent( netItem );
2629 }
2630
2631 if( parent == m_netNavigator->GetRootItem() )
2632 {
2633 if( wxStringClientData* data =
2634 dynamic_cast<wxStringClientData*>( m_netNavigator->GetItemData( netItem ) ) )
2635 {
2636 netName = data->GetData();
2637 }
2638 }
2639 }
2640 else if( m_netNavigator->GetItemParent( netItem ) == m_netNavigator->GetRootItem() )
2641 {
2642 if( wxStringClientData* data =
2643 dynamic_cast<wxStringClientData*>( m_netNavigator->GetItemData( netItem ) ) )
2644 {
2645 netName = data->GetData();
2646 }
2647 }
2648 else if( !m_highlightedConn.IsEmpty() && netItem == m_netNavigator->GetRootItem() )
2649 {
2650 netName = m_highlightedConn;
2651 }
2652 }
2653 else if( !m_highlightedConn.IsEmpty() && m_netNavigator->GetRootItem().IsOk() )
2654 {
2655 netName = m_highlightedConn;
2656 }
2657
2658 if( netName.IsEmpty() )
2659 {
2660 findInInspector->Enable( false );
2662 }
2663 else
2664 {
2665 m_netNavigatorMenuNetName = netName;
2666 }
2667
2668 PopupMenu( &menu );
2669}
2670
2671
2672void SCH_EDIT_FRAME::onNetNavigatorMenuCommand( wxCommandEvent& aEvent )
2673{
2674 if( !m_netNavigator )
2675 return;
2676
2677 switch( aEvent.GetId() )
2678 {
2680 m_netNavigator->ExpandAll();
2681 break;
2682
2684 m_netNavigator->CollapseAll();
2685
2686 if( m_netNavigator->GetRootItem().IsOk() )
2687 m_netNavigator->Expand( m_netNavigator->GetRootItem() );
2688 break;
2689
2691 if( !m_netNavigatorMenuNetName.IsEmpty() )
2693 break;
2694
2697 {
2698 EESCHEMA_SETTINGS* cfg = eeconfig();
2699 if( cfg )
2700 {
2702 ( aEvent.GetId() == ID_NET_NAVIGATOR_SEARCH_WILDCARD );
2703
2704 // Refresh the navigator with current filter
2706 }
2707 break;
2708 }
2709
2710 default:
2711 aEvent.Skip();
2712 return;
2713 }
2714
2716
2717 aEvent.Skip( false );
2718}
2719
2720
2722{
2723 wxAuiPaneInfo& hierarchyPane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
2724 wxAuiPaneInfo& netNavigatorPane = m_auimgr.GetPane( NetNavigatorPaneName() );
2725 wxAuiPaneInfo& propertiesPane = m_auimgr.GetPane( PropertiesPaneName() );
2726 wxAuiPaneInfo& selectionFilterPane = m_auimgr.GetPane( wxS( "SelectionFilter" ) );
2727
2728 // Don't give the selection filter its own visibility controls; instead show it if
2729 // anything else is visible
2730 bool showFilter = ( hierarchyPane.IsShown() && hierarchyPane.IsDocked() )
2731 || ( netNavigatorPane.IsShown() && netNavigatorPane.IsDocked() )
2732 || ( propertiesPane.IsShown() && propertiesPane.IsDocked() );
2733
2734 selectionFilterPane.Show( showFilter );
2735}
2736
2737
2738#ifdef KICAD_IPC_API
2739void SCH_EDIT_FRAME::onPluginAvailabilityChanged( wxCommandEvent& aEvt )
2740{
2741 wxLogTrace( traceApi, "SCH frame: EDA_EVT_PLUGIN_AVAILABILITY_CHANGED" );
2743 aEvt.Skip();
2744}
2745#endif
2746
2747
2749{
2750 EESCHEMA_SETTINGS* cfg = eeconfig();
2751
2752 // Ensure m_show_search is up to date (the pane can be closed outside the menu)
2753 m_show_search = m_auimgr.GetPane( SearchPaneName() ).IsShown();
2754
2756
2757 wxAuiPaneInfo& searchPaneInfo = m_auimgr.GetPane( SearchPaneName() );
2758 searchPaneInfo.Show( m_show_search );
2759
2760 if( m_show_search )
2761 {
2762 searchPaneInfo.Direction( cfg->m_AuiPanels.search_panel_dock_direction );
2763
2764 if( cfg->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_TOP
2765 || cfg->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_BOTTOM )
2766 {
2767 SetAuiPaneSize( m_auimgr, searchPaneInfo, -1, cfg->m_AuiPanels.search_panel_height );
2768 }
2769 else if( cfg->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_LEFT
2770 || cfg->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_RIGHT )
2771 {
2772 SetAuiPaneSize( m_auimgr, searchPaneInfo, cfg->m_AuiPanels.search_panel_width, -1 );
2773 }
2774
2775 m_searchPane->FocusSearch();
2776 m_searchPane->RefreshSearch();
2777 }
2778 else
2779 {
2780 cfg->m_AuiPanels.search_panel_height = m_searchPane->GetSize().y;
2781 cfg->m_AuiPanels.search_panel_width = m_searchPane->GetSize().x;
2782 cfg->m_AuiPanels.search_panel_dock_direction = searchPaneInfo.dock_direction;
2783 m_auimgr.Update();
2784 }
2785}
2786
2787
2789{
2790 if( !m_propertiesPanel )
2791 return;
2792
2793 bool show = !m_propertiesPanel->IsShownOnScreen();
2794
2795 wxAuiPaneInfo& propertiesPaneInfo = m_auimgr.GetPane( PropertiesPaneName() );
2796 propertiesPaneInfo.Show( show );
2797
2799
2800 EESCHEMA_SETTINGS* settings = eeconfig();
2801
2802 if( show )
2803 {
2804 SetAuiPaneSize( m_auimgr, propertiesPaneInfo,
2805 settings->m_AuiPanels.properties_panel_width, -1 );
2806 }
2807 else
2808 {
2809 settings->m_AuiPanels.properties_panel_width = m_propertiesPanel->GetSize().x;
2810 m_auimgr.Update();
2811 }
2812}
2813
2814
2816{
2817 EESCHEMA_SETTINGS* cfg = eeconfig();
2818
2819 wxCHECK( cfg, /* void */ );
2820
2821 wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
2822
2823 hierarchy_pane.Show( !hierarchy_pane.IsShown() );
2824
2826
2827 if( hierarchy_pane.IsShown() )
2828 {
2829 if( hierarchy_pane.IsFloating() )
2830 {
2831 hierarchy_pane.FloatingSize( cfg->m_AuiPanels.hierarchy_panel_float_width,
2833 m_auimgr.Update();
2834 }
2835 else if( cfg->m_AuiPanels.hierarchy_panel_docked_width > 0 )
2836 {
2837 // SetAuiPaneSize also updates m_auimgr
2838 SetAuiPaneSize( m_auimgr, hierarchy_pane,
2840 }
2841 }
2842 else
2843 {
2844 if( hierarchy_pane.IsFloating() )
2845 {
2846 cfg->m_AuiPanels.hierarchy_panel_float_width = hierarchy_pane.floating_size.x;
2847 cfg->m_AuiPanels.hierarchy_panel_float_height = hierarchy_pane.floating_size.y;
2848 }
2849 else
2850 {
2852 }
2853
2854 m_auimgr.Update();
2855 }
2856}
2857
2858
2860{
2861 EESCHEMA_SETTINGS* cfg = eeconfig();
2862
2863 wxCHECK( cfg, /* void */ );
2864
2865 wxAuiPaneInfo& db_library_pane = m_auimgr.GetPane( DesignBlocksPaneName() );
2866
2867 db_library_pane.Show( !db_library_pane.IsShown() );
2868
2869 if( db_library_pane.IsShown() )
2870 {
2871 if( db_library_pane.IsFloating() )
2872 {
2873 db_library_pane.FloatingSize( cfg->m_AuiPanels.design_blocks_panel_float_width,
2875 m_auimgr.Update();
2876 }
2878 {
2879 // SetAuiPaneSize also updates m_auimgr
2880 SetAuiPaneSize( m_auimgr, db_library_pane,
2882 }
2883 }
2884 else
2885 {
2886 if( db_library_pane.IsFloating() )
2887 {
2888 cfg->m_AuiPanels.design_blocks_panel_float_width = db_library_pane.floating_size.x;
2889 cfg->m_AuiPanels.design_blocks_panel_float_height = db_library_pane.floating_size.y;
2890 }
2891 else
2892 {
2894 }
2895
2896 m_auimgr.Update();
2897 }
2898}
2899
2900
2902{
2903 wxCHECK( aSchematic, /* void */ );
2904
2905 if( m_schematic )
2906 m_schematic->SetProject( nullptr );
2907
2908 aSchematic->SetProject( &Prj() );
2909 delete m_schematic;
2910
2911 m_schematic = aSchematic;
2912 m_schematic->SetSchematicHolder( this );
2913
2914 KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
2915 static_cast<KIGFX::SCH_PAINTER*>( view->GetPainter() )->SetSchematic( m_schematic );
2916 m_toolManager->SetEnvironment( m_schematic, GetCanvas()->GetView(), GetCanvas()->GetViewControls(), config(),
2917 this );
2918}
2919
2920
2922{
2924 return;
2925
2926 wxTextEntryDialog dlg( this, _( "Enter new variant name" ), _( "Variant Name" ) );
2927
2928 if( dlg.ShowModal() == wxID_CANCEL )
2929 return;
2930
2931 wxString variantName = dlg.GetValue();
2932
2933 if( variantName.IsEmpty() || ( m_currentVariantCtrl->FindString( variantName ) != wxNOT_FOUND ) )
2934 return;
2935
2936 Schematic().AddVariant( variantName );
2937
2938 int selected = m_currentVariantCtrl->GetSelection();
2939 wxString tmp;
2940
2941 if( selected != wxNOT_FOUND )
2942 tmp = m_currentVariantCtrl->GetString( selected );
2943
2944 m_currentVariantCtrl->Set( Schematic().GetVariantNamesForUI() );
2945
2946 if( selected != wxNOT_FOUND )
2947 {
2948 selected = m_currentVariantCtrl->FindString( tmp );
2949 m_currentVariantCtrl->SetSelection( selected );
2950 }
2951}
2952
2953
2955{
2957 return;
2958
2959 wxArrayString choices = Schematic().GetVariantNamesForUI();
2960
2961 // Default variant cannot be removed.
2962 choices.RemoveAt( 0 );
2963
2964 wxSingleChoiceDialog dlg( this, _( "Select variant name to remove" ), _( "Variant Name" ), choices );
2965
2966 if( dlg.ShowModal() == wxID_CANCEL )
2967 return;
2968
2969 wxString variantName = dlg.GetStringSelection();
2970
2971 if( variantName.IsEmpty() || ( m_currentVariantCtrl->FindString( variantName ) != wxNOT_FOUND ) )
2972 return;
2973
2974 Schematic().DeleteVariant( variantName );
2975
2976 int selected = m_currentVariantCtrl->GetSelection();
2977 wxString tmp;
2978
2979 if( selected != wxNOT_FOUND )
2980 tmp = m_currentVariantCtrl->GetString( selected );
2981
2982 m_currentVariantCtrl->Set( Schematic().GetVariantNamesForUI() );
2983
2984 if( selected != wxNOT_FOUND )
2985 {
2986 if( tmp != variantName )
2987 {
2988 selected = m_currentVariantCtrl->FindString( tmp );
2989 m_currentVariantCtrl->SetSelection( selected );
2990 }
2991 else
2992 {
2993 m_currentVariantCtrl->SetSelection( 0 );
2994 SetCurrentVariant( wxEmptyString );
2995 }
2996 }
2997}
2998
2999
3001{
3002 // Delegate to base auto-save behavior (commits pending local history) for now.
3004}
const KICOMMON_API wxEventTypeTag< wxCommandEvent > EDA_EVT_PLUGIN_AVAILABILITY_CHANGED
Notifies other parts of KiCad when plugin availability changes.
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:114
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:104
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:110
@ icon_eeschema_16
@ icon_eeschema_32
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
static TOOL_ACTION toggleGrid
Definition actions.h:197
static TOOL_ACTION paste
Definition actions.h:80
static TOOL_ACTION cancelInteractive
Definition actions.h:72
static TOOL_ACTION unselectAll
Definition actions.h:83
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition actions.h:226
static TOOL_ACTION copy
Definition actions.h:78
static TOOL_ACTION group
Definition actions.h:238
static TOOL_ACTION pasteSpecial
Definition actions.h:81
static TOOL_ACTION ungroup
Definition actions.h:239
static TOOL_ACTION toggleBoundingBoxes
Definition actions.h:156
static TOOL_ACTION showSearch
Definition actions.h:115
static TOOL_ACTION undo
Definition actions.h:75
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition actions.h:213
static TOOL_ACTION duplicate
Definition actions.h:84
static TOOL_ACTION doDelete
Definition actions.h:85
static TOOL_ACTION selectionTool
Definition actions.h:250
static TOOL_ACTION save
Definition actions.h:58
static TOOL_ACTION zoomFitScreen
Definition actions.h:141
static TOOL_ACTION redo
Definition actions.h:76
static TOOL_ACTION deleteTool
Definition actions.h:86
static TOOL_ACTION zoomTool
Definition actions.h:145
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:223
static TOOL_ACTION showProperties
Definition actions.h:265
static TOOL_ACTION cut
Definition actions.h:77
static TOOL_ACTION copyAsText
Definition actions.h:79
static TOOL_ACTION toggleGridOverrides
Definition actions.h:198
static TOOL_ACTION selectAll
Definition actions.h:82
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...
Handles how to draw a screen (a board, a schematic ...)
Definition base_screen.h:41
void SetContentModified(bool aModified=true)
Definition base_screen.h:59
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:658
bool Empty() const
Definition commit.h:137
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:106
Handle actions that are shared between different applications.
Handles action that are shared between different applications.
A subgraph is a set of items that are electrically connected on a single sheet.
Dialog to update or change schematic library symbols.
virtual bool doAutoSave()
This should be overridden by the derived class to handle the auto save feature.
virtual APP_SETTINGS_BASE * config() const
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
virtual void ProjectChanged()
Notification event that the project has changed.
UNDO_REDO_CONTAINER m_undoList
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
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...
ACTION_TOOLBAR * m_tbRight
TOOLBAR_SETTINGS * m_toolbarSettings
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
wxAuiManager m_auimgr
virtual void RecreateToolbars()
ACTION_TOOLBAR * m_tbLeft
virtual void OnSize(wxSizeEvent &aEvent)
virtual void ClearFileHistory()
Remove all files from the file history.
virtual void OnDropFiles(wxDropFilesEvent &aEvent)
Handle event fired when a file is dropped to the window.
std::map< const wxString, TOOL_ACTION * > m_acceptedExts
Associate file extensions with action to execute.
wxString GetFileFromHistory(int cmdId, const wxString &type, FILE_HISTORY *aFileHistory=nullptr)
Fetch the file name from the file history list.
virtual int GetUndoCommandCount() const
ACTION_TOOLBAR * m_tbTopMain
wxString m_aboutTitle
bool m_isClosing
Set by the close window event handler after frames are asked if they can close.
void ReCreateMenuBar()
Recreate the menu bar.
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType
The current canvas type.
void setupUnits(APP_SETTINGS_BASE *aCfg)
virtual void SwitchCanvas(EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Change the current rendering backend.
virtual void OnSize(wxSizeEvent &event) override
Recalculate the size of toolbars and display panel when the frame size changes.
GAL_DISPLAY_OPTIONS_IMPL & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
virtual void resolveCanvasType()
Determine the canvas type to load (with prompt if required) and initializes m_canvasType.
static const wxString PropertiesPaneName()
EDA_MSG_PANEL * m_messagePanel
virtual void SetScreen(BASE_SCREEN *aScreen)
virtual void UpdateMsgPanel()
Redraw the message panel.
void FocusOnLocation(const VECTOR2I &aPos, bool aAllowScroll=true)
Useful to focus on a particular location, in find functions.
virtual void ClearFocus()
SEARCH_PANE * m_searchPane
static const wxString DesignBlocksPaneName()
std::unique_ptr< EDA_SEARCH_DATA > m_findReplaceData
PROPERTIES_PANEL * m_propertiesPanel
bool m_showBorderAndTitleBlock
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
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:98
virtual const VECTOR2I GetFocusPosition() const
Similar to GetPosition() but allows items to return their visual center rather than their anchor.
Definition eda_item.h:279
const KIID m_Uuid
Definition eda_item.h:516
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
void ClearBrightened()
Definition eda_item.h:138
void SetBrightened()
Definition eda_item.h:135
bool IsBrightened() const
Definition eda_item.h:129
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:80
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:98
SELECTION_CONDITION NoActiveTool()
Create a functor testing if there are no tools active in the frame.
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 GridVisible()
Create a functor testing if the grid is visible in a frame.
SELECTION_CONDITION GridOverrides()
Create a functor testing if the grid overrides wires is enabled in a frame.
PANEL_ANNOTATE m_AnnotatePanel
bool empty() const
Definition sch_rtree.h:179
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:241
SEVERITY GetSeverity(int aErrorCode) const
void ReadWindowSettings(WINDOW_SETTINGS &aCfg)
Read GAL config options from application-level config.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
APP_SETTINGS_BASE * KifaceSettings() const
Definition kiface_base.h:95
void SetDefaultFont(const wxString &aFont)
Contains methods for drawing schematic-specific items.
Definition sch_painter.h:69
void SetSchematic(SCHEMATIC *aSchematic)
Definition sch_painter.h:79
void Update(const KIGFX::VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition sch_view.cpp:60
DS_PROXY_VIEW_ITEM * GetDrawingSheet() const
Definition sch_view.h:120
void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 }) override
Set the scaling factor, zooming around a given anchor point.
Definition sch_view.cpp:102
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:86
bool IsSCH_ITEM() const
Definition view_item.h:101
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:66
double GetScale() const
Definition view.h:276
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition view.h:400
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition view.h:220
void SetCenter(const VECTOR2D &aCenter)
Set the center point of the VIEW (i.e.
Definition view.cpp:596
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:1571
wxString AsString() const
Definition kiid.cpp:356
Definition kiid.h:49
KIWAY_PLAYER(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName, const EDA_IU_SCALE &aIuScale)
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.
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:292
void OnKiCadExit()
Definition kiway.cpp:756
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition kiway.cpp:403
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr, bool aFromOtherThread=false)
Send aPayload to aDestination from aSource.
Definition kiway.cpp:507
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
Definition kiway.cpp:206
@ FACE_SCH
eeschema DSO
Definition kiway.h:299
LOCAL_HISTORY & LocalHistory()
Return the LOCAL_HISTORY associated with this KIWAY.
Definition kiway.h:404
Define a library symbol object.
Definition lib_symbol.h:85
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
bool CommitDuplicateOfLastSave(const wxString &aProjectPath, const wxString &aFileType, const wxString &aMessage)
Create a new commit duplicating the tree pointed to by Last_Save_<fileType> and move the Last_Save_<f...
void NoteFileChange(const wxString &aFile)
Record that a file has been modified and should be included in the next snapshot.
void RegisterSaver(const void *aSaverObject, const std::function< void(const wxString &, std::vector< wxString > &)> &aSaver)
Register a saver callback invoked during autosave history commits.
Tree view item data for the net navigator.
A singleton reporter that reports to nowhere.
Definition reporter.h:216
int GetHeightIU(double aIUScale) const
Gets the page height in IU.
Definition page_info.h:168
int GetWidthIU(double aIUScale) const
Gets the page width in IU.
Definition page_info.h:159
A progress reporter interface for use in multi-threaded environments.
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition project.cpp:161
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition project.cpp:167
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:391
Action handler for the Properties panel.
These are loaded from Eeschema settings but then overwritten by the project settings.
Holds all the data relating to one schematic.
Definition schematic.h:88
void SetCurrentSheet(const SCH_SHEET_PATH &aPath)
Definition schematic.h:191
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
void RecomputeIntersheetRefs()
Update the schematic's page reference map for all global labels, and refresh the labels so that they ...
wxString GetFileName() const
Helper to retrieve the filename from the root sheet screen.
void AddVariant(const wxString &aVariantName)
Definition schematic.h:467
SCHEMATIC_SETTINGS & Settings() const
SCH_ITEM * ResolveItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr, bool aAllowNullptrReturn=false) const
Definition schematic.h:119
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
void DeleteVariant(const wxString &aVariantName)
Delete all information for aVariantName.
void SetProject(PROJECT *aPrj)
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
wxArrayString GetVariantNamesForUI() const
Return an array of variant names for using in wxWidgets UI controls.
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
void RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags, TOOL_MANAGER *aToolManager, PROGRESS_REPORTER *aProgressReporter=nullptr, KIGFX::SCH_VIEW *aSchView=nullptr, std::function< void(SCH_ITEM *)> *aChangedItemHandler=nullptr, PICKED_ITEMS_LIST *aLastChangeList=nullptr)
Generate the connection data for the entire schematic hierarchy.
ERC_SETTINGS & ErcSettings() const
Gather all the actions that are shared by tools.
Definition sch_actions.h:40
static TOOL_ACTION rotateCCW
static TOOL_ACTION placeClassLabel
Definition sch_actions.h:79
static TOOL_ACTION placeSheetPin
Definition sch_actions.h:85
static TOOL_ACTION saveSheetAsDesignBlock
static TOOL_ACTION mirrorV
static TOOL_ACTION drawSheetFromFile
Definition sch_actions.h:83
static TOOL_ACTION toggleOPCurrents
static TOOL_ACTION saveToLinkedDesignBlock
Definition sch_actions.h:71
static TOOL_ACTION saveSelectionAsDesignBlock
static TOOL_ACTION placeGlobalLabel
Definition sch_actions.h:80
static TOOL_ACTION drawTextBox
Definition sch_actions.h:93
static TOOL_ACTION toggleAnnotateAuto
static TOOL_ACTION ddAddImage
static TOOL_ACTION drawArc
Definition sch_actions.h:97
static TOOL_ACTION drawSheet
Definition sch_actions.h:82
static TOOL_ACTION toggleERCWarnings
static TOOL_ACTION toggleDirectiveLabels
static TOOL_ACTION highlightNetTool
static TOOL_ACTION leaveSheet
static TOOL_ACTION ddImportGraphics
static TOOL_ACTION toggleHiddenFields
static TOOL_ACTION drawRectangle
Definition sch_actions.h:95
static TOOL_ACTION drawLines
Definition sch_actions.h:99
static TOOL_ACTION placeHierLabel
Definition sch_actions.h:81
static TOOL_ACTION alignTop
static TOOL_ACTION alignRight
static TOOL_ACTION placeLabel
Definition sch_actions.h:78
static TOOL_ACTION drawCircle
Definition sch_actions.h:96
static TOOL_ACTION placeBusWireEntry
Definition sch_actions.h:77
static TOOL_ACTION drawBezier
Definition sch_actions.h:98
static TOOL_ACTION drawWire
Definition sch_actions.h:72
static TOOL_ACTION remapSymbols
static TOOL_ACTION rotateCW
static TOOL_ACTION alignBottom
static TOOL_ACTION showHierarchy
static TOOL_ACTION showNetNavigator
static TOOL_ACTION placeJunction
Definition sch_actions.h:76
static TOOL_ACTION markSimExclusions
static TOOL_ACTION drawRuleArea
static TOOL_ACTION placeSymbol
Definition sch_actions.h:66
static TOOL_ACTION placeImage
static TOOL_ACTION alignLeft
static TOOL_ACTION toggleERCErrors
static TOOL_ACTION alignCenterX
static TOOL_ACTION angleSnapModeChanged
static TOOL_ACTION placeLinkedDesignBlock
Definition sch_actions.h:70
static TOOL_ACTION drawSheetFromDesignBlock
Definition sch_actions.h:84
static TOOL_ACTION mirrorH
static TOOL_ACTION placeDesignBlock
Definition sch_actions.h:69
static TOOL_ACTION toggleOPVoltages
static TOOL_ACTION drawBus
Definition sch_actions.h:73
static TOOL_ACTION drawTable
Definition sch_actions.h:94
static TOOL_ACTION ddAppendFile
static TOOL_ACTION placeSchematicText
Definition sch_actions.h:92
static TOOL_ACTION showDesignBlockPanel
static TOOL_ACTION togglePinAltIcons
static TOOL_ACTION toggleERCExclusions
static TOOL_ACTION updateNetHighlighting
static TOOL_ACTION alignCenterY
static TOOL_ACTION placeNoConnect
Definition sch_actions.h:75
static TOOL_ACTION toggleHiddenPins
static TOOL_ACTION syncSheetPins
Definition sch_actions.h:89
static TOOL_ACTION placePower
Definition sch_actions.h:68
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
SCH_BASE_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aWindowType, const wxString &aTitle, const wxPoint &aPosition, const wxSize &aSize, long aStyle, const wxString &aFrameName)
SCH_RENDER_SETTINGS * GetRenderSettings()
void doCloseWindow() override
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
DIALOG_SCH_FIND * m_findReplaceDialog
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
EESCHEMA_SETTINGS * eeconfig() const
PANEL_SCH_SELECTION_FILTER * m_selectionFilterPanel
virtual void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false)
Mark an item for refresh.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
bool HasDriverChanged() const
wxString Name(bool aIgnoreSheet=false) const
Handle design block actions in the schematic editor.
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.
int UpdateNetHighlighting(const TOOL_EVENT &aEvent)
Launch a tool to highlight nets.
Schematic editor (Eeschema) main window.
void DefaultExecFlags()
Reset the execution flags to defaults for external netlist and bom generators.
void OnCrossProbeFlashTimer(wxTimerEvent &aEvent)
void ToggleProperties() override
bool IsContentModified() const override
Get if the current schematic has been modified but not saved.
void RefreshOperatingPointDisplay()
Refresh the display of any operating points.
wxPageSetupDialogData m_pageSetupData
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
wxTreeCtrl * m_netNavigator
std::vector< std::unique_ptr< SCH_ITEM > > m_items_to_repeat
For the repeat-last-item cmd.
void FocusOnItem(EDA_ITEM *aItem, bool aAllowScroll=true) override
Focus on a particular canvas item.
void onResizeNetNavigator(wxSizeEvent &aEvent)
void updateSelectionFilterVisbility() override
Selection filter panel doesn't have a dedicated visibility control, so show it if any other AUI panel...
void onNetNavigatorSelChanging(wxTreeEvent &aEvent)
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag and update other data struc...
void showNetNavigatorMenu(const wxTreeItemId &aItem)
void ShowAllIntersheetRefs(bool aShow)
void SaveProjectLocalSettings() override
Save changes to the project settings to the project (.pro) file.
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
Open a project or set of files given by aFileList.
void doCloseWindow() override
DIALOG_BOOK_REPORTER * m_diffSymbolDialog
void ToggleLibraryTree() override
void SetHighlightedConnection(const wxString &aConnection, const NET_NAVIGATOR_ITEM_DATA *aSelection=nullptr)
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.
wxWindow * createHighlightedNetNavigator()
void onCloseErcDialog(wxCommandEvent &aEvent)
void UpdateHierarchySelection()
Update the hierarchy navigation tree selection (cross-probe from schematic to hierarchy pane).
bool m_syncingPcbToSchSelection
void SetScreen(BASE_SCREEN *aScreen) override
friend class SCH_EDITOR_CONTROL
bool doAutoSave() override
Save the schematic files that have been modified and not yet saved.
wxChoice * m_currentVariantCtrl
void SaveSymbolToSchematic(const LIB_SYMBOL &aSymbol, const KIID &aSchematicSymbolUUID)
Update a schematic symbol from a LIB_SYMBOL.
void SetCurrentVariant(const wxString &aVariantName)
void onSize(wxSizeEvent &aEvent)
void CommonSettingsChanged(int aFlags) override
Called after the preferences dialog is run.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
BITMAP_BUTTON * m_netNavigatorMenuButton
void onNetNavigatorKey(wxKeyEvent &aEvent)
void configureToolbars() override
std::vector< wxEvtHandler * > m_schematicChangeListeners
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.
SCHEMATIC * m_schematic
The currently loaded schematic.
void onNetNavigatorFilterChanged(wxCommandEvent &aEvent)
void onCloseSymbolFieldsTableDialog(wxCommandEvent &aEvent)
SCH_SHEET_PATH & GetCurrentSheet() const
void RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags, PROGRESS_REPORTER *aProgressReporter=nullptr)
Generate the connection data for the entire schematic hierarchy.
wxString m_netNavigatorFilterValue
void ProjectChanged() override
Notification event that the project has changed.
void OnLoadFile(wxCommandEvent &event)
SCHEMATIC & Schematic() const
void updateTitle()
Set the main window title bar text.
void SetSchematic(SCHEMATIC *aSchematic)
void ToggleSearch()
Toggle the show/hide state of Search pane.
bool LoadProjectSettings()
Load the KiCad project file (*.pro) settings specific to Eeschema.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void RefreshNetNavigator(const NET_NAVIGATOR_ITEM_DATA *aSelection=nullptr)
wxSearchCtrl * m_netNavigatorFilter
wxString GetFullScreenDesc() const override
static const wxString SearchPaneName()
DIALOG_BOOK_REPORTER * GetSymbolDiffDialog()
bool canCloseWindow(wxCloseEvent &aCloseEvent) override
void onNetNavigatorContextMenu(wxContextMenuEvent &aEvent)
void RecomputeIntersheetRefs()
Update the schematic's page reference map for all global labels, and refresh the labels so that they ...
DIALOG_ERC * GetErcDialog()
void sendNetlistToCvpcb()
Send the KiCad netlist over to CVPCB.
SCH_DESIGN_BLOCK_PANE * m_designBlocksPane
void UpdateHierarchyNavigator(bool aRefreshNetNavigator=true, bool aClear=false)
Update the hierarchy navigation tree and history.
SCH_EDIT_FRAME(KIWAY *aKiway, wxWindow *aParent)
void ToggleSchematicHierarchy()
Toggle the show/hide state of the left side schematic navigation panel.
std::vector< KIID > m_crossProbeFlashItems
Items to flash.
void LoadDrawingSheet()
Load the drawing sheet file.
void onNetNavigatorMenuCommand(wxCommandEvent &aEvent)
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
std::vector< LIB_ID > m_designBlockHistoryList
void OnPageSettingsChange() override
Called when modifying the page settings.
void ClearRepeatItemsList()
Clear the list of items which are to be repeated with the insert key.
const BOX2I GetDocumentExtents(bool aIncludeAllVisible=true) const override
Return bounding box of document with option to not include some items.
void CaptureHierarchyPaneSize()
void StartCrossProbeFlash(const std::vector< SCH_ITEM * > &aItems)
void initScreenZoom()
Initialize the zoom value of the current screen and mark the screen as zoom-initialized.
void UpdateLabelsHierarchyNavigator()
Update the hierarchy navigation tree labels.
void OnImportProject(wxCommandEvent &event)
double GetSchematicHopOverScale()
static const wxString SchematicHierarchyPaneName()
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
EDA_ITEM * ResolveItem(const KIID &aId, bool aAllowNullptrReturn=false) const override
Fetch an item by KIID.
wxString m_netNavigatorMenuNetName
void unitsChangeRefresh() override
Called when when the units setting has changed to allow for any derived classes to handle refreshing ...
void RemoveSchematicChangeListener(wxEvtHandler *aListener)
Remove aListener to from the schematic changed listener list.
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
void DisplayCurrentSheet()
Draw the current sheet on the display.
~SCH_EDIT_FRAME() override
const wxString & GetHighlightedConnection() const
DIALOG_ERC * m_ercDialog
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.
void onNetNavigatorItemMenu(wxTreeEvent &aEvent)
void AddCopyForRepeatItem(const SCH_ITEM *aItem)
DIALOG_SYMBOL_FIELDS_TABLE * GetSymbolFieldsTableDialog()
void OnResizeHierarchyNavigator(wxSizeEvent &aEvent)
wxString GetCurrentFileName() const override
Get the full filename + path of the currently opened file in the frame.
wxString m_highlightedConn
The highlighted net or bus or empty string.
static const wxString NetNavigatorPaneName()
void onCloseSymbolDiffDialog(wxCommandEvent &aEvent)
void IntersheetRefUpdate(SCH_GLOBALLABEL *aItem) override
Callback from schematic ref update.
void OnExit(wxCommandEvent &event)
void AutoRotateItem(SCH_SCREEN *aScreen, SCH_ITEM *aItem)
Automatically set the rotation of an item (if the item supports it).
wxTimer m_crossProbeFlashTimer
Timer to toggle selection visibility.
void AddSchematicChangeListener(wxEvtHandler *aListener)
Add aListener to post #EDA_EVT_SCHEMATIC_CHANGED command events to.
HIERARCHY_PANE * m_hierarchy
DIALOG_SYMBOL_FIELDS_TABLE * m_symbolFieldsTableDialog
std::unique_ptr< GRID_HELPER > MakeGridHelper() override
void UpdateHopOveredWires(SCH_ITEM *aItem)
SEVERITY GetSeverity(int aErrorCode) const override
void onNetNavigatorSelection(wxTreeEvent &aEvent)
void FindNetInInspector(const wxString &aNetName)
void SaveCopyForRepeatItem(const SCH_ITEM *aItem)
Clone aItem and owns that clone in this container.
Handle actions specific to the schematic editor.
A set of SCH_ITEMs (i.e., without duplicates).
Definition sch_group.h:52
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
SCH_ITEM * Duplicate(bool addToParentGroup, SCH_COMMIT *aCommit=nullptr, bool doClone=false) const
Routine to create a new copy of given item.
Definition sch_item.cpp:137
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction, RECURSE_MODE aMode)
Definition sch_item.h:611
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:352
bool ResolveExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.cpp:274
bool AutoRotateOnPlacement() const
autoRotateOnPlacement
SPIN_STYLE GetSpinStyle() const
void AutoplaceFields(SCH_SCREEN *aScreen, AUTOPLACE_ALGO aAlgo) override
virtual void SetSpinStyle(SPIN_STYLE aSpinStyle)
Tool responsible for drawing/placing items (symbols, wires, buses, labels, etc.)
static bool IsDrawingLineWireOrBus(const SELECTION &aSelection)
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:42
void SetOperatingPoint(const wxString &aText)
Definition sch_line.h:348
bool IsWire() const
Return true if the line is a wire.
Definition sch_line.cpp:989
double GetLength() const
Definition sch_line.cpp:249
const wxString & GetOperatingPoint() const
Definition sch_line.h:347
Handle actions specific to the schematic editor.
void SetOperatingPoint(const wxString &aText)
Definition sch_pin.h:338
Tool that displays edit points allowing to modify items by dragging the points.
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition sch_screen.h:728
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:139
void Clear(bool aFree=true)
Delete all draw items and clears the project settings.
void TestDanglingEnds(const SCH_SHEET_PATH *aPath=nullptr, std::function< void(SCH_ITEM *)> *aChangedHandler=nullptr) const
Test all of the connectable objects in the schematic for unused connection points.
const std::map< wxString, LIB_SYMBOL * > & GetLibSymbols() const
Fetch a list of unique LIB_SYMBOL object pointers required to properly render each SCH_SYMBOL in this...
Definition sch_screen.h:485
double m_LastZoomLevel
last value for the zoom level, useful in Eeschema when changing the current displayed sheet to reuse ...
Definition sch_screen.h:655
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:117
const wxString & GetFileName() const
Definition sch_screen.h:152
bool IsReadOnly() const
Definition sch_screen.h:155
void Update(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Update aItem's bounding box in the tree.
bool m_zoomInitialized
Definition sch_screen.h:680
bool FileExists() const
Definition sch_screen.h:158
SPIN_STYLE GetLabelOrientationForPoint(const VECTOR2I &aPosition, SPIN_STYLE aDefaultOrientation, const SCH_SHEET_PATH *aSheet) const
int ClearSelection(const TOOL_EVENT &aEvent)
Select all visible items in sheet.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
SCH_ITEM * ResolveItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr, bool aAllowNullptrReturn=false) 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...
wxString PathHumanReadable(bool aUseShortRootName=true, bool aStripTrailingSeparator=false) const
Return the sheet path in a human readable form made from the sheet names.
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
void UpdateAllScreenReferences() const
Update all the symbol references for this sheet path.
SCH_SCREEN * LastScreen()
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
void clear()
Forwarded method from std::vector.
size_t size() const
Forwarded method from std::vector.
wxString GetName() const
Definition sch_sheet.h:113
Schematic symbol object.
Definition sch_symbol.h:76
EMBEDDED_FILES * GetEmbeddedFiles() override
SCH_SYMBOLs don't currently support embedded files, but their LIB_SYMBOL counterparts do.
bool IsAnnotated(const SCH_SHEET_PATH *aSheet) const
Check if the symbol has a valid annotation (reference) for the given sheet path.
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
SCH_PIN * GetPin(const wxString &number) const
Find a symbol pin by number.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
VECTOR2I GetPosition() const override
Definition sch_text.h:150
static SELECTION_CONDITION HasType(KICAD_T aType)
Create a functor that tests if among the selected items there is at least one of a given type.
static bool NotEmpty(const SELECTION &aSelection)
Test if there are any items selected.
static SELECTION_CONDITION MoreThan(int aNumber)
Create a functor that tests if the number of selected items is greater than the value given as parame...
static 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).
void BrightenItem(EDA_ITEM *aItem)
int AddItemToSel(const TOOL_EVENT &aEvent)
void UnbrightenItem(EDA_ITEM *aItem)
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Save, unload and unregister the given PROJECT.
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
void SetFilesStack(std::vector< EMBEDDED_FILES * > aFilesStack)
Definition sim_lib_mgr.h:48
const SPICE_GENERATOR & SpiceGenerator() const
Definition sim_model.h:431
std::vector< std::reference_wrapper< const SIM_MODEL_PIN > > GetPins() const
virtual std::string ItemName(const SPICE_ITEM &aItem) const
Symbol library viewer main window.
The symbol library editor main window.
Symbol library viewer main window.
void AddTemplateFieldNames(const wxString &aSerializedFieldNames)
Add a serialized list of template field names.
void DeleteAllFieldNameTemplates(bool aGlobal)
Delete the entire contents.
TOOL_MANAGER * m_toolManager
TOOL_DISPATCHER * m_toolDispatcher
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
ACTIONS * m_actions
@ REDRAW
Full drawing refresh.
Definition tool_base.h:83
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition tool_base.h:80
Generic, UI-independent tool event.
Definition tool_event.h:171
Master controller class:
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
wxString EnsureFileExtension(const wxString &aFilename, const wxString &aExtension)
It's annoying to throw up nag dialogs when the extension isn't right.
Definition common.cpp:439
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:131
int GetLastUnsavedChangesResponse()
Return the result code from the last call to HandleUnsavedChanges(): wxID_YES, wxID_NO or wxID_CANCEL...
Definition confirm.cpp:144
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:177
This file is part of the common library.
#define CHECK(x)
#define ENABLE(x)
#define _(s)
wxDEFINE_EVENT(wxEVT_REFRESH_CUSTOM_COMMAND, wxEvent)
#define KICAD_DEFAULT_DRAWFRAME_STYLE
#define SCH_EDIT_FRAME_NAME
@ NO_RECURSE
Definition eda_item.h:52
#define IGNORE_PARENT_GROUP
Definition eda_item.h:55
@ ID_IMPORT_NON_KICAD_SCH
Definition eeschema_id.h:62
const wxAuiPaneInfo & defaultSchSelectionFilterPaneInfo(wxWindow *aWindow)
const wxAuiPaneInfo & defaultPropertiesPaneInfo(wxWindow *aWindow)
const wxAuiPaneInfo & defaultNetNavigatorPaneInfo()
const wxAuiPaneInfo & defaultDesignBlocksPaneInfo(wxWindow *aWindow)
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:42
@ 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_SIMULATOR
Definition frame_type.h:38
@ FRAME_CVPCB
Definition frame_type.h:52
@ FRAME_SYMBOL_CHOOSER
Definition frame_type.h:37
int ExecuteFile(const wxString &aEditorName, const wxString &aFileName, wxProcess *aCallback, bool aFileForKicad)
Call the executable file aEditorName with the parameter aFileName.
Definition gestfich.cpp:143
static const std::string NetlistFileExtension
static const std::string JpegFileExtension
static const std::string PngFileExtension
static const std::string LegacyPcbFileExtension
static const std::string KiCadSchematicFileExtension
static const std::string SVGFileExtension
static wxString LegacySchematicFileWildcard()
static wxString AllSchematicFilesWildcard()
static wxString KiCadSchematicFileWildcard()
const wxChar *const traceSchCurrentSheet
Flag to enable debug output of current sheet tracking in the schematic editor.
const wxChar *const traceCrossProbeFlash
Flag to enable debug output for cross-probe flash operations.
const wxChar *const traceApi
Flag to enable debug output related to the IPC API and its plugin system.
Definition api_utils.cpp:27
@ ID_FILE_LIST_CLEAR
Definition id.h:62
@ ID_EDA_SOCKET_EVENT
Definition id.h:132
@ ID_EDA_SOCKET_EVENT_SERV
Definition id.h:131
@ ID_FILEMAX
Definition id.h:60
@ ID_FILE1
Definition id.h:59
PROJECT & Prj()
Definition kicad.cpp:629
KIID niluuid(0)
#define KICTL_CREATE
caller thinks requested project files may not exist.
@ LAYER_ERC_WARN
Definition layer_ids.h:479
@ LAYER_ERC_EXCLUSION
Definition layer_ids.h:481
@ LAYER_ERC_ERR
Definition layer_ids.h:480
@ LAYER_OP_CURRENTS
Definition layer_ids.h:502
@ LAYER_INTERSHEET_REFS
Definition layer_ids.h:463
@ LAYER_OP_VOLTAGES
Definition layer_ids.h:501
@ MAIL_PCB_UPDATE
Definition mail_type.h:46
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:58
@ GEOMETRY
Position or shape has changed.
Definition view_item.h:55
void SetShutdownBlockReason(wxWindow *aWindow, const wxString &aReason)
Sets the block reason why the window/application is preventing OS shutdown.
Definition unix/app.cpp:90
bool SupportsShutdownBlockReason()
Whether or not the window supports setting a shutdown block reason.
Definition unix/app.cpp:79
#define _HKI(x)
Definition page_info.cpp:44
PGM_BASE & Pgm()
The global program "get" accessor.
Definition pgm_base.cpp:946
see class PGM_BASE
SEVERITY
#define DIFF_SYMBOLS_DIALOG_NAME
#define CURRENT_TOOL(action)
@ AUTOPLACE_AUTO
Definition sch_item.h:70
SCH_CLEANUP_FLAGS
Definition schematic.h:74
@ GLOBAL_CLEANUP
Definition schematic.h:77
T * GetToolbarSettings(const wxString &aFilename)
T * GetAppSettings(const char *aFilename)
KIWAY Kiway(KFCTL_STANDALONE)
std::vector< FAB_LAYER_COLOR > dummy
wxString UnescapeString(const wxString &aSource)
Implement a participant in the KIWAY alchemy.
Definition kiway.h:155
virtual void PreloadLibraries(KIWAY *aKiway)
Definition kiway.h:258
std::string refName
wxLogTrace helper definitions.
@ SCH_GROUP_T
Definition typeinfo.h:177
@ SCH_LINE_T
Definition typeinfo.h:167
@ SCH_SYMBOL_T
Definition typeinfo.h:176
@ SCH_HIER_LABEL_T
Definition typeinfo.h:173
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:172
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
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.