KiCad PCB EDA Suite
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) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <sch_draw_panel.h>
27#include <plotters/plotter.h>
28#include <sch_screen.h>
29#include <richio.h>
30#include <general.h>
31#include <template_fieldnames.h>
32#include <transform.h>
33#include <symbol_library.h>
34#include <lib_pin.h>
36#include <lib_shape.h>
37
38// the separator char between the subpart id and the reference
39// 0 (no separator) or '.' or some other character
41
42// the ascii char value to calculate the subpart symbol id from the part number:
43// 'A' or '1' usually. (to print U1.A or U1.1)
44// if this a digit, a number is used as id symbol
46
47
49{
50 // Matches are scored by offset from front of string, so inclusion of this spacer
51 // discounts matches found after it.
52 static const wxString discount( wxT( " " ) );
53
54 wxString text = GetKeyWords() + discount + GetDescription();
55 wxString footprint = GetFootprintField().GetText();
56
57 if( !footprint.IsEmpty() )
58 {
59 text += discount + footprint;
60 }
61
62 // TODO(JE) rework this later so we can highlight matches in their column
63 std::map<wxString, wxString> fields;
64 GetChooserFields( fields );
65
66 for( const auto& it : fields )
67 text += discount + it.second;
68
69 return text;
70}
71
72
73void LIB_SYMBOL::GetChooserFields( std::map<wxString , wxString>& aColumnMap )
74{
75 for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
76 {
77 LIB_FIELD* field = static_cast<LIB_FIELD*>( &item );
78
79 if( field->ShowInChooser() )
80 aColumnMap[field->GetName()] = field->EDA_TEXT::GetShownText();
81 }
82}
83
84
85bool operator<( const LIB_SYMBOL& aItem1, const LIB_SYMBOL& aItem2 )
86{
87 return aItem1.GetName() < aItem2.GetName();
88}
89
90
93{
94 void operator()(void const *) const
95 {
96 }
97};
98
99
100LIB_SYMBOL::LIB_SYMBOL( const wxString& aName, LIB_SYMBOL* aParent, SYMBOL_LIB* aLibrary ) :
102 m_me( this, null_deleter() ),
103 m_includeInBom( true ),
104 m_includeOnBoard( true )
105{
106 m_lastModDate = 0;
107 m_unitCount = 1;
110 m_unitsLocked = false;
111 m_showPinNumbers = true;
112 m_showPinNames = true;
113
114 // Add the MANDATORY_FIELDS in RAM only. These are assumed to be present
115 // when the field editors are invoked.
116 m_drawings[LIB_FIELD_T].reserve( 4 );
121
122 SetName( aName );
123
124 if( aParent )
125 SetParent( aParent );
126
127 SetLib( aLibrary );
128}
129
130
131LIB_SYMBOL::LIB_SYMBOL( const LIB_SYMBOL& aSymbol, SYMBOL_LIB* aLibrary ) :
132 EDA_ITEM( aSymbol ),
133 m_me( this, null_deleter() )
134{
135 LIB_ITEM* newItem;
136
137 m_library = aLibrary;
138 m_name = aSymbol.m_name;
139 m_fpFilters = wxArrayString( aSymbol.m_fpFilters );
140 m_unitCount = aSymbol.m_unitCount;
148 m_options = aSymbol.m_options;
149 m_libId = aSymbol.m_libId;
151 m_keyWords = aSymbol.m_keyWords;
152
154
156
157 for( const LIB_ITEM& oldItem : aSymbol.m_drawings )
158 {
159 if( ( oldItem.GetFlags() & ( IS_NEW | STRUCT_DELETED ) ) != 0 )
160 continue;
161
162 try
163 {
164 newItem = (LIB_ITEM*) oldItem.Clone();
165 newItem->ClearSelected();
166 newItem->SetParent( this );
167 m_drawings.push_back( newItem );
168 }
169 catch( ... )
170 {
171 wxFAIL_MSG( "Failed to clone LIB_ITEM." );
172 return;
173 }
174 }
175
176 LIB_SYMBOL_SPTR parent = aSymbol.m_parent.lock();
177
178 if( parent )
179 SetParent( parent.get() );
180}
181
182
184{
185}
186
187
189{
190 if( &aSymbol == this )
191 return aSymbol;
192
193 LIB_ITEM* newItem;
194
195 m_library = aSymbol.m_library;
196 m_name = aSymbol.m_name;
197 m_fpFilters = wxArrayString( aSymbol.m_fpFilters );
198 m_unitCount = aSymbol.m_unitCount;
206 m_options = aSymbol.m_options;
207 m_libId = aSymbol.m_libId;
209 m_keyWords = aSymbol.m_keyWords;
210
211 m_unitDisplayNames.clear();
213
215
216 for( const LIB_ITEM& oldItem : aSymbol.m_drawings )
217 {
218 if( ( oldItem.GetFlags() & ( IS_NEW | STRUCT_DELETED ) ) != 0 )
219 continue;
220
221 newItem = (LIB_ITEM*) oldItem.Clone();
222 newItem->SetParent( this );
223 m_drawings.push_back( newItem );
224 }
225
227
228 LIB_SYMBOL_SPTR parent = aSymbol.m_parent.lock();
229
230 if( parent )
231 SetParent( parent.get() );
232
233 return *this;
234}
235
236
237int LIB_SYMBOL::Compare( const LIB_SYMBOL& aRhs, int aCompareFlags ) const
238{
239 if( m_me == aRhs.m_me )
240 return 0;
241
242 int retv = 0;
243
244 if( ( aCompareFlags & LIB_ITEM::COMPARE_FLAGS::ERC ) == 0 )
245 {
246 retv = m_name.Cmp( aRhs.m_name );
247
248 if( retv )
249 return retv;
250
251 retv = m_libId.compare( aRhs.m_libId );
252
253 if( retv )
254 return retv;
255 }
256
257 if( m_parent.lock() < aRhs.m_parent.lock() )
258 return -1;
259
260 if( m_parent.lock() > aRhs.m_parent.lock() )
261 return 1;
262
263 if( m_options != aRhs.m_options )
264 return ( m_options == ENTRY_NORMAL ) ? -1 : 1;
265
266 if( m_unitCount != aRhs.m_unitCount )
267 return m_unitCount - aRhs.m_unitCount;
268
269 if( m_drawings.size() != aRhs.m_drawings.size() )
270 return m_drawings.size() - aRhs.m_drawings.size();
271
274
275 while( lhsItemIt != m_drawings.end() )
276 {
277 const LIB_ITEM* lhsItem = static_cast<const LIB_ITEM*>( &(*lhsItemIt) );
278 const LIB_ITEM* rhsItem = static_cast<const LIB_ITEM*>( &(*rhsItemIt) );
279
280 wxCHECK( lhsItem && rhsItem, lhsItem - rhsItem );
281
282 if( lhsItem->Type() != rhsItem->Type() )
283 return lhsItem->Type() - rhsItem->Type();
284
285 // Non-mandatory fields are a special case. They can have different ordinal numbers
286 // and are compared separately below.
287 if( lhsItem->Type() == LIB_FIELD_T )
288 {
289 const LIB_FIELD* lhsField = static_cast<const LIB_FIELD*>( lhsItem );
290
291 if( lhsField->GetId() == VALUE_FIELD )
292 {
293 if( ( aCompareFlags & LIB_ITEM::COMPARE_FLAGS::ERC ) == 0 || IsPower() )
294 retv = lhsItem->compare( *rhsItem, aCompareFlags );
295 }
296 else if( lhsField->IsMandatory() )
297 {
298 retv = lhsItem->compare( *rhsItem, aCompareFlags );
299 }
300 }
301 else
302 {
303 retv = lhsItem->compare( *rhsItem, aCompareFlags );
304 }
305
306 if( retv )
307 return retv;
308
309 ++lhsItemIt;
310 ++rhsItemIt;
311 }
312
313 // Compare the optional fields.
314 for( const LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
315 {
316 const LIB_FIELD* field = dynamic_cast<const LIB_FIELD*>( &item );
317
318 wxCHECK2( field, continue );
319
320 // Mandatory fields were already compared above.
321 if( field->IsMandatory() )
322 continue;
323
324 const LIB_FIELD* foundField = aRhs.FindField( field->GetName() );
325
326 if( foundField == nullptr )
327 return 1;
328
329 retv = item.compare( static_cast<const LIB_ITEM&>( *foundField ), aCompareFlags );
330
331 if( retv )
332 return retv;
333 }
334
335 if( m_fpFilters.GetCount() != aRhs.m_fpFilters.GetCount() )
336 return m_fpFilters.GetCount() - aRhs.m_fpFilters.GetCount();
337
338 for( size_t i = 0; i < m_fpFilters.GetCount(); i++ )
339 {
340 retv = m_fpFilters[i].Cmp( aRhs.m_fpFilters[i] );
341
342 if( retv )
343 return retv;
344 }
345
346 retv = m_description.Cmp( aRhs.m_description );
347
348 if( retv )
349 return retv;
350
351 retv = m_keyWords.Cmp( aRhs.m_keyWords );
352
353 if( retv )
354 return retv;
355
356 if( m_pinNameOffset != aRhs.m_pinNameOffset )
357 return m_pinNameOffset - aRhs.m_pinNameOffset;
358
359 if( m_unitsLocked != aRhs.m_unitsLocked )
360 return ( m_unitsLocked ) ? 1 : -1;
361
362 if( ( aCompareFlags & LIB_ITEM::COMPARE_FLAGS::ERC ) == 0 )
363 {
364 if( m_showPinNames != aRhs.m_showPinNames )
365 return ( m_showPinNames ) ? 1 : -1;
366
368 return ( m_showPinNumbers ) ? 1 : -1;
369
370 if( m_includeInBom != aRhs.m_includeInBom )
371 return ( m_includeInBom ) ? 1 : -1;
372
374 return ( m_includeOnBoard ) ? 1 : -1;
375 }
376
377 // Compare unit display names
379 {
380 return -1;
381 }
382 else if( m_unitDisplayNames > aRhs.m_unitDisplayNames )
383 {
384 return 1;
385 }
386
387 return 0;
388}
389
390
391wxString LIB_SYMBOL::GetUnitReference( int aUnit )
392{
393 return LIB_SYMBOL::SubReference( aUnit, false );
394}
395
396
398{
399 return ( m_unitDisplayNames.count( aUnit ) == 1 );
400}
401
402
404{
405 if( HasUnitDisplayName( aUnit ) )
406 {
407 return m_unitDisplayNames[aUnit];
408 }
409 else
410 {
411 return wxString::Format( _( "Unit %s" ), GetUnitReference( aUnit ) );
412 }
413}
414
415
416void LIB_SYMBOL::CopyUnitDisplayNames( std::map<int, wxString>& aTarget ) const
417{
418 for( const auto& it : m_unitDisplayNames )
419 {
420 aTarget[it.first] = it.second;
421 }
422}
423
424
425void LIB_SYMBOL::SetUnitDisplayName( int aUnit, const wxString& aName )
426{
427 if( aUnit <= GetUnitCount() )
428 {
429 if( aName.Length() > 0 )
430 {
431 m_unitDisplayNames[aUnit] = aName;
432 }
433 else
434 {
435 m_unitDisplayNames.erase( aUnit );
436 }
437 }
438}
439
440
441void LIB_SYMBOL::SetName( const wxString& aName )
442{
443 m_name = aName;
444 m_libId.SetLibItemName( aName );
445
446 if( IsPower() )
447 GetValueField().SetText( aName );
448}
449
450
452{
453 if( aParent )
454 m_parent = aParent->SharedPtr();
455 else
456 m_parent.reset();
457}
458
459
460std::unique_ptr< LIB_SYMBOL > LIB_SYMBOL::Flatten() const
461{
462 std::unique_ptr< LIB_SYMBOL > retv;
463
464 if( IsAlias() )
465 {
466 LIB_SYMBOL_SPTR parent = m_parent.lock();
467
468 wxCHECK_MSG( parent, retv,
469 wxString::Format( "Parent of derived symbol '%s' undefined", m_name ) );
470
471 // Copy the parent.
472 retv.reset( new LIB_SYMBOL( *parent.get() ) );
473
474 retv->m_name = m_name;
475 retv->SetLibId( m_libId );
476
477 // Now add the inherited part mandatory field (this) information.
478 for( int i = 0; i < MANDATORY_FIELDS; i++ )
479 {
480 wxString tmp = GetFieldById( i )->GetText();
481
482 // If the field isn't defined then inherit the parent field value.
483 if( tmp.IsEmpty() )
484 retv->GetFieldById( i )->SetText( parent->GetFieldById( i )->GetText() );
485 else
486 *retv->GetFieldById( i ) = *GetFieldById( i );
487 }
488
489 // Grab all the rest of derived symbol fields.
490 for( const LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
491 {
492 const LIB_FIELD* aliasField = dynamic_cast<const LIB_FIELD*>( &item );
493
494 wxCHECK2( aliasField, continue );
495
496 // Mandatory fields were already resolved.
497 if( aliasField->IsMandatory() )
498 continue;
499
500 LIB_FIELD* newField = new LIB_FIELD( *aliasField );
501 newField->SetParent( retv.get() );
502
503 LIB_FIELD* parentField = retv->FindField( aliasField->GetName() );
504
505 if( !parentField ) // Derived symbol field does not exist in parent symbol.
506 {
507 retv->AddDrawItem( newField );
508 }
509 else // Derived symbol field overrides the parent symbol field.
510 {
511 retv->RemoveDrawItem( parentField );
512 retv->AddDrawItem( newField );
513 }
514 }
515
516 retv->SetKeyWords( m_keyWords.IsEmpty() ? parent->GetKeyWords() : m_keyWords );
517 retv->SetDescription( m_description.IsEmpty() ? parent->GetDescription() : m_description );
518 retv->SetFPFilters( m_fpFilters.IsEmpty() ? parent->GetFPFilters() : m_fpFilters );
519 retv->UpdateFieldOrdinals();
520 }
521 else
522 {
523 retv.reset( new LIB_SYMBOL( *this ) );
524 }
525
526 return retv;
527}
528
529
531{
532 for( LIB_ITEM& item : m_drawings )
533 {
534 if( EDA_TEXT* eda_text = dynamic_cast<EDA_TEXT*>( &item ) )
535 {
536 eda_text->ClearBoundingBoxCache();
537 eda_text->ClearRenderCache();
538 }
539 }
540}
541
542
543const wxString LIB_SYMBOL::GetLibraryName() const
544{
545 if( m_library )
546 return m_library->GetName();
547
548 return m_libId.GetLibNickname();
549}
550
551
553{
554 if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
555 return parent->m_options == ENTRY_POWER;
556
557 return m_options == ENTRY_POWER;
558}
559
560
562{
563 if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
564 parent->m_options = ENTRY_POWER;
565
567}
568
569
571{
572 if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
573 return parent->m_options == ENTRY_NORMAL;
574
575 return m_options == ENTRY_NORMAL;
576}
577
578
580{
581 if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
582 parent->m_options = ENTRY_NORMAL;
583
585}
586
587
588wxString LIB_SYMBOL::SubReference( int aUnit, bool aAddSeparator )
589{
590 wxString subRef;
591
592 if( aUnit < 1 )
593 return subRef;
594
595 if( m_subpartIdSeparator != 0 && aAddSeparator )
596 subRef << wxChar( m_subpartIdSeparator );
597
598 if( m_subpartFirstId >= '0' && m_subpartFirstId <= '9' )
599 {
600 subRef << aUnit;
601 }
602 else
603 {
604 // use letters as notation. To allow more than 26 units, the sub ref
605 // use one letter if letter = A .. Z or a ... z, and 2 letters otherwise
606 // first letter is expected to be 'A' or 'a' (i.e. 26 letters are available)
607 int u;
608
609 do
610 {
611 u = ( aUnit - 1 ) % 26;
612 subRef = wxChar( m_subpartFirstId + u ) + subRef;
613 aUnit = ( aUnit - u ) / 26;
614 } while( aUnit > 0 );
615
616 }
617
618 return subRef;
619}
620
621
622void LIB_SYMBOL::PrintBackground( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset,
623 int aUnit, int aConvert, const LIB_SYMBOL_OPTIONS& aOpts, bool aDimmed )
624{
625 /* draw background for filled items using background option
626 * Solid lines will be drawn after the background
627 * Note also, background is not drawn when printing in black and white
628 */
630 {
631 for( LIB_ITEM& item : m_drawings )
632 {
633 // Do not print private items
634 if( item.IsPrivate() )
635 continue;
636
637 if( item.Type() == LIB_SHAPE_T )
638 {
639 LIB_SHAPE& shape = static_cast<LIB_SHAPE&>( item );
640
641 // Do not draw items not attached to the current part
642 if( aUnit && shape.m_unit && ( shape.m_unit != aUnit ) )
643 continue;
644
645 if( aConvert && shape.m_convert && ( shape.m_convert != aConvert ) )
646 continue;
647
649 shape.Print( aSettings, aOffset, (void*) false, aOpts.transform, aDimmed );
650 }
651 }
652 }
653}
654
655
656void LIB_SYMBOL::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, int aUnit,
657 int aConvert, const LIB_SYMBOL_OPTIONS& aOpts, bool aDimmed )
658{
659
660 for( LIB_ITEM& item : m_drawings )
661 {
662 // Do not print private items
663 if( item.IsPrivate() )
664 continue;
665
666 // Do not draw items not attached to the current part
667 if( aUnit && item.m_unit && ( item.m_unit != aUnit ) )
668 continue;
669
670 if( aConvert && item.m_convert && ( item.m_convert != aConvert ) )
671 continue;
672
673 if( item.Type() == LIB_FIELD_T )
674 {
675 LIB_FIELD& field = static_cast<LIB_FIELD&>( item );
676
677 if( field.IsVisible() && !aOpts.draw_visible_fields )
678 continue;
679
680 if( !field.IsVisible() && !aOpts.draw_hidden_fields )
681 continue;
682 }
683
684 if( item.Type() == LIB_PIN_T )
685 {
686 item.Print( aSettings, aOffset, (void*) &aOpts, aOpts.transform, aDimmed );
687 }
688 else if( item.Type() == LIB_FIELD_T )
689 {
690 item.Print( aSettings, aOffset, (void*) NULL, aOpts.transform, aDimmed );
691 }
692 else if( item.Type() == LIB_SHAPE_T )
693 {
694 LIB_SHAPE& shape = static_cast<LIB_SHAPE&>( item );
695 bool forceNoFill = shape.GetFillMode() == FILL_T::FILLED_WITH_BG_BODYCOLOR;
696
697 shape.Print( aSettings, aOffset, (void*) forceNoFill, aOpts.transform, aDimmed );
698 }
699 else
700 {
701 item.Print( aSettings, aOffset, (void*) false, aOpts.transform, aDimmed );
702 }
703 }
704}
705
706
707void LIB_SYMBOL::Plot( PLOTTER *aPlotter, int aUnit, int aConvert, bool aBackground,
708 const VECTOR2I &aOffset, const TRANSFORM &aTransform, bool aDimmed ) const
709{
710 wxASSERT( aPlotter != nullptr );
711
713 COLOR4D bg = aPlotter->RenderSettings()->GetBackgroundColor();
714
715 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
716 bg = COLOR4D::WHITE;
717
718 if( aDimmed )
719 color = color.Mix( bg, 0.5f );
720
721 aPlotter->SetColor( color );
722
723 for( const LIB_ITEM& item : m_drawings )
724 {
725 // Do not plot private items
726 if( item.IsPrivate() )
727 continue;
728
729 // LIB_FIELDs are not plotted here, because this plot function is used to plot schematic
730 // items which have their own SCH_FIELDs
731 if( item.Type() == LIB_FIELD_T )
732 continue;
733
734 if( aUnit && item.m_unit && ( item.m_unit != aUnit ) )
735 continue;
736
737 if( aConvert && item.m_convert && ( item.m_convert != aConvert ) )
738 continue;
739
740 item.Plot( aPlotter, aBackground, aOffset, aTransform, aDimmed );
741 }
742}
743
744
745void LIB_SYMBOL::PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert, bool aBackground,
746 const VECTOR2I& aOffset, const TRANSFORM& aTransform, bool aDimmed )
747{
748 wxASSERT( aPlotter != nullptr );
749
751 COLOR4D bg = aPlotter->RenderSettings()->GetBackgroundColor();
752
753 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
754 bg = COLOR4D::WHITE;
755
756 if( aDimmed )
757 color = color.Mix( bg, 0.5f );
758
759 aPlotter->SetColor( color );
760
761 for( LIB_ITEM& item : m_drawings )
762 {
763 if( item.Type() != LIB_FIELD_T )
764 continue;
765
766 if( aUnit && item.m_unit && ( item.m_unit != aUnit ) )
767 continue;
768
769 if( aConvert && item.m_convert && ( item.m_convert != aConvert ) )
770 continue;
771
772 LIB_FIELD& field = (LIB_FIELD&) item;
773
774 // The reference is a special case: we should change the basic text
775 // to add '?' and the part id
776 wxString tmp = field.GetShownText();
777
778 if( field.GetId() == REFERENCE_FIELD )
779 {
780 wxString text = field.GetFullText( aUnit );
781 field.SetText( text );
782 }
783
784 item.Plot( aPlotter, aBackground, aOffset, aTransform, aDimmed );
785 field.SetText( tmp );
786 }
787}
788
789
791{
792 wxASSERT( aItem != nullptr );
793
794 // none of the MANDATORY_FIELDS may be removed in RAM, but they may be
795 // omitted when saving to disk.
796 if( aItem->Type() == LIB_FIELD_T )
797 {
798 if( static_cast<LIB_FIELD*>( aItem )->IsMandatory() )
799 return;
800 }
801
802 LIB_ITEMS& items = m_drawings[ aItem->Type() ];
803
804 for( LIB_ITEMS::iterator i = items.begin(); i != items.end(); i++ )
805 {
806 if( &*i == aItem )
807 {
808 items.erase( i );
809 SetModified();
810 break;
811 }
812 }
813}
814
815
816void LIB_SYMBOL::AddDrawItem( LIB_ITEM* aItem, bool aSort )
817{
818 wxCHECK( aItem, /* void */ );
819
820 m_drawings.push_back( aItem );
821
822 if( aSort )
824}
825
826
828{
829 if( aItem == nullptr )
830 {
832
833 return (it1 != m_drawings.end( aType ) ) ? &( *( m_drawings.begin( aType ) ) ) : nullptr;
834 }
835
836 // Search for the last item, assume aItem is of type aType
837 wxASSERT( ( aType == TYPE_NOT_INIT ) || ( aType == aItem->Type() ) );
839
840 while( ( it != m_drawings.end( aType ) ) && ( aItem != &( *it ) ) )
841 ++it;
842
843 // Search the next item
844 if( it != m_drawings.end( aType ) )
845 {
846 ++it;
847
848 if( it != m_drawings.end( aType ) )
849 return &( *it );
850 }
851
852 return nullptr;
853}
854
855
856void LIB_SYMBOL::GetPins( LIB_PINS& aList, int aUnit, int aConvert ) const
857{
858 /* Notes:
859 * when aUnit == 0: no unit filtering
860 * when aConvert == 0: no convert (shape selection) filtering
861 * when m_unit == 0, the body item is common to units
862 * when m_convert == 0, the body item is common to shapes
863 */
864
865 LIB_SYMBOL_SPTR parent = m_parent.lock();
866 const LIB_ITEMS_CONTAINER& drawItems = parent ? parent->m_drawings : m_drawings;
867
868 for( const LIB_ITEM& item : drawItems[LIB_PIN_T] )
869 {
870 // Unit filtering:
871 if( aUnit && item.m_unit && ( item.m_unit != aUnit ) )
872 continue;
873
874 // Shape filtering:
875 if( aConvert && item.m_convert && ( item.m_convert != aConvert ) )
876 continue;
877
878 aList.push_back( (LIB_PIN*) &item );
879 }
880}
881
882
883LIB_PIN* LIB_SYMBOL::GetPin( const wxString& aNumber, int aUnit, int aConvert ) const
884{
885 LIB_PINS pinList;
886
887 GetPins( pinList, aUnit, aConvert );
888
889 for( size_t i = 0; i < pinList.size(); i++ )
890 {
891 wxASSERT( pinList[i]->Type() == LIB_PIN_T );
892
893 if( aNumber == pinList[i]->GetNumber() )
894 return pinList[i];
895 }
896
897 return nullptr;
898}
899
900
901bool LIB_SYMBOL::PinsConflictWith( const LIB_SYMBOL& aOtherPart, bool aTestNums, bool aTestNames,
902 bool aTestType, bool aTestOrientation, bool aTestLength ) const
903{
904 LIB_PINS thisPinList;
905 GetPins( thisPinList, /* aUnit */ 0, /* aConvert */ 0 );
906
907 for( const LIB_PIN* eachThisPin : thisPinList )
908 {
909 wxASSERT( eachThisPin );
910 LIB_PINS otherPinList;
911 aOtherPart.GetPins( otherPinList, /* aUnit */ 0, /* aConvert */ 0 );
912 bool foundMatch = false;
913
914 for( const LIB_PIN* eachOtherPin : otherPinList )
915 {
916 wxASSERT( eachOtherPin );
917
918 // Same unit?
919 if( eachThisPin->GetUnit() != eachOtherPin->GetUnit() )
920 continue;
921
922 // Same body stype?
923 if( eachThisPin->GetConvert() != eachOtherPin->GetConvert() )
924 continue;
925
926 // Same position?
927 if( eachThisPin->GetPosition() != eachOtherPin->GetPosition() )
928 continue;
929
930 // Same number?
931 if( aTestNums && ( eachThisPin->GetNumber() != eachOtherPin->GetNumber() ) )
932 continue;
933
934 // Same name?
935 if( aTestNames && ( eachThisPin->GetName() != eachOtherPin->GetName() ) )
936 continue;
937
938 // Same electrical type?
939 if( aTestType && ( eachThisPin->GetType() != eachOtherPin->GetType() ) )
940 continue;
941
942 // Same orientation?
943 if( aTestOrientation
944 && ( eachThisPin->GetOrientation() != eachOtherPin->GetOrientation() ) )
945 continue;
946
947 // Same length?
948 if( aTestLength && ( eachThisPin->GetLength() != eachOtherPin->GetLength() ) )
949 continue;
950
951 foundMatch = true;
952 break; // Match found so search is complete.
953 }
954
955 if( !foundMatch )
956 {
957 // This means there was not an identical (according to the arguments)
958 // pin at the same position in the other symbol.
959 return true;
960 }
961 }
962
963 // The loop never gave up, so no conflicts were found.
964 return false;
965}
966
967
968const BOX2I LIB_SYMBOL::GetUnitBoundingBox( int aUnit, int aConvert ) const
969{
970 BOX2I bBox; // Start with a fresh BOX2I so the Merge algorithm works
971
972 for( const LIB_ITEM& item : m_drawings )
973 {
974 if( item.m_unit > 0
975 && m_unitCount > 1
976 && aUnit > 0
977 && aUnit != item.m_unit )
978 {
979 continue;
980 }
981
982 if( item.m_convert > 0 && aConvert > 0 && aConvert != item.m_convert )
983 continue;
984
985 if ( ( item.Type() == LIB_FIELD_T ) && !( ( LIB_FIELD& ) item ).IsVisible() )
986 continue;
987
988 bBox.Merge( item.GetBoundingBox() );
989 }
990
991 return bBox;
992}
993
994
995void LIB_SYMBOL::ViewGetLayers( int aLayers[], int& aCount ) const
996{
997 aCount = 6;
998 aLayers[0] = LAYER_DEVICE;
999 aLayers[1] = LAYER_DEVICE_BACKGROUND;
1000 aLayers[2] = LAYER_REFERENCEPART;
1001 aLayers[3] = LAYER_VALUEPART;
1002 aLayers[4] = LAYER_FIELDS;
1003 aLayers[5] = LAYER_SELECTION_SHADOWS;
1004}
1005
1006
1007const BOX2I LIB_SYMBOL::GetBodyBoundingBox( int aUnit, int aConvert, bool aIncludePins,
1008 bool aIncludePrivateItems ) const
1009{
1010 BOX2I bbox;
1011
1012 for( const LIB_ITEM& item : m_drawings )
1013 {
1014 if( item.m_unit > 0 && aUnit > 0 && aUnit != item.m_unit )
1015 continue;
1016
1017 if( item.m_convert > 0 && aConvert > 0 && aConvert != item.m_convert )
1018 continue;
1019
1020 if( item.IsPrivate() && !aIncludePrivateItems )
1021 continue;
1022
1023 if( item.Type() == LIB_FIELD_T )
1024 continue;
1025
1026 if( item.Type() == LIB_PIN_T )
1027 {
1028 const LIB_PIN& pin = static_cast<const LIB_PIN&>( item );
1029
1030 if( pin.IsVisible() )
1031 {
1032 // Note: the roots of the pins are always included for symbols that don't have
1033 // a well-defined body.
1034
1035 if( aIncludePins )
1036 bbox.Merge( pin.GetBoundingBox( false, false, false ) );
1037 else
1038 bbox.Merge( pin.GetPinRoot() );
1039 }
1040 }
1041 else
1042 {
1043 bbox.Merge( item.GetBoundingBox() );
1044 }
1045 }
1046
1047 return bbox;
1048}
1049
1050
1052{
1054}
1055
1056
1058{
1059 AddDrawItem( aField );
1060}
1061
1062
1063void LIB_SYMBOL::SetFields( const std::vector <LIB_FIELD>& aFields )
1064{
1066
1067 for( unsigned i=0; i<aFields.size(); ++i )
1068 {
1069 // drawings is a ptr_vector, new and copy an object on the heap.
1070 LIB_FIELD* field = new LIB_FIELD( aFields[i] );
1071
1072 field->SetParent( this );
1073 m_drawings.push_back( field );
1074 }
1075
1076 m_drawings.sort();
1077}
1078
1079
1080void LIB_SYMBOL::GetFields( std::vector<LIB_FIELD*>& aList )
1081{
1082 // Grab the MANDATORY_FIELDS first, in expected order given by enum MANDATORY_FIELD_T
1083 for( int id = 0; id < MANDATORY_FIELDS; ++id )
1084 aList.push_back( GetFieldById( id ) );
1085
1086 // Now grab all the rest of fields.
1087 for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
1088 {
1089 LIB_FIELD* field = static_cast<LIB_FIELD*>( &item );
1090
1091 if( !field->IsMandatory() )
1092 aList.push_back( field );
1093 }
1094}
1095
1096
1097void LIB_SYMBOL::GetFields( std::vector<LIB_FIELD>& aList )
1098{
1099 // Grab the MANDATORY_FIELDS first, in expected order given by enum MANDATORY_FIELD_T
1100 for( int id = 0; id < MANDATORY_FIELDS; ++id )
1101 aList.push_back( *GetFieldById( id ) );
1102
1103 // Now grab all the rest of fields.
1104 for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
1105 {
1106 LIB_FIELD* field = static_cast<LIB_FIELD*>( &item );
1107
1108 if( !field->IsMandatory() )
1109 aList.push_back( *field );
1110 }
1111}
1112
1113
1115{
1116 for( const LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
1117 {
1118 LIB_FIELD* field = ( LIB_FIELD* ) &item;
1119
1120 if( field->GetId() == aId )
1121 return field;
1122 }
1123
1124 return nullptr;
1125}
1126
1127
1128LIB_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName )
1129{
1130 for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
1131 {
1132 if( static_cast<LIB_FIELD*>( &item )->GetCanonicalName() == aFieldName )
1133 return static_cast<LIB_FIELD*>( &item );
1134 }
1135
1136 return nullptr;
1137}
1138
1139
1140const LIB_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName ) const
1141{
1142 for( const LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
1143 {
1144 if( static_cast<const LIB_FIELD*>( &item )->GetCanonicalName() == aFieldName )
1145 return static_cast<const LIB_FIELD*>( &item );
1146 }
1147
1148 return nullptr;
1149}
1150
1151
1153{
1155 wxASSERT( field != nullptr );
1156 return *field;
1157}
1158
1159
1161{
1163 wxASSERT( field != nullptr );
1164 return *field;
1165}
1166
1167
1169{
1171 wxASSERT( field != nullptr );
1172 return *field;
1173}
1174
1175
1177{
1179 wxASSERT( field != nullptr );
1180 return *field;
1181}
1182
1183
1185{
1186 int retv = 0;
1187 int lastOrdinal = MANDATORY_FIELDS;
1188
1189 for( LIB_ITEM& item : m_drawings[ LIB_FIELD_T ] )
1190 {
1191 LIB_FIELD* field = dynamic_cast<LIB_FIELD*>( &item );
1192
1193 wxCHECK2( field, continue );
1194
1195 // Mandatory fields were already resolved always have the same ordinal values.
1196 if( field->IsMandatory() )
1197 continue;
1198
1199 if( field->GetId() != lastOrdinal )
1200 {
1201 field->SetId( lastOrdinal );
1202 retv += 1;
1203 }
1204
1205 lastOrdinal += 1;
1206 }
1207
1208 return retv;
1209}
1210
1211
1213{
1214 int retv = MANDATORY_FIELDS;
1215
1216 while( GetFieldById( retv ) )
1217 retv += 1;
1218
1219 return retv;
1220}
1221
1222
1223void LIB_SYMBOL::SetOffset( const VECTOR2I& aOffset )
1224{
1225 for( LIB_ITEM& item : m_drawings )
1226 item.Offset( aOffset );
1227}
1228
1229
1231{
1233}
1234
1235
1237{
1238 for( const LIB_ITEM& item : m_drawings )
1239 {
1240 if( item.m_convert > LIB_ITEM::LIB_CONVERT::BASE )
1241 return true;
1242 }
1243
1244 if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
1245 {
1246 for( const LIB_ITEM& item : parent->GetDrawItems() )
1247 {
1248 if( item.m_convert > LIB_ITEM::LIB_CONVERT::BASE )
1249 return true;
1250 }
1251 }
1252
1253 return false;
1254}
1255
1257{
1258 int maxPinNumber = 0;
1259 LIB_SYMBOL_SPTR parent = m_parent.lock();
1260 const LIB_ITEMS_CONTAINER& drawItems = parent ? parent->m_drawings : m_drawings;
1261
1262 for( const LIB_ITEM& item : drawItems[LIB_PIN_T] )
1263 {
1264 const LIB_PIN* pin = static_cast<const LIB_PIN*>( &item );
1265 long currentPinNumber = 0;
1266 bool isNum = pin->GetNumber().ToLong( &currentPinNumber );
1267
1268 if( isNum && currentPinNumber > maxPinNumber )
1269 {
1270 maxPinNumber = currentPinNumber;
1271 }
1272 }
1273
1274 return maxPinNumber;
1275}
1276
1277
1279{
1280 for( LIB_ITEM& item : m_drawings )
1281 item.ClearTempFlags();
1282}
1283
1284
1286{
1287 for( LIB_ITEM& item : m_drawings )
1288 item.ClearEditFlags();
1289}
1290
1291
1292LIB_ITEM* LIB_SYMBOL::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
1293 const VECTOR2I& aPoint )
1294{
1295 for( LIB_ITEM& item : m_drawings )
1296 {
1297 if( ( aUnit && item.m_unit && aUnit != item.m_unit )
1298 || ( aConvert && item.m_convert && aConvert != item.m_convert )
1299 || ( item.Type() != aType && aType != TYPE_NOT_INIT ) )
1300 {
1301 continue;
1302 }
1303
1304 if( item.HitTest( aPoint ) )
1305 return &item;
1306 }
1307
1308 return nullptr;
1309}
1310
1311
1312LIB_ITEM* LIB_SYMBOL::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
1313 const VECTOR2I& aPoint, const TRANSFORM& aTransform )
1314{
1315 /* we use LocateDrawItem( int aUnit, int convert, KICAD_T type, const
1316 * VECTOR2I& pt ) to search items.
1317 * because this function uses DefaultTransform as orient/mirror matrix
1318 * we temporary copy aTransform in DefaultTransform
1319 */
1320 LIB_ITEM* item;
1321 TRANSFORM transform = DefaultTransform;
1322 DefaultTransform = aTransform;
1323
1324 item = LocateDrawItem( aUnit, aConvert, aType, aPoint );
1325
1326 // Restore matrix
1327 DefaultTransform = transform;
1328
1329 return item;
1330}
1331
1332
1333INSPECT_RESULT LIB_SYMBOL::Visit( INSPECTOR aInspector, void* aTestData,
1334 const std::vector<KICAD_T>& aScanTypes )
1335{
1336 // The part itself is never inspected, only its children
1337 for( LIB_ITEM& item : m_drawings )
1338 {
1339 if( item.IsType( aScanTypes ) )
1340 {
1341 if( aInspector( &item, aTestData ) == INSPECT_RESULT::QUIT )
1342 return INSPECT_RESULT::QUIT;
1343 }
1344 }
1345
1347}
1348
1349
1350void LIB_SYMBOL::SetUnitCount( int aCount, bool aDuplicateDrawItems )
1351{
1352 if( m_unitCount == aCount )
1353 return;
1354
1355 if( aCount < m_unitCount )
1356 {
1358
1359 while( i != m_drawings.end() )
1360 {
1361 if( i->m_unit > aCount )
1362 i = m_drawings.erase( i );
1363 else
1364 ++i;
1365 }
1366 }
1367 else if( aDuplicateDrawItems )
1368 {
1369 int prevCount = m_unitCount;
1370
1371 // Temporary storage for new items, as adding new items directly to
1372 // m_drawings may cause the buffer reallocation which invalidates the
1373 // iterators
1374 std::vector< LIB_ITEM* > tmp;
1375
1376 for( LIB_ITEM& item : m_drawings )
1377 {
1378 if( item.m_unit != 1 )
1379 continue;
1380
1381 for( int j = prevCount + 1; j <= aCount; j++ )
1382 {
1383 LIB_ITEM* newItem = (LIB_ITEM*) item.Clone();
1384 newItem->m_unit = j;
1385 tmp.push_back( newItem );
1386 }
1387 }
1388
1389 for( LIB_ITEM* item : tmp )
1390 m_drawings.push_back( item );
1391 }
1392
1393 m_drawings.sort();
1394 m_unitCount = aCount;
1395}
1396
1397
1399{
1400 if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
1401 return parent->GetUnitCount();
1402
1403 return m_unitCount;
1404}
1405
1406
1407void LIB_SYMBOL::SetConversion( bool aSetConvert, bool aDuplicatePins )
1408{
1409 if( aSetConvert == HasConversion() )
1410 return;
1411
1412 // Duplicate items to create the converted shape
1413 if( aSetConvert )
1414 {
1415 if( aDuplicatePins )
1416 {
1417 std::vector< LIB_ITEM* > tmp; // Temporarily store the duplicated pins here.
1418
1419 for( LIB_ITEM& item : m_drawings )
1420 {
1421 // Only pins are duplicated.
1422 if( item.Type() != LIB_PIN_T )
1423 continue;
1424
1425 if( item.m_convert == 1 )
1426 {
1427 LIB_ITEM* newItem = (LIB_ITEM*) item.Clone();
1428 newItem->m_convert = 2;
1429 tmp.push_back( newItem );
1430 }
1431 }
1432
1433 // Transfer the new pins to the LIB_SYMBOL.
1434 for( unsigned i = 0; i < tmp.size(); i++ )
1435 m_drawings.push_back( tmp[i] );
1436 }
1437 }
1438 else
1439 {
1440 // Delete converted shape items because the converted shape does
1441 // not exist
1443
1444 while( i != m_drawings.end() )
1445 {
1446 if( i->m_convert > 1 )
1447 i = m_drawings.erase( i );
1448 else
1449 ++i;
1450 }
1451 }
1452
1453 m_drawings.sort();
1454}
1455
1456
1457void LIB_SYMBOL::SetSubpartIdNotation( int aSep, int aFirstId )
1458{
1459 m_subpartFirstId = 'A';
1461
1462 if( aSep == '.' || aSep == '-' || aSep == '_' )
1463 m_subpartIdSeparator = aSep;
1464
1465 if( aFirstId == '1' && aSep != 0 )
1466 m_subpartFirstId = aFirstId;
1467}
1468
1469
1470std::vector<LIB_ITEM*> LIB_SYMBOL::GetUnitDrawItems( int aUnit, int aConvert )
1471{
1472 std::vector<LIB_ITEM*> unitItems;
1473
1474 for( LIB_ITEM& item : m_drawings )
1475 {
1476 if( item.Type() == LIB_FIELD_T )
1477 continue;
1478
1479 if( ( aConvert == -1 && item.GetUnit() == aUnit )
1480 || ( aUnit == -1 && item.GetConvert() == aConvert )
1481 || ( aUnit == item.GetUnit() && aConvert == item.GetConvert() ) )
1482 {
1483 unitItems.push_back( &item );
1484 }
1485 }
1486
1487 return unitItems;
1488}
1489
1490
1491std::vector<struct LIB_SYMBOL_UNIT> LIB_SYMBOL::GetUnitDrawItems()
1492{
1493 std::vector<struct LIB_SYMBOL_UNIT> units;
1494
1495 for( LIB_ITEM& item : m_drawings )
1496 {
1497 if( item.Type() == LIB_FIELD_T )
1498 continue;
1499
1500 int unit = item.GetUnit();
1501 int convert = item.GetConvert();
1502
1503 auto it = std::find_if( units.begin(), units.end(),
1504 [unit, convert]( const LIB_SYMBOL_UNIT& a )
1505 {
1506 return a.m_unit == unit && a.m_convert == convert;
1507 } );
1508
1509 if( it == units.end() )
1510 {
1511 struct LIB_SYMBOL_UNIT newUnit;
1512 newUnit.m_unit = item.GetUnit();
1513 newUnit.m_convert = item.GetConvert();
1514 newUnit.m_items.push_back( &item );
1515 units.emplace_back( newUnit );
1516 }
1517 else
1518 {
1519 it->m_items.push_back( &item );
1520 }
1521 }
1522
1523 return units;
1524}
1525
1526
1527std::vector<struct LIB_SYMBOL_UNIT> LIB_SYMBOL::GetUniqueUnits()
1528{
1529 int unitNum;
1530 size_t i;
1531 struct LIB_SYMBOL_UNIT unit;
1532 std::vector<LIB_ITEM*> compareDrawItems;
1533 std::vector<LIB_ITEM*> currentDrawItems;
1534 std::vector<struct LIB_SYMBOL_UNIT> uniqueUnits;
1535
1536 // The first unit is guaranteed to be unique so always include it.
1537 unit.m_unit = 1;
1538 unit.m_convert = 1;
1539 unit.m_items = GetUnitDrawItems( 1, 1 );
1540
1541 // There are no unique units if there are no draw items other than fields.
1542 if( unit.m_items.size() == 0 )
1543 return uniqueUnits;
1544
1545 uniqueUnits.emplace_back( unit );
1546
1547 if( ( GetUnitCount() == 1 || UnitsLocked() ) && !HasConversion() )
1548 return uniqueUnits;
1549
1550 currentDrawItems = unit.m_items;
1551
1552 for( unitNum = 2; unitNum <= GetUnitCount(); unitNum++ )
1553 {
1554 compareDrawItems = GetUnitDrawItems( unitNum, 1 );
1555
1556 wxCHECK2_MSG( compareDrawItems.size() != 0, continue,
1557 "Multiple unit symbol defined with empty units." );
1558
1559 if( currentDrawItems.size() != compareDrawItems.size() )
1560 {
1561 unit.m_unit = unitNum;
1562 unit.m_convert = 1;
1563 unit.m_items = compareDrawItems;
1564 uniqueUnits.emplace_back( unit );
1565 }
1566 else
1567 {
1568 for( i = 0; i < currentDrawItems.size(); i++ )
1569 {
1570 if( currentDrawItems[i]->compare( *compareDrawItems[i],
1571 LIB_ITEM::COMPARE_FLAGS::UNIT ) != 0 )
1572 {
1573 unit.m_unit = unitNum;
1574 unit.m_convert = 1;
1575 unit.m_items = compareDrawItems;
1576 uniqueUnits.emplace_back( unit );
1577 }
1578 }
1579 }
1580 }
1581
1582 if( HasConversion() )
1583 {
1584 currentDrawItems = GetUnitDrawItems( 1, 2 );
1585
1586 if( ( GetUnitCount() == 1 || UnitsLocked() ) )
1587 {
1588 unit.m_unit = 1;
1589 unit.m_convert = 2;
1590 unit.m_items = currentDrawItems;
1591 uniqueUnits.emplace_back( unit );
1592
1593 return uniqueUnits;
1594 }
1595
1596 for( unitNum = 2; unitNum <= GetUnitCount(); unitNum++ )
1597 {
1598 compareDrawItems = GetUnitDrawItems( unitNum, 2 );
1599
1600 wxCHECK2_MSG( compareDrawItems.size() != 0, continue,
1601 "Multiple unit symbol defined with empty units." );
1602
1603 if( currentDrawItems.size() != compareDrawItems.size() )
1604 {
1605 unit.m_unit = unitNum;
1606 unit.m_convert = 2;
1607 unit.m_items = compareDrawItems;
1608 uniqueUnits.emplace_back( unit );
1609 }
1610 else
1611 {
1612 for( i = 0; i < currentDrawItems.size(); i++ )
1613 {
1614 if( currentDrawItems[i]->compare( *compareDrawItems[i],
1615 LIB_ITEM::COMPARE_FLAGS::UNIT ) != 0 )
1616 {
1617 unit.m_unit = unitNum;
1618 unit.m_convert = 2;
1619 unit.m_items = compareDrawItems;
1620 uniqueUnits.emplace_back( unit );
1621 }
1622 }
1623 }
1624 }
1625 }
1626
1627 return uniqueUnits;
1628}
int color
Definition: DXF_plotter.cpp:57
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:588
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
void SetModified()
Definition: eda_item.cpp:64
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
void ClearSelected()
Definition: eda_item.h:121
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:100
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:144
FILL_T GetFillMode() const
Definition: eda_shape.h:101
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:72
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
virtual bool IsVisible() const
Definition: eda_text.h:136
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:163
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
virtual const COLOR4D & GetBackgroundColor() const =0
Return current background color settings.
Field object used in symbol libraries.
Definition: lib_field.h:60
bool ShowInChooser() const
Definition: lib_field.h:187
void SetId(int aId)
Definition: lib_field.cpp:113
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:391
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: lib_field.cpp:470
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: lib_field.cpp:419
bool IsMandatory() const
Definition: lib_field.cpp:574
int GetId() const
Definition: lib_field.h:115
wxString GetShownText(int aDepth=0, bool aAllowExtraText=true) const override
Return the string actually shown after processing of the base text.
Definition: lib_field.cpp:408
int compare(const LIB_ITEM &aOther, int aCompareFlags=0) const override
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_field.cpp:225
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:109
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:159
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:87
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
int m_convert
Shape identification for alternate body styles.
Definition: lib_item.h:333
virtual int compare(const LIB_ITEM &aOther, int aCompareFlags=0) const
Provide the draw object specific comparison called by the == and < operators.
Definition: lib_item.cpp:74
virtual void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, void *aData, const TRANSFORM &aTransform, bool aDimmed)
Draw an item.
Definition: lib_item.cpp:136
int m_unit
Unit identification for multiple parts per package.
Definition: lib_item.h:327
Define a library symbol object.
Definition: lib_symbol.h:98
LIB_ITEMS_CONTAINER m_drawings
Definition: lib_symbol.h:754
void Plot(PLOTTER *aPlotter, int aUnit, int aConvert, bool aBackground, const VECTOR2I &aOffset, const TRANSFORM &aTransform, bool aDimmed) const
Plot lib symbol to plotter.
Definition: lib_symbol.cpp:707
void PrintBackground(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, int aMulti, int aConvert, const LIB_SYMBOL_OPTIONS &aOpts, bool aDimmed)
Print just the background fills of a symbol.
Definition: lib_symbol.cpp:622
void ClearTempFlags()
Clears the status flag all draw objects in this symbol.
LIBRENTRYOPTIONS m_options
Special symbol features such as POWER or NORMAL.)
Definition: lib_symbol.h:752
void RemoveDrawItem(LIB_ITEM *aItem)
Remove draw aItem from list.
Definition: lib_symbol.cpp:790
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:901
wxString GetKeyWords() const
Definition: lib_symbol.h:159
void SetConversion(bool aSetConvert, bool aDuplicatePins=true)
Set or clear the alternate body style (DeMorgan) for the symbol.
LIB_FIELD & GetReferenceField()
Return reference to the reference designator field.
void SetUnitCount(int aCount, bool aDuplicateDrawItems=true)
Set the units per symbol count.
static int m_subpartFirstId
the ASCII char value to calculate the subpart symbol id from the symbol number: only 'A',...
Definition: lib_symbol.h:766
bool UnitsLocked() const
Check whether symbol units are interchangeable.
Definition: lib_symbol.h:253
int GetNextAvailableFieldId() const
std::map< int, wxString > m_unitDisplayNames
Definition: lib_symbol.h:769
SYMBOL_LIB * m_library
Definition: lib_symbol.h:756
LIB_ITEM * GetNextDrawItem(const LIB_ITEM *aItem=nullptr, KICAD_T aType=TYPE_NOT_INIT)
Return the next draw object pointer.
Definition: lib_symbol.cpp:827
wxString GetUnitDisplayName(int aUnit) override
Return the user-defined display name for aUnit for symbols with units.
Definition: lib_symbol.cpp:403
const wxString GetLibraryName() const
Definition: lib_symbol.cpp:543
LIB_FIELD * GetFieldById(int aId) const
Return pointer to the requested field.
bool IsAlias() const
Definition: lib_symbol.h:183
std::vector< struct LIB_SYMBOL_UNIT > GetUnitDrawItems()
Return a list of LIB_ITEM objects separated by unit and convert number.
int GetMaxPinNumber() const
LIB_SYMBOL(const wxString &aName, LIB_SYMBOL *aParent=nullptr, SYMBOL_LIB *aLibrary=nullptr)
Definition: lib_symbol.cpp:100
LIB_SYMBOL_SPTR m_me
Definition: lib_symbol.h:736
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
Definition: lib_symbol.cpp:995
bool IsPower() const
Definition: lib_symbol.cpp:552
wxString m_name
Definition: lib_symbol.h:757
void SetPower()
Definition: lib_symbol.cpp:561
wxString m_keyWords
Search keywords.
Definition: lib_symbol.h:759
bool m_includeInBom
Definition: lib_symbol.h:750
LIB_FIELD & GetFootprintField()
Return reference to the footprint field.
void RemoveDuplicateDrawItems()
Remove duplicate draw items from list.
void SetParent(LIB_SYMBOL *aParent=nullptr)
Definition: lib_symbol.cpp:451
wxString GetName() const override
Definition: lib_symbol.h:136
static int m_subpartIdSeparator
the separator char between the subpart id and the reference like U1A ( m_subpartIdSeparator = 0 ) or ...
Definition: lib_symbol.h:763
void ClearEditFlags()
int m_pinNameOffset
The offset in mils to draw the pin name.
Definition: lib_symbol.h:745
bool m_showPinNumbers
Definition: lib_symbol.h:748
void GetFields(std::vector< LIB_FIELD * > &aList)
Return a list of fields within this symbol.
void AddDrawItem(LIB_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
Definition: lib_symbol.cpp:816
LIB_FIELD * FindField(const wxString &aFieldName)
Find a field within this symbol matching aFieldName and returns it or NULL if not found.
void GetChooserFields(std::map< wxString, wxString > &aColumnMap) override
Retrieves a key/value map of the fields on this item that should be exposed to the library browser/ch...
Definition: lib_symbol.cpp:73
static wxString SubReference(int aUnit, bool aAddSeparator=true)
Definition: lib_symbol.cpp:588
virtual ~LIB_SYMBOL()
http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared
Definition: lib_symbol.cpp:183
timestamp_t m_lastModDate
Definition: lib_symbol.h:739
bool m_includeOnBoard
Definition: lib_symbol.h:751
LIB_ID m_libId
Definition: lib_symbol.h:738
void SetLib(SYMBOL_LIB *aLibrary)
Definition: lib_symbol.h:188
wxString m_description
Definition: lib_symbol.h:758
std::vector< struct LIB_SYMBOL_UNIT > GetUniqueUnits()
Return a list of unit numbers that are unique to this symbol.
const BOX2I GetBodyBoundingBox(int aUnit, int aConvert, bool aIncludePins, bool aIncludePrivateItems) const
Get the symbol bounding box excluding fields.
static void SetSubpartIdNotation(int aSep, int aFirstId)
Set the separator char between the subpart id and the reference 0 (no separator) or '.
const LIB_SYMBOL & operator=(const LIB_SYMBOL &aSymbol)
Definition: lib_symbol.cpp:188
LIB_FIELD & GetValueField()
Return reference to the value field.
bool m_unitsLocked
True if symbol has multiple units and changing one unit does not automatically change another unit.
Definition: lib_symbol.h:742
wxArrayString m_fpFilters
List of suitable footprint names for the symbol (wild card names accepted).
Definition: lib_symbol.h:760
bool HasUnitDisplayName(int aUnit) override
Return true if the given unit aUnit has a display name defined.
Definition: lib_symbol.cpp:397
bool IsNormal() const
Definition: lib_symbol.cpp:570
LIB_SYMBOL_SPTR SharedPtr() const
Definition: lib_symbol.h:108
LIB_ITEM * LocateDrawItem(int aUnit, int aConvert, KICAD_T aType, const VECTOR2I &aPoint)
Locate a draw object.
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:391
wxString GetDescription() override
Definition: lib_symbol.h:146
int m_unitCount
Number of units (parts) per package.
Definition: lib_symbol.h:741
void ClearCaches()
Definition: lib_symbol.cpp:530
int GetUnitCount() const override
For items with units, return the number of units.
void AddField(LIB_FIELD *aField)
Add a field.
LIB_SYMBOL_REF m_parent
Use for inherited symbols.
Definition: lib_symbol.h:737
void GetPins(LIB_PINS &aList, int aUnit=0, int aConvert=0) const
Return a list of pin object pointers from the draw item list.
Definition: lib_symbol.cpp:856
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Definition: lib_symbol.cpp:460
int Compare(const LIB_SYMBOL &aRhs, int aCompareFlags=0) const
Comparison test that can be used for operators.
Definition: lib_symbol.cpp:237
LIB_FIELD & GetDatasheetField()
Return reference to the datasheet field.
const BOX2I GetUnitBoundingBox(int aUnit, int aConvert) const
Get the bounding box for the symbol.
Definition: lib_symbol.cpp:968
void deleteAllFields()
bool HasConversion() const
Test if symbol has more than one body conversion type (DeMorgan).
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset, int aMulti, int aConvert, const LIB_SYMBOL_OPTIONS &aOpts, bool aDimmed)
Print symbol.
Definition: lib_symbol.cpp:656
void PlotLibFields(PLOTTER *aPlotter, int aUnit, int aConvert, bool aBackground, const VECTOR2I &aOffset, const TRANSFORM &aTransform, bool aDimmed)
Plot Lib Fields only of the symbol to plotter.
Definition: lib_symbol.cpp:745
LIB_PIN * GetPin(const wxString &aNumber, int aUnit=0, int aConvert=0) const
Return pin object with the requested pin aNumber.
Definition: lib_symbol.cpp:883
void SetFields(const std::vector< LIB_FIELD > &aFieldsList)
Overwrite all the existing fields in this symbol with fields supplied in aFieldsList.
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:425
void SetOffset(const VECTOR2I &aOffset)
Move the symbol aOffset.
wxString GetSearchText() override
Definition: lib_symbol.cpp:48
virtual void SetName(const wxString &aName)
Definition: lib_symbol.cpp:441
bool m_showPinNames
Definition: lib_symbol.h:747
void SetNormal()
Definition: lib_symbol.cpp:579
void CopyUnitDisplayNames(std::map< int, wxString > &aTarget) const
Copy all unit display names into the given map aTarget.
Definition: lib_symbol.cpp:416
size_t size(int aType=UNDEFINED_TYPE) const
Definition: multivector.h:225
void sort()
Definition: multivector.h:247
ITERATOR_BASE< const LIB_ITEM, const MULTIVECTOR< LIB_ITEM, FIRST_TYPE_VAL, LAST_TYPE_VAL >, typename ITEM_PTR_VECTOR::const_iterator > CONST_ITERATOR
Definition: multivector.h:167
void unique()
Remove duplicate elements in list.
Definition: multivector.h:256
void push_back(T *aItem)
Definition: multivector.h:174
ITERATOR_BASE< LIB_ITEM, MULTIVECTOR< LIB_ITEM, FIRST_TYPE_VAL, LAST_TYPE_VAL >, typename ITEM_PTR_VECTOR::iterator > ITERATOR
The const iterator.
Definition: multivector.h:164
ITERATOR end(int aType=UNDEFINED_TYPE)
Definition: multivector.h:194
void clear(int aType=UNDEFINED_TYPE)
Definition: multivector.h:212
ITERATOR erase(const ITERATOR &aIterator)
Definition: multivector.h:179
ITERATOR begin(int aType=UNDEFINED_TYPE)
Definition: multivector.h:188
Base plotter engine class.
Definition: plotter.h:110
RENDER_SETTINGS * RenderSettings()
Definition: plotter.h:141
bool GetColorMode() const
Definition: plotter.h:138
virtual void SetColor(const COLOR4D &color)=0
Object used to load, save, search, and otherwise manipulate symbol library files.
const wxString GetName() const
Return the file name without path or extension.
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:47
@ WHITE
Definition: color4d.h:48
#define DEFAULT_PIN_NAME_OFFSET
The intersheets references prefix string.
#define _(s)
INSPECT_RESULT
Definition: eda_item.h:42
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:78
#define IS_NEW
New item, just created.
#define STRUCT_DELETED
flag indication structures to be erased
@ FILLED_WITH_BG_BODYCOLOR
TRANSFORM DefaultTransform
Definition: eeschema.cpp:68
bool GetGRForceBlackPenState(void)
Definition: gr_basic.cpp:156
@ LAYER_DEVICE
Definition: layer_ids.h:357
@ LAYER_VALUEPART
Definition: layer_ids.h:353
@ LAYER_FIELDS
Definition: layer_ids.h:354
@ LAYER_DEVICE_BACKGROUND
Definition: layer_ids.h:372
@ LAYER_REFERENCEPART
Definition: layer_ids.h:352
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:381
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_item.h:54
bool operator<(const LIB_SYMBOL &aItem1, const LIB_SYMBOL &aItem2)
Definition: lib_symbol.cpp:85
@ ENTRY_NORMAL
Definition: lib_symbol.h:53
@ ENTRY_POWER
Definition: lib_symbol.h:54
std::shared_ptr< LIB_SYMBOL > LIB_SYMBOL_SPTR
shared pointer to LIB_SYMBOL
Definition: lib_symbol.h:44
LIB_ITEMS_CONTAINER::ITEM_PTR_VECTOR LIB_ITEMS
Definition: lib_symbol.h:47
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94
bool draw_visible_fields
Definition: lib_symbol.h:65
TRANSFORM transform
Definition: lib_symbol.h:63
std::vector< LIB_ITEM * > m_items
The items unique to this unit and alternate body style.
Definition: lib_symbol.h:87
int m_convert
The alternate body style of the unit.
Definition: lib_symbol.h:86
int m_unit
The unit number.
Definition: lib_symbol.h:85
http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared
Definition: lib_symbol.cpp:93
void operator()(void const *) const
Definition: lib_symbol.cpp:94
Definition for symbol library class.
@ 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 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ LIB_SYMBOL_T
Definition: typeinfo.h:198
@ TYPE_NOT_INIT
Definition: typeinfo.h:81
@ LIB_SHAPE_T
Definition: typeinfo.h:199
@ LIB_PIN_T
Definition: typeinfo.h:202
@ LIB_FIELD_T
Definition: typeinfo.h:208