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 <plotter.h>
34 
35 #include <gal/color4d.h>
36 
37 #include <default_values.h>
38 #include <sch_sheet_path.h>
39 #include <render_settings.h>
40 
41 class CONNECTION_GRAPH;
42 class SCH_CONNECTION;
43 class SCH_SHEET_PATH;
44 class SCHEMATIC;
45 class LINE_READER;
46 class SCH_EDIT_FRAME;
47 class wxFindReplaceData;
48 class PLOTTER;
49 class NETLIST_OBJECT;
51 
53 
54 
56 {
60 };
61 
62 
64 {
65  UNKNOWN = 0,
77 };
78 
79 
85 {
86 private:
89 
92 
95 
98 
99 public:
100  DANGLING_END_ITEM( DANGLING_END_T aType, EDA_ITEM* aItem, const wxPoint& aPosition )
101  {
102  m_item = aItem;
103  m_type = aType;
104  m_pos = aPosition;
105  m_parent = aItem;
106  }
107 
109  const wxPoint& aPosition, const EDA_ITEM* aParent )
110  {
111  m_item = aItem;
112  m_type = aType;
113  m_pos = aPosition;
114  m_parent = aParent;
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& aB )
126  {
127  return GetItem() != aB.GetItem()
128  || GetPosition() != aB.GetPosition()
129  || GetType() != aB.GetType()
130  || GetParent() != aB.GetParent();;
131  }
132 
133  bool operator<( const DANGLING_END_ITEM& rhs ) const
134  {
135  return( m_pos.x < rhs.m_pos.x || ( m_pos.x == rhs.m_pos.x && m_pos.y < rhs.m_pos.y )
136  || ( m_pos == rhs.m_pos && m_item < rhs.m_item ) );
137  }
138 
139  const wxPoint GetPosition() const { return m_pos; }
140  EDA_ITEM* GetItem() const { return m_item; }
141  const EDA_ITEM* GetParent() const { return m_parent; }
142  DANGLING_END_T GetType() const { return m_type; }
143 };
144 
145 
146 typedef std::unordered_set<SCH_ITEM*> ITEM_SET;
147 
148 
153 {
154  int m_width;
157 
158 public:
159  STROKE_PARAMS( int aWidth = Mils2iu( DEFAULT_LINE_THICKNESS ),
161  const COLOR4D& aColor = COLOR4D::UNSPECIFIED ) :
162  m_width( aWidth ),
163  m_type( aType ),
164  m_color( aColor )
165  {
166  }
167 
168  int GetWidth() const { return m_width; }
169  void SetWidth( int aWidth ) { m_width = aWidth; }
170 
171  PLOT_DASH_TYPE GetType() const { return m_type; }
172  void SetType( PLOT_DASH_TYPE aType ) { m_type = aType; }
173 
174  COLOR4D GetColor() const { return m_color; }
175  void SetColor( const COLOR4D& aColor ) { m_color = aColor; }
176 };
177 
178 
186 class SCH_ITEM : public EDA_ITEM
187 {
188  friend class CONNECTION_GRAPH;
189 
190 protected:
192  EDA_ITEMS m_connections; // List of items connected to this item.
193  FIELDS_AUTOPLACED m_fieldsAutoplaced; // indicates status of field autoplacement
194  wxPoint m_storedPos; // a temporary variable used in some move commands
195  // to store a initial pos of the item or mouse cursor
196 
198  std::unordered_map<SCH_SHEET_PATH, ITEM_SET> m_connected_items;
199 
201  std::unordered_map<SCH_SHEET_PATH, SCH_CONNECTION*> m_connection_map;
202 
205 
206 public:
207  SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType );
208 
209  SCH_ITEM( const SCH_ITEM& aItem );
210 
211  ~SCH_ITEM();
212 
213  virtual wxString GetClass() const override
214  {
215  return wxT( "SCH_ITEM" );
216  }
217 
223  virtual void SwapData( SCH_ITEM* aItem );
224 
232  SCH_ITEM* Duplicate( bool doClone = false ) const;
233 
240  virtual bool IsMovableFromAnchorPoint() { return true; }
241 
243  void SetStoredPos( wxPoint aPos ) { m_storedPos = aPos; }
244 
256  SCHEMATIC* Schematic() const;
257 
261  virtual bool IsLocked() const { return false; }
262 
266  virtual void SetLocked( bool aLocked ) {}
267 
271  SCH_LAYER_ID GetLayer() const { return m_Layer; }
272 
278  void SetLayer( SCH_LAYER_ID aLayer ) { m_Layer = aLayer; }
279 
283  void ViewGetLayers( int aLayers[], int& aCount ) const override;
284 
288  virtual int GetPenWidth() const { return 0; }
289 
297  virtual void Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) = 0;
298 
304  virtual void Move( const wxPoint& aMoveVector ) = 0;
305 
311  virtual void MirrorY( int aYaxis_position ) = 0;
312 
318  virtual void MirrorX( int aXaxis_position ) = 0;
319 
326  virtual void Rotate( wxPoint aPosition ) = 0;
327 
338  virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) {}
339 
356  virtual bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
357  const SCH_SHEET_PATH* aPath = nullptr )
358  {
359  return false;
360  }
361 
362  virtual bool IsDangling() const { return false; }
363 
364  virtual bool CanConnect( const SCH_ITEM* aItem ) const { return m_Layer == aItem->GetLayer(); }
365 
369  virtual bool IsConnectable() const { return false; }
370 
378  virtual void GetConnectionPoints( std::vector< wxPoint >& aPoints ) const { }
379 
386  void ClearConnections() { m_connections.clear(); }
387 
394  bool IsConnected( const wxPoint& aPoint ) const;
395 
401  SCH_CONNECTION* Connection( const SCH_SHEET_PATH& aPath ) const;
402 
406  ITEM_SET& ConnectedItems( const SCH_SHEET_PATH& aPath );
407 
411  void AddConnectionTo( const SCH_SHEET_PATH& aPath, SCH_ITEM* aItem );
412 
419 
423  virtual bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const { return true; }
424 
426 
427  void SetConnectivityDirty( bool aDirty = true ) { m_connectivity_dirty = aDirty; }
428 
433 
438 
448  {
449  if( GetFieldsAutoplaced() )
451  }
452 
453  virtual void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) { }
454 
462  virtual bool HasLineStroke() const { return false; }
463 
464  virtual STROKE_PARAMS GetStroke() const { wxCHECK( false, STROKE_PARAMS() ); }
465 
466  virtual void SetStroke( const STROKE_PARAMS& aStroke ) { wxCHECK( false, /* void */ ); }
467 
473  virtual void Plot( PLOTTER* aPlotter );
474 
484  virtual void GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
485  SCH_SHEET_PATH* aSheetPath ) { }
486 
492  virtual void SetPosition( const wxPoint& aPosition ) = 0;
493 
494  virtual bool operator <( const SCH_ITEM& aItem ) const;
495 
496 private:
510  virtual bool doIsConnected( const wxPoint& aPosition ) const { return false; }
511 };
512 
513 #endif /* SCH_ITEM_H */
virtual STROKE_PARAMS GetStroke() const
Definition: sch_item.h:464
bool operator<(const DANGLING_END_ITEM &rhs) const
Definition: sch_item.h:133
SCH_LAYER_ID m_Layer
Definition: sch_item.h:191
LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived to re...
Definition: richio.h:81
void SetWidth(int aWidth)
Definition: sch_item.h:169
virtual bool IsConnectable() const
Definition: sch_item.h:369
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:157
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:198
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
Holds all the data relating to one schematic A schematic may consist of one or more sheets (and one r...
Definition: schematic.h:42
const EDA_ITEM * GetParent() const
Definition: sch_item.h:141
virtual bool IsMovableFromAnchorPoint()
Definition: sch_item.h:240
virtual void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList)
Add the schematic item end points to aItemList if the item has end points.
Definition: sch_item.h:338
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:447
virtual void Print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset)=0
Print a schematic item.
void AddConnectionTo(const SCH_SHEET_PATH &aPath, SCH_ITEM *aItem)
Adds a connection link between this item and another.
Definition: sch_item.cpp:163
PLOT_DASH_TYPE m_type
Definition: sch_item.h:155
virtual bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const
Returns true if this item should propagate connection info to aItem.
Definition: sch_item.h:423
void SetType(PLOT_DASH_TYPE aType)
Definition: sch_item.h:172
EDA_ITEMS m_connections
Definition: sch_item.h:192
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:113
virtual void GetConnectionPoints(std::vector< wxPoint > &aPoints) const
Add all the connection points for this item to aPoints.
Definition: sch_item.h:378
bool IsConnectivityDirty()
Definition: sch_item.h:425
const wxPoint GetPosition() const
Definition: sch_item.h:139
Schematic editor (Eeschema) main window.
virtual void SetLocked(bool aLocked)
Set the 'lock' status to aLocked for of this item.
Definition: sch_item.h:266
FIELDS_AUTOPLACED m_fieldsAutoplaced
Definition: sch_item.h:193
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:432
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)
Test the schematic item to aItemList to check if it's dangling state has changed.
Definition: sch_item.h:356
virtual void Rotate(wxPoint aPosition)=0
Rotate the item around aPosition 90 degrees in the clockwise direction.
COLOR4D m_color
Definition: sch_item.h:156
DANGLING_END_T m_type
The type of connection of m_item.
Definition: sch_item.h:94
wxPoint & GetStoredPos()
Definition: sch_item.h:242
virtual bool CanConnect(const SCH_ITEM *aItem) const
Definition: sch_item.h:364
SCH_CONNECTION * InitializeConnection(const SCH_SHEET_PATH &aPath, CONNECTION_GRAPH *aGraph)
Creates a new connection object associated with this object.
Definition: sch_item.cpp:169
virtual void SetStroke(const STROKE_PARAMS &aStroke)
Definition: sch_item.h:466
SCH_ITEM * Duplicate(bool doClone=false) const
Routine to create a new copy of given item.
Definition: sch_item.cpp:78
virtual void SwapData(SCH_ITEM *aItem)
Swap the internal data structures aItem with the schematic item.
Definition: sch_item.cpp:188
virtual void SetPosition(const wxPoint &aPosition)=0
Set the schematic item position to aPosition.
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:587
virtual void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual)
Definition: sch_item.h:453
void SetLayer(SCH_LAYER_ID aLayer)
Set the layer this item is on.
Definition: sch_item.h:278
virtual bool HasLineStroke() const
Check if this schematic item has line stoke properties.
Definition: sch_item.h:462
EDA_ITEM * GetItem() const
Definition: sch_item.h:140
void ClearFieldsAutoplaced()
Set fields automatically placed flag false.
Definition: sch_item.h:437
STROKE_PARAMS(int aWidth=Mils2iu(DEFAULT_LINE_THICKNESS), PLOT_DASH_TYPE aType=PLOT_DASH_TYPE::DEFAULT, const COLOR4D &aColor=COLOR4D::UNSPECIFIED)
Definition: sch_item.h:159
bool m_connectivity_dirty
True if connectivity info might be out of date.
Definition: sch_item.h:204
SCH_LAYER_ID
Eeschema drawing layers.
int GetWidth() const
Definition: sch_item.h:168
virtual void MirrorX(int aXaxis_position)=0
Mirror 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:201
SCH_SHEET_PATH.
DANGLING_END_ITEM(DANGLING_END_T aType, EDA_ITEM *aItem, const wxPoint &aPosition, const EDA_ITEM *aParent)
Definition: sch_item.h:108
std::unordered_set< SCH_ITEM * > ITEM_SET
Definition: sch_item.h:146
virtual void MirrorY(int aYaxis_position)=0
Mirror item relative to the Y axis about aYaxis_position.
#define DEFAULT_LINE_THICKNESS
The default wire width in mils. (can be changed in preference menu)
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition: sch_item.cpp:129
SCH_CONNECTION * Connection(const SCH_SHEET_PATH &aPath) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:147
virtual int GetPenWidth() const
Definition: sch_item.h:288
PLOT_DASH_TYPE
Enum for choosing dashed line type.
Definition: plotter.h:87
FIELDS_AUTOPLACED
Definition: sch_item.h:55
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:271
virtual bool IsLocked() const
Definition: sch_item.h:261
EDA_ITEM * m_item
A pointer to the connectable object.
Definition: sch_item.h:88
virtual void Plot(PLOTTER *aPlotter)
Plot the schematic item to aPlotter.
Definition: sch_item.cpp:209
Base plotter engine class.
Definition: plotter.h:114
COLOR4D GetColor() const
Definition: sch_item.h:174
bool operator==(const DANGLING_END_ITEM &aB)
Definition: sch_item.h:117
DANGLING_END_ITEM(DANGLING_END_T aType, EDA_ITEM *aItem, const wxPoint &aPosition)
Definition: sch_item.h:100
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
Simple container to manage line stroke parameters.
Definition: sch_item.h:152
void ClearConnections()
Clears all of the connection items from the list.
Definition: sch_item.h:386
~SCH_ITEM()
Definition: sch_item.cpp:65
DANGLING_END_T GetType() const
Definition: sch_item.h:142
PLOT_DASH_TYPE GetType() const
Definition: sch_item.h:171
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
wxPoint m_pos
The position of the connection point.
Definition: sch_item.h:91
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_item.h:213
virtual bool operator<(const SCH_ITEM &aItem) const
Definition: sch_item.cpp:194
wxPoint m_storedPos
Definition: sch_item.h:194
void SetColor(const COLOR4D &aColor)
Definition: sch_item.h:175
virtual bool doIsConnected(const wxPoint &aPosition) const
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_item.h:510
virtual bool IsDangling() const
Definition: sch_item.h:362
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:84
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
DANGLING_END_T
Definition: sch_item.h:63
void SetStoredPos(wxPoint aPos)
Definition: sch_item.h:243
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:186
bool IsConnected(const wxPoint &aPoint) const
Test the item to see if it is connected to aPoint.
Definition: sch_item.cpp:138
const EDA_ITEM * m_parent
A pointer to the parent object (in the case of pins)
Definition: sch_item.h:97
bool operator!=(const DANGLING_END_ITEM &aB)
Definition: sch_item.h:125
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:427
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType)
Definition: sch_item.cpp:47
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99
virtual void GetNetListItem(NETLIST_OBJECT_LIST &aNetListItems, SCH_SHEET_PATH *aSheetPath)
Create a new NETLIST_OBJECT for the schematic object and adds it to aNetListItems.
Definition: sch_item.h:484
virtual void Move(const wxPoint &aMoveVector)=0
Move the item by aMoveVector to a new position.