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