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, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 1992-2020 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 {
41  wxPoint m_start;
42  wxPoint m_end;
44 
45 public:
46 
47  static const enum wxPenStyle PenStyle[];
48 
49  SCH_LINE( const wxPoint& pos = wxPoint( 0, 0 ), int layer = LAYER_NOTES );
50 
51  SCH_LINE( const VECTOR2D& pos, int layer = LAYER_NOTES ) :
52  SCH_LINE( wxPoint( pos.x, pos.y ), layer )
53  {}
54 
55  SCH_LINE( const SCH_LINE& aLine );
56 
57  ~SCH_LINE() { }
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  bool IsType( const KICAD_T aScanTypes[] ) const override
70  {
71  if( SCH_ITEM::IsType( aScanTypes ) )
72  return true;
73 
74  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
75  {
76  if( *p == SCH_LINE_LOCATE_WIRE_T && m_layer == LAYER_WIRE )
77  return true;
78  else if ( *p == SCH_LINE_LOCATE_BUS_T && m_layer == LAYER_BUS )
79  return true;
80  else if ( *p == SCH_LINE_LOCATE_GRAPHIC_LINE_T && m_layer == LAYER_NOTES )
81  return true;
82  }
83 
84  return false;
85  }
86 
87  bool IsEndPoint( const wxPoint& aPoint ) const
88  {
89  return aPoint == m_start || aPoint == m_end;
90  }
91 
92  bool IsNull() const { return m_start == m_end; }
93 
94  wxPoint GetStartPoint() const { return m_start; }
95  void SetStartPoint( const wxPoint& aPosition ) { m_start = aPosition; }
96 
97  wxPoint GetEndPoint() const { return m_end; }
98  void SetEndPoint( const wxPoint& aPosition ) { m_end = aPosition; }
99 
101 
102  void SetLineStyle( const PLOT_DASH_TYPE aStyle );
103  void SetLineStyle( const int aStyleId );
105 
109 
112  static const char* GetLineStyleName( PLOT_DASH_TYPE aStyle );
113 
116  static PLOT_DASH_TYPE GetLineStyleByName( const wxString& aStyleName );
117 
118  void SetLineColor( const COLOR4D& aColor );
119 
120  void SetLineColor( const double r, const double g, const double b, const double a );
121 
123  COLOR4D GetLineColor() const;
124 
125  void SetLineWidth( const int aSize );
126 
127  virtual bool HasLineStroke() const override { return true; }
128  virtual STROKE_PARAMS GetStroke() const override { return m_stroke; }
129  virtual void SetStroke( const STROKE_PARAMS& aStroke ) override { m_stroke = aStroke; }
130 
131  bool IsStrokeEquivalent( const SCH_LINE* aLine )
132  {
133  if( m_stroke.GetWidth() != aLine->GetStroke().GetWidth() )
134  return false;
135 
136  if( m_stroke.GetColor() != aLine->GetStroke().GetColor() )
137  return false;
138 
140  PLOT_DASH_TYPE style_b = aLine->GetStroke().GetPlotStyle();
141 
142  return style_a == style_b
143  || ( style_a == PLOT_DASH_TYPE::DEFAULT && style_b == PLOT_DASH_TYPE::SOLID )
144  || ( style_a == PLOT_DASH_TYPE::SOLID && style_b == PLOT_DASH_TYPE::DEFAULT );
145  }
146 
154  bool UsesDefaultStroke() const;
155 
156  int GetLineSize() const { return m_stroke.GetWidth(); }
157 
158  void ViewGetLayers( int aLayers[], int& aCount ) const override;
159 
160  const EDA_RECT GetBoundingBox() const override;
161 
165  double GetLength() const;
166 
167  void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override;
168 
169  int GetPenWidth() const override;
170 
171  void Move( const wxPoint& aMoveVector ) override;
172  void MoveStart( const wxPoint& aMoveVector );
173  void MoveEnd( const wxPoint& aMoveVector );
174 
175  void MirrorVertically( int aCenter ) override;
176  void MirrorHorizontally( int aCenter ) override;
177  void Rotate( wxPoint aPosition ) override;
178  void RotateStart( wxPoint aPosition );
179  void RotateEnd( wxPoint aPosition );
180 
194  SCH_LINE* MergeOverlap( SCH_SCREEN* aScreen, SCH_LINE* aLine, bool aCheckJunctions );
195 
204  bool IsSameQuadrant( const SCH_LINE* aLine, const wxPoint& aPosition ) const;
205 
206  bool IsParallel( const SCH_LINE* aLine ) const;
207 
208  void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override;
209 
210  bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
211  const SCH_SHEET_PATH* aPath = nullptr ) override;
212 
213  bool IsStartDangling() const { return m_startIsDangling; }
214  bool IsEndDangling() const { return m_endIsDangling; }
215  bool IsDangling() const override { return m_startIsDangling || m_endIsDangling; }
216 
217  bool IsConnectable() const override;
218 
219  std::vector<wxPoint> GetConnectionPoints() 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  BITMAP_DEF 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 ) 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 };
279 
280 
281 #endif // _SCH_LINE_H_
void Rotate(wxPoint aPosition) override
Rotate the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_line.cpp:394
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:567
static const char * GetLineStyleName(PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:84
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:449
COLOR4D GetLineColor() const
Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
Definition: sch_line.cpp:209
wxString GetClass() const override
Return the class name.
Definition: sch_line.h:64
bool IsGraphicLine() const
Returns if the line is a graphic (non electrical line)
Definition: sch_line.cpp:909
PNG memory record (file in memory).
Definition: bitmap_def.h:29
bool IsStrokeEquivalent(const SCH_LINE *aLine)
Definition: sch_line.h:131
wxPoint GetStartPoint() const
Definition: sch_line.h:94
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
bool IsWire() const
Returns true if the line is a wire.
Definition: sch_line.cpp:915
bool m_endIsDangling
True if end point is not connected.
Definition: sch_line.h:40
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_line.cpp:380
virtual bool HasLineStroke() const override
Check if this schematic item has line stoke properties.
Definition: sch_line.h:127
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:270
void RotateEnd(wxPoint aPosition)
Definition: sch_line.cpp:407
void MoveStart(const wxPoint &aMoveVector)
Definition: sch_line.cpp:120
void Plot(PLOTTER *aPlotter) override
Plot the schematic item to aPlotter.
Definition: sch_line.cpp:828
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:868
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_line.cpp:648
The base class for create windows for drawing purpose.
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_line.h:59
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:157
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:705
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 contained within or on the bounding box of an item.
Definition: sch_line.cpp:776
void RotateStart(wxPoint aPosition)
Definition: sch_line.cpp:401
bool UsesDefaultStroke() const
Test if the SCH_LINE object uses the default stroke settings.
Definition: sch_line.cpp:926
void Move(const wxPoint &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_line.cpp:109
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:98
bool IsConnectable() const override
Definition: sch_line.cpp:639
PLOT_DASH_TYPE GetDefaultStyle() const
Definition: sch_line.cpp:223
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:238
SCH_LAYER_ID m_layer
Definition: sch_item.h:201
BITMAP_DEF GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_line.cpp:742
PLOT_DASH_TYPE GetLineStyle() const
Definition: sch_line.cpp:247
bool IsNull() const
Definition: sch_line.h:92
bool IsEndDangling() const
Definition: sch_line.h:214
double GetLength() const
Definition: sch_line.cpp:182
void SetStartPoint(const wxPoint &aPosition)
Definition: sch_line.h:95
bool m_startIsDangling
True if start point is not connected.
Definition: sch_line.h:39
int GetPenWidth() const override
Definition: sch_line.cpp:276
PLOT_DASH_TYPE GetPlotStyle() const
Definition: sch_item.h:174
virtual bool IsType(const KICAD_T aScanTypes[]) const
Check whether the item is one of the listed types.
Definition: eda_item.h:232
bool IsDangling() const override
Definition: sch_line.h:215
~SCH_LINE()
Definition: sch_line.h:57
void SetLineColor(const COLOR4D &aColor)
Definition: sch_line.cpp:188
bool IsEndPoint(const wxPoint &aPoint) const
Definition: sch_line.h:87
int GetWidth() const
Definition: sch_item.h:171
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
bool doIsConnected(const wxPoint &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_line.cpp:819
void GetSelectedPoints(std::vector< wxPoint > &aPoints) const
Definition: sch_line.cpp:695
static PLOT_DASH_TYPE GetLineStyleByName(const wxString &aStyleName)
Definition: sch_line.cpp:94
wxPoint m_end
Line end point.
Definition: sch_line.h:42
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_line.cpp:805
STROKE_PARAMS m_stroke
Line stroke properties.
Definition: sch_line.h:43
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:177
int GetLineSize() const
Definition: sch_line.h:156
virtual void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: sch_line.h:129
PLOT_DASH_TYPE GetEffectiveLineStyle() const
Definition: sch_line.cpp:256
static enum wxPenStyle PenStyle[]
Definition: sch_line.h:47
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:67
void MoveEnd(const wxPoint &aMoveVector)
Definition: sch_line.cpp:130
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_line.cpp:753
Simple container to manage line stroke parameters.
Definition: sch_item.h:155
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:318
bool IsStartDangling() const
Definition: sch_line.h:213
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_line.cpp:387
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:149
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_line.h:128
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:595
bool IsParallel(const SCH_LINE *aLine) const
Definition: sch_line.cpp:436
bool IsSameQuadrant(const SCH_LINE *aLine, const wxPoint &aPosition) const
Check if two lines are in the same quadrant as each other, using a reference point as the origin.
Definition: sch_line.cpp:413
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_line.cpp:165
bool IsPointClickableAnchor(const wxPoint &aPos) const override
Definition: sch_line.h:234
void SetPosition(const wxPoint &aPosition) override
Definition: sch_line.cpp:861
bool IsType(const KICAD_T aScanTypes[]) const override
Check whether the item is one of the listed types.
Definition: sch_line.h:69
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:196
wxPoint m_start
Line start point.
Definition: sch_line.h:41
bool IsBus() const
Returns true if the line is a bus.
Definition: sch_line.cpp:920
SCH_LINE(const wxPoint &pos=wxPoint(0, 0), int layer=LAYER_NOTES)
Definition: sch_line.cpp:37
std::vector< wxPoint > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_line.cpp:689
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:162
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98
SCH_LINE(const VECTOR2D &pos, int layer=LAYER_NOTES)
Definition: sch_line.h:51
wxPoint GetEndPoint() const
Definition: sch_line.h:97