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;
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 
80  bool IsType( const KICAD_T aScanTypes[] ) const override
81  {
82  if( BOARD_ITEM::IsType( aScanTypes ) )
83  return true;
84 
85  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
86  {
87  if( *p == PCB_LOCATE_GRAPHIC_T )
88  return true;
89  else if( *p == PCB_LOCATE_BOARD_EDGE_T )
90  return m_Layer == Edge_Cuts;
91  }
92 
93  return false;
94  }
95 
99  bool IsPolygonFilled() const { return m_Layer != Edge_Cuts; }
100 
101  void SetWidth( int aWidth ) { m_Width = aWidth; }
102  int GetWidth() const { return m_Width; }
103 
109  void SetAngle( double aAngle ); // encapsulates the transition to degrees
110  double GetAngle() const { return m_Angle; }
111 
112  void SetType( int aType ) { m_Type = aType; }
113  int GetType() const { return m_Type; }
114 
115  void SetShape( STROKE_T aShape ) { m_Shape = aShape; }
116  STROKE_T GetShape() const { return m_Shape; }
117 
118  void SetBezControl1( const wxPoint& aPoint ) { m_BezierC1 = aPoint; }
119  const wxPoint& GetBezControl1() const { return m_BezierC1; }
120 
121  void SetBezControl2( const wxPoint& aPoint ) { m_BezierC2 = aPoint; }
122  const wxPoint& GetBezControl2() const { return m_BezierC2; }
123 
124  void SetPosition( const wxPoint& aPos ) override;
125  const wxPoint GetPosition() const override;
126 
131  const wxPoint& GetStart() const { return m_Start; }
132  void SetStart( const wxPoint& aStart ) { m_Start = aStart; }
133  void SetStartY( int y ) { m_Start.y = y; }
134  void SetStartX( int x ) { m_Start.x = x; }
135 
140  const wxPoint& GetEnd() const { return m_End; }
141  void SetEnd( const wxPoint& aEnd ) { m_End = aEnd; }
142  void SetEndY( int y ) { m_End.y = y; }
143  void SetEndX( int x ) { m_End.x = x; }
144 
145  // Some attributes are read only, since they are "calculated" from
146  // m_Start, m_End, and m_Angle.
147  // No Set...() function for these attributes.
148 
149  const wxPoint GetCenter() const override;
150  const wxPoint& GetArcStart() const { return m_End; }
151  const wxPoint GetArcEnd() const;
152  const wxPoint GetArcMid() const;
153  void GetRectCorners( std::vector<wxPoint>* pts ) const;
154 
159  double GetArcAngleStart() const;
160 
166  int GetRadius() const
167  {
168  double radius = GetLineLength( m_Start, m_End );
169 
170  // don't allow degenerate arcs
171  return std::max( 1, KiROUND( radius ) );
172  }
173 
178  void SetArcStart( const wxPoint& aArcStartPoint )
179  { m_End = aArcStartPoint; }
180 
183  void SetCenter( const wxPoint& aCenterPoint ) { m_Start = aCenterPoint; }
184 
185  const wxPoint GetFocusPosition() const override
186  {
187  return GetCenter();
188  }
189 
196  MODULE* GetParentModule() const;
197 
198  // Accessors:
199  const std::vector<wxPoint>& GetBezierPoints() const { return m_BezierPoints; }
200 
206  const std::vector<wxPoint> BuildPolyPointsList() const;
207 
210  int GetPointCount() const;
211 
212  // Accessors to the polygonal shape
214  const SHAPE_POLY_SET& GetPolyShape() const { return m_Poly; }
215 
219  bool IsPolyShapeValid() const;
220 
221  void SetPolyShape( const SHAPE_POLY_SET& aShape ) { m_Poly = aShape; }
222 
223  void SetBezierPoints( const std::vector<wxPoint>& aPoints )
224  {
225  m_BezierPoints = aPoints;
226  }
227 
236  void RebuildBezierToSegmentsPointsList( int aMinSegLen );
237 
238  void SetPolyPoints( const std::vector<wxPoint>& aPoints );
239 
243  std::vector<SHAPE*> MakeEffectiveShapes();
244 
245  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
246 
247  const EDA_RECT GetBoundingBox() const override;
248 
249  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
250  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
251 
252  wxString GetClass() const override
253  {
254  return wxT( "DRAWSEGMENT" );
255  }
256 
262  double GetLength() const;
263 
264  virtual void Move( const wxPoint& aMoveVector ) override;
265 
266  virtual void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
267 
268  virtual void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
269 
270  void Scale( double aScale );
271 
283  void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, int aClearanceValue,
284  int aError = ARC_HIGH_DEF, bool ignoreLineWidth = false ) const override;
285 
286  virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
287 
288  virtual BITMAP_DEF GetMenuImage() const override;
289 
290  virtual EDA_ITEM* Clone() const override;
291 
292  virtual const BOX2I ViewBBox() const override;
293 
294  virtual void SwapData( BOARD_ITEM* aImage ) override;
295 
296 #if defined(DEBUG)
297  void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
298 #endif
299 };
300 
301 #endif // CLASS_DRAWSEGMENT_H_
const wxPoint GetArcMid() const
EDA_UNITS
Definition: common.h:198
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)
Return the length of a line segment defined by aPointA and aPointB.
Definition: trigo.h:206
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...
std::vector< SHAPE * > MakeEffectiveShapes()
Makes a set of SHAPE objects representing the DRAWSEGMENT.
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 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.
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)
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
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.
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.
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
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.
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
void GetRectCorners(std::vector< wxPoint > *pts) const
bool IsPolygonFilled() const
Polygonal shape is not always filled.
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)