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 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>
34#include <project_rescue.h>
35#include <erc.h>
36#include <invoke_sch_dialog.h>
37#include <string_utils.h>
38#include <kiway.h>
39#include <kiway_player.h>
41#include <paths.h>
44#include <sch_edit_frame.h>
46#include <sch_line.h>
47#include <sch_junction.h>
48#include <sch_bus_entry.h>
49#include <sch_shape.h>
50#include <sch_painter.h>
51#include <sch_sheet.h>
52#include <sch_sheet_pin.h>
53#include <sch_view.h>
54#include <schematic.h>
55#include <advanced_config.h>
56#include <sim/simulator_frame.h>
57#include <sim/spice_generator.h>
58#include <sim/sim_lib_mgr.h>
60#include <symbol_viewer_frame.h>
61#include <tool/picker_tool.h>
62#include <tool/tool_manager.h>
63#include <tools/ee_actions.h>
64#include <tools/ee_selection.h>
69#include <eda_list_dialog.h>
71#include <wx_filename.h>
72#include <sch_sheet_path.h>
73#include <wx/filedlg.h>
74#include <wx/treectrl.h>
75
76
78{
80 return 0;
81}
82
83
85{
87 return 0;
88}
89
90
92{
94 return 0;
95}
96
97
99{
100 m_frame->SaveProject( true );
101 return 0;
102}
103
104
106{
107 SCH_SHEET* curr_sheet = m_frame->GetCurrentSheet().Last();
108 wxFileName curr_fn = curr_sheet->GetFileName();
109 wxFileDialog dlg( m_frame, _( "Schematic Files" ), curr_fn.GetPath(),
110 curr_fn.GetFullName(), KiCadSchematicFileWildcard(),
111 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
112
113 if( dlg.ShowModal() == wxID_CANCEL )
114 return false;
115
116 wxString newFilename = EnsureFileExtension( dlg.GetPath(), KiCadSchematicFileExtension );
117
118 m_frame->saveSchematicFile( curr_sheet, newFilename );
119 return 0;
120}
121
122
124{
125 SCHEMATIC& schematic = m_frame->Schematic();
126 SCH_SHEET& root = schematic.Root();
127
128 if( m_frame->GetCurrentSheet().Last() != &root )
129 {
132
133 // Store the current zoom level into the current screen before switching
135
136 SCH_SHEET_PATH rootSheetPath;
137 rootSheetPath.push_back( &root );
138 m_frame->SetCurrentSheet( rootSheetPath );
140
141 wxSafeYield();
142 }
143
144 wxString msg;
145 msg.Printf( _( "Revert '%s' (and all sub-sheets) to last version saved?" ),
146 schematic.GetFileName() );
147
148 if( !IsOK( m_frame, msg ) )
149 return false;
150
151 SCH_SCREENS screenList( schematic.Root() );
152
153 for( SCH_SCREEN* screen = screenList.GetFirst(); screen; screen = screenList.GetNext() )
154 screen->SetContentModified( false ); // do not prompt the user for changes
155
157 m_frame->OpenProjectFiles( std::vector<wxString>( 1, schematic.GetFileName() ) );
158
159 return 0;
160}
161
162
164{
166 return 0;
167}
168
169
171{
172 PICKED_ITEMS_LIST undoCmd;
174 ITEM_PICKER wrapper( m_frame->GetScreen(), undoItem, UNDO_REDO::PAGESETTINGS );
175
176 undoCmd.PushItem( wrapper );
177 m_frame->SaveCopyInUndoList( undoCmd, UNDO_REDO::PAGESETTINGS, false, false );
178
182
183 if( dlg.ShowModal() == wxID_OK )
184 {
185 // Update text variables
189
190 m_frame->OnModify();
191 }
192 else
193 {
195 }
196
197 return 0;
198}
199
200
202{
203 SCH_SCREENS schematic( m_frame->Schematic().Root() );
204
205 if( schematic.HasNoFullyDefinedLibIds() )
206 RescueLegacyProject( true );
207 else
209
210 return 0;
211}
212
213
214bool SCH_EDITOR_CONTROL::RescueLegacyProject( bool aRunningOnDemand )
215{
218
219 return rescueProject( rescuer, aRunningOnDemand );
220}
221
222
224{
228
229 return rescueProject( rescuer, aRunningOnDemand );
230}
231
232
233bool SCH_EDITOR_CONTROL::rescueProject( RESCUER& aRescuer, bool aRunningOnDemand )
234{
235 if( !RESCUER::RescueProject( m_frame, aRescuer, aRunningOnDemand ) )
236 return false;
237
238 if( aRescuer.GetCandidateCount() )
239 {
240 KIWAY_PLAYER* viewer = m_frame->Kiway().Player( FRAME_SCH_VIEWER, false );
241
242 if( viewer )
243 static_cast<SYMBOL_VIEWER_FRAME*>( viewer )->ReCreateLibList();
244
245 if( aRunningOnDemand )
246 {
247 SCH_SCREENS schematic( m_frame->Schematic().Root() );
248
249 schematic.UpdateSymbolLinks();
251 }
252
254 m_frame->SyncView();
256 m_frame->OnModify();
257 }
258
259 return true;
260}
261
262
264{
265 DIALOG_SYMBOL_REMAP dlgRemap( m_frame );
266
267 dlgRemap.ShowQuasiModal();
268
269 m_frame->GetCanvas()->Refresh( true );
270
271 return 0;
272}
273
274
276{
278 return 0;
279}
280
281
283{
285
286 dlg.ShowModal();
287
288 // save project config if the prj config has changed:
289 if( dlg.PrjConfigChanged() )
290 m_frame->OnModify();
291
292 return 0;
293}
294
295
297{
298 m_frame->Close( false );
299 return 0;
300}
301
302
304{
305 doCrossProbeSchToPcb( aEvent, false );
306 return 0;
307}
308
309
311{
312 doCrossProbeSchToPcb( aEvent, true );
313 return 0;
314}
315
316
317void SCH_EDITOR_CONTROL::doCrossProbeSchToPcb( const TOOL_EVENT& aEvent, bool aForce )
318{
319 // Don't get in an infinite loop SCH -> PCB -> SCH -> PCB -> SCH -> ...
321 return;
322
324
325 EE_SELECTION& selection = aForce ? selTool->RequestSelection() : selTool->GetSelection();
326
327 m_frame->SendSelectItemsToPcb( selection.GetItemsSortedBySelectionOrder(), aForce );
328}
329
330
332{
333 bool createNew = aEvent.IsAction( &EE_ACTIONS::exportSymbolsToNewLibrary );
334
335 SCH_REFERENCE_LIST symbols;
336 m_frame->Schematic().GetSheets().GetSymbols( symbols, false );
337
338 std::map<LIB_ID, LIB_SYMBOL*> libSymbols;
339 std::map<LIB_ID, std::vector<SCH_SYMBOL*>> symbolMap;
340
341 for( size_t i = 0; i < symbols.GetCount(); ++i )
342 {
343 SCH_SYMBOL* symbol = symbols[i].GetSymbol();
344 LIB_SYMBOL* libSymbol = symbol->GetLibSymbolRef().get();
345 LIB_ID id = libSymbol->GetLibId();
346
347 if( libSymbols.count( id ) )
348 {
349 wxASSERT_MSG( libSymbols[id]->Compare( *libSymbol, LIB_ITEM::COMPARE_FLAGS::ERC ) == 0,
350 "Two symbols have the same LIB_ID but are different!" );
351 }
352 else
353 {
354 libSymbols[id] = libSymbol;
355 }
356
357 symbolMap[id].emplace_back( symbol );
358 }
359
361
362 wxString targetLib;
363
364 if( createNew )
365 {
366 wxFileName fn;
368
371 ( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() ),
373 {
374 return 0;
375 }
376
377 targetLib = fn.GetName();
378
379 if( libTable->HasLibrary( targetLib, false ) )
380 {
381 DisplayError( m_frame, wxString::Format( _( "Library '%s' already exists." ),
382 targetLib ) );
383 return 0;
384 }
385
386 // if the "new" library is in fact an existing library and the used asked for replacing
387 // it by the recreated lib, erase it:
388 if( fn.FileExists() )
389 wxRemoveFile( fn.GetFullPath() );
390
391 if( !mgr.CreateLibrary( fn.GetFullPath(), libTable ) )
392 {
393 DisplayError( m_frame, wxString::Format( _( "Could not add library '%s'." ),
394 targetLib ) );
395 return 0;
396 }
397 }
398 else
399 {
400 targetLib = m_frame->SelectLibraryFromList();
401 }
402
403 if( targetLib.IsEmpty() )
404 return 0;
405
406 bool map = IsOK( m_frame, _( "Update symbols in schematic to refer to new library?" ) );
407 bool append = false;
408
409 SYMBOL_LIB_TABLE_ROW* row = mgr.GetLibrary( targetLib );
410 SCH_IO_MGR::SCH_FILE_T type = SCH_IO_MGR::EnumFromStr( row->GetType() );
411 SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( type ) );
412
413 wxFileName dest = row->GetFullURI( true );
414 dest.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
415
416 for( const std::pair<const LIB_ID, LIB_SYMBOL*>& it : libSymbols )
417 {
418 LIB_SYMBOL* origSym = it.second;
419 LIB_SYMBOL* newSym = origSym->Flatten().release();
420
421 pi->SaveSymbol( dest.GetFullPath(), newSym );
422
423 if( map )
424 {
425 LIB_ID id = it.first;
426 id.SetLibNickname( targetLib );
427
428
429 for( SCH_SYMBOL* symbol : symbolMap[it.first] )
430 {
431 m_frame->SaveCopyInUndoList( m_frame->GetScreen(), symbol, UNDO_REDO::CHANGED,
432 append, false );
433 symbol->SetLibId( id );
434 append = true;
435 }
436 }
437 }
438
439 // Save the modified symbol library table. We need to look this up by name in each table to find
440 // whether the new library is a global or project entity as the code above to choose the library
441 // returns a different type depending on whether a global or project library is chosen.
443 SYMBOL_LIB_TABLE* projectTable = nullptr;
444
445 if( !m_frame->Prj().IsNullProject() )
446 projectTable = m_frame->Prj().SchSymbolLibTable();
447
448 if( globalTable->FindRow( targetLib ) )
449 {
450 try
451 {
452 wxString globalTablePath = SYMBOL_LIB_TABLE::GetGlobalTableFileName();
453 globalTable->Save( globalTablePath );
454 }
455 catch( const IO_ERROR& ioe )
456 {
457 wxString msg;
458 msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
459 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
460 }
461 }
462 else if( projectTable && projectTable->FindRow( targetLib ) )
463 {
464 try
465 {
466 wxString projectPath = m_frame->Prj().GetProjectPath();
467 wxFileName projectTableFn( projectPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
468 projectTable->Save( projectTableFn.GetFullPath() );
469 }
470 catch( const IO_ERROR& ioe )
471 {
472 wxString msg;
473 msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
474 wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
475 }
476 }
477
478 if( append )
479 {
480 std::set<SCH_SCREEN*> processedScreens;
482
483 for( SCH_SHEET_PATH& sheet : sheets )
484 {
485 SCH_SCREEN* screen = sheet.LastScreen();
486 if( processedScreens.find( ( screen ) ) == processedScreens.end() )
487 {
488 processedScreens.insert( screen );
489 screen->UpdateSymbolLinks();
490 }
491 }
492
493 m_frame->OnModify();
494 }
495
496 return 0;
497}
498
499
500#define HITTEST_THRESHOLD_PIXELS 5
501
503{
506 false );
507
508 if( !simFrame ) // Defensive coding; shouldn't happen.
509 return 0;
510
511 if( wxWindow* blocking_win = simFrame->Kiway().GetBlockingDialog() )
512 blocking_win->Close( true );
513
514 // Deactivate other tools; particularly important if another PICKER is currently running
515 Activate();
516
517 picker->SetCursor( KICURSOR::VOLTAGE_PROBE );
518 picker->SetSnapping( false );
519
520 picker->SetClickHandler(
521 [this, simFrame]( const VECTOR2D& aPosition )
522 {
524 EDA_ITEM* item = selTool->GetNode( aPosition );
526
527 if( !item )
528 return false;
529
530 if( item->Type() == SCH_PIN_T )
531 {
532 try
533 {
534 LIB_PIN* pin = static_cast<SCH_PIN*>( item )->GetLibPin();
535 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item->GetParent() );
536
537 wxString msg;
538 WX_STRING_REPORTER reporter( &msg );
539 SIM_LIB_MGR mgr( &m_frame->Prj(), &reporter );
540
541 SIM_MODEL& model = mgr.CreateModel( &sheet, *symbol ).model;
542
543 if( reporter.HasMessage() )
544 THROW_IO_ERROR( msg );
545
546 SPICE_ITEM spiceItem;
547 spiceItem.refName = symbol->GetRef( &sheet ).ToStdString();
548 std::vector<std::string> currentNames =
549 model.SpiceGenerator().CurrentNames( spiceItem );
550
551 if( currentNames.size() == 0 )
552 {
553 return true;
554 }
555 else if( currentNames.size() == 1 )
556 {
557 simFrame->AddCurrentTrace( currentNames.at( 0 ) );
558 return true;
559 }
560
561 int modelPinIndex = model.FindModelPinIndex( pin->GetNumber().ToStdString() );
562
563 if( modelPinIndex != SIM_MODEL::PIN::NOT_CONNECTED )
564 {
565 wxString name = currentNames.at( modelPinIndex );
566 simFrame->AddCurrentTrace( name );
567 }
568 }
569 catch( const IO_ERROR& e )
570 {
572 }
573 }
574 else if( item->IsType( { SCH_ITEM_LOCATE_WIRE_T } )
575 || item->IsType( { SCH_JUNCTION_T } ) )
576 {
577 if( SCH_CONNECTION* conn = static_cast<SCH_ITEM*>( item )->Connection() )
578 {
579 std::string spiceNet = UnescapeString( conn->Name() ).ToStdString();
581
582 simFrame->AddVoltageTrace( wxString::Format( "V(%s)", spiceNet ) );
583 }
584 }
585
586 return true;
587 } );
588
589 picker->SetMotionHandler(
590 [this, picker]( const VECTOR2D& aPos )
591 {
592 EE_COLLECTOR collector;
593 collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
594 collector.Collect( m_frame->GetScreen(), { SCH_ITEM_LOCATE_WIRE_T,
595 SCH_PIN_T,
596 SCH_SHEET_PIN_T }, aPos );
597
599 selectionTool->GuessSelectionCandidates( collector, aPos );
600
601 EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
602 SCH_LINE* wire = dynamic_cast<SCH_LINE*>( item );
603
604 const SCH_CONNECTION* conn = nullptr;
605
606 if( wire )
607 {
608 item = nullptr;
609 conn = wire->Connection();
610 }
611
612 if( item && item->Type() == SCH_PIN_T )
613 picker->SetCursor( KICURSOR::CURRENT_PROBE );
614 else
615 picker->SetCursor( KICURSOR::VOLTAGE_PROBE );
616
617 if( m_pickerItem != item )
618 {
619 if( m_pickerItem )
620 selectionTool->UnbrightenItem( m_pickerItem );
621
622 m_pickerItem = item;
623
624 if( m_pickerItem )
625 selectionTool->BrightenItem( m_pickerItem );
626 }
627
628 wxString connectionName = ( conn ) ? conn->Name() : wxString( wxS( "" ) );
629
630 if( m_frame->GetHighlightedConnection() != connectionName )
631 {
632 m_frame->SetHighlightedConnection( connectionName );
633
634 TOOL_EVENT dummyEvent;
635 UpdateNetHighlighting( dummyEvent );
636 }
637 } );
638
639 picker->SetFinalizeHandler(
640 [this]( const int& aFinalState )
641 {
642 if( m_pickerItem )
643 m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
644
645 if( !m_frame->GetHighlightedConnection().IsEmpty() )
646 {
647 m_frame->SetHighlightedConnection( wxEmptyString );
648
649 TOOL_EVENT dummyEvent;
650 UpdateNetHighlighting( dummyEvent );
651 }
652
653 // Wake the selection tool after exiting to ensure the cursor gets updated
655 } );
656
657 m_toolMgr->RunAction( ACTIONS::pickerTool, true, (void*) &aEvent );
658
659 return 0;
660}
661
662
664{
666
667 // Deactivate other tools; particularly important if another PICKER is currently running
668 Activate();
669
670 picker->SetCursor( KICURSOR::TUNE );
671 picker->SetSnapping( false );
672
673 picker->SetClickHandler(
674 [this]( const VECTOR2D& aPosition )
675 {
677 EDA_ITEM* item = nullptr;
678 selTool->SelectPoint( aPosition, { SCH_SYMBOL_T, SCH_FIELD_T }, &item );
679
680 if( !item )
681 return false;
682
683 if( item->Type() != SCH_SYMBOL_T )
684 {
685 item = item->GetParent();
686
687 if( item->Type() != SCH_SYMBOL_T )
688 return false;
689 }
690
691 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
692 SCH_SHEET_PATH sheetPath = symbol->Schematic()->CurrentSheet();
693 KIWAY_PLAYER* simFrame = m_frame->Kiway().Player( FRAME_SIMULATOR, false );
694
695 if( simFrame )
696 {
697 if( wxWindow* blocking_win = simFrame->Kiway().GetBlockingDialog() )
698 blocking_win->Close( true );
699
700 static_cast<SIMULATOR_FRAME*>( simFrame )->AddTuner( sheetPath, symbol );
701 }
702
703 // We do not really want to keep a symbol selected in schematic,
704 // so clear the current selection
705 selTool->ClearSelection();
706 return true;
707 } );
708
709 picker->SetMotionHandler(
710 [this]( const VECTOR2D& aPos )
711 {
712 EE_COLLECTOR collector;
713 collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
714 collector.Collect( m_frame->GetScreen(), { SCH_SYMBOL_T, SCH_FIELD_T }, aPos );
715
717 selectionTool->GuessSelectionCandidates( collector, aPos );
718
719 EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
720
721 if( m_pickerItem != item )
722 {
723 if( m_pickerItem )
724 selectionTool->UnbrightenItem( m_pickerItem );
725
726 m_pickerItem = item;
727
728 if( m_pickerItem )
729 selectionTool->BrightenItem( m_pickerItem );
730 }
731 } );
732
733 picker->SetFinalizeHandler(
734 [this]( const int& aFinalState )
735 {
736 if( m_pickerItem )
737 m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
738
739 // Wake the selection tool after exiting to ensure the cursor gets updated
740 // and deselect previous selection from simulator to avoid any issue
741 // ( avoid crash in some cases when the SimTune tool is deselected )
743 selectionTool->ClearSelection();
745 } );
746
747 m_toolMgr->RunAction( ACTIONS::pickerTool, true, (void*) &aEvent );
748
749 return 0;
750}
751
752
753// A singleton reference for clearing the highlight
755
756
757static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition )
758{
759 SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( aToolMgr->GetToolHolder() );
760 EE_SELECTION_TOOL* selTool = aToolMgr->GetTool<EE_SELECTION_TOOL>();
761 SCH_EDITOR_CONTROL* editorControl = aToolMgr->GetTool<SCH_EDITOR_CONTROL>();
762 SCH_CONNECTION* conn = nullptr;
763 bool retVal = true;
764
765 if( aPosition != CLEAR )
766 {
767 ERC_TESTER erc( &editFrame->Schematic() );
768
769 if( erc.TestDuplicateSheetNames( false ) > 0 )
770 {
771 wxMessageBox( _( "Error: duplicate sub-sheet names found in current sheet." ) );
772 retVal = false;
773 }
774 else
775 {
776 SCH_ITEM* item = static_cast<SCH_ITEM*>( selTool->GetNode( aPosition ) );
777 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
778
779 if( item )
780 {
781 if( item->IsConnectivityDirty() )
782 {
784 }
785
786 if( item->Type() == SCH_FIELD_T )
787 symbol = dynamic_cast<SCH_SYMBOL*>( item->GetParent() );
788
789 if( symbol && symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->IsPower() )
790 {
791 std::vector<SCH_PIN*> pins = symbol->GetPins();
792
793 if( pins.size() == 1 )
794 conn = pins[0]->Connection();
795 }
796 else
797 {
798 conn = item->Connection();
799 }
800 }
801 }
802 }
803
804 wxString connectionName = ( conn ) ? conn->Name() : wxString( wxS( "" ) );
805
806 if( !conn || connectionName == editFrame->GetHighlightedConnection() )
807 {
808 editFrame->SetStatusText( wxT( "" ) );
809 editFrame->SendCrossProbeClearHighlight();
810 editFrame->SetHighlightedConnection( wxEmptyString );
811 }
812 else
813 {
814 editFrame->SetCrossProbeConnection( conn );
815 editFrame->SetHighlightedConnection( connectionName );
816 }
817
818 editFrame->UpdateNetHighlightStatus();
819
821 editorControl->UpdateNetHighlighting( dummy );
822
823 return retVal;
824}
825
826
828{
830 VECTOR2D cursorPos = controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
831
832 highlightNet( m_toolMgr, cursorPos );
833
834 return 0;
835}
836
837
839{
841
842 return 0;
843}
844
845
847{
849 SCHEMATIC& schematic = m_frame->Schematic();
851
852 const SCH_CONNECTION* conn = nullptr;
853 VECTOR2D connPos;
854
855 for( EDA_ITEM* item : selectionTool->GetSelection() )
856 {
857 conn = static_cast<SCH_ITEM*>( item )->Connection();
858 connPos = item->GetPosition();
859
860 if( conn )
861 break;
862 }
863
864 if( !conn )
865 {
866 m_frame->ShowInfoBarError( _( "No net selected." ) );
867 return 0;
868 }
869
870 // Remove selection in favor of highlighting so the whole net is highlighted
871 selectionTool->ClearSelection();
872 highlightNet( m_toolMgr, connPos );
873
874 wxString netName = conn->Name();
875
876 if( conn->IsBus() )
877 {
878 wxString prefix;
879
880 if( NET_SETTINGS::ParseBusVector( netName, &prefix, nullptr ) )
881 {
882 netName = prefix + wxT( "*" );
883 }
884 else if( NET_SETTINGS::ParseBusGroup( netName, &prefix, nullptr ) )
885 {
886 netName = prefix + wxT( ".*" );
887 }
888 }
889 else if( !conn->Driver() || CONNECTION_SUBGRAPH::GetDriverPriority( conn->Driver() )
891 {
892 m_frame->ShowInfoBarError( _( "Net must be labeled to assign a netclass." ) );
894 return 0;
895 }
896
897 DIALOG_ASSIGN_NETCLASS dlg( m_frame, netName, schematic.GetNetClassAssignmentCandidates(),
898 [&]( const std::vector<wxString>& aNetNames )
899 {
900 for( SCH_ITEM* item : screen->Items() )
901 {
902 bool redraw = item->IsBrightened();
903 SCH_CONNECTION* itemConn = item->Connection();
904
905 if( itemConn && alg::contains( aNetNames, itemConn->Name() ) )
906 item->SetBrightened();
907 else
908 item->ClearBrightened();
909
910 redraw |= item->IsBrightened();
911
912 if( item->Type() == SCH_SYMBOL_T )
913 {
914 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
915
916 redraw |= symbol->HasBrightenedPins();
917
918 symbol->ClearBrightenedPins();
919
920 for( SCH_PIN* pin : symbol->GetPins() )
921 {
922 SCH_CONNECTION* pin_conn = pin->Connection();
923
924 if( pin_conn && alg::contains( aNetNames, pin_conn->Name() ) )
925 {
926 pin->SetBrightened();
927 redraw = true;
928 }
929 }
930 }
931 else if( item->Type() == SCH_SHEET_T )
932 {
933 for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( item )->GetPins() )
934 {
935 SCH_CONNECTION* pin_conn = pin->Connection();
936
937 redraw |= pin->IsBrightened();
938
939 if( pin_conn && alg::contains( aNetNames, pin_conn->Name() ) )
940 pin->SetBrightened();
941 else
942 pin->ClearBrightened();
943
944 redraw |= pin->IsBrightened();
945 }
946 }
947
948 if( redraw )
949 getView()->Update( item, KIGFX::VIEW_UPDATE_FLAGS::REPAINT );
950 }
951
953 } );
954
955 if( dlg.ShowModal() )
956 {
957 getView()->UpdateAllItemsConditionally(
958 [&]( KIGFX::VIEW_ITEM* aItem ) -> int
959 {
960 int flags = 0;
961
962 // Netclass coloured items
963 //
964 if( dynamic_cast<SCH_LINE*>( aItem ) )
965 flags |= KIGFX::REPAINT;
966 else if( dynamic_cast<SCH_JUNCTION*>( aItem ) )
967 flags |= KIGFX::REPAINT;
968 else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( aItem ) )
969 flags |= KIGFX::REPAINT;
970
971 // Items that might reference an item's netclass name
972 //
973 if( SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem ) )
974 {
975 item->RunOnChildren(
976 [&flags]( SCH_ITEM* aChild )
977 {
978 EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aChild );
979
980 if( text && text->HasTextVars() )
981 {
982 text->ClearRenderCache();
983 text->ClearBoundingBoxCache();
984 flags |= KIGFX::GEOMETRY | KIGFX::REPAINT;
985 }
986 } );
987
988 EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
989
990 if( text && text->HasTextVars() )
991 {
992 text->ClearRenderCache();
993 text->ClearBoundingBoxCache();
995 }
996
997 if( flags & KIGFX::GEOMETRY )
998 m_frame->GetScreen()->Update( item, false ); // Refresh RTree
999 }
1000
1001 return flags;
1002 } );
1003 }
1004
1005 highlightNet( m_toolMgr, CLEAR );
1006 return 0;
1007}
1008
1009
1011{
1013 CONNECTION_GRAPH* connectionGraph = m_frame->Schematic().ConnectionGraph();
1014 std::vector<EDA_ITEM*> itemsToRedraw;
1015
1016 wxCHECK( screen && connectionGraph, 0 );
1017
1018 bool selectedIsBus = false;
1019 wxString selectedName = m_frame->GetHighlightedConnection();
1020
1021 bool selectedIsNoNet = false;
1022 CONNECTION_SUBGRAPH* selectedSubgraph = nullptr;
1023
1024 for( SCH_ITEM* item : screen->Items() )
1025 {
1026 bool redraw = item->IsBrightened();
1027 bool highlight = false;
1028
1029 if( !selectedName.IsEmpty() )
1030 {
1031 SCH_CONNECTION* itemConn = nullptr;
1032 SCH_SYMBOL* symbol = nullptr;
1033
1034 if( item->Type() == SCH_SYMBOL_T )
1035 symbol = static_cast<SCH_SYMBOL*>( item );
1036
1037 if( symbol && symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->IsPower() )
1038 itemConn = symbol->Connection();
1039 else
1040 itemConn = item->Connection();
1041
1042 if( itemConn && ( selectedName == itemConn->Name() ) )
1043 {
1044 selectedIsBus = itemConn->IsBus();
1045
1046 if( itemConn->Driver() == nullptr )
1047 {
1048 selectedIsNoNet = true;
1049 selectedSubgraph = connectionGraph->GetSubgraphForItem( itemConn->Parent() );
1050 }
1051
1052 if( selectedIsNoNet && selectedSubgraph )
1053 {
1054 for( SCH_ITEM* subgraphItem : selectedSubgraph->GetItems() )
1055 {
1056 if( item == subgraphItem )
1057 {
1058 highlight = true;
1059 break;
1060 }
1061 }
1062 }
1063 else if( selectedIsBus && itemConn && itemConn->IsNet() )
1064 {
1065 for( const std::shared_ptr<SCH_CONNECTION>& member : itemConn->Members() )
1066 {
1067 if( member->Name() == itemConn->Name() )
1068 {
1069 highlight = true;
1070 break;
1071 }
1072 else if( member->IsBus() )
1073 {
1074 for( const std::shared_ptr<SCH_CONNECTION>& bus_member :
1075 member->Members() )
1076 {
1077 if( bus_member->Name() == itemConn->Name() )
1078 {
1079 highlight = true;
1080 break;
1081 }
1082 }
1083 }
1084 }
1085 }
1086 else if( !selectedName.IsEmpty() && itemConn
1087 && ( selectedName == itemConn->Name() ) )
1088 {
1089 highlight = true;
1090 }
1091 }
1092 }
1093
1094 if( highlight )
1095 {
1096 item->SetBrightened();
1097 }
1098 else
1099 {
1100 item->ClearBrightened();
1101 }
1102
1103 redraw |= item->IsBrightened();
1104
1105 if( item->Type() == SCH_SYMBOL_T )
1106 {
1107 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1108
1109 redraw |= symbol->HasBrightenedPins();
1110
1111 symbol->ClearBrightenedPins();
1112
1113 for( SCH_PIN* pin : symbol->GetPins() )
1114 {
1115 SCH_CONNECTION* pin_conn = pin->Connection();
1116
1117 if( pin_conn && pin_conn->Name() == selectedName )
1118 {
1119 pin->SetBrightened();
1120 redraw = true;
1121 }
1122 }
1123
1124 if( symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->IsPower() )
1125 {
1126 std::vector<SCH_FIELD>& fields = symbol->GetFields();
1127
1128 for( int id : { REFERENCE_FIELD, VALUE_FIELD } )
1129 {
1130 if( item->IsBrightened() && fields[id].IsVisible() )
1131 fields[id].SetBrightened();
1132 else
1133 fields[id].ClearBrightened();
1134 }
1135 }
1136 }
1137 else if( item->Type() == SCH_SHEET_T )
1138 {
1139 for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( item )->GetPins() )
1140 {
1141 SCH_CONNECTION* pin_conn = pin->Connection();
1142 bool redrawPin = pin->IsBrightened();
1143
1144 if( pin_conn && pin_conn->Name() == selectedName )
1145 pin->SetBrightened();
1146 else
1147 pin->ClearBrightened();
1148
1149 redrawPin ^= pin->IsBrightened();
1150 redraw |= redrawPin;
1151 }
1152 }
1153
1154 if( redraw )
1155 itemsToRedraw.push_back( item );
1156 }
1157
1158 // Be sure highlight change will be redrawn
1159 KIGFX::VIEW* view = getView();
1160
1161 for( EDA_ITEM* redrawItem : itemsToRedraw )
1163
1165
1166 return 0;
1167}
1168
1169
1171{
1173
1174 // Deactivate other tools; particularly important if another PICKER is currently running
1175 Activate();
1176
1177 picker->SetCursor( KICURSOR::BULLSEYE );
1178 picker->SetSnapping( false );
1179
1180 picker->SetClickHandler(
1181 [this] ( const VECTOR2D& aPos )
1182 {
1183 return highlightNet( m_toolMgr, aPos );
1184 } );
1185
1186 m_toolMgr->RunAction( ACTIONS::pickerTool, true, (void*) &aEvent );
1187
1188 return 0;
1189}
1190
1191
1193{
1194 if( m_frame->GetUndoCommandCount() <= 0 )
1195 return 0;
1196
1197 // Inform tools that undo command was issued
1199
1200 // Get the old list
1202
1203 m_frame->PutDataInPreviousState( undo_list );
1206
1207 // Now push the old command to the RedoList
1208 undo_list->ReversePickersListOrder();
1209 m_frame->PushCommandToRedoList( undo_list );
1210
1211 m_toolMgr->GetTool<EE_SELECTION_TOOL>()->RebuildSelection();
1212
1213 m_frame->SyncView();
1214 m_frame->OnModify();
1215
1216 return 0;
1217}
1218
1219
1221{
1222 if( m_frame->GetRedoCommandCount() == 0 )
1223 return 0;
1224
1225 // Inform tools that undo command was issued
1227
1228 /* Get the old list */
1230
1231 /* Redo the command: */
1233
1234 /* Put the old list in UndoList */
1237
1240
1241 m_toolMgr->GetTool<EE_SELECTION_TOOL>()->RebuildSelection();
1242
1243 m_frame->SyncView();
1245 m_frame->OnModify();
1246
1247 return 0;
1248}
1249
1250
1251bool SCH_EDITOR_CONTROL::doCopy( bool aUseDuplicateClipboard )
1252{
1254 EE_SELECTION& selection = selTool->RequestSelection();
1255 SCHEMATIC& schematic = m_frame->Schematic();
1256
1257 if( selection.Empty() )
1258 return false;
1259
1260 if( aUseDuplicateClipboard )
1261 m_duplicateIsHoverSelection = selection.IsHover();
1262
1263 selection.SetScreen( m_frame->GetScreen() );
1265
1266 for( EDA_ITEM* item : selection )
1267 {
1268 if( item->Type() == SCH_SHEET_T )
1269 {
1270 SCH_SHEET* sheet = (SCH_SHEET*) item;
1271 m_supplementaryClipboard[ sheet->GetFileName() ] = sheet->GetScreen();
1272 }
1273 else if( item->Type() == SCH_FIELD_T && selection.IsHover() )
1274 {
1275 // Most of the time the user is trying to duplicate the parent symbol
1276 // and the field text is in it
1277 selection.Add( item->GetParent() );
1278 }
1279 }
1280
1281 STRING_FORMATTER formatter;
1282 SCH_SEXPR_PLUGIN plugin;
1283 SCH_SHEET_LIST hierarchy = schematic.GetSheets();
1285
1286 plugin.Format( &selection, &selPath, schematic, &formatter, true );
1287
1288 if( selection.IsHover() )
1290
1291 if( aUseDuplicateClipboard )
1292 {
1293 m_duplicateClipboard = formatter.GetString();
1294 return true;
1295 }
1296
1297 return m_toolMgr->SaveClipboard( formatter.GetString() );
1298}
1299
1300
1301bool SCH_EDITOR_CONTROL::searchSupplementaryClipboard( const wxString& aSheetFilename,
1302 SCH_SCREEN** aScreen )
1303{
1304 if( m_supplementaryClipboard.count( aSheetFilename ) > 0 )
1305 {
1306 *aScreen = m_supplementaryClipboard[ aSheetFilename ];
1307 return true;
1308 }
1309
1310 return false;
1311}
1312
1313
1315{
1316 doCopy( true ); // Use the local clipboard
1317 Paste( aEvent );
1318
1319 return 0;
1320}
1321
1322
1324{
1325 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
1326
1327 if( textEntry )
1328 {
1329 textEntry->Cut();
1330 return 0;
1331 }
1332
1333 if( doCopy() )
1335
1336 return 0;
1337}
1338
1339
1341{
1342 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
1343
1344 if( textEntry )
1345 {
1346 textEntry->Copy();
1347 return 0;
1348 }
1349
1350 doCopy();
1351
1352 return 0;
1353}
1354
1355
1357 const SCH_SHEET_PATH& aPastePath,
1358 const KIID_PATH& aClipPath,
1359 bool aForceKeepAnnotations )
1360{
1361 wxCHECK( aSymbol && aPasteScreen, /* void */ );
1362
1363 KIID_PATH clipItemPath = aClipPath;
1364
1365 wxString reference, value, footprint;
1366 int unit;
1367
1368 if( m_clipboardSymbolInstances.count( clipItemPath ) > 0 )
1369 {
1370 SCH_SYMBOL_INSTANCE instance = m_clipboardSymbolInstances.at( clipItemPath );
1371
1372 unit = instance.m_Unit;
1373 reference = instance.m_Reference;
1374 }
1375 else
1376 {
1377 // Some legacy versions saved value fields escaped. While we still do in the symbol
1378 // editor, we don't anymore in the schematic, so be sure to unescape them.
1379 SCH_FIELD* valueField = aSymbol->GetField( VALUE_FIELD );
1380 valueField->SetText( UnescapeString( valueField->GetText() ) );
1381
1382 // Pasted from notepad or an older instance of eeschema. Use the values in the fields
1383 // instead.
1384 reference = aSymbol->GetField( REFERENCE_FIELD )->GetText();
1385 value = aSymbol->GetField( VALUE_FIELD )->GetText();
1386 footprint = aSymbol->GetField( FOOTPRINT_FIELD )->GetText();
1387 unit = aSymbol->GetUnit();
1388 }
1389
1390 if( aForceKeepAnnotations && !reference.IsEmpty() )
1391 aSymbol->SetRef( &aPastePath, reference );
1392 else
1393 aSymbol->ClearAnnotation( &aPastePath, false );
1394
1395 // We might clear annotations but always leave the original unit number from the paste.
1396 aSymbol->SetUnitSelection( &aPastePath, unit );
1397 aSymbol->SetUnit( unit );
1398}
1399
1400
1402 const KIID_PATH& aClipPath, SCH_SHEET* aSheet,
1403 bool aForceKeepAnnotations,
1404 SCH_SHEET_LIST* aPastedSheetsSoFar,
1405 SCH_REFERENCE_LIST* aPastedSymbolsSoFar )
1406{
1407 wxCHECK( aSheet && aPastedSheetsSoFar && aPastedSymbolsSoFar, aPastePath );
1408
1409 SCH_SHEET_PATH sheetPath = aPastePath;
1410 sheetPath.push_back( aSheet );
1411
1412 aPastedSheetsSoFar->push_back( sheetPath );
1413
1414 if( aSheet->GetScreen() == nullptr )
1415 return sheetPath; // We can only really set the page number but not load any items
1416
1417 for( SCH_ITEM* item : aSheet->GetScreen()->Items() )
1418 {
1419 if( item->Type() == SCH_SYMBOL_T )
1420 {
1421 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1422
1423 updatePastedSymbol( symbol, aSheet->GetScreen(), sheetPath, aClipPath,
1424 aForceKeepAnnotations );
1425 }
1426 else if( item->Type() == SCH_SHEET_T )
1427 {
1428 SCH_SHEET* subsheet = static_cast<SCH_SHEET*>( item );
1429
1430 KIID_PATH newClipPath = aClipPath;
1431 newClipPath.push_back( subsheet->m_Uuid );
1432
1433 updatePastedSheet( sheetPath, newClipPath, subsheet, aForceKeepAnnotations,
1434 aPastedSheetsSoFar, aPastedSymbolsSoFar );
1435
1436 SCH_SHEET_PATH subSheetPath = sheetPath;
1437
1438 subSheetPath.push_back( subsheet );
1439 subSheetPath.GetSymbols( *aPastedSymbolsSoFar );
1440 }
1441 }
1442
1443 return sheetPath;
1444}
1445
1446
1448{
1450
1451 for( const SCH_SHEET_INSTANCE& sheet : aPastedScreen->GetSheetInstances() )
1452 m_clipboardSheetInstances[sheet.m_Path] = sheet;
1453
1455
1456 for( const SCH_SYMBOL_INSTANCE& symbol : aPastedScreen->GetSymbolInstances() )
1457 m_clipboardSymbolInstances[symbol.m_Path] = symbol;
1458}
1459
1460
1462{
1463 wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
1464
1465 if( textEntry )
1466 {
1467 textEntry->Paste();
1468 return 0;
1469 }
1470
1472 std::string content;
1473 VECTOR2I eventPos;
1474
1475 if( aEvent.IsAction( &ACTIONS::duplicate ) )
1476 content = m_duplicateClipboard;
1477 else
1478 content = m_toolMgr->GetClipboardUTF8();
1479
1480 if( content.empty() )
1481 return 0;
1482
1483 if( aEvent.IsAction( &ACTIONS::duplicate ) )
1484 eventPos = getViewControls()->GetCursorPosition( false );
1485
1486 STRING_LINE_READER reader( content, "Clipboard" );
1487 SCH_SEXPR_PLUGIN plugin;
1488
1489 SCH_SHEET tempSheet;
1490 SCH_SCREEN* tempScreen = new SCH_SCREEN( &m_frame->Schematic() );
1491
1493 int annotateStartNum = m_frame->Schematic().Settings().m_AnnotateStartNum;
1494
1495 // Screen object on heap is owned by the sheet.
1496 tempSheet.SetScreen( tempScreen );
1497
1498 try
1499 {
1500 plugin.LoadContent( reader, &tempSheet );
1501 }
1502 catch( IO_ERROR& )
1503 {
1504 // If it wasn't content, then paste as text object.
1505 SCH_TEXT* text_item = new SCH_TEXT( VECTOR2I( 0, 0 ), content );
1506 text_item->SetTextSpinStyle( TEXT_SPIN_STYLE::RIGHT ); // Left alignment
1507 tempScreen->Append( text_item );
1508 }
1509
1510 // Save loaded screen instances to m_clipboardSheetInstances
1511 setClipboardInstances( tempScreen );
1512
1513 tempScreen->MigrateSimModels();
1514
1515 PASTE_MODE pasteMode = annotate.automatic ? PASTE_MODE::RESPECT_OPTIONS
1516 : PASTE_MODE::REMOVE_ANNOTATIONS;
1517
1518 if( aEvent.IsAction( &ACTIONS::pasteSpecial ) )
1519 {
1520 DIALOG_PASTE_SPECIAL dlg( m_frame, &pasteMode );
1521
1522 if( dlg.ShowModal() == wxID_CANCEL )
1523 return 0;
1524 }
1525
1526 bool forceKeepAnnotations = pasteMode != PASTE_MODE::REMOVE_ANNOTATIONS;
1527
1528 // SCH_SEXP_PLUGIN added the items to the paste screen, but not to the view or anything
1529 // else. Pull them back out to start with.
1530 EDA_ITEMS loadedItems;
1531 bool sheetsPasted = false;
1532 SCH_SHEET_LIST hierarchy = m_frame->Schematic().GetSheets();
1533 SCH_SHEET_PATH& pasteRoot = m_frame->GetCurrentSheet();
1534 wxFileName destFn = pasteRoot.Last()->GetFileName();
1535
1536 if( destFn.IsRelative() )
1537 destFn.MakeAbsolute( m_frame->Prj().GetProjectPath() );
1538
1539 // List of paths in the hierarchy that refer to the destination sheet of the paste
1540 SCH_SHEET_LIST pasteInstances = hierarchy.FindAllSheetsForScreen( pasteRoot.LastScreen() );
1541 pasteInstances.SortByPageNumbers();
1542
1543 // Build a list of screens from the current design (to avoid loading sheets that already exist)
1544 std::map<wxString, SCH_SCREEN*> loadedScreens;
1545
1546 for( const SCH_SHEET_PATH& item : hierarchy )
1547 {
1548 if( item.LastScreen() )
1549 loadedScreens[item.Last()->GetFileName()] = item.LastScreen();
1550 }
1551
1552 // Build symbol list for reannotation of duplicates
1553 SCH_REFERENCE_LIST existingRefs;
1554 hierarchy.GetSymbols( existingRefs );
1555 existingRefs.SortByReferenceOnly();
1556
1557 // Build UUID map for fetching last-resolved-properties
1558 std::map<KIID, EDA_ITEM*> itemMap;
1559 hierarchy.FillItemMap( itemMap );
1560
1561 // Keep track of pasted sheets and symbols for the different paths to the hierarchy.
1562 std::map<SCH_SHEET_PATH, SCH_REFERENCE_LIST> pastedSymbols;
1563 std::map<SCH_SHEET_PATH, SCH_SHEET_LIST> pastedSheets;
1564
1565 for( SCH_ITEM* item : tempScreen->Items() )
1566 {
1567 loadedItems.push_back( item );
1568
1569 //@todo: we might want to sort the sheets by page number before adding to loadedItems
1570 if( item->Type() == SCH_SHEET_T )
1571 {
1572 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
1573 wxFileName srcFn = sheet->GetFileName();
1574
1575 if( srcFn.IsRelative() )
1576 srcFn.MakeAbsolute( m_frame->Prj().GetProjectPath() );
1577
1578 SCH_SHEET_LIST sheetHierarchy( sheet );
1579
1580 if( hierarchy.TestForRecursion( sheetHierarchy, destFn.GetFullPath( wxPATH_UNIX ) ) )
1581 {
1582 auto msg = wxString::Format( _( "The pasted sheet '%s'\n"
1583 "was dropped because the destination already has "
1584 "the sheet or one of its subsheets as a parent." ),
1585 sheet->GetFileName() );
1586 DisplayError( m_frame, msg );
1587 loadedItems.pop_back();
1588 }
1589 }
1590 }
1591
1592 // Remove the references from our temporary screen to prevent freeing on the DTOR
1593 tempScreen->Clear( false );
1594
1595 for( unsigned i = 0; i < loadedItems.size(); ++i )
1596 {
1597 EDA_ITEM* item = loadedItems[i];
1598 KIID_PATH clipPath( wxT( "/" ) ); // clipboard is at root
1599
1600 if( item->Type() == SCH_SYMBOL_T )
1601 {
1602 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1603
1604 // The library symbol gets set from the cached library symbols in the current
1605 // schematic not the symbol libraries. The cached library symbol may have
1606 // changed from the original library symbol which would cause the copy to
1607 // be incorrect.
1608 SCH_SCREEN* currentScreen = m_frame->GetScreen();
1609
1610 wxCHECK2( currentScreen, continue );
1611
1612 auto it = currentScreen->GetLibSymbols().find( symbol->GetSchSymbolLibraryName() );
1613 auto end = currentScreen->GetLibSymbols().end();
1614
1615 if( it == end )
1616 {
1617 // If can't find library definition in the design, use the pasted library
1618 it = tempScreen->GetLibSymbols().find( symbol->GetSchSymbolLibraryName() );
1619 end = tempScreen->GetLibSymbols().end();
1620 }
1621
1622 LIB_SYMBOL* libSymbol = nullptr;
1623
1624 if( it != end )
1625 {
1626 libSymbol = new LIB_SYMBOL( *it->second );
1627 symbol->SetLibSymbol( libSymbol );
1628 }
1629
1630 for( SCH_SHEET_PATH& instance : pasteInstances )
1631 updatePastedSymbol( symbol, tempScreen, instance, clipPath, forceKeepAnnotations );
1632
1633 // Assign a new KIID
1634 const_cast<KIID&>( item->m_Uuid ) = KIID();
1635
1636 // Make sure pins get a new UUID
1637 for( SCH_PIN* pin : symbol->GetPins() )
1638 const_cast<KIID&>( pin->m_Uuid ) = KIID();
1639
1640 for( SCH_SHEET_PATH& instance : pasteInstances )
1641 {
1642 // Ignore symbols from a non-existant library.
1643 if( libSymbol )
1644 {
1645 SCH_REFERENCE schReference( symbol, libSymbol, instance );
1646 schReference.SetSheetNumber( instance.GetVirtualPageNumber() );
1647 pastedSymbols[instance].AddItem( schReference );
1648 }
1649 }
1650 }
1651 else if( item->Type() == SCH_SHEET_T )
1652 {
1653 SCH_SHEET* sheet = (SCH_SHEET*) item;
1654 SCH_FIELD& nameField = sheet->GetFields()[SHEETNAME];
1655 wxString baseName = nameField.GetText();
1656 wxString candidateName = baseName;
1657 wxString number;
1658
1659 while( !baseName.IsEmpty() && wxIsdigit( baseName.Last() ) )
1660 {
1661 number = baseName.Last() + number;
1662 baseName.RemoveLast();
1663 }
1664
1665 // Update hierarchy to include any other sheets we already added, avoiding
1666 // duplicate sheet names
1667 hierarchy = m_frame->Schematic().GetSheets();
1668
1669 //@todo: it might be better to just iterate through the sheet names
1670 // in this screen instead of the whole hierarchy.
1671 int uniquifier = std::max( 0, wxAtoi( number ) ) + 1;
1672
1673 while( hierarchy.NameExists( candidateName ) )
1674 candidateName = wxString::Format( wxT( "%s%d" ), baseName, uniquifier++ );
1675
1676 nameField.SetText( candidateName );
1677
1678 wxFileName fn = sheet->GetFileName();
1679 SCH_SCREEN* existingScreen = nullptr;
1680
1681 sheet->SetParent( pasteRoot.Last() );
1682 sheet->SetScreen( nullptr );
1683
1684 if( !fn.IsAbsolute() )
1685 {
1686 wxFileName currentSheetFileName = pasteRoot.LastScreen()->GetFileName();
1687 fn.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS,
1688 currentSheetFileName.GetPath() );
1689 }
1690
1691 // Try to find the screen for the pasted sheet by several means
1692 if( !m_frame->Schematic().Root().SearchHierarchy( fn.GetFullPath( wxPATH_UNIX ),
1693 &existingScreen ) )
1694 {
1695 if( loadedScreens.count( sheet->GetFileName() ) > 0 )
1696 existingScreen = loadedScreens.at( sheet->GetFileName() );
1697 else
1698 searchSupplementaryClipboard( sheet->GetFileName(), &existingScreen );
1699 }
1700
1701 if( existingScreen )
1702 {
1703 sheet->SetScreen( existingScreen );
1704 }
1705 else
1706 {
1707 if( !m_frame->LoadSheetFromFile( sheet, &pasteRoot, fn.GetFullPath() ) )
1708 m_frame->InitSheet( sheet, sheet->GetFileName() );
1709 }
1710
1711 sheetsPasted = true;
1712
1713 // Push it to the clipboard path while it still has its old KIID
1714 clipPath.push_back( sheet->m_Uuid );
1715
1716 // Assign a new KIID to the pasted sheet
1717 const_cast<KIID&>( sheet->m_Uuid ) = KIID();
1718
1719 // Make sure pins get a new UUID
1720 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
1721 const_cast<KIID&>( pin->m_Uuid ) = KIID();
1722
1723 // Once we have our new KIID we can update all pasted instances. This will either
1724 // reset the annotations or copy "kept" annotations from the supplementary clipboard.
1725 for( SCH_SHEET_PATH& instance : pasteInstances )
1726 {
1727 SCH_SHEET_PATH sheetPath = updatePastedSheet( instance, clipPath, sheet,
1728 ( forceKeepAnnotations && annotate.automatic ),
1729 &pastedSheets[instance],
1730 &pastedSymbols[instance] );
1731
1732 sheetPath.GetSymbols( pastedSymbols[instance] );
1733 }
1734 }
1735 else
1736 {
1737 SCH_ITEM* srcItem = dynamic_cast<SCH_ITEM*>( itemMap[ item->m_Uuid ] );
1738 SCH_ITEM* destItem = dynamic_cast<SCH_ITEM*>( item );
1739
1740 // Everything gets a new KIID
1741 const_cast<KIID&>( item->m_Uuid ) = KIID();
1742
1743 if( srcItem && destItem )
1744 {
1745 destItem->SetConnectivityDirty( true );
1746 destItem->SetLastResolvedState( srcItem );
1747 }
1748 }
1749
1750 // Lines need both ends selected for a move after paste so the whole line moves.
1751 if( item->Type() == SCH_LINE_T )
1752 item->SetFlags( STARTPOINT | ENDPOINT );
1753
1754 item->SetFlags( IS_NEW | IS_PASTED | IS_MOVING );
1756
1757 // Reset flags for subsequent move operation
1758 item->SetFlags( IS_NEW | IS_PASTED | IS_MOVING );
1759
1760 // Start out hidden so the pasted items aren't "ghosted" in their original location
1761 // before being moved to the current location.
1762 getView()->Hide( item, true );
1763 }
1764
1765 pasteInstances.SortByPageNumbers();
1766
1767 if( sheetsPasted )
1768 {
1769 // Update page numbers: Find next free numeric page number
1770 for( SCH_SHEET_PATH& instance : pasteInstances )
1771 {
1772 pastedSheets[instance].SortByPageNumbers();
1773
1774 for( SCH_SHEET_PATH& pastedSheet : pastedSheets[instance] )
1775 {
1776 int page = 1;
1777 wxString pageNum = wxString::Format( "%d", page );
1778
1779 while( hierarchy.PageNumberExists( pageNum ) )
1780 pageNum = wxString::Format( "%d", ++page );
1781
1782 pastedSheet.SetPageNumber( pageNum );
1783 hierarchy.push_back( pastedSheet );
1784 }
1785 }
1786
1789
1790 // Get a version with correct sheet numbers since we've pasted sheets,
1791 // we'll need this when annotating next
1792 hierarchy = m_frame->Schematic().GetSheets();
1793 }
1794
1795 std::map<SCH_SHEET_PATH, SCH_REFERENCE_LIST> annotatedSymbols;
1796
1797 // Update the list of symbol instances that satisfy the annotation criteria.
1798 for( const SCH_SHEET_PATH& sheetPath : pasteInstances )
1799 {
1800 for( size_t i = 0; i < pastedSymbols[sheetPath].GetCount(); i++ )
1801 {
1802 if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS
1803 || pasteMode == PASTE_MODE::RESPECT_OPTIONS
1804 || pastedSymbols[sheetPath][i].AlwaysAnnotate() )
1805 {
1806 annotatedSymbols[sheetPath].AddItem( pastedSymbols[sheetPath][i] );
1807 }
1808 }
1809 }
1810
1811 if( !annotatedSymbols.empty() )
1812 {
1813 for( SCH_SHEET_PATH& instance : pasteInstances )
1814 {
1815 annotatedSymbols[instance].SortByReferenceOnly();
1816
1817 if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS )
1818 annotatedSymbols[instance].ReannotateDuplicates( existingRefs );
1819 else
1820 annotatedSymbols[instance].ReannotateByOptions( (ANNOTATE_ORDER_T) annotate.sort_order,
1821 (ANNOTATE_ALGO_T) annotate.method,
1822 annotateStartNum, existingRefs,
1823 false,
1824 &hierarchy );
1825
1826 annotatedSymbols[instance].UpdateAnnotation();
1827
1828 // Update existing refs for next iteration
1829 for( size_t i = 0; i < annotatedSymbols[instance].GetCount(); i++ )
1830 existingRefs.AddItem( annotatedSymbols[instance][i] );
1831 }
1832 }
1833
1835
1836 // Now clear the previous selection, select the pasted items, and fire up the "move" tool.
1838 m_toolMgr->RunAction( EE_ACTIONS::addItemsToSel, true, &loadedItems );
1839
1840 EE_SELECTION& selection = selTool->GetSelection();
1841
1842 if( !selection.Empty() )
1843 {
1844 if( aEvent.IsAction( &ACTIONS::duplicate ) )
1845 {
1846 int closest_dist = INT_MAX;
1847
1848 auto processPt =
1849 [&]( const VECTOR2I& pt )
1850 {
1851 int dist = ( eventPos - pt ).EuclideanNorm();
1852
1853 if( dist < closest_dist )
1854 {
1855 selection.SetReferencePoint( pt );
1856 closest_dist = dist;
1857 }
1858 };
1859
1860 // Prefer connection points (which should remain on grid)
1861 for( EDA_ITEM* item : selection.Items() )
1862 {
1863 SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item );
1864 LIB_PIN* lib_pin = dynamic_cast<LIB_PIN*>( item );
1865
1866 if( sch_item && sch_item->IsConnectable() )
1867 {
1868 for( const VECTOR2I& pt : sch_item->GetConnectionPoints() )
1869 processPt( pt );
1870 }
1871 else if( lib_pin )
1872 {
1873 processPt( lib_pin->GetPosition() );
1874 }
1875 }
1876
1877 // Only process other points if we didn't find any connection points
1878 if( closest_dist == INT_MAX )
1879 {
1880 for( EDA_ITEM* item : selection.Items() )
1881 {
1882 switch( item->Type() )
1883 {
1884 case SCH_LINE_T:
1885 processPt( static_cast<SCH_LINE*>( item )->GetStartPoint() );
1886 processPt( static_cast<SCH_LINE*>( item )->GetEndPoint() );
1887 break;
1888
1889 case SCH_SHAPE_T:
1890 {
1891 SCH_SHAPE* shape = static_cast<SCH_SHAPE*>( item );
1892
1893 switch( shape->GetShape() )
1894 {
1895 case SHAPE_T::RECT:
1896 for( const VECTOR2I& pt : shape->GetRectCorners() )
1897 processPt( pt );
1898
1899 break;
1900
1901 case SHAPE_T::CIRCLE:
1902 processPt( shape->GetCenter() );
1903 break;
1904
1905 case SHAPE_T::POLY:
1906 for( int ii = 0; ii < shape->GetPolyShape().TotalVertices(); ++ii )
1907 processPt( shape->GetPolyShape().CVertex( ii ) );
1908
1909 break;
1910
1911 default:
1912 processPt( shape->GetStart() );
1913 processPt( shape->GetEnd() );
1914 break;
1915 }
1916
1917 break;
1918 }
1919
1920 default:
1921 processPt( item->GetPosition() );
1922 break;
1923 }
1924 }
1925 }
1926
1928 }
1929 else
1930 {
1931 SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.GetTopLeftItem() );
1932
1933 selection.SetReferencePoint( item->GetPosition() );
1934 }
1935
1937 }
1938
1939 return 0;
1940}
1941
1942
1944{
1946 EE_SELECTION& selection = selTool->RequestSelection( { SCH_SYMBOL_T } );
1947 SCH_SYMBOL* symbol = nullptr;
1948 SYMBOL_EDIT_FRAME* symbolEditor;
1949
1950 if( selection.GetSize() >= 1 )
1951 symbol = (SCH_SYMBOL*) selection.Front();
1952
1953 if( selection.IsHover() )
1955
1956 if( !symbol || symbol->GetEditFlags() != 0 )
1957 return 0;
1958
1959 if( symbol->IsMissingLibSymbol() )
1960 {
1961 m_frame->ShowInfoBarError( _( "Symbols with broken library symbol links cannot "
1962 "be edited." ) );
1963 return 0;
1964 }
1965
1967 symbolEditor = (SYMBOL_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
1968
1969 if( symbolEditor )
1970 {
1971 if( wxWindow* blocking_win = symbolEditor->Kiway().GetBlockingDialog() )
1972 blocking_win->Close( true );
1973
1974 if( aEvent.IsAction( &EE_ACTIONS::editWithLibEdit ) )
1975 {
1976 symbolEditor->LoadSymbolFromSchematic( symbol );
1977 }
1979 {
1980 symbolEditor->LoadSymbol( symbol->GetLibId(), symbol->GetUnit(), symbol->GetConvert() );
1981
1982 if( !symbolEditor->IsSymbolTreeShown() )
1983 {
1984 wxCommandEvent evt;
1985 symbolEditor->OnToggleSymbolTree( evt );
1986 }
1987 }
1988 }
1989
1990 return 0;
1991}
1992
1993
1995{
1996 wxCommandEvent dummy;
1998 return 0;
1999}
2000
2001
2003{
2004 wxCommandEvent dummy;
2006 return 0;
2007}
2008
2009
2011{
2013 dlg.ShowQuasiModal();
2014 return 0;
2015}
2016
2017
2019{
2022
2023 return 0;
2024}
2025
2026
2028{
2029 wxCommandEvent dummy;
2031 return 0;
2032}
2033
2034
2036{
2037 wxCommandEvent dummy;
2039 return 0;
2040}
2041
2042
2044{
2046 dlg.ShowModal();
2047 return 0;
2048}
2049
2050
2052{
2053 int result = NET_PLUGIN_CHANGE;
2054
2055 // If a plugin is removed or added, rebuild and reopen the new dialog
2056 while( result == NET_PLUGIN_CHANGE )
2057 result = InvokeDialogNetList( m_frame );
2058
2059 return 0;
2060}
2061
2062
2064{
2066 return 0;
2067}
2068
2069
2071{
2074 return 0;
2075}
2076
2077
2079{
2080 getEditFrame<SCH_EDIT_FRAME>()->ToggleSearch();
2081 return 0;
2082}
2083
2084
2086{
2087 getEditFrame<SCH_EDIT_FRAME>()->ToggleSchematicHierarchy();
2088 return 0;
2089}
2090
2091
2093{
2094 getEditFrame<SCH_EDIT_FRAME>()->ToggleNetNavigator();
2095 return 0;
2096}
2097
2098
2100{
2103
2106
2107 return 0;
2108}
2109
2110
2112{
2115
2118
2119 return 0;
2120}
2121
2122
2124{
2127
2130
2131 return 0;
2132}
2133
2134
2136{
2139
2142
2143 return 0;
2144}
2145
2146
2148{
2151
2154
2155 return 0;
2156}
2157
2158
2160{
2163
2166
2167 return 0;
2168}
2169
2170
2172{
2175
2179
2180 return 0;
2181}
2182
2183
2185{
2188
2192
2193 return 0;
2194}
2195
2196
2198{
2199 m_frame->eeconfig()->m_Drawing.line_mode = aEvent.Parameter<int>();
2201 return 0;
2202}
2203
2204
2206{
2208 m_frame->eeconfig()->m_Drawing.line_mode %= LINE_MODE::LINE_MODE_COUNT;
2210 return 0;
2211}
2212
2213
2215{
2218 return 0;
2219}
2220
2221
2223{
2226 return 0;
2227}
2228
2229
2231{
2232
2234 return 0;
2235}
2236
2237
2239{
2240 int errors = 0;
2241 wxString details;
2242 bool quiet = aEvent.Parameter<bool>();
2243
2244 // Repair duplicate IDs.
2245 std::map<KIID, EDA_ITEM*> ids;
2246 int duplicates = 0;
2247
2248 auto processItem =
2249 [&]( EDA_ITEM* aItem )
2250 {
2251 auto it = ids.find( aItem->m_Uuid );
2252
2253 if( it != ids.end() && it->second != aItem )
2254 {
2255 duplicates++;
2256 const_cast<KIID&>( aItem->m_Uuid ) = KIID();
2257 }
2258
2259 ids[ aItem->m_Uuid ] = aItem;
2260 };
2261
2262 // Symbol IDs are the most important, so give them the first crack at "claiming" a
2263 // particular KIID.
2264
2265 for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().GetSheets() )
2266 {
2267 SCH_SCREEN* screen = sheet.LastScreen();
2268
2269 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
2270 {
2271 processItem( item );
2272
2273 for( SCH_PIN* pin : static_cast<SCH_SYMBOL*>( item )->GetPins( &sheet ) )
2274 processItem( pin );
2275 }
2276 }
2277
2278 for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().GetSheets() )
2279 {
2280 SCH_SCREEN* screen = sheet.LastScreen();
2281
2282 for( SCH_ITEM* item : screen->Items() )
2283 {
2284 processItem( item );
2285
2286 item->RunOnChildren(
2287 [&]( SCH_ITEM* aChild )
2288 {
2289 processItem( item );
2290 } );
2291 }
2292 }
2293
2294 /*******************************
2295 * Your test here
2296 */
2297
2298 /*******************************
2299 * Inform the user
2300 */
2301
2302 if( duplicates )
2303 {
2304 errors += duplicates;
2305 details += wxString::Format( _( "%d duplicate IDs replaced.\n" ), duplicates );
2306 }
2307
2308 if( errors )
2309 {
2310 m_frame->OnModify();
2311
2312 wxString msg = wxString::Format( _( "%d potential problems repaired." ), errors );
2313
2314 if( !quiet )
2315 DisplayInfoMessage( m_frame, msg, details );
2316 }
2317 else if( !quiet )
2318 {
2319 DisplayInfoMessage( m_frame, _( "No errors found." ) );
2320 }
2321
2322 return 0;
2323}
2324
2325
2327{
2328 Go( &SCH_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() );
2329 Go( &SCH_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() );
2330 Go( &SCH_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
2337 Go( &SCH_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() );
2338 Go( &SCH_EDITOR_CONTROL::Quit, ACTIONS::quit.MakeEvent() );
2339
2342
2348
2351
2357
2359
2360 Go( &SCH_EDITOR_CONTROL::Undo, ACTIONS::undo.MakeEvent() );
2361 Go( &SCH_EDITOR_CONTROL::Redo, ACTIONS::redo.MakeEvent() );
2362 Go( &SCH_EDITOR_CONTROL::Cut, ACTIONS::cut.MakeEvent() );
2363 Go( &SCH_EDITOR_CONTROL::Copy, ACTIONS::copy.MakeEvent() );
2367
2381
2385
2399
2401
2403
2408}
const char * name
Definition: DXF_plotter.cpp:56
static TOOL_ACTION updatePcbFromSchematic
Definition: actions.h:168
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:159
static TOOL_ACTION showSymbolEditor
Definition: actions.h:165
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:77
static TOOL_ACTION undo
Definition: actions.h:65
static TOOL_ACTION duplicate
Definition: actions.h:72
static TOOL_ACTION doDelete
Definition: actions.h:73
static TOOL_ACTION quit
Definition: actions.h:59
static TOOL_ACTION save
Definition: actions.h:51
static TOOL_ACTION redo
Definition: actions.h:66
static TOOL_ACTION updateSchematicFromPcb
Definition: actions.h:169
static TOOL_ACTION print
Definition: actions.h:57
static TOOL_ACTION doNew
Definition: actions.h:47
static TOOL_ACTION cut
Definition: actions.h:67
static TOOL_ACTION refreshPreview
Definition: actions.h:110
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
Calculates the connectivity of a schematic and generates netlists.
CONNECTION_SUBGRAPH * GetSubgraphForItem(SCH_ITEM *aItem)
A subgraph is a set of items that are electrically connected on a single sheet.
PRIORITY GetDriverPriority()
const std::vector< SCH_ITEM * > & GetItems() const
Provides 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.
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...
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)
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:232
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:129
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:123
const KIID m_Uuid
Definition: eda_item.h:475
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
EDA_ITEM * GetParent() const
Definition: eda_item.h:99
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:247
SHAPE_T GetShape() const
Definition: eda_shape.h:113
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:145
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:120
std::vector< VECTOR2I > GetRectCorners() const
Definition: eda_shape.cpp:1020
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:77
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:92
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:175
PANEL_ANNOTATE m_AnnotatePanel
static TOOL_ACTION importFPAssignments
Definition: ee_actions.h:175
static TOOL_ACTION repairSchematic
Definition: ee_actions.h:252
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:261
static TOOL_ACTION lineMode90
Definition: ee_actions.h:256
static TOOL_ACTION toggleHiddenPins
Definition: ee_actions.h:230
static TOOL_ACTION highlightNet
Definition: ee_actions.h:283
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:284
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:251
static TOOL_ACTION toggleERCWarnings
Definition: ee_actions.h:233
static TOOL_ACTION simTune
Definition: ee_actions.h:272
static TOOL_ACTION toggleERCExclusions
Definition: ee_actions.h:235
static TOOL_ACTION lineModeNext
Definition: ee_actions.h:258
static TOOL_ACTION lineModeFree
Definition: ee_actions.h:255
static TOOL_ACTION editLibSymbolWithLibEdit
Definition: ee_actions.h:173
static TOOL_ACTION toggleERCErrors
Definition: ee_actions.h:234
static TOOL_ACTION toggleOPCurrents
Definition: ee_actions.h:237
static TOOL_ACTION highlightNetTool
Definition: ee_actions.h:286
static TOOL_ACTION updateNetHighlighting
Definition: ee_actions.h:285
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:240
static TOOL_ACTION rescueSymbols
Definition: ee_actions.h:168
static TOOL_ACTION toggleHiddenFields
Definition: ee_actions.h:231
static TOOL_ACTION editWithLibEdit
Definition: ee_actions.h:172
static TOOL_ACTION simProbe
Definition: ee_actions.h:271
static TOOL_ACTION exportSymbolsToLibrary
Definition: ee_actions.h:179
static TOOL_ACTION drawSheetOnClipboard
Definition: ee_actions.h:248
static TOOL_ACTION editSymbolFields
Definition: ee_actions.h:153
static TOOL_ACTION showNetNavigator
Definition: ee_actions.h:287
static TOOL_ACTION annotate
Definition: ee_actions.h:152
static TOOL_ACTION toggleDirectiveLabels
Definition: ee_actions.h:232
static TOOL_ACTION showHierarchy
Definition: ee_actions.h:222
static TOOL_ACTION toggleOPVoltages
Definition: ee_actions.h:236
static TOOL_ACTION lineMode45
Definition: ee_actions.h:257
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:180
void Collect(SCH_SCREEN *aScreen, const std::vector< KICAD_T > &aScanTypes, const VECTOR2I &aPos, int aUnit=0, int aConvert=0)
Scan a EDA_ITEM using this class's Inspector method which does the collection.
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:238
void GuessSelectionCandidates(EE_COLLECTOR &collector, const VECTOR2I &aPos)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
EE_SELECTION & RequestSelection(const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T })
Return either an existing selection (filtered), or the selection at the current cursor position if th...
bool SelectPoint(const VECTOR2I &aWhere, const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T }, EDA_ITEM **aItem=nullptr, bool *aSelectionCancelledFlag=nullptr, bool aCheckLocked=false, bool aAdd=false, bool aSubtract=false, bool aExclusiveOr=false)
Perform a click-type selection at a point (usually the cursor position).
int ClearSelection(const TOOL_EVENT &aEvent)
Select all visible items in sheet.
EDA_ITEM * GetNode(VECTOR2I aPosition)
Finds a connected item at a point (usually the cursor position).
EE_SELECTION & GetSelection()
EDA_ITEM * GetTopLeftItem(bool onlyModules=false) const override
Definition: erc.h:48
static const TOOL_EVENT ClearedEvent
Definition: actions.h:209
static const TOOL_EVENT SelectedEvent
Definition: actions.h:207
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:214
static const TOOL_EVENT PointSelectedEvent
Definition: actions.h:206
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:208
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
An interface for classes handling user events controlling the view behavior such as zooming,...
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:77
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:69
double GetScale() const
Definition: view.h:269
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1608
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition: view.h:393
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hide the item in the view (e.g.
Definition: view.cpp:1567
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition: view.cpp:1501
void MarkDirty()
Force redraw of view on the next rendering.
Definition: view.h:641
Definition: kiid.h:48
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:66
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:432
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
Definition: kiway.cpp:685
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:98
VECTOR2I GetPosition() const override
Definition: lib_pin.h:243
Define a library symbol object.
Definition: lib_symbol.h:99
LIB_ID GetLibId() const override
Definition: lib_symbol.h:146
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Definition: lib_symbol.cpp:588
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.
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:97
A holder to handle information on schematic or board items.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
void ReversePickersListOrder()
Reverse the order of pickers stored in this list.
void SetMotionHandler(MOTION_HANDLER aHandler)
Set a handler for mouse motion.
Definition: picker_tool.h:82
void SetClickHandler(CLICK_HANDLER aHandler)
Set a handler for mouse click event.
Definition: picker_tool.h:71
void SetSnapping(bool aSnap)
Definition: picker_tool.h:64
void SetCursor(KICURSOR aCursor)
Definition: picker_tool.h:62
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Set a handler for the finalize event.
Definition: picker_tool.h:102
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:126
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition: project.cpp:138
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:72
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:133
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:199
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:205
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:143
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:97
SCH_SHEET & Root() const
Definition: schematic.h:102
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
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
bool IsNet() const
SCH_ITEM * Parent() const
wxString Name(bool aIgnoreSheet=false) const
bool IsBus() const
SCH_ITEM * Driver() const
const std::vector< std::shared_ptr< SCH_CONNECTION > > & Members() 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 HighlightNetCursor(const TOOL_EVENT &aEvent)
int ImportFPAssignments(const TOOL_EVENT &aEvent)
int ChangeLineMode(const TOOL_EVENT &aEvent)
void setClipboardInstances(const SCH_SCREEN *aPastedScreen)
void doCrossProbeSchToPcb(const TOOL_EVENT &aEvent, bool aForce)
int ExportSymbolsToLibrary(const TOOL_EVENT &aEvent)
int SaveCurrSheetCopyAs(const TOOL_EVENT &aEvent)
Saves the currently-open schematic sheet to an other name.
bool rescueProject(RESCUER &aRescuer, bool aRunningOnDemand)
int CrossProbeToPcb(const TOOL_EVENT &aEvent)
Equivalent to the above, but initiated by the user.
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 ShowSearch(const TOOL_EVENT &aEvent)
int EditWithSymbolEditor(const TOOL_EVENT &aEvent)
int SimTune(const TOOL_EVENT &aEvent)
Highlight net under the cursor.
int EditSymbolLibraryLinks(const TOOL_EVENT &aEvent)
int New(const TOOL_EVENT &aEvent)
std::map< wxString, SCH_SCREEN * > m_supplementaryClipboard
int ExplicitCrossProbeToPcb(const TOOL_EVENT &aEvent)
int ToggleOPCurrents(const TOOL_EVENT &aEvent)
int ShowPcbNew(const TOOL_EVENT &aEvent)
int UpdateNetHighlighting(const TOOL_EVENT &aEvent)
Launch a tool to highlight nets.
int ToggleERCErrors(const TOOL_EVENT &aEvent)
int TogglePythonConsole(const TOOL_EVENT &aEvent)
int ShowHierarchy(const TOOL_EVENT &aEvent)
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int ShowNetNavigator(const TOOL_EVENT &aEvent)
int SimProbe(const TOOL_EVENT &aEvent)
void updatePastedSymbol(SCH_SYMBOL *aSymbol, 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)
std::map< KIID_PATH, SCH_SYMBOL_INSTANCE > m_clipboardSymbolInstances
int Save(const TOOL_EVENT &aEvent)
bool RescueSymbolLibTableProject(bool aRunningOnDemand)
Notifies pcbnew about the selected item.
bool doCopy(bool aUseDuplicateClipboard=false)
< copy selection to clipboard or to m_duplicateClipboard
int Undo(const TOOL_EVENT &aEvent)
int ToggleERCExclusions(const TOOL_EVENT &aEvent)
int Plot(const TOOL_EVENT &aEvent)
int Print(const TOOL_EVENT &aEvent)
int Revert(const TOOL_EVENT &aEvent)
int GenerateBOM(const TOOL_EVENT &aEvent)
int 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:106
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 AddItemToScreenAndUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItem, bool aUndoAppend)
Add an item to the schematic and adds the changes to the undo/redo container.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void InitSheet(SCH_SHEET *aSheet, const wxString &aNewFilename)
Definition: sheet.cpp:98
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
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:544
void OnUpdatePCB(wxCommandEvent &event)
void SetHighlightedConnection(const wxString &aConnection)
void OnOpenPcbnew(wxCommandEvent &event)
void RecalculateConnections(SCH_CLEANUP_FLAGS aCleanupFlags)
Generate the connection data for the entire schematic hierarchy.
void OnAnnotate(wxCommandEvent &event)
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
void 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 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:51
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:105
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
virtual bool IsConnectable() const
Definition: sch_item.h:352
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:423
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:418
bool IsConnectivityDirty() const
Definition: sch_item.h:416
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:367
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:536
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:82
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:662
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()
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:144
std::map< wxString, LIB_SYMBOL * > & GetLibSymbols()
Fetch a list of unique LIB_SYMBOL object pointers required to properly render each SCH_SYMBOL in this...
Definition: sch_screen.h:481
void Clear(bool aFree=true)
Delete all draw items and clears the project settings.
Definition: sch_screen.cpp:269
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:889
double m_LastZoomLevel
last value for the zoom level, useful in Eeschema when changing the current displayed sheet to reuse ...
Definition: sch_screen.h:586
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:109
const wxString & GetFileName() const
Definition: sch_screen.h:144
const std::vector< SCH_SYMBOL_INSTANCE > & GetSymbolInstances() const
Definition: sch_screen.h:516
const std::vector< SCH_SHEET_INSTANCE > & GetSheetInstances() const
Definition: sch_screen.h:521
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:310
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:722
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:161
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:183
Schematic symbol object.
Definition: sch_symbol.h:81
bool HasBrightenedPins()
int GetUnit() const
Definition: sch_symbol.h:231
wxString GetSchSymbolLibraryName() const
Definition: sch_symbol.cpp:294
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:698
void ClearBrightenedPins()
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:891
int GetConvert() const
Definition: sch_symbol.h:273
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:740
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:239
void SetUnit(int aUnit)
Change the unit number to aUnit.
Definition: sch_symbol.cpp:388
const LIB_ID & GetLibId() const
Definition: sch_symbol.h:178
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:939
void SetUnitSelection(const SCH_SHEET_PATH *aSheet, int aUnitSelection)
Set the selected unit of this symbol on one sheet.
Definition: sch_symbol.cpp:833
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:195
void SetLibSymbol(LIB_SYMBOL *aLibSymbol)
Set this schematic symbol library symbol reference to aLibSymbol.
Definition: sch_symbol.cpp:303
virtual void SetTextSpinStyle(TEXT_SPIN_STYLE aSpinStyle)
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:193
void BrightenItem(EDA_ITEM *aItem)
void UnbrightenItem(EDA_ITEM *aItem)
void SetIsHover(bool aIsHover)
Definition: selection.h:78
std::deque< EDA_ITEM * > & Items()
Definition: selection.h:213
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:260
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:109
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)
int FindModelPinIndex(const std::string &aSymbolPinNumber)
Definition: sim_model.cpp:722
const SPICE_GENERATOR & SpiceGenerator() const
Definition: sim_model.h:430
virtual std::vector< std::string > CurrentNames(const SPICE_ITEM &aItem) const
Implement an OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:427
const std::string & GetString()
Definition: richio.h:450
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:156
bool DisableGridSnapping() const
Definition: tool_event.h:344
T Parameter() const
Return a non-standard parameter assigned to the event.
Definition: tool_event.h:442
bool 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:81
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
void Activate()
Run the tool.
Master controller class:
Definition: tool_manager.h:55
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
std::string GetClipboardUTF8() const
Return the information currently stored in the system clipboard.
TOOLS_HOLDER * GetToolHolder() const
Definition: tool_manager.h:296
bool SaveClipboard(const std::string &aTextUTF8)
Store information to the system clipboard.
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:69
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:380
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:363
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:283
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:335
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:308
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)
int InvokeDialogPrintUsingPrinter(SCH_EDIT_FRAME *aCaller)
Create and show DIALOG_PRINT_USING_PRINTER and return whatever DIALOG_PRINT_USING_PRINTER::ShowModal(...
#define _(s)
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:506
#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
@ FRAME_SCH_SYMBOL_EDITOR
Definition: frame_type.h:35
@ FRAME_SCH_VIEWER
Definition: frame_type.h:36
@ FRAME_SIMULATOR
Definition: frame_type.h:38
const std::string KiCadSymbolLibFileExtension
const std::string KiCadSchematicFileExtension
wxString KiCadSchematicFileWildcard()
wxString KiCadSymbolLibFileWildcard()
#define NET_PLUGIN_CHANGE
Create and shows DIALOG_EXPORT_NETLIST and returns whatever DIALOG_EXPORT_NETLIST::ShowModal() return...
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
@ LAYER_ERC_WARN
Definition: layer_ids.h:373
@ LAYER_ERC_EXCLUSION
Definition: layer_ids.h:375
@ LAYER_ERC_ERR
Definition: layer_ids.h:374
@ LAYER_OP_CURRENTS
Definition: layer_ids.h:392
@ LAYER_OP_VOLTAGES
Definition: layer_ids.h:391
@ REPAINT
Item needs to be redrawn.
Definition: view_item.h:52
@ GEOMETRY
Position or shape has changed.
Definition: view_item.h:49
#define MAX_PAGE_SIZE_EESCHEMA_MILS
Definition: page_info.h:41
@ 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.
std::vector< FAB_LAYER_COLOR > dummy
wxString UnescapeString(const wxString &aSource)
A simple container for sheet instance information.
A simple container for schematic symbol instance information.
static constexpr auto NOT_CONNECTED
Definition: sim_model.h:302
std::string refName
Definition for symbol library class.
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
@ AS_GLOBAL
Global action (toolbar/main menu event, global shortcut)
Definition: tool_action.h:45
@ TA_UNDO_REDO_PRE
Definition: tool_event.h:101
@ TC_MESSAGE
Definition: tool_event.h:53
double EuclideanNorm(const VECTOR2I &vector)
Definition: trigo.h:129
@ SCH_LINE_T
Definition: typeinfo.h:136
@ SCH_SYMBOL_T
Definition: typeinfo.h:146
@ SCH_FIELD_T
Definition: typeinfo.h:145
@ SCH_SHEET_T
Definition: typeinfo.h:148
@ SCH_SHAPE_T
Definition: typeinfo.h:137
@ SCH_PIN_T
Definition: typeinfo.h:149
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:38