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 (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <symbol_library.h>
26#include <confirm.h>
27#include <connection_graph.h>
36#include <project_rescue.h>
37#include <erc.h>
38#include <invoke_sch_dialog.h>
39#include <string_utils.h>
40#include <kiway.h>
42#include <paths.h>
43#include <pgm_base.h>
46#include <project_sch.h>
47#include <sch_edit_frame.h>
49#include <sch_line.h>
50#include <sch_junction.h>
51#include <sch_bus_entry.h>
52#include <sch_shape.h>
53#include <sch_painter.h>
54#include <sch_sheet.h>
55#include <sch_sheet_pin.h>
56#include <sch_view.h>
57#include <schematic.h>
58#include <sch_commit.h>
59#include <advanced_config.h>
61#include <sim/simulator_frame.h>
62#include <sim/spice_generator.h>
63#include <sim/sim_lib_mgr.h>
65#include <symbol_viewer_frame.h>
66#include <tool/common_tools.h>
67#include <tool/picker_tool.h>
68#include <tool/tool_manager.h>
69#include <tools/ee_actions.h>
70#include <tools/ee_selection.h>
73#include <tools/sch_move_tool.h>
75#include <eda_list_dialog.h>
77#include <wx_filename.h>
78#include <sch_sheet_path.h>
79#include <wx/filedlg.h>
80#include <wx/treectrl.h>
81
82
84{
86 return 0;
87}
88
89
91{
93 return 0;
94}
95
96
98{
100 return 0;
101}
102
103
105{
106 m_frame->SaveProject( true );
107 return 0;
108}
109
110
112{
113 SCH_SHEET* curr_sheet = m_frame->GetCurrentSheet().Last();
114 wxFileName curr_fn = curr_sheet->GetFileName();
115 wxFileDialog dlg( m_frame, _( "Schematic Files" ), curr_fn.GetPath(),
116 curr_fn.GetFullName(), KiCadSchematicFileWildcard(),
117 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
118
119 if( dlg.ShowModal() == wxID_CANCEL )
120 return false;
121
122 wxString newFilename = EnsureFileExtension( dlg.GetPath(), KiCadSchematicFileExtension );
123
124 m_frame->saveSchematicFile( curr_sheet, newFilename );
125 return 0;
126}
127
128
130{
131 SCHEMATIC& schematic = m_frame->Schematic();
132 SCH_SHEET& root = schematic.Root();
133
134 if( m_frame->GetCurrentSheet().Last() != &root )
135 {
138
139 // Store the current zoom level into the current screen before switching
141
142 SCH_SHEET_PATH rootSheetPath;
143 rootSheetPath.push_back( &root );
144 m_frame->SetCurrentSheet( rootSheetPath );
146
147 wxSafeYield();
148 }
149
150 wxString msg;
151 msg.Printf( _( "Revert '%s' (and all sub-sheets) to last version saved?" ),
152 schematic.GetFileName() );
153
154 if( !IsOK( m_frame, msg ) )
155 return false;
156
157 SCH_SCREENS screenList( schematic.Root() );
158
159 for( SCH_SCREEN* screen = screenList.GetFirst(); screen; screen = screenList.GetNext() )
160 screen->SetContentModified( false ); // do not prompt the user for changes
161
163 m_frame->OpenProjectFiles( std::vector<wxString>( 1, schematic.GetFileName() ), KICTL_REVERT );
164
165 return 0;
166}
167
168
170{
172 return 0;
173}
174
175
177{
178 PICKED_ITEMS_LIST undoCmd;
180 ITEM_PICKER wrapper( m_frame->GetScreen(), undoItem, UNDO_REDO::PAGESETTINGS );
181
182 undoCmd.PushItem( wrapper );
183 undoCmd.SetDescription( _( "Page Settings" ) );
184 m_frame->SaveCopyInUndoList( undoCmd, UNDO_REDO::PAGESETTINGS, false, false );
185
189
190 if( dlg.ShowModal() == wxID_OK )
191 {
192 // Update text variables
196
197 m_frame->OnModify();
198 }
199 else
200 {
202 }
203
204 return 0;
205}
206
207
209{
210 SCH_SCREENS schematic( m_frame->Schematic().Root() );
211
212 if( schematic.HasNoFullyDefinedLibIds() )
213 RescueLegacyProject( true );
214 else
216
217 return 0;
218}
219
220
221bool SCH_EDITOR_CONTROL::RescueLegacyProject( bool aRunningOnDemand )
222{
225
226 return rescueProject( rescuer, aRunningOnDemand );
227}
228
229
231{
235
236 return rescueProject( rescuer, aRunningOnDemand );
237}
238
239
240bool SCH_EDITOR_CONTROL::rescueProject( RESCUER& aRescuer, bool aRunningOnDemand )
241{
242 if( !RESCUER::RescueProject( m_frame, aRescuer, aRunningOnDemand ) )
243 return false;
244
245 if( aRescuer.GetCandidateCount() )
246 {
247 KIWAY_PLAYER* viewer = m_frame->Kiway().Player( FRAME_SCH_VIEWER, false );
248
249 if( viewer )
250 static_cast<SYMBOL_VIEWER_FRAME*>( viewer )->ReCreateLibList();
251
252 if( aRunningOnDemand )
253 {
254 SCH_SCREENS schematic( m_frame->Schematic().Root() );
255
256 schematic.UpdateSymbolLinks();
258 }
259
261 m_frame->SyncView();
263 m_frame->OnModify();
264 }
265
266 return true;
267}
268
269
271{
272 DIALOG_SYMBOL_REMAP dlgRemap( m_frame );
273
274 dlgRemap.ShowQuasiModal();
275
276 m_frame->GetCanvas()->Refresh( true );
277
278 return 0;
279}
280
281
283{
285 return 0;
286}
287
288
290{
292
293 dlg.ShowModal();
294
295 // save project config if the prj config has changed:
296 if( dlg.PrjConfigChanged() )
297 m_frame->OnModify();
298
299 return 0;
300}
301
302
304{
305 m_frame->Close( false );
306 return 0;
307}
308
309
311{
312 doCrossProbeSchToPcb( aEvent, false );
313 return 0;
314}
315
316
318{
319 doCrossProbeSchToPcb( aEvent, true );
320 return 0;
321}
322
323
324void SCH_EDITOR_CONTROL::doCrossProbeSchToPcb( const TOOL_EVENT& aEvent, bool aForce )
325{
326 // Don't get in an infinite loop SCH -> PCB -> SCH -> PCB -> SCH -> ...
328 return;
329
331
332 EE_SELECTION& selection = aForce ? selTool->RequestSelection() : selTool->GetSelection();
333
334 m_frame->SendSelectItemsToPcb( selection.GetItemsSortedBySelectionOrder(), aForce );
335}
336
337
339{
340 bool savePowerSymbols = IsOK( m_frame, _( "Include power symbols in schematic to the library?" ) );
341
342 bool createNew = aEvent.IsAction( &EE_ACTIONS::exportSymbolsToNewLibrary );
343
344 SCH_REFERENCE_LIST symbols;
345 m_frame->Schematic().GetSheets().GetSymbols( symbols, savePowerSymbols );
346
347 std::map<LIB_ID, LIB_SYMBOL*> libSymbols;
348 std::map<LIB_ID, std::vector<SCH_SYMBOL*>> symbolMap;
349
350 for( size_t i = 0; i < symbols.GetCount(); ++i )
351 {
352 SCH_SYMBOL* symbol = symbols[i].GetSymbol();
353 LIB_SYMBOL* libSymbol = symbol->GetLibSymbolRef().get();
354 LIB_ID id = libSymbol->GetLibId();
355
356 if( libSymbols.count( id ) )
357 {
358 wxASSERT_MSG( libSymbols[id]->Compare( *libSymbol, LIB_ITEM::COMPARE_FLAGS::ERC ) == 0,
359 "Two symbols have the same LIB_ID but are different!" );
360 }
361 else
362 {
363 libSymbols[id] = libSymbol;
364 }
365
366 symbolMap[id].emplace_back( symbol );
367 }
368
370
371 wxString targetLib;
372
373 if( createNew )
374 {
375 wxFileName fn;
377
378 if( !libTable ) // Cancelled by user
379 return 0;
380
383 ( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() ),
385 {
386 return 0;
387 }
388
389 targetLib = fn.GetName();
390
391 if( libTable->HasLibrary( targetLib, false ) )
392 {
393 DisplayError( m_frame, wxString::Format( _( "Library '%s' already exists." ),
394 targetLib ) );
395 return 0;
396 }
397
398 // if the "new" library is in fact an existing library and the used asked for replacing
399 // it by the recreated lib, erase it:
400 if( fn.FileExists() )
401 wxRemoveFile( fn.GetFullPath() );
402
403 if( !mgr.CreateLibrary( fn.GetFullPath(), libTable ) )
404 {
405 DisplayError( m_frame, wxString::Format( _( "Could not add library '%s'." ),
406 targetLib ) );
407 return 0;
408 }
409 }
410 else
411 {
412 targetLib = m_frame->SelectLibraryFromList();
413 }
414
415 if( targetLib.IsEmpty() )
416 return 0;
417
418 bool map = IsOK( m_frame, _( "Update symbols in schematic to refer to new library?" ) );
419 bool append = false;
420
421 SYMBOL_LIB_TABLE_ROW* row = mgr.GetLibrary( targetLib );
422 SCH_IO_MGR::SCH_FILE_T type = SCH_IO_MGR::EnumFromStr( row->GetType() );
423 SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( type ) );
424
425 wxFileName dest = row->GetFullURI( true );
426 dest.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
427
428 for( const std::pair<const LIB_ID, LIB_SYMBOL*>& it : libSymbols )
429 {
430 LIB_SYMBOL* origSym = it.second;
431 LIB_SYMBOL* newSym = origSym->Flatten().release();
432
433 pi->SaveSymbol( dest.GetFullPath(), newSym );
434
435 if( map )
436 {
437 LIB_ID id = it.first;
438 id.SetLibNickname( targetLib );
439
440 for( SCH_SYMBOL* symbol : symbolMap[it.first] )
441 {
442 m_frame->SaveCopyInUndoList( m_frame->GetScreen(), symbol, UNDO_REDO::CHANGED,
443 append, false );
444 symbol->SetLibId( id );
445 append = true;
446 }
447 }
448 }
449
450 // Save the modified symbol library table. We need to look this up by name in each table to find
451 // whether the new library is a global or project entity as the code above to choose the library
452 // returns a different type depending on whether a global or project library is chosen.
454 SYMBOL_LIB_TABLE* projectTable = nullptr;
455
456 if( !m_frame->Prj().IsNullProject() )
457 projectTable = PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() );
458
459 if( globalTable->FindRow( targetLib ) )
460 {
461 try
462 {
463 wxString globalTablePath = SYMBOL_LIB_TABLE::GetGlobalTableFileName();
464 globalTable->Save( globalTablePath );
465 }
466 catch( const IO_ERROR& ioe )
467 {
468 wxString msg;
469 msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
470 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
471 }
472 }
473 else if( projectTable && projectTable->FindRow( targetLib ) )
474 {
475 try
476 {
477 wxString projectPath = m_frame->Prj().GetProjectPath();
478 wxFileName projectTableFn( projectPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
479 projectTable->Save( projectTableFn.GetFullPath() );
480 }
481 catch( const IO_ERROR& ioe )
482 {
483 wxString msg;
484 msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
485 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
486 }
487 }
488
489 if( append )
490 {
491 std::set<SCH_SCREEN*> processedScreens;
493
494 for( SCH_SHEET_PATH& sheet : sheets )
495 {
496 SCH_SCREEN* screen = sheet.LastScreen();
497
498 if( processedScreens.find( ( screen ) ) == processedScreens.end() )
499 {
500 processedScreens.insert( screen );
501 screen->UpdateSymbolLinks();
502 }
503 }
504
505 m_frame->OnModify();
506 }
507
508 return 0;
509}
510
511
512#define HITTEST_THRESHOLD_PIXELS 5
513
515{
518 false );
519
520 if( !simFrame ) // Defensive coding; shouldn't happen.
521 return 0;
522
523 if( wxWindow* blocking_win = simFrame->Kiway().GetBlockingDialog() )
524 blocking_win->Close( true );
525
526 // Deactivate other tools; particularly important if another PICKER is currently running
527 Activate();
528
529 picker->SetCursor( KICURSOR::VOLTAGE_PROBE );
530 picker->SetSnapping( false );
531
532 picker->SetClickHandler(
533 [this, simFrame]( const VECTOR2D& aPosition )
534 {
536 EDA_ITEM* item = selTool->GetNode( aPosition );
538
539 if( !item )
540 return false;
541
542 if( item->Type() == SCH_PIN_T )
543 {
544 try
545 {
546 LIB_PIN* pin = static_cast<SCH_PIN*>( item )->GetLibPin();
547 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item->GetParent() );
548
549 wxString msg;
550 WX_STRING_REPORTER reporter( &msg );
551 SIM_LIB_MGR mgr( &m_frame->Prj() );
552
553 SIM_MODEL& model = mgr.CreateModel( &sheet, *symbol, reporter ).model;
554
555 if( reporter.HasMessage() )
556 THROW_IO_ERROR( msg );
557
558 SPICE_ITEM spiceItem;
559 spiceItem.refName = symbol->GetRef( &sheet ).ToStdString();
560 std::vector<std::string> currentNames =
561 model.SpiceGenerator().CurrentNames( spiceItem );
562
563 if( currentNames.size() == 0 )
564 {
565 return true;
566 }
567 else if( currentNames.size() == 1 )
568 {
569 simFrame->AddCurrentTrace( currentNames.at( 0 ) );
570 return true;
571 }
572
573 int modelPinIndex = model.FindModelPinIndex( pin->GetNumber().ToStdString() );
574
575 if( modelPinIndex != SIM_MODEL::PIN::NOT_CONNECTED )
576 {
577 wxString name = currentNames.at( modelPinIndex );
578 simFrame->AddCurrentTrace( name );
579 }
580 }
581 catch( const IO_ERROR& e )
582 {
584 }
585 }
586 else if( item->IsType( { SCH_ITEM_LOCATE_WIRE_T } )
587 || item->IsType( { SCH_JUNCTION_T } ) )
588 {
589 if( SCH_CONNECTION* conn = static_cast<SCH_ITEM*>( item )->Connection() )
590 {
591 std::string spiceNet = UnescapeString( conn->Name() ).ToStdString();
593
594 simFrame->AddVoltageTrace( wxString::Format( "V(%s)", spiceNet ) );
595 }
596 }
597
598 return true;
599 } );
600
601 picker->SetMotionHandler(
602 [this, picker]( const VECTOR2D& aPos )
603 {
604 EE_COLLECTOR collector;
605 collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
606 collector.Collect( m_frame->GetScreen(), { SCH_ITEM_LOCATE_WIRE_T,
607 SCH_PIN_T,
608 SCH_SHEET_PIN_T }, aPos );
609
611 selectionTool->GuessSelectionCandidates( collector, aPos );
612
613 EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
614 SCH_LINE* wire = dynamic_cast<SCH_LINE*>( item );
615
616 const SCH_CONNECTION* conn = nullptr;
617
618 if( wire )
619 {
620 item = nullptr;
621 conn = wire->Connection();
622 }
623
624 if( item && item->Type() == SCH_PIN_T )
625 picker->SetCursor( KICURSOR::CURRENT_PROBE );
626 else
627 picker->SetCursor( KICURSOR::VOLTAGE_PROBE );
628
629 if( m_pickerItem != item )
630 {
631 if( m_pickerItem )
632 selectionTool->UnbrightenItem( m_pickerItem );
633
634 m_pickerItem = item;
635
636 if( m_pickerItem )
637 selectionTool->BrightenItem( m_pickerItem );
638 }
639
640 wxString connectionName = ( conn ) ? conn->Name() : wxString( wxS( "" ) );
641
642 if( m_frame->GetHighlightedConnection() != connectionName )
643 {
644 m_frame->SetHighlightedConnection( connectionName );
645
646 TOOL_EVENT dummyEvent;
647 UpdateNetHighlighting( dummyEvent );
648 }
649 } );
650
651 picker->SetFinalizeHandler(
652 [this]( const int& aFinalState )
653 {
654 if( m_pickerItem )
655 m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
656
657 if( !m_frame->GetHighlightedConnection().IsEmpty() )
658 {
659 m_frame->SetHighlightedConnection( wxEmptyString );
660
661 TOOL_EVENT dummyEvent;
662 UpdateNetHighlighting( dummyEvent );
663 }
664
665 // Wake the selection tool after exiting to ensure the cursor gets updated
667 } );
668
670
671 return 0;
672}
673
674
676{
678
679 // Deactivate other tools; particularly important if another PICKER is currently running
680 Activate();
681
682 picker->SetCursor( KICURSOR::TUNE );
683 picker->SetSnapping( false );
684
685 picker->SetClickHandler(
686 [this]( const VECTOR2D& aPosition )
687 {
689 EDA_ITEM* item = nullptr;
690 selTool->SelectPoint( aPosition, { SCH_SYMBOL_T, SCH_FIELD_T }, &item );
691
692 if( !item )
693 return false;
694
695 if( item->Type() != SCH_SYMBOL_T )
696 {
697 item = item->GetParent();
698
699 if( item->Type() != SCH_SYMBOL_T )
700 return false;
701 }
702
703 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
704 SCH_SHEET_PATH sheetPath = symbol->Schematic()->CurrentSheet();
705 KIWAY_PLAYER* simFrame = m_frame->Kiway().Player( FRAME_SIMULATOR, false );
706
707 if( simFrame )
708 {
709 if( wxWindow* blocking_win = simFrame->Kiway().GetBlockingDialog() )
710 blocking_win->Close( true );
711
712 static_cast<SIMULATOR_FRAME*>( simFrame )->AddTuner( sheetPath, symbol );
713 }
714
715 // We do not really want to keep a symbol selected in schematic,
716 // so clear the current selection
717 selTool->ClearSelection();
718 return true;
719 } );
720
721 picker->SetMotionHandler(
722 [this]( const VECTOR2D& aPos )
723 {
724 EE_COLLECTOR collector;
725 collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
726 collector.Collect( m_frame->GetScreen(), { SCH_SYMBOL_T, SCH_FIELD_T }, aPos );
727
729 selectionTool->GuessSelectionCandidates( collector, aPos );
730
731 EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
732
733 if( m_pickerItem != item )
734 {
735 if( m_pickerItem )
736 selectionTool->UnbrightenItem( m_pickerItem );
737
738 m_pickerItem = item;
739
740 if( m_pickerItem )
741 selectionTool->BrightenItem( m_pickerItem );
742 }
743 } );
744
745 picker->SetFinalizeHandler(
746 [this]( const int& aFinalState )
747 {
748 if( m_pickerItem )
749 m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
750
751 // Wake the selection tool after exiting to ensure the cursor gets updated
752 // and deselect previous selection from simulator to avoid any issue
753 // ( avoid crash in some cases when the SimTune tool is deselected )
755 selectionTool->ClearSelection();
757 } );
758
760
761 return 0;
762}
763
764
765// A singleton reference for clearing the highlight
767
768
769static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition )
770{
771 SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( aToolMgr->GetToolHolder() );
772 EE_SELECTION_TOOL* selTool = aToolMgr->GetTool<EE_SELECTION_TOOL>();
773 SCH_EDITOR_CONTROL* editorControl = aToolMgr->GetTool<SCH_EDITOR_CONTROL>();
774 SCH_CONNECTION* conn = nullptr;
775 SCH_ITEM* item = nullptr;
776 bool retVal = true;
777
778 if( aPosition != CLEAR )
779 {
780 ERC_TESTER erc( &editFrame->Schematic() );
781
782 if( erc.TestDuplicateSheetNames( false ) > 0 )
783 {
784 wxMessageBox( _( "Error: duplicate sub-sheet names found in current sheet." ) );
785 retVal = false;
786 }
787 else
788 {
789 item = static_cast<SCH_ITEM*>( selTool->GetNode( aPosition ) );
790 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
791
792 if( item )
793 {
794 if( item->IsConnectivityDirty() )
795 editFrame->RecalculateConnections( nullptr, NO_CLEANUP );
796
797 if( item->Type() == SCH_FIELD_T )
798 symbol = dynamic_cast<SCH_SYMBOL*>( item->GetParent() );
799
800 if( symbol && symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->IsPower() )
801 {
802 std::vector<SCH_PIN*> pins = symbol->GetPins();
803
804 if( pins.size() == 1 )
805 conn = pins[0]->Connection();
806 }
807 else
808 {
809 conn = item->Connection();
810 }
811 }
812 }
813 }
814
815 wxString connName = ( conn ) ? conn->Name() : wxString( wxS( "" ) );
816
817 if( !conn )
818 {
819 editFrame->SetStatusText( wxT( "" ) );
820 editFrame->SendCrossProbeClearHighlight();
821 editFrame->SetHighlightedConnection( wxEmptyString );
822 editorControl->SetHighlightBusMembers( false );
823 }
824 else
825 {
826 NET_NAVIGATOR_ITEM_DATA itemData( editFrame->GetCurrentSheet(), item );
827
828 if( connName != editFrame->GetHighlightedConnection() )
829 {
830 editorControl->SetHighlightBusMembers( false );
831 editFrame->SetCrossProbeConnection( conn );
832 editFrame->SetHighlightedConnection( connName, &itemData );
833 }
834 else
835 {
836 editorControl->SetHighlightBusMembers( !editorControl->GetHighlightBusMembers() );
837
838 if( item != editFrame->GetSelectedNetNavigatorItem() )
839 editFrame->SelectNetNavigatorItem( &itemData );
840 }
841 }
842
843 editFrame->UpdateNetHighlightStatus();
844
846 editorControl->UpdateNetHighlighting( dummy );
847
848 return retVal;
849}
850
851
853{
855 VECTOR2D cursorPos = controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
856
857 highlightNet( m_toolMgr, cursorPos );
858
859 return 0;
860}
861
862
864{
866
867 return 0;
868}
869
870
872{
874 SCHEMATIC& schematic = m_frame->Schematic();
876
877 const SCH_CONNECTION* conn = nullptr;
878 VECTOR2D connPos;
879
880 for( EDA_ITEM* item : selectionTool->GetSelection() )
881 {
882 conn = static_cast<SCH_ITEM*>( item )->Connection();
883 connPos = item->GetPosition();
884
885 if( conn )
886 break;
887 }
888
889 if( !conn )
890 {
891 m_frame->ShowInfoBarError( _( "No net selected." ) );
892 return 0;
893 }
894
895 // Remove selection in favor of highlighting so the whole net is highlighted
896 selectionTool->ClearSelection();
897 highlightNet( m_toolMgr, connPos );
898
899 wxString netName = conn->Name();
900
901 if( conn->IsBus() )
902 {
903 wxString prefix;
904
905 if( NET_SETTINGS::ParseBusVector( netName, &prefix, nullptr ) )
906 {
907 netName = prefix + wxT( "*" );
908 }
909 else if( NET_SETTINGS::ParseBusGroup( netName, &prefix, nullptr ) )
910 {
911 netName = prefix + wxT( ".*" );
912 }
913 }
914 else if( !conn->Driver() || CONNECTION_SUBGRAPH::GetDriverPriority( conn->Driver() )
916 {
917 m_frame->ShowInfoBarError( _( "Net must be labeled to assign a netclass." ) );
919 return 0;
920 }
921
922 DIALOG_ASSIGN_NETCLASS dlg( m_frame, netName, schematic.GetNetClassAssignmentCandidates(),
923 [&]( const std::vector<wxString>& aNetNames )
924 {
925 for( SCH_ITEM* item : screen->Items() )
926 {
927 bool redraw = item->IsBrightened();
928 SCH_CONNECTION* itemConn = item->Connection();
929
930 if( itemConn && alg::contains( aNetNames, itemConn->Name() ) )
931 item->SetBrightened();
932 else
933 item->ClearBrightened();
934
935 redraw |= item->IsBrightened();
936
937 if( item->Type() == SCH_SYMBOL_T )
938 {
939 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
940
941 redraw |= symbol->HasBrightenedPins();
942
943 symbol->ClearBrightenedPins();
944
945 for( SCH_PIN* pin : symbol->GetPins() )
946 {
947 SCH_CONNECTION* pin_conn = pin->Connection();
948
949 if( pin_conn && alg::contains( aNetNames, pin_conn->Name() ) )
950 {
951 pin->SetBrightened();
952 redraw = true;
953 }
954 }
955 }
956 else if( item->Type() == SCH_SHEET_T )
957 {
958 for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( item )->GetPins() )
959 {
960 SCH_CONNECTION* pin_conn = pin->Connection();
961
962 redraw |= pin->IsBrightened();
963
964 if( pin_conn && alg::contains( aNetNames, pin_conn->Name() ) )
965 pin->SetBrightened();
966 else
967 pin->ClearBrightened();
968
969 redraw |= pin->IsBrightened();
970 }
971 }
972
973 if( redraw )
974 getView()->Update( item, KIGFX::VIEW_UPDATE_FLAGS::REPAINT );
975 }
976
978 } );
979
980 if( dlg.ShowModal() )
981 {
982 getView()->UpdateAllItemsConditionally(
983 [&]( KIGFX::VIEW_ITEM* aItem ) -> int
984 {
985 int flags = 0;
986
987 // Netclass coloured items
988 //
989 if( dynamic_cast<SCH_LINE*>( aItem ) )
990 flags |= KIGFX::REPAINT;
991 else if( dynamic_cast<SCH_JUNCTION*>( aItem ) )
992 flags |= KIGFX::REPAINT;
993 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( aItem ) )
994 flags |= KIGFX::REPAINT;
995
996 // Items that might reference an item's netclass name
997 //
998 if( SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem ) )
999 {
1000 item->RunOnChildren(
1001 [&flags]( SCH_ITEM* aChild )
1002 {
1003 EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aChild );
1004
1005 if( text && text->HasTextVars() )
1006 {
1007 text->ClearRenderCache();
1008 text->ClearBoundingBoxCache();
1009 flags |= KIGFX::GEOMETRY | KIGFX::REPAINT;
1010 }
1011 } );
1012
1013 EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
1014
1015 if( text && text->HasTextVars() )
1016 {
1017 text->ClearRenderCache();
1018 text->ClearBoundingBoxCache();
1020 }
1021
1022 if( flags & KIGFX::GEOMETRY )
1023 m_frame->GetScreen()->Update( item, false ); // Refresh RTree
1024 }
1025
1026 return flags;
1027 } );
1028 }
1029
1030 highlightNet( m_toolMgr, CLEAR );
1031 return 0;
1032}
1033
1034
1036{
1037 wxCHECK( m_frame, 0 );
1038
1039 const SCH_SHEET_PATH& sheetPath = m_frame->GetCurrentSheet();
1041 CONNECTION_GRAPH* connectionGraph = m_frame->Schematic().ConnectionGraph();
1042 wxString selectedName = m_frame->GetHighlightedConnection();
1043
1044 std::set<wxString> connNames;
1045 std::vector<EDA_ITEM*> itemsToRedraw;
1046
1047 wxCHECK( screen && connectionGraph, 0 );
1048
1049 if( !selectedName.IsEmpty() )
1050 {
1051 connNames.emplace( selectedName );
1052
1053 CONNECTION_SUBGRAPH* sg = connectionGraph->FindSubgraphByName( selectedName, sheetPath );
1054
1055 if( sg && m_highlightBusMembers )
1056 {
1057 for( const SCH_ITEM* item : sg->GetItems() )
1058 {
1059 wxCHECK2( item, continue );
1060
1061 SCH_CONNECTION* connection = item->Connection();
1062
1063 wxCHECK2( connection, continue );
1064
1065 for( const std::shared_ptr<SCH_CONNECTION>& member : connection->AllMembers() )
1066 {
1067 if( member )
1068 connNames.emplace( member->Name() );
1069 }
1070 }
1071 }
1072 }
1073
1074 for( SCH_ITEM* item : screen->Items() )
1075 {
1076 wxCHECK2( item, continue );
1077
1078 if( !item->IsConnectable() )
1079 continue;
1080
1081 SCH_ITEM* redrawItem = nullptr;
1082
1083 if( item->Type() == SCH_SYMBOL_T )
1084 {
1085 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1086
1087 wxCHECK2( symbol, continue );
1088
1089 for( SCH_PIN* pin : symbol->GetPins() )
1090 {
1091 SCH_CONNECTION* pin_conn = pin->Connection();
1092
1093 wxCHECK2( pin_conn, continue );
1094
1095 if( !pin->IsBrightened() && connNames.count( pin_conn->Name() ) )
1096 {
1097 pin->SetBrightened();
1098 redrawItem = symbol;
1099 }
1100 else if( pin->IsBrightened() && !connNames.count( pin_conn->Name() ) )
1101 {
1102 pin->ClearBrightened();
1103 redrawItem = symbol;
1104 }
1105 }
1106
1107 if( symbol->IsPower() )
1108 {
1109 wxCHECK2( symbol->GetPins().size(), continue );
1110
1111 SCH_CONNECTION* pinConn = symbol->GetPins()[0]->Connection();
1112
1113 wxCHECK2( pinConn, continue );
1114
1115 std::vector<SCH_FIELD>& fields = symbol->GetFields();
1116
1117 for( int id : { REFERENCE_FIELD, VALUE_FIELD } )
1118 {
1119 if( !fields[id].IsVisible() )
1120 continue;
1121
1122 if( !fields[id].IsBrightened() && connNames.count( pinConn->Name() ) )
1123 {
1124 fields[id].SetBrightened();
1125 redrawItem = symbol;
1126 }
1127 else if( fields[id].IsBrightened() && !connNames.count( pinConn->Name() ) )
1128 {
1129 fields[id].ClearBrightened();
1130 redrawItem = symbol;
1131 }
1132 }
1133 }
1134 }
1135 else if( item->Type() == SCH_SHEET_T )
1136 {
1137 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
1138
1139 wxCHECK2( sheet, continue );
1140
1141 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
1142 {
1143 wxCHECK2( pin, continue );
1144
1145 SCH_CONNECTION* pin_conn = pin->Connection();
1146
1147 wxCHECK2( pin_conn, continue );
1148
1149 if( !pin->IsBrightened() && connNames.count( pin_conn->Name() ) )
1150 {
1151 pin->SetBrightened();
1152 redrawItem = sheet;
1153 }
1154 else if( pin->IsBrightened() && !connNames.count( pin_conn->Name() ) )
1155 {
1156 pin->ClearBrightened();
1157 redrawItem = sheet;
1158 }
1159 }
1160 }
1161 else
1162 {
1163 SCH_CONNECTION* itemConn = item->Connection();
1164
1165 wxCHECK2( itemConn, continue );
1166
1167 if( !item->IsBrightened() && connNames.count( itemConn->Name() ) )
1168 {
1169 item->SetBrightened();
1170 redrawItem = item;
1171 }
1172 else if( item->IsBrightened() && !connNames.count( itemConn->Name() ) )
1173 {
1174 item->ClearBrightened();
1175 redrawItem = item;
1176 }
1177 }
1178
1179 if( redrawItem )
1180 itemsToRedraw.push_back( redrawItem );
1181 }
1182
1183 if( itemsToRedraw.size() )
1184 {
1185 // Be sure highlight change will be redrawn
1186 KIGFX::VIEW* view = getView();
1187
1188 for( EDA_ITEM* redrawItem : itemsToRedraw )
1190
1192 }
1193
1194 return 0;
1195}
1196
1197
1199{
1201
1202 // Deactivate other tools; particularly important if another PICKER is currently running
1203 Activate();
1204
1205 picker->SetCursor( KICURSOR::BULLSEYE );
1206 picker->SetSnapping( false );
1207
1208 picker->SetClickHandler(
1209 [this] ( const VECTOR2D& aPos )
1210 {
1211 return highlightNet( m_toolMgr, aPos );
1212 } );
1213
1215
1216 return 0;
1217}
1218
1219
1221{
1222 if( m_frame->GetUndoCommandCount() <= 0 )
1223 return 0;
1224
1225 // Inform tools that undo command was issued
1227
1228 // Get the old list
1230
1231 m_frame->PutDataInPreviousState( undo_list );
1235
1236 // Now push the old command to the RedoList
1237 undo_list->ReversePickersListOrder();
1238 m_frame->PushCommandToRedoList( undo_list );
1239
1240 m_toolMgr->GetTool<EE_SELECTION_TOOL>()->RebuildSelection();
1241
1243 m_frame->OnModify();
1244
1245 return 0;
1246}
1247
1248
1250{
1251 if( m_frame->GetRedoCommandCount() == 0 )
1252 return 0;
1253
1254 // Inform tools that undo command was issued
1256
1257 /* Get the old list */
1259
1260 /* Redo the command: */
1262
1263 /* Put the old list in UndoList */
1266
1270
1271 m_toolMgr->GetTool<EE_SELECTION_TOOL>()->RebuildSelection();
1272
1274 m_frame->OnModify();
1275
1276 return 0;
1277}
1278
1279
1280bool SCH_EDITOR_CONTROL::doCopy( bool aUseDuplicateClipboard )
1281{
1283 EE_SELECTION& selection = selTool->RequestSelection();
1284 SCHEMATIC& schematic = m_frame->Schematic();
1285
1286 if( selection.Empty() )
1287 return false;
1288
1289 if( aUseDuplicateClipboard )
1290 m_duplicateIsHoverSelection = selection.IsHover();
1291
1292 selection.SetScreen( m_frame->GetScreen() );
1294
1295 for( EDA_ITEM* item : selection )
1296 {
1297 if( item->Type() == SCH_SHEET_T )
1298 {
1299 SCH_SHEET* sheet = (SCH_SHEET*) item;
1300 m_supplementaryClipboard[ sheet->GetFileName() ] = sheet->GetScreen();
1301 }
1302 else if( item->Type() == SCH_FIELD_T && selection.IsHover() )
1303 {
1304 // Most of the time the user is trying to duplicate the parent symbol
1305 // and the field text is in it
1306 selection.Add( item->GetParent() );
1307 }
1308 }
1309
1310 STRING_FORMATTER formatter;
1311 SCH_SEXPR_PLUGIN plugin;
1312 SCH_SHEET_LIST hierarchy = schematic.GetSheets();
1314
1315 plugin.Format( &selection, &selPath, schematic, &formatter, true );
1316
1317 if( selection.IsHover() )
1319
1320 if( aUseDuplicateClipboard )
1321 {
1322 m_duplicateClipboard = formatter.GetString();
1323 return true;
1324 }
1325
1326 return m_toolMgr->SaveClipboard( formatter.GetString() );
1327}
1328
1329
1330bool SCH_EDITOR_CONTROL::searchSupplementaryClipboard( const wxString& aSheetFilename,
1331 SCH_SCREEN** aScreen )
1332{
1333 if( m_supplementaryClipboard.count( aSheetFilename ) > 0 )
1334 {
1335 *aScreen = m_supplementaryClipboard[ aSheetFilename ];
1336 return true;
1337 }
1338
1339 return false;
1340}
1341
1342
1344{
1345 doCopy( true ); // Use the local clipboard
1346 Paste( aEvent );
1347
1348 return 0;
1349}
1350
1351
1353{
1354 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
1355
1356 if( textEntry )
1357 {
1358 textEntry->Cut();
1359 return 0;
1360 }
1361
1362 if( doCopy() )
1364
1365 return 0;
1366}
1367
1368
1370{
1371 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
1372
1373 if( textEntry )
1374 {
1375 textEntry->Copy();
1376 return 0;
1377 }
1378
1379 doCopy();
1380
1381 return 0;
1382}
1383
1384
1386 const SCH_SHEET_PATH& aPastePath,
1387 const KIID_PATH& aClipPath,
1388 bool aForceKeepAnnotations )
1389{
1390 wxCHECK( aSymbol && aPasteScreen, /* void */ );
1391
1392 KIID_PATH clipItemPath = aClipPath;
1393
1394 wxString reference, value, footprint;
1395 int unit;
1396
1397 clipItemPath.push_back( aSymbol->m_Uuid );
1398
1399 if( m_clipboardSymbolInstances.count( clipItemPath ) > 0 )
1400 {
1401 SCH_SYMBOL_INSTANCE instance = m_clipboardSymbolInstances.at( clipItemPath );
1402
1403 unit = instance.m_Unit;
1404 reference = instance.m_Reference;
1405 }
1406 else
1407 {
1408 // Some legacy versions saved value fields escaped. While we still do in the symbol
1409 // editor, we don't anymore in the schematic, so be sure to unescape them.
1410 SCH_FIELD* valueField = aSymbol->GetField( VALUE_FIELD );
1411 valueField->SetText( UnescapeString( valueField->GetText() ) );
1412
1413 // Pasted from notepad or an older instance of eeschema. Use the values in the fields
1414 // instead.
1415 reference = aSymbol->GetField( REFERENCE_FIELD )->GetText();
1416 value = aSymbol->GetField( VALUE_FIELD )->GetText();
1417 footprint = aSymbol->GetField( FOOTPRINT_FIELD )->GetText();
1418 unit = aSymbol->GetUnit();
1419 }
1420
1421 if( aForceKeepAnnotations && !reference.IsEmpty() )
1422 aSymbol->SetRef( &aPastePath, reference );
1423 else
1424 aSymbol->ClearAnnotation( &aPastePath, false );
1425
1426 // We might clear annotations but always leave the original unit number from the paste.
1427 aSymbol->SetUnitSelection( &aPastePath, unit );
1428 aSymbol->SetUnit( unit );
1429}
1430
1431
1433 const KIID_PATH& aClipPath, SCH_SHEET* aSheet,
1434 bool aForceKeepAnnotations,
1435 SCH_SHEET_LIST* aPastedSheetsSoFar,
1436 SCH_REFERENCE_LIST* aPastedSymbolsSoFar )
1437{
1438 wxCHECK( aSheet && aPastedSheetsSoFar && aPastedSymbolsSoFar, aPastePath );
1439
1440 SCH_SHEET_PATH sheetPath = aPastePath;
1441 sheetPath.push_back( aSheet );
1442
1443 aPastedSheetsSoFar->push_back( sheetPath );
1444
1445 if( aSheet->GetScreen() == nullptr )
1446 return sheetPath; // We can only really set the page number but not load any items
1447
1448 for( SCH_ITEM* item : aSheet->GetScreen()->Items() )
1449 {
1450 if( item->Type() == SCH_SYMBOL_T )
1451 {
1452 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1453
1454 updatePastedSymbol( symbol, aSheet->GetScreen(), sheetPath, aClipPath,
1455 aForceKeepAnnotations );
1456 }
1457 else if( item->Type() == SCH_SHEET_T )
1458 {
1459 SCH_SHEET* subsheet = static_cast<SCH_SHEET*>( item );
1460
1461 KIID_PATH newClipPath = aClipPath;
1462 newClipPath.push_back( subsheet->m_Uuid );
1463
1464 updatePastedSheet( sheetPath, newClipPath, subsheet, aForceKeepAnnotations,
1465 aPastedSheetsSoFar, aPastedSymbolsSoFar );
1466
1467 SCH_SHEET_PATH subSheetPath = sheetPath;
1468
1469 subSheetPath.push_back( subsheet );
1470 subSheetPath.GetSymbols( *aPastedSymbolsSoFar );
1471 }
1472 }
1473
1474 return sheetPath;
1475}
1476
1477
1479{
1480 wxCHECK( aPastedSheet, /* void */ );
1481
1482 for( const SCH_SHEET_INSTANCE& sheetInstance : aPastedSheet->GetInstances() )
1483 {
1484 KIID_PATH pathWithSheet = sheetInstance.m_Path;
1485
1486 pathWithSheet.push_back( aPastedSheet->m_Uuid );
1487 m_clipboardSheetInstances[pathWithSheet] = sheetInstance;
1488 }
1489
1490 const SCH_SCREEN* screen = aPastedSheet->GetScreen();
1491
1492 wxCHECK( screen, /* void */ );
1493
1494 for( SCH_ITEM* item : screen->Items() )
1495 {
1496 if( item->Type() == SCH_SHEET_T )
1497 {
1498 const SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
1499
1500 wxCHECK2( sheet, continue );
1501
1502 setPastedSheetInstances( sheet );
1503 }
1504 }
1505}
1506
1507
1509{
1510 for( SCH_SCREEN* screen = aScreenList.GetFirst(); screen; screen = aScreenList.GetNext() )
1511 {
1512 for( const SCH_ITEM* item : screen->Items() )
1513 {
1514 if( item->Type() == SCH_SYMBOL_T )
1515 {
1516 const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( item );
1517
1518 wxCHECK2( symbol, continue );
1519
1520 for( const SCH_SYMBOL_INSTANCE& symbolInstance : symbol->GetInstanceReferences() )
1521 {
1522 KIID_PATH pathWithSymbol = symbolInstance.m_Path;
1523
1524 pathWithSymbol.push_back( symbol->m_Uuid );
1525
1526 m_clipboardSymbolInstances[pathWithSymbol] = symbolInstance;
1527 }
1528 }
1529 }
1530 }
1531}
1532
1533
1535{
1536 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
1537
1538 if( textEntry )
1539 {
1540 textEntry->Paste();
1541 return 0;
1542 }
1543
1545 std::string content;
1546 VECTOR2I eventPos;
1547
1548 if( aEvent.IsAction( &ACTIONS::duplicate ) )
1549 content = m_duplicateClipboard;
1550 else
1551 content = m_toolMgr->GetClipboardUTF8();
1552
1553 if( content.empty() )
1554 return 0;
1555
1556 if( aEvent.IsAction( &ACTIONS::duplicate ) )
1557 eventPos = getViewControls()->GetCursorPosition( false );
1558
1559 STRING_LINE_READER reader( content, "Clipboard" );
1560 SCH_SEXPR_PLUGIN plugin;
1561
1562 SCH_SHEET tempSheet;
1563 SCH_SCREEN* tempScreen = new SCH_SCREEN( &m_frame->Schematic() );
1564
1566 int annotateStartNum = m_frame->Schematic().Settings().m_AnnotateStartNum;
1567
1568 // Screen object on heap is owned by the sheet.
1569 tempSheet.SetScreen( tempScreen );
1570
1571 try
1572 {
1573 plugin.LoadContent( reader, &tempSheet );
1574 }
1575 catch( IO_ERROR& )
1576 {
1577 // If it wasn't content, then paste as text object.
1578 SCH_TEXT* text_item = new SCH_TEXT( VECTOR2I( 0, 0 ), content );
1579 tempScreen->Append( text_item );
1580 }
1581
1582 SCH_SCREENS tempScreens( tempSheet );
1583
1586
1587 // Save pasted sheet and symbol instances.
1588 setPastedSheetInstances( &tempSheet );
1589 setPastedSymbolInstances( tempScreens );
1590
1591 tempScreen->MigrateSimModels();
1592
1593 PASTE_MODE pasteMode = annotate.automatic ? PASTE_MODE::RESPECT_OPTIONS
1594 : PASTE_MODE::REMOVE_ANNOTATIONS;
1595
1596 if( aEvent.IsAction( &ACTIONS::pasteSpecial ) )
1597 {
1598 DIALOG_PASTE_SPECIAL dlg( m_frame, &pasteMode );
1599
1600 if( dlg.ShowModal() == wxID_CANCEL )
1601 return 0;
1602 }
1603
1604 bool forceKeepAnnotations = pasteMode != PASTE_MODE::REMOVE_ANNOTATIONS;
1605
1606 // SCH_SEXP_PLUGIN added the items to the paste screen, but not to the view or anything
1607 // else. Pull them back out to start with.
1608 SCH_COMMIT commit( m_toolMgr );
1609 EDA_ITEMS loadedItems;
1610 std::vector<SCH_ITEM*> sortedLoadedItems;
1611 bool sheetsPasted = false;
1612 SCH_SHEET_LIST hierarchy = m_frame->Schematic().GetSheets();
1613 SCH_SHEET_PATH& pasteRoot = m_frame->GetCurrentSheet();
1614 wxFileName destFn = pasteRoot.Last()->GetFileName();
1615
1616 if( destFn.IsRelative() )
1617 destFn.MakeAbsolute( m_frame->Prj().GetProjectPath() );
1618
1619 // List of paths in the hierarchy that refer to the destination sheet of the paste
1620 SCH_SHEET_LIST sheetPathsForScreen = hierarchy.FindAllSheetsForScreen( pasteRoot.LastScreen() );
1621 sheetPathsForScreen.SortByPageNumbers();
1622
1623 // Build a list of screens from the current design (to avoid loading sheets that already exist)
1624 std::map<wxString, SCH_SCREEN*> loadedScreens;
1625
1626 for( const SCH_SHEET_PATH& item : hierarchy )
1627 {
1628 if( item.LastScreen() )
1629 loadedScreens[item.Last()->GetFileName()] = item.LastScreen();
1630 }
1631
1632 // Build symbol list for reannotation of duplicates
1633 SCH_REFERENCE_LIST existingRefs;
1634 hierarchy.GetSymbols( existingRefs );
1635 existingRefs.SortByReferenceOnly();
1636
1637 // Build UUID map for fetching last-resolved-properties
1638 std::map<KIID, EDA_ITEM*> itemMap;
1639 hierarchy.FillItemMap( itemMap );
1640
1641 // Keep track of pasted sheets and symbols for the different paths to the hierarchy.
1642 std::map<SCH_SHEET_PATH, SCH_REFERENCE_LIST> pastedSymbols;
1643 std::map<SCH_SHEET_PATH, SCH_SHEET_LIST> pastedSheets;
1644
1645 for( SCH_ITEM* item : tempScreen->Items() )
1646 {
1647 if( item->Type() == SCH_SHEET_T )
1648 sortedLoadedItems.push_back( item );
1649 else
1650 loadedItems.push_back( item );
1651 }
1652
1653 sort( sortedLoadedItems.begin(), sortedLoadedItems.end(),
1654 []( SCH_ITEM* firstItem, SCH_ITEM* secondItem )
1655 {
1656 SCH_SHEET* firstSheet = static_cast<SCH_SHEET*>( firstItem );
1657 SCH_SHEET* secondSheet = static_cast<SCH_SHEET*>( secondItem );
1658 return StrNumCmp( firstSheet->GetName(), secondSheet->GetName(), false ) < 0;
1659 });
1660
1661
1662 for( SCH_ITEM* item : sortedLoadedItems )
1663 {
1664 loadedItems.push_back( item );
1665
1666 if( item->Type() == SCH_SHEET_T )
1667 {
1668 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
1669 SCH_FIELD& nameField = sheet->GetFields()[SHEETNAME];
1670 wxString baseName = nameField.GetText();
1671 wxFileName srcFn = sheet->GetFileName();
1672
1673 if( srcFn.IsRelative() )
1674 srcFn.MakeAbsolute( m_frame->Prj().GetProjectPath() );
1675
1676 SCH_SHEET_LIST sheetHierarchy( sheet );
1677
1678 if( hierarchy.TestForRecursion( sheetHierarchy, destFn.GetFullPath( wxPATH_UNIX ) ) )
1679 {
1680 auto msg = wxString::Format( _( "The pasted sheet '%s'\n"
1681 "was dropped because the destination already has "
1682 "the sheet or one of its subsheets as a parent." ),
1683 sheet->GetFileName() );
1684 DisplayError( m_frame, msg );
1685 loadedItems.pop_back();
1686 }
1687 }
1688 }
1689
1690 // Remove the references from our temporary screen to prevent freeing on the DTOR
1691 tempScreen->Clear( false );
1692
1693 for( EDA_ITEM* item : loadedItems )
1694 {
1695 KIID_PATH clipPath( wxT( "/" ) ); // clipboard is at root
1696
1697 if( item->Type() == SCH_SYMBOL_T )
1698 {
1699 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1700
1701 // The library symbol gets set from the cached library symbols in the current
1702 // schematic not the symbol libraries. The cached library symbol may have
1703 // changed from the original library symbol which would cause the copy to
1704 // be incorrect.
1705 SCH_SCREEN* currentScreen = m_frame->GetScreen();
1706
1707 wxCHECK2( currentScreen, continue );
1708
1709 auto it = currentScreen->GetLibSymbols().find( symbol->GetSchSymbolLibraryName() );
1710 auto end = currentScreen->GetLibSymbols().end();
1711
1712 if( it == end )
1713 {
1714 // If can't find library definition in the design, use the pasted library
1715 it = tempScreen->GetLibSymbols().find( symbol->GetSchSymbolLibraryName() );
1716 end = tempScreen->GetLibSymbols().end();
1717 }
1718
1719 LIB_SYMBOL* libSymbol = nullptr;
1720
1721 if( it != end )
1722 {
1723 libSymbol = new LIB_SYMBOL( *it->second );
1724 symbol->SetLibSymbol( libSymbol );
1725 }
1726
1727 for( SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
1728 updatePastedSymbol( symbol, tempScreen, sheetPath, clipPath, forceKeepAnnotations );
1729
1730 // Assign a new KIID
1731 const_cast<KIID&>( item->m_Uuid ) = KIID();
1732
1733 // Make sure pins get a new UUID
1734 for( SCH_PIN* pin : symbol->GetPins() )
1735 const_cast<KIID&>( pin->m_Uuid ) = KIID();
1736
1737 for( SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
1738 {
1739 // Ignore symbols from a non-existant library.
1740 if( libSymbol )
1741 {
1742 SCH_REFERENCE schReference( symbol, libSymbol, sheetPath );
1743 schReference.SetSheetNumber( sheetPath.GetVirtualPageNumber() );
1744 pastedSymbols[sheetPath].AddItem( schReference );
1745 }
1746 }
1747 }
1748 else if( item->Type() == SCH_SHEET_T )
1749 {
1750 SCH_SHEET* sheet = (SCH_SHEET*) item;
1751 SCH_FIELD& nameField = sheet->GetFields()[SHEETNAME];
1752 wxString baseName = nameField.GetText();
1753 wxString candidateName = baseName;
1754 wxString number;
1755
1756 while( !baseName.IsEmpty() && wxIsdigit( baseName.Last() ) )
1757 {
1758 number = baseName.Last() + number;
1759 baseName.RemoveLast();
1760 }
1761
1762 // Update hierarchy to include any other sheets we already added, avoiding
1763 // duplicate sheet names
1764 hierarchy = m_frame->Schematic().GetSheets();
1765
1766 //@todo: it might be better to just iterate through the sheet names
1767 // in this screen instead of the whole hierarchy.
1768 int uniquifier = std::max( 0, wxAtoi( number ) ) + 1;
1769
1770 while( hierarchy.NameExists( candidateName ) )
1771 candidateName = wxString::Format( wxT( "%s%d" ), baseName, uniquifier++ );
1772
1773 nameField.SetText( candidateName );
1774
1775 wxFileName fn = sheet->GetFileName();
1776 SCH_SCREEN* existingScreen = nullptr;
1777
1778 sheet->SetParent( pasteRoot.Last() );
1779 sheet->SetScreen( nullptr );
1780
1781 if( !fn.IsAbsolute() )
1782 {
1783 wxFileName currentSheetFileName = pasteRoot.LastScreen()->GetFileName();
1784 fn.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS,
1785 currentSheetFileName.GetPath() );
1786 }
1787
1788 // Try to find the screen for the pasted sheet by several means
1789 if( !m_frame->Schematic().Root().SearchHierarchy( fn.GetFullPath( wxPATH_UNIX ),
1790 &existingScreen ) )
1791 {
1792 if( loadedScreens.count( sheet->GetFileName() ) > 0 )
1793 existingScreen = loadedScreens.at( sheet->GetFileName() );
1794 else
1795 searchSupplementaryClipboard( sheet->GetFileName(), &existingScreen );
1796 }
1797
1798 if( existingScreen )
1799 {
1800 sheet->SetScreen( existingScreen );
1801 }
1802 else
1803 {
1804 if( !m_frame->LoadSheetFromFile( sheet, &pasteRoot, fn.GetFullPath() ) )
1805 m_frame->InitSheet( sheet, sheet->GetFileName() );
1806 }
1807
1808 sheetsPasted = true;
1809
1810 // Push it to the clipboard path while it still has its old KIID
1811 clipPath.push_back( sheet->m_Uuid );
1812
1813 // Assign a new KIID to the pasted sheet
1814 const_cast<KIID&>( sheet->m_Uuid ) = KIID();
1815
1816 // Make sure pins get a new UUID
1817 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
1818 const_cast<KIID&>( pin->m_Uuid ) = KIID();
1819
1820 // Once we have our new KIID we can update all pasted instances. This will either
1821 // reset the annotations or copy "kept" annotations from the supplementary clipboard.
1822 for( SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
1823 {
1824 SCH_SHEET_PATH subPath = updatePastedSheet( sheetPath, clipPath, sheet,
1825 ( forceKeepAnnotations && annotate.automatic ),
1826 &pastedSheets[sheetPath],
1827 &pastedSymbols[sheetPath] );
1828
1829 subPath.GetSymbols( pastedSymbols[sheetPath] );
1830 }
1831 }
1832 else
1833 {
1834 SCH_ITEM* srcItem = dynamic_cast<SCH_ITEM*>( itemMap[ item->m_Uuid ] );
1835 SCH_ITEM* destItem = dynamic_cast<SCH_ITEM*>( item );
1836
1837 // Everything gets a new KIID
1838 const_cast<KIID&>( item->m_Uuid ) = KIID();
1839
1840 if( srcItem && destItem )
1841 {
1842 destItem->SetConnectivityDirty( true );
1843 destItem->SetLastResolvedState( srcItem );
1844 }
1845 }
1846
1847 // Lines need both ends selected for a move after paste so the whole line moves.
1848 if( item->Type() == SCH_LINE_T )
1849 item->SetFlags( STARTPOINT | ENDPOINT );
1850
1851 item->SetFlags( IS_NEW | IS_PASTED | IS_MOVING );
1852
1853 if( !m_frame->GetScreen()->CheckIfOnDrawList( (SCH_ITEM*) item ) ) // don't want a loop!
1854 m_frame->AddToScreen( item, m_frame->GetScreen() );
1855
1856 commit.Added( (SCH_ITEM*) item, m_frame->GetScreen() );
1857
1858 // Start out hidden so the pasted items aren't "ghosted" in their original location
1859 // before being moved to the current location.
1860 getView()->Hide( item, true );
1861 }
1862
1863 sheetPathsForScreen.SortByPageNumbers();
1864
1865 if( sheetsPasted )
1866 {
1867 // Update page numbers: Find next free numeric page number
1868 for( SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
1869 {
1870 pastedSheets[sheetPath].SortByPageNumbers();
1871
1872 for( SCH_SHEET_PATH& pastedSheet : pastedSheets[sheetPath] )
1873 {
1874 int page = 1;
1875 wxString pageNum = wxString::Format( "%d", page );
1876
1877 while( hierarchy.PageNumberExists( pageNum ) )
1878 pageNum = wxString::Format( "%d", ++page );
1879
1880 pastedSheet.SetPageNumber( pageNum );
1881 hierarchy.push_back( pastedSheet );
1882 }
1883 }
1884
1887
1888 // Get a version with correct sheet numbers since we've pasted sheets,
1889 // we'll need this when annotating next
1890 hierarchy = m_frame->Schematic().GetSheets();
1891 }
1892
1893 std::map<SCH_SHEET_PATH, SCH_REFERENCE_LIST> annotatedSymbols;
1894
1895 // Update the list of symbol instances that satisfy the annotation criteria.
1896 for( const SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
1897 {
1898 for( size_t i = 0; i < pastedSymbols[sheetPath].GetCount(); i++ )
1899 {
1900 if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS
1901 || pasteMode == PASTE_MODE::RESPECT_OPTIONS
1902 || pastedSymbols[sheetPath][i].AlwaysAnnotate() )
1903 {
1904 annotatedSymbols[sheetPath].AddItem( pastedSymbols[sheetPath][i] );
1905 }
1906 }
1907 }
1908
1909 if( !annotatedSymbols.empty() )
1910 {
1911 for( SCH_SHEET_PATH& path : sheetPathsForScreen )
1912 {
1913 annotatedSymbols[path].SortByReferenceOnly();
1914
1915 if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS )
1916 {
1917 annotatedSymbols[path].ReannotateDuplicates( existingRefs );
1918 }
1919 else
1920 {
1921 annotatedSymbols[path].ReannotateByOptions( (ANNOTATE_ORDER_T) annotate.sort_order,
1922 (ANNOTATE_ALGO_T) annotate.method,
1923 annotateStartNum, existingRefs, false,
1924 &hierarchy );
1925 }
1926
1927 annotatedSymbols[path].UpdateAnnotation();
1928
1929 // Update existing refs for next iteration
1930 for( size_t i = 0; i < annotatedSymbols[path].GetCount(); i++ )
1931 existingRefs.AddItem( annotatedSymbols[path][i] );
1932 }
1933 }
1934
1936
1937 // The copy operation creates instance paths that are not valid for the current project or
1938 // saved as part of another project. Prune them now so they do not accumulate in the saved
1939 // schematic file.
1940 SCH_SCREENS allScreens( m_frame->Schematic().Root() );
1941
1944
1945 // Now clear the previous selection, select the pasted items, and fire up the "move" tool.
1948
1949 EE_SELECTION& selection = selTool->GetSelection();
1950
1951 if( !selection.Empty() )
1952 {
1953 if( aEvent.IsAction( &ACTIONS::duplicate ) )
1954 {
1955 int closest_dist = INT_MAX;
1956
1957 auto processPt =
1958 [&]( const VECTOR2I& pt )
1959 {
1960 int dist = ( eventPos - pt ).EuclideanNorm();
1961
1962 if( dist < closest_dist )
1963 {
1964 selection.SetReferencePoint( pt );
1965 closest_dist = dist;
1966 }
1967 };
1968
1969 // Prefer connection points (which should remain on grid)
1970 for( EDA_ITEM* item : selection.Items() )
1971 {
1972 SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item );
1973 LIB_PIN* lib_pin = dynamic_cast<LIB_PIN*>( item );
1974
1975 if( sch_item && sch_item->IsConnectable() )
1976 {
1977 for( const VECTOR2I& pt : sch_item->GetConnectionPoints() )
1978 processPt( pt );
1979 }
1980 else if( lib_pin )
1981 {
1982 processPt( lib_pin->GetPosition() );
1983 }
1984 }
1985
1986 // Only process other points if we didn't find any connection points
1987 if( closest_dist == INT_MAX )
1988 {
1989 for( EDA_ITEM* item : selection.Items() )
1990 {
1991 switch( item->Type() )
1992 {
1993 case SCH_LINE_T:
1994 processPt( static_cast<SCH_LINE*>( item )->GetStartPoint() );
1995 processPt( static_cast<SCH_LINE*>( item )->GetEndPoint() );
1996 break;
1997
1998 case SCH_SHAPE_T:
1999 {
2000 SCH_SHAPE* shape = static_cast<SCH_SHAPE*>( item );
2001
2002 switch( shape->GetShape() )
2003 {
2004 case SHAPE_T::RECTANGLE:
2005 for( const VECTOR2I& pt : shape->GetRectCorners() )
2006 processPt( pt );
2007
2008 break;
2009
2010 case SHAPE_T::CIRCLE:
2011 processPt( shape->GetCenter() );
2012 break;
2013
2014 case SHAPE_T::POLY:
2015 for( int ii = 0; ii < shape->GetPolyShape().TotalVertices(); ++ii )
2016 processPt( shape->GetPolyShape().CVertex( ii ) );
2017
2018 break;
2019
2020 default:
2021 processPt( shape->GetStart() );
2022 processPt( shape->GetEnd() );
2023 break;
2024 }
2025
2026 break;
2027 }
2028
2029 default:
2030 processPt( item->GetPosition() );
2031 break;
2032 }
2033 }
2034 }
2035
2036 selection.SetIsHover( m_duplicateIsHoverSelection );
2037 }
2038 else
2039 {
2040 SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.GetTopLeftItem() );
2041
2042 selection.SetReferencePoint( item->GetPosition() );
2043 }
2044
2046 commit.Push( _( "Paste" ) );
2047 else
2048 commit.Revert();
2049 }
2050
2051 return 0;
2052}
2053
2054
2056{
2058 EE_SELECTION& selection = selTool->RequestSelection( { SCH_SYMBOL_T } );
2059 SCH_SYMBOL* symbol = nullptr;
2060 SYMBOL_EDIT_FRAME* symbolEditor;
2061
2062 if( selection.GetSize() >= 1 )
2063 symbol = (SCH_SYMBOL*) selection.Front();
2064
2065 if( selection.IsHover() )
2067
2068 if( !symbol || symbol->GetEditFlags() != 0 )
2069 return 0;
2070
2071 if( symbol->IsMissingLibSymbol() )
2072 {
2073 m_frame->ShowInfoBarError( _( "Symbols with broken library symbol links cannot "
2074 "be edited." ) );
2075 return 0;
2076 }
2077
2079 symbolEditor = (SYMBOL_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
2080
2081 if( symbolEditor )
2082 {
2083 if( wxWindow* blocking_win = symbolEditor->Kiway().GetBlockingDialog() )
2084 blocking_win->Close( true );
2085
2086 if( aEvent.IsAction( &EE_ACTIONS::editWithLibEdit ) )
2087 {
2088 symbolEditor->LoadSymbolFromSchematic( symbol );
2089 }
2091 {
2092 symbolEditor->LoadSymbol( symbol->GetLibId(), symbol->GetUnit(), symbol->GetConvert() );
2093
2094 if( !symbolEditor->IsSymbolTreeShown() )
2095 {
2096 wxCommandEvent evt;
2097 symbolEditor->OnToggleSymbolTree( evt );
2098 }
2099 }
2100 }
2101
2102 return 0;
2103}
2104
2105
2107{
2108 wxCommandEvent dummy;
2110 return 0;
2111}
2112
2113
2115{
2116 wxCommandEvent dummy;
2118 return 0;
2119}
2120
2121
2123{
2125
2126 wxCHECK( dlg, 0 );
2127
2128 // Needed at least on Windows. Raise() is not enough
2129 dlg->Show( true );
2130
2131 // Bring it to the top if already open. Dual monitor users need this.
2132 dlg->Raise();
2133
2134 dlg->ShowEditTab();
2135
2136 return 0;
2137}
2138
2139
2141{
2144
2145 return 0;
2146}
2147
2148
2150{
2151 wxCommandEvent dummy;
2153 return 0;
2154}
2155
2156
2158{
2159 wxCommandEvent dummy;
2161 return 0;
2162}
2163
2164
2166{
2168 dlg.ShowModal();
2169 return 0;
2170}
2171
2172
2174{
2175 int result = NET_PLUGIN_CHANGE;
2176
2177 // If a plugin is removed or added, rebuild and reopen the new dialog
2178 while( result == NET_PLUGIN_CHANGE )
2179 result = InvokeDialogNetList( m_frame );
2180
2181 return 0;
2182}
2183
2184
2186{
2187 EditSymbolFields( aEvent );
2189 return 0;
2190}
2191
2192
2194{
2196 return 0;
2197}
2198
2199
2201{
2204 return 0;
2205}
2206
2207
2209{
2210 getEditFrame<SCH_EDIT_FRAME>()->ToggleSearch();
2211 return 0;
2212}
2213
2214
2216{
2217 getEditFrame<SCH_EDIT_FRAME>()->ToggleSchematicHierarchy();
2218 return 0;
2219}
2220
2221
2223{
2224 getEditFrame<SCH_EDIT_FRAME>()->ToggleNetNavigator();
2225 return 0;
2226}
2227
2228
2230{
2231 getEditFrame<SCH_EDIT_FRAME>()->ToggleProperties();
2232 return 0;
2233}
2234
2235
2237{
2240
2243
2244 return 0;
2245}
2246
2247
2249{
2252
2255
2256 return 0;
2257}
2258
2259
2261{
2264
2267
2268 return 0;
2269}
2270
2271
2273{
2276
2279
2280 return 0;
2281}
2282
2283
2285{
2288
2291
2292 return 0;
2293}
2294
2295
2297{
2300
2303
2304 return 0;
2305}
2306
2307
2309{
2312
2316
2317 return 0;
2318}
2319
2320
2322{
2325
2329
2330 return 0;
2331}
2332
2333
2335{
2338 return 0;
2339}
2340
2341
2343{
2345 m_frame->eeconfig()->m_Drawing.line_mode %= LINE_MODE::LINE_MODE_COUNT;
2347 return 0;
2348}
2349
2350
2352{
2355 return 0;
2356}
2357
2358
2360{
2363 return 0;
2364}
2365
2366
2368{
2369
2371 return 0;
2372}
2373
2374
2376{
2377 int errors = 0;
2378 wxString details;
2379 bool quiet = aEvent.Parameter<bool>();
2380
2381 // Repair duplicate IDs.
2382 std::map<KIID, EDA_ITEM*> ids;
2383 int duplicates = 0;
2384
2385 auto processItem =
2386 [&]( EDA_ITEM* aItem )
2387 {
2388 auto it = ids.find( aItem->m_Uuid );
2389
2390 if( it != ids.end() && it->second != aItem )
2391 {
2392 duplicates++;
2393 const_cast<KIID&>( aItem->m_Uuid ) = KIID();
2394 }
2395
2396 ids[ aItem->m_Uuid ] = aItem;
2397 };
2398
2399 // Symbol IDs are the most important, so give them the first crack at "claiming" a
2400 // particular KIID.
2401
2402 for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().GetSheets() )
2403 {
2404 SCH_SCREEN* screen = sheet.LastScreen();
2405
2406 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
2407 {
2408 processItem( item );
2409
2410 for( SCH_PIN* pin : static_cast<SCH_SYMBOL*>( item )->GetPins( &sheet ) )
2411 processItem( pin );
2412 }
2413 }
2414
2415 for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().GetSheets() )
2416 {
2417 SCH_SCREEN* screen = sheet.LastScreen();
2418
2419 for( SCH_ITEM* item : screen->Items() )
2420 {
2421 processItem( item );
2422
2423 item->RunOnChildren(
2424 [&]( SCH_ITEM* aChild )
2425 {
2426 processItem( item );
2427 } );
2428 }
2429 }
2430
2431 /*******************************
2432 * Your test here
2433 */
2434
2435 /*******************************
2436 * Inform the user
2437 */
2438
2439 if( duplicates )
2440 {
2441 errors += duplicates;
2442 details += wxString::Format( _( "%d duplicate IDs replaced.\n" ), duplicates );
2443 }
2444
2445 if( errors )
2446 {
2447 m_frame->OnModify();
2448
2449 wxString msg = wxString::Format( _( "%d potential problems repaired." ), errors );
2450
2451 if( !quiet )
2452 DisplayInfoMessage( m_frame, msg, details );
2453 }
2454 else if( !quiet )
2455 {
2456 DisplayInfoMessage( m_frame, _( "No errors found." ) );
2457 }
2458
2459 return 0;
2460}
2461
2462
2464{
2465 if( !Pgm().GetCommonSettings()->m_Input.hotkey_feedback )
2466 return 0;
2467
2468 GRID_SETTINGS& gridSettings = m_toolMgr->GetSettings()->m_Window.grid;
2469 int currentIdx = m_toolMgr->GetSettings()->m_Window.grid.last_size_idx;
2470
2471 wxArrayString gridsLabels;
2472
2473 for( const GRID& grid : gridSettings.grids )
2474 gridsLabels.Add( grid.UserUnitsMessageText( m_frame ) );
2475
2476 if( !m_frame->GetHotkeyPopup() )
2478
2480
2481 if( popup )
2482 popup->Popup( _( "Grid" ), gridsLabels, currentIdx );
2483
2484 return 0;
2485}
2486
2487
2489{
2490 Go( &SCH_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() );
2491 Go( &SCH_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() );
2492 Go( &SCH_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
2499 Go( &SCH_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() );
2500 Go( &SCH_EDITOR_CONTROL::Quit, ACTIONS::quit.MakeEvent() );
2501
2504
2510
2513
2519
2521
2522 Go( &SCH_EDITOR_CONTROL::Undo, ACTIONS::undo.MakeEvent() );
2523 Go( &SCH_EDITOR_CONTROL::Redo, ACTIONS::redo.MakeEvent() );
2524 Go( &SCH_EDITOR_CONTROL::Cut, ACTIONS::cut.MakeEvent() );
2525 Go( &SCH_EDITOR_CONTROL::Copy, ACTIONS::copy.MakeEvent() );
2529
2531
2546
2551
2565
2567
2569
2574}
const char * name
Definition: DXF_plotter.cpp:57
static TOOL_ACTION updatePcbFromSchematic
Definition: actions.h:175
static TOOL_ACTION paste
Definition: actions.h:69
static TOOL_ACTION cancelInteractive
Definition: actions.h:63
static TOOL_ACTION revert
Definition: actions.h:55
static TOOL_ACTION saveAs
Definition: actions.h:52
static TOOL_ACTION copy
Definition: actions.h:68
static TOOL_ACTION pickerTool
Definition: actions.h:165
static TOOL_ACTION showSymbolEditor
Definition: actions.h:172
static TOOL_ACTION pasteSpecial
Definition: actions.h:70
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:78
static TOOL_ACTION undo
Definition: actions.h:65
static TOOL_ACTION duplicate
Definition: actions.h:73
static TOOL_ACTION doDelete
Definition: actions.h:74
static TOOL_ACTION quit
Definition: actions.h:59
static TOOL_ACTION save
Definition: actions.h:51
static TOOL_ACTION redo
Definition: actions.h:66
static TOOL_ACTION updateSchematicFromPcb
Definition: actions.h:176
static TOOL_ACTION print
Definition: actions.h:57
static TOOL_ACTION showProperties
Definition: actions.h:177
static TOOL_ACTION doNew
Definition: actions.h:47
static TOOL_ACTION cut
Definition: actions.h:67
static TOOL_ACTION refreshPreview
Definition: actions.h:113
WINDOW_SETTINGS m_Window
Definition: app_settings.h:169
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 & Added(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
Definition: commit.h:84
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.
A subgraph is a set of items that are electrically connected on a single sheet.
PRIORITY GetDriverPriority()
const std::set< SCH_ITEM * > & GetItems() const
Provide a read-only reference to the items in the subgraph.
void SetWksFileName(const wxString &aFilename)
bool PrjConfigChanged()
Return true if the project configuration was modified.
bool Show(bool show) override
int ShowQuasiModal()
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()
Toggles the scripting console visibility.
bool LibraryFileBrowser(bool doOpen, wxFileName &aFilename, const wxString &wildcard, const wxString &ext, bool isDirectory=false, bool aIsGlobal=false, const wxString &aGlobalPath=wxEmptyString)
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:85
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:239
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:129
const KIID m_Uuid
Definition: eda_item.h:482
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:100
void ClearBrightened()
Definition: eda_item.h:119
EDA_ITEM * GetParent() const
Definition: eda_item.h:99
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:258
SHAPE_T GetShape() const
Definition: eda_shape.h:119
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:151
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:126
std::vector< VECTOR2I > GetRectCorners() const
Definition: eda_shape.cpp:1132
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:95
PANEL_ANNOTATE m_AnnotatePanel
static TOOL_ACTION importFPAssignments
Definition: ee_actions.h:175
static TOOL_ACTION repairSchematic
Definition: ee_actions.h:253
static TOOL_ACTION remapSymbols
Definition: ee_actions.h:169
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: ee_actions.h:46
static TOOL_ACTION toggleAnnotateAuto
Definition: ee_actions.h:262
static TOOL_ACTION lineMode90
Definition: ee_actions.h:257
static TOOL_ACTION toggleHiddenPins
Definition: ee_actions.h:231
static TOOL_ACTION highlightNet
Definition: ee_actions.h:284
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:121
static TOOL_ACTION clearHighlight
Definition: ee_actions.h:285
static TOOL_ACTION assignNetclass
Definition: ee_actions.h:162
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
static TOOL_ACTION showPythonConsole
Definition: ee_actions.h:252
static TOOL_ACTION toggleERCWarnings
Definition: ee_actions.h:234
static TOOL_ACTION simTune
Definition: ee_actions.h:273
static TOOL_ACTION toggleERCExclusions
Definition: ee_actions.h:236
static TOOL_ACTION lineModeNext
Definition: ee_actions.h:259
static TOOL_ACTION lineModeFree
Definition: ee_actions.h:256
static TOOL_ACTION editLibSymbolWithLibEdit
Definition: ee_actions.h:173
static TOOL_ACTION generateBOMLegacy
Definition: ee_actions.h:178
static TOOL_ACTION toggleERCErrors
Definition: ee_actions.h:235
static TOOL_ACTION toggleOPCurrents
Definition: ee_actions.h:238
static TOOL_ACTION highlightNetTool
Definition: ee_actions.h:287
static TOOL_ACTION updateNetHighlighting
Definition: ee_actions.h:286
static TOOL_ACTION exportNetlist
Definition: ee_actions.h:176
static TOOL_ACTION assignFootprints
Definition: ee_actions.h:161
static TOOL_ACTION selectOnPCB
Definition: ee_actions.h:241
static TOOL_ACTION rescueSymbols
Definition: ee_actions.h:168
static TOOL_ACTION toggleHiddenFields
Definition: ee_actions.h:232
static TOOL_ACTION editWithLibEdit
Definition: ee_actions.h:172
static TOOL_ACTION simProbe
Definition: ee_actions.h:272
static TOOL_ACTION exportSymbolsToLibrary
Definition: ee_actions.h:180
static TOOL_ACTION drawSheetOnClipboard
Definition: ee_actions.h:249
static TOOL_ACTION editSymbolFields
Definition: ee_actions.h:153
static TOOL_ACTION showNetNavigator
Definition: ee_actions.h:288
static TOOL_ACTION annotate
Definition: ee_actions.h:152
static TOOL_ACTION toggleDirectiveLabels
Definition: ee_actions.h:233
static TOOL_ACTION showHierarchy
Definition: ee_actions.h:223
static TOOL_ACTION toggleOPVoltages
Definition: ee_actions.h:237
static TOOL_ACTION lineMode45
Definition: ee_actions.h:258
static TOOL_ACTION editSymbolLibraryLinks
Definition: ee_actions.h:154
static TOOL_ACTION saveCurrSheetCopyAs
Definition: ee_actions.h:42
static TOOL_ACTION showPcbNew
Definition: ee_actions.h:174
static TOOL_ACTION generateBOM
Definition: ee_actions.h:177
static TOOL_ACTION schematicSetup
Definition: ee_actions.h:163
static TOOL_ACTION exportSymbolsToNewLibrary
Definition: ee_actions.h:181
void Collect(SCH_SCREEN *aScreen, const std::vector< KICAD_T > &aScanTypes, const VECTOR2I &aPos, int aUnit=0, int aConvert=0)
Scan a EDA_ITEM using this class's Inspector method which does the collection.
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:238
void GuessSelectionCandidates(EE_COLLECTOR &collector, const VECTOR2I &aPos)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
EDA_ITEM * GetNode(const VECTOR2I &aPosition)
Finds a connected item at a point (usually the cursor position).
EE_SELECTION & RequestSelection(const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T })
Return either an existing selection (filtered), or the selection at the current cursor position if th...
bool SelectPoint(const VECTOR2I &aWhere, const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T }, EDA_ITEM **aItem=nullptr, bool *aSelectionCancelledFlag=nullptr, bool aCheckLocked=false, bool aAdd=false, bool aSubtract=false, bool aExclusiveOr=false)
Perform a click-type selection at a point (usually the cursor position).
int ClearSelection(const TOOL_EVENT &aEvent)
Select all visible items in sheet.
EE_SELECTION & GetSelection()
Definition: erc.h:46
static const TOOL_EVENT ClearedEvent
Definition: actions.h:235
static const TOOL_EVENT GridChangedByKeyEvent
Definition: actions.h:253
static const TOOL_EVENT SelectedEvent
Definition: actions.h:233
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:240
static const TOOL_EVENT PointSelectedEvent
Definition: actions.h:232
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:234
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:84
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
double GetScale() const
Definition: view.h:271
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:1618
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition: view.h:395
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition: view.cpp:1500
void Hide(VIEW_ITEM *aItem, bool aHide=true, bool aHideOverlay=false)
Temporarily hide the item in the view (e.g.
Definition: view.cpp:1566
void MarkDirty()
Force redraw of view on the next rendering.
Definition: view.h:643
Definition: kiid.h:49
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:67
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:432
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
Definition: kiway.cpp:689
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:99
VECTOR2I GetPosition() const override
Definition: lib_pin.h:232
Define a library symbol object.
Definition: lib_symbol.h:99
LIB_ID GetLibId() const override
Definition: lib_symbol.h:163
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Definition: lib_symbol.cpp:605
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(std::string &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:98
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:83
void SetClickHandler(CLICK_HANDLER aHandler)
Set a handler for mouse click event.
Definition: picker_tool.h:72
void SetSnapping(bool aSnap)
Definition: picker_tool.h:65
void SetCursor(KICURSOR aCursor)
Definition: picker_tool.h:63
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Set a handler for the finalize event.
Definition: picker_tool.h:103
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:143
virtual const wxString GetProjectName() const
Return the short name of the project.
Definition: project.cpp:155
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition: project.cpp:161
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:75
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:136
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:281
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:287
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:146
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:100
SCH_SHEET & Root() const
Definition: schematic.h:105
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
Revert the commit by restoring the modified items state.
Definition: sch_commit.cpp:353
virtual void Revert() override
Definition: sch_commit.cpp:417
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
const std::vector< std::shared_ptr< SCH_CONNECTION > > AllMembers() const
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 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 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)
int RescueSymbols(const TOOL_EVENT &aEvent)
Perform rescue operations to recover old projects from before certain changes were made.
std::map< KIID_PATH, SCH_SHEET_INSTANCE > m_clipboardSheetInstances
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)
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)
void setPastedSymbolInstances(SCH_SCREENS &aScreenList)
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, SCH_SCREEN *aPasteScreen, const SCH_SHEET_PATH &aPastePath, const KIID_PATH &aClipPath, bool aForceKeepAnnotations)
int ShowCvpcb(const TOOL_EVENT &aEvent)
SCH_SHEET_PATH updatePastedSheet(const SCH_SHEET_PATH &aPastePath, const KIID_PATH &aClipPath, SCH_SHEET *aSheet, bool aForceKeepAnnotations, SCH_SHEET_LIST *aPastedSheetsSoFar, SCH_REFERENCE_LIST *aPastedSymbolsSoFar)
int RepairSchematic(const TOOL_EVENT &aEvent)
int Cut(const TOOL_EVENT &aEvent)
int 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)
void setPastedSheetInstances(const SCH_SHEET *aPastedSheet)
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 operaintg points.
bool LoadSheetFromFile(SCH_SHEET *aSheet, SCH_SHEET_PATH *aHierarchy, const wxString &aFileName)
Load a the KiCad schematic file aFileName into the sheet aSheet.
Definition: sheet.cpp:158
void OnOpenCvpcb(wxCommandEvent &event)
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag and update other data struc...
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:99
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.
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:601
void OnUpdatePCB(wxCommandEvent &event)
void OnOpenPcbnew(wxCommandEvent &event)
void OnAnnotate(wxCommandEvent &event)
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 UpdateHierarchyNavigator()
Update the hierarchy navigation tree and history.
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.
void TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
bool SaveProject(bool aSaveAs=false)
Save the currently-open schematic (including its hierarchy) and associated project.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:52
void SetText(const wxString &aText) override
Definition: sch_field.cpp:989
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:116
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:151
virtual bool IsConnectable() const
Definition: sch_item.h:372
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:113
virtual void SetLastResolvedState(const SCH_ITEM *aItem)
Definition: sch_item.h:446
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:438
bool IsConnectivityDirty() const
Definition: sch_item.h:436
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:147
virtual std::vector< VECTOR2I > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
Definition: sch_item.h:387
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:530
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const STRING_UTF8_MAP *aProperties=nullptr)
Write aSymbol to an existing library located at aLibraryPath.
Definition: sch_plugin.cpp:165
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
void SortByReferenceOnly()
Sort the list of references by reference.
size_t GetCount() const
void AddItem(const SCH_REFERENCE &aItem)
A helper to define a symbol's reference designator in a schematic.
void SetSheetNumber(int aSheetNumber)
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:688
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 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:150
void Clear(bool aFree=true)
Delete all draw items and clears the project settings.
Definition: sch_screen.cpp:275
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:880
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:481
double m_LastZoomLevel
last value for the zoom level, useful in Eeschema when changing the current displayed sheet to reuse ...
Definition: sch_screen.h:612
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:109
const wxString & GetFileName() const
Definition: sch_screen.h:144
bool CheckIfOnDrawList(const SCH_ITEM *aItem) const
Definition: sch_screen.cpp:383
void MigrateSimModels()
Migrate any symbols having V6 simulation models to their V7 equivalents.
A SCH_PLUGIN derivation for loading schematic files using the new s-expression file format.
void Format(SCH_SHEET *aSheet)
void LoadContent(LINE_READER &aReader, SCH_SHEET *aSheet, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
VECTOR2I GetCenter() const
Definition: sch_shape.h:80
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void FillItemMap(std::map< KIID, EDA_ITEM * > &aMap)
Fill an item cache for temporary use when many items need to be fetched.
void SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sort the list of sheets by page number.
bool NameExists(const wxString &aSheetName) const
SCH_SHEET_LIST FindAllSheetsForScreen(const SCH_SCREEN *aScreen) const
Return a SCH_SHEET_LIST with a copy of all the SCH_SHEET_PATH using a particular screen.
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
bool PageNumberExists(const wxString &aPageNumber) const
bool TestForRecursion(const SCH_SHEET_LIST &aSrcSheetHierarchy, const wxString &aDestFileName)
Test every SCH_SHEET_PATH in this SCH_SHEET_LIST to verify if adding the sheets stored in aSrcSheetHi...
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Adds SCH_REFERENCE object to aReferences for each symbol in the sheet.
void UpdateAllScreenReferences() const
Update all the symbol references for this sheet path.
SCH_SCREEN * LastScreen()
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:57
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:308
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:93
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:728
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:110
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:162
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:181
const std::vector< SCH_SHEET_INSTANCE > & GetInstances() const
Definition: sch_sheet.h:388
Schematic symbol object.
Definition: sch_symbol.h:81
int GetUnit() const
Definition: sch_symbol.h:228
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstanceReferences() const
Definition: sch_symbol.h:140
wxString GetSchSymbolLibraryName() const
Definition: sch_symbol.cpp:293
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:738
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:940
int GetConvert() const
Definition: sch_symbol.h:270
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
Definition: sch_symbol.cpp:780
void ClearAnnotation(const SCH_SHEET_PATH *aSheetPath, bool aResetPrefix)
Clear exiting symbol annotation.
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve a list of the SCH_PINs for the given sheet path.
bool IsMissingLibSymbol() const
Check to see if the library symbol is set to the dummy library symbol.
Definition: sch_symbol.cpp:242
void SetUnit(int aUnit)
Change the unit number to aUnit.
Definition: sch_symbol.cpp:442
const LIB_ID & GetLibId() const
Definition: sch_symbol.h:175
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:988
void SetUnitSelection(const SCH_SHEET_PATH *aSheet, int aUnitSelection)
Set the selected unit of this symbol on one sheet.
Definition: sch_symbol.cpp:882
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:192
void SetLibSymbol(LIB_SYMBOL *aLibSymbol)
Set this schematic symbol library symbol reference to aLibSymbol.
Definition: sch_symbol.cpp:302
bool IsPower() const
void BrightenItem(EDA_ITEM *aItem)
void UnbrightenItem(EDA_ITEM *aItem)
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.
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, const std::vector< LIB_PIN * > &aPins, REPORTER &aReporter)
int FindModelPinIndex(const std::string &aSymbolPinNumber)
Definition: sim_model.cpp:714
const SPICE_GENERATOR & SpiceGenerator() const
Definition: sim_model.h:439
virtual std::vector< std::string > CurrentNames(const SPICE_ITEM &aItem) const
Implement an OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:433
const std::string & GetString()
Definition: richio.h:456
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:253
The symbol library editor main window.
void LoadSymbol(const wxString &aLibrary, const wxString &aSymbol, int Unit)
bool IsSymbolTreeShown() const
void OnToggleSymbolTree(wxCommandEvent &event)
void LoadSymbolFromSchematic(SCH_SYMBOL *aSymbol)
Load a symbol from the schematic to edit in place.
Class to handle modifications to the symbol libraries.
bool CreateLibrary(const wxString &aFilePath, SYMBOL_LIB_TABLE *aTable)
Create an empty library and adds it to the library table.
SYMBOL_LIB_TABLE_ROW * GetLibrary(const wxString &aLibrary) const
Find a single library within the (aggregate) library table.
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
const wxString GetType() const override
Return the type of symbol library table represented by this row.
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
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:42
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:216
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
Generic, UI-independent tool event.
Definition: tool_event.h:167
bool DisableGridSnapping() const
Definition: tool_event.h:363
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:460
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:57
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:145
std::string GetClipboardUTF8() const
Return the information currently stored in the system clipboard.
TOOLS_HOLDER * GetToolHolder() const
Definition: tool_manager.h:389
APP_SETTINGS_BASE * GetSettings() const
Definition: tool_manager.h:387
bool PostAction(const std::string &aActionName, T aParam)
Run the specified action after the current action (coroutine) ends.
Definition: tool_manager.h:230
bool SaveClipboard(const std::string &aTextUTF8)
Store information to the system clipboard.
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:192
A wrapper for reporting to a wxString object.
Definition: reporter.h:164
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:71
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:398
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:360
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:280
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:332
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:305
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:110
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:529
#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
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
const std::string KiCadSymbolLibFileExtension
const std::string KiCadSchematicFileExtension
wxString KiCadSchematicFileWildcard()
wxString KiCadSymbolLibFileWildcard()
int InvokeDialogPrintUsingPrinter(SCH_EDIT_FRAME *aCaller)
Create and show DIALOG_PRINT_USING_PRINTER and return whatever DIALOG_PRINT_USING_PRINTER::ShowModal(...
#define NET_PLUGIN_CHANGE
Create and shows DIALOG_EXPORT_NETLIST and returns whatever DIALOG_EXPORT_NETLIST::ShowModal() return...
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:39
#define KICTL_REVERT
reverting to a previously-saved (KiCad) file.
Definition: kiway_player.h:80
@ LAYER_ERC_WARN
Definition: layer_ids.h:375
@ LAYER_ERC_EXCLUSION
Definition: layer_ids.h:377
@ LAYER_ERC_ERR
Definition: layer_ids.h:376
@ LAYER_OP_CURRENTS
Definition: layer_ids.h:394
@ LAYER_OP_VOLTAGES
Definition: layer_ids.h:393
@ REPAINT
Item needs to be redrawn.
Definition: view_item.h:57
@ GEOMETRY
Position or shape has changed.
Definition: view_item.h:54
#define MAX_PAGE_SIZE_EESCHEMA_MILS
Definition: page_info.h:39
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
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119
std::vector< FAB_LAYER_COLOR > dummy
wxString UnescapeString(const wxString &aSource)
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:310
std::string refName
GRID_SETTINGS grid
Definition: app_settings.h:81
Definition for symbol library class.
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
@ AS_GLOBAL
Global action (toolbar/main menu event, global shortcut)
Definition: tool_action.h:48
@ TA_UNDO_REDO_PRE
Definition: tool_event.h:105
@ TC_MESSAGE
Definition: tool_event.h:57
double EuclideanNorm(const VECTOR2I &vector)
Definition: trigo.h:128
@ SCH_LINE_T
Definition: typeinfo.h:146
@ SCH_SYMBOL_T
Definition: typeinfo.h:156
@ SCH_FIELD_T
Definition: typeinfo.h:155
@ SCH_SHEET_T
Definition: typeinfo.h:158
@ SCH_SHAPE_T
Definition: typeinfo.h:147
@ SCH_PIN_T
Definition: typeinfo.h:159
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:85
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().
Definition: wx_filename.h:39