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.

161 lines
4.6 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. EDA_COLOR_T aColor, GR_DRAWMODE aDrawMode, void* aData,
  56. const TRANSFORM& aTransform );
  57. /**
  58. * Draw the graphics when the arc is being edited.
  59. */
  60. void drawEditGraphics( EDA_RECT* aClipBox, wxDC* aDC, EDA_COLOR_T aColor );
  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 );
  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_COMPONENT * aParent );
  75. // Do not create a copy constructor. The one generated by the compiler is adequate.
  76. ~LIB_ARC() { }
  77. wxString GetClass() const
  78. {
  79. return wxT( "LIB_ARC" );
  80. }
  81. bool Save( OUTPUTFORMATTER& aFormatter );
  82. bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
  83. bool HitTest( const wxPoint& aPosition ) const;
  84. bool HitTest( const wxPoint& aPosition, int aThreshold, const TRANSFORM& aTransform ) const;
  85. const EDA_RECT GetBoundingBox() const; // Virtual
  86. void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
  87. int GetPenSize() const;
  88. void BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) );
  89. bool ContinueEdit( const wxPoint aNextPoint );
  90. void EndEdit( const wxPoint& aPosition, bool aAbort = false );
  91. void SetOffset( const wxPoint& aOffset );
  92. bool Inside( EDA_RECT& aRect ) const;
  93. void Move( const wxPoint& aPosition );
  94. wxPoint GetPosition() const { return m_Pos; }
  95. void MirrorHorizontal( const wxPoint& aCenter );
  96. void MirrorVertical( const wxPoint& aCenter );
  97. void Rotate( const wxPoint& aCenter, bool aRotateCCW = true );
  98. void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
  99. const TRANSFORM& aTransform );
  100. int GetWidth() const { return m_Width; }
  101. void SetWidth( int aWidth ) { m_Width = aWidth; }
  102. wxString GetSelectMenuText() const;
  103. BITMAP_DEF GetMenuImage() const { return add_arc_xpm; }
  104. EDA_ITEM* Clone() const;
  105. private:
  106. /**
  107. * @copydoc LIB_ITEM::compare()
  108. *
  109. * The arc specific sort order is as follows:
  110. * - Arc horizontal (X) position.
  111. * - Arc vertical (Y) position.
  112. * - Arc start angle.
  113. * - Arc end angle.
  114. */
  115. int compare( const LIB_ITEM& aOther ) const;
  116. };
  117. #endif // _LIB_ARC_H_