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
43 EDA_ITEM( nullptr, SCHEMATIC_T ),
44 m_project( nullptr ),
45 m_rootSheet( nullptr )
46{
50
51 SetProject( aPrj );
52
54 [&]( INSPECTABLE* aItem, PROPERTY_BASE* aProperty, COMMIT* aCommit )
55 {
56 // Special case: propagate value, footprint, and datasheet fields to other units
57 // of a given symbol if they aren't in the selection
58
59 SCH_FIELD* field = dynamic_cast<SCH_FIELD*>( aItem );
60
61 if( !field || !IsValid() )
62 return;
63
64 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( field->GetParent() );
65
66 if( !symbol || aProperty->Name() != _HKI( "Text" ) )
67 return;
68
69 // TODO(JE) This will need to get smarter to enable API access
70 SCH_SHEET_PATH sheetPath = CurrentSheet();
71
72 wxString newValue = aItem->Get<wxString>( aProperty );
73
74 wxString ref = symbol->GetRef( &sheetPath );
75 int unit = symbol->GetUnit();
76 LIB_ID libId = symbol->GetLibId();
77
79 {
80 std::vector<SCH_SYMBOL*> otherUnits;
81
82 CollectOtherUnits( ref, unit, libId, sheet, &otherUnits );
83
84 for( SCH_SYMBOL* otherUnit : otherUnits )
85 {
86 switch( field->GetId() )
87 {
88 case VALUE_FIELD:
89 {
90 if( aCommit )
91 aCommit->Modify( otherUnit, sheet.LastScreen() );
92
93 otherUnit->SetValueFieldText( newValue );
94 break;
95 }
96
97 case FOOTPRINT_FIELD:
98 {
99 if( aCommit )
100 aCommit->Modify( otherUnit, sheet.LastScreen() );
101
102 otherUnit->SetFootprintFieldText( newValue );
103 break;
104 }
105
106 case DATASHEET_FIELD:
107 {
108 if( aCommit )
109 aCommit->Modify( otherUnit, sheet.LastScreen() );
110
111 otherUnit->GetField( DATASHEET_FIELD )->SetText( newValue );
112 break;
113 }
114
115 default:
116 break;
117 }
118 }
119 }
120 } );
121}
122
123
125{
127
128 delete m_currentSheet;
129 delete m_connectionGraph;
130
131 m_IsSchematicExists = false;
132}
133
134
136{
137 if( m_project )
138 {
140
141 // d'tor will save settings to file
142 delete project.m_ErcSettings;
143 project.m_ErcSettings = nullptr;
144
145 // d'tor will save settings to file
146 delete project.m_SchematicSettings;
147 project.m_SchematicSettings = nullptr;
148
149 m_project = nullptr; // clear the project, so we don't do this again when setting a new one
150 }
151
152 delete m_rootSheet;
153
154 m_rootSheet = nullptr;
155
158}
159
160
162{
163 if( m_project )
164 {
166
167 // d'tor will save settings to file
168 delete project.m_ErcSettings;
169 project.m_ErcSettings = nullptr;
170
171 // d'tor will save settings to file
172 delete project.m_SchematicSettings;
173 project.m_SchematicSettings = nullptr;
174 }
175
176 m_project = aPrj;
177
178 if( m_project )
179 {
181 project.m_ErcSettings = new ERC_SETTINGS( &project, "erc" );
182 project.m_SchematicSettings = new SCHEMATIC_SETTINGS( &project, "schematic" );
183
184 project.m_SchematicSettings->LoadFromFile();
185 project.m_SchematicSettings->m_NgspiceSettings->LoadFromFile();
186 project.m_ErcSettings->LoadFromFile();
187 }
188}
189
190
191void SCHEMATIC::SetRoot( SCH_SHEET* aRootSheet )
192{
193 wxCHECK_RET( aRootSheet, wxS( "Call to SetRoot with null SCH_SHEET!" ) );
194
195 m_rootSheet = aRootSheet;
196
199
201}
202
203
205{
206 return IsValid() ? m_rootSheet->GetScreen() : nullptr;
207}
208
209
210void SCHEMATIC::GetContextualTextVars( wxArrayString* aVars ) const
211{
212 auto add =
213 [&]( const wxString& aVar )
214 {
215 if( !alg::contains( *aVars, aVar ) )
216 aVars->push_back( aVar );
217 };
218
219 add( wxT( "#" ) );
220 add( wxT( "##" ) );
221 add( wxT( "SHEETPATH" ) );
222 add( wxT( "SHEETNAME" ) );
223 add( wxT( "FILENAME" ) );
224 add( wxT( "FILEPATH" ) );
225 add( wxT( "PROJECTNAME" ) );
226
227 if( !CurrentSheet().empty() )
229
230 for( std::pair<wxString, wxString> entry : Prj().GetTextVars() )
231 add( entry.first );
232}
233
234
235bool SCHEMATIC::ResolveTextVar( const SCH_SHEET_PATH* aSheetPath, wxString* token,
236 int aDepth ) const
237{
238 wxCHECK( aSheetPath, false );
239
240 if( token->IsSameAs( wxT( "#" ) ) )
241 {
242 *token = aSheetPath->GetPageNumber();
243 return true;
244 }
245 else if( token->IsSameAs( wxT( "##" ) ) )
246 {
247 *token = wxString::Format( "%i", Root().CountSheets() );
248 return true;
249 }
250 else if( token->IsSameAs( wxT( "SHEETPATH" ) ) )
251 {
252 *token = aSheetPath->PathHumanReadable();
253 return true;
254 }
255 else if( token->IsSameAs( wxT( "SHEETNAME" ) ) )
256 {
257 *token = aSheetPath->Last()->GetName();
258 return true;
259 }
260 else if( token->IsSameAs( wxT( "FILENAME" ) ) )
261 {
262 wxFileName fn( GetFileName() );
263 *token = fn.GetFullName();
264 return true;
265 }
266 else if( token->IsSameAs( wxT( "FILEPATH" ) ) )
267 {
268 wxFileName fn( GetFileName() );
269 *token = fn.GetFullPath();
270 return true;
271 }
272 else if( token->IsSameAs( wxT( "PROJECTNAME" ) ) )
273 {
274 *token = Prj().GetProjectName();
275 return true;
276 }
277
278 if( aSheetPath->LastScreen()->GetTitleBlock().TextVarResolver( token, m_project ) )
279 return true;
280
281 if( Prj().TextVarResolver( token ) )
282 return true;
283
284 return false;
285}
286
287
289{
290 return IsValid() ? m_rootSheet->GetScreen()->GetFileName() : wxString( wxEmptyString );
291}
292
293
295{
296 wxASSERT( m_project );
298}
299
300
302{
303 wxASSERT( m_project );
305}
306
307
308std::vector<SCH_MARKER*> SCHEMATIC::ResolveERCExclusions()
309{
311 ERC_SETTINGS& settings = ErcSettings();
312
313 // Migrate legacy marker exclusions to new format to ensure exclusion matching functions across
314 // file versions. Silently drops any legacy exclusions which can not be mapped to the new format
315 // without risking an incorrect exclusion - this is preferable to silently dropping
316 // new ERC errors / warnings due to an incorrect match between a legacy and new
317 // marker serialization format
318 std::set<wxString> migratedExclusions;
319
320 for( auto it = settings.m_ErcExclusions.begin(); it != settings.m_ErcExclusions.end(); )
321 {
322 SCH_MARKER* testMarker = SCH_MARKER::DeserializeFromString( sheetList, *it );
323
324 if( !testMarker )
325 {
326 it = settings.m_ErcExclusions.erase( it );
327 continue;
328 }
329
330 if( testMarker->IsLegacyMarker() )
331 {
332 const wxString settingsKey = testMarker->GetRCItem()->GetSettingsKey();
333
334 if( settingsKey != wxT( "pin_to_pin" )
335 && settingsKey != wxT( "hier_label_mismatch" )
336 && settingsKey != wxT( "different_unit_net" ) )
337 {
338 migratedExclusions.insert( testMarker->SerializeToString() );
339 }
340
341 it = settings.m_ErcExclusions.erase( it );
342 }
343 else
344 {
345 ++it;
346 }
347
348 delete testMarker;
349 }
350
351 settings.m_ErcExclusions.insert( migratedExclusions.begin(), migratedExclusions.end() );
352
353 // End of legacy exclusion removal / migrations
354
355 for( const SCH_SHEET_PATH& sheet : sheetList )
356 {
357 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_MARKER_T ) )
358 {
359 SCH_MARKER* marker = static_cast<SCH_MARKER*>( item );
360 wxString serialized = marker->SerializeToString();
361 std::set<wxString>::iterator it = settings.m_ErcExclusions.find( serialized );
362
363 if( it != settings.m_ErcExclusions.end() )
364 {
365 marker->SetExcluded( true, settings.m_ErcExclusionComments[serialized] );
366 settings.m_ErcExclusions.erase( it );
367 }
368 }
369 }
370
371 std::vector<SCH_MARKER*> newMarkers;
372
373 for( const wxString& serialized : settings.m_ErcExclusions )
374 {
375 SCH_MARKER* marker = SCH_MARKER::DeserializeFromString( sheetList, serialized );
376
377 if( marker )
378 {
379 marker->SetExcluded( true, settings.m_ErcExclusionComments[serialized] );
380 newMarkers.push_back( marker );
381 }
382 }
383
384 settings.m_ErcExclusions.clear();
385
386 return newMarkers;
387}
388
389
390std::shared_ptr<BUS_ALIAS> SCHEMATIC::GetBusAlias( const wxString& aLabel ) const
391{
392 for( const SCH_SHEET_PATH& sheet : BuildUnorderedSheetList() )
393 {
394 for( const std::shared_ptr<BUS_ALIAS>& alias : sheet.LastScreen()->GetBusAliases() )
395 {
396 if( alias->GetName() == aLabel )
397 return alias;
398 }
399 }
400
401 return nullptr;
402}
403
404
406{
407 std::set<wxString> names;
408
409 for( const auto& [ key, subgraphList ] : m_connectionGraph->GetNetMap() )
410 {
411 CONNECTION_SUBGRAPH* firstSubgraph = subgraphList[0];
412
413 if( !firstSubgraph->GetDriverConnection()->IsBus()
415 {
416 names.insert( key.Name );
417 }
418 }
419
420 return names;
421}
422
423
424bool SCHEMATIC::ResolveCrossReference( wxString* token, int aDepth ) const
425{
426 wxString remainder;
427 wxString ref = token->BeforeFirst( ':', &remainder );
428 SCH_SHEET_PATH sheetPath;
429 SCH_ITEM* refItem = GetItem( KIID( ref ), &sheetPath );
430
431 if( refItem && refItem->Type() == SCH_SYMBOL_T )
432 {
433 SCH_SYMBOL* refSymbol = static_cast<SCH_SYMBOL*>( refItem );
434
435 if( refSymbol->ResolveTextVar( &sheetPath, &remainder, aDepth + 1 ) )
436 *token = remainder;
437 else
438 *token = refSymbol->GetRef( &sheetPath, true ) + wxS( ":" ) + remainder;
439
440 return true; // Cross-reference is resolved whether or not the actual textvar was
441 }
442 else if( refItem && refItem->Type() == SCH_SHEET_T )
443 {
444 SCH_SHEET* refSheet = static_cast<SCH_SHEET*>( refItem );
445
446 sheetPath.push_back( refSheet );
447
448 if( refSheet->ResolveTextVar( &sheetPath, &remainder, aDepth + 1 ) )
449 *token = remainder;
450
451 return true; // Cross-reference is resolved whether or not the actual textvar was
452 }
453
454 return false;
455}
456
457
458std::map<int, wxString> SCHEMATIC::GetVirtualPageToSheetNamesMap() const
459{
460 std::map<int, wxString> namesMap;
461
462 for( const SCH_SHEET_PATH& sheet : BuildUnorderedSheetList() )
463 {
464 if( sheet.size() == 1 )
465 namesMap[sheet.GetVirtualPageNumber()] = _( "<root sheet>" );
466 else
467 namesMap[sheet.GetVirtualPageNumber()] = sheet.Last()->GetName();
468 }
469
470 return namesMap;
471}
472
473
474std::map<int, wxString> SCHEMATIC::GetVirtualPageToSheetPagesMap() const
475{
476 std::map<int, wxString> pagesMap;
477
478 for( const SCH_SHEET_PATH& sheet : BuildUnorderedSheetList() )
479 pagesMap[sheet.GetVirtualPageNumber()] = sheet.GetPageNumber();
480
481 return pagesMap;
482}
483
484
485wxString SCHEMATIC::ConvertRefsToKIIDs( const wxString& aSource ) const
486{
487 wxString newbuf;
488 size_t sourceLen = aSource.length();
489
490 for( size_t i = 0; i < sourceLen; ++i )
491 {
492 if( aSource[i] == '$' && i + 1 < sourceLen && aSource[i+1] == '{' )
493 {
494 wxString token;
495 bool isCrossRef = false;
496 int nesting = 0;
497
498 for( i = i + 2; i < sourceLen; ++i )
499 {
500 if( aSource[i] == '{'
501 && ( aSource[i-1] == '_' || aSource[i-1] == '^' || aSource[i-1] == '~' ) )
502 {
503 nesting++;
504 }
505
506 if( aSource[i] == '}' )
507 {
508 nesting--;
509
510 if( nesting < 0 )
511 break;
512 }
513
514 if( aSource[i] == ':' )
515 isCrossRef = true;
516
517 token.append( aSource[i] );
518 }
519
520 if( isCrossRef )
521 {
522 wxString remainder;
523 wxString ref = token.BeforeFirst( ':', &remainder );
524 SCH_REFERENCE_LIST references;
525
526 BuildUnorderedSheetList().GetSymbols( references );
527
528 for( size_t jj = 0; jj < references.GetCount(); jj++ )
529 {
530 SCH_SYMBOL* refSymbol = references[ jj ].GetSymbol();
531
532 if( ref == refSymbol->GetRef( &references[ jj ].GetSheetPath(), true ) )
533 {
534 token = refSymbol->m_Uuid.AsString() + wxS( ":" ) + remainder;
535 break;
536 }
537 }
538 }
539
540 newbuf.append( wxS( "${" ) + token + wxS( "}" ) );
541 }
542 else
543 {
544 newbuf.append( aSource[i] );
545 }
546 }
547
548 return newbuf;
549}
550
551
552wxString SCHEMATIC::ConvertKIIDsToRefs( const wxString& aSource ) const
553{
554 wxString newbuf;
555 size_t sourceLen = aSource.length();
556
557 for( size_t i = 0; i < sourceLen; ++i )
558 {
559 if( aSource[i] == '$' && i + 1 < sourceLen && aSource[i+1] == '{' )
560 {
561 wxString token;
562 bool isCrossRef = false;
563
564 for( i = i + 2; i < sourceLen; ++i )
565 {
566 if( aSource[i] == '}' )
567 break;
568
569 if( aSource[i] == ':' )
570 isCrossRef = true;
571
572 token.append( aSource[i] );
573 }
574
575 if( isCrossRef )
576 {
577 wxString remainder;
578 wxString ref = token.BeforeFirst( ':', &remainder );
579
580 SCH_SHEET_PATH refSheetPath;
581 SCH_ITEM* refItem = GetItem( KIID( ref ), &refSheetPath );
582
583 if( refItem && refItem->Type() == SCH_SYMBOL_T )
584 {
585 SCH_SYMBOL* refSymbol = static_cast<SCH_SYMBOL*>( refItem );
586 token = refSymbol->GetRef( &refSheetPath, true ) + wxS( ":" ) + remainder;
587 }
588 }
589
590 newbuf.append( wxS( "${" ) + token + wxS( "}" ) );
591 }
592 else
593 {
594 newbuf.append( aSource[i] );
595 }
596 }
597
598 return newbuf;
599}
600
601
603{
604 static SCH_SHEET_LIST hierarchy;
605
606 hierarchy.clear();
607 hierarchy.BuildSheetList( m_rootSheet, false );
608
609 return hierarchy;
610}
611
612
614{
615 SCH_SCREENS screens( m_rootSheet );
616
618}
619
620
622{
623 // Filename is rootSheetName-sheetName-...-sheetName
624 // Note that we need to fetch the rootSheetName out of its filename, as the root SCH_SHEET's
625 // name is just a timestamp.
626
627 wxFileName rootFn( CurrentSheet().at( 0 )->GetFileName() );
628 wxString filename = rootFn.GetName();
629
630 for( unsigned i = 1; i < CurrentSheet().size(); i++ )
631 filename += wxT( "-" ) + CurrentSheet().at( i )->GetName();
632
633 return filename;
634}
635
636
638{
639 SCH_SCREEN* screen;
640 SCH_SCREENS s_list( Root() );
641
642 // Set the sheet count, and the sheet number (1 for root sheet)
643 int sheet_count = Root().CountSheets();
644 int sheet_number = 1;
645 const KIID_PATH& current_sheetpath = CurrentSheet().Path();
646
647 // @todo Remove all pseudo page number system is left over from prior to real page number
648 // implementation.
650 {
651 if( sheet.Path() == current_sheetpath ) // Current sheet path found
652 break;
653
654 sheet_number++; // Not found, increment before this current path
655 }
656
657 for( screen = s_list.GetFirst(); screen != nullptr; screen = s_list.GetNext() )
658 screen->SetPageCount( sheet_count );
659
660 CurrentSheet().SetVirtualPageNumber( sheet_number );
661 CurrentSheet().LastScreen()->SetVirtualPageNumber( sheet_number );
662 CurrentSheet().LastScreen()->SetPageNumber( CurrentSheet().GetPageNumber() );
663}
664
665
666void SCHEMATIC::RecomputeIntersheetRefs( const std::function<void( SCH_GLOBALLABEL* )>& aItemCallback )
667{
668 std::map<wxString, std::set<int>>& pageRefsMap = GetPageRefsMap();
669
670 pageRefsMap.clear();
671
673 {
674 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_GLOBAL_LABEL_T ) )
675 {
676 SCH_GLOBALLABEL* global = static_cast<SCH_GLOBALLABEL*>( item );
677 wxString resolvedLabel = global->GetShownText( &sheet, false );
678
679 pageRefsMap[ resolvedLabel ].insert( sheet.GetVirtualPageNumber() );
680 }
681 }
682
683 bool show = Settings().m_IntersheetRefsShow;
684
685 // Refresh all visible global labels. Note that we have to collect them first as the
686 // SCH_SCREEN::Update() call is going to invalidate the RTree iterator.
687
688 std::vector<SCH_GLOBALLABEL*> currentSheetGlobalLabels;
689
690 for( EDA_ITEM* item : CurrentSheet().LastScreen()->Items().OfType( SCH_GLOBAL_LABEL_T ) )
691 currentSheetGlobalLabels.push_back( static_cast<SCH_GLOBALLABEL*>( item ) );
692
693 for( SCH_GLOBALLABEL* globalLabel : currentSheetGlobalLabels )
694 {
695 std::vector<SCH_FIELD>& fields = globalLabel->GetFields();
696
697 fields[0].SetVisible( show );
698
699 if( show )
700 {
701 if( fields.size() == 1 && fields[0].GetTextPos() == globalLabel->GetPosition() )
702 globalLabel->AutoplaceFields( CurrentSheet().LastScreen(), false );
703
704 CurrentSheet().LastScreen()->Update( globalLabel );
705 aItemCallback( globalLabel );
706 }
707 }
708}
709
710
711wxString SCHEMATIC::GetOperatingPoint( const wxString& aNetName, int aPrecision,
712 const wxString& aRange )
713{
714 wxString spiceNetName( aNetName.Lower() );
716
717 if( spiceNetName == wxS( "gnd" ) || spiceNetName == wxS( "0" ) )
718 return wxEmptyString;
719
720 auto it = m_operatingPoints.find( spiceNetName );
721
722 if( it != m_operatingPoints.end() )
723 return SPICE_VALUE( it->second ).ToString( { aPrecision, aRange } );
724 else if( m_operatingPoints.empty() )
725 return wxS( "--" );
726 else
727 return wxS( "?" );
728}
729
730
732{
733 SCH_SCREENS screens( Root() );
734
735 for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
736 {
737 std::deque<EDA_ITEM*> allItems;
738
739 for( auto item : screen->Items() )
740 allItems.push_back( item );
741
742 // Add missing junctions and breakup wires as needed
743 for( const VECTOR2I& point : screen->GetNeededJunctions( allItems ) )
744 {
745 SCH_JUNCTION* junction = new SCH_JUNCTION( point );
746 screen->Append( junction );
747
748 // Breakup wires
749 for( SCH_LINE* wire : screen->GetBusesAndWires( point, true ) )
750 {
751 SCH_LINE* newSegment = wire->BreakAt( point );
752 screen->Append( newSegment );
753 }
754 }
755 }
756}
757
758
759void SCHEMATIC::OnItemsAdded( std::vector<SCH_ITEM*>& aNewItems )
760{
762}
763
764
765void SCHEMATIC::OnItemsRemoved( std::vector<SCH_ITEM*>& aRemovedItems )
766{
768}
769
770
771void SCHEMATIC::OnItemsChanged( std::vector<SCH_ITEM*>& aItems )
772{
774}
775
776
778{
780}
781
782
784{
785 if( !alg::contains( m_listeners, aListener ) )
786 m_listeners.push_back( aListener );
787}
788
789
791{
792 auto i = std::find( m_listeners.begin(), m_listeners.end(), aListener );
793
794 if( i != m_listeners.end() )
795 {
796 std::iter_swap( i, m_listeners.end() - 1 );
797 m_listeners.pop_back();
798 }
799}
800
801
803{
804 m_listeners.clear();
805}
806
807
809{
810 // Use a sorted sheetList to reduce file churn
812 ERC_SETTINGS& ercSettings = ErcSettings();
813
814 ercSettings.m_ErcExclusions.clear();
815 ercSettings.m_ErcExclusionComments.clear();
816
817 for( unsigned i = 0; i < sheetList.size(); i++ )
818 {
819 for( SCH_ITEM* item : sheetList[i].LastScreen()->Items().OfType( SCH_MARKER_T ) )
820 {
821 SCH_MARKER* marker = static_cast<SCH_MARKER*>( item );
822
823 if( marker->IsExcluded() )
824 {
825 wxString serialized = marker->SerializeToString();
826 ercSettings.m_ErcExclusions.insert( serialized );
827 ercSettings.m_ErcExclusionComments[ serialized ] = marker->GetComment();
828 }
829 }
830 }
831}
832
833
835{
837
838 for( SCH_MARKER* marker : ResolveERCExclusions() )
839 {
840 SCH_SHEET_PATH errorPath;
841 ignore_unused( sheetList.GetItem( marker->GetRCItem()->GetMainItemID(), &errorPath ) );
842
843 if( errorPath.LastScreen() )
844 errorPath.LastScreen()->Append( marker );
845 else
846 RootScreen()->Append( marker );
847 }
848}
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:122
std::map< wxString, wxString > m_ErcExclusionComments
Definition: erc_settings.h:183
std::set< wxString > m_ErcExclusions
Definition: erc_settings.h:182
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:246
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(wxString *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:135
void SetLegacySymbolInstanceData()
Update the symbol value and footprint instance data for legacy designs.
Definition: schematic.cpp:613
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:759
CONNECTION_GRAPH * m_connectionGraph
Holds and calculates connectivity information of this schematic.
Definition: schematic.h:341
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:143
void ResolveERCExclusionsPostUpdate()
Update markers to match recorded exclusions.
Definition: schematic.cpp:834
void RemoveListener(SCHEMATIC_LISTENER *aListener)
Remove the specified listener.
Definition: schematic.cpp:790
void OnSchSheetChanged()
Notify the schematic and its listeners that the current sheet has been changed.
Definition: schematic.cpp:777
SCH_SHEET_PATH * m_currentSheet
The sheet path of the sheet currently being edited or displayed.
Definition: schematic.h:338
wxString GetOperatingPoint(const wxString &aNetName, int aPrecision, const wxString &aRange)
Definition: schematic.cpp:711
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:765
virtual ~SCHEMATIC()
Definition: schematic.cpp:124
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:390
std::vector< SCH_MARKER * > ResolveERCExclusions()
Definition: schematic.cpp:308
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:288
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:294
wxString ConvertKIIDsToRefs(const wxString &aSource) const
Definition: schematic.cpp:552
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
Definition: schematic.cpp:808
std::map< wxString, std::set< int > > & GetPageRefsMap()
Definition: schematic.h:184
SCH_SHEET_LIST BuildUnorderedSheetList() const
Definition: schematic.h:100
SCH_SHEET_LIST & GetFullHierarchy() const
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:602
void FixupJunctions()
Add junctions to this schematic where required.
Definition: schematic.cpp:731
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr) const
Definition: schematic.h:107
wxString ConvertRefsToKIIDs(const wxString &aSource) const
Definition: schematic.cpp:485
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
Definition: schematic.cpp:191
void SetProject(PROJECT *aPrj)
Definition: schematic.cpp:161
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:783
std::map< int, wxString > GetVirtualPageToSheetPagesMap() const
Definition: schematic.cpp:474
PROJECT * m_project
Definition: schematic.h:327
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:204
SCHEMATIC(PROJECT *aPrj)
Definition: schematic.cpp:42
bool ResolveTextVar(const SCH_SHEET_PATH *aSheetPath, wxString *token, int aDepth) const
Definition: schematic.cpp:235
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
Definition: schematic.cpp:405
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:666
void InvokeListeners(Func &&aFunc, Args &&... args)
Definition: schematic.h:321
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:128
static bool m_IsSchematicExists
True if a SCHEMATIC exists, false if not.
Definition: schematic.h:311
void RemoveAllListeners()
Remove all listeners.
Definition: schematic.cpp:802
void GetContextualTextVars(wxArrayString *aVars) const
Definition: schematic.cpp:210
SCH_SHEET & Root() const
Definition: schematic.h:112
std::map< int, wxString > GetVirtualPageToSheetNamesMap() const
Definition: schematic.cpp:458
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const override
Definition: schematic.h:95
wxString GetUniqueFilenameForCurrentSheet()
Definition: schematic.cpp:621
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
Definition: schematic.cpp:637
std::vector< SCHEMATIC_LISTENER * > m_listeners
Currently installed listeners.
Definition: schematic.h:362
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:424
std::map< wxString, double > m_operatingPoints
Simulation operating points for text variable substitution.
Definition: schematic.h:357
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:301
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:771
SCH_SHEET * m_rootSheet
The top-level sheet in this schematic hierarchy (or potentially the only one)
Definition: schematic.h:330
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:166
int GetUnit() const
Definition: sch_item.h:229
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const override
Definition: sch_label.cpp:895
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:41
SCH_LINE * BreakAt(const VECTOR2I &aPoint)
Break this segment into two at the specified point.
Definition: sch_line.cpp:582
static SCH_MARKER * DeserializeFromString(const SCH_SHEET_LIST &aSheetList, 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:152
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:315
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:842
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:251
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:720
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