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 public:
91  LIB_ALIAS( const wxString& aName, LIB_PART* aRootComponent );
92  LIB_ALIAS( const LIB_ALIAS& aAlias, LIB_PART* aRootComponent = NULL );
93 
94  virtual ~LIB_ALIAS();
95 
96  virtual wxString GetClass() const override
97  {
98  return wxT( "LIB_ALIAS" );
99  }
100 
107  LIB_PART* GetPart() const
108  {
109  return shared;
110  }
111 
112  PART_LIB* GetLib();
113 
114  LIB_ID GetLibId() const override;
115 
116  wxString GetLibNickname() const override;
117  const wxString& GetName() const override { return name; }
118 
119  void SetName( const wxString& aName );
120 
121  void SetDescription( const wxString& aDescription )
122  {
123  description = aDescription;
124  }
125 
126  const wxString& GetDescription() override { return description; }
127 
128  void SetKeyWords( const wxString& aKeyWords )
129  {
130  keyWords = aKeyWords;
131  }
132 
133  const wxString& GetKeyWords() const { return keyWords; }
134 
135  void SetDocFileName( const wxString& aDocFileName )
136  {
137  docFileName = aDocFileName;
138  }
139 
140  const wxString& GetDocFileName() const { return docFileName; }
141 
142  wxString GetSearchText() override;
143 
147  bool IsRoot() const override;
148 
152  int GetUnitCount() override;
153 
157  wxString GetUnitReference( int aUnit ) override;
158 
162  bool operator==( const wxChar* aName ) const;
163  bool operator!=( const wxChar* aName ) const
164  {
165  return !( *this == aName );
166  }
167 
168  bool operator==( const LIB_ALIAS* aAlias ) const { return this == aAlias; }
169 
170 #if defined(DEBUG)
171  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
172 #endif
173 };
174 
175 extern bool operator<( const LIB_ALIAS& aItem1, const LIB_ALIAS& aItem2 );
176 
177 
179 {
187  std::vector<bool> dangling;
189 
191  {
192  PART_DRAW_OPTIONS def;
194  def.color = COLOR4D::UNSPECIFIED;
196  def.show_pin_text = true;
197  def.draw_visible_fields = true;
198  def.draw_hidden_fields = true;
199  def.only_selected = false;
200  def.show_elec_type = false;
201  return def;
202  }
203 
204  bool PinIsDangling( size_t aPin ) const
205  {
206  if( aPin < dangling.size() )
207  return dangling[aPin];
208  else
209  return true;
210  }
211 };
212 
213 
220 class LIB_PART : public EDA_ITEM
221 {
225  bool m_unitsLocked;
227  bool m_showPinNames;
234  wxArrayString m_FootprintList;
237  PART_LIB* m_library;
239 
240  static int m_subpartIdSeparator;
241  static int m_subpartFirstId;
244 private:
247  void deleteAllFields();
248 
249 
250 
251 public:
252 
253  LIB_PART( const wxString& aName, PART_LIB* aLibrary = NULL );
254  LIB_PART( LIB_PART& aPart, PART_LIB* aLibrary = NULL );
255 
256  virtual ~LIB_PART();
257 
259  {
260  // clone a shared pointer
261  return m_me;
262  }
263 
264  virtual wxString GetClass() const override
265  {
266  return wxT( "LIB_PART" );
267  }
268 
269  virtual void SetName( const wxString& aName );
270 
271  const wxString& GetName() const;
272 
273  const LIB_ID& GetLibId() const { return m_libId; }
274  void SetLibId( const LIB_ID& aLibId ) { m_libId = aLibId; }
275 
276  const wxString GetLibraryName();
277 
278  PART_LIB* GetLib() { return m_library; }
279 
280  void SetLib( PART_LIB* aLibrary ) { m_library = aLibrary; }
281 
282  wxArrayString GetAliasNames( bool aIncludeRoot = true ) const;
283 
284  LIB_ALIASES GetAliases() const { return m_aliases; }
285 
286  size_t GetAliasCount() const { return m_aliases.size(); }
287 
288  LIB_ALIAS* GetAlias( size_t aIndex );
289 
290  LIB_ALIAS* GetAlias( const wxString& aName );
291 
292  timestamp_t GetDateLastEdition() const { return m_dateLastEdition; }
293 
302  void AddAlias( const wxString& aName );
303 
304  void AddAlias( LIB_ALIAS* aAlias );
305 
314  bool HasAlias( const wxString& aName ) const;
315 
316  void RemoveAlias( const wxString& aName );
317  LIB_ALIAS* RemoveAlias( LIB_ALIAS* aAlias );
318 
319  void RemoveAllAliases();
320 
321  wxArrayString& GetFootprints() { return m_FootprintList; }
322 
333  const EDA_RECT GetUnitBoundingBox( int aUnit, int aConvert ) const;
334 
345  const EDA_RECT GetBodyBoundingBox( int aUnit, int aConvert ) const;
346 
347  const EDA_RECT GetBoundingBox() const override
348  {
349  return GetUnitBoundingBox( 0, 0 );
350  }
351 
360  bool SaveDateAndTime( OUTPUTFORMATTER& aFormatter );
361 
362  bool LoadDateAndTime( char* aLine );
363 
370  bool Save( OUTPUTFORMATTER& aFormatter );
371 
372  bool IsPower() const { return m_options == ENTRY_POWER; }
373  bool IsNormal() const { return m_options == ENTRY_NORMAL; }
374 
375  void SetPower() { m_options = ENTRY_POWER; }
376  void SetNormal() { m_options = ENTRY_NORMAL; }
377 
382  void LockUnits( bool aLockUnits ) { m_unitsLocked = aLockUnits; }
383 
388  bool UnitsLocked() const { return m_unitsLocked; }
389 
399  void SetFields( const std::vector <LIB_FIELD>& aFieldsList );
400 
408  void GetFields( LIB_FIELDS& aList );
409 
413  LIB_FIELD* FindField( const wxString& aFieldName );
414 
421  LIB_FIELD* GetField( int aId );
422 
424  LIB_FIELD& GetValueField();
425 
427  LIB_FIELD& GetReferenceField();
428 
430  LIB_FIELD& GetFootprintField();
431 
442  void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset,
443  int aMulti, int aConvert,
444  const PART_DRAW_OPTIONS& aOpts );
445 
457  void Plot( PLOTTER* aPlotter, int aUnit, int aConvert, const wxPoint& aOffset,
458  const TRANSFORM& aTransform );
459 
470  void PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert,
471  const wxPoint& aOffset, const TRANSFORM& aTransform );
472 
478  void AddDrawItem( LIB_ITEM* aItem );
479 
487  void RemoveDrawItem( LIB_ITEM* aItem, EDA_DRAW_PANEL* aPanel = NULL, wxDC* aDc = NULL );
488 
498  LIB_ITEM* GetNextDrawItem( LIB_ITEM* aItem = NULL, KICAD_T aType = TYPE_NOT_INIT );
499 
509  LIB_PIN* GetNextPin( LIB_PIN* aItem = NULL )
510  {
511  return (LIB_PIN*) GetNextDrawItem( (LIB_ITEM*) aItem, LIB_PIN_T );
512  }
513 
514 
528  void GetPins( LIB_PINS& aList, int aUnit = 0, int aConvert = 0 );
529 
540  LIB_PIN* GetPin( const wxString& aNumber, int aUnit = 0, int aConvert = 0 );
541 
554  bool PinsConflictWith( LIB_PART& aOtherPart, bool aTestNums, bool aTestNames,
555  bool aTestType, bool aTestOrientation, bool aTestLength );
556 
562  void SetOffset( const wxPoint& aOffset );
563 
567  void RemoveDuplicateDrawItems();
568 
574  bool HasConversion() const;
575 
579  void ClearStatus();
580 
594  int SelectItems( EDA_RECT& aRect, int aUnit, int aConvert, bool aSyncPinEdit );
595 
599  void ClearSelectedItems();
600 
608  void DeleteSelectedItems();
609 
613  void MoveSelectedItems( const wxPoint& aOffset );
614 
622  void CopySelectedItems( const wxPoint& aOffset );
623 
629  void MirrorSelectedItemsH( const wxPoint& aCenter );
630 
636  void MirrorSelectedItemsV( const wxPoint& aCenter );
637 
643  void RotateSelectedItems( const wxPoint& aCenter );
644 
654  LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, const wxPoint& aPoint );
655 
666  LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
667  const wxPoint& aPoint, const TRANSFORM& aTransform );
668 
675  {
676  return m_drawings;
677  }
678 
689  void SetUnitCount( int count );
690 
691  int GetUnitCount() const { return m_unitCount; }
692 
697  bool IsMulti() const { return m_unitCount > 1; }
698 
707  static wxString SubReference( int aUnit, bool aAddSeparator = true );
708 
709  // Accessors to sub ref parameters
710  static int GetSubpartIdSeparator() { return m_subpartIdSeparator; }
711 
715  static int* SubpartIdSeparatorPtr() { return &m_subpartIdSeparator; }
716 
717  static int GetSubpartFirstId() { return m_subpartFirstId; }
718 
721  static int* SubpartFirstIdPtr() { return &m_subpartFirstId; }
722 
733  static void SetSubpartIdNotation( int aSep, int aFirstId );
734 
746  void SetConversion( bool aSetConvert );
747 
755  void SetPinNameOffset( int aOffset ) { m_pinNameOffset = aOffset; }
756 
757  int GetPinNameOffset() { return m_pinNameOffset; }
758 
764  void SetShowPinNames( bool aShow ) { m_showPinNames = aShow; }
765 
766  bool ShowPinNames() { return m_showPinNames; }
767 
773  void SetShowPinNumbers( bool aShow ) { m_showPinNumbers = aShow; }
774 
775  bool ShowPinNumbers() { return m_showPinNumbers; }
776 
777  bool operator==( const LIB_PART* aPart ) const { return this == aPart; }
778 
779 #if defined(DEBUG)
780  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
781 #endif
782 };
783 
784 #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
The base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:66
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
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:60
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.
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 ...