KiCad PCB EDA Suite
sch_line.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) 2009 Jean-Pierre Charras, [email protected]
5 * Copyright (C) 1992-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_LINE_H_
26#define _SCH_LINE_H_
27
28#include <sch_item.h>
29#include <wx/pen.h> // for wxPenStyle
30#include <list> // for std::list
31
32class NETLIST_OBJECT_LIST;
33
34
39class SCH_LINE : public SCH_ITEM
40{
41public:
42 static const enum wxPenStyle PenStyle[];
43
44 SCH_LINE( const VECTOR2I& pos = VECTOR2I( 0, 0 ), int layer = LAYER_NOTES );
45
46 SCH_LINE( const VECTOR2D& pos, int layer = LAYER_NOTES ) :
47 SCH_LINE( VECTOR2I( pos.x, pos.y ), layer )
48 {}
49
50 SCH_LINE( const SCH_LINE& aLine );
51
53
54 static inline bool ClassOf( const EDA_ITEM* aItem )
55 {
56 return aItem && SCH_LINE_T == aItem->Type();
57 }
58
59 wxString GetClass() const override
60 {
61 return wxT( "SCH_LINE" );
62 }
63
70 wxString GetNetname(const SCH_SHEET_PATH &aSheet);
71
72 bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
73 {
74 if( SCH_ITEM::IsType( aScanTypes ) )
75 return true;
76
77 for( KICAD_T scanType : aScanTypes )
78 {
79 if( scanType == SCH_ITEM_LOCATE_WIRE_T && m_layer == LAYER_WIRE )
80 return true;
81
82 if ( scanType == SCH_ITEM_LOCATE_BUS_T && m_layer == LAYER_BUS )
83 return true;
84
86 return true;
87 }
88
89 return false;
90 }
91
92 bool IsEndPoint( const VECTOR2I& aPoint ) const
93 {
94 return aPoint == m_start || aPoint == m_end;
95 }
96
97 int GetAngleFrom( const VECTOR2I& aPoint ) const;
98 int GetReverseAngleFrom( const VECTOR2I& aPoint ) const;
99
105 inline EDA_ANGLE Angle() const
106 {
107 return ( EDA_ANGLE( (VECTOR2I) m_end - (VECTOR2I) m_start ) );
108 }
109
114 inline void StoreAngle()
115 {
116 if( !IsNull() )
118 }
119
120 inline void StoreAngle( const EDA_ANGLE& aAngle ) { m_storedAngle = aAngle; }
121
127 inline EDA_ANGLE GetStoredAngle() const { return m_storedAngle; }
128
134 inline bool IsOrthogonal() const { return Angle().IsCardinal(); }
135
136 bool IsNull() const { return m_start == m_end; }
137
138 VECTOR2I GetStartPoint() const { return m_start; }
139 void SetStartPoint( const VECTOR2I& aPosition ) { m_start = aPosition; }
140
141 VECTOR2I GetMidPoint() const { return ( m_start + m_end ) / 2; }
142
143 VECTOR2I GetEndPoint() const { return m_end; }
144 void SetEndPoint( const VECTOR2I& aPosition ) { m_end = aPosition; }
145
146 void SetLastResolvedState( const SCH_ITEM* aItem ) override
147 {
148 const SCH_LINE* aLine = dynamic_cast<const SCH_LINE*>( aItem );
149
150 if( aLine )
151 {
152 m_stroke = aLine->GetStroke();
156 }
157 }
158
159 void SetLineStyle( const PLOT_DASH_TYPE aStyle );
160 void SetLineStyle( const int aStyleId );
162
166
167 void SetLineColor( const COLOR4D& aColor );
168
169 void SetLineColor( const double r, const double g, const double b, const double a );
170
172 COLOR4D GetLineColor() const;
173
174 void SetLineWidth( const int aSize );
175
176 virtual bool HasLineStroke() const override { return true; }
177 virtual STROKE_PARAMS GetStroke() const override { return m_stroke; }
178 virtual void SetStroke( const STROKE_PARAMS& aStroke ) override { m_stroke = aStroke; }
179
180 bool IsStrokeEquivalent( const SCH_LINE* aLine )
181 {
182 if( m_stroke.GetWidth() != aLine->GetStroke().GetWidth() )
183 return false;
184
185 if( m_stroke.GetColor() != aLine->GetStroke().GetColor() )
186 return false;
187
189 PLOT_DASH_TYPE style_b = aLine->GetStroke().GetPlotStyle();
190
191 return style_a == style_b
192 || ( style_a == PLOT_DASH_TYPE::DEFAULT && style_b == PLOT_DASH_TYPE::SOLID )
193 || ( style_a == PLOT_DASH_TYPE::SOLID && style_b == PLOT_DASH_TYPE::DEFAULT );
194 }
195
196 int GetLineSize() const { return m_stroke.GetWidth(); }
197
198 void ViewGetLayers( int aLayers[], int& aCount ) const override;
199
200 const BOX2I GetBoundingBox() const override;
201
205 double GetLength() const;
206
207 void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) override;
208
209 int GetPenWidth() const override;
210
211 void Move( const VECTOR2I& aMoveVector ) override;
212 void MoveStart( const VECTOR2I& aMoveVector );
213 void MoveEnd( const VECTOR2I& aMoveVector );
214
215 void MirrorVertically( int aCenter ) override;
216 void MirrorHorizontally( int aCenter ) override;
217 void Rotate( const VECTOR2I& aCenter ) override;
218 void RotateStart( const VECTOR2I& aCenter );
219 void RotateEnd( const VECTOR2I& aCenter );
220
234 SCH_LINE* MergeOverlap( SCH_SCREEN* aScreen, SCH_LINE* aLine, bool aCheckJunctions );
235
248 SCH_LINE* BreakAt( const VECTOR2I& aPoint );
249
250 bool IsParallel( const SCH_LINE* aLine ) const;
251
252 void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override;
253
254 bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
255 const SCH_SHEET_PATH* aPath = nullptr ) override;
256
257 bool IsStartDangling() const { return m_startIsDangling; }
258 bool IsEndDangling() const { return m_endIsDangling; }
259 bool IsDangling() const override { return m_startIsDangling || m_endIsDangling; }
260
261 bool IsConnectable() const override;
262
263 std::vector<VECTOR2I> GetConnectionPoints() const override;
264
265 bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const override;
266
267 void GetSelectedPoints( std::vector<VECTOR2I>& aPoints ) const;
268
269 bool CanConnect( const SCH_ITEM* aItem ) const override;
270
271 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
272
273 BITMAPS GetMenuImage() const override;
274
275 bool operator <( const SCH_ITEM& aItem ) const override;
276
277 VECTOR2I GetPosition() const override { return m_start; }
278 void SetPosition( const VECTOR2I& aPosition ) override;
279 VECTOR2I GetSortPosition() const override { return GetMidPoint(); }
280
281 bool IsPointClickableAnchor( const VECTOR2I& aPos ) const override
282 {
283 return ( GetStartPoint() == aPos && IsStartDangling() )
284 || ( GetEndPoint() == aPos && IsEndDangling() );
285 }
286
287 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
288 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
289
290 void Plot( PLOTTER* aPlotter, bool aBackground ) const override;
291
292 EDA_ITEM* Clone() const override;
293
294 void SwapData( SCH_ITEM* aItem ) override;
295
296 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
297
298#if defined(DEBUG)
299 void Show( int nestLevel, std::ostream& os ) const override;
300#endif
301
307 bool IsGraphicLine() const;
308
314 bool IsWire() const;
315
321 bool IsBus() const;
322
323private:
333 wxString FindWireSegmentNetNameRecursive( SCH_LINE *line, std::list<const SCH_LINE*>& checkedLines,
334 const SCH_SHEET_PATH &aSheet ) const;
335 bool doIsConnected( const VECTOR2I& aPosition ) const override;
336
343
344 // If real-time connectivity gets disabled (due to being too slow on a particular
345 // design), we can no longer rely on getting the NetClass to find netclass-specific
346 // linestyles, linewidths and colors.
350};
351
352
353#endif // _SCH_LINE_H_
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
bool IsCardinal() const
Definition: eda_angle.cpp:49
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
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Base plotter engine class.
Definition: plotter.h:110
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
SCH_LAYER_ID m_layer
Definition: sch_item.h:491
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
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
int GetPenWidth() const override
Definition: sch_line.cpp:292
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_line.cpp:376
bool doIsConnected(const VECTOR2I &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_line.cpp:822
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Add the schematic item end points to aItemList if the item has end points.
Definition: sch_line.cpp:573
void SetStartPoint(const VECTOR2I &aPosition)
Definition: sch_line.h:139
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_line.cpp:128
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_line.cpp:742
bool m_startIsDangling
True if start point is not connected.
Definition: sch_line.h:337
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: sch_line.cpp:776
bool IsPointClickableAnchor(const VECTOR2I &aPos) const override
Definition: sch_line.h:281
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_line.cpp:886
void StoreAngle()
Saves the current line angle.
Definition: sch_line.h:114
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_line.cpp:676
int GetReverseAngleFrom(const VECTOR2I &aPoint) const
Definition: sch_line.cpp:414
SCH_LINE(const VECTOR2I &pos=VECTOR2I(0, 0), int layer=LAYER_NOTES)
Definition: sch_line.cpp:43
virtual bool HasLineStroke() const override
Check if this schematic item has line stoke properties.
Definition: sch_line.h:176
bool IsWire() const
Return true if the line is a wire.
Definition: sch_line.cpp:937
bool IsStartDangling() const
Definition: sch_line.h:257
SCH_LINE(const VECTOR2D &pos, int layer=LAYER_NOTES)
Definition: sch_line.h:46
void RotateEnd(const VECTOR2I &aCenter)
Definition: sch_line.cpp:395
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_line.cpp:191
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_line.cpp:182
void SetLineColor(const COLOR4D &aColor)
Definition: sch_line.cpp:213
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_line.cpp:633
EDA_ANGLE GetStoredAngle() const
Returns the angle stored by StoreAngle()
Definition: sch_line.h:127
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: sch_line.cpp:705
bool IsParallel(const SCH_LINE *aLine) const
Definition: sch_line.cpp:427
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:285
void RotateStart(const VECTOR2I &aCenter)
Definition: sch_line.cpp:389
int GetLineSize() const
Definition: sch_line.h:196
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_line.cpp:366
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_line.h:177
int GetAngleFrom(const VECTOR2I &aPoint) const
Definition: sch_line.cpp:401
void GetSelectedPoints(std::vector< VECTOR2I > &aPoints) const
Definition: sch_line.cpp:695
COLOR4D m_lastResolvedColor
Definition: sch_line.h:349
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition: sch_line.cpp:893
EDA_ANGLE Angle() const
Gets the angle between the start and end lines.
Definition: sch_line.h:105
wxString GetClass() const override
Return the class name.
Definition: sch_line.h:59
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_line.h:54
VECTOR2I GetMidPoint() const
Definition: sch_line.h:141
VECTOR2I GetEndPoint() const
Definition: sch_line.h:143
VECTOR2I GetStartPoint() const
Definition: sch_line.h:138
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Return true if this item should propagate connection info to aItem.
Definition: sch_line.cpp:682
VECTOR2I GetPosition() const override
Definition: sch_line.h:277
bool IsEndDangling() const
Definition: sch_line.h:258
SCH_LINE * MergeOverlap(SCH_SCREEN *aScreen, SCH_LINE *aLine, bool aCheckJunctions)
Check line against aLine to see if it overlaps and merge if it does.
Definition: sch_line.cpp:440
VECTOR2I m_start
Line start point.
Definition: sch_line.h:339
bool IsBus() const
Return true if the line is a bus.
Definition: sch_line.cpp:943
int m_lastResolvedWidth
Definition: sch_line.h:348
void StoreAngle(const EDA_ANGLE &aAngle)
Definition: sch_line.h:120
VECTOR2I m_end
Line end point.
Definition: sch_line.h:340
PLOT_DASH_TYPE m_lastResolvedLineStyle
Definition: sch_line.h:347
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_line.cpp:134
bool UpdateDanglingState(std::vector< DANGLING_END_ITEM > &aItemList, const SCH_SHEET_PATH *aPath=nullptr) override
Test the schematic item to aItemList to check if it's dangling state has changed.
Definition: sch_line.cpp:583
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:256
bool IsNull() const
Definition: sch_line.h:136
PLOT_DASH_TYPE GetLineStyle() const
Definition: sch_line.cpp:263
void MoveEnd(const VECTOR2I &aMoveVector)
Definition: sch_line.cpp:155
VECTOR2I GetSortPosition() const override
Return the coordinates that should be used for sorting this element visually compared to other elemen...
Definition: sch_line.h:279
STROKE_PARAMS m_stroke
Line stroke properties.
Definition: sch_line.h:342
EDA_ANGLE m_storedAngle
Stored angle.
Definition: sch_line.h:341
bool m_endIsDangling
True if end point is not connected.
Definition: sch_line.h:338
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_line.cpp:808
bool IsConnectable() const override
Definition: sch_line.cpp:624
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_line.cpp:356
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_line.cpp:753
virtual void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: sch_line.h:178
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset) override
Print a schematic item.
Definition: sch_line.cpp:326
wxString GetNetname(const SCH_SHEET_PATH &aSheet)
This function travel though all the connected wire segments to look for connected labels.
Definition: sch_line.cpp:90
bool IsEndPoint(const VECTOR2I &aPoint) const
Definition: sch_line.h:92
void Plot(PLOTTER *aPlotter, bool aBackground) const override
Plot the schematic item to aPlotter.
Definition: sch_line.cpp:831
bool IsStrokeEquivalent(const SCH_LINE *aLine)
Definition: sch_line.h:180
void SetLastResolvedState(const SCH_ITEM *aItem) override
Definition: sch_line.h:146
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
Definition: sch_line.cpp:931
static enum wxPenStyle PenStyle[]
Definition: sch_line.h:42
COLOR4D GetLineColor() const
Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
Definition: sch_line.cpp:237
void MoveStart(const VECTOR2I &aMoveVector)
Definition: sch_line.cpp:145
double GetLength() const
Definition: sch_line.cpp:207
PLOT_DASH_TYPE GetEffectiveLineStyle() const
Definition: sch_line.cpp:272
SCH_LINE * BreakAt(const VECTOR2I &aPoint)
Break this segment into two at the specified point.
Definition: sch_line.cpp:561
~SCH_LINE()
Definition: sch_line.h:52
bool IsOrthogonal() const
Checks if line is orthogonal (to the grid).
Definition: sch_line.h:134
wxString FindWireSegmentNetNameRecursive(SCH_LINE *line, std::list< const SCH_LINE * > &checkedLines, const SCH_SHEET_PATH &aSheet) const
Recursively called function to travel through the connected wires and find a connected net name label...
Definition: sch_line.cpp:97
void SetEndPoint(const VECTOR2I &aPosition)
Definition: sch_line.h:144
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition: sch_line.h:72
bool IsDangling() const override
Definition: sch_line.h:259
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
int GetWidth() const
Definition: stroke_params.h:98
KIGFX::COLOR4D GetColor() const
PLOT_DASH_TYPE GetPlotStyle() const
@ LAYER_WIRE
Definition: layer_ids.h:344
@ LAYER_NOTES
Definition: layer_ids.h:358
@ LAYER_BUS
Definition: layer_ids.h:345
PLOT_DASH_TYPE
Dashed line types.
Definition: stroke_params.h:48
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
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618