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_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 
73 class LIB_ALIAS : public EDA_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  const wxString GetLibraryName();
113 
114  bool IsRoot() const;
115 
116  PART_LIB* GetLib();
117 
118  const wxString& GetName() const { return name; }
119 
120  void SetName( const wxString& aName );
121 
123  static void ValidateName( wxString& aName );
124 
125  void SetDescription( const wxString& aDescription )
126  {
127  description = aDescription;
128  }
129 
130  wxString GetDescription() const { return description; }
131 
132  void SetKeyWords( const wxString& aKeyWords )
133  {
134  keyWords = aKeyWords;
135  }
136 
137  wxString GetKeyWords() const { return keyWords; }
138 
139  void SetDocFileName( const wxString& aDocFileName )
140  {
141  docFileName = aDocFileName;
142  }
143 
144  wxString GetDocFileName() const { return docFileName; }
145 
149  bool operator==( const wxChar* aName ) const;
150  bool operator!=( const wxChar* aName ) const
151  {
152  return !( *this == aName );
153  }
154 
155  bool operator==( const LIB_ALIAS* aAlias ) const { return this == aAlias; }
156 
157 #if defined(DEBUG)
158  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
159 #endif
160 };
161 
162 extern bool operator<( const LIB_ALIAS& aItem1, const LIB_ALIAS& aItem2 );
163 
164 extern int LibraryEntryCompare( const LIB_ALIAS* aItem1, const LIB_ALIAS* aItem2 );
165 
166 
168 {
176  std::vector<bool> dangling;
178 
180  {
181  PART_DRAW_OPTIONS def;
183  def.color = COLOR4D::UNSPECIFIED;
185  def.show_pin_text = true;
186  def.draw_visible_fields = true;
187  def.draw_hidden_fields = true;
188  def.only_selected = false;
189  def.show_elec_type = false;
190  return def;
191  }
192 
193  bool PinIsDangling( size_t aPin ) const
194  {
195  if( aPin < dangling.size() )
196  return dangling[aPin];
197  else
198  return true;
199  }
200 };
201 
202 
209 class LIB_PART : public EDA_ITEM
210 {
214  bool m_unitsLocked;
216  bool m_showPinNames;
223  wxArrayString m_FootprintList;
226  PART_LIB* m_library;
228 
229  static int m_subpartIdSeparator;
230  static int m_subpartFirstId;
233 private:
236  void deleteAllFields();
237 
238 
239 
240 public:
241 
242  LIB_PART( const wxString& aName, PART_LIB* aLibrary = NULL );
243  LIB_PART( LIB_PART& aPart, PART_LIB* aLibrary = NULL );
244 
245  virtual ~LIB_PART();
246 
248  {
249  // clone a shared pointer
250  return m_me;
251  }
252 
253  virtual wxString GetClass() const override
254  {
255  return wxT( "LIB_PART" );
256  }
257 
258  virtual void SetName( const wxString& aName );
259 
260  const wxString& GetName() const;
261 
262  const LIB_ID& GetLibId() const { return m_libId; }
263  void SetLibId( const LIB_ID& aLibId ) { m_libId = aLibId; }
264 
265  const wxString GetLibraryName();
266 
267  PART_LIB* GetLib() { return m_library; }
268 
269  void SetLib( PART_LIB* aLibrary ) { m_library = aLibrary; }
270 
271  wxArrayString GetAliasNames( bool aIncludeRoot = true ) const;
272 
273  size_t GetAliasCount() const { return m_aliases.size(); }
274 
275  LIB_ALIAS* GetAlias( size_t aIndex );
276 
277  LIB_ALIAS* GetAlias( const wxString& aName );
278 
279  timestamp_t GetDateLastEdition() const { return m_dateLastEdition; }
280 
289  void AddAlias( const wxString& aName );
290 
299  bool HasAlias( const wxString& aName ) const;
300 
301  void SetAliases( const wxArrayString& aAliasList );
302 
303  void RemoveAlias( const wxString& aName );
304  LIB_ALIAS* RemoveAlias( LIB_ALIAS* aAlias );
305 
306  void RemoveAllAliases();
307 
308  wxArrayString& GetFootprints() { return m_FootprintList; }
309 
320  const EDA_RECT GetUnitBoundingBox( int aUnit, int aConvert ) const;
321 
332  const EDA_RECT GetBodyBoundingBox( int aUnit, int aConvert ) const;
333 
334  const EDA_RECT GetBoundingBox() const override
335  {
336  return GetUnitBoundingBox( 0, 0 );
337  }
338 
347  bool SaveDateAndTime( OUTPUTFORMATTER& aFormatter );
348 
349  bool LoadDateAndTime( char* aLine );
350 
357  bool Save( OUTPUTFORMATTER& aFormatter );
358 
359  bool IsPower() const { return m_options == ENTRY_POWER; }
360  bool IsNormal() const { return m_options == ENTRY_NORMAL; }
361 
362  void SetPower() { m_options = ENTRY_POWER; }
363  void SetNormal() { m_options = ENTRY_NORMAL; }
364 
369  void LockUnits( bool aLockUnits ) { m_unitsLocked = aLockUnits; }
370 
375  bool UnitsLocked() const { return m_unitsLocked; }
376 
386  void SetFields( const std::vector <LIB_FIELD>& aFieldsList );
387 
395  void GetFields( LIB_FIELDS& aList );
396 
400  LIB_FIELD* FindField( const wxString& aFieldName );
401 
408  LIB_FIELD* GetField( int aId );
409 
411  LIB_FIELD& GetValueField();
412 
414  LIB_FIELD& GetReferenceField();
415 
417  LIB_FIELD& GetFootprintField();
418 
429  void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset,
430  int aMulti, int aConvert,
431  const PART_DRAW_OPTIONS& aOpts );
432 
444  void Plot( PLOTTER* aPlotter, int aUnit, int aConvert, const wxPoint& aOffset,
445  const TRANSFORM& aTransform );
446 
457  void PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert,
458  const wxPoint& aOffset, const TRANSFORM& aTransform );
459 
465  void AddDrawItem( LIB_ITEM* aItem );
466 
474  void RemoveDrawItem( LIB_ITEM* aItem, EDA_DRAW_PANEL* aPanel = NULL, wxDC* aDc = NULL );
475 
485  LIB_ITEM* GetNextDrawItem( LIB_ITEM* aItem = NULL, KICAD_T aType = TYPE_NOT_INIT );
486 
496  LIB_PIN* GetNextPin( LIB_PIN* aItem = NULL )
497  {
498  return (LIB_PIN*) GetNextDrawItem( (LIB_ITEM*) aItem, LIB_PIN_T );
499  }
500 
501 
515  void GetPins( LIB_PINS& aList, int aUnit = 0, int aConvert = 0 );
516 
527  LIB_PIN* GetPin( const wxString& aNumber, int aUnit = 0, int aConvert = 0 );
528 
541  bool PinsConflictWith( LIB_PART& aOtherPart, bool aTestNums, bool aTestNames,
542  bool aTestType, bool aTestOrientation, bool aTestLength );
543 
549  void SetOffset( const wxPoint& aOffset );
550 
554  void RemoveDuplicateDrawItems();
555 
561  bool HasConversion() const;
562 
566  void ClearStatus();
567 
581  int SelectItems( EDA_RECT& aRect, int aUnit, int aConvert, bool aSyncPinEdit );
582 
586  void ClearSelectedItems();
587 
595  void DeleteSelectedItems();
596 
600  void MoveSelectedItems( const wxPoint& aOffset );
601 
609  void CopySelectedItems( const wxPoint& aOffset );
610 
616  void MirrorSelectedItemsH( const wxPoint& aCenter );
617 
623  void MirrorSelectedItemsV( const wxPoint& aCenter );
624 
630  void RotateSelectedItems( const wxPoint& aCenter );
631 
641  LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, const wxPoint& aPoint );
642 
653  LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType,
654  const wxPoint& aPoint, const TRANSFORM& aTransform );
655 
662  {
663  return m_drawings;
664  }
665 
676  void SetUnitCount( int count );
677 
678  int GetUnitCount() const { return m_unitCount; }
679 
684  bool IsMulti() const { return m_unitCount > 1; }
685 
694  static wxString SubReference( int aUnit, bool aAddSeparator = true );
695 
696  // Accessors to sub ref parameters
697  static int GetSubpartIdSeparator() { return m_subpartIdSeparator; }
698 
702  static int* SubpartIdSeparatorPtr() { return &m_subpartIdSeparator; }
703 
704  static int GetSubpartFirstId() { return m_subpartFirstId; }
705 
708  static int* SubpartFirstIdPtr() { return &m_subpartFirstId; }
709 
720  static void SetSubpartIdNotation( int aSep, int aFirstId );
721 
733  void SetConversion( bool aSetConvert );
734 
742  void SetPinNameOffset( int aOffset ) { m_pinNameOffset = aOffset; }
743 
744  int GetPinNameOffset() { return m_pinNameOffset; }
745 
751  void SetShowPinNames( bool aShow ) { m_showPinNames = aShow; }
752 
753  bool ShowPinNames() { return m_showPinNames; }
754 
760  void SetShowPinNumbers( bool aShow ) { m_showPinNumbers = aShow; }
761 
762  bool ShowPinNumbers() { return m_showPinNumbers; }
763 
764  bool operator==( const LIB_PART* aPart ) const { return this == aPart; }
765 
766 #if defined(DEBUG)
767  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
768 #endif
769 };
770 
771 #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:155
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 void ValidateName(wxString &aName)
Helper function to replace illegal chars in symbol names
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 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:162
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 ...