KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_item.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) 2006 Jean-Pierre Charras, [email protected]
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <pgm_base.h>
23#include <eeschema_settings.h>
24#include <eda_item.h>
25#include <sch_connection.h>
26#include <sch_group.h>
27#include <sch_rule_area.h>
28#include <sch_draw_panel.h>
29#include <sch_edit_frame.h>
30#include <connection_graph.h>
31#include <netclass.h>
35#include <properties/property.h>
37
38
39// Rendering fonts is expensive (particularly when using outline fonts). At small effective
40// sizes (ie: zoomed out) the visual differences between outline and/or stroke fonts and the
41// bitmap font becomes immaterial, and there's often more to draw when zoomed out so the
42// performance gain becomes more significant.
43#define BITMAP_FONT_SIZE_THRESHOLD 3
44
45
46static const std::vector<KICAD_T> labelTypes = { SCH_LABEL_LOCATE_ANY_T };
47
48
49/* Constructor and destructor for SCH_ITEM */
50/* They are not inline because this creates problems with gcc at linking time in debug mode */
51
52SCH_ITEM::SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType, int aUnit, int aBodyStyle ) :
53 EDA_ITEM( aParent, aType, true, false ),
54 m_unit( aUnit ),
55 m_bodyStyle( aBodyStyle ),
56 m_private( false ),
57 m_isLocked( false )
58{
59 m_layer = LAYER_WIRE; // It's only a default, in fact
61 m_connectivity_dirty = false; // Item is unconnected until it is placed, so it's clean
62}
63
64
66 EDA_ITEM( aItem )
67{
68 m_layer = aItem.m_layer;
69 m_unit = aItem.m_unit;
71 m_private = aItem.m_private;
74 m_isLocked = aItem.m_isLocked;
75}
76
77
79{
80 m_layer = aItem.m_layer;
81 m_unit = aItem.m_unit;
83 m_private = aItem.m_private;
86 m_isLocked = aItem.m_isLocked;
87
88 return *this;
89}
90
91
93{
94 for( const auto& it : m_connection_map )
95 delete it.second;
96
97 // Remove this item from any rule areas that contain it
98 for( SCH_RULE_AREA* ruleArea : m_rule_areas_cache )
99 ruleArea->RemoveItem( this );
100
101 // Do not try to modify SCHEMATIC::ConnectionGraph()
102 // if the schematic does not exist
104 return;
105
106 SCHEMATIC* sch = Schematic();
107
108 if( sch != nullptr )
109 sch->ConnectionGraph()->RemoveItem( this );
110}
111
112
114{
115 switch( Type() )
116 {
117 case SCH_SYMBOL_T:
118 case SCH_PIN_T:
119 case SCH_SHAPE_T:
120 case SCH_BITMAP_T:
121 case SCH_FIELD_T:
122 case SCH_TEXT_T:
123 case SCH_TEXTBOX_T:
124 case SCH_TABLE_T:
125 case SCH_GROUP_T:
126 case SCH_LINE_T:
127 case SCH_JUNCTION_T:
128 case SCH_NO_CONNECT_T:
131 case SCH_LABEL_T:
133 case SCH_HIER_LABEL_T:
134 case SCH_RULE_AREA_T:
136 case SCH_SHEET_T:
137 return true;
138
139 // Don't group sheet pins directly, they go along with an SCH_SHEET, and all operations
140 // should be performed on that sheet.
141 case SCH_SHEET_PIN_T:
142 default:
143 return false;
144 }
145}
146
147
149{
151 {
152 if( group->AsEdaItem()->IsLocked() )
153 return true;
154 }
155
156 return m_isLocked;
157}
158
159
160SCH_ITEM* SCH_ITEM::Duplicate( bool addToParentGroup, SCH_COMMIT* aCommit, bool doClone ) const
161{
162 SCH_ITEM* newItem = (SCH_ITEM*) Clone();
163
164 if( !doClone )
165 const_cast<KIID&>( newItem->m_Uuid ) = KIID();
166
167 newItem->ClearFlags( SELECTED | BRIGHTENED );
168
169 newItem->RunOnChildren(
170 []( SCH_ITEM* aChild )
171 {
172 aChild->ClearFlags( SELECTED | BRIGHTENED );
173 },
175
176 if( addToParentGroup )
177 {
178 wxCHECK_MSG( aCommit, newItem, "Must supply a commit to update parent group" );
179
180 if( EDA_GROUP* group = newItem->GetParentGroup() )
181 {
182 aCommit->Modify( group->AsEdaItem(), nullptr, RECURSE_MODE::NO_RECURSE );
183 group->AddItem( newItem );
184 }
185 }
186
187 return newItem;
188}
189
190
191wxString SCH_ITEM::GetUnitDisplayName( int aUnit, bool aLabel ) const
192{
193 if( aUnit == 0 )
194 return aLabel ? _( "All units" ) : wxString( _HKI( "All units" ) );
195 else if( const SYMBOL* symbol = GetParentSymbol() )
196 return symbol->GetUnitDisplayName( aUnit, aLabel );
197
198 return wxEmptyString;
199}
200
201
202wxString SCH_ITEM::GetBodyStyleDescription( int aBodyStyle, bool aLabel ) const
203{
204 if( aBodyStyle == 0 )
205 return aLabel ? _( "All body styles" ) : wxString( _HKI( "All body styles" ) );
206 else if( const SYMBOL* symbol = GetParentSymbol() )
207 return symbol->GetBodyStyleDescription( aBodyStyle, aLabel );
208
209 return wxEmptyString;
210}
211
212
213void SCH_ITEM::SetUnitString( const wxString& aUnit )
214{
215 if( aUnit == _HKI( "All units" ) )
216 {
217 m_unit = 0;
218 return;
219 }
220
221 if( SYMBOL* symbol = GetParentSymbol() )
222 {
223 for( int ii = 1; ii <= symbol->GetUnitCount(); ii++ )
224 {
225 if( symbol->GetUnitDisplayName( ii, false ) == aUnit )
226 {
227 m_unit = ii;
228 return;
229 }
230 }
231 }
232}
233
234
236{
237 return GetUnitDisplayName( m_unit, false );
238}
239
240void SCH_ITEM::SetBodyStyleProp( const wxString& aBodyStyle )
241{
242 if( aBodyStyle == _HKI( "All body styles" ) )
243 {
244 m_bodyStyle = 0;
245 return;
246 }
247
248 if( SYMBOL* symbol = GetParentSymbol() )
249 {
250 for( int bodyStyle : { BODY_STYLE::BASE, BODY_STYLE::DEMORGAN } )
251 {
252 if( symbol->GetBodyStyleDescription( bodyStyle, false ) == aBodyStyle )
253 {
254 m_bodyStyle = bodyStyle;
255 return;
256 }
257 }
258 }
259}
260
261
263{
264 return GetBodyStyleDescription( m_bodyStyle, false );
265}
266
267
269{
270 return static_cast<SCHEMATIC*>( findParent( SCHEMATIC_T ) );
271}
272
273
275{
276 if( SYMBOL* sch_symbol = static_cast<SCH_SYMBOL*>( findParent( SCH_SYMBOL_T ) ) )
277 return sch_symbol;
278
279 if( SYMBOL* lib_symbol = static_cast<LIB_SYMBOL*>( findParent( LIB_SYMBOL_T ) ) )
280 return lib_symbol;
281
282 return nullptr;
283}
284
285
287{
288 if( SYMBOL* sch_symbol = static_cast<SCH_SYMBOL*>( findParent( SCH_SYMBOL_T ) ) )
289 return sch_symbol;
290
291 if( SYMBOL* lib_symbol = static_cast<LIB_SYMBOL*>( findParent( LIB_SYMBOL_T ) ) )
292 return lib_symbol;
293
294 return nullptr;
295}
296
297
299 const wxString& aVariantName ) const
300{
301 if( GetExcludedFromSim( aInstance, aVariantName ) )
302 return true;
303
304 for( SCH_RULE_AREA* area : m_rule_areas_cache )
305 {
306 if( area->GetExcludedFromSim( aInstance, aVariantName ) )
307 return true;
308 }
309
310 return false;
311}
312
313
315 const wxString& aVariantName ) const
316{
317 if( GetExcludedFromBOM( aInstance, aVariantName ) )
318 return true;
319
320 for( SCH_RULE_AREA* area : m_rule_areas_cache )
321 {
322 if( area->GetExcludedFromBOM( aInstance, aVariantName ) )
323 return true;
324 }
325
326 return false;
327}
328
329
331 const wxString& aVariantName ) const
332{
333 if( GetExcludedFromBoard( aInstance, aVariantName ) )
334 return true;
335
336 for( SCH_RULE_AREA* area : m_rule_areas_cache )
337 {
338 if( area->GetExcludedFromBoard( aInstance, aVariantName ) )
339 return true;
340 }
341
342 return false;
343}
344
345
347 const wxString& aVariantName ) const
348{
349 if( GetExcludedFromPosFiles( aInstance, aVariantName ) )
350 return true;
351
352 for( SCH_RULE_AREA* area : m_rule_areas_cache )
353 {
354 if( area->GetExcludedFromPosFiles( aInstance, aVariantName ) )
355 return true;
356 }
357
358 return false;
359}
360
361
362bool SCH_ITEM::ResolveDNP( const SCH_SHEET_PATH* aInstance, const wxString& aVariantName ) const
363{
364 if( GetDNP( aInstance, aVariantName ) )
365 return true;
366
367 for( SCH_RULE_AREA* area : m_rule_areas_cache )
368 {
369 if( area->GetDNP( aInstance, aVariantName ) )
370 return true;
371 }
372
373 return false;
374}
375
376
377wxString SCH_ITEM::ResolveText( const wxString& aText, const SCH_SHEET_PATH* aPath, int aDepth ) const
378{
379 // Use aDepth to track recursion across nested GetShownText/ResolveText calls
380 int depth = aDepth;
381
382 std::function<bool( wxString* )> libSymbolResolver =
383 [&]( wxString* token ) -> bool
384 {
385 LIB_SYMBOL* symbol = static_cast<LIB_SYMBOL*>( m_parent );
386 return symbol->ResolveTextVar( token, depth + 1 );
387 };
388
389 std::function<bool( wxString* )> symbolResolver =
390 [&]( wxString* token ) -> bool
391 {
392 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( m_parent );
393 return symbol->ResolveTextVar( aPath, token, depth + 1 );
394 };
395
396 std::function<bool( wxString* )> schematicResolver =
397 [&]( wxString* token ) -> bool
398 {
399 if( !aPath )
400 return false;
401
402 if( SCHEMATIC* schematic = Schematic() )
403 return schematic->ResolveTextVar( aPath, token, depth + 1 );
404
405 return false;
406 };
407
408 std::function<bool( wxString* )> sheetResolver =
409 [&]( wxString* token ) -> bool
410 {
411 if( !aPath )
412 return false;
413
414 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( m_parent );
415
416 SCHEMATIC* schematic = Schematic();
417 SCH_SHEET_PATH path = *aPath;
418 path.push_back( sheet );
419
420 bool retval = sheet->ResolveTextVar( &path, token, depth + 1 );
421
422 if( schematic )
423 retval |= schematic->ResolveTextVar( &path, token, depth + 1 );
424
425 return retval;
426 };
427
428 std::function<bool( wxString* )> labelResolver =
429 [&]( wxString* token ) -> bool
430 {
431 if( !aPath )
432 return false;
433
434 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( m_parent );
435 return label->ResolveTextVar( aPath, token, depth + 1 );
436 };
437
438 wxString variantName;
439
440 if( SCHEMATIC* schematic = Schematic() )
441 variantName = schematic->GetCurrentVariant();
442
443 // Create a unified resolver that delegates to the appropriate resolver based on parent type
444 std::function<bool( wxString* )> fieldResolver =
445 [&]( wxString* token ) -> bool
446 {
447 bool resolved = false;
448
449 if( m_parent && m_parent->Type() == LIB_SYMBOL_T )
450 resolved = libSymbolResolver( token );
451 else if( m_parent && m_parent->Type() == SCH_SYMBOL_T )
452 resolved = symbolResolver( token );
453 else if( m_parent && m_parent->Type() == SCH_SHEET_T )
454 resolved = sheetResolver( token );
455 else if( m_parent && m_parent->IsType( labelTypes ) )
456 resolved = labelResolver( token );
457 else if( Schematic() )
458 {
459 // Project-level and schematic-level variables
460 resolved = Schematic()->Project().TextVarResolver( token );
461 resolved |= schematicResolver( token );
462 }
463
464 return resolved;
465 };
466
467 return ResolveTextVars( aText, &fieldResolver, depth );
468}
469
470
471std::vector<int> SCH_ITEM::ViewGetLayers() const
472{
473 // Basic fallback
475}
476
477
478bool SCH_ITEM::IsConnected( const VECTOR2I& aPosition ) const
479{
480 if(( m_flags & STRUCT_DELETED ) || ( m_flags & SKIP_STRUCT ) )
481 return false;
482
483 return doIsConnected( aPosition );
484}
485
486
488{
489 if( !IsConnectable() )
490 return nullptr;
491
492 if( !aSheet )
493 {
494 SCHEMATIC* sch = Schematic();
495
496 if( !sch )
497 return nullptr; // Item has been removed from schematic (e.g. SCH_PIN during symbol deletion)
498
499 aSheet = &sch->CurrentSheet();
500 }
501
502 auto it = m_connection_map.find( *aSheet );
503
504 if( it == m_connection_map.end() )
505 return nullptr;
506 else
507 return it->second;
508}
509
510
512{
513 for( auto& [path, conn] : m_connection_map )
514 {
515 conn->SetGraph( aGraph );
516
517 for( auto& member : conn->AllMembers() )
518 member->SetGraph( aGraph );
519 }
520}
521
522
523std::shared_ptr<NETCLASS> SCH_ITEM::GetEffectiveNetClass( const SCH_SHEET_PATH* aSheet ) const
524{
525 static std::shared_ptr<NETCLASS> nullNetclass = std::make_shared<NETCLASS>( wxEmptyString );
526
527 SCHEMATIC* schematic = Schematic();
528
529 if( !schematic || !schematic->IsValid() )
530 return nullNetclass;
531
532 std::shared_ptr<NET_SETTINGS>& netSettings = schematic->Project().GetProjectFile().m_NetSettings;
533
534 if( !netSettings )
535 return nullNetclass;
536
537 SCH_CONNECTION* connection = Connection( aSheet );
538
539 if( connection )
540 return netSettings->GetEffectiveNetClass( connection->Name() );
541
542 if( std::shared_ptr<NETCLASS> defaultNetclass = netSettings->GetDefaultNetclass() )
543 return defaultNetclass;
544
545 return nullNetclass;
546}
547
548
550{
551 auto it = m_connected_items.find( aSheet );
552
553 if( it != m_connected_items.end() )
554 it->second.clear();
555}
556
557
558const std::vector<SCH_ITEM*>& SCH_ITEM::ConnectedItems( const SCH_SHEET_PATH& aSheet )
559{
560 return m_connected_items[ aSheet ];
561}
562
563
565{
566 std::vector<SCH_ITEM*>& vec = m_connected_items[ aSheet ];
567
568 // The vector elements are small, so reserve 1k at a time to prevent re-allocations
569 if( vec.size() == vec.capacity() )
570 vec.reserve( vec.size() + 4096 );
571
572 // Add item to the correct place in the sorted vector if it is not already there
573 auto it = std::lower_bound( vec.begin(), vec.end(), aItem );
574
575 if( it == vec.end() || *it != aItem )
576 vec.insert( it, aItem );
577}
578
579
581 CONNECTION_GRAPH* aGraph )
582{
583 SCH_CONNECTION* connection = Connection( &aSheet );
584
585 // N.B. Do not clear the dirty connectivity flag here because we may need
586 // to create a connection for a different sheet, and we don't want to
587 // skip the connection creation because the flag is cleared.
588 if( connection )
589 {
590 connection->Reset();
591 }
592 else
593 {
594 connection = new SCH_CONNECTION( this );
595 m_connection_map.insert( std::make_pair( aSheet, connection ) );
596 }
597
598 connection->SetGraph( aGraph );
599 connection->SetSheet( aSheet );
600 return connection;
601}
602
603
605 CONNECTION_GRAPH* aGraph )
606{
607 if( !IsConnectable() )
608 return nullptr;
609
610 SCH_CONNECTION* connection = Connection( &aSheet );
611
612 if( connection )
613 return connection;
614 else
615 return InitializeConnection( aSheet, aGraph );
616}
617
618
619const wxString& SCH_ITEM::GetCachedDriverName() const
620{
621 static wxString s_empty;
622 return s_empty;
623}
624
625
627{
629}
630
631
633{
634 if( aImage == nullptr )
635 return;
636
637 EDA_ITEM* parent = GetParent();
638
639 SwapFlags( aImage );
640 std::swap( m_layer, aImage->m_layer );
641 std::swap( m_unit, aImage->m_unit );
642 std::swap( m_bodyStyle, aImage->m_bodyStyle );
643 std::swap( m_private, aImage->m_private );
644 std::swap( m_fieldsAutoplaced, aImage->m_fieldsAutoplaced );
645
646 // Don't swap m_group. Group membership is restored by SCH_GROUP::swapData, and the undo copy
647 // has no group, so swapping it here would drop the item out of its group.
648 std::swap( m_isLocked, aImage->m_isLocked );
649 swapData( aImage );
650
651 SetParent( parent );
652}
653
654
656{
657 EDA_ITEM_FLAGS editFlags = GetEditFlags();
658 EDA_ITEM_FLAGS tempFlags = GetTempFlags();
659 EDA_ITEM_FLAGS aItem_editFlags = aItem->GetEditFlags();
660 EDA_ITEM_FLAGS aItem_tempFlags = aItem->GetTempFlags();
661
662 std::swap( m_flags, aItem->m_flags );
663
665 SetFlags( editFlags );
667 SetFlags( tempFlags );
668
669 aItem->ClearEditFlags();
670 aItem->SetFlags( aItem_editFlags );
671 aItem->ClearTempFlags();
672 aItem->SetFlags( aItem_tempFlags );
673}
674
675
677{
678 auto clearTextCaches =
679 []( SCH_ITEM* aItem )
680 {
681 EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
682
683 if( text )
684 {
685 text->ClearBoundingBoxCache();
686 text->ClearRenderCache();
687 }
688 };
689
690 clearTextCaches( this );
691
692 RunOnChildren( clearTextCaches, RECURSE_MODE::NO_RECURSE );
693}
694
695
696bool SCH_ITEM::operator==( const SCH_ITEM& aOther ) const
697{
698 if( Type() != aOther.Type() )
699 return false;
700
701 return compare( aOther, SCH_ITEM::COMPARE_FLAGS::EQUALITY ) == 0;
702}
703
704
705bool SCH_ITEM::operator<( const SCH_ITEM& aOther ) const
706{
707 if( Type() != aOther.Type() )
708 return Type() < aOther.Type();
709
710 return ( compare( aOther ) < 0 );
711}
712
713
714bool SCH_ITEM::cmp_items::operator()( const SCH_ITEM* aFirst, const SCH_ITEM* aSecond ) const
715{
716 return aFirst->compare( *aSecond, COMPARE_FLAGS::EQUALITY ) < 0;
717}
718
719
720int SCH_ITEM::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
721{
722 if( Type() != aOther.Type() )
723 return Type() - aOther.Type();
724
725 if( !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::UNIT ) && m_unit != aOther.m_unit )
726 return m_unit - aOther.m_unit;
727
728 if( !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::UNIT ) && m_bodyStyle != aOther.m_bodyStyle )
729 return m_bodyStyle - aOther.m_bodyStyle;
730
731 if( IsPrivate() != aOther.IsPrivate() )
732 return IsPrivate() ? 1 : -1;
733
734 if( !( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::SKIP_TST_POS ) )
735 {
736 if( GetPosition().x != aOther.GetPosition().x )
737 return GetPosition().x - aOther.GetPosition().x;
738
739 if( GetPosition().y != aOther.GetPosition().y )
740 return GetPosition().y - aOther.GetPosition().y;
741 }
742
743 if( ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::EQUALITY )
744 || ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) )
745 {
746 return 0;
747 }
748
749 if( m_Uuid < aOther.m_Uuid )
750 return -1;
751
752 if( m_Uuid > aOther.m_Uuid )
753 return 1;
754
755 return 0;
756}
757
758
760{
761 if( SCHEMATIC* schematic = Schematic() )
762 return schematic->Settings().m_MaxError;
763 else
764 return schIUScale.mmToIU( ARC_LOW_DEF_MM );
765}
766
767
768const wxString& SCH_ITEM::GetDefaultFont( const RENDER_SETTINGS* aSettings ) const
769{
770 static wxString defaultName = KICAD_FONT_NAME;
771
772 if( aSettings )
773 return aSettings->GetDefaultFont();
774 else if( EESCHEMA_SETTINGS* cfg = GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" ) )
775 return cfg->m_Appearance.default_font;
776 else
777 return defaultName;
778}
779
780
782{
783 if( SCHEMATIC* schematic = Schematic() )
784 return schematic->Settings().m_FontMetrics;
785
787}
788
789
791{
792 // For historical reasons, a stored value of 0 means "default width" and negative
793 // numbers meant "don't stroke".
794
795 if( GetPenWidth() < 0 )
796 {
797 return 0;
798 }
799 else if( GetPenWidth() == 0 )
800 {
801 if( GetParent() && GetParent()->Type() == LIB_SYMBOL_T )
802 return std::max( aSettings->m_SymbolLineWidth, aSettings->GetMinPenWidth() );
803 else
804 return std::max( aSettings->GetDefaultPenWidth(), aSettings->GetMinPenWidth() );
805 }
806 else
807 {
808 return std::max( GetPenWidth(), aSettings->GetMinPenWidth() );
809 }
810}
811
812
813bool SCH_ITEM::RenderAsBitmap( double aWorldScale ) const
814{
815 if( HasHypertext() )
816 return false;
817
818 if( const EDA_TEXT* text = dynamic_cast<const EDA_TEXT*>( this ) )
819 return text->GetTextHeight() * aWorldScale < BITMAP_FONT_SIZE_THRESHOLD;
820
821 return false;
822}
823
824
825void SCH_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
826{
827 if( SYMBOL* symbol = GetParentSymbol() )
828 {
829 if( symbol->IsMultiUnit() )
830 aList.emplace_back( _( "Unit" ), GetUnitDisplayName( GetUnit(), false ) );
831
832 if( symbol->IsMultiBodyStyle() )
833 aList.emplace_back( _( "Body Style" ), GetBodyStyleDescription( GetBodyStyle(), true ) );
834
835 if( dynamic_cast<LIB_SYMBOL*>( symbol ) && IsPrivate() )
836 aList.emplace_back( _( "Private" ), wxEmptyString );
837 }
838}
839
840
841const std::vector<wxString>* SCH_ITEM::GetEmbeddedFonts()
842{
843 if( SCHEMATIC* schematic = Schematic() )
844 return schematic->GetEmbeddedFiles()->GetFontFiles();
845
846 if( SYMBOL* symbol = GetParentSymbol() )
847 {
848 if( EMBEDDED_FILES* symbolEmbeddedFiles = symbol->GetEmbeddedFiles() )
849 return symbolEmbeddedFiles->UpdateFontFiles();
850 }
851
852 return nullptr;
853}
854
855
856static struct SCH_ITEM_DESC
857{
859 {
863
864 propMgr.AddProperty( new PROPERTY<SCH_ITEM, bool>( _HKI( "Locked" ),
867
868 auto multiUnit =
869 [=]( INSPECTABLE* aItem ) -> bool
870 {
871 if( SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( aItem ) )
872 {
873 if( const SYMBOL* symbol = schItem->GetParentSymbol() )
874 return symbol->IsMultiUnit();
875 }
876
877 return false;
878 };
879
880 auto multiBodyStyle =
881 [=]( INSPECTABLE* aItem ) -> bool
882 {
883 if( SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( aItem ) )
884 {
885 if( const SYMBOL* symbol = schItem->GetParentSymbol() )
886 return symbol->IsMultiBodyStyle();
887 }
888
889 return false;
890 };
891
892 propMgr.AddProperty( new PROPERTY<SCH_ITEM, wxString>( _HKI( "Unit" ),
894 .SetAvailableFunc( multiUnit )
896 .SetChoicesFunc( []( INSPECTABLE* aItem )
897 {
898 wxPGChoices choices;
899 choices.Add( _HKI( "All units" ), 0 );
900
901 if( SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem ) )
902 {
903 if( SYMBOL* symbol = item->GetParentSymbol() )
904 {
905 for( int ii = 1; ii <= symbol->GetUnitCount(); ii++ )
906 choices.Add( symbol->GetUnitDisplayName( ii, false ), ii );
907 }
908 }
909
910 return choices;
911 } );
912
913
914 propMgr.AddProperty( new PROPERTY<SCH_ITEM, wxString>( _HKI( "Body Style" ),
916 .SetAvailableFunc( multiBodyStyle )
918 .SetChoicesFunc( []( INSPECTABLE* aItem )
919 {
920 wxPGChoices choices;
921 choices.Add( _HKI( "All body styles" ) );
922
923 if( SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem ) )
924 {
925 if( SYMBOL* symbol = item->GetParentSymbol() )
926 {
927 for( int ii : { BODY_STYLE::BASE, BODY_STYLE::DEMORGAN } )
928 choices.Add( symbol->GetBodyStyleDescription( ii, false ) );
929 }
930 }
931
932 return choices;
933 } );
934
935 propMgr.AddProperty( new PROPERTY<SCH_ITEM, bool>( _HKI( "Private" ),
938 }
940
942
943
944static bool lessYX( const DANGLING_END_ITEM& a, const DANGLING_END_ITEM& b )
945{
946 const auto aPos = a.GetPosition();
947 const auto bPos = b.GetPosition();
948 return aPos.y < bPos.y ? true : ( aPos.y > bPos.y ? false : aPos.x < bPos.x );
949};
950
951
952static bool lessType( const DANGLING_END_ITEM& a, const DANGLING_END_ITEM& b )
953{
954 return a.GetType() < b.GetType();
955};
956
957
958std::vector<DANGLING_END_ITEM>::iterator
959DANGLING_END_ITEM_HELPER::get_lower_pos( std::vector<DANGLING_END_ITEM>& aItemListByPos,
960 const VECTOR2I& aPos )
961{
962 DANGLING_END_ITEM needle = DANGLING_END_ITEM( PIN_END, nullptr, aPos );
963 auto start = aItemListByPos.begin();
964 auto end = aItemListByPos.end();
965 return std::lower_bound( start, end, needle, lessYX );
966}
967
968
969std::vector<DANGLING_END_ITEM>::iterator
970DANGLING_END_ITEM_HELPER::get_lower_type( std::vector<DANGLING_END_ITEM>& aItemListByType,
971 const DANGLING_END_T& aType )
972{
973 DANGLING_END_ITEM needle = DANGLING_END_ITEM( aType, nullptr, VECTOR2I{} );
974 auto start = aItemListByType.begin();
975 auto end = aItemListByType.end();
976 return std::lower_bound( start, end, needle, lessType );
977}
978
979
981 std::vector<DANGLING_END_ITEM>& aItemListByType,
982 std::vector<DANGLING_END_ITEM>& aItemListByPos )
983{
984 // WIRE_END pairs must be kept together. Hence stable sort.
985 std::stable_sort( aItemListByType.begin(), aItemListByType.end(), lessType );
986
987 // Sort by y first, pins are more likely to share x than y.
988 std::sort( aItemListByPos.begin(), aItemListByPos.end(), lessYX );
989}
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:123
constexpr double ARC_LOW_DEF_MM
Definition base_units.h:127
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:102
void RemoveItem(SCH_ITEM *aItem)
static std::vector< DANGLING_END_ITEM >::iterator get_lower_type(std::vector< DANGLING_END_ITEM > &aItemListByType, const DANGLING_END_T &aType)
Definition sch_item.cpp:970
static std::vector< DANGLING_END_ITEM >::iterator get_lower_pos(std::vector< DANGLING_END_ITEM > &aItemListByPos, const VECTOR2I &aPos)
Definition sch_item.cpp:959
static void sort_dangling_end_items(std::vector< DANGLING_END_ITEM > &aItemListByType, std::vector< DANGLING_END_ITEM > &aItemListByPos)
Both contain the same information.
Definition sch_item.cpp:980
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition sch_item.h:93
DANGLING_END_T GetType() const
Definition sch_item.h:129
The base class for create windows for drawing purpose.
A set of EDA_ITEMs (i.e., without duplicates).
Definition eda_group.h:42
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
virtual VECTOR2I GetPosition() const
Definition eda_item.h:282
virtual void ClearEditFlags()
Definition eda_item.h:166
EDA_ITEM_FLAGS GetEditFlags() const
Definition eda_item.h:158
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:152
const KIID m_Uuid
Definition eda_item.h:531
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:114
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:154
EDA_ITEM_FLAGS m_flags
Definition eda_item.h:542
EDA_ITEM_FLAGS GetTempFlags() const
Definition eda_item.h:171
EDA_ITEM * GetParent() const
Definition eda_item.h:110
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition eda_item.cpp:143
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:89
EDA_ITEM * m_parent
Owner.
Definition eda_item.h:543
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:37
virtual void ClearTempFlags()
Definition eda_item.h:179
EDA_ITEM * findParent(KICAD_T aType) const
Definition eda_item.cpp:73
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:89
Class that other classes need to inherit from, in order to be inspectable.
Definition inspectable.h:38
static const METRICS & Default()
Definition font.cpp:48
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
const wxString & GetDefaultFont() const
Definition kiid.h:44
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the symbol.
virtual bool TextVarResolver(wxString *aToken) const
Definition project.cpp:81
PROPERTY_BASE & SetChoicesFunc(std::function< wxPGChoices(INSPECTABLE *)> aFunc)
Definition property.h:276
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
Definition property.h:262
PROPERTY_BASE & SetIsHiddenFromDesignEditors(bool aIsHidden=true)
Definition property.h:340
PROPERTY_BASE & SetIsHiddenFromLibraryEditors(bool aIsHidden=true)
Definition property.h:333
Provide class metadata.Helper macro to map type hashes to names.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
Holds all the data relating to one schematic.
Definition schematic.h:90
PROJECT & Project() const
Return a reference to the project this schematic is part of.
Definition schematic.h:105
CONNECTION_GRAPH * ConnectionGraph() const
Definition schematic.h:201
static bool m_IsSchematicExists
True if a SCHEMATIC exists, false if not.
Definition schematic.h:532
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:189
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
void Reset()
Clears connectivity information.
wxString Name(bool aIgnoreSheet=false) const
void SetGraph(CONNECTION_GRAPH *aGraph)
void SetSheet(const SCH_SHEET_PATH &aSheet)
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:162
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition sch_item.cpp:825
friend class CONNECTION_GRAPH
Definition sch_item.h:757
SCH_ITEM * Duplicate(bool addToParentGroup, SCH_COMMIT *aCommit=nullptr, bool doClone=false) const
Routine to create a new copy of given item.
Definition sch_item.cpp:160
virtual bool IsConnectable() const
Definition sch_item.h:524
void SetLocked(bool aLocked) override
Definition sch_item.h:251
int m_unit
Definition sch_item.h:776
bool ResolveExcludedFromPosFiles(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.cpp:346
virtual int GetPenWidth() const
Definition sch_item.h:351
SCH_ITEM & operator=(const SCH_ITEM &aPin)
Definition sch_item.cpp:78
std::map< SCH_SHEET_PATH, std::vector< SCH_ITEM * >, SHEET_PATH_CMP > m_connected_items
Store pointers to other items that are connected to this one, per sheet.
Definition sch_item.h:784
void ClearConnectedItems(const SCH_SHEET_PATH &aPath)
Clear all connections to this item.
Definition sch_item.cpp:549
virtual bool doIsConnected(const VECTOR2I &aPosition) const
Provide the object specific test to see if it is connected to aPosition.
Definition sch_item.h:772
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction, RECURSE_MODE aMode)
Definition sch_item.h:628
int m_bodyStyle
Definition sch_item.h:777
const std::vector< wxString > * GetEmbeddedFonts() override
Definition sch_item.cpp:841
virtual ~SCH_ITEM()
Definition sch_item.cpp:92
const SYMBOL * GetParentSymbol() const
Definition sch_item.cpp:274
virtual wxString GetBodyStyleDescription(int aBodyStyle, bool aLabel) const
Definition sch_item.cpp:202
void SetPrivate(bool aPrivate)
Definition sch_item.h:247
virtual void swapData(SCH_ITEM *aItem)
Swap the internal data structures aItem with the schematic item.
Definition sch_item.cpp:626
virtual const wxString & GetCachedDriverName() const
Definition sch_item.cpp:619
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:268
int GetBodyStyle() const
Definition sch_item.h:242
std::vector< int > ViewGetLayers() const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition sch_item.cpp:471
SCH_CONNECTION * InitializeConnection(const SCH_SHEET_PATH &aPath, CONNECTION_GRAPH *aGraph)
Create a new connection object associated with this object.
Definition sch_item.cpp:580
virtual wxString GetUnitDisplayName(int aUnit, bool aLabel) const
Definition sch_item.cpp:191
bool IsLocked() const override
Definition sch_item.cpp:148
void AddConnectionTo(const SCH_SHEET_PATH &aPath, SCH_ITEM *aItem)
Add a connection link between this item and another.
Definition sch_item.cpp:564
friend class LIB_SYMBOL
Definition sch_item.h:797
@ SKIP_TST_POS
Definition sch_item.h:707
virtual bool HasHypertext() const
Indicates that the item has at least one hypertext action.
Definition sch_item.h:325
virtual bool GetExcludedFromPosFiles(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.h:276
int GetUnit() const
Definition sch_item.h:233
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition sch_item.cpp:523
virtual bool operator==(const SCH_ITEM &aOther) const
Definition sch_item.cpp:696
bool m_connectivity_dirty
Definition sch_item.h:789
bool IsPrivate() const
Definition sch_item.h:248
virtual void ClearCaches()
Definition sch_item.cpp:676
const std::vector< SCH_ITEM * > & ConnectedItems(const SCH_SHEET_PATH &aPath)
Retrieve the set of items connected to this item on the given sheet.
Definition sch_item.cpp:558
int GetMaxError() const
Definition sch_item.cpp:759
virtual bool GetExcludedFromBoard(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.h:269
virtual void SetBodyStyleProp(const wxString &aBodyStyle)
Definition sch_item.cpp:240
virtual int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const
Provide the draw object specific comparison called by the == and < operators.
Definition sch_item.cpp:720
virtual wxString GetBodyStyleProp() const
Definition sch_item.cpp:262
bool RenderAsBitmap(double aWorldScale) const override
Definition sch_item.cpp:813
const wxString & GetDefaultFont(const RENDER_SETTINGS *aSettings) const
Definition sch_item.cpp:768
void SetConnectionGraph(CONNECTION_GRAPH *aGraph)
Update the connection graph for all connections in this item.
Definition sch_item.cpp:511
AUTOPLACE_ALGO m_fieldsAutoplaced
Definition sch_item.h:779
std::unordered_set< SCH_RULE_AREA * > m_rule_areas_cache
Store pointers to rule areas which this item is contained within.
Definition sch_item.h:792
void SwapFlags(SCH_ITEM *aItem)
Swap the non-temp and non-edit flags.
Definition sch_item.cpp:655
bool IsConnected(const VECTOR2I &aPoint) const
Test the item to see if it is connected to aPoint.
Definition sch_item.cpp:478
virtual void SetUnitString(const wxString &aUnit)
Definition sch_item.cpp:213
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType, int aUnit=0, int aBodyStyle=0)
Definition sch_item.cpp:52
std::unordered_map< SCH_SHEET_PATH, SCH_CONNECTION * > m_connection_map
Store connectivity information, per sheet.
Definition sch_item.h:787
virtual bool operator<(const SCH_ITEM &aItem) const
Definition sch_item.cpp:705
bool ResolveExcludedFromBOM(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.cpp:314
bool m_private
Definition sch_item.h:778
SCH_CONNECTION * GetOrInitConnection(const SCH_SHEET_PATH &aPath, CONNECTION_GRAPH *aGraph)
Definition sch_item.cpp:604
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition sch_item.cpp:487
wxString ResolveText(const wxString &aText, const SCH_SHEET_PATH *aPath, int aDepth=0) const
Definition sch_item.cpp:377
wxString GetClass() const override
Return the class name.
Definition sch_item.h:172
bool ResolveExcludedFromBoard(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.cpp:330
const KIFONT::METRICS & GetFontMetrics() const
Definition sch_item.cpp:781
bool ResolveDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.cpp:362
virtual wxString GetUnitString() const
Definition sch_item.cpp:235
int GetEffectivePenWidth(const SCH_RENDER_SETTINGS *aSettings) const
Definition sch_item.cpp:790
bool IsGroupableType() const
Definition sch_item.cpp:113
void SwapItemData(SCH_ITEM *aImage)
Swap data between aItem and aImage.
Definition sch_item.cpp:632
bool ResolveExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.cpp:298
SCH_LAYER_ID m_layer
Definition sch_item.h:775
bool m_isLocked
Definition sch_item.h:794
virtual bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.h:255
virtual bool GetDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.h:283
virtual bool GetExcludedFromBOM(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.h:262
virtual bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth) const
Resolve any references to system tokens supported by the label.
int m_SymbolLineWidth
Override line widths for symbol drawing objects set to default line width.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:44
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the sheet.
Schematic symbol object.
Definition sch_symbol.h:69
bool ResolveTextVar(const SCH_SHEET_PATH *aPath, wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the symbol.
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition symbol.h:59
wxString ResolveTextVars(const wxString &aSource, const std::function< bool(wxString *)> *aResolver, int &aDepth)
Multi-pass text variable expansion and math expression evaluation.
Definition common.cpp:296
#define _(s)
@ NO_RECURSE
Definition eda_item.h:50
#define BRIGHTENED
item is drawn with a bright contour
#define SELECTED
Item was manually selected by the user.
#define STRUCT_DELETED
flag indication structures to be erased
#define SKIP_STRUCT
flag indicating that the structure should be ignored
std::uint32_t EDA_ITEM_FLAGS
#define KICAD_FONT_NAME
SCH_LAYER_ID
Eeschema drawing layers.
Definition layer_ids.h:447
@ LAYER_DEVICE
Definition layer_ids.h:464
@ LAYER_WIRE
Definition layer_ids.h:450
@ LAYER_DEVICE_BACKGROUND
Definition layer_ids.h:482
@ LAYER_SELECTION_SHADOWS
Definition layer_ids.h:493
#define UNIMPLEMENTED_FOR(type)
Definition macros.h:92
#define _HKI(x)
Definition page_info.cpp:40
see class PGM_BASE
#define TYPE_HASH(x)
Definition property.h:74
#define IMPLEMENT_ENUM_TO_WXANY(type)
Definition property.h:821
#define REGISTER_TYPE(x)
static const std::vector< KICAD_T > labelTypes
Definition sch_field.cpp:44
Class to handle a set of SCH_ITEMs.
static bool lessYX(const DANGLING_END_ITEM &a, const DANGLING_END_ITEM &b)
Definition sch_item.cpp:944
#define BITMAP_FONT_SIZE_THRESHOLD
Definition sch_item.cpp:43
static bool lessType(const DANGLING_END_ITEM &a, const DANGLING_END_ITEM &b)
Definition sch_item.cpp:952
static struct SCH_ITEM_DESC _SCH_ITEM_DESC
@ AUTOPLACE_NONE
Definition sch_item.h:66
DANGLING_END_T
Definition sch_item.h:74
@ PIN_END
Definition sch_item.h:79
@ BASE
Definition sch_item.h:56
@ DEMORGAN
Definition sch_item.h:57
T * GetAppSettings(const char *aFilename)
bool operator()(const SCH_ITEM *aFirst, const SCH_ITEM *aSecond) const
Definition sch_item.cpp:714
std::string path
VECTOR2I end
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:71
@ SCH_GROUP_T
Definition typeinfo.h:170
@ SCH_TABLE_T
Definition typeinfo.h:162
@ SCH_LINE_T
Definition typeinfo.h:160
@ LIB_SYMBOL_T
Definition typeinfo.h:145
@ SCH_NO_CONNECT_T
Definition typeinfo.h:157
@ SCH_SYMBOL_T
Definition typeinfo.h:169
@ SCH_FIELD_T
Definition typeinfo.h:147
@ SCH_DIRECTIVE_LABEL_T
Definition typeinfo.h:168
@ SCH_LABEL_T
Definition typeinfo.h:164
@ SCH_SHEET_T
Definition typeinfo.h:172
@ SCH_SHAPE_T
Definition typeinfo.h:146
@ SCH_RULE_AREA_T
Definition typeinfo.h:167
@ SCH_HIER_LABEL_T
Definition typeinfo.h:166
@ SCH_BUS_BUS_ENTRY_T
Definition typeinfo.h:159
@ SCH_LABEL_LOCATE_ANY_T
Definition typeinfo.h:188
@ SCHEMATIC_T
Definition typeinfo.h:201
@ SCH_SHEET_PIN_T
Definition typeinfo.h:171
@ SCH_TEXT_T
Definition typeinfo.h:148
@ SCH_BUS_WIRE_ENTRY_T
Definition typeinfo.h:158
@ SCH_BITMAP_T
Definition typeinfo.h:161
@ SCH_TEXTBOX_T
Definition typeinfo.h:149
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:165
@ SCH_JUNCTION_T
Definition typeinfo.h:156
@ SCH_PIN_T
Definition typeinfo.h:150
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683