KiCad PCB EDA Suite
class_drawsegment.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) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 1992-2017 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 
30 #ifndef CLASS_DRAWSEGMENT_H_
31 #define CLASS_DRAWSEGMENT_H_
32 
33 #include <class_board_item.h>
34 #include <PolyLine.h>
35 #include <math_for_graphics.h>
36 #include <trigo.h>
37 #include <common.h>
38 
39 
40 class LINE_READER;
41 class EDA_DRAW_FRAME;
42 class MODULE;
43 class MSG_PANEL_ITEM;
44 
45 
46 class DRAWSEGMENT : public BOARD_ITEM
47 {
48 protected:
49  int m_Width;
52 
54  int m_Type;
55  double m_Angle;
58 
59  std::vector<wxPoint> m_BezierPoints;
60  std::vector<wxPoint> m_PolyPoints;
61 
62  // Computes the bounding box for an arc
63  void computeArcBBox( EDA_RECT& aBBox ) const;
64 
65 public:
66  DRAWSEGMENT( BOARD_ITEM* aParent = NULL, KICAD_T idtype = PCB_LINE_T );
67 
68  // Do not create a copy constructor & operator=.
69  // The ones generated by the compiler are adequate.
70 
71  ~DRAWSEGMENT();
72 
73  static inline bool ClassOf( const EDA_ITEM* aItem )
74  {
75  return aItem && PCB_LINE_T == aItem->Type();
76  }
77 
78  void SetWidth( int aWidth ) { m_Width = aWidth; }
79  int GetWidth() const { return m_Width; }
80 
86  void SetAngle( double aAngle ); // encapsulates the transition to degrees
87  double GetAngle() const { return m_Angle; }
88 
89  void SetType( int aType ) { m_Type = aType; }
90  int GetType() const { return m_Type; }
91 
92  void SetShape( STROKE_T aShape ) { m_Shape = aShape; }
93  STROKE_T GetShape() const { return m_Shape; }
94 
95  void SetBezControl1( const wxPoint& aPoint ) { m_BezierC1 = aPoint; }
96  const wxPoint& GetBezControl1() const { return m_BezierC1; }
97 
98  void SetBezControl2( const wxPoint& aPoint ) { m_BezierC2 = aPoint; }
99  const wxPoint& GetBezControl2() const { return m_BezierC2; }
100 
101  void SetPosition( const wxPoint& aPos ) override { m_Start = aPos; }
102  const wxPoint& GetPosition() const override { return m_Start; }
103 
108  const wxPoint& GetStart() const { return m_Start; }
109  void SetStart( const wxPoint& aStart ) { m_Start = aStart; }
110  void SetStartY( int y ) { m_Start.y = y; }
111  void SetStartX( int x ) { m_Start.x = x; }
112 
117  const wxPoint& GetEnd() const { return m_End; }
118  void SetEnd( const wxPoint& aEnd ) { m_End = aEnd; }
119  void SetEndY( int y ) { m_End.y = y; }
120  void SetEndX( int x ) { m_End.x = x; }
121 
122  // Some attributes are read only, since they are "calculated" from
123  // m_Start, m_End, and m_Angle.
124  // No Set...() function for these attributes.
125 
126  const wxPoint GetCenter() const override;
127  const wxPoint& GetArcStart() const { return m_End; }
128  const wxPoint GetArcEnd() const;
129 
134  double GetArcAngleStart() const;
135 
141  int GetRadius() const
142  {
143  double radius = GetLineLength( m_Start, m_End );
144  return KiROUND( radius );
145  }
146 
151  void SetArcStart( const wxPoint& aArcStartPoint )
152  { m_End = aArcStartPoint; }
153 
156  void SetCenter( const wxPoint& aCenterPoint ) { m_Start = aCenterPoint; }
157 
164  MODULE* GetParentModule() const;
165 
166  // Accessors:
167  const std::vector<wxPoint>& GetBezierPoints() const { return m_BezierPoints; }
168  const std::vector<wxPoint>& GetPolyPoints() const { return m_PolyPoints; }
169  // same accessor, to add/change corners of the polygon
170  std::vector<wxPoint>& GetPolyPoints() { return m_PolyPoints; }
171 
172  void SetBezierPoints( const std::vector<wxPoint>& aPoints )
173  {
174  m_BezierPoints = aPoints;
175  }
176 
177  void SetPolyPoints( const std::vector<wxPoint>& aPoints )
178  {
179  m_PolyPoints = aPoints;
180  }
181 
182  void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
183  GR_DRAWMODE aDrawMode, const wxPoint& aOffset = ZeroOffset ) override;
184 
185  virtual void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
186 
187  virtual const EDA_RECT GetBoundingBox() const override;
188 
189  virtual bool HitTest( const wxPoint& aPosition ) const override;
190 
191  bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const override;
192 
193  wxString GetClass() const override
194  {
195  return wxT( "DRAWSEGMENT" );
196  }
197 
203  double GetLength() const
204  {
205  return GetLineLength( GetStart(), GetEnd() );
206  }
207 
208  virtual void Move( const wxPoint& aMoveVector ) override
209  {
210  m_Start += aMoveVector;
211  m_End += aMoveVector;
212  }
213 
214  virtual void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
215 
216  virtual void Flip( const wxPoint& aCentre ) override;
217 
231  int aClearanceValue,
232  int aCircleToSegmentsCount,
233  double aCorrectionFactor ) const;
234 
235  virtual wxString GetSelectMenuText() const override;
236 
237  virtual BITMAP_DEF GetMenuImage() const override;
238 
239  virtual EDA_ITEM* Clone() const override;
240 
241  virtual const BOX2I ViewBBox() const override;
242 
243 #if defined(DEBUG)
244  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
245 #endif
246 };
247 
248 #endif // CLASS_DRAWSEGMENT_H_
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
virtual void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
virtual const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers. ...
double GetLength() const
Function GetLength returns the length of the track using the hypotenuse calculation.
void SetShape(STROKE_T aShape)
const wxPoint & GetBezControl2() const
double GetLineLength(const wxPoint &aPointA, const wxPoint &aPointB)
Function GetLineLength returns the length of a line segment defined by aPointA and aPointB...
Definition: trigo.h:183
void SetBezierPoints(const std::vector< wxPoint > &aPoints)
virtual void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
PNG memory record (file in memory).
Definition: bitmap_types.h:38
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
void SetArcStart(const wxPoint &aArcStartPoint)
Initialize the start arc point.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
void SetType(int aType)
const wxPoint GetCenter() const override
Function GetCenter()
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
void SetStartY(int y)
virtual BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
virtual bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
double GetArcAngleStart() const
function GetArcAngleStart()
const std::vector< wxPoint > & GetPolyPoints() const
void SetPosition(const wxPoint &aPos) override
double m_Angle
Used only for Arcs: Arc angle in 1/10 deg.
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:53
void SetCenter(const wxPoint &aCenterPoint)
For arcs and circles:
void SetBezControl2(const wxPoint &aPoint)
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:90
static wxPoint ZeroOffset
A value of wxPoint(0,0) which can be passed to the Draw() functions.
wxPoint m_BezierC1
Bezier Control Point 1.
const wxPoint & GetArcStart() const
virtual EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
STROKE_T GetShape() const
wxPoint m_Start
Line start point or Circle and Arc center.
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
std::vector< wxPoint > & GetPolyPoints()
wxPoint m_End
Line end point or circle and arc start point.
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
Class SHAPE_POLY_SET.
void SetEndY(int y)
STROKE_T
Enum STROKE_T is the set of shapes for segments (graphic segments and tracks) which are often in the ...
STROKE_T m_Shape
Shape: line, Circle, Arc.
const wxPoint & GetBezControl1() const
int GetType() const
void computeArcBBox(EDA_RECT &aBBox) const
virtual void Move(const wxPoint &aMoveVector) override
Function Move move this object.
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aCircleToSegmentsCount, double aCorrectionFactor) const
Function TransformShapeWithClearanceToPolygon Convert the track shape to a closed polygon Used in fil...
void SetStart(const wxPoint &aStart)
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
const std::vector< wxPoint > & GetBezierPoints() const
virtual void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
double GetAngle() const
int m_Type
Used in complex associations ( Dimensions.. )
const wxPoint GetArcEnd() const
wxString GetClass() const override
Function GetClass returns the class name.
Class EDA_RECT handles the component boundary box.
wxPoint m_BezierC2
Bezier Control Point 2.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
The common library.
int GetWidth() const
static bool ClassOf(const EDA_ITEM *aItem)
void SetEndX(int x)
void SetEnd(const wxPoint &aEnd)
void SetAngle(double aAngle)
Function SetAngle sets the angle for arcs, and normalizes it within the range 0 - 360 degrees...
MODULE * GetParentModule() const
Function GetParentModule returns a pointer to the parent module, or NULL if DRAWSEGMENT does not belo...
void SetStartX(int x)
int m_Width
thickness of lines ...
DRAWSEGMENT(BOARD_ITEM *aParent=NULL, KICAD_T idtype=PCB_LINE_T)
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
std::vector< wxPoint > m_PolyPoints
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw BOARD_ITEMs have their own color information.
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:103
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
int GetRadius() const
Function GetRadius returns the radius of this item Has meaning only for arc and circle.
virtual wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
const wxPoint & GetPosition() const override
void SetBezControl1(const wxPoint &aPoint)
std::vector< wxPoint > m_BezierPoints
virtual const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
void SetWidth(int aWidth)