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