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.

239 lines
7.2 KiB

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) 1992-2011 KiCad Developers, see AUTHORS.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 class_dimension.h
  26. * @brief DIMENSION class definition.
  27. */
  28. #ifndef DIMENSION_H_
  29. #define DIMENSION_H_
  30. #include <class_board_item.h>
  31. #include <class_pcb_text.h>
  32. class LINE_READER;
  33. class EDA_DRAW_PANEL;
  34. class TEXTE_PCB;
  35. class MSG_PANEL_ITEM;
  36. /**
  37. * Class DIMENSION
  38. *
  39. * For better understanding of the points that make a dimension:
  40. *
  41. * m_featureLineGO m_featureLineDO
  42. * | |
  43. * | |
  44. * | |
  45. * | m_arrowG2F m_arrowD2F |
  46. * | / \ |
  47. * m_crossBarO|/____________________________\|m_crossBarF
  48. * |\ m_Text /|
  49. * | \ / |
  50. * | m_arrowG1F m_arrowD1F |
  51. * | |
  52. * m_featureLineGF m_featureLineDF
  53. */
  54. class DIMENSION : public BOARD_ITEM
  55. {
  56. int m_Width; ///< Line width
  57. int m_Shape; ///< Currently always 0.
  58. EDA_UNITS_T m_Unit; ///< 0 = inches, 1 = mm
  59. int m_Value; ///< value of PCB dimensions.
  60. int m_Height; ///< length of feature lines
  61. TEXTE_PCB m_Text;
  62. public:
  63. // TODO private: These member should be private. they are public only due to legacy code
  64. wxPoint m_crossBarO, m_crossBarF;
  65. wxPoint m_featureLineGO, m_featureLineGF;
  66. wxPoint m_featureLineDO, m_featureLineDF;
  67. wxPoint m_arrowD1F, m_arrowD2F;
  68. wxPoint m_arrowG1F, m_arrowG2F;
  69. DIMENSION( BOARD_ITEM* aParent );
  70. // Do not create a copy constructor & operator=.
  71. // The ones generated by the compiler are adequate.
  72. ~DIMENSION();
  73. void SetValue( int aValue ) { m_Value = aValue; }
  74. int GetValue() const { return m_Value; }
  75. const wxPoint& GetPosition() const override;
  76. void SetPosition( const wxPoint& aPos ) override;
  77. void SetTextSize( const wxSize& aTextSize )
  78. {
  79. m_Text.SetSize( aTextSize );
  80. }
  81. void SetLayer( LAYER_ID aLayer ) override;
  82. void SetShape( int aShape ) { m_Shape = aShape; }
  83. int GetShape() const { return m_Shape; }
  84. int GetWidth() const { return m_Width; }
  85. void SetWidth( int aWidth ) { m_Width = aWidth; }
  86. /**
  87. * Function SetOrigin
  88. * Sets a new origin of the crossbar line. All remaining lines are adjusted after that.
  89. * @param aOrigin is the new point to be used as the new origin of the crossbar line.
  90. */
  91. void SetOrigin( const wxPoint& aOrigin );
  92. /**
  93. * Function GetOrigin
  94. * @return Origin of the crossbar line.
  95. */
  96. const wxPoint& GetOrigin() const
  97. {
  98. return m_featureLineGO;
  99. }
  100. /**
  101. * Function SetEnd
  102. * Sets a new end of the crossbar line. All remaining lines are adjusted after that.
  103. * @param aEnd is the new point to be used as the new end of the crossbar line.
  104. */
  105. void SetEnd( const wxPoint& aEnd );
  106. /**
  107. * Function GetEnd
  108. * @return End of the crossbar line.
  109. */
  110. const wxPoint& GetEnd()
  111. {
  112. return m_featureLineDO;
  113. }
  114. /**
  115. * Function SetHeight
  116. * Sets the length of feature lines.
  117. * @param aHeight is the new height.
  118. */
  119. void SetHeight( int aHeight );
  120. /**
  121. * Function GetHeight
  122. * Returns the length of feature lines.
  123. */
  124. int GetHeight() const
  125. {
  126. return m_Height;
  127. }
  128. /**
  129. * Function UpdateHeight
  130. * Updates stored height basing on points coordinates.
  131. */
  132. void UpdateHeight();
  133. /**
  134. * Function GetAngle
  135. * Returns angle of the crossbar.
  136. * @return Angle of the crossbar line expressed in radians.
  137. */
  138. double GetAngle() const
  139. {
  140. wxPoint delta( m_featureLineDO - m_featureLineGO );
  141. return atan2( (double)delta.y, (double)delta.x );
  142. }
  143. /**
  144. * Function AdjustDimensionDetails
  145. * Calculate coordinates of segments used to draw the dimension.
  146. * @param aDoNotChangeText (bool) if false, the dimension text is initialized
  147. */
  148. void AdjustDimensionDetails( bool aDoNotChangeText = false );
  149. void SetText( const wxString& NewText );
  150. const wxString GetText() const;
  151. TEXTE_PCB& Text() { return m_Text; }
  152. TEXTE_PCB& Text() const { return *(const_cast<TEXTE_PCB*> (&m_Text)); }
  153. void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
  154. GR_DRAWMODE aColorMode, const wxPoint& offset = ZeroOffset ) override;
  155. /**
  156. * Function Move
  157. * @param offset : moving vector
  158. */
  159. void Move( const wxPoint& offset ) override;
  160. void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
  161. void Flip( const wxPoint& aCentre ) override;
  162. /**
  163. * Function Mirror
  164. * Mirror the Dimension , relative to a given horizontal axis
  165. * the text is not mirrored. only its position (and angle) is mirrored
  166. * the layer is not changed
  167. * @param axis_pos : vertical axis position
  168. */
  169. void Mirror( const wxPoint& axis_pos );
  170. void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
  171. bool HitTest( const wxPoint& aPosition ) const override;
  172. /** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect,
  173. * bool aContained = true, int aAccuracy ) const
  174. */
  175. bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const override;
  176. wxString GetClass() const override
  177. {
  178. return wxT( "DIMENSION" );
  179. }
  180. // Virtual function
  181. const EDA_RECT GetBoundingBox() const override;
  182. wxString GetSelectMenuText() const override;
  183. BITMAP_DEF GetMenuImage() const override { return add_dimension_xpm; }
  184. EDA_ITEM* Clone() const override;
  185. /// @copydoc VIEW_ITEM::ViewBBox()
  186. virtual const BOX2I ViewBBox() const override;
  187. #if defined(DEBUG)
  188. virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  189. #endif
  190. };
  191. #endif // DIMENSION_H_