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-2019 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_screen.h>
33 #include <general.h>
34 #include <sch_sheet_path.h>
35 
36 class SCH_ITEM;
37 class SCH_CONNECTION;
38 class LINE_READER;
39 class SCH_EDIT_FRAME;
40 class wxFindReplaceData;
41 class PLOTTER;
42 class NETLIST_OBJECT;
44 
45 
47  UNKNOWN = 0,
59 };
60 
61 
68 {
69 private:
72 
74  wxPoint m_pos;
75 
78 
81 
82 public:
83  DANGLING_END_ITEM( DANGLING_END_T aType, EDA_ITEM* aItem, const wxPoint& aPosition )
84  {
85  m_item = aItem;
86  m_type = aType;
87  m_pos = aPosition;
88  m_parent = aItem;
89  }
90 
92  const wxPoint& aPosition, const EDA_ITEM* aParent )
93  {
94  m_item = aItem;
95  m_type = aType;
96  m_pos = aPosition;
97  m_parent = aParent;
98  }
99 
100  wxPoint GetPosition() const { return m_pos; }
101  EDA_ITEM* GetItem() const { return m_item; }
102  const EDA_ITEM* GetParent() const { return m_parent; }
103  DANGLING_END_T GetType() const { return m_type; }
104 };
105 
106 
114 class SCH_ITEM : public EDA_ITEM
115 {
116  friend class CONNECTION_GRAPH;
117 
118 protected:
121  wxPoint m_storedPos;
122 
125  std::unordered_set<SCH_ITEM*> m_connected_items;
126 
128  std::unordered_map<SCH_SHEET_PATH, SCH_CONNECTION*> m_connection_map;
129 
132 
133 public:
134  SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType );
135 
136  SCH_ITEM( const SCH_ITEM& aItem );
137 
138  ~SCH_ITEM();
139 
140  virtual wxString GetClass() const override
141  {
142  return wxT( "SCH_ITEM" );
143  }
144 
151  virtual void SwapData( SCH_ITEM* aItem );
152 
153  SCH_ITEM* Next() const { return static_cast<SCH_ITEM*>( Pnext ); }
154  SCH_ITEM* Back() const { return static_cast<SCH_ITEM*>( Pback ); }
155 
163  SCH_ITEM* Duplicate( bool doClone = false );
164 
172  virtual bool IsMovableFromAnchorPoint() { return true; }
173 
174  wxPoint& GetStoredPos() { return m_storedPos; }
175  void SetStoredPos( wxPoint aPos ) { m_storedPos = aPos; }
176 
181  virtual bool IsLocked() const { return false; }
182 
187  virtual void SetLocked( bool aLocked ) {}
188 
193  SCH_LAYER_ID GetLayer() const { return m_Layer; }
194 
200  void SetLayer( SCH_LAYER_ID aLayer ) { m_Layer = aLayer; }
201 
206  void ViewGetLayers( int aLayers[], int& aCount ) const override;
207 
212  virtual int GetPenSize() const { return 0; }
213 
221  virtual void Print( wxDC* aDC, const wxPoint& aOffset ) = 0;
222 
228  virtual void Move( const wxPoint& aMoveVector ) = 0;
229 
235  virtual void MirrorY( int aYaxis_position ) = 0;
236 
242  virtual void MirrorX( int aXaxis_position ) = 0;
243 
250  virtual void Rotate( wxPoint aPosition ) = 0;
251 
260  virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ) { return false; }
261 
273  virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) {}
274 
288  virtual bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList ) { return false; }
289 
290  virtual bool IsDangling() const { return false; }
291 
292  virtual bool CanConnect( const SCH_ITEM* aItem ) const { return m_Layer == aItem->GetLayer(); }
293 
298  virtual bool IsConnectable() const { return false; }
299 
308  virtual void GetConnectionPoints( std::vector< wxPoint >& aPoints ) const { }
309 
317  void ClearConnections() { m_connections.clear(); }
318 
326  bool IsConnected( const wxPoint& aPoint ) const;
327 
331  SCH_CONNECTION* Connection( const SCH_SHEET_PATH& aPath ) const;
332 
336  std::unordered_set<SCH_ITEM*>& ConnectedItems();
337 
341  void AddConnectionTo( SCH_ITEM* aItem );
342 
349 
353  virtual bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const { return true; }
354 
356 
357  void SetConnectivityDirty( bool aDirty = true ) { m_connectivity_dirty = aDirty; }
358 
359  virtual bool CanIncrementLabel() const { return false; }
360 
367  virtual void Plot( PLOTTER* aPlotter );
368 
379  virtual void GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
380  SCH_SHEET_PATH* aSheetPath ) { }
381 
386  virtual wxPoint GetPosition() const = 0;
387 
394  virtual void SetPosition( const wxPoint& aPosition ) = 0;
395 
396  virtual bool operator <( const SCH_ITEM& aItem ) const;
397 
398 private:
413  virtual bool doIsConnected( const wxPoint& aPosition ) const { return false; }
414 };
415 
416 #endif /* SCH_ITEM_H */
SCH_LAYER_ID m_Layer
Definition: sch_item.h:119
EDA_ITEM * Pback
previous in linked list
Definition: base_struct.h:177
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
wxPoint GetPosition() const
Definition: sch_item.h:100
virtual bool IsConnectable() const
Function IsConnectable returns true if the schematic item can connect to another schematic item.
Definition: sch_item.h:298
void AddConnectionTo(SCH_ITEM *aItem)
Adds a connection link between this item and another.
Definition: sch_item.cpp:143
SCH_ITEM * Duplicate(bool doClone=false)
Routine to create a new copy of given item.
Definition: sch_item.cpp:75
virtual bool Load(LINE_READER &aLine, wxString &aErrorMsg)
Function Load reads a schematic item from aLine in a .sch file.
Definition: sch_item.h:260
const EDA_ITEM * GetParent() const
Definition: sch_item.h:102
virtual bool IsMovableFromAnchorPoint()
Virtual function IsMovableFromAnchorPoint.
Definition: sch_item.h:172
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:273
SCH_ITEM * Next() const
Definition: sch_item.h:153
Calculates the connectivity of a schematic and generates netlists.
virtual bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const
Returns true if this item should propagate connection info to aItem.
Definition: sch_item.h:353
virtual void Print(wxDC *aDC, const wxPoint &aOffset)=0
Function Print Print a schematic item.
EDA_ITEMS m_connections
List of items connected to this item.
Definition: sch_item.h:120
virtual void GetConnectionPoints(std::vector< wxPoint > &aPoints) const
Function GetConnectionPoints add all the connection points for this item to aPoints.
Definition: sch_item.h:308
virtual bool CanIncrementLabel() const
Definition: sch_item.h:359
bool IsConnectivityDirty()
Definition: sch_item.h:355
Schematic editor (Eeschema) main window.
virtual void SetLocked(bool aLocked)
Function SetLocked modifies 'lock' status for of the item.
Definition: sch_item.h:187
std::unordered_set< SCH_ITEM * > m_connected_items
Stores pointers to other items that are connected to this one (schematic only)
Definition: sch_item.h:125
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
Class NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected item...
SCH_ITEM * Back() const
Definition: sch_item.h:154
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:77
virtual bool UpdateDanglingState(std::vector< DANGLING_END_ITEM > &aItemList)
Function IsDanglingStateChanged tests the schematic item to aItemList to check if it's dangling state...
Definition: sch_item.h:288
wxPoint & GetStoredPos()
Definition: sch_item.h:174
virtual wxPoint GetPosition() const =0
Function GetPosition.
virtual bool CanConnect(const SCH_ITEM *aItem) const
Definition: sch_item.h:292
virtual int GetPenSize() const
Function GetPenSize virtual pure.
Definition: sch_item.h:212
virtual void SwapData(SCH_ITEM *aItem)
Function SwapData swap the internal data structures aItem with the schematic item.
Definition: sch_item.cpp:165
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:622
void SetLayer(SCH_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Definition: sch_item.h:200
EDA_ITEM * GetItem() const
Definition: sch_item.h:101
bool m_connectivity_dirty
True if connectivity info might be out of date.
Definition: sch_item.h:131
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:128
Class SCH_SHEET_PATH.
DANGLING_END_ITEM(DANGLING_END_T aType, EDA_ITEM *aItem, const wxPoint &aPosition, const EDA_ITEM *aParent)
Definition: sch_item.h:91
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.
Definition: sch_item.cpp:128
std::unordered_set< SCH_ITEM * > & ConnectedItems()
Retrieves the set of items connected to this item (schematic only)
Definition: sch_item.cpp:137
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
Definition: sch_item.h:193
virtual bool IsLocked() const
Function IsLocked.
Definition: sch_item.h:181
EDA_ITEM * m_item
A pointer to the connectable object.
Definition: sch_item.h:71
virtual void Plot(PLOTTER *aPlotter)
Function Plot plots the schematic item to aPlotter.
Definition: sch_item.cpp:178
Base plotter engine class.
Definition: plotter.h:97
DANGLING_END_ITEM(DANGLING_END_T aType, EDA_ITEM *aItem, const wxPoint &aPosition)
Definition: sch_item.h:83
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:317
~SCH_ITEM()
Definition: sch_item.cpp:62
DANGLING_END_T GetType() const
Definition: sch_item.h:103
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
wxPoint m_pos
The position of the connection point.
Definition: sch_item.h:74
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_item.h:140
virtual bool operator<(const SCH_ITEM &aItem) const
Definition: sch_item.cpp:171
wxPoint m_storedPos
a temporary variable used in some move commands to store a initial pos (of the item or mouse cursor)
Definition: sch_item.h:121
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:413
virtual bool IsDangling() const
Definition: sch_item.h:290
Class DANGLING_END_ITEM is a helper class used to store the state of schematic items that can be conn...
Definition: sch_item.h:67
SCH_CONNECTION * InitializeConnection(const SCH_SHEET_PATH &aPath)
Creates a new connection object associated with this object.
Definition: sch_item.cpp:149
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
BASE_SCREEN class implementation.
DANGLING_END_T
Definition: sch_item.h:46
void SetStoredPos(wxPoint aPos)
Definition: sch_item.h:175
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
EDA_ITEM * Pnext
next in linked list
Definition: base_struct.h:176
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:80
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:357
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:379
virtual void Move(const wxPoint &aMoveVector)=0
Function Move moves the item by aMoveVector to a new position.