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 (C) 1992-2024 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 void Serialize( google::protobuf::Any &aContainer ) const override;
55 bool Deserialize( const google::protobuf::Any &aContainer ) override;
56
57 static inline bool ClassOf( const EDA_ITEM* aItem )
58 {
59 return aItem && SCH_LINE_T == aItem->Type();
60 }
61
62 wxString GetClass() const override
63 {
64 return wxT( "SCH_LINE" );
65 }
66
67 wxString GetFriendlyName() const override;
68
69 bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
70 {
71 if( SCH_ITEM::IsType( aScanTypes ) )
72 return true;
73
74 for( KICAD_T scanType : aScanTypes )
75 {
76 if( scanType == SCH_ITEM_LOCATE_WIRE_T && m_layer == LAYER_WIRE )
77 return true;
78
79 if ( scanType == SCH_ITEM_LOCATE_BUS_T && m_layer == LAYER_BUS )
80 return true;
81
83 return true;
84 }
85
86 return false;
87 }
88
89 bool IsEndPoint( const VECTOR2I& aPoint ) const
90 {
91 return aPoint == m_start || aPoint == m_end;
92 }
93
94 int GetAngleFrom( const VECTOR2I& aPoint ) const;
95 int GetReverseAngleFrom( const VECTOR2I& aPoint ) const;
96
102 inline EDA_ANGLE Angle() const
103 {
104 return ( EDA_ANGLE( (VECTOR2I) m_end - (VECTOR2I) m_start ) );
105 }
106
111 inline void StoreAngle()
112 {
113 if( !IsNull() )
115 }
116
117 inline void StoreAngle( const EDA_ANGLE& aAngle ) { m_storedAngle = aAngle; }
118
124 inline EDA_ANGLE GetStoredAngle() const { return m_storedAngle; }
125
131 inline bool IsOrthogonal() const { return Angle().IsCardinal(); }
132
133 bool IsNull() const { return m_start == m_end; }
134
135 VECTOR2I GetStartPoint() const { return m_start; }
136 void SetStartPoint( const VECTOR2I& aPosition ) { m_start = aPosition; }
137
138 VECTOR2I GetMidPoint() const { return ( m_start + m_end ) / 2; }
139
140 VECTOR2I GetEndPoint() const { return m_end; }
141 void SetEndPoint( const VECTOR2I& aPosition ) { m_end = aPosition; }
142
143 void SetLastResolvedState( const SCH_ITEM* aItem ) override
144 {
145 const SCH_LINE* aLine = dynamic_cast<const SCH_LINE*>( aItem );
146
147 if( aLine )
148 {
149 m_stroke = aLine->GetStroke();
153 }
154 }
155
156 void SetLineStyle( const LINE_STYLE aStyle );
157 void SetLineStyle( const int aStyleId );
158 LINE_STYLE GetLineStyle() const;
159
163
164 void SetLineColor( const COLOR4D& aColor );
165
166 void SetLineColor( const double r, const double g, const double b, const double a );
167
169 COLOR4D GetLineColor() const;
170
171 void SetLineWidth( const int aSize );
172 int GetLineWidth() const { return m_stroke.GetWidth(); }
173
174 virtual bool HasLineStroke() const override { return true; }
175 virtual STROKE_PARAMS GetStroke() const override { return m_stroke; }
176 virtual void SetStroke( const STROKE_PARAMS& aStroke ) override { m_stroke = aStroke; }
177
178 bool IsStrokeEquivalent( const SCH_LINE* aLine )
179 {
180 if( m_stroke.GetWidth() != aLine->GetStroke().GetWidth() )
181 return false;
182
183 if( m_stroke.GetColor() != aLine->GetStroke().GetColor() )
184 return false;
185
186 LINE_STYLE style_a = m_stroke.GetLineStyle();
187 LINE_STYLE style_b = aLine->GetStroke().GetLineStyle();
188
189 return style_a == style_b
190 || ( style_a == LINE_STYLE::DEFAULT && style_b == LINE_STYLE::SOLID )
191 || ( style_a == LINE_STYLE::SOLID && style_b == LINE_STYLE::DEFAULT );
192 }
193
194 void ViewGetLayers( int aLayers[], int& aCount ) const override;
195
196 double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
197
198 const BOX2I GetBoundingBox() const override;
199
203 double GetLength() const;
204
205 int GetPenWidth() const override;
206
207 void Move( const VECTOR2I& aMoveVector ) override;
208 void MoveStart( const VECTOR2I& aMoveVector );
209 void MoveEnd( const VECTOR2I& aMoveVector );
210
211 void MirrorVertically( int aCenter ) override;
212 void MirrorHorizontally( int aCenter ) override;
213 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
214
228 SCH_LINE* MergeOverlap( SCH_SCREEN* aScreen, SCH_LINE* aLine, bool aCheckJunctions );
229
242 SCH_LINE* BreakAt( const VECTOR2I& aPoint );
243
244 bool IsParallel( const SCH_LINE* aLine ) const;
245
246 void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override;
247
248 bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemListByType,
249 std::vector<DANGLING_END_ITEM>& aItemListByPos,
250 const SCH_SHEET_PATH* aPath = nullptr ) override;
251
252 bool IsStartDangling() const { return m_startIsDangling; }
253 bool IsEndDangling() const { return m_endIsDangling; }
254 bool IsDangling() const override { return m_startIsDangling || m_endIsDangling; }
255
256 bool IsConnectable() const override;
257
258 bool HasConnectivityChanges( const SCH_ITEM* aItem,
259 const SCH_SHEET_PATH* aInstance = nullptr ) const override;
260
261 std::vector<VECTOR2I> GetConnectionPoints() const override;
262
263 bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const override;
264
265 void GetSelectedPoints( std::vector<VECTOR2I>& aPoints ) const;
266
267 bool CanConnect( const SCH_ITEM* aItem ) const override;
268
269 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
270
271 BITMAPS GetMenuImage() const override;
272
273 bool operator <( const SCH_ITEM& aItem ) const override;
274
275 VECTOR2I GetPosition() const override { return m_start; }
276 void SetPosition( const VECTOR2I& aPosition ) override;
277 VECTOR2I GetSortPosition() const override { return GetMidPoint(); }
278
279 bool IsPointClickableAnchor( const VECTOR2I& aPos ) const override
280 {
281 return ( GetStartPoint() == aPos && IsStartDangling() )
282 || ( GetEndPoint() == aPos && IsEndDangling() );
283 }
284
285 bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
286 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
287
288 void Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
289 const VECTOR2I& aOffset, bool aForceNoFill, bool aDimmed ) override;
290
291 void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
292 int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
293
294 EDA_ITEM* Clone() const override;
295
296 void SwapData( SCH_ITEM* aItem ) override;
297
298 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
299
300 const wxString& GetOperatingPoint() const { return m_operatingPoint; }
301 void SetOperatingPoint( const wxString& aText ) { m_operatingPoint = aText; }
302
303#if defined(DEBUG)
304 void Show( int nestLevel, std::ostream& os ) const override;
305#endif
306
312 bool IsGraphicLine() const;
313
319 bool IsWire() const;
320
326 bool IsBus() const;
327
328 double Similarity( const SCH_ITEM& aOther ) const override;
329
330 bool operator==( const SCH_ITEM& aOther ) const override;
331
332private:
333 bool doIsConnected( const VECTOR2I& aPosition ) const override;
334
335private:
342
343 // If real-time connectivity gets disabled (due to being too slow on a particular
344 // design), we can no longer rely on getting the NetClass to find netclass-specific
345 // linestyles, linewidths and colors.
349
351};
352
353
354#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:88
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:100
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:68
Base plotter engine class.
Definition: plotter.h:104
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:174
SCH_LAYER_ID m_layer
Definition: sch_item.h:731
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition: sch_item.h:189
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:327
bool doIsConnected(const VECTOR2I &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_line.cpp:857
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:594
void SetStartPoint(const VECTOR2I &aPosition)
Definition: sch_line.h:136
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_line.cpp:149
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_line.cpp:775
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:604
void SetOperatingPoint(const wxString &aText)
Definition: sch_line.h:301
bool m_startIsDangling
True if start point is not connected.
Definition: sch_line.h:336
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:809
bool IsPointClickableAnchor(const VECTOR2I &aPos) const override
Definition: sch_line.h:279
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_line.cpp:925
void StoreAngle()
Saves the current line angle.
Definition: sch_line.h:111
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_line.cpp:709
int GetReverseAngleFrom(const VECTOR2I &aPoint) const
Definition: sch_line.cpp:435
double ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition: sch_line.cpp:201
virtual bool HasLineStroke() const override
Check if this schematic item has line stoke properties.
Definition: sch_line.h:174
bool IsWire() const
Return true if the line is a wire.
Definition: sch_line.cpp:976
bool IsStartDangling() const
Definition: sch_line.h:252
SCH_LINE(const VECTOR2D &pos, int layer=LAYER_NOTES)
Definition: sch_line.h:46
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_line.cpp:226
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:191
void SetLineColor(const COLOR4D &aColor)
Definition: sch_line.cpp:248
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_line.cpp:666
EDA_ANGLE GetStoredAngle() const
Returns the angle stored by StoreAngle()
Definition: sch_line.h:124
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: sch_line.cpp:738
bool IsParallel(const SCH_LINE *aLine) const
Definition: sch_line.cpp:448
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:320
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_line.cpp:402
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_line.h:175
int GetAngleFrom(const VECTOR2I &aPoint) const
Definition: sch_line.cpp:422
void GetSelectedPoints(std::vector< VECTOR2I > &aPoints) const
Definition: sch_line.cpp:728
COLOR4D m_lastResolvedColor
Definition: sch_line.h:348
LINE_STYLE GetEffectiveLineStyle() const
Definition: sch_line.cpp:307
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:932
EDA_ANGLE Angle() const
Gets the angle between the start and end lines.
Definition: sch_line.h:102
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:866
wxString m_operatingPoint
Definition: sch_line.h:350
wxString GetClass() const override
Return the class name.
Definition: sch_line.h:62
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_line.h:57
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_line.cpp:412
VECTOR2I GetMidPoint() const
Definition: sch_line.h:138
VECTOR2I GetEndPoint() const
Definition: sch_line.h:140
VECTOR2I GetStartPoint() const
Definition: sch_line.h:135
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Return true if this item should propagate connection info to aItem.
Definition: sch_line.cpp:715
LINE_STYLE m_lastResolvedLineStyle
Definition: sch_line.h:346
VECTOR2I GetPosition() const override
Definition: sch_line.h:275
bool IsEndDangling() const
Definition: sch_line.h:253
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:461
VECTOR2I m_start
Line start point.
Definition: sch_line.h:338
bool IsBus() const
Return true if the line is a bus.
Definition: sch_line.cpp:982
int m_lastResolvedWidth
Definition: sch_line.h:347
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:361
void StoreAngle(const EDA_ANGLE &aAngle)
Definition: sch_line.h:117
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:690
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition: sch_line.cpp:95
void SetLineStyle(const LINE_STYLE aStyle)
Definition: sch_line.cpp:291
VECTOR2I m_end
Line end point.
Definition: sch_line.h:339
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_line.cpp:155
LINE_STYLE GetLineStyle() const
Definition: sch_line.cpp:298
bool IsNull() const
Definition: sch_line.h:133
void MoveEnd(const VECTOR2I &aMoveVector)
Definition: sch_line.cpp:168
VECTOR2I GetSortPosition() const override
Return the coordinates that should be used for sorting this element visually compared to other elemen...
Definition: sch_line.h:277
STROKE_PARAMS m_stroke
Line stroke properties.
Definition: sch_line.h:341
EDA_ANGLE m_storedAngle
Stored angle.
Definition: sch_line.h:340
bool m_endIsDangling
True if end point is not connected.
Definition: sch_line.h:337
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_line.cpp:841
bool IsConnectable() const override
Definition: sch_line.cpp:657
wxString GetFriendlyName() const override
Definition: sch_line.cpp:138
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_line.cpp:392
bool operator==(const SCH_ITEM &aOther) const override
Definition: sch_line.cpp:988
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_line.cpp:786
virtual void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: sch_line.h:176
bool IsEndPoint(const VECTOR2I &aPoint) const
Definition: sch_line.h:89
bool IsStrokeEquivalent(const SCH_LINE *aLine)
Definition: sch_line.h:178
void SetLastResolvedState(const SCH_ITEM *aItem) override
Definition: sch_line.h:143
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
Definition: sch_line.cpp:970
static enum wxPenStyle PenStyle[]
Definition: sch_line.h:42
int GetLineWidth() const
Definition: sch_line.h:172
COLOR4D GetLineColor() const
Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
Definition: sch_line.cpp:272
void MoveStart(const VECTOR2I &aMoveVector)
Definition: sch_line.cpp:162
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition: sch_line.cpp:109
double GetLength() const
Definition: sch_line.cpp:242
SCH_LINE * BreakAt(const VECTOR2I &aPoint)
Break this segment into two at the specified point.
Definition: sch_line.cpp:582
~SCH_LINE()
Definition: sch_line.h:52
bool IsOrthogonal() const
Checks if line is orthogonal (to the grid).
Definition: sch_line.h:131
void SetEndPoint(const VECTOR2I &aPosition)
Definition: sch_line.h:141
bool IsType(const std::vector< KICAD_T > &aScanTypes) const override
Check whether the item is one of the listed types.
Definition: sch_line.h:69
bool IsDangling() const override
Definition: sch_line.h:254
const wxString & GetOperatingPoint() const
Definition: sch_line.h:300
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:1017
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
int GetWidth() const
Definition: stroke_params.h:91
LINE_STYLE GetLineStyle() const
Definition: stroke_params.h:94
KIGFX::COLOR4D GetColor() const
Definition: stroke_params.h:97
@ LAYER_WIRE
Definition: layer_ids.h:356
@ LAYER_NOTES
Definition: layer_ids.h:371
@ LAYER_BUS
Definition: layer_ids.h:357
LINE_STYLE
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: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< int > VECTOR2I
Definition: vector2d.h:602