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#include <math/vector3.h>
33
34class NETLIST_OBJECT_LIST;
35
36
41class SCH_LINE : public SCH_ITEM
42{
43public:
44 static const enum wxPenStyle PenStyle[];
45
46 SCH_LINE( const VECTOR2I& pos = VECTOR2I( 0, 0 ), int layer = LAYER_NOTES );
47
48 SCH_LINE( const VECTOR2D& pos, int layer = LAYER_NOTES ) :
49 SCH_LINE( VECTOR2I( pos.x, pos.y ), layer )
50 {}
51
52 SCH_LINE( const SCH_LINE& aLine );
53
55
56 void Serialize( google::protobuf::Any &aContainer ) const override;
57 bool Deserialize( const google::protobuf::Any &aContainer ) override;
58
59 static inline bool ClassOf( const EDA_ITEM* aItem )
60 {
61 return aItem && SCH_LINE_T == aItem->Type();
62 }
63
64 wxString GetClass() const override
65 {
66 return wxT( "SCH_LINE" );
67 }
68
69 wxString GetFriendlyName() const override;
70
71 bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
72 {
73 if( SCH_ITEM::IsType( aScanTypes ) )
74 return true;
75
76 for( KICAD_T scanType : aScanTypes )
77 {
78 if( scanType == SCH_ITEM_LOCATE_WIRE_T && m_layer == LAYER_WIRE )
79 return true;
80
81 if ( scanType == SCH_ITEM_LOCATE_BUS_T && m_layer == LAYER_BUS )
82 return true;
83
85 return true;
86 }
87
88 return false;
89 }
90
91 bool IsEndPoint( const VECTOR2I& aPoint ) const override
92 {
93 return aPoint == m_start || aPoint == m_end;
94 }
95
96 int GetAngleFrom( const VECTOR2I& aPoint ) const;
97 int GetReverseAngleFrom( const VECTOR2I& aPoint ) const;
98
104 inline EDA_ANGLE Angle() const
105 {
106 return ( EDA_ANGLE( (VECTOR2I) m_end - (VECTOR2I) m_start ) );
107 }
108
115 inline void StoreAngle()
116 {
117 if( !IsNull() )
119 }
120
121 inline void StoreAngle( const EDA_ANGLE& aAngle ) { m_storedAngle = aAngle; }
122
128 inline EDA_ANGLE GetStoredAngle() const { return m_storedAngle; }
129
135 inline bool IsOrthogonal() const { return Angle().IsCardinal(); }
136
137 bool IsNull() const { return m_start == m_end; }
138
139 VECTOR2I GetStartPoint() const { return m_start; }
140 void SetStartPoint( const VECTOR2I& aPosition ) { m_start = aPosition; }
141
142 VECTOR2I GetMidPoint() const { return ( m_start + m_end ) / 2; }
143
144 VECTOR2I GetEndPoint() const { return m_end; }
145 void SetEndPoint( const VECTOR2I& aPosition ) { m_end = aPosition; }
146
150 SEG GetSeg() const
151 {
152 return SEG{ m_start, m_end };
153 }
154
155 void SetLastResolvedState( const SCH_ITEM* aItem ) override
156 {
157 const SCH_LINE* aLine = dynamic_cast<const SCH_LINE*>( aItem );
158
159 if( aLine )
160 {
161 m_stroke = aLine->GetStroke();
165 }
166 }
167
168 void SetLineStyle( const LINE_STYLE aStyle );
169 LINE_STYLE GetLineStyle() const;
170
174
175 // Special Getter/Setters for properties panel. Required because it uses #WIRE_STYLE instead
176 // of #LINE_STYLE. (The two enums are identical, but we expose "default" in the #WIRE_STYLE
177 // property while we don't with the LINE_STYLE property.)
178 void SetWireStyle( const WIRE_STYLE aStyle ) { SetLineStyle( (LINE_STYLE) aStyle ); }
180
181
182 void SetLineColor( const COLOR4D& aColor );
183
184 void SetLineColor( const double r, const double g, const double b, const double a );
185
187 COLOR4D GetLineColor() const;
188
189 void SetLineWidth( const int aSize );
190 int GetLineWidth() const { return m_stroke.GetWidth(); }
191
192 virtual bool HasLineStroke() const override { return true; }
193 virtual STROKE_PARAMS GetStroke() const override { return m_stroke; }
194 virtual void SetStroke( const STROKE_PARAMS& aStroke ) override { m_stroke = aStroke; }
195
196 bool IsStrokeEquivalent( const SCH_LINE* aLine )
197 {
198 if( m_stroke.GetWidth() != aLine->GetStroke().GetWidth() )
199 return false;
200
201 if( m_stroke.GetColor() != aLine->GetStroke().GetColor() )
202 return false;
203
204 LINE_STYLE style_a = m_stroke.GetLineStyle();
205 LINE_STYLE style_b = aLine->GetStroke().GetLineStyle();
206
207 return style_a == style_b
208 || ( style_a == LINE_STYLE::DEFAULT && style_b == LINE_STYLE::SOLID )
209 || ( style_a == LINE_STYLE::SOLID && style_b == LINE_STYLE::DEFAULT );
210 }
211
212 std::vector<int> ViewGetLayers() const override;
213
214 double ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const override;
215
216 const BOX2I GetBoundingBox() const override;
217
221 double GetLength() const;
222
223 int GetPenWidth() const override;
224
225 void Move( const VECTOR2I& aMoveVector ) override;
226 void MoveStart( const VECTOR2I& aMoveVector );
227 void MoveEnd( const VECTOR2I& aMoveVector );
228
229 void MirrorVertically( int aCenter ) override;
230 void MirrorHorizontally( int aCenter ) override;
231 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
232
246 SCH_LINE* MergeOverlap( SCH_SCREEN* aScreen, SCH_LINE* aLine, bool aCheckJunctions );
247
260 SCH_LINE* BreakAt( SCH_COMMIT* aCommit, const VECTOR2I& aPoint );
261
266 SCH_LINE* NonGroupAware_BreakAt( const VECTOR2I& aPoint );
267
268 bool IsParallel( const SCH_LINE* aLine ) const;
269
275 bool ShouldHopOver( const SCH_LINE* aLine ) const;
276
286 std::vector<VECTOR3I> BuildWireWithHopShape( const SCH_SCREEN* aScreen, double aArcRadius ) const;
287
288 void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override;
289
290 bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemListByType,
291 std::vector<DANGLING_END_ITEM>& aItemListByPos,
292 const SCH_SHEET_PATH* aPath = nullptr ) override;
293
294 bool IsStartDangling() const { return m_startIsDangling; }
295 bool IsEndDangling() const { return m_endIsDangling; }
296 bool IsDangling() const override { return m_startIsDangling || m_endIsDangling; }
297
298 bool IsConnectable() const override;
299
300 bool HasConnectivityChanges( const SCH_ITEM* aItem,
301 const SCH_SHEET_PATH* aInstance = nullptr ) const override;
302
303 std::vector<VECTOR2I> GetConnectionPoints() const override;
304
305 bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const override;
306
307 void GetSelectedPoints( std::vector<VECTOR2I>& aPoints ) const;
308
309 bool CanConnect( const SCH_ITEM* aItem ) const override;
310
311 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
312
313 BITMAPS GetMenuImage() const override;
314
315 bool operator <( const SCH_ITEM& aItem ) const override;
316
317 VECTOR2I GetPosition() const override { return m_start; }
318 void SetPosition( const VECTOR2I& aPosition ) override;
319 VECTOR2I GetSortPosition() const override { return GetMidPoint(); }
320
321 bool IsPointClickableAnchor( const VECTOR2I& aPos ) const override
322 {
323 return ( GetStartPoint() == aPos && IsStartDangling() )
324 || ( GetEndPoint() == aPos && IsEndDangling() );
325 }
326
327 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
328 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
329
330 void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
331 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
332
333 EDA_ITEM* Clone() const override;
334
335 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
336
337 const wxString& GetOperatingPoint() const { return m_operatingPoint; }
338 void SetOperatingPoint( const wxString& aText ) { m_operatingPoint = aText; }
339
340#if defined(DEBUG)
341 void Show( int nestLevel, std::ostream& os ) const override;
342#endif
343
349 bool IsGraphicLine() const;
350
356 bool IsWire() const;
357
363 bool IsBus() const;
364
365 double Similarity( const SCH_ITEM& aOther ) const override;
366
367 bool operator==( const SCH_ITEM& aOther ) const override;
368
369protected:
370 void swapData( SCH_ITEM* aItem ) override;
371
372private:
373 bool doIsConnected( const VECTOR2I& aPosition ) const override;
374
375private:
382
383 // If real-time connectivity gets disabled (due to being too slow on a particular
384 // design), we can no longer rely on getting the NetClass to find netclass-specific
385 // linestyles, linewidths and colors.
389
391};
392
393
394#ifndef SWIG
396#endif
397
398
399#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:98
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:110
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:66
Base plotter engine class.
Definition: plotter.h:121
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:168
SCH_LAYER_ID m_layer
Definition: sch_item.h:744
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition: sch_item.h:183
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:42
int GetPenWidth() const override
Definition: sch_line.cpp:322
bool doIsConnected(const VECTOR2I &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_line.cpp:831
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:570
void SetStartPoint(const VECTOR2I &aPosition)
Definition: sch_line.h:140
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_line.cpp:156
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_line.cpp:751
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:580
void SetOperatingPoint(const wxString &aText)
Definition: sch_line.h:338
bool m_startIsDangling
True if start point is not connected.
Definition: sch_line.h:376
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:785
bool IsPointClickableAnchor(const VECTOR2I &aPos) const override
Definition: sch_line.h:321
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_line.cpp:898
void StoreAngle()
Save the current line angle.
Definition: sch_line.h:115
std::vector< VECTOR3I > BuildWireWithHopShape(const SCH_SCREEN *aScreen, double aArcRadius) const
For wires only: build the list of points to draw the shape using segments and 180 deg arcs Points are...
Definition: sch_line.cpp:1049
SCH_LINE * NonGroupAware_BreakAt(const VECTOR2I &aPoint)
This version should only be used when importing files.
Definition: sch_line.cpp:558
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_line.cpp:685
int GetReverseAngleFrom(const VECTOR2I &aPoint) const
Definition: sch_line.cpp:399
virtual bool HasLineStroke() const override
Check if this schematic item has line stoke properties.
Definition: sch_line.h:192
bool IsWire() const
Return true if the line is a wire.
Definition: sch_line.cpp:949
bool IsStartDangling() const
Definition: sch_line.h:294
SCH_LINE(const VECTOR2D &pos, int layer=LAYER_NOTES)
Definition: sch_line.h:48
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_line.cpp:227
void SetWireStyle(const WIRE_STYLE aStyle)
Definition: sch_line.h:178
void SetLineColor(const COLOR4D &aColor)
Definition: sch_line.cpp:249
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_line.cpp:642
EDA_ANGLE GetStoredAngle() const
Return the angle stored by StoreAngle().
Definition: sch_line.h:128
bool IsParallel(const SCH_LINE *aLine) const
Definition: sch_line.cpp:412
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:315
bool ShouldHopOver(const SCH_LINE *aLine) const
For wires only:
Definition: sch_line.cpp:1024
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:193
int GetAngleFrom(const VECTOR2I &aPoint) const
Definition: sch_line.cpp:386
void GetSelectedPoints(std::vector< VECTOR2I > &aPoints) const
Definition: sch_line.cpp:704
COLOR4D m_lastResolvedColor
Definition: sch_line.h:388
LINE_STYLE GetEffectiveLineStyle() const
Definition: sch_line.cpp:302
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:905
EDA_ANGLE Angle() const
Get the angle between the start and end lines.
Definition: sch_line.h:104
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:840
wxString m_operatingPoint
Definition: sch_line.h:390
wxString GetClass() const override
Return the class name.
Definition: sch_line.h:64
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_line.h:59
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_line.cpp:376
VECTOR2I GetMidPoint() const
Definition: sch_line.h:142
VECTOR2I GetEndPoint() const
Definition: sch_line.h:144
VECTOR2I GetStartPoint() const
Definition: sch_line.h:139
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Return true if this item should propagate connection info to aItem.
Definition: sch_line.cpp:691
LINE_STYLE m_lastResolvedLineStyle
Definition: sch_line.h:386
VECTOR2I GetPosition() const override
Definition: sch_line.h:317
SEG GetSeg() const
Get the geometric aspect of the wire as a SEG.
Definition: sch_line.h:150
bool IsEndDangling() const
Definition: sch_line.h:295
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:425
VECTOR2I m_start
Line start point.
Definition: sch_line.h:378
bool IsBus() const
Return true if the line is a bus.
Definition: sch_line.cpp:955
int m_lastResolvedWidth
Definition: sch_line.h:387
void StoreAngle(const EDA_ANGLE &aAngle)
Definition: sch_line.h:121
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:666
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition: sch_line.cpp:102
void SetLineStyle(const LINE_STYLE aStyle)
Definition: sch_line.cpp:286
VECTOR2I m_end
Line end point.
Definition: sch_line.h:379
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_line.cpp:162
LINE_STYLE GetLineStyle() const
Definition: sch_line.cpp:293
bool IsNull() const
Definition: sch_line.h:137
void MoveEnd(const VECTOR2I &aMoveVector)
Definition: sch_line.cpp:175
VECTOR2I GetSortPosition() const override
Return the coordinates that should be used for sorting this element visually compared to other elemen...
Definition: sch_line.h:319
STROKE_PARAMS m_stroke
Line stroke properties.
Definition: sch_line.h:381
EDA_ANGLE m_storedAngle
Stored angle.
Definition: sch_line.h:380
SCH_LINE * BreakAt(SCH_COMMIT *aCommit, const VECTOR2I &aPoint)
Break this segment into two at the specified point.
Definition: sch_line.cpp:546
bool m_endIsDangling
True if end point is not connected.
Definition: sch_line.h:377
bool IsConnectable() const override
Definition: sch_line.cpp:633
wxString GetFriendlyName() const override
Definition: sch_line.cpp:145
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition: sch_line.cpp:205
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_line.cpp:356
bool operator==(const SCH_ITEM &aOther) const override
Definition: sch_line.cpp:961
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_line.cpp:762
virtual void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: sch_line.h:194
bool IsStrokeEquivalent(const SCH_LINE *aLine)
Definition: sch_line.h:196
WIRE_STYLE GetWireStyle() const
Definition: sch_line.h:179
void SetLastResolvedState(const SCH_ITEM *aItem) override
Definition: sch_line.h:155
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: sch_line.cpp:714
bool IsEndPoint(const VECTOR2I &aPoint) const override
Test if aPt is an end point of this schematic object.
Definition: sch_line.h:91
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
Definition: sch_line.cpp:943
static enum wxPenStyle PenStyle[]
Definition: sch_line.h:44
int GetLineWidth() const
Definition: sch_line.h:190
COLOR4D GetLineColor() const
Return #COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
Definition: sch_line.cpp:273
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:198
void MoveStart(const VECTOR2I &aMoveVector)
Definition: sch_line.cpp:169
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition: sch_line.cpp:116
double GetLength() const
Definition: sch_line.cpp:243
~SCH_LINE()
Definition: sch_line.h:54
bool IsOrthogonal() const
Check if line is orthogonal (to the grid).
Definition: sch_line.h:135
void SetEndPoint(const VECTOR2I &aPosition)
Definition: sch_line.h:145
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition: sch_line.h:71
bool IsDangling() const override
Definition: sch_line.h:296
const wxString & GetOperatingPoint() const
Definition: sch_line.h:337
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:990
void swapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_line.cpp:817
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:94
int GetWidth() const
LINE_STYLE GetLineStyle() const
KIGFX::COLOR4D GetColor() const
@ LAYER_WIRE
Definition: layer_ids.h:442
@ LAYER_NOTES
Definition: layer_ids.h:457
@ LAYER_BUS
Definition: layer_ids.h:443
#define DECLARE_ENUM_TO_WXANY(type)
Definition: property.h:763
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:164
@ SCH_ITEM_LOCATE_WIRE_T
Definition: typeinfo.h:187
@ SCH_ITEM_LOCATE_BUS_T
Definition: typeinfo.h:188
@ SCH_ITEM_LOCATE_GRAPHIC_LINE_T
Definition: typeinfo.h:189
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695