KiCad PCB EDA Suite
Loading...
Searching...
No Matches
schematic.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) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <bus_alias.h>
21#include <commit.h>
22#include <connection_graph.h>
23#include <core/ignore.h>
24#include <core/kicad_algo.h>
25#include <ee_collectors.h>
26#include <erc/erc_settings.h>
27#include <sch_marker.h>
28#include <project.h>
31#include <schematic.h>
32#include <sch_junction.h>
33#include <sch_line.h>
34#include <sch_screen.h>
35#include <sim/spice_settings.h>
36#include <sch_label.h>
37#include <sim/spice_value.h>
39
41 EDA_ITEM( nullptr, SCHEMATIC_T ),
42 m_project( nullptr ),
43 m_rootSheet( nullptr )
44{
47
48 SetProject( aPrj );
49
51 [&]( INSPECTABLE* aItem, PROPERTY_BASE* aProperty, COMMIT* aCommit )
52 {
53 // Special case: propagate value, footprint, and datasheet fields to other units
54 // of a given symbol if they aren't in the selection
55
56 SCH_FIELD* field = dynamic_cast<SCH_FIELD*>( aItem );
57
58 if( !field || !IsValid() )
59 return;
60
61 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( field->GetParent() );
62
63 if( !symbol || aProperty->Name() != _HKI( "Text" ) )
64 return;
65
66 // TODO(JE) This will need to get smarter to enable API access
67 SCH_SHEET_PATH sheetPath = CurrentSheet();
68
69 wxString newValue = aItem->Get<wxString>( aProperty );
70
71 wxString ref = symbol->GetRef( &sheetPath );
72 int unit = symbol->GetUnit();
73 LIB_ID libId = symbol->GetLibId();
74
75 for( SCH_SHEET_PATH& sheet : GetSheets() )
76 {
77 std::vector<SCH_SYMBOL*> otherUnits;
78
79 CollectOtherUnits( ref, unit, libId, sheet, &otherUnits );
80
81 for( SCH_SYMBOL* otherUnit : otherUnits )
82 {
83 switch( field->GetId() )
84 {
85 case VALUE_FIELD:
86 {
87 if( aCommit )
88 aCommit->Modify( otherUnit, sheet.LastScreen() );
89
90 otherUnit->SetValueFieldText( newValue );
91 break;
92 }
93
94 case FOOTPRINT_FIELD:
95 {
96 if( aCommit )
97 aCommit->Modify( otherUnit, sheet.LastScreen() );
98
99 otherUnit->SetFootprintFieldText( newValue );
100 break;
101 }
102
103 case DATASHEET_FIELD:
104 {
105 if( aCommit )
106 aCommit->Modify( otherUnit, sheet.LastScreen() );
107
108 otherUnit->GetField( DATASHEET_FIELD )->SetText( newValue );
109 break;
110 }
111
112 default:
113 break;
114 }
115 }
116 }
117 } );
118}
119
120
122{
124
125 delete m_currentSheet;
126 delete m_connectionGraph;
127}
128
129
131{
132 if( m_project )
133 {
135
136 // d'tor will save settings to file
137 delete project.m_ErcSettings;
138 project.m_ErcSettings = nullptr;
139
140 // d'tor will save settings to file
141 delete project.m_SchematicSettings;
142 project.m_SchematicSettings = nullptr;
143
144 m_project = nullptr; // clear the project, so we don't do this again when setting a new one
145 }
146
147 delete m_rootSheet;
148
149 m_rootSheet = nullptr;
150
153}
154
155
157{
158 if( m_project )
159 {
161
162 // d'tor will save settings to file
163 delete project.m_ErcSettings;
164 project.m_ErcSettings = nullptr;
165
166 // d'tor will save settings to file
167 delete project.m_SchematicSettings;
168 project.m_SchematicSettings = nullptr;
169 }
170
171 m_project = aPrj;
172
173 if( m_project )
174 {
176 project.m_ErcSettings = new ERC_SETTINGS( &project, "erc" );
177 project.m_SchematicSettings = new SCHEMATIC_SETTINGS( &project, "schematic" );
178
179 project.m_SchematicSettings->LoadFromFile();
180 project.m_SchematicSettings->m_NgspiceSettings->LoadFromFile();
181 project.m_ErcSettings->LoadFromFile();
182 }
183}
184
185
186void SCHEMATIC::SetRoot( SCH_SHEET* aRootSheet )
187{
188 wxCHECK_RET( aRootSheet, wxS( "Call to SetRoot with null SCH_SHEET!" ) );
189
190 m_rootSheet = aRootSheet;
191
194
196}
197
198
200{
201 return IsValid() ? m_rootSheet->GetScreen() : nullptr;
202}
203
204
205void SCHEMATIC::GetContextualTextVars( wxArrayString* aVars ) const
206{
207 auto add =
208 [&]( const wxString& aVar )
209 {
210 if( !alg::contains( *aVars, aVar ) )
211 aVars->push_back( aVar );
212 };
213
214 add( wxT( "#" ) );
215 add( wxT( "##" ) );
216 add( wxT( "SHEETPATH" ) );
217 add( wxT( "SHEETNAME" ) );
218 add( wxT( "FILENAME" ) );
219 add( wxT( "FILEPATH" ) );
220 add( wxT( "PROJECTNAME" ) );
221
222 if( !CurrentSheet().empty() )
224
225 for( std::pair<wxString, wxString> entry : Prj().GetTextVars() )
226 add( entry.first );
227}
228
229
230bool SCHEMATIC::ResolveTextVar( const SCH_SHEET_PATH* aSheetPath, wxString* token,
231 int aDepth ) const
232{
233 wxCHECK( aSheetPath, false );
234
235 if( token->IsSameAs( wxT( "#" ) ) )
236 {
237 *token = aSheetPath->GetPageNumber();
238 return true;
239 }
240 else if( token->IsSameAs( wxT( "##" ) ) )
241 {
242 *token = wxString::Format( "%i", Root().CountSheets() );
243 return true;
244 }
245 else if( token->IsSameAs( wxT( "SHEETPATH" ) ) )
246 {
247 *token = aSheetPath->PathHumanReadable();
248 return true;
249 }
250 else if( token->IsSameAs( wxT( "SHEETNAME" ) ) )
251 {
252 *token = aSheetPath->Last()->GetName();
253 return true;
254 }
255 else if( token->IsSameAs( wxT( "FILENAME" ) ) )
256 {
257 wxFileName fn( GetFileName() );
258 *token = fn.GetFullName();
259 return true;
260 }
261 else if( token->IsSameAs( wxT( "FILEPATH" ) ) )
262 {
263 wxFileName fn( GetFileName() );
264 *token = fn.GetFullPath();
265 return true;
266 }
267 else if( token->IsSameAs( wxT( "PROJECTNAME" ) ) )
268 {
269 *token = Prj().GetProjectName();
270 return true;
271 }
272
273 if( aSheetPath->LastScreen()->GetTitleBlock().TextVarResolver( token, m_project ) )
274 return true;
275
276 if( Prj().TextVarResolver( token ) )
277 return true;
278
279 return false;
280}
281
282
284{
285 return IsValid() ? m_rootSheet->GetScreen()->GetFileName() : wxString( wxEmptyString );
286}
287
288
290{
291 wxASSERT( m_project );
293}
294
295
297{
298 wxASSERT( m_project );
300}
301
302
303std::vector<SCH_MARKER*> SCHEMATIC::ResolveERCExclusions()
304{
305 SCH_SHEET_LIST sheetList = GetSheets();
306 ERC_SETTINGS& settings = ErcSettings();
307
308 // Migrate legacy marker exclusions to new format to ensure exclusion matching functions across
309 // file versions. Silently drops any legacy exclusions which can not be mapped to the new format
310 // without risking an incorrect exclusion - this is preferable to silently dropping
311 // new ERC errors / warnings due to an incorrect match between a legacy and new
312 // marker serialization format
313 std::set<wxString> migratedExclusions;
314
315 for( auto it = settings.m_ErcExclusions.begin(); it != settings.m_ErcExclusions.end(); )
316 {
317 SCH_MARKER* testMarker = SCH_MARKER::DeserializeFromString( this, *it );
318
319 if( testMarker->IsLegacyMarker() )
320 {
321 const wxString settingsKey = testMarker->GetRCItem()->GetSettingsKey();
322
323 if( settingsKey != wxT( "pin_to_pin" )
324 && settingsKey != wxT( "hier_label_mismatch" )
325 && settingsKey != wxT( "different_unit_net" ) )
326 {
327 migratedExclusions.insert( testMarker->SerializeToString() );
328 }
329
330 it = settings.m_ErcExclusions.erase( it );
331 }
332 else
333 {
334 ++it;
335 }
336
337 delete testMarker;
338 }
339
340 settings.m_ErcExclusions.insert( migratedExclusions.begin(), migratedExclusions.end() );
341
342 // End of legacy exclusion removal / migrations
343
344 for( const SCH_SHEET_PATH& sheet : sheetList )
345 {
346 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_MARKER_T ) )
347 {
348 SCH_MARKER* marker = static_cast<SCH_MARKER*>( item );
349 wxString serialized = marker->SerializeToString();
350 std::set<wxString>::iterator it = settings.m_ErcExclusions.find( serialized );
351
352 if( it != settings.m_ErcExclusions.end() )
353 {
354 marker->SetExcluded( true, settings.m_ErcExclusionComments[serialized] );
355 settings.m_ErcExclusions.erase( it );
356 }
357 }
358 }
359
360 std::vector<SCH_MARKER*> newMarkers;
361
362 for( const wxString& serialized : settings.m_ErcExclusions )
363 {
364 SCH_MARKER* marker = SCH_MARKER::DeserializeFromString( this, serialized );
365
366 if( marker )
367 {
368 marker->SetExcluded( true, settings.m_ErcExclusionComments[serialized] );
369 newMarkers.push_back( marker );
370 }
371 }
372
373 settings.m_ErcExclusions.clear();
374
375 return newMarkers;
376}
377
378
379std::shared_ptr<BUS_ALIAS> SCHEMATIC::GetBusAlias( const wxString& aLabel ) const
380{
381 for( const SCH_SHEET_PATH& sheet : GetSheets() )
382 {
383 for( const std::shared_ptr<BUS_ALIAS>& alias : sheet.LastScreen()->GetBusAliases() )
384 {
385 if( alias->GetName() == aLabel )
386 return alias;
387 }
388 }
389
390 return nullptr;
391}
392
393
395{
396 std::set<wxString> names;
397
398 for( const auto& [ key, subgraphList ] : m_connectionGraph->GetNetMap() )
399 {
400 CONNECTION_SUBGRAPH* firstSubgraph = subgraphList[0];
401
402 if( !firstSubgraph->GetDriverConnection()->IsBus()
404 {
405 names.insert( key.Name );
406 }
407 }
408
409 return names;
410}
411
412
413bool SCHEMATIC::ResolveCrossReference( wxString* token, int aDepth ) const
414{
415 SCH_SHEET_LIST sheetList = GetSheets();
416 wxString remainder;
417 wxString ref = token->BeforeFirst( ':', &remainder );
418 SCH_SHEET_PATH sheetPath;
419 SCH_ITEM* refItem = sheetList.GetItem( KIID( ref ), &sheetPath );
420
421 if( refItem && refItem->Type() == SCH_SYMBOL_T )
422 {
423 SCH_SYMBOL* refSymbol = static_cast<SCH_SYMBOL*>( refItem );
424
425 if( refSymbol->ResolveTextVar( &sheetPath, &remainder, aDepth + 1 ) )
426 *token = remainder;
427 else
428 *token = refSymbol->GetRef( &sheetPath, true ) + wxS( ":" ) + remainder;
429
430 return true; // Cross-reference is resolved whether or not the actual textvar was
431 }
432 else if( refItem && refItem->Type() == SCH_SHEET_T )
433 {
434 SCH_SHEET* refSheet = static_cast<SCH_SHEET*>( refItem );
435
436 sheetPath.push_back( refSheet );
437
438 if( refSheet->ResolveTextVar( &sheetPath, &remainder, aDepth + 1 ) )
439 *token = remainder;
440
441 return true; // Cross-reference is resolved whether or not the actual textvar was
442 }
443
444 return false;
445}
446
447
448std::map<int, wxString> SCHEMATIC::GetVirtualPageToSheetNamesMap() const
449{
450 std::map<int, wxString> namesMap;
451
452 for( const SCH_SHEET_PATH& sheet : GetSheets() )
453 {
454 if( sheet.size() == 1 )
455 namesMap[sheet.GetVirtualPageNumber()] = _( "<root sheet>" );
456 else
457 namesMap[sheet.GetVirtualPageNumber()] = sheet.Last()->GetName();
458 }
459
460 return namesMap;
461}
462
463
464std::map<int, wxString> SCHEMATIC::GetVirtualPageToSheetPagesMap() const
465{
466 std::map<int, wxString> pagesMap;
467
468 for( const SCH_SHEET_PATH& sheet : GetSheets() )
469 pagesMap[sheet.GetVirtualPageNumber()] = sheet.GetPageNumber();
470
471 return pagesMap;
472}
473
474
475wxString SCHEMATIC::ConvertRefsToKIIDs( const wxString& aSource ) const
476{
477 wxString newbuf;
478 size_t sourceLen = aSource.length();
479
480 for( size_t i = 0; i < sourceLen; ++i )
481 {
482 if( aSource[i] == '$' && i + 1 < sourceLen && aSource[i+1] == '{' )
483 {
484 wxString token;
485 bool isCrossRef = false;
486 int nesting = 0;
487
488 for( i = i + 2; i < sourceLen; ++i )
489 {
490 if( aSource[i] == '{'
491 && ( aSource[i-1] == '_' || aSource[i-1] == '^' || aSource[i-1] == '~' ) )
492 {
493 nesting++;
494 }
495
496 if( aSource[i] == '}' )
497 {
498 nesting--;
499
500 if( nesting < 0 )
501 break;
502 }
503
504 if( aSource[i] == ':' )
505 isCrossRef = true;
506
507 token.append( aSource[i] );
508 }
509
510 if( isCrossRef )
511 {
512 SCH_SHEET_LIST sheetList = GetSheets();
513 wxString remainder;
514 wxString ref = token.BeforeFirst( ':', &remainder );
515 SCH_REFERENCE_LIST references;
516
517 sheetList.GetSymbols( references );
518
519 for( size_t jj = 0; jj < references.GetCount(); jj++ )
520 {
521 SCH_SYMBOL* refSymbol = references[ jj ].GetSymbol();
522
523 if( ref == refSymbol->GetRef( &references[ jj ].GetSheetPath(), true ) )
524 {
525 token = refSymbol->m_Uuid.AsString() + wxS( ":" ) + remainder;
526 break;
527 }
528 }
529 }
530
531 newbuf.append( wxS( "${" ) + token + wxS( "}" ) );
532 }
533 else
534 {
535 newbuf.append( aSource[i] );
536 }
537 }
538
539 return newbuf;
540}
541
542
543wxString SCHEMATIC::ConvertKIIDsToRefs( const wxString& aSource ) const
544{
545 wxString newbuf;
546 size_t sourceLen = aSource.length();
547
548 for( size_t i = 0; i < sourceLen; ++i )
549 {
550 if( aSource[i] == '$' && i + 1 < sourceLen && aSource[i+1] == '{' )
551 {
552 wxString token;
553 bool isCrossRef = false;
554
555 for( i = i + 2; i < sourceLen; ++i )
556 {
557 if( aSource[i] == '}' )
558 break;
559
560 if( aSource[i] == ':' )
561 isCrossRef = true;
562
563 token.append( aSource[i] );
564 }
565
566 if( isCrossRef )
567 {
568 SCH_SHEET_LIST sheetList = GetSheets();
569 wxString remainder;
570 wxString ref = token.BeforeFirst( ':', &remainder );
571
572 SCH_SHEET_PATH refSheetPath;
573 SCH_ITEM* refItem = sheetList.GetItem( KIID( ref ), &refSheetPath );
574
575 if( refItem && refItem->Type() == SCH_SYMBOL_T )
576 {
577 SCH_SYMBOL* refSymbol = static_cast<SCH_SYMBOL*>( refItem );
578 token = refSymbol->GetRef( &refSheetPath, true ) + wxS( ":" ) + remainder;
579 }
580 }
581
582 newbuf.append( wxS( "${" ) + token + wxS( "}" ) );
583 }
584 else
585 {
586 newbuf.append( aSource[i] );
587 }
588 }
589
590 return newbuf;
591}
592
593
595{
596 static SCH_SHEET_LIST hierarchy;
597
598 hierarchy.clear();
599 hierarchy.BuildSheetList( m_rootSheet, false );
600
601 return hierarchy;
602}
603
604
606{
607 SCH_SCREENS screens( m_rootSheet );
608
610}
611
612
614{
615 // Filename is rootSheetName-sheetName-...-sheetName
616 // Note that we need to fetch the rootSheetName out of its filename, as the root SCH_SHEET's
617 // name is just a timestamp.
618
619 wxFileName rootFn( CurrentSheet().at( 0 )->GetFileName() );
620 wxString filename = rootFn.GetName();
621
622 for( unsigned i = 1; i < CurrentSheet().size(); i++ )
623 filename += wxT( "-" ) + CurrentSheet().at( i )->GetName();
624
625 return filename;
626}
627
628
630{
631 SCH_SCREEN* screen;
632 SCH_SCREENS s_list( Root() );
633
634 // Set the sheet count, and the sheet number (1 for root sheet)
635 int sheet_count = Root().CountSheets();
636 int sheet_number = 1;
637 const KIID_PATH& current_sheetpath = CurrentSheet().Path();
638
639 // @todo Remove all pseudo page number system is left over from prior to real page number
640 // implementation.
641 for( const SCH_SHEET_PATH& sheet : GetSheets() )
642 {
643 if( sheet.Path() == current_sheetpath ) // Current sheet path found
644 break;
645
646 sheet_number++; // Not found, increment before this current path
647 }
648
649 for( screen = s_list.GetFirst(); screen != nullptr; screen = s_list.GetNext() )
650 screen->SetPageCount( sheet_count );
651
652 CurrentSheet().SetVirtualPageNumber( sheet_number );
653 CurrentSheet().LastScreen()->SetVirtualPageNumber( sheet_number );
654 CurrentSheet().LastScreen()->SetPageNumber( CurrentSheet().GetPageNumber() );
655}
656
657
658void SCHEMATIC::RecomputeIntersheetRefs( const std::function<void( SCH_GLOBALLABEL* )>& aItemCallback )
659{
660 std::map<wxString, std::set<int>>& pageRefsMap = GetPageRefsMap();
661
662 pageRefsMap.clear();
663
664 for( const SCH_SHEET_PATH& sheet : GetSheets() )
665 {
666 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_GLOBAL_LABEL_T ) )
667 {
668 SCH_GLOBALLABEL* global = static_cast<SCH_GLOBALLABEL*>( item );
669 wxString resolvedLabel = global->GetShownText( &sheet, false );
670
671 pageRefsMap[ resolvedLabel ].insert( sheet.GetVirtualPageNumber() );
672 }
673 }
674
675 bool show = Settings().m_IntersheetRefsShow;
676
677 // Refresh all visible global labels. Note that we have to collect them first as the
678 // SCH_SCREEN::Update() call is going to invalidate the RTree iterator.
679
680 std::vector<SCH_GLOBALLABEL*> currentSheetGlobalLabels;
681
682 for( EDA_ITEM* item : CurrentSheet().LastScreen()->Items().OfType( SCH_GLOBAL_LABEL_T ) )
683 currentSheetGlobalLabels.push_back( static_cast<SCH_GLOBALLABEL*>( item ) );
684
685 for( SCH_GLOBALLABEL* globalLabel : currentSheetGlobalLabels )
686 {
687 std::vector<SCH_FIELD>& fields = globalLabel->GetFields();
688
689 fields[0].SetVisible( show );
690
691 if( show )
692 {
693 if( fields.size() == 1 && fields[0].GetTextPos() == globalLabel->GetPosition() )
694 globalLabel->AutoplaceFields( CurrentSheet().LastScreen(), false );
695
696 CurrentSheet().LastScreen()->Update( globalLabel );
697 aItemCallback( globalLabel );
698 }
699 }
700}
701
702
703wxString SCHEMATIC::GetOperatingPoint( const wxString& aNetName, int aPrecision,
704 const wxString& aRange )
705{
706 std::string spiceNetName( aNetName.Lower().ToStdString() );
708
709 if( spiceNetName == "gnd" || spiceNetName == "0" )
710 return wxEmptyString;
711
712 auto it = m_operatingPoints.find( spiceNetName );
713
714 if( it != m_operatingPoints.end() )
715 return SPICE_VALUE( it->second ).ToString( { aPrecision, aRange } );
716 else if( m_operatingPoints.empty() )
717 return wxS( "--" );
718 else
719 return wxS( "?" );
720}
721
722
724{
725 for( const SCH_SHEET_PATH& sheet : GetSheets() )
726 {
727 SCH_SCREEN* screen = sheet.LastScreen();
728
729 std::deque<EDA_ITEM*> allItems;
730
731 for( auto item : screen->Items() )
732 allItems.push_back( item );
733
734 // Add missing junctions and breakup wires as needed
735 for( const VECTOR2I& point : screen->GetNeededJunctions( allItems ) )
736 {
737 SCH_JUNCTION* junction = new SCH_JUNCTION( point );
738 screen->Append( junction );
739
740 // Breakup wires
741 for( SCH_LINE* wire : screen->GetBusesAndWires( point, true ) )
742 {
743 SCH_LINE* newSegment = wire->BreakAt( point );
744 screen->Append( newSegment );
745 }
746 }
747 }
748}
749
750
751void SCHEMATIC::OnItemsAdded( std::vector<SCH_ITEM*>& aNewItems )
752{
754}
755
756
757void SCHEMATIC::OnItemsRemoved( std::vector<SCH_ITEM*>& aRemovedItems )
758{
760}
761
762
763void SCHEMATIC::OnItemsChanged( std::vector<SCH_ITEM*>& aItems )
764{
766}
767
768
770{
772}
773
774
776{
777 if( !alg::contains( m_listeners, aListener ) )
778 m_listeners.push_back( aListener );
779}
780
781
783{
784 auto i = std::find( m_listeners.begin(), m_listeners.end(), aListener );
785
786 if( i != m_listeners.end() )
787 {
788 std::iter_swap( i, m_listeners.end() - 1 );
789 m_listeners.pop_back();
790 }
791}
792
793
795{
796 m_listeners.clear();
797}
798
799
801{
802 SCH_SHEET_LIST sheetList = GetSheets();
803 ERC_SETTINGS& ercSettings = ErcSettings();
804
805 ercSettings.m_ErcExclusions.clear();
806 ercSettings.m_ErcExclusionComments.clear();
807
808 for( unsigned i = 0; i < sheetList.size(); i++ )
809 {
810 for( SCH_ITEM* item : sheetList[i].LastScreen()->Items().OfType( SCH_MARKER_T ) )
811 {
812 SCH_MARKER* marker = static_cast<SCH_MARKER*>( item );
813
814 if( marker->IsExcluded() )
815 {
816 wxString serialized = marker->SerializeToString();
817 ercSettings.m_ErcExclusions.insert( serialized );
818 ercSettings.m_ErcExclusionComments[ serialized ] = marker->GetComment();
819 }
820 }
821 }
822}
823
824
826{
827 SCH_SHEET_LIST sheetList = GetSheets();
828
829 for( SCH_MARKER* marker : ResolveERCExclusions() )
830 {
831 SCH_SHEET_PATH errorPath;
832 ignore_unused( sheetList.GetItem( marker->GetRCItem()->GetMainItemID(), &errorPath ) );
833
834 if( errorPath.LastScreen() )
835 errorPath.LastScreen()->Append( marker );
836 else
837 RootScreen()->Append( marker );
838 }
839}
void SetPageCount(int aPageCount)
Definition: base_screen.cpp:63
void SetPageNumber(const wxString &aPageNumber)
Definition: base_screen.h:79
void SetVirtualPageNumber(int aPageNumber)
Definition: base_screen.h:76
Represent a set of changes (additions, deletions or modifications) of a data model (e....
Definition: commit.h:74
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
Definition: commit.h:105
Calculate the connectivity of a schematic and generates netlists.
const NET_MAP & GetNetMap() const
A subgraph is a set of items that are electrically connected on a single sheet.
static PRIORITY GetDriverPriority(SCH_ITEM *aDriver)
Return the priority (higher is more important) of a candidate driver.
const SCH_CONNECTION * GetDriverConnection() const
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:88
const KIID m_Uuid
Definition: eda_item.h:485
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:100
EDA_ITEM * GetParent() const
Definition: eda_item.h:102
Container for ERC settings.
Definition: erc_settings.h:121
std::map< wxString, wxString > m_ErcExclusionComments
Definition: erc_settings.h:182
std::set< wxString > m_ErcExclusions
Definition: erc_settings.h:181
Class that other classes need to inherit from, in order to be inspectable.
Definition: inspectable.h:36
wxAny Get(PROPERTY_BASE *aProperty) const
Definition: inspectable.h:99
Definition: kiid.h:49
wxString AsString() const
Definition: kiid.cpp:257
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
bool IsExcluded() const
Definition: marker_base.h:98
std::shared_ptr< RC_ITEM > GetRCItem() const
Definition: marker_base.h:112
void SetExcluded(bool aExcluded, const wxString &aComment=wxEmptyString)
Definition: marker_base.h:99
wxString GetComment() const
Definition: marker_base.h:105
static void ConvertToSpiceMarkup(std::string &aNetName)
Remove formatting wrappers and replace illegal spice net name characters with underscores.
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:70
ERC_SETTINGS * m_ErcSettings
Eeschema params.
Definition: project_file.h:132
SCHEMATIC_SETTINGS * m_SchematicSettings
Definition: project_file.h:135
Container for project specific data.
Definition: project.h:62
virtual const wxString GetProjectName() const
Return the short name of the project.
Definition: project.cpp:147
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:166
const wxString & Name() const
Definition: property.h:217
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:87
void UnregisterListeners(TYPE_ID aType)
Definition: property_mgr.h:280
void RegisterListener(TYPE_ID aType, PROPERTY_LISTENER aListenerFunc)
Registers a listener for the given type.
Definition: property_mgr.h:275
virtual void OnSchItemsRemoved(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:60
virtual void OnSchItemsChanged(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:61
virtual void OnSchSheetChanged(SCHEMATIC &aSch)
Definition: schematic.h:64
virtual void OnSchItemsAdded(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:59
These are loaded from Eeschema settings but then overwritten by the project settings.
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
Definition: schematic.cpp:130
void SetLegacySymbolInstanceData()
Update the symbol value and footprint instance data for legacy designs.
Definition: schematic.cpp:605
void OnItemsAdded(std::vector< SCH_ITEM * > &aNewItems)
Must be used if Add() is used using a BULK_x ADD_MODE to generate a change event for listeners.
Definition: schematic.cpp:751
CONNECTION_GRAPH * m_connectionGraph
Holds and calculates connectivity information of this schematic.
Definition: schematic.h:329
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:136
void ResolveERCExclusionsPostUpdate()
Update markers to match recorded exclusions.
Definition: schematic.cpp:825
void RemoveListener(SCHEMATIC_LISTENER *aListener)
Remove the specified listener.
Definition: schematic.cpp:782
void OnSchSheetChanged()
Notify the schematic and its listeners that the current sheet has been changed.
Definition: schematic.cpp:769
SCH_SHEET_PATH * m_currentSheet
The sheet path of the sheet currently being edited or displayed.
Definition: schematic.h:326
wxString GetOperatingPoint(const wxString &aNetName, int aPrecision, const wxString &aRange)
Definition: schematic.cpp:703
void OnItemsRemoved(std::vector< SCH_ITEM * > &aRemovedItems)
Must be used if Remove() is used using a BULK_x REMOVE_MODE to generate a change event for listeners.
Definition: schematic.cpp:757
virtual ~SCHEMATIC()
Definition: schematic.cpp:121
std::shared_ptr< BUS_ALIAS > GetBusAlias(const wxString &aLabel) const
Return a pointer to a bus alias object for the given label, or null if one doesn't exist.
Definition: schematic.cpp:379
std::vector< SCH_MARKER * > ResolveERCExclusions()
Definition: schematic.cpp:303
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:283
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:289
wxString ConvertKIIDsToRefs(const wxString &aSource) const
Definition: schematic.cpp:543
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
Definition: schematic.cpp:800
std::map< wxString, std::set< int > > & GetPageRefsMap()
Definition: schematic.h:177
SCH_SHEET_LIST & GetFullHierarchy() const
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:594
void FixupJunctions()
Add junctions to this schematic where required.
Definition: schematic.cpp:723
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:100
wxString ConvertRefsToKIIDs(const wxString &aSource) const
Definition: schematic.cpp:475
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
Definition: schematic.cpp:186
void SetProject(PROJECT *aPrj)
Definition: schematic.cpp:156
void AddListener(SCHEMATIC_LISTENER *aListener)
Add a listener to the schematic to receive calls whenever something on the schematic has been modifie...
Definition: schematic.cpp:775
std::map< int, wxString > GetVirtualPageToSheetPagesMap() const
Definition: schematic.cpp:464
PROJECT * m_project
Definition: schematic.h:315
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:199
SCHEMATIC(PROJECT *aPrj)
Definition: schematic.cpp:40
bool ResolveTextVar(const SCH_SHEET_PATH *aSheetPath, wxString *token, int aDepth) const
Definition: schematic.cpp:230
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
Definition: schematic.cpp:394
void RecomputeIntersheetRefs(const std::function< void(SCH_GLOBALLABEL *)> &aItemCallback)
Update the schematic's page reference map for all global labels, and refresh the labels so that they ...
Definition: schematic.cpp:658
void InvokeListeners(Func &&aFunc, Args &&... args)
Definition: schematic.h:309
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:121
void RemoveAllListeners()
Remove all listeners.
Definition: schematic.cpp:794
void GetContextualTextVars(wxArrayString *aVars) const
Definition: schematic.cpp:205
SCH_SHEET & Root() const
Definition: schematic.h:105
std::map< int, wxString > GetVirtualPageToSheetNamesMap() const
Definition: schematic.cpp:448
wxString GetUniqueFilenameForCurrentSheet()
Definition: schematic.cpp:613
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
Definition: schematic.cpp:629
std::vector< SCHEMATIC_LISTENER * > m_listeners
Currently installed listeners.
Definition: schematic.h:350
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:90
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
Definition: schematic.cpp:413
std::map< wxString, double > m_operatingPoints
Simulation operating points for text variable substitution.
Definition: schematic.h:345
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:296
void OnItemsChanged(std::vector< SCH_ITEM * > &aItems)
Notify the schematic and its listeners that an item on the schematic has been modified in some way.
Definition: schematic.cpp:763
SCH_SHEET * m_rootSheet
The top-level sheet in this schematic hierarchy (or potentially the only one)
Definition: schematic.h:318
bool IsBus() const
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
int GetId() const
Definition: sch_field.h:133
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:174
int GetUnit() const
Definition: sch_item.h:237
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const override
Definition: sch_label.cpp:892
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
SCH_LINE * BreakAt(const VECTOR2I &aPoint)
Break this segment into two at the specified point.
Definition: sch_line.cpp:582
static SCH_MARKER * DeserializeFromString(SCHEMATIC *schematic, const wxString &data)
Definition: sch_marker.cpp:112
wxString SerializeToString() const
Definition: sch_marker.cpp:91
bool IsLegacyMarker() const
Determines if this marker is legacy (i.e.
Definition: sch_marker.h:123
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
size_t GetCount() const
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:703
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
void SetLegacySymbolInstanceData()
Update the symbol value and footprint instance data for legacy designs.
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Definition: sch_screen.cpp:151
std::vector< SCH_LINE * > GetBusesAndWires(const VECTOR2I &aPosition, bool aIgnoreEndpoints=false) const
Return buses and wires passing through aPosition.
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:108
const wxString & GetFileName() const
Definition: sch_screen.h:143
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:154
void Update(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Update aItem's bounding box in the tree.
Definition: sch_screen.cpp:314
std::vector< VECTOR2I > GetNeededJunctions(const std::deque< EDA_ITEM * > &aItems) const
Return the unique set of points belonging to aItems where a junction is needed.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr) const
Fetch a SCH_ITEM by ID.
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.
void BuildSheetList(SCH_SHEET *aSheet, bool aCheckIntegrity)
Build the list of sheets and their sheet path from aSheet.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
wxString PathHumanReadable(bool aUseShortRootName=true, bool aStripTrailingSeparator=false) const
Return the sheet path in a human readable form made from the sheet names.
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
SCH_SCREEN * LastScreen()
wxString GetPageNumber() const
SCH_SHEET * at(size_t aIndex) const
Forwarded method from std::vector.
void SetVirtualPageNumber(int aPageNumber)
Set the sheet instance virtual page number.
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.
void clear()
Forwarded method from std::vector.
size_t size() const
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
wxString GetName() const
Definition: sch_sheet.h:107
int CountSheets() const
Count the number of sheets found in "this" sheet including all of the subsheets.
Definition: sch_sheet.cpp:788
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:110
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the sheet.
Definition: sch_sheet.cpp:237
Schematic symbol object.
Definition: sch_symbol.h:105
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the symbol.
const LIB_ID & GetLibId() const override
Definition: sch_symbol.h:194
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
Definition: sch_symbol.cpp:712
Helper class to recognize Spice formatted values.
Definition: spice_value.h:56
wxString ToString() const
Return string value as when converting double to string (e.g.
bool TextVarResolver(wxString *aToken, const PROJECT *aProject) const
Definition: title_block.cpp:96
static void GetContextualTextVars(wxArrayString *aVars)
Definition: title_block.cpp:74
wxString GetTextVars(const wxString &aSource)
Returns any variables unexpanded, e.g.
Definition: common.cpp:115
#define _HKI(x)
static bool empty(const wxTextEntryBase *aCtrl)
#define _(s)
void CollectOtherUnits(const wxString &aRef, int aUnit, const LIB_ID &aLibId, SCH_SHEET_PATH &aSheet, std::vector< SCH_SYMBOL * > *otherUnits)
void ignore_unused(const T &)
Definition: ignore.h:24
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:100
#define TYPE_HASH(x)
Definition: property.h:71
@ DATASHEET_FIELD
name of datasheet
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ SCH_SYMBOL_T
Definition: typeinfo.h:172
@ SCH_SHEET_T
Definition: typeinfo.h:174
@ SCH_MARKER_T
Definition: typeinfo.h:158
@ SCHEMATIC_T
Definition: typeinfo.h:203
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:168