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, [email protected]
5  * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.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 
31 #include <eda_item.h>
32 #include <plotters/plotter.h> // for PLOT_DASH_TYPE definition
33 
34 #include <default_values.h>
35 #include <sch_sheet_path.h>
36 #include <netclass.h>
37 
38 class CONNECTION_GRAPH;
39 class SCH_CONNECTION;
40 class SCH_SHEET_PATH;
41 class SCHEMATIC;
42 class LINE_READER;
43 class SCH_EDIT_FRAME;
44 class wxFindReplaceData;
45 class PLOTTER;
46 class NETLIST_OBJECT;
47 class NETLIST_OBJECT_LIST;
48 
50 
51 
53 {
57 };
58 
59 
61 {
62  UNKNOWN = 0,
72 };
73 
74 
80 {
81 public:
82  DANGLING_END_ITEM( DANGLING_END_T aType, EDA_ITEM* aItem, const wxPoint& aPosition )
83  {
84  m_item = aItem;
85  m_type = aType;
86  m_pos = aPosition;
87  m_parent = aItem;
88  }
89 
90  DANGLING_END_ITEM( DANGLING_END_T aType, EDA_ITEM* aItem, const wxPoint& aPosition,
91  const EDA_ITEM* aParent )
92  {
93  m_item = aItem;
94  m_type = aType;
95  m_pos = aPosition;
96  m_parent = aParent;
97  }
98 
99  bool operator==( const DANGLING_END_ITEM& aB ) const
100  {
101  return GetItem() == aB.GetItem()
102  && GetPosition() == aB.GetPosition()
103  && GetType() == aB.GetType()
104  && GetParent() == aB.GetParent();
105  }
106 
107  bool operator!=( const DANGLING_END_ITEM& aB ) const
108  {
109  return GetItem() != aB.GetItem()
110  || GetPosition() != aB.GetPosition()
111  || GetType() != aB.GetType()
112  || GetParent() != aB.GetParent();;
113  }
114 
115  bool operator<( const DANGLING_END_ITEM& rhs ) const
116  {
117  return( m_pos.x < rhs.m_pos.x || ( m_pos.x == rhs.m_pos.x && m_pos.y < rhs.m_pos.y )
118  || ( m_pos == rhs.m_pos && m_item < rhs.m_item ) );
119  }
120 
121  wxPoint GetPosition() const { return m_pos; }
122  EDA_ITEM* GetItem() const { return m_item; }
123  const EDA_ITEM* GetParent() const { return m_parent; }
124  DANGLING_END_T GetType() const { return m_type; }
125 
126 private:
128  wxPoint m_pos;
131 };
132 
133 
134 typedef std::unordered_set<SCH_ITEM*> SCH_ITEM_SET;
135 
136 
141 {
142 public:
143  STROKE_PARAMS( int aWidth = Mils2iu( DEFAULT_LINE_WIDTH_MILS ),
145  const COLOR4D& aColor = COLOR4D::UNSPECIFIED ) :
146  m_width( aWidth ),
147  m_plotstyle( aPlotStyle ),
148  m_color( aColor )
149  {
150  }
151 
152  int GetWidth() const { return m_width; }
153  void SetWidth( int aWidth ) { m_width = aWidth; }
154 
156  void SetPlotStyle( PLOT_DASH_TYPE aPlotStyle ) { m_plotstyle = aPlotStyle; }
157 
158  COLOR4D GetColor() const { return m_color; }
159  void SetColor( const COLOR4D& aColor ) { m_color = aColor; }
160 
161  bool operator!=( const STROKE_PARAMS& aOther )
162  {
163  return m_width != aOther.m_width
164  || m_plotstyle != aOther.m_plotstyle
165  || m_color != aOther.m_color;
166  }
167 
168 private:
169  int m_width;
172 };
173 
174 
182 class SCH_ITEM : public EDA_ITEM
183 {
184 public:
185  SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType );
186 
187  SCH_ITEM( const SCH_ITEM& aItem );
188 
189  SCH_ITEM& operator=( const SCH_ITEM& aPin );
190 
191  virtual ~SCH_ITEM();
192 
193  virtual wxString GetClass() const override
194  {
195  return wxT( "SCH_ITEM" );
196  }
197 
203  virtual void SwapData( SCH_ITEM* aItem );
204 
212  SCH_ITEM* Duplicate( bool doClone = false ) const;
213 
220  virtual bool IsMovableFromAnchorPoint() const { return true; }
221 
222  wxPoint& GetStoredPos() { return m_storedPos; }
223  void SetStoredPos( const wxPoint& aPos ) { m_storedPos = aPos; }
224 
237  SCHEMATIC* Schematic() const;
238 
242  virtual bool IsLocked() const { return false; }
243 
247  virtual void SetLocked( bool aLocked ) {}
248 
252  virtual bool IsHypertext() const { return false; }
253 
254  virtual void DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) { }
255 
259  SCH_LAYER_ID GetLayer() const { return m_layer; }
260 
266  void SetLayer( SCH_LAYER_ID aLayer ) { m_layer = aLayer; }
267 
271  void ViewGetLayers( int aLayers[], int& aCount ) const override;
272 
276  virtual int GetPenWidth() const { return 0; }
277 
286  virtual void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) = 0;
287 
291  virtual void Move( const wxPoint& aMoveVector ) = 0;
292 
296  virtual void MirrorHorizontally( int aCenter ) = 0;
297 
301  virtual void MirrorVertically( int aCenter ) = 0;
302 
306  virtual void Rotate( const wxPoint& aCenter ) = 0;
307 
318  virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) {}
319 
336  virtual bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
337  const SCH_SHEET_PATH* aPath = nullptr )
338  {
339  return false;
340  }
341 
342  virtual bool IsDangling() const { return false; }
343 
344  virtual bool CanConnect( const SCH_ITEM* aItem ) const { return m_layer == aItem->GetLayer(); }
345 
349  virtual bool IsConnectable() const { return false; }
350 
355  virtual bool IsPointClickableAnchor( const wxPoint& aPos ) const { return false; }
356 
364  virtual std::vector<wxPoint> GetConnectionPoints() const { return {}; }
365 
372  void ClearConnections() { m_connections.clear(); }
373 
380  bool IsConnected( const wxPoint& aPoint ) const;
381 
387  SCH_CONNECTION* Connection( const SCH_SHEET_PATH* aSheet = nullptr ) const;
388 
392  SCH_ITEM_SET& ConnectedItems( const SCH_SHEET_PATH& aPath );
393 
397  void AddConnectionTo( const SCH_SHEET_PATH& aPath, SCH_ITEM* aItem );
398 
405 
407 
411  virtual bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const { return true; }
412 
413  bool IsConnectivityDirty() const { return m_connectivity_dirty; }
414 
415  void SetConnectivityDirty( bool aDirty = true ) { m_connectivity_dirty = aDirty; }
416 
417  virtual void SetLastResolvedState( const SCH_ITEM* aItem ) { }
418 
419  NETCLASSPTR NetClass( const SCH_SHEET_PATH* aSheet = nullptr ) const;
420 
425 
428 
437  {
438  if( GetFieldsAutoplaced() )
440  }
441 
442  virtual void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) { }
443 
444  virtual void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) { }
445 
453  virtual bool HasLineStroke() const { return false; }
454 
455  virtual STROKE_PARAMS GetStroke() const { wxCHECK( false, STROKE_PARAMS() ); }
456 
457  virtual void SetStroke( const STROKE_PARAMS& aStroke ) { wxCHECK( false, /* void */ ); }
458 
464  virtual void Plot( PLOTTER* aPlotter ) const;
465 
466  virtual bool operator <( const SCH_ITEM& aItem ) const;
467 
468 private:
469  friend class CONNECTION_GRAPH;
470 
484  virtual bool doIsConnected( const wxPoint& aPosition ) const { return false; }
485 
486 protected:
488  EDA_ITEMS m_connections; // List of items connected to this item.
489  FIELDS_AUTOPLACED m_fieldsAutoplaced; // indicates status of field autoplacement
490  wxPoint m_storedPos; // a temporary variable used in some move commands
491  // to store a initial pos of the item or mouse cursor
492 
494  std::unordered_map<SCH_SHEET_PATH, SCH_ITEM_SET> m_connected_items;
495 
497  std::unordered_map<SCH_SHEET_PATH, SCH_CONNECTION*> m_connection_map;
498 
500 };
501 
502 #endif /* SCH_ITEM_H */
virtual STROKE_PARAMS GetStroke() const
Definition: sch_item.h:455
bool operator<(const DANGLING_END_ITEM &rhs) const
Definition: sch_item.h:115
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:80
virtual void SetLastResolvedState(const SCH_ITEM *aItem)
Definition: sch_item.h:417
void SetWidth(int aWidth)
Definition: sch_item.h:153
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
wxPoint GetPosition() const
Definition: sch_item.h:121
virtual bool IsConnectable() const
Definition: sch_item.h:349
SCH_CONNECTION * GetOrInitConnection(const SCH_SHEET_PATH &aPath, CONNECTION_GRAPH *aGraph)
Definition: sch_item.cpp:212
virtual std::vector< wxPoint > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
Definition: sch_item.h:364
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Holds all the data relating to one schematic.
Definition: schematic.h:59
const EDA_ITEM * GetParent() const
Definition: sch_item.h:123
#define DEFAULT_LINE_WIDTH_MILS
The default wire width in mils. (can be changed in preference menu)
virtual void DoHypertextMenu(EDA_DRAW_FRAME *aFrame)
Definition: sch_item.h:254
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:318
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:436
void AddConnectionTo(const SCH_SHEET_PATH &aPath, SCH_ITEM *aItem)
Add a connection link between this item and another.
Definition: sch_item.cpp:183
virtual bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const
Return true if this item should propagate connection info to aItem.
Definition: sch_item.h:411
EDA_ITEMS m_connections
Definition: sch_item.h:488
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:104
virtual void MirrorVertically(int aCenter)=0
Mirror item vertically about aCenter.
Schematic editor (Eeschema) main window.
void SetPlotStyle(PLOT_DASH_TYPE aPlotStyle)
Definition: sch_item.h:156
STROKE_PARAMS(int aWidth=Mils2iu(DEFAULT_LINE_WIDTH_MILS), PLOT_DASH_TYPE aPlotStyle=PLOT_DASH_TYPE::DEFAULT, const COLOR4D &aColor=COLOR4D::UNSPECIFIED)
Definition: sch_item.h:143
The base class for create windows for drawing purpose.
virtual void Rotate(const wxPoint &aCenter)=0
Rotate the item around aCenter 90 degrees in the clockwise direction.
virtual void SetLocked(bool aLocked)
Set the 'lock' status to aLocked for of this item.
Definition: sch_item.h:247
FIELDS_AUTOPLACED m_fieldsAutoplaced
Definition: sch_item.h:489
bool IsConnectivityDirty() const
Definition: sch_item.h:413
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
FIELDS_AUTOPLACED GetFieldsAutoplaced() const
Return whether the fields have been automatically placed.
Definition: sch_item.h:424
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:138
void SetFieldsAutoplaced()
Definition: sch_item.h:426
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:336
NETCLASSPTR NetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition: sch_item.cpp:158
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction)
Definition: sch_item.h:444
COLOR4D m_color
Definition: sch_item.h:171
DANGLING_END_T m_type
The position of the connection point.
Definition: sch_item.h:129
bool operator!=(const DANGLING_END_ITEM &aB) const
Definition: sch_item.h:107
wxPoint & GetStoredPos()
Definition: sch_item.h:222
virtual bool CanConnect(const SCH_ITEM *aItem) const
Definition: sch_item.h:344
SCH_LAYER_ID m_layer
Definition: sch_item.h:487
SCH_CONNECTION * InitializeConnection(const SCH_SHEET_PATH &aPath, CONNECTION_GRAPH *aGraph)
Create a new connection object associated with this object.
Definition: sch_item.cpp:189
virtual void SetStroke(const STROKE_PARAMS &aStroke)
Definition: sch_item.h:457
virtual void Plot(PLOTTER *aPlotter) const
Plot the schematic item to aPlotter.
Definition: sch_item.cpp:247
SCH_ITEM * Duplicate(bool doClone=false) const
Routine to create a new copy of given item.
Definition: sch_item.cpp:85
virtual void SwapData(SCH_ITEM *aItem)
Swap the internal data structures aItem with the schematic item.
Definition: sch_item.cpp:226
virtual bool IsMovableFromAnchorPoint() const
Definition: sch_item.h:220
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:324
virtual void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual)
Definition: sch_item.h:442
void SetLayer(SCH_LAYER_ID aLayer)
Set the layer this item is on.
Definition: sch_item.h:266
virtual bool HasLineStroke() const
Check if this schematic item has line stoke properties.
Definition: sch_item.h:453
virtual bool IsHypertext() const
Allow items to support hypertext actions when hovered/clicked.
Definition: sch_item.h:252
virtual void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset)=0
Print a schematic item.
EDA_ITEM * GetItem() const
Definition: sch_item.h:122
void ClearFieldsAutoplaced()
Definition: sch_item.h:427
PLOT_DASH_TYPE GetPlotStyle() const
Definition: sch_item.h:155
bool m_connectivity_dirty
Definition: sch_item.h:499
int GetWidth() const
Definition: sch_item.h:152
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:506
std::unordered_map< SCH_SHEET_PATH, SCH_CONNECTION * > m_connection_map
Store connectivity information, per sheet.
Definition: sch_item.h:497
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
DANGLING_END_ITEM(DANGLING_END_T aType, EDA_ITEM *aItem, const wxPoint &aPosition, const EDA_ITEM *aParent)
Definition: sch_item.h:90
virtual void MirrorHorizontally(int aCenter)=0
Mirror item horizontally about aCenter.
std::unordered_map< SCH_SHEET_PATH, SCH_ITEM_SET > m_connected_items
Store pointers to other items that are connected to this one, per sheet.
Definition: sch_item.h:494
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:120
virtual int GetPenWidth() const
Definition: sch_item.h:276
PLOT_DASH_TYPE
Dashed line types.
Definition: plotter.h:104
FIELDS_AUTOPLACED
Definition: sch_item.h:52
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:259
virtual bool IsLocked() const
Definition: sch_item.h:242
EDA_ITEM * m_item
Definition: sch_item.h:127
Base plotter engine class.
Definition: plotter.h:121
COLOR4D GetColor() const
Definition: sch_item.h:158
virtual bool IsPointClickableAnchor(const wxPoint &aPos) const
Definition: sch_item.h:355
DANGLING_END_ITEM(DANGLING_END_T aType, EDA_ITEM *aItem, const wxPoint &aPosition)
Definition: sch_item.h:82
bool operator!=(const STROKE_PARAMS &aOther)
Definition: sch_item.h:161
SCH_ITEM_SET & ConnectedItems(const SCH_SHEET_PATH &aPath)
Retrieve the set of items connected to this item on the given sheet.
Definition: sch_item.cpp:177
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:140
void ClearConnections()
Clears all of the connection items from the list.
Definition: sch_item.h:372
virtual ~SCH_ITEM()
Definition: sch_item.cpp:72
DANGLING_END_T GetType() const
Definition: sch_item.h:124
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
wxPoint m_pos
A pointer to the connectable object.
Definition: sch_item.h:128
virtual wxString GetClass() const override
Return the class name.
Definition: sch_item.h:193
virtual bool operator<(const SCH_ITEM &aItem) const
Definition: sch_item.cpp:232
wxPoint m_storedPos
Definition: sch_item.h:490
void SetColor(const COLOR4D &aColor)
Definition: sch_item.h:159
virtual bool doIsConnected(const wxPoint &aPosition) const
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_item.h:484
virtual bool IsDangling() const
Definition: sch_item.h:342
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:79
std::unordered_set< SCH_ITEM * > SCH_ITEM_SET
Definition: sch_item.h:134
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
bool operator==(const DANGLING_END_ITEM &aB) const
Definition: sch_item.h:99
DANGLING_END_T
Definition: sch_item.h:60
void SetStoredPos(const wxPoint &aPos)
Definition: sch_item.h:223
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
bool IsConnected(const wxPoint &aPoint) const
Test the item to see if it is connected to aPoint.
Definition: sch_item.cpp:129
SCH_ITEM & operator=(const SCH_ITEM &aPin)
Definition: sch_item.cpp:62
const EDA_ITEM * m_parent
The type of connection of m_item.
Definition: sch_item.h:130
PLOT_DASH_TYPE m_plotstyle
Definition: sch_item.h:170
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:415
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType)
Definition: sch_item.cpp:44
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
virtual void Move(const wxPoint &aMoveVector)=0
Move the item by aMoveVector to a new position.