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