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 
31 
32 
37 class SCH_LINE : public SCH_ITEM
38 {
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 
138  bool UsesDefaultStroke() const;
139 
140  int GetLineSize() const { return m_stroke.GetWidth(); }
141 
142  void ViewGetLayers( int aLayers[], int& aCount ) const override;
143 
144  const EDA_RECT GetBoundingBox() const override;
145 
149  double GetLength() const;
150 
151  void Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override;
152 
153  int GetPenWidth() const override;
154 
155  void Move( const wxPoint& aMoveVector ) override;
156  void MoveStart( const wxPoint& aMoveVector );
157  void MoveEnd( const wxPoint& aMoveVector );
158 
159  void MirrorX( int aXaxis_position ) override;
160  void MirrorY( int aYaxis_position ) override;
161  void Rotate( wxPoint aPosition ) override;
162  void RotateStart( wxPoint aPosition );
163  void RotateEnd( wxPoint aPosition );
164 
175  SCH_LINE* MergeOverlap( SCH_LINE* aLine );
176 
185  bool IsSameQuadrant( SCH_LINE* aLine, const wxPoint& aPosition );
186 
187  bool IsParallel( SCH_LINE* aLine );
188 
189  void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override;
190 
191  bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
192  const SCH_SHEET_PATH* aPath = nullptr ) override;
193 
194  bool IsStartDangling() const { return m_startIsDangling; }
195  bool IsEndDangling() const { return m_endIsDangling; }
196  bool IsDangling() const override { return m_startIsDangling || m_endIsDangling; }
197 
198  bool IsConnectable() const override;
199 
200  void GetConnectionPoints( std::vector< wxPoint >& aPoints ) const override;
201 
202  void GetSelectedPoints( std::vector< wxPoint >& aPoints ) const;
203 
204  bool CanConnect( const SCH_ITEM* aItem ) const override;
205 
206  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
207 
208  BITMAP_DEF GetMenuImage() const override;
209 
210  void GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems, SCH_SHEET_PATH* aSheetPath ) override;
211 
212  bool operator <( const SCH_ITEM& aItem ) const override;
213 
214  wxPoint GetPosition() const override { return m_start; }
215  void SetPosition( const wxPoint& aPosition ) override;
216 
217  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
218  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
219 
220  void Plot( PLOTTER* aPlotter ) override;
221 
222  EDA_ITEM* Clone() const override;
223 
224  void SwapData( SCH_ITEM* aItem ) override;
225 
226  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
227 
228 #if defined(DEBUG)
229  void Show( int nestLevel, std::ostream& os ) const override;
230 #endif
231 
237  bool IsGraphicLine() const;
238 
244  bool IsWire() const;
245 
246 private:
247  bool doIsConnected( const wxPoint& aPosition ) const override;
248 };
249 
250 
251 #endif // _SCH_LINE_H_
void Rotate(wxPoint aPosition) override
Rotate the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_line.cpp:343
void GetConnectionPoints(std::vector< wxPoint > &aPoints) const override
Add all the connection points for this item to aPoints.
Definition: sch_line.cpp:599
EDA_UNITS
Definition: common.h:198
SCH_LINE * MergeOverlap(SCH_LINE *aLine)
Check line against aLine to see if it overlaps and merge if it does.
Definition: sch_line.cpp:398
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:511
static const char * GetLineStyleName(PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:84
SCH_LAYER_ID m_Layer
Definition: sch_item.h:199
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
Function GetClass returns 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:838
PNG memory record (file in memory).
Definition: bitmap_def.h:29
wxPoint GetStartPoint() const
Definition: sch_line.h:94
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
bool IsWire() const
Returns true if the line is a wire.
Definition: sch_line.cpp:844
bool m_endIsDangling
True if end point is not connected.
Definition: sch_line.h:40
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:264
void RotateEnd(wxPoint aPosition)
Definition: sch_line.cpp:356
void MoveStart(const wxPoint &aMoveVector)
Definition: sch_line.cpp:120
bool IsParallel(SCH_LINE *aLine)
Definition: sch_line.cpp:385
void Plot(PLOTTER *aPlotter) override
Plot the schematic item to aPlotter.
Definition: sch_line.cpp:757
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
Definition: sch_line.cpp:797
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_line.cpp:578
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
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_line.cpp:616
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: sch_line.cpp:703
void RotateStart(wxPoint aPosition)
Definition: sch_line.cpp:350
bool UsesDefaultStroke() const
Test if the SCH_LINE object uses the default stroke settings.
Definition: sch_line.cpp:850
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
NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected items in a...
bool IsConnectable() const override
Definition: sch_line.cpp:569
PLOT_DASH_TYPE GetDefaultStyle() const
Definition: sch_line.cpp:220
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:235
void MirrorX(int aXaxis_position) override
Mirror item relative to the X axis about aXaxis_position.
Definition: sch_line.cpp:329
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_line.cpp:642
PLOT_DASH_TYPE GetLineStyle() const
Definition: sch_line.cpp:244
bool IsNull() const
Definition: sch_line.h:92
bool IsEndDangling() const
Definition: sch_line.h:195
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:270
virtual bool IsType(const KICAD_T aScanTypes[]) const
Function IsType Checks whether the item is one of the listed types.
Definition: base_struct.h:262
bool IsDangling() const override
Definition: sch_line.h:196
~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:169
SCH_SHEET_PATH.
bool doIsConnected(const wxPoint &aPosition) const override
Provide the object specific test to see if it is connected to aPosition.
Definition: sch_line.cpp:748
void GetSelectedPoints(std::vector< wxPoint > &aPoints) const
Definition: sch_line.cpp:606
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:734
STROKE_PARAMS m_stroke
Line stroke properties.
Definition: sch_line.h:43
PLOT_DASH_TYPE
Enum for choosing dashed line type.
Definition: plotter.h:87
bool IsSameQuadrant(SCH_LINE *aLine, const wxPoint &aPosition)
Check if two lines are in the same quadrant as each other, using a reference point as the origin.
Definition: sch_line.cpp:362
Base plotter engine class.
Definition: plotter.h:114
int GetLineSize() const
Definition: sch_line.h:140
virtual void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: sch_line.h:129
PLOT_DASH_TYPE GetEffectiveLineStyle() const
Definition: sch_line.cpp:253
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
Function Clone creates 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:680
Simple container to manage line stroke parameters.
Definition: sch_item.h:153
wxPoint GetPosition() const override
Definition: sch_line.h:214
bool IsStartDangling() const
Definition: sch_line.h:194
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_line.h:128
void Print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_line.cpp:312
void MirrorY(int aYaxis_position) override
Mirror item relative to the Y axis about aYaxis_position.
Definition: sch_line.cpp:336
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:529
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_line.cpp:165
void SetPosition(const wxPoint &aPosition) override
Set the schematic item position to aPosition.
Definition: sch_line.cpp:790
bool IsType(const KICAD_T aScanTypes[]) const override
Function IsType Checks 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:194
wxPoint m_start
Line start point.
Definition: sch_line.h:41
SCH_LINE(const wxPoint &pos=wxPoint(0, 0), int layer=LAYER_NOTES)
Definition: sch_line.cpp:37
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
void GetNetListItem(NETLIST_OBJECT_LIST &aNetListItems, SCH_SHEET_PATH *aSheetPath) override
Create a new NETLIST_OBJECT for the schematic object and adds it to aNetListItems.
Definition: sch_line.cpp:653
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99
SCH_LINE(const VECTOR2D &pos, int layer=LAYER_NOTES)
Definition: sch_line.h:51
wxPoint GetEndPoint() const
Definition: sch_line.h:97