KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_tool_utils.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include "sch_tool_utils.h"
21
22#include <sch_text.h>
23#include <sch_field.h>
24#include <sch_pin.h>
25#include <sch_reference_list.h>
26#include <sch_symbol.h>
27#include <sch_table.h>
28#include <sch_tablecell.h>
29#include <sch_textbox.h>
30#include <schematic.h>
31#include <sch_sheet_path.h>
32#include <sch_sheet.h>
33#include <sch_sheet_pin.h>
34#include <sch_screen.h>
35#include <sch_group.h>
36#include <kiid.h>
37
38#include <algorithm>
39#include <limits>
40
41#include <wx/arrstr.h>
42
43wxString GetSchItemAsText( const SCH_ITEM& aItem )
44{
45 switch( aItem.Type() )
46 {
47 case SCH_TEXT_T:
48 case SCH_LABEL_T:
52 case SCH_SHEET_PIN_T:
53 {
54 const SCH_TEXT& text = static_cast<const SCH_TEXT&>( aItem );
55 return text.GetShownText( FOR_CANVAS );
56 }
57
58 case SCH_FIELD_T:
59 {
60 // Goes via EDA_TEXT
61 const SCH_FIELD& field = static_cast<const SCH_FIELD&>( aItem );
62 return field.GetShownText( FOR_CANVAS );
63 }
64
65 case SCH_TEXTBOX_T:
66 case SCH_TABLECELL_T:
67 {
68 // Also EDA_TEXT
69 const SCH_TEXTBOX& textbox = static_cast<const SCH_TEXTBOX&>( aItem );
70
71 // Call the correct GetShownText overload with nullptr for settings/path and aDepth=0
72 // This ensures proper variable expansion and escape marker conversion
73 return textbox.GetShownText( nullptr, nullptr, FOR_CANVAS );
74 }
75
76 case SCH_PIN_T:
77 {
78 // This is a choice - probably the name makes more sense than the number
79 // (or should it be name/number?)
80 const SCH_PIN& pin = static_cast<const SCH_PIN&>( aItem );
81 return pin.GetShownName();
82 }
83
84 case SCH_TABLE_T:
85 {
86 // A simple tabbed list of the cells seems like a place to start here
87 const SCH_TABLE& table = static_cast<const SCH_TABLE&>( aItem );
88 wxString s;
89
90 for( int row = 0; row < table.GetRowCount(); ++row )
91 {
92 for( int col = 0; col < table.GetColCount(); ++col )
93 {
94 const SCH_TABLECELL* cell = table.GetCell( row, col );
95 s << cell->GetShownText( FOR_CANVAS );
96
97 if( col < table.GetColCount() - 1 )
98 {
99 s << '\t';
100 }
101 }
102
103 if( row < table.GetRowCount() - 1 )
104 {
105 s << '\n';
106 }
107 }
108 return s;
109 }
110
111 default:
112 break;
113 }
114
115 return wxEmptyString;
116};
117
118
119wxString GetSelectedItemsAsText( const SELECTION& aSel )
120{
121 wxArrayString itemTexts;
122
123 for( EDA_ITEM* item : aSel )
124 {
125 if( item->IsSCH_ITEM() )
126 {
127 const SCH_ITEM& schItem = static_cast<const SCH_ITEM&>( *item );
128 wxString itemText = GetSchItemAsText( schItem );
129
130 itemText.Trim( false ).Trim( true );
131
132 if( !itemText.IsEmpty() )
133 itemTexts.Add( itemText );
134 }
135 }
136
137 return wxJoin( itemTexts, '\n', '\0' );
138}
139
140
141template <typename T>
142static std::vector<SCH_ITEM*> flattenGroups( const T& aItems )
143{
144 std::vector<SCH_ITEM*> flattened;
145 std::vector<SCH_ITEM*> toVisit;
146
147 for( EDA_ITEM* item : aItems )
148 toVisit.push_back( static_cast<SCH_ITEM*>( item ) );
149
150 while( !toVisit.empty() )
151 {
152 SCH_ITEM* item = toVisit.back();
153 toVisit.pop_back();
154 flattened.push_back( item );
155
156 if( item->Type() == SCH_GROUP_T )
157 {
158 for( EDA_ITEM* child : static_cast<SCH_GROUP*>( item )->GetItems() )
159 toVisit.push_back( static_cast<SCH_ITEM*>( child ) );
160 }
161 }
162
163 return flattened;
164}
165
166
167std::vector<SCH_ITEM*> FlattenGroups( const EDA_ITEMS& aItems )
168{
169 return flattenGroups( aItems );
170}
171
172
173std::vector<SCH_ITEM*> FlattenGroups( const std::deque<EDA_ITEM*>& aItems )
174{
175 return flattenGroups( aItems );
176}
177
178
179bool IsUnannotatedUnitOccupied( const SCH_REFERENCE_LIST& aRefs, const wxString& aRef,
180 const LIB_ID& aLibId, int aUnit )
181{
182 for( size_t i = 0; i < aRefs.GetCount(); ++i )
183 {
184 const SCH_REFERENCE& ref = aRefs[i];
185
186 if( ref.GetUnit() != aUnit )
187 continue;
188
189 if( ref.GetRef() != aRef )
190 continue;
191
192 SCH_SYMBOL* refSym = ref.GetSymbol();
193
194 if( refSym && refSym->GetLibId() == aLibId )
195 return true;
196 }
197
198 return false;
199}
200
201
202std::set<int> GetUnplacedUnitsForSymbol( const SCH_SYMBOL& aSym )
203{
204 SCHEMATIC const* schematic = aSym.Schematic();
205
206 if( !schematic )
207 return {};
208
209 const wxString symRefDes = aSym.GetRef( &schematic->CurrentSheet(), false );
210
211 // Pre-annotation references all share the same "U?" form regardless of which library symbol
212 // they came from, so an unannotated AD8620 and an unannotated OPA1664 would otherwise be
213 // collapsed into one logical part. Match library identity as a tie-breaker when the
214 // reference is still unannotated.
215 const bool refIsUnannotated = !symRefDes.IsEmpty() && symRefDes.Last() == '?';
216 const LIB_ID& symLibId = aSym.GetLibId();
217
218 // Get a list of all references in the schematic
219 SCH_SHEET_LIST hierarchy = schematic->Hierarchy();
220 SCH_REFERENCE_LIST existingRefs;
221 hierarchy.GetSymbols( existingRefs, SYMBOL_FILTER_ALL );
222
223 std::set<int> missingUnits;
224
225 for( int unit = 1; unit <= aSym.GetUnitCount(); ++unit )
226 missingUnits.insert( unit );
227
228 for( const SCH_REFERENCE& ref : existingRefs )
229 {
230 if( symRefDes != ref.GetRef() )
231 continue;
232
233 if( refIsUnannotated && ref.GetSymbol() && ref.GetSymbol()->GetLibId() != symLibId )
234 continue;
235
236 missingUnits.erase( ref.GetUnit() );
237 }
238
239 return missingUnits;
240}
241
242
243std::optional<SCH_REFERENCE> FindSymbolByRefAndUnit( const SCHEMATIC& aSchematic,
244 const wxString& aRef, int aUnit )
245{
247 aSchematic.Hierarchy().GetSymbols( refs, SYMBOL_FILTER_ALL );
248
249 for( const SCH_REFERENCE& ref : refs )
250 {
251 if( ref.GetRef() == aRef && ref.GetUnit() == aUnit )
252 {
253 return ref;
254 }
255 }
256
257 return std::nullopt;
258}
259
260
261std::vector<SCH_SYMBOL*> GetSameSymbolMultiUnitSelection( const SELECTION& aSel )
262{
263 std::vector<SCH_SYMBOL*> result;
264
265 if( aSel.GetSize() < 2 || !aSel.OnlyContains( { SCH_SYMBOL_T } ) )
266 return result;
267
268 wxString rootRef;
269 LIB_ID rootLibId;
270 bool haveRootLibId = false;
271 size_t rootPinCount = 0;
272 bool haveRootPinCount = false;
273
274 // Preserve selection order for cyclical swaps A->B->C
275 std::vector<EDA_ITEM*> itemsInOrder = aSel.GetItemsSortedBySelectionOrder();
276
277 for( EDA_ITEM* it : itemsInOrder )
278 {
279 SCH_SYMBOL* sym = dynamic_cast<SCH_SYMBOL*>( it );
280
281 if( !sym || !sym->GetLibSymbolRef() || sym->GetLibSymbolRef()->GetUnitCount() < 2 )
282 return {};
283
284 const SCH_SHEET_PATH& sheet = sym->Schematic()->CurrentSheet();
285
286 // Get unit-less reference
287 wxString ref = sym->GetRef( &sheet, false );
288
289 if( rootRef.IsEmpty() )
290 rootRef = ref;
291
292 if( ref != rootRef )
293 return {};
294
295 // Make sure the user isn't selecting units that are misreferenced such that
296 // they have U1A and U1B that are actually from different library symbols.
297 const LIB_ID& libId = sym->GetLibId();
298
299 if( !haveRootLibId )
300 {
301 rootLibId = libId;
302 haveRootLibId = true;
303 }
304
305 if( libId != rootLibId )
306 return {};
307
308 // Ensure same pin count across selected units
309 size_t pinCount = sym->GetPins( &sheet ).size();
310
311 if( !haveRootPinCount )
312 {
313 rootPinCount = pinCount;
314 haveRootPinCount = true;
315 }
316
317 if( pinCount != rootPinCount )
318 return {};
319
320 result.push_back( sym );
321 }
322
323 if( result.size() < 2 )
324 return {};
325
326 return result;
327}
328
329
330bool SwapPinGeometry( SCH_PIN* aFirst, SCH_PIN* aSecond )
331{
332 wxCHECK_MSG( aFirst && aSecond, false, "Invalid pins supplied to SwapPinGeometry" );
333
334 // If the schematic pin is still backed by a library definition, swap that library pin; once the
335 // caller sees the true return value it can decide to clone the updated library data into the
336 // schematic cache. Otherwise the schematic already owns a local copy, so swap in place.
337 SCH_PIN* firstPin = aFirst->GetLibPin() ? aFirst->GetLibPin() : aFirst;
338 SCH_PIN* secondPin = aSecond->GetLibPin() ? aSecond->GetLibPin() : aSecond;
339
340 VECTOR2I firstLocal = firstPin->GetLocalPosition();
341 VECTOR2I secondLocal = secondPin->GetLocalPosition();
342 firstPin->SetPosition( secondLocal );
343 secondPin->SetPosition( firstLocal );
344
345 PIN_ORIENTATION firstOrientation = firstPin->GetOrientation();
346 PIN_ORIENTATION secondOrientation = secondPin->GetOrientation();
347 firstPin->SetOrientation( secondOrientation );
348 secondPin->SetOrientation( firstOrientation );
349
350 int firstLength = firstPin->GetLength();
351 int secondLength = secondPin->GetLength();
352 firstPin->SetLength( secondLength );
353 secondPin->SetLength( firstLength );
354
355 const wxString& firstOp = firstPin->GetOperatingPoint();
356 const wxString& secondOp = secondPin->GetOperatingPoint();
357 firstPin->SetOperatingPoint( secondOp );
358 secondPin->SetOperatingPoint( firstOp );
359
360 // Return true if we touched the library-backed copy so callers can refresh the schematic symbol
361 // cache once the swap completes.
362 return ( firstPin != aFirst ) || ( secondPin != aSecond );
363}
364
365
366bool SymbolHasSheetInstances( const SCH_SYMBOL& aSymbol, const wxString& aCurrentProject,
367 std::set<wxString>* aSheetPaths, std::set<wxString>* aProjectNames )
368{
369 std::set<KIID_PATH> uniquePaths;
370 std::set<wxString> sheetPaths;
371 std::set<wxString> otherProjects;
372
373 for( const SCH_SYMBOL_INSTANCE& instance : aSymbol.GetInstances() )
374 {
375 uniquePaths.insert( instance.m_Path );
376
377 if( !instance.m_Path.empty() )
378 sheetPaths.insert( instance.m_Path.AsString() );
379
380 if( !instance.m_ProjectName.IsEmpty() )
381 {
382 if( aCurrentProject.IsEmpty() || !instance.m_ProjectName.IsSameAs( aCurrentProject ) )
383 otherProjects.insert( instance.m_ProjectName );
384 }
385 }
386
387 bool sharedWithinProject = uniquePaths.size() > 1;
388 bool sharedWithOtherProjects = !otherProjects.empty();
389
390 if( aSheetPaths )
391 {
392 if( sharedWithinProject )
393 *aSheetPaths = sheetPaths;
394 else
395 aSheetPaths->clear();
396 }
397
398 if( aProjectNames )
399 {
400 if( sharedWithOtherProjects )
401 *aProjectNames = otherProjects;
402 else
403 aProjectNames->clear();
404 }
405
406 return sharedWithinProject || sharedWithOtherProjects;
407}
408
409
410std::set<wxString> GetSheetNamesFromPaths( const std::set<wxString>& aSheetPaths, const SCHEMATIC& aSchematic )
411{
412 std::set<wxString> friendlyNames;
413
414 if( aSheetPaths.empty() )
415 return friendlyNames;
416
417 SCH_SHEET_LIST hierarchy = aSchematic.Hierarchy();
418
419 for( const wxString& pathStr : aSheetPaths )
420 {
421 wxString display = pathStr;
422
423 try
424 {
425 KIID_PATH kiidPath( pathStr );
426
427 for( const SCH_SHEET_PATH& sheetPath : hierarchy )
428 {
429 if( sheetPath.Path() == kiidPath )
430 {
431 wxString sheetNames;
432
433 for( size_t ii = 0; ii < sheetPath.size(); ++ii )
434 {
435 SCH_SHEET* sheet = sheetPath.at( ii );
436
437 if( !sheet )
438 continue;
439
440 const SCH_FIELD* nameField = sheet->GetField( FIELD_T::SHEET_NAME );
441
442 if( !nameField )
443 continue;
444
445 wxString name = nameField->GetShownText( FOR_NETNAME );
446
447 if( name.IsEmpty() )
448 continue;
449
450 if( !sheetNames.IsEmpty() )
451 sheetNames << wxS( "/" );
452
453 sheetNames << name;
454 }
455
456 if( sheetNames.IsEmpty() )
457 display = sheetPath.PathHumanReadable( false, true );
458 else
459 display = sheetNames;
460
461 break;
462 }
463 }
464 }
465 catch( ... )
466 {
467 // If the path cannot be parsed, fall back to the raw string.
468 }
469
470 friendlyNames.insert( display );
471 }
472
473 return friendlyNames;
474}
475
476
477wxString UniqueSheetName( SCH_SCREEN* aScreen, const wxString& aBaseName )
478{
479 if( !aScreen )
480 return aBaseName;
481
482 std::set<wxString> existing;
483
484 for( SCH_ITEM* item : aScreen->Items().OfType( SCH_SHEET_T ) )
485 existing.insert( static_cast<SCH_SHEET*>( item )->GetShownName( INTERNAL ).Lower() );
486
487 if( !existing.count( aBaseName.Lower() ) )
488 return aBaseName;
489
490 for( int n = 1; n < std::numeric_limits<int>::max(); ++n )
491 {
492 wxString candidate = aBaseName + wxString::Format( wxT( "%d" ), n );
493
494 if( !existing.count( candidate.Lower() ) )
495 return candidate;
496 }
497
498 return aBaseName;
499}
500
501
502std::vector<SCH_HIERLABEL*> GetUnplacedSheetPinLabels( const SCH_SHEET& aSheet )
503{
504 if( !aSheet.GetScreen() )
505 return {};
506
507 std::vector<SCH_HIERLABEL*> labels;
508 std::set<wxString> names;
509
510 for( SCH_SHEET_PIN* pin : aSheet.GetPins() )
511 names.insert( pin->GetText() );
512
513 for( EDA_ITEM* item : aSheet.GetScreen()->Items().OfType( SCH_HIER_LABEL_T ) )
514 {
515 SCH_HIERLABEL* label = static_cast<SCH_HIERLABEL*>( item );
516
517 if( names.insert( label->GetText() ).second )
518 labels.push_back( label );
519 }
520
521 return labels;
522}
523
524
525void AutoPlaceSheetPins( SCH_SHEET* aSheet, const std::vector<SCH_HIERLABEL*>& aLabels )
526{
527 if( aLabels.empty() )
528 return;
529
530 // Vertical pitch big enough to keep pin text from touching, snapped to grid.
531 const int grid = schIUScale.MilsToIU( 50 );
532 int textSize = aSheet->Schematic()->Settings().m_DefaultTextSize;
533 int pitch = std::max( KiROUND( textSize * 2.0 ), schIUScale.MilsToIU( 100 ) );
534 pitch = KiROUND( (double) pitch / grid ) * grid;
535
536 const int margin = pitch;
537 int leftX = aSheet->GetPosition().x;
538 int rightX = aSheet->GetPosition().x + aSheet->GetSize().x;
539 int topY = aSheet->GetPosition().y;
540
541 // Stack new pins below whatever is already on each edge, without moving it.
542 int leftY = topY + margin - pitch;
543 int rightY = topY + margin - pitch;
544
545 for( SCH_SHEET_PIN* pin : aSheet->GetPins() )
546 {
547 if( pin->GetSide() == SHEET_SIDE::RIGHT )
548 rightY = std::max( rightY, pin->GetPosition().y );
549 else if( pin->GetSide() == SHEET_SIDE::LEFT )
550 leftY = std::max( leftY, pin->GetPosition().y );
551 }
552
553 // New pins: outputs on the right edge, everything else on the left.
554 std::vector<SCH_HIERLABEL*> leftLabels;
555 std::vector<SCH_HIERLABEL*> rightLabels;
556
557 for( SCH_HIERLABEL* label : aLabels )
558 {
559 if( label->GetShape() == LABEL_FLAG_SHAPE::L_OUTPUT )
560 rightLabels.push_back( label );
561 else
562 leftLabels.push_back( label );
563 }
564
565 auto byText =
566 []( const SCH_HIERLABEL* a, const SCH_HIERLABEL* b )
567 {
568 return a->GetText() < b->GetText();
569 };
570
571 std::sort( leftLabels.begin(), leftLabels.end(), byText );
572 std::sort( rightLabels.begin(), rightLabels.end(), byText );
573
574 // Grow the sheet if the new pins would run past the bottom edge.
575 int botLeft = leftY + (int) leftLabels.size() * pitch;
576 int botRight = rightY + (int) rightLabels.size() * pitch;
577 int needBot = std::max( botLeft, botRight ) + margin;
578
579 if( needBot > topY + aSheet->GetSize().y )
580 aSheet->Resize( VECTOR2I( aSheet->GetSize().x, needBot - topY ) );
581
582 auto placeColumn =
583 [&]( const std::vector<SCH_HIERLABEL*>& aColumn, int aX, int aStartY, SHEET_SIDE aSide )
584 {
585 int y = KiROUND( (double) aStartY / grid ) * grid;
586
587 for( SCH_HIERLABEL* label : aColumn )
588 {
589 y += pitch;
590
591 SCH_SHEET_PIN* pin = new SCH_SHEET_PIN( aSheet );
592 pin->SetTextSize( VECTOR2I( textSize, textSize ) );
593 pin->SetPosition( VECTOR2I( aX, y ) );
594 pin->ClearSelected();
595 pin->SetText( label->GetText() );
596 pin->SetShape( label->GetShape() );
597 pin->SetSide( aSide );
598 aSheet->AddPin( pin );
599 pin->AutoplaceFields( aSheet->GetParentScreen(), AUTOPLACE_AUTO );
600 }
601 };
602
603 placeColumn( leftLabels, leftX, leftY, SHEET_SIDE::LEFT );
604 placeColumn( rightLabels, rightX, rightY, SHEET_SIDE::RIGHT );
605}
606
607
608wxString UniqueGroupName( SCH_SCREEN* aScreen, const wxString& aBaseName )
609{
610 if( !aScreen )
611 return aBaseName;
612
613 std::set<wxString> existing;
614
615 for( SCH_ITEM* item : aScreen->Items().OfType( SCH_GROUP_T ) )
616 existing.insert( static_cast<SCH_GROUP*>( item )->GetName() );
617
618 if( !existing.count( aBaseName ) )
619 return aBaseName;
620
621 for( int n = 1; n < std::numeric_limits<int>::max(); ++n )
622 {
623 wxString candidate = aBaseName + wxString::Format( wxT( "%d" ), n );
624
625 if( !existing.count( candidate ) )
626 return candidate;
627 }
628
629 return aBaseName;
630}
631
632
633void PrunePastedSymbolInstances( SCH_SYMBOL* aSymbol, const SCHEMATIC& aSchematic )
634{
635 wxCHECK( aSymbol && aSchematic.IsValid(), /* void */ );
636
637 const wxString projectName = aSchematic.Project().GetProjectName();
638
639 std::vector<KIID_PATH> pathsToRemove;
640
641 // Claiming rewrites a field in place, so only the removals have to wait for the walk to end
642 for( const SCH_SYMBOL_INSTANCE& instance : aSymbol->GetInstances() )
643 {
644 if( !aSchematic.IsInstancePathInProject( instance.m_Path ) )
645 pathsToRemove.emplace_back( instance.m_Path );
646 else if( instance.m_ProjectName != projectName )
647 aSymbol->SetInstanceProjectName( instance.m_Path, projectName );
648 }
649
650 for( const KIID_PATH& path : pathsToRemove )
651 aSymbol->RemoveInstance( path );
652}
const char * name
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:130
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:982
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:118
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:248
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int GetUnitCount() const override
virtual const wxString GetProjectName() const
Return the short name of the project.
Definition project.cpp:195
Holds all the data relating to one schematic.
Definition schematic.h:149
SCHEMATIC_SETTINGS & Settings() const
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
PROJECT & Project() const
Return a reference to the project this schematic is part of.
Definition schematic.h:171
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition schematic.h:289
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:304
bool IsInstancePathInProject(const KIID_PATH &aPath) const
Test whether an instance path is rooted in this schematic's top level sheets.
wxString GetShownText(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString, int aDepth=0) const
A set of SCH_ITEMs (i.e., without duplicates).
Definition sch_group.h:48
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
SCH_SCREEN * GetParentScreen() const
Definition sch_item.cpp:308
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:302
VECTOR2I GetLocalPosition() const
Definition sch_pin.h:317
int GetLength() const
Definition sch_pin.cpp:421
const wxString & GetOperatingPoint() const
Definition sch_pin.h:412
void SetOrientation(PIN_ORIENTATION aOrientation)
Definition sch_pin.h:113
SCH_PIN * GetLibPin() const
Definition sch_pin.h:109
void SetPosition(const VECTOR2I &aPos) override
Definition sch_pin.h:318
void SetLength(int aLength)
Definition sch_pin.h:119
PIN_ORIENTATION GetOrientation() const
Definition sch_pin.cpp:386
void SetOperatingPoint(const wxString &aText)
Definition sch_pin.h:413
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
A helper to define a symbol's reference designator in a schematic.
SCH_SYMBOL * GetSymbol() const
wxString GetRef() const
int GetUnit() const
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:122
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void GetSymbols(SCH_REFERENCE_LIST &aReferences, SYMBOL_FILTER aSymbolFilter, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
void AddPin(SCH_SHEET_PIN *aSheetPin)
Add aSheetPin to the sheet.
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
VECTOR2I GetSize() const
Definition sch_sheet.h:147
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:145
VECTOR2I GetPosition() const override
Definition sch_sheet.h:506
void Resize(const VECTOR2I &aSize)
Resize this sheet to aSize and adjust all of the labels accordingly.
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition sch_sheet.h:243
Schematic symbol object.
Definition sch_symbol.h:73
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstances() const
Definition sch_symbol.h:133
void RemoveInstance(const SCH_SHEET_PATH &aInstancePath)
bool SetInstanceProjectName(const KIID_PATH &aSheetPath, const wxString &aProjectName)
Set the owning project of the instance stored for aSheetPath.
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
const LIB_ID & GetLibId() const override
Definition sch_symbol.h:163
int GetUnitCount() const override
Return the number of units per package of the symbol.
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:182
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
wxString GetShownText(const RENDER_SETTINGS *aSettings, const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, int aDepth=0) const override
virtual wxString GetShownText(const RENDER_SETTINGS *aSettings, const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, int aDepth=0) const
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition selection.h:104
std::vector< EDA_ITEM * > GetItemsSortedBySelectionOrder() const
bool OnlyContains(std::vector< KICAD_T > aList) const
Checks if all items in the selection have a type in aList.
@ FOR_CANVAS
Definition common.h:90
@ FOR_NETNAME
Definition common.h:92
@ INTERNAL
Definition common.h:94
PIN_ORIENTATION
The symbol library pin object orientations.
Definition pin_type.h:101
Class to handle a set of SCH_ITEMs.
@ AUTOPLACE_AUTO
Definition sch_item.h:75
std::vector< EDA_ITEM * > EDA_ITEMS
@ L_OUTPUT
Definition sch_label.h:99
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
@ SYMBOL_FILTER_ALL
SHEET_SIDE
Define the edge of the sheet that the sheet pin is positioned.
wxString UniqueGroupName(SCH_SCREEN *aScreen, const wxString &aBaseName)
Return aBaseName, or aBaseName + smallest free integer if a group with that name already exists on aS...
bool IsUnannotatedUnitOccupied(const SCH_REFERENCE_LIST &aRefs, const wxString &aRef, const LIB_ID &aLibId, int aUnit)
Decide whether aUnit of an unannotated multi-unit symbol is already placed.
std::set< wxString > GetSheetNamesFromPaths(const std::set< wxString > &aSheetPaths, const SCHEMATIC &aSchematic)
Get human-readable sheet names from a set of sheet paths, e.g.
bool SwapPinGeometry(SCH_PIN *aFirst, SCH_PIN *aSecond)
Swap the positions/lengths/etc.
std::set< int > GetUnplacedUnitsForSymbol(const SCH_SYMBOL &aSym)
Get a list of unplaced (i.e.
wxString GetSelectedItemsAsText(const SELECTION &aSel)
void AutoPlaceSheetPins(SCH_SHEET *aSheet, const std::vector< SCH_HIERLABEL * > &aLabels)
Import and auto-place sheet pins for the given labels, growing the sheet as needed.
bool SymbolHasSheetInstances(const SCH_SYMBOL &aSymbol, const wxString &aCurrentProject, std::set< wxString > *aSheetPaths, std::set< wxString > *aProjectNames)
Returns true when the given symbol has instances, e.g.
std::optional< SCH_REFERENCE > FindSymbolByRefAndUnit(const SCHEMATIC &aSchematic, const wxString &aRef, int aUnit)
Find a symbol by reference and unit.
void PrunePastedSymbolInstances(SCH_SYMBOL *aSymbol, const SCHEMATIC &aSchematic)
Discard the instance data a paste dragged in from somewhere else, keyed by path rather than project n...
std::vector< SCH_ITEM * > FlattenGroups(const EDA_ITEMS &aItems)
Return the given items with the members of any group added, recursively.
static std::vector< SCH_ITEM * > flattenGroups(const T &aItems)
std::vector< SCH_SYMBOL * > GetSameSymbolMultiUnitSelection(const SELECTION &aSel)
Validates and gathers a selection containing multiple symbol units that all belong to the same refere...
std::vector< SCH_HIERLABEL * > GetUnplacedSheetPinLabels(const SCH_SHEET &aSheet)
Return one sheet hierarchical label per name that does not already have a sheet pin.
wxString UniqueSheetName(SCH_SCREEN *aScreen, const wxString &aBaseName)
Return aBaseName, or aBaseName + smallest free integer if a sheet with that name already exists on aS...
wxString GetSchItemAsText(const SCH_ITEM &aItem)
A simple container for schematic symbol instance information.
std::string path
KIBIS_PIN * pin
wxString result
Test unit parsing edge cases and error handling.
@ SCH_GROUP_T
Definition typeinfo.h:169
@ SCH_TABLE_T
Definition typeinfo.h:161
@ SCH_TABLECELL_T
Definition typeinfo.h:162
@ SCH_FIELD_T
Definition typeinfo.h:146
@ SCH_DIRECTIVE_LABEL_T
Definition typeinfo.h:167
@ SCH_LABEL_T
Definition typeinfo.h:163
@ SCH_SHEET_T
Definition typeinfo.h:171
@ SCH_HIER_LABEL_T
Definition typeinfo.h:165
@ SCH_SHEET_PIN_T
Definition typeinfo.h:170
@ SCH_TEXT_T
Definition typeinfo.h:147
@ SCH_TEXTBOX_T
Definition typeinfo.h:148
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:164
@ SCH_PIN_T
Definition typeinfo.h:149
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708