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