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-2018 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_draw_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_ALIAS;
45 class LIB_PART;
46 class LIB_FIELD;
47 
48 
49 typedef std::vector<LIB_ALIAS*> LIB_ALIASES;
50 typedef std::shared_ptr<LIB_PART> PART_SPTR;
51 typedef std::weak_ptr<LIB_PART> PART_REF;
54 
55 
56 /* values for member .m_options */
58 {
59  ENTRY_NORMAL, // Libentry is a standard part (real or alias)
60  ENTRY_POWER // Libentry is a power symbol
61 };
62 
63 
73 class LIB_ALIAS : public EDA_ITEM, public LIB_TREE_ITEM
74 {
83 
84 protected:
85  wxString name;
86  wxString description;
87  wxString keyWords;
88  wxString docFileName;
89 
90  int tmpUnit;
92 
93 public:
94  LIB_ALIAS( const wxString& aName, LIB_PART* aRootComponent );
95  LIB_ALIAS( const LIB_ALIAS& aAlias, LIB_PART* aRootComponent = NULL );
96 
97  virtual ~LIB_ALIAS();
98 
99  virtual wxString GetClass() const override
100  {
101  return wxT( "LIB_ALIAS" );
102  }
103 
110  LIB_PART* GetPart() const
111  {
112  return shared;
113  }
114 
115  PART_LIB* GetLib();
116 
117  LIB_ID GetLibId() const override;
118 
119  wxString GetLibNickname() const override;
120  const wxString& GetName() const override { return name; }
121 
122  void SetName( const wxString& aName );
123 
124  void SetDescription( const wxString& aDescription )
125  {
126  description = aDescription;
127  }
128 
129  const wxString& GetDescription() override { return description; }
130 
131  void SetKeyWords( const wxString& aKeyWords )
132  {
133  keyWords = aKeyWords;
134  }
135 
136  const wxString& GetKeyWords() const { return keyWords; }
137 
138  void SetDocFileName( const wxString& aDocFileName )
139  {
140  docFileName = aDocFileName;
141  }
142 
143  const wxString& GetDocFileName() const { return docFileName; }
144 
145  wxString GetSearchText() override;
146 
150  bool IsRoot() const override;
151 
155  int GetUnitCount() override;
156 
160  wxString GetUnitReference( int aUnit ) override;
161 
165  void SetTmpConversion( int aConversion ) { tmpConversion = aConversion; }
166  int GetTmpConversion() { return tmpConversion; }
167 
171  bool operator==( const wxChar* aName ) const;
172  bool operator!=( const wxChar* aName ) const
173  {
174  return !( *this == aName );
175  }
176 
177  bool operator==( const LIB_ALIAS* aAlias ) const { return this == aAlias; }
178 
179 #if defined(DEBUG)
180  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
181 #endif
182 };
183 
184 extern bool operator<( const LIB_ALIAS& aItem1, const LIB_ALIAS& aItem2 );
185 
186 
188 {
196  std::vector<bool> dangling;
198 
200  {
201  PART_DRAW_OPTIONS def;
203  def.color = COLOR4D::UNSPECIFIED;
205  def.show_pin_text = true;
206  def.draw_visible_fields = true;
207  def.draw_hidden_fields = true;
208  def.only_selected = false;
209  def.show_elec_type = false;
210  return def;
211  }
212 
213  bool PinIsDangling( size_t aPin ) const
214  {
215  if( aPin < dangling.size() )
216  return dangling[aPin];
217  else
218  return true;
219  }
220 };
221 
222 
229 class LIB_PART : public EDA_ITEM
230 {
234  bool m_unitsLocked;
236  bool m_showPinNames;
243  wxArrayString m_FootprintList;
246  PART_LIB* m_library;
248 
249  static int m_subpartIdSeparator;
250  static int m_subpartFirstId;
253 private:
256  void deleteAllFields();
257 
258 
259 
260 public:
261 
262  LIB_PART( const wxString& aName, PART_LIB* aLibrary = NULL );
263  LIB_PART( LIB_PART& aPart, PART_LIB* aLibrary = NULL );
264 
265  virtual ~LIB_PART();
266 
268  {
269  // clone a shared pointer
270  return m_me;
271  }
272 
273  virtual wxString GetClass() const override
274  {
275  return wxT( "LIB_PART" );
276  }
277 
278  virtual void SetName( const wxString& aName );
279 
280  const wxString& GetName() const;
281 
282  const LIB_ID& GetLibId() const { return m_libId; }
283  void SetLibId( const LIB_ID& aLibId ) { m_libId = aLibId; }
284 
285  const wxString GetLibraryName();
286 
287  PART_LIB* GetLib() { return m_library; }
288 
289  void SetLib( PART_LIB* aLibrary ) { m_library = aLibrary; }
290 
291  wxArrayString GetAliasNames( bool aIncludeRoot = true ) const;
292 
293  LIB_ALIASES GetAliases() const { return m_aliases; }
294 
295  size_t GetAliasCount() const { return m_aliases.size(); }
296 
297  LIB_ALIAS* GetAlias( size_t aIndex );
298 
299  LIB_ALIAS* GetAlias( const wxString& aName );
300 
301  timestamp_t GetDateLastEdition() const { return m_dateLastEdition; }
302 
311  void AddAlias( const wxString& aName );
312 
313  void AddAlias( LIB_ALIAS* aAlias );
314 
323  bool HasAlias( const wxString& aName ) const;
324 
325  void RemoveAlias( const wxString& aName );
326  LIB_ALIAS* RemoveAlias( LIB_ALIAS* aAlias );
327 
328  void RemoveAllAliases();
329 
330  wxArrayString& GetFootprints() { return m_FootprintList; }
331 
342  const EDA_RECT GetUnitBoundingBox( int aUnit, int aConvert ) const;
343 
354  const EDA_RECT GetBodyBoundingBox( int aUnit, int aConvert ) const;
355 
356  const EDA_RECT GetBoundingBox() const override
357  {
358  return GetUnitBoundingBox( 0, 0 );
359  }
360 
369  bool SaveDateAndTime( OUTPUTFORMATTER& aFormatter );
370 
371  bool LoadDateAndTime( char* aLine );
372 
379  bool Save( OUTPUTFORMATTER& aFormatter );
380 
381  bool IsPower() const { return m_options == ENTRY_POWER; }
382  bool IsNormal() const { return m_options == ENTRY_NORMAL; }
383 
384  void SetPower() { m_options = ENTRY_POWER; }
385  void SetNormal() { m_options = ENTRY_NORMAL; }
386 
391  void LockUnits( bool aLockUnits ) { m_unitsLocked = aLockUnits; }
392 
397  bool UnitsLocked() const { return m_unitsLocked; }
398 
408  void SetFields( const std::vector <LIB_FIELD>& aFieldsList );
409 
415  void GetFields( LIB_FIELDS& aList );
416 
420  LIB_FIELD* FindField( const wxString& aFieldName );
421 
428  LIB_FIELD* GetField( int aId );
429 
431  LIB_FIELD& GetValueField();
432 
434  LIB_FIELD& GetReferenceField();
435 
437  LIB_FIELD& GetFootprintField();
438 
449  void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset,
450  int aMulti, int aConvert,
451  const PART_DRAW_OPTIONS& aOpts );
452 
464  void Plot( PLOTTER* aPlotter, int aUnit, int aConvert, const wxPoint& aOffset,
465  const TRANSFORM& aTransform );
466 
477  void PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert,
478  const wxPoint& aOffset, const TRANSFORM& aTransform );
479 
485  void AddDrawItem( LIB_ITEM* aItem );
486 
494  void RemoveDrawItem( LIB_ITEM* aItem, EDA_DRAW_PANEL* aPanel = NULL, wxDC* aDc = NULL );
495 
505  LIB_ITEM* GetNextDrawItem( LIB_ITEM* aItem = NULL, KICAD_T aType = TYPE_NOT_INIT );
506 
516  LIB_PIN* GetNextPin( LIB_PIN* aItem = NULL )
517  {
518  return (LIB_PIN*) GetNextDrawItem( (LIB_ITEM*) aItem, LIB_PIN_T );
519  }
520 
521 
535  void GetPins( LIB_PINS& aList, int aUnit = 0, int aConvert = 0 );
536 
547  LIB_PIN* GetPin( const wxString& aNumber, int aUnit = 0, int aConvert = 0 );
548 
561  bool PinsConflictWith( LIB_PART& aOtherPart, bool aTestNums, bool aTestNames,
562  bool aTestType, bool aTestOrientation, bool aTestLength );
563 
569  void SetOffset( const wxPoint& aOffset );
570 
574  void RemoveDuplicateDrawItems();
575 
581  bool HasConversion() const;
582 
586  void ClearStatus();
587 
597  LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, const wxPoint& aPoint );
598 
609  LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
610  const wxPoint& aPoint, const TRANSFORM& aTransform );
611 
618  {
619  return m_drawings;
620  }
621 
632  void SetUnitCount( int count );
633 
634  int GetUnitCount() const { return m_unitCount; }
635 
640  bool IsMulti() const { return m_unitCount > 1; }
641 
650  static wxString SubReference( int aUnit, bool aAddSeparator = true );
651 
652  // Accessors to sub ref parameters
653  static int GetSubpartIdSeparator() { return m_subpartIdSeparator; }
654 
658  static int* SubpartIdSeparatorPtr() { return &m_subpartIdSeparator; }
659 
660  static int GetSubpartFirstId() { return m_subpartFirstId; }
661 
664  static int* SubpartFirstIdPtr() { return &m_subpartFirstId; }
665 
676  static void SetSubpartIdNotation( int aSep, int aFirstId );
677 
689  void SetConversion( bool aSetConvert );
690 
698  void SetPinNameOffset( int aOffset ) { m_pinNameOffset = aOffset; }
699 
700  int GetPinNameOffset() { return m_pinNameOffset; }
701 
707  void SetShowPinNames( bool aShow ) { m_showPinNames = aShow; }
708 
709  bool ShowPinNames() { return m_showPinNames; }
710 
716  void SetShowPinNumbers( bool aShow ) { m_showPinNumbers = aShow; }
717 
718  bool ShowPinNumbers() { return m_showPinNumbers; }
719 
720  bool operator==( const LIB_PART* aPart ) const { return this == aPart; }
721 
722 #if defined(DEBUG)
723  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
724 #endif
725 };
726 
727 #endif // CLASS_LIBENTRY_H
timestamp_t m_dateLastEdition
Date of the last modification.
LIB_ALIASES m_aliases
List of alias object pointers associated with the part.
PART_LIB * GetLib()
virtual ~LIB_ALIAS()
void SetLib(PART_LIB *aLibrary)
bool UnitsLocked() const
Check whether part units are interchangeable.
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
Part library alias object definition.
bool PinIsDangling(size_t aPin) const
bool IsMulti() const
static int * SubpartFirstIdPtr()
return a reference to m_subpartFirstId, only for read/save setting functions
void SetPower()
virtual wxString GetClass() const override
Function GetClass returns the class name.
int GetPinNameOffset()
bool m_showPinNumbers
Determines if part pin numbers are visible.
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:52
wxString description
documentation for info
int GetUnitCount() override
For symbols with units, return the number of units.
bool operator<(const EDA_ITEM &aItem) const
Test if another item is less than this object.
bool IsPower() const
MULTIVECTOR< LIB_ITEM, LIB_ARC_T, LIB_FIELD_T > LIB_ITEMS_CONTAINER
LIB_ID GetLibId() const override
wxString GetSearchText() override
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints)...
Definition: lib_tree_item.h:39
LIB_ALIASES GetAliases() 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.
Field object used in symbol libraries.
Definition: lib_field.h:59
std::weak_ptr< LIB_PART > PART_REF
weak pointer to LIB_PART
wxString GetUnitReference(int aUnit) override
For symbols with units, return an identifier for unit x.
LIB_ITEMS_CONTAINER m_drawings
Drawing items of this part.
const LIB_ID & GetLibId() const
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
LIB_ALIAS(const wxString &aName, LIB_PART *aRootComponent)
std::vector< LIB_ALIAS * > LIB_ALIASES
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
size_t GetAliasCount() const
LIBRENTRYOPTIONS m_options
Special part features such as POWER or NORMAL.)
PART_LIB * GetLib()
void SetDocFileName(const wxString &aDocFileName)
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
void SetTmpConversion(int aConversion)
A temporary conversion (deMorgan) designation for rendering, preview, etc.
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:67
LIB_ITEMS_CONTAINER::ITEM_PTR_VECTOR LIB_ITEMS
wxString GetLibNickname() const override
wxString name
std::vector< bool > dangling
which pins should display as dangling, or empty for All
int GetTmpConversion()
static struct PcbQueue * Save
Definition: queue.cpp:56
int m_pinNameOffset
The offset in mils to draw the pin name.
bool ShowPinNames()
bool IsRoot() const override
For symbols having aliases, IsRoot() indicates the principal item.
static int GetSubpartIdSeparator()
void SetName(const wxString &aName)
bool ShowPinNumbers()
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
virtual wxString GetClass() const override
Function GetClass returns the class name.
bool operator!=(const wxChar *aName) const
const wxString & GetKeyWords() const
static int GetSubpartFirstId()
wxString docFileName
Associate doc file name.
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
LIB_PART * shared
Actual LIB_PART referenced by [multiple] aliases.
std::shared_ptr< LIB_PART > PART_SPTR
shared pointer to LIB_PART
PART_SPTR SharedPtr()
bool operator==(const wxChar *aName) const
KEEPCASE sensitive comparison of the part entry name.
Define a library symbol object.
timestamp_t GetDateLastEdition() const
static PART_DRAW_OPTIONS Default()
wxArrayString m_FootprintList
List of suitable footprint names for the part (wild card names accepted).
void SetDescription(const wxString &aDescription)
LIB_ID m_libId
wxArrayString & GetFootprints()
bool operator==(const LIB_PART *aPart) const
LIB_PART * GetPart() const
Get the shared LIB_PART.
int GetUnitCount() const
LIB_PIN * GetNextPin(LIB_PIN *aItem=NULL)
Return the next pin object from the draw list.
const wxString & GetDescription() override
const wxString & GetDocFileName() const
Base plotter engine class.
Definition: plotter.h:97
#define GR_DEFAULT_DRAWMODE
Definition: general.h:70
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:61
TRANSFORM DefaultTransform
Definition: eeschema.cpp:59
const wxString & GetName() const override
GR_DRAWMODE draw_mode
Device context drawing mode, see wxDC.
COLOR4D color
Color to draw part in.
void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
void SetKeyWords(const wxString &aKeyWords)
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:257
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
bool show_pin_text
Whether to show pin texts.
bool operator==(const LIB_ALIAS *aAlias) const
LIBRENTRYOPTIONS
static int * SubpartIdSeparatorPtr()
return a reference to m_subpartIdSeparator, only for read/save setting functions
bool only_selected
Draws only the body items that are selected, for block moves.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
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.
int tmpUnit
Temporary unit designator (used for rendering)
int tmpConversion
Temporary conversion designator (used for rendering)
bool draw_visible_fields
Whether to draw "visible" fields.
void SetShowPinNames(bool aShow)
Set or clear the pin name visibility flag.
void SetPinNameOffset(int aOffset)
Set the offset in mils of the pin name text from the pin symbol.
Object used to load, save, search, and otherwise manipulate symbol library files. ...
void SetLibId(const LIB_ID &aLibId)
TRANSFORM transform
Coordinate adjustment settings.
wxString keyWords
keyword list (used for search for parts by keyword)
bool IsNormal() const
void LockUnits(bool aLockUnits)
Set interchangeable the property for part units.
void SetNormal()
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
PART_SPTR m_me
http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared ...