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 
104  // a LIB_ALIAS does not really have a bounding box.
105  // But because it is derived from EDA_ITEM, returns a dummy bounding box
106  // to avoid useless messages in debug mode
107  const EDA_RECT GetBoundingBox() const override;
108 
115  LIB_PART* GetPart() const
116  {
117  return shared;
118  }
119 
120  PART_LIB* GetLib();
121 
122  LIB_ID GetLibId() const override;
123 
124  wxString GetLibNickname() const override;
125  const wxString& GetName() const override { return name; }
126 
127  void SetName( const wxString& aName );
128 
129  void SetDescription( const wxString& aDescription )
130  {
131  description = aDescription;
132  }
133 
134  const wxString& GetDescription() override { return description; }
135 
136  void SetKeyWords( const wxString& aKeyWords )
137  {
138  keyWords = aKeyWords;
139  }
140 
141  const wxString& GetKeyWords() const { return keyWords; }
142 
143  void SetDocFileName( const wxString& aDocFileName )
144  {
145  docFileName = aDocFileName;
146  }
147 
148  const wxString& GetDocFileName() const { return docFileName; }
149 
150  wxString GetSearchText() override;
151 
155  bool IsRoot() const override;
156 
160  int GetUnitCount() override;
161 
165  wxString GetUnitReference( int aUnit ) override;
166 
170  void SetTmpConversion( int aConversion ) { tmpConversion = aConversion; }
171  int GetTmpConversion() { return tmpConversion; }
172 
176  bool operator==( const wxChar* aName ) const;
177  bool operator!=( const wxChar* aName ) const
178  {
179  return !( *this == aName );
180  }
181 
182  bool operator==( const LIB_ALIAS* aAlias ) const { return this == aAlias; }
183 
184  void ViewGetLayers( int aLayers[], int& aCount ) const override;
185 
186 #if defined(DEBUG)
187  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
188 #endif
189 };
190 
191 extern bool operator<( const LIB_ALIAS& aItem1, const LIB_ALIAS& aItem2 );
192 
193 
195 {
203  std::vector<bool> dangling;
205 
207  {
208  PART_DRAW_OPTIONS def;
210  def.color = COLOR4D::UNSPECIFIED;
212  def.show_pin_text = true;
213  def.draw_visible_fields = true;
214  def.draw_hidden_fields = true;
215  def.only_selected = false;
216  def.show_elec_type = false;
217  return def;
218  }
219 
220  bool PinIsDangling( size_t aPin ) const
221  {
222  if( aPin < dangling.size() )
223  return dangling[aPin];
224  else
225  return true;
226  }
227 };
228 
229 
236 class LIB_PART : public EDA_ITEM
237 {
241  bool m_unitsLocked;
243  bool m_showPinNames;
250  wxArrayString m_FootprintList;
253  PART_LIB* m_library;
255 
256  static int m_subpartIdSeparator;
257  static int m_subpartFirstId;
260 private:
263  void deleteAllFields();
264 
265 
266 
267 public:
268 
269  LIB_PART( const wxString& aName, PART_LIB* aLibrary = NULL );
270  LIB_PART( LIB_PART& aPart, PART_LIB* aLibrary = NULL );
271 
272  virtual ~LIB_PART();
273 
275  {
276  // clone a shared pointer
277  return m_me;
278  }
279 
280  virtual wxString GetClass() const override
281  {
282  return wxT( "LIB_PART" );
283  }
284 
285  virtual void SetName( const wxString& aName );
286 
287  const wxString& GetName() const;
288 
289  const LIB_ID& GetLibId() const { return m_libId; }
290  void SetLibId( const LIB_ID& aLibId ) { m_libId = aLibId; }
291 
292  const wxString GetLibraryName();
293 
294  PART_LIB* GetLib() { return m_library; }
295 
296  void SetLib( PART_LIB* aLibrary ) { m_library = aLibrary; }
297 
298  wxArrayString GetAliasNames( bool aIncludeRoot = true ) const;
299 
300  LIB_ALIASES GetAliases() const { return m_aliases; }
301 
302  size_t GetAliasCount() const { return m_aliases.size(); }
303 
304  LIB_ALIAS* GetAlias( size_t aIndex );
305 
306  LIB_ALIAS* GetAlias( const wxString& aName );
307 
308  timestamp_t GetDateLastEdition() const { return m_dateLastEdition; }
309 
318  void AddAlias( const wxString& aName );
319 
320  void AddAlias( LIB_ALIAS* aAlias );
321 
330  bool HasAlias( const wxString& aName ) const;
331 
332  void RemoveAlias( const wxString& aName );
333  LIB_ALIAS* RemoveAlias( LIB_ALIAS* aAlias );
334 
335  void RemoveAllAliases();
336 
337  wxArrayString& GetFootprints() { return m_FootprintList; }
338 
339  void ViewGetLayers( int aLayers[], int& aCount ) const override;
340 
351  const EDA_RECT GetUnitBoundingBox( int aUnit, int aConvert ) const;
352 
363  const EDA_RECT GetBodyBoundingBox( int aUnit, int aConvert ) const;
364 
365  const EDA_RECT GetBoundingBox() const override
366  {
367  return GetUnitBoundingBox( 0, 0 );
368  }
369 
378  bool SaveDateAndTime( OUTPUTFORMATTER& aFormatter );
379 
380  bool LoadDateAndTime( char* aLine );
381 
388  bool Save( OUTPUTFORMATTER& aFormatter );
389 
390  bool IsPower() const { return m_options == ENTRY_POWER; }
391  bool IsNormal() const { return m_options == ENTRY_NORMAL; }
392 
393  void SetPower() { m_options = ENTRY_POWER; }
394  void SetNormal() { m_options = ENTRY_NORMAL; }
395 
400  void LockUnits( bool aLockUnits ) { m_unitsLocked = aLockUnits; }
401 
406  bool UnitsLocked() const { return m_unitsLocked; }
407 
417  void SetFields( const std::vector <LIB_FIELD>& aFieldsList );
418 
424  void GetFields( LIB_FIELDS& aList );
425 
429  LIB_FIELD* FindField( const wxString& aFieldName );
430 
437  LIB_FIELD* GetField( int aId );
438 
440  LIB_FIELD& GetValueField();
441 
443  LIB_FIELD& GetReferenceField();
444 
446  LIB_FIELD& GetFootprintField();
447 
458  void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset,
459  int aMulti, int aConvert,
460  const PART_DRAW_OPTIONS& aOpts );
461 
473  void Plot( PLOTTER* aPlotter, int aUnit, int aConvert, const wxPoint& aOffset,
474  const TRANSFORM& aTransform );
475 
486  void PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert,
487  const wxPoint& aOffset, const TRANSFORM& aTransform );
488 
494  void AddDrawItem( LIB_ITEM* aItem );
495 
503  void RemoveDrawItem( LIB_ITEM* aItem, EDA_DRAW_PANEL* aPanel = NULL, wxDC* aDc = NULL );
504 
514  LIB_ITEM* GetNextDrawItem( LIB_ITEM* aItem = NULL, KICAD_T aType = TYPE_NOT_INIT );
515 
525  LIB_PIN* GetNextPin( LIB_PIN* aItem = NULL )
526  {
527  return (LIB_PIN*) GetNextDrawItem( (LIB_ITEM*) aItem, LIB_PIN_T );
528  }
529 
530 
544  void GetPins( LIB_PINS& aList, int aUnit = 0, int aConvert = 0 );
545 
556  LIB_PIN* GetPin( const wxString& aNumber, int aUnit = 0, int aConvert = 0 );
557 
570  bool PinsConflictWith( LIB_PART& aOtherPart, bool aTestNums, bool aTestNames,
571  bool aTestType, bool aTestOrientation, bool aTestLength );
572 
578  void SetOffset( const wxPoint& aOffset );
579 
583  void RemoveDuplicateDrawItems();
584 
590  bool HasConversion() const;
591 
595  void ClearStatus();
596 
606  LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, const wxPoint& aPoint );
607 
618  LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
619  const wxPoint& aPoint, const TRANSFORM& aTransform );
620 
627  {
628  return m_drawings;
629  }
630 
641  void SetUnitCount( int count );
642 
643  int GetUnitCount() const { return m_unitCount; }
644 
649  bool IsMulti() const { return m_unitCount > 1; }
650 
659  static wxString SubReference( int aUnit, bool aAddSeparator = true );
660 
661  // Accessors to sub ref parameters
662  static int GetSubpartIdSeparator() { return m_subpartIdSeparator; }
663 
667  static int* SubpartIdSeparatorPtr() { return &m_subpartIdSeparator; }
668 
669  static int GetSubpartFirstId() { return m_subpartFirstId; }
670 
673  static int* SubpartFirstIdPtr() { return &m_subpartFirstId; }
674 
685  static void SetSubpartIdNotation( int aSep, int aFirstId );
686 
698  void SetConversion( bool aSetConvert );
699 
707  void SetPinNameOffset( int aOffset ) { m_pinNameOffset = aOffset; }
708 
709  int GetPinNameOffset() { return m_pinNameOffset; }
710 
716  void SetShowPinNames( bool aShow ) { m_showPinNames = aShow; }
717 
718  bool ShowPinNames() { return m_showPinNames; }
719 
725  void SetShowPinNumbers( bool aShow ) { m_showPinNumbers = aShow; }
726 
727  bool ShowPinNumbers() { return m_showPinNumbers; }
728 
729  bool operator==( const LIB_PART* aPart ) const { return this == aPart; }
730 
731 #if defined(DEBUG)
732  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
733 #endif
734 };
735 
736 #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.
void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on...
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
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
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:259
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:154
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 ...