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 
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,
76 };
77 
78 
84 {
85 public:
86  DANGLING_END_ITEM( DANGLING_END_T aType, EDA_ITEM* aItem, const wxPoint& aPosition )
87  {
88  m_item = aItem;
89  m_type = aType;
90  m_pos = aPosition;
91  m_parent = aItem;
92  }
93 
95  const wxPoint& aPosition, const EDA_ITEM* aParent )
96  {
97  m_item = aItem;
98  m_type = aType;
99  m_pos = aPosition;
100  m_parent = aParent;
101  }
102 
103  bool operator==( const DANGLING_END_ITEM& aB ) const
104  {
105  return GetItem() == aB.GetItem()
106  && GetPosition() == aB.GetPosition()
107  && GetType() == aB.GetType()
108  && GetParent() == aB.GetParent();
109  }
110 
111  bool operator!=( const DANGLING_END_ITEM& aB ) const
112  {
113  return GetItem() != aB.GetItem()
114  || GetPosition() != aB.GetPosition()
115  || GetType() != aB.GetType()
116  || GetParent() != aB.GetParent();;
117  }
118 
119  bool operator<( const DANGLING_END_ITEM& rhs ) const
120  {
121  return( m_pos.x < rhs.m_pos.x || ( m_pos.x == rhs.m_pos.x && m_pos.y < rhs.m_pos.y )
122  || ( m_pos == rhs.m_pos && m_item < rhs.m_item ) );
123  }
124 
125  wxPoint GetPosition() const { return m_pos; }
126  EDA_ITEM* GetItem() const { return m_item; }
127  const EDA_ITEM* GetParent() const { return m_parent; }
128  DANGLING_END_T GetType() const { return m_type; }
129 
130 private:
133 
135  wxPoint m_pos;
136 
139 
142 };
143 
144 
145 typedef std::unordered_set<SCH_ITEM*> SCH_ITEM_SET;
146 
147 
152 {
153 public:
154  STROKE_PARAMS( int aWidth = Mils2iu( DEFAULT_LINE_WIDTH_MILS ),
156  const COLOR4D& aColor = COLOR4D::UNSPECIFIED ) :
157  m_width( aWidth ),
158  m_plotstyle( aPlotStyle ),
159  m_color( aColor )
160  {
161  }
162 
163  int GetWidth() const { return m_width; }
164  void SetWidth( int aWidth ) { m_width = aWidth; }
165 
167  void SetPlotStyle( PLOT_DASH_TYPE aPlotStyle ) { m_plotstyle = aPlotStyle; }
168 
169  COLOR4D GetColor() const { return m_color; }
170  void SetColor( const COLOR4D& aColor ) { m_color = aColor; }
171 
172  bool operator!=( const STROKE_PARAMS& aOther )
173  {
174  return m_width != aOther.m_width
175  || m_plotstyle != aOther.m_plotstyle
176  || m_color != aOther.m_color;
177  }
178 
179 private:
180  int m_width;
183 };
184 
185 
193 class SCH_ITEM : public EDA_ITEM
194 {
195 public:
196  SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType );
197 
198  SCH_ITEM( const SCH_ITEM& aItem );
199 
200  virtual ~SCH_ITEM();
201 
202  virtual wxString GetClass() const override
203  {
204  return wxT( "SCH_ITEM" );
205  }
206 
212  virtual void SwapData( SCH_ITEM* aItem );
213 
221  SCH_ITEM* Duplicate( bool doClone = false ) const;
222 
229  virtual bool IsMovableFromAnchorPoint() const { return true; }
230 
231  wxPoint& GetStoredPos() { return m_storedPos; }
232  void SetStoredPos( const wxPoint& aPos ) { m_storedPos = aPos; }
233 
246  SCHEMATIC* Schematic() const;
247 
251  virtual bool IsLocked() const { return false; }
252 
256  virtual void SetLocked( bool aLocked ) {}
257 
261  virtual bool IsHypertext() const { return false; }
262 
263  virtual void DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) { }
264 
268  SCH_LAYER_ID GetLayer() const { return m_layer; }
269 
275  void SetLayer( SCH_LAYER_ID aLayer ) { m_layer = aLayer; }
276 
280  void ViewGetLayers( int aLayers[], int& aCount ) const override;
281 
285  virtual int GetPenWidth() const { return 0; }
286 
295  virtual void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) = 0;
296 
300  virtual void Move( const wxPoint& aMoveVector ) = 0;
301 
305  virtual void MirrorHorizontally( int aCenter ) = 0;
306 
310  virtual void MirrorVertically( int aCenter ) = 0;
311 
315  virtual void Rotate( const wxPoint& aCenter ) = 0;
316 
327  virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) {}
328 
345  virtual bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
346  const SCH_SHEET_PATH* aPath = nullptr )
347  {
348  return false;
349  }
350 
351  virtual bool IsDangling() const { return false; }
352 
353  virtual bool CanConnect( const SCH_ITEM* aItem ) const { return m_layer == aItem->GetLayer(); }
354 
358  virtual bool IsConnectable() const { return false; }
359 
364  virtual bool IsPointClickableAnchor( const wxPoint& aPos ) const { return false; }
365 
373  virtual std::vector<wxPoint> GetConnectionPoints() const { return {}; }
374 
381  void ClearConnections() { m_connections.clear(); }
382 
389  bool IsConnected( const wxPoint& aPoint ) const;
390 
396  SCH_CONNECTION* Connection( const SCH_SHEET_PATH* aSheet = nullptr ) const;
397 
401  SCH_ITEM_SET& ConnectedItems( const SCH_SHEET_PATH& aPath );
402 
406  void AddConnectionTo( const SCH_SHEET_PATH& aPath, SCH_ITEM* aItem );
407 
414 
418  virtual bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const { return true; }
419 
421 
422  void SetConnectivityDirty( bool aDirty = true ) { m_connectivity_dirty = aDirty; }
423 
424  NETCLASSPTR NetClass( const SCH_SHEET_PATH* aSheet = nullptr ) const;
425 
430 
433 
442  {
443  if( GetFieldsAutoplaced() )
445  }
446 
447  virtual void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) { }
448 
449  virtual void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) { }
450 
458  virtual bool HasLineStroke() const { return false; }
459 
460  virtual STROKE_PARAMS GetStroke() const { wxCHECK( false, STROKE_PARAMS() ); }
461 
462  virtual void SetStroke( const STROKE_PARAMS& aStroke ) { wxCHECK( false, /* void */ ); }
463 
469  virtual void Plot( PLOTTER* aPlotter ) const;
470 
471  virtual bool operator <( const SCH_ITEM& aItem ) const;
472 
473 private:
474  friend class CONNECTION_GRAPH;
475 
489  virtual bool doIsConnected( const wxPoint& aPosition ) const { return false; }
490 
491 protected:
493  EDA_ITEMS m_connections; // List of items connected to this item.
494  FIELDS_AUTOPLACED m_fieldsAutoplaced; // indicates status of field autoplacement
495  wxPoint m_storedPos; // a temporary variable used in some move commands
496  // to store a initial pos of the item or mouse cursor
497 
499  std::unordered_map<SCH_SHEET_PATH, SCH_ITEM_SET> m_connected_items;
500 
502  std::unordered_map<SCH_SHEET_PATH, SCH_CONNECTION*> m_connection_map;
503 
505 };
506 
507 #endif /* SCH_ITEM_H */
virtual STROKE_PARAMS GetStroke() const
Definition: sch_item.h:460
bool operator<(const DANGLING_END_ITEM &rhs) const
Definition: sch_item.h:119
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:164
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
wxPoint GetPosition() const
Definition: sch_item.h:125
virtual bool IsConnectable() const
Definition: sch_item.h:358
virtual std::vector< wxPoint > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
Definition: sch_item.h:373
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:127
#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:263
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:327
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:441
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 bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const
Return true if this item should propagate connection info to aItem.
Definition: sch_item.h:418
EDA_ITEMS m_connections
Definition: sch_item.h:493
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:420
Schematic editor (Eeschema) main window.
void SetPlotStyle(PLOT_DASH_TYPE aPlotStyle)
Definition: sch_item.h:167
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:154
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:256
FIELDS_AUTOPLACED m_fieldsAutoplaced
Definition: sch_item.h:494
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:429
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:431
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:345
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:449
COLOR4D m_color
Definition: sch_item.h:182
DANGLING_END_T m_type
The type of connection of m_item.
Definition: sch_item.h:138
bool operator!=(const DANGLING_END_ITEM &aB) const
Definition: sch_item.h:111
wxPoint & GetStoredPos()
Definition: sch_item.h:231
virtual bool CanConnect(const SCH_ITEM *aItem) const
Definition: sch_item.h:353
SCH_LAYER_ID m_layer
Definition: sch_item.h:492
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:462
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:229
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:323
virtual void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual)
Definition: sch_item.h:447
void SetLayer(SCH_LAYER_ID aLayer)
Set the layer this item is on.
Definition: sch_item.h:275
virtual bool HasLineStroke() const
Check if this schematic item has line stoke properties.
Definition: sch_item.h:458
virtual bool IsHypertext() const
Allow items to support hypertext actions when hovered/clicked.
Definition: sch_item.h:261
virtual void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset)=0
Print a schematic item.
EDA_ITEM * GetItem() const
Definition: sch_item.h:126
void ClearFieldsAutoplaced()
Definition: sch_item.h:432
PLOT_DASH_TYPE GetPlotStyle() const
Definition: sch_item.h:166
bool m_connectivity_dirty
Definition: sch_item.h:504
int GetWidth() const
Definition: sch_item.h:163
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:507
std::unordered_map< SCH_SHEET_PATH, SCH_CONNECTION * > m_connection_map
Store connectivity information, per sheet.
Definition: sch_item.h:502
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:94
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:499
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:285
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:268
virtual bool IsLocked() const
Definition: sch_item.h:251
EDA_ITEM * m_item
A pointer to the connectable object.
Definition: sch_item.h:132
Base plotter engine class.
Definition: plotter.h:121
COLOR4D GetColor() const
Definition: sch_item.h:169
virtual bool IsPointClickableAnchor(const wxPoint &aPos) const
Definition: sch_item.h:364
DANGLING_END_ITEM(DANGLING_END_T aType, EDA_ITEM *aItem, const wxPoint &aPosition)
Definition: sch_item.h:86
bool operator!=(const STROKE_PARAMS &aOther)
Definition: sch_item.h:172
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:151
void ClearConnections()
Clears all of the connection items from the list.
Definition: sch_item.h:381
virtual ~SCH_ITEM()
Definition: sch_item.cpp:65
DANGLING_END_T GetType() const
Definition: sch_item.h:128
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
wxPoint m_pos
The position of the connection point.
Definition: sch_item.h:135
virtual wxString GetClass() const override
Return the class name.
Definition: sch_item.h:202
virtual bool operator<(const SCH_ITEM &aItem) const
Definition: sch_item.cpp:203
wxPoint m_storedPos
Definition: sch_item.h:495
void SetColor(const COLOR4D &aColor)
Definition: sch_item.h:170
virtual bool doIsConnected(const wxPoint &aPosition) const
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_item.h:489
virtual bool IsDangling() const
Definition: sch_item.h:351
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:83
std::unordered_set< SCH_ITEM * > SCH_ITEM_SET
Definition: sch_item.h:145
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:103
DANGLING_END_T
Definition: sch_item.h:60
void SetStoredPos(const wxPoint &aPos)
Definition: sch_item.h:232
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:193
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:141
PLOT_DASH_TYPE m_plotstyle
Definition: sch_item.h:181
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:422
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:103
virtual void Move(const wxPoint &aMoveVector)=0
Move the item by aMoveVector to a new position.