KiCad PCB EDA Suite
class_libentry.h
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 <stambaughw@gmail.com>
6  * Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
30 #ifndef CLASS_LIBENTRY_H
31 #define CLASS_LIBENTRY_H
32 
33 #include <general.h>
34 #include <lib_tree_item.h>
35 #include <lib_item.h>
36 #include <lib_field.h>
37 #include <vector>
38 #include <multivector.h>
39 
40 class EDA_RECT;
41 class LINE_READER;
42 class OUTPUTFORMATTER;
43 class PART_LIB;
44 class LIB_PART;
45 class LIB_FIELD;
47 
48 
49 typedef std::shared_ptr<LIB_PART> PART_SPTR;
50 typedef std::weak_ptr<LIB_PART> PART_REF;
53 
54 
55 /* values for member .m_options */
57 {
58  ENTRY_NORMAL, // Libentry is a standard part (real or alias)
59  ENTRY_POWER // Libentry is a power symbol
60 };
61 
62 
63 extern bool operator<( const LIB_PART& aItem1, const LIB_PART& aItem2 );
64 
65 
67 {
68  TRANSFORM transform; // Coordinate adjustment settings
69  bool draw_visible_fields; // Whether to draw "visible" fields
70  bool draw_hidden_fields; // Whether to draw "hidden" fields
71  bool show_elec_type; // Whether to show the pin electrical type
72 
74  {
76  draw_visible_fields = true;
77  draw_hidden_fields = true;
78  show_elec_type = false;
79  }
80 };
81 
82 
83 struct PART_UNITS
84 {
85  int m_unit;
86  int m_convert;
87  std::vector<LIB_ITEM*> m_items;
88 };
89 
90 
97 class LIB_PART : public EDA_ITEM, public LIB_TREE_ITEM
98 {
102 
104 
106  bool m_unitsLocked;
108  bool m_showPinNames;
115  wxArrayString m_FootprintList;
118  wxString m_name;
119  wxString m_description;
120  wxString m_keyWords;
121 
122  static int m_subpartIdSeparator;
123  static int m_subpartFirstId;
126  void deleteAllFields();
129 
130 public:
131 
132  LIB_PART( const wxString& aName, LIB_PART* aParent = nullptr, PART_LIB* aLibrary = nullptr );
133 
137  LIB_PART( const LIB_PART& aPart, PART_LIB* aLibrary = NULL );
138 
139  virtual ~LIB_PART();
140 
141  PART_SPTR SharedPtr() { return m_me; }
142 
143 private:
144  // We create a different set parent function for this class, so we hide
145  // the inherited one.
146  using EDA_ITEM::SetParent;
147 
148 public:
149 
150  void SetParent( LIB_PART* aParent = nullptr );
151  PART_REF& GetParent() { return m_parent; }
152 
153  virtual wxString GetClass() const override
154  {
155  return wxT( "LIB_PART" );
156  }
157 
158  virtual void SetName( const wxString& aName );
159  wxString GetName() const override { return m_name; }
160 
161  LIB_ID GetLibId() const override { return m_libId; }
162  void SetLibId( const LIB_ID& aLibId ) { m_libId = aLibId; }
163 
164  wxString GetLibNickname() const override { return GetLibraryName(); }
165 
166  void SetDescription( const wxString& aDescription )
167  {
168  m_description = aDescription;
169  }
170 
171  wxString GetDescription() override { return m_description; }
172 
173  void SetKeyWords( const wxString& aKeyWords )
174  {
175  m_keyWords = aKeyWords;
176  }
177 
178  wxString GetKeyWords() const { return m_keyWords; }
179 
180  wxString GetSearchText() override;
181 
185  bool IsRoot() const override { return m_parent.use_count() == 0; }
186  bool IsAlias() const { return !m_parent.expired() && m_parent.use_count() > 0; }
187 
188  const wxString GetLibraryName() const;
189 
190  PART_LIB* GetLib() { return m_library; }
191  void SetLib( PART_LIB* aLibrary ) { m_library = aLibrary; }
192 
194 
195  wxArrayString GetFootprints() const { return m_FootprintList; }
196  void SetFootprintFilters( const wxArrayString& aFootprintFilters )
197  {
198  m_FootprintList = aFootprintFilters;
199  }
200 
201  void ViewGetLayers( int aLayers[], int& aCount ) const override;
202 
213  const EDA_RECT GetUnitBoundingBox( int aUnit, int aConvert ) const;
214 
225  const EDA_RECT GetBodyBoundingBox( int aUnit, int aConvert ) const;
226 
227  const EDA_RECT GetBoundingBox() const override
228  {
229  return GetUnitBoundingBox( 0, 0 );
230  }
231 
232  bool IsPower() const { return m_options == ENTRY_POWER; }
233  bool IsNormal() const { return m_options == ENTRY_NORMAL; }
234 
237 
242  void LockUnits( bool aLockUnits ) { m_unitsLocked = aLockUnits; }
243 
248  bool UnitsLocked() const { return m_unitsLocked; }
249 
259  void SetFields( const std::vector <LIB_FIELD>& aFieldsList );
260 
266  void GetFields( LIB_FIELDS& aList );
267 
272  LIB_FIELD* FindField( const wxString& aFieldName );
273 
274  const LIB_FIELD* FindField( const wxString& aFieldName ) const;
275 
282  LIB_FIELD* GetField( int aId ) const;
283 
286 
289 
292 
295 
304  void Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, int aMulti, int aConvert,
305  const PART_DRAW_OPTIONS& aOpts );
306 
318  void Plot( PLOTTER* aPlotter, int aUnit, int aConvert, const wxPoint& aOffset,
319  const TRANSFORM& aTransform );
320 
331  void PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert, const wxPoint& aOffset,
332  const TRANSFORM& aTransform );
333 
339  void AddDrawItem( LIB_ITEM* aItem );
340 
346  void RemoveDrawItem( LIB_ITEM* aItem );
347 
358 
359  size_t GetPinCount() const { return m_drawings.size( LIB_PIN_T ); }
360 
371  {
372  return (LIB_PIN*) GetNextDrawItem( (LIB_ITEM*) aItem, LIB_PIN_T );
373  }
374 
375 
389  void GetPins( LIB_PINS& aList, int aUnit = 0, int aConvert = 0 );
390 
401  LIB_PIN* GetPin( const wxString& aNumber, int aUnit = 0, int aConvert = 0 );
402 
415  bool PinsConflictWith( LIB_PART& aOtherPart, bool aTestNums, bool aTestNames,
416  bool aTestType, bool aTestOrientation, bool aTestLength );
417 
423  void SetOffset( const wxPoint& aOffset );
424 
429 
435  bool HasConversion() const;
436 
440  void ClearTempFlags();
441  void ClearEditFlags();
451  LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, const wxPoint& aPoint );
452 
463  LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, const wxPoint& aPoint,
464  const TRANSFORM& aTransform );
465 
472 
473  SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
474 
486  void SetUnitCount( int aCount, bool aDuplicateDrawItems = true );
487  int GetUnitCount() const override;
488 
492  wxString GetUnitReference( int aUnit ) override;
493 
498  bool IsMulti() const { return m_unitCount > 1; }
499 
508  static wxString SubReference( int aUnit, bool aAddSeparator = true );
509 
510  // Accessors to sub ref parameters
512 
516  static int* SubpartIdSeparatorPtr() { return &m_subpartIdSeparator; }
517  static int GetSubpartFirstId() { return m_subpartFirstId; }
518 
521  static int* SubpartFirstIdPtr() { return &m_subpartFirstId; }
522 
533  static void SetSubpartIdNotation( int aSep, int aFirstId );
534 
547  void SetConversion( bool aSetConvert, bool aDuplicatePins = true );
548 
556  void SetPinNameOffset( int aOffset ) { m_pinNameOffset = aOffset; }
558 
564  void SetShowPinNames( bool aShow ) { m_showPinNames = aShow; }
565  bool ShowPinNames() { return m_showPinNames; }
566 
572  void SetShowPinNumbers( bool aShow ) { m_showPinNumbers = aShow; }
573  bool ShowPinNumbers() { return m_showPinNumbers; }
574 
584  int Compare( const LIB_PART& aRhs ) const;
585 
586  bool operator==( const LIB_PART* aPart ) const { return this == aPart; }
587  bool operator==( const LIB_PART& aPart ) const { return Compare( aPart ) == 0; }
588  bool operator!=( const LIB_PART& aPart ) const { return Compare( aPart ) != 0; }
589 
590  const LIB_PART& operator=( const LIB_PART& aPart );
591 
599  std::unique_ptr< LIB_PART > Flatten() const;
600 
607  std::vector<struct PART_UNITS> GetUnitDrawItems();
608 
617  std::vector<struct PART_UNITS> GetUniqueUnits();
618 
629  std::vector<LIB_ITEM*> GetUnitItems( int aUnit, int aConvert );
630 
631 #if defined(DEBUG)
632  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
633 #endif
634 };
635 
636 #endif // CLASS_LIBENTRY_H
timestamp_t m_dateLastEdition
Date of the last modification.
PART_LIB * GetLib()
LIB_FIELD & GetFootprintField()
Return reference to the footprint field.
void SetLib(PART_LIB *aLibrary)
bool PinsConflictWith(LIB_PART &aOtherPart, bool aTestNums, bool aTestNames, bool aTestType, bool aTestOrientation, bool aTestLength)
Return true if this part's pins do not match another part's pins.
static int m_subpartIdSeparator
the separator char between the subpart id and the reference like U1A ( m_subpartIdSeparator = 0 ) or ...
LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived to re...
Definition: richio.h:81
static int * SubpartFirstIdPtr()
return a reference to m_subpartFirstId, only for read/save setting functions
void SetPower()
virtual ~LIB_PART()
LIB_ID GetLibId() const override
LIB_FIELD & GetDatasheetField()
Return reference to the datasheet field.
int GetPinNameOffset()
bool m_showPinNumbers
Determines if part pin numbers are visible.
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
wxString GetName() const override
const wxString GetLibraryName() const
MULTIVECTOR< LIB_ITEM, LIB_ARC_T, LIB_FIELD_T > LIB_ITEMS_CONTAINER
bool HasConversion() const
Test if part has more than one body conversion type (DeMorgan).
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_item.h:55
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints).
Definition: lib_tree_item.h:39
timestamp_t GetDateLastEdition() const
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
int m_unitCount
Number of units (parts) per package.
wxString GetLibNickname() const override
LIB_ITEM * GetNextDrawItem(LIB_ITEM *aItem=NULL, KICAD_T aType=TYPE_NOT_INIT)
Return the next draw object pointer.
PART_LIB * m_library
Library the part belongs to if any.
bool operator==(const LIB_PART *aPart) const
Field object used in symbol libraries.
Definition: lib_field.h:59
void SetUnitCount(int aCount, bool aDuplicateDrawItems=true)
Set the units per part count.
std::weak_ptr< LIB_PART > PART_REF
weak pointer to LIB_PART
static int m_subpartFirstId
the ASCII char value to calculate the subpart symbol id from the part number: only 'A',...
void SetFootprintFilters(const wxArrayString &aFootprintFilters)
std::vector< struct PART_UNITS > GetUnitDrawItems()
Return a list of LIB_ITEM objects separated by unit and convert number.
LIB_ITEMS_CONTAINER m_drawings
Drawing items of this part.
std::vector< LIB_ITEM * > m_items
The items unique to this unit and alternate body style.
LIB_FIELD & GetValueField()
Return reference to the value field.
bool operator==(const LIB_PART &aPart) const
TRANSFORM DefaultTransform
int Compare(const LIB_PART &aRhs) const
Comparison test that can be used for operators.
OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a convenient ...
Definition: richio.h:327
bool IsNormal() const
wxString GetKeyWords() const
int m_unit
The unit number.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
LIBRENTRYOPTIONS m_options
Special part features such as POWER or NORMAL.)
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
bool m_unitsLocked
True if part has multiple units and changing one unit does not automatically change another unit.
void ClearTempFlags()
Clears the status flag all draw objects in this part.
virtual void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:196
The base class for drawable items used by schematic library components.
Definition: lib_item.h:61
std::vector< struct PART_UNITS > GetUniqueUnits()
Return a list of unit numbers that are unique to this symbol.
LIB_ITEMS_CONTAINER::ITEM_PTR_VECTOR LIB_ITEMS
void PlotLibFields(PLOTTER *aPlotter, int aUnit, int aConvert, const wxPoint &aOffset, const TRANSFORM &aTransform)
Plot Lib Fields only of the part to plotter.
void SetOffset(const wxPoint &aOffset)
Move the part aOffset.
void AddDrawItem(LIB_ITEM *aItem)
Add a new draw aItem to the draw object list.
void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
int m_pinNameOffset
The offset in mils to draw the pin name.
void GetPins(LIB_PINS &aList, int aUnit=0, int aConvert=0)
Return a list of pin object pointers from the draw item list.
const INSPECTOR_FUNC & INSPECTOR
Definition: base_struct.h:105
bool ShowPinNames()
void deleteAllFields()
PART_REF m_parent
Use for inherited symbols.
static int GetSubpartIdSeparator()
bool ShowPinNumbers()
std::vector< LIB_ITEM * > GetUnitItems(int aUnit, int aConvert)
Return a list of item pointers for aUnit and aConvert for this symbol.
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
void SetConversion(bool aSetConvert, bool aDuplicatePins=true)
Set or clear the alternate body style (DeMorgan) for the part.
LIB_FIELD & GetReferenceField()
Return reference to the reference designator field.
virtual wxString GetClass() const override
Function GetClass returns the class name.
void Plot(PLOTTER *aPlotter, int aUnit, int aConvert, const wxPoint &aOffset, const TRANSFORM &aTransform)
Plot lib part to plotter.
LIB_FIELD * FindField(const wxString &aFieldName)
Find a field within this part matching aFieldName and returns it or NULL if not found.
#define NULL
int GetUnitCount() const override
For items with units, return the number of units.
wxString m_name
Symbol name.
static int GetSubpartFirstId()
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
std::shared_ptr< LIB_PART > PART_SPTR
shared pointer to LIB_PART
void SetDescription(const wxString &aDescription)
bool operator<(const LIB_PART &aItem1, const LIB_PART &aItem2)
PART_SPTR SharedPtr()
void SetParent(LIB_PART *aParent=nullptr)
PART_REF & GetParent()
Define a library symbol object.
wxString GetDescription() override
LIB_PART(const wxString &aName, LIB_PART *aParent=nullptr, PART_LIB *aLibrary=nullptr)
size_t GetPinCount() const
void RemoveDuplicateDrawItems()
Remove duplicate draw items from list.
wxArrayString m_FootprintList
List of suitable footprint names for the part (wild card names accepted).
std::unique_ptr< LIB_PART > Flatten() const
Return a flattened symbol inheritance to the caller.
wxArrayString GetFootprints() const
LIB_ID m_libId
LIB_PIN * GetNextPin(LIB_PIN *aItem=NULL)
Return the next pin object from the draw list.
int m_convert
The alternate body style of the unit.
wxString GetUnitReference(int aUnit) override
Return an identifier for aUnit for symbols with units.
Base plotter engine class.
Definition: plotter.h:114
bool IsPower() const
void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
static void SetSubpartIdNotation(int aSep, int aFirstId)
Set the separator char between the subpart id and the reference 0 (no separator) or '.
void ClearEditFlags()
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:218
void SetKeyWords(const wxString &aKeyWords)
bool IsAlias() const
const EDA_RECT GetUnitBoundingBox(int aUnit, int aConvert) const
Get the bounding box for the symbol.
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
static wxString SubReference(int aUnit, bool aAddSeparator=true)
LIBRENTRYOPTIONS
static int * SubpartIdSeparatorPtr()
return a reference to m_subpartIdSeparator, only for read/save setting functions
wxString GetSearchText() override
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
bool IsMulti() const
SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[]) override
Function Visit may be re-implemented for each derived class in order to handle all the types given by...
boost::ptr_vector< LIB_ITEM > ITEM_PTR_VECTOR
Helper for defining a list of library draw object pointers.
Definition: multivector.h:51
LIB_ITEM * LocateDrawItem(int aUnit, int aConvert, KICAD_T aType, const wxPoint &aPoint)
Locate a draw object.
const LIB_PART & operator=(const LIB_PART &aPart)
virtual void SetName(const wxString &aName)
wxString m_keyWords
keyword list (used for search for parts by keyword)
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:56
void Print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset, int aMulti, int aConvert, const PART_DRAW_OPTIONS &aOpts)
Print part.
bool operator!=(const LIB_PART &aPart) const
SEARCH_RESULT
Definition: base_struct.h:51
void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
LIB_FIELD * GetField(int aId) const
Return pointer to the requested field.
void SetPinNameOffset(int aOffset)
Set the offset in mils of the pin name text from the pin symbol.
bool m_showPinNames
Determines if part pin names are visible.
const EDA_RECT GetBodyBoundingBox(int aUnit, int aConvert) const
Get the symbol bounding box excluding fields.
void SetFields(const std::vector< LIB_FIELD > &aFieldsList)
Overwrite all the existing fields in this symbol with fields supplied in aFieldsList.
wxString m_description
documentation for info
Object used to load, save, search, and otherwise manipulate symbol library files.
void SetLibId(const LIB_ID &aLibId)
size_t size(int aType=UNDEFINED_TYPE) const
Definition: multivector.h:220
bool UnitsLocked() const
Check whether part units are interchangeable.
void GetFields(LIB_FIELDS &aList)
Return a list of fields within this part.
LIB_PIN * GetPin(const wxString &aNumber, int aUnit=0, int aConvert=0)
Return pin object with the requested pin aNumber.
void LockUnits(bool aLockUnits)
Set interchangeable the property for part units.
void RemoveDrawItem(LIB_ITEM *aItem)
Remove draw aItem from list.
void SetNormal()
PART_SPTR m_me
< http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared