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-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 #include <vector>
31 
32 #include <eda_item.h>
33 #include <plotter.h> // for PLOT_DASH_TYPE definition
34 
35 #include <gal/color4d.h>
36 
37 #include <default_values.h>
38 #include <sch_sheet_path.h>
39 #include <render_settings.h>
40 #include <netclass.h>
41 
42 class CONNECTION_GRAPH;
43 class SCH_CONNECTION;
44 class SCH_SHEET_PATH;
45 class SCHEMATIC;
46 class LINE_READER;
47 class SCH_EDIT_FRAME;
48 class wxFindReplaceData;
49 class PLOTTER;
50 class NETLIST_OBJECT;
51 class NETLIST_OBJECT_LIST;
52 
54 
55 
57 {
61 };
62 
63 
65 {
66  UNKNOWN = 0,
80 };
81 
82 
88 {
89 public:
90  DANGLING_END_ITEM( DANGLING_END_T aType, EDA_ITEM* aItem, const wxPoint& aPosition )
91  {
92  m_item = aItem;
93  m_type = aType;
94  m_pos = aPosition;
95  m_parent = aItem;
96  }
97 
99  const wxPoint& aPosition, const EDA_ITEM* aParent )
100  {
101  m_item = aItem;
102  m_type = aType;
103  m_pos = aPosition;
104  m_parent = aParent;
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& aB ) const
116  {
117  return GetItem() != aB.GetItem()
118  || GetPosition() != aB.GetPosition()
119  || GetType() != aB.GetType()
120  || GetParent() != aB.GetParent();;
121  }
122 
123  bool operator<( const DANGLING_END_ITEM& rhs ) const
124  {
125  return( m_pos.x < rhs.m_pos.x || ( m_pos.x == rhs.m_pos.x && m_pos.y < rhs.m_pos.y )
126  || ( m_pos == rhs.m_pos && m_item < rhs.m_item ) );
127  }
128 
129  wxPoint GetPosition() const { return m_pos; }
130  EDA_ITEM* GetItem() const { return m_item; }
131  const EDA_ITEM* GetParent() const { return m_parent; }
132  DANGLING_END_T GetType() const { return m_type; }
133 
134 private:
137 
139  wxPoint m_pos;
140 
143 
146 };
147 
148 
149 typedef std::unordered_set<SCH_ITEM*> SCH_ITEM_SET;
150 
151 
156 {
157 public:
158  STROKE_PARAMS( int aWidth = Mils2iu( DEFAULT_LINE_THICKNESS ),
160  const COLOR4D& aColor = COLOR4D::UNSPECIFIED ) :
161  m_width( aWidth ),
162  m_plotstyle( aPlotStyle ),
163  m_color( aColor )
164  {
165  }
166 
167  int GetWidth() const { return m_width; }
168  void SetWidth( int aWidth ) { m_width = aWidth; }
169 
171  void SetPlotStyle( PLOT_DASH_TYPE aPlotStyle ) { m_plotstyle = aPlotStyle; }
172 
173  COLOR4D GetColor() const { return m_color; }
174  void SetColor( const COLOR4D& aColor ) { m_color = aColor; }
175 
176  bool operator!=( const STROKE_PARAMS& aOther )
177  {
178  return m_width != aOther.m_width
179  || m_plotstyle != aOther.m_plotstyle
180  || m_color != aOther.m_color;
181  }
182 
183 private:
184  int m_width;
187 };
188 
189 
197 class SCH_ITEM : public EDA_ITEM
198 {
199 public:
200  SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType );
201 
202  SCH_ITEM( const SCH_ITEM& aItem );
203 
204  virtual ~SCH_ITEM();
205 
206  virtual wxString GetClass() const override
207  {
208  return wxT( "SCH_ITEM" );
209  }
210 
216  virtual void SwapData( SCH_ITEM* aItem );
217 
225  SCH_ITEM* Duplicate( bool doClone = false ) const;
226 
233  virtual bool IsMovableFromAnchorPoint() const { return true; }
234 
235  wxPoint& GetStoredPos() { return m_storedPos; }
236  void SetStoredPos( wxPoint aPos ) { m_storedPos = aPos; }
237 
250  SCHEMATIC* Schematic() const;
251 
255  virtual bool IsLocked() const { return false; }
256 
260  virtual void SetLocked( bool aLocked ) {}
261 
265  virtual bool IsHypertext() const { return false; }
266 
267  virtual void DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) { }
268 
272  SCH_LAYER_ID GetLayer() const { return m_layer; }
273 
279  void SetLayer( SCH_LAYER_ID aLayer ) { m_layer = aLayer; }
280 
284  void ViewGetLayers( int aLayers[], int& aCount ) const override;
285 
289  virtual int GetPenWidth() const { return 0; }
290 
299  virtual void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) = 0;
300 
304  virtual void Move( const wxPoint& aMoveVector ) = 0;
305 
309  virtual void MirrorHorizontally( int aCenter ) = 0;
310 
314  virtual void MirrorVertically( int aCenter ) = 0;
315 
319  virtual void Rotate( wxPoint aCenter ) = 0;
320 
331  virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) {}
332 
349  virtual bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
350  const SCH_SHEET_PATH* aPath = nullptr )
351  {
352  return false;
353  }
354 
355  virtual bool IsDangling() const { return false; }
356 
357  virtual bool CanConnect( const SCH_ITEM* aItem ) const { return m_layer == aItem->GetLayer(); }
358 
362  virtual bool IsConnectable() const { return false; }
363 
368  virtual bool IsPointClickableAnchor( const wxPoint& aPos ) const { return false; }
369 
377  virtual std::vector<wxPoint> GetConnectionPoints() const { return {}; }
378 
385  void ClearConnections() { m_connections.clear(); }
386 
393  bool IsConnected( const wxPoint& aPoint ) const;
394 
400  SCH_CONNECTION* Connection( const SCH_SHEET_PATH* aSheet = nullptr ) const;
401 
405  SCH_ITEM_SET& ConnectedItems( const SCH_SHEET_PATH& aPath );
406 
410  void AddConnectionTo( const SCH_SHEET_PATH& aPath, SCH_ITEM* aItem );
411 
418 
422  virtual bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const { return true; }
423 
425 
426  void SetConnectivityDirty( bool aDirty = true ) { m_connectivity_dirty = aDirty; }
427 
428  NETCLASSPTR NetClass( const SCH_SHEET_PATH* aSheet = nullptr ) const;
429 
434 
437 
446  {
447  if( GetFieldsAutoplaced() )
449  }
450 
451  virtual void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) { }
452 
453  virtual void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) { }
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 ) const;
474 
475  virtual bool operator <( const SCH_ITEM& aItem ) const;
476 
477 private:
478  friend class CONNECTION_GRAPH;
479 
493  virtual bool doIsConnected( const wxPoint& aPosition ) const { return false; }
494 
495 protected:
497  EDA_ITEMS m_connections; // List of items connected to this item.
498  FIELDS_AUTOPLACED m_fieldsAutoplaced; // indicates status of field autoplacement
499  wxPoint m_storedPos; // a temporary variable used in some move commands
500  // to store a initial pos of the item or mouse cursor
501 
503  std::unordered_map<SCH_SHEET_PATH, SCH_ITEM_SET> m_connected_items;
504 
506  std::unordered_map<SCH_SHEET_PATH, SCH_CONNECTION*> m_connection_map;
507 
509 };
510 
511 #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:123
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:80
void SetWidth(int aWidth)
Definition: sch_item.h:168
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
wxPoint GetPosition() const
Definition: sch_item.h:129
virtual bool IsConnectable() const
Definition: sch_item.h:362
STROKE_PARAMS(int aWidth=Mils2iu(DEFAULT_LINE_THICKNESS), PLOT_DASH_TYPE aPlotStyle=PLOT_DASH_TYPE::DEFAULT, const COLOR4D &aColor=COLOR4D::UNSPECIFIED)
Definition: sch_item.h:158
virtual std::vector< wxPoint > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
Definition: sch_item.h:377
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:131
virtual void DoHypertextMenu(EDA_DRAW_FRAME *aFrame)
Definition: sch_item.h:267
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:331
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:445
void AddConnectionTo(const SCH_SHEET_PATH &aPath, SCH_ITEM *aItem)
Add a connection link between this item and another.
Definition: sch_item.cpp:170
virtual void Rotate(wxPoint aCenter)=0
Rotate the item around aCenter 90 degrees in the clockwise direction.
virtual bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const
Return true if this item should propagate connection info to aItem.
Definition: sch_item.h:422
EDA_ITEMS m_connections
Definition: sch_item.h:497
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:97
virtual void MirrorVertically(int aCenter)=0
Mirror item vertically about aCenter.
bool IsConnectivityDirty()
Definition: sch_item.h:424
Schematic editor (Eeschema) main window.
void SetPlotStyle(PLOT_DASH_TYPE aPlotStyle)
Definition: sch_item.h:171
The base class for create windows for drawing purpose.
virtual void SetLocked(bool aLocked)
Set the 'lock' status to aLocked for of this item.
Definition: sch_item.h:260
FIELDS_AUTOPLACED m_fieldsAutoplaced
Definition: sch_item.h:498
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:433
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:131
void SetFieldsAutoplaced()
Definition: sch_item.h:435
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:349
NETCLASSPTR NetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition: sch_item.cpp:145
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction)
Definition: sch_item.h:453
COLOR4D m_color
Definition: sch_item.h:186
DANGLING_END_T m_type
The type of connection of m_item.
Definition: sch_item.h:142
bool operator!=(const DANGLING_END_ITEM &aB) const
Definition: sch_item.h:115
wxPoint & GetStoredPos()
Definition: sch_item.h:235
virtual bool CanConnect(const SCH_ITEM *aItem) const
Definition: sch_item.h:357
SCH_LAYER_ID m_layer
Definition: sch_item.h:496
SCH_CONNECTION * InitializeConnection(const SCH_SHEET_PATH &aPath, CONNECTION_GRAPH *aGraph)
Create a new connection object associated with this object.
Definition: sch_item.cpp:176
virtual void SetStroke(const STROKE_PARAMS &aStroke)
Definition: sch_item.h:466
virtual void Plot(PLOTTER *aPlotter) const
Plot the schematic item to aPlotter.
Definition: sch_item.cpp:218
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:197
virtual bool IsMovableFromAnchorPoint() const
Definition: sch_item.h:233
virtual void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual)
Definition: sch_item.h:451
void SetLayer(SCH_LAYER_ID aLayer)
Set the layer this item is on.
Definition: sch_item.h:279
virtual bool HasLineStroke() const
Check if this schematic item has line stoke properties.
Definition: sch_item.h:462
virtual bool IsHypertext() const
Allow items to support hypertext actions when hovered/clicked.
Definition: sch_item.h:265
virtual void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset)=0
Print a schematic item.
EDA_ITEM * GetItem() const
Definition: sch_item.h:130
void ClearFieldsAutoplaced()
Definition: sch_item.h:436
PLOT_DASH_TYPE GetPlotStyle() const
Definition: sch_item.h:170
bool m_connectivity_dirty
Definition: sch_item.h:508
SCH_LAYER_ID
Eeschema drawing layers.
int GetWidth() const
Definition: sch_item.h:167
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:557
std::unordered_map< SCH_SHEET_PATH, SCH_CONNECTION * > m_connection_map
Store connectivity information, per sheet.
Definition: sch_item.h:506
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:98
virtual void MirrorHorizontally(int aCenter)=0
Mirror item horizontally about aCenter.
#define DEFAULT_LINE_THICKNESS
The default wire width in mils. (can be changed in preference menu)
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:503
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:113
virtual int GetPenWidth() const
Definition: sch_item.h:289
PLOT_DASH_TYPE
Dashed line types.
Definition: plotter.h:104
FIELDS_AUTOPLACED
Definition: sch_item.h:56
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:272
virtual bool IsLocked() const
Definition: sch_item.h:255
EDA_ITEM * m_item
A pointer to the connectable object.
Definition: sch_item.h:136
Base plotter engine class.
Definition: plotter.h:121
COLOR4D GetColor() const
Definition: sch_item.h:173
virtual bool IsPointClickableAnchor(const wxPoint &aPos) const
Definition: sch_item.h:368
DANGLING_END_ITEM(DANGLING_END_T aType, EDA_ITEM *aItem, const wxPoint &aPosition)
Definition: sch_item.h:90
bool operator!=(const STROKE_PARAMS &aOther)
Definition: sch_item.h:176
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:164
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:155
void ClearConnections()
Clears all of the connection items from the list.
Definition: sch_item.h:385
virtual ~SCH_ITEM()
Definition: sch_item.cpp:65
DANGLING_END_T GetType() const
Definition: sch_item.h:132
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:150
wxPoint m_pos
The position of the connection point.
Definition: sch_item.h:139
virtual wxString GetClass() const override
Return the class name.
Definition: sch_item.h:206
virtual bool operator<(const SCH_ITEM &aItem) const
Definition: sch_item.cpp:203
wxPoint m_storedPos
Definition: sch_item.h:499
void SetColor(const COLOR4D &aColor)
Definition: sch_item.h:174
virtual bool doIsConnected(const wxPoint &aPosition) const
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_item.h:493
virtual bool IsDangling() const
Definition: sch_item.h:355
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:87
std::unordered_set< SCH_ITEM * > SCH_ITEM_SET
Definition: sch_item.h:149
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:107
DANGLING_END_T
Definition: sch_item.h:64
void SetStoredPos(wxPoint aPos)
Definition: sch_item.h:236
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:197
bool IsConnected(const wxPoint &aPoint) const
Test the item to see if it is connected to aPoint.
Definition: sch_item.cpp:122
const EDA_ITEM * m_parent
A pointer to the parent object (in the case of pins)
Definition: sch_item.h:145
PLOT_DASH_TYPE m_plotstyle
Definition: sch_item.h:185
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:426
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType)
Definition: sch_item.cpp:47
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98
virtual void Move(const wxPoint &aMoveVector)=0
Move the item by aMoveVector to a new position.