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 <plotter.h>
29 #include <sch_item.h>
30 
32 
33 
38 class SCH_LINE : public SCH_ITEM
39 {
44  int m_size;
47 
48 public:
49 
50  static const enum wxPenStyle PenStyle[];
51 
52  SCH_LINE( const wxPoint& pos = wxPoint( 0, 0 ), int layer = LAYER_NOTES );
53 
54  SCH_LINE( const VECTOR2D& pos, int layer = LAYER_NOTES ) :
55  SCH_LINE( wxPoint( pos.x, pos.y ), layer )
56  {}
57 
58  SCH_LINE( const SCH_LINE& aLine );
59 
60  ~SCH_LINE() { }
61 
62  static inline bool ClassOf( const EDA_ITEM* aItem )
63  {
64  return aItem && SCH_LINE_T == aItem->Type();
65  }
66 
67  wxString GetClass() const override
68  {
69  return wxT( "SCH_LINE" );
70  }
71 
72  bool IsType( const KICAD_T aScanTypes[] ) const override
73  {
74  if( SCH_ITEM::IsType( aScanTypes ) )
75  return true;
76 
77  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
78  {
79  if( *p == SCH_LINE_LOCATE_WIRE_T && m_Layer == LAYER_WIRE )
80  return true;
81  else if ( *p == SCH_LINE_LOCATE_BUS_T && m_Layer == LAYER_BUS )
82  return true;
83  else if ( *p == SCH_LINE_LOCATE_GRAPHIC_LINE_T && m_Layer == LAYER_NOTES )
84  return true;
85  }
86 
87  return false;
88  }
89 
90  bool IsEndPoint( const wxPoint& aPoint ) const
91  {
92  return aPoint == m_start || aPoint == m_end;
93  }
94 
95  bool IsNull() const { return m_start == m_end; }
96 
97  wxPoint GetStartPoint() const { return m_start; }
98  void SetStartPoint( const wxPoint& aPosition ) { m_start = aPosition; }
99 
100  wxPoint GetEndPoint() const { return m_end; }
101  void SetEndPoint( const wxPoint& aPosition ) { m_end = aPosition; }
102 
104 
105  void SetLineStyle( const PLOT_DASH_TYPE aStyle );
106  void SetLineStyle( const int aStyleId );
108 
111  static const char* GetLineStyleName( PLOT_DASH_TYPE aStyle );
112 
115  static PLOT_DASH_TYPE GetLineStyleByName( const wxString& aStyleName );
116 
117  void SetLineColor( const COLOR4D aColor );
118 
119  void SetLineColor( const double r, const double g, const double b, const double a );
120 
122  COLOR4D GetLineColor() const;
123 
124  int GetDefaultWidth() const;
125 
126  void SetLineWidth( const int aSize );
127 
135  bool UsesDefaultStroke() const;
136 
137  int GetLineSize() const { return m_size; }
138 
139  void ViewGetLayers( int aLayers[], int& aCount ) const override;
140 
141  const EDA_RECT GetBoundingBox() const override;
142 
146  double GetLength() const;
147 
148  void Print( wxDC* aDC, const wxPoint& aOffset ) override;
149 
150  int GetPenSize() const override;
151 
152  void Move( const wxPoint& aMoveVector ) override;
153  void MoveStart( const wxPoint& aMoveVector );
154  void MoveEnd( const wxPoint& aMoveVector );
155 
156  void MirrorX( int aXaxis_position ) override;
157  void MirrorY( int aYaxis_position ) override;
158  void Rotate( wxPoint aPosition ) override;
159  void RotateStart( wxPoint aPosition );
160  void RotateEnd( wxPoint aPosition );
161 
172  SCH_LINE* MergeOverlap( SCH_LINE* aLine );
173 
182  bool IsSameQuadrant( SCH_LINE* aLine, const wxPoint& aPosition );
183 
184  bool IsParallel( SCH_LINE* aLine );
185 
186  void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override;
187 
188  bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
189  const SCH_SHEET_PATH* aPath = nullptr ) override;
190 
191  bool IsStartDangling() const { return m_startIsDangling; }
192  bool IsEndDangling() const { return m_endIsDangling; }
193  bool IsDangling() const override { return m_startIsDangling || m_endIsDangling; }
194 
195  bool IsConnectable() const override;
196 
197  void GetConnectionPoints( std::vector< wxPoint >& aPoints ) const override;
198 
199  void GetSelectedPoints( std::vector< wxPoint >& aPoints ) const;
200 
201  bool CanConnect( const SCH_ITEM* aItem ) const override;
202 
203  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
204 
205  BITMAP_DEF GetMenuImage() const override;
206 
207  void GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems, SCH_SHEET_PATH* aSheetPath ) override;
208 
209  bool operator <( const SCH_ITEM& aItem ) const override;
210 
211  wxPoint GetPosition() const override { return m_start; }
212  void SetPosition( const wxPoint& aPosition ) override;
213 
214  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
215  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
216 
217  void Plot( PLOTTER* aPlotter ) override;
218 
219  EDA_ITEM* Clone() const override;
220 
221  void SwapData( SCH_ITEM* aItem ) override;
222 
223  void GetMsgPanelInfo( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList ) override;
224 
225 #if defined(DEBUG)
226  void Show( int nestLevel, std::ostream& os ) const override;
227 #endif
228 
234  bool IsGraphicLine() const;
235 
236 private:
237  bool doIsConnected( const wxPoint& aPosition ) const override;
238 };
239 
240 
241 #endif // _SCH_LINE_H_
void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_line.cpp:341
void GetConnectionPoints(std::vector< wxPoint > &aPoints) const override
Function GetConnectionPoints add all the connection points for this item to aPoints.
Definition: sch_line.cpp:597
EDA_UNITS
Definition: common.h:184
SCH_LINE * MergeOverlap(SCH_LINE *aLine)
Check line against aLine to see if it overlaps and merge if it does.
Definition: sch_line.cpp:396
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Function GetEndPoints adds the schematic item end points to aItemList if the item has end points.
Definition: sch_line.cpp:509
static const char * GetLineStyleName(PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:122
SCH_LAYER_ID m_Layer
Definition: sch_item.h:152
COLOR4D GetLineColor() const
Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
Definition: sch_line.cpp:247
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_line.h:67
bool IsGraphicLine() const
Returns if the line is a graphic (non electrical line)
Definition: sch_line.cpp:809
PNG memory record (file in memory).
Definition: bitmap_def.h:29
void Print(wxDC *aDC, const wxPoint &aOffset) override
Function Print Print a schematic item.
Definition: sch_line.cpp:315
wxPoint GetStartPoint() const
Definition: sch_line.h:97
PLOT_DASH_TYPE m_style
Line style.
Definition: sch_line.h:45
bool m_endIsDangling
True if end point is not connected.
Definition: sch_line.h:41
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:297
void RotateEnd(wxPoint aPosition)
Definition: sch_line.cpp:354
void MoveStart(const wxPoint &aMoveVector)
Definition: sch_line.cpp:158
bool IsParallel(SCH_LINE *aLine)
Definition: sch_line.cpp:383
void Plot(PLOTTER *aPlotter) override
Function Plot plots the schematic item to aPlotter.
Definition: sch_line.cpp:757
void GetMsgPanelInfo(EDA_UNITS aUnits, 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:782
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_line.cpp:576
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_line.h:62
void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers returns the layers the item is drawn on (which may be more than its "home" lay...
Definition: sch_line.cpp:195
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:614
int GetDefaultWidth() const
Definition: sch_line.cpp:286
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:701
void RotateStart(wxPoint aPosition)
Definition: sch_line.cpp:348
bool UsesDefaultStroke() const
Test if the SCH_LINE object uses the default stroke settings.
Definition: sch_line.cpp:815
void Move(const wxPoint &aMoveVector) override
Function Move moves the item by aMoveVector to a new position.
Definition: sch_line.cpp:147
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:101
NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected items in a...
void SetLineColor(const COLOR4D aColor)
Definition: sch_line.cpp:226
bool IsConnectable() const override
Function IsConnectable returns true if the schematic item can connect to another schematic item.
Definition: sch_line.cpp:567
PLOT_DASH_TYPE GetDefaultStyle() const
Definition: sch_line.cpp:253
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:268
void MirrorX(int aXaxis_position) override
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
Definition: sch_line.cpp:327
COLOR4D m_color
Line color.
Definition: sch_line.h:46
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_line.cpp:640
PLOT_DASH_TYPE GetLineStyle() const
Definition: sch_line.cpp:277
bool IsNull() const
Definition: sch_line.h:95
bool IsEndDangling() const
Definition: sch_line.h:192
double GetLength() const
Definition: sch_line.cpp:220
void SetStartPoint(const wxPoint &aPosition)
Definition: sch_line.h:98
bool m_startIsDangling
True if start point is not connected.
Definition: sch_line.h:40
virtual bool IsType(const KICAD_T aScanTypes[]) const
Function IsType Checks whether the item is one of the listed types.
Definition: base_struct.h:286
bool IsDangling() const override
Definition: sch_line.h:193
~SCH_LINE()
Definition: sch_line.h:60
bool IsEndPoint(const wxPoint &aPoint) const
Definition: sch_line.h:90
SCH_SHEET_PATH.
bool doIsConnected(const wxPoint &aPosition) const override
Function doIsConnected provides 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:604
static PLOT_DASH_TYPE GetLineStyleByName(const wxString &aStyleName)
Definition: sch_line.cpp:132
wxPoint m_end
Line end point.
Definition: sch_line.h:43
void SwapData(SCH_ITEM *aItem) override
Function SwapData swap the internal data structures aItem with the schematic item.
Definition: sch_line.cpp:732
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:360
int m_size
Line pensize.
Definition: sch_line.h:44
Base plotter engine class.
Definition: plotter.h:104
int GetLineSize() const
Definition: sch_line.h:137
static enum wxPenStyle PenStyle[]
Definition: sch_line.h:50
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:38
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_line.cpp:105
void MoveEnd(const wxPoint &aMoveVector)
Definition: sch_line.cpp:168
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_line.cpp:678
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_line.h:211
bool IsStartDangling() const
Definition: sch_line.h:191
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:166
void MirrorY(int aYaxis_position) override
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
Definition: sch_line.cpp:334
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_line.cpp:306
bool UpdateDanglingState(std::vector< DANGLING_END_ITEM > &aItemList, const SCH_SHEET_PATH *aPath=nullptr) override
Function IsDanglingStateChanged tests the schematic item to aItemList to check if it's dangling state...
Definition: sch_line.cpp:527
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_line.cpp:203
void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
Definition: sch_line.cpp:775
bool IsType(const KICAD_T aScanTypes[]) const override
Function IsType Checks whether the item is one of the listed types.
Definition: sch_line.h:72
SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
wxPoint m_start
Line start point.
Definition: sch_line.h:42
SCH_LINE(const wxPoint &pos=wxPoint(0, 0), int layer=LAYER_NOTES)
Definition: sch_line.cpp:65
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
void GetNetListItem(NETLIST_OBJECT_LIST &aNetListItems, SCH_SHEET_PATH *aSheetPath) override
Function GetNetListItem creates a new NETLIST_OBJECT for the schematic object and adds it to aNetList...
Definition: sch_line.cpp:651
SCH_LINE(const VECTOR2D &pos, int layer=LAYER_NOTES)
Definition: sch_line.h:54
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:40
wxPoint GetEndPoint() const
Definition: sch_line.h:100