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 <connection_graph.h>
22#include <core/kicad_algo.h>
23#include <erc_settings.h>
24#include <sch_marker.h>
25#include <project.h>
28#include <schematic.h>
29#include <sch_junction.h>
30#include <sch_line.h>
31#include <sch_screen.h>
32#include <sim/spice_settings.h>
33#include <sch_label.h>
34#include <sim/spice_value.h>
36
38 EDA_ITEM( nullptr, SCHEMATIC_T ),
39 m_project( nullptr ),
40 m_rootSheet( nullptr )
41{
44
45 SetProject( aPrj );
46}
47
48
50{
51 delete m_currentSheet;
52 delete m_connectionGraph;
53}
54
55
57{
58 // Assume project already saved
59 if( m_project )
60 {
62
63 delete project.m_ErcSettings;
64 delete project.m_SchematicSettings;
65
66 project.m_ErcSettings = nullptr;
67 project.m_SchematicSettings = nullptr;
68
69 m_project = nullptr; // clear the project, so we don't do this again when setting a new one
70 }
71
72 delete m_rootSheet;
73
74 m_rootSheet = nullptr;
75
78}
79
80
82{
83 if( m_project )
84 {
86
87 delete project.m_ErcSettings;
88 delete project.m_SchematicSettings;
89
90 project.m_ErcSettings = nullptr;
91 project.m_SchematicSettings = nullptr;
92 }
93
94 m_project = aPrj;
95
96 if( m_project )
97 {
99 project.m_ErcSettings = new ERC_SETTINGS( &project, "erc" );
100 project.m_SchematicSettings = new SCHEMATIC_SETTINGS( &project, "schematic" );
101
102 project.m_SchematicSettings->LoadFromFile();
103 project.m_SchematicSettings->m_NgspiceSimulatorSettings->LoadFromFile();
104 project.m_ErcSettings->LoadFromFile();
105 }
106}
107
108
109void SCHEMATIC::SetRoot( SCH_SHEET* aRootSheet )
110{
111 wxCHECK_RET( aRootSheet, wxS( "Call to SetRoot with null SCH_SHEET!" ) );
112
113 m_rootSheet = aRootSheet;
114
117
119}
120
121
123{
124 return IsValid() ? m_rootSheet->GetScreen() : nullptr;
125}
126
127
128void SCHEMATIC::GetContextualTextVars( wxArrayString* aVars ) const
129{
130 auto add =
131 [&]( const wxString& aVar )
132 {
133 if( !alg::contains( *aVars, aVar ) )
134 aVars->push_back( aVar );
135 };
136
137 add( wxT( "#" ) );
138 add( wxT( "##" ) );
139 add( wxT( "SHEETPATH" ) );
140 add( wxT( "SHEETNAME" ) );
141 add( wxT( "FILENAME" ) );
142 add( wxT( "PROJECTNAME" ) );
143
144 if( !CurrentSheet().empty() )
146
147 for( std::pair<wxString, wxString> entry : Prj().GetTextVars() )
148 add( entry.first );
149}
150
151
152bool SCHEMATIC::ResolveTextVar( wxString* token, int aDepth ) const
153{
154 if( !CurrentSheet().empty() )
155 {
156 if( token->IsSameAs( wxT( "#" ) ) )
157 {
158 *token = CurrentSheet().GetPageNumber();
159 return true;
160 }
161 else if( token->IsSameAs( wxT( "##" ) ) )
162 {
163 *token = wxString::Format( "%i", Root().CountSheets() );
164 return true;
165 }
166 else if( token->IsSameAs( wxT( "SHEETPATH" ) ) )
167 {
168 *token = CurrentSheet().PathHumanReadable();
169 return true;
170 }
171 else if( token->IsSameAs( wxT( "SHEETNAME" ) ) )
172 {
173 *token = CurrentSheet().Last()->GetName();
174 return true;
175 }
176 else if( token->IsSameAs( wxT( "FILENAME" ) ) )
177 {
178 wxFileName fn( GetFileName() );
179 *token = fn.GetFullName();
180 return true;
181 }
182 else if( token->IsSameAs( wxT( "PROJECTNAME" ) ) )
183 {
184 *token = Prj().GetProjectName();
185 return true;
186 }
187
188 if( CurrentSheet().LastScreen()->GetTitleBlock().TextVarResolver( token, m_project ) )
189 return true;
190 }
191
192 if( Prj().TextVarResolver( token ) )
193 return true;
194
195 return false;
196}
197
198
200{
201 return IsValid() ? m_rootSheet->GetScreen()->GetFileName() : wxString( wxEmptyString );
202}
203
204
206{
207 wxASSERT( m_project );
209}
210
211
213{
214 wxASSERT( m_project );
216}
217
218
219std::vector<SCH_MARKER*> SCHEMATIC::ResolveERCExclusions()
220{
221 SCH_SHEET_LIST sheetList = GetSheets();
222 ERC_SETTINGS& settings = ErcSettings();
223
224 // Migrate legacy marker exclusions to new format to ensure exclusion matching functions across
225 // file versions. Silently drops any legacy exclusions which can not be mapped to the new format
226 // without risking an incorrect exclusion - this is preferable to silently dropping
227 // new ERC errors / warnings due to an incorrect match between a legacy and new
228 // marker serialization format
229 std::set<wxString> migratedExclusions;
230
231 for( auto it = settings.m_ErcExclusions.begin(); it != settings.m_ErcExclusions.end(); )
232 {
233 SCH_MARKER* testMarker = SCH_MARKER::Deserialize( this, *it );
234 if( testMarker->IsLegacyMarker() )
235 {
236 const wxString settingsKey = testMarker->GetRCItem()->GetSettingsKey();
237
238 if( settingsKey != wxT( "pin_to_pin" ) && settingsKey != wxT( "hier_label_mismatch" )
239 && settingsKey != wxT( "different_unit_net" ) )
240 {
241 migratedExclusions.insert( testMarker->Serialize() );
242 }
243
244 it = settings.m_ErcExclusions.erase( it );
245 }
246 else
247 {
248 ++it;
249 }
250 delete testMarker;
251 }
252
253 settings.m_ErcExclusions.insert( migratedExclusions.begin(), migratedExclusions.end() );
254
255 // End of legacy exclusion removal / migrations
256
257 for( const SCH_SHEET_PATH& sheet : sheetList )
258 {
259 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_MARKER_T ) )
260 {
261 SCH_MARKER* marker = static_cast<SCH_MARKER*>( item );
262 auto it = settings.m_ErcExclusions.find( marker->Serialize() );
263
264 if( it != settings.m_ErcExclusions.end() )
265 {
266 marker->SetExcluded( true );
267 settings.m_ErcExclusions.erase( it );
268 }
269 }
270 }
271
272 std::vector<SCH_MARKER*> newMarkers;
273
274 for( const wxString& exclusionData : settings.m_ErcExclusions )
275 {
276 SCH_MARKER* marker = SCH_MARKER::Deserialize( this, exclusionData );
277
278 if( marker )
279 {
280 marker->SetExcluded( true );
281 newMarkers.push_back( marker );
282 }
283 }
284
285 settings.m_ErcExclusions.clear();
286
287 return newMarkers;
288}
289
290
291std::shared_ptr<BUS_ALIAS> SCHEMATIC::GetBusAlias( const wxString& aLabel ) const
292{
293 for( const SCH_SHEET_PATH& sheet : GetSheets() )
294 {
295 for( const std::shared_ptr<BUS_ALIAS>& alias : sheet.LastScreen()->GetBusAliases() )
296 {
297 if( alias->GetName() == aLabel )
298 return alias;
299 }
300 }
301
302 return nullptr;
303}
304
305
307{
308 std::set<wxString> names;
309
310 for( const auto& [ key, subgraphList ] : m_connectionGraph->GetNetMap() )
311 {
312 CONNECTION_SUBGRAPH* firstSubgraph = subgraphList[0];
313
314 if( !firstSubgraph->GetDriverConnection()->IsBus()
316 {
317 names.insert( key.Name );
318 }
319 }
320
321 return names;
322}
323
324
325bool SCHEMATIC::ResolveCrossReference( wxString* token, int aDepth ) const
326{
327 SCH_SHEET_LIST sheetList = GetSheets();
328 wxString remainder;
329 wxString ref = token->BeforeFirst( ':', &remainder );
330 SCH_SHEET_PATH sheetPath;
331 SCH_ITEM* refItem = sheetList.GetItem( KIID( ref ), &sheetPath );
332
333 if( refItem && refItem->Type() == SCH_SYMBOL_T )
334 {
335 SCH_SYMBOL* refSymbol = static_cast<SCH_SYMBOL*>( refItem );
336
337 if( refSymbol->ResolveTextVar( &sheetPath, &remainder, aDepth + 1 ) )
338 *token = remainder;
339 else
340 *token = refSymbol->GetRef( &sheetPath, true ) + wxS( ":" ) + remainder;
341
342 return true; // Cross-reference is resolved whether or not the actual textvar was
343 }
344 else if( refItem && refItem->Type() == SCH_SHEET_T )
345 {
346 SCH_SHEET* refSheet = static_cast<SCH_SHEET*>( refItem );
347
348 if( refSheet->ResolveTextVar( &remainder, aDepth + 1 ) )
349 *token = remainder;
350
351 return true; // Cross-reference is resolved whether or not the actual textvar was
352 }
353
354 return false;
355}
356
357
358std::map<int, wxString> SCHEMATIC::GetVirtualPageToSheetNamesMap() const
359{
360 std::map<int, wxString> namesMap;
361
362 for( const SCH_SHEET_PATH& sheet : GetSheets() )
363 {
364 if( sheet.size() == 1 )
365 namesMap[sheet.GetVirtualPageNumber()] = _( "<root sheet>" );
366 else
367 namesMap[sheet.GetVirtualPageNumber()] = sheet.Last()->GetName();
368 }
369
370 return namesMap;
371}
372
373
374std::map<int, wxString> SCHEMATIC::GetVirtualPageToSheetPagesMap() const
375{
376 std::map<int, wxString> pagesMap;
377
378 for( const SCH_SHEET_PATH& sheet : GetSheets() )
379 pagesMap[sheet.GetVirtualPageNumber()] = sheet.GetPageNumber();
380
381 return pagesMap;
382}
383
384
385wxString SCHEMATIC::ConvertRefsToKIIDs( const wxString& aSource ) const
386{
387 wxString newbuf;
388 size_t sourceLen = aSource.length();
389
390 for( size_t i = 0; i < sourceLen; ++i )
391 {
392 if( aSource[i] == '$' && i + 1 < sourceLen && aSource[i+1] == '{' )
393 {
394 wxString token;
395 bool isCrossRef = false;
396 int nesting = 0;
397
398 for( i = i + 2; i < sourceLen; ++i )
399 {
400 if( aSource[i] == '{'
401 && ( aSource[i-1] == '_' || aSource[i-1] == '^' || aSource[i-1] == '~' ) )
402 {
403 nesting++;
404 }
405
406 if( aSource[i] == '}' )
407 {
408 nesting--;
409
410 if( nesting < 0 )
411 break;
412 }
413
414 if( aSource[i] == ':' )
415 isCrossRef = true;
416
417 token.append( aSource[i] );
418 }
419
420 if( isCrossRef )
421 {
422 SCH_SHEET_LIST sheetList = GetSheets();
423 wxString remainder;
424 wxString ref = token.BeforeFirst( ':', &remainder );
425 SCH_REFERENCE_LIST references;
426
427 sheetList.GetSymbols( references );
428
429 for( size_t jj = 0; jj < references.GetCount(); jj++ )
430 {
431 SCH_SYMBOL* refSymbol = references[ jj ].GetSymbol();
432
433 if( ref == refSymbol->GetRef( &references[ jj ].GetSheetPath(), true ) )
434 {
435 token = refSymbol->m_Uuid.AsString() + wxS( ":" ) + remainder;
436 break;
437 }
438 }
439 }
440
441 newbuf.append( wxS( "${" ) + token + wxS( "}" ) );
442 }
443 else
444 {
445 newbuf.append( aSource[i] );
446 }
447 }
448
449 return newbuf;
450}
451
452
453wxString SCHEMATIC::ConvertKIIDsToRefs( const wxString& aSource ) const
454{
455 wxString newbuf;
456 size_t sourceLen = aSource.length();
457
458 for( size_t i = 0; i < sourceLen; ++i )
459 {
460 if( aSource[i] == '$' && i + 1 < sourceLen && aSource[i+1] == '{' )
461 {
462 wxString token;
463 bool isCrossRef = false;
464
465 for( i = i + 2; i < sourceLen; ++i )
466 {
467 if( aSource[i] == '}' )
468 break;
469
470 if( aSource[i] == ':' )
471 isCrossRef = true;
472
473 token.append( aSource[i] );
474 }
475
476 if( isCrossRef )
477 {
478 SCH_SHEET_LIST sheetList = GetSheets();
479 wxString remainder;
480 wxString ref = token.BeforeFirst( ':', &remainder );
481
482 SCH_SHEET_PATH refSheetPath;
483 SCH_ITEM* refItem = sheetList.GetItem( KIID( ref ), &refSheetPath );
484
485 if( refItem && refItem->Type() == SCH_SYMBOL_T )
486 {
487 SCH_SYMBOL* refSymbol = static_cast<SCH_SYMBOL*>( refItem );
488 token = refSymbol->GetRef( &refSheetPath, true ) + wxS( ":" ) + remainder;
489 }
490 }
491
492 newbuf.append( wxS( "${" ) + token + wxS( "}" ) );
493 }
494 else
495 {
496 newbuf.append( aSource[i] );
497 }
498 }
499
500 return newbuf;
501}
502
503
505{
506 static SCH_SHEET_LIST hierarchy;
507
508 hierarchy.clear();
509 hierarchy.BuildSheetList( m_rootSheet, false );
510
511 return hierarchy;
512}
513
514
516{
517 SCH_SCREENS screens( m_rootSheet );
518
520}
521
522
524{
525 // Filename is rootSheetName-sheetName-...-sheetName
526 // Note that we need to fetch the rootSheetName out of its filename, as the root SCH_SHEET's
527 // name is just a timestamp.
528
529 wxFileName rootFn( CurrentSheet().at( 0 )->GetFileName() );
530 wxString filename = rootFn.GetName();
531
532 for( unsigned i = 1; i < CurrentSheet().size(); i++ )
533 filename += wxT( "-" ) + CurrentSheet().at( i )->GetName();
534
535 return filename;
536}
537
538
540{
541 SCH_SCREEN* screen;
542 SCH_SCREENS s_list( Root() );
543
544 // Set the sheet count, and the sheet number (1 for root sheet)
545 int sheet_count = Root().CountSheets();
546 int sheet_number = 1;
547 const KIID_PATH& current_sheetpath = CurrentSheet().Path();
548
549 // @todo Remove all pseudo page number system is left over from prior to real page number
550 // implementation.
551 for( const SCH_SHEET_PATH& sheet : GetSheets() )
552 {
553 if( sheet.Path() == current_sheetpath ) // Current sheet path found
554 break;
555
556 sheet_number++; // Not found, increment before this current path
557 }
558
559 for( screen = s_list.GetFirst(); screen != nullptr; screen = s_list.GetNext() )
560 screen->SetPageCount( sheet_count );
561
562 CurrentSheet().SetVirtualPageNumber( sheet_number );
563 CurrentSheet().LastScreen()->SetVirtualPageNumber( sheet_number );
564 CurrentSheet().LastScreen()->SetPageNumber( CurrentSheet().GetPageNumber() );
565}
566
567
568void SCHEMATIC::RecomputeIntersheetRefs( const std::function<void( SCH_GLOBALLABEL* )>& aItemCallback )
569{
570 std::map<wxString, std::set<int>>& pageRefsMap = GetPageRefsMap();
571
572 pageRefsMap.clear();
573
574 SCH_SCREENS screens( Root() );
575 std::vector<int> virtualPageNumbers;
576
577 /* Iterate over screens */
578 for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
579 {
580 virtualPageNumbers.clear();
581
582 /* Find in which sheets this screen is used */
583 for( const SCH_SHEET_PATH& sheet : GetSheets() )
584 {
585 if( sheet.LastScreen() == screen )
586 virtualPageNumbers.push_back( sheet.GetVirtualPageNumber() );
587 }
588
589 for( SCH_ITEM* item : screen->Items() )
590 {
591 if( item->Type() == SCH_GLOBAL_LABEL_T )
592 {
593 SCH_GLOBALLABEL* globalLabel = static_cast<SCH_GLOBALLABEL*>( item );
594 std::set<int>& virtualpageList = pageRefsMap[globalLabel->GetText()];
595
596 for( const int& pageNo : virtualPageNumbers )
597 virtualpageList.insert( pageNo );
598 }
599 }
600 }
601
602 bool show = Settings().m_IntersheetRefsShow;
603
604 // Refresh all global labels. Note that we have to collect them first as the
605 // SCH_SCREEN::Update() call is going to invalidate the RTree iterator.
606
607 std::vector<SCH_GLOBALLABEL*> currentSheetGlobalLabels;
608
609 for( EDA_ITEM* item : CurrentSheet().LastScreen()->Items().OfType( SCH_GLOBAL_LABEL_T ) )
610 currentSheetGlobalLabels.push_back( static_cast<SCH_GLOBALLABEL*>( item ) );
611
612 for( SCH_GLOBALLABEL* globalLabel : currentSheetGlobalLabels )
613 {
614 std::vector<SCH_FIELD>& fields = globalLabel->GetFields();
615
616 fields[0].SetVisible( show );
617
618 if( show )
619 {
620 if( fields.size() == 1 && fields[0].GetTextPos() == globalLabel->GetPosition() )
621 globalLabel->AutoplaceFields( CurrentSheet().LastScreen(), false );
622
623 CurrentSheet().LastScreen()->Update( globalLabel );
624 aItemCallback( globalLabel );
625 }
626 }
627}
628
629
630wxString SCHEMATIC::GetOperatingPoint( const wxString& aNetName, int aPrecision,
631 const wxString& aRange )
632{
633 std::string spiceNetName( aNetName.Lower().ToStdString() );
635
636 if( spiceNetName == "gnd" || spiceNetName == "0" )
637 return wxEmptyString;
638
639 auto it = m_operatingPoints.find( spiceNetName );
640
641 if( it != m_operatingPoints.end() )
642 return SPICE_VALUE( it->second ).ToString( { aPrecision, aRange } );
643 else if( m_operatingPoints.empty() )
644 return wxS( "--" );
645 else
646 return wxS( "?" );
647}
648
649
651{
652 for( const SCH_SHEET_PATH& sheet : GetSheets() )
653 {
654 SCH_SCREEN* screen = sheet.LastScreen();
655
656 std::deque<EDA_ITEM*> allItems;
657
658 for( auto item : screen->Items() )
659 allItems.push_back( item );
660
661 // Add missing junctions and breakup wires as needed
662 for( const VECTOR2I& point : screen->GetNeededJunctions( allItems ) )
663 {
664 SCH_JUNCTION* junction = new SCH_JUNCTION( point );
665 screen->Append( junction );
666
667 // Breakup wires
668 for( SCH_LINE* wire : screen->GetBusesAndWires( point, true ) )
669 {
670 SCH_LINE* newSegment = wire->BreakAt( point );
671 screen->Append( newSegment );
672 }
673 }
674 }
675}
676
677
678void SCHEMATIC::OnItemsAdded( std::vector<SCH_ITEM*>& aNewItems )
679{
681}
682
683
684void SCHEMATIC::OnItemsRemoved( std::vector<SCH_ITEM*>& aRemovedItems )
685{
687}
688
689
691{
692 if( !alg::contains( m_listeners, aListener ) )
693 m_listeners.push_back( aListener );
694}
695
696
698{
699 auto i = std::find( m_listeners.begin(), m_listeners.end(), aListener );
700
701 if( i != m_listeners.end() )
702 {
703 std::iter_swap( i, m_listeners.end() - 1 );
704 m_listeners.pop_back();
705 }
706}
707
708
710{
711 m_listeners.clear();
712}
713
714
715void SCHEMATIC::OnItemsChanged( std::vector<SCH_ITEM*>& aItems )
716{
718}
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
Calculates 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:85
const KIID m_Uuid
Definition: eda_item.h:475
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
Container for ERC settings.
Definition: erc_settings.h:114
std::set< wxString > m_ErcExclusions
Definition: erc_settings.h:174
Definition: kiid.h:48
wxString AsString() const
Definition: kiid.cpp:257
std::shared_ptr< RC_ITEM > GetRCItem() const
Definition: marker_base.h:105
void SetExcluded(bool aExcluded)
Definition: marker_base.h:98
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:65
ERC_SETTINGS * m_ErcSettings
Eeschema params.
Definition: project_file.h:127
SCHEMATIC_SETTINGS * m_SchematicSettings
Definition: project_file.h:130
Container for project specific data.
Definition: project.h:64
virtual const wxString GetProjectName() const
Return the short name of the project.
Definition: project.cpp:132
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:149
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 OnSchItemsAdded(SCHEMATIC &aSch, std::vector< SCH_ITEM * > &aSchItem)
Definition: schematic.h:59
These settings were stored in SCH_BASE_FRAME previously.
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
Definition: schematic.cpp:56
void SetLegacySymbolInstanceData()
Update the symbol value and footprint instance data for legacy designs.
Definition: schematic.cpp:515
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:678
CONNECTION_GRAPH * m_connectionGraph
Holds and calculates connectivity information of this schematic.
Definition: schematic.h:309
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:133
void RemoveListener(SCHEMATIC_LISTENER *aListener)
Remove the specified listener.
Definition: schematic.cpp:697
SCH_SHEET_PATH * m_currentSheet
The sheet path of the sheet currently being edited or displayed.
Definition: schematic.h:306
wxString GetOperatingPoint(const wxString &aNetName, int aPrecision, const wxString &aRange)
Definition: schematic.cpp:630
bool ResolveTextVar(wxString *token, int aDepth) const
Definition: schematic.cpp:152
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:684
virtual ~SCHEMATIC()
Definition: schematic.cpp:49
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:291
std::vector< SCH_MARKER * > ResolveERCExclusions()
Definition: schematic.cpp:219
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
wxString ConvertKIIDsToRefs(const wxString &aSource) const
Definition: schematic.cpp:453
std::map< wxString, std::set< int > > & GetPageRefsMap()
Definition: schematic.h:174
SCH_SHEET_LIST & GetFullHierarchy() const
Return the full schematic flattened hierarchical sheet list.
Definition: schematic.cpp:504
void FixupJunctions()
Add junctions to this schematic where required.
Definition: schematic.cpp:650
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:97
wxString ConvertRefsToKIIDs(const wxString &aSource) const
Definition: schematic.cpp:385
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
Definition: schematic.cpp:109
void SetProject(PROJECT *aPrj)
Definition: schematic.cpp:81
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:690
std::map< int, wxString > GetVirtualPageToSheetPagesMap() const
Definition: schematic.cpp:374
PROJECT * m_project
Definition: schematic.h:295
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:122
SCHEMATIC(PROJECT *aPrj)
Definition: schematic.cpp:37
std::set< wxString > GetNetClassAssignmentCandidates()
Return the set of netname candidates for netclass assignment.
Definition: schematic.cpp:306
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:568
void InvokeListeners(Func &&aFunc, Args &&... args)
Definition: schematic.h:289
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:118
void RemoveAllListeners()
Remove all listeners.
Definition: schematic.cpp:709
void GetContextualTextVars(wxArrayString *aVars) const
Definition: schematic.cpp:128
SCH_SHEET & Root() const
Definition: schematic.h:102
std::map< int, wxString > GetVirtualPageToSheetNamesMap() const
Definition: schematic.cpp:358
wxString GetUniqueFilenameForCurrentSheet()
Definition: schematic.cpp:523
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
Definition: schematic.cpp:539
std::vector< SCHEMATIC_LISTENER * > m_listeners
Currently installed listeners.
Definition: schematic.h:330
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:87
bool ResolveCrossReference(wxString *token, int aDepth) const
Resolves text vars that refer to other items.
Definition: schematic.cpp:325
std::map< wxString, double > m_operatingPoints
Simulation operating points for text variable substitution.
Definition: schematic.h:325
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:212
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:715
SCH_SHEET * m_rootSheet
The top-level sheet in this schematic hierarchy (or potentially the only one)
Definition: schematic.h:298
bool IsBus() const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
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:592
wxString Serialize() const
Definition: sch_marker.cpp:78
bool IsLegacyMarker() const
Determines if this marker is legacy (i.e.
Definition: sch_marker.h:121
static SCH_MARKER * Deserialize(SCHEMATIC *schematic, const wxString &data)
Definition: sch_marker.cpp:99
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:662
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:144
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:109
const wxString & GetFileName() const
Definition: sch_screen.h:144
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:155
void Update(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Update aItem's bounding box in the tree.
Definition: sch_screen.cpp:307
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:782
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:236
Schematic symbol object.
Definition: sch_symbol.h:81
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
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the symbol.
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.
static void GetContextualTextVars(wxArrayString *aVars)
Definition: title_block.cpp:74
static bool empty(const wxTextEntryBase *aCtrl)
#define _(s)
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:99
@ SCH_SYMBOL_T
Definition: typeinfo.h:146
@ SCH_SHEET_T
Definition: typeinfo.h:148
@ SCH_MARKER_T
Definition: typeinfo.h:131
@ SCHEMATIC_T
Definition: typeinfo.h:178
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:142