KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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
201 virtual void SetExcludeFromSim( bool aExclude ) { }
202 virtual bool GetExcludeFromSim() const { return false; }
203
210 virtual bool IsMovableFromAnchorPoint() const { return true; }
211
213 void SetStoredPos( const VECTOR2I& aPos ) { m_storedPos = aPos; }
214
227 SCHEMATIC* Schematic() const;
228
232 virtual bool IsLocked() const { return false; }
233
237 virtual void SetLocked( bool aLocked ) {}
238
242 virtual bool IsHypertext() const { return false; }
243
244 virtual void DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const { }
245
249 SCH_LAYER_ID GetLayer() const { return m_layer; }
250
256 void SetLayer( SCH_LAYER_ID aLayer ) { m_layer = aLayer; }
257
261 void ViewGetLayers( int aLayers[], int& aCount ) const override;
262
266 virtual int GetPenWidth() const { return 0; }
267
268 const wxString& GetDefaultFont() const;
269
270 bool RenderAsBitmap( double aWorldScale ) const override;
271
280 virtual void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) = 0;
281
289 virtual void PrintBackground( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) {};
290
294 virtual void Move( const VECTOR2I& aMoveVector ) = 0;
295
299 virtual void MirrorHorizontally( int aCenter ) = 0;
300
304 virtual void MirrorVertically( int aCenter ) = 0;
305
309 virtual void Rotate( const VECTOR2I& aCenter ) = 0;
310
321 virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) {}
322
339 virtual bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
340 const SCH_SHEET_PATH* aPath = nullptr )
341 {
342 return false;
343 }
344
345 virtual bool IsDangling() const { return false; }
346
347 virtual bool CanConnect( const SCH_ITEM* aItem ) const { return m_layer == aItem->GetLayer(); }
348
352 virtual bool IsConnectable() const { return false; }
353
358 virtual bool IsPointClickableAnchor( const VECTOR2I& aPos ) const { return false; }
359
367 virtual std::vector<VECTOR2I> GetConnectionPoints() const { return {}; }
368
375 void ClearConnections() { m_connections.clear(); }
376
383 bool IsConnected( const VECTOR2I& aPoint ) const;
384
390 SCH_CONNECTION* Connection( const SCH_SHEET_PATH* aSheet = nullptr ) const;
391
396
400 void AddConnectionTo( const SCH_SHEET_PATH& aPath, SCH_ITEM* aItem );
401
408
410
414 virtual bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const { return true; }
415
417
418 void SetConnectivityDirty( bool aDirty = true ) { m_connectivity_dirty = aDirty; }
419
421 void SetConnectionGraph( CONNECTION_GRAPH* aGraph );
422
423 virtual void SetLastResolvedState( const SCH_ITEM* aItem ) { }
424
425 std::shared_ptr<NETCLASS> GetEffectiveNetClass( const SCH_SHEET_PATH* aSheet = nullptr ) const;
426
431
434
443 {
444 if( GetFieldsAutoplaced() )
446 }
447
448 virtual void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) { }
449
450 virtual void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) { }
451
452 virtual void ClearCaches();
453
461 virtual bool HasLineStroke() const { return false; }
462
463 virtual STROKE_PARAMS GetStroke() const { wxCHECK( false, STROKE_PARAMS() ); }
464
465 virtual void SetStroke( const STROKE_PARAMS& aStroke ) { wxCHECK( false, /* void */ ); }
466
474 virtual void Plot( PLOTTER* aPlotter, bool aBackground ) const;
475
476 virtual bool operator <( const SCH_ITEM& aItem ) const;
477
478private:
479 friend class CONNECTION_GRAPH;
480
494 virtual bool doIsConnected( const VECTOR2I& aPosition ) const { return false; }
495
496protected:
498 EDA_ITEMS m_connections; // List of items connected to this item.
499 FIELDS_AUTOPLACED m_fieldsAutoplaced; // indicates status of field autoplacement
500 VECTOR2I m_storedPos; // a temporary variable used in some move commands
501 // to store a initial pos of the item or mouse cursor
502
504 std::map<SCH_SHEET_PATH, SCH_ITEM_SET, SHEET_PATH_CMP> m_connected_items;
505
507 std::unordered_map<SCH_SHEET_PATH, SCH_CONNECTION*> m_connection_map;
508
510};
511
512#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:165
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:93
Base plotter engine class.
Definition: plotter.h:110
Holds all the data relating to one schematic.
Definition: schematic.h:72
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:213
virtual void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset)=0
Print a schematic item.
VECTOR2I m_storedPos
Definition: sch_item.h:500
virtual bool CanConnect(const SCH_ITEM *aItem) const
Definition: sch_item.h:347
virtual bool IsConnectable() const
Definition: sch_item.h:352
virtual bool IsLocked() const
Definition: sch_item.h:232
virtual int GetPenWidth() const
Definition: sch_item.h:266
SCH_ITEM & operator=(const SCH_ITEM &aPin)
Definition: sch_item.cpp:71
virtual bool GetExcludeFromSim() const
Definition: sch_item.h:202
EDA_ITEMS m_connections
Definition: sch_item.h:498
virtual bool doIsConnected(const VECTOR2I &aPosition) const
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_item.h:494
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:321
const wxString & GetDefaultFont() const
Definition: sch_item.cpp:294
virtual ~SCH_ITEM()
Definition: sch_item.cpp:81
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:113
virtual void SetLastResolvedState(const SCH_ITEM *aItem)
Definition: sch_item.h:423
virtual bool IsDangling() const
Definition: sch_item.h:345
virtual bool IsPointClickableAnchor(const VECTOR2I &aPos) const
Definition: sch_item.h:358
SCH_CONNECTION * InitializeConnection(const SCH_SHEET_PATH &aPath, CONNECTION_GRAPH *aGraph)
Create a new connection object associated with this object.
Definition: sch_item.cpp:213
void ClearConnections()
Clears all of the connection items from the list.
Definition: sch_item.h:375
void AddConnectionTo(const SCH_SHEET_PATH &aPath, SCH_ITEM *aItem)
Add a connection link between this item and another.
Definition: sch_item.cpp:201
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:195
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:504
virtual void SetLocked(bool aLocked)
Set the 'lock' status to aLocked for of this item.
Definition: sch_item.h:237
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:174
virtual void PrintBackground(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset)
Print the (optional) backaground elements if they exist.
Definition: sch_item.h:289
bool m_connectivity_dirty
Definition: sch_item.h:509
void ClearFieldsAutoplaced()
Definition: sch_item.h:433
virtual void ClearCaches()
Definition: sch_item.cpp:259
void SetLayer(SCH_LAYER_ID aLayer)
Set the layer this item is on.
Definition: sch_item.h:256
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:249
FIELDS_AUTOPLACED GetFieldsAutoplaced() const
Return whether the fields have been automatically placed.
Definition: sch_item.h:430
virtual void SetStroke(const STROKE_PARAMS &aStroke)
Definition: sch_item.h:465
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction)
Definition: sch_item.h:450
virtual void SwapData(SCH_ITEM *aItem)
Swap the internal data structures aItem with the schematic item.
Definition: sch_item.cpp:253
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:418
virtual void Move(const VECTOR2I &aMoveVector)=0
Move the item by aMoveVector to a new position.
void SetFieldsAutoplaced()
Definition: sch_item.h:432
FIELDS_AUTOPLACED m_fieldsAutoplaced
Definition: sch_item.h:499
bool RenderAsBitmap(double aWorldScale) const override
Definition: sch_item.cpp:302
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:339
bool IsConnectivityDirty() const
Definition: sch_item.h:416
void SetConnectionGraph(CONNECTION_GRAPH *aGraph)
Updates the connection graph for all connections in this item.
Definition: sch_item.cpp:167
virtual void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual)
Definition: sch_item.h:448
bool IsConnected(const VECTOR2I &aPoint) const
Test the item to see if it is connected to aPoint.
Definition: sch_item.cpp:138
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:129
std::unordered_map< SCH_SHEET_PATH, SCH_CONNECTION * > m_connection_map
Store connectivity information, per sheet.
Definition: sch_item.h:507
virtual bool operator<(const SCH_ITEM &aItem) const
Definition: sch_item.cpp:279
virtual bool IsHypertext() const
Allow items to support hypertext actions when hovered/clicked.
Definition: sch_item.h:242
SCH_CONNECTION * GetOrInitConnection(const SCH_SHEET_PATH &aPath, CONNECTION_GRAPH *aGraph)
Definition: sch_item.cpp:236
virtual bool IsMovableFromAnchorPoint() const
Definition: sch_item.h:210
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:147
virtual void DoHypertextAction(EDA_DRAW_FRAME *aFrame) const
Definition: sch_item.h:244
VECTOR2I & GetStoredPos()
Definition: sch_item.h:212
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:463
void AutoAutoplaceFields(SCH_SCREEN *aScreen)
Autoplace fields only if correct to do so automatically.
Definition: sch_item.h:442
virtual void SetExcludeFromSim(bool aExclude)
Definition: sch_item.h:201
virtual void Plot(PLOTTER *aPlotter, bool aBackground) const
Plot the schematic item to aPlotter.
Definition: sch_item.cpp:314
SCH_LAYER_ID m_layer
Definition: sch_item.h:497
virtual bool HasLineStroke() const
Check if this schematic item has line stoke properties.
Definition: sch_item.h:461
virtual bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const
Return true if this item should propagate connection info to aItem.
Definition: sch_item.h:414
virtual std::vector< VECTOR2I > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
Definition: sch_item.h:367
SCH_ITEM * Duplicate(bool doClone=false) const
Routine to create a new copy of given item.
Definition: sch_item.cpp:94
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:506
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:345
@ LAYER_WIRE
Definition: layer_ids.h:348
@ LAYER_NOTES
Definition: layer_ids.h:362
@ LAYER_BUS
Definition: layer_ids.h:349
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:136
@ SCH_ITEM_LOCATE_WIRE_T
Definition: typeinfo.h:160
@ SCH_ITEM_LOCATE_BUS_T
Definition: typeinfo.h:161
@ SCH_ITEM_LOCATE_GRAPHIC_LINE_T
Definition: typeinfo.h:162