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-2019 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 {
41  wxPoint m_start;
42  wxPoint m_end;
43  int m_size;
44  int m_style;
46 
47 public:
48 
49  static const enum wxPenStyle PenStyle[];
50 
51  SCH_LINE( const wxPoint& pos = wxPoint( 0, 0 ), int layer = LAYER_NOTES );
52 
53  SCH_LINE( const SCH_LINE& aLine );
54 
55  ~SCH_LINE() { }
56 
57  SCH_LINE* Next() const { return (SCH_LINE*) Pnext; }
58  SCH_LINE* Back() const { return (SCH_LINE*) Pback; }
59 
60  static inline bool ClassOf( const EDA_ITEM* aItem )
61  {
62  return aItem && SCH_LINE_T == aItem->Type();
63  }
64 
65  wxString GetClass() const override
66  {
67  return wxT( "SCH_LINE" );
68  }
69 
70  bool IsType( const KICAD_T aScanTypes[] ) override
71  {
72  if( SCH_ITEM::IsType( aScanTypes ) )
73  return true;
74 
75  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
76  {
77  if( *p == SCH_LINE_LOCATE_WIRE_T && m_Layer == LAYER_WIRE )
78  return true;
79  else if ( *p == SCH_LINE_LOCATE_BUS_T && m_Layer == LAYER_BUS )
80  return true;
81  else if ( *p == SCH_LINE_LOCATE_GRAPHIC_LINE_T && m_Layer == LAYER_NOTES )
82  return true;
83  }
84 
85  return false;
86  }
87 
88  bool IsEndPoint( const wxPoint& aPoint ) const
89  {
90  return aPoint == m_start || aPoint == m_end;
91  }
92 
93  bool IsNull() const { return m_start == m_end; }
94 
95  wxPoint GetStartPoint() const { return m_start; }
96  void SetStartPoint( const wxPoint& aPosition ) { m_start = aPosition; }
97 
98  wxPoint GetEndPoint() const { return m_end; }
99  void SetEndPoint( const wxPoint& aPosition ) { m_end = aPosition; }
100 
101  int GetDefaultStyle() const;
102 
103  void SetLineStyle( const int aStyle );
104  int GetLineStyle() const;
105 
108  static const char* GetLineStyleName( int aStyle );
109 
112  static int GetLineStyleInternalId( 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 
118  COLOR4D GetLineColor() const;
119 
120  COLOR4D GetDefaultColor() const;
121 
122  int GetDefaultWidth() const;
123 
124  void SetLineWidth( const int aSize );
125 
126  int GetLineSize() const { return m_size; }
127 
128  void ViewGetLayers( int aLayers[], int& aCount ) const override;
129 
130  const EDA_RECT GetBoundingBox() const override;
131 
136  double GetLength() const;
137 
138  void Print( wxDC* aDC, const wxPoint& aOffset ) override;
139 
140  int GetPenSize() const override;
141 
142  void Move( const wxPoint& aMoveVector ) override;
143  void MoveStart( const wxPoint& aMoveVector );
144  void MoveEnd( const wxPoint& aMoveVector );
145 
146  void MirrorX( int aXaxis_position ) override;
147  void MirrorY( int aYaxis_position ) override;
148  void Rotate( wxPoint aPosition ) override;
149  void RotateStart( wxPoint aPosition );
150  void RotateEnd( wxPoint aPosition );
151 
162  EDA_ITEM* MergeOverlap( SCH_LINE* aLine );
163 
172  bool IsSameQuadrant( SCH_LINE* aLine, const wxPoint& aPosition );
173 
174  bool IsParallel( SCH_LINE* aLine );
175 
176  void GetEndPoints( std::vector<DANGLING_END_ITEM>& aItemList ) override;
177 
178  bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList ) override;
179 
180  bool IsStartDangling() const { return m_startIsDangling; }
181  bool IsEndDangling() const { return m_endIsDangling; }
182  bool IsDangling() const override { return m_startIsDangling || m_endIsDangling; }
183 
184  bool IsConnectable() const override;
185 
186  void GetConnectionPoints( std::vector< wxPoint >& aPoints ) const override;
187 
188  void GetSelectedPoints( std::vector< wxPoint >& aPoints ) const;
189 
190  bool CanConnect( const SCH_ITEM* aItem ) const override;
191 
192  wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
193 
194  BITMAP_DEF GetMenuImage() const override;
195 
196  void GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems, SCH_SHEET_PATH* aSheetPath ) override;
197 
198  bool operator <( const SCH_ITEM& aItem ) const override;
199 
200  wxPoint GetPosition() const override { return m_start; }
201  void SetPosition( const wxPoint& aPosition ) override;
202 
203  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
204  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
205 
206  void Plot( PLOTTER* aPlotter ) override;
207 
208  EDA_ITEM* Clone() const override;
209 
210  void SwapData( SCH_ITEM* aItem ) override;
211 
212  void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override;
213 
214 #if defined(DEBUG)
215  void Show( int nestLevel, std::ostream& os ) const override;
216 #endif
217 
218 private:
219  bool doIsConnected( const wxPoint& aPosition ) const override;
220 };
221 
222 
223 #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:353
bool UpdateDanglingState(std::vector< DANGLING_END_ITEM > &aItemList) override
Function IsDanglingStateChanged tests the schematic item to aItemList to check if it's dangling state...
Definition: sch_line.cpp:539
void GetConnectionPoints(std::vector< wxPoint > &aPoints) const override
Function GetConnectionPoints add all the connection points for this item to aPoints.
Definition: sch_line.cpp:608
int m_style
Line style.
Definition: sch_line.h:44
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:521
SCH_LAYER_ID m_Layer
Definition: sch_item.h:119
COLOR4D GetLineColor() const
Definition: sch_line.cpp:263
EDA_ITEM * Pback
previous in linked list
Definition: base_struct.h:177
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_line.h:65
bool IsType(const KICAD_T aScanTypes[]) override
Function IsType Checks whether the item is one of the listed types.
Definition: sch_line.h:70
void Print(wxDC *aDC, const wxPoint &aOffset) override
Function Print Print a schematic item.
Definition: sch_line.cpp:327
wxPoint GetStartPoint() const
Definition: sch_line.h:95
bool m_endIsDangling
True if end point is not connected.
Definition: sch_line.h:40
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:309
void RotateEnd(wxPoint aPosition)
Definition: sch_line.cpp:366
void MoveStart(const wxPoint &aMoveVector)
Definition: sch_line.cpp:165
bool IsParallel(SCH_LINE *aLine)
Definition: sch_line.cpp:395
void Plot(PLOTTER *aPlotter) override
Function Plot plots the schematic item to aPlotter.
Definition: sch_line.cpp:765
virtual bool IsType(const KICAD_T aScanTypes[])
Function IsType Checks whether the item is one of the listed types.
Definition: base_struct.h:294
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_line.cpp:587
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_line.h:60
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:202
int GetDefaultWidth() const
Definition: sch_line.cpp:298
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:709
void RotateStart(wxPoint aPosition)
Definition: sch_line.cpp:360
void Move(const wxPoint &aMoveVector) override
Function Move moves the item by aMoveVector to a new position.
Definition: sch_line.cpp:154
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:99
Class NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected item...
void GetMsgPanelInfo(EDA_UNITS_T 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:790
void SetLineColor(const COLOR4D aColor)
Definition: sch_line.cpp:239
bool IsConnectable() const override
Function IsConnectable returns true if the schematic item can connect to another schematic item.
Definition: sch_line.cpp:578
SCH_LINE * Next() const
Definition: sch_line.h:57
void SetLineStyle(const int aStyle)
Definition: sch_line.cpp:280
void MirrorX(int aXaxis_position) override
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
Definition: sch_line.cpp:339
COLOR4D m_color
Line color.
Definition: sch_line.h:45
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_line.cpp:651
bool IsNull() const
Definition: sch_line.h:93
bool IsEndDangling() const
Definition: sch_line.h:181
double GetLength() const
Function GetLength.
Definition: sch_line.cpp:227
void SetStartPoint(const wxPoint &aPosition)
Definition: sch_line.h:96
bool m_startIsDangling
True if start point is not connected.
Definition: sch_line.h:39
bool IsDangling() const override
Definition: sch_line.h:182
~SCH_LINE()
Definition: sch_line.h:55
bool IsEndPoint(const wxPoint &aPoint) const
Definition: sch_line.h:88
Class SCH_SHEET_PATH.
int GetDefaultStyle() const
Definition: sch_line.cpp:271
static int GetLineStyleInternalId(const wxString &aStyleName)
Definition: sch_line.cpp:137
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:756
void GetSelectedPoints(std::vector< wxPoint > &aPoints) const
Definition: sch_line.cpp:615
wxPoint m_end
Line end point.
Definition: sch_line.h:42
void SwapData(SCH_ITEM *aItem) override
Function SwapData swap the internal data structures aItem with the schematic item.
Definition: sch_line.cpp:740
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:372
int m_size
Line pensize.
Definition: sch_line.h:43
Base plotter engine class.
Definition: plotter.h:97
int GetLineSize() const
Definition: sch_line.h:126
EDA_ITEM * MergeOverlap(SCH_LINE *aLine)
Check line against aLine to see if it overlaps and merge if it does.
Definition: sch_line.cpp:408
SCH_LINE * Back() const
Definition: sch_line.h:58
static enum wxPenStyle PenStyle[]
Definition: sch_line.h:49
COLOR4D GetDefaultColor() const
Definition: sch_line.cpp:233
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:99
void MoveEnd(const wxPoint &aMoveVector)
Definition: sch_line.cpp:175
bool operator<(const SCH_ITEM &aItem) const override
Definition: sch_line.cpp:689
static const char * GetLineStyleName(int aStyle)
Definition: sch_line.cpp:109
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_line.h:200
bool IsStartDangling() const
Definition: sch_line.h:180
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
void MirrorY(int aYaxis_position) override
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
Definition: sch_line.cpp:346
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_line.cpp:318
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_line.cpp:210
wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_line.cpp:625
void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
Definition: sch_line.cpp:783
int GetLineStyle() const
Definition: sch_line.cpp:289
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
wxPoint m_start
Line start point.
Definition: sch_line.h:41
EDA_ITEM * Pnext
next in linked list
Definition: base_struct.h:176
EDA_UNITS_T
Definition: common.h:133
SCH_LINE(const wxPoint &pos=wxPoint(0, 0), int layer=LAYER_NOTES)
Definition: sch_line.cpp:59
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210
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:662
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
wxPoint GetEndPoint() const
Definition: sch_line.h:98