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.

160 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
  34. {
  35. START,
  36. END,
  37. 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. int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform );
  56. /**
  57. * Draw the graphics when the arc is being edited.
  58. */
  59. void drawEditGraphics( EDA_RECT* aClipBox, wxDC* aDC, int aColor );
  60. /**
  61. * Calculates the center, radius, and angles at \a aPosition when the arc is being edited.
  62. *
  63. * Note: The center may not necessarily be on the grid.
  64. *
  65. * @param aPosition - The current mouse position in drawing coordinates.
  66. */
  67. void calcEdit( const wxPoint& aPosition );
  68. /**
  69. * Calculate the radius and angle of an arc using the start, end, and center points.
  70. */
  71. void calcRadiusAngles();
  72. public:
  73. LIB_ARC( LIB_COMPONENT * aParent );
  74. // Do not create a copy constructor. The one generated by the compiler is adequate.
  75. ~LIB_ARC() { }
  76. wxString GetClass() const
  77. {
  78. return wxT( "LIB_ARC" );
  79. }
  80. bool Save( OUTPUTFORMATTER& aFormatter );
  81. bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
  82. bool HitTest( const wxPoint& aPosition );
  83. bool HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform );
  84. EDA_RECT GetBoundingBox() const;
  85. void DisplayInfo( EDA_DRAW_FRAME* frame );
  86. int GetPenSize() const;
  87. void BeginEdit( int aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) );
  88. bool ContinueEdit( const wxPoint aNextPoint );
  89. void EndEdit( const wxPoint& aPosition, bool aAbort = false );
  90. void SetOffset( const wxPoint& aOffset );
  91. bool Inside( EDA_RECT& aRect ) const;
  92. void Move( const wxPoint& aPosition );
  93. wxPoint GetPosition() const { return m_Pos; }
  94. void MirrorHorizontal( const wxPoint& aCenter );
  95. void MirrorVertical( const wxPoint& aCenter );
  96. void Rotate( const wxPoint& aCenter, bool aRotateCCW = true );
  97. void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
  98. const TRANSFORM& aTransform );
  99. int GetWidth() const { return m_Width; }
  100. void SetWidth( int aWidth ) { m_Width = aWidth; }
  101. wxString GetSelectMenuText() const;
  102. BITMAP_DEF GetMenuImage() const { return add_arc_xpm; }
  103. EDA_ITEM* Clone() const;
  104. private:
  105. /**
  106. * @copydoc LIB_ITEM::compare()
  107. *
  108. * The arc specific sort order is as follows:
  109. * - Arc horizontal (X) position.
  110. * - Arc vertical (Y) position.
  111. * - Arc start angle.
  112. * - Arc end angle.
  113. */
  114. int compare( const LIB_ITEM& aOther ) const;
  115. };
  116. #endif // _LIB_ARC_H_