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-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 
97 
98  void SetLineStyle( const PLOT_DASH_TYPE aStyle );
99  void SetLineStyle( const int aStyleId );
101 
105 
108  static const char* GetLineStyleName( PLOT_DASH_TYPE aStyle );
109 
112  static PLOT_DASH_TYPE GetLineStyleByName( const wxString& aStyleName );
113 
114  void SetLineColor( const COLOR4D& aColor );
115 
116  void SetLineColor( const double r, const double g, const double b, const double a );
117 
119  COLOR4D GetLineColor() const;
120 
121  void SetLineWidth( const int aSize );
122 
123  virtual bool HasLineStroke() const override { return true; }
124  virtual STROKE_PARAMS GetStroke() const override { return m_stroke; }
125  virtual void SetStroke( const STROKE_PARAMS& aStroke ) override { m_stroke = aStroke; }
126 
127  bool IsStrokeEquivalent( const SCH_LINE* aLine )
128  {
129  if( m_stroke.GetWidth() != aLine->GetStroke().GetWidth() )
130  return false;
131 
132  if( m_stroke.GetColor() != aLine->GetStroke().GetColor() )
133  return false;
134 
136  PLOT_DASH_TYPE style_b = aLine->GetStroke().GetPlotStyle();
137 
138  return style_a == style_b
139  || ( style_a == PLOT_DASH_TYPE::DEFAULT && style_b == PLOT_DASH_TYPE::SOLID )
140  || ( style_a == PLOT_DASH_TYPE::SOLID && style_b == PLOT_DASH_TYPE::DEFAULT );
141  }
142 
150  bool UsesDefaultStroke() const;
151 
152  int GetLineSize() const { return m_stroke.GetWidth(); }
153 
154  void ViewGetLayers( int aLayers[], int& aCount ) const override;
155 
156  const EDA_RECT GetBoundingBox() const override;
157 
161  double GetLength() const;
162 
163  void Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override;
164 
165  int GetPenWidth() const override;
166 
167  void Move( const wxPoint& aMoveVector ) override;
168  void MoveStart( const wxPoint& aMoveVector );
169  void MoveEnd( const wxPoint& aMoveVector );
170 
171  void MirrorVertically( int aCenter ) override;
172  void MirrorHorizontally( int aCenter ) override;
173  void Rotate( wxPoint aCenter ) override;
174  void RotateStart( wxPoint aCenter );
175  void RotateEnd( wxPoint aCenter );
176 
190  SCH_LINE* MergeOverlap( SCH_SCREEN* aScreen, SCH_LINE* aLine, bool aCheckJunctions );
191 
192  bool IsParallel( const SCH_LINE* aLine ) const;
193 
194  void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override;
195 
196  bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
197  const SCH_SHEET_PATH* aPath = nullptr ) override;
198 
199  bool IsStartDangling() const { return m_startIsDangling; }
200  bool IsEndDangling() const { return m_endIsDangling; }
201  bool IsDangling() const override { return m_startIsDangling || m_endIsDangling; }
202 
203  bool IsConnectable() const override;
204 
205  std::vector<wxPoint> GetConnectionPoints() const override;
206 
207  void GetSelectedPoints( std::vector< wxPoint >& aPoints ) const;
208 
209  bool CanConnect( const SCH_ITEM* aItem ) const override;
210 
211  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
212 
213  BITMAPS GetMenuImage() const override;
214 
215  bool operator <( const SCH_ITEM& aItem ) const override;
216 
217  wxPoint GetPosition() const override { return m_start; }
218  void SetPosition( const wxPoint& aPosition ) override;
219 
220  bool IsPointClickableAnchor( const wxPoint& aPos ) const override
221  {
222  return ( GetStartPoint() == aPos && IsStartDangling() )
223  || ( GetEndPoint() == aPos && IsEndDangling() );
224  }
225 
226  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
227  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
228 
229  void Plot( PLOTTER* aPlotter ) const override;
230 
231  EDA_ITEM* Clone() const override;
232 
233  void SwapData( SCH_ITEM* aItem ) override;
234 
235  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
236 
237 #if defined(DEBUG)
238  void Show( int nestLevel, std::ostream& os ) const override;
239 #endif
240 
246  bool IsGraphicLine() const;
247 
253  bool IsWire() const;
254 
260  bool IsBus() const;
261 
262 private:
263  bool doIsConnected( const wxPoint& aPosition ) const override;
264 
267  wxPoint m_start;
268  wxPoint m_end;
270 };
271 
272 
273 #endif // _SCH_LINE_H_
int GetReverseAngleFrom(const wxPoint &aPoint) const
Definition: sch_line.cpp:427
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:571
static const char * GetLineStyleName(PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:85
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:453
COLOR4D GetLineColor() const
Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
Definition: sch_line.cpp:210
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:916
bool IsStrokeEquivalent(const SCH_LINE *aLine)
Definition: sch_line.h:127
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_line.cpp:746
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:922
bool m_endIsDangling
True if end point is not connected.
Definition: sch_line.h:266
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_line.cpp:381
virtual bool HasLineStroke() const override
Check if this schematic item has line stoke properties.
Definition: sch_line.h:123
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:271
void MoveStart(const wxPoint &aMoveVector)
Definition: sch_line.cpp:121
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:875
void Rotate(wxPoint aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_line.cpp:395
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_line.cpp:652
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:158
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:709
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:780
bool UsesDefaultStroke() const
Test if the SCH_LINE object uses the default stroke settings.
Definition: sch_line.cpp:933
void Move(const wxPoint &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_line.cpp:110
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:94
bool IsConnectable() const override
Definition: sch_line.cpp:643
void RotateStart(wxPoint aCenter)
Definition: sch_line.cpp:402
PLOT_DASH_TYPE GetDefaultStyle() const
Definition: sch_line.cpp:224
int GetAngleFrom(const wxPoint &aPoint) const
Definition: sch_line.cpp:414
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:239
SCH_LAYER_ID m_layer
Definition: sch_item.h:496
PLOT_DASH_TYPE GetLineStyle() const
Definition: sch_line.cpp:248
bool IsNull() const
Definition: sch_line.h:88
bool IsEndDangling() const
Definition: sch_line.h:200
double GetLength() const
Definition: sch_line.cpp:183
void SetStartPoint(const wxPoint &aPosition)
Definition: sch_line.h:91
bool m_startIsDangling
True if start point is not connected.
Definition: sch_line.h:265
int GetPenWidth() const override
Definition: sch_line.cpp:277
PLOT_DASH_TYPE GetPlotStyle() const
Definition: sch_item.h:170
virtual bool IsType(const KICAD_T aScanTypes[]) const
Check whether the item is one of the listed types.
Definition: eda_item.h:233
bool IsDangling() const override
Definition: sch_line.h:201
~SCH_LINE()
Definition: sch_line.h:50
void SetLineColor(const COLOR4D &aColor)
Definition: sch_line.cpp:189
bool IsEndPoint(const wxPoint &aPoint) const
Definition: sch_line.h:80
int GetWidth() const
Definition: sch_item.h:167
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:826
void GetSelectedPoints(std::vector< wxPoint > &aPoints) const
Definition: sch_line.cpp:699
void Plot(PLOTTER *aPlotter) const override
Plot the schematic item to aPlotter.
Definition: sch_line.cpp:835
static PLOT_DASH_TYPE GetLineStyleByName(const wxString &aStyleName)
Definition: sch_line.cpp:95
wxPoint m_end
Line end point.
Definition: sch_line.h:268
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_line.cpp:812
STROKE_PARAMS m_stroke
Line stroke properties.
Definition: sch_line.h:269
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:173
int GetLineSize() const
Definition: sch_line.h:152
void RotateEnd(wxPoint aCenter)
Definition: sch_line.cpp:408
virtual void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: sch_line.h:125
PLOT_DASH_TYPE GetEffectiveLineStyle() const
Definition: sch_line.cpp:257
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:68
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
void MoveEnd(const wxPoint &aMoveVector)
Definition: sch_line.cpp:131
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_line.cpp:757
Simple container to manage line stroke parameters.
Definition: sch_item.h:155
wxPoint GetPosition() const override
Definition: sch_line.h:217
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_line.cpp:319
bool IsStartDangling() const
Definition: sch_line.h:199
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_line.cpp:388
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:150
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_line.h:124
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:599
bool IsParallel(const SCH_LINE *aLine) const
Definition: sch_line.cpp:440
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_line.cpp:166
bool IsPointClickableAnchor(const wxPoint &aPos) const override
Definition: sch_line.h:220
void SetPosition(const wxPoint &aPosition) override
Definition: sch_line.cpp:868
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:197
wxPoint m_start
Line start point.
Definition: sch_line.h:267
bool IsBus() const
Return true if the line is a bus.
Definition: sch_line.cpp:927
SCH_LINE(const wxPoint &pos=wxPoint(0, 0), int layer=LAYER_NOTES)
Definition: sch_line.cpp:38
std::vector< wxPoint > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_line.cpp:693
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:163
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:44
wxPoint GetEndPoint() const
Definition: sch_line.h:93