KiCad PCB EDA Suite
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 CERN
5 * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <symbol_library.h>
26#include <confirm.h>
27#include <connection_graph.h>
34#include <project_rescue.h>
35#include <erc.h>
36#include <fmt.h>
37#include <invoke_sch_dialog.h>
38#include <string_utils.h>
39#include <kiway.h>
40#include <kiway_player.h>
42#include <paths.h>
45#include <sch_edit_frame.h>
47#include <sch_line.h>
48#include <sch_painter.h>
49#include <sch_sheet.h>
50#include <sch_sheet_pin.h>
51#include <sch_view.h>
52#include <schematic.h>
53#include <advanced_config.h>
54#include <sim/sim_plot_frame.h>
55#include <sim/spice_generator.h>
57#include <symbol_viewer_frame.h>
58#include <status_popup.h>
59#include <tool/picker_tool.h>
60#include <tool/tool_manager.h>
61#include <tools/ee_actions.h>
62#include <tools/ee_selection.h>
67#include <eda_list_dialog.h>
69#include <wx_filename.h>
70#include <sch_sheet_path.h>
71#include <wx/filedlg.h>
72
73
75{
77 return 0;
78}
79
80
82{
84 return 0;
85}
86
87
89{
91 return 0;
92}
93
94
96{
97 m_frame->SaveProject( true );
98 return 0;
99}
100
101
103{
104 SCH_SHEET* curr_sheet = m_frame->GetCurrentSheet().Last();
105 wxFileName curr_fn = curr_sheet->GetFileName();
106 wxFileDialog dlg( m_frame, _( "Schematic Files" ), curr_fn.GetPath(),
107 curr_fn.GetFullName(), KiCadSchematicFileWildcard(),
108 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
109
110 if( dlg.ShowModal() == wxID_CANCEL )
111 return false;
112
113 wxFileName newFileName = dlg.GetPath();
114 newFileName.SetExt( KiCadSchematicFileExtension );
115
116 m_frame->saveSchematicFile( curr_sheet, newFileName.GetFullPath() );
117 return 0;
118}
119
120
122{
123 SCHEMATIC& schematic = m_frame->Schematic();
124 SCH_SHEET& root = schematic.Root();
125
126 if( m_frame->GetCurrentSheet().Last() != &root )
127 {
130
131 // Store the current zoom level into the current screen before switching
133
134 SCH_SHEET_PATH rootSheetPath;
135 rootSheetPath.push_back( &root );
136 m_frame->SetCurrentSheet( rootSheetPath );
138
139 wxSafeYield();
140 }
141
142 wxString msg;
143 msg.Printf( _( "Revert '%s' (and all sub-sheets) to last version saved?" ),
144 schematic.GetFileName() );
145
146 if( !IsOK( m_frame, msg ) )
147 return false;
148
149 SCH_SCREENS screenList( schematic.Root() );
150
151 for( SCH_SCREEN* screen = screenList.GetFirst(); screen; screen = screenList.GetNext() )
152 screen->SetContentModified( false ); // do not prompt the user for changes
153
155 m_frame->OpenProjectFiles( std::vector<wxString>( 1, schematic.GetFileName() ) );
156
157 return 0;
158}
159
160
162{
164 return 0;
165}
166
167
169{
170 PICKED_ITEMS_LIST undoCmd;
172 ITEM_PICKER wrapper( m_frame->GetScreen(), undoItem, UNDO_REDO::PAGESETTINGS );
173
174 undoCmd.PushItem( wrapper );
175 m_frame->SaveCopyInUndoList( undoCmd, UNDO_REDO::PAGESETTINGS, false, false );
176
180
181 if( dlg.ShowModal() )
182 {
183 // Update text variables
187
188 m_frame->OnModify();
189 }
190 else
191 {
193 }
194
195 return 0;
196}
197
198
200{
201 SCH_SCREENS schematic( m_frame->Schematic().Root() );
202
203 if( schematic.HasNoFullyDefinedLibIds() )
204 RescueLegacyProject( true );
205 else
207
208 return 0;
209}
210
211
212bool SCH_EDITOR_CONTROL::RescueLegacyProject( bool aRunningOnDemand )
213{
216
217 return rescueProject( rescuer, aRunningOnDemand );
218}
219
220
222{
226
227 return rescueProject( rescuer, aRunningOnDemand );
228}
229
230
231bool SCH_EDITOR_CONTROL::rescueProject( RESCUER& aRescuer, bool aRunningOnDemand )
232{
233 if( !RESCUER::RescueProject( m_frame, aRescuer, aRunningOnDemand ) )
234 return false;
235
236 if( aRescuer.GetCandidateCount() )
237 {
238 KIWAY_PLAYER* viewer = m_frame->Kiway().Player( FRAME_SCH_VIEWER, false );
239
240 if( viewer )
241 static_cast<SYMBOL_VIEWER_FRAME*>( viewer )->ReCreateLibList();
242
243 if( aRunningOnDemand )
244 {
245 SCH_SCREENS schematic( m_frame->Schematic().Root() );
246
247 schematic.UpdateSymbolLinks();
249 }
250
252 m_frame->SyncView();
254 m_frame->OnModify();
255 }
256
257 return true;
258}
259
260
262{
263 DIALOG_SYMBOL_REMAP dlgRemap( m_frame );
264
265 dlgRemap.ShowQuasiModal();
266
267 m_frame->GetCanvas()->Refresh( true );
268
269 return 0;
270}
271
272
274{
275 if( !ADVANCED_CFG::GetCfg().m_RealTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
277
279
280 wxFileName fn = m_frame->Prj().AbsolutePath( m_frame->Schematic().RootScreen()->GetFileName() );
281
282 if( fn.GetName() != NAMELESS_PROJECT )
284
285 return 0;
286}
287
288
290{
291 if( !ADVANCED_CFG::GetCfg().m_RealTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
293
295
296 dlg.ShowModal();
297
298 // save project config if the prj config has changed:
299 if( dlg.PrjConfigChanged() )
301
302 return 0;
303}
304
305
307{
308 m_frame->Close( false );
309 return 0;
310}
311
312
313// A dummy wxFindReplaceData signaling any marker should be found
315
316
318{
320 return UpdateFind( aEvent );
321}
322
323
325{
327
328 auto visit =
329 [&]( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheet )
330 {
331 // We may get triggered when the dialog is not opened due to binding
332 // SelectedItemsModified we also get triggered when the find dialog is
333 // closed....so we need to double check the dialog is open.
334 if( m_frame->m_findReplaceDialog != nullptr
335 && !data.findString.IsEmpty()
336 && aItem->Matches( data, aSheet ) )
337 {
338 aItem->SetForceVisible( true );
340 }
341 else if( aItem->IsBrightened() )
342 {
343 aItem->SetForceVisible( false );
345 }
346 };
347
348 if( aEvent.IsAction( &ACTIONS::find ) || aEvent.IsAction( &ACTIONS::findAndReplace )
349 || aEvent.IsAction( &ACTIONS::updateFind ) )
350 {
352
353 for( SCH_ITEM* item : m_frame->GetScreen()->Items() )
354 {
355 visit( item, &m_frame->GetCurrentSheet() );
356
357 item->RunOnChildren(
358 [&]( SCH_ITEM* aChild )
359 {
360 visit( aChild, &m_frame->GetCurrentSheet() );
361 } );
362 }
363 }
364 else if( aEvent.Matches( EVENTS::SelectedItemsModified ) )
365 {
366 for( EDA_ITEM* item : m_selectionTool->GetSelection() )
367 visit( item, &m_frame->GetCurrentSheet() );
368 }
369
370 getView()->UpdateItems();
373
374 return 0;
375}
376
377
379 SCH_ITEM* aAfter, EDA_SEARCH_DATA& aData )
380{
381 bool past_item = true;
382
383 if( aAfter != nullptr )
384 {
385 past_item = false;
386
387 if( aAfter->Type() == SCH_PIN_T || aAfter->Type() == SCH_FIELD_T )
388 aAfter = static_cast<SCH_ITEM*>( aAfter->GetParent() );
389 }
390
391 std::vector<SCH_ITEM*> sorted_items;
392
393 for( SCH_ITEM* item : aScreen->Items() )
394 sorted_items.push_back( item );
395
396 std::sort( sorted_items.begin(), sorted_items.end(),
397 [&]( SCH_ITEM* a, SCH_ITEM* b )
398 {
399 if( a->GetPosition().x == b->GetPosition().x )
400 {
401 // Ensure deterministic sort
402 if( a->GetPosition().y == b->GetPosition().y )
403 return a->m_Uuid < b->m_Uuid;
404
405 return a->GetPosition().y < b->GetPosition().y;
406 }
407 else
408 return a->GetPosition().x < b->GetPosition().x;
409 }
410 );
411
412 for( SCH_ITEM* item : sorted_items )
413 {
414 if( item == aAfter )
415 {
416 past_item = true;
417 }
418 else if( past_item )
419 {
420 if( &aData == &g_markersOnly && item->Type() == SCH_MARKER_T )
421 return item;
422
423 if( item->Matches( aData, aSheet ) )
424 return item;
425
426 if( item->Type() == SCH_SYMBOL_T )
427 {
428 SCH_SYMBOL* cmp = static_cast<SCH_SYMBOL*>( item );
429
430 for( SCH_FIELD& field : cmp->GetFields() )
431 {
432 if( field.Matches( aData, aSheet ) )
433 return &field;
434 }
435
436 for( SCH_PIN* pin : cmp->GetPins() )
437 {
438 if( pin->Matches( aData, aSheet ) )
439 return pin;
440 }
441 }
442
443 if( item->Type() == SCH_SHEET_T )
444 {
445 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
446
447 for( SCH_FIELD& field : sheet->GetFields() )
448 {
449 if( field.Matches( aData, aSheet ) )
450 return &field;
451 }
452
453 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
454 {
455 if( pin->Matches( aData, aSheet ) )
456 return pin;
457 }
458 }
459 }
460 }
461
462 return nullptr;
463}
464
465
467{
469 bool searchAllSheets = false;
470 try
471 {
472 const SCH_SEARCH_DATA& schSearchData = dynamic_cast<const SCH_SEARCH_DATA&>( data );
473 searchAllSheets = !( schSearchData.searchCurrentSheetOnly );
474 }
475 catch( const std::bad_cast& )
476 {
477 }
478
479 // A timer during which a subsequent FindNext will result in a wrap-around
480 static wxTimer wrapAroundTimer;
481
482 if( aEvent.IsAction( &ACTIONS::findNextMarker ) )
483 {
484 // g_markersOnly.SetFlags( data.GetFlags() );
485
486 // data = g_markersOnly;
487 }
488 else if( data.findString.IsEmpty() )
489 {
490 return FindAndReplace( ACTIONS::find.MakeEvent() );
491 }
492
494 SCH_ITEM* afterItem = dynamic_cast<SCH_ITEM*>( selection.Front() );
495 SCH_ITEM* item = nullptr;
496
497 SCH_SHEET_PATH* afterSheet = &m_frame->GetCurrentSheet();
498
499 if( wrapAroundTimer.IsRunning() )
500 {
501 afterSheet = nullptr;
502 afterItem = nullptr;
503 wrapAroundTimer.Stop();
505 }
506
508
509 if( afterSheet || !searchAllSheets )
510 item = nextMatch( m_frame->GetScreen(), &m_frame->GetCurrentSheet(), afterItem, data );
511
512 if( !item && searchAllSheets )
513 {
514 SCH_SCREENS screens( m_frame->Schematic().Root() );
515 std::vector<SCH_SHEET_PATH*> paths;
516
517 screens.BuildClientSheetPathList();
518
519 for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
520 {
521 for( SCH_SHEET_PATH& sheet : screen->GetClientSheetPaths() )
522 paths.push_back( &sheet );
523 }
524
525 std::sort( paths.begin(), paths.end(), [] ( const SCH_SHEET_PATH* lhs,
526 const SCH_SHEET_PATH* rhs ) -> bool
527 {
528 int retval = lhs->ComparePageNum( *rhs );
529
530 if( retval < 0 )
531 return true;
532 else if( retval > 0 )
533 return false;
534 else
535 return lhs->GetCurrentHash() < rhs->GetCurrentHash();
536 } );
537
538 for( SCH_SHEET_PATH* sheet : paths )
539 {
540 if( afterSheet )
541 {
542 if( afterSheet->GetPageNumber() == sheet->GetPageNumber() )
543 afterSheet = nullptr;
544
545 continue;
546 }
547
548 item = nextMatch( sheet->LastScreen(), sheet, nullptr, data );
549
550 if( item )
551 {
552 m_frame->Schematic().SetCurrentSheet( *sheet );
554 UpdateFind( ACTIONS::updateFind.MakeEvent() );
555
556 break;
557 }
558 }
559 }
560
561 if( item )
562 {
566 }
567 else
568 {
569 wxString msg = searchAllSheets ? _( "Reached end of schematic." )
570 : _( "Reached end of sheet." );
571
572 // Show the popup during the time period the user can wrap the search
573 m_frame->ShowFindReplaceStatus( msg + wxS( " " ) +
574 _( "Find again to wrap around to the start." ), 4000 );
575 wrapAroundTimer.StartOnce( 4000 );
576 }
577
578 return 0;
579}
580
581
583{
586
587 return item && item->Matches( data, &m_frame->GetCurrentSheet() );
588}
589
590
592{
596
597 if( data.findString.IsEmpty() )
598 return FindAndReplace( ACTIONS::find.MakeEvent() );
599
600 if( item && item->Matches( data, sheet ) )
601 {
602 SCH_ITEM* sch_item = static_cast<SCH_ITEM*>( item );
603
604 m_frame->SaveCopyInUndoList( sheet->LastScreen(), sch_item, UNDO_REDO::CHANGED, false );
605
606 if( item->Replace( data, sheet ) )
607 {
608 m_frame->UpdateItem( item, false, true );
610 m_frame->OnModify();
611 }
612
613 FindNext( ACTIONS::findNext.MakeEvent() );
614 }
615
616 return 0;
617}
618
619
621{
623 bool currentSheetOnly = false;
624
625 try
626 {
627 const SCH_SEARCH_DATA& schSearchData = dynamic_cast<const SCH_SEARCH_DATA&>( data );
628 currentSheetOnly = schSearchData.searchCurrentSheetOnly;
629 }
630 catch( const std::bad_cast& )
631 {
632 }
633
634 bool modified = false;
635
636 if( data.findString.IsEmpty() )
637 return FindAndReplace( ACTIONS::find.MakeEvent() );
638
639 auto doReplace =
640 [&]( SCH_ITEM* aItem, SCH_SHEET_PATH* aSheet, EDA_SEARCH_DATA& aData )
641 {
642 m_frame->SaveCopyInUndoList( aSheet->LastScreen(), aItem, UNDO_REDO::CHANGED,
643 modified );
644
645 if( aItem->Replace( aData, aSheet ) )
646 {
647 m_frame->UpdateItem( aItem, false, true );
648 modified = true;
649 }
650 };
651
652 if( currentSheetOnly )
653 {
654 SCH_SHEET_PATH* currentSheet = &m_frame->GetCurrentSheet();
655
656 SCH_ITEM* item = nextMatch( m_frame->GetScreen(), currentSheet, nullptr, data );
657
658 while( item )
659 {
660 doReplace( item, currentSheet, data );
661 item = nextMatch( m_frame->GetScreen(), currentSheet, item, data );
662 }
663 }
664 else
665 {
666 SCH_SHEET_LIST allSheets = m_frame->Schematic().GetSheets();
667 SCH_SCREENS screens( m_frame->Schematic().Root() );
668
669 for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
670 {
671 SCH_SHEET_LIST sheets = allSheets.FindAllSheetsForScreen( screen );
672
673 for( unsigned ii = 0; ii < sheets.size(); ++ii )
674 {
675 SCH_ITEM* item = nextMatch( screen, &sheets[ii], nullptr, data );
676
677 while( item )
678 {
679 if( ii == 0 )
680 {
681 doReplace( item, &sheets[0], data );
682 }
683 else if( item->Type() == SCH_FIELD_T )
684 {
685 SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
686
687 if( field->GetParent() && field->GetParent()->Type() == SCH_SYMBOL_T )
688 {
689 switch( field->GetId() )
690 {
691 case REFERENCE_FIELD:
692 case VALUE_FIELD:
693 case FOOTPRINT_FIELD:
694 // must be handled for each distinct sheet
695 doReplace( field, &sheets[ii], data );
696 break;
697
698 default:
699 // handled in first iteration
700 break;
701 }
702 }
703 }
704
705 item = nextMatch( screen, &sheets[ii], item, data );
706 }
707 }
708 }
709 }
710
711 if( modified )
712 {
714 m_frame->OnModify();
715 }
716
717 return 0;
718}
719
720
722{
723 doCrossProbeSchToPcb( aEvent, false );
724 return 0;
725}
726
727
729{
730 doCrossProbeSchToPcb( aEvent, true );
731 return 0;
732}
733
734
735void SCH_EDITOR_CONTROL::doCrossProbeSchToPcb( const TOOL_EVENT& aEvent, bool aForce )
736{
737 // Don't get in an infinite loop SCH -> PCB -> SCH -> PCB -> SCH -> ...
739 return;
740
742
743 EE_SELECTION& selection = aForce ? selTool->RequestSelection() : selTool->GetSelection();
744
745 m_frame->SendSelectItemsToPcb( selection.GetItemsSortedBySelectionOrder(), aForce );
746}
747
748
750{
751 bool createNew = aEvent.IsAction( &EE_ACTIONS::exportSymbolsToNewLibrary );
752
753 SCH_REFERENCE_LIST symbols;
754 m_frame->Schematic().GetSheets().GetSymbols( symbols, false );
755
756 std::map<LIB_ID, LIB_SYMBOL*> libSymbols;
757 std::map<LIB_ID, std::vector<SCH_SYMBOL*>> symbolMap;
758
759 for( size_t i = 0; i < symbols.GetCount(); ++i )
760 {
761 SCH_SYMBOL* symbol = symbols[i].GetSymbol();
762 LIB_SYMBOL* libSymbol = symbol->GetLibSymbolRef().get();
763 LIB_ID id = libSymbol->GetLibId();
764
765 if( libSymbols.count( id ) )
766 {
767 wxASSERT_MSG( libSymbols[id]->Compare( *libSymbol, LIB_ITEM::COMPARE_FLAGS::ERC ) == 0,
768 "Two symbols have the same LIB_ID but are different!" );
769 }
770 else
771 {
772 libSymbols[id] = libSymbol;
773 }
774
775 symbolMap[id].emplace_back( symbol );
776 }
777
779
780 wxString targetLib;
781
782 if( createNew )
783 {
784 wxFileName fn;
786
789 ( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() ),
791 {
792 return 0;
793 }
794
795 targetLib = fn.GetName();
796
797 if( libTable->HasLibrary( targetLib, false ) )
798 {
799 DisplayError( m_frame, wxString::Format( _( "Library '%s' already exists." ),
800 targetLib ) );
801 return 0;
802 }
803
804 if( !mgr.CreateLibrary( fn.GetFullPath(), libTable ) )
805 {
806 DisplayError( m_frame, wxString::Format( _( "Could not add library '%s'." ),
807 targetLib ) );
808 return 0;
809 }
810 }
811 else
812 {
813 targetLib = m_frame->SelectLibraryFromList();
814 }
815
816 if( targetLib.IsEmpty() )
817 return 0;
818
819 bool map = IsOK( m_frame, _( "Update symbols in schematic to refer to new library?" ) );
820
821 SYMBOL_LIB_TABLE_ROW* row = mgr.GetLibrary( targetLib );
822 SCH_IO_MGR::SCH_FILE_T type = SCH_IO_MGR::EnumFromStr( row->GetType() );
823 SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( type ) );
824
825 wxFileName dest = row->GetFullURI( true );
826 dest.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
827
828 for( const std::pair<const LIB_ID, LIB_SYMBOL*>& it : libSymbols )
829 {
830 LIB_SYMBOL* origSym = it.second;
831 LIB_SYMBOL* newSym = origSym->Flatten().release();
832
833 pi->SaveSymbol( dest.GetFullPath(), newSym );
834
835 if( map )
836 {
837 LIB_ID id = it.first;
838 id.SetLibNickname( targetLib );
839
840 for( SCH_SYMBOL* symbol : symbolMap[it.first] )
841 symbol->SetLibId( id );
842 }
843 }
844
845 return 0;
846}
847
848
849#ifdef KICAD_SPICE
850
851#define HITTEST_THRESHOLD_PIXELS 5
852
853int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
854{
857
858 if( !simFrame ) // Defensive coding; shouldn't happen.
859 return 0;
860
861 if( wxWindow* blocking_win = simFrame->Kiway().GetBlockingDialog() )
862 blocking_win->Close( true );
863
864 // Deactivate other tools; particularly important if another PICKER is currently running
865 Activate();
866
868 picker->SetSnapping( false );
869
870 picker->SetClickHandler(
871 [this, simFrame]( const VECTOR2D& aPosition )
872 {
874 EDA_ITEM* item = selTool->GetNode( aPosition );
875
876 if( !item )
877 return false;
878
879 if( item->Type() == SCH_PIN_T )
880 {
881 LIB_PIN* pin = static_cast<SCH_PIN*>( item )->GetLibPin();
882 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item->GetParent() );
883 std::vector<LIB_PIN*> pins = symbol->GetLibPins();
884
885 // TODO: We need to unify this library-model inheritance stuff into one
886 // abstraction.
887
888 // It might not be the best idea to have to load a file every time current is
889 // probed either.
890
891 std::unique_ptr<SIM_MODEL> model;
892 std::unique_ptr<SIM_LIBRARY> library;
893
894 SCH_FIELD* libraryField = symbol->FindField( SIM_LIBRARY::LIBRARY_FIELD );
895 SCH_FIELD* nameField = symbol->FindField( SIM_LIBRARY::NAME_FIELD );
896
897 if( libraryField )
898 {
899 wxString path = m_frame->Prj().AbsolutePath( libraryField->GetShownText() );
900
901 try
902 {
903 library = SIM_LIBRARY::Create( std::string( path.ToUTF8() ) );
904 }
905 catch( const IO_ERROR& e )
906 {
908 wxString::Format( "Failed reading model library '%s'", path ),
909 e.What() );
910 return true;
911 }
912
913 if( !nameField )
914 return true;
915
916 SIM_MODEL* baseModel = library->FindModel( std::string( nameField->GetShownText().ToUTF8() ) );
917
918 if( !baseModel )
919 return true;
920
921 model = SIM_MODEL::Create( *baseModel,
922 static_cast<int>( pins.size() ),
923 symbol->GetFields() );
924 }
925 else
926 model = SIM_MODEL::Create( static_cast<int>( pins.size() ),
927 symbol->GetFields() );
928
929 auto ref = std::string( symbol->GetRef( &m_frame->GetCurrentSheet() ).ToUTF8() );
930 std::vector<std::string> currentNames = model->SpiceGenerator().CurrentNames( ref );
931
932 if( currentNames.size() == 0 )
933 return true;
934 else if( currentNames.size() == 1 )
935 {
936 simFrame->AddCurrentPlot( currentNames.at( 0 ) );
937 return true;
938 }
939
940 int modelPinIndex = model->FindModelPinIndex( std::string( pin->GetNumber().ToUTF8() ) );
941
942 if( modelPinIndex != SIM_MODEL::PIN::NOT_CONNECTED )
943 {
944 wxString name = currentNames.at( modelPinIndex );
945 simFrame->AddCurrentPlot( name );
946 }
947 }
948 else if( item->IsType( { SCH_ITEM_LOCATE_WIRE_T } ) )
949 {
950 if( SCH_CONNECTION* conn = static_cast<SCH_ITEM*>( item )->Connection() )
951 {
952 std::string spiceNet = std::string( UnescapeString( conn->Name() ).ToUTF8() );
954
955 simFrame->AddVoltagePlot( wxString::Format( "V(%s)", spiceNet ) );
956 }
957 }
958
959 return true;
960 } );
961
962 picker->SetMotionHandler(
963 [this, picker]( const VECTOR2D& aPos )
964 {
965 EE_COLLECTOR collector;
966 collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
967 collector.Collect( m_frame->GetScreen(), { SCH_ITEM_LOCATE_WIRE_T,
968 SCH_PIN_T,
969 SCH_SHEET_PIN_T }, aPos );
970
972 selectionTool->GuessSelectionCandidates( collector, aPos );
973
974 EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
975 SCH_LINE* wire = dynamic_cast<SCH_LINE*>( item );
976
977 const SCH_CONNECTION* conn = nullptr;
978
979 if( wire )
980 {
981 item = nullptr;
982 conn = wire->Connection();
983 }
984
985 if( item && item->Type() == SCH_PIN_T )
987 else
989
990 if( m_pickerItem != item )
991 {
992 if( m_pickerItem )
993 selectionTool->UnbrightenItem( m_pickerItem );
994
995 m_pickerItem = item;
996
997 if( m_pickerItem )
998 selectionTool->BrightenItem( m_pickerItem );
999 }
1000
1001 if( m_frame->GetHighlightedConnection() != conn )
1002 {
1004
1005 TOOL_EVENT dummyEvent;
1006 UpdateNetHighlighting( dummyEvent );
1007 }
1008 } );
1009
1010 picker->SetFinalizeHandler(
1011 [this]( const int& aFinalState )
1012 {
1013 if( m_pickerItem )
1014 m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
1015
1017 {
1019
1020 TOOL_EVENT dummyEvent;
1021 UpdateNetHighlighting( dummyEvent );
1022 }
1023
1024 // Wake the selection tool after exiting to ensure the cursor gets updated
1026 } );
1027
1029
1030 return 0;
1031}
1032
1033
1034int SCH_EDITOR_CONTROL::SimTune( const TOOL_EVENT& aEvent )
1035{
1037
1038 // Deactivate other tools; particularly important if another PICKER is currently running
1039 Activate();
1040
1041 picker->SetCursor( KICURSOR::TUNE );
1042 picker->SetSnapping( false );
1043
1044 picker->SetClickHandler(
1045 [this]( const VECTOR2D& aPosition )
1046 {
1048 EDA_ITEM* item = nullptr;
1049 selTool->SelectPoint( aPosition, { SCH_SYMBOL_T, SCH_FIELD_T }, &item );
1050
1051 if( !item )
1052 return false;
1053
1054 if( item->Type() != SCH_SYMBOL_T )
1055 {
1056 item = item->GetParent();
1057
1058 if( item->Type() != SCH_SYMBOL_T )
1059 return false;
1060 }
1061
1062 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1063 KIWAY_PLAYER* simFrame = m_frame->Kiway().Player( FRAME_SIMULATOR, false );
1064
1065 if( simFrame )
1066 {
1067 if( wxWindow* blocking_win = simFrame->Kiway().GetBlockingDialog() )
1068 blocking_win->Close( true );
1069
1070 static_cast<SIM_PLOT_FRAME*>( simFrame )->AddTuner( symbol );
1071 }
1072
1073 // We do not really want to keep a symbol selected in schematic,
1074 // so clear the current selection
1075 selTool->ClearSelection();
1076 return true;
1077 } );
1078
1079 picker->SetMotionHandler(
1080 [this]( const VECTOR2D& aPos )
1081 {
1082 EE_COLLECTOR collector;
1083 collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
1084 collector.Collect( m_frame->GetScreen(), { SCH_SYMBOL_T, SCH_FIELD_T }, aPos );
1085
1087 selectionTool->GuessSelectionCandidates( collector, aPos );
1088
1089 EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
1090
1091 if( m_pickerItem != item )
1092 {
1093 if( m_pickerItem )
1094 selectionTool->UnbrightenItem( m_pickerItem );
1095
1096 m_pickerItem = item;
1097
1098 if( m_pickerItem )
1099 selectionTool->BrightenItem( m_pickerItem );
1100 }
1101 } );
1102
1103 picker->SetFinalizeHandler(
1104 [this]( const int& aFinalState )
1105 {
1106 if( m_pickerItem )
1107 m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
1108
1109 // Wake the selection tool after exiting to ensure the cursor gets updated
1110 // and deselect previous selection from simulator to avoid any issue
1111 // ( avoid crash in some cases when the SimTune tool is deselected )
1113 selectionTool->ClearSelection();
1115 } );
1116
1118
1119 return 0;
1120}
1121#endif /* KICAD_SPICE */
1122
1123
1124// A singleton reference for clearing the highlight
1126
1127
1128static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition )
1129{
1130 SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( aToolMgr->GetToolHolder() );
1131 EE_SELECTION_TOOL* selTool = aToolMgr->GetTool<EE_SELECTION_TOOL>();
1132 SCH_EDITOR_CONTROL* editorControl = aToolMgr->GetTool<SCH_EDITOR_CONTROL>();
1133 SCH_CONNECTION* conn = nullptr;
1134 bool retVal = true;
1135
1136 if( aPosition != CLEAR )
1137 {
1138 ERC_TESTER erc( &editFrame->Schematic() );
1139
1140 if( erc.TestDuplicateSheetNames( false ) > 0 )
1141 {
1142 wxMessageBox( _( "Error: duplicate sub-sheet names found in current sheet." ) );
1143 retVal = false;
1144 }
1145 else
1146 {
1147 SCH_ITEM* item = static_cast<SCH_ITEM*>( selTool->GetNode( aPosition ) );
1148 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
1149
1150 if( item )
1151 {
1152 if( item->IsConnectivityDirty() )
1153 {
1154 editFrame->RecalculateConnections( NO_CLEANUP );
1155 }
1156
1157 if( item->Type() == SCH_FIELD_T )
1158 symbol = dynamic_cast<SCH_SYMBOL*>( item->GetParent() );
1159
1160 if( symbol && symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->IsPower() )
1161 {
1162 std::vector<SCH_PIN*> pins = symbol->GetPins();
1163
1164 if( pins.size() == 1 )
1165 conn = pins[0]->Connection();
1166 }
1167 else
1168 {
1169 conn = item->Connection();
1170 }
1171 }
1172 }
1173 }
1174
1175 if( !conn || conn == editFrame->GetHighlightedConnection() )
1176 {
1177 editFrame->SetStatusText( wxT( "" ) );
1178 editFrame->SendCrossProbeClearHighlight();
1179 editFrame->SetHighlightedConnection( nullptr );
1180 }
1181 else
1182 {
1183 editFrame->SetCrossProbeConnection( conn );
1184 editFrame->SetHighlightedConnection( conn );
1185 }
1186
1187 editFrame->UpdateNetHighlightStatus();
1188
1190 editorControl->UpdateNetHighlighting( dummy );
1191
1192 return retVal;
1193}
1194
1195
1197{
1199 VECTOR2D cursorPos = controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
1200
1201 highlightNet( m_toolMgr, cursorPos );
1202
1203 return 0;
1204}
1205
1206
1208{
1210
1211 return 0;
1212}
1213
1214
1216{
1219 VECTOR2D cursorPos = controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
1220 SCHEMATIC& schematic = m_frame->Schematic();
1222
1223 // TODO remove once real-time connectivity is a given
1224 if( !ADVANCED_CFG::GetCfg().m_RealTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
1225 {
1226 // Ensure the netlist data is up to date:
1228 }
1229
1230 // Remove selection in favor of highlighting so the whole net is highlighted
1231 selectionTool->ClearSelection();
1232 highlightNet( m_toolMgr, cursorPos );
1233
1235
1236 if( conn )
1237 {
1238 if( !conn->IsBus()
1239 && ( !conn->Driver()
1242 {
1243 m_frame->ShowInfoBarError( _( "Net must be labeled to assign a netclass." ) );
1245 return 0;
1246 }
1247 else if( conn->IsBus() && conn->Members().size() == 0 )
1248 {
1249 m_frame->ShowInfoBarError( _( "Bus has no members to assign netclass to." ) );
1251 return 0;
1252 }
1253
1254 wxString netName;
1255
1256 if( conn->IsBus() && conn->Members().size() )
1257 {
1258 const std::shared_ptr<SCH_CONNECTION>& member = conn->Members()[0];
1259
1260 if( member->IsBus() && member->Members().size() )
1261 netName = member->Members()[0]->Name();
1262 else
1263 netName = member->Name();
1264 }
1265 else
1266 {
1267 netName = conn->Name();
1268 }
1269
1271 [&]( const std::vector<wxString>& aNetNames )
1272 {
1273 for( SCH_ITEM* item : screen->Items() )
1274 {
1275 bool redraw = item->IsBrightened();
1276 SCH_CONNECTION* itemConn = item->Connection();
1277
1278 if( itemConn && alg::contains( aNetNames, itemConn->Name() ) )
1279 item->SetBrightened();
1280 else
1281 item->ClearBrightened();
1282
1283 redraw |= item->IsBrightened();
1284
1285 if( item->Type() == SCH_SYMBOL_T )
1286 {
1287 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1288
1289 redraw |= symbol->HasBrightenedPins();
1290
1291 symbol->ClearBrightenedPins();
1292
1293 for( SCH_PIN* pin : symbol->GetPins() )
1294 {
1295 SCH_CONNECTION* pin_conn = pin->Connection();
1296
1297 if( pin_conn && alg::contains( aNetNames, pin_conn->Name() ) )
1298 {
1299 pin->SetBrightened();
1300 redraw = true;
1301 }
1302 }
1303 }
1304 else if( item->Type() == SCH_SHEET_T )
1305 {
1306 for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( item )->GetPins() )
1307 {
1308 SCH_CONNECTION* pin_conn = pin->Connection();
1309
1310 redraw |= pin->IsBrightened();
1311
1312 if( pin_conn && alg::contains( aNetNames, pin_conn->Name() ) )
1313 pin->SetBrightened();
1314 else
1315 pin->ClearBrightened();
1316
1317 redraw |= pin->IsBrightened();
1318 }
1319 }
1320
1321 if( redraw )
1322 getView()->Update( item, KIGFX::VIEW_UPDATE_FLAGS::REPAINT );
1323 }
1324
1326 } );
1327
1328 dlg.ShowModal();
1329 }
1330
1331 highlightNet( m_toolMgr, CLEAR );
1332 return 0;
1333}
1334
1335
1337{
1339 CONNECTION_GRAPH* connectionGraph = m_frame->Schematic().ConnectionGraph();
1340 std::vector<EDA_ITEM*> itemsToRedraw;
1341 const SCH_CONNECTION* selectedConn = m_frame->GetHighlightedConnection();
1342
1343 if( !screen )
1344 return 0;
1345
1346 bool selectedIsBus = selectedConn ? selectedConn->IsBus() : false;
1347 wxString selectedName = selectedConn ? selectedConn->Name() : "";
1348
1349 bool selectedIsNoNet = false;
1350 CONNECTION_SUBGRAPH* selectedSubgraph = nullptr;
1351
1352 if( selectedConn && selectedConn->Driver() == nullptr )
1353 {
1354 selectedIsNoNet = true;
1355 selectedSubgraph = connectionGraph->GetSubgraphForItem( selectedConn->Parent() );
1356 }
1357
1358 for( SCH_ITEM* item : screen->Items() )
1359 {
1360 bool redraw = item->IsBrightened();
1361 bool highlight = false;
1362
1363 if( selectedConn )
1364 {
1365 SCH_CONNECTION* itemConn = nullptr;
1366 SCH_SYMBOL* symbol = nullptr;
1367
1368 if( item->Type() == SCH_SYMBOL_T )
1369 symbol = static_cast<SCH_SYMBOL*>( item );
1370
1371 if( symbol && symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->IsPower() )
1372 itemConn = symbol->Connection();
1373 else
1374 itemConn = item->Connection();
1375
1376 if( selectedIsNoNet && selectedSubgraph )
1377 {
1378 for( SCH_ITEM* subgraphItem : selectedSubgraph->m_items )
1379 {
1380 if( item == subgraphItem )
1381 {
1382 highlight = true;
1383 break;
1384 }
1385 }
1386 }
1387 else if( selectedIsBus && itemConn && itemConn->IsNet() )
1388 {
1389 for( const std::shared_ptr<SCH_CONNECTION>& member : selectedConn->Members() )
1390 {
1391 if( member->Name() == itemConn->Name() )
1392 {
1393 highlight = true;
1394 break;
1395 }
1396 else if( member->IsBus() )
1397 {
1398 for( const std::shared_ptr<SCH_CONNECTION>& bus_member : member->Members() )
1399 {
1400 if( bus_member->Name() == itemConn->Name() )
1401 {
1402 highlight = true;
1403 break;
1404 }
1405 }
1406 }
1407 }
1408 }
1409 else if( selectedConn && itemConn && selectedName == itemConn->Name() )
1410 {
1411 highlight = true;
1412 }
1413 }
1414
1415 if( highlight )
1416 item->SetBrightened();
1417 else
1418 item->ClearBrightened();
1419
1420 redraw |= item->IsBrightened();
1421
1422 if( item->Type() == SCH_SYMBOL_T )
1423 {
1424 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1425
1426 redraw |= symbol->HasBrightenedPins();
1427
1428 symbol->ClearBrightenedPins();
1429
1430 for( SCH_PIN* pin : symbol->GetPins() )
1431 {
1432 SCH_CONNECTION* pin_conn = pin->Connection();
1433
1434 if( pin_conn && pin_conn->Name() == selectedName )
1435 {
1436 pin->SetBrightened();
1437 redraw = true;
1438 }
1439 }
1440
1441 if( symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->IsPower() )
1442 {
1443 std::vector<SCH_FIELD>& fields = symbol->GetFields();
1444
1445 for( int id : { REFERENCE_FIELD, VALUE_FIELD } )
1446 {
1447 if( item->IsBrightened() && fields[id].IsVisible() )
1448 fields[id].SetBrightened();
1449 else
1450 fields[id].ClearBrightened();
1451 }
1452 }
1453 }
1454 else if( item->Type() == SCH_SHEET_T )
1455 {
1456 for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( item )->GetPins() )
1457 {
1458 SCH_CONNECTION* pin_conn = pin->Connection();
1459 bool redrawPin = pin->IsBrightened();
1460
1461 if( pin_conn && pin_conn->Name() == selectedName )
1462 pin->SetBrightened();
1463 else
1464 pin->ClearBrightened();
1465
1466 redrawPin ^= pin->IsBrightened();
1467 redraw |= redrawPin;
1468 }
1469 }
1470
1471 if( redraw )
1472 itemsToRedraw.push_back( item );
1473 }
1474
1475 // Be sure highlight change will be redrawn
1476 KIGFX::VIEW* view = getView();
1477
1478 for( EDA_ITEM* redrawItem : itemsToRedraw )
1480
1482
1483 return 0;
1484}
1485
1486
1488{
1490
1491 // Deactivate other tools; particularly important if another PICKER is currently running
1492 Activate();
1493
1494 picker->SetCursor( KICURSOR::BULLSEYE );
1495 picker->SetSnapping( false );
1496
1497 picker->SetClickHandler(
1498 [this] ( const VECTOR2D& aPos )
1499 {
1500 return highlightNet( m_toolMgr, aPos );
1501 } );
1502
1504
1505 return 0;
1506}
1507
1508
1510{
1511 if( m_frame->GetUndoCommandCount() <= 0 )
1512 return 0;
1513
1514 // Inform tools that undo command was issued
1516
1517 // Get the old list
1519 size_t num_undos = m_frame->m_undoList.m_CommandsList.size();
1520
1521 // The cleanup routines normally run after an operation and so attempt to append their
1522 // undo items onto the operation's list. However, in this case that's going be the list
1523 // under us, which we don't want, so we push a dummy list onto the stack.
1526
1528
1532
1533 // The cleanup routines *should* have appended to our dummy list, but just to be doubly
1534 // sure pop any other new lists off the stack as well
1535 while( m_frame->m_undoList.m_CommandsList.size() > num_undos )
1537
1538 // Now push the old command to the RedoList
1541
1542 m_toolMgr->GetTool<EE_SELECTION_TOOL>()->RebuildSelection();
1543
1544 m_frame->SyncView();
1546 m_frame->OnModify();
1547
1548 return 0;
1549}
1550
1551
1553{
1554 if( m_frame->GetRedoCommandCount() == 0 )
1555 return 0;
1556
1557 // Inform tools that undo command was issued
1559
1560 /* Get the old list */
1562
1563 /* Redo the command: */
1565
1566 /* Put the old list in UndoList */
1569
1573
1574 m_toolMgr->GetTool<EE_SELECTION_TOOL>()->RebuildSelection();
1575
1576 m_frame->SyncView();
1578 m_frame->OnModify();
1579
1580 return 0;
1581}
1582
1583
1584bool SCH_EDITOR_CONTROL::doCopy( bool aUseLocalClipboard )
1585{
1587 EE_SELECTION& selection = selTool->RequestSelection();
1588 SCHEMATIC& schematic = m_frame->Schematic();
1589
1590 if( !selection.GetSize() )
1591 return false;
1592
1593 selection.SetScreen( m_frame->GetScreen() );
1595
1596 for( EDA_ITEM* item : selection )
1597 {
1598 if( item->Type() == SCH_SHEET_T )
1599 {
1600 SCH_SHEET* sheet = (SCH_SHEET*) item;
1601 m_supplementaryClipboard[ sheet->GetFileName() ] = sheet->GetScreen();
1602 }
1603 }
1604
1605 STRING_FORMATTER formatter;
1606 SCH_SEXPR_PLUGIN plugin;
1607 SCH_SHEET_LIST hierarchy = schematic.GetSheets();
1609
1610 plugin.Format( &selection, &selPath, &hierarchy, &formatter, true );
1611
1612 if( aUseLocalClipboard )
1613 {
1614 m_localClipboard = formatter.GetString();
1615 return true;
1616 }
1617
1618 return m_toolMgr->SaveClipboard( formatter.GetString() );
1619}
1620
1621
1622bool SCH_EDITOR_CONTROL::searchSupplementaryClipboard( const wxString& aSheetFilename,
1623 SCH_SCREEN** aScreen )
1624{
1625 if( m_supplementaryClipboard.count( aSheetFilename ) > 0 )
1626 {
1627 *aScreen = m_supplementaryClipboard[ aSheetFilename ];
1628 return true;
1629 }
1630
1631 return false;
1632}
1633
1634
1636{
1637 doCopy( true ); // Use the local clipboard
1638 Paste( aEvent );
1639
1640 return 0;
1641}
1642
1643
1645{
1646 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
1647
1648 if( textEntry )
1649 {
1650 textEntry->Cut();
1651 return 0;
1652 }
1653
1654 if( doCopy() )
1656
1657 return 0;
1658}
1659
1660
1662{
1663 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
1664
1665 if( textEntry )
1666 {
1667 textEntry->Copy();
1668 return 0;
1669 }
1670
1671 doCopy();
1672
1673 return 0;
1674}
1675
1676
1678 const SCH_SHEET_PATH& aPastePath,
1679 const KIID_PATH& aClipPath,
1680 bool aForceKeepAnnotations )
1681{
1682 KIID_PATH clipItemPath = aClipPath;
1683 clipItemPath.push_back( aSymbol->m_Uuid );
1684
1685 wxString reference, value, footprint;
1686 int unit;
1687
1688 if( m_clipboardSymbolInstances.count( clipItemPath ) > 0 )
1689 {
1690 SYMBOL_INSTANCE_REFERENCE instance = m_clipboardSymbolInstances.at( clipItemPath );
1691
1692 unit = instance.m_Unit;
1693 reference = instance.m_Reference;
1694 value = instance.m_Value;
1695 footprint = instance.m_Footprint;
1696 }
1697 else
1698 {
1699 // Some legacy versions saved value fields escaped. While we still do in the symbol
1700 // editor, we don't anymore in the schematic, so be sure to unescape them.
1701 SCH_FIELD* valueField = aSymbol->GetField( VALUE_FIELD );
1702 valueField->SetText( UnescapeString( valueField->GetText() ) );
1703
1704 // Pasted from notepad or an older instance of eeschema. Use the values in the fields
1705 // instead.
1706 reference = aSymbol->GetField( REFERENCE_FIELD )->GetText();
1707 value = aSymbol->GetField( VALUE_FIELD )->GetText();
1708 footprint = aSymbol->GetField( FOOTPRINT_FIELD )->GetText();
1709 unit = aSymbol->GetUnit();
1710 }
1711
1712 if( aForceKeepAnnotations && !reference.IsEmpty() )
1713 aSymbol->SetRef( &aPastePath, reference );
1714 else
1715 aSymbol->ClearAnnotation( &aPastePath, false );
1716
1717 // We might clear annotations but always leave the original unit number, value and footprint
1718 // from the paste
1719 aSymbol->SetUnitSelection( &aPastePath, unit );
1720 aSymbol->SetUnit( unit );
1721 aSymbol->SetValue( &aPastePath, value );
1722 aSymbol->SetFootprint( &aPastePath, footprint );
1723}
1724
1725
1727 const KIID_PATH& aClipPath, SCH_SHEET* aSheet,
1728 bool aForceKeepAnnotations,
1729 SCH_SHEET_LIST* aPastedSheetsSoFar,
1730 SCH_REFERENCE_LIST* aPastedSymbolsSoFar )
1731{
1732 SCH_SHEET_PATH sheetPath = aPastePath;
1733 sheetPath.push_back( aSheet );
1734
1735 aSheet->AddInstance( sheetPath );
1736
1737 wxString pageNum;
1738
1739 if( m_clipboardSheetInstances.count( aClipPath ) > 0 )
1740 pageNum = m_clipboardSheetInstances.at( aClipPath ).m_PageNumber;
1741 else
1742 pageNum = wxString::Format( "%d", static_cast<int>( aPastedSheetsSoFar->size() ) );
1743
1744 aSheet->SetPageNumber( sheetPath, pageNum );
1745 aPastedSheetsSoFar->push_back( sheetPath );
1746
1747 if( aSheet->GetScreen() == nullptr )
1748 return sheetPath; // We can only really set the page number but not load any items
1749
1750 for( SCH_ITEM* item : aSheet->GetScreen()->Items() )
1751 {
1752 if( item->Type() == SCH_SYMBOL_T )
1753 {
1754 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1755
1756 updatePastedSymbol( symbol, aSheet->GetScreen(), sheetPath, aClipPath,
1757 aForceKeepAnnotations );
1758 }
1759 else if( item->Type() == SCH_SHEET_T )
1760 {
1761 SCH_SHEET* subsheet = static_cast<SCH_SHEET*>( item );
1762
1763 KIID_PATH newClipPath = aClipPath;
1764 newClipPath.push_back( subsheet->m_Uuid );
1765
1766 updatePastedSheet( sheetPath, newClipPath, subsheet, aForceKeepAnnotations,
1767 aPastedSheetsSoFar, aPastedSymbolsSoFar );
1768
1769 SCH_SHEET_PATH subSheetPath = sheetPath;
1770 subSheetPath.push_back( subsheet );
1771
1772 subSheetPath.GetSymbols( *aPastedSymbolsSoFar );
1773 }
1774 }
1775
1776 return sheetPath;
1777}
1778
1779
1781{
1783
1784 for( const SCH_SHEET_INSTANCE& sheet : aPastedScreen->GetSheetInstances() )
1785 m_clipboardSheetInstances[sheet.m_Path] = sheet;
1786
1788
1789 for( const SYMBOL_INSTANCE_REFERENCE& symbol : aPastedScreen->GetSymbolInstances() )
1790 m_clipboardSymbolInstances[symbol.m_Path] = symbol;
1791}
1792
1793
1795{
1796 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
1797
1798 if( textEntry )
1799 {
1800 textEntry->Paste();
1801 return 0;
1802 }
1803
1805 std::string content;
1806
1807 if( aEvent.IsAction( &ACTIONS::duplicate ) )
1808 content = m_localClipboard;
1809 else
1810 content = m_toolMgr->GetClipboardUTF8();
1811
1812 if( content.empty() )
1813 return 0;
1814
1815 STRING_LINE_READER reader( content, "Clipboard" );
1816 SCH_SEXPR_PLUGIN plugin;
1817
1818 SCH_SHEET tempSheet;
1819 SCH_SCREEN* tempScreen = new SCH_SCREEN( &m_frame->Schematic() );
1820
1822 int annotateStartNum = m_frame->Schematic().Settings().m_AnnotateStartNum;
1823
1824 // Screen object on heap is owned by the sheet.
1825 tempSheet.SetScreen( tempScreen );
1826
1827 try
1828 {
1829 plugin.LoadContent( reader, &tempSheet );
1830 }
1831 catch( IO_ERROR& )
1832 {
1833 // If it wasn't content, then paste as content
1834 SCH_TEXT* text_item = new SCH_TEXT( wxPoint( 0, 0 ), content );
1835 text_item->SetTextSpinStyle( TEXT_SPIN_STYLE::RIGHT ); // Left alignment
1836 tempScreen->Append( text_item );
1837 }
1838
1839 // Save loaded screen instances to m_clipboardSheetInstances
1840 setClipboardInstances( tempScreen );
1841
1842 PASTE_MODE pasteMode =
1844
1845 if( aEvent.IsAction( &ACTIONS::pasteSpecial ) )
1846 {
1847 DIALOG_PASTE_SPECIAL dlg( m_frame, &pasteMode );
1848
1849 if( dlg.ShowModal() == wxID_CANCEL )
1850 return 0;
1851 }
1852
1853 bool forceKeepAnnotations = pasteMode != PASTE_MODE::REMOVE_ANNOTATIONS;
1854
1855 // SCH_SEXP_PLUGIN added the items to the paste screen, but not to the view or anything
1856 // else. Pull them back out to start with.
1857 //
1858 EDA_ITEMS loadedItems;
1859 bool sheetsPasted = false;
1860 SCH_SHEET_LIST hierarchy = m_frame->Schematic().GetSheets();
1861 SCH_SHEET_PATH& pasteRoot = m_frame->GetCurrentSheet();
1862 wxFileName destFn = pasteRoot.Last()->GetFileName();
1863
1864 if( destFn.IsRelative() )
1865 destFn.MakeAbsolute( m_frame->Prj().GetProjectPath() );
1866
1867 // List of paths in the hierarchy that refer to the destination sheet of the paste
1868 SCH_SHEET_LIST pasteInstances = hierarchy.FindAllSheetsForScreen( pasteRoot.LastScreen() );
1869 pasteInstances.SortByPageNumbers();
1870
1871 // Build a list of screens from the current design (to avoid loading sheets that already exist)
1872 std::map<wxString, SCH_SCREEN*> loadedScreens;
1873
1874 for( const SCH_SHEET_PATH& item : hierarchy )
1875 {
1876 if( item.LastScreen() )
1877 loadedScreens[item.Last()->GetFileName()] = item.LastScreen();
1878 }
1879
1880 // Build symbol list for reannotation of duplicates
1881 SCH_REFERENCE_LIST existingRefs;
1882 hierarchy.GetSymbols( existingRefs );
1883 existingRefs.SortByReferenceOnly();
1884
1885 // Build UUID map for fetching last-resolved-properties
1886 std::map<KIID, EDA_ITEM*> itemMap;
1887 hierarchy.FillItemMap( itemMap );
1888
1889 // Keep track of pasted sheets and symbols for the different
1890 // paths to the hierarchy
1891 std::map<SCH_SHEET_PATH, SCH_REFERENCE_LIST> pastedSymbols;
1892 std::map<SCH_SHEET_PATH, SCH_SHEET_LIST> pastedSheets;
1893
1894 for( SCH_ITEM* item : tempScreen->Items() )
1895 {
1896 loadedItems.push_back( item );
1897
1898 //@todo: we might want to sort the sheets by page number before adding to loadedItems
1899 if( item->Type() == SCH_SHEET_T )
1900 {
1901 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
1902 wxFileName srcFn = sheet->GetFileName();
1903
1904 if( srcFn.IsRelative() )
1905 srcFn.MakeAbsolute( m_frame->Prj().GetProjectPath() );
1906
1907 SCH_SHEET_LIST sheetHierarchy( sheet );
1908
1909 if( hierarchy.TestForRecursion( sheetHierarchy, destFn.GetFullPath( wxPATH_UNIX ) ) )
1910 {
1911 auto msg = wxString::Format( _( "The pasted sheet '%s'\n"
1912 "was dropped because the destination already has "
1913 "the sheet or one of its subsheets as a parent." ),
1914 sheet->GetFileName() );
1915 DisplayError( m_frame, msg );
1916 loadedItems.pop_back();
1917 }
1918 }
1919 }
1920
1921 // Remove the references from our temporary screen to prevent freeing on the DTOR
1922 tempScreen->Clear( false );
1923
1924 for( unsigned i = 0; i < loadedItems.size(); ++i )
1925 {
1926 EDA_ITEM* item = loadedItems[i];
1927 KIID_PATH clipPath( wxT("/") ); // clipboard is at root
1928
1929 if( item->Type() == SCH_SYMBOL_T )
1930 {
1931 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1932
1933 // The library symbol gets set from the cached library symbols in the current
1934 // schematic not the symbol libraries. The cached library symbol may have
1935 // changed from the original library symbol which would cause the copy to
1936 // be incorrect.
1937 SCH_SCREEN* currentScreen = m_frame->GetScreen();
1938
1939 wxCHECK2( currentScreen, continue );
1940
1941 auto it = currentScreen->GetLibSymbols().find( symbol->GetSchSymbolLibraryName() );
1942 auto end = currentScreen->GetLibSymbols().end();
1943
1944 if( it == end )
1945 {
1946 // If can't find library definition in the design, use the pasted library
1947 it = tempScreen->GetLibSymbols().find( symbol->GetSchSymbolLibraryName() );
1948 end = tempScreen->GetLibSymbols().end();
1949 }
1950
1951 LIB_SYMBOL* libSymbol = nullptr;
1952
1953 if( it != end )
1954 {
1955 libSymbol = new LIB_SYMBOL( *it->second );
1956 symbol->SetLibSymbol( libSymbol );
1957 }
1958
1959 for( SCH_SHEET_PATH& instance : pasteInstances )
1960 updatePastedSymbol( symbol, tempScreen, instance, clipPath, forceKeepAnnotations );
1961
1962 // Assign a new KIID
1963 const_cast<KIID&>( item->m_Uuid ) = KIID();
1964
1965 // Make sure pins get a new UUID
1966 for( SCH_PIN* pin : symbol->GetPins() )
1967 const_cast<KIID&>( pin->m_Uuid ) = KIID();
1968
1969 for( SCH_SHEET_PATH& instance : pasteInstances )
1970 {
1971 // Ignore pseudo-symbols (e.g. power symbols) and symbols from a non-existant
1972 // library.
1973 if( libSymbol && symbol->GetRef( &instance )[0] != wxT( '#' ) )
1974 {
1975 SCH_REFERENCE schReference( symbol, libSymbol, instance );
1976 schReference.SetSheetNumber( instance.GetVirtualPageNumber() );
1977 pastedSymbols[instance].AddItem( schReference );
1978 }
1979 }
1980 }
1981 else if( item->Type() == SCH_SHEET_T )
1982 {
1983 SCH_SHEET* sheet = (SCH_SHEET*) item;
1984 SCH_FIELD& nameField = sheet->GetFields()[SHEETNAME];
1985 wxString baseName = nameField.GetText();
1986 wxString candidateName = baseName;
1987 wxString number;
1988
1989 while( !baseName.IsEmpty() && wxIsdigit( baseName.Last() ) )
1990 {
1991 number = baseName.Last() + number;
1992 baseName.RemoveLast();
1993 }
1994 // Update hierarchy to include any other sheets we already added, avoiding
1995 // duplicate sheet names
1996 hierarchy = m_frame->Schematic().GetSheets();
1997
1998 //@todo: it might be better to just iterate through the sheet names
1999 // in this screen instead of the whole hierarchy.
2000 int uniquifier = std::max( 0, wxAtoi( number ) ) + 1;
2001
2002 while( hierarchy.NameExists( candidateName ) )
2003 candidateName = wxString::Format( wxT( "%s%d" ), baseName, uniquifier++ );
2004
2005 nameField.SetText( candidateName );
2006
2007 wxFileName fn = sheet->GetFileName();
2008 SCH_SCREEN* existingScreen = nullptr;
2009
2010 sheet->SetParent( pasteRoot.Last() );
2011 sheet->SetScreen( nullptr );
2012
2013 if( !fn.IsAbsolute() )
2014 {
2015 wxFileName currentSheetFileName = pasteRoot.LastScreen()->GetFileName();
2016 fn.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS,
2017 currentSheetFileName.GetPath() );
2018 }
2019
2020 // Try to find the screen for the pasted sheet by several means
2021 if( !m_frame->Schematic().Root().SearchHierarchy( fn.GetFullPath( wxPATH_UNIX ),
2022 &existingScreen ) )
2023 {
2024 if( loadedScreens.count( sheet->GetFileName() ) > 0 )
2025 existingScreen = loadedScreens.at( sheet->GetFileName() );
2026 else
2027 searchSupplementaryClipboard( sheet->GetFileName(), &existingScreen );
2028 }
2029
2030 if( existingScreen )
2031 {
2032 sheet->SetScreen( existingScreen );
2033 }
2034 else
2035 {
2036 if( !m_frame->LoadSheetFromFile( sheet, &pasteRoot, fn.GetFullPath() ) )
2037 m_frame->InitSheet( sheet, sheet->GetFileName() );
2038 }
2039
2040 sheetsPasted = true;
2041
2042 // Push it to the clipboard path while it still has its old KIID
2043 clipPath.push_back( sheet->m_Uuid );
2044
2045 // Assign a new KIID to the pasted sheet
2046 const_cast<KIID&>( sheet->m_Uuid ) = KIID();
2047
2048 // Make sure pins get a new UUID
2049 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
2050 const_cast<KIID&>( pin->m_Uuid ) = KIID();
2051
2052 // Once we have our new KIID we can update all pasted instances. This will either
2053 // reset the annotations or copy "kept" annotations from the supplementary clipboard.
2054 for( SCH_SHEET_PATH& instance : pasteInstances )
2055 {
2056 SCH_SHEET_PATH sheetPath = updatePastedSheet( instance, clipPath, sheet,
2057 ( forceKeepAnnotations && annotate.recursive ),
2058 &pastedSheets[instance],
2059 &pastedSymbols[instance] );
2060
2061 sheetPath.GetSymbols( pastedSymbols[instance] );
2062 }
2063 }
2064 else
2065 {
2066 SCH_ITEM* srcItem = dynamic_cast<SCH_ITEM*>( itemMap[ item->m_Uuid ] );
2067 SCH_ITEM* destItem = dynamic_cast<SCH_ITEM*>( item );
2068
2069 // Everything gets a new KIID
2070 const_cast<KIID&>( item->m_Uuid ) = KIID();
2071
2072 if( srcItem && destItem )
2073 {
2074 destItem->SetConnectivityDirty( true );
2075 destItem->SetLastResolvedState( srcItem );
2076 }
2077 }
2078
2079 // Lines need both ends selected for a move after paste so the whole
2080 // line moves
2081 if( item->Type() == SCH_LINE_T )
2082 item->SetFlags( STARTPOINT | ENDPOINT );
2083
2084 item->SetFlags( IS_NEW | IS_PASTED | IS_MOVING );
2086
2087 // Reset flags for subsequent move operation
2088 item->SetFlags( IS_NEW | IS_PASTED | IS_MOVING );
2089 // Start out hidden so the pasted items aren't "ghosted" in their original location
2090 // before being moved to the current location.
2091 getView()->Hide( item, true );
2092 }
2093
2094 pasteInstances.SortByPageNumbers();
2095
2096 if( sheetsPasted )
2097 {
2098 // Update page numbers: Find next free numeric page number
2099 for( SCH_SHEET_PATH& instance : pasteInstances )
2100 {
2101 pastedSheets[instance].SortByPageNumbers();
2102
2103 for( SCH_SHEET_PATH& pastedSheet : pastedSheets[instance] )
2104 {
2105 int page = 1;
2106 wxString pageNum = wxString::Format( "%d", page );
2107
2108 while( hierarchy.PageNumberExists( pageNum ) )
2109 pageNum = wxString::Format( "%d", ++page );
2110
2111 pastedSheet.SetPageNumber( pageNum );
2112 hierarchy.push_back( pastedSheet );
2113 }
2114 }
2115
2118
2119 // Get a version with correct sheet numbers since we've pasted sheets,
2120 // we'll need this when annotating next
2121 hierarchy = m_frame->Schematic().GetSheets();
2122 }
2123
2124 if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS || pasteMode == PASTE_MODE::RESPECT_OPTIONS )
2125 {
2126 for( SCH_SHEET_PATH& instance : pasteInstances )
2127 {
2128 pastedSymbols[instance].SortByReferenceOnly();
2129
2130 if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS )
2131 pastedSymbols[instance].ReannotateDuplicates( existingRefs );
2132 else
2133 pastedSymbols[instance].ReannotateByOptions( (ANNOTATE_ORDER_T) annotate.sort_order,
2134 (ANNOTATE_ALGO_T) annotate.method,
2135 annotateStartNum, existingRefs, true,
2136 &hierarchy );
2137
2138 pastedSymbols[instance].UpdateAnnotation();
2139
2140 // Update existing refs for next iteration
2141 for( size_t i = 0; i < pastedSymbols[instance].GetCount(); i++ )
2142 existingRefs.AddItem( pastedSymbols[instance][i] );
2143 }
2144 }
2145
2147
2148 // Now clear the previous selection, select the pasted items, and fire up the "move"
2149 // tool.
2150 //
2152 m_toolMgr->RunAction( EE_ACTIONS::addItemsToSel, true, &loadedItems );
2153
2154 EE_SELECTION& selection = selTool->GetSelection();
2155
2156 if( !selection.Empty() )
2157 {
2158 SCH_ITEM* item = (SCH_ITEM*) selection.GetTopLeftItem();
2159
2160 selection.SetReferencePoint( item->GetPosition() );
2161
2163 }
2164
2165 return 0;
2166}
2167
2168
2170{
2172 EE_SELECTION& selection = selTool->RequestSelection( { SCH_SYMBOL_T } );
2173 SCH_SYMBOL* symbol = nullptr;
2174 SYMBOL_EDIT_FRAME* symbolEditor;
2175
2176 if( selection.GetSize() >= 1 )
2177 symbol = (SCH_SYMBOL*) selection.Front();
2178
2179 if( !symbol || symbol->GetEditFlags() != 0 )
2180 return 0;
2181
2182 if( symbol->IsMissingLibSymbol() )
2183 {
2184 m_frame->ShowInfoBarError( _( "Symbols with broken library symbol links cannot "
2185 "be edited." ) );
2186 return 0;
2187 }
2188
2190 symbolEditor = (SYMBOL_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
2191
2192 if( symbolEditor )
2193 {
2194 if( wxWindow* blocking_win = symbolEditor->Kiway().GetBlockingDialog() )
2195 blocking_win->Close( true );
2196
2197 if( aEvent.IsAction( &EE_ACTIONS::editWithLibEdit ) )
2198 {
2199 symbolEditor->LoadSymbolFromSchematic( symbol );
2200 }
2202 {
2203 symbolEditor->LoadSymbol( symbol->GetLibId(), symbol->GetUnit(), symbol->GetConvert() );
2204
2205 if( !symbolEditor->IsSymbolTreeShown() )
2206 {
2207 wxCommandEvent evt;
2208 symbolEditor->OnToggleSymbolTree( evt );
2209 }
2210 }
2211 }
2212
2213 return 0;
2214}
2215
2216
2218{
2219 wxCommandEvent dummy;
2221 return 0;
2222}
2223
2224
2226{
2227 wxCommandEvent dummy;
2229 return 0;
2230}
2231
2232
2234{
2236 dlg.ShowQuasiModal();
2237 return 0;
2238}
2239
2240
2242{
2245
2246 return 0;
2247}
2248
2249
2251{
2252 wxCommandEvent dummy;
2254 return 0;
2255}
2256
2257
2259{
2260 wxCommandEvent dummy;
2262 return 0;
2263}
2264
2265
2267{
2269 dlg.ShowModal();
2270 return 0;
2271}
2272
2273
2275{
2276 int result = NET_PLUGIN_CHANGE;
2277
2278 // If a plugin is removed or added, rebuild and reopen the new dialog
2279 while( result == NET_PLUGIN_CHANGE )
2280 result = InvokeDialogNetList( m_frame );
2281
2282 return 0;
2283}
2284
2285
2287{
2289 return 0;
2290}
2291
2292
2294{
2295 if( !ADVANCED_CFG::GetCfg().m_RealTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
2297
2299 return 0;
2300}
2301
2302
2304{
2305 getEditFrame<SCH_EDIT_FRAME>()->ToggleSchematicHierarchy();
2306 return 0;
2307}
2308
2309
2311{
2314
2317
2318 return 0;
2319}
2320
2321
2323{
2326
2329
2330 return 0;
2331}
2332
2333
2335{
2338
2341
2342 return 0;
2343}
2344
2345
2347{
2350
2353
2354 return 0;
2355}
2356
2357
2359{
2362
2365
2366 return 0;
2367}
2368
2369
2371{
2372 m_frame->eeconfig()->m_Drawing.line_mode = aEvent.Parameter<int>();
2374 return 0;
2375}
2376
2377
2379{
2383 return 0;
2384}
2385
2386
2388{
2391 return 0;
2392}
2393
2394
2396{
2399 return 0;
2400}
2401
2402
2404{
2405
2407 return 0;
2408}
2409
2410
2412{
2413 int errors = 0;
2414 wxString details;
2415 bool quiet = aEvent.Parameter<bool>();
2416
2417 // Repair duplicate IDs.
2418 std::map<KIID, EDA_ITEM*> ids;
2419 int duplicates = 0;
2420
2421 auto processItem =
2422 [&]( EDA_ITEM* aItem )
2423 {
2424 auto it = ids.find( aItem->m_Uuid );
2425
2426 if( it != ids.end() && it->second != aItem )
2427 {
2428 duplicates++;
2429 const_cast<KIID&>( aItem->m_Uuid ) = KIID();
2430 }
2431
2432 ids[ aItem->m_Uuid ] = aItem;
2433 };
2434
2435 // Symbol IDs are the most important, so give them the first crack at "claiming" a
2436 // particular KIID.
2437
2438 for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().GetSheets() )
2439 {
2440 SCH_SCREEN* screen = sheet.LastScreen();
2441
2442 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
2443 {
2444 processItem( item );
2445
2446 for( SCH_PIN* pin : static_cast<SCH_SYMBOL*>( item )->GetPins( &sheet ) )
2447 processItem( pin );
2448 }
2449 }
2450
2451 for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().GetSheets() )
2452 {
2453 SCH_SCREEN* screen = sheet.LastScreen();
2454
2455 for( SCH_ITEM* item : screen->Items() )
2456 {
2457 processItem( item );
2458
2459 item->RunOnChildren(
2460 [&]( SCH_ITEM* aChild )
2461 {
2462 processItem( item );
2463 } );
2464 }
2465 }
2466
2467 /*******************************
2468 * Your test here
2469 */
2470
2471 /*******************************
2472 * Inform the user
2473 */
2474
2475 if( duplicates )
2476 {
2477 errors += duplicates;
2478 details += wxString::Format( _( "%d duplicate IDs replaced.\n" ), duplicates );
2479 }
2480
2481 if( errors )
2482 {
2483 m_frame->OnModify();
2484
2485 wxString msg = wxString::Format( _( "%d potential problems repaired." ), errors );
2486
2487 if( !quiet )
2488 DisplayInfoMessage( m_frame, msg, details );
2489 }
2490 else if( !quiet )
2491 {
2492 DisplayInfoMessage( m_frame, _( "No errors found." ) );
2493 }
2494
2495 return 0;
2496}
2497
2498
2500{
2501 Go( &SCH_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() );
2502 Go( &SCH_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() );
2503 Go( &SCH_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
2510 Go( &SCH_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() );
2511 Go( &SCH_EDITOR_CONTROL::Quit, ACTIONS::quit.MakeEvent() );
2512
2515
2524
2530
2531#ifdef KICAD_SPICE
2532 Go( &SCH_EDITOR_CONTROL::SimProbe, EE_ACTIONS::simProbe.MakeEvent() );
2533 Go( &SCH_EDITOR_CONTROL::SimTune, EE_ACTIONS::simTune.MakeEvent() );
2534#endif /* KICAD_SPICE */
2535
2541
2543
2544 Go( &SCH_EDITOR_CONTROL::Undo, ACTIONS::undo.MakeEvent() );
2545 Go( &SCH_EDITOR_CONTROL::Redo, ACTIONS::redo.MakeEvent() );
2546 Go( &SCH_EDITOR_CONTROL::Cut, ACTIONS::cut.MakeEvent() );
2547 Go( &SCH_EDITOR_CONTROL::Copy, ACTIONS::copy.MakeEvent() );
2551
2565
2567
2578
2580
2582
2585}
const char * name
Definition: DXF_plotter.cpp:56
static TOOL_ACTION updatePcbFromSchematic
Definition: actions.h:166
static TOOL_ACTION paste
Definition: actions.h:69
static TOOL_ACTION cancelInteractive
Definition: actions.h:63
static TOOL_ACTION revert
Definition: actions.h:55
static TOOL_ACTION replaceAll
Definition: actions.h:83
static TOOL_ACTION saveAs
Definition: actions.h:52
static TOOL_ACTION copy
Definition: actions.h:68
static TOOL_ACTION pickerTool
Definition: actions.h:158
static TOOL_ACTION updateFind
Definition: actions.h:84
static TOOL_ACTION showSymbolEditor
Definition: actions.h:163
static TOOL_ACTION pasteSpecial
Definition: actions.h:70
static TOOL_ACTION findAndReplace
Definition: actions.h:79
static TOOL_ACTION replaceAndFindNext
Definition: actions.h:82
static TOOL_ACTION plot
Definition: actions.h:58
static TOOL_ACTION open
Definition: actions.h:50
static TOOL_ACTION findNext
Definition: actions.h:80
static TOOL_ACTION pageSettings
Definition: actions.h:56
static TOOL_ACTION undo
Definition: actions.h:65
static TOOL_ACTION duplicate
Definition: actions.h:72
static TOOL_ACTION doDelete
Definition: actions.h:73
static TOOL_ACTION quit
Definition: actions.h:59
static TOOL_ACTION save
Definition: actions.h:51
static TOOL_ACTION redo
Definition: actions.h:66
static TOOL_ACTION updateSchematicFromPcb
Definition: actions.h:167
static TOOL_ACTION print
Definition: actions.h:57
static TOOL_ACTION findNextMarker
Definition: actions.h:81
static TOOL_ACTION doNew
Definition: actions.h:47
static TOOL_ACTION cut
Definition: actions.h:67
static TOOL_ACTION refreshPreview
Definition: actions.h:109
static TOOL_ACTION find
Definition: actions.h:78
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
Definition: base_screen.h:85
const Vec GetCenter() const
Definition: box2.h:195
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:81
int m_Threshold
Definition: collector.h:234
Calculates the connectivity of a schematic and generates netlists.
static bool m_allowRealTime
CONNECTION_SUBGRAPH * GetSubgraphForItem(SCH_ITEM *aItem)
A subgraph is a set of items that are electrically connected on a single sheet.
PRIORITY GetDriverPriority()
std::vector< SCH_ITEM * > m_items
void SetWksFileName(const wxString &aFilename)
bool PrjConfigChanged()
Return true if the project configuration was modified.
int ShowQuasiModal()
virtual void PushCommandToUndoList(PICKED_ITEMS_LIST *aItem)
Add a command to undo in the undo list.
virtual int GetRedoCommandCount() const
UNDO_REDO_CONTAINER m_undoList
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...
void ReleaseFile()
Release the current file marked in use.
void ScriptingConsoleEnableDisable()
Toggles 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)
void FocusOnLocation(const VECTOR2I &aPos)
Useful to focus on a particular location, in find functions.
EDA_SEARCH_DATA & GetFindReplaceData()
GAL_TYPE GetBackend() const
Return the type of backend currently used by GAL canvas.
void ForceRefresh()
Force a redraw.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:249
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:74
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:147
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:142
const KIID m_Uuid
Definition: eda_item.h:492
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
void SetForceVisible(bool aEnable)
Set and clear force visible flag used to force the item to be drawn even if it's draw attribute is se...
Definition: eda_item.h:201
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:382
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:100
void ClearBrightened()
Definition: eda_item.h:122
void SetBrightened()
Definition: eda_item.h:119
EDA_ITEM * GetParent() const
Definition: eda_item.h:99
bool IsBrightened() const
Definition: eda_item.h:110
static bool Replace(const EDA_SEARCH_DATA &aSearchData, wxString &aText)
Perform a text replace on aText using the find and replace criteria in aSearchData on items that supp...
Definition: eda_item.cpp:168
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:163
PANEL_ANNOTATE m_AnnotatePanel
static TOOL_ACTION importFPAssignments
Definition: ee_actions.h:176
static TOOL_ACTION repairSchematic
Definition: ee_actions.h:235
static TOOL_ACTION remapSymbols
Definition: ee_actions.h:170
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: ee_actions.h:46
static TOOL_ACTION toggleAnnotateAuto
Definition: ee_actions.h:244
static TOOL_ACTION lineMode90
Definition: ee_actions.h:239
static TOOL_ACTION toggleHiddenPins
Definition: ee_actions.h:216
static TOOL_ACTION highlightNet
Definition: ee_actions.h:252
static TOOL_ACTION addItemsToSel
Selects a list of items (specified as the event parameter)
Definition: ee_actions.h:63
static TOOL_ACTION move
Definition: ee_actions.h:123
static TOOL_ACTION clearHighlight
Definition: ee_actions.h:253
static TOOL_ACTION assignNetclass
Definition: ee_actions.h:164
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
static TOOL_ACTION showPythonConsole
Definition: ee_actions.h:234
static TOOL_ACTION toggleERCWarnings
Definition: ee_actions.h:218
static TOOL_ACTION simTune
Definition: ee_actions.h:249
static TOOL_ACTION toggleERCExclusions
Definition: ee_actions.h:220
static TOOL_ACTION lineModeNext
Definition: ee_actions.h:241
static TOOL_ACTION lineModeFree
Definition: ee_actions.h:238
static TOOL_ACTION editLibSymbolWithLibEdit
Definition: ee_actions.h:174
static TOOL_ACTION toggleERCErrors
Definition: ee_actions.h:219
static TOOL_ACTION highlightNetTool
Definition: ee_actions.h:255
static TOOL_ACTION updateNetHighlighting
Definition: ee_actions.h:254
static TOOL_ACTION exportNetlist
Definition: ee_actions.h:177
static TOOL_ACTION assignFootprints
Definition: ee_actions.h:163
static TOOL_ACTION selectOnPCB
Definition: ee_actions.h:223
static TOOL_ACTION rescueSymbols
Definition: ee_actions.h:169
static TOOL_ACTION toggleHiddenFields
Definition: ee_actions.h:217
static TOOL_ACTION editWithLibEdit
Definition: ee_actions.h:173
static TOOL_ACTION simProbe
Definition: ee_actions.h:248
static TOOL_ACTION exportSymbolsToLibrary
Definition: ee_actions.h:180
static TOOL_ACTION drawSheetOnClipboard
Definition: ee_actions.h:231
static TOOL_ACTION editSymbolFields
Definition: ee_actions.h:155
static TOOL_ACTION annotate
Definition: ee_actions.h:154
static TOOL_ACTION showHierarchy
Definition: ee_actions.h:208
static TOOL_ACTION lineMode45
Definition: ee_actions.h:240
static TOOL_ACTION editSymbolLibraryLinks
Definition: ee_actions.h:156
static TOOL_ACTION saveCurrSheetCopyAs
Definition: ee_actions.h:42
static TOOL_ACTION showPcbNew
Definition: ee_actions.h:175
static TOOL_ACTION generateBOM
Definition: ee_actions.h:178
static TOOL_ACTION schematicSetup
Definition: ee_actions.h:165
static TOOL_ACTION exportSymbolsToNewLibrary
Definition: ee_actions.h:181
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.
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:238
void GuessSelectionCandidates(EE_COLLECTOR &collector, const VECTOR2I &aPos)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
EE_SELECTION & RequestSelection(const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T })
Return either an existing selection (filtered), or the selection at the current cursor position if th...
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.
EDA_ITEM * GetNode(VECTOR2I aPosition)
Finds a connected item at a point (usually the cursor position).
EE_SELECTION & GetSelection()
EDA_ITEM * GetTopLeftItem(bool onlyModules=false) const override
EE_SELECTION_TOOL * m_selectionTool
Definition: ee_tool_base.h:184
Definition: erc.h:48
static const TOOL_EVENT ClearedEvent
Selected item had a property changed (except movement)
Definition: actions.h:207
static const TOOL_EVENT SelectedEvent
Definition: actions.h:205
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:210
static const TOOL_EVENT PointSelectedEvent
Definition: actions.h:204
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:206
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
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:77
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:69
double GetScale() const
Definition: view.h:269
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1574
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition: view.h:393
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hide the item in the view (e.g.
Definition: view.cpp:1533
void UpdateItems()
Iterate through the list of items that asked for updating and updates them.
Definition: view.cpp:1398
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition: view.cpp:1478
void MarkDirty()
Force redraw of view on the next rendering.
Definition: view.h:641
Definition: kiid.h:47
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:66
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:394
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
Definition: kiway.cpp:617
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:98
Define a library symbol object.
Definition: lib_symbol.h:98
LIB_ID GetLibId() const override
Definition: lib_symbol.h:139
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Definition: lib_symbol.cpp:460
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.
static void ReplaceForbiddenChars(std::string &aNetName)
Replace illegal spice net name characters with underscores.
static wxString GetDefaultUserSymbolsPath()
Gets the default path we point users to create projects.
Definition: paths.cpp:97
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 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:82
void SetClickHandler(CLICK_HANDLER aHandler)
Set a handler for mouse click event.
Definition: picker_tool.h:71
void SetSnapping(bool aSnap)
Definition: picker_tool.h:64
void SetCursor(KICURSOR aCursor)
Definition: picker_tool.h:62
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Set a handler for the finalize event.
Definition: picker_tool.h:102
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:125
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
Definition: project.cpp:304
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:60
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:166
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:172
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:129
void SetCurrentSheet(const SCH_SHEET_PATH &aPath) override
Definition: schematic.h:124
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:85
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:117
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
Definition: schematic.cpp:240
SCH_SHEET & Root() const
Definition: schematic.h:90
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
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
bool IsNet() const
SCH_ITEM * Parent() const
wxString Name(bool aIgnoreSheet=false) const
bool IsBus() const
SCH_ITEM * Driver() const
std::vector< std::shared_ptr< SCH_CONNECTION > > & Members()
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 SaveAs(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)
< Highlight net under the cursor.
int ClearHighlight(const TOOL_EVENT &aEvent)
Update net highlighting after an edit.
int EditSymbolFields(const TOOL_EVENT &aEvent)
int HighlightNetCursor(const TOOL_EVENT &aEvent)
int ImportFPAssignments(const TOOL_EVENT &aEvent)
int ChangeLineMode(const TOOL_EVENT &aEvent)
void setClipboardInstances(const SCH_SCREEN *aPastedScreen)
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.
SCH_ITEM * nextMatch(SCH_SCREEN *aScreen, SCH_SHEET_PATH *aSheet, SCH_ITEM *aAfter, EDA_SEARCH_DATA &aData)
Advance the search and returns the next matching item after aAfter.
int Quit(const TOOL_EVENT &aEvent)
int RemapSymbols(const TOOL_EVENT &aEvent)
int FindAndReplace(const TOOL_EVENT &aEvent)
int DrawSheetOnClipboard(const TOOL_EVENT &aEvent)
int RescueSymbols(const TOOL_EVENT &aEvent)
Perform rescue operations to recover old projects from before certain changes were made.
std::string m_localClipboard
std::map< KIID_PATH, SCH_SHEET_INSTANCE > m_clipboardSheetInstances
int AssignNetclass(const TOOL_EVENT &aEvent)
int ExportNetlist(const TOOL_EVENT &aEvent)
int Open(const TOOL_EVENT &aEvent)
int Paste(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)
bool doCopy(bool aUseLocalClipboard=false)
< copy selection to clipboard or to m_localClipboard if aUseLocalClipboard is true
bool searchSupplementaryClipboard(const wxString &aSheetFilename, SCH_SCREEN **aScreen)
int EditWithSymbolEditor(const TOOL_EVENT &aEvent)
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 ShowPcbNew(const TOOL_EVENT &aEvent)
int ReplaceAll(const TOOL_EVENT &aEvent)
std::map< KIID_PATH, SYMBOL_INSTANCE_REFERENCE > m_clipboardSymbolInstances
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 ReplaceAndFindNext(const TOOL_EVENT &aEvent)
void updatePastedSymbol(SCH_SYMBOL *aSymbol, SCH_SCREEN *aPasteScreen, const SCH_SHEET_PATH &aPastePath, const KIID_PATH &aClipPath, bool aForceKeepAnnotations)
int ShowCvpcb(const TOOL_EVENT &aEvent)
SCH_SHEET_PATH updatePastedSheet(const SCH_SHEET_PATH &aPastePath, const KIID_PATH &aClipPath, SCH_SHEET *aSheet, bool aForceKeepAnnotations, SCH_SHEET_LIST *aPastedSheetsSoFar, SCH_REFERENCE_LIST *aPastedSymbolsSoFar)
int RepairSchematic(const TOOL_EVENT &aEvent)
int Cut(const TOOL_EVENT &aEvent)
int UpdateFind(const TOOL_EVENT &aEvent)
Notifies pcbnew about the selected item.
int Save(const TOOL_EVENT &aEvent)
bool RescueSymbolLibTableProject(bool aRunningOnDemand)
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 FindNext(const TOOL_EVENT &aEvent)
int GenerateBOM(const TOOL_EVENT &aEvent)
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()
bool LoadSheetFromFile(SCH_SHEET *aSheet, SCH_SHEET_PATH *aHierarchy, const wxString &aFileName)
Load a the KiCad schematic file aFileName into the sheet aSheet.
Definition: sheet.cpp:105
const SCH_CONNECTION * GetHighlightedConnection() const
void SaveProjectSettings() override
Save changes to the project settings to the project (.pro) file.
void OnOpenCvpcb(wxCommandEvent &event)
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current screen and u...
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
Open a project or set of files given by aFileList.
void UpdateTitle()
Set the main window title bar text.
void AddItemToScreenAndUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItem, bool aUndoAppend)
Add an item to the schematic and adds the changes to the undo/redo container.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void ShowFindReplaceDialog(bool aReplace)
Run the Find or Find & Replace dialog.
void InitSheet(SCH_SHEET *aSheet, const wxString &aNewFilename)
Definition: sheet.cpp:97
void SendSelectItemsToPcb(const std::vector< EDA_ITEM * > &aItems, bool aForce)
Sends items to Pcbnew 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.
void ClearFindReplaceStatus()
SCH_SHEET_PATH & GetCurrentSheet() 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:477
void OnUpdatePCB(wxCommandEvent &event)
void OnOpenPcbnew(wxCommandEvent &event)
void RecalculateConnections(SCH_CLEANUP_FLAGS aCleanupFlags)
Generate the connection data for the entire schematic hierarchy.
void OnAnnotate(wxCommandEvent &event)
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
void OnPageSettingsChange() override
Called when modifying the page settings.
void ShowFindReplaceStatus(const wxString &aMsg, int aStatusTime)
void SetCurrentSheet(const SCH_SHEET_PATH &aSheet)
void SetHighlightedConnection(const SCH_CONNECTION *aConnection)
void DisplayCurrentSheet()
Draw the current sheet on the display.
void PutDataInPreviousState(PICKED_ITEMS_LIST *aList)
Restore an undo or redo command to put data pointed by aList in the previous state.
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false) override
Mark an item for refresh.
void UpdateNetHighlightStatus()
DIALOG_SCH_FIND * m_findReplaceDialog
void UpdateHierarchyNavigator()
Update the hierarchy navigation tree and history.
void SetCrossProbeConnection(const SCH_CONNECTION *aConnection)
Send a connection (net or bus) to Pcbnew for highlighting.
void TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
bool SaveProject(bool aSaveAs=false)
Save the currently-open schematic (including its hierarchy) and associated project.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:50
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: sch_field.cpp:169
int GetId() const
Definition: sch_field.h:116
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:101
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
virtual void SetLastResolvedState(const SCH_ITEM *aItem)
Definition: sch_item.h:408
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:406
bool IsConnectivityDirty() const
Definition: sch_item.h:404
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:146
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:535
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const PROPERTIES *aProperties=nullptr)
Write aSymbol to an existing library located at aLibraryPath.
Definition: sch_plugin.cpp:94
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 AddItem(const SCH_REFERENCE &aItem)
A helper to define a symbol's reference designator in a schematic.
void SetSheetNumber(int aSheetNumber)
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:613
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 BuildClientSheetPathList()
built the list of sheet paths sharing a screen for each screen in use
bool HasNoFullyDefinedLibIds()
Test all of the schematic symbols to see if all LIB_ID objects library nickname is not set.
std::map< wxString, LIB_SYMBOL * > & GetLibSymbols()
Fetch a list of unique LIB_SYMBOL object pointers required to properly render each SCH_SYMBOL in this...
Definition: sch_screen.h:453
void Clear(bool aFree=true)
Delete all draw items and clears the project settings.
Definition: sch_screen.cpp:221
double m_LastZoomLevel
last value for the zoom level, useful in Eeschema when changing the current displayed sheet to reuse ...
Definition: sch_screen.h:527
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:108
const wxString & GetFileName() const
Definition: sch_screen.h:143
const std::vector< SYMBOL_INSTANCE_REFERENCE > & GetSymbolInstances() const
Definition: sch_screen.h:488
const std::vector< SCH_SHEET_INSTANCE > & GetSheetInstances() const
Definition: sch_screen.h:493
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:139
A SCH_PLUGIN derivation for loading schematic files using the new s-expression file format.
void Format(SCH_SHEET *aSheet)
void LoadContent(LINE_READER &aReader, SCH_SHEET *aSheet, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
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.
bool NameExists(const wxString &aSheetName) const
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 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.
void UpdateAllScreenReferences() const
Update all the symbol references for this sheet path.
SCH_SCREEN * LastScreen()
wxString GetPageNumber() const
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:55
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:299
wxString GetPageNumber(const SCH_SHEET_PATH &aInstance) const
Return the sheet page number for aInstance.
Definition: sch_sheet.cpp:1229
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:91
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:706
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:103
void SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1249
bool AddInstance(const SCH_SHEET_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1204
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:161
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:172
Schematic symbol object.
Definition: sch_symbol.h:79
void GetLibPins(std::vector< LIB_PIN * > &aPinsList) const
Populate a vector with all the pins from the library object.
Definition: sch_symbol.cpp:949
bool HasBrightenedPins()
void SetValue(const SCH_SHEET_PATH *sheet, const wxString &aValue)
Definition: sch_symbol.cpp:679
int GetUnit() const
Definition: sch_symbol.h:225
SCH_FIELD * FindField(const wxString &aFieldName, bool aIncludeDefaultFields=true)
Search for a SCH_FIELD with aFieldName.
Definition: sch_symbol.cpp:844
wxString GetSchSymbolLibraryName() const
Definition: sch_symbol.cpp:296
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:516
void ClearBrightenedPins()
void SetFootprint(const SCH_SHEET_PATH *sheet, const wxString &aFootprint)
Definition: sch_symbol.cpp:738
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:776
int GetConvert() const
Definition: sch_symbol.h:267
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
Definition: sch_symbol.cpp:558
void ClearAnnotation(const SCH_SHEET_PATH *aSheetPath, bool aResetPrefix)
Clear exiting symbol annotation.
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve a list of the SCH_PINs for the given sheet path.
Definition: sch_symbol.cpp:972
bool IsMissingLibSymbol() const
Check to see if the library symbol is set to the dummy library symbol.
Definition: sch_symbol.cpp:242
void SetUnit(int aUnit)
Change the unit number to aUnit.
Definition: sch_symbol.cpp:390
const LIB_ID & GetLibId() const
Definition: sch_symbol.h:172
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:812
void SetUnitSelection(const SCH_SHEET_PATH *aSheet, int aUnitSelection)
Set the selected unit of this symbol on one sheet.
Definition: sch_symbol.cpp:625
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:189
void SetLibSymbol(LIB_SYMBOL *aLibSymbol)
Set this schematic symbol library symbol reference to aLibSymbol.
Definition: sch_symbol.cpp:305
virtual void SetTextSpinStyle(TEXT_SPIN_STYLE aSpinStyle)
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:188
void BrightenItem(EDA_ITEM *aItem)
int AddItemToSel(const TOOL_EVENT &aEvent)
void UnbrightenItem(EDA_ITEM *aItem)
EDA_ITEM * Front() const
Definition: selection.h:200
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:252
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:107
static constexpr auto LIBRARY_FIELD
Definition: sim_library.h:34
static std::unique_ptr< SIM_LIBRARY > Create(std::string aFilePath)
Read library from a source file (e.g.
Definition: sim_library.cpp:30
static constexpr auto NAME_FIELD
Definition: sim_library.h:35
static std::unique_ptr< SIM_MODEL > Create(TYPE aType, unsigned aSymbolPinCount)
Definition: sim_model.cpp:611
Implementing SIM_PLOT_FRAME_BASE.
Implement an OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:415
const std::string & GetString()
Definition: richio.h:438
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:241
The symbol library editor main window.
void LoadSymbol(const wxString &aLibrary, const wxString &aSymbol, int Unit)
bool IsSymbolTreeShown() const
void OnToggleSymbolTree(wxCommandEvent &event)
void LoadSymbolFromSchematic(SCH_SYMBOL *aSymbol)
Load a symbol from the schematic to edit in place.
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_PLUGIN obje...
const wxString GetType() const override
Return the type of symbol library table represented by this row.
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
Symbol library viewer main window.
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
Generic, UI-independent tool event.
Definition: tool_event.h:156
bool DisableGridSnapping() const
Definition: tool_event.h:344
T Parameter() const
Return a non-standard parameter assigned to the event.
Definition: tool_event.h:442
bool Matches(const TOOL_EVENT &aEvent) const
Test whether two events match in terms of category & action or command.
Definition: tool_event.h:365
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:88
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:55
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
std::string GetClipboardUTF8() const
Return the information currently stored in the system clipboard.
TOOLS_HOLDER * GetToolHolder() const
Definition: tool_manager.h:296
bool SaveClipboard(const std::string &aTextUTF8)
Store information to the system clipboard.
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:342
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:280
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:320
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:299
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:109
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...
@ REMOVE_ANNOTATIONS
@ UNIQUE_ANNOTATIONS
int InvokeDialogPrintUsingPrinter(SCH_EDIT_FRAME *aCaller)
Create and show DIALOG_PRINT_USING_PRINTER and return whatever DIALOG_PRINT_USING_PRINTER::ShowModal(...
#define _(s)
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:524
#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.
#define HITTEST_THRESHOLD_PIXELS
int InvokeDialogNetList(SCH_EDIT_FRAME *aCaller)
@ LINE_MODE_COUNT
@ FRAME_SCH_SYMBOL_EDITOR
Definition: frame_type.h:35
@ FRAME_SCH_VIEWER
Definition: frame_type.h:36
@ FRAME_SIMULATOR
Definition: frame_type.h:38
const std::string KiCadSymbolLibFileExtension
const std::string KiCadSchematicFileExtension
wxString KiCadSchematicFileWildcard()
wxString KiCadSymbolLibFileWildcard()
#define NET_PLUGIN_CHANGE
Create and shows NETLIST_DIALOG and returns whatever NETLIST_DIALOG::ShowModal() returns.
@ LAYER_ERC_WARN
Definition: layer_ids.h:369
@ LAYER_ERC_EXCLUSION
Definition: layer_ids.h:371
@ LAYER_ERC_ERR
Definition: layer_ids.h:370
@ REPAINT
Item needs to be redrawn.
Definition: view_item.h:52
#define MAX_PAGE_SIZE_EESCHEMA_MILS
Definition: page_info.h:41
#define NAMELESS_PROJECT
default name for nameless projects
Definition: project.h:41
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
@ LOCAL_CLEANUP
@ NO_CLEANUP
@ GLOBAL_CLEANUP
static bool highlightNet(TOOL_MANAGER *aToolMgr, const VECTOR2D &aPosition)
static VECTOR2D CLEAR
static EDA_SEARCH_DATA g_markersOnly
ANNOTATE_ORDER_T
Schematic annotation order options.
ANNOTATE_ALGO_T
Schematic annotation type options.
@ SHEETNAME
Definition: sch_sheet.h:43
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:74
Subclass of SIM_PLOT_FRAME_BASE, which is generated by wxFormBuilder.
wxString UnescapeString(const wxString &aSource)
A simple container for sheet instance information.
static constexpr auto NOT_CONNECTED
Definition: sim_model.h:332
A simple container for schematic symbol instance information.
Definition for symbol library class.
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
@ AS_GLOBAL
Global action (toolbar/main menu event, global shortcut)
Definition: tool_action.h:45
@ TA_UNDO_REDO_PRE
Definition: tool_event.h:101
@ TC_MESSAGE
Definition: tool_event.h:53
@ SCH_LINE_T
Definition: typeinfo.h:145
@ SCH_SYMBOL_T
Definition: typeinfo.h:155
@ SCH_FIELD_T
Definition: typeinfo.h:154
@ SCH_SHEET_T
Definition: typeinfo.h:157
@ SCH_MARKER_T
Definition: typeinfo.h:140
@ SCH_PIN_T
Definition: typeinfo.h:158
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:80
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().
Definition: wx_filename.h:38