KiCad PCB EDA Suite
Loading...
Searching...
No Matches
lib_symbol.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) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2008 Wayne Stambaugh <[email protected]>
6 * Copyright (C) 2022 CERN
7 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#include <font/outline_font.h>
28#include <sch_draw_panel.h>
29#include <plotters/plotter.h>
30#include <sch_screen.h>
31#include <template_fieldnames.h>
32#include <transform.h>
33#include <symbol_library.h>
35#include <sch_pin.h>
36#include <sch_shape.h>
37
38#include <memory>
39
40std::vector<SEARCH_TERM> LIB_SYMBOL::GetSearchTerms()
41{
42 std::vector<SEARCH_TERM> terms;
43
44 terms.emplace_back( SEARCH_TERM( GetLibNickname(), 4 ) );
45 terms.emplace_back( SEARCH_TERM( GetName(), 8 ) );
46 terms.emplace_back( SEARCH_TERM( GetLIB_ID().Format(), 16 ) );
47
48 wxStringTokenizer keywordTokenizer( GetKeyWords(), wxS( " " ), wxTOKEN_STRTOK );
49
50 while( keywordTokenizer.HasMoreTokens() )
51 terms.emplace_back( SEARCH_TERM( keywordTokenizer.GetNextToken(), 4 ) );
52
53 // Also include keywords as one long string, just in case
54 terms.emplace_back( SEARCH_TERM( GetKeyWords(), 1 ) );
55 terms.emplace_back( SEARCH_TERM( GetDescription(), 1 ) );
56
57 wxString footprint = GetFootprint();
58
59 if( !footprint.IsEmpty() )
60 terms.emplace_back( SEARCH_TERM( GetFootprintField().GetText(), 1 ) );
61
62 return terms;
63}
64
65
66void LIB_SYMBOL::GetChooserFields( std::map<wxString, wxString>& aColumnMap )
67{
68 for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
69 {
70 SCH_FIELD* field = static_cast<SCH_FIELD*>( &item );
71
72 if( field->ShowInChooser() )
73 aColumnMap[field->GetName()] = field->EDA_TEXT::GetShownText( false );
74 }
75}
76
77
78bool operator<( const LIB_SYMBOL& aItem1, const LIB_SYMBOL& aItem2 )
79{
80 return aItem1.GetName() < aItem2.GetName();
81}
82
83
86{
87 void operator()(void const *) const
88 {
89 }
90};
91
92
93LIB_SYMBOL::LIB_SYMBOL( const wxString& aName, LIB_SYMBOL* aParent, SYMBOL_LIB* aLibrary ) :
95 m_me( this, null_deleter() )
96{
97 m_lastModDate = 0;
98 m_unitCount = 1;
101 m_unitsLocked = false;
103
104 auto addField =
105 [&]( FIELD_T id, bool visible )
106 {
107 SCH_FIELD* field = new SCH_FIELD( this, id );
108 field->SetVisible( visible );
110 };
111
112 // construct only the mandatory fields
113 addField( FIELD_T::REFERENCE, true );
114 addField( FIELD_T::VALUE, true );
115 addField( FIELD_T::FOOTPRINT, false );
116 addField( FIELD_T::DATASHEET, false );
117 addField( FIELD_T::DESCRIPTION, false );
118
119 SetName( aName );
120
121 if( aParent )
122 SetParent( aParent );
123
124 SetLib( aLibrary );
125}
126
127
128LIB_SYMBOL::LIB_SYMBOL( const LIB_SYMBOL& aSymbol, SYMBOL_LIB* aLibrary ) :
129 SYMBOL( aSymbol ),
130 EMBEDDED_FILES( aSymbol ),
131 m_me( this, null_deleter() )
132{
133 m_library = aLibrary;
134 m_name = aSymbol.m_name;
135 m_fpFilters = wxArrayString( aSymbol.m_fpFilters );
136 m_unitCount = aSymbol.m_unitCount;
139 m_options = aSymbol.m_options;
140 m_libId = aSymbol.m_libId;
141 m_keyWords = aSymbol.m_keyWords;
142
143 std::ranges::copy( aSymbol.m_jumperPinGroups, std::back_inserter( m_jumperPinGroups ) );
145
147
149
150 for( const SCH_ITEM& oldItem : aSymbol.m_drawings )
151 {
152 if( ( oldItem.GetFlags() & ( IS_NEW | STRUCT_DELETED ) ) != 0 )
153 continue;
154
155 try
156 {
157 SCH_ITEM* newItem = (SCH_ITEM*) oldItem.Clone();
158 newItem->ClearSelected();
159 newItem->SetParent( this );
160 m_drawings.push_back( newItem );
161 }
162 catch( ... )
163 {
164 wxFAIL_MSG( "Failed to clone SCH_ITEM." );
165 return;
166 }
167 }
168
169 LIB_SYMBOL_SPTR parent = aSymbol.m_parent.lock();
170
171 if( parent )
172 SetParent( parent.get() );
173}
174
175
177{
178 if( &aSymbol == this )
179 return aSymbol;
180
181 SYMBOL::operator=( aSymbol );
182
183 m_library = aSymbol.m_library;
184 m_name = aSymbol.m_name;
185 m_fpFilters = wxArrayString( aSymbol.m_fpFilters );
186 m_unitCount = aSymbol.m_unitCount;
189 m_options = aSymbol.m_options;
190 m_libId = aSymbol.m_libId;
191 m_keyWords = aSymbol.m_keyWords;
192
193 std::ranges::copy( aSymbol.m_jumperPinGroups, std::back_inserter( m_jumperPinGroups ) );
195
196 m_unitDisplayNames.clear();
198
200
201 for( const SCH_ITEM& oldItem : aSymbol.m_drawings )
202 {
203 if( ( oldItem.GetFlags() & ( IS_NEW | STRUCT_DELETED ) ) != 0 )
204 continue;
205
206 SCH_ITEM* newItem = (SCH_ITEM*) oldItem.Clone();
207 newItem->SetParent( this );
208 m_drawings.push_back( newItem );
209 }
210
212
213 LIB_SYMBOL_SPTR parent = aSymbol.m_parent.lock();
214
215 if( parent )
216 SetParent( parent.get() );
217
218 EMBEDDED_FILES::operator=( aSymbol );
219
220 return *this;
221}
222
223
230{
231 static LIB_SYMBOL* symbol;
232
233 if( !symbol )
234 {
235 symbol = new LIB_SYMBOL( wxEmptyString );
236
237 SCH_SHAPE* square = new SCH_SHAPE( SHAPE_T::RECTANGLE, LAYER_DEVICE );
238
239 square->SetPosition( VECTOR2I( schIUScale.MilsToIU( -200 ), schIUScale.MilsToIU( 200 ) ) );
240 square->SetEnd( VECTOR2I( schIUScale.MilsToIU( 200 ), schIUScale.MilsToIU( -200 ) ) );
241 symbol->AddDrawItem( square );
242
243 SCH_TEXT* text = new SCH_TEXT( { 0, 0 }, wxT( "??" ), LAYER_DEVICE );
244
245 text->SetTextSize( VECTOR2I( schIUScale.MilsToIU( 150 ), schIUScale.MilsToIU( 150 ) ) );
246 symbol->AddDrawItem( text );
247 }
248
249 return symbol;
250}
251
252
254{
255 unsigned depth = 0;
256
257 LIB_SYMBOL_SPTR parent = GetParent().lock();
258
259 while( parent )
260 {
261 depth += 1;
262 parent = parent->GetParent().lock();
263 }
264
265 return depth;
266}
267
268
270{
271 const LIB_SYMBOL_SPTR sp = m_parent.lock();
272
273 // Recurse until the parent symbol is empty.
274 if( sp )
275 return sp->GetRootSymbol();
276
277 return m_me;
278}
279
280
281bool LIB_SYMBOL::HasUnitDisplayName( int aUnit ) const
282{
283 return ( m_unitDisplayNames.count( aUnit ) == 1 );
284}
285
286
287wxString LIB_SYMBOL::GetUnitDisplayName( int aUnit, bool aLabel ) const
288{
289 if( m_unitDisplayNames.contains( aUnit ) )
290 return m_unitDisplayNames.at( aUnit );
291 else if( aLabel )
292 return wxString::Format( _( "Unit %s" ), LIB_SYMBOL::LetterSubReference( aUnit, 'A' ) );
293 else
294 return LIB_SYMBOL::LetterSubReference( aUnit, 'A' );
295}
296
297
298wxString LIB_SYMBOL::GetBodyStyleDescription( int aBodyStyle, bool aLabel ) const
299{
300 if( aBodyStyle == BODY_STYLE::DEMORGAN )
301 return aLabel ? _( "Alternate" ) : wxString( _HKI( "Alternate" ) );
302 else if( aBodyStyle == BODY_STYLE::BASE )
303 return aLabel ? _( "Standard" ) : wxString( _HKI( "Standard" ) );
304 else
305 return wxT( "?" );
306}
307
308
309void LIB_SYMBOL::CopyUnitDisplayNames( std::map<int, wxString>& aTarget ) const
310{
311 for( const auto& it : m_unitDisplayNames )
312 aTarget[it.first] = it.second;
313}
314
315
316void LIB_SYMBOL::SetUnitDisplayName( int aUnit, const wxString& aName )
317{
318 if( aUnit <= GetUnitCount() )
319 {
320 if( aName.Length() > 0 )
321 m_unitDisplayNames[aUnit] = aName;
322 else
323 m_unitDisplayNames.erase( aUnit );
324 }
325}
326
327
328void LIB_SYMBOL::SetName( const wxString& aName )
329{
330 m_name = aName;
331 m_libId.SetLibItemName( aName );
332}
333
334
336{
337 if( aParent )
338 m_parent = aParent->SharedPtr();
339 else
340 m_parent.reset();
341}
342
343
344std::unique_ptr< LIB_SYMBOL > LIB_SYMBOL::Flatten() const
345{
346 std::unique_ptr< LIB_SYMBOL > retv;
347
348 if( IsDerived() )
349 {
350 LIB_SYMBOL_SPTR parent = m_parent.lock();
351
352 wxCHECK_MSG( parent, retv,
353 wxString::Format( "Parent of derived symbol '%s' undefined", m_name ) );
354
355 // Copy the parent.
356 if( parent->IsDerived() )
357 retv = parent->Flatten();
358 else
359 retv = std::make_unique<LIB_SYMBOL>( *parent.get() );
360
361 retv->m_name = m_name;
362 retv->SetLibId( m_libId );
363
364 // Overwrite parent's mandatory fields for fields which are defined in this.
365 for( FIELD_T fieldId : MANDATORY_FIELDS )
366 {
367 if( !GetField( fieldId )->GetText().IsEmpty() )
368 *retv->GetField( fieldId ) = *GetField( fieldId );
369 }
370
371 // Grab all the rest of derived symbol fields.
372 for( const SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
373 {
374 const SCH_FIELD* field = static_cast<const SCH_FIELD*>( &item );
375
376 // Mandatory fields were already resolved.
377 if( field->IsMandatory() )
378 continue;
379
380 SCH_FIELD* newField = new SCH_FIELD( *field );
381 newField->SetParent( retv.get() );
382
383 SCH_FIELD* parentField = retv->GetField( field->GetName() );
384
385 if( !parentField ) // Derived symbol field does not exist in parent symbol.
386 {
387 retv->AddDrawItem( newField );
388 }
389 else // Derived symbol field overrides the parent symbol field.
390 {
391 retv->RemoveDrawItem( parentField );
392 retv->AddDrawItem( newField );
393 }
394 }
395
396 retv->SetKeyWords( m_keyWords.IsEmpty() ? parent->GetKeyWords() : m_keyWords );
397 retv->SetFPFilters( m_fpFilters.IsEmpty() ? parent->GetFPFilters() : m_fpFilters );
398
399 retv->SetExcludedFromSim( parent->GetExcludedFromSim() );
400 retv->SetExcludedFromBOM( parent->GetExcludedFromBOM() );
401 retv->SetExcludedFromBoard( parent->GetExcludedFromBoard() );
402
403 retv->m_parent.reset();
404 }
405 else
406 {
407 retv = std::make_unique<LIB_SYMBOL>( *this );
408 }
409
410 return retv;
411}
412
413
414const wxString LIB_SYMBOL::GetLibraryName() const
415{
416 if( m_library )
417 return m_library->GetName();
418
419 return m_libId.GetLibNickname();
420}
421
422
424{
425 std::shared_ptr<LIB_SYMBOL> parent;
426
427 if( !m_parent.expired() && ( parent = m_parent.lock() ) )
428 {
429 if( parent->IsRoot() )
430 return parent->m_options == ENTRY_LOCAL_POWER;
431 else
432 return parent->IsLocalPower();
433 }
434
436}
437
438
440{
441 if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
442 {
443 if( parent->IsRoot() )
444 parent->m_options = ENTRY_LOCAL_POWER;
445 else
446 parent->SetLocalPower();
447 }
448
450}
451
452
454{
455 std::shared_ptr<LIB_SYMBOL> parent;
456
457 if( !m_parent.expired() && ( parent = m_parent.lock() ) )
458 {
459 if( parent->IsRoot() )
460 return parent->m_options == ENTRY_GLOBAL_POWER;
461 else
462 return parent->IsGlobalPower();
463 }
464
466}
467
468
470{
471 return IsLocalPower() || IsGlobalPower();
472}
473
474
476{
477 if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
478 {
479 if( parent->IsRoot() )
480 parent->m_options = ENTRY_GLOBAL_POWER;
481 else
482 parent->SetGlobalPower();
483 }
484
486}
487
488
490{
491 if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
492 {
493 if( parent->IsRoot() )
494 return parent->m_options == ENTRY_NORMAL;
495 else
496 return parent->IsNormal();
497 }
498
499 return m_options == ENTRY_NORMAL;
500}
501
502
504{
505 if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
506 {
507 if( parent->IsRoot() )
508 parent->m_options = ENTRY_NORMAL;
509 else
510 parent->SetNormal();
511 }
512
514}
515
516
517wxString LIB_SYMBOL::LetterSubReference( int aUnit, wxChar aInitialLetter )
518{
519 // use letters as notation. To allow more than 26 units, the sub ref
520 // use one letter if letter = A .. Z or a ... z, and 2 letters otherwise
521 // first letter is expected to be 'A' or 'a' (i.e. 26 letters are available)
522 int u;
523 wxString suffix;
524
525 do
526 {
527 u = ( aUnit - 1 ) % 26;
528 suffix = wxChar( aInitialLetter + u ) + suffix;
529 aUnit = ( aUnit - u ) / 26;
530 } while( aUnit > 0 );
531
532 return suffix;
533}
534
535
536bool LIB_SYMBOL::ResolveTextVar( wxString* token, int aDepth ) const
537{
538 wxString footprint;
539
540 for( const SCH_ITEM& item : m_drawings )
541 {
542 if( item.Type() == SCH_FIELD_T )
543 {
544 const SCH_FIELD& field = static_cast<const SCH_FIELD&>( item );
545
546 if( field.GetId() == FIELD_T::FOOTPRINT )
547 footprint = field.GetShownText( nullptr, false, aDepth + 1 );
548
549 if( token->IsSameAs( field.GetCanonicalName().Upper() )
550 || token->IsSameAs( field.GetName(), false ) )
551 {
552 *token = field.GetShownText( nullptr, false, aDepth + 1 );
553 return true;
554 }
555 }
556 }
557
558 // Consider missing simulation fields as empty, not un-resolved
559 if( token->IsSameAs( wxT( "SIM.DEVICE" ) )
560 || token->IsSameAs( wxT( "SIM.TYPE" ) )
561 || token->IsSameAs( wxT( "SIM.PINS" ) )
562 || token->IsSameAs( wxT( "SIM.PARAMS" ) )
563 || token->IsSameAs( wxT( "SIM.LIBRARY" ) )
564 || token->IsSameAs( wxT( "SIM.NAME" ) ) )
565 {
566 *token = wxEmptyString;
567 return true;
568 }
569
570 if( token->IsSameAs( wxT( "FOOTPRINT_LIBRARY" ) ) )
571 {
572 wxArrayString parts = wxSplit( footprint, ':' );
573
574 if( parts.Count() > 0 )
575 *token = parts[ 0 ];
576 else
577 *token = wxEmptyString;
578
579 return true;
580 }
581 else if( token->IsSameAs( wxT( "FOOTPRINT_NAME" ) ) )
582 {
583 wxArrayString parts = wxSplit( footprint, ':' );
584
585 if( parts.Count() > 1 )
586 *token = parts[ std::min( 1, (int) parts.size() - 1 ) ];
587 else
588 *token = wxEmptyString;
589
590 return true;
591 }
592 else if( token->IsSameAs( wxT( "SYMBOL_LIBRARY" ) ) )
593 {
595 return true;
596 }
597 else if( token->IsSameAs( wxT( "SYMBOL_NAME" ) ) )
598 {
600 return true;
601 }
602 else if( token->IsSameAs( wxT( "SYMBOL_DESCRIPTION" ) ) )
603 {
604 *token = GetDescription();
605 return true;
606 }
607 else if( token->IsSameAs( wxT( "SYMBOL_KEYWORDS" ) ) )
608 {
609 *token = GetKeyWords();
610 return true;
611 }
612 else if( token->IsSameAs( wxT( "EXCLUDE_FROM_BOM" ) ) )
613 {
614 *token = this->GetExcludedFromBOM() ? _( "Excluded from BOM" ) : wxString( "" );
615 return true;
616 }
617 else if( token->IsSameAs( wxT( "EXCLUDE_FROM_BOARD" ) ) )
618 {
619 *token = this->GetExcludedFromBoard() ? _( "Excluded from board" ) : wxString( "" );
620 return true;
621 }
622 else if( token->IsSameAs( wxT( "EXCLUDE_FROM_SIM" ) ) )
623 {
624 *token = this->GetExcludedFromSim() ? _( "Excluded from simulation" ) : wxString( "" );
625 return true;
626 }
627 else if( token->IsSameAs( wxT( "DNP" ) ) )
628 {
629 *token = this->GetDNP() ? _( "DNP" ) : wxString( "" );
630 return true;
631 }
632
633 return false;
634}
635
636
637void LIB_SYMBOL::Plot( PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
638 int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed )
639{
640 wxASSERT( aPlotter != nullptr );
641
642 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
643 COLOR4D color = renderSettings->GetLayerColor( LAYER_DEVICE );
644 COLOR4D bg = renderSettings->GetBackgroundColor();
645
646 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
647 bg = COLOR4D::WHITE;
648
649 if( aDimmed )
650 {
651 color.Desaturate( );
652 color = color.Mix( bg, 0.5f );
653 }
654
655 aPlotter->SetColor( color );
656
657 for( SCH_ITEM& item : m_drawings )
658 {
659 // Do not plot private items
660 if( item.IsPrivate() )
661 continue;
662
663 // LIB_FIELDs are not plotted here, because this plot function is used to plot schematic
664 // items which have their own SCH_FIELDs
665 if( item.Type() == SCH_FIELD_T )
666 continue;
667
668 if( aUnit && item.m_unit && ( item.m_unit != aUnit ) )
669 continue;
670
671 if( aBodyStyle && item.m_bodyStyle && ( item.m_bodyStyle != aBodyStyle ) )
672 continue;
673
674 item.Plot( aPlotter, aBackground, aPlotOpts, aUnit, aBodyStyle, aOffset, aDimmed );
675 }
676}
677
678
679void LIB_SYMBOL::PlotFields( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
680 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
681{
682 wxASSERT( aPlotter != nullptr );
683
684 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
685 COLOR4D color = renderSettings->GetLayerColor( LAYER_FIELDS );
686 COLOR4D bg = renderSettings->GetBackgroundColor();
687
688 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
689 bg = COLOR4D::WHITE;
690
691 if( aDimmed )
692 {
693 color.Desaturate( );
694 color = color.Mix( bg, 0.5f );
695 }
696
697 aPlotter->SetColor( color );
698
699 for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
700 {
701 SCH_FIELD& field = static_cast<SCH_FIELD&>( item );
702
703 if( !renderSettings->m_ShowHiddenFields && !field.IsVisible() )
704 continue;
705
706 // The reference is a special case: we should change the basic text
707 // to add '?' and the part id
708 wxString tmp = field.GetText();
709
710 field.SetText( field.GetFullText( aUnit ) );
711 item.Plot( aPlotter, aBackground, aPlotOpts, aUnit, aBodyStyle, aOffset, aDimmed );
712
713 field.SetText( tmp );
714 }
715}
716
717
719{
720 std::vector<SCH_SHAPE*> potential_top_items;
721 std::vector<SCH_ITEM*> bottom_items;
722
723 for( SCH_ITEM& item : m_drawings )
724 {
725 if( item.Type() == SCH_SHAPE_T )
726 {
727 SCH_SHAPE& shape = static_cast<SCH_SHAPE&>( item );
728
729 if( shape.GetFillMode() == FILL_T::FILLED_WITH_COLOR )
730 potential_top_items.push_back( &shape );
731 else
732 bottom_items.push_back( &item );
733 }
734 else
735 {
736 bottom_items.push_back( &item );
737 }
738 }
739
740 std::sort( potential_top_items.begin(), potential_top_items.end(),
741 []( SCH_ITEM* a, SCH_ITEM* b )
742 {
743 return a->GetBoundingBox().GetArea() > b->GetBoundingBox().GetArea();
744 } );
745
746 for( SCH_SHAPE* item : potential_top_items )
747 {
748 for( SCH_ITEM* bottom_item : bottom_items )
749 {
750 if( item->GetBoundingBox().Contains( bottom_item->GetBoundingBox() ) )
751 {
752 item->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
753 break;
754 }
755 }
756 }
757}
758
759
761{
762 wxASSERT( aItem != nullptr );
763
764 // none of the MANDATORY_FIELDS may be removed in RAM, but they may be
765 // omitted when saving to disk.
766 if( aItem->Type() == SCH_FIELD_T )
767 {
768 if( static_cast<SCH_FIELD*>( aItem )->IsMandatory() )
769 return;
770 }
771
772 LIB_ITEMS& items = m_drawings[ aItem->Type() ];
773
774 for( LIB_ITEMS::iterator i = items.begin(); i != items.end(); i++ )
775 {
776 if( &*i == aItem )
777 {
778 items.erase( i );
779 break;
780 }
781 }
782}
783
784
785void LIB_SYMBOL::AddDrawItem( SCH_ITEM* aItem, bool aSort )
786{
787 if( aItem )
788 {
789 aItem->SetParent( this );
790
791 m_drawings.push_back( aItem );
792
793 if( aSort )
795 }
796}
797
798
799std::vector<SCH_PIN*> LIB_SYMBOL::GetPins( int aUnit, int aBodyStyle ) const
800{
801 std::vector<SCH_PIN*> pins;
802
803 /* Notes:
804 * when aUnit == 0: no unit filtering
805 * when aBodyStyle == 0: no body style filtering
806 * when m_unit == 0, the item is common to all units
807 * when m_bodyStyle == 0, the item is common to all body styles
808 */
809
810 LIB_SYMBOL_SPTR parent = m_parent.lock();
811 const LIB_ITEMS_CONTAINER& drawItems = parent ? parent->m_drawings : m_drawings;
812
813 for( const SCH_ITEM& item : drawItems[SCH_PIN_T] )
814 {
815 // Unit filtering:
816 if( aUnit && item.m_unit && ( item.m_unit != aUnit ) )
817 continue;
818
819 // De Morgan variant filtering:
820 if( aBodyStyle && item.m_bodyStyle && ( item.m_bodyStyle != aBodyStyle ) )
821 continue;
822
823 // TODO: get rid of const_cast. (It used to be a C-style cast so was less noticeable.)
824 pins.push_back( const_cast<SCH_PIN*>( static_cast<const SCH_PIN*>( &item ) ) );
825 }
826
827 return pins;
828}
829
830
831std::vector<SCH_PIN*> LIB_SYMBOL::GetPins() const
832{
833 return GetPins( 0, 0 );
834}
835
836
838{
839 return (int) GetPins( 0 /* all units */, 1 /* single body style */ ).size();
840}
841
842
843SCH_PIN* LIB_SYMBOL::GetPin( const wxString& aNumber, int aUnit, int aBodyStyle ) const
844{
845 for( SCH_PIN* pin : GetPins( aUnit, aBodyStyle ) )
846 {
847 if( aNumber == pin->GetNumber() )
848 return pin;
849 }
850
851 return nullptr;
852}
853
854
855bool LIB_SYMBOL::PinsConflictWith( const LIB_SYMBOL& aOtherPart, bool aTestNums, bool aTestNames,
856 bool aTestType, bool aTestOrientation, bool aTestLength ) const
857{
858 for( const SCH_PIN* pin : GetPins() )
859 {
860 wxASSERT( pin );
861 bool foundMatch = false;
862
863 for( const SCH_PIN* otherPin : aOtherPart.GetPins() )
864 {
865 wxASSERT( otherPin );
866
867 // Same unit?
868 if( pin->GetUnit() != otherPin->GetUnit() )
869 continue;
870
871 // Same body stype?
872 if( pin->GetBodyStyle() != otherPin->GetBodyStyle() )
873 continue;
874
875 // Same position?
876 if( pin->GetPosition() != otherPin->GetPosition() )
877 continue;
878
879 // Same number?
880 if( aTestNums && ( pin->GetNumber() != otherPin->GetNumber() ) )
881 continue;
882
883 // Same name?
884 if( aTestNames && ( pin->GetName() != otherPin->GetName() ) )
885 continue;
886
887 // Same electrical type?
888 if( aTestType && ( pin->GetType() != otherPin->GetType() ) )
889 continue;
890
891 // Same orientation?
892 if( aTestOrientation
893 && ( pin->GetOrientation() != otherPin->GetOrientation() ) )
894 continue;
895
896 // Same length?
897 if( aTestLength && ( pin->GetLength() != otherPin->GetLength() ) )
898 continue;
899
900 foundMatch = true;
901 break; // Match found so search is complete.
902 }
903
904 if( !foundMatch )
905 {
906 // This means there was not an identical (according to the arguments)
907 // pin at the same position in the other symbol.
908 return true;
909 }
910 }
911
912 // The loop never gave up, so no conflicts were found.
913 return false;
914}
915
916
917const BOX2I LIB_SYMBOL::GetUnitBoundingBox( int aUnit, int aBodyStyle,
918 bool aIgnoreHiddenFields ) const
919{
920 BOX2I bBox; // Start with a fresh BOX2I so the Merge algorithm works
921
922 for( const SCH_ITEM& item : m_drawings )
923 {
924 if( item.m_unit > 0 && m_unitCount > 1 && aUnit > 0 && aUnit != item.m_unit )
925 continue;
926
927 if( item.m_bodyStyle > 0 && aBodyStyle > 0 && aBodyStyle != item.m_bodyStyle )
928 continue;
929
930 if( aIgnoreHiddenFields && item.Type() == SCH_FIELD_T )
931 {
932 if( !static_cast<const SCH_FIELD&>( item ).IsVisible() )
933 continue;
934 }
935
936 bBox.Merge( item.GetBoundingBox() );
937 }
938
939 return bBox;
940}
941
942
943const BOX2I LIB_SYMBOL::GetBodyBoundingBox( int aUnit, int aBodyStyle, bool aIncludePins,
944 bool aIncludePrivateItems ) const
945{
946 BOX2I bbox;
947
948 for( const SCH_ITEM& item : m_drawings )
949 {
950 if( item.m_unit > 0 && aUnit > 0 && aUnit != item.m_unit )
951 continue;
952
953 if( item.m_bodyStyle > 0 && aBodyStyle > 0 && aBodyStyle != item.m_bodyStyle )
954 continue;
955
956 if( item.IsPrivate() && !aIncludePrivateItems )
957 continue;
958
959 if( item.Type() == SCH_FIELD_T )
960 continue;
961
962 if( item.Type() == SCH_PIN_T )
963 {
964 const SCH_PIN& pin = static_cast<const SCH_PIN&>( item );
965
966 if( pin.IsVisible() )
967 {
968 // Note: the roots of the pins are always included for symbols that don't have
969 // a well-defined body.
970
971 if( aIncludePins )
972 bbox.Merge( pin.GetBoundingBox( false, false, false ) );
973 else
974 bbox.Merge( pin.GetPinRoot() );
975 }
976 }
977 else
978 {
979 bbox.Merge( item.GetBoundingBox() );
980 }
981 }
982
983 return bbox;
984}
985
986
988{
990}
991
992
994{
995 AddDrawItem( aField );
996}
997
998
999void LIB_SYMBOL::SetFields( const std::vector<SCH_FIELD>& aFieldsList )
1000{
1002
1003 for( const SCH_FIELD& src : aFieldsList )
1004 {
1005 // drawings is a ptr_vector, new and copy an object on the heap.
1006 SCH_FIELD* field = new SCH_FIELD( src );
1007
1008 field->SetParent( this );
1009 m_drawings.push_back( field );
1010 }
1011
1012 m_drawings.sort();
1013}
1014
1015
1016void LIB_SYMBOL::GetFields( std::vector<SCH_FIELD*>& aList, bool aVisibleOnly ) const
1017{
1018 for( const SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1019 {
1020 const SCH_FIELD* field = static_cast<const SCH_FIELD*>( &item );
1021
1022 if( aVisibleOnly )
1023 {
1024 if( !field->IsVisible() || field->GetText().IsEmpty() )
1025 continue;
1026 }
1027
1028 aList.push_back( const_cast<SCH_FIELD*>( field ) );
1029 }
1030
1031 std::sort( aList.begin(), aList.end(),
1032 []( SCH_FIELD* lhs, SCH_FIELD* rhs )
1033 {
1034 return lhs->GetOrdinal() < rhs->GetOrdinal();
1035 } );
1036}
1037
1038
1039void LIB_SYMBOL::CopyFields( std::vector<SCH_FIELD>& aList )
1040{
1041 std::vector<SCH_FIELD*> orderedFields;
1042
1043 GetFields( orderedFields );
1044
1045 for( SCH_FIELD* field : orderedFields )
1046 aList.emplace_back( *field );
1047}
1048
1049
1051{
1052 int ordinal = 42; // Arbitrarily larger than any mandatory FIELD_T id
1053
1054 for( const SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1055 ordinal = std::max( ordinal, static_cast<const SCH_FIELD*>( &item )->GetOrdinal() + 1 );
1056
1057 return ordinal;
1058}
1059
1060
1061const SCH_FIELD* LIB_SYMBOL::GetField( FIELD_T aFieldType ) const
1062{
1063 for( const SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1064 {
1065 const SCH_FIELD* field = static_cast<const SCH_FIELD*>( &item );
1066
1067 if( field->GetId() == aFieldType )
1068 return field;
1069 }
1070
1071 return nullptr;
1072}
1073
1074
1076{
1077 for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1078 {
1079 SCH_FIELD* field = static_cast<SCH_FIELD*>( &item );
1080
1081 if( field->GetId() == aFieldType )
1082 return field;
1083 }
1084
1085 return nullptr;
1086}
1087
1088
1089const SCH_FIELD* LIB_SYMBOL::GetField( const wxString& aFieldName ) const
1090{
1091 for( const SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1092 {
1093 const SCH_FIELD& field = static_cast<const SCH_FIELD&>( item );
1094
1095 if( field.GetName() == aFieldName )
1096 return &field;
1097 }
1098
1099 return nullptr;
1100}
1101
1102
1103SCH_FIELD* LIB_SYMBOL::GetField( const wxString& aFieldName )
1104{
1105 for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1106 {
1107 SCH_FIELD& field = static_cast<SCH_FIELD&>( item );
1108
1109 if( field.GetName() == aFieldName )
1110 return &field;
1111 }
1112
1113 return nullptr;
1114}
1115
1116
1118{
1119 for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1120 {
1121 SCH_FIELD& field = static_cast<SCH_FIELD&>( item );
1122
1123 if( field.GetCanonicalName().IsSameAs( aFieldName, false ) )
1124 return &field;
1125 }
1126
1127 return nullptr;
1128}
1129
1130
1132{
1133 const SCH_FIELD* field = GetField( FIELD_T::VALUE );
1134 wxASSERT( field != nullptr );
1135 return *field;
1136}
1137
1138
1140{
1141 const SCH_FIELD* field = GetField( FIELD_T::REFERENCE );
1142 wxASSERT( field != nullptr );
1143 return *field;
1144}
1145
1146
1148{
1149 const SCH_FIELD* field = GetField( FIELD_T::FOOTPRINT );
1150 wxASSERT( field != nullptr );
1151 return *field;
1152}
1153
1154
1156{
1157 const SCH_FIELD* field = GetField( FIELD_T::DATASHEET );
1158 wxASSERT( field != nullptr );
1159 return *field;
1160}
1161
1162
1164{
1165 const SCH_FIELD* field = GetField( FIELD_T::DESCRIPTION );
1166 wxASSERT( field != nullptr );
1167 return *field;
1168}
1169
1170
1172{
1173 wxString refDesignator = GetField( FIELD_T::REFERENCE )->GetText();
1174
1175 refDesignator.Replace( wxS( "~" ), wxS( " " ) );
1176
1177 wxString prefix = refDesignator;
1178
1179 while( prefix.Length() )
1180 {
1181 wxUniCharRef last = prefix.Last();
1182
1183 if( ( last >= '0' && last <= '9' ) || last == '?' || last == '*' )
1184 prefix.RemoveLast();
1185 else
1186 break;
1187 }
1188
1189 // Avoid a prefix containing trailing/leading spaces
1190 prefix.Trim( true );
1191 prefix.Trim( false );
1192
1193 return prefix;
1194}
1195
1196
1197void LIB_SYMBOL::RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction, RECURSE_MODE aMode )
1198{
1199 for( SCH_ITEM& item : m_drawings )
1200 aFunction( &item );
1201}
1202
1203
1204void LIB_SYMBOL::Move( const VECTOR2I& aOffset )
1205{
1206 for( SCH_ITEM& item : m_drawings )
1207 item.Move( aOffset );
1208}
1209
1210
1212{
1213 for( const SCH_ITEM& item : m_drawings )
1214 {
1215 if( item.m_bodyStyle > BODY_STYLE::BASE )
1216 return true;
1217 }
1218
1219 if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
1220 {
1221 for( const SCH_ITEM& item : parent->GetDrawItems() )
1222 {
1223 if( item.m_bodyStyle > BODY_STYLE::BASE )
1224 return true;
1225 }
1226 }
1227
1228 return false;
1229}
1230
1231
1233{
1234 int maxPinNumber = 0;
1235 LIB_SYMBOL_SPTR parent = m_parent.lock();
1236 const LIB_ITEMS_CONTAINER& drawItems = parent ? parent->m_drawings : m_drawings;
1237
1238 for( const SCH_ITEM& item : drawItems[SCH_PIN_T] )
1239 {
1240 const SCH_PIN* pin = static_cast<const SCH_PIN*>( &item );
1241 long currentPinNumber = 0;
1242
1243 if( pin->GetNumber().ToLong( &currentPinNumber ) )
1244 maxPinNumber = std::max( maxPinNumber, (int) currentPinNumber );
1245 }
1246
1247 return maxPinNumber;
1248}
1249
1250
1252{
1254
1255 for( SCH_ITEM& item : m_drawings )
1256 item.ClearTempFlags();
1257}
1258
1259
1261{
1263
1264 for( SCH_ITEM& item : m_drawings )
1265 item.ClearEditFlags();
1266}
1267
1268
1269SCH_ITEM* LIB_SYMBOL::LocateDrawItem( int aUnit, int aBodyStyle, KICAD_T aType,
1270 const VECTOR2I& aPoint )
1271{
1272 for( SCH_ITEM& item : m_drawings )
1273 {
1274 if( ( aUnit && item.m_unit && aUnit != item.m_unit )
1275 || ( aBodyStyle && item.m_bodyStyle && aBodyStyle != item.m_bodyStyle )
1276 || ( item.Type() != aType && aType != TYPE_NOT_INIT ) )
1277 {
1278 continue;
1279 }
1280
1281 if( item.HitTest( aPoint ) )
1282 return &item;
1283 }
1284
1285 return nullptr;
1286}
1287
1288
1289SCH_ITEM* LIB_SYMBOL::LocateDrawItem( int aUnit, int aBodyStyle, KICAD_T aType,
1290 const VECTOR2I& aPoint, const TRANSFORM& aTransform )
1291{
1292 /* we use LocateDrawItem( int aUnit, int convert, KICAD_T type, const
1293 * VECTOR2I& pt ) to search items.
1294 * because this function uses DefaultTransform as orient/mirror matrix
1295 * we temporary copy aTransform in DefaultTransform
1296 */
1297 TRANSFORM transform = DefaultTransform;
1298 DefaultTransform = aTransform;
1299
1300 SCH_ITEM* item = LocateDrawItem( aUnit, aBodyStyle, aType, aPoint );
1301
1302 // Restore matrix
1303 DefaultTransform = transform;
1304
1305 return item;
1306}
1307
1308
1309INSPECT_RESULT LIB_SYMBOL::Visit( INSPECTOR aInspector, void* aTestData,
1310 const std::vector<KICAD_T>& aScanTypes )
1311{
1312 // The part itself is never inspected, only its children
1313 for( SCH_ITEM& item : m_drawings )
1314 {
1315 if( item.IsType( aScanTypes ) )
1316 {
1317 if( aInspector( &item, aTestData ) == INSPECT_RESULT::QUIT )
1318 return INSPECT_RESULT::QUIT;
1319 }
1320 }
1321
1322 return INSPECT_RESULT::CONTINUE;
1323}
1324
1325
1326void LIB_SYMBOL::SetUnitCount( int aCount, bool aDuplicateDrawItems )
1327{
1328 if( m_unitCount == aCount )
1329 return;
1330
1331 if( aCount < m_unitCount )
1332 {
1334
1335 while( i != m_drawings.end() )
1336 {
1337 if( i->m_unit > aCount )
1338 i = m_drawings.erase( i );
1339 else
1340 ++i;
1341 }
1342 }
1343 else if( aDuplicateDrawItems )
1344 {
1345 int prevCount = m_unitCount;
1346
1347 // Temporary storage for new items, as adding new items directly to
1348 // m_drawings may cause the buffer reallocation which invalidates the
1349 // iterators
1350 std::vector<SCH_ITEM*> tmp;
1351
1352 for( SCH_ITEM& item : m_drawings )
1353 {
1354 if( item.m_unit != 1 )
1355 continue;
1356
1357 for( int j = prevCount + 1; j <= aCount; j++ )
1358 {
1359 SCH_ITEM* newItem = item.Duplicate( IGNORE_PARENT_GROUP );
1360 newItem->m_unit = j;
1361 tmp.push_back( newItem );
1362 }
1363 }
1364
1365 for( SCH_ITEM* item : tmp )
1366 m_drawings.push_back( item );
1367 }
1368
1369 m_drawings.sort();
1370 m_unitCount = aCount;
1371}
1372
1373
1375{
1376 if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
1377 return parent->GetUnitCount();
1378
1379 return m_unitCount;
1380}
1381
1382
1383void LIB_SYMBOL::SetHasAlternateBodyStyle( bool aHasAlternate, bool aDuplicatePins )
1384{
1385 if( aHasAlternate == HasAlternateBodyStyle() )
1386 return;
1387
1388 // Duplicate items to create the converted shape
1389 if( aHasAlternate )
1390 {
1391 if( aDuplicatePins )
1392 {
1393 std::vector<SCH_ITEM*> tmp; // Temporarily store the duplicated pins here.
1394
1395 for( SCH_ITEM& item : m_drawings[ SCH_PIN_T ] )
1396 {
1397 if( item.m_bodyStyle == 1 )
1398 {
1399 SCH_ITEM* newItem = item.Duplicate( IGNORE_PARENT_GROUP );
1400 newItem->m_bodyStyle = 2;
1401 tmp.push_back( newItem );
1402 }
1403 }
1404
1405 // Transfer the new pins to the LIB_SYMBOL.
1406 for( SCH_ITEM* item : tmp )
1407 m_drawings.push_back( item );
1408 }
1409 }
1410 else
1411 {
1412 // Delete converted shape items because the converted shape does not exist
1414
1415 while( i != m_drawings.end() )
1416 {
1417 if( i->m_bodyStyle > 1 )
1418 i = m_drawings.erase( i );
1419 else
1420 ++i;
1421 }
1422 }
1423
1424 m_drawings.sort();
1425}
1426
1427
1428std::vector<SCH_ITEM*> LIB_SYMBOL::GetUnitDrawItems( int aUnit, int aBodyStyle )
1429{
1430 std::vector<SCH_ITEM*> unitItems;
1431
1432 for( SCH_ITEM& item : m_drawings )
1433 {
1434 if( item.Type() == SCH_FIELD_T )
1435 continue;
1436
1437 if( ( aBodyStyle == -1 && item.GetUnit() == aUnit )
1438 || ( aUnit == -1 && item.GetBodyStyle() == aBodyStyle )
1439 || ( aUnit == item.GetUnit() && aBodyStyle == item.GetBodyStyle() ) )
1440 {
1441 unitItems.push_back( &item );
1442 }
1443 }
1444
1445 return unitItems;
1446}
1447
1448
1449std::vector<LIB_SYMBOL_UNIT> LIB_SYMBOL::GetUnitDrawItems()
1450{
1451 std::vector<LIB_SYMBOL_UNIT> units;
1452
1453 for( SCH_ITEM& item : m_drawings )
1454 {
1455 if( item.Type() == SCH_FIELD_T )
1456 continue;
1457
1458 int unit = item.GetUnit();
1459 int bodyStyle = item.GetBodyStyle();
1460
1461 auto it = std::find_if( units.begin(), units.end(),
1462 [unit, bodyStyle]( const LIB_SYMBOL_UNIT& a )
1463 {
1464 return a.m_unit == unit && a.m_bodyStyle == bodyStyle;
1465 } );
1466
1467 if( it == units.end() )
1468 {
1469 LIB_SYMBOL_UNIT newUnit;
1470 newUnit.m_unit = item.GetUnit();
1471 newUnit.m_bodyStyle = item.GetBodyStyle();
1472 newUnit.m_items.push_back( &item );
1473 units.emplace_back( newUnit );
1474 }
1475 else
1476 {
1477 it->m_items.push_back( &item );
1478 }
1479 }
1480
1481 return units;
1482}
1483
1484
1485
1486
1487#define REPORT( msg ) { if( aReporter ) aReporter->Report( msg ); }
1488#define ITEM_DESC( item ) ( item )->GetItemDescription( &unitsProvider, true )
1489
1490int LIB_SYMBOL::Compare( const LIB_SYMBOL& aRhs, int aCompareFlags, REPORTER* aReporter ) const
1491{
1492 UNITS_PROVIDER unitsProvider( schIUScale, EDA_UNITS::MM );
1493
1494 if( m_me == aRhs.m_me )
1495 return 0;
1496
1497 if( !aReporter && ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) == 0 )
1498 {
1499 if( int tmp = m_name.Cmp( aRhs.m_name ) )
1500 return tmp;
1501
1502 if( int tmp = m_libId.compare( aRhs.m_libId ) )
1503 return tmp;
1504
1505 if( m_parent.lock() < aRhs.m_parent.lock() )
1506 return -1;
1507
1508 if( m_parent.lock() > aRhs.m_parent.lock() )
1509 return 1;
1510 }
1511
1512 int retv = 0;
1513
1514 if( m_options != aRhs.m_options )
1515 {
1516 retv = ( m_options == ENTRY_NORMAL ) ? -1 : 1;
1517 REPORT( _( "Power flag differs." ) );
1518
1519 if( !aReporter )
1520 return retv;
1521 }
1522
1523 if( int tmp = m_unitCount - aRhs.m_unitCount )
1524 {
1525 retv = tmp;
1526 REPORT( _( "Unit count differs." ) );
1527
1528 if( !aReporter )
1529 return retv;
1530 }
1531
1532 // Make sure shapes and pins are sorted. No need with fields as those are
1533 // matched by id/name.
1534
1535 std::set<const SCH_ITEM*, SCH_ITEM::cmp_items> aShapes;
1536 std::set<const SCH_ITEM*> aFields;
1537 std::set<const SCH_ITEM*, SCH_ITEM::cmp_items> aPins;
1538
1539 for( auto it = m_drawings.begin(); it != m_drawings.end(); ++it )
1540 {
1541 if( it->Type() == SCH_SHAPE_T )
1542 aShapes.insert( &(*it) );
1543 else if( it->Type() == SCH_FIELD_T )
1544 aFields.insert( &(*it) );
1545 else if( it->Type() == SCH_PIN_T )
1546 aPins.insert( &(*it) );
1547 }
1548
1549 std::set<const SCH_ITEM*, SCH_ITEM::cmp_items> bShapes;
1550 std::set<const SCH_ITEM*> bFields;
1551 std::set<const SCH_ITEM*, SCH_ITEM::cmp_items> bPins;
1552
1553 for( auto it = aRhs.m_drawings.begin(); it != aRhs.m_drawings.end(); ++it )
1554 {
1555 if( it->Type() == SCH_SHAPE_T )
1556 bShapes.insert( &(*it) );
1557 else if( it->Type() == SCH_FIELD_T )
1558 bFields.insert( &(*it) );
1559 else if( it->Type() == SCH_PIN_T )
1560 bPins.insert( &(*it) );
1561 }
1562
1563 if( int tmp = static_cast<int>( aShapes.size() - bShapes.size() ) )
1564 {
1565 retv = tmp;
1566 REPORT( _( "Graphic item count differs." ) );
1567
1568 if( !aReporter )
1569 return retv;
1570 }
1571 else
1572 {
1573 for( auto aIt = aShapes.begin(), bIt = bShapes.begin(); aIt != aShapes.end(); aIt++, bIt++ )
1574 {
1575 if( int tmp2 = (*aIt)->compare( *(*bIt), aCompareFlags ) )
1576 {
1577 retv = tmp2;
1578 REPORT( wxString::Format( _( "%s differs." ), ITEM_DESC( *aIt ) ) );
1579
1580 if( !aReporter )
1581 return retv;
1582 }
1583 }
1584 }
1585
1586 if( int tmp = static_cast<int>( aPins.size() - bPins.size() ) )
1587 {
1588 retv = tmp;
1589 REPORT( _( "Pin count differs." ) );
1590
1591 if( !aReporter )
1592 return retv;
1593 }
1594 else
1595 {
1596 for( const SCH_ITEM* aPinItem : aPins )
1597 {
1598 const SCH_PIN* aPin = static_cast<const SCH_PIN*>( aPinItem );
1599 const SCH_PIN* bPin = aRhs.GetPin( aPin->GetNumber(), aPin->GetUnit(),
1600 aPin->GetBodyStyle() );
1601
1602 if( !bPin )
1603 {
1604 retv = 1;
1605 REPORT( wxString::Format( _( "Pin %s not found." ), aPin->GetNumber() ) );
1606
1607 if( !aReporter )
1608 return retv;
1609 }
1610 else if( int tmp2 = aPinItem->compare( *bPin, aCompareFlags ) )
1611 {
1612 retv = tmp2;
1613 REPORT( wxString::Format( _( "Pin %s differs." ), aPin->GetNumber() ) );
1614
1615 if( !aReporter )
1616 return retv;
1617 }
1618 }
1619 }
1620
1621 for( const SCH_ITEM* aFieldItem : aFields )
1622 {
1623 const SCH_FIELD* aField = static_cast<const SCH_FIELD*>( aFieldItem );
1624 const SCH_FIELD* bField = nullptr;
1625 int tmp = 0;
1626
1627 if( aField->IsMandatory() )
1628 bField = aRhs.GetField( aField->GetId() );
1629 else
1630 bField = aRhs.GetField( aField->GetName() );
1631
1632 if( !bField )
1633 tmp = 1;
1634 else
1635 tmp = aFieldItem->compare( *bField, aCompareFlags );
1636
1637 if( tmp )
1638 {
1639 retv = tmp;
1640 REPORT( wxString::Format( _( "%s field differs." ), aField->GetName( false ) ) );
1641
1642 if( !aReporter )
1643 return retv;
1644 }
1645 }
1646
1647 if( int tmp = static_cast<int>( aFields.size() - bFields.size() ) )
1648 {
1649 retv = tmp;
1650 REPORT( _( "Field count differs." ) );
1651
1652 if( !aReporter )
1653 return retv;
1654 }
1655
1656 if( int tmp = static_cast<int>( m_fpFilters.GetCount() - aRhs.m_fpFilters.GetCount() ) )
1657 {
1658 retv = tmp;
1659 REPORT( _( "Footprint filters differs." ) );
1660
1661 if( !aReporter )
1662 return retv;
1663 }
1664 else
1665 {
1666 for( size_t i = 0; i < m_fpFilters.GetCount(); i++ )
1667 {
1668 if( int tmp2 = m_fpFilters[i].Cmp( aRhs.m_fpFilters[i] ) )
1669 {
1670 retv = tmp2;
1671 REPORT( _( "Footprint filters differ." ) );
1672
1673 if( !aReporter )
1674 return retv;
1675 }
1676 }
1677 }
1678
1679 if( int tmp = m_keyWords.Cmp( aRhs.m_keyWords ) )
1680 {
1681 retv = tmp;
1682 REPORT( _( "Symbol keywords differ." ) );
1683
1684 if( !aReporter )
1685 return retv;
1686 }
1687
1688 if( int tmp = m_pinNameOffset - aRhs.m_pinNameOffset )
1689 {
1690 retv = tmp;
1691 REPORT( _( "Symbol pin name offsets differ." ) );
1692
1693 if( !aReporter )
1694 return retv;
1695 }
1696
1697 if( ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) == 0 )
1698 {
1699 if( m_showPinNames != aRhs.m_showPinNames )
1700 {
1701 retv = ( m_showPinNames ) ? 1 : -1;
1702 REPORT( _( "Show pin names settings differ." ) );
1703
1704 if( !aReporter )
1705 return retv;
1706 }
1707
1709 {
1710 retv = ( m_showPinNumbers ) ? 1 : -1;
1711 REPORT( _( "Show pin numbers settings differ." ) );
1712
1713 if( !aReporter )
1714 return retv;
1715 }
1716
1718 {
1719 retv = ( m_excludedFromSim ) ? -1 : 1;
1720 REPORT( _( "Exclude from simulation settings differ." ) );
1721
1722 if( !aReporter )
1723 return retv;
1724 }
1725
1727 {
1728 retv = ( m_excludedFromBOM ) ? -1 : 1;
1729 REPORT( _( "Exclude from bill of materials settings differ." ) );
1730
1731 if( !aReporter )
1732 return retv;
1733 }
1734
1736 {
1737 retv = ( m_excludedFromBoard ) ? -1 : 1;
1738 REPORT( _( "Exclude from board settings differ." ) );
1739
1740 if( !aReporter )
1741 return retv;
1742 }
1743 }
1744
1745 if( !aReporter )
1746 {
1747 if( m_unitsLocked != aRhs.m_unitsLocked )
1748 return ( m_unitsLocked ) ? 1 : -1;
1749
1750 // Compare unit display names
1752 return -1;
1753 else if( m_unitDisplayNames > aRhs.m_unitDisplayNames )
1754 return 1;
1755 }
1756
1757 return retv;
1758}
1759
1760
1761int LIB_SYMBOL::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
1762{
1763 if( Type() != aOther.Type() )
1764 return Type() - aOther.Type();
1765
1766 const LIB_SYMBOL* tmp = static_cast<const LIB_SYMBOL*>( &aOther );
1767
1768 return Compare( *tmp, aCompareFlags );
1769}
1770
1771
1772double LIB_SYMBOL::Similarity( const SCH_ITEM& aOther ) const
1773{
1774 wxCHECK( aOther.Type() == LIB_SYMBOL_T, 0.0 );
1775
1776 const LIB_SYMBOL& other = static_cast<const LIB_SYMBOL&>( aOther );
1777 double similarity = 0.0;
1778 int totalItems = 0;
1779
1780 if( m_Uuid == aOther.m_Uuid )
1781 return 1.0;
1782
1783 for( const SCH_ITEM& item : m_drawings )
1784 {
1785 totalItems += 1;
1786 double max_similarity = 0.0;
1787
1788 for( const SCH_ITEM& otherItem : other.m_drawings )
1789 {
1790 double temp_similarity = item.Similarity( otherItem );
1791 max_similarity = std::max( max_similarity, temp_similarity );
1792
1793 if( max_similarity == 1.0 )
1794 break;
1795 }
1796
1797 similarity += max_similarity;
1798 }
1799
1800 for( const SCH_PIN* pin : GetPins() )
1801 {
1802 totalItems += 1;
1803 double max_similarity = 0.0;
1804
1805 for( const SCH_PIN* otherPin : other.GetPins() )
1806 {
1807 double temp_similarity = pin->Similarity( *otherPin );
1808 max_similarity = std::max( max_similarity, temp_similarity );
1809
1810 if( max_similarity == 1.0 )
1811 break;
1812 }
1813
1814 similarity += max_similarity;
1815 }
1816
1817 if( totalItems == 0 )
1818 similarity = 0.0;
1819 else
1820 similarity /= totalItems;
1821
1823 similarity *= 0.9;
1824
1826 similarity *= 0.9;
1827
1829 similarity *= 0.9;
1830
1831 if( m_flags != other.m_flags )
1832 similarity *= 0.9;
1833
1834 if( m_unitCount != other.m_unitCount )
1835 similarity *= 0.5;
1836
1837 if( m_pinNameOffset != other.m_pinNameOffset )
1838 similarity *= 0.9;
1839
1840 if( m_showPinNames != other.m_showPinNames )
1841 similarity *= 0.9;
1842
1843 if( m_showPinNumbers != other.m_showPinNumbers )
1844 similarity *= 0.9;
1845
1846 return similarity;
1847}
1848
1849
1851{
1852 return static_cast<EMBEDDED_FILES*>( this );
1853}
1854
1855
1857{
1858 return static_cast<const EMBEDDED_FILES*>( this );
1859}
1860
1861
1862std::set<KIFONT::OUTLINE_FONT*> LIB_SYMBOL::GetFonts() const
1863{
1864 using EMBEDDING_PERMISSION = KIFONT::OUTLINE_FONT::EMBEDDING_PERMISSION;
1865
1866 std::set<KIFONT::OUTLINE_FONT*> fonts;
1867
1868 for( const SCH_ITEM& item : m_drawings )
1869 {
1870 if( item.Type() == SCH_TEXT_T )
1871 {
1872 const SCH_TEXT& text = static_cast<const SCH_TEXT&>( item );
1873
1874 if( auto* font = text.GetFont(); font && !font->IsStroke() )
1875 {
1876 auto* outline = static_cast<KIFONT::OUTLINE_FONT*>( font );
1877 auto permission = outline->GetEmbeddingPermission();
1878
1879 if( permission == EMBEDDING_PERMISSION::EDITABLE
1880 || permission == EMBEDDING_PERMISSION::INSTALLABLE )
1881 {
1882 fonts.insert( outline );
1883 }
1884 }
1885 }
1886 }
1887
1888 return fonts;
1889}
1890
1891
1893{
1894 std::set<KIFONT::OUTLINE_FONT*> fonts = GetFonts();
1895
1896 for( KIFONT::OUTLINE_FONT* font : fonts )
1897 {
1898 auto file = GetEmbeddedFiles()->AddFile( font->GetFileName(), false );
1900 }
1901}
1902
1903
1904std::optional<const std::set<wxString>> LIB_SYMBOL::GetJumperPinGroup( const wxString& aPinNumber ) const
1905{
1906 for( const std::set<wxString>& group : m_jumperPinGroups )
1907 {
1908 if( group.contains( aPinNumber ) )
1909 return group;
1910 }
1911
1912 return std::nullopt;
1913}
int color
Definition: DXF_plotter.cpp:63
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:114
double square(double x)
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:658
virtual void ClearEditFlags()
Definition: eda_item.h:156
const KIID m_Uuid
Definition: eda_item.h:516
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:110
void ClearSelected()
Definition: eda_item.h:137
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:527
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:113
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:118
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:145
virtual void ClearTempFlags()
Definition: eda_item.h:169
FILL_T GetFillMode() const
Definition: eda_shape.h:142
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:97
virtual bool IsVisible() const
Definition: eda_text.h:184
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:386
bool IsEmpty() const
EMBEDDED_FILES & operator=(EMBEDDED_FILES &&other) noexcept
EMBEDDED_FILE * AddFile(const wxFileName &aName, bool aOverwrite)
Load a file from disk and adds it to the collection.
Class OUTLINE_FONT implements outline font drawing.
Definition: outline_font.h:53
EMBEDDING_PERMISSION GetEmbeddingPermission() const
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:111
int compare(const LIB_ID &aLibId) const
Compare the contents of LIB_ID objects by performing a std::string comparison of the library nickname...
Definition: lib_id.cpp:161
const wxString GetUniStringLibItemName() const
Get strings for display messages in dialogs.
Definition: lib_id.h:112
const wxString GetUniStringLibNickname() const
Definition: lib_id.h:88
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:87
Define a library symbol object.
Definition: lib_symbol.h:85
LIB_ITEMS_CONTAINER m_drawings
Definition: lib_symbol.h:687
bool ResolveTextVar(wxString *token, int aDepth=0) const
Resolve any references to system tokens supported by the symbol.
Definition: lib_symbol.cpp:536
SCH_FIELD & GetDescriptionField()
Return reference to the description field.
Definition: lib_symbol.h:350
wxString GetDescription() const override
Definition: lib_symbol.h:170
wxString GetKeyWords() const override
Definition: lib_symbol.h:183
void SetGlobalPower()
Definition: lib_symbol.cpp:475
bool HasUnitDisplayName(int aUnit) const
Return true if the given unit aUnit has a display name defined.
Definition: lib_symbol.cpp:281
std::vector< SCH_PIN * > GetPins(int aUnit, int aBodyStyle) const
Return a list of pin object pointers from the draw item list.
Definition: lib_symbol.cpp:799
LIBRENTRYOPTIONS m_options
Special symbol features such as POWER or NORMAL.)
Definition: lib_symbol.h:685
bool PinsConflictWith(const LIB_SYMBOL &aOtherSymbol, bool aTestNums, bool aTestNames, bool aTestType, bool aTestOrientation, bool aTestLength) const
Return true if this symbol's pins do not match another symbol's pins.
Definition: lib_symbol.cpp:855
void GetFields(std::vector< SCH_FIELD * > &aList, bool aVisibleOnly=false) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
bool IsPower() const override
Definition: lib_symbol.cpp:469
wxString GetPrefix()
void SetUnitCount(int aCount, bool aDuplicateDrawItems=true)
Set the units per symbol count.
SCH_FIELD & GetDatasheetField()
Return reference to the datasheet field.
Definition: lib_symbol.h:346
const BOX2I GetUnitBoundingBox(int aUnit, int aBodyStyle, bool aIgnoreHiddenFields=true) const
Get the bounding box for the symbol.
Definition: lib_symbol.cpp:917
std::vector< struct LIB_SYMBOL_UNIT > GetUnitDrawItems()
Return a list of SCH_ITEM objects separated by unit and convert number.
std::map< int, wxString > m_unitDisplayNames
Definition: lib_symbol.h:703
std::vector< std::set< wxString > > m_jumperPinGroups
A list of jumper pin groups, each of which is a set of pin numbers that should be jumpered together (...
Definition: lib_symbol.h:697
void ClearTempFlags() override
Clears the status flag all draw objects in this symbol.
bool IsDerived() const
Definition: lib_symbol.h:207
SYMBOL_LIB * m_library
Definition: lib_symbol.h:689
wxString GetFootprint() override
For items with footprint fields.
Definition: lib_symbol.h:196
const wxString GetLibraryName() const
Definition: lib_symbol.cpp:414
void SetFields(const std::vector< SCH_FIELD > &aFieldsList)
Overwrite all the existing fields in this symbol with fields supplied in aFieldsList.
Definition: lib_symbol.cpp:999
std::vector< SEARCH_TERM > GetSearchTerms() override
Definition: lib_symbol.cpp:40
int GetMaxPinNumber() const
LIB_SYMBOL_SPTR m_me
Definition: lib_symbol.h:675
void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Plot the item to aPlotter.
Definition: lib_symbol.cpp:637
SCH_FIELD * GetField(const wxString &aFieldName)
Find a field within this symbol matching aFieldName; return nullptr if not found.
SCH_FIELD & GetFootprintField()
Return reference to the footprint field.
Definition: lib_symbol.h:342
int Compare(const LIB_SYMBOL &aRhs, int aCompareFlags=0, REPORTER *aReporter=nullptr) const
Comparison test that can be used for operators.
void FixupDrawItems()
This function finds the filled draw items that are covering up smaller draw items and replaces their ...
Definition: lib_symbol.cpp:718
SCH_PIN * GetPin(const wxString &aNumber, int aUnit=0, int aBodyStyle=0) const
Return pin object with the requested pin aNumber.
Definition: lib_symbol.cpp:843
bool IsNormal() const override
Definition: lib_symbol.cpp:489
wxString m_name
Definition: lib_symbol.h:690
std::set< KIFONT::OUTLINE_FONT * > GetFonts() const override
bool HasAlternateBodyStyle() const override
Test if symbol has more than one body conversion type (DeMorgan).
SCH_FIELD * FindFieldCaseInsensitive(const wxString &aFieldName)
wxString m_keyWords
Search keywords.
Definition: lib_symbol.h:691
SCH_ITEM * LocateDrawItem(int aUnit, int aBodyStyle, KICAD_T aType, const VECTOR2I &aPoint)
Locate a draw object.
static wxString LetterSubReference(int aUnit, wxChar aInitialLetter)
Definition: lib_symbol.cpp:517
double Similarity(const SCH_ITEM &aSymbol) const override
Return a measure of similarity between this symbol and aSymbol.
static LIB_SYMBOL * GetDummy()
Returns a dummy LIB_SYMBOL, used when one is missing in the schematic.
Definition: lib_symbol.cpp:229
void PlotFields(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed)
Plot symbol fields.
Definition: lib_symbol.cpp:679
void SetParent(LIB_SYMBOL *aParent=nullptr)
Definition: lib_symbol.cpp:335
wxString GetName() const override
Definition: lib_symbol.h:149
SCH_FIELD & GetValueField()
Return reference to the value field.
Definition: lib_symbol.h:334
bool IsLocalPower() const override
Definition: lib_symbol.cpp:423
void RemoveDrawItem(SCH_ITEM *aItem)
Remove draw aItem from list.
Definition: lib_symbol.cpp:760
void GetChooserFields(std::map< wxString, wxString > &aColumnMap) override
Retrieves a key/value map of the fields on this item that should be exposed to the library browser/ch...
Definition: lib_symbol.cpp:66
int compare(const SCH_ITEM &aOther, int aCompareFlags=SCH_ITEM::COMPARE_FLAGS::EQUALITY) const override
The library symbol specific sort order is as follows:
timestamp_t m_lastModDate
Definition: lib_symbol.h:679
std::optional< const std::set< wxString > > GetJumperPinGroup(const wxString &aPinNumber) const
Retrieves the jumper group containing the specified pin number, if one exists.
LIB_ID m_libId
Definition: lib_symbol.h:677
void SetLocalPower()
Definition: lib_symbol.cpp:439
void SetLib(SYMBOL_LIB *aLibrary)
Definition: lib_symbol.h:212
std::vector< SCH_PIN * > GetPins() const override
Return a list of pin pointers for all units / converts.
Definition: lib_symbol.cpp:831
wxString GetLibNickname() const override
Sets the Description field text value.
Definition: lib_symbol.h:161
const LIB_SYMBOL & operator=(const LIB_SYMBOL &aSymbol)
Definition: lib_symbol.cpp:176
bool m_unitsLocked
True if symbol has multiple units and changing one unit does not automatically change another unit.
Definition: lib_symbol.h:682
wxArrayString m_fpFilters
List of suitable footprint names for the symbol (wild card names accepted).
Definition: lib_symbol.h:692
void Move(const VECTOR2I &aOffset) override
Move the symbol aOffset.
void CopyFields(std::vector< SCH_FIELD > &aList)
Create a copy of the SCH_FIELDs, sorted in ordinal order.
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction, RECURSE_MODE aMode) override
LIB_SYMBOL_SPTR SharedPtr() const
http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared.
Definition: lib_symbol.h:96
INSPECT_RESULT Visit(INSPECTOR inspector, void *testData, const std::vector< KICAD_T > &aScanTypes) override
May be re-implemented for each derived class in order to handle all the types given by its member dat...
EMBEDDED_FILES * GetEmbeddedFiles() override
int m_unitCount
Number of units (parts) per package.
Definition: lib_symbol.h:681
void SetHasAlternateBodyStyle(bool aHasAlternate, bool aDuplicatePins=true)
Set or clear the alternate body style (DeMorgan) for the symbol.
bool IsGlobalPower() const override
Definition: lib_symbol.cpp:453
wxString GetBodyStyleDescription(int aBodyStyle, bool aLabel) const override
Definition: lib_symbol.cpp:298
unsigned GetInheritanceDepth() const
Get the number of parents for this symbol.
Definition: lib_symbol.cpp:253
int GetUnitCount() const override
LIB_SYMBOL_REF m_parent
Use for inherited symbols.
Definition: lib_symbol.h:676
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Definition: lib_symbol.cpp:344
BOX2I GetBodyBoundingBox() const override
Return a bounding box for the symbol body but not the pins or fields.
Definition: lib_symbol.h:260
int GetPinCount() override
Definition: lib_symbol.cpp:837
void AddField(SCH_FIELD *aField)
Add a field.
Definition: lib_symbol.cpp:993
void ClearEditFlags() override
void deleteAllFields()
Definition: lib_symbol.cpp:987
LIB_ID GetLIB_ID() const override
Definition: lib_symbol.h:151
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:118
bool m_duplicatePinNumbersAreJumpers
Flag that this symbol should automatically treat sets of two or more pins with the same number as jum...
Definition: lib_symbol.h:701
LIB_SYMBOL_SPTR GetRootSymbol() const
Get the parent symbol that does not have another parent.
Definition: lib_symbol.cpp:269
void SetUnitDisplayName(int aUnit, const wxString &aName)
Set the user-defined display name for aUnit to aName for symbols with units.
Definition: lib_symbol.cpp:316
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
Definition: lib_symbol.cpp:785
wxString GetUnitDisplayName(int aUnit, bool aLabel) const override
Return the user-defined display name for aUnit for symbols with units.
Definition: lib_symbol.cpp:287
void EmbedFonts() override
virtual void SetName(const wxString &aName)
Definition: lib_symbol.cpp:328
void SetNormal()
Definition: lib_symbol.cpp:503
void CopyUnitDisplayNames(std::map< int, wxString > &aTarget) const
Copy all unit display names into the given map aTarget.
Definition: lib_symbol.cpp:309
SCH_FIELD & GetReferenceField()
Return reference to the reference designator field.
Definition: lib_symbol.h:338
int GetNextFieldOrdinal() const
Return the next ordinal for a user field for this symbol.
void sort()
Definition: multivector.h:248
void push_back(T *aItem)
Definition: multivector.h:175
ITERATOR_BASE< SCH_ITEM, MULTIVECTOR< SCH_ITEM, FIRST_TYPE_VAL, LAST_TYPE_VAL >, typename ITEM_PTR_VECTOR::iterator > ITERATOR
The const iterator.
Definition: multivector.h:165
ITERATOR end(int aType=UNDEFINED_TYPE)
Definition: multivector.h:195
void clear(int aType=UNDEFINED_TYPE)
Definition: multivector.h:213
ITERATOR erase(const ITERATOR &aIterator)
Definition: multivector.h:180
ITERATOR begin(int aType=UNDEFINED_TYPE)
Definition: multivector.h:189
Base plotter engine class.
Definition: plotter.h:121
bool GetColorMode() const
Definition: plotter.h:149
virtual void SetColor(const COLOR4D &color)=0
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:73
int compare(const SCH_ITEM &aOther, int aCompareFlags=0) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: sch_field.cpp:1486
bool IsMandatory() const
Definition: sch_field.cpp:1359
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: sch_field.cpp:301
FIELD_T GetId() const
Definition: sch_field.h:116
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: sch_field.cpp:1117
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: sch_field.cpp:1103
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Definition: sch_field.cpp:191
bool ShowInChooser() const
Definition: sch_field.h:223
void SetText(const wxString &aText) override
Definition: sch_field.cpp:1089
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:168
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:137
int m_unit
Definition: sch_item.h:745
int m_bodyStyle
Definition: sch_item.h:746
SCH_RENDER_SETTINGS * getRenderSettings(PLOTTER *aPlotter) const
Definition: sch_item.h:693
int GetBodyStyle() const
Definition: sch_item.h:248
friend class LIB_SYMBOL
Definition: sch_item.h:764
int GetUnit() const
Definition: sch_item.h:239
virtual void SetExcludedFromSim(bool aExclude)
Definition: sch_item.h:256
const wxString & GetNumber() const
Definition: sch_pin.h:123
const KIGFX::COLOR4D & GetBackgroundColor() const override
Return current background color settings.
Object used to load, save, search, and otherwise manipulate symbol library files.
const wxString GetName() const
Return the file name without path or extension.
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition: symbol.h:63
bool m_showPinNumbers
Definition: symbol.h:222
bool m_excludedFromSim
Definition: symbol.h:224
bool m_showPinNames
Definition: symbol.h:221
bool GetExcludedFromBoard() const override
Definition: symbol.h:187
bool m_excludedFromBOM
Definition: symbol.h:225
bool m_excludedFromBoard
Definition: symbol.h:226
bool GetDNP() const override
Set or clear the 'Do Not Populate' flag.
Definition: symbol.h:192
SYMBOL & operator=(const SYMBOL &aItem)
Definition: symbol.h:91
bool GetExcludedFromBOM() const override
Definition: symbol.h:181
int m_pinNameOffset
The offset in mils to draw the pin name.
Definition: symbol.h:219
bool GetExcludedFromSim() const override
Definition: symbol.h:175
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:46
#define DEFAULT_PIN_NAME_OFFSET
The intersheets references prefix string.
#define _HKI(x)
#define _(s)
RECURSE_MODE
Definition: eda_item.h:50
INSPECT_RESULT
Definition: eda_item.h:44
const INSPECTOR_FUNC & INSPECTOR
std::function passed to nested users by ref, avoids copying std::function.
Definition: eda_item.h:91
#define IGNORE_PARENT_GROUP
Definition: eda_item.h:55
#define IS_NEW
New item, just created.
#define STRUCT_DELETED
flag indication structures to be erased
TRANSFORM DefaultTransform
Definition: transform.cpp:32
@ LAYER_DEVICE
Definition: layer_ids.h:456
@ LAYER_FIELDS
Definition: layer_ids.h:452
#define REPORT(msg)
bool operator<(const LIB_SYMBOL &aItem1, const LIB_SYMBOL &aItem2)
Definition: lib_symbol.cpp:78
#define ITEM_DESC(item)
@ ENTRY_NORMAL
Definition: lib_symbol.h:61
@ ENTRY_LOCAL_POWER
Definition: lib_symbol.h:63
@ ENTRY_GLOBAL_POWER
Definition: lib_symbol.h:62
std::shared_ptr< LIB_SYMBOL > LIB_SYMBOL_SPTR
shared pointer to LIB_SYMBOL
Definition: lib_symbol.h:52
LIB_ITEMS_CONTAINER::ITEM_PTR_VECTOR LIB_ITEMS
Definition: lib_symbol.h:55
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:198
constexpr int MilsToIU(int mils) const
Definition: base_units.h:97
int m_bodyStyle
The alternate body style of the unit.
Definition: lib_symbol.h:73
std::vector< SCH_ITEM * > m_items
The items unique to this unit and alternate body style.
Definition: lib_symbol.h:74
int m_unit
The unit number.
Definition: lib_symbol.h:72
A structure for storing weighted search terms.
http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared
Definition: lib_symbol.cpp:86
void operator()(void const *) const
Definition: lib_symbol.cpp:87
Definition for symbol library class.
#define MANDATORY_FIELDS
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ LIB_SYMBOL_T
Definition: typeinfo.h:149
@ TYPE_NOT_INIT
Definition: typeinfo.h:81
@ SCH_FIELD_T
Definition: typeinfo.h:151
@ SCH_SHAPE_T
Definition: typeinfo.h:150
@ SCH_TEXT_T
Definition: typeinfo.h:152
@ SCH_PIN_T
Definition: typeinfo.h:154
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695