KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_editor_control.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) 2019-2023 CERN
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
26
27#include <clipboard.h>
28#include <confirm.h>
29#include <connection_graph.h>
39#include <project_rescue.h>
40#include <erc/erc.h>
41#include <invoke_sch_dialog.h>
42#include <string_utils.h>
43#include <kiway.h>
45#include <paths.h>
46#include <pgm_base.h>
49#include <project_sch.h>
50#include <sch_edit_frame.h>
52#include <sch_bitmap.h>
53#include <sch_line.h>
54#include <sch_junction.h>
55#include <sch_bus_entry.h>
56#include <sch_shape.h>
57#include <sch_painter.h>
58#include <sch_sheet_pin.h>
59#include <sch_commit.h>
60#include <sim/simulator_frame.h>
61#include <symbol_lib_table.h>
62#include <symbol_library.h>
64#include <symbol_viewer_frame.h>
65#include <tool/picker_tool.h>
66#include <tool/tool_manager.h>
67#include <tools/sch_actions.h>
68#include <tools/sch_selection.h>
73#include <eda_list_dialog.h>
74#include <view/view_controls.h>
76#include <wx_filename.h>
77#include <wx/filedlg.h>
78#include <wx/log.h>
79#include <wx/treectrl.h>
80#include <wx/msgdlg.h>
83
84#ifdef KICAD_IPC_API
86#endif
87
88
94static const wxChar traceSchPaste[] = wxT( "KICAD_SCH_PASTE" );
95
96
98{
100 return 0;
101}
102
103
105{
107 return 0;
108}
109
110
112{
114 return 0;
115}
116
117
119{
120 m_frame->SaveProject( true );
121 return 0;
122}
123
124
126{
127 SCH_SHEET* curr_sheet = m_frame->GetCurrentSheet().Last();
128 wxFileName curr_fn = curr_sheet->GetFileName();
129 wxFileDialog dlg( m_frame, _( "Schematic Files" ), curr_fn.GetPath(), curr_fn.GetFullName(),
131 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
132
133 if( dlg.ShowModal() == wxID_CANCEL )
134 return false;
135
136 wxString newFilename =
138
139 m_frame->saveSchematicFile( curr_sheet, newFilename );
140 return 0;
141}
142
143
145{
146 SCHEMATIC& schematic = m_frame->Schematic();
147 SCH_SHEET& root = schematic.Root();
148
149 if( m_frame->GetCurrentSheet().Last() != &root )
150 {
151 SCH_SHEET_PATH rootSheetPath;
152 rootSheetPath.push_back( &root );
153
155 &rootSheetPath );
156 wxSafeYield();
157 }
158
159 wxString msg;
160 msg.Printf( _( "Revert '%s' (and all sub-sheets) to last version saved?" ),
161 schematic.GetFileName() );
162
163 if( !IsOK( m_frame, msg ) )
164 return false;
165
166 SCH_SCREENS screenList( schematic.Root() );
167
168 for( SCH_SCREEN* screen = screenList.GetFirst(); screen; screen = screenList.GetNext() )
169 screen->SetContentModified( false ); // do not prompt the user for changes
170
172 m_frame->OpenProjectFiles( std::vector<wxString>( 1, schematic.GetFileName() ), KICTL_REVERT );
173
174 return 0;
175}
176
177
179{
181 return 0;
182}
183
184
186{
187 PICKED_ITEMS_LIST undoCmd;
189 ITEM_PICKER wrapper( m_frame->GetScreen(), undoItem, UNDO_REDO::PAGESETTINGS );
190
191 undoCmd.PushItem( wrapper );
192 undoCmd.SetDescription( _( "Page Settings" ) );
193 m_frame->SaveCopyInUndoList( undoCmd, UNDO_REDO::PAGESETTINGS, false, false );
194
198
199 if( dlg.ShowModal() == wxID_OK )
200 {
201 // Update text variables
205
206 m_frame->OnModify();
207 }
208 else
209 {
211 }
212
213 return 0;
214}
215
216
218{
219 SCH_SCREENS schematic( m_frame->Schematic().Root() );
220
221 if( schematic.HasNoFullyDefinedLibIds() )
222 RescueLegacyProject( true );
223 else
225
226 return 0;
227}
228
229
230bool SCH_EDITOR_CONTROL::RescueLegacyProject( bool aRunningOnDemand )
231{
234
235 return rescueProject( rescuer, aRunningOnDemand );
236}
237
238
240{
244
245 return rescueProject( rescuer, aRunningOnDemand );
246}
247
248
249bool SCH_EDITOR_CONTROL::rescueProject( RESCUER& aRescuer, bool aRunningOnDemand )
250{
251 if( !RESCUER::RescueProject( m_frame, aRescuer, aRunningOnDemand ) )
252 return false;
253
254 if( aRescuer.GetCandidateCount() )
255 {
256 KIWAY_PLAYER* viewer = m_frame->Kiway().Player( FRAME_SCH_VIEWER, false );
257
258 if( viewer )
259 static_cast<SYMBOL_VIEWER_FRAME*>( viewer )->ReCreateLibList();
260
261 if( aRunningOnDemand )
262 {
263 SCH_SCREENS schematic( m_frame->Schematic().Root() );
264
265 schematic.UpdateSymbolLinks();
267 }
268
270 m_frame->SyncView();
272 m_frame->OnModify();
273 }
274
275 return true;
276}
277
278
280{
281 DIALOG_SYMBOL_REMAP dlgRemap( m_frame );
282
283 dlgRemap.ShowQuasiModal();
284
285 m_frame->GetCanvas()->Refresh( true );
286
287 return 0;
288}
289
290
292{
293 DIALOG_PRINT dlg( m_frame );
294
295 dlg.ShowModal();
296
297 return 0;
298}
299
300
302{
304
305 dlg.ShowModal();
306
307 // save project config if the prj config has changed:
308 if( dlg.PrjConfigChanged() )
309 m_frame->OnModify();
310
311 return 0;
312}
313
314
316{
317 m_frame->Close( false );
318 return 0;
319}
320
321
323{
324 doCrossProbeSchToPcb( aEvent, false );
325 return 0;
326}
327
328
330{
331 doCrossProbeSchToPcb( aEvent, true );
332 return 0;
333}
334
335
336void SCH_EDITOR_CONTROL::doCrossProbeSchToPcb( const TOOL_EVENT& aEvent, bool aForce )
337{
338 // Don't get in an infinite loop SCH -> PCB -> SCH -> PCB -> SCH -> ...
340 return;
341
343 SCH_SELECTION& selection = aForce ? selTool->RequestSelection() : selTool->GetSelection();
344
345 m_frame->SendSelectItemsToPcb( selection.GetItemsSortedBySelectionOrder(), aForce );
346}
347
348
350{
351 bool savePowerSymbols = IsOK( m_frame,
352 _( "Include power symbols in schematic to the library?" ) );
353
354 bool createNew = aEvent.IsAction( &SCH_ACTIONS::exportSymbolsToNewLibrary );
355
357 SCH_REFERENCE_LIST symbols;
358 sheets.GetSymbols( symbols, savePowerSymbols );
359
360 std::map<LIB_ID, LIB_SYMBOL*> libSymbols;
361 std::map<LIB_ID, std::vector<SCH_SYMBOL*>> symbolMap;
362
363 for( size_t i = 0; i < symbols.GetCount(); ++i )
364 {
365 SCH_SYMBOL* symbol = symbols[i].GetSymbol();
366 LIB_SYMBOL* libSymbol = symbol->GetLibSymbolRef().get();
367 LIB_ID id = libSymbol->GetLibId();
368
369 if( libSymbols.count( id ) )
370 {
371 wxASSERT_MSG( libSymbols[id]->Compare( *libSymbol, SCH_ITEM::COMPARE_FLAGS::ERC ) == 0,
372 "Two symbols have the same LIB_ID but are different!" );
373 }
374 else
375 {
376 libSymbols[id] = libSymbol;
377 }
378
379 symbolMap[id].emplace_back( symbol );
380 }
381
383
384 wxString targetLib;
385
386 if( createNew )
387 {
388 wxFileName fn;
390
391 if( !libTable ) // Cancelled by user
392 return 0;
393
396 ( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() ),
398 {
399 return 0;
400 }
401
402 targetLib = fn.GetName();
403
404 if( libTable->HasLibrary( targetLib, false ) )
405 {
406 DisplayError( m_frame, wxString::Format( _( "Library '%s' already exists." ),
407 targetLib ) );
408 return 0;
409 }
410
411 // if the "new" library is in fact an existing library and the used asked for replacing
412 // it by the recreated lib, erase it:
413 if( fn.FileExists() )
414 wxRemoveFile( fn.GetFullPath() );
415
416 if( !mgr.CreateLibrary( fn.GetFullPath(), *libTable ) )
417 {
418 DisplayError( m_frame, wxString::Format( _( "Could not add library '%s'." ),
419 targetLib ) );
420 return 0;
421 }
422 }
423 else
424 {
425 targetLib = m_frame->SelectLibraryFromList();
426 }
427
428 if( targetLib.IsEmpty() )
429 return 0;
430
431 bool map = IsOK( m_frame, _( "Update symbols in schematic to refer to new library?" ) );
432 bool append = false;
433
434 SCH_COMMIT commit( m_frame );
435 SYMBOL_LIB_TABLE_ROW* row = mgr.GetLibrary( targetLib );
436 SCH_IO_MGR::SCH_FILE_T type = SCH_IO_MGR::EnumFromStr( row->GetType() );
437 IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( type ) );
438
439 wxFileName dest = row->GetFullURI( true );
440 dest.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
441
442 for( const std::pair<const LIB_ID, LIB_SYMBOL*>& it : libSymbols )
443 {
444 LIB_SYMBOL* origSym = it.second;
445 LIB_SYMBOL* newSym = origSym->Flatten().release();
446
447 try
448 {
449 pi->SaveSymbol( dest.GetFullPath(), newSym );
450 }
451 catch( const IO_ERROR& ioe )
452 {
453 wxString msg;
454 msg.Printf( _( "Error saving symbol %s to library '%s'." ),
455 newSym->GetName(), row->GetNickName() );
456 msg += wxS( "\n\n" ) + ioe.What();
457 wxLogWarning( msg );
458 return 0;
459 }
460
461 if( map )
462 {
463 LIB_ID id = it.first;
464 id.SetLibNickname( targetLib );
465
466 for( SCH_SYMBOL* symbol : symbolMap[it.first] )
467 {
468 SCH_SCREEN* parentScreen = static_cast<SCH_SCREEN*>( symbol->GetParent() );
469
470 wxCHECK2( parentScreen, continue );
471
472 commit.Modify( symbol, parentScreen );
473 symbol->SetLibId( id );
474 append = true;
475 }
476 }
477 }
478
479 // Save the modified symbol library table. We need to look this up by name in each table to find
480 // whether the new library is a global or project entity as the code above to choose the library
481 // returns a different type depending on whether a global or project library is chosen.
483 SYMBOL_LIB_TABLE* projectTable = nullptr;
484
485 if( !m_frame->Prj().IsNullProject() )
486 projectTable = PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() );
487
488 if( globalTable->FindRow( targetLib ) )
489 {
490 try
491 {
492 wxString globalTablePath = SYMBOL_LIB_TABLE::GetGlobalTableFileName();
493 globalTable->Save( globalTablePath );
494 }
495 catch( const IO_ERROR& ioe )
496 {
497 wxString msg;
498 msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
499 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
500 }
501 }
502 else if( projectTable && projectTable->FindRow( targetLib ) )
503 {
504 try
505 {
506 wxString projectPath = m_frame->Prj().GetProjectPath();
507 wxFileName projectTableFn( projectPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
508 projectTable->Save( projectTableFn.GetFullPath() );
509 }
510 catch( const IO_ERROR& ioe )
511 {
512 wxString msg;
513 msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
514 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
515 }
516 }
517
518 if( append )
519 {
520 std::set<SCH_SCREEN*> processedScreens;
521
522 for( SCH_SHEET_PATH& sheet : sheets )
523 {
524 SCH_SCREEN* screen = sheet.LastScreen();
525
526 if( processedScreens.find( ( screen ) ) == processedScreens.end() )
527 {
528 processedScreens.insert( screen );
529 screen->UpdateSymbolLinks();
530 }
531 }
532
533 commit.Push( wxS( "Update Library Identifiers" ) );
534 }
535
536 return 0;
537}
538
539
540#define HITTEST_THRESHOLD_PIXELS 5
541
543{
545 KIWAY_PLAYER* player = m_frame->Kiway().Player( FRAME_SIMULATOR, false );
546 SIMULATOR_FRAME* simFrame = static_cast<SIMULATOR_FRAME*>( player );
547
548 if( !simFrame ) // Defensive coding; shouldn't happen.
549 return 0;
550
551 if( wxWindow* blocking_win = simFrame->Kiway().GetBlockingDialog() )
552 blocking_win->Close( true );
553
554 // Deactivate other tools; particularly important if another PICKER is currently running
555 Activate();
556
557 picker->SetCursor( KICURSOR::VOLTAGE_PROBE );
558 picker->SetSnapping( false );
559
560 picker->SetClickHandler(
561 [this, simFrame]( const VECTOR2D& aPosition )
562 {
564
565 // We do not really want to keep an item selected in schematic,
566 // so clear the current selection
567 selTool->ClearSelection();
568
569 EDA_ITEM* item = selTool->GetNode( aPosition );
571
572 if( !item )
573 return false;
574
575 if( item->Type() == SCH_PIN_T )
576 {
577 try
578 {
579 SCH_PIN* pin = static_cast<SCH_PIN*>( item )->GetLibPin();
580 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item->GetParent() );
581
582 WX_STRING_REPORTER reporter;
583 SIM_LIB_MGR mgr( &m_frame->Prj(), &m_frame->Schematic() );
584
585 SIM_MODEL& model = mgr.CreateModel( &sheet, *symbol, reporter ).model;
586
587 if( reporter.HasMessage() )
588 THROW_IO_ERROR( reporter.GetMessages() );
589
590 SPICE_ITEM spiceItem;
591 spiceItem.refName = symbol->GetRef( &sheet ).ToStdString();
592 std::vector<std::string> currentNames =
593 model.SpiceGenerator().CurrentNames( spiceItem );
594
595 if( currentNames.size() == 0 )
596 {
597 return true;
598 }
599 else if( currentNames.size() == 1 )
600 {
601 simFrame->AddCurrentTrace( currentNames.at( 0 ) );
602 return true;
603 }
604
605 int modelPinIndex = model.FindModelPinIndex( pin->GetNumber().ToStdString() );
606
607 if( modelPinIndex != SIM_MODEL_PIN::NOT_CONNECTED )
608 {
609 wxString name = currentNames.at( modelPinIndex );
610 simFrame->AddCurrentTrace( name );
611 }
612 }
613 catch( const IO_ERROR& e )
614 {
616 }
617 }
618 else if( item->IsType( { SCH_ITEM_LOCATE_WIRE_T } )
619 || item->IsType( { SCH_JUNCTION_T } ) )
620 {
621 if( SCH_CONNECTION* conn = static_cast<SCH_ITEM*>( item )->Connection() )
622 {
623 wxString spiceNet = UnescapeString( conn->Name() );
625
626 simFrame->AddVoltageTrace( wxString::Format( "V(%s)", spiceNet ) );
627 }
628 }
629
630 return true;
631 } );
632
633 picker->SetMotionHandler(
634 [this, picker]( const VECTOR2D& aPos )
635 {
636 SCH_COLLECTOR collector;
637 collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
638 collector.Collect( m_frame->GetScreen(), { SCH_ITEM_LOCATE_WIRE_T,
639 SCH_PIN_T,
640 SCH_SHEET_PIN_T }, aPos );
641
643 selectionTool->GuessSelectionCandidates( collector, aPos );
644
645 EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
646 SCH_LINE* wire = dynamic_cast<SCH_LINE*>( item );
647
648 const SCH_CONNECTION* conn = nullptr;
649
650 if( wire )
651 {
652 item = nullptr;
653 conn = wire->Connection();
654 }
655
656 if( item && item->Type() == SCH_PIN_T )
657 picker->SetCursor( KICURSOR::CURRENT_PROBE );
658 else
659 picker->SetCursor( KICURSOR::VOLTAGE_PROBE );
660
661 if( m_pickerItem != item )
662 {
663 if( m_pickerItem )
664 selectionTool->UnbrightenItem( m_pickerItem );
665
666 m_pickerItem = item;
667
668 if( m_pickerItem )
669 selectionTool->BrightenItem( m_pickerItem );
670 }
671
672 wxString connectionName = ( conn ) ? conn->Name() : wxString( wxS( "" ) );
673
674 if( m_frame->GetHighlightedConnection() != connectionName )
675 {
676 m_frame->SetHighlightedConnection( connectionName );
677
678 TOOL_EVENT dummyEvent;
679 UpdateNetHighlighting( dummyEvent );
680 }
681 } );
682
683 picker->SetFinalizeHandler(
684 [this]( const int& aFinalState )
685 {
686 if( m_pickerItem )
687 m_toolMgr->GetTool<SCH_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
688
689 if( !m_frame->GetHighlightedConnection().IsEmpty() )
690 {
691 m_frame->SetHighlightedConnection( wxEmptyString );
692
693 TOOL_EVENT dummyEvent;
694 UpdateNetHighlighting( dummyEvent );
695 }
696
697 // Wake the selection tool after exiting to ensure the cursor gets updated
698 // and deselect previous selection from simulator to avoid any issue
699 // ( avoid crash in some cases when the SimProbe tool is deselected )
701 selectionTool->ClearSelection();
703 } );
704
706
707 return 0;
708}
709
710
712{
714
715 // Deactivate other tools; particularly important if another PICKER is currently running
716 Activate();
717
718 picker->SetCursor( KICURSOR::TUNE );
719 picker->SetSnapping( false );
720
721 picker->SetClickHandler(
722 [this]( const VECTOR2D& aPosition )
723 {
725 EDA_ITEM* item = nullptr;
726 selTool->SelectPoint( aPosition, { SCH_SYMBOL_T, SCH_FIELD_T }, &item );
727
728 if( !item )
729 return false;
730
731 if( item->Type() != SCH_SYMBOL_T )
732 {
733 item = item->GetParent();
734
735 if( item->Type() != SCH_SYMBOL_T )
736 return false;
737 }
738
739 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
740 SCH_SHEET_PATH sheetPath = symbol->Schematic()->CurrentSheet();
741 KIWAY_PLAYER* simFrame = m_frame->Kiway().Player( FRAME_SIMULATOR, false );
742
743 if( simFrame )
744 {
745 if( wxWindow* blocking_win = simFrame->Kiway().GetBlockingDialog() )
746 blocking_win->Close( true );
747
748 static_cast<SIMULATOR_FRAME*>( simFrame )->AddTuner( sheetPath, symbol );
749 }
750
751 // We do not really want to keep a symbol selected in schematic,
752 // so clear the current selection
753 selTool->ClearSelection();
754 return true;
755 } );
756
757 picker->SetMotionHandler(
758 [this]( const VECTOR2D& aPos )
759 {
760 SCH_COLLECTOR collector;
761 collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
762 collector.Collect( m_frame->GetScreen(), { SCH_SYMBOL_T, SCH_FIELD_T }, aPos );
763
765 selectionTool->GuessSelectionCandidates( collector, aPos );
766
767 EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
768
769 if( item && item->Type() == SCH_FIELD_T )
770 item = static_cast<SCH_FIELD*>( item )->GetParentSymbol();
771
772 if( m_pickerItem != item )
773 {
774 if( m_pickerItem )
775 selectionTool->UnbrightenItem( m_pickerItem );
776
777 m_pickerItem = item;
778
779 if( m_pickerItem )
780 selectionTool->BrightenItem( m_pickerItem );
781 }
782 } );
783
784 picker->SetFinalizeHandler(
785 [this]( const int& aFinalState )
786 {
787 if( m_pickerItem )
788 m_toolMgr->GetTool<SCH_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
789
790 // Wake the selection tool after exiting to ensure the cursor gets updated
791 // and deselect previous selection from simulator to avoid any issue
792 // ( avoid crash in some cases when the SimTune tool is deselected )
794 selectionTool->ClearSelection();
796 } );
797
799
800 return 0;
801}
802
803
804// A singleton reference for clearing the highlight
806
807
808static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition )
809{
810 SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( aToolMgr->GetToolHolder() );
811 SCH_SELECTION_TOOL* selTool = aToolMgr->GetTool<SCH_SELECTION_TOOL>();
812 SCH_EDITOR_CONTROL* editorControl = aToolMgr->GetTool<SCH_EDITOR_CONTROL>();
813 SCH_CONNECTION* conn = nullptr;
814 SCH_ITEM* item = nullptr;
815 bool retVal = true;
816
817 if( aPosition != CLEAR )
818 {
819 ERC_TESTER erc( &editFrame->Schematic() );
820
821 if( erc.TestDuplicateSheetNames( false ) > 0 )
822 {
823 wxMessageBox( _( "Error: duplicate sub-sheet names found in current sheet." ) );
824 retVal = false;
825 }
826 else
827 {
828 item = static_cast<SCH_ITEM*>( selTool->GetNode( aPosition ) );
829 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
830
831 if( item )
832 {
833 if( item->IsConnectivityDirty() )
834 editFrame->RecalculateConnections( nullptr, NO_CLEANUP );
835
836 if( item->Type() == SCH_FIELD_T )
837 symbol = dynamic_cast<SCH_SYMBOL*>( item->GetParent() );
838
839 if( symbol && symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->IsPower() )
840 {
841 std::vector<SCH_PIN*> pins = symbol->GetPins();
842
843 if( pins.size() == 1 )
844 conn = pins[0]->Connection();
845 }
846 else
847 {
848 conn = item->Connection();
849 }
850 }
851 }
852 }
853
854 wxString connName = ( conn ) ? conn->Name() : wxString( wxS( "" ) );
855
856 if( !conn )
857 {
858 editFrame->SetStatusText( wxT( "" ) );
859 editFrame->SendCrossProbeClearHighlight();
860 editFrame->SetHighlightedConnection( wxEmptyString );
861 editorControl->SetHighlightBusMembers( false );
862 }
863 else
864 {
865 NET_NAVIGATOR_ITEM_DATA itemData( editFrame->GetCurrentSheet(), item );
866
867 if( connName != editFrame->GetHighlightedConnection() )
868 {
869 editorControl->SetHighlightBusMembers( false );
870 editFrame->SetCrossProbeConnection( conn );
871 editFrame->SetHighlightedConnection( connName, &itemData );
872 }
873 else
874 {
875 editorControl->SetHighlightBusMembers( !editorControl->GetHighlightBusMembers() );
876
877 if( item != editFrame->GetSelectedNetNavigatorItem() )
878 editFrame->SelectNetNavigatorItem( &itemData );
879 }
880 }
881
882 editFrame->UpdateNetHighlightStatus();
883
885 editorControl->UpdateNetHighlighting( dummy );
886
887 return retVal;
888}
889
890
892{
894 VECTOR2D cursorPos = controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
895
896 highlightNet( m_toolMgr, cursorPos );
897
898 return 0;
899}
900
901
903{
905
906 return 0;
907}
908
909
911{
913 SCHEMATIC& schematic = m_frame->Schematic();
915
916 const SCH_CONNECTION* conn = nullptr;
917 VECTOR2D connPos;
918
919 for( EDA_ITEM* item : selectionTool->GetSelection() )
920 {
921 conn = static_cast<SCH_ITEM*>( item )->Connection();
922 connPos = item->GetPosition();
923
924 if( conn )
925 break;
926 }
927
928 if( !conn )
929 {
930 m_frame->ShowInfoBarError( _( "No net selected." ) );
931 return 0;
932 }
933
934 // Remove selection in favor of highlighting so the whole net is highlighted
935 selectionTool->ClearSelection();
936 highlightNet( m_toolMgr, connPos );
937
938 wxString netName = conn->Name();
939
940 if( conn->IsBus() )
941 {
942 wxString prefix;
943
944 if( NET_SETTINGS::ParseBusVector( netName, &prefix, nullptr ) )
945 {
946 netName = prefix + wxT( "*" );
947 }
948 else if( NET_SETTINGS::ParseBusGroup( netName, &prefix, nullptr ) )
949 {
950 netName = prefix + wxT( ".*" );
951 }
952 }
953 else if( !conn->Driver() || CONNECTION_SUBGRAPH::GetDriverPriority( conn->Driver() )
955 {
956 m_frame->ShowInfoBarError( _( "Net must be labeled to assign a netclass." ) );
958 return 0;
959 }
960
961 DIALOG_ASSIGN_NETCLASS dlg( m_frame, netName, schematic.GetNetClassAssignmentCandidates(),
962 [&]( const std::vector<wxString>& aNetNames )
963 {
964 for( SCH_ITEM* item : screen->Items() )
965 {
966 bool redraw = item->IsBrightened();
967 SCH_CONNECTION* itemConn = item->Connection();
968
969 if( itemConn && alg::contains( aNetNames, itemConn->Name() ) )
970 item->SetBrightened();
971 else
972 item->ClearBrightened();
973
974 redraw |= item->IsBrightened();
975
976 if( item->Type() == SCH_SYMBOL_T )
977 {
978 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
979
980 redraw |= symbol->HasBrightenedPins();
981
982 symbol->ClearBrightenedPins();
983
984 for( SCH_PIN* pin : symbol->GetPins() )
985 {
986 SCH_CONNECTION* pin_conn = pin->Connection();
987
988 if( pin_conn && alg::contains( aNetNames, pin_conn->Name() ) )
989 {
990 pin->SetBrightened();
991 redraw = true;
992 }
993 }
994 }
995 else if( item->Type() == SCH_SHEET_T )
996 {
997 for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( item )->GetPins() )
998 {
999 SCH_CONNECTION* pin_conn = pin->Connection();
1000
1001 redraw |= pin->IsBrightened();
1002
1003 if( pin_conn && alg::contains( aNetNames, pin_conn->Name() ) )
1004 pin->SetBrightened();
1005 else
1006 pin->ClearBrightened();
1007
1008 redraw |= pin->IsBrightened();
1009 }
1010 }
1011
1012 if( redraw )
1013 getView()->Update( item, KIGFX::VIEW_UPDATE_FLAGS::REPAINT );
1014 }
1015
1017 } );
1018
1019 if( dlg.ShowModal() )
1020 {
1021 getView()->UpdateAllItemsConditionally(
1022 [&]( KIGFX::VIEW_ITEM* aItem ) -> int
1023 {
1024 int flags = 0;
1025
1026 auto invalidateTextVars =
1027 [&flags]( EDA_TEXT* text )
1028 {
1029 if( text->HasTextVars() )
1030 {
1031 text->ClearRenderCache();
1032 text->ClearBoundingBoxCache();
1034 }
1035 };
1036
1037 // Netclass coloured items
1038 //
1039 if( dynamic_cast<SCH_LINE*>( aItem ) )
1040 flags |= KIGFX::REPAINT;
1041 else if( dynamic_cast<SCH_JUNCTION*>( aItem ) )
1042 flags |= KIGFX::REPAINT;
1043 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( aItem ) )
1044 flags |= KIGFX::REPAINT;
1045
1046 // Items that might reference an item's netclass name
1047 //
1048 if( SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem ) )
1049 {
1050 item->RunOnChildren(
1051 [&invalidateTextVars]( SCH_ITEM* aChild )
1052 {
1053 if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aChild ) )
1054 invalidateTextVars( text );
1055 },
1057
1058 if( flags & KIGFX::GEOMETRY )
1059 m_frame->GetScreen()->Update( item, false ); // Refresh RTree
1060 }
1061
1062 if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem ) )
1063 invalidateTextVars( text );
1064
1065 return flags;
1066 } );
1067 }
1068
1069 highlightNet( m_toolMgr, CLEAR );
1070 return 0;
1071}
1072
1073
1075{
1076 wxCHECK( m_frame, 0 );
1077
1078 const SCH_SHEET_PATH& sheetPath = m_frame->GetCurrentSheet();
1080 CONNECTION_GRAPH* connectionGraph = m_frame->Schematic().ConnectionGraph();
1081 wxString selectedName = m_frame->GetHighlightedConnection();
1082
1083 std::set<wxString> connNames;
1084 std::vector<EDA_ITEM*> itemsToRedraw;
1085
1086 wxCHECK( screen && connectionGraph, 0 );
1087
1088 if( !selectedName.IsEmpty() )
1089 {
1090 connNames.emplace( selectedName );
1091
1092 if( CONNECTION_SUBGRAPH* sg =
1093 connectionGraph->FindSubgraphByName( selectedName, sheetPath ) )
1094 {
1096 {
1097 for( const SCH_ITEM* item : sg->GetItems() )
1098 {
1099 wxCHECK2( item, continue );
1100
1101 if( SCH_CONNECTION* connection = item->Connection() )
1102 {
1103 for( const std::shared_ptr<SCH_CONNECTION>& member :
1104 connection->AllMembers() )
1105 {
1106 if( member )
1107 connNames.emplace( member->Name() );
1108 }
1109 }
1110 }
1111 }
1112 }
1113
1114 // Place all bus names that are connected to the selected net in the set, regardless of
1115 // their sheet. This ensures that nets that are connected to a bus on a different sheet
1116 // get their buses highlighted as well.
1117 for( CONNECTION_SUBGRAPH* sg : connectionGraph->GetAllSubgraphs( selectedName ) )
1118 {
1119 for( const auto& [_, bus_sgs] : sg->GetBusParents() )
1120 {
1121 for( CONNECTION_SUBGRAPH* bus_sg : bus_sgs )
1122 {
1123 connNames.emplace( bus_sg->GetNetName() );
1124 }
1125 }
1126
1127 }
1128 }
1129
1130 for( SCH_ITEM* item : screen->Items() )
1131 {
1132 wxCHECK2( item, continue );
1133
1134 if( !item->IsConnectable() )
1135 continue;
1136
1137 SCH_ITEM* redrawItem = nullptr;
1138
1139 if( item->Type() == SCH_SYMBOL_T )
1140 {
1141 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1142
1143 for( SCH_PIN* pin : symbol->GetPins() )
1144 {
1145 if( SCH_CONNECTION* pin_conn = pin->Connection() )
1146 {
1147 if( !pin->IsBrightened() && connNames.count( pin_conn->Name() ) )
1148 {
1149 pin->SetBrightened();
1150 redrawItem = symbol;
1151 }
1152 else if( pin->IsBrightened() && !connNames.count( pin_conn->Name() ) )
1153 {
1154 pin->ClearBrightened();
1155 redrawItem = symbol;
1156 }
1157 }
1158 }
1159
1160 if( symbol->IsPower() && symbol->GetPins().size() )
1161 {
1162 if( SCH_CONNECTION* pinConn = symbol->GetPins()[0]->Connection() )
1163 {
1164 for( FIELD_T id : { FIELD_T::REFERENCE, FIELD_T::VALUE } )
1165 {
1166 SCH_FIELD* field = symbol->GetField( id );
1167
1168 if( !field->IsVisible() )
1169 continue;
1170
1171 if( !field->IsBrightened() && connNames.count( pinConn->Name() ) )
1172 {
1173 field->SetBrightened();
1174 redrawItem = symbol;
1175 }
1176 else if( field->IsBrightened() && !connNames.count( pinConn->Name() ) )
1177 {
1178 field->ClearBrightened();
1179 redrawItem = symbol;
1180 }
1181 }
1182 }
1183 }
1184 }
1185 else if( item->Type() == SCH_SHEET_T )
1186 {
1187 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
1188
1189 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
1190 {
1191 wxCHECK2( pin, continue );
1192
1193 if( SCH_CONNECTION* pin_conn = pin->Connection() )
1194 {
1195 if( !pin->IsBrightened() && connNames.count( pin_conn->Name() ) )
1196 {
1197 pin->SetBrightened();
1198 redrawItem = sheet;
1199 }
1200 else if( pin->IsBrightened() && !connNames.count( pin_conn->Name() ) )
1201 {
1202 pin->ClearBrightened();
1203 redrawItem = sheet;
1204 }
1205 }
1206 }
1207 }
1208 else
1209 {
1210 if( SCH_CONNECTION* itemConn = item->Connection() )
1211 {
1212 if( !item->IsBrightened() && connNames.count( itemConn->Name() ) )
1213 {
1214 item->SetBrightened();
1215 redrawItem = item;
1216 }
1217 else if( item->IsBrightened() && !connNames.count( itemConn->Name() ) )
1218 {
1219 item->ClearBrightened();
1220 redrawItem = item;
1221 }
1222 }
1223 }
1224
1225 if( redrawItem )
1226 itemsToRedraw.push_back( redrawItem );
1227 }
1228
1229 if( itemsToRedraw.size() )
1230 {
1231 // Be sure highlight change will be redrawn
1232 KIGFX::VIEW* view = getView();
1233
1234 for( EDA_ITEM* redrawItem : itemsToRedraw )
1236
1238 }
1239
1240 return 0;
1241}
1242
1243
1245{
1247
1248 // Deactivate other tools; particularly important if another PICKER is currently running
1249 Activate();
1250
1251 picker->SetCursor( KICURSOR::BULLSEYE );
1252 picker->SetSnapping( false );
1253
1254 picker->SetClickHandler(
1255 [this] ( const VECTOR2D& aPos )
1256 {
1257 return highlightNet( m_toolMgr, aPos );
1258 } );
1259
1261
1262 return 0;
1263}
1264
1265
1267{
1268 wxCHECK( m_frame, 0 );
1269
1270 if( m_frame->GetUndoCommandCount() <= 0 )
1271 return 0;
1272
1273 // Inform tools that undo command was issued
1275
1276 // Get the old list
1278
1279 wxCHECK( undo_list, 0 );
1280
1281 m_frame->PutDataInPreviousState( undo_list );
1282
1283 // Now push the old command to the RedoList
1284 undo_list->ReversePickersListOrder();
1285 m_frame->PushCommandToRedoList( undo_list );
1286
1287 m_toolMgr->GetTool<SCH_SELECTION_TOOL>()->RebuildSelection();
1288
1290 m_frame->OnModify();
1291
1292 return 0;
1293}
1294
1295
1297{
1298 wxCHECK( m_frame, 0 );
1299
1300 if( m_frame->GetRedoCommandCount() == 0 )
1301 return 0;
1302
1303 // Inform tools that undo command was issued
1305
1306 /* Get the old list */
1308
1309 wxCHECK( list, 0 );
1310
1311 /* Redo the command: */
1313
1314 /* Put the old list in UndoList */
1317
1318 m_toolMgr->GetTool<SCH_SELECTION_TOOL>()->RebuildSelection();
1319
1321 m_frame->OnModify();
1322
1323 return 0;
1324}
1325
1326
1327bool SCH_EDITOR_CONTROL::doCopy( bool aUseDuplicateClipboard )
1328{
1330 SCH_SELECTION& selection = selTool->RequestSelection();
1331 SCHEMATIC& schematic = m_frame->Schematic();
1332
1333 if( selection.Empty() )
1334 return false;
1335
1336 if( aUseDuplicateClipboard )
1337 m_duplicateIsHoverSelection = selection.IsHover();
1338
1339 selection.SetScreen( m_frame->GetScreen() );
1341
1342 for( EDA_ITEM* item : selection.GetItems() )
1343 {
1344 if( item->Type() == SCH_SHEET_T )
1345 {
1346 SCH_SHEET* sheet = (SCH_SHEET*) item;
1347 m_supplementaryClipboard[ sheet->GetFileName() ] = sheet->GetScreen();
1348 }
1349 else if( item->Type() == SCH_FIELD_T && selection.IsHover() )
1350 {
1351 // Most of the time the user is trying to duplicate the parent symbol
1352 // and the field text is in it
1353 selection.Add( item->GetParent() );
1354 }
1355 else if( item->Type() == SCH_MARKER_T )
1356 {
1357 // Don't let the markers be copied
1358 selection.Remove( item );
1359 }
1360 else if( item->Type() == SCH_GROUP_T )
1361 {
1362 // Groups need to have all their items selected
1363 static_cast<SCH_ITEM*>( item )->RunOnChildren(
1364 [&]( EDA_ITEM* aChild )
1365 {
1366 selection.Add( aChild );
1367 },
1368 RECURSE_MODE::RECURSE );
1369 }
1370 }
1371
1372 STRING_FORMATTER formatter;
1373 SCH_IO_KICAD_SEXPR plugin;
1375
1376 plugin.Format( &selection, &selPath, schematic, &formatter, true );
1377
1378 std::string prettyData = formatter.GetString();
1379 KICAD_FORMAT::Prettify( prettyData, true );
1380
1381 if( selection.IsHover() )
1383
1384 if( aUseDuplicateClipboard )
1385 {
1386 m_duplicateClipboard = prettyData;
1387 return true;
1388 }
1389
1390 return SaveClipboard( prettyData );
1391}
1392
1393
1394bool SCH_EDITOR_CONTROL::searchSupplementaryClipboard( const wxString& aSheetFilename,
1395 SCH_SCREEN** aScreen )
1396{
1397 if( m_supplementaryClipboard.count( aSheetFilename ) > 0 )
1398 {
1399 *aScreen = m_supplementaryClipboard[ aSheetFilename ];
1400 return true;
1401 }
1402
1403 return false;
1404}
1405
1406
1408{
1409 doCopy( true ); // Use the local clipboard
1410 Paste( aEvent );
1411
1412 return 0;
1413}
1414
1415
1417{
1418 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
1419
1420 if( textEntry )
1421 {
1422 textEntry->Cut();
1423 return 0;
1424 }
1425
1426 if( doCopy() )
1428
1429 return 0;
1430}
1431
1432
1434{
1435 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
1436
1437 if( textEntry )
1438 {
1439 textEntry->Copy();
1440 return 0;
1441 }
1442
1443 doCopy();
1444
1445 return 0;
1446}
1447
1448
1450{
1452 SCH_SELECTION& selection = selTool->RequestSelection();
1453
1454 if( selection.Empty() )
1455 return false;
1456
1457 wxString itemsAsText = GetSelectedItemsAsText( selection );
1458
1459 if( selection.IsHover() )
1461
1462 return SaveClipboard( itemsAsText.ToStdString() );
1463}
1464
1465
1467 const SCH_SHEET_PATH& aPastePath,
1468 const KIID_PATH& aClipPath,
1469 bool aForceKeepAnnotations )
1470{
1471 wxCHECK( m_frame && aSymbol, /* void */ );
1472
1473 SCH_SYMBOL_INSTANCE newInstance;
1474 bool instanceFound = false;
1475 KIID_PATH pasteLookupPath = aClipPath;
1476
1477 m_pastedSymbols.insert( aSymbol );
1478
1479 for( const SCH_SYMBOL_INSTANCE& tmp : aSymbol->GetInstances() )
1480 {
1481 if( ( tmp.m_Path.empty() && aClipPath.empty() )
1482 || ( !aClipPath.empty() && tmp.m_Path.EndsWith( aClipPath ) ) )
1483 {
1484 newInstance = tmp;
1485 instanceFound = true;
1486
1487 wxLogTrace( traceSchPaste,
1488 wxS( "Pasting found symbol instance with reference %s, unit %d:"
1489 "\n\tClipboard path: %s\n\tSymbol UUID: %s." ),
1490 tmp.m_Reference, tmp.m_Unit,
1491 aClipPath.AsString(), aSymbol->m_Uuid.AsString() );
1492
1493 break;
1494 }
1495 }
1496
1497 // The pasted symbol look up paths include the symbol UUID.
1498 pasteLookupPath.push_back( aSymbol->m_Uuid );
1499
1500 if( !instanceFound )
1501 {
1502 wxLogTrace( traceSchPaste,
1503 wxS( "Clipboard symbol instance **not** found:\n\tClipboard path: %s\n\t"
1504 "Symbol UUID: %s." ),
1505 aClipPath.AsString(), aSymbol->m_Uuid.AsString() );
1506
1507 // Some legacy versions saved value fields escaped. While we still do in the symbol
1508 // editor, we don't anymore in the schematic, so be sure to unescape them.
1509 SCH_FIELD* valueField = aSymbol->GetField( FIELD_T::VALUE );
1510 valueField->SetText( UnescapeString( valueField->GetText() ) );
1511
1512 // Pasted from notepad or an older instance of eeschema. Use the values in the fields
1513 // instead.
1514 newInstance.m_Reference = aSymbol->GetField( FIELD_T::REFERENCE )->GetText();
1515 newInstance.m_Unit = aSymbol->GetUnit();
1516 }
1517
1518 newInstance.m_Path = aPastePath.Path();
1519 newInstance.m_ProjectName = m_frame->Prj().GetProjectName();
1520
1521 aSymbol->AddHierarchicalReference( newInstance );
1522
1523 if( !aForceKeepAnnotations )
1524 aSymbol->ClearAnnotation( &aPastePath, false );
1525
1526 // We might clear annotations but always leave the original unit number from the paste.
1527 aSymbol->SetUnit( newInstance.m_Unit );
1528}
1529
1530
1532 const SCH_SHEET_PATH& aPastePath,
1533 const KIID_PATH& aClipPath,
1534 bool aForceKeepAnnotations,
1535 SCH_SHEET_LIST* aPastedSheets,
1536 std::map<SCH_SHEET_PATH,
1537 SCH_REFERENCE_LIST>& aPastedSymbols )
1538{
1539 wxCHECK( aSheet && aPastedSheets, aPastePath );
1540
1541 SCH_SHEET_PATH sheetPath = aPastePath;
1542 sheetPath.push_back( aSheet );
1543
1544 aPastedSheets->push_back( sheetPath );
1545
1546 if( aSheet->GetScreen() == nullptr )
1547 return sheetPath; // We can only really set the page number but not load any items
1548
1549 for( SCH_ITEM* item : aSheet->GetScreen()->Items() )
1550 {
1551 if( item->IsConnectable() )
1552 item->SetConnectivityDirty();
1553
1554 if( item->Type() == SCH_SYMBOL_T )
1555 {
1556 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1557
1558 wxCHECK2( symbol, continue );
1559
1560 // Only do this once if the symbol is shared across multiple sheets.
1561 if( !m_pastedSymbols.count( symbol ) )
1562 {
1563 for( SCH_PIN* pin : symbol->GetPins() )
1564 {
1565 const_cast<KIID&>( pin->m_Uuid ) = KIID();
1566 pin->SetConnectivityDirty();
1567 }
1568 }
1569
1570 updatePastedSymbol( symbol, sheetPath, aClipPath, aForceKeepAnnotations );
1571 }
1572 else if( item->Type() == SCH_SHEET_T )
1573 {
1574 SCH_SHEET* subsheet = static_cast<SCH_SHEET*>( item );
1575
1576 wxCHECK2( subsheet, continue );
1577
1578 // Make sure pins get a new UUID and set the dirty connectivity flag.
1579 if( !aPastedSheets->ContainsSheet( subsheet ) )
1580 {
1581 for( SCH_SHEET_PIN* pin : subsheet->GetPins() )
1582 {
1583 const_cast<KIID&>( pin->m_Uuid ) = KIID();
1584 pin->SetConnectivityDirty();
1585 }
1586 }
1587
1588 KIID_PATH newClipPath = aClipPath;
1589 newClipPath.push_back( subsheet->m_Uuid );
1590
1591 updatePastedSheet( subsheet, sheetPath, newClipPath, aForceKeepAnnotations,
1592 aPastedSheets, aPastedSymbols );
1593 }
1594 }
1595
1596 sheetPath.GetSymbols( aPastedSymbols[aPastePath] );
1597
1598 return sheetPath;
1599}
1600
1601
1603{
1604 wxCHECK( aScreen, /* void */ );
1605
1606 for( const SCH_ITEM* item : aScreen->Items() )
1607 {
1608 if( item->Type() == SCH_SYMBOL_T )
1609 {
1610 const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( item );
1611
1612 wxCHECK2( symbol, continue );
1613
1614 for( const SCH_SYMBOL_INSTANCE& symbolInstance : symbol->GetInstances() )
1615 {
1616 KIID_PATH pathWithSymbol = symbolInstance.m_Path;
1617
1618 pathWithSymbol.push_back( symbol->m_Uuid );
1619
1620 m_clipboardSymbolInstances[pathWithSymbol] = symbolInstance;
1621 }
1622 }
1623 }
1624}
1625
1626
1628{
1629 wxCHECK( m_frame, /* void */ );
1630
1631 for( SCH_SYMBOL* symbol : m_pastedSymbols )
1632 {
1633 wxCHECK2( symbol, continue );
1634
1635 std::vector<KIID_PATH> instancePathsToRemove;
1636
1637 for( const SCH_SYMBOL_INSTANCE& instance : symbol->GetInstances() )
1638 {
1639 if( ( instance.m_ProjectName != m_frame->Prj().GetProjectName() )
1640 || instance.m_Path.empty() )
1641 instancePathsToRemove.emplace_back( instance.m_Path );
1642 }
1643
1644 for( const KIID_PATH& path : instancePathsToRemove )
1645 symbol->RemoveInstance( path );
1646 }
1647}
1648
1649
1651{
1652 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
1653
1654 if( textEntry )
1655 {
1656 textEntry->Paste();
1657 return 0;
1658 }
1659
1661 std::string content;
1662 VECTOR2I eventPos;
1663
1664 SCH_SHEET tempSheet;
1665 SCH_SCREEN* tempScreen = new SCH_SCREEN( &m_frame->Schematic() );
1666 std::unique_ptr<wxImage> clipImg = GetImageFromClipboard();
1667
1668 if( !aEvent.IsAction( &ACTIONS::duplicate ) && clipImg )
1669 {
1670 // Just image data
1671 auto bitmap = std::make_unique<SCH_BITMAP>();
1672
1673 bool ok = bitmap->GetReferenceImage().SetImage( *clipImg );
1674
1675 if( !ok )
1676 {
1677 delete tempScreen;
1678 return 0;
1679 }
1680
1681 tempScreen->Append( bitmap.release() );
1682 }
1683 else
1684 {
1685 if( aEvent.IsAction( &ACTIONS::duplicate ) )
1686 content = m_duplicateClipboard;
1687 else
1688 content = GetClipboardUTF8();
1689
1690 if( content.empty() )
1691 {
1692 delete tempScreen;
1693 return 0;
1694 }
1695
1696 if( aEvent.IsAction( &ACTIONS::duplicate ) )
1697 eventPos = getViewControls()->GetCursorPosition( false );
1698
1699 STRING_LINE_READER reader( content, "Clipboard" );
1700 SCH_IO_KICAD_SEXPR plugin;
1701
1702 // Screen object on heap is owned by the sheet.
1703 tempSheet.SetScreen( tempScreen );
1704
1705 try
1706 {
1707 plugin.LoadContent( reader, &tempSheet );
1708 }
1709 catch( IO_ERROR& )
1710 {
1711 // If it wasn't content, then paste as a text object.
1712 SCH_TEXT* text_item = new SCH_TEXT( VECTOR2I( 0, 0 ), content );
1713 tempScreen->Append( text_item );
1714 }
1715 }
1716
1717 m_pastedSymbols.clear();
1719
1720 // Save pasted symbol instances in case the user chooses to keep existing symbol annotation.
1721 setPastedSymbolInstances( tempScreen );
1722
1723 tempScreen->MigrateSimModels();
1724
1726 int annotateStartNum = m_frame->Schematic().Settings().m_AnnotateStartNum;
1727
1728 PASTE_MODE pasteMode = annotate.automatic ? PASTE_MODE::RESPECT_OPTIONS : PASTE_MODE::REMOVE_ANNOTATIONS;
1729 bool forceRemoveAnnotations = false;
1730
1731 if( aEvent.IsAction( &ACTIONS::pasteSpecial ) )
1732 {
1733 PASTE_MODE pasteModeSpecial = pasteMode;
1734 DIALOG_PASTE_SPECIAL dlg( m_frame, &pasteModeSpecial );
1735
1736 if( dlg.ShowModal() == wxID_CANCEL )
1737 return 0;
1738
1739 // We have to distinguish if removing was explicit
1740 forceRemoveAnnotations = ( pasteModeSpecial == PASTE_MODE::REMOVE_ANNOTATIONS );
1741 pasteMode = pasteModeSpecial;
1742 }
1743
1744 bool forceKeepAnnotations = pasteMode != PASTE_MODE::REMOVE_ANNOTATIONS;
1745
1746 // SCH_SEXP_PLUGIN added the items to the paste screen, but not to the view or anything
1747 // else. Pull them back out to start with.
1748 SCH_COMMIT commit( m_toolMgr );
1749 EDA_ITEMS loadedItems;
1750 std::vector<SCH_ITEM*> sortedLoadedItems;
1751 bool sheetsPasted = false;
1752 SCH_SHEET_LIST hierarchy = m_frame->Schematic().Hierarchy();
1753 SCH_SHEET_PATH& pasteRoot = m_frame->GetCurrentSheet();
1754 wxFileName destFn = pasteRoot.Last()->GetFileName();
1755
1756 if( destFn.IsRelative() )
1757 destFn.MakeAbsolute( m_frame->Prj().GetProjectPath() );
1758
1759 // List of paths in the hierarchy that refer to the destination sheet of the paste
1760 SCH_SHEET_LIST sheetPathsForScreen = hierarchy.FindAllSheetsForScreen( pasteRoot.LastScreen() );
1761 sheetPathsForScreen.SortByPageNumbers();
1762
1763 // Build a list of screens from the current design (to avoid loading sheets that already exist)
1764 std::map<wxString, SCH_SCREEN*> loadedScreens;
1765
1766 for( const SCH_SHEET_PATH& item : hierarchy )
1767 {
1768 if( item.LastScreen() )
1769 loadedScreens[item.Last()->GetFileName()] = item.LastScreen();
1770 }
1771
1772 // Get set of sheet names in the current schematic to prevent duplicate sheet names on paste.
1773 std::set<wxString> existingSheetNames = pasteRoot.LastScreen()->GetSheetNames();
1774
1775 // Build symbol list for reannotation of duplicates
1776 SCH_REFERENCE_LIST existingRefs;
1777 hierarchy.GetSymbols( existingRefs );
1778 existingRefs.SortByReferenceOnly();
1779
1780 std::set<wxString> existingRefsSet;
1781
1782 for( const SCH_REFERENCE& ref : existingRefs )
1783 existingRefsSet.insert( ref.GetRef() );
1784
1785 // Build UUID map for fetching last-resolved-properties
1786 std::map<KIID, EDA_ITEM*> itemMap;
1787 hierarchy.FillItemMap( itemMap );
1788
1789 // Keep track of pasted sheets and symbols for the different paths to the hierarchy.
1790 std::map<SCH_SHEET_PATH, SCH_REFERENCE_LIST> pastedSymbols;
1791 std::map<SCH_SHEET_PATH, SCH_SHEET_LIST> pastedSheets;
1792
1793 for( SCH_ITEM* item : tempScreen->Items() )
1794 {
1795 if( item->Type() == SCH_SHEET_T )
1796 sortedLoadedItems.push_back( item );
1797 else
1798 loadedItems.push_back( item );
1799 }
1800
1801 sort( sortedLoadedItems.begin(), sortedLoadedItems.end(),
1802 []( SCH_ITEM* firstItem, SCH_ITEM* secondItem )
1803 {
1804 SCH_SHEET* firstSheet = static_cast<SCH_SHEET*>( firstItem );
1805 SCH_SHEET* secondSheet = static_cast<SCH_SHEET*>( secondItem );
1806 return StrNumCmp( firstSheet->GetName(), secondSheet->GetName(), false ) < 0;
1807 });
1808
1809
1810 for( SCH_ITEM* item : sortedLoadedItems )
1811 {
1812 loadedItems.push_back( item );
1813
1814 if( item->Type() == SCH_SHEET_T )
1815 {
1816 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
1817 SCH_FIELD* nameField = sheet->GetField( FIELD_T::SHEET_NAME );
1818 wxString baseName = nameField->GetText();
1819 wxFileName srcFn = sheet->GetFileName();
1820
1821 if( srcFn.IsRelative() )
1822 srcFn.MakeAbsolute( m_frame->Prj().GetProjectPath() );
1823
1824 SCH_SHEET_LIST sheetHierarchy( sheet );
1825
1826 if( hierarchy.TestForRecursion( sheetHierarchy, destFn.GetFullPath( wxPATH_UNIX ) ) )
1827 {
1828 auto msg = wxString::Format( _( "The pasted sheet '%s'\n"
1829 "was dropped because the destination already has "
1830 "the sheet or one of its subsheets as a parent." ),
1831 sheet->GetFileName() );
1832 DisplayError( m_frame, msg );
1833 loadedItems.pop_back();
1834 }
1835 }
1836 }
1837
1838 // Remove the references from our temporary screen to prevent freeing on the DTOR
1839 tempScreen->Clear( false );
1840
1841 for( EDA_ITEM* item : loadedItems )
1842 {
1843 KIID_PATH clipPath( wxT( "/" ) ); // clipboard is at root
1844
1845 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( item );
1846
1847 wxCHECK2( schItem, continue );
1848
1849 if( schItem->IsConnectable() )
1850 schItem->SetConnectivityDirty();
1851
1852 if( item->Type() == SCH_SYMBOL_T )
1853 {
1854 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1855
1856 // The library symbol gets set from the cached library symbols in the current
1857 // schematic not the symbol libraries. The cached library symbol may have
1858 // changed from the original library symbol which would cause the copy to
1859 // be incorrect.
1860 SCH_SCREEN* currentScreen = m_frame->GetScreen();
1861
1862 wxCHECK2( currentScreen, continue );
1863
1864 auto it = currentScreen->GetLibSymbols().find( symbol->GetSchSymbolLibraryName() );
1865 auto end = currentScreen->GetLibSymbols().end();
1866
1867 if( it == end )
1868 {
1869 // If can't find library definition in the design, use the pasted library
1870 it = tempScreen->GetLibSymbols().find( symbol->GetSchSymbolLibraryName() );
1871 end = tempScreen->GetLibSymbols().end();
1872 }
1873
1874 LIB_SYMBOL* libSymbol = nullptr;
1875
1876 if( it != end )
1877 {
1878 libSymbol = new LIB_SYMBOL( *it->second );
1879 symbol->SetLibSymbol( libSymbol );
1880 }
1881
1882 // If the symbol is already in the schematic we have to always keep the
1883 // annotations. The exception is if the user has chosen to remove them.
1884 for( const SCH_SYMBOL_INSTANCE& instance : symbol->GetInstances() )
1885 {
1886 if( !existingRefsSet.contains( instance.m_Reference ) )
1887 {
1888 forceKeepAnnotations = !forceRemoveAnnotations;
1889 break;
1890 }
1891 }
1892
1893 for( SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
1894 updatePastedSymbol( symbol, sheetPath, clipPath, forceKeepAnnotations );
1895
1896 // Most modes will need new KIIDs for the symbol and its pins
1897 // However, if we are pasting unique annotations, we need to check if the symbol
1898 // is not already in the hierarchy. If we don't already have a copy of the
1899 // symbol, we just keep the existing KIID data as it is likely the same symbol
1900 // being moved around the schematic
1901 bool needsNewKiid = ( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS );
1902
1903 for( const SCH_SYMBOL_INSTANCE& instance : symbol->GetInstances() )
1904 {
1905 if( existingRefsSet.contains( instance.m_Reference ) )
1906 {
1907 needsNewKiid = true;
1908 break;
1909 }
1910 }
1911
1912 if( needsNewKiid )
1913 {
1914 // Assign a new KIID
1915 const_cast<KIID&>( item->m_Uuid ) = KIID();
1916
1917 // Make sure pins get a new UUID
1918 for( SCH_PIN* pin : symbol->GetPins() )
1919 {
1920 const_cast<KIID&>( pin->m_Uuid ) = KIID();
1921 pin->SetConnectivityDirty();
1922 }
1923
1924 for( SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
1925 {
1926 // Ignore symbols from a non-existant library.
1927 if( libSymbol )
1928 {
1929 SCH_REFERENCE schReference( symbol, sheetPath );
1930 schReference.SetSheetNumber( sheetPath.GetVirtualPageNumber() );
1931 pastedSymbols[sheetPath].AddItem( schReference );
1932 }
1933 }
1934 }
1935 }
1936 else if( item->Type() == SCH_SHEET_T )
1937 {
1938 SCH_SHEET* sheet = (SCH_SHEET*) item;
1939 SCH_FIELD* nameField = sheet->GetField( FIELD_T::SHEET_NAME );
1940 wxString baseName = nameField->GetText();
1941 wxString candidateName = baseName;
1942 wxString number;
1943
1944 while( !baseName.IsEmpty() && wxIsdigit( baseName.Last() ) )
1945 {
1946 number = baseName.Last() + number;
1947 baseName.RemoveLast();
1948 }
1949
1950 // Update hierarchy to include any other sheets we already added, avoiding
1951 // duplicate sheet names
1952 hierarchy = m_frame->Schematic().Hierarchy();
1953
1954 int uniquifier = std::max( 0, wxAtoi( number ) ) + 1;
1955
1956 while( existingSheetNames.count( candidateName ) )
1957 candidateName = wxString::Format( wxT( "%s%d" ), baseName, uniquifier++ );
1958
1959 nameField->SetText( candidateName );
1960 existingSheetNames.emplace( candidateName );
1961
1962 wxFileName fn = sheet->GetFileName();
1963 SCH_SCREEN* existingScreen = nullptr;
1964
1965 sheet->SetParent( pasteRoot.Last() );
1966 sheet->SetScreen( nullptr );
1967
1968 if( !fn.IsAbsolute() )
1969 {
1970 wxFileName currentSheetFileName = pasteRoot.LastScreen()->GetFileName();
1971 fn.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS,
1972 currentSheetFileName.GetPath() );
1973 }
1974
1975 // Try to find the screen for the pasted sheet by several means
1976 if( !m_frame->Schematic().Root().SearchHierarchy( fn.GetFullPath( wxPATH_UNIX ),
1977 &existingScreen ) )
1978 {
1979 if( loadedScreens.count( sheet->GetFileName() ) > 0 )
1980 existingScreen = loadedScreens.at( sheet->GetFileName() );
1981 else
1982 searchSupplementaryClipboard( sheet->GetFileName(), &existingScreen );
1983 }
1984
1985 if( existingScreen )
1986 {
1987 sheet->SetScreen( existingScreen );
1988 }
1989 else
1990 {
1991 if( !m_frame->LoadSheetFromFile( sheet, &pasteRoot, fn.GetFullPath() ) )
1992 m_frame->InitSheet( sheet, sheet->GetFileName() );
1993 }
1994
1995 // Save the symbol instances in case the user chooses to keep the existing
1996 // symbol annotation.
1998 sheetsPasted = true;
1999
2000 // Push it to the clipboard path while it still has its old KIID
2001 clipPath.push_back( sheet->m_Uuid );
2002
2003 // Assign a new KIID to the pasted sheet
2004 const_cast<KIID&>( sheet->m_Uuid ) = KIID();
2005
2006 // Make sure pins get a new UUID
2007 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
2008 {
2009 const_cast<KIID&>( pin->m_Uuid ) = KIID();
2010 pin->SetConnectivityDirty();
2011 }
2012
2013 // Once we have our new KIID we can update all pasted instances. This will either
2014 // reset the annotations or copy "kept" annotations from the supplementary clipboard.
2015 for( SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
2016 {
2017 SCH_SHEET_PATH subPath = updatePastedSheet( sheet, sheetPath, clipPath,
2018 ( forceKeepAnnotations && annotate.automatic ),
2019 &pastedSheets[sheetPath],
2020 pastedSymbols );
2021 }
2022 }
2023 else
2024 {
2025 SCH_ITEM* srcItem = dynamic_cast<SCH_ITEM*>( itemMap[ item->m_Uuid ] );
2026 SCH_ITEM* destItem = dynamic_cast<SCH_ITEM*>( item );
2027
2028 // Everything gets a new KIID
2029 const_cast<KIID&>( item->m_Uuid ) = KIID();
2030
2031 if( srcItem && destItem )
2032 {
2033 destItem->SetConnectivityDirty( true );
2034 destItem->SetLastResolvedState( srcItem );
2035 }
2036 }
2037
2038 // Lines need both ends selected for a move after paste so the whole line moves.
2039 if( item->Type() == SCH_LINE_T )
2040 item->SetFlags( STARTPOINT | ENDPOINT );
2041
2042 item->SetFlags( IS_NEW | IS_PASTED | IS_MOVING );
2043
2044 if( !m_frame->GetScreen()->CheckIfOnDrawList( (SCH_ITEM*) item ) ) // don't want a loop!
2045 m_frame->AddToScreen( item, m_frame->GetScreen() );
2046
2047 commit.Added( (SCH_ITEM*) item, m_frame->GetScreen() );
2048
2049 // Start out hidden so the pasted items aren't "ghosted" in their original location
2050 // before being moved to the current location.
2051 getView()->Hide( item, true );
2052 }
2053
2054 if( sheetsPasted )
2055 {
2056 // The full schematic hierarchy need to be update before assigning new annotation and
2057 // page numbers.
2059
2060 // Update page numbers: Find next free numeric page number
2061 for( SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
2062 {
2063 for( SCH_SHEET_PATH& pastedSheet : pastedSheets[sheetPath] )
2064 {
2065 int page = 1;
2066 wxString pageNum = wxString::Format( "%d", page );
2067
2068 while( hierarchy.PageNumberExists( pageNum ) )
2069 pageNum = wxString::Format( "%d", ++page );
2070
2071 SCH_SHEET_INSTANCE sheetInstance;
2072
2073 sheetInstance.m_Path = pastedSheet.Path();
2074
2075 // Don't include the actual sheet in the instance path.
2076 sheetInstance.m_Path.pop_back();
2077 sheetInstance.m_PageNumber = pageNum;
2078 sheetInstance.m_ProjectName = m_frame->Prj().GetProjectName();
2079
2080 SCH_SHEET* sheet = pastedSheet.Last();
2081
2082 wxCHECK2( sheet, continue );
2083
2084 sheet->AddInstance( sheetInstance );
2085 hierarchy.push_back( pastedSheet );
2086
2087 // Remove all pasted sheet instance data that is not part of the current project.
2088 std::vector<KIID_PATH> instancesToRemove;
2089
2090 for( const SCH_SHEET_INSTANCE& instance : sheet->GetInstances() )
2091 {
2092 if( !hierarchy.HasPath( instance.m_Path ) )
2093 instancesToRemove.push_back( instance.m_Path );
2094 }
2095
2096 for( const KIID_PATH& instancePath : instancesToRemove )
2097 sheet->RemoveInstance( instancePath );
2098 }
2099 }
2100
2102
2103 // Get a version with correct sheet numbers since we've pasted sheets,
2104 // we'll need this when annotating next
2105 hierarchy = m_frame->Schematic().Hierarchy();
2106 }
2107
2108 std::map<SCH_SHEET_PATH, SCH_REFERENCE_LIST> annotatedSymbols;
2109
2110 // Update the list of symbol instances that satisfy the annotation criteria.
2111 for( const SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
2112 {
2113 for( size_t i = 0; i < pastedSymbols[sheetPath].GetCount(); i++ )
2114 {
2115 if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS
2116 || pasteMode == PASTE_MODE::RESPECT_OPTIONS
2117 || pastedSymbols[sheetPath][i].AlwaysAnnotate() )
2118 {
2119 annotatedSymbols[sheetPath].AddItem( pastedSymbols[sheetPath][i] );
2120 }
2121 }
2122
2123 for( const SCH_SHEET_PATH& pastedSheetPath : pastedSheets[sheetPath] )
2124 {
2125 for( size_t i = 0; i < pastedSymbols[pastedSheetPath].GetCount(); i++ )
2126 {
2127 if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS
2128 || pasteMode == PASTE_MODE::RESPECT_OPTIONS
2129 || pastedSymbols[pastedSheetPath][i].AlwaysAnnotate() )
2130 {
2131 annotatedSymbols[pastedSheetPath].AddItem( pastedSymbols[pastedSheetPath][i] );
2132 }
2133 }
2134 }
2135 }
2136
2137 if( !annotatedSymbols.empty() )
2138 {
2139 for( SCH_SHEET_PATH& path : sheetPathsForScreen )
2140 {
2141 annotatedSymbols[path].SortByReferenceOnly();
2142
2143 if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS )
2144 {
2145 annotatedSymbols[path].ReannotateDuplicates( existingRefs );
2146 }
2147 else
2148 {
2149 annotatedSymbols[path].ReannotateByOptions( (ANNOTATE_ORDER_T) annotate.sort_order,
2150 (ANNOTATE_ALGO_T) annotate.method,
2151 annotateStartNum, existingRefs, false,
2152 &hierarchy );
2153 }
2154
2155 annotatedSymbols[path].UpdateAnnotation();
2156
2157 // Update existing refs for next iteration
2158 for( size_t i = 0; i < annotatedSymbols[path].GetCount(); i++ )
2159 existingRefs.AddItem( annotatedSymbols[path][i] );
2160
2161 for( const SCH_SHEET_PATH& pastedSheetPath : pastedSheets[path] )
2162 {
2163 annotatedSymbols[pastedSheetPath].SortByReferenceOnly();
2164
2165 if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS )
2166 {
2167 annotatedSymbols[pastedSheetPath].ReannotateDuplicates( existingRefs );
2168 }
2169 else
2170 {
2171 annotatedSymbols[pastedSheetPath].ReannotateByOptions( (ANNOTATE_ORDER_T) annotate.sort_order,
2172 (ANNOTATE_ALGO_T) annotate.method,
2173 annotateStartNum, existingRefs,
2174 false,
2175 &hierarchy );
2176 }
2177
2178 annotatedSymbols[pastedSheetPath].UpdateAnnotation();
2179
2180 // Update existing refs for next iteration
2181 for( size_t i = 0; i < annotatedSymbols[pastedSheetPath].GetCount(); i++ )
2182 existingRefs.AddItem( annotatedSymbols[pastedSheetPath][i] );
2183 }
2184 }
2185 }
2186
2188
2189 // The copy operation creates instance paths that are not valid for the current project or
2190 // saved as part of another project. Prune them now so they do not accumulate in the saved
2191 // schematic file.
2193
2195 SCH_SCREENS allScreens( m_frame->Schematic().Root() );
2196
2197 allScreens.PruneOrphanedSymbolInstances( m_frame->Prj().GetProjectName(), sheets );
2198 allScreens.PruneOrphanedSheetInstances( m_frame->Prj().GetProjectName(), sheets );
2199
2200 // Now clear the previous selection, select the pasted items, and fire up the "move" tool.
2202
2203 // If the item has a parent group, it will be part of the loadedItems, and will handle
2204 // the move action. Iterate backwards to avoid invalidating the iterator.
2205 for( int i = loadedItems.size() - 1; i >= 0; i-- )
2206 {
2207 EDA_ITEM* item = loadedItems[i];
2208
2209 if( item->GetParentGroup() )
2210 {
2211 loadedItems.erase( loadedItems.begin() + i );
2212 // These were hidden before because they would be added to the move preview,
2213 // but now they need to be shown as a preview so they appear to move when
2214 // the group moves.
2215 getView()->SetVisible( item );
2216 getView()->AddToPreview( item, false );
2217 }
2218 }
2219
2221
2222 SCH_SELECTION& selection = selTool->GetSelection();
2223
2224 if( !selection.Empty() )
2225 {
2226 if( aEvent.IsAction( &ACTIONS::duplicate ) )
2227 {
2228 int closest_dist = INT_MAX;
2229
2230 auto processPt =
2231 [&]( const VECTOR2I& pt )
2232 {
2233 int dist = ( eventPos - pt ).EuclideanNorm();
2234
2235 if( dist < closest_dist )
2236 {
2237 selection.SetReferencePoint( pt );
2238 closest_dist = dist;
2239 }
2240 };
2241
2242 // Prefer connection points (which should remain on grid)
2243 for( EDA_ITEM* item : selection.Items() )
2244 {
2245 SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item );
2246 SCH_PIN* pin = dynamic_cast<SCH_PIN*>( item );
2247
2248 if( sch_item && sch_item->IsConnectable() )
2249 {
2250 for( const VECTOR2I& pt : sch_item->GetConnectionPoints() )
2251 processPt( pt );
2252 }
2253 else if( pin )
2254 {
2255 processPt( pin->GetPosition() );
2256 }
2257
2258 // Symbols need to have their center point added since often users are trying to
2259 // move parts from their center.
2260 if( dynamic_cast<SCH_SYMBOL*>( item ) )
2261 processPt( item->GetPosition() );
2262 }
2263
2264 // Only process other points if we didn't find any connection points
2265 if( closest_dist == INT_MAX )
2266 {
2267 for( EDA_ITEM* item : selection.Items() )
2268 {
2269 switch( item->Type() )
2270 {
2271 case SCH_LINE_T:
2272 processPt( static_cast<SCH_LINE*>( item )->GetStartPoint() );
2273 processPt( static_cast<SCH_LINE*>( item )->GetEndPoint() );
2274 break;
2275
2276 case SCH_SHAPE_T:
2277 {
2278 SCH_SHAPE* shape = static_cast<SCH_SHAPE*>( item );
2279
2280 switch( shape->GetShape() )
2281 {
2282 case SHAPE_T::RECTANGLE:
2283 for( const VECTOR2I& pt : shape->GetRectCorners() )
2284 processPt( pt );
2285
2286 break;
2287
2288 case SHAPE_T::CIRCLE:
2289 processPt( shape->GetCenter() );
2290 break;
2291
2292 case SHAPE_T::POLY:
2293 for( int ii = 0; ii < shape->GetPolyShape().TotalVertices(); ++ii )
2294 processPt( shape->GetPolyShape().CVertex( ii ) );
2295
2296 break;
2297
2298 default:
2299 processPt( shape->GetStart() );
2300 processPt( shape->GetEnd() );
2301 break;
2302 }
2303
2304 break;
2305 }
2306
2307 default:
2308 processPt( item->GetPosition() );
2309 break;
2310 }
2311 }
2312 }
2313
2314 selection.SetIsHover( m_duplicateIsHoverSelection );
2315 }
2316 else
2317 {
2318 SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.GetTopLeftItem() );
2319
2320 selection.SetReferencePoint( item->GetPosition() );
2321 }
2322
2324 {
2325 // Pushing the commit will update the connectivity.
2326 commit.Push( _( "Paste" ) );
2327
2328 if( sheetsPasted )
2330 // UpdateHierarchyNavigator() will call RefreshNetNavigator()
2331 else
2333 }
2334 else
2335 {
2336 commit.Revert();
2337 }
2338
2339 getView()->ClearPreview();
2340 }
2341
2342 return 0;
2343}
2344
2345
2347{
2349 SCH_SELECTION& selection = selTool->RequestSelection( { SCH_SYMBOL_T } );
2350 SCH_SYMBOL* symbol = nullptr;
2351 SYMBOL_EDIT_FRAME* symbolEditor;
2352
2353 if( selection.GetSize() >= 1 )
2354 symbol = (SCH_SYMBOL*) selection.Front();
2355
2356 if( selection.IsHover() )
2358
2359 if( !symbol )
2360 {
2361 // Giant hack: by default we assign Edit Table to the same hotkey, so give the table
2362 // tool a chance to handle it if we can't.
2364 tableTool->EditTable( aEvent );
2365
2366 return 0;
2367 }
2368
2369 if( symbol->GetEditFlags() != 0 )
2370 return 0;
2371
2372 if( symbol->IsMissingLibSymbol() )
2373 {
2374 m_frame->ShowInfoBarError( _( "Symbols with broken library symbol links cannot "
2375 "be edited." ) );
2376 return 0;
2377 }
2378
2380 symbolEditor = (SYMBOL_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
2381
2382 if( symbolEditor )
2383 {
2384 if( wxWindow* blocking_win = symbolEditor->Kiway().GetBlockingDialog() )
2385 blocking_win->Close( true );
2386
2387 if( aEvent.IsAction( &SCH_ACTIONS::editWithLibEdit ) )
2388 {
2389 symbolEditor->LoadSymbolFromSchematic( symbol );
2390 }
2392 {
2393 symbolEditor->LoadSymbol( symbol->GetLibId(), symbol->GetUnit(),
2394 symbol->GetBodyStyle() );
2395
2396 if( !symbolEditor->IsLibraryTreeShown() )
2397 symbolEditor->ToggleLibraryTree();
2398 }
2399 }
2400
2401 return 0;
2402}
2403
2404
2406{
2408 return 0;
2409}
2410
2411
2413{
2415
2416 dlg.SetInitialFocus( dlg.m_FirstRefDes );
2417
2418 if( dlg.ShowModal() == wxID_OK )
2419 {
2420 SCH_REFERENCE startRef;
2421 startRef.SetRef( dlg.m_FirstRefDes->GetValue() );
2422
2423 if( startRef.IsSplitNeeded() )
2424 startRef.Split();
2425 else
2426 return 0;
2427
2428 int startNum = atoi( startRef.GetRefNumber().utf8_string().c_str() );
2429
2430 SCH_COMMIT commit( m_frame );
2431 SCHEMATIC* schematic = m_frame->m_schematic;
2432 SCH_REFERENCE_LIST references;
2433
2434 if( dlg.m_AllSheets->GetValue() )
2435 schematic->Hierarchy().GetSymbols( references );
2436 else
2437 schematic->CurrentSheet().GetSymbols( references );
2438
2439 references.SplitReferences();
2440
2441 for( SCH_REFERENCE& ref : references )
2442 {
2443 if( ref.GetRef() == startRef.GetRef() )
2444 {
2445 int num = atoi( ref.GetRefNumber().utf8_string().c_str() );
2446
2447 if( num >= startNum )
2448 {
2449 const SCH_SHEET_PATH& sheet = ref.GetSheetPath();
2450 wxString fullRef = ref.GetRef();
2451
2452 num += dlg.m_Increment->GetValue();
2453 fullRef << num;
2454
2455 commit.Modify( ref.GetSymbol(), sheet.LastScreen() );
2456 ref.GetSymbol()->SetRef( &sheet, From_UTF8( fullRef.c_str() ) );
2457 }
2458 }
2459 }
2460
2461 if( !commit.Empty() )
2462 commit.Push( _( "Increment Annotations" ) );
2463 }
2464
2465 return 0;
2466}
2467
2468
2470{
2472 return 0;
2473}
2474
2475
2477{
2479
2480 wxCHECK( dlg, 0 );
2481
2482 // Needed at least on Windows. Raise() is not enough
2483 dlg->Show( true );
2484
2485 // Bring it to the top if already open. Dual monitor users need this.
2486 dlg->Raise();
2487
2488 dlg->ShowEditTab();
2489
2490 return 0;
2491}
2492
2493
2495{
2498
2499 return 0;
2500}
2501
2502
2504{
2506 return 0;
2507}
2508
2509
2511{
2513 return 0;
2514}
2515
2516
2518{
2520 dlg.ShowModal();
2521 return 0;
2522}
2523
2524
2526{
2527 int result = NET_PLUGIN_CHANGE;
2528
2529 // If a plugin is removed or added, rebuild and reopen the new dialog
2530 while( result == NET_PLUGIN_CHANGE )
2531 result = InvokeDialogNetList( m_frame );
2532
2533 return 0;
2534}
2535
2536
2538{
2540
2541 wxCHECK( dlg, 0 );
2542
2543 // Needed at least on Windows. Raise() is not enough
2544 dlg->Show( true );
2545
2546 // Bring it to the top if already open. Dual monitor users need this.
2547 dlg->Raise();
2548
2549 dlg->ShowExportTab();
2550
2551 return 0;
2552}
2553
2554
2556{
2558 return 0;
2559}
2560
2561
2563{
2566 return 0;
2567}
2568
2569
2571{
2572 getEditFrame<SCH_EDIT_FRAME>()->ToggleSearch();
2573 return 0;
2574}
2575
2576
2578{
2579 getEditFrame<SCH_EDIT_FRAME>()->ToggleSchematicHierarchy();
2580 return 0;
2581}
2582
2583
2585{
2586 getEditFrame<SCH_EDIT_FRAME>()->ToggleNetNavigator();
2587 return 0;
2588}
2589
2590
2592{
2593 getEditFrame<SCH_EDIT_FRAME>()->ToggleProperties();
2594 return 0;
2595}
2596
2597
2599{
2600 getEditFrame<SCH_EDIT_FRAME>()->ToggleLibraryTree();
2601 return 0;
2602}
2603
2604
2606{
2609
2612
2613 return 0;
2614}
2615
2616
2618{
2621
2624
2625 return 0;
2626}
2627
2628
2630{
2633
2636
2637 return 0;
2638}
2639
2640
2642{
2645
2648
2649 return 0;
2650}
2651
2652
2654{
2657
2660
2661 return 0;
2662}
2663
2664
2666{
2669
2671
2672 return 0;
2673}
2674
2675
2677{
2680
2682 [&]( KIGFX::VIEW_ITEM* aItem ) -> int
2683 {
2684 int flags = 0;
2685
2686 auto invalidateTextVars =
2687 [&flags]( EDA_TEXT* text )
2688 {
2689 if( text->HasTextVars() )
2690 {
2691 text->ClearRenderCache();
2692 text->ClearBoundingBoxCache();
2694 }
2695 };
2696
2697 if( SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem ) )
2698 {
2699 item->RunOnChildren(
2700 [&invalidateTextVars]( SCH_ITEM* aChild )
2701 {
2702 if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aChild ) )
2703 invalidateTextVars( text );
2704 },
2705 RECURSE_MODE::NO_RECURSE );
2706
2707 if( item->GetExcludedFromSim() )
2709 }
2710
2711 if( EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem ) )
2712 invalidateTextVars( text );
2713
2714 return flags;
2715 } );
2716
2718
2719 return 0;
2720}
2721
2722
2724{
2727
2731
2732 return 0;
2733}
2734
2735
2737{
2740
2744
2745 return 0;
2746}
2747
2748
2750{
2753
2755
2758
2759 return 0;
2760}
2761
2762
2764{
2767 return 0;
2768}
2769
2770
2772{
2774 m_frame->eeconfig()->m_Drawing.line_mode %= LINE_MODE::LINE_MODE_COUNT;
2776 return 0;
2777}
2778
2779
2781{
2784 return 0;
2785}
2786
2787
2789{
2792 return 0;
2793}
2794
2795
2797{
2798
2800 return 0;
2801}
2802
2803
2805{
2806#ifdef KICAD_IPC_API
2807 if( Pgm().GetCommonSettings()->m_Api.enable_server )
2808 Pgm().GetPluginManager().ReloadPlugins();
2809#endif
2810 return 0;
2811}
2812
2813
2815{
2816 int errors = 0;
2817 wxString details;
2818 bool quiet = aEvent.Parameter<bool>();
2819
2820 // Repair duplicate IDs.
2821 std::map<KIID, EDA_ITEM*> ids;
2822 int duplicates = 0;
2823
2825
2826 auto processItem =
2827 [&]( EDA_ITEM* aItem )
2828 {
2829 auto it = ids.find( aItem->m_Uuid );
2830
2831 if( it != ids.end() && it->second != aItem )
2832 {
2833 duplicates++;
2834 const_cast<KIID&>( aItem->m_Uuid ) = KIID();
2835 }
2836
2837 ids[ aItem->m_Uuid ] = aItem;
2838 };
2839
2840 // Symbol IDs are the most important, so give them the first crack at "claiming" a
2841 // particular KIID.
2842
2843 for( const SCH_SHEET_PATH& sheet : sheets )
2844 {
2845 SCH_SCREEN* screen = sheet.LastScreen();
2846
2847 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
2848 {
2849 processItem( item );
2850
2851 for( SCH_PIN* pin : static_cast<SCH_SYMBOL*>( item )->GetPins( &sheet ) )
2852 processItem( pin );
2853 }
2854 }
2855
2856 for( const SCH_SHEET_PATH& sheet : sheets )
2857 {
2858 SCH_SCREEN* screen = sheet.LastScreen();
2859
2860 for( SCH_ITEM* item : screen->Items() )
2861 {
2862 processItem( item );
2863
2864 item->RunOnChildren(
2865 [&]( SCH_ITEM* aChild )
2866 {
2867 processItem( item );
2868 },
2869 RECURSE_MODE::NO_RECURSE );
2870 }
2871 }
2872
2873 /*******************************
2874 * Your test here
2875 */
2876
2877 /*******************************
2878 * Inform the user
2879 */
2880
2881 if( duplicates )
2882 {
2883 errors += duplicates;
2884 details += wxString::Format( _( "%d duplicate IDs replaced.\n" ), duplicates );
2885
2886 // Rehash sheetpaths as we may have changed their uuids.
2888 }
2889
2890 if( errors )
2891 {
2892 m_frame->OnModify();
2893
2894 wxString msg = wxString::Format( _( "%d potential problems repaired." ), errors );
2895
2896 if( !quiet )
2897 DisplayInfoMessage( m_frame, msg, details );
2898 }
2899 else if( !quiet )
2900 {
2901 DisplayInfoMessage( m_frame, _( "No errors found." ) );
2902 }
2903
2904 return 0;
2905}
2906
2907
2909{
2910 if( !Pgm().GetCommonSettings()->m_Input.hotkey_feedback )
2911 return 0;
2912
2913 GRID_SETTINGS& gridSettings = m_toolMgr->GetSettings()->m_Window.grid;
2914 int currentIdx = m_toolMgr->GetSettings()->m_Window.grid.last_size_idx;
2915
2916 wxArrayString gridsLabels;
2917
2918 for( const GRID& grid : gridSettings.grids )
2919 gridsLabels.Add( grid.UserUnitsMessageText( m_frame ) );
2920
2921 if( !m_frame->GetHotkeyPopup() )
2923
2925
2926 if( popup )
2927 popup->Popup( _( "Grid" ), gridsLabels, currentIdx );
2928
2929 return 0;
2930}
2931
2932
2934{
2935 Go( &SCH_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() );
2936 Go( &SCH_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() );
2937 Go( &SCH_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
2944 Go( &SCH_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() );
2945 Go( &SCH_EDITOR_CONTROL::Quit, ACTIONS::quit.MakeEvent() );
2946
2949
2955
2958
2964
2966
2967 Go( &SCH_EDITOR_CONTROL::Undo, ACTIONS::undo.MakeEvent() );
2968 Go( &SCH_EDITOR_CONTROL::Redo, ACTIONS::redo.MakeEvent() );
2969 Go( &SCH_EDITOR_CONTROL::Cut, ACTIONS::cut.MakeEvent() );
2970 Go( &SCH_EDITOR_CONTROL::Copy, ACTIONS::copy.MakeEvent() );
2975
2977
2993
3000
3016
3018
3020
3023}
const char * name
Definition: DXF_plotter.cpp:59
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition: box2.h:990
static TOOL_ACTION updatePcbFromSchematic
Definition: actions.h:259
static TOOL_ACTION paste
Definition: actions.h:80
static TOOL_ACTION revert
Definition: actions.h:62
static TOOL_ACTION saveAs
Definition: actions.h:59
static TOOL_ACTION copy
Definition: actions.h:78
static TOOL_ACTION pluginsReload
Definition: actions.h:286
static TOOL_ACTION pickerTool
Definition: actions.h:248
static TOOL_ACTION showSymbolEditor
Definition: actions.h:255
static TOOL_ACTION pasteSpecial
Definition: actions.h:81
static TOOL_ACTION plot
Definition: actions.h:65
static TOOL_ACTION open
Definition: actions.h:57
static TOOL_ACTION pageSettings
Definition: actions.h:63
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:214
static TOOL_ACTION duplicate
Definition: actions.h:84
static TOOL_ACTION doDelete
Definition: actions.h:85
static TOOL_ACTION quit
Definition: actions.h:66
static TOOL_ACTION save
Definition: actions.h:58
static TOOL_ACTION redo
Definition: actions.h:76
static TOOL_ACTION updateSchematicFromPcb
Definition: actions.h:260
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: actions.h:220
static TOOL_ACTION print
Definition: actions.h:64
static TOOL_ACTION showProperties
Definition: actions.h:261
static TOOL_ACTION doNew
Definition: actions.h:54
static TOOL_ACTION cut
Definition: actions.h:77
static TOOL_ACTION copyAsText
Definition: actions.h:79
static TOOL_ACTION refreshPreview
Definition: actions.h:156
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition: actions.h:228
WINDOW_SETTINGS m_Window
Definition: app_settings.h:215
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
Definition: base_screen.h:85
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:82
int m_Threshold
Definition: collector.h:235
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Modify a given item in the model.
Definition: commit.h:108
COMMIT & Added(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been added.
Definition: commit.h:86
bool Empty() const
Definition: commit.h:150
Calculate the connectivity of a schematic and generates netlists.
CONNECTION_SUBGRAPH * FindSubgraphByName(const wxString &aNetName, const SCH_SHEET_PATH &aPath)
Return the subgraph for a given net name on a given sheet.
const std::vector< CONNECTION_SUBGRAPH * > & GetAllSubgraphs(const wxString &aNetName) const
A subgraph is a set of items that are electrically connected on a single sheet.
PRIORITY GetDriverPriority()
Class DIALOG_INCREMENT_ANNOTATIONS_BASE.
void SetWksFileName(const wxString &aFilename)
bool PrjConfigChanged()
Return true if the project configuration was modified.
bool Show(bool show) override
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:66
int ShowQuasiModal()
int ShowModal() override
virtual void PushCommandToUndoList(PICKED_ITEMS_LIST *aItem)
Add a command to undo in the undo list.
virtual int GetRedoCommandCount() const
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
virtual PICKED_ITEMS_LIST * PopCommandFromRedoList()
Return the last command to undo and remove it from list, nothing is deleted.
virtual PICKED_ITEMS_LIST * PopCommandFromUndoList()
Return the last command to undo and remove it from list, nothing is deleted.
virtual int GetUndoCommandCount() const
virtual void PushCommandToRedoList(PICKED_ITEMS_LIST *aItem)
Add a command to redo in the redo list.
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, WX_INFOBAR::MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
HOTKEY_CYCLE_POPUP * GetHotkeyPopup()
void ReleaseFile()
Release the current file marked in use.
void ScriptingConsoleEnableDisable()
Toggle the scripting console visibility.
bool LibraryFileBrowser(bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory=false, bool aIsGlobal=false, const wxString &aGlobalPath=wxEmptyString)
virtual void CreateHotkeyPopup()
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
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:96
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:255
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:144
const KIID m_Uuid
Definition: eda_item.h:501
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:108
EDA_GROUP * GetParentGroup() const
Definition: eda_item.h:114
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition: eda_item.h:187
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:111
void ClearBrightened()
Definition: eda_item.h:134
void SetBrightened()
Definition: eda_item.h:131
EDA_ITEM * GetParent() const
Definition: eda_item.h:110
bool IsBrightened() const
Definition: eda_item.h:125
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:337
SHAPE_T GetShape() const
Definition: eda_shape.h:168
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:215
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:173
std::vector< VECTOR2I > GetRectCorners() const
Definition: eda_shape.cpp:1585
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
virtual bool IsVisible() const
Definition: eda_text.h:185
PANEL_ANNOTATE m_AnnotatePanel
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:241
Definition: erc.h:52
static const TOOL_EVENT ClearedEvent
Definition: actions.h:339
static const TOOL_EVENT GridChangedByKeyEvent
Definition: actions.h:357
static const TOOL_EVENT SelectedEvent
Definition: actions.h:337
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:344
static const TOOL_EVENT PointSelectedEvent
Definition: actions.h:336
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:338
Similar to EDA_VIEW_SWITCHER, this dialog is a popup that shows feedback when using a hotkey to cycle...
void Popup(const wxString &aTitle, const wxArrayString &aItems, int aSelection)
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
An interface for classes handling user events controlling the view behavior such as zooming,...
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:86
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1673
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition: view.h:396
void ClearPreview()
Definition: view.cpp:1695
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition: view.cpp:1549
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
Definition: view.cpp:1621
void AddToPreview(VIEW_ITEM *aItem, bool aTakeOwnership=true)
Definition: view.cpp:1717
void MarkDirty()
Force redraw of view on the next rendering.
Definition: view.h:655
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:1559
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition: view.cpp:1600
bool EndsWith(const KIID_PATH &aPath) const
Test if aPath from the last path towards the first path.
Definition: kiid.cpp:335
wxString AsString() const
Definition: kiid.cpp:356
Definition: kiid.h:49
wxString AsString() const
Definition: kiid.cpp:246
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:55
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:65
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:406
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
Definition: kiway.cpp:670
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
Definition: lib_id.cpp:100
Define a library symbol object.
Definition: lib_symbol.h:85
const LIB_ID & GetLibId() const override
Definition: lib_symbol.h:155
wxString GetName() const override
Definition: lib_symbol.h:149
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Definition: lib_symbol.cpp:345
const wxString & GetNickName() const
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
void Save(const wxString &aFileName) const
Write this library table to aFileName in s-expression form.
static void ConvertToSpiceMarkup(wxString *aNetName)
Remove formatting wrappers and replace illegal spice net name characters with underscores.
Tree view item data for the net navigator.
static bool ParseBusGroup(const wxString &aGroup, wxString *name, std::vector< wxString > *aMemberList)
Parse a bus group label into the name and a list of components.
static bool ParseBusVector(const wxString &aBus, wxString *aName, std::vector< wxString > *aMemberList)
Parse a bus vector (e.g.
static wxString GetDefaultUserSymbolsPath()
Gets the default path we point users to create projects.
Definition: paths.cpp:88
A holder to handle information on schematic or board items.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
void SetDescription(const wxString &aDescription)
void ReversePickersListOrder()
Reverse the order of pickers stored in this list.
void SetMotionHandler(MOTION_HANDLER aHandler)
Set a handler for mouse motion.
Definition: picker_tool.h:84
void SetClickHandler(CLICK_HANDLER aHandler)
Set a handler for mouse click event.
Definition: picker_tool.h:73
void SetSnapping(bool aSnap)
Definition: picker_tool.h:66
void SetCursor(KICURSOR aCursor)
Definition: picker_tool.h:64
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Set a handler for the finalize event.
Definition: picker_tool.h:104
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:146
virtual const wxString GetProjectName() const
Return the short name of the project.
Definition: project.cpp:158
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition: project.cpp:164
static bool RescueProject(wxWindow *aParent, RESCUER &aRescuer, bool aRunningOnDemand)
size_t GetCandidateCount()
Return the number of rescue candidates found.
Holds all the data relating to one schematic.
Definition: schematic.h:69
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const
Definition: schematic.h:89
wxString GetFileName() const
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:300
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:306
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:208
EMBEDDED_FILES * GetEmbeddedFiles() override
Definition: schematic.cpp:871
CONNECTION_GRAPH * ConnectionGraph() const
Definition: schematic.h:158
SCH_SHEET & Root() const
Definition: schematic.h:117
SCH_SHEET_PATH & CurrentSheet() const
Definition: schematic.h:148
void RefreshHierarchy()
Definition: schematic.cpp:216
static TOOL_ACTION showPcbNew
Definition: sch_actions.h:172
static TOOL_ACTION assignFootprints
Definition: sch_actions.h:155
static TOOL_ACTION lineModeNext
Definition: sch_actions.h:266
static TOOL_ACTION toggleOPCurrents
Definition: sch_actions.h:242
static TOOL_ACTION clearHighlight
Definition: sch_actions.h:294
static TOOL_ACTION editSymbolFields
Definition: sch_actions.h:147
static TOOL_ACTION importFPAssignments
Definition: sch_actions.h:173
static TOOL_ACTION toggleAnnotateAuto
Definition: sch_actions.h:269
static TOOL_ACTION editLibSymbolWithLibEdit
Definition: sch_actions.h:171
static TOOL_ACTION toggleERCWarnings
Definition: sch_actions.h:237
static TOOL_ACTION schematicSetup
Definition: sch_actions.h:157
static TOOL_ACTION toggleDirectiveLabels
Definition: sch_actions.h:236
static TOOL_ACTION highlightNetTool
Definition: sch_actions.h:296
static TOOL_ACTION toggleHiddenFields
Definition: sch_actions.h:233
static TOOL_ACTION saveCurrSheetCopyAs
Definition: sch_actions.h:43
static TOOL_ACTION exportSymbolsToNewLibrary
Definition: sch_actions.h:180
static TOOL_ACTION repairSchematic
Definition: sch_actions.h:258
static TOOL_ACTION remapSymbols
Definition: sch_actions.h:164
static TOOL_ACTION lineMode45
Definition: sch_actions.h:265
static TOOL_ACTION editSymbolLibraryLinks
Definition: sch_actions.h:148
static TOOL_ACTION simTune
Definition: sch_actions.h:282
static TOOL_ACTION generateBOM
Definition: sch_actions.h:175
static TOOL_ACTION showHierarchy
Definition: sch_actions.h:224
static TOOL_ACTION showNetNavigator
Definition: sch_actions.h:297
static TOOL_ACTION markSimExclusions
Definition: sch_actions.h:240
static TOOL_ACTION editWithLibEdit
Definition: sch_actions.h:170
static TOOL_ACTION toggleERCErrors
Definition: sch_actions.h:238
static TOOL_ACTION incrementAnnotations
Definition: sch_actions.h:146
static TOOL_ACTION rescueSymbols
Definition: sch_actions.h:163
static TOOL_ACTION generateBOMLegacy
Definition: sch_actions.h:176
static TOOL_ACTION toggleOPVoltages
Definition: sch_actions.h:241
static TOOL_ACTION simProbe
Definition: sch_actions.h:281
static TOOL_ACTION lineMode90
Definition: sch_actions.h:264
static TOOL_ACTION lineModeFree
Definition: sch_actions.h:263
static TOOL_ACTION changeSheet
Definition: sch_actions.h:216
static TOOL_ACTION highlightNet
Definition: sch_actions.h:293
static TOOL_ACTION assignNetclass
Definition: sch_actions.h:156
static TOOL_ACTION annotate
Definition: sch_actions.h:145
static TOOL_ACTION showDesignBlockPanel
Definition: sch_actions.h:189
static TOOL_ACTION togglePinAltIcons
Definition: sch_actions.h:243
static TOOL_ACTION toggleERCExclusions
Definition: sch_actions.h:239
static TOOL_ACTION updateNetHighlighting
Definition: sch_actions.h:295
static TOOL_ACTION exportNetlist
Definition: sch_actions.h:174
static TOOL_ACTION drawSheetOnClipboard
Definition: sch_actions.h:253
static TOOL_ACTION exportSymbolsToLibrary
Definition: sch_actions.h:179
static TOOL_ACTION toggleHiddenPins
Definition: sch_actions.h:232
static TOOL_ACTION selectOnPCB
Definition: sch_actions.h:246
static TOOL_ACTION move
Definition: sch_actions.h:115
SCH_RENDER_SETTINGS * GetRenderSettings()
void AddToScreen(EDA_ITEM *aItem, SCH_SCREEN *aScreen=nullptr)
Add an item to the screen (and view) aScreen is the screen the item is located on,...
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
SYMBOL_LIB_TABLE * SelectSymLibTable(bool aOptional=false)
Display a dialog asking the user to select a symbol library table.
wxString SelectLibraryFromList()
Display a list of loaded libraries and allows the user to select a library.
void SyncView()
Mark all items for refresh.
EESCHEMA_SETTINGS * eeconfig() const
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:38
void Collect(SCH_SCREEN *aScreen, const std::vector< KICAD_T > &aScanTypes, const VECTOR2I &aPos, int aUnit=0, int aConvert=0)
Scan a EDA_ITEM using this class's Inspector method which does the collection.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Definition: sch_commit.cpp:487
virtual void Revert() override
Revert the commit by restoring the modified items state.
Definition: sch_commit.cpp:565
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
wxString Name(bool aIgnoreSheet=false) const
bool IsBus() const
SCH_ITEM * Driver() const
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
Handle actions specific to the schematic editor.
int PageSetup(const TOOL_EVENT &aEvent)
bool RescueLegacyProject(bool aRunningOnDemand)
int ToggleDirectiveLabels(const TOOL_EVENT &aEvent)
int SaveAs(const TOOL_EVENT &aEvent)
int MarkSimExclusions(const TOOL_EVENT &aEvent)
int Annotate(const TOOL_EVENT &aEvent)
int ToggleAnnotateRecursive(const TOOL_EVENT &aEvent)
int ShowSchematicSetup(const TOOL_EVENT &aEvent)
int HighlightNet(const TOOL_EVENT &aEvent)
Remove any net highlighting.
int ClearHighlight(const TOOL_EVENT &aEvent)
Update net highlighting after an edit.
int EditSymbolFields(const TOOL_EVENT &aEvent)
int GenerateBOMLegacy(const TOOL_EVENT &aEvent)
int HighlightNetCursor(const TOOL_EVENT &aEvent)
int CopyAsText(const TOOL_EVENT &aEvent)
int ImportFPAssignments(const TOOL_EVENT &aEvent)
int ChangeLineMode(const TOOL_EVENT &aEvent)
void doCrossProbeSchToPcb(const TOOL_EVENT &aEvent, bool aForce)
int ExportSymbolsToLibrary(const TOOL_EVENT &aEvent)
int SaveCurrSheetCopyAs(const TOOL_EVENT &aEvent)
Saves the currently-open schematic sheet to an other name.
bool rescueProject(RESCUER &aRescuer, bool aRunningOnDemand)
int CrossProbeToPcb(const TOOL_EVENT &aEvent)
Equivalent to the above, but initiated by the user.
int Quit(const TOOL_EVENT &aEvent)
int RemapSymbols(const TOOL_EVENT &aEvent)
int DrawSheetOnClipboard(const TOOL_EVENT &aEvent)
SCH_SHEET_PATH updatePastedSheet(SCH_SHEET *aSheet, const SCH_SHEET_PATH &aPastePath, const KIID_PATH &aClipPath, bool aForceKeepAnnotations, SCH_SHEET_LIST *aPastedSheets, std::map< SCH_SHEET_PATH, SCH_REFERENCE_LIST > &aPastedSymbols)
int TogglePinAltIcons(const TOOL_EVENT &aEvent)
int RescueSymbols(const TOOL_EVENT &aEvent)
Perform rescue operations to recover old projects from before certain changes were made.
int AssignNetclass(const TOOL_EVENT &aEvent)
std::string m_duplicateClipboard
int ExportNetlist(const TOOL_EVENT &aEvent)
int Open(const TOOL_EVENT &aEvent)
int Paste(const TOOL_EVENT &aEvent)
int ToggleOPVoltages(const TOOL_EVENT &aEvent)
int Copy(const TOOL_EVENT &aEvent)
int ToggleERCWarnings(const TOOL_EVENT &aEvent)
int NextLineMode(const TOOL_EVENT &aEvent)
int Redo(const TOOL_EVENT &aEvent)
Clipboard support.
int UpdatePCB(const TOOL_EVENT &aEvent)
int UpdateFromPCB(const TOOL_EVENT &aEvent)
int ToggleAnnotateAuto(const TOOL_EVENT &aEvent)
int ToggleHiddenPins(const TOOL_EVENT &aEvent)
int Duplicate(const TOOL_EVENT &aEvent)
int IncrementAnnotations(const TOOL_EVENT &aEvent)
bool searchSupplementaryClipboard(const wxString &aSheetFilename, SCH_SCREEN **aScreen)
int GridFeedback(const TOOL_EVENT &aEvent)
int ShowSearch(const TOOL_EVENT &aEvent)
int EditWithSymbolEditor(const TOOL_EVENT &aEvent)
int SimTune(const TOOL_EVENT &aEvent)
Highlight net under the cursor.
int EditSymbolLibraryLinks(const TOOL_EVENT &aEvent)
int New(const TOOL_EVENT &aEvent)
std::map< wxString, SCH_SCREEN * > m_supplementaryClipboard
int ExplicitCrossProbeToPcb(const TOOL_EVENT &aEvent)
int ToggleOPCurrents(const TOOL_EVENT &aEvent)
int ShowPcbNew(const TOOL_EVENT &aEvent)
int UpdateNetHighlighting(const TOOL_EVENT &aEvent)
Launch a tool to highlight nets.
int ToggleERCErrors(const TOOL_EVENT &aEvent)
int TogglePythonConsole(const TOOL_EVENT &aEvent)
int ShowHierarchy(const TOOL_EVENT &aEvent)
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int ShowNetNavigator(const TOOL_EVENT &aEvent)
int SimProbe(const TOOL_EVENT &aEvent)
void updatePastedSymbol(SCH_SYMBOL *aSymbol, const SCH_SHEET_PATH &aPastePath, const KIID_PATH &aClipPath, bool aForceKeepAnnotations)
int ShowCvpcb(const TOOL_EVENT &aEvent)
int ToggleLibraryTree(const TOOL_EVENT &aEvent)
int RepairSchematic(const TOOL_EVENT &aEvent)
std::set< SCH_SYMBOL * > m_pastedSymbols
void prunePastedSymbolInstances()
Remove all pasted symbol instances that do not belong to the current project.
int Cut(const TOOL_EVENT &aEvent)
int ToggleProperties(const TOOL_EVENT &aEvent)
std::map< KIID_PATH, SCH_SYMBOL_INSTANCE > m_clipboardSymbolInstances
int Save(const TOOL_EVENT &aEvent)
bool RescueSymbolLibTableProject(bool aRunningOnDemand)
Notifies pcbnew about the selected item.
bool doCopy(bool aUseDuplicateClipboard=false)
< copy selection to clipboard or to m_duplicateClipboard
int Undo(const TOOL_EVENT &aEvent)
int ToggleERCExclusions(const TOOL_EVENT &aEvent)
int Plot(const TOOL_EVENT &aEvent)
int Print(const TOOL_EVENT &aEvent)
int Revert(const TOOL_EVENT &aEvent)
int GenerateBOM(const TOOL_EVENT &aEvent)
int ReloadPlugins(const TOOL_EVENT &aEvent)
void setPastedSymbolInstances(const SCH_SCREEN *aScreen)
int ToggleHiddenFields(const TOOL_EVENT &aEvent)
Schematic editor (Eeschema) main window.
void ShowSchematicSetupDialog(const wxString &aInitialPage=wxEmptyString)
void RollbackSchematicFromUndo()
Perform an undo of the last edit without logging a corresponding redo.
bool IsSyncingSelection()
void RefreshOperatingPointDisplay()
Refresh the display of any operating points.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag and update other data struc...
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
Open a project or set of files given by aFileList.
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.
void InitSheet(SCH_SHEET *aSheet, const wxString &aNewFilename)
Definition: sheet.cpp:110
bool LoadSheetFromFile(SCH_SHEET *aSheet, SCH_SHEET_PATH *aCurrentSheet, const wxString &aFileName, bool aSkipRecursionCheck=false, bool aSkipLibCheck=false)
Load a the KiCad schematic file aFileName into the sheet aSheet.
Definition: sheet.cpp:169
void SendSelectItemsToPcb(const std::vector< EDA_ITEM * > &aItems, bool aForce)
Send items to board editor for selection.
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend, bool aDirtyConnectivity=true)
Create a copy of the current schematic item, and put it in the undo list.
void SendCrossProbeClearHighlight()
Tell Pcbnew to clear the existing highlighted net, if one exists.
void HardRedraw() override
Rebuild the GAL and redraw the screen.
SCHEMATIC * m_schematic
The currently loaded schematic.
SCH_SHEET_PATH & GetCurrentSheet() const
const SCH_ITEM * GetSelectedNetNavigatorItem() const
SCHEMATIC & Schematic() const
bool saveSchematicFile(SCH_SHEET *aSheet, const wxString &aSavePath)
Save aSheet to a schematic file.
void DrawCurrentSheetToClipboard()
Use the wxWidgets print code to draw an image of the current sheet onto the clipboard.
Definition: sheet.cpp:622
void RefreshNetNavigator(const NET_NAVIGATOR_ITEM_DATA *aSelection=nullptr)
void UpdateHierarchyNavigator(bool aRefreshNetNavigator=true, bool aClear=false)
Update the hierarchy navigation tree and history.
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
void RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags)
Generate the connection data for the entire schematic hierarchy.
void PutDataInPreviousState(PICKED_ITEMS_LIST *aList)
Restore an undo or redo command to put data pointed by aList in the previous state.
const wxString & GetHighlightedConnection() const
void UpdateNetHighlightStatus()
void SelectNetNavigatorItem(const NET_NAVIGATOR_ITEM_DATA *aSelection=nullptr)
DIALOG_SYMBOL_FIELDS_TABLE * GetSymbolFieldsTableDialog()
void SetCrossProbeConnection(const SCH_CONNECTION *aConnection)
Send a connection (net or bus) to Pcbnew for highlighting.
bool SaveProject(bool aSaveAs=false)
Save the currently-open schematic (including its hierarchy) and associated project.
void SetText(const wxString &aText) override
Definition: sch_field.cpp:1077
A SCH_IO derivation for loading schematic files using the new s-expression file format.
void LoadContent(LINE_READER &aReader, SCH_SHEET *aSheet, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
void Format(SCH_SHEET *aSheet)
static SCH_FILE_T EnumFromStr(const wxString &aFileType)
Return the #SCH_FILE_T from the corresponding plugin type name: "kicad", "legacy",...
Definition: sch_io_mgr.cpp:107
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:167
virtual bool IsConnectable() const
Definition: sch_item.h:461
const SYMBOL * GetParentSymbol() const
Definition: sch_item.cpp:193
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:177
virtual void SetLastResolvedState(const SCH_ITEM *aItem)
Definition: sch_item.h:553
int GetBodyStyle() const
Definition: sch_item.h:240
int GetUnit() const
Definition: sch_item.h:236
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:524
bool IsConnectivityDirty() const
Definition: sch_item.h:522
virtual void SetUnit(int aUnit)
Definition: sch_item.h:235
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:245
virtual std::vector< VECTOR2I > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
Definition: sch_item.h:476
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:41
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
void SortByReferenceOnly()
Sort the list of references by reference.
size_t GetCount() const
void SplitReferences()
Attempt to split all reference designators into a name (U) and number (1).
void AddItem(const SCH_REFERENCE &aItem)
A helper to define a symbol's reference designator in a schematic.
void SetRef(const wxString &aReference)
void Split()
Attempt to split the reference designator into a name (U) and number (1).
bool IsSplitNeeded()
Determine if this reference needs to be split or if it likely already has been.
wxString GetRef() const
void SetSheetNumber(int aSheetNumber)
wxString GetRefNumber() const
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:749
SCH_SCREEN * GetNext()
void UpdateSymbolLinks(REPORTER *aReporter=nullptr)
Initialize the LIB_SYMBOL reference for each SCH_SYMBOL found in the full schematic.
SCH_SCREEN * GetFirst()
void PruneOrphanedSheetInstances(const wxString &aProjectName, const SCH_SHEET_LIST &aValidSheetPaths)
void PruneOrphanedSymbolInstances(const wxString &aProjectName, const SCH_SHEET_LIST &aValidSheetPaths)
bool HasNoFullyDefinedLibIds()
Test all of the schematic symbols to see if all LIB_ID objects library nickname is not set.
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Definition: sch_screen.cpp:156
void Clear(bool aFree=true)
Delete all draw items and clears the project settings.
Definition: sch_screen.cpp:281
void UpdateSymbolLinks(REPORTER *aReporter=nullptr)
Initialize the LIB_SYMBOL reference for each SCH_SYMBOL found in this schematic from the project SYMB...
Definition: sch_screen.cpp:679
std::set< wxString > GetSheetNames() const
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:479
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition: sch_screen.h:112
const wxString & GetFileName() const
Definition: sch_screen.h:147
bool Remove(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:333
bool CheckIfOnDrawList(const SCH_ITEM *aItem) const
Definition: sch_screen.cpp:396
void MigrateSimModels()
Migrate any symbols having V6 simulation models to their V7 equivalents.
EDA_ITEM * GetNode(const VECTOR2I &aPosition)
Finds a connected item at a point (usually the cursor position).
bool SelectPoint(const VECTOR2I &aWhere, const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T }, EDA_ITEM **aItem=nullptr, bool *aSelectionCancelledFlag=nullptr, bool aCheckLocked=false, bool aAdd=false, bool aSubtract=false, bool aExclusiveOr=false)
Perform a click-type selection at a point (usually the cursor position).
int ClearSelection(const TOOL_EVENT &aEvent)
Select all visible items in sheet.
void GuessSelectionCandidates(SCH_COLLECTOR &collector, const VECTOR2I &aPos)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
SCH_SELECTION & GetSelection()
SCH_SELECTION & RequestSelection(const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T }, bool aPromoteCellSelections=false, bool aPromoteGroups=false)
Return either an existing selection (filtered), or the selection at the current cursor position if th...
VECTOR2I GetCenter() const
Definition: sch_shape.h:84
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void FillItemMap(std::map< KIID, EDA_ITEM * > &aMap)
Fill an item cache for temporary use when many items need to be fetched.
void SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sort the list of sheets by page number.
SCH_SHEET_LIST FindAllSheetsForScreen(const SCH_SCREEN *aScreen) const
Return a SCH_SHEET_LIST with a copy of all the SCH_SHEET_PATH using a particular screen.
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
bool PageNumberExists(const wxString &aPageNumber) const
bool ContainsSheet(const SCH_SHEET *aSheet) const
bool HasPath(const KIID_PATH &aPath) const
bool TestForRecursion(const SCH_SHEET_LIST &aSrcSheetHierarchy, const wxString &aDestFileName)
Test every SCH_SHEET_PATH in this SCH_SHEET_LIST to verify if adding the sheets stored in aSrcSheetHi...
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Adds SCH_REFERENCE object to aReferences for each symbol in the sheet.
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 push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:66
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:47
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:321
void RemoveInstance(const KIID_PATH &aInstancePath)
Definition: sch_sheet.cpp:1339
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
Definition: sch_sheet.cpp:369
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:753
void AddInstance(const SCH_SHEET_INSTANCE &aInstance)
Definition: sch_sheet.cpp:1360
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:116
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:137
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:187
const std::vector< SCH_SHEET_INSTANCE > & GetInstances() const
Definition: sch_sheet.h:429
Schematic symbol object.
Definition: sch_symbol.h:75
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstances() const
Definition: sch_symbol.h:134
wxString GetSchSymbolLibraryName() const
Definition: sch_symbol.cpp:242
void ClearAnnotation(const SCH_SHEET_PATH *aSheetPath, bool aResetPrefix)
Clear exiting symbol annotation.
void AddHierarchicalReference(const KIID_PATH &aPath, const wxString &aRef, int aUnit)
Add a full hierarchical reference to this symbol.
Definition: sch_symbol.cpp:511
bool IsMissingLibSymbol() const
Check to see if the library symbol is set to the dummy library symbol.
Definition: sch_symbol.cpp:209
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
const LIB_ID & GetLibId() const override
Definition: sch_symbol.h:164
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:183
void SetLibSymbol(LIB_SYMBOL *aLibSymbol)
Set this schematic symbol library symbol reference to aLibSymbol.
Definition: sch_symbol.cpp:251
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
Definition: sch_symbol.cpp:611
bool IsPower() const override
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:813
void BrightenItem(EDA_ITEM *aItem)
void UnbrightenItem(EDA_ITEM *aItem)
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.cpp:178
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Return the index-th vertex in a given hole outline within a given outline.
The SIMULATOR_FRAME holds the main user-interface for running simulations.
void AddCurrentTrace(const wxString &aDeviceName)
Add a current trace for a given device to the current plot.
void AddVoltageTrace(const wxString &aNetName)
Add a voltage trace for a given net to the current plot.
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
int FindModelPinIndex(const std::string &aSymbolPinNumber)
Definition: sim_model.cpp:654
const SPICE_GENERATOR & SpiceGenerator() const
Definition: sim_model.h:428
virtual std::vector< std::string > CurrentNames(const SPICE_ITEM &aItem) const
Implement an OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:449
const std::string & GetString()
Definition: richio.h:472
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:253
The symbol library editor main window.
bool IsLibraryTreeShown() const override
void LoadSymbol(const wxString &aLibrary, const wxString &aSymbol, int Unit)
void LoadSymbolFromSchematic(SCH_SYMBOL *aSymbol)
Load a symbol from the schematic to edit in place.
void ToggleLibraryTree() override
Class to handle modifications to the symbol libraries.
bool CreateLibrary(const wxString &aFilePath, SYMBOL_LIB_TABLE &aTable)
Create an empty library and adds it to the library table.
SYMBOL_LIB_TABLE_ROW * GetLibrary(const wxString &aLibrary) const
Find a single library within the (aggregate) library table.
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_IO object i...
const wxString GetType() const override
Return the type of symbol library table represented by this row.
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
static const wxString GetSymbolLibTableFileName()
static wxString GetGlobalTableFileName()
Fetch the global symbol library table file name.
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
Symbol library viewer main window.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:44
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:38
Generic, UI-independent tool event.
Definition: tool_event.h:168
bool DisableGridSnapping() const
Definition: tool_event.h:368
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:82
T Parameter() const
Return a parameter assigned to the event.
Definition: tool_event.h:465
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
void Activate()
Run the tool.
Master controller class:
Definition: tool_manager.h:62
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
TOOLS_HOLDER * GetToolHolder() const
Definition: tool_manager.h:406
APP_SETTINGS_BASE * GetSettings() const
Definition: tool_manager.h:404
bool PostAction(const std::string &aActionName, T aParam)
Run the specified action after the current action (coroutine) ends.
Definition: tool_manager.h:235
bool RunSynchronousAction(const TOOL_ACTION &aAction, COMMIT *aCommit, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:197
A wrapper for reporting to a wxString object.
Definition: reporter.h:190
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:96
const wxString & GetMessages() const
Definition: reporter.cpp:83
bool SaveClipboard(const std::string &aTextUTF8)
Store information to the system clipboard.
Definition: clipboard.cpp:31
std::string GetClipboardUTF8()
Return the information currently stored in the system clipboard.
Definition: clipboard.cpp:51
std::unique_ptr< wxImage > GetImageFromClipboard()
Get image data from the clipboard, if there is any.
Definition: clipboard.cpp:77
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:427
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:249
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:221
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:194
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:170
This file is part of the common library.
int InvokeDialogCreateBOM(SCH_EDIT_FRAME *aCaller)
Create and show DIALOG_BOM and return whatever DIALOG_BOM::ShowModal() returns.
Definition: dialog_bom.cpp:60
bool InvokeDialogEditSymbolsLibId(SCH_EDIT_FRAME *aCaller)
Run a dialog to modify the LIB_ID of symbols for instance when a symbol has moved from a symbol libra...
int InvokeDialogNetList(SCH_EDIT_FRAME *aCaller)
#define _(s)
@ NO_RECURSE
Definition: eda_item.h:51
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:551
#define IS_PASTED
Modifier on IS_NEW which indicates it came from clipboard.
#define IS_NEW
New item, just created.
#define ENDPOINT
ends. (Used to support dragging.)
#define IS_MOVING
Item being moved.
#define STARTPOINT
When a line is selected, these flags indicate which.
LINE_MODE
@ FRAME_SCH_SYMBOL_EDITOR
Definition: frame_type.h:35
@ FRAME_SCH_VIEWER
Definition: frame_type.h:36
@ FRAME_SIMULATOR
Definition: frame_type.h:38
static const std::string KiCadSchematicFileExtension
static const std::string KiCadSymbolLibFileExtension
static wxString KiCadSymbolLibFileWildcard()
static wxString KiCadSchematicFileWildcard()
static const wxChar traceSchPaste[]
Flag to enable schematic paste debugging output.
#define NET_PLUGIN_CHANGE
Create and shows DIALOG_EXPORT_NETLIST and returns whatever DIALOG_EXPORT_NETLIST::ShowModal() return...
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition: io_mgr.h:33
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:39
#define KICTL_REVERT
reverting to a previously-saved (KiCad) file.
Definition: kiway_player.h:78
@ LAYER_ERC_WARN
Definition: layer_ids.h:468
@ LAYER_ERC_ERR
Definition: layer_ids.h:469
@ LAYER_OP_CURRENTS
Definition: layer_ids.h:490
@ LAYER_OP_VOLTAGES
Definition: layer_ids.h:489
void Prettify(std::string &aSource, bool aCompactSave)
@ REPAINT
Item needs to be redrawn.
Definition: view_item.h:58
@ GEOMETRY
Position or shape has changed.
Definition: view_item.h:55
#define MAX_PAGE_SIZE_EESCHEMA_MILS
Definition: page_info.h:40
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:1071
see class PGM_BASE
@ LOCAL_CLEANUP
@ NO_CLEANUP
@ GLOBAL_CLEANUP
#define HITTEST_THRESHOLD_PIXELS
static bool highlightNet(TOOL_MANAGER *aToolMgr, const VECTOR2D &aPosition)
static VECTOR2D CLEAR
ANNOTATE_ORDER_T
Schematic annotation order options.
ANNOTATE_ALGO_T
Schematic annotation type options.
wxString GetSelectedItemsAsText(const SELECTION &aSel)
std::vector< FAB_LAYER_COLOR > dummy
wxString UnescapeString(const wxString &aSource)
wxString From_UTF8(const char *cstring)
std::vector< GRID > grids
Definition: grid_settings.h:66
Common grid settings, available to every frame.
Definition: grid_settings.h:34
A simple container for sheet instance information.
A simple container for schematic symbol instance information.
static constexpr auto NOT_CONNECTED
Definition: sim_model.h:73
std::string refName
GRID_SETTINGS grid
Definition: app_settings.h:81
Definition for symbol library class.
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
VECTOR2I end
@ AS_GLOBAL
Global action (toolbar/main menu event, global shortcut)
Definition: tool_action.h:49
@ TA_UNDO_REDO_PRE
This event is sent before undo/redo command is performed.
Definition: tool_event.h:106
@ TC_MESSAGE
Definition: tool_event.h:58
@ SCH_GROUP_T
Definition: typeinfo.h:173
@ SCH_LINE_T
Definition: typeinfo.h:163
@ SCH_SYMBOL_T
Definition: typeinfo.h:172
@ SCH_FIELD_T
Definition: typeinfo.h:150
@ SCH_SHEET_T
Definition: typeinfo.h:175
@ SCH_MARKER_T
Definition: typeinfo.h:158
@ SCH_SHAPE_T
Definition: typeinfo.h:149
@ SCH_PIN_T
Definition: typeinfo.h:153
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().
Definition: wx_filename.h:39