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 <map>
30#include <set>
31
32#include <eda_item.h>
33#include <default_values.h>
34#include <sch_sheet_path.h>
35#include <netclass.h>
36#include <stroke_params.h>
37#include <layer_ids.h>
38
40class SCH_CONNECTION;
41class SCH_SHEET_PATH;
42class SCHEMATIC;
43class LINE_READER;
44class SCH_EDIT_FRAME;
45class wxFindReplaceData;
46class PLOTTER;
47class NETLIST_OBJECT;
48class NETLIST_OBJECT_LIST;
49class PLOTTER;
50
52
53
55{
59};
60
61
63{
74};
75
76
82{
83public:
84 DANGLING_END_ITEM( DANGLING_END_T aType, EDA_ITEM* aItem, const VECTOR2I& aPosition )
85 {
86 m_item = aItem;
87 m_type = aType;
88 m_pos = aPosition;
89 m_parent = aItem;
90 }
91
92 DANGLING_END_ITEM( DANGLING_END_T aType, EDA_ITEM* aItem, const VECTOR2I& aPosition,
93 const EDA_ITEM* aParent )
94 {
95 m_item = aItem;
96 m_type = aType;
97 m_pos = aPosition;
98 m_parent = aParent;
99 }
100
101 bool operator==( const DANGLING_END_ITEM& aB ) const
102 {
103 return GetItem() == aB.GetItem()
104 && GetPosition() == aB.GetPosition()
105 && GetType() == aB.GetType()
106 && GetParent() == aB.GetParent();
107 }
108
109 bool operator!=( const DANGLING_END_ITEM& aB ) const
110 {
111 return GetItem() != aB.GetItem()
112 || GetPosition() != aB.GetPosition()
113 || GetType() != aB.GetType()
114 || GetParent() != aB.GetParent();;
115 }
116
117 bool operator<( const DANGLING_END_ITEM& rhs ) const
118 {
119 return( m_pos.x < rhs.m_pos.x || ( m_pos.x == rhs.m_pos.x && m_pos.y < rhs.m_pos.y )
120 || ( m_pos == rhs.m_pos && m_item < rhs.m_item ) );
121 }
122
123 VECTOR2I GetPosition() const { return m_pos; }
124 EDA_ITEM* GetItem() const { return m_item; }
125 const EDA_ITEM* GetParent() const { return m_parent; }
126 DANGLING_END_T GetType() const { return m_type; }
127
128private:
133};
134
135
136typedef std::vector<SCH_ITEM*> SCH_ITEM_SET;
137
138
146class SCH_ITEM : public EDA_ITEM
147{
148public:
149 SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType );
150
151 SCH_ITEM( const SCH_ITEM& aItem );
152
153 SCH_ITEM& operator=( const SCH_ITEM& aPin );
154
155 virtual ~SCH_ITEM();
156
157 virtual wxString GetClass() const override
158 {
159 return wxT( "SCH_ITEM" );
160 }
161
162 bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
163 {
164 if( EDA_ITEM::IsType( aScanTypes ) )
165 return true;
166
167 for( KICAD_T scanType : aScanTypes )
168 {
169 if( scanType == SCH_ITEM_LOCATE_WIRE_T && m_layer == LAYER_WIRE )
170 return true;
171
172 if ( scanType == SCH_ITEM_LOCATE_BUS_T && m_layer == LAYER_BUS )
173 return true;
174
175 if ( scanType == SCH_ITEM_LOCATE_GRAPHIC_LINE_T
176 && Type() == SCH_LINE_T && m_layer == LAYER_NOTES )
177 {
178 return true;
179 }
180 }
181
182 return false;
183 }
184
190 virtual void SwapData( SCH_ITEM* aItem );
191
199 SCH_ITEM* Duplicate( bool doClone = false ) const;
200
207 virtual bool IsMovableFromAnchorPoint() const { return true; }
208
210 void SetStoredPos( const VECTOR2I& aPos ) { m_storedPos = aPos; }
211
224 SCHEMATIC* Schematic() const;
225
229 virtual bool IsLocked() const { return false; }
230
234 virtual void SetLocked( bool aLocked ) {}
235
239 virtual bool IsHypertext() const { return false; }
240
241 virtual void DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const { }
242
246 SCH_LAYER_ID GetLayer() const { return m_layer; }
247
253 void SetLayer( SCH_LAYER_ID aLayer ) { m_layer = aLayer; }
254
258 void ViewGetLayers( int aLayers[], int& aCount ) const override;
259
263 virtual int GetPenWidth() const { return 0; }
264
265 const wxString& GetDefaultFont() const;
266
267 bool RenderAsBitmap( double aWorldScale ) const override;
268
277 virtual void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) = 0;
278
282 virtual void Move( const VECTOR2I& aMoveVector ) = 0;
283
287 virtual void MirrorHorizontally( int aCenter ) = 0;
288
292 virtual void MirrorVertically( int aCenter ) = 0;
293
297 virtual void Rotate( const VECTOR2I& aCenter ) = 0;
298
309 virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) {}
310
327 virtual bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
328 const SCH_SHEET_PATH* aPath = nullptr )
329 {
330 return false;
331 }
332
333 virtual bool IsDangling() const { return false; }
334
335 virtual bool CanConnect( const SCH_ITEM* aItem ) const { return m_layer == aItem->GetLayer(); }
336
340 virtual bool IsConnectable() const { return false; }
341
346 virtual bool IsPointClickableAnchor( const VECTOR2I& aPos ) const { return false; }
347
355 virtual std::vector<VECTOR2I> GetConnectionPoints() const { return {}; }
356
363 void ClearConnections() { m_connections.clear(); }
364
371 bool IsConnected( const VECTOR2I& aPoint ) const;
372
378 SCH_CONNECTION* Connection( const SCH_SHEET_PATH* aSheet = nullptr ) const;
379
384
388 void AddConnectionTo( const SCH_SHEET_PATH& aPath, SCH_ITEM* aItem );
389
396
398
402 virtual bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const { return true; }
403
405
406 void SetConnectivityDirty( bool aDirty = true ) { m_connectivity_dirty = aDirty; }
407
408 virtual void SetLastResolvedState( const SCH_ITEM* aItem ) { }
409
410 std::shared_ptr<NETCLASS> GetEffectiveNetClass( const SCH_SHEET_PATH* aSheet = nullptr ) const;
411
416
419
428 {
429 if( GetFieldsAutoplaced() )
431 }
432
433 virtual void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) { }
434
435 virtual void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) { }
436
437 virtual void ClearCaches();
438
446 virtual bool HasLineStroke() const { return false; }
447
448 virtual STROKE_PARAMS GetStroke() const { wxCHECK( false, STROKE_PARAMS() ); }
449
450 virtual void SetStroke( const STROKE_PARAMS& aStroke ) { wxCHECK( false, /* void */ ); }
451
459 virtual void Plot( PLOTTER* aPlotter, bool aBackground ) const;
460
461 virtual bool operator <( const SCH_ITEM& aItem ) const;
462
463private:
464 friend class CONNECTION_GRAPH;
465
479 virtual bool doIsConnected( const VECTOR2I& aPosition ) const { return false; }
480
481protected:
483 EDA_ITEMS m_connections; // List of items connected to this item.
484 FIELDS_AUTOPLACED m_fieldsAutoplaced; // indicates status of field autoplacement
485 VECTOR2I m_storedPos; // a temporary variable used in some move commands
486 // to store a initial pos of the item or mouse cursor
487
489 std::map<SCH_SHEET_PATH, SCH_ITEM_SET, SHEET_PATH_CMP> m_connected_items;
490
492 std::unordered_map<SCH_SHEET_PATH, SCH_CONNECTION*> m_connection_map;
493
495};
496
497#endif /* SCH_ITEM_H */
Calculates the connectivity of a schematic and generates netlists.
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:82
const EDA_ITEM * m_parent
The type of connection of m_item.
Definition: sch_item.h:132
bool operator==(const DANGLING_END_ITEM &aB) const
Definition: sch_item.h:101
DANGLING_END_T m_type
The position of the connection point.
Definition: sch_item.h:131
bool operator!=(const DANGLING_END_ITEM &aB) const
Definition: sch_item.h:109
DANGLING_END_ITEM(DANGLING_END_T aType, EDA_ITEM *aItem, const VECTOR2I &aPosition)
Definition: sch_item.h:84
DANGLING_END_T GetType() const
Definition: sch_item.h:126
bool operator<(const DANGLING_END_ITEM &rhs) const
Definition: sch_item.h:117
DANGLING_END_ITEM(DANGLING_END_T aType, EDA_ITEM *aItem, const VECTOR2I &aPosition, const EDA_ITEM *aParent)
Definition: sch_item.h:92
VECTOR2I m_pos
A pointer to the connectable object.
Definition: sch_item.h:130
const EDA_ITEM * GetParent() const
Definition: sch_item.h:125
EDA_ITEM * GetItem() const
Definition: sch_item.h:124
EDA_ITEM * m_item
Definition: sch_item.h:129
VECTOR2I GetPosition() const
Definition: sch_item.h:123
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition: eda_item.h:183
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:81
Base plotter engine class.
Definition: plotter.h:110
Holds all the data relating to one schematic.
Definition: schematic.h:60
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
void SetStoredPos(const VECTOR2I &aPos)
Definition: sch_item.h:210
virtual void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset)=0
Print a schematic item.
VECTOR2I m_storedPos
Definition: sch_item.h:485
virtual bool CanConnect(const SCH_ITEM *aItem) const
Definition: sch_item.h:335
virtual bool IsConnectable() const
Definition: sch_item.h:340
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType)
Definition: sch_item.cpp:52
virtual bool IsLocked() const
Definition: sch_item.h:229
virtual int GetPenWidth() const
Definition: sch_item.h:263
SCH_ITEM & operator=(const SCH_ITEM &aPin)
Definition: sch_item.cpp:70
EDA_ITEMS m_connections
Definition: sch_item.h:483
virtual bool doIsConnected(const VECTOR2I &aPosition) const
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_item.h:479
virtual void MirrorVertically(int aCenter)=0
Mirror item vertically about aCenter.
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:309
const wxString & GetDefaultFont() const
Definition: sch_item.cpp:286
virtual ~SCH_ITEM()
Definition: sch_item.cpp:80
virtual wxString GetClass() const override
Return the class name.
Definition: sch_item.h:157
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:112
virtual void SetLastResolvedState(const SCH_ITEM *aItem)
Definition: sch_item.h:408
virtual bool IsDangling() const
Definition: sch_item.h:333
virtual bool IsPointClickableAnchor(const VECTOR2I &aPos) const
Definition: sch_item.h:346
SCH_CONNECTION * InitializeConnection(const SCH_SHEET_PATH &aPath, CONNECTION_GRAPH *aGraph)
Create a new connection object associated with this object.
Definition: sch_item.cpp:205
void ClearConnections()
Clears all of the connection items from the list.
Definition: sch_item.h:363
void AddConnectionTo(const SCH_SHEET_PATH &aPath, SCH_ITEM *aItem)
Add a connection link between this item and another.
Definition: sch_item.cpp:193
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:187
std::map< SCH_SHEET_PATH, SCH_ITEM_SET, SHEET_PATH_CMP > m_connected_items
Store pointers to other items that are connected to this one, per sheet.
Definition: sch_item.h:489
virtual void SetLocked(bool aLocked)
Set the 'lock' status to aLocked for of this item.
Definition: sch_item.h:234
virtual void MirrorHorizontally(int aCenter)=0
Mirror item horizontally about aCenter.
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const SCH_SHEET_PATH *aSheet=nullptr) const
Definition: sch_item.cpp:166
bool m_connectivity_dirty
Definition: sch_item.h:494
void ClearFieldsAutoplaced()
Definition: sch_item.h:418
virtual void ClearCaches()
Definition: sch_item.cpp:251
void SetLayer(SCH_LAYER_ID aLayer)
Set the layer this item is on.
Definition: sch_item.h:253
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:246
FIELDS_AUTOPLACED GetFieldsAutoplaced() const
Return whether the fields have been automatically placed.
Definition: sch_item.h:415
virtual void SetStroke(const STROKE_PARAMS &aStroke)
Definition: sch_item.h:450
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction)
Definition: sch_item.h:435
virtual void SwapData(SCH_ITEM *aItem)
Swap the internal data structures aItem with the schematic item.
Definition: sch_item.cpp:245
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:406
virtual void Move(const VECTOR2I &aMoveVector)=0
Move the item by aMoveVector to a new position.
void SetFieldsAutoplaced()
Definition: sch_item.h:417
FIELDS_AUTOPLACED m_fieldsAutoplaced
Definition: sch_item.h:484
bool RenderAsBitmap(double aWorldScale) const override
Definition: sch_item.cpp:294
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:327
bool IsConnectivityDirty() const
Definition: sch_item.h:404
virtual void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual)
Definition: sch_item.h:433
bool IsConnected(const VECTOR2I &aPoint) const
Test the item to see if it is connected to aPoint.
Definition: sch_item.cpp:137
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:128
std::unordered_map< SCH_SHEET_PATH, SCH_CONNECTION * > m_connection_map
Store connectivity information, per sheet.
Definition: sch_item.h:492
virtual bool operator<(const SCH_ITEM &aItem) const
Definition: sch_item.cpp:271
virtual bool IsHypertext() const
Allow items to support hypertext actions when hovered/clicked.
Definition: sch_item.h:239
SCH_CONNECTION * GetOrInitConnection(const SCH_SHEET_PATH &aPath, CONNECTION_GRAPH *aGraph)
Definition: sch_item.cpp:228
virtual bool IsMovableFromAnchorPoint() const
Definition: sch_item.h:207
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:146
virtual void DoHypertextAction(EDA_DRAW_FRAME *aFrame) const
Definition: sch_item.h:241
VECTOR2I & GetStoredPos()
Definition: sch_item.h:209
virtual void Rotate(const VECTOR2I &aCenter)=0
Rotate the item around aCenter 90 degrees in the clockwise direction.
virtual STROKE_PARAMS GetStroke() const
Definition: sch_item.h:448
void AutoAutoplaceFields(SCH_SCREEN *aScreen)
Autoplace fields only if correct to do so automatically.
Definition: sch_item.h:427
virtual void Plot(PLOTTER *aPlotter, bool aBackground) const
Plot the schematic item to aPlotter.
Definition: sch_item.cpp:306
SCH_LAYER_ID m_layer
Definition: sch_item.h:482
virtual bool HasLineStroke() const
Check if this schematic item has line stoke properties.
Definition: sch_item.h:446
virtual bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const
Return true if this item should propagate connection info to aItem.
Definition: sch_item.h:402
virtual std::vector< VECTOR2I > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
Definition: sch_item.h:355
SCH_ITEM * Duplicate(bool doClone=false) const
Routine to create a new copy of given item.
Definition: sch_item.cpp:93
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition: sch_item.h:162
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Simple container to manage line stroke parameters.
Definition: stroke_params.h:88
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:524
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:341
@ LAYER_WIRE
Definition: layer_ids.h:344
@ LAYER_NOTES
Definition: layer_ids.h:358
@ LAYER_BUS
Definition: layer_ids.h:345
DANGLING_END_T
Definition: sch_item.h:63
@ NO_CONNECT_END
Definition: sch_item.h:73
@ SHEET_LABEL_END
Definition: sch_item.h:72
@ LABEL_END
Definition: sch_item.h:69
@ UNKNOWN
Definition: sch_item.h:64
@ JUNCTION_END
Definition: sch_item.h:67
@ BUS_END
Definition: sch_item.h:66
@ PIN_END
Definition: sch_item.h:68
@ BUS_ENTRY_END
Definition: sch_item.h:70
@ WIRE_END
Definition: sch_item.h:65
@ WIRE_ENTRY_END
Definition: sch_item.h:71
std::vector< SCH_ITEM * > SCH_ITEM_SET
Definition: sch_item.h:136
FIELDS_AUTOPLACED
Definition: sch_item.h:55
@ FIELDS_AUTOPLACED_NO
Definition: sch_item.h:56
@ FIELDS_AUTOPLACED_AUTO
Definition: sch_item.h:57
@ FIELDS_AUTOPLACED_MANUAL
Definition: sch_item.h:58
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ SCH_LINE_T
Definition: typeinfo.h:145
@ SCH_ITEM_LOCATE_WIRE_T
Definition: typeinfo.h:169
@ SCH_ITEM_LOCATE_BUS_T
Definition: typeinfo.h:170
@ SCH_ITEM_LOCATE_GRAPHIC_LINE_T
Definition: typeinfo.h:171