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