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 // Ensure the color of shape is from LAYER_DEVICE if not specified.
605 COLOR4D init_color = shape.GetStroke().GetColor();
606 STROKE_PARAMS prms = shape.GetStroke();
607
608 if( init_color == COLOR4D::UNSPECIFIED )
609 {
610 COLOR4D color = aSettings->GetLayerColor( LAYER_DEVICE );
611 prms.SetColor( color );
612 shape.SetStroke( prms );
613 }
614 shape.Print( aSettings, aUnit, aBodyStyle, aOffset, aForceNoFill, aDimmed );
615 prms.SetColor( init_color );
616 shape.SetStroke( prms );
617 }
618 else
619 {
620 item.Print( aSettings, aUnit, aBodyStyle, aOffset, aForceNoFill, aDimmed );
621 }
622 }
623}
624
625
626void LIB_SYMBOL::PrintBackground( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
627 const VECTOR2I& aOffset, bool aDimmed )
628{
629 /* draw background for filled items using background option
630 * Solid lines will be drawn after the background
631 * Note also, background is not drawn when printing in black and white
632 */
634 {
635 for( SCH_ITEM& item : m_drawings )
636 {
637 // Do not print private items
638 if( item.IsPrivate() )
639 continue;
640
641 if( item.Type() == SCH_SHAPE_T )
642 {
643 SCH_SHAPE& shape = static_cast<SCH_SHAPE&>( item );
644
645 // Do not draw items not attached to the current part
646 if( aUnit && shape.m_unit && ( shape.m_unit != aUnit ) )
647 continue;
648
649 if( aBodyStyle && shape.m_bodyStyle && ( shape.m_bodyStyle != aBodyStyle ) )
650 continue;
651
652 if( shape.GetFillMode() == FILL_T::FILLED_WITH_BG_BODYCOLOR )
653 shape.Print( aSettings, aUnit, aBodyStyle, aOffset, false, aDimmed );
654 }
655 }
656 }
657}
658
659
660void LIB_SYMBOL::Plot( PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
661 int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed )
662{
663 wxASSERT( aPlotter != nullptr );
664
665 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
666 COLOR4D color = renderSettings->GetLayerColor( LAYER_DEVICE );
667 COLOR4D bg = renderSettings->GetBackgroundColor();
668
669 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
670 bg = COLOR4D::WHITE;
671
672 if( aDimmed )
673 {
674 color.Desaturate( );
675 color = color.Mix( bg, 0.5f );
676 }
677
678 aPlotter->SetColor( color );
679
680 for( SCH_ITEM& item : m_drawings )
681 {
682 // Do not plot private items
683 if( item.IsPrivate() )
684 continue;
685
686 // LIB_FIELDs are not plotted here, because this plot function is used to plot schematic
687 // items which have their own SCH_FIELDs
688 if( item.Type() == SCH_FIELD_T )
689 continue;
690
691 if( aUnit && item.m_unit && ( item.m_unit != aUnit ) )
692 continue;
693
694 if( aBodyStyle && item.m_bodyStyle && ( item.m_bodyStyle != aBodyStyle ) )
695 continue;
696
697 item.Plot( aPlotter, aBackground, aPlotOpts, aUnit, aBodyStyle, aOffset, aDimmed );
698 }
699}
700
701
702void LIB_SYMBOL::PlotFields( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
703 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed )
704{
705 wxASSERT( aPlotter != nullptr );
706
707 SCH_RENDER_SETTINGS* renderSettings = getRenderSettings( aPlotter );
708 COLOR4D color = renderSettings->GetLayerColor( LAYER_FIELDS );
709 COLOR4D bg = renderSettings->GetBackgroundColor();
710
711 if( bg == COLOR4D::UNSPECIFIED || !aPlotter->GetColorMode() )
712 bg = COLOR4D::WHITE;
713
714 if( aDimmed )
715 {
716 color.Desaturate( );
717 color = color.Mix( bg, 0.5f );
718 }
719
720 aPlotter->SetColor( color );
721
722 for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
723 {
724 SCH_FIELD& field = static_cast<SCH_FIELD&>( item );
725
726 if( !renderSettings->m_ShowHiddenFields && !field.IsVisible() )
727 continue;
728
729 // The reference is a special case: we should change the basic text
730 // to add '?' and the part id
731 wxString tmp = field.GetText();
732
733 field.SetText( field.GetFullText( aUnit ) );
734 item.Plot( aPlotter, aBackground, aPlotOpts, aUnit, aBodyStyle, aOffset, aDimmed );
735
736 field.SetText( tmp );
737 }
738}
739
740
742{
743 std::vector<SCH_SHAPE*> potential_top_items;
744 std::vector<SCH_ITEM*> bottom_items;
745
746 for( SCH_ITEM& item : m_drawings )
747 {
748 if( item.Type() == SCH_SHAPE_T )
749 {
750 SCH_SHAPE& shape = static_cast<SCH_SHAPE&>( item );
751
752 if( shape.GetFillMode() == FILL_T::FILLED_WITH_COLOR )
753 potential_top_items.push_back( &shape );
754 else
755 bottom_items.push_back( &item );
756 }
757 else
758 {
759 bottom_items.push_back( &item );
760 }
761 }
762
763 std::sort( potential_top_items.begin(), potential_top_items.end(),
764 []( SCH_ITEM* a, SCH_ITEM* b )
765 {
766 return a->GetBoundingBox().GetArea() > b->GetBoundingBox().GetArea();
767 } );
768
769 for( SCH_SHAPE* item : potential_top_items )
770 {
771 for( SCH_ITEM* bottom_item : bottom_items )
772 {
773 if( item->GetBoundingBox().Contains( bottom_item->GetBoundingBox() ) )
774 {
775 item->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
776 break;
777 }
778 }
779 }
780}
781
782
784{
785 wxASSERT( aItem != nullptr );
786
787 // none of the MANDATORY_FIELDS may be removed in RAM, but they may be
788 // omitted when saving to disk.
789 if( aItem->Type() == SCH_FIELD_T )
790 {
791 if( static_cast<SCH_FIELD*>( aItem )->IsMandatory() )
792 return;
793 }
794
795 LIB_ITEMS& items = m_drawings[ aItem->Type() ];
796
797 for( LIB_ITEMS::iterator i = items.begin(); i != items.end(); i++ )
798 {
799 if( &*i == aItem )
800 {
801 items.erase( i );
802 break;
803 }
804 }
805}
806
807
808void LIB_SYMBOL::AddDrawItem( SCH_ITEM* aItem, bool aSort )
809{
810 if( aItem )
811 {
812 aItem->SetParent( this );
813
814 m_drawings.push_back( aItem );
815
816 if( aSort )
818 }
819}
820
821
822std::vector<SCH_PIN*> LIB_SYMBOL::GetPins( int aUnit, int aBodyStyle ) const
823{
824 std::vector<SCH_PIN*> pins;
825
826 /* Notes:
827 * when aUnit == 0: no unit filtering
828 * when aBodyStyle == 0: no body style filtering
829 * when m_unit == 0, the item is common to all units
830 * when m_bodyStyle == 0, the item is common to all body styles
831 */
832
833 LIB_SYMBOL_SPTR parent = m_parent.lock();
834 const LIB_ITEMS_CONTAINER& drawItems = parent ? parent->m_drawings : m_drawings;
835
836 for( const SCH_ITEM& item : drawItems[SCH_PIN_T] )
837 {
838 // Unit filtering:
839 if( aUnit && item.m_unit && ( item.m_unit != aUnit ) )
840 continue;
841
842 // De Morgan variant filtering:
843 if( aBodyStyle && item.m_bodyStyle && ( item.m_bodyStyle != aBodyStyle ) )
844 continue;
845
846 // TODO: get rid of const_cast. (It used to be a C-style cast so was less noticeable.)
847 pins.push_back( const_cast<SCH_PIN*>( static_cast<const SCH_PIN*>( &item ) ) );
848 }
849
850 return pins;
851}
852
853
854std::vector<SCH_PIN*> LIB_SYMBOL::GetAllLibPins() const
855{
856 return GetPins( 0, 0 );
857}
858
859
861{
862 return (int) GetPins( 0 /* all units */, 1 /* single body style */ ).size();
863}
864
865
866SCH_PIN* LIB_SYMBOL::GetPin( const wxString& aNumber, int aUnit, int aBodyStyle ) const
867{
868 for( SCH_PIN* pin : GetPins( aUnit, aBodyStyle ) )
869 {
870 if( aNumber == pin->GetNumber() )
871 return pin;
872 }
873
874 return nullptr;
875}
876
877
878bool LIB_SYMBOL::PinsConflictWith( const LIB_SYMBOL& aOtherPart, bool aTestNums, bool aTestNames,
879 bool aTestType, bool aTestOrientation, bool aTestLength ) const
880{
881 std::vector<SCH_PIN*> thisPinList = GetAllLibPins();
882
883 for( const SCH_PIN* eachThisPin : thisPinList )
884 {
885 wxASSERT( eachThisPin );
886 std::vector<SCH_PIN*> otherPinList = aOtherPart.GetAllLibPins();
887 bool foundMatch = false;
888
889 for( const SCH_PIN* eachOtherPin : otherPinList )
890 {
891 wxASSERT( eachOtherPin );
892
893 // Same unit?
894 if( eachThisPin->GetUnit() != eachOtherPin->GetUnit() )
895 continue;
896
897 // Same body stype?
898 if( eachThisPin->GetBodyStyle() != eachOtherPin->GetBodyStyle() )
899 continue;
900
901 // Same position?
902 if( eachThisPin->GetPosition() != eachOtherPin->GetPosition() )
903 continue;
904
905 // Same number?
906 if( aTestNums && ( eachThisPin->GetNumber() != eachOtherPin->GetNumber() ) )
907 continue;
908
909 // Same name?
910 if( aTestNames && ( eachThisPin->GetName() != eachOtherPin->GetName() ) )
911 continue;
912
913 // Same electrical type?
914 if( aTestType && ( eachThisPin->GetType() != eachOtherPin->GetType() ) )
915 continue;
916
917 // Same orientation?
918 if( aTestOrientation
919 && ( eachThisPin->GetOrientation() != eachOtherPin->GetOrientation() ) )
920 continue;
921
922 // Same length?
923 if( aTestLength && ( eachThisPin->GetLength() != eachOtherPin->GetLength() ) )
924 continue;
925
926 foundMatch = true;
927 break; // Match found so search is complete.
928 }
929
930 if( !foundMatch )
931 {
932 // This means there was not an identical (according to the arguments)
933 // pin at the same position in the other symbol.
934 return true;
935 }
936 }
937
938 // The loop never gave up, so no conflicts were found.
939 return false;
940}
941
942
943const BOX2I LIB_SYMBOL::GetUnitBoundingBox( int aUnit, int aBodyStyle,
944 bool aIgnoreHiddenFields ) const
945{
946 BOX2I bBox; // Start with a fresh BOX2I so the Merge algorithm works
947
948 for( const SCH_ITEM& item : m_drawings )
949 {
950 if( item.m_unit > 0 && m_unitCount > 1 && aUnit > 0 && aUnit != item.m_unit )
951 continue;
952
953 if( item.m_bodyStyle > 0 && aBodyStyle > 0 && aBodyStyle != item.m_bodyStyle )
954 continue;
955
956 if( aIgnoreHiddenFields && item.Type() == SCH_FIELD_T )
957 {
958 if( !static_cast<const SCH_FIELD&>( item ).IsVisible() )
959 continue;
960 }
961
962 bBox.Merge( item.GetBoundingBox() );
963 }
964
965 return bBox;
966}
967
968
969const BOX2I LIB_SYMBOL::GetBodyBoundingBox( int aUnit, int aBodyStyle, bool aIncludePins,
970 bool aIncludePrivateItems ) const
971{
972 BOX2I bbox;
973
974 for( const SCH_ITEM& item : m_drawings )
975 {
976 if( item.m_unit > 0 && aUnit > 0 && aUnit != item.m_unit )
977 continue;
978
979 if( item.m_bodyStyle > 0 && aBodyStyle > 0 && aBodyStyle != item.m_bodyStyle )
980 continue;
981
982 if( item.IsPrivate() && !aIncludePrivateItems )
983 continue;
984
985 if( item.Type() == SCH_FIELD_T )
986 continue;
987
988 if( item.Type() == SCH_PIN_T )
989 {
990 const SCH_PIN& pin = static_cast<const SCH_PIN&>( item );
991
992 if( pin.IsVisible() )
993 {
994 // Note: the roots of the pins are always included for symbols that don't have
995 // a well-defined body.
996
997 if( aIncludePins )
998 bbox.Merge( pin.GetBoundingBox( false, false, false ) );
999 else
1000 bbox.Merge( pin.GetPinRoot() );
1001 }
1002 }
1003 else
1004 {
1005 bbox.Merge( item.GetBoundingBox() );
1006 }
1007 }
1008
1009 return bbox;
1010}
1011
1012
1014{
1016}
1017
1018
1020{
1021 AddDrawItem( aField );
1022}
1023
1024
1025void LIB_SYMBOL::SetFields( const std::vector<SCH_FIELD>& aFieldsList )
1026{
1028
1029 for( const SCH_FIELD& src : aFieldsList )
1030 {
1031 // drawings is a ptr_vector, new and copy an object on the heap.
1032 SCH_FIELD* field = new SCH_FIELD( src );
1033
1034 field->SetParent( this );
1035 m_drawings.push_back( field );
1036 }
1037
1038 m_drawings.sort();
1039}
1040
1041
1042void LIB_SYMBOL::GetFields( std::vector<SCH_FIELD*>& aList )
1043{
1044 // Grab the MANDATORY_FIELDS first, in expected order given by enum MANDATORY_FIELD_T
1045 for( int id = 0; id < MANDATORY_FIELDS; ++id )
1046 aList.push_back( GetFieldById( id ) );
1047
1048 // Now grab all the rest of fields.
1049 for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1050 {
1051 SCH_FIELD* field = static_cast<SCH_FIELD*>( &item );
1052
1053 if( !field->IsMandatory() )
1054 aList.push_back( field );
1055 }
1056}
1057
1058
1059void LIB_SYMBOL::GetFields( std::vector<SCH_FIELD>& aList )
1060{
1061 // Grab the MANDATORY_FIELDS first, in expected order given by enum MANDATORY_FIELD_T
1062 for( int id = 0; id < MANDATORY_FIELDS; ++id )
1063 aList.push_back( *GetFieldById( id ) );
1064
1065 // Now grab all the rest of fields.
1066 for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1067 {
1068 SCH_FIELD* field = static_cast<SCH_FIELD*>( &item );
1069
1070 if( !field->IsMandatory() )
1071 aList.push_back( *field );
1072 }
1073}
1074
1075
1077{
1078 for( const SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1079 {
1080 SCH_FIELD* field = ( SCH_FIELD* ) &item;
1081
1082 if( field->GetId() == aId )
1083 return field;
1084 }
1085
1086 return nullptr;
1087}
1088
1089
1090SCH_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName, bool aCaseInsensitive )
1091{
1092 for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1093 {
1094 if( aCaseInsensitive )
1095 {
1096 if( static_cast<SCH_FIELD*>( &item )->GetCanonicalName().Upper() == aFieldName.Upper() )
1097 return static_cast<SCH_FIELD*>( &item );
1098 }
1099 else
1100 {
1101 if( static_cast<SCH_FIELD*>( &item )->GetCanonicalName() == aFieldName )
1102 return static_cast<SCH_FIELD*>( &item );
1103 }
1104 }
1105
1106 return nullptr;
1107}
1108
1109
1110const SCH_FIELD* LIB_SYMBOL::FindField( const wxString& aFieldName,
1111 bool aCaseInsensitive ) const
1112{
1113 for( const SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1114 {
1115 const SCH_FIELD& field = static_cast<const SCH_FIELD&>( item );
1116
1117 if( aCaseInsensitive )
1118 {
1119 if( field.GetCanonicalName().Upper() == aFieldName.Upper() )
1120 return &field;
1121 }
1122 else
1123 {
1124 if( field.GetCanonicalName() == aFieldName )
1125 return &field;
1126 }
1127 }
1128
1129 return nullptr;
1130}
1131
1132
1134{
1136 wxASSERT( field != nullptr );
1137 return *field;
1138}
1139
1140
1142{
1144 wxASSERT( field != nullptr );
1145 return *field;
1146}
1147
1148
1150{
1152 wxASSERT( field != nullptr );
1153 return *field;
1154}
1155
1156
1158{
1160 wxASSERT( field != nullptr );
1161 return *field;
1162}
1163
1164
1166{
1168 wxASSERT( field != nullptr );
1169 return *field;
1170}
1171
1172
1174{
1175 wxString refDesignator = GetFieldById( REFERENCE_FIELD )->GetText();
1176
1177 refDesignator.Replace( wxS( "~" ), wxS( " " ) );
1178
1179 wxString prefix = refDesignator;
1180
1181 while( prefix.Length() )
1182 {
1183 wxUniCharRef last = prefix.Last();
1184
1185 if( ( last >= '0' && last <= '9' ) || last == '?' || last == '*' )
1186 prefix.RemoveLast();
1187 else
1188 break;
1189 }
1190
1191 // Avoid a prefix containing trailing/leading spaces
1192 prefix.Trim( true );
1193 prefix.Trim( false );
1194
1195 return prefix;
1196}
1197
1198
1199void LIB_SYMBOL::RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction )
1200{
1201 for( SCH_ITEM& item : m_drawings )
1202 aFunction( &item );
1203}
1204
1205
1207{
1208 int retv = 0;
1209 int lastOrdinal = MANDATORY_FIELDS;
1210
1211 for( SCH_ITEM& item : m_drawings[ SCH_FIELD_T ] )
1212 {
1213 SCH_FIELD* field = static_cast<SCH_FIELD*>( &item );
1214
1215 // Mandatory fields were already resolved always have the same ordinal values.
1216 if( field->IsMandatory() )
1217 continue;
1218
1219 if( field->GetId() != lastOrdinal )
1220 {
1221 field->SetId( lastOrdinal );
1222 retv += 1;
1223 }
1224
1225 lastOrdinal += 1;
1226 }
1227
1228 return retv;
1229}
1230
1231
1233{
1234 int retv = MANDATORY_FIELDS;
1235
1236 while( GetFieldById( retv ) )
1237 retv += 1;
1238
1239 return retv;
1240}
1241
1242
1243void LIB_SYMBOL::Move( const VECTOR2I& aOffset )
1244{
1245 for( SCH_ITEM& item : m_drawings )
1246 item.Move( aOffset );
1247}
1248
1249
1251{
1252 for( const SCH_ITEM& item : m_drawings )
1253 {
1254 if( item.m_bodyStyle > BODY_STYLE::BASE )
1255 return true;
1256 }
1257
1258 if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
1259 {
1260 for( const SCH_ITEM& item : parent->GetDrawItems() )
1261 {
1262 if( item.m_bodyStyle > BODY_STYLE::BASE )
1263 return true;
1264 }
1265 }
1266
1267 return false;
1268}
1269
1270
1272{
1273 int maxPinNumber = 0;
1274 LIB_SYMBOL_SPTR parent = m_parent.lock();
1275 const LIB_ITEMS_CONTAINER& drawItems = parent ? parent->m_drawings : m_drawings;
1276
1277 for( const SCH_ITEM& item : drawItems[SCH_PIN_T] )
1278 {
1279 const SCH_PIN* pin = static_cast<const SCH_PIN*>( &item );
1280 long currentPinNumber = 0;
1281
1282 if( pin->GetNumber().ToLong( &currentPinNumber ) )
1283 maxPinNumber = std::max( maxPinNumber, (int) currentPinNumber );
1284 }
1285
1286 return maxPinNumber;
1287}
1288
1289
1291{
1293
1294 for( SCH_ITEM& item : m_drawings )
1295 item.ClearTempFlags();
1296}
1297
1298
1300{
1302
1303 for( SCH_ITEM& item : m_drawings )
1304 item.ClearEditFlags();
1305}
1306
1307
1308SCH_ITEM* LIB_SYMBOL::LocateDrawItem( int aUnit, int aBodyStyle, KICAD_T aType,
1309 const VECTOR2I& aPoint )
1310{
1311 for( SCH_ITEM& item : m_drawings )
1312 {
1313 if( ( aUnit && item.m_unit && aUnit != item.m_unit )
1314 || ( aBodyStyle && item.m_bodyStyle && aBodyStyle != item.m_bodyStyle )
1315 || ( item.Type() != aType && aType != TYPE_NOT_INIT ) )
1316 {
1317 continue;
1318 }
1319
1320 if( item.HitTest( aPoint ) )
1321 return &item;
1322 }
1323
1324 return nullptr;
1325}
1326
1327
1328SCH_ITEM* LIB_SYMBOL::LocateDrawItem( int aUnit, int aBodyStyle, KICAD_T aType,
1329 const VECTOR2I& aPoint, const TRANSFORM& aTransform )
1330{
1331 /* we use LocateDrawItem( int aUnit, int convert, KICAD_T type, const
1332 * VECTOR2I& pt ) to search items.
1333 * because this function uses DefaultTransform as orient/mirror matrix
1334 * we temporary copy aTransform in DefaultTransform
1335 */
1336 TRANSFORM transform = DefaultTransform;
1337 DefaultTransform = aTransform;
1338
1339 SCH_ITEM* item = LocateDrawItem( aUnit, aBodyStyle, aType, aPoint );
1340
1341 // Restore matrix
1342 DefaultTransform = transform;
1343
1344 return item;
1345}
1346
1347
1348INSPECT_RESULT LIB_SYMBOL::Visit( INSPECTOR aInspector, void* aTestData,
1349 const std::vector<KICAD_T>& aScanTypes )
1350{
1351 // The part itself is never inspected, only its children
1352 for( SCH_ITEM& item : m_drawings )
1353 {
1354 if( item.IsType( aScanTypes ) )
1355 {
1356 if( aInspector( &item, aTestData ) == INSPECT_RESULT::QUIT )
1357 return INSPECT_RESULT::QUIT;
1358 }
1359 }
1360
1361 return INSPECT_RESULT::CONTINUE;
1362}
1363
1364
1365void LIB_SYMBOL::SetUnitCount( int aCount, bool aDuplicateDrawItems )
1366{
1367 if( m_unitCount == aCount )
1368 return;
1369
1370 if( aCount < m_unitCount )
1371 {
1373
1374 while( i != m_drawings.end() )
1375 {
1376 if( i->m_unit > aCount )
1377 i = m_drawings.erase( i );
1378 else
1379 ++i;
1380 }
1381 }
1382 else if( aDuplicateDrawItems )
1383 {
1384 int prevCount = m_unitCount;
1385
1386 // Temporary storage for new items, as adding new items directly to
1387 // m_drawings may cause the buffer reallocation which invalidates the
1388 // iterators
1389 std::vector<SCH_ITEM*> tmp;
1390
1391 for( SCH_ITEM& item : m_drawings )
1392 {
1393 if( item.m_unit != 1 )
1394 continue;
1395
1396 for( int j = prevCount + 1; j <= aCount; j++ )
1397 {
1398 SCH_ITEM* newItem = item.Duplicate();
1399 newItem->m_unit = j;
1400 tmp.push_back( newItem );
1401 }
1402 }
1403
1404 for( SCH_ITEM* item : tmp )
1405 m_drawings.push_back( item );
1406 }
1407
1408 m_drawings.sort();
1409 m_unitCount = aCount;
1410}
1411
1412
1414{
1415 if( LIB_SYMBOL_SPTR parent = m_parent.lock() )
1416 return parent->GetUnitCount();
1417
1418 return m_unitCount;
1419}
1420
1421
1422void LIB_SYMBOL::SetHasAlternateBodyStyle( bool aHasAlternate, bool aDuplicatePins )
1423{
1424 if( aHasAlternate == HasAlternateBodyStyle() )
1425 return;
1426
1427 // Duplicate items to create the converted shape
1428 if( aHasAlternate )
1429 {
1430 if( aDuplicatePins )
1431 {
1432 std::vector<SCH_ITEM*> tmp; // Temporarily store the duplicated pins here.
1433
1434 for( SCH_ITEM& item : m_drawings[ SCH_PIN_T ] )
1435 {
1436 if( item.m_bodyStyle == 1 )
1437 {
1438 SCH_ITEM* newItem = item.Duplicate();
1439 newItem->m_bodyStyle = 2;
1440 tmp.push_back( newItem );
1441 }
1442 }
1443
1444 // Transfer the new pins to the LIB_SYMBOL.
1445 for( SCH_ITEM* item : tmp )
1446 m_drawings.push_back( item );
1447 }
1448 }
1449 else
1450 {
1451 // Delete converted shape items because the converted shape does not exist
1453
1454 while( i != m_drawings.end() )
1455 {
1456 if( i->m_bodyStyle > 1 )
1457 i = m_drawings.erase( i );
1458 else
1459 ++i;
1460 }
1461 }
1462
1463 m_drawings.sort();
1464}
1465
1466
1467std::vector<SCH_ITEM*> LIB_SYMBOL::GetUnitDrawItems( int aUnit, int aBodyStyle )
1468{
1469 std::vector<SCH_ITEM*> unitItems;
1470
1471 for( SCH_ITEM& item : m_drawings )
1472 {
1473 if( item.Type() == SCH_FIELD_T )
1474 continue;
1475
1476 if( ( aBodyStyle == -1 && item.GetUnit() == aUnit )
1477 || ( aUnit == -1 && item.GetBodyStyle() == aBodyStyle )
1478 || ( aUnit == item.GetUnit() && aBodyStyle == item.GetBodyStyle() ) )
1479 {
1480 unitItems.push_back( &item );
1481 }
1482 }
1483
1484 return unitItems;
1485}
1486
1487
1488std::vector<LIB_SYMBOL_UNIT> LIB_SYMBOL::GetUnitDrawItems()
1489{
1490 std::vector<LIB_SYMBOL_UNIT> units;
1491
1492 for( SCH_ITEM& item : m_drawings )
1493 {
1494 if( item.Type() == SCH_FIELD_T )
1495 continue;
1496
1497 int unit = item.GetUnit();
1498 int bodyStyle = item.GetBodyStyle();
1499
1500 auto it = std::find_if( units.begin(), units.end(),
1501 [unit, bodyStyle]( const LIB_SYMBOL_UNIT& a )
1502 {
1503 return a.m_unit == unit && a.m_bodyStyle == bodyStyle;
1504 } );
1505
1506 if( it == units.end() )
1507 {
1508 LIB_SYMBOL_UNIT newUnit;
1509 newUnit.m_unit = item.GetUnit();
1510 newUnit.m_bodyStyle = item.GetBodyStyle();
1511 newUnit.m_items.push_back( &item );
1512 units.emplace_back( newUnit );
1513 }
1514 else
1515 {
1516 it->m_items.push_back( &item );
1517 }
1518 }
1519
1520 return units;
1521}
1522
1523
1524
1525
1526#define REPORT( msg ) { if( aReporter ) aReporter->Report( msg ); }
1527#define ITEM_DESC( item ) ( item )->GetItemDescription( &unitsProvider, true )
1528
1529int LIB_SYMBOL::Compare( const LIB_SYMBOL& aRhs, int aCompareFlags, REPORTER* aReporter ) const
1530{
1531 UNITS_PROVIDER unitsProvider( schIUScale, EDA_UNITS::MILLIMETRES );
1532
1533 if( m_me == aRhs.m_me )
1534 return 0;
1535
1536 if( !aReporter && ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) == 0 )
1537 {
1538 if( int tmp = m_name.Cmp( aRhs.m_name ) )
1539 return tmp;
1540
1541 if( int tmp = m_libId.compare( aRhs.m_libId ) )
1542 return tmp;
1543
1544 if( m_parent.lock() < aRhs.m_parent.lock() )
1545 return -1;
1546
1547 if( m_parent.lock() > aRhs.m_parent.lock() )
1548 return 1;
1549 }
1550
1551 int retv = 0;
1552
1553 if( m_options != aRhs.m_options )
1554 {
1555 retv = ( m_options == ENTRY_NORMAL ) ? -1 : 1;
1556 REPORT( _( "Power flag differs." ) );
1557
1558 if( !aReporter )
1559 return retv;
1560 }
1561
1562 if( int tmp = m_unitCount - aRhs.m_unitCount )
1563 {
1564 retv = tmp;
1565 REPORT( _( "Unit count differs." ) );
1566
1567 if( !aReporter )
1568 return retv;
1569 }
1570
1571 // Make sure shapes and pins are sorted. No need with fields as those are
1572 // matched by id/name.
1573
1574 std::set<const SCH_ITEM*, SCH_ITEM::cmp_items> aShapes;
1575 std::set<const SCH_ITEM*> aFields;
1576 std::set<const SCH_ITEM*, SCH_ITEM::cmp_items> aPins;
1577
1578 for( auto it = m_drawings.begin(); it != m_drawings.end(); ++it )
1579 {
1580 if( it->Type() == SCH_SHAPE_T )
1581 aShapes.insert( &(*it) );
1582 else if( it->Type() == SCH_FIELD_T )
1583 aFields.insert( &(*it) );
1584 else if( it->Type() == SCH_PIN_T )
1585 aPins.insert( &(*it) );
1586 }
1587
1588 std::set<const SCH_ITEM*, SCH_ITEM::cmp_items> bShapes;
1589 std::set<const SCH_ITEM*> bFields;
1590 std::set<const SCH_ITEM*, SCH_ITEM::cmp_items> bPins;
1591
1592 for( auto it = aRhs.m_drawings.begin(); it != aRhs.m_drawings.end(); ++it )
1593 {
1594 if( it->Type() == SCH_SHAPE_T )
1595 bShapes.insert( &(*it) );
1596 else if( it->Type() == SCH_FIELD_T )
1597 bFields.insert( &(*it) );
1598 else if( it->Type() == SCH_PIN_T )
1599 bPins.insert( &(*it) );
1600 }
1601
1602 if( int tmp = static_cast<int>( aShapes.size() - bShapes.size() ) )
1603 {
1604 retv = tmp;
1605 REPORT( _( "Graphic item count differs." ) );
1606
1607 if( !aReporter )
1608 return retv;
1609 }
1610 else
1611 {
1612 for( auto aIt = aShapes.begin(), bIt = bShapes.begin(); aIt != aShapes.end(); aIt++, bIt++ )
1613 {
1614 if( int tmp2 = (*aIt)->compare( *(*bIt), aCompareFlags ) )
1615 {
1616 retv = tmp2;
1617 REPORT( wxString::Format( _( "%s differs." ), ITEM_DESC( *aIt ) ) );
1618
1619 if( !aReporter )
1620 return retv;
1621 }
1622 }
1623 }
1624
1625 if( int tmp = static_cast<int>( aPins.size() - bPins.size() ) )
1626 {
1627 retv = tmp;
1628 REPORT( _( "Pin count differs." ) );
1629
1630 if( !aReporter )
1631 return retv;
1632 }
1633 else
1634 {
1635 for( const SCH_ITEM* aPinItem : aPins )
1636 {
1637 const SCH_PIN* aPin = static_cast<const SCH_PIN*>( aPinItem );
1638 const SCH_PIN* bPin = aRhs.GetPin( aPin->GetNumber(), aPin->GetUnit(),
1639 aPin->GetBodyStyle() );
1640
1641 if( !bPin )
1642 {
1643 retv = 1;
1644 REPORT( wxString::Format( _( "Pin %s not found." ), aPin->GetNumber() ) );
1645
1646 if( !aReporter )
1647 return retv;
1648 }
1649 else if( int tmp2 = aPinItem->compare( *bPin, aCompareFlags ) )
1650 {
1651 retv = tmp2;
1652 REPORT( wxString::Format( _( "Pin %s differs." ), aPin->GetNumber() ) );
1653
1654 if( !aReporter )
1655 return retv;
1656 }
1657 }
1658 }
1659
1660 for( const SCH_ITEM* aFieldItem : aFields )
1661 {
1662 const SCH_FIELD* aField = static_cast<const SCH_FIELD*>( aFieldItem );
1663 const SCH_FIELD* bField = nullptr;
1664 int tmp = 0;
1665
1666 if( aField->IsMandatory() )
1667 bField = aRhs.GetFieldById( aField->GetId() );
1668 else
1669 bField = aRhs.FindField( aField->GetName() );
1670
1671 if( !bField )
1672 tmp = 1;
1673 else
1674 tmp = aFieldItem->compare( *bField, aCompareFlags );
1675
1676 if( tmp )
1677 {
1678 retv = tmp;
1679 REPORT( wxString::Format( _( "%s field differs." ), aField->GetName( false ) ) );
1680
1681 if( !aReporter )
1682 return retv;
1683 }
1684 }
1685
1686 if( int tmp = static_cast<int>( aFields.size() - bFields.size() ) )
1687 {
1688 retv = tmp;
1689 REPORT( _( "Field count differs." ) );
1690
1691 if( !aReporter )
1692 return retv;
1693 }
1694
1695 if( int tmp = static_cast<int>( m_fpFilters.GetCount() - aRhs.m_fpFilters.GetCount() ) )
1696 {
1697 retv = tmp;
1698 REPORT( _( "Footprint filters differs." ) );
1699
1700 if( !aReporter )
1701 return retv;
1702 }
1703 else
1704 {
1705 for( size_t i = 0; i < m_fpFilters.GetCount(); i++ )
1706 {
1707 if( int tmp2 = m_fpFilters[i].Cmp( aRhs.m_fpFilters[i] ) )
1708 {
1709 retv = tmp2;
1710 REPORT( _( "Footprint filters differ." ) );
1711
1712 if( !aReporter )
1713 return retv;
1714 }
1715 }
1716 }
1717
1718 if( int tmp = m_keyWords.Cmp( aRhs.m_keyWords ) )
1719 {
1720 retv = tmp;
1721 REPORT( _( "Symbol keywords differ." ) );
1722
1723 if( !aReporter )
1724 return retv;
1725 }
1726
1727 if( int tmp = m_pinNameOffset - aRhs.m_pinNameOffset )
1728 {
1729 retv = tmp;
1730 REPORT( _( "Symbol pin name offsets differ." ) );
1731
1732 if( !aReporter )
1733 return retv;
1734 }
1735
1736 if( ( aCompareFlags & SCH_ITEM::COMPARE_FLAGS::ERC ) == 0 )
1737 {
1738 if( m_showPinNames != aRhs.m_showPinNames )
1739 {
1740 retv = ( m_showPinNames ) ? 1 : -1;
1741 REPORT( _( "Show pin names settings differ." ) );
1742
1743 if( !aReporter )
1744 return retv;
1745 }
1746
1748 {
1749 retv = ( m_showPinNumbers ) ? 1 : -1;
1750 REPORT( _( "Show pin numbers settings differ." ) );
1751
1752 if( !aReporter )
1753 return retv;
1754 }
1755
1757 {
1758 retv = ( m_excludedFromSim ) ? -1 : 1;
1759 REPORT( _( "Exclude from simulation settings differ." ) );
1760
1761 if( !aReporter )
1762 return retv;
1763 }
1764
1766 {
1767 retv = ( m_excludedFromBOM ) ? -1 : 1;
1768 REPORT( _( "Exclude from bill of materials settings differ." ) );
1769
1770 if( !aReporter )
1771 return retv;
1772 }
1773
1775 {
1776 retv = ( m_excludedFromBoard ) ? -1 : 1;
1777 REPORT( _( "Exclude from board settings differ." ) );
1778
1779 if( !aReporter )
1780 return retv;
1781 }
1782 }
1783
1784 if( !aReporter )
1785 {
1786 if( m_unitsLocked != aRhs.m_unitsLocked )
1787 return ( m_unitsLocked ) ? 1 : -1;
1788
1789 // Compare unit display names
1791 return -1;
1792 else if( m_unitDisplayNames > aRhs.m_unitDisplayNames )
1793 return 1;
1794 }
1795
1796 return retv;
1797}
1798
1799
1800int LIB_SYMBOL::compare( const SCH_ITEM& aOther, int aCompareFlags ) const
1801{
1802 if( Type() != aOther.Type() )
1803 return Type() - aOther.Type();
1804
1805 const LIB_SYMBOL* tmp = static_cast<const LIB_SYMBOL*>( &aOther );
1806
1807 return Compare( *tmp, aCompareFlags );
1808}
1809
1810
1811double LIB_SYMBOL::Similarity( const SCH_ITEM& aOther ) const
1812{
1813 wxCHECK( aOther.Type() == LIB_SYMBOL_T, 0.0 );
1814
1815 const LIB_SYMBOL& other = static_cast<const LIB_SYMBOL&>( aOther );
1816 double similarity = 0.0;
1817 int totalItems = 0;
1818
1819 if( m_Uuid == aOther.m_Uuid )
1820 return 1.0;
1821
1822 for( const SCH_ITEM& item : m_drawings )
1823 {
1824 totalItems += 1;
1825 double max_similarity = 0.0;
1826
1827 for( const SCH_ITEM& otherItem : other.m_drawings )
1828 {
1829 double temp_similarity = item.Similarity( otherItem );
1830 max_similarity = std::max( max_similarity, temp_similarity );
1831
1832 if( max_similarity == 1.0 )
1833 break;
1834 }
1835
1836 similarity += max_similarity;
1837 }
1838
1839 for( const SCH_PIN* pin : GetAllLibPins() )
1840 {
1841 totalItems += 1;
1842 double max_similarity = 0.0;
1843
1844 for( const SCH_PIN* otherPin : other.GetAllLibPins() )
1845 {
1846 double temp_similarity = pin->Similarity( *otherPin );
1847 max_similarity = std::max( max_similarity, temp_similarity );
1848
1849 if( max_similarity == 1.0 )
1850 break;
1851 }
1852
1853 similarity += max_similarity;
1854 }
1855
1856 if( totalItems == 0 )
1857 similarity = 0.0;
1858 else
1859 similarity /= totalItems;
1860
1862 similarity *= 0.9;
1863
1865 similarity *= 0.9;
1866
1868 similarity *= 0.9;
1869
1870 if( m_flags != other.m_flags )
1871 similarity *= 0.9;
1872
1873 if( m_unitCount != other.m_unitCount )
1874 similarity *= 0.5;
1875
1876 if( m_pinNameOffset != other.m_pinNameOffset )
1877 similarity *= 0.9;
1878
1879 if( m_showPinNames != other.m_showPinNames )
1880 similarity *= 0.9;
1881
1882 if( m_showPinNumbers != other.m_showPinNumbers )
1883 similarity *= 0.9;
1884
1885 return similarity;
1886}
1887
1888
1890{
1891 return static_cast<EMBEDDED_FILES*>( this );
1892}
1893
1894
1896{
1897 return static_cast<const EMBEDDED_FILES*>( this );
1898}
1899
1900
1902{
1903 using OUTLINE_FONT = KIFONT::OUTLINE_FONT;
1904 using EMBEDDING_PERMISSION = OUTLINE_FONT::EMBEDDING_PERMISSION;
1905
1906 std::set<OUTLINE_FONT*> fonts;
1907
1908 for( SCH_ITEM& item : m_drawings )
1909 {
1910 if( item.Type() == SCH_TEXT_T )
1911 {
1912 auto* text = static_cast<SCH_TEXT*>( &item );
1913
1914 if( auto* font = text->GetFont(); font && !font->IsStroke() )
1915 {
1916 auto* outline = static_cast<OUTLINE_FONT*>( font );
1917 auto permission = outline->GetEmbeddingPermission();
1918
1919 if( permission == EMBEDDING_PERMISSION::EDITABLE
1920 || permission == EMBEDDING_PERMISSION::INSTALLABLE )
1921 {
1922 fonts.insert( outline );
1923 }
1924 }
1925 }
1926 }
1927
1928 for( auto* font : fonts )
1929 {
1930 auto file = GetEmbeddedFiles()->AddFile( font->GetFileName(), false );
1932 }
1933}
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:114
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
virtual bool IsVisible() const
Definition: eda_text.h:174
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:377
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:878
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:822
const BOX2I GetUnitBoundingBox(int aUnit, int aBodyStyle, bool aIgnoreHiddenFields=true) const
Get the bounding box for the symbol.
Definition: lib_symbol.cpp:943
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:660
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:741
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:866
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:854
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:702
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:626
void RemoveDrawItem(SCH_ITEM *aItem)
Remove draw aItem from list.
Definition: lib_symbol.cpp:783
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:969
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:860
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:808
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:1620
bool IsMandatory() const
Definition: sch_field.cpp:1508
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: sch_field.cpp:337
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:429
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:1253
int GetId() const
Definition: sch_field.h:133
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: sch_field.cpp:1228
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Definition: sch_field.cpp:211
void SetId(int aId)
Definition: sch_field.cpp:161
bool ShowInChooser() const
Definition: sch_field.h:229
void SetText(const wxString &aText) override
Definition: sch_field.cpp:1213
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
void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: sch_shape.cpp:63
STROKE_PARAMS GetStroke() const override
Definition: sch_shape.h:55
Simple container to manage line stroke parameters.
Definition: stroke_params.h:79
void SetColor(const KIGFX::COLOR4D &aColor)
Definition: stroke_params.h:96
KIGFX::COLOR4D GetColor() const
Definition: stroke_params.h:95
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:370
@ LAYER_FIELDS
Definition: layer_ids.h:366
#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