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