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 <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,
78 };
79 
80 
86 {
87 private:
90 
92  wxPoint m_pos;
93 
96 
99 
100 public:
101  DANGLING_END_ITEM( DANGLING_END_T aType, EDA_ITEM* aItem, const wxPoint& aPosition )
102  {
103  m_item = aItem;
104  m_type = aType;
105  m_pos = aPosition;
106  m_parent = aItem;
107  }
108 
110  const wxPoint& aPosition, const EDA_ITEM* aParent )
111  {
112  m_item = aItem;
113  m_type = aType;
114  m_pos = aPosition;
115  m_parent = aParent;
116  }
117 
118  bool operator==( const DANGLING_END_ITEM& aB )
119  {
120  return GetItem() == aB.GetItem()
121  && GetPosition() == aB.GetPosition()
122  && GetType() == aB.GetType()
123  && GetParent() == aB.GetParent();
124  }
125 
126  bool operator!=( const DANGLING_END_ITEM& aB )
127  {
128  return GetItem() != aB.GetItem()
129  || GetPosition() != aB.GetPosition()
130  || GetType() != aB.GetType()
131  || GetParent() != aB.GetParent();;
132  }
133 
134  bool operator<( const DANGLING_END_ITEM& rhs ) const
135  {
136  return( m_pos.x < rhs.m_pos.x || ( m_pos.x == rhs.m_pos.x && m_pos.y < rhs.m_pos.y )
137  || ( m_pos == rhs.m_pos && m_item < rhs.m_item ) );
138  }
139 
140  wxPoint GetPosition() const { return m_pos; }
141  EDA_ITEM* GetItem() const { return m_item; }
142  const EDA_ITEM* GetParent() const { return m_parent; }
143  DANGLING_END_T GetType() const { return m_type; }
144 };
145 
146 
147 typedef std::unordered_set<SCH_ITEM*> SCH_ITEM_SET;
148 
149 
154 {
155  int m_width;
158 
159 public:
160  STROKE_PARAMS( int aWidth = Mils2iu( DEFAULT_LINE_THICKNESS ),
162  const COLOR4D& aColor = COLOR4D::UNSPECIFIED ) :
163  m_width( aWidth ),
164  m_plotstyle( aPlotStyle ),
165  m_color( aColor )
166  {
167  }
168 
169  int GetWidth() const { return m_width; }
170  void SetWidth( int aWidth ) { m_width = aWidth; }
171 
173  void SetPlotStyle( PLOT_DASH_TYPE aPlotStyle ) { m_plotstyle = aPlotStyle; }
174 
175  COLOR4D GetColor() const { return m_color; }
176  void SetColor( const COLOR4D& aColor ) { m_color = aColor; }
177 
178  bool operator!=( const STROKE_PARAMS& aOther )
179  {
180  return m_width != aOther.m_width
181  || m_plotstyle != aOther.m_plotstyle
182  || m_color != aOther.m_color;
183  }
184 };
185 
186 
194 class SCH_ITEM : public EDA_ITEM
195 {
196  friend class CONNECTION_GRAPH;
197 
198 protected:
200  EDA_ITEMS m_connections; // List of items connected to this item.
201  FIELDS_AUTOPLACED m_fieldsAutoplaced; // indicates status of field autoplacement
202  wxPoint m_storedPos; // a temporary variable used in some move commands
203  // to store a initial pos of the item or mouse cursor
204 
206  std::unordered_map<SCH_SHEET_PATH, SCH_ITEM_SET> m_connected_items;
207 
209  std::unordered_map<SCH_SHEET_PATH, SCH_CONNECTION*> m_connection_map;
210 
212 
213 public:
214  SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType );
215 
216  SCH_ITEM( const SCH_ITEM& aItem );
217 
218  ~SCH_ITEM();
219 
220  virtual wxString GetClass() const override
221  {
222  return wxT( "SCH_ITEM" );
223  }
224 
230  virtual void SwapData( SCH_ITEM* aItem );
231 
239  SCH_ITEM* Duplicate( bool doClone = false ) const;
240 
247  virtual bool IsMovableFromAnchorPoint() { return true; }
248 
249  wxPoint& GetStoredPos() { return m_storedPos; }
250  void SetStoredPos( wxPoint aPos ) { m_storedPos = aPos; }
251 
263  SCHEMATIC* Schematic() const;
264 
268  virtual bool IsLocked() const { return false; }
269 
273  virtual void SetLocked( bool aLocked ) {}
274 
278  virtual bool IsHypertext() const { return false; }
279 
280  virtual void DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) { }
281 
285  SCH_LAYER_ID GetLayer() const { return m_layer; }
286 
292  void SetLayer( SCH_LAYER_ID aLayer ) { m_layer = aLayer; }
293 
297  void ViewGetLayers( int aLayers[], int& aCount ) const override;
298 
302  virtual int GetPenWidth() const { return 0; }
303 
311  virtual void Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) = 0;
312 
318  virtual void Move( const wxPoint& aMoveVector ) = 0;
319 
325  virtual void MirrorY( int aYaxis_position ) = 0;
326 
332  virtual void MirrorX( int aXaxis_position ) = 0;
333 
340  virtual void Rotate( wxPoint aPosition ) = 0;
341 
352  virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) {}
353 
370  virtual bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
371  const SCH_SHEET_PATH* aPath = nullptr )
372  {
373  return false;
374  }
375 
376  virtual bool IsDangling() const { return false; }
377 
378  virtual bool CanConnect( const SCH_ITEM* aItem ) const { return m_layer == aItem->GetLayer(); }
379 
383  virtual bool IsConnectable() const { return false; }
384 
388  virtual bool IsPointClickableAnchor( const wxPoint& aPos ) const { return false; }
389 
397  virtual std::vector<wxPoint> GetConnectionPoints() const { return {}; }
398 
405  void ClearConnections() { m_connections.clear(); }
406 
413  bool IsConnected( const wxPoint& aPoint ) const;
414 
420  SCH_CONNECTION* Connection( const SCH_SHEET_PATH* aSheet = nullptr ) const;
421 
425  SCH_ITEM_SET& ConnectedItems( const SCH_SHEET_PATH& aPath );
426 
430  void AddConnectionTo( const SCH_SHEET_PATH& aPath, SCH_ITEM* aItem );
431 
438 
442  virtual bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const { return true; }
443 
445 
446  void SetConnectivityDirty( bool aDirty = true ) { m_connectivity_dirty = aDirty; }
447 
448  NETCLASSPTR NetClass( const SCH_SHEET_PATH* aSheet = nullptr ) const;
449 
454 
459 
468  {
469  if( GetFieldsAutoplaced() )
471  }
472 
473  virtual void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) { }
474 
475  virtual void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) { }
476 
484  virtual bool HasLineStroke() const { return false; }
485 
486  virtual STROKE_PARAMS GetStroke() const { wxCHECK( false, STROKE_PARAMS() ); }
487 
488  virtual void SetStroke( const STROKE_PARAMS& aStroke ) { wxCHECK( false, /* void */ ); }
489 
495  virtual void Plot( PLOTTER* aPlotter );
496 
497  virtual bool operator <( const SCH_ITEM& aItem ) const;
498 
499 private:
513  virtual bool doIsConnected( const wxPoint& aPosition ) const { return false; }
514 };
515 
516 #endif /* SCH_ITEM_H */
virtual STROKE_PARAMS GetStroke() const
Definition: sch_item.h:486
bool operator<(const DANGLING_END_ITEM &rhs) const
Definition: sch_item.h:134
LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived to re...
Definition: richio.h:82
void SetWidth(int aWidth)
Definition: sch_item.h:170
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
wxPoint GetPosition() const
Definition: sch_item.h:140
virtual bool IsConnectable() const
Definition: sch_item.h:383
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:160
virtual std::vector< wxPoint > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
Definition: sch_item.h:397
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:44
const EDA_ITEM * GetParent() const
Definition: sch_item.h:142
virtual bool IsMovableFromAnchorPoint()
Definition: sch_item.h:247
virtual void DoHypertextMenu(EDA_DRAW_FRAME *aFrame)
Definition: sch_item.h:280
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:352
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:467
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:170
virtual bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const
Returns true if this item should propagate connection info to aItem.
Definition: sch_item.h:442
EDA_ITEMS m_connections
Definition: sch_item.h:200
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:97
bool IsConnectivityDirty()
Definition: sch_item.h:444
Schematic editor (Eeschema) main window.
void SetPlotStyle(PLOT_DASH_TYPE aPlotStyle)
Definition: sch_item.h:173
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:273
FIELDS_AUTOPLACED m_fieldsAutoplaced
Definition: sch_item.h:201
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:453
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
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:370
virtual void Rotate(wxPoint aPosition)=0
Rotate the item around aPosition 90 degrees in the clockwise direction.
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:475
COLOR4D m_color
Definition: sch_item.h:157
DANGLING_END_T m_type
The type of connection of m_item.
Definition: sch_item.h:95
wxPoint & GetStoredPos()
Definition: sch_item.h:249
virtual bool CanConnect(const SCH_ITEM *aItem) const
Definition: sch_item.h:378
SCH_LAYER_ID m_layer
Definition: sch_item.h:199
SCH_CONNECTION * InitializeConnection(const SCH_SHEET_PATH &aPath, CONNECTION_GRAPH *aGraph)
Creates a new connection object associated with this object.
Definition: sch_item.cpp:176
virtual void SetStroke(const STROKE_PARAMS &aStroke)
Definition: sch_item.h:488
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 void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual)
Definition: sch_item.h:473
void SetLayer(SCH_LAYER_ID aLayer)
Set the layer this item is on.
Definition: sch_item.h:292
virtual bool HasLineStroke() const
Check if this schematic item has line stoke properties.
Definition: sch_item.h:484
virtual bool IsHypertext() const
Allows items to support hypertext actions when hovered/clicked.
Definition: sch_item.h:278
EDA_ITEM * GetItem() const
Definition: sch_item.h:141
void ClearFieldsAutoplaced()
Set fields automatically placed flag false.
Definition: sch_item.h:458
PLOT_DASH_TYPE GetPlotStyle() const
Definition: sch_item.h:172
bool m_connectivity_dirty
Definition: sch_item.h:211
SCH_LAYER_ID
Eeschema drawing layers.
int GetWidth() const
Definition: sch_item.h:169
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:576
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:209
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:109
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)
std::unordered_map< SCH_SHEET_PATH, SCH_ITEM_SET > m_connected_items
Stores pointers to other items that are connected to this one, per sheet.
Definition: sch_item.h:206
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:302
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:285
virtual bool IsLocked() const
Definition: sch_item.h:268
EDA_ITEM * m_item
A pointer to the connectable object.
Definition: sch_item.h:89
virtual void Plot(PLOTTER *aPlotter)
Plot the schematic item to aPlotter.
Definition: sch_item.cpp:218
Base plotter engine class.
Definition: plotter.h:131
COLOR4D GetColor() const
Definition: sch_item.h:175
virtual bool IsPointClickableAnchor(const wxPoint &aPos) const
Definition: sch_item.h:388
bool operator==(const DANGLING_END_ITEM &aB)
Definition: sch_item.h:118
DANGLING_END_ITEM(DANGLING_END_T aType, EDA_ITEM *aItem, const wxPoint &aPosition)
Definition: sch_item.h:101
bool operator!=(const STROKE_PARAMS &aOther)
Definition: sch_item.h:178
SCH_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: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:153
void ClearConnections()
Clears all of the connection items from the list.
Definition: sch_item.h:405
~SCH_ITEM()
Definition: sch_item.cpp:65
DANGLING_END_T GetType() const
Definition: sch_item.h:143
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
wxPoint m_pos
The position of the connection point.
Definition: sch_item.h:92
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_item.h:220
virtual bool operator<(const SCH_ITEM &aItem) const
Definition: sch_item.cpp:203
wxPoint m_storedPos
Definition: sch_item.h:202
void SetColor(const COLOR4D &aColor)
Definition: sch_item.h:176
virtual bool doIsConnected(const wxPoint &aPosition) const
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_item.h:513
virtual bool IsDangling() const
Definition: sch_item.h:376
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:85
std::unordered_set< SCH_ITEM * > SCH_ITEM_SET
Definition: sch_item.h:147
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
DANGLING_END_T
Definition: sch_item.h:64
void SetStoredPos(wxPoint aPos)
Definition: sch_item.h:250
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194
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:98
PLOT_DASH_TYPE m_plotstyle
Definition: sch_item.h:156
bool operator!=(const DANGLING_END_ITEM &aB)
Definition: sch_item.h:126
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:446
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:100
virtual void Move(const wxPoint &aMoveVector)=0
Move the item by aMoveVector to a new position.