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 <common.h>
35 #include <convert_to_biu.h>
36 #include <math/util.h> // for KiROUND
37 #include <math_for_graphics.h>
38 #include <trigo.h>
39 
41 
42 class LINE_READER;
43 class EDA_DRAW_FRAME;
44 class MODULE;
45 class MSG_PANEL_ITEM;
46 
47 
48 class DRAWSEGMENT : public BOARD_ITEM
49 {
50 protected:
51  int m_Width;
54 
56  int m_Type;
57  double m_Angle;
60 
61  std::vector<wxPoint> m_BezierPoints;
63 
64  // Computes the bounding box for an arc
65  void computeArcBBox( EDA_RECT& aBBox ) const;
66 
67 public:
68  DRAWSEGMENT( BOARD_ITEM* aParent = NULL, KICAD_T idtype = PCB_LINE_T );
69 
70  // Do not create a copy constructor & operator=.
71  // The ones generated by the compiler are adequate.
72 
73  ~DRAWSEGMENT();
74 
75  static inline bool ClassOf( const EDA_ITEM* aItem )
76  {
77  return aItem && PCB_LINE_T == aItem->Type();
78  }
79 
83  bool IsPolygonFilled() const { return m_Layer != Edge_Cuts; }
84 
85  void SetWidth( int aWidth ) { m_Width = aWidth; }
86  int GetWidth() const { return m_Width; }
87 
93  void SetAngle( double aAngle ); // encapsulates the transition to degrees
94  double GetAngle() const { return m_Angle; }
95 
96  void SetType( int aType ) { m_Type = aType; }
97  int GetType() const { return m_Type; }
98 
99  void SetShape( STROKE_T aShape ) { m_Shape = aShape; }
100  STROKE_T GetShape() const { return m_Shape; }
101 
102  void SetBezControl1( const wxPoint& aPoint ) { m_BezierC1 = aPoint; }
103  const wxPoint& GetBezControl1() const { return m_BezierC1; }
104 
105  void SetBezControl2( const wxPoint& aPoint ) { m_BezierC2 = aPoint; }
106  const wxPoint& GetBezControl2() const { return m_BezierC2; }
107 
108  void SetPosition( const wxPoint& aPos ) override;
109  const wxPoint GetPosition() const override;
110 
115  const wxPoint& GetStart() const { return m_Start; }
116  void SetStart( const wxPoint& aStart ) { m_Start = aStart; }
117  void SetStartY( int y ) { m_Start.y = y; }
118  void SetStartX( int x ) { m_Start.x = x; }
119 
124  const wxPoint& GetEnd() const { return m_End; }
125  void SetEnd( const wxPoint& aEnd ) { m_End = aEnd; }
126  void SetEndY( int y ) { m_End.y = y; }
127  void SetEndX( int x ) { m_End.x = x; }
128 
129  // Some attributes are read only, since they are "calculated" from
130  // m_Start, m_End, and m_Angle.
131  // No Set...() function for these attributes.
132 
133  const wxPoint GetCenter() const override;
134  const wxPoint& GetArcStart() const { return m_End; }
135  const wxPoint GetArcEnd() const;
136  const wxPoint GetArcMid() const;
137 
142  double GetArcAngleStart() const;
143 
149  int GetRadius() const
150  {
151  double radius = GetLineLength( m_Start, m_End );
152 
153  // don't allow degenerate arcs
154  return std::max( 1, KiROUND( radius ) );
155  }
156 
161  void SetArcStart( const wxPoint& aArcStartPoint )
162  { m_End = aArcStartPoint; }
163 
166  void SetCenter( const wxPoint& aCenterPoint ) { m_Start = aCenterPoint; }
167 
174  MODULE* GetParentModule() const;
175 
176  // Accessors:
177  const std::vector<wxPoint>& GetBezierPoints() const { return m_BezierPoints; }
178 
184  const std::vector<wxPoint> BuildPolyPointsList() const;
185 
188  int GetPointCount() const;
189 
190  // Accessors to the polygonal shape
192  const SHAPE_POLY_SET& GetPolyShape() const { return m_Poly; }
193 
197  bool IsPolyShapeValid() const;
198 
199  void SetPolyShape( const SHAPE_POLY_SET& aShape ) { m_Poly = aShape; }
200 
201  void SetBezierPoints( const std::vector<wxPoint>& aPoints )
202  {
203  m_BezierPoints = aPoints;
204  }
205 
214  void RebuildBezierToSegmentsPointsList( int aMinSegLen );
215 
216  void SetPolyPoints( const std::vector<wxPoint>& aPoints );
217 
218  void Print( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& aOffset = ZeroOffset ) override;
219 
220  void GetMsgPanelInfo( EDA_UNITS aUnits, std::vector<MSG_PANEL_ITEM>& aList ) override;
221 
222  const EDA_RECT GetBoundingBox() const override;
223 
224  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
225  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
226 
227  wxString GetClass() const override
228  {
229  return wxT( "DRAWSEGMENT" );
230  }
231 
237  double GetLength() const;
238 
239  virtual void Move( const wxPoint& aMoveVector ) override;
240 
241  virtual void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
242 
243  virtual void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
244 
256  void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, int aClearanceValue,
257  int aError = ARC_HIGH_DEF, bool ignoreLineWidth = false ) const override;
258 
259  virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
260 
261  virtual BITMAP_DEF GetMenuImage() const override;
262 
263  virtual EDA_ITEM* Clone() const override;
264 
265  virtual const BOX2I ViewBBox() const override;
266 
267  virtual void SwapData( BOARD_ITEM* aImage ) override;
268 
269 #if defined(DEBUG)
270  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
271 #endif
272 };
273 
274 #endif // CLASS_DRAWSEGMENT_H_
const wxPoint GetArcMid() const
EDA_UNITS
Definition: common.h:72
LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived to re...
Definition: richio.h:81
virtual const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
void SetShape(STROKE_T aShape)
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:202
void SetBezierPoints(const std::vector< wxPoint > &aPoints)
PNG memory record (file in memory).
Definition: bitmap_def.h:29
virtual void Move(const wxPoint &aMoveVector) override
Function Move move this object.
void SetArcStart(const wxPoint &aArcStartPoint)
Initialize the start arc point.
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()
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aError=ARC_HIGH_DEF, bool ignoreLineWidth=false) const override
Function TransformShapeWithClearanceToPolygon Convert the draw segment to a closed polygon Used in fi...
STROKE_T GetShape() const
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
void SetStartY(int y)
const wxPoint GetArcEnd() const
SHAPE_POLY_SET m_Poly
Stores the S_POLYGON shape.
const SHAPE_POLY_SET & GetPolyShape() const
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...
double GetArcAngleStart() const
function GetArcAngleStart()
int GetType() const
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
const wxPoint GetPosition() const override
const std::vector< wxPoint > & GetBezierPoints() const
void SetPosition(const wxPoint &aPos) override
double m_Angle
Used only for Arcs: Arc angle in 1/10 deg.
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...
The base class for create windows for drawing purpose.
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
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.
PCB_LAYER_ID m_Layer
virtual EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
wxPoint m_Start
Line start point or Circle and Arc center.
#define NULL
void computeArcBBox(EDA_RECT &aBBox) const
wxPoint m_End
Line end point or circle and arc start point.
SHAPE_POLY_SET.
MODULE * GetParentModule() const
Function GetParentModule returns a pointer to the parent module, or NULL if DRAWSEGMENT does not belo...
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 & GetArcStart() const
int GetRadius() const
Function GetRadius returns the radius of this item Has meaning only for arc and circle.
SHAPE_POLY_SET & GetPolyShape()
int GetPointCount() const
int GetWidth() const
void SetStart(const wxPoint &aStart)
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
virtual void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Function Flip Flip this object, i.e.
double GetAngle() const
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...
virtual void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
double GetLength() const
Function GetLength returns the length of the track using the hypotenuse calculation.
int m_Type
Used in complex associations ( Dimensions.. )
wxString GetClass() const override
Function GetClass returns the class name.
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void Print(PCB_BASE_FRAME *aFrame, wxDC *DC, const wxPoint &aOffset=ZeroOffset) override
Function Print BOARD_ITEMs have their own color information.
wxPoint m_BezierC2
Bezier Control Point 2.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:61
const wxPoint & GetBezControl2() const
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:163
The common library.
bool IsPolyShapeValid() 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.
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.
const wxPoint & GetBezControl1() const
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
void SetStartX(int x)
int m_Width
thickness of lines ...
DRAWSEGMENT(BOARD_ITEM *aParent=NULL, KICAD_T idtype=PCB_LINE_T)
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
bool IsPolygonFilled() const
Polygonal shape is not always filled.
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207
void SetBezControl1(const wxPoint &aPoint)
std::vector< wxPoint > m_BezierPoints
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
void SetWidth(int aWidth)