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-2023 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 PLOTTER;
47class NETLIST_OBJECT_LIST;
48class PLOTTER;
49
50namespace KIFONT
51{
52class METRICS;
53}
54
56
57
59{
63};
64
65
67{
78};
79
80
86{
87public:
88 DANGLING_END_ITEM( DANGLING_END_T aType, EDA_ITEM* aItem, const VECTOR2I& aPosition )
89 {
90 m_item = aItem;
91 m_type = aType;
92 m_pos = aPosition;
93 m_parent = aItem;
94 }
95
96 DANGLING_END_ITEM( DANGLING_END_T aType, EDA_ITEM* aItem, const VECTOR2I& aPosition,
97 const EDA_ITEM* aParent )
98 {
99 m_item = aItem;
100 m_type = aType;
101 m_pos = aPosition;
102 m_parent = aParent;
103 }
104
105 bool operator==( const DANGLING_END_ITEM& aB ) const
106 {
107 return GetItem() == aB.GetItem()
108 && GetPosition() == aB.GetPosition()
109 && GetType() == aB.GetType()
110 && GetParent() == aB.GetParent();
111 }
112
113 bool operator!=( const DANGLING_END_ITEM& aB ) const
114 {
115 return GetItem() != aB.GetItem()
116 || GetPosition() != aB.GetPosition()
117 || GetType() != aB.GetType()
118 || GetParent() != aB.GetParent();;
119 }
120
121 bool operator<( const DANGLING_END_ITEM& rhs ) const
122 {
123 return( m_pos.x < rhs.m_pos.x || ( m_pos.x == rhs.m_pos.x && m_pos.y < rhs.m_pos.y )
124 || ( m_pos == rhs.m_pos && m_item < rhs.m_item ) );
125 }
126
127 VECTOR2I GetPosition() const { return m_pos; }
128 EDA_ITEM* GetItem() const { return m_item; }
129 const EDA_ITEM* GetParent() const { return m_parent; }
130 DANGLING_END_T GetType() const { return m_type; }
131
132private:
137};
138
139
140typedef std::vector<SCH_ITEM*> SCH_ITEM_SET;
141
142
150class SCH_ITEM : public EDA_ITEM
151{
152public:
153 SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType );
154
155 SCH_ITEM( const SCH_ITEM& aItem );
156
157 SCH_ITEM& operator=( const SCH_ITEM& aPin );
158
159 virtual ~SCH_ITEM();
160
161 virtual wxString GetClass() const override
162 {
163 return wxT( "SCH_ITEM" );
164 }
165
166 bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
167 {
168 if( EDA_ITEM::IsType( aScanTypes ) )
169 return true;
170
171 for( KICAD_T scanType : aScanTypes )
172 {
173 if( scanType == SCH_ITEM_LOCATE_WIRE_T && m_layer == LAYER_WIRE )
174 return true;
175
176 if ( scanType == SCH_ITEM_LOCATE_BUS_T && m_layer == LAYER_BUS )
177 return true;
178
179 if ( scanType == SCH_ITEM_LOCATE_GRAPHIC_LINE_T
180 && Type() == SCH_LINE_T && m_layer == LAYER_NOTES )
181 {
182 return true;
183 }
184 }
185
186 return false;
187 }
188
194 virtual void SwapData( SCH_ITEM* aItem );
195
199 void SwapFlags( SCH_ITEM* aItem );
200
208 SCH_ITEM* Duplicate( bool doClone = false ) const;
209
210 virtual void SetExcludedFromSim( bool aExclude ) { }
211 virtual bool GetExcludedFromSim() const { return false; }
212
219 virtual bool IsMovableFromAnchorPoint() const { return true; }
220
222 void SetStoredPos( const VECTOR2I& aPos ) { m_storedPos = aPos; }
223
236 SCHEMATIC* Schematic() const;
237
241 virtual bool IsLocked() const { return false; }
242
246 virtual void SetLocked( bool aLocked ) {}
247
251 virtual bool IsHypertext() const { return false; }
252
253 virtual void DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const { }
254
258 SCH_LAYER_ID GetLayer() const { return m_layer; }
259
265 void SetLayer( SCH_LAYER_ID aLayer ) { m_layer = aLayer; }
266
270 void ViewGetLayers( int aLayers[], int& aCount ) const override;
271
275 virtual int GetPenWidth() const { return 0; }
276
277 const wxString& GetDefaultFont() const;
278
279 const KIFONT::METRICS& GetFontMetrics() const;
280
281 bool RenderAsBitmap( double aWorldScale ) const override;
282
289 virtual double Similarity( const SCH_ITEM& aItem ) const = 0;
290 virtual bool operator==( const SCH_ITEM& aItem ) const = 0;
291
300 virtual void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) = 0;
301
309 virtual void PrintBackground( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) {};
310
314 virtual void Move( const VECTOR2I& aMoveVector ) = 0;
315
319 virtual void MirrorHorizontally( int aCenter ) = 0;
320
324 virtual void MirrorVertically( int aCenter ) = 0;
325
329 virtual void Rotate( const VECTOR2I& aCenter ) = 0;
330
341 virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) {}
342
359 virtual bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
360 const SCH_SHEET_PATH* aPath = nullptr )
361 {
362 return false;
363 }
364
365 virtual bool IsDangling() const { return false; }
366
367 virtual bool CanConnect( const SCH_ITEM* aItem ) const { return m_layer == aItem->GetLayer(); }
368
372 virtual bool IsConnectable() const { return false; }
373
378 virtual bool IsPointClickableAnchor( const VECTOR2I& aPos ) const { return false; }
379
387 virtual std::vector<VECTOR2I> GetConnectionPoints() const { return {}; }
388
395 void ClearConnections() { m_connections.clear(); }
396
403 bool IsConnected( const VECTOR2I& aPoint ) const;
404
410 SCH_CONNECTION* Connection( const SCH_SHEET_PATH* aSheet = nullptr ) const;
411
416
420 void AddConnectionTo( const SCH_SHEET_PATH& aPath, SCH_ITEM* aItem );
421
428
430
434 virtual bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const { return true; }
435
437
438 void SetConnectivityDirty( bool aDirty = true ) { m_connectivity_dirty = aDirty; }
439
441 void SetConnectionGraph( CONNECTION_GRAPH* aGraph );
442
443 virtual bool HasCachedDriverName() const { return false; }
444 virtual const wxString& GetCachedDriverName() const;
445
446 virtual void SetLastResolvedState( const SCH_ITEM* aItem ) { }
447
448 std::shared_ptr<NETCLASS> GetEffectiveNetClass( const SCH_SHEET_PATH* aSheet = nullptr ) const;
449
454
457
466 {
467 if( GetFieldsAutoplaced() )
469 }
470
471 virtual void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) { }
472
473 virtual void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) { }
474
475 virtual void ClearCaches();
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
497 virtual void Plot( PLOTTER* aPlotter, bool aBackground,
498 const SCH_PLOT_SETTINGS& aPlotSettings ) const;
499
500 virtual bool operator <( const SCH_ITEM& aItem ) const;
501
502private:
503 friend class CONNECTION_GRAPH;
504
518 virtual bool doIsConnected( const VECTOR2I& aPosition ) const { return false; }
519
520protected:
522 EDA_ITEMS m_connections; // List of items connected to this item.
523 FIELDS_AUTOPLACED m_fieldsAutoplaced; // indicates status of field autoplacement
524 VECTOR2I m_storedPos; // a temporary variable used in some move commands
525 // to store a initial pos of the item or mouse cursor
526
528 std::map<SCH_SHEET_PATH, SCH_ITEM_SET, SHEET_PATH_CMP> m_connected_items;
529
531 std::unordered_map<SCH_SHEET_PATH, SCH_CONNECTION*> m_connection_map;
532
534};
535
536#ifndef SWIG
538#endif
539
540#endif /* SCH_ITEM_H */
Calculate 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:86
const EDA_ITEM * m_parent
The type of connection of m_item.
Definition: sch_item.h:136
bool operator==(const DANGLING_END_ITEM &aB) const
Definition: sch_item.h:105
DANGLING_END_T m_type
The position of the connection point.
Definition: sch_item.h:135
bool operator!=(const DANGLING_END_ITEM &aB) const
Definition: sch_item.h:113
DANGLING_END_ITEM(DANGLING_END_T aType, EDA_ITEM *aItem, const VECTOR2I &aPosition)
Definition: sch_item.h:88
DANGLING_END_T GetType() const
Definition: sch_item.h:130
bool operator<(const DANGLING_END_ITEM &rhs) const
Definition: sch_item.h:121
DANGLING_END_ITEM(DANGLING_END_T aType, EDA_ITEM *aItem, const VECTOR2I &aPosition, const EDA_ITEM *aParent)
Definition: sch_item.h:96
VECTOR2I m_pos
A pointer to the connectable object.
Definition: sch_item.h:134
const EDA_ITEM * GetParent() const
Definition: sch_item.h:129
EDA_ITEM * GetItem() const
Definition: sch_item.h:128
EDA_ITEM * m_item
Definition: sch_item.h:133
VECTOR2I GetPosition() const
Definition: sch_item.h:127
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:172
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:104
Holds all the data relating to one schematic.
Definition: schematic.h:75
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:151
virtual bool GetExcludedFromSim() const
Definition: sch_item.h:211
void SetStoredPos(const VECTOR2I &aPos)
Definition: sch_item.h:222
virtual void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset)=0
Print a schematic item.
VECTOR2I m_storedPos
Definition: sch_item.h:524
virtual bool CanConnect(const SCH_ITEM *aItem) const
Definition: sch_item.h:367
virtual bool IsConnectable() const
Definition: sch_item.h:372
virtual bool IsLocked() const
Definition: sch_item.h:241
virtual int GetPenWidth() const
Definition: sch_item.h:275
SCH_ITEM & operator=(const SCH_ITEM &aPin)
Definition: sch_item.cpp:71
EDA_ITEMS m_connections
Definition: sch_item.h:522
virtual bool doIsConnected(const VECTOR2I &aPosition) const
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_item.h:518
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:341
const wxString & GetDefaultFont() const
Definition: sch_item.cpp:323
virtual ~SCH_ITEM()
Definition: sch_item.cpp:81
virtual wxString GetClass() const override
Return the class name.
Definition: sch_item.h:161
virtual const wxString & GetCachedDriverName() const
Definition: sch_item.cpp:254
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:446
virtual bool IsDangling() const
Definition: sch_item.h:365
virtual bool IsPointClickableAnchor(const VECTOR2I &aPos) const
Definition: sch_item.h:378
SCH_CONNECTION * InitializeConnection(const SCH_SHEET_PATH &aPath, CONNECTION_GRAPH *aGraph)
Create a new connection object associated with this object.
Definition: sch_item.cpp:215
void ClearConnections()
Clears all of the connection items from the list.
Definition: sch_item.h:395
void AddConnectionTo(const SCH_SHEET_PATH &aPath, SCH_ITEM *aItem)
Add a connection link between this item and another.
Definition: sch_item.cpp:203
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:197
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:528
virtual void SetLocked(bool aLocked)
Set the 'lock' status to aLocked for of this item.
Definition: sch_item.h:246
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:176
virtual void PrintBackground(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset)
Print the (optional) backaground elements if they exist.
Definition: sch_item.h:309
bool m_connectivity_dirty
Definition: sch_item.h:533
void ClearFieldsAutoplaced()
Definition: sch_item.h:456
virtual void ClearCaches()
Definition: sch_item.cpp:288
void SetLayer(SCH_LAYER_ID aLayer)
Set the layer this item is on.
Definition: sch_item.h:265
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:258
virtual double Similarity(const SCH_ITEM &aItem) const =0
Return a measure of how likely the other object is to represent the same object.
FIELDS_AUTOPLACED GetFieldsAutoplaced() const
Return whether the fields have been automatically placed.
Definition: sch_item.h:453
virtual void SetStroke(const STROKE_PARAMS &aStroke)
Definition: sch_item.h:488
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction)
Definition: sch_item.h:473
virtual void SwapData(SCH_ITEM *aItem)
Swap the internal data structures aItem with the schematic item.
Definition: sch_item.cpp:261
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:438
virtual void Move(const VECTOR2I &aMoveVector)=0
Move the item by aMoveVector to a new position.
void SetFieldsAutoplaced()
Definition: sch_item.h:455
FIELDS_AUTOPLACED m_fieldsAutoplaced
Definition: sch_item.h:523
bool RenderAsBitmap(double aWorldScale) const override
Definition: sch_item.cpp:340
virtual bool operator==(const SCH_ITEM &aItem) const =0
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:359
virtual void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_SETTINGS &aPlotSettings) const
Plot the schematic item to aPlotter.
Definition: sch_item.cpp:352
bool IsConnectivityDirty() const
Definition: sch_item.h:436
virtual void SetExcludedFromSim(bool aExclude)
Definition: sch_item.h:210
void SetConnectionGraph(CONNECTION_GRAPH *aGraph)
Updates the connection graph for all connections in this item.
Definition: sch_item.cpp:164
virtual void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual)
Definition: sch_item.h:471
void SwapFlags(SCH_ITEM *aItem)
Swap the non-temp and non-edit flags.
Definition: sch_item.cpp:267
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:531
virtual bool HasCachedDriverName() const
Definition: sch_item.h:443
virtual bool operator<(const SCH_ITEM &aItem) const
Definition: sch_item.cpp:308
virtual bool IsHypertext() const
Allow items to support hypertext actions when hovered/clicked.
Definition: sch_item.h:251
SCH_CONNECTION * GetOrInitConnection(const SCH_SHEET_PATH &aPath, CONNECTION_GRAPH *aGraph)
Definition: sch_item.cpp:239
virtual bool IsMovableFromAnchorPoint() const
Definition: sch_item.h:219
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:253
VECTOR2I & GetStoredPos()
Definition: sch_item.h:221
const KIFONT::METRICS & GetFontMetrics() const
Definition: sch_item.cpp:331
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:486
void AutoAutoplaceFields(SCH_SCREEN *aScreen)
Autoplace fields only if correct to do so automatically.
Definition: sch_item.h:465
SCH_LAYER_ID m_layer
Definition: sch_item.h:521
virtual bool HasLineStroke() const
Check if this schematic item has line stoke properties.
Definition: sch_item.h:484
virtual bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const
Return true if this item should propagate connection info to aItem.
Definition: sch_item.h:434
virtual std::vector< VECTOR2I > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
Definition: sch_item.h:387
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:166
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:81
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:529
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:346
@ LAYER_WIRE
Definition: layer_ids.h:349
@ LAYER_NOTES
Definition: layer_ids.h:363
@ LAYER_BUS
Definition: layer_ids.h:350
#define DECLARE_ENUM_TO_WXANY(type)
Definition: property.h:706
DANGLING_END_T
Definition: sch_item.h:67
@ NO_CONNECT_END
Definition: sch_item.h:77
@ SHEET_LABEL_END
Definition: sch_item.h:76
@ LABEL_END
Definition: sch_item.h:73
@ UNKNOWN
Definition: sch_item.h:68
@ JUNCTION_END
Definition: sch_item.h:71
@ BUS_END
Definition: sch_item.h:70
@ PIN_END
Definition: sch_item.h:72
@ BUS_ENTRY_END
Definition: sch_item.h:74
@ WIRE_END
Definition: sch_item.h:69
@ WIRE_ENTRY_END
Definition: sch_item.h:75
std::vector< SCH_ITEM * > SCH_ITEM_SET
Definition: sch_item.h:140
FIELDS_AUTOPLACED
Definition: sch_item.h:59
@ FIELDS_AUTOPLACED_NO
Definition: sch_item.h:60
@ FIELDS_AUTOPLACED_AUTO
Definition: sch_item.h:61
@ FIELDS_AUTOPLACED_MANUAL
Definition: sch_item.h:62
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:146
@ SCH_ITEM_LOCATE_WIRE_T
Definition: typeinfo.h:170
@ SCH_ITEM_LOCATE_BUS_T
Definition: typeinfo.h:171
@ SCH_ITEM_LOCATE_GRAPHIC_LINE_T
Definition: typeinfo.h:172