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