You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

283 lines
9.8 KiB

14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file class_drawsegment.h
  27. * @brief Class to handle a graphic segment.
  28. */
  29. #ifndef CLASS_DRAWSEGMENT_H_
  30. #define CLASS_DRAWSEGMENT_H_
  31. #include "class_board_item.h"
  32. #include "PolyLine.h"
  33. class LINE_READER;
  34. class EDA_DRAW_FRAME;
  35. class MODULE;
  36. class DRAWSEGMENT : public BOARD_ITEM
  37. {
  38. protected:
  39. int m_Width; ///< thickness of lines ...
  40. wxPoint m_Start; ///< Line start point or Circle and Arc center
  41. wxPoint m_End; ///< Line end point or circle and arc start point
  42. int m_Shape; ///< Shape: line, Circle, Arc
  43. int m_Type; ///< Used in complex associations ( Dimensions.. )
  44. double m_Angle; ///< Used only for Arcs: Arc angle in 1/10 deg
  45. wxPoint m_BezierC1; ///< Bezier Control Point 1
  46. wxPoint m_BezierC2; ///< Bezier Control Point 1
  47. std::vector<wxPoint> m_BezierPoints;
  48. std::vector<wxPoint> m_PolyPoints;
  49. public:
  50. DRAWSEGMENT( BOARD_ITEM* aParent = NULL, KICAD_T idtype = PCB_LINE_T );
  51. // Do not create a copy constructor. The one generated by the compiler is adequate.
  52. ~DRAWSEGMENT();
  53. /// skip the linked list stuff, and parent
  54. const DRAWSEGMENT& operator = ( const DRAWSEGMENT& rhs );
  55. DRAWSEGMENT* Next() const { return (DRAWSEGMENT*) Pnext; }
  56. DRAWSEGMENT* Back() const { return (DRAWSEGMENT*) Pback; }
  57. void SetWidth( int aWidth ) { m_Width = aWidth; }
  58. int GetWidth() const { return m_Width; }
  59. /**
  60. * Function SetAngle
  61. * sets the angle for arcs, and normalizes it within the range 0 - 360 degrees.
  62. * @param aAngle is tenths of degrees, but will soon be degrees.
  63. */
  64. void SetAngle( double aAngle ); // encapsulates the transition to degrees
  65. double GetAngle() const { return m_Angle; }
  66. void SetType( int aType ) { m_Type = aType; }
  67. int GetType() const { return m_Type; }
  68. void SetShape( int aShape ) { m_Shape = aShape; }
  69. int GetShape() const { return m_Shape; }
  70. void SetBezControl1( const wxPoint& aPoint ) { m_BezierC1 = aPoint; }
  71. const wxPoint& GetBezControl1() const { return m_BezierC1; }
  72. void SetBezControl2( const wxPoint& aPoint ) { m_BezierC2 = aPoint; }
  73. const wxPoint& GetBezControl2() const { return m_BezierC2; }
  74. void SetPosition( const wxPoint& aPos ) { m_Start = aPos; } // override
  75. const wxPoint GetPosition() const { return m_Start; } // override
  76. /**
  77. * Function GetStart
  78. * returns the starting point of the graphic
  79. */
  80. const wxPoint& GetStart() const { return m_Start; }
  81. void SetStart( const wxPoint& aStart ) { m_Start = aStart; }
  82. void SetStartY( int y ) { m_Start.y = y; }
  83. void SetStartX( int x ) { m_Start.x = x; }
  84. /**
  85. * Function GetEnd
  86. * returns the ending point of the graphic
  87. */
  88. const wxPoint& GetEnd() const { return m_End; }
  89. void SetEnd( const wxPoint& aEnd ) { m_End = aEnd; }
  90. void SetEndY( int y ) { m_End.y = y; }
  91. void SetEndX( int x ) { m_End.x = x; }
  92. // Arc attributes are read only, since they are "calculated" from
  93. // m_Start, m_End, and m_Angle. No Set...() functions.
  94. const wxPoint& GetCenter() const { return m_Start; }
  95. const wxPoint& GetArcStart() const { return m_End; }
  96. const wxPoint GetArcEnd() const;
  97. /**
  98. * Function GetRadius
  99. * returns the radius of this item
  100. * Has meaning only for arc and circle
  101. */
  102. int GetRadius() const
  103. {
  104. double radius = hypot( (double) (m_End.x - m_Start.x), (double) (m_End.y - m_Start.y) );
  105. return wxRound( radius );
  106. }
  107. /**
  108. * Function GetParentModule
  109. * returns a pointer to the parent module, or NULL if DRAWSEGMENT does not
  110. * belong to a module.
  111. * @return MODULE* - pointer to the parent module or NULL.
  112. */
  113. MODULE* GetParentModule() const;
  114. const std::vector<wxPoint>& GetBezierPoints() const { return m_BezierPoints; };
  115. const std::vector<wxPoint>& GetPolyPoints() const { return m_PolyPoints; };
  116. void SetBezierPoints( std::vector<wxPoint>& aPoints )
  117. {
  118. m_BezierPoints = aPoints;
  119. }
  120. void SetPolyPoints( std::vector<wxPoint>& aPoints )
  121. {
  122. m_PolyPoints = aPoints;
  123. }
  124. /**
  125. * Function Save
  126. * writes the data structures for this object out to a FILE in "*.brd" format.
  127. * @param aFile The FILE to write to.
  128. * @return bool - true if success writing else false.
  129. */
  130. bool Save( FILE* aFile ) const;
  131. bool ReadDrawSegmentDescr( LINE_READER* aReader );
  132. void Copy( DRAWSEGMENT* source );
  133. void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
  134. int aDrawMode, const wxPoint& aOffset = ZeroOffset );
  135. /**
  136. * Function DisplayInfo
  137. * has knowledge about the frame and how and where to put status information
  138. * about this object into the frame's message panel.
  139. * Is virtual from EDA_ITEM.
  140. * @param frame A PCB_BASE_FRAME in which to print status information.
  141. */
  142. virtual void DisplayInfo( EDA_DRAW_FRAME* frame );
  143. /**
  144. * Function GetBoundingBox
  145. * returns the orthogonal, bounding box of this object for display purposes.
  146. * This box should be an enclosing perimeter for visible components of this
  147. * object, and the units should be in the pcb or schematic coordinate system.
  148. * It is OK to overestimate the size by a few counts.
  149. */
  150. virtual EDA_RECT GetBoundingBox() const;
  151. /**
  152. * Function HitTest
  153. * tests if the given wxPoint is within the bounds of this object.
  154. * @param aRefPos A wxPoint to test
  155. * @return bool - true if a hit, else false
  156. */
  157. bool HitTest( const wxPoint& aRefPos );
  158. /**
  159. * Function HitTest (overlayed)
  160. * tests if the given EDA_RECT intersect this object.
  161. * For now, an ending point must be inside this rect.
  162. * @param refArea the given EDA_RECT to test
  163. * @return bool - true if a hit, else false
  164. */
  165. bool HitTest( EDA_RECT& refArea );
  166. /**
  167. * Function GetClass
  168. * returns the class name.
  169. * @return wxString
  170. */
  171. wxString GetClass() const
  172. {
  173. return wxT( "DRAWSEGMENT" );
  174. }
  175. /**
  176. * Function GetLength
  177. * returns the length of the track using the hypotenuse calculation.
  178. * @return double - the length of the track
  179. */
  180. double GetLength() const
  181. {
  182. wxPoint delta = GetEnd() - GetStart();
  183. return hypot( double( delta.x ), double( delta.y ) );
  184. }
  185. /**
  186. * Function Move
  187. * move this object.
  188. * @param aMoveVector - the move vector for this object.
  189. */
  190. virtual void Move( const wxPoint& aMoveVector )
  191. {
  192. m_Start += aMoveVector;
  193. m_End += aMoveVector;
  194. }
  195. /**
  196. * Function Rotate
  197. * Rotate this object.
  198. * @param aRotCentre - the rotation point.
  199. * @param aAngle - the rotation angle in 0.1 degree.
  200. */
  201. virtual void Rotate( const wxPoint& aRotCentre, double aAngle );
  202. /**
  203. * Function Flip
  204. * Flip this object, i.e. change the board side for this object
  205. * @param aCentre - the rotation point.
  206. */
  207. virtual void Flip( const wxPoint& aCentre );
  208. /**
  209. * Function TransformShapeWithClearanceToPolygon
  210. * Convert the track shape to a closed polygon
  211. * Used in filling zones calculations
  212. * Circles and arcs are approximated by segments
  213. * @param aCornerBuffer = a buffer to store the polygon
  214. * @param aClearanceValue = the clearance around the pad
  215. * @param aCircleToSegmentsCount = the number of segments to approximate a circle
  216. * @param aCorrectionFactor = the correction to apply to circles radius to keep
  217. * clearance when the circle is approximated by segment bigger or equal
  218. * to the real clearance value (usually near from 1.0)
  219. */
  220. void TransformShapeWithClearanceToPolygon( std::vector <CPolyPt>& aCornerBuffer,
  221. int aClearanceValue,
  222. int aCircleToSegmentsCount,
  223. double aCorrectionFactor );
  224. virtual wxString GetSelectMenuText() const;
  225. virtual BITMAP_DEF GetMenuImage() const { return add_dashed_line_xpm; }
  226. #if defined(DEBUG)
  227. void Show( int nestLevel, std::ostream& os ) const; // overload
  228. #endif
  229. private:
  230. virtual EDA_ITEM* doClone() const;
  231. };
  232. #endif // CLASS_DRAWSEGMENT_H_