KiCad PCB EDA Suite
sch_item.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 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef SCH_ITEM_H
26 #define SCH_ITEM_H
27 
28 #include <unordered_map>
29 #include <unordered_set>
30 #include <vector>
31 
32 #include <base_struct.h>
33 #include <general.h>
34 #include <sch_sheet_path.h>
35 
36 class SCH_CONNECTION;
37 class SCH_SHEET_PATH;
38 class LINE_READER;
39 class SCH_EDIT_FRAME;
40 class wxFindReplaceData;
41 class PLOTTER;
42 class NETLIST_OBJECT;
44 
45 
47 {
51 };
52 
53 
55 {
56  UNKNOWN = 0,
68 };
69 
70 
77 {
78 private:
81 
84 
87 
90 
91 public:
92  DANGLING_END_ITEM( DANGLING_END_T aType, EDA_ITEM* aItem, const wxPoint& aPosition )
93  {
94  m_item = aItem;
95  m_type = aType;
96  m_pos = aPosition;
97  m_parent = aItem;
98  }
99 
101  const wxPoint& aPosition, const EDA_ITEM* aParent )
102  {
103  m_item = aItem;
104  m_type = aType;
105  m_pos = aPosition;
106  m_parent = aParent;
107  }
108 
109  bool operator==( const DANGLING_END_ITEM& aB )
110  {
111  return GetItem() == aB.GetItem()
112  && GetPosition() == aB.GetPosition()
113  && GetType() == aB.GetType()
114  && GetParent() == aB.GetParent();
115  }
116 
117  bool operator!=( const DANGLING_END_ITEM& aB )
118  {
119  return GetItem() != aB.GetItem()
120  || GetPosition() != aB.GetPosition()
121  || GetType() != aB.GetType()
122  || GetParent() != aB.GetParent();;
123  }
124 
125  bool operator<( const DANGLING_END_ITEM& rhs ) const
126  {
127  return( m_pos.x < rhs.m_pos.x || ( m_pos.x == rhs.m_pos.x && m_pos.y < rhs.m_pos.y )
128  || ( m_pos == rhs.m_pos && m_item < rhs.m_item ) );
129  }
130 
131  wxPoint GetPosition() const { return m_pos; }
132  EDA_ITEM* GetItem() const { return m_item; }
133  const EDA_ITEM* GetParent() const { return m_parent; }
134  DANGLING_END_T GetType() const { return m_type; }
135 };
136 
137 
138 typedef std::unordered_set<SCH_ITEM*> ITEM_SET;
139 
147 class SCH_ITEM : public EDA_ITEM
148 {
149  friend class CONNECTION_GRAPH;
150 
151 protected:
153  EDA_ITEMS m_connections; // List of items connected to this item.
154  FIELDS_AUTOPLACED m_fieldsAutoplaced; // indicates status of field autoplacement
155  wxPoint m_storedPos; // a temporary variable used in some move commands
156  // to store a initial pos of the item or mouse cursor
157 
159  std::unordered_map<SCH_SHEET_PATH, ITEM_SET> m_connected_items;
160 
162  std::unordered_map<SCH_SHEET_PATH, SCH_CONNECTION*> m_connection_map;
163 
166 
167 public:
168  SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType );
169 
170  SCH_ITEM( const SCH_ITEM& aItem );
171 
172  ~SCH_ITEM();
173 
174  virtual wxString GetClass() const override
175  {
176  return wxT( "SCH_ITEM" );
177  }
178 
185  virtual void SwapData( SCH_ITEM* aItem );
186 
194  SCH_ITEM* Duplicate( bool doClone = false ) const;
195 
203  virtual bool IsMovableFromAnchorPoint() { return true; }
204 
206  void SetStoredPos( wxPoint aPos ) { m_storedPos = aPos; }
207 
212  virtual bool IsLocked() const { return false; }
213 
218  virtual void SetLocked( bool aLocked ) {}
219 
224  SCH_LAYER_ID GetLayer() const { return m_Layer; }
225 
231  void SetLayer( SCH_LAYER_ID aLayer ) { m_Layer = aLayer; }
232 
237  void ViewGetLayers( int aLayers[], int& aCount ) const override;
238 
243  virtual int GetPenSize() const { return 0; }
244 
252  virtual void Print( wxDC* aDC, const wxPoint& aOffset ) = 0;
253 
259  virtual void Move( const wxPoint& aMoveVector ) = 0;
260 
266  virtual void MirrorY( int aYaxis_position ) = 0;
267 
273  virtual void MirrorX( int aXaxis_position ) = 0;
274 
281  virtual void Rotate( wxPoint aPosition ) = 0;
282 
291  virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ) { return false; }
292 
304  virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) {}
305 
323  virtual bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
324  const SCH_SHEET_PATH* aPath = nullptr )
325  {
326  return false;
327  }
328 
329  virtual bool IsDangling() const { return false; }
330 
331  virtual bool CanConnect( const SCH_ITEM* aItem ) const { return m_Layer == aItem->GetLayer(); }
332 
337  virtual bool IsConnectable() const { return false; }
338 
347  virtual void GetConnectionPoints( std::vector< wxPoint >& aPoints ) const { }
348 
356  void ClearConnections() { m_connections.clear(); }
357 
365  bool IsConnected( const wxPoint& aPoint ) const;
366 
371  SCH_CONNECTION* Connection( const SCH_SHEET_PATH& aPath ) const;
372 
376  ITEM_SET& ConnectedItems( const SCH_SHEET_PATH& aPath );
377 
381  void AddConnectionTo( const SCH_SHEET_PATH& aPath, SCH_ITEM* aItem );
382 
389 
393  virtual bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const { return true; }
394 
396 
397  void SetConnectivityDirty( bool aDirty = true ) { m_connectivity_dirty = aDirty; }
398 
399  virtual bool CanIncrementLabel() const { return false; }
400 
405 
410 
420  {
421  if( GetFieldsAutoplaced() )
423  }
424 
425  virtual void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) { }
426 
433  virtual void Plot( PLOTTER* aPlotter );
434 
445  virtual void GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
446  SCH_SHEET_PATH* aSheetPath ) { }
447 
452  virtual wxPoint GetPosition() const = 0;
453 
460  virtual void SetPosition( const wxPoint& aPosition ) = 0;
461 
462  virtual bool operator <( const SCH_ITEM& aItem ) const;
463 
464 private:
479  virtual bool doIsConnected( const wxPoint& aPosition ) const { return false; }
480 };
481 
482 #endif /* SCH_ITEM_H */
bool operator<(const DANGLING_END_ITEM &rhs) const
Definition: sch_item.h:125
SCH_LAYER_ID m_Layer
Definition: sch_item.h:152
LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived to re...
Definition: richio.h:81
wxPoint GetPosition() const
Definition: sch_item.h:131
virtual bool IsConnectable() const
Function IsConnectable returns true if the schematic item can connect to another schematic item.
Definition: sch_item.h:337
ITEM_SET & ConnectedItems(const SCH_SHEET_PATH &aPath)
Retrieves the set of items connected to this item on the given sheet.
Definition: sch_item.cpp:138
std::unordered_map< SCH_SHEET_PATH, ITEM_SET > m_connected_items
Stores pointers to other items that are connected to this one, per sheet.
Definition: sch_item.h:159
virtual bool Load(LINE_READER &aLine, wxString &aErrorMsg)
Function Load reads a schematic item from aLine in a .sch file.
Definition: sch_item.h:291
const EDA_ITEM * GetParent() const
Definition: sch_item.h:133
virtual bool IsMovableFromAnchorPoint()
Virtual function IsMovableFromAnchorPoint.
Definition: sch_item.h:203
virtual void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList)
Function GetEndPoints adds the schematic item end points to aItemList if the item has end points.
Definition: sch_item.h:304
Calculates the connectivity of a schematic and generates netlists.
void AutoAutoplaceFields(SCH_SCREEN *aScreen)
Autoplace fields only if correct to do so automatically.
Definition: sch_item.h:419
void AddConnectionTo(const SCH_SHEET_PATH &aPath, SCH_ITEM *aItem)
Adds a connection link between this item and another.
Definition: sch_item.cpp:144
virtual bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const
Returns true if this item should propagate connection info to aItem.
Definition: sch_item.h:393
virtual void Print(wxDC *aDC, const wxPoint &aOffset)=0
Function Print Print a schematic item.
EDA_ITEMS m_connections
Definition: sch_item.h:153
virtual void GetConnectionPoints(std::vector< wxPoint > &aPoints) const
Function GetConnectionPoints add all the connection points for this item to aPoints.
Definition: sch_item.h:347
virtual bool CanIncrementLabel() const
Definition: sch_item.h:399
bool IsConnectivityDirty()
Definition: sch_item.h:395
Schematic editor (Eeschema) main window.
virtual void SetLocked(bool aLocked)
Function SetLocked modifies 'lock' status for of the item.
Definition: sch_item.h:218
FIELDS_AUTOPLACED m_fieldsAutoplaced
Definition: sch_item.h:154
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
FIELDS_AUTOPLACED GetFieldsAutoplaced() const
Return whether the fields have been automatically placed.
Definition: sch_item.h:404
NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected items in a...
virtual bool UpdateDanglingState(std::vector< DANGLING_END_ITEM > &aItemList, const SCH_SHEET_PATH *aPath=nullptr)
Function IsDanglingStateChanged tests the schematic item to aItemList to check if it's dangling state...
Definition: sch_item.h:323
virtual void Rotate(wxPoint aPosition)=0
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
DANGLING_END_T m_type
The type of connection of m_item.
Definition: sch_item.h:86
wxPoint & GetStoredPos()
Definition: sch_item.h:205
virtual wxPoint GetPosition() const =0
Function GetPosition.
virtual bool CanConnect(const SCH_ITEM *aItem) const
Definition: sch_item.h:331
virtual int GetPenSize() const
Function GetPenSize virtual pure.
Definition: sch_item.h:243
SCH_ITEM * Duplicate(bool doClone=false) const
Routine to create a new copy of given item.
Definition: sch_item.cpp:75
virtual void SwapData(SCH_ITEM *aItem)
Function SwapData swap the internal data structures aItem with the schematic item.
Definition: sch_item.cpp:166
virtual void SetPosition(const wxPoint &aPosition)=0
Function SetPosition set the schematic item position to aPosition.
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:603
virtual void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual)
Definition: sch_item.h:425
void SetLayer(SCH_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Definition: sch_item.h:231
EDA_ITEM * GetItem() const
Definition: sch_item.h:132
void ClearFieldsAutoplaced()
Set fields automatically placed flag false.
Definition: sch_item.h:409
bool m_connectivity_dirty
True if connectivity info might be out of date.
Definition: sch_item.h:165
SCH_LAYER_ID
Eeschema drawing layers.
virtual void MirrorX(int aXaxis_position)=0
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
std::unordered_map< SCH_SHEET_PATH, SCH_CONNECTION * > m_connection_map
Stores connectivity information, per sheet.
Definition: sch_item.h:162
SCH_SHEET_PATH.
DANGLING_END_ITEM(DANGLING_END_T aType, EDA_ITEM *aItem, const wxPoint &aPosition, const EDA_ITEM *aParent)
Definition: sch_item.h:100
std::unordered_set< SCH_ITEM * > ITEM_SET
Definition: sch_item.h:138
virtual void MirrorY(int aYaxis_position)=0
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers returns the layers the item is drawn on (which may be more than its "home" lay...
Definition: sch_item.cpp:110
SCH_CONNECTION * Connection(const SCH_SHEET_PATH &aPath) const
Retrieves the connection associated with this object in the given sheet Note: the returned value can ...
Definition: sch_item.cpp:128
FIELDS_AUTOPLACED
Definition: sch_item.h:46
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
Definition: sch_item.h:224
virtual bool IsLocked() const
Function IsLocked.
Definition: sch_item.h:212
EDA_ITEM * m_item
A pointer to the connectable object.
Definition: sch_item.h:80
virtual void Plot(PLOTTER *aPlotter)
Function Plot plots the schematic item to aPlotter.
Definition: sch_item.cpp:187
Base plotter engine class.
Definition: plotter.h:104
bool operator==(const DANGLING_END_ITEM &aB)
Definition: sch_item.h:109
DANGLING_END_ITEM(DANGLING_END_T aType, EDA_ITEM *aItem, const wxPoint &aPosition)
Definition: sch_item.h:92
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
void ClearConnections()
Function ClearConnections clears all of the connection items from the list.
Definition: sch_item.h:356
~SCH_ITEM()
Definition: sch_item.cpp:62
DANGLING_END_T GetType() const
Definition: sch_item.h:134
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:166
wxPoint m_pos
The position of the connection point.
Definition: sch_item.h:83
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_item.h:174
virtual bool operator<(const SCH_ITEM &aItem) const
Definition: sch_item.cpp:172
wxPoint m_storedPos
Definition: sch_item.h:155
virtual bool doIsConnected(const wxPoint &aPosition) const
Function doIsConnected provides the object specific test to see if it is connected to aPosition.
Definition: sch_item.h:479
virtual bool IsDangling() const
Definition: sch_item.h:329
DANGLING_END_ITEM is a helper class used to store the state of schematic items that can be connected ...
Definition: sch_item.h:76
SCH_CONNECTION * InitializeConnection(const SCH_SHEET_PATH &aPath)
Creates a new connection object associated with this object.
Definition: sch_item.cpp:150
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
DANGLING_END_T
Definition: sch_item.h:54
void SetStoredPos(wxPoint aPos)
Definition: sch_item.h:206
SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
bool IsConnected(const wxPoint &aPoint) const
Function IsConnected tests the item to see if it is connected to aPoint.
Definition: sch_item.cpp:119
const EDA_ITEM * m_parent
A pointer to the parent object (in the case of pins)
Definition: sch_item.h:89
bool operator!=(const DANGLING_END_ITEM &aB)
Definition: sch_item.h:117
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:397
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType)
Definition: sch_item.cpp:46
virtual void GetNetListItem(NETLIST_OBJECT_LIST &aNetListItems, SCH_SHEET_PATH *aSheetPath)
Function GetNetListItem creates a new NETLIST_OBJECT for the schematic object and adds it to aNetList...
Definition: sch_item.h:445
virtual void Move(const wxPoint &aMoveVector)=0
Function Move moves the item by aMoveVector to a new position.