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;
112  bool m_includeOnBoard;
119  wxArrayString m_footprintFilters;
122  wxString m_name;
123  wxString m_description;
124  wxString m_keyWords;
125 
126  static int m_subpartIdSeparator;
127  static int m_subpartFirstId;
130  void deleteAllFields();
133 
134 public:
135 
136  LIB_PART( const wxString& aName, LIB_PART* aParent = nullptr, PART_LIB* aLibrary = nullptr );
137 
141  LIB_PART( const LIB_PART& aPart, PART_LIB* aLibrary = NULL );
142 
143  virtual ~LIB_PART();
144 
145  PART_SPTR SharedPtr() { return m_me; }
146 
147 private:
148  // We create a different set parent function for this class, so we hide
149  // the inherited one.
150  using EDA_ITEM::SetParent;
151 
152 public:
153 
154  void SetParent( LIB_PART* aParent = nullptr );
155  PART_REF& GetParent() { return m_parent; }
156 
157  virtual wxString GetClass() const override
158  {
159  return wxT( "LIB_PART" );
160  }
161 
162  virtual void SetName( const wxString& aName );
163  wxString GetName() const override { return m_name; }
164 
165  LIB_ID GetLibId() const override { return m_libId; }
166  void SetLibId( const LIB_ID& aLibId ) { m_libId = aLibId; }
167 
168  wxString GetLibNickname() const override { return GetLibraryName(); }
169 
170  void SetDescription( const wxString& aDescription )
171  {
172  m_description = aDescription;
173  }
174 
175  wxString GetDescription() override { return m_description; }
176 
177  void SetKeyWords( const wxString& aKeyWords )
178  {
179  m_keyWords = aKeyWords;
180  }
181 
182  wxString GetKeyWords() const { return m_keyWords; }
183 
184  wxString GetSearchText() override;
185 
189  bool IsRoot() const override { return m_parent.use_count() == 0; }
190  bool IsAlias() const { return !m_parent.expired() && m_parent.use_count() > 0; }
191 
192  const wxString GetLibraryName() const;
193 
194  PART_LIB* GetLib() { return m_library; }
195  void SetLib( PART_LIB* aLibrary ) { m_library = aLibrary; }
196 
198 
199  wxArrayString GetFootprints() const { return m_footprintFilters; }
200  void SetFootprintFilters( const wxArrayString& aFootprintFilters )
201  {
202  m_footprintFilters = aFootprintFilters;
203  }
204 
205  void ViewGetLayers( int aLayers[], int& aCount ) const override;
206 
217  const EDA_RECT GetUnitBoundingBox( int aUnit, int aConvert ) const;
218 
229  const EDA_RECT GetBodyBoundingBox( int aUnit, int aConvert ) const;
230 
231  const EDA_RECT GetBoundingBox() const override
232  {
233  return GetUnitBoundingBox( 0, 0 );
234  }
235 
236  bool IsPower() const { return m_options == ENTRY_POWER; }
237  bool IsNormal() const { return m_options == ENTRY_NORMAL; }
238 
241 
246  void LockUnits( bool aLockUnits ) { m_unitsLocked = aLockUnits; }
247 
252  bool UnitsLocked() const { return m_unitsLocked; }
253 
263  void SetFields( const std::vector <LIB_FIELD>& aFieldsList );
264 
270  void GetFields( LIB_FIELDS& aList );
271 
276  LIB_FIELD* FindField( const wxString& aFieldName );
277 
278  const LIB_FIELD* FindField( const wxString& aFieldName ) const;
279 
286  LIB_FIELD* GetField( int aId ) const;
287 
290 
293 
296 
299 
308  void Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, int aMulti, int aConvert,
309  const PART_DRAW_OPTIONS& aOpts );
310 
322  void Plot( PLOTTER* aPlotter, int aUnit, int aConvert, const wxPoint& aOffset,
323  const TRANSFORM& aTransform );
324 
335  void PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert, const wxPoint& aOffset,
336  const TRANSFORM& aTransform );
337 
343  void AddDrawItem( LIB_ITEM* aItem );
344 
350  void RemoveDrawItem( LIB_ITEM* aItem );
351 
362 
363  size_t GetPinCount() const { return m_drawings.size( LIB_PIN_T ); }
364 
375  {
376  return (LIB_PIN*) GetNextDrawItem( (LIB_ITEM*) aItem, LIB_PIN_T );
377  }
378 
379 
393  void GetPins( LIB_PINS& aList, int aUnit = 0, int aConvert = 0 );
394 
405  LIB_PIN* GetPin( const wxString& aNumber, int aUnit = 0, int aConvert = 0 );
406 
419  bool PinsConflictWith( LIB_PART& aOtherPart, bool aTestNums, bool aTestNames,
420  bool aTestType, bool aTestOrientation, bool aTestLength );
421 
427  void SetOffset( const wxPoint& aOffset );
428 
433 
439  bool HasConversion() const;
440 
444  void ClearTempFlags();
445  void ClearEditFlags();
455  LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, const wxPoint& aPoint );
456 
467  LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, const wxPoint& aPoint,
468  const TRANSFORM& aTransform );
469 
476 
477  SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
478 
490  void SetUnitCount( int aCount, bool aDuplicateDrawItems = true );
491  int GetUnitCount() const override;
492 
496  wxString GetUnitReference( int aUnit ) override;
497 
502  bool IsMulti() const { return m_unitCount > 1; }
503 
512  static wxString SubReference( int aUnit, bool aAddSeparator = true );
513 
514  // Accessors to sub ref parameters
516 
520  static int* SubpartIdSeparatorPtr() { return &m_subpartIdSeparator; }
521  static int GetSubpartFirstId() { return m_subpartFirstId; }
522 
525  static int* SubpartFirstIdPtr() { return &m_subpartFirstId; }
526 
537  static void SetSubpartIdNotation( int aSep, int aFirstId );
538 
551  void SetConversion( bool aSetConvert, bool aDuplicatePins = true );
552 
560  void SetPinNameOffset( int aOffset ) { m_pinNameOffset = aOffset; }
562 
568  void SetShowPinNames( bool aShow ) { m_showPinNames = aShow; }
569  bool ShowPinNames() { return m_showPinNames; }
570 
576  void SetShowPinNumbers( bool aShow ) { m_showPinNumbers = aShow; }
577  bool ShowPinNumbers() { return m_showPinNumbers; }
578 
584  void SetIncludeInBom( bool aIncludeInBom ) { m_includeInBom = aIncludeInBom; }
585  bool GetIncludeInBom() const { return m_includeInBom; }
586 
592  void SetIncludeOnBoard( bool aIncludeOnBoard ) { m_includeOnBoard = aIncludeOnBoard; }
593  bool GetIncludeOnBoard() const { return m_includeOnBoard; }
594 
604  int Compare( const LIB_PART& aRhs ) const;
605 
606  bool operator==( const LIB_PART* aPart ) const { return this == aPart; }
607  bool operator==( const LIB_PART& aPart ) const { return Compare( aPart ) == 0; }
608  bool operator!=( const LIB_PART& aPart ) const { return Compare( aPart ) != 0; }
609 
610  const LIB_PART& operator=( const LIB_PART& aPart );
611 
619  std::unique_ptr< LIB_PART > Flatten() const;
620 
627  std::vector<struct PART_UNITS> GetUnitDrawItems();
628 
637  std::vector<struct PART_UNITS> GetUniqueUnits();
638 
649  std::vector<LIB_ITEM*> GetUnitItems( int aUnit, int aConvert );
650 
651 #if defined(DEBUG)
652  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
653 #endif
654 };
655 
656 #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:82
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:56
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',...
bool m_includeOnBoard
Determines if symbol should be excluded from netlist when updating board.
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:328
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
void SetIncludeInBom(bool aIncludeInBom)
Set or clear the include in schematic bill of materials flag.
LIBRENTRYOPTIONS m_options
Special part features such as POWER or NORMAL.)
bool m_includeInBom
Determines if symbol should be included in schematic BOM.
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:94
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: eda_item.h:184
The base class for drawable items used by schematic library components.
Definition: lib_item.h:62
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.
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.
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.
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: kiid.h:32
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:131
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
bool GetIncludeOnBoard() const
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: eda_item.h:148
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)
void SetIncludeOnBoard(bool aIncludeOnBoard)
Set or clear include in board netlist flag.
wxString m_keyWords
keyword list (used for search for parts by keyword)
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
wxArrayString m_footprintFilters
List of suitable footprint names for the part (wild card names accepted).
void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
bool GetIncludeInBom() const
SEARCH_RESULT
Definition: eda_item.h:40
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