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) 2018 Jean-Pierre Charras jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2018 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 <math_for_graphics.h>
35 #include <trigo.h>
36 #include <common.h>
37 
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;
50  wxPoint m_Start;
51  wxPoint m_End;
52 
54  int m_Type;
55  double m_Angle;
56  wxPoint m_BezierC1;
57  wxPoint m_BezierC2;
58 
59  std::vector<wxPoint> m_BezierPoints;
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 
81  bool IsPolygonFilled() const { return m_Layer != Edge_Cuts; }
82 
83  void SetWidth( int aWidth ) { m_Width = aWidth; }
84  int GetWidth() const { return m_Width; }
85 
91  void SetAngle( double aAngle ); // encapsulates the transition to degrees
92  double GetAngle() const { return m_Angle; }
93 
94  void SetType( int aType ) { m_Type = aType; }
95  int GetType() const { return m_Type; }
96 
97  void SetShape( STROKE_T aShape ) { m_Shape = aShape; }
98  STROKE_T GetShape() const { return m_Shape; }
99 
100  void SetBezControl1( const wxPoint& aPoint ) { m_BezierC1 = aPoint; }
101  const wxPoint& GetBezControl1() const { return m_BezierC1; }
102 
103  void SetBezControl2( const wxPoint& aPoint ) { m_BezierC2 = aPoint; }
104  const wxPoint& GetBezControl2() const { return m_BezierC2; }
105 
106  void SetPosition( const wxPoint& aPos ) override;
107  const wxPoint GetPosition() const override;
108 
113  const wxPoint& GetStart() const { return m_Start; }
114  void SetStart( const wxPoint& aStart ) { m_Start = aStart; }
115  void SetStartY( int y ) { m_Start.y = y; }
116  void SetStartX( int x ) { m_Start.x = x; }
117 
122  const wxPoint& GetEnd() const { return m_End; }
123  void SetEnd( const wxPoint& aEnd ) { m_End = aEnd; }
124  void SetEndY( int y ) { m_End.y = y; }
125  void SetEndX( int x ) { m_End.x = x; }
126 
127  // Some attributes are read only, since they are "calculated" from
128  // m_Start, m_End, and m_Angle.
129  // No Set...() function for these attributes.
130 
131  const wxPoint GetCenter() const override;
132  const wxPoint& GetArcStart() const { return m_End; }
133  const wxPoint GetArcEnd() const;
134 
139  double GetArcAngleStart() const;
140 
146  int GetRadius() const
147  {
148  double radius = GetLineLength( m_Start, m_End );
149  return KiROUND( radius );
150  }
151 
156  void SetArcStart( const wxPoint& aArcStartPoint )
157  { m_End = aArcStartPoint; }
158 
161  void SetCenter( const wxPoint& aCenterPoint ) { m_Start = aCenterPoint; }
162 
169  MODULE* GetParentModule() const;
170 
171  // Accessors:
172  const std::vector<wxPoint>& GetBezierPoints() const { return m_BezierPoints; }
173 
179  const std::vector<wxPoint> BuildPolyPointsList() const;
180 
183  int GetPointCount() const;
184 
185  // Accessors to the polygonal shape
187  const SHAPE_POLY_SET& GetPolyShape() const { return m_Poly; }
188 
192  bool IsPolyShapeValid() const;
193 
194  void SetPolyShape( const SHAPE_POLY_SET& aShape ) { m_Poly = aShape; }
195 
196  void SetBezierPoints( const std::vector<wxPoint>& aPoints )
197  {
198  m_BezierPoints = aPoints;
199  }
200 
209  void RebuildBezierToSegmentsPointsList( int aMinSegLen );
210 
211  void SetPolyPoints( const std::vector<wxPoint>& aPoints );
212 
213  void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
214  GR_DRAWMODE aDrawMode, const wxPoint& aOffset = ZeroOffset ) override;
215 
216  virtual void GetMsgPanelInfo( EDA_UNITS_T aUnits,
217  std::vector< MSG_PANEL_ITEM >& aList ) override;
218 
219  virtual const EDA_RECT GetBoundingBox() const override;
220 
221  virtual bool HitTest( const wxPoint& aPosition ) const override;
222 
223  bool HitTest( const EDA_RECT& aRect, bool aContained = true,
224  int aAccuracy = 0 ) const override;
225 
226  wxString GetClass() const override
227  {
228  return wxT( "DRAWSEGMENT" );
229  }
230 
236  double GetLength() const
237  {
238  return GetLineLength( GetStart(), GetEnd() );
239  }
240 
241  virtual void Move( const wxPoint& aMoveVector ) override;
242 
243  virtual void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
244 
245  virtual void Flip( const wxPoint& aCentre ) override;
246 
262  int aClearanceValue,
263  int aCircleToSegmentsCount,
264  double aCorrectionFactor,
265  bool ignoreLineWidth = false ) const override;
266 
267  virtual wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
268 
269  virtual BITMAP_DEF GetMenuImage() const override;
270 
271  virtual EDA_ITEM* Clone() const override;
272 
273  virtual const BOX2I ViewBBox() const override;
274 
275  virtual void SwapData( BOARD_ITEM* aImage ) override;
276 
277 #if defined(DEBUG)
278  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
279 #endif
280 };
281 
282 #endif // CLASS_DRAWSEGMENT_H_
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
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
void SetPolyShape(const SHAPE_POLY_SET &aShape)
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:191
void SetBezierPoints(const std::vector< wxPoint > &aPoints)
const std::vector< wxPoint > BuildPolyPointsList() const
Build and return the list of corners in a std::vector<wxPoint> It must be used only to convert the SH...
PNG memory record (file in memory).
Definition: bitmap_types.h:43
virtual void Move(const wxPoint &aMoveVector) override
Function Move move this object.
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
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)
SHAPE_POLY_SET m_Poly
Stores the S_POLYGON shape.
virtual BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
void RebuildBezierToSegmentsPointsList(int aMinSegLen)
Rebuild the m_BezierPoints vertex list that approximate the Bezier curve by a list of segments Has me...
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 wxPoint GetPosition() const override
virtual wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
void SetPosition(const wxPoint &aPos) override
double m_Angle
Used only for Arcs: Arc angle in 1/10 deg.
bool IsPolyShapeValid() const
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
void SetCenter(const wxPoint &aCenterPoint)
For arcs and circles:
virtual void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
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:78
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
PCB_LAYER_ID m_Layer
int GetPointCount() 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.
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:37
Class SHAPE_POLY_SET.
const SHAPE_POLY_SET & GetPolyShape() const
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
SHAPE_POLY_SET & GetPolyShape()
int GetType() const
bool IsPolygonFilled() const
Polygonal shape is not always filled.
void computeArcBBox(EDA_RECT &aBBox) const
void SetStart(const wxPoint &aStart)
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
const std::vector< wxPoint > & GetBezierPoints() const
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aCircleToSegmentsCount, double aCorrectionFactor, bool ignoreLineWidth=false) const override
Function TransformShapeWithClearanceToPolygon Convert the draw segment to a closed polygon Used in fi...
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.
Definition: eda_rect.h:44
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:154
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...
virtual void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it&#39;s internal state for displ...
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
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:91
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.
EDA_UNITS_T
Definition: common.h:159
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)