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