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-2019 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;
46 class TEST_LIB_PART_FIXTURE;
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 
91 class LIB_PART : public EDA_ITEM, public LIB_TREE_ITEM
92 {
96 
98 
100  bool m_unitsLocked;
102  bool m_showPinNames;
109  wxArrayString m_FootprintList;
112  wxString m_name;
113  wxString m_description;
114  wxString m_keyWords;
115  wxString m_docFileName;
116 
117  static int m_subpartIdSeparator;
118  static int m_subpartFirstId;
121  void deleteAllFields();
124 
125 public:
126 
127  LIB_PART( const wxString& aName, LIB_PART* aParent = nullptr, PART_LIB* aLibrary = nullptr );
128 
132  LIB_PART( const LIB_PART& aPart, PART_LIB* aLibrary = NULL );
133 
134  virtual ~LIB_PART();
135 
136  PART_SPTR SharedPtr() { return m_me; }
137 
138  void SetParent( LIB_PART* aParent = nullptr );
139  PART_REF& GetParent() { return m_parent; }
140 
141  virtual wxString GetClass() const override
142  {
143  return wxT( "LIB_PART" );
144  }
145 
146  virtual void SetName( const wxString& aName );
147  wxString GetName() const override { return m_name; }
148 
149  LIB_ID GetLibId() const override { return m_libId; }
150  void SetLibId( const LIB_ID& aLibId ) { m_libId = aLibId; }
151 
152  wxString GetLibNickname() const override { return GetLibraryName(); }
153 
154  void SetDescription( const wxString& aDescription )
155  {
156  m_description = aDescription;
157  }
158 
159  wxString GetDescription() override { return m_description; }
160 
161  void SetKeyWords( const wxString& aKeyWords )
162  {
163  m_keyWords = aKeyWords;
164  }
165 
166  wxString GetKeyWords() const { return m_keyWords; }
167 
168  void SetDocFileName( const wxString& aDocFileName )
169  {
170  m_docFileName = aDocFileName;
171  }
172 
173  wxString GetDocFileName() const { return m_docFileName; }
174 
175  wxString GetSearchText() override;
176 
180  bool IsRoot() const override { return m_parent.use_count() == 0; }
181  bool IsAlias() const { return !IsRoot(); }
182 
183  const wxString GetLibraryName() const;
184 
185  PART_LIB* GetLib() { return m_library; }
186  void SetLib( PART_LIB* aLibrary ) { m_library = aLibrary; }
187 
189 
190  wxArrayString GetFootprints() const { return m_FootprintList; }
191  void SetFootprintFilters( const wxArrayString& aFootprintFilters )
192  {
193  m_FootprintList = aFootprintFilters;
194  }
195 
196  void ViewGetLayers( int aLayers[], int& aCount ) const override;
197 
208  const EDA_RECT GetUnitBoundingBox( int aUnit, int aConvert ) const;
209 
220  const EDA_RECT GetBodyBoundingBox( int aUnit, int aConvert ) const;
221 
222  const EDA_RECT GetBoundingBox() const override
223  {
224  return GetUnitBoundingBox( 0, 0 );
225  }
226 
227  bool IsPower() const { return m_options == ENTRY_POWER; }
228  bool IsNormal() const { return m_options == ENTRY_NORMAL; }
229 
232 
237  void LockUnits( bool aLockUnits ) { m_unitsLocked = aLockUnits; }
238 
243  bool UnitsLocked() const { return m_unitsLocked; }
244 
254  void SetFields( const std::vector <LIB_FIELD>& aFieldsList );
255 
261  void GetFields( LIB_FIELDS& aList );
262 
266  LIB_FIELD* FindField( const wxString& aFieldName );
267 
274  LIB_FIELD* GetField( int aId ) const;
275 
278 
281 
284 
294  void Print( wxDC* aDc, const wxPoint& aOffset, int aMulti, int aConvert,
295  const PART_DRAW_OPTIONS& aOpts );
296 
308  void Plot( PLOTTER* aPlotter, int aUnit, int aConvert, const wxPoint& aOffset,
309  const TRANSFORM& aTransform );
310 
321  void PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert, const wxPoint& aOffset,
322  const TRANSFORM& aTransform );
323 
329  void AddDrawItem( LIB_ITEM* aItem );
330 
336  void RemoveDrawItem( LIB_ITEM* aItem );
337 
347  LIB_ITEM* GetNextDrawItem( LIB_ITEM* aItem = NULL, KICAD_T aType = TYPE_NOT_INIT );
348 
358  LIB_PIN* GetNextPin( LIB_PIN* aItem = NULL )
359  {
360  return (LIB_PIN*) GetNextDrawItem( (LIB_ITEM*) aItem, LIB_PIN_T );
361  }
362 
363 
377  void GetPins( LIB_PINS& aList, int aUnit = 0, int aConvert = 0 );
378 
389  LIB_PIN* GetPin( const wxString& aNumber, int aUnit = 0, int aConvert = 0 );
390 
403  bool PinsConflictWith( LIB_PART& aOtherPart, bool aTestNums, bool aTestNames,
404  bool aTestType, bool aTestOrientation, bool aTestLength );
405 
411  void SetOffset( const wxPoint& aOffset );
412 
417 
423  bool HasConversion() const;
424 
428  void ClearTempFlags();
429  void ClearEditFlags();
439  LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, const wxPoint& aPoint );
440 
451  LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, const wxPoint& aPoint,
452  const TRANSFORM& aTransform );
453 
460 
461  SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
462 
473  void SetUnitCount( int count );
474  int GetUnitCount() const override;
475 
479  wxString GetUnitReference( int aUnit ) override;
480 
485  bool IsMulti() const { return m_unitCount > 1; }
486 
495  static wxString SubReference( int aUnit, bool aAddSeparator = true );
496 
497  // Accessors to sub ref parameters
499 
503  static int* SubpartIdSeparatorPtr() { return &m_subpartIdSeparator; }
504  static int GetSubpartFirstId() { return m_subpartFirstId; }
505 
508  static int* SubpartFirstIdPtr() { return &m_subpartFirstId; }
509 
520  static void SetSubpartIdNotation( int aSep, int aFirstId );
521 
533  void SetConversion( bool aSetConvert );
534 
542  void SetPinNameOffset( int aOffset ) { m_pinNameOffset = aOffset; }
544 
550  void SetShowPinNames( bool aShow ) { m_showPinNames = aShow; }
551  bool ShowPinNames() { return m_showPinNames; }
552 
558  void SetShowPinNumbers( bool aShow ) { m_showPinNumbers = aShow; }
559  bool ShowPinNumbers() { return m_showPinNumbers; }
560 
570  int Compare( const LIB_PART& aRhs ) const;
571 
572  bool operator==( const LIB_PART* aPart ) const { return this == aPart; }
573  bool operator==( const LIB_PART& aPart ) const { return Compare( aPart ) == 0; }
574 
582  std::unique_ptr< LIB_PART > Flatten() const;
583 
584 #if defined(DEBUG)
585  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
586 #endif
587 };
588 
589 #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 ...
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
void SetConversion(bool aSetConvert)
Set or clear the alternate body style (DeMorgan) for the part.
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: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
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)
LIB_ITEMS_CONTAINER m_drawings
Drawing items of this part.
LIB_FIELD & GetValueField()
Return reference to the value field.
bool operator==(const LIB_PART &aPart) const
int Compare(const LIB_PART &aRhs) const
Comparison test that can be used for operators.
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
bool IsNormal() const
wxString m_docFileName
Associate doc file name.
wxString GetKeyWords() const
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:61
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.
Class for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
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.
int GetUnitCount() const override
For items with units, return the number of units.
wxString m_name
Symbol name.
static int GetSubpartFirstId()
void SetUnitCount(int count)
Set the units per part count.
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.
wxString GetUnitReference(int aUnit) override
Return an identifier for aUnit for symbols with units.
Base plotter engine class.
Definition: plotter.h:97
bool IsPower() const
TRANSFORM DefaultTransform
Definition: eeschema.cpp:50
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:214
void SetKeyWords(const wxString &aKeyWords)
bool IsAlias() const
const EDA_RECT GetUnitBoundingBox(int aUnit, int aConvert) const
Get the bounding box for the symbol.
Class 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.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
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.
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