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 {
72 
74  {
77  def.draw_visible_fields = true;
78  def.draw_hidden_fields = true;
79  def.show_elec_type = false;
80  return def;
81  }
82 };
83 
84 
85 struct PART_UNITS
86 {
87  int m_unit;
88  int m_convert;
89  std::vector<LIB_ITEM*> m_items;
90 };
91 
92 
99 class LIB_PART : public EDA_ITEM, public LIB_TREE_ITEM
100 {
104 
106 
108  bool m_unitsLocked;
110  bool m_showPinNames;
117  wxArrayString m_FootprintList;
120  wxString m_name;
121  wxString m_description;
122  wxString m_keyWords;
123  wxString m_docFileName;
124 
125  static int m_subpartIdSeparator;
126  static int m_subpartFirstId;
129  void deleteAllFields();
132 
133 public:
134 
135  LIB_PART( const wxString& aName, LIB_PART* aParent = nullptr, PART_LIB* aLibrary = nullptr );
136 
140  LIB_PART( const LIB_PART& aPart, PART_LIB* aLibrary = NULL );
141 
142  virtual ~LIB_PART();
143 
144  PART_SPTR SharedPtr() { return m_me; }
145 
146  void SetParent( LIB_PART* aParent = nullptr );
147  PART_REF& GetParent() { return m_parent; }
148 
149  virtual wxString GetClass() const override
150  {
151  return wxT( "LIB_PART" );
152  }
153 
154  virtual void SetName( const wxString& aName );
155  wxString GetName() const override { return m_name; }
156 
157  LIB_ID GetLibId() const override { return m_libId; }
158  void SetLibId( const LIB_ID& aLibId ) { m_libId = aLibId; }
159 
160  wxString GetLibNickname() const override { return GetLibraryName(); }
161 
162  void SetDescription( const wxString& aDescription )
163  {
164  m_description = aDescription;
165  }
166 
167  wxString GetDescription() override { return m_description; }
168 
169  void SetKeyWords( const wxString& aKeyWords )
170  {
171  m_keyWords = aKeyWords;
172  }
173 
174  wxString GetKeyWords() const { return m_keyWords; }
175 
176  void SetDocFileName( const wxString& aDocFileName )
177  {
178  m_docFileName = aDocFileName;
179  }
180 
181  wxString GetDocFileName() const { return m_docFileName; }
182 
183  wxString GetSearchText() override;
184 
188  bool IsRoot() const override { return m_parent.use_count() == 0; }
189  bool IsAlias() const { return !m_parent.expired() && m_parent.use_count() > 0; }
190 
191  const wxString GetLibraryName() const;
192 
193  PART_LIB* GetLib() { return m_library; }
194  void SetLib( PART_LIB* aLibrary ) { m_library = aLibrary; }
195 
197 
198  wxArrayString GetFootprints() const { return m_FootprintList; }
199  void SetFootprintFilters( const wxArrayString& aFootprintFilters )
200  {
201  m_FootprintList = aFootprintFilters;
202  }
203 
204  void ViewGetLayers( int aLayers[], int& aCount ) const override;
205 
216  const EDA_RECT GetUnitBoundingBox( int aUnit, int aConvert ) const;
217 
228  const EDA_RECT GetBodyBoundingBox( int aUnit, int aConvert ) const;
229 
230  const EDA_RECT GetBoundingBox() const override
231  {
232  return GetUnitBoundingBox( 0, 0 );
233  }
234 
235  bool IsPower() const { return m_options == ENTRY_POWER; }
236  bool IsNormal() const { return m_options == ENTRY_NORMAL; }
237 
240 
245  void LockUnits( bool aLockUnits ) { m_unitsLocked = aLockUnits; }
246 
251  bool UnitsLocked() const { return m_unitsLocked; }
252 
262  void SetFields( const std::vector <LIB_FIELD>& aFieldsList );
263 
269  void GetFields( LIB_FIELDS& aList );
270 
275  LIB_FIELD* FindField( const wxString& aFieldName );
276 
283  LIB_FIELD* GetField( int aId ) const;
284 
287 
290 
293 
303  void Print( wxDC* aDc, const wxPoint& aOffset, int aMulti, int aConvert,
304  const PART_DRAW_OPTIONS& aOpts );
305 
317  void Plot( PLOTTER* aPlotter, int aUnit, int aConvert, const wxPoint& aOffset,
318  const TRANSFORM& aTransform );
319 
330  void PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert, const wxPoint& aOffset,
331  const TRANSFORM& aTransform );
332 
338  void AddDrawItem( LIB_ITEM* aItem );
339 
345  void RemoveDrawItem( LIB_ITEM* aItem );
346 
357 
368  {
369  return (LIB_PIN*) GetNextDrawItem( (LIB_ITEM*) aItem, LIB_PIN_T );
370  }
371 
372 
386  void GetPins( LIB_PINS& aList, int aUnit = 0, int aConvert = 0 );
387 
398  LIB_PIN* GetPin( const wxString& aNumber, int aUnit = 0, int aConvert = 0 );
399 
412  bool PinsConflictWith( LIB_PART& aOtherPart, bool aTestNums, bool aTestNames,
413  bool aTestType, bool aTestOrientation, bool aTestLength );
414 
420  void SetOffset( const wxPoint& aOffset );
421 
426 
432  bool HasConversion() const;
433 
437  void ClearTempFlags();
438  void ClearEditFlags();
448  LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, const wxPoint& aPoint );
449 
460  LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, const wxPoint& aPoint,
461  const TRANSFORM& aTransform );
462 
469 
470  SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
471 
483  void SetUnitCount( int aCount, bool aDuplicateDrawItems = true );
484  int GetUnitCount() const override;
485 
489  wxString GetUnitReference( int aUnit ) override;
490 
495  bool IsMulti() const { return m_unitCount > 1; }
496 
505  static wxString SubReference( int aUnit, bool aAddSeparator = true );
506 
507  // Accessors to sub ref parameters
509 
513  static int* SubpartIdSeparatorPtr() { return &m_subpartIdSeparator; }
514  static int GetSubpartFirstId() { return m_subpartFirstId; }
515 
518  static int* SubpartFirstIdPtr() { return &m_subpartFirstId; }
519 
530  static void SetSubpartIdNotation( int aSep, int aFirstId );
531 
544  void SetConversion( bool aSetConvert, bool aDuplicatePins = true );
545 
553  void SetPinNameOffset( int aOffset ) { m_pinNameOffset = aOffset; }
555 
561  void SetShowPinNames( bool aShow ) { m_showPinNames = aShow; }
562  bool ShowPinNames() { return m_showPinNames; }
563 
569  void SetShowPinNumbers( bool aShow ) { m_showPinNumbers = aShow; }
570  bool ShowPinNumbers() { return m_showPinNumbers; }
571 
581  int Compare( const LIB_PART& aRhs ) const;
582 
583  bool operator==( const LIB_PART* aPart ) const { return this == aPart; }
584  bool operator==( const LIB_PART& aPart ) const { return Compare( aPart ) == 0; }
585 
586  const LIB_PART& operator=( const LIB_PART& aPart );
587 
595  std::unique_ptr< LIB_PART > Flatten() const;
596 
603  std::vector<struct PART_UNITS> GetUnitDrawItems();
604 
613  std::vector<struct PART_UNITS> GetUniqueUnits();
614 
625  std::vector<LIB_ITEM*> GetUnitItems( int aUnit, int aConvert );
626 
627 #if defined(DEBUG)
628  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
629 #endif
630 };
631 
632 #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
int GetPinNameOffset()
bool m_showPinNumbers
Determines if part pin numbers are visible.
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:54
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 m_docFileName
Associate doc file name.
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.)
bool draw_hidden_fields
Whether to draw "hidden" fields.
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.
The base class for drawable items used by schematic library components.
Definition: lib_item.h:60
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:108
bool ShowPinNames()
void deleteAllFields()
PART_REF m_parent
Use for inherited symbols.
static int GetSubpartIdSeparator()
bool ShowPinNumbers()
void Print(wxDC *aDc, const wxPoint &aOffset, int aMulti, int aConvert, const PART_DRAW_OPTIONS &aOpts)
Print part.
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)
void SetDocFileName(const wxString &aDocFileName)
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 GetDocFileName() const
wxString GetDescription() override
LIB_PART(const wxString &aName, LIB_PART *aParent=nullptr, PART_LIB *aLibrary=nullptr)
static PART_DRAW_OPTIONS Default()
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:104
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:223
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:166
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
bool show_elec_type
Whether to show the pin electrical type.
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:53
bool draw_visible_fields
Whether to draw "visible" fields.
SEARCH_RESULT
Definition: base_struct.h:54
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)
TRANSFORM transform
Coordinate adjustment settings.
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