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.

177 lines
5.3 KiB

  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) 2004-2011 KiCad Developers, see change_log.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. /**
  25. * @file lib_arc.h
  26. */
  27. #ifndef _LIB_ARC_H_
  28. #define _LIB_ARC_H_
  29. #include <lib_draw_item.h>
  30. class TRANSFORM;
  31. class LIB_ARC : public LIB_ITEM
  32. {
  33. enum SELECT_T // When creating an arc: status of arc
  34. {
  35. ARC_STATUS_START,
  36. ARC_STATUS_END,
  37. ARC_STATUS_OUTLINE,
  38. };
  39. int m_Radius;
  40. int m_t1; // First radius angle of the arc in 0.1 degrees.
  41. int m_t2; /* Second radius angle of the arc in 0.1 degrees. */
  42. wxPoint m_ArcStart;
  43. wxPoint m_ArcEnd; /* Arc end position. */
  44. wxPoint m_Pos; /* Radius center point. */
  45. int m_Width; /* Line width */
  46. double m_editCenterDistance;
  47. SELECT_T m_editSelectPoint;
  48. int m_editState;
  49. int m_editDirection;
  50. int m_lastEditState;
  51. /**
  52. * Draws the arc.
  53. */
  54. void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
  55. COLOR4D aColor, GR_DRAWMODE aDrawMode, void* aData,
  56. const TRANSFORM& aTransform ) override;
  57. /**
  58. * Draw the graphics when the arc is being edited.
  59. */
  60. void drawEditGraphics( EDA_RECT* aClipBox, wxDC* aDC, COLOR4D aColor ) override;
  61. /**
  62. * Calculates the center, radius, and angles at \a aPosition when the arc is being edited.
  63. *
  64. * Note: The center may not necessarily be on the grid.
  65. *
  66. * @param aPosition - The current mouse position in drawing coordinates.
  67. */
  68. void calcEdit( const wxPoint& aPosition ) override;
  69. /**
  70. * Calculate the radius and angle of an arc using the start, end, and center points.
  71. */
  72. void calcRadiusAngles();
  73. public:
  74. LIB_ARC( LIB_PART * aParent );
  75. // Do not create a copy constructor. The one generated by the compiler is adequate.
  76. ~LIB_ARC() { }
  77. wxString GetClass() const override
  78. {
  79. return wxT( "LIB_ARC" );
  80. }
  81. bool Save( OUTPUTFORMATTER& aFormatter ) override;
  82. bool Load( LINE_READER& aLineReader, wxString& aErrorMsg ) override;
  83. bool HitTest( const wxPoint& aPosition ) const override;
  84. bool HitTest( const wxPoint& aPosition, int aThreshold, const TRANSFORM& aTransform ) const override;
  85. const EDA_RECT GetBoundingBox() const override;
  86. void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
  87. int GetPenSize() const override;
  88. void BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) ) override;
  89. bool ContinueEdit( const wxPoint aNextPoint ) override;
  90. void EndEdit( const wxPoint& aPosition, bool aAbort = false ) override;
  91. void SetOffset( const wxPoint& aOffset ) override;
  92. bool Inside( EDA_RECT& aRect ) const override;
  93. void Move( const wxPoint& aPosition ) override;
  94. wxPoint GetPosition() const override { return m_Pos; }
  95. void MirrorHorizontal( const wxPoint& aCenter ) override;
  96. void MirrorVertical( const wxPoint& aCenter ) override;
  97. void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
  98. void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
  99. const TRANSFORM& aTransform ) override;
  100. int GetWidth() const override { return m_Width; }
  101. void SetWidth( int aWidth ) override { m_Width = aWidth; }
  102. void SetRadius( int aRadius ) { m_Radius = aRadius; }
  103. int GetRadius() const { return m_Radius; }
  104. void SetFirstRadiusAngle( int aAngle ) { m_t1 = aAngle; }
  105. int GetFirstRadiusAngle() const { return m_t1; }
  106. void SetSecondRadiusAngle( int aAngle ) { m_t2 = aAngle; }
  107. int GetSecondRadiusAngle() const { return m_t2; }
  108. void SetStart( const wxPoint& aPoint ) { m_ArcStart = aPoint; }
  109. void SetEnd( const wxPoint& aPoint ) { m_ArcEnd = aPoint; }
  110. wxString GetSelectMenuText() const override;
  111. BITMAP_DEF GetMenuImage() const override;
  112. EDA_ITEM* Clone() const override;
  113. private:
  114. /**
  115. * @copydoc LIB_ITEM::compare()
  116. *
  117. * The arc specific sort order is as follows:
  118. * - Arc horizontal (X) position.
  119. * - Arc vertical (Y) position.
  120. * - Arc start angle.
  121. * - Arc end angle.
  122. */
  123. int compare( const LIB_ITEM& aOther ) const override;
  124. };
  125. #endif // _LIB_ARC_H_