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-2017 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_id.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 
69 extern const wxChar traceSchLibMem[];
70 
71 
81 class LIB_ALIAS : public EDA_ITEM
82 {
91 
92 protected:
93  wxString name;
94  wxString description;
95  wxString keyWords;
96  wxString docFileName;
97 
98 public:
99  LIB_ALIAS( const wxString& aName, LIB_PART* aRootComponent );
100  LIB_ALIAS( const LIB_ALIAS& aAlias, LIB_PART* aRootComponent = NULL );
101 
102  virtual ~LIB_ALIAS();
103 
104  virtual wxString GetClass() const override
105  {
106  return wxT( "LIB_ALIAS" );
107  }
108 
115  LIB_PART* GetPart() const
116  {
117  return shared;
118  }
119 
120  const wxString GetLibraryName();
121 
122  bool IsRoot() const;
123 
124  PART_LIB* GetLib();
125 
126  const wxString& GetName() const { return name; }
127 
128  void SetName( const wxString& aName ) { name = aName; }
129 
130  void SetDescription( const wxString& aDescription )
131  {
132  description = aDescription;
133  }
134 
135  wxString GetDescription() const { return description; }
136 
137  void SetKeyWords( const wxString& aKeyWords )
138  {
139  keyWords = aKeyWords;
140  }
141 
142  wxString GetKeyWords() const { return keyWords; }
143 
144  void SetDocFileName( const wxString& aDocFileName )
145  {
146  docFileName = aDocFileName;
147  }
148 
149  wxString GetDocFileName() const { return docFileName; }
150 
154  bool operator==( const wxChar* aName ) const;
155  bool operator!=( const wxChar* aName ) const
156  {
157  return !( *this == aName );
158  }
159 
160  bool operator==( const LIB_ALIAS* aAlias ) const { return this == aAlias; }
161 
162 #if defined(DEBUG)
163  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
164 #endif
165 };
166 
167 extern bool operator<( const LIB_ALIAS& aItem1, const LIB_ALIAS& aItem2 );
168 
169 extern int LibraryEntryCompare( const LIB_ALIAS* aItem1, const LIB_ALIAS* aItem2 );
170 
171 
173 {
181  std::vector<bool> dangling;
183 
185  {
186  PART_DRAW_OPTIONS def;
188  def.color = COLOR4D::UNSPECIFIED;
190  def.show_pin_text = true;
191  def.draw_visible_fields = true;
192  def.draw_hidden_fields = true;
193  def.only_selected = false;
194  def.show_elec_type = false;
195  return def;
196  }
197 
198  bool PinIsDangling( size_t aPin ) const
199  {
200  if( aPin < dangling.size() )
201  return dangling[aPin];
202  else
203  return true;
204  }
205 };
206 
207 
214 class LIB_PART : public EDA_ITEM
215 {
219  bool m_unitsLocked;
221  bool m_showPinNames;
228  wxArrayString m_FootprintList;
231  PART_LIB* m_library;
233 
234  static int m_subpartIdSeparator;
235  static int m_subpartFirstId;
238 private:
241  void deleteAllFields();
242 
243 
244 
245 public:
246 
247  LIB_PART( const wxString& aName, PART_LIB* aLibrary = NULL );
248  LIB_PART( LIB_PART& aPart, PART_LIB* aLibrary = NULL );
249 
250  virtual ~LIB_PART();
251 
253  {
254  // clone a shared pointer
255  return m_me;
256  }
257 
258  virtual wxString GetClass() const override
259  {
260  return wxT( "LIB_PART" );
261  }
262 
263  virtual void SetName( const wxString& aName );
264 
265  const wxString& GetName() const;
266 
267  const LIB_ID& GetLibId() const { return m_libId; }
268  void SetLibId( const LIB_ID& aLibId ) { m_libId = aLibId; }
269 
270  const wxString GetLibraryName();
271 
272  PART_LIB* GetLib() { return m_library; }
273 
274  void SetLib( PART_LIB* aLibrary ) { m_library = aLibrary; }
275 
276  wxArrayString GetAliasNames( bool aIncludeRoot = true ) const;
277 
278  size_t GetAliasCount() const { return m_aliases.size(); }
279 
280  LIB_ALIAS* GetAlias( size_t aIndex );
281 
282  LIB_ALIAS* GetAlias( const wxString& aName );
283 
284  timestamp_t GetDateLastEdition() const { return m_dateLastEdition; }
285 
294  void AddAlias( const wxString& aName );
295 
304  bool HasAlias( const wxString& aName ) const;
305 
306  void SetAliases( const wxArrayString& aAliasList );
307 
308  void RemoveAlias( const wxString& aName );
309  LIB_ALIAS* RemoveAlias( LIB_ALIAS* aAlias );
310 
311  void RemoveAllAliases();
312 
313  wxArrayString& GetFootprints() { return m_FootprintList; }
314 
325  const EDA_RECT GetUnitBoundingBox( int aUnit, int aConvert ) const;
326 
337  const EDA_RECT GetBodyBoundingBox( int aUnit, int aConvert ) const;
338 
339  const EDA_RECT GetBoundingBox() const override
340  {
341  return GetUnitBoundingBox( 0, 0 );
342  }
343 
352  bool SaveDateAndTime( OUTPUTFORMATTER& aFormatter );
353 
354  bool LoadDateAndTime( char* aLine );
355 
362  bool Save( OUTPUTFORMATTER& aFormatter );
363 
364  bool IsPower() const { return m_options == ENTRY_POWER; }
365  bool IsNormal() const { return m_options == ENTRY_NORMAL; }
366 
367  void SetPower() { m_options = ENTRY_POWER; }
368  void SetNormal() { m_options = ENTRY_NORMAL; }
369 
374  void LockUnits( bool aLockUnits ) { m_unitsLocked = aLockUnits; }
375 
380  bool UnitsLocked() const { return m_unitsLocked; }
381 
391  void SetFields( const std::vector <LIB_FIELD>& aFieldsList );
392 
400  void GetFields( LIB_FIELDS& aList );
401 
405  LIB_FIELD* FindField( const wxString& aFieldName );
406 
413  LIB_FIELD* GetField( int aId );
414 
416  LIB_FIELD& GetValueField();
417 
419  LIB_FIELD& GetReferenceField();
420 
422  LIB_FIELD& GetFootprintField();
423 
434  void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset,
435  int aMulti, int aConvert,
436  const PART_DRAW_OPTIONS& aOpts );
437 
449  void Plot( PLOTTER* aPlotter, int aUnit, int aConvert, const wxPoint& aOffset,
450  const TRANSFORM& aTransform );
451 
462  void PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert,
463  const wxPoint& aOffset, const TRANSFORM& aTransform );
464 
470  void AddDrawItem( LIB_ITEM* aItem );
471 
479  void RemoveDrawItem( LIB_ITEM* aItem, EDA_DRAW_PANEL* aPanel = NULL, wxDC* aDc = NULL );
480 
490  LIB_ITEM* GetNextDrawItem( LIB_ITEM* aItem = NULL, KICAD_T aType = TYPE_NOT_INIT );
491 
501  LIB_PIN* GetNextPin( LIB_PIN* aItem = NULL )
502  {
503  return (LIB_PIN*) GetNextDrawItem( (LIB_ITEM*) aItem, LIB_PIN_T );
504  }
505 
506 
520  void GetPins( LIB_PINS& aList, int aUnit = 0, int aConvert = 0 );
521 
532  LIB_PIN* GetPin( const wxString& aNumber, int aUnit = 0, int aConvert = 0 );
533 
546  bool PinsConflictWith( LIB_PART& aOtherPart, bool aTestNums, bool aTestNames,
547  bool aTestType, bool aTestOrientation, bool aTestLength );
548 
554  void SetOffset( const wxPoint& aOffset );
555 
559  void RemoveDuplicateDrawItems();
560 
566  bool HasConversion() const;
567 
571  void ClearStatus();
572 
586  int SelectItems( EDA_RECT& aRect, int aUnit, int aConvert, bool aSyncPinEdit );
587 
591  void ClearSelectedItems();
592 
600  void DeleteSelectedItems();
601 
605  void MoveSelectedItems( const wxPoint& aOffset );
606 
614  void CopySelectedItems( const wxPoint& aOffset );
615 
621  void MirrorSelectedItemsH( const wxPoint& aCenter );
622 
628  void MirrorSelectedItemsV( const wxPoint& aCenter );
629 
635  void RotateSelectedItems( const wxPoint& aCenter );
636 
646  LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, const wxPoint& aPoint );
647 
658  LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
659  const wxPoint& aPoint, const TRANSFORM& aTransform );
660 
667  {
668  return m_drawings;
669  }
670 
681  void SetUnitCount( int count );
682 
683  int GetUnitCount() const { return m_unitCount; }
684 
689  bool IsMulti() const { return m_unitCount > 1; }
690 
699  static wxString SubReference( int aUnit, bool aAddSeparator = true );
700 
701  // Accessors to sub ref parameters
702  static int GetSubpartIdSeparator() { return m_subpartIdSeparator; }
703 
707  static int* SubpartIdSeparatorPtr() { return &m_subpartIdSeparator; }
708 
709  static int GetSubpartFirstId() { return m_subpartFirstId; }
710 
713  static int* SubpartFirstIdPtr() { return &m_subpartFirstId; }
714 
725  static void SetSubpartIdNotation( int aSep, int aFirstId );
726 
738  void SetConversion( bool aSetConvert );
739 
747  void SetPinNameOffset( int aOffset ) { m_pinNameOffset = aOffset; }
748 
749  int GetPinNameOffset() { return m_pinNameOffset; }
750 
756  void SetShowPinNames( bool aShow ) { m_showPinNames = aShow; }
757 
758  bool ShowPinNames() { return m_showPinNames; }
759 
765  void SetShowPinNumbers( bool aShow ) { m_showPinNumbers = aShow; }
766 
767  bool ShowPinNumbers() { return m_showPinNumbers; }
768 
769  bool operator==( const LIB_PART* aPart ) const { return this == aPart; }
770 
771 #if defined(DEBUG)
772  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
773 #endif
774 };
775 
776 #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.
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: base_struct.h:173
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.
wxString description
documentation for info
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
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.
const wxString GetLibraryName()
Field object used in symbol libraries.
Definition: lib_field.h:59
std::weak_ptr< LIB_PART > PART_REF
weak pointer to LIB_PART
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 name
int LibraryEntryCompare(const LIB_ALIAS *aItem1, const LIB_ALIAS *aItem2)
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
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
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
wxString GetDescription() const
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.
Base plotter engine class.
Definition: plotter.h:96
wxString GetDocFileName() const
#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:58
GR_DRAWMODE draw_mode
Device context drawing mode, see wxDC.
COLOR4D color
Color to draw part in.
const wxChar traceSchLibMem[]
Flag to enable schematic library memory deletion debug output.
const wxString & GetName() const
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:180
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. ...
wxString GetKeyWords() const
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 ...