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.

173 lines
5.1 KiB

  1. /*************************************/
  2. /* class to handle a graphic segment */
  3. /**************************************/
  4. #ifndef CLASS_DRAWSEGMENT_H
  5. #define CLASS_DRAWSEGMENT_H
  6. #include "PolyLine.h"
  7. class DRAWSEGMENT : public BOARD_ITEM
  8. {
  9. public:
  10. int m_Width; // thickness of lines ...
  11. wxPoint m_Start; // Line start point
  12. wxPoint m_End; // Line end point
  13. int m_Shape; // Shape: line, Circle, Arc
  14. int m_Type; // Used in complex associations ( Dimensions.. )
  15. int m_Angle; // Used only for Arcs: Arc angle in 1/10 deg
  16. wxPoint m_BezierC1; // Bezier Control Point 1
  17. wxPoint m_BezierC2; // Bezier Control Point 1
  18. std::vector<wxPoint> m_BezierPoints;
  19. public:
  20. DRAWSEGMENT( BOARD_ITEM* aParent, KICAD_T idtype = TYPE_DRAWSEGMENT );
  21. ~DRAWSEGMENT();
  22. DRAWSEGMENT* Next() const { return (DRAWSEGMENT*) Pnext; }
  23. DRAWSEGMENT* Back() const { return (DRAWSEGMENT*) Pback; }
  24. /**
  25. * Function GetPosition
  26. * returns the position of this object.
  27. * Required by pure virtual BOARD_ITEM::GetPosition()
  28. * @return const wxPoint& - The position of this object.
  29. */
  30. wxPoint& GetPosition()
  31. {
  32. return m_Start;
  33. }
  34. /**
  35. * Function GetStart
  36. * returns the starting point of the graphic
  37. */
  38. wxPoint GetStart() const;
  39. /**
  40. * Function GetEnd
  41. * returns the ending point of the graphic
  42. */
  43. wxPoint GetEnd() const;
  44. /**
  45. * Function Save
  46. * writes the data structures for this object out to a FILE in "*.brd" format.
  47. * @param aFile The FILE to write to.
  48. * @return bool - true if success writing else false.
  49. */
  50. bool Save( FILE* aFile ) const;
  51. bool ReadDrawSegmentDescr( FILE* File, int* LineNum );
  52. void Copy( DRAWSEGMENT* source );
  53. void Draw( WinEDA_DrawPanel* panel, wxDC* DC,
  54. int aDrawMode, const wxPoint& offset = ZeroOffset );
  55. /**
  56. * Function DisplayInfo
  57. * has knowledge about the frame and how and where to put status information
  58. * about this object into the frame's message panel.
  59. * Is virtual from EDA_BaseStruct.
  60. * @param frame A WinEDA_BasePcbFrame in which to print status information.
  61. */
  62. virtual void DisplayInfo( WinEDA_DrawFrame* frame );
  63. /**
  64. * Function HitTest
  65. * tests if the given wxPoint is within the bounds of this object.
  66. * @param ref_pos A wxPoint to test
  67. * @return bool - true if a hit, else false
  68. */
  69. bool HitTest( const wxPoint& ref_pos );
  70. /**
  71. * Function HitTest (overlayed)
  72. * tests if the given EDA_Rect intersect this object.
  73. * For now, an ending point must be inside this rect.
  74. * @param refPos the given EDA_Rect to test
  75. * @return bool - true if a hit, else false
  76. */
  77. bool HitTest( EDA_Rect& refArea );
  78. /**
  79. * Function GetClass
  80. * returns the class name.
  81. * @return wxString
  82. */
  83. wxString GetClass() const
  84. {
  85. return wxT( "DRAWSEGMENT" );
  86. }
  87. /**
  88. * Function GetLength
  89. * returns the length of the track using the hypotenuse calculation.
  90. * @return double - the length of the track
  91. */
  92. double GetLength() const
  93. {
  94. wxPoint delta = GetEnd() - GetStart();
  95. return hypot( delta.x, delta.y );
  96. }
  97. /**
  98. * Function Move
  99. * move this object.
  100. * @param const wxPoint& aMoveVector - the move vector for this object.
  101. */
  102. virtual void Move( const wxPoint& aMoveVector )
  103. {
  104. m_Start += aMoveVector;
  105. m_End += aMoveVector;
  106. }
  107. /**
  108. * Function Rotate
  109. * Rotate this object.
  110. * @param const wxPoint& aRotCentre - the rotation point.
  111. * @param aAngle - the rotation angle in 0.1 degree.
  112. */
  113. virtual void Rotate( const wxPoint& aRotCentre, int aAngle );
  114. /**
  115. * Function Flip
  116. * Flip this object, i.e. change the board side for this object
  117. * @param const wxPoint& aCentre - the rotation point.
  118. */
  119. virtual void Flip( const wxPoint& aCentre );
  120. /** Function TransformShapeWithClearanceToPolygon
  121. * Convert the track shape to a closed polygon
  122. * Used in filling zones calculations
  123. * Circles and arcs are approximated by segments
  124. * @param aCornerBuffer = a buffer to store the polygon
  125. * @param aClearanceValue = the clearance around the pad
  126. * @param aCircleToSegmentsCount = the number of segments to approximate a circle
  127. * @param aCorrectionFactor = the correction to apply to circles radius to keep
  128. * clearance when the circle is approxiamted by segment bigger or equal
  129. * to the real clearance value (usually near from 1.0)
  130. */
  131. void TransformShapeWithClearanceToPolygon(
  132. std::vector <CPolyPt>& aCornerBuffer,
  133. int aClearanceValue,
  134. int
  135. aCircleToSegmentsCount,
  136. double aCorrectionFactor );
  137. #if defined(DEBUG)
  138. void Show( int nestLevel, std::ostream& os );
  139. #endif
  140. };
  141. #endif // #ifndef CLASS_DRAWSEGMENT_H