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 <PolyLine.h>
35 #include <math_for_graphics.h>
36 #include <trigo.h>
37 #include <common.h>
38 
40 
41 class LINE_READER;
42 class EDA_DRAW_FRAME;
43 class MODULE;
44 class MSG_PANEL_ITEM;
45 
46 
47 class DRAWSEGMENT : public BOARD_ITEM
48 {
49 protected:
50  int m_Width;
53 
55  int m_Type;
56  double m_Angle;
59 
60  std::vector<wxPoint> m_BezierPoints;
62 
63  // Computes the bounding box for an arc
64  void computeArcBBox( EDA_RECT& aBBox ) const;
65 
66 public:
67  DRAWSEGMENT( BOARD_ITEM* aParent = NULL, KICAD_T idtype = PCB_LINE_T );
68 
69  // Do not create a copy constructor & operator=.
70  // The ones generated by the compiler are adequate.
71 
72  ~DRAWSEGMENT();
73 
74  static inline bool ClassOf( const EDA_ITEM* aItem )
75  {
76  return aItem && PCB_LINE_T == aItem->Type();
77  }
78 
79  void SetWidth( int aWidth ) { m_Width = aWidth; }
80  int GetWidth() const { return m_Width; }
81 
87  void SetAngle( double aAngle ); // encapsulates the transition to degrees
88  double GetAngle() const { return m_Angle; }
89 
90  void SetType( int aType ) { m_Type = aType; }
91  int GetType() const { return m_Type; }
92 
93  void SetShape( STROKE_T aShape ) { m_Shape = aShape; }
94  STROKE_T GetShape() const { return m_Shape; }
95 
96  void SetBezControl1( const wxPoint& aPoint ) { m_BezierC1 = aPoint; }
97  const wxPoint& GetBezControl1() const { return m_BezierC1; }
98 
99  void SetBezControl2( const wxPoint& aPoint ) { m_BezierC2 = aPoint; }
100  const wxPoint& GetBezControl2() const { return m_BezierC2; }
101 
102  void SetPosition( const wxPoint& aPos ) override;
103  const wxPoint GetPosition() const override;
104 
109  const wxPoint& GetStart() const { return m_Start; }
110  void SetStart( const wxPoint& aStart ) { m_Start = aStart; }
111  void SetStartY( int y ) { m_Start.y = y; }
112  void SetStartX( int x ) { m_Start.x = x; }
113 
118  const wxPoint& GetEnd() const { return m_End; }
119  void SetEnd( const wxPoint& aEnd ) { m_End = aEnd; }
120  void SetEndY( int y ) { m_End.y = y; }
121  void SetEndX( int x ) { m_End.x = x; }
122 
123  // Some attributes are read only, since they are "calculated" from
124  // m_Start, m_End, and m_Angle.
125  // No Set...() function for these attributes.
126 
127  const wxPoint GetCenter() const override;
128  const wxPoint& GetArcStart() const { return m_End; }
129  const wxPoint GetArcEnd() const;
130 
135  double GetArcAngleStart() const;
136 
142  int GetRadius() const
143  {
144  double radius = GetLineLength( m_Start, m_End );
145  return KiROUND( radius );
146  }
147 
152  void SetArcStart( const wxPoint& aArcStartPoint )
153  { m_End = aArcStartPoint; }
154 
157  void SetCenter( const wxPoint& aCenterPoint ) { m_Start = aCenterPoint; }
158 
165  MODULE* GetParentModule() const;
166 
167  // Accessors:
168  const std::vector<wxPoint>& GetBezierPoints() const { return m_BezierPoints; }
169 
175  const std::vector<wxPoint> BuildPolyPointsList() const;
176 
179  int GetPointCount() const;
180 
181  // Accessors to the polygonal shape
183  const SHAPE_POLY_SET& GetPolyShape() const { return m_Poly; }
184 
188  bool IsPolyShapeValid() const;
189 
190  void SetPolyShape( const SHAPE_POLY_SET& aShape ) { m_Poly = aShape; }
191 
192  void SetBezierPoints( const std::vector<wxPoint>& aPoints )
193  {
194  m_BezierPoints = aPoints;
195  }
196 
205  void RebuildBezierToSegmentsPointsList( int aMinSegLen );
206 
207  void SetPolyPoints( const std::vector<wxPoint>& aPoints );
208 
209  void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
210  GR_DRAWMODE aDrawMode, const wxPoint& aOffset = ZeroOffset ) override;
211 
212  virtual void GetMsgPanelInfo( EDA_UNITS_T aUnits,
213  std::vector< MSG_PANEL_ITEM >& aList ) override;
214 
215  virtual const EDA_RECT GetBoundingBox() const override;
216 
217  virtual bool HitTest( const wxPoint& aPosition ) const override;
218 
219  bool HitTest( const EDA_RECT& aRect, bool aContained = true,
220  int aAccuracy = 0 ) const override;
221 
222  wxString GetClass() const override
223  {
224  return wxT( "DRAWSEGMENT" );
225  }
226 
232  double GetLength() const
233  {
234  return GetLineLength( GetStart(), GetEnd() );
235  }
236 
237  virtual void Move( const wxPoint& aMoveVector ) override;
238 
239  virtual void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
240 
241  virtual void Flip( const wxPoint& aCentre ) override;
242 
256  int aClearanceValue,
257  int aCircleToSegmentsCount,
258  double aCorrectionFactor ) const override;
259 
260  virtual wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
261 
262  virtual BITMAP_DEF GetMenuImage() const override;
263 
264  virtual EDA_ITEM* Clone() const override;
265 
266  virtual const BOX2I ViewBBox() const override;
267 
268  virtual void SwapData( BOARD_ITEM* aImage ) override;
269 
270 #if defined(DEBUG)
271  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
272 #endif
273 };
274 
275 #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
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:41
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
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:63
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
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
void computeArcBBox(EDA_RECT &aBBox) const
void SetStart(const wxPoint &aStart)
void SetPolyPoints(const std::vector< wxPoint > &aPoints)
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, int aClearanceValue, int aCircleToSegmentsCount, double aCorrectionFactor) const override
Function TransformShapeWithClearanceToPolygon Convert the track shape to a closed polygon Used in fil...
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.
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: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...
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)