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