KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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#include <geometry/seg.h>
32
33class NETLIST_OBJECT_LIST;
34
35
40class SCH_LINE : public SCH_ITEM
41{
42public:
43 static const enum wxPenStyle PenStyle[];
44
45 SCH_LINE( const VECTOR2I& pos = VECTOR2I( 0, 0 ), int layer = LAYER_NOTES );
46
47 SCH_LINE( const VECTOR2D& pos, int layer = LAYER_NOTES ) :
48 SCH_LINE( VECTOR2I( pos.x, pos.y ), layer )
49 {}
50
51 SCH_LINE( const SCH_LINE& aLine );
52
54
55 void Serialize( google::protobuf::Any &aContainer ) const override;
56 bool Deserialize( const google::protobuf::Any &aContainer ) override;
57
58 static inline bool ClassOf( const EDA_ITEM* aItem )
59 {
60 return aItem && SCH_LINE_T == aItem->Type();
61 }
62
63 wxString GetClass() const override
64 {
65 return wxT( "SCH_LINE" );
66 }
67
68 wxString GetFriendlyName() const override;
69
70 bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
71 {
72 if( SCH_ITEM::IsType( aScanTypes ) )
73 return true;
74
75 for( KICAD_T scanType : aScanTypes )
76 {
77 if( scanType == SCH_ITEM_LOCATE_WIRE_T && m_layer == LAYER_WIRE )
78 return true;
79
80 if ( scanType == SCH_ITEM_LOCATE_BUS_T && m_layer == LAYER_BUS )
81 return true;
82
84 return true;
85 }
86
87 return false;
88 }
89
90 bool IsEndPoint( const VECTOR2I& aPoint ) const
91 {
92 return aPoint == m_start || aPoint == m_end;
93 }
94
95 int GetAngleFrom( const VECTOR2I& aPoint ) const;
96 int GetReverseAngleFrom( const VECTOR2I& aPoint ) const;
97
103 inline EDA_ANGLE Angle() const
104 {
105 return ( EDA_ANGLE( (VECTOR2I) m_end - (VECTOR2I) m_start ) );
106 }
107
112 inline void StoreAngle()
113 {
114 if( !IsNull() )
116 }
117
118 inline void StoreAngle( const EDA_ANGLE& aAngle ) { m_storedAngle = aAngle; }
119
125 inline EDA_ANGLE GetStoredAngle() const { return m_storedAngle; }
126
132 inline bool IsOrthogonal() const { return Angle().IsCardinal(); }
133
134 bool IsNull() const { return m_start == m_end; }
135
136 VECTOR2I GetStartPoint() const { return m_start; }
137 void SetStartPoint( const VECTOR2I& aPosition ) { m_start = aPosition; }
138
139 VECTOR2I GetMidPoint() const { return ( m_start + m_end ) / 2; }
140
141 VECTOR2I GetEndPoint() const { return m_end; }
142 void SetEndPoint( const VECTOR2I& aPosition ) { m_end = aPosition; }
143
147 SEG GetSeg() const
148 {
149 return SEG{ m_start, m_end };
150 }
151
152 void SetLastResolvedState( const SCH_ITEM* aItem ) override
153 {
154 const SCH_LINE* aLine = dynamic_cast<const SCH_LINE*>( aItem );
155
156 if( aLine )
157 {
158 m_stroke = aLine->GetStroke();
162 }
163 }
164
165 void SetLineStyle( const LINE_STYLE aStyle );
170
171 // Special Getter/Setters for properties panel. Required because it uses WIRE_STYLE instead
172 // of LINE_STYLE. (The two enums are identical, but we expose "default" in the WIRE_STYLE
173 // property while we don't with the LINE_STYLE property.)
174 void SetWireStyle( const WIRE_STYLE aStyle ) { SetLineStyle( (LINE_STYLE) aStyle ); }
176
177
178 void SetLineColor( const COLOR4D& aColor );
179
180 void SetLineColor( const double r, const double g, const double b, const double a );
181
183 COLOR4D GetLineColor() const;
184
185 void SetLineWidth( const int aSize );
186 int GetLineWidth() const { return m_stroke.GetWidth(); }
187
188 virtual bool HasLineStroke() const override { return true; }
189 virtual STROKE_PARAMS GetStroke() const override { return m_stroke; }
190 virtual void SetStroke( const STROKE_PARAMS& aStroke ) override { m_stroke = aStroke; }
191
192 bool IsStrokeEquivalent( const SCH_LINE* aLine )
193 {
194 if( m_stroke.GetWidth() != aLine->GetStroke().GetWidth() )
195 return false;
196
197 if( m_stroke.GetColor() != aLine->GetStroke().GetColor() )
198 return false;
199
200 LINE_STYLE style_a = m_stroke.GetLineStyle();
201 LINE_STYLE style_b = aLine->GetStroke().GetLineStyle();
202
203 return style_a == style_b
204 || ( style_a == LINE_STYLE::DEFAULT && style_b == LINE_STYLE::SOLID )
205 || ( style_a == LINE_STYLE::SOLID && style_b == LINE_STYLE::DEFAULT );
206 }
207
208 std::vector<int> ViewGetLayers() const override;
209
210 double ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const override;
211
212 const BOX2I GetBoundingBox() const override;
213
217 double GetLength() const;
218
219 int GetPenWidth() const override;
220
221 void Move( const VECTOR2I& aMoveVector ) override;
222 void MoveStart( const VECTOR2I& aMoveVector );
223 void MoveEnd( const VECTOR2I& aMoveVector );
224
225 void MirrorVertically( int aCenter ) override;
226 void MirrorHorizontally( int aCenter ) override;
227 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
228
242 SCH_LINE* MergeOverlap( SCH_SCREEN* aScreen, SCH_LINE* aLine, bool aCheckJunctions );
243
256 SCH_LINE* BreakAt( const VECTOR2I& aPoint );
257
258 bool IsParallel( const SCH_LINE* aLine ) const;
259
260 void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override;
261
262 bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemListByType,
263 std::vector<DANGLING_END_ITEM>& aItemListByPos,
264 const SCH_SHEET_PATH* aPath = nullptr ) override;
265
266 bool IsStartDangling() const { return m_startIsDangling; }
267 bool IsEndDangling() const { return m_endIsDangling; }
268 bool IsDangling() const override { return m_startIsDangling || m_endIsDangling; }
269
270 bool IsConnectable() const override;
271
272 bool HasConnectivityChanges( const SCH_ITEM* aItem,
273 const SCH_SHEET_PATH* aInstance = nullptr ) const override;
274
275 std::vector<VECTOR2I> GetConnectionPoints() const override;
276
277 bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const override;
278
279 void GetSelectedPoints( std::vector<VECTOR2I>& aPoints ) const;
280
281 bool CanConnect( const SCH_ITEM* aItem ) const override;
282
283 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
284
285 BITMAPS GetMenuImage() const override;
286
287 bool operator <( const SCH_ITEM& aItem ) const override;
288
289 VECTOR2I GetPosition() const override { return m_start; }
290 void SetPosition( const VECTOR2I& aPosition ) override;
291 VECTOR2I GetSortPosition() const override { return GetMidPoint(); }
292
293 bool IsPointClickableAnchor( const VECTOR2I& aPos ) const override
294 {
295 return ( GetStartPoint() == aPos && IsStartDangling() )
296 || ( GetEndPoint() == aPos && IsEndDangling() );
297 }
298
299 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
300 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
301
302 void Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
303 const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed ) override;
304
305 void PrintBackground( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
306 const VECTOR2I& aOffset, bool aDimmed ) override {}
307
308 void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
309 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
310
311 EDA_ITEM* Clone() const override;
312
313 void SwapData( SCH_ITEM* aItem ) override;
314
315 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
316
317 const wxString& GetOperatingPoint() const { return m_operatingPoint; }
318 void SetOperatingPoint( const wxString& aText ) { m_operatingPoint = aText; }
319
320#if defined(DEBUG)
321 void Show( int nestLevel, std::ostream& os ) const override;
322#endif
323
329 bool IsGraphicLine() const;
330
336 bool IsWire() const;
337
343 bool IsBus() const;
344
345 double Similarity( const SCH_ITEM& aOther ) const override;
346
347 bool operator==( const SCH_ITEM& aOther ) const override;
348
349private:
350 bool doIsConnected( const VECTOR2I& aPosition ) const override;
351
352private:
359
360 // If real-time connectivity gets disabled (due to being too slow on a particular
361 // design), we can no longer rely on getting the NetClass to find netclass-specific
362 // linestyles, linewidths and colors.
366
368};
369
370
371#ifndef SWIG
373#endif
374
375
376#endif // _SCH_LINE_H_
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
bool IsCardinal() const
Definition: eda_angle.cpp:40
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:89
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
Base plotter engine class.
Definition: plotter.h:105
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:167
SCH_LAYER_ID m_layer
Definition: sch_item.h:709
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition: sch_item.h:182
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:41
int GetPenWidth() const override
Definition: sch_line.cpp:307
bool doIsConnected(const VECTOR2I &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_line.cpp:837
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:574
void SetStartPoint(const VECTOR2I &aPosition)
Definition: sch_line.h:137
void PrintBackground(const SCH_RENDER_SETTINGS *aSettings, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Print just the background fills.
Definition: sch_line.h:305
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_line.cpp:150
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_line.cpp:755
bool UpdateDanglingState(std::vector< DANGLING_END_ITEM > &aItemListByType, std::vector< DANGLING_END_ITEM > &aItemListByPos, 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:584
void SetOperatingPoint(const wxString &aText)
Definition: sch_line.h:318
bool m_startIsDangling
True if start point is not connected.
Definition: sch_line.h:353
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:789
bool IsPointClickableAnchor(const VECTOR2I &aPos) const override
Definition: sch_line.h:293
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_line.cpp:905
void StoreAngle()
Saves the current line angle.
Definition: sch_line.h:112
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_line.cpp:689
int GetReverseAngleFrom(const VECTOR2I &aPoint) const
Definition: sch_line.cpp:415
virtual bool HasLineStroke() const override
Check if this schematic item has line stoke properties.
Definition: sch_line.h:188
bool IsWire() const
Return true if the line is a wire.
Definition: sch_line.cpp:956
bool IsStartDangling() const
Definition: sch_line.h:266
SCH_LINE(const VECTOR2D &pos, int layer=LAYER_NOTES)
Definition: sch_line.h:47
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_line.cpp:221
void SetWireStyle(const WIRE_STYLE aStyle)
Definition: sch_line.h:174
void SetLineColor(const COLOR4D &aColor)
Definition: sch_line.cpp:243
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_line.cpp:646
EDA_ANGLE GetStoredAngle() const
Returns the angle stored by StoreAngle()
Definition: sch_line.h:125
bool IsParallel(const SCH_LINE *aLine) const
Definition: sch_line.cpp:428
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:300
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_line.cpp:382
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_line.h:189
int GetAngleFrom(const VECTOR2I &aPoint) const
Definition: sch_line.cpp:402
void GetSelectedPoints(std::vector< VECTOR2I > &aPoints) const
Definition: sch_line.cpp:708
COLOR4D m_lastResolvedColor
Definition: sch_line.h:365
LINE_STYLE GetEffectiveLineStyle() const
Definition: sch_line.cpp:287
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:912
EDA_ANGLE Angle() const
Gets the angle between the start and end lines.
Definition: sch_line.h:103
void Plot(PLOTTER *aPlotter, bool aBackground, const SCH_PLOT_OPTS &aPlotOpts, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aDimmed) override
Plot the item to aPlotter.
Definition: sch_line.cpp:846
wxString m_operatingPoint
Definition: sch_line.h:367
wxString GetClass() const override
Return the class name.
Definition: sch_line.h:63
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_line.h:58
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_line.cpp:392
VECTOR2I GetMidPoint() const
Definition: sch_line.h:139
VECTOR2I GetEndPoint() const
Definition: sch_line.h:141
VECTOR2I GetStartPoint() const
Definition: sch_line.h:136
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Return true if this item should propagate connection info to aItem.
Definition: sch_line.cpp:695
LINE_STYLE m_lastResolvedLineStyle
Definition: sch_line.h:363
VECTOR2I GetPosition() const override
Definition: sch_line.h:289
SEG GetSeg() const
Get the geometric aspect of the wire as a SEG.
Definition: sch_line.h:147
bool IsEndDangling() const
Definition: sch_line.h:267
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:441
VECTOR2I m_start
Line start point.
Definition: sch_line.h:355
bool IsBus() const
Return true if the line is a bus.
Definition: sch_line.cpp:962
int m_lastResolvedWidth
Definition: sch_line.h:364
void Print(const SCH_RENDER_SETTINGS *aSettings, int aUnit, int aBodyStyle, const VECTOR2I &aOffset, bool aForceNoFill, bool aDimmed) override
Print an item.
Definition: sch_line.cpp:341
void StoreAngle(const EDA_ANGLE &aAngle)
Definition: sch_line.h:118
bool HasConnectivityChanges(const SCH_ITEM *aItem, const SCH_SHEET_PATH *aInstance=nullptr) const override
Check if aItem has connectivity changes against this object.
Definition: sch_line.cpp:670
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition: sch_line.cpp:96
void SetLineStyle(const LINE_STYLE aStyle)
Definition: sch_line.cpp:280
VECTOR2I m_end
Line end point.
Definition: sch_line.h:356
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_line.cpp:156
LINE_STYLE GetLineStyle() const
Definition: sch_line.h:166
bool IsNull() const
Definition: sch_line.h:134
void MoveEnd(const VECTOR2I &aMoveVector)
Definition: sch_line.cpp:169
VECTOR2I GetSortPosition() const override
Return the coordinates that should be used for sorting this element visually compared to other elemen...
Definition: sch_line.h:291
STROKE_PARAMS m_stroke
Line stroke properties.
Definition: sch_line.h:358
EDA_ANGLE m_storedAngle
Stored angle.
Definition: sch_line.h:357
bool m_endIsDangling
True if end point is not connected.
Definition: sch_line.h:354
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_line.cpp:821
bool IsConnectable() const override
Definition: sch_line.cpp:637
wxString GetFriendlyName() const override
Definition: sch_line.cpp:139
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition: sch_line.cpp:199
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_line.cpp:372
bool operator==(const SCH_ITEM &aOther) const override
Definition: sch_line.cpp:968
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_line.cpp:766
virtual void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: sch_line.h:190
bool IsEndPoint(const VECTOR2I &aPoint) const
Definition: sch_line.h:90
bool IsStrokeEquivalent(const SCH_LINE *aLine)
Definition: sch_line.h:192
WIRE_STYLE GetWireStyle() const
Definition: sch_line.h:175
void SetLastResolvedState(const SCH_ITEM *aItem) override
Definition: sch_line.h:152
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: sch_line.cpp:718
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
Definition: sch_line.cpp:950
static enum wxPenStyle PenStyle[]
Definition: sch_line.h:43
int GetLineWidth() const
Definition: sch_line.h:186
COLOR4D GetLineColor() const
Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
Definition: sch_line.cpp:267
std::vector< int > ViewGetLayers() const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition: sch_line.cpp:192
void MoveStart(const VECTOR2I &aMoveVector)
Definition: sch_line.cpp:163
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition: sch_line.cpp:110
double GetLength() const
Definition: sch_line.cpp:237
SCH_LINE * BreakAt(const VECTOR2I &aPoint)
Break this segment into two at the specified point.
Definition: sch_line.cpp:562
~SCH_LINE()
Definition: sch_line.h:53
bool IsOrthogonal() const
Checks if line is orthogonal (to the grid).
Definition: sch_line.h:132
void SetEndPoint(const VECTOR2I &aPosition)
Definition: sch_line.h:142
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition: sch_line.h:70
bool IsDangling() const override
Definition: sch_line.h:268
const wxString & GetOperatingPoint() const
Definition: sch_line.h:317
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
Definition: sch_line.cpp:997
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Definition: seg.h:42
Simple container to manage line stroke parameters.
Definition: stroke_params.h:93
int GetWidth() const
LINE_STYLE GetLineStyle() const
KIGFX::COLOR4D GetColor() const
@ LAYER_WIRE
Definition: layer_ids.h:404
@ LAYER_NOTES
Definition: layer_ids.h:419
@ LAYER_BUS
Definition: layer_ids.h:405
#define DECLARE_ENUM_TO_WXANY(type)
Definition: property.h:746
LINE_STYLE
Dashed line types.
Definition: stroke_params.h:46
WIRE_STYLE
Definition: stroke_params.h:68
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ SCH_LINE_T
Definition: typeinfo.h:163
@ SCH_ITEM_LOCATE_WIRE_T
Definition: typeinfo.h:185
@ SCH_ITEM_LOCATE_BUS_T
Definition: typeinfo.h:186
@ SCH_ITEM_LOCATE_GRAPHIC_LINE_T
Definition: typeinfo.h:187
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695