KiCad PCB EDA Suite
sch_component.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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2014 Dick Hollenbeck, dick@softplc.com
6  * Copyright (C) 2015-2017 Wayne Stambaugh <stambaughw@verizon.net>
7  * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
32 #ifndef COMPONENT_CLASS_H
33 #define COMPONENT_CLASS_H
34 
35 #include <lib_id.h>
36 
37 #include <sch_field.h>
38 #include <transform.h>
39 #include <general.h>
40 #include <vector>
41 #include <lib_draw_item.h>
42 
43 class SCH_SCREEN;
44 class SCH_SHEET_PATH;
45 class LIB_ITEM;
46 class LIB_PIN;
47 class LIB_PART;
49 class LIB_PART;
50 class PART_LIBS;
51 class SCH_COLLECTOR;
52 class SCH_SCREEN;
53 
54 
56 typedef std::vector<SCH_FIELD> SCH_FIELDS;
57 
58 typedef std::weak_ptr<LIB_PART> PART_REF;
59 
60 
61 extern std::string toUTFTildaText( const wxString& txt );
62 
63 
68 class SCH_COMPONENT : public SCH_ITEM
69 {
71 
72 public:
74 private:
75 
77 
80 
81  int m_unit;
82  int m_convert;
83  wxString m_prefix;
91 
93 
94  std::vector<bool> m_isDangling;
95 
97 
105 
112  wxArrayString m_PathsAndReferences;
113 
114  void Init( const wxPoint& pos = wxPoint( 0, 0 ) );
115 
116 public:
117  SCH_COMPONENT( const wxPoint& pos = wxPoint( 0, 0 ), SCH_ITEM* aParent = NULL );
118 
131  SCH_COMPONENT( LIB_PART& aPart, SCH_SHEET_PATH* aSheet,
132  int unit = 0, int convert = 0,
133  const wxPoint& pos = wxPoint( 0, 0 ),
134  bool setNewItemFlag = false );
135 
143  SCH_COMPONENT( const SCH_COMPONENT& aComponent );
144 
146 
147  wxString GetClass() const override
148  {
149  return wxT( "SCH_COMPONENT" );
150  }
151 
152  const wxArrayString& GetPathsAndReferences() const { return m_PathsAndReferences; }
153 
162  bool IsMovableFromAnchorPoint() override { return false; }
163 
164  void SetLibId( const LIB_ID& aName, PART_LIBS* aLibs=NULL );
165  const LIB_ID& GetLibId() const { return m_lib_id; }
166 
167  PART_REF& GetPartRef() { return m_part; }
168 
175  bool Resolve( PART_LIBS* aLibs );
176 
177  static void ResolveAll( const SCH_COLLECTOR& aComponents, PART_LIBS* aLibs );
178 
179  int GetUnit() const { return m_unit; }
180 
187  void SetUnit( int aUnit );
188 
196  void UpdateUnit( int aUnit );
197 
198  int GetConvert() const { return m_convert; }
199 
200  void SetConvert( int aConvert );
201 
202  wxString GetPrefix() const { return m_prefix; }
203 
204  void SetPrefix( const wxString& aPrefix ) { m_prefix = aPrefix; }
205 
206  TRANSFORM& GetTransform() const { return const_cast< TRANSFORM& >( m_transform ); }
207 
208  void SetTransform( const TRANSFORM& aTransform );
209 
216  int GetUnitCount() const;
217 
218  bool Save( FILE* aFile ) const override;
219 
220  bool Load( LINE_READER& aLine, wxString& aErrorMsg ) override;
221 
228  void SetOrientation( int aOrientation );
229 
244  int GetOrientation();
245 
253  wxPoint GetScreenCoord( const wxPoint& aPoint );
254 
255  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
256 
263  void ClearAnnotation( SCH_SHEET_PATH* aSheetPath );
264 
271  void SetTimeStamp( time_t aNewTimeStamp );
272 
273  const EDA_RECT GetBoundingBox() const override;
274 
280 
281 
282  //-----<Fields>-----------------------------------------------------------
283 
290  SCH_FIELD* GetField( int aFieldNdx ) const;
291 
298  void GetFields( std::vector<SCH_FIELD*>& aVector, bool aVisibleOnly );
299 
307  SCH_FIELD* AddField( const SCH_FIELD& aField );
308 
313  SCH_FIELD* FindField( const wxString& aFieldName );
314 
315  void SetFields( const SCH_FIELDS& aFields )
316  {
317  m_Fields = aFields; // vector copying, length is changed possibly
318  }
323  int GetFieldCount() const { return (int)m_Fields.size(); }
324 
330 
335  void ClearFieldsAutoplaced() { m_fieldsAutoplaced = AUTOPLACED_NO; }
336 
346  void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual );
347 
356  {
357  if( GetFieldsAutoplaced() )
359  }
360 
361 
362  //-----</Fields>----------------------------------------------------------
363 
364 
372  LIB_PIN* GetPin( const wxString& number );
373 
378  void GetPins( std::vector<LIB_PIN*>& aPinsList );
379 
383  void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
384  GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override
385  {
386  Draw( aPanel, aDC, aOffset, aDrawMode, aColor, true );
387  }
388 
401  void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
402  GR_DRAWMODE aDrawMode, COLOR4D aColor,
403  bool aDrawPinText );
404 
405  void SwapData( SCH_ITEM* aItem ) override;
406 
407  // returns a unique ID, in the form of a path.
408  wxString GetPath( const SCH_SHEET_PATH* sheet ) const;
409 
418  static bool IsReferenceStringValid( const wxString& aReferenceString );
419 
420  void SetCurrentSheetPath( const SCH_SHEET_PATH* aSheetPath )
421  {
422  m_currentSheetPath = aSheetPath;
423  }
424 
429  const wxString GetRef( const SCH_SHEET_PATH* sheet );
430 
434  void SetRef( const SCH_SHEET_PATH* sheet, const wxString& ref );
435 
444  void AddHierarchicalReference( const wxString& aPath,
445  const wxString& aRef,
446  int aMulti );
447 
448  // returns the unit selection, for the given sheet path.
449  int GetUnitSelection( SCH_SHEET_PATH* aSheet );
450 
451  // Set the unit selection, for the given sheet path.
452  void SetUnitSelection( SCH_SHEET_PATH* aSheet, int aUnitSelection );
453 
454  // Geometric transforms (used in block operations):
455 
456  void Move( const wxPoint& aMoveVector ) override
457  {
458  if( aMoveVector == wxPoint( 0, 0 ) )
459  return;
460 
461  m_Pos += aMoveVector;
462 
463  for( int ii = 0; ii < GetFieldCount(); ii++ )
464  GetField( ii )->Move( aMoveVector );
465 
466  SetModified();
467  }
468 
469  void MirrorY( int aYaxis_position ) override;
470 
471  void MirrorX( int aXaxis_position ) override;
472 
473  void Rotate( wxPoint aPosition ) override;
474 
475  bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation ) override;
476 
477  void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override;
478 
488  bool IsPinDanglingStateChanged( std::vector<DANGLING_END_ITEM>& aItemList,
489  LIB_PINS& aLibPins, unsigned aPin );
490 
498  bool IsDanglingStateChanged( std::vector<DANGLING_END_ITEM>& aItemList ) override;
499 
504  bool IsDangling() const override;
505 
507 
508  bool IsSelectStateChanged( const wxRect& aRect ) override;
509 
510  bool IsConnectable() const override { return true; }
511 
517  bool IsInNetlist() const;
518 
519  void GetConnectionPoints( std::vector<wxPoint>& aPoints ) const override;
520 
521  SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
522 
531  LIB_ITEM* GetDrawItem( const wxPoint& aPosition, KICAD_T aType = TYPE_NOT_INIT );
532 
533  wxString GetSelectMenuText() const override;
534 
535  BITMAP_DEF GetMenuImage() const override;
536 
537  void GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
538  SCH_SHEET_PATH* aSheetPath ) override;
539 
540  bool operator <( const SCH_ITEM& aItem ) const override;
541 
542  bool operator==( const SCH_COMPONENT& aComponent) const;
543  bool operator!=( const SCH_COMPONENT& aComponent) const;
544 
545  SCH_ITEM& operator=( const SCH_ITEM& aItem );
546 
547  bool IsReplaceable() const override { return true; }
548 
549  wxPoint GetPosition() const override { return m_Pos; }
550 
551  void SetPosition( const wxPoint& aPosition ) override { Move( aPosition - m_Pos ); }
552 
553  bool HitTest( const wxPoint& aPosition, int aAccuracy ) const override;
554 
555  bool HitTest( const EDA_RECT& aRect, bool aContained = false, int aAccuracy = 0 ) const override;
556 
557  void Plot( PLOTTER* aPlotter ) override;
558 
559  EDA_ITEM* Clone() const override;
560 
561 #if defined(DEBUG)
562  void Show( int nestLevel, std::ostream& os ) const override;
563 #endif
564 
565 private:
566  bool doIsConnected( const wxPoint& aPosition ) const override;
567 };
568 
569 
570 #endif /* COMPONENT_CLASS_H */
void Move(const wxPoint &aMoveVector) override
Function Move moves the item by aMoveVector to a new position.
Definition: sch_field.h:150
bool HitTest(const wxPoint &aPosition, int aAccuracy) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item...
Class SCH_FIELD instances are attached to a component and provide a place for the component's value...
Definition: sch_field.h:56
void SetModified()
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
void AutoAutoplaceFields(SCH_SCREEN *aScreen)
Function AutoAutoplaceFields Autoplace fields only if correct to do so automatically.
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
void Plot(PLOTTER *aPlotter) override
Function Plot plots the schematic item to aPlotter.
PART_REF & GetPartRef()
TRANSFORM & GetTransform() const
void SetTransform(const TRANSFORM &aTransform)
PNG memory record (file in memory).
Definition: bitmap_types.h:38
void UpdateUnit(int aUnit)
change the unit id to aUnit has maening only for multiple parts per package Do not change the modifie...
wxString GetPath(const SCH_SHEET_PATH *sheet) const
int GetOrientation()
Function GetOrientation Used to display component orientation (in dialog editor or info) ...
AUTOPLACED GetFieldsAutoplaced() const
Function GetFieldsAutoplaced returns whether the fields are autoplaced.
std::string toUTFTildaText(const wxString &txt)
Function toUTFTildaText convert a wxString to UTF8 and replace any control characters with a ~...
SCH_FIELDS m_Fields
Variable length list of fields.
Definition: sch_component.h:90
const SCH_SHEET_PATH * m_currentSheetPath
A temporary sheet path is required to generate the correct reference designator string in complex hei...
wxPoint GetScreenCoord(const wxPoint &aPoint)
Function GetScreenCoord Returns the coordinated point relative to the orientation of the component of...
bool Resolve(PART_LIBS *aLibs)
Function Resolve [re-]assigns the current LIB_PART from aLibs which this component is based on...
wxArrayString m_PathsAndReferences
Defines the hierarchical path and reference of the component.
bool IsConnectable() const override
Function IsConnectable returns true if the schematic item can connect to another schematic item...
wxPoint m_Pos
Name and library where symbol was loaded from, i.e. "74xx:74LS00".
Definition: sch_component.h:76
void GetConnectionPoints(std::vector< wxPoint > &aPoints) const override
Function GetConnectionPoints add all the connection points for this item to aPoints.
bool Save(FILE *aFile) const override
Function Save writes the data structures for this object out to a FILE in "*.sch" format...
std::weak_ptr< LIB_PART > PART_REF
weak pointer to LIB_PART
wxString GetPrefix() const
int GetUnitSelection(SCH_SHEET_PATH *aSheet)
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Function GetEndPoints adds the schematic item end points to aItemList if the item has end points...
void MirrorX(int aXaxis_position) override
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
SCH_FIELD * FindField(const wxString &aFieldName)
Function FindField searches for SCH_FIELD with aFieldName and returns it if found, else NULL.
void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
LIB_PIN * GetPin(const wxString &number)
Function GetPin finds a component pin by number.
void SetRef(const SCH_SHEET_PATH *sheet, const wxString &ref)
Set the reference, for the given sheet path.
LIB_ITEM * GetDrawItem(const wxPoint &aPosition, KICAD_T aType=TYPE_NOT_INIT)
Function GetDrawItem().
void SetUnitSelection(SCH_SHEET_PATH *aSheet, int aUnitSelection)
void SwapData(SCH_ITEM *aItem) override
Function SwapData swap the internal data structures aItem with the schematic item.
int GetUnitCount() const
Function GetUnitCount returns the number of parts per package of the component.
std::vector< bool > m_isDangling
One isDangling per pin.
Definition: sch_component.h:94
EDA_RECT GetBodyBoundingBox() const
Function GetBodyBoundingBox Return a bounding box for the component body but not the fields...
Class LIB_ID.
Definition: lib_id.h:56
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:90
Class LIB_ITEM is the base class for drawable items used by schematic library components.
Definition: lib_draw_item.h:77
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Function GetFields populates a std::vector with SCH_FIELDs.
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
void ClearFieldsAutoplaced()
Function ClearFieldsAutoplaced Set fields autoplaced flag false.
Class NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected item...
void SetConvert(int aConvert)
bool IsSelectStateChanged(const wxRect &aRect) override
Function IsSelectStateChanged checks if the selection state of an item inside aRect has changed...
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
void SetCurrentSheetPath(const SCH_SHEET_PATH *aSheetPath)
const INSPECTOR_FUNC & INSPECTOR
Definition: base_struct.h:104
Class SCH_COLLECTOR.
int GetConvert() const
void SetLibId(const LIB_ID &aName, PART_LIBS *aLibs=NULL)
void SetTimeStamp(time_t aNewTimeStamp)
Function SetTimeStamp changes the time stamp to aNewTimeStamp updates the reference path...
void Move(const wxPoint &aMoveVector) override
Function Move moves the item by aMoveVector to a new position.
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
PART_REF m_part
points into the PROJECT's libraries to the LIB_PART for this component
Definition: sch_component.h:92
bool IsMovableFromAnchorPoint() override
Virtual function IsMovableFromAnchorPoint Return true for items which are moved with the anchor point...
void SetFields(const SCH_FIELDS &aFields)
SCH_FIELD * GetField(int aFieldNdx) const
Function GetField returns a field.
static void ResolveAll(const SCH_COLLECTOR &aComponents, PART_LIBS *aLibs)
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
wxPoint GetPinPhysicalPosition(LIB_PIN *Pin)
std::vector< SCH_FIELD > SCH_FIELDS
A container for several SCH_FIELD items.
Definition: sch_component.h:52
bool operator<(const SCH_ITEM &aItem) const override
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
const wxArrayString & GetPathsAndReferences() const
SCH_COMPONENT(const wxPoint &pos=wxPoint(0, 0), SCH_ITEM *aParent=NULL)
Class LIB_PART defines a library part object.
SCH_FIELD * AddField(const SCH_FIELD &aField)
Function AddField adds a field to the component.
bool IsDangling() const override
Return whether any pin has dangling status.
void GetNetListItem(NETLIST_OBJECT_LIST &aNetListItems, SCH_SHEET_PATH *aSheetPath) override
Function GetNetListItem creates a new NETLIST_OBJECT for the schematic object and adds it to aNetList...
void SetUnit(int aUnit)
change the unit id to aUnit has maening only for multiple parts per package Also set the modified fla...
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation) override
Function Matches compares the item against the search criteria in aSearchData.
int GetUnit() const
Class SCH_SHEET_PATH.
bool IsInNetlist() const
bool IsReplaceable() const override
Function IsReplaceable.
void ClearAnnotation(SCH_SHEET_PATH *aSheetPath)
Function ClearAnnotation clears exiting component annotation ( i.i IC23 changed to IC...
bool Load(LINE_READER &aLine, wxString &aErrorMsg) override
Function Load reads a schematic item from aLine in a .sch file.
bool Show(bool show) override
bool operator==(const SCH_COMPONENT &aComponent) const
std::weak_ptr< LIB_PART > PART_REF
Definition: sch_component.h:58
SCH_ITEM & operator=(const SCH_ITEM &aItem)
Class PART_LIBS is a collection of PART_LIBs.
int m_unit
The unit for multiple part per package components.
Definition: sch_component.h:81
void Init(const wxPoint &pos=wxPoint(0, 0))
bool IsDanglingStateChanged(std::vector< DANGLING_END_ITEM > &aItemList) override
Test if the component's dangling state has changed for all pins.
Base plotter engine class.
Definition: plot_common.h:86
const wxString GetRef(const SCH_SHEET_PATH *sheet)
Function GetRef returns the reference, for the given sheet path.
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:70
void GetPins(std::vector< LIB_PIN * > &aPinsList)
Function GetPins populate a vector with all the pins.
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual)
Function AutoplaceFields Automatically orient all the fields in the component.
int GetFieldCount() const
Function GetFieldCount returns the number of fields in this component.
void AddHierarchicalReference(const wxString &aPath, const wxString &aRef, int aMulti)
Function AddHierarchicalReference adds a full hierarchical reference (path + local reference) ...
wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
void MirrorY(int aYaxis_position) override
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
bool IsPinDanglingStateChanged(std::vector< DANGLING_END_ITEM > &aItemList, LIB_PINS &aLibPins, unsigned aPin)
Test if the component's dangling state has changed for one given pin index.
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED) override
Virtual function, from the base class SCH_ITEM::Draw.
class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC is hand coded and implements DIALOG_EDIT_COMPONENT_IN_SCHEMA...
Class EDA_RECT handles the component boundary box.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:68
void SetPrefix(const wxString &aPrefix)
wxPoint GetPosition() const override
Function GetPosition.
const LIB_ID & GetLibId() const
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[]) override
Function Visit may be re-implemented for each derived class in order to handle all the types given by...
bool operator!=(const SCH_COMPONENT &aComponent) const
int m_convert
The alternate body style for components that have more than one body style defined.
Definition: sch_component.h:82
Definition of the SCH_FIELD class for Eeschema.
SEARCH_RESULT
Definition: base_struct.h:68
static bool IsReferenceStringValid(const wxString &aReferenceString)
Function IsReferenceStringValid (static) Tests for an acceptable reference string An acceptable refer...
wxString GetClass() const override
Function GetClass returns the class name.
AUTOPLACED m_fieldsAutoplaced
indicates status of field autoplacement
Definition: sch_component.h:96
wxString m_prefix
C, R, U, Q etc - the first character which typically indicates what the component is...
Definition: sch_component.h:85
TRANSFORM m_transform
The rotation/mirror transformation matrix.
Definition: sch_component.h:89
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
bool doIsConnected(const wxPoint &aPosition) const override
Function doIsConnected provides the object specific test to see if it is connected to aPosition...
void SetOrientation(int aOrientation)
Function SetOrientation computes the new transform matrix based on aOrientation for the component whi...
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39