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