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>
40 
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;
55 
57  int m_Type;
58  double m_Angle;
61 
62  std::vector<wxPoint> m_BezierPoints;
64 
65  // Computes the bounding box for an arc
66  void computeArcBBox( EDA_RECT& aBBox ) const;
67 
68  const std::vector<wxPoint> buildBezierToSegmentsPointsList( int aMinSegLen ) const;
69 
70 public:
71  DRAWSEGMENT( BOARD_ITEM* aParent = NULL, KICAD_T idtype = PCB_LINE_T );
72 
73  // Do not create a copy constructor & operator=.
74  // The ones generated by the compiler are adequate.
75 
76  ~DRAWSEGMENT();
77 
78  static inline bool ClassOf( const EDA_ITEM* aItem )
79  {
80  return aItem && PCB_LINE_T == aItem->Type();
81  }
82 
83  bool IsType( const KICAD_T aScanTypes[] ) const override
84  {
85  if( BOARD_ITEM::IsType( aScanTypes ) )
86  return true;
87 
88  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
89  {
90  if( *p == PCB_LOCATE_GRAPHIC_T )
91  return true;
92  else if( *p == PCB_LOCATE_BOARD_EDGE_T )
93  return m_Layer == Edge_Cuts;
94  }
95 
96  return false;
97  }
98 
102  bool IsPolygonFilled() const { return m_Layer != Edge_Cuts; }
103 
104  void SetWidth( int aWidth ) { m_Width = aWidth; }
105  int GetWidth() const { return m_Width; }
106 
112  virtual void SetAngle( double aAngle ); // encapsulates the transition to degrees
113  double GetAngle() const { return m_Angle; }
114 
115  void SetType( int aType ) { m_Type = aType; }
116  int GetType() const { return m_Type; }
117 
118  void SetShape( STROKE_T aShape ) { m_Shape = aShape; }
119  STROKE_T GetShape() const { return m_Shape; }
120 
121  void SetBezControl1( const wxPoint& aPoint ) { m_BezierC1 = aPoint; }
122  const wxPoint& GetBezControl1() const { return m_BezierC1; }
123 
124  void SetBezControl2( const wxPoint& aPoint ) { m_BezierC2 = aPoint; }
125  const wxPoint& GetBezControl2() const { return m_BezierC2; }
126 
127  void SetPosition( const wxPoint& aPos ) override;
128  wxPoint GetPosition() const override;
129 
134  const wxPoint& GetStart() const { return m_Start; }
135  int GetStartY() { return m_Start.y; }
136  int GetStartX() { return m_Start.x; }
137  void SetStart( const wxPoint& aStart ) { m_Start = aStart; }
138  void SetStartY( int y ) { m_Start.y = y; }
139  void SetStartX( int x ) { m_Start.x = x; }
140 
145  const wxPoint& GetEnd() const { return m_End; }
146  int GetEndY() { return m_End.y; }
147  int GetEndX() { return m_End.x; }
148  void SetEnd( const wxPoint& aEnd ) { m_End = aEnd; }
149  void SetEndY( int y ) { m_End.y = y; }
150  void SetEndX( int x ) { m_End.x = x; }
151 
156  const wxPoint& GetThirdPoint() const { return m_ThirdPoint; }
157  int GetThirdPointY() { return m_ThirdPoint.y; }
158  int GetThirdPointX() { return m_ThirdPoint.x; }
159  void SetThirdPoint( const wxPoint& aPoint ) { m_ThirdPoint = aPoint; }
160  void SetThirdPointY( int y ) { m_ThirdPoint.y = y; }
161  void SetThirdPointX( int x ) { m_ThirdPoint.x = x; }
162 
163  // Some attributes are read only, since they are "calculated" from
164  // m_Start, m_End, and m_Angle.
165  // No Set...() function for these attributes.
166 
167  wxPoint GetCenter() const override;
168  wxPoint GetArcStart() const { return m_End; }
169  wxPoint GetArcEnd() const;
170  wxPoint GetArcMid() const;
171  std::vector<wxPoint> GetRectCorners() const;
172 
177  double GetArcAngleStart() const;
178 
183  double GetArcAngleEnd() const;
184 
190  int GetRadius() const
191  {
192  double radius = GetLineLength( m_Start, m_End );
193 
194  // don't allow degenerate arcs
195  return std::max( 1, KiROUND( radius ) );
196  }
197 
202  void SetArcStart( const wxPoint& aArcStartPoint )
203  {
204  m_End = aArcStartPoint;
205  }
206 
211  void SetArcEnd( const wxPoint& aArcEndPoint )
212  {
213  m_ThirdPoint = aArcEndPoint;
214  }
215 
218  void SetCenter( const wxPoint& aCenterPoint ) { m_Start = aCenterPoint; }
219 
220  const wxPoint GetFocusPosition() const override
221  {
222  return GetCenter();
223  }
224 
231  MODULE* GetParentModule() const;
232 
233  // Accessors:
234  const std::vector<wxPoint>& GetBezierPoints() const { return m_BezierPoints; }
235 
241  const std::vector<wxPoint> BuildPolyPointsList() const;
242 
245  int GetPointCount() const;
246 
247  // Accessors to the polygonal shape
249  const SHAPE_POLY_SET& GetPolyShape() const { return m_Poly; }
250 
254  bool IsPolyShapeValid() const;
255 
256  void SetPolyShape( const SHAPE_POLY_SET& aShape ) { m_Poly = aShape; }
257 
258  void SetBezierPoints( const std::vector<wxPoint>& aPoints )
259  {
260  m_BezierPoints = aPoints;
261  }
262 
271  void RebuildBezierToSegmentsPointsList( int aMinSegLen );
272 
273  void SetPolyPoints( const std::vector<wxPoint>& aPoints );
274 
278  std::vector<SHAPE*> MakeEffectiveShapes() const; // fixme: move to shape_compound
279  virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER ) const override;
280 
281  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
282 
283  const EDA_RECT GetBoundingBox() const override;
284 
285  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
286  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
287 
288  wxString GetClass() const override
289  {
290  return wxT( "DRAWSEGMENT" );
291  }
292 
298  double GetLength() const;
299 
300  virtual void Move( const wxPoint& aMoveVector ) override;
301 
302  virtual void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
303 
304  virtual void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
305 
306  void Scale( double aScale );
307 
320  int aClearanceValue, int aError = ARC_HIGH_DEF,
321  bool ignoreLineWidth = false ) const override;
322 
323  virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
324 
325  virtual BITMAP_DEF GetMenuImage() const override;
326 
327  virtual EDA_ITEM* Clone() const override;
328 
329  virtual const BOX2I ViewBBox() const override;
330 
331  virtual void SwapData( BOARD_ITEM* aImage ) override;
332 
334  {
335  bool operator()( const BOARD_ITEM* aFirst, const BOARD_ITEM* aSecond ) const;
336  };
337 
338 #if defined(DEBUG)
339  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
340 #endif
341 };
342 
343 #endif // CLASS_DRAWSEGMENT_H_
EDA_UNITS
Definition: common.h:198
wxPoint GetArcStart() const
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)
wxPoint GetArcEnd() const
void SetPolyShape(const SHAPE_POLY_SET &aShape)
double GetLineLength(const wxPoint &aPointA, const wxPoint &aPointB)
Return the length of a line segment defined by aPointA and aPointB.
Definition: trigo.h:211
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)
STROKE_T GetShape() const
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
void SetStartY(int y)
void SetThirdPointX(int x)
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...
void SetThirdPoint(const wxPoint &aPoint)
const wxPoint GetFocusPosition() const override
Function GetFocusPosition similar to GetPosition, but allows items to return their visual center rath...
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.
wxPoint GetArcMid() const
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:
const wxPoint & GetThirdPoint() const
Function GetThirdPoint returns the third point point of the graphic.
virtual void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
void SetBezControl2(const wxPoint &aPoint)
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
void SetThirdPointY(int y)
wxPoint m_BezierC1
Bezier Control Point 1.
PCB_LAYER_ID m_Layer
wxPoint GetPosition() const override
double GetArcAngleEnd() const
function GetArcAngleEnd()
void SetArcEnd(const wxPoint &aArcEndPoint)
Initialize the end arc point.
virtual EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
PCB_LAYER_ID
A quick note on layer IDs:
wxPoint m_Start
Line start point or Circle and Arc center.
#define NULL
void computeArcBBox(EDA_RECT &aBBox) const
std::vector< wxPoint > GetRectCorners() const
wxPoint m_ThirdPoint
Used only for Arcs: arc end point.
wxPoint m_End
Line end point or circle and arc start point.
SHAPE_POLY_SET.
void Scale(double aScale)
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 ...
virtual bool IsType(const KICAD_T aScanTypes[]) const
Function IsType Checks whether the item is one of the listed types.
Definition: base_struct.h:262
STROKE_T m_Shape
Shape: line, Circle, Arc.
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)
const std::vector< wxPoint > buildBezierToSegmentsPointsList(int aMinSegLen) const
virtual void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Function Flip Flip this object, i.e.
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER) const override
Function GetEffectiveShape Some pad shapes can be complex (rounded/chamfered rectangle),...
double GetAngle() const
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.. )
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
wxString GetClass() const override
Function GetClass returns the class name.
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
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:68
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:159
The common library.
bool IsPolyShapeValid() const
static bool ClassOf(const EDA_ITEM *aItem)
void SetEndX(int x)
void SetEnd(const wxPoint &aEnd)
bool IsType(const KICAD_T aScanTypes[]) const override
Function IsType Checks whether the item is one of the listed types.
virtual 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 operator()(const BOARD_ITEM *aFirst, const BOARD_ITEM *aSecond) const
bool IsPolygonFilled() const
Polygonal shape is not always filled.
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, PCB_LAYER_ID aLayer, 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...
std::vector< SHAPE * > MakeEffectiveShapes() const
Makes a set of SHAPE objects representing the DRAWSEGMENT.
wxPoint GetCenter() const override
Function GetCenter()
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
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)