1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2014 Dick Hollenbeck, dick@softplc.com
6  * Copyright (C) 2015 Wayne Stambaugh <stambaughw@gmail.com>
7  * Copyright (C) 1992-2021 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 #ifndef __SYMBOL_H__
28 #define __SYMBOL_H__
29 
30 #include <eda_item.h>
31 #include <core/typeinfo.h>
32 #include <layer_ids.h>
33 #include <lib_id.h>
34 #include <widgets/msgpanel.h>
35 
36 #include <memory>
37 #include <string>
38 #include <unordered_map>
39 #include <vector>
40 #include <wx/arrstr.h>
41 #include <wx/chartype.h>
42 #include <wx/fdrepdlg.h>
43 #include <wx/gdicmn.h>
44 #include <wx/string.h>
45 
46 #include <sch_field.h>
47 #include <sch_item.h>
48 #include <sch_pin.h>
49 #include <sch_sheet_path.h>    // SYMBOL_INSTANCE_REFERENCE
50 #include <symbol_lib_table.h>
51 #include <transform.h>
52 
53 struct PICKED_SYMBOL;
54 class SCH_SCREEN;
55 class LIB_ITEM;
56 class LIB_PIN;
57 class LIB_SYMBOL;
58 class NETLIST_OBJECT_LIST;
59 class SYMBOL_LIB;
60 class SYMBOL_LIBS;
61 class EE_COLLECTOR;
62 class SCH_SCREEN;
63 class SYMBOL_LIB_TABLE;
64 
65 
66 /// A container for several SCH_FIELD items
67 typedef std::vector<SCH_FIELD>    SCH_FIELDS;
68 
69 typedef std::weak_ptr<LIB_SYMBOL> PART_REF;
70 
71 
72 extern std::string toUTFTildaText( const wxString& txt );
73 
74 
75 /**
76  * Schematic symbol object.
77  */
78 class SCH_SYMBOL : public SCH_ITEM
79 {
80 public:
81     SCH_SYMBOL( const wxPoint& pos = wxPoint( 0, 0 ), SCH_ITEM* aParent = nullptr );
82 
83     /**
84      * Create schematic symbol from library symbol object.
85      *
86      * @param aSymbol is the library symbol to create schematic symbol from.
87      * @param aLibId is the #LIB_ID of alias to create.
88      * @param aSheet is the schematic sheet the symbol is place into.
89      * @param unit is unit for symbols that have multiple parts per package.
90      * @param convert is the alternate body style for the schematic symbols.
91      * @param pos is the position of the symbol.
92      * @param setNewItemFlag is used to set the symbol #IS_NEW and #IS_MOVING flags.
93      */
94     SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const LIB_ID& aLibId, const SCH_SHEET_PATH* aSheet,
95                 int unit = 0, int convert = 0, const wxPoint& pos = wxPoint( 0, 0 ) );
96 
97     SCH_SYMBOL( const LIB_SYMBOL& aSymbol, const SCH_SHEET_PATH* aSheet, const PICKED_SYMBOL& aSel,
98                 const wxPoint& pos = wxPoint( 0, 0 ) );
99 
100     /**
101      * Clone \a aSymbol into a new schematic symbol object.
102      *
103      * All fields are copied as is except for the linked list management pointers
104      * which are set to NULL, and the SCH_FIELD's m_Parent pointers which are set
105      * to the new object.
106      *
107      * @param aSymbol is the schematic symbol to clone.
108      */
109     SCH_SYMBOL( const SCH_SYMBOL& aSymbol );
110 
~SCH_SYMBOL()111     ~SCH_SYMBOL() { }
112 
ClassOf(const EDA_ITEM * aItem)113     static inline bool ClassOf( const EDA_ITEM* aItem )
114     {
115         return aItem && SCH_SYMBOL_T == aItem->Type();
116     }
117 
GetClass()118     wxString GetClass() const override
119     {
120         return wxT( "SCH_SYMBOL" );
121     }
122 
GetInstanceReferences()123     const std::vector<SYMBOL_INSTANCE_REFERENCE>& GetInstanceReferences()
124     {
125         return m_instanceReferences;
126     }
127 
128     void ViewGetLayers( int aLayers[], int& aCount ) const override;
129 
130     /**
131      * Return true for items which are moved with the anchor point at mouse cursor
132      * and false for items moved with no reference to anchor.
133      *
134      * Usually return true for small items (labels, junctions) and false for items which can
135      * be large (hierarchical sheets, symbols).
136      *
137      * @note We used to try and be smart about this and return false for symbols in case
138      *       they are big.  However, this annoyed some users and we now have a preference which
139      *       controls warping on move in general, so this was switched to true for symbols.
140      *
141      * @return true for a symbol.
142      */
IsMovableFromAnchorPoint()143     bool IsMovableFromAnchorPoint() const override { return true; }
144 
145     void SetLibId( const LIB_ID& aName );
146 
GetLibId()147     const LIB_ID& GetLibId() const { return m_lib_id; }
148 
149     /**
150      * The name of the symbol in the schematic library symbol list.
151      *
152      * @note See #SCH_SCREEN::m_libSymbols
153      *
154      * The name of the schematic symbol list entry can vary from the item name in the #LIB_ID
155      * object because the library symbol may have changed so a new name has to be generated
156      * but the original symbol library link has to be preserved in order to update it from
157      * the library at some point in the future.  If this name is empty, then the library item
158      * name from #LIB_ID is used.
159      */
SetSchSymbolLibraryName(const wxString & aName)160     void SetSchSymbolLibraryName( const wxString& aName ) { m_schLibSymbolName = aName; }
161     wxString GetSchSymbolLibraryName() const;
UseLibIdLookup()162     bool UseLibIdLookup() const { return m_schLibSymbolName.IsEmpty(); }
163 
GetLibSymbolRef()164     std::unique_ptr< LIB_SYMBOL >& GetLibSymbolRef() { return m_part; }
GetLibSymbolRef()165     const std::unique_ptr< LIB_SYMBOL >& GetLibSymbolRef() const { return m_part; }
166 
167     /**
168      * Set this schematic symbol library symbol reference to \a aLibSymbol
169      *
170      * The schematic symbol object owns \a aLibSymbol and the pin list will be updated
171      * accordingly.  The #LIB_SYMBOL object can be null to clear the library symbol link
172      * as well as the pin map.  If the #LIB_SYMBOL object is not null, it must be a root
173      * symbol.  Otherwise an assertion will be raised in debug builds and the library
174      * symbol will be cleared.  The new file format will no longer require a cache
175      * library so all library symbols must be valid.
176      *
177      * @note This is the only way to publicly set the library symbol for a schematic
178      *       symbol except for the ctors that take a LIB_SYMBOL reference.  All previous
179      *       public resolvers have been deprecated.
180      *
181      * @param aLibSymbol is the library symbol to associate with this schematic symbol.
182      */
183     void SetLibSymbol( LIB_SYMBOL* aLibSymbol );
184 
185     /**
186      * Return information about the aliased parts
187      */
188     wxString GetDescription() const;
189 
190     /**
191      * Return the documentation text for the given part alias
192      */
193     wxString GetDatasheet() const;
194 
GetUnit()195     int GetUnit() const { return m_unit; }
196 
197     /**
198      * Updates the cache of SCH_PIN objects for each pin
199      */
200     void UpdatePins();
201 
202     /**
203      * Change the unit number to \a aUnit
204      *
205      * This has meaning only for symbols made up of multiple units per package.
206      *
207      * @note This also set the modified flag bit
208      *
209      * @param aUnit is the new unit to select.
210      */
211     void SetUnit( int aUnit );
212 
213     /**
214      * Change the unit number to \a aUnit without setting any internal flags.
215      * This has meaning only for symbols made up of multiple units per package.
216      *
217      * @note This also set the modified flag bit
218      *
219      * @param aUnit is the new unit to select.
220      */
221     void UpdateUnit( int aUnit );
222 
GetConvert()223     int GetConvert() const { return m_convert; }
224 
225     void SetConvert( int aConvert );
226 
GetPrefix()227     wxString GetPrefix() const { return m_prefix; }
228 
SetPrefix(const wxString & aPrefix)229     void SetPrefix( const wxString& aPrefix ) { m_prefix = aPrefix; }
230 
GetTransform()231     TRANSFORM& GetTransform() { return m_transform; }
GetTransform()232     const TRANSFORM& GetTransform() const { return m_transform; }
233 
234     void SetTransform( const TRANSFORM& aTransform );
235 
236     /**
237      * Return the number of units per package of the symbol.
238      *
239      * @return the number of units per package or zero if the library entry cannot be found.
240      */
241     int GetUnitCount() const;
242 
243     /**
244      * Compute the new transform matrix based on \a aOrientation for the symbol which is
245      * applied to the current transform.
246      *
247      * @param aOrientation is the orientation to apply to the transform.
248      */
249     void SetOrientation( int aOrientation );
250 
251     /**
252      * Get the display symbol orientation.
253      *
254      * Because there are different ways to have a given orientation/mirror,
255      * the orientation/mirror is not necessary what the user does.  For example:
256      * a mirrorV then a mirrorH returns no mirror but a rotate.  This function finds
257      * a rotation and a mirror value #SYM_MIRROR_X because this is the first mirror
258      * option tested.  This can differs from the orientation made by an user.  A
259      * #SYM_MIRROR_Y is returned as a #SYM_MIRROR_X with an orientation 180 because
260      * they are equivalent.
261      *
262      * @sa SYMBOL_ORIENTATION_T
263      *
264      * @return the orientation and mirror of the symbol.
265      */
266     int GetOrientation();
267 
268     /**
269      * Return the list of system text vars & fields for this symbol.
270      */
271     void GetContextualTextVars( wxArrayString* aVars ) const;
272 
273     /**
274      * Resolve any references to system tokens supported by the symbol.
275      *
276      * @param aDepth a counter to limit recursion and circular references.
277      */
278     bool ResolveTextVar( wxString* token, int aDepth = 0 ) const;
279 
280     void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
281 
282     /**
283      * Clear exiting symbol annotation.
284      *
285      * For example, IC23 would be changed to IC? and unit number would be reset.
286      *
287      * @param aSheetPath is the hierarchical path of the symbol to clear or remove all
288      *                   annotations for this symbol if NULL.
289      */
290     void ClearAnnotation( const SCH_SHEET_PATH* aSheetPath );
291 
292     /**
293      * Add an instance to the alternate references list (m_instanceReferences), if this entry
294      * does not already exist.
295      *
296      * Do nothing if already exists. In symbol lists shared by more than one sheet path, an
297      * entry for each sheet path must exist to manage references.
298      *
299      * @param aSheetPath is the candidate sheet path of the sheet containing the symbol not the
300      *                   full symbol sheet path.
301      * @return false if the alternate reference was existing, true if added.
302      */
303     bool AddSheetPathReferenceEntryIfMissing( const KIID_PATH& aSheetPath );
304 
305     /**
306      * Replace \a aOldSheetPath with \a aNewSheetPath in the instance list.
307      *
308      * @param aOldSheetPath is a #KIID_PATH object of an existing path in the instance list.
309      * @param aNewSheetPath is a #KIID_PATH object of the path to replace the existing path.
310      *
311      * @return true if \a aOldSheetPath was found and replaced or false if \a aOldSheetPath was
312      *         not found in the instance list.
313      */
314     bool ReplaceInstanceSheetPath( const KIID_PATH& aOldSheetPath, const KIID_PATH& aNewSheetPath );
315 
316     const EDA_RECT GetBoundingBox() const override;
317 
318     /**
319      * Return a bounding box for the symbol body but not the pins or fields.
320      */
321     EDA_RECT GetBodyBoundingBox() const;
322 
323     /**
324      * Return a bounding box for the symbol body and pins but not the fields.
325      */
326     EDA_RECT GetBodyAndPinsBoundingBox() const;
327 
328 
329     //-----<Fields>-----------------------------------------------------------
330 
331     /**
332      * Return a mandatory field in this symbol.
333      *
334      * @note If you need to fetch a user field, use GetFieldById.
335      *
336      * @param aFieldType is one of the mandatory field types (REFERENCE_FIELD, VALUE_FIELD, etc.).
337      * @return is the field at \a aFieldType or NULL if the field does not exist.
338      */
339     SCH_FIELD* GetField( MANDATORY_FIELD_T aFieldType );
340     const SCH_FIELD* GetField( MANDATORY_FIELD_T aFieldNdx ) const;
341 
342     /**
343      * Return a field in this symbol.
344      *
345      * @param aFieldId is the id of the field requested.  Note that this id ONLY SOMETIMES equates
346      *                 to the field's position in the vector.
347      * @return is the field at \a aFieldType or NULL if the field does not exist.
348      */
349     SCH_FIELD* GetFieldById( int aFieldId );
350 
351     /**
352      * Search for a field named \a aFieldName and returns text associated with this field.
353      *
354      * @param aFieldName is the name of the field
355      */
356     wxString GetFieldText( const wxString& aFieldName, SCH_EDIT_FRAME* aFrame ) const;
357 
358     /**
359      * Populate a std::vector with SCH_FIELDs.
360      *
361      * @param aVector is the vector to populate.
362      * @param aVisibleOnly is used to add only the fields that are visible and contain text.
363      */
364     void GetFields( std::vector<SCH_FIELD*>& aVector, bool aVisibleOnly );
365 
366     /**
367      * Return a vector of fields from the symbol
368      */
GetFields()369     std::vector<SCH_FIELD>& GetFields() { return m_fields; }
GetFields()370     const std::vector<SCH_FIELD>& GetFields() const { return m_fields; }
371 
372     /**
373      * Add a field to the symbol.
374      *
375      * @param aField is the field to add to this symbol.
376      *
377      * @return the newly inserted field.
378      */
379     SCH_FIELD* AddField( const SCH_FIELD& aField );
380 
381     /**
382      * Remove a user field from the symbol.
383      * @param aFieldName is the user fieldName to remove.  Attempts to remove a mandatory
384      *                   field or a non-existant field are silently ignored.
385      */
386     void RemoveField( const wxString& aFieldName );
387 
388     /**
389      * Search for a #SCH_FIELD with \a aFieldName
390      *
391      * @param aFieldName is the name of the field to find.
392      * @param aIncludeDefaultFields searches the library symbol default fields if true.
393      *
394      * @return the field if found or NULL if the field was not found.
395      */
396     SCH_FIELD* FindField( const wxString& aFieldName, bool aIncludeDefaultFields = true );
397 
398     /**
399      * Set multiple schematic fields.
400      *
401      * @param aFields are the fields to set in this symbol.
402      */
SetFields(const SCH_FIELDS & aFields)403     void SetFields( const SCH_FIELDS& aFields )
404     {
405         m_fields = aFields;     // vector copying, length is changed possibly
406     }
407 
408     /**
409      * Restore fields to the original library values.
410      *
411      * @param aUpdateStyle selects whether fields should update the position and text attributes.
412      * @param aUpdateRef selects whether the reference field should be updated.
413      * @param aUpdateOtherFields selects whether non-reference fields should be updated.
414      * @param aResetRef selects whether the reference should be reset to the library value.
415      * @param aResetOtherFields selects whether non-reference fields should be reset to library
416      *                          values.
417      */
418     void UpdateFields( const SCH_SHEET_PATH* aPath, bool aUpdateStyle, bool aUpdateRef,
419                        bool aUpdateOtherFields, bool aResetRef, bool aResetOtherFields );
420 
421     /**
422      * Return the number of fields in this symbol.
423      */
GetFieldCount()424     int GetFieldCount() const { return (int)m_fields.size(); }
425 
426     /**
427      * Automatically orient all the fields in the symbol.
428      *
429      * @param aScreen is the SCH_SCREEN associated with the current instance of the
430      *                symbol. This can be NULL when aManual is false.
431      * @param aManual should be true if the autoplace was manually initiated (e.g. by a hotkey
432      *                or a menu item). Some more 'intelligent' routines will be used that would be
433      *                annoying if done automatically during moves.
434      */
435     void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) override;
436 
437     void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override;
438 
439 
440     //-----</Fields>----------------------------------------------------------
441 
442 
443     /**
444      * Find a symbol pin by number.
445      *
446      * @param number is the number of the pin to find.
447      * @return Pin object if found, otherwise NULL.
448      */
449     SCH_PIN* GetPin( const wxString& number ) const;
450 
451     /**
452      * Populate a vector with all the pins from the library object.
453      *
454      * @param aPinsList is the list to populate with all of the pins.
455      */
456     void GetLibPins( std::vector<LIB_PIN*>& aPinsList ) const;
457 
458     SCH_PIN* GetPin( LIB_PIN* aLibPin );
459 
460     /**
461      * Retrieve a list of the SCH_PINs for the given sheet path.
462      *
463      * Since a symbol can have a different unit on a different instance of a sheet,
464      * this list returns the subset of pins that exist on a given sheet.
465      *
466      * @return a vector of pointers (non-owning) to SCH_PINs
467      */
468     std::vector<SCH_PIN*> GetPins( const SCH_SHEET_PATH* aSheet = nullptr ) const;
469 
GetRawPins()470     std::vector<std::unique_ptr<SCH_PIN>>& GetRawPins() { return m_pins; }
471 
472     /**
473      * Print a symbol.
474      *
475      * @param aDC is the device context (can be null).
476      * @param aOffset is the drawing offset (usually wxPoint(0,0), but can be different when
477      *                moving an object)
478      */
479     void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override;
480 
481     void SwapData( SCH_ITEM* aItem ) override;
482 
483     /**
484      * Test for an acceptable reference string.
485      *
486      * An acceptable reference string must support unannotation i.e starts by letter
487      *
488      * @param aReferenceString is the reference string to validate
489      * @return true if reference string is valid.
490      */
491     static bool IsReferenceStringValid( const wxString& aReferenceString );
492 
493     /**
494      * Return the reference for the given sheet path.
495      *
496      * @return the reference for the sheet.
497      */
498     const wxString GetRef( const SCH_SHEET_PATH* aSheet, bool aIncludeUnit = false ) const;
499 
500     /**
501      * Set the reference for the given sheet path for this symbol.
502      *
503      * @param aSheet is the hierarchical path of the reference.
504      * @param aReference is the new reference for the symbol.
505      */
506     void SetRef( const SCH_SHEET_PATH* aSheet, const wxString& aReference );
507 
508     /**
509      * Check if the symbol has a valid annotation (reference) for the given sheet path.
510      *
511      * @param aSheet is the sheet path to test.
512      * @return true if the symbol exists on that sheet and has a valid reference.
513      */
514     bool IsAnnotated( const SCH_SHEET_PATH* aSheet );
515 
516     /**
517      * Add a full hierarchical reference to this symbol.
518      *
519      * @param aPath is the hierarchical path (/&ltsheet timestamp&gt/&ltsymbol
520      *              timestamp&gt like /05678E50/A23EF560).
521      * @param aRef is the local reference like C45, R56.
522      * @param aUnit is the unit selection used for symbols with multiple units per package.
523      * @param aValue is the value used for this instance.
524      * @param aFootprint is the footprint used for this instance (which might have different
525      *                   hole spacing or other board-specific changes from other instances).
526      */
527     void AddHierarchicalReference( const KIID_PATH& aPath,
528                                    const wxString&  aRef,
529                                    int              aUnit,
530                                    const wxString&  aValue = wxEmptyString,
531                                    const wxString&  aFootprint = wxEmptyString );
532 
533     /// Return the instance-specific unit selection for the given sheet path.
534     int GetUnitSelection( const SCH_SHEET_PATH* aSheet ) const;
535 
536     /// Set the selected unit of this symbol on one sheet.
537     void SetUnitSelection( const SCH_SHEET_PATH* aSheet, int aUnitSelection );
538 
539     /// Set the selected unit of this symbol for all sheets.
540     void SetUnitSelection( int aUnitSelection );
541 
542     /// Return the instance-specific value for the given sheet path.
543     const wxString GetValue( const SCH_SHEET_PATH* sheet, bool aResolve ) const;
544     void SetValue( const SCH_SHEET_PATH* sheet, const wxString& aValue );
545 
546     /// Set the value for all instances (the default GUI behavior).
SetValue(const wxString & aValue)547     void SetValue( const wxString& aValue )
548     {
549         SetValue( nullptr, aValue );
550     }
551 
552     /// Return the instance-specific footprint assignment for the given sheet path.
553     const wxString GetFootprint( const SCH_SHEET_PATH* sheet, bool aResolve ) const;
554     void SetFootprint( const SCH_SHEET_PATH* sheet, const wxString& aFootprint );
555 
556     /// Set the value for all instances (the default GUI behavior).
SetFootprint(const wxString & aFootprint)557     void SetFootprint( const wxString& aFootprint )
558     {
559         SetFootprint( nullptr, aFootprint );
560     }
561 
562     // Geometric transforms (used in block operations):
563 
Move(const wxPoint & aMoveVector)564     void Move( const wxPoint& aMoveVector ) override
565     {
566         if( aMoveVector == wxPoint( 0, 0 ) )
567             return;
568 
569         m_pos += aMoveVector;
570 
571         for( SCH_FIELD& field : m_fields )
572             field.Move( aMoveVector );
573 
574         SetModified();
575     }
576 
577     void MirrorHorizontally( int aCenter ) override;
578     void MirrorVertically( int aCenter ) override;
579     void Rotate( const wxPoint& aCenter ) override;
580 
581     bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override;
582 
583     void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override;
584 
585     /**
586      * Test if the symbol's dangling state has changed for all pins.
587      *
588      * As a side effect, actually update the dangling status for all pins.
589      *
590      * @note This does not test for  short circuits.
591      *
592      * @param aItemList is list of all #DANGLING_END_ITEM items to be tested.
593      * @return true if any pin's state has changed.
594      */
595     bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
596                               const SCH_SHEET_PATH* aPath = nullptr ) override;
597 
598     wxPoint GetPinPhysicalPosition( const LIB_PIN* Pin ) const;
599 
IsConnectable()600     bool IsConnectable() const override { return true; }
601 
CanConnect(const SCH_ITEM * aItem)602     bool CanConnect( const SCH_ITEM* aItem ) const override
603     {
604         return ( aItem->Type() == SCH_LINE_T && aItem->GetLayer() == LAYER_WIRE ) ||
605                 ( aItem->Type() == SCH_NO_CONNECT_T ) ||
606                 ( aItem->Type() == SCH_JUNCTION_T ) ||
607                 ( aItem->Type() == SCH_SYMBOL_T ) ||
608                 ( aItem->Type() == SCH_LABEL_T ) ||
609                 ( aItem->Type() == SCH_HIER_LABEL_T ) ||
610                 ( aItem->Type() == SCH_GLOBAL_LABEL_T );
611     }
612 
613     /**
614      * @return true if the symbol is in netlist.
615      */
616     bool IsInNetlist() const;
617 
618     std::vector<wxPoint> GetConnectionPoints() const override;
619 
620     SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
621 
622     /**
623      * Return the symbol library item at \a aPosition that is part of this symbol.
624      *
625      * @param aPosition is the schematic position of the symbol library object.
626      * @param aType is the type of symbol library object to find or any if set to TYPE_NOT_INIT.
627      * @return is the symbol library object if found otherwise NULL.
628      */
629     LIB_ITEM* GetDrawItem( const wxPoint& aPosition, KICAD_T aType = TYPE_NOT_INIT );
630 
631     wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
632 
633     BITMAPS GetMenuImage() const override;
634 
635     bool operator <( const SCH_ITEM& aItem ) const override;
636 
637     bool operator==( const SCH_SYMBOL& aSymbol) const;
638     bool operator!=( const SCH_SYMBOL& aSymbol) const;
639 
640     SCH_SYMBOL& operator=( const SCH_ITEM& aItem );
641 
IsReplaceable()642     bool IsReplaceable() const override { return true; }
643 
GetPosition()644     wxPoint GetPosition() const override { return m_pos; }
SetPosition(const wxPoint & aPosition)645     void SetPosition( const wxPoint& aPosition ) override { Move( aPosition - m_pos ); }
646 
647     bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
648     bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
649 
650     void Plot( PLOTTER* aPlotter ) const override;
651 
652     EDA_ITEM* Clone() const override;
653 
654 #if defined(DEBUG)
655     void Show( int nestLevel, std::ostream& os ) const override;
656 #endif
657 
658     void ClearBrightenedPins();
659 
660     bool HasBrightenedPins();
661 
GetIncludeInBom()662     bool GetIncludeInBom() const { return m_inBom; }
SetIncludeInBom(bool aIncludeInBom)663     void SetIncludeInBom( bool aIncludeInBom ) { m_inBom = aIncludeInBom; }
664 
GetIncludeOnBoard()665     bool GetIncludeOnBoard() const { return m_onBoard; }
SetIncludeOnBoard(bool aIncludeOnBoard)666     void SetIncludeOnBoard( bool aIncludeOnBoard ) { m_onBoard = aIncludeOnBoard; }
667 
668     bool IsPointClickableAnchor( const wxPoint& aPos ) const override;
669 
670 private:
671     EDA_RECT doGetBoundingBox( bool aIncludePins, bool aIncludeFields ) const;
672 
673     bool doIsConnected( const wxPoint& aPosition ) const override;
674 
675     void Init( const wxPoint& pos = wxPoint( 0, 0 ) );
676 
677     wxPoint     m_pos;
678     LIB_ID      m_lib_id;       ///< Name and library the symbol was loaded from, i.e. 74xx:74LS00.
679     int         m_unit;         ///< The unit for multiple part per package symbols.
680     int         m_convert;      ///< The alternate body style for symbols that have more than
681                                 ///<   one body style defined.  Primarily used for symbols that
682                                 ///<   have a De Morgan conversion.
683     wxString    m_prefix;       ///< C, R, U, Q etc - the first character(s) which typically
684                                 ///<   indicate what the symbol is. Determined, upon placement,
685                                 ///<   from the library symbol.  Created upon file load, by the
686                                 ///<   first non-digits in the reference fields.
687 
688     /**
689      * The name used to look up a symbol in the symbol library embedded in a schematic.
690      *
691      * By default this is the same as #LIB_ID::GetLibItemName().  However, schematics allow for
692      * multiple variants of the same library symbol.  Set this member in order to preserve the
693      * link to the original symbol library.  If empty, #LIB_ID::GetLibItemName() should be used.
694      */
695     wxString    m_schLibSymbolName;
696 
697     TRANSFORM   m_transform;    ///< The rotation/mirror transformation matrix.
698     SCH_FIELDS  m_fields;       ///< Variable length list of fields.
699 
700     std::unique_ptr< LIB_SYMBOL >          m_part;    // a flattened copy of the LIB_SYMBOL from
701                                                       // the PROJECT's libraries.
702     std::vector<std::unique_ptr<SCH_PIN>>  m_pins;    // a SCH_PIN for every LIB_PIN (all units)
703     std::unordered_map<LIB_PIN*, unsigned> m_pinMap;  // library pin pointer to SCH_PIN's index
704 
705     bool        m_isInNetlist;  ///< True if the symbol should appear in the netlist
706     bool        m_inBom;        ///< True to include in bill of materials export.
707     bool        m_onBoard;      ///< True to include in netlist when updating board.
708 
709     // Defines the hierarchical path and reference of the symbol.  This allows support
710     // for multiple references to a single sub-sheet.
711     std::vector<SYMBOL_INSTANCE_REFERENCE> m_instanceReferences;
712 };
713 
714 #endif /* __SYMBOL_H__ */
715