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 
30 class NETLIST_OBJECT_LIST;
31 
32 
37 class SCH_LINE : public SCH_ITEM
38 {
39 public:
40  static const enum wxPenStyle PenStyle[];
41 
42  SCH_LINE( const wxPoint& pos = wxPoint( 0, 0 ), int layer = LAYER_NOTES );
43 
44  SCH_LINE( const VECTOR2D& pos, int layer = LAYER_NOTES ) :
45  SCH_LINE( wxPoint( pos.x, pos.y ), layer )
46  {}
47 
48  SCH_LINE( const SCH_LINE& aLine );
49 
50  ~SCH_LINE() { }
51 
52  static inline bool ClassOf( const EDA_ITEM* aItem )
53  {
54  return aItem && SCH_LINE_T == aItem->Type();
55  }
56 
57  wxString GetClass() const override
58  {
59  return wxT( "SCH_LINE" );
60  }
61 
62  bool IsType( const KICAD_T aScanTypes[] ) const override
63  {
64  if( SCH_ITEM::IsType( aScanTypes ) )
65  return true;
66 
67  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
68  {
69  if( *p == SCH_LINE_LOCATE_WIRE_T && m_layer == LAYER_WIRE )
70  return true;
71  else if ( *p == SCH_LINE_LOCATE_BUS_T && m_layer == LAYER_BUS )
72  return true;
73  else if ( *p == SCH_LINE_LOCATE_GRAPHIC_LINE_T && m_layer == LAYER_NOTES )
74  return true;
75  }
76 
77  return false;
78  }
79 
80  bool IsEndPoint( const wxPoint& aPoint ) const
81  {
82  return aPoint == m_start || aPoint == m_end;
83  }
84 
85  int GetAngleFrom( const wxPoint& aPoint ) const;
86  int GetReverseAngleFrom( const wxPoint& aPoint ) const;
87 
88  bool IsNull() const { return m_start == m_end; }
89 
90  wxPoint GetStartPoint() const { return m_start; }
91  void SetStartPoint( const wxPoint& aPosition ) { m_start = aPosition; }
92 
93  wxPoint GetEndPoint() const { return m_end; }
94  void SetEndPoint( const wxPoint& aPosition ) { m_end = aPosition; }
95 
96  void SetLastResolvedState( const SCH_ITEM* aItem ) override
97  {
98  const SCH_LINE* aLine = dynamic_cast<const SCH_LINE*>( aItem );
99 
100  if( aLine )
101  {
105  }
106  }
107 
109 
110  void SetLineStyle( const PLOT_DASH_TYPE aStyle );
111  void SetLineStyle( const int aStyleId );
113 
117 
120  static const char* GetLineStyleName( PLOT_DASH_TYPE aStyle );
121 
124  static PLOT_DASH_TYPE GetLineStyleByName( const wxString& aStyleName );
125 
126  void SetLineColor( const COLOR4D& aColor );
127 
128  void SetLineColor( const double r, const double g, const double b, const double a );
129 
131  COLOR4D GetLineColor() const;
132 
133  void SetLineWidth( const int aSize );
134 
135  virtual bool HasLineStroke() const override { return true; }
136  virtual STROKE_PARAMS GetStroke() const override { return m_stroke; }
137  virtual void SetStroke( const STROKE_PARAMS& aStroke ) override { m_stroke = aStroke; }
138 
139  bool IsStrokeEquivalent( const SCH_LINE* aLine )
140  {
141  if( m_stroke.GetWidth() != aLine->GetStroke().GetWidth() )
142  return false;
143 
144  if( m_stroke.GetColor() != aLine->GetStroke().GetColor() )
145  return false;
146 
148  PLOT_DASH_TYPE style_b = aLine->GetStroke().GetPlotStyle();
149 
150  return style_a == style_b
151  || ( style_a == PLOT_DASH_TYPE::DEFAULT && style_b == PLOT_DASH_TYPE::SOLID )
152  || ( style_a == PLOT_DASH_TYPE::SOLID && style_b == PLOT_DASH_TYPE::DEFAULT );
153  }
154 
162  bool UsesDefaultStroke() const;
163 
164  int GetLineSize() const { return m_stroke.GetWidth(); }
165 
166  void ViewGetLayers( int aLayers[], int& aCount ) const override;
167 
168  const EDA_RECT GetBoundingBox() const override;
169 
173  double GetLength() const;
174 
175  void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override;
176 
177  int GetPenWidth() const override;
178 
179  void Move( const wxPoint& aMoveVector ) override;
180  void MoveStart( const wxPoint& aMoveVector );
181  void MoveEnd( const wxPoint& aMoveVector );
182 
183  void MirrorVertically( int aCenter ) override;
184  void MirrorHorizontally( int aCenter ) override;
185  void Rotate( const wxPoint& aCenter ) override;
186  void RotateStart( const wxPoint& aCenter );
187  void RotateEnd( const wxPoint& aCenter );
188 
202  SCH_LINE* MergeOverlap( SCH_SCREEN* aScreen, SCH_LINE* aLine, bool aCheckJunctions );
203 
204  bool IsParallel( const SCH_LINE* aLine ) const;
205 
206  void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override;
207 
208  bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
209  const SCH_SHEET_PATH* aPath = nullptr ) override;
210 
211  bool IsStartDangling() const { return m_startIsDangling; }
212  bool IsEndDangling() const { return m_endIsDangling; }
213  bool IsDangling() const override { return m_startIsDangling || m_endIsDangling; }
214 
215  bool IsConnectable() const override;
216 
217  std::vector<wxPoint> GetConnectionPoints() const override;
218 
219  bool ConnectionPropagatesTo( const EDA_ITEM* aItem ) const override;
220 
221  void GetSelectedPoints( std::vector< wxPoint >& aPoints ) const;
222 
223  bool CanConnect( const SCH_ITEM* aItem ) const override;
224 
225  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
226 
227  BITMAPS GetMenuImage() const override;
228 
229  bool operator <( const SCH_ITEM& aItem ) const override;
230 
231  wxPoint GetPosition() const override { return m_start; }
232  void SetPosition( const wxPoint& aPosition ) override;
233 
234  bool IsPointClickableAnchor( const wxPoint& aPos ) const override
235  {
236  return ( GetStartPoint() == aPos && IsStartDangling() )
237  || ( GetEndPoint() == aPos && IsEndDangling() );
238  }
239 
240  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
241  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
242 
243  void Plot( PLOTTER* aPlotter ) const override;
244 
245  EDA_ITEM* Clone() const override;
246 
247  void SwapData( SCH_ITEM* aItem ) override;
248 
249  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
250 
251 #if defined(DEBUG)
252  void Show( int nestLevel, std::ostream& os ) const override;
253 #endif
254 
260  bool IsGraphicLine() const;
261 
267  bool IsWire() const;
268 
274  bool IsBus() const;
275 
276 private:
277  bool doIsConnected( const wxPoint& aPosition ) const override;
278 
281  wxPoint m_start;
282  wxPoint m_end;
284 
285  // If real-time connectivity gets disabled (due to being too slow on a particular
286  // design), we can no longer rely on getting the NetClass to find netclass-specific
287  // linestyles, linewidths and colors.
289  mutable int m_lastResolvedWidth;
291 };
292 
293 
294 #endif // _SCH_LINE_H_
int GetReverseAngleFrom(const wxPoint &aPoint) const
Definition: sch_line.cpp:485
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:632
static const char * GetLineStyleName(PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:105
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:511
COLOR4D GetLineColor() const
Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
Definition: sch_line.cpp:236
wxString GetClass() const override
Return the class name.
Definition: sch_line.h:57
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
Definition: sch_line.cpp:966
bool IsStrokeEquivalent(const SCH_LINE *aLine)
Definition: sch_line.h:139
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_line.cpp:799
wxPoint GetStartPoint() const
Definition: sch_line.h:90
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
bool IsWire() const
Return true if the line is a wire.
Definition: sch_line.cpp:972
bool m_endIsDangling
True if end point is not connected.
Definition: sch_line.h:280
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_line.cpp:428
virtual bool HasLineStroke() const override
Check if this schematic item has line stoke properties.
Definition: sch_line.h:135
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:305
void MoveStart(const wxPoint &aMoveVector)
Definition: sch_line.cpp:144
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:922
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_line.cpp:692
The base class for create windows for drawing purpose.
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_line.h:52
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:181
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: sch_line.cpp:762
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: sch_line.cpp:833
bool UsesDefaultStroke() const
Test if the SCH_LINE object uses the default stroke settings.
Definition: sch_line.cpp:983
void Move(const wxPoint &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_line.cpp:133
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:94
bool IsConnectable() const override
Definition: sch_line.cpp:683
PLOT_DASH_TYPE GetDefaultStyle() const
Definition: sch_line.cpp:254
int GetAngleFrom(const wxPoint &aPoint) const
Definition: sch_line.cpp:472
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:269
SCH_LAYER_ID m_layer
Definition: sch_item.h:487
void Rotate(const wxPoint &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_line.cpp:448
PLOT_DASH_TYPE GetLineStyle() const
Definition: sch_line.cpp:278
bool IsNull() const
Definition: sch_line.h:88
bool IsEndDangling() const
Definition: sch_line.h:212
double GetLength() const
Definition: sch_line.cpp:207
void SetStartPoint(const wxPoint &aPosition)
Definition: sch_line.h:91
bool m_startIsDangling
True if start point is not connected.
Definition: sch_line.h:279
int GetPenWidth() const override
Definition: sch_line.cpp:311
PLOT_DASH_TYPE GetPlotStyle() const
Definition: sch_item.h:155
virtual bool IsType(const KICAD_T aScanTypes[]) const
Check whether the item is one of the listed types.
Definition: eda_item.h:182
bool IsDangling() const override
Definition: sch_line.h:213
~SCH_LINE()
Definition: sch_line.h:50
void SetLineColor(const COLOR4D &aColor)
Definition: sch_line.cpp:213
bool IsEndPoint(const wxPoint &aPoint) const
Definition: sch_line.h:80
int GetWidth() const
Definition: sch_item.h:152
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
PLOT_DASH_TYPE m_lastResolvedLineStyle
Definition: sch_line.h:288
E_SERIE r
Definition: eserie.cpp:41
bool doIsConnected(const wxPoint &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_line.cpp:885
void GetSelectedPoints(std::vector< wxPoint > &aPoints) const
Definition: sch_line.cpp:752
void Plot(PLOTTER *aPlotter) const override
Plot the schematic item to aPlotter.
Definition: sch_line.cpp:894
static PLOT_DASH_TYPE GetLineStyleByName(const wxString &aStyleName)
Definition: sch_line.cpp:115
wxPoint m_end
Line end point.
Definition: sch_line.h:282
COLOR4D m_lastResolvedColor
Definition: sch_line.h:290
void SetLastResolvedState(const SCH_ITEM *aItem) override
Definition: sch_line.h:96
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_line.cpp:871
STROKE_PARAMS m_stroke
Line stroke properties.
Definition: sch_line.h:283
PLOT_DASH_TYPE
Dashed line types.
Definition: plotter.h:104
EDA_UNITS
Definition: eda_units.h:38
Base plotter engine class.
Definition: plotter.h:121
COLOR4D GetColor() const
Definition: sch_item.h:158
int GetLineSize() const
Definition: sch_line.h:164
int m_lastResolvedWidth
Definition: sch_line.h:289
virtual void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: sch_line.h:137
PLOT_DASH_TYPE GetEffectiveLineStyle() const
Definition: sch_line.cpp:287
static enum wxPenStyle PenStyle[]
Definition: sch_line.h:40
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_line.cpp:88
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
void MoveEnd(const wxPoint &aMoveVector)
Definition: sch_line.cpp:154
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_line.cpp:810
Simple container to manage line stroke parameters.
Definition: sch_item.h:140
wxPoint GetPosition() const override
Definition: sch_line.h:231
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_line.cpp:366
bool IsStartDangling() const
Definition: sch_line.h:211
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_line.cpp:438
Handle the component boundary box.
Definition: eda_rect.h:42
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_line.h:136
void RotateEnd(const wxPoint &aCenter)
Definition: sch_line.cpp:466
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:642
bool IsParallel(const SCH_LINE *aLine) const
Definition: sch_line.cpp:498
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_line.cpp:190
bool IsPointClickableAnchor(const wxPoint &aPos) const override
Definition: sch_line.h:234
void RotateStart(const wxPoint &aCenter)
Definition: sch_line.cpp:460
void SetPosition(const wxPoint &aPosition) override
Definition: sch_line.cpp:915
bool IsType(const KICAD_T aScanTypes[]) const override
Check whether the item is one of the listed types.
Definition: sch_line.h:62
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
wxPoint m_start
Line start point.
Definition: sch_line.h:281
bool IsBus() const
Return true if the line is a bus.
Definition: sch_line.cpp:977
SCH_LINE(const wxPoint &pos=wxPoint(0, 0), int layer=LAYER_NOTES)
Definition: sch_line.cpp:40
std::vector< wxPoint > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_line.cpp:733
bool ConnectionPropagatesTo(const EDA_ITEM *aItem) const override
Return true if this item should propagate connection info to aItem.
Definition: sch_line.cpp:739
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
SCH_LINE(const VECTOR2D &pos, int layer=LAYER_NOTES)
Definition: sch_line.h:44
wxPoint GetEndPoint() const
Definition: sch_line.h:93