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 if( aItem )
799 {
800 aItem->SetParent( this );
801
802 m_drawings.push_back( aItem );
803
804 if( aSort )
806 }
807}
808
809
810std::vector<SCH_PIN*> LIB_SYMBOL::GetPins( int aUnit, int aBodyStyle ) const
811{
812 std::vector<SCH_PIN*> pins;
813
814 /* Notes:
815 * when aUnit == 0: no unit filtering
816 * when aBodyStyle == 0: no body style filtering
817 * when m_unit == 0, the item is common to all units
818 * when m_bodyStyle == 0, the item is common to all body styles
819 */
820
821 LIB_SYMBOL_SPTR parent = m_parent.lock();
822 const LIB_ITEMS_CONTAINER& drawItems = parent ? parent->m_drawings : m_drawings;
823
824 for( const SCH_ITEM& item : drawItems[SCH_PIN_T] )
825 {
826 // Unit filtering:
827 if( aUnit && item.m_unit && ( item.m_unit != aUnit ) )
828 continue;
829
830 // De Morgan variant filtering:
831 if( aBodyStyle && item.m_bodyStyle && ( item.m_bodyStyle != aBodyStyle ) )
832 continue;
833
834 // TODO: get rid of const_cast. (It used to be a C-style cast so was less noticeable.)
835 pins.push_back( const_cast<SCH_PIN*>( static_cast<const SCH_PIN*>( &item ) ) );
836 }
837
838 return pins;
839}
840
841
842std::vector<SCH_PIN*> LIB_SYMBOL::GetAllLibPins() const
843{
844 return GetPins( 0, 0 );
845}
846
847
849{
850 return (int) GetPins( 0 /* all units */, 1 /* single body style */ ).size();
851}
852
853
854SCH_PIN* LIB_SYMBOL::GetPin( const wxString& aNumber, int aUnit, int aBodyStyle ) const
855{
856 for( SCH_PIN* pin : GetPins( aUnit, aBodyStyle ) )
857 {
858 if( aNumber == pin->GetNumber() )
859 return pin;
860 }
861
862 return nullptr;
863}
864
865
866bool LIB_SYMBOL::PinsConflictWith( const LIB_SYMBOL& aOtherPart, bool aTestNums, bool aTestNames,
867 bool aTestType, bool aTestOrientation, bool aTestLength ) const
868{
869 std::vector<SCH_PIN*> thisPinList = GetAllLibPins();
870
871 for( const SCH_PIN* eachThisPin : thisPinList )
872 {
873 wxASSERT( eachThisPin );
874 std::vector<SCH_PIN*> otherPinList = aOtherPart.GetAllLibPins();
875 bool foundMatch = false;
876
877 for( const SCH_PIN* eachOtherPin : otherPinList )
878 {
879 wxASSERT( eachOtherPin );
880
881 // Same unit?
882 if( eachThisPin->GetUnit() != eachOtherPin->GetUnit() )
883 continue;
884
885 // Same body stype?
886 if( eachThisPin->GetBodyStyle() != eachOtherPin->GetBodyStyle() )
887 continue;
888
889 // Same position?
890 if( eachThisPin->GetPosition() != eachOtherPin->GetPosition() )
891 continue;
892
893 // Same number?
894 if( aTestNums && ( eachThisPin->GetNumber() != eachOtherPin->GetNumber() ) )
895 continue;
896
897 // Same name?
898 if( aTestNames && ( eachThisPin->GetName() != eachOtherPin->GetName() ) )
899 continue;
900
901 // Same electrical type?
902 if( aTestType && ( eachThisPin->GetType() != eachOtherPin->GetType() ) )
903 continue;
904
905 // Same orientation?
906 if( aTestOrientation
907 && ( eachThisPin->GetOrientation() != eachOtherPin->GetOrientation() ) )
908 continue;
909
910 // Same length?
911 if( aTestLength && ( eachThisPin->GetLength() != eachOtherPin->GetLength() ) )
912 continue;
913
914 foundMatch = true;
915 break; // Match found so search is complete.
916 }
917
918 if( !foundMatch )
919 {
920 // This means there was not an identical (according to the arguments)
921 // pin at the same position in the other symbol.
922 return true;
923 }
924 }
925
926 // The loop never gave up, so no conflicts were found.
927 return false;
928}
929
930
931const BOX2I LIB_SYMBOL::GetUnitBoundingBox( int aUnit, int aBodyStyle,
932 bool aIgnoreHiddenFields ) const
933{
934 BOX2I bBox; // Start with a fresh BOX2I so the Merge algorithm works
935
936 for( const SCH_ITEM& item : m_drawings )
937 {
938 if( item.m_unit > 0 && m_unitCount > 1 && aUnit > 0 && aUnit != item.m_unit )
939 continue;
940
941 if( item.m_bodyStyle > 0 && aBodyStyle > 0 && aBodyStyle != item.m_bodyStyle )
942 continue;
943
944 if( aIgnoreHiddenFields && item.Type() == SCH_FIELD_T )
945 {
946 if( !static_cast<const SCH_FIELD&>( item ).IsVisible() )
947 continue;
948 }
949
950 bBox.Merge( item.GetBoundingBox() );
951 }
952
953 return bBox;
954}
955
956
957const BOX2I LIB_SYMBOL::GetBodyBoundingBox( int aUnit, int aBodyStyle, bool aIncludePins,
958 bool aIncludePrivateItems ) const
959{
960 BOX2I bbox;
961
962 for( const SCH_ITEM& item : m_drawings )
963 {
964 if( item.m_unit > 0 && aUnit > 0 && aUnit != item.m_unit )
965 continue;
966
967 if( item.m_bodyStyle > 0 && aBodyStyle > 0 && aBodyStyle != item.m_bodyStyle )
968 continue;
969
970 if( item.IsPrivate() && !aIncludePrivateItems )
971 continue;
972
973 if( item.Type() == SCH_FIELD_T )
974 continue;
975
976 if( item.Type() == SCH_PIN_T )
977 {
978 const SCH_PIN& pin = static_cast<const SCH_PIN&>( item );
979
980 if( pin.IsVisible() )
981 {
982 // Note: the roots of the pins are always included for symbols that don't have
983 // a well-defined body.
984
985 if( aIncludePins )
986 bbox.Merge( pin.GetBoundingBox( false, false, false ) );
987 else
988 bbox.Merge( pin.GetPinRoot() );
989 }
990 }
991 else
992 {
993 bbox.Merge( item.GetBoundingBox() );
994 }
995 }
996
997 return bbox;
998}
999
1000
1002{
1004}
1005
1006
1008{
1009 AddDrawItem( aField );
1010}
1011
1012
1013void LIB_SYMBOL::SetFields( const std::vector<SCH_FIELD>& aFieldsList )
1014{
1016
1017 for( const SCH_FIELD& src : aFieldsList )
1018 {
1019 // drawings is a ptr_vector, new and copy an object on the heap.
1020 SCH_FIELD* field = new SCH_FIELD( src );
1021
1022 field->SetParent( this );
1023 m_drawings.push_back( field );
1024 }
1025
1026 m_drawings.sort();
1027}
1028
1029
1030void LIB_SYMBOL::GetFields( std::vector<SCH_FIELD*>& aList )
1031{
1032 // Grab the MANDATORY_FIELDS first, in expected order given by enum MANDATORY_FIELD_T
1033 for( int id = 0; id < MANDATORY_FIELDS; ++id )
1034 aList.push_back( GetFieldById( id ) );
1035
1036 // Now grab all the rest of fields.
1037 for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1038 {
1039 SCH_FIELD* field = static_cast<SCH_FIELD*>( &item );
1040
1041 if( !field->IsMandatory() )
1042 aList.push_back( field );
1043 }
1044}
1045
1046
1047void LIB_SYMBOL::GetFields( std::vector<SCH_FIELD>& aList )
1048{
1049 // Grab the MANDATORY_FIELDS first, in expected order given by enum MANDATORY_FIELD_T
1050 for( int id = 0; id < MANDATORY_FIELDS; ++id )
1051 aList.push_back( *GetFieldById( id ) );
1052
1053 // Now grab all the rest of fields.
1054 for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1055 {
1056 SCH_FIELD* field = static_cast<SCH_FIELD*>( &item );
1057
1058 if( !field->IsMandatory() )
1059 aList.push_back( *field );
1060 }
1061}
1062
1063
1065{
1066 for( const SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1067 {
1068 SCH_FIELD* field = ( SCH_FIELD* ) &item;
1069
1070 if( field->GetId() == aId )
1071 return field;
1072 }
1073
1074 return nullptr;
1075}
1076
1077
1078SCH_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName, bool aCaseInsensitive )
1079{
1080 for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1081 {
1082 if( aCaseInsensitive )
1083 {
1084 if( static_cast<SCH_FIELD*>( &item )->GetCanonicalName().Upper() == aFieldName.Upper() )
1085 return static_cast<SCH_FIELD*>( &item );
1086 }
1087 else
1088 {
1089 if( static_cast<SCH_FIELD*>( &item )->GetCanonicalName() == aFieldName )
1090 return static_cast<SCH_FIELD*>( &item );
1091 }
1092 }
1093
1094 return nullptr;
1095}
1096
1097
1098const SCH_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName,
1099 bool aCaseInsensitive ) const
1100{
1101 for( const SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1102 {
1103 const SCH_FIELD& field = static_cast<const SCH_FIELD&>( item );
1104
1105 if( aCaseInsensitive )
1106 {
1107 if( field.GetCanonicalName().Upper() == aFieldName.Upper() )
1108 return &field;
1109 }
1110 else
1111 {
1112 if( field.GetCanonicalName() == aFieldName )
1113 return &field;
1114 }
1115 }
1116
1117 return nullptr;
1118}
1119
1120
1122{
1124 wxASSERT( field != nullptr );
1125 return *field;
1126}
1127
1128
1130{
1132 wxASSERT( field != nullptr );
1133 return *field;
1134}
1135
1136
1138{
1140 wxASSERT( field != nullptr );
1141 return *field;
1142}
1143
1144
1146{
1148 wxASSERT( field != nullptr );
1149 return *field;
1150}
1151
1152
1154{
1156 wxASSERT( field != nullptr );
1157 return *field;
1158}
1159
1160
1162{
1163 wxString refDesignator = GetFieldById( REFERENCE_FIELD )->GetText();
1164
1165 refDesignator.Replace( wxS( "~" ), wxS( " " ) );
1166
1167 wxString prefix = refDesignator;
1168
1169 while( prefix.Length() )
1170 {
1171 wxUniCharRef last = prefix.Last();
1172
1173 if( ( last >= '0' && last <= '9' ) || last == '?' || last == '*' )
1174 prefix.RemoveLast();
1175 else
1176 break;
1177 }
1178
1179 // Avoid a prefix containing trailing/leading spaces
1180 prefix.Trim( true );
1181 prefix.Trim( false );
1182
1183 return prefix;
1184}
1185
1186
1187void LIB_SYMBOL::RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction )
1188{
1189 for( SCH_ITEM& item : m_drawings )
1190 aFunction( &item );
1191}
1192
1193
1195{
1196 int retv = 0;
1197 int lastOrdinal = MANDATORY_FIELDS;
1198
1199 for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1200 {
1201 SCH_FIELD* field = static_cast<SCH_FIELD*>( &item );
1202
1203 // Mandatory fields were already resolved always have the same ordinal values.
1204 if( field->IsMandatory() )
1205 continue;
1206
1207 if( field->GetId() != lastOrdinal )
1208 {
1209 field->SetId( lastOrdinal );
1210 retv += 1;
1211 }
1212
1213 lastOrdinal += 1;
1214 }
1215
1216 return retv;
1217}
1218
1219
1221{
1222 int retv = MANDATORY_FIELDS;
1223
1224 while( GetFieldById( retv ) )
1225 retv += 1;
1226
1227 return retv;
1228}
1229
1230
1231void LIB_SYMBOL::Move( const VECTOR2I& aOffset )
1232{
1233 for( SCH_ITEM& item : m_drawings )
1234 item.Move( aOffset );
1235}
1236
1237
1239{
1240 for( const SCH_ITEM& item : m_drawings )
1241 {
1242 if( item.m_bodyStyle > BODY_STYLE::BASE )
1243 return true;
1244 }
1245
1246 if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
1247 {
1248 for( const SCH_ITEM& item : parent->GetDrawItems() )
1249 {
1250 if( item.m_bodyStyle > BODY_STYLE::BASE )
1251 return true;
1252 }
1253 }
1254
1255 return false;
1256}
1257
1258
1260{
1261 int maxPinNumber = 0;
1262 LIB_SYMBOL_SPTR parent = m_parent.lock();
1263 const LIB_ITEMS_CONTAINER& drawItems = parent ? parent->m_drawings : m_drawings;
1264
1265 for( const SCH_ITEM& item : drawItems[SCH_PIN_T] )
1266 {
1267 const SCH_PIN* pin = static_cast<const SCH_PIN*>( &item );
1268 long currentPinNumber = 0;
1269
1270 if( pin->GetNumber().ToLong( &currentPinNumber ) )
1271 maxPinNumber = std::max( maxPinNumber, (int) currentPinNumber );
1272 }
1273
1274 return maxPinNumber;
1275}
1276
1277
1279{
1281
1282 for( SCH_ITEM& item : m_drawings )
1283 item.ClearTempFlags();
1284}
1285
1286
1288{
1290
1291 for( SCH_ITEM& item : m_drawings )
1292 item.ClearEditFlags();
1293}
1294
1295
1296SCH_ITEM* LIB_SYMBOL::LocateDrawItem( int aUnit, int aBodyStyle, KICAD_T aType,
1297 const VECTOR2I& aPoint )
1298{
1299 for( SCH_ITEM& item : m_drawings )
1300 {
1301 if( ( aUnit && item.m_unit && aUnit != item.m_unit )
1302 || ( aBodyStyle && item.m_bodyStyle && aBodyStyle != item.m_bodyStyle )
1303 || ( item.Type() != aType && aType != TYPE_NOT_INIT ) )
1304 {
1305 continue;
1306 }
1307
1308 if( item.HitTest( aPoint ) )
1309 return &item;
1310 }
1311
1312 return nullptr;
1313}
1314
1315
1316SCH_ITEM* LIB_SYMBOL::LocateDrawItem( int aUnit, int aBodyStyle, KICAD_T aType,
1317 const VECTOR2I& aPoint, const TRANSFORM& aTransform )
1318{
1319 /* we use LocateDrawItem( int aUnit, int convert, KICAD_T type, const
1320 * VECTOR2I& pt ) to search items.
1321 * because this function uses DefaultTransform as orient/mirror matrix
1322 * we temporary copy aTransform in DefaultTransform
1323 */
1324 TRANSFORM transform = DefaultTransform;
1325 DefaultTransform = aTransform;
1326
1327 SCH_ITEM* item = LocateDrawItem( aUnit, aBodyStyle, aType, aPoint );
1328
1329 // Restore matrix
1330 DefaultTransform = transform;
1331
1332 return item;
1333}
1334
1335
1336INSPECT_RESULT LIB_SYMBOL::Visit( INSPECTOR aInspector, void* aTestData,
1337 const std::vector<KICAD_T>& aScanTypes )
1338{
1339 // The part itself is never inspected, only its children
1340 for( SCH_ITEM& item : m_drawings )
1341 {
1342 if( item.IsType( aScanTypes ) )
1343 {
1344 if( aInspector( &item, aTestData ) == INSPECT_RESULT::QUIT )
1345 return INSPECT_RESULT::QUIT;
1346 }
1347 }
1348
1349 return INSPECT_RESULT::CONTINUE;
1350}
1351
1352
1353void LIB_SYMBOL::SetUnitCount( int aCount, bool aDuplicateDrawItems )
1354{
1355 if( m_unitCount == aCount )
1356 return;
1357
1358 if( aCount < m_unitCount )
1359 {
1361
1362 while( i != m_drawings.end() )
1363 {
1364 if( i->m_unit > aCount )
1365 i = m_drawings.erase( i );
1366 else
1367 ++i;
1368 }
1369 }
1370 else if( aDuplicateDrawItems )
1371 {
1372 int prevCount = m_unitCount;
1373
1374 // Temporary storage for new items, as adding new items directly to
1375 // m_drawings may cause the buffer reallocation which invalidates the
1376 // iterators
1377 std::vector<SCH_ITEM*> tmp;
1378
1379 for( SCH_ITEM& item : m_drawings )
1380 {
1381 if( item.m_unit != 1 )
1382 continue;
1383
1384 for( int j = prevCount + 1; j <= aCount; j++ )
1385 {
1386 SCH_ITEM* newItem = item.Duplicate();
1387 newItem->m_unit = j;
1388 tmp.push_back( newItem );
1389 }
1390 }
1391
1392 for( SCH_ITEM* item : tmp )
1393 m_drawings.push_back( item );
1394 }
1395
1396 m_drawings.sort();
1397 m_unitCount = aCount;
1398}
1399
1400
1402{
1403 if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
1404 return parent->GetUnitCount();
1405
1406 return m_unitCount;
1407}
1408
1409
1410void LIB_SYMBOL::SetHasAlternateBodyStyle( bool aHasAlternate, bool aDuplicatePins )
1411{
1412 if( aHasAlternate == HasAlternateBodyStyle() )
1413 return;
1414
1415 // Duplicate items to create the converted shape
1416 if( aHasAlternate )
1417 {
1418 if( aDuplicatePins )
1419 {
1420 std::vector<SCH_ITEM*> tmp; // Temporarily store the duplicated pins here.
1421
1422 for( SCH_ITEM& item : m_drawings[ SCH_PIN_T ] )
1423 {
1424 if( item.m_bodyStyle == 1 )
1425 {
1426 SCH_ITEM* newItem = item.Duplicate();
1427 newItem->m_bodyStyle = 2;
1428 tmp.push_back( newItem );
1429 }
1430 }
1431
1432 // Transfer the new pins to the LIB_SYMBOL.
1433 for( SCH_ITEM* item : tmp )
1434 m_drawings.push_back( item );
1435 }
1436 }
1437 else
1438 {
1439 // Delete converted shape items because the converted shape does not exist
1441
1442 while( i != m_drawings.end() )
1443 {
1444 if( i->m_bodyStyle > 1 )
1445 i = m_drawings.erase( i );
1446 else
1447 ++i;
1448 }
1449 }
1450
1451 m_drawings.sort();
1452}
1453
1454
1455std::vector<SCH_ITEM*> LIB_SYMBOL::GetUnitDrawItems( int aUnit, int aBodyStyle )
1456{
1457 std::vector<SCH_ITEM*> unitItems;
1458
1459 for( SCH_ITEM& item : m_drawings )
1460 {
1461 if( item.Type() == SCH_FIELD_T )
1462 continue;
1463
1464 if( ( aBodyStyle == -1 && item.GetUnit() == aUnit )
1465 || ( aUnit == -1 && item.GetBodyStyle() == aBodyStyle )
1466 || ( aUnit == item.GetUnit() && aBodyStyle == item.GetBodyStyle() ) )
1467 {
1468 unitItems.push_back( &item );
1469 }
1470 }
1471
1472 return unitItems;
1473}
1474
1475
1476std::vector<LIB_SYMBOL_UNIT> LIB_SYMBOL::GetUnitDrawItems()
1477{
1478 std::vector<LIB_SYMBOL_UNIT> units;
1479
1480 for( SCH_ITEM& item : m_drawings )
1481 {
1482 if( item.Type() == SCH_FIELD_T )
1483 continue;
1484
1485 int unit = item.GetUnit();
1486 int bodyStyle = item.GetBodyStyle();
1487
1488 auto it = std::find_if( units.begin(), units.end(),
1489 [unit, bodyStyle]( const LIB_SYMBOL_UNIT& a )
1490 {
1491 return a.m_unit == unit && a.m_bodyStyle == bodyStyle;
1492 } );
1493
1494 if( it == units.end() )
1495 {
1496 LIB_SYMBOL_UNIT newUnit;
1497 newUnit.m_unit = item.GetUnit();
1498 newUnit.m_bodyStyle = item.GetBodyStyle();
1499 newUnit.m_items.push_back( &item );
1500 units.emplace_back( newUnit );
1501 }
1502 else
1503 {
1504 it->m_items.push_back( &item );
1505 }
1506 }
1507
1508 return units;
1509}
1510
1511
1512
1513
1514#define REPORT( msg ) { if( aReporter ) aReporter->Report( msg ); }
1515#define ITEM_DESC( item ) ( item )->GetItemDescription( &unitsProvider, true )
1516
1517int LIB_SYMBOL::Compare( const LIB_SYMBOL& aRhs, int aCompareFlags, REPORTER* aReporter ) const
1518{
1519 UNITS_PROVIDER unitsProvider( schIUScale, EDA_UNITS::MILLIMETRES );
1520
1521 if( m_me == aRhs.m_me )
1522 return 0;
1523
1524 if( !aReporter && ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) == 0 )
1525 {
1526 if( int tmp = m_name.Cmp( aRhs.m_name ) )
1527 return tmp;
1528
1529 if( int tmp = m_libId.compare( aRhs.m_libId ) )
1530 return tmp;
1531
1532 if( m_parent.lock() < aRhs.m_parent.lock() )
1533 return -1;
1534
1535 if( m_parent.lock() > aRhs.m_parent.lock() )
1536 return 1;
1537 }
1538
1539 int retv = 0;
1540
1541 if( m_options != aRhs.m_options )
1542 {
1543 retv = ( m_options == ENTRY_NORMAL ) ? -1 : 1;
1544 REPORT( _( "Power flag differs." ) );
1545
1546 if( !aReporter )
1547 return retv;
1548 }
1549
1550 if( int tmp = m_unitCount - aRhs.m_unitCount )
1551 {
1552 retv = tmp;
1553 REPORT( _( "Unit count differs." ) );
1554
1555 if( !aReporter )
1556 return retv;
1557 }
1558
1559 // Make sure shapes and pins are sorted. No need with fields as those are
1560 // matched by id/name.
1561
1562 std::set<const SCH_ITEM*, SCH_ITEM::cmp_items> aShapes;
1563 std::set<const SCH_ITEM*> aFields;
1564 std::set<const SCH_ITEM*, SCH_ITEM::cmp_items> aPins;
1565
1566 for( auto it = m_drawings.begin(); it != m_drawings.end(); ++it )
1567 {
1568 if( it->Type() == SCH_SHAPE_T )
1569 aShapes.insert( &(*it) );
1570 else if( it->Type() == SCH_FIELD_T )
1571 aFields.insert( &(*it) );
1572 else if( it->Type() == SCH_PIN_T )
1573 aPins.insert( &(*it) );
1574 }
1575
1576 std::set<const SCH_ITEM*, SCH_ITEM::cmp_items> bShapes;
1577 std::set<const SCH_ITEM*> bFields;
1578 std::set<const SCH_ITEM*, SCH_ITEM::cmp_items> bPins;
1579
1580 for( auto it = aRhs.m_drawings.begin(); it != aRhs.m_drawings.end(); ++it )
1581 {
1582 if( it->Type() == SCH_SHAPE_T )
1583 bShapes.insert( &(*it) );
1584 else if( it->Type() == SCH_FIELD_T )
1585 bFields.insert( &(*it) );
1586 else if( it->Type() == SCH_PIN_T )
1587 bPins.insert( &(*it) );
1588 }
1589
1590 if( int tmp = static_cast<int>( aShapes.size() - bShapes.size() ) )
1591 {
1592 retv = tmp;
1593 REPORT( _( "Graphic item count differs." ) );
1594
1595 if( !aReporter )
1596 return retv;
1597 }
1598 else
1599 {
1600 for( auto aIt = aShapes.begin(), bIt = bShapes.begin(); aIt != aShapes.end(); aIt++, bIt++ )
1601 {
1602 if( int tmp2 = (*aIt)->compare( *(*bIt), aCompareFlags ) )
1603 {
1604 retv = tmp2;
1605 REPORT( wxString::Format( _( "%s differs." ), ITEM_DESC( *aIt ) ) );
1606
1607 if( !aReporter )
1608 return retv;
1609 }
1610 }
1611 }
1612
1613 if( int tmp = static_cast<int>( aPins.size() - bPins.size() ) )
1614 {
1615 retv = tmp;
1616 REPORT( _( "Pin count differs." ) );
1617
1618 if( !aReporter )
1619 return retv;
1620 }
1621 else
1622 {
1623 for( const SCH_ITEM* aPinItem : aPins )
1624 {
1625 const SCH_PIN* aPin = static_cast<const SCH_PIN*>( aPinItem );
1626 const SCH_PIN* bPin = aRhs.GetPin( aPin->GetNumber(), aPin->GetUnit(),
1627 aPin->GetBodyStyle() );
1628
1629 if( !bPin )
1630 {
1631 retv = 1;
1632 REPORT( wxString::Format( _( "Pin %s not found." ), aPin->GetNumber() ) );
1633
1634 if( !aReporter )
1635 return retv;
1636 }
1637 else if( int tmp2 = aPinItem->compare( *bPin, aCompareFlags ) )
1638 {
1639 retv = tmp2;
1640 REPORT( wxString::Format( _( "Pin %s differs." ), aPin->GetNumber() ) );
1641
1642 if( !aReporter )
1643 return retv;
1644 }
1645 }
1646 }
1647
1648 for( const SCH_ITEM* aFieldItem : aFields )
1649 {
1650 const SCH_FIELD* aField = static_cast<const SCH_FIELD*>( aFieldItem );
1651 const SCH_FIELD* bField = nullptr;
1652 int tmp = 0;
1653
1654 if( aField->IsMandatory() )
1655 bField = aRhs.GetFieldById( aField->GetId() );
1656 else
1657 bField = aRhs.FindField( aField->GetName() );
1658
1659 if( !bField )
1660 tmp = 1;
1661 else
1662 tmp = aFieldItem->compare( *bField, aCompareFlags );
1663
1664 if( tmp )
1665 {
1666 retv = tmp;
1667 REPORT( wxString::Format( _( "%s field differs." ), aField->GetName( false ) ) );
1668
1669 if( !aReporter )
1670 return retv;
1671 }
1672 }
1673
1674 if( int tmp = static_cast<int>( aFields.size() - bFields.size() ) )
1675 {
1676 retv = tmp;
1677 REPORT( _( "Field count differs." ) );
1678
1679 if( !aReporter )
1680 return retv;
1681 }
1682
1683 if( int tmp = static_cast<int>( m_fpFilters.GetCount() - aRhs.m_fpFilters.GetCount() ) )
1684 {
1685 retv = tmp;
1686 REPORT( _( "Footprint filters differs." ) );
1687
1688 if( !aReporter )
1689 return retv;
1690 }
1691 else
1692 {
1693 for( size_t i = 0; i < m_fpFilters.GetCount(); i++ )
1694 {
1695 if( int tmp2 = m_fpFilters[i].Cmp( aRhs.m_fpFilters[i] ) )
1696 {
1697 retv = tmp2;
1698 REPORT( _( "Footprint filters differ." ) );
1699
1700 if( !aReporter )
1701 return retv;
1702 }
1703 }
1704 }
1705
1706 if( int tmp = m_keyWords.Cmp( aRhs.m_keyWords ) )
1707 {
1708 retv = tmp;
1709 REPORT( _( "Symbol keywords differ." ) );
1710
1711 if( !aReporter )
1712 return retv;
1713 }
1714
1715 if( int tmp = m_pinNameOffset - aRhs.m_pinNameOffset )
1716 {
1717 retv = tmp;
1718 REPORT( _( "Symbol pin name offsets differ." ) );
1719
1720 if( !aReporter )
1721 return retv;
1722 }
1723
1724 if( ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) == 0 )
1725 {
1726 if( m_showPinNames != aRhs.m_showPinNames )
1727 {
1728 retv = ( m_showPinNames ) ? 1 : -1;
1729 REPORT( _( "Show pin names settings differ." ) );
1730
1731 if( !aReporter )
1732 return retv;
1733 }
1734
1736 {
1737 retv = ( m_showPinNumbers ) ? 1 : -1;
1738 REPORT( _( "Show pin numbers settings differ." ) );
1739
1740 if( !aReporter )
1741 return retv;
1742 }
1743
1745 {
1746 retv = ( m_excludedFromSim ) ? -1 : 1;
1747 REPORT( _( "Exclude from simulation settings differ." ) );
1748
1749 if( !aReporter )
1750 return retv;
1751 }
1752
1754 {
1755 retv = ( m_excludedFromBOM ) ? -1 : 1;
1756 REPORT( _( "Exclude from bill of materials settings differ." ) );
1757
1758 if( !aReporter )
1759 return retv;
1760 }
1761
1763 {
1764 retv = ( m_excludedFromBoard ) ? -1 : 1;
1765 REPORT( _( "Exclude from board settings differ." ) );
1766
1767 if( !aReporter )
1768 return retv;
1769 }
1770 }
1771
1772 if( !aReporter )
1773 {
1774 if( m_unitsLocked != aRhs.m_unitsLocked )
1775 return ( m_unitsLocked ) ? 1 : -1;
1776
1777 // Compare unit display names
1779 return -1;
1780 else if( m_unitDisplayNames > aRhs.m_unitDisplayNames )
1781 return 1;
1782 }
1783
1784 return retv;
1785}
1786
1787
1788int LIB_SYMBOL::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
1789{
1790 if( Type() != aOther.Type() )
1791 return Type() - aOther.Type();
1792
1793 const LIB_SYMBOL* tmp = static_cast<const LIB_SYMBOL*>( &aOther );
1794
1795 return Compare( *tmp, aCompareFlags );
1796}
1797
1798
1799double LIB_SYMBOL::Similarity( const SCH_ITEM& aOther ) const
1800{
1801 wxCHECK( aOther.Type() == LIB_SYMBOL_T, 0.0 );
1802
1803 const LIB_SYMBOL& other = static_cast<const LIB_SYMBOL&>( aOther );
1804 double similarity = 0.0;
1805 int totalItems = 0;
1806
1807 if( m_Uuid == aOther.m_Uuid )
1808 return 1.0;
1809
1810 for( const SCH_ITEM& item : m_drawings )
1811 {
1812 totalItems += 1;
1813 double max_similarity = 0.0;
1814
1815 for( const SCH_ITEM& otherItem : other.m_drawings )
1816 {
1817 double temp_similarity = item.Similarity( otherItem );
1818 max_similarity = std::max( max_similarity, temp_similarity );
1819
1820 if( max_similarity == 1.0 )
1821 break;
1822 }
1823
1824 similarity += max_similarity;
1825 }
1826
1827 for( const SCH_PIN* pin : GetAllLibPins() )
1828 {
1829 totalItems += 1;
1830 double max_similarity = 0.0;
1831
1832 for( const SCH_PIN* otherPin : other.GetAllLibPins() )
1833 {
1834 double temp_similarity = pin->Similarity( *otherPin );
1835 max_similarity = std::max( max_similarity, temp_similarity );
1836
1837 if( max_similarity == 1.0 )
1838 break;
1839 }
1840
1841 similarity += max_similarity;
1842 }
1843
1844 if( totalItems == 0 )
1845 similarity = 0.0;
1846 else
1847 similarity /= totalItems;
1848
1850 similarity *= 0.9;
1851
1853 similarity *= 0.9;
1854
1856 similarity *= 0.9;
1857
1858 if( m_flags != other.m_flags )
1859 similarity *= 0.9;
1860
1861 if( m_unitCount != other.m_unitCount )
1862 similarity *= 0.5;
1863
1864 if( m_pinNameOffset != other.m_pinNameOffset )
1865 similarity *= 0.9;
1866
1867 if( m_showPinNames != other.m_showPinNames )
1868 similarity *= 0.9;
1869
1870 if( m_showPinNumbers != other.m_showPinNumbers )
1871 similarity *= 0.9;
1872
1873 return similarity;
1874}
1875
1876
1878{
1879 return static_cast<EMBEDDED_FILES*>( this );
1880}
1881
1882
1884{
1885 return static_cast<const EMBEDDED_FILES*>( this );
1886}
1887
1888
1890{
1891 using OUTLINE_FONT = KIFONT::OUTLINE_FONT;
1892 using EMBEDDING_PERMISSION = OUTLINE_FONT::EMBEDDING_PERMISSION;
1893
1894 std::set<OUTLINE_FONT*> fonts;
1895
1896 for( SCH_ITEM& item : m_drawings )
1897 {
1898 if( item.Type() == SCH_TEXT_T )
1899 {
1900 auto* text = static_cast<SCH_TEXT*>( &item );
1901
1902 if( auto* font = text->GetFont(); font && !font->IsStroke() )
1903 {
1904 auto* outline = static_cast<OUTLINE_FONT*>( font );
1905 auto permission = outline->GetEmbeddingPermission();
1906
1907 if( permission == EMBEDDING_PERMISSION::EDITABLE
1908 || permission == EMBEDDING_PERMISSION::INSTALLABLE )
1909 {
1910 fonts.insert( outline );
1911 }
1912 }
1913 }
1914 }
1915
1916 for( auto* font : fonts )
1917 {
1918 auto file = GetEmbeddedFiles()->AddFile( font->GetFileName(), false );
1920 }
1921}
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
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: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:85
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:170
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:275
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:866
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:810
const BOX2I GetUnitBoundingBox(int aUnit, int aBodyStyle, bool aIgnoreHiddenFields=true) const
Get the bounding box for the symbol.
Definition: lib_symbol.cpp:931
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:854
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:842
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:957
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:848
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:72
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:1619
bool IsMandatory() const
Definition: sch_field.cpp:1507
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: sch_field.cpp:335
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:427
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:1252
int GetId() const
Definition: sch_field.h:133
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: sch_field.cpp:1227
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Definition: sch_field.cpp:209
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:1212
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:117
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