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.

254 lines
7.4 KiB

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-2017 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. bool m_UseMils; ///< If inches, use mils.
  60. int m_Value; ///< value of PCB dimensions.
  61. int m_Height; ///< length of feature lines
  62. TEXTE_PCB m_Text;
  63. public:
  64. // TODO private: These member should be private. they are public only due to legacy code
  65. wxPoint m_crossBarO, m_crossBarF;
  66. wxPoint m_featureLineGO, m_featureLineGF;
  67. wxPoint m_featureLineDO, m_featureLineDF;
  68. wxPoint m_arrowD1F, m_arrowD2F;
  69. wxPoint m_arrowG1F, m_arrowG2F;
  70. DIMENSION( BOARD_ITEM* aParent );
  71. // Do not create a copy constructor & operator=.
  72. // The ones generated by the compiler are adequate.
  73. ~DIMENSION();
  74. static inline bool ClassOf( const EDA_ITEM* aItem )
  75. {
  76. return aItem && PCB_DIMENSION_T == aItem->Type();
  77. }
  78. void SetValue( int aValue ) { m_Value = aValue; }
  79. int GetValue() const { return m_Value; }
  80. const wxPoint GetPosition() const override;
  81. void SetPosition( const wxPoint& aPos ) override;
  82. void SetTextSize( const wxSize& aTextSize )
  83. {
  84. m_Text.SetTextSize( aTextSize );
  85. }
  86. void SetLayer( PCB_LAYER_ID aLayer ) override;
  87. void SetShape( int aShape ) { m_Shape = aShape; }
  88. int GetShape() const { return m_Shape; }
  89. int GetWidth() const { return m_Width; }
  90. void SetWidth( int aWidth ) { m_Width = aWidth; }
  91. /**
  92. * Function SetOrigin
  93. * Sets a new origin of the crossbar line. All remaining lines are adjusted after that.
  94. * @param aOrigin is the new point to be used as the new origin of the crossbar line.
  95. */
  96. void SetOrigin( const wxPoint& aOrigin );
  97. /**
  98. * Function GetOrigin
  99. * @return Origin of the crossbar line.
  100. */
  101. const wxPoint& GetOrigin() const
  102. {
  103. return m_featureLineGO;
  104. }
  105. /**
  106. * Function SetEnd
  107. * Sets a new end of the crossbar line. All remaining lines are adjusted after that.
  108. * @param aEnd is the new point to be used as the new end of the crossbar line.
  109. */
  110. void SetEnd( const wxPoint& aEnd );
  111. /**
  112. * Function GetEnd
  113. * @return End of the crossbar line.
  114. */
  115. const wxPoint& GetEnd()
  116. {
  117. return m_featureLineDO;
  118. }
  119. /**
  120. * Function SetHeight
  121. * Sets the length of feature lines.
  122. * @param aHeight is the new height.
  123. */
  124. void SetHeight( int aHeight );
  125. /**
  126. * Function GetHeight
  127. * Returns the length of feature lines.
  128. */
  129. int GetHeight() const
  130. {
  131. return m_Height;
  132. }
  133. /**
  134. * Function UpdateHeight
  135. * Updates stored height basing on points coordinates.
  136. */
  137. void UpdateHeight();
  138. /**
  139. * Function GetAngle
  140. * Returns angle of the crossbar.
  141. * @return Angle of the crossbar line expressed in radians.
  142. */
  143. double GetAngle() const
  144. {
  145. wxPoint delta( m_featureLineDO - m_featureLineGO );
  146. return atan2( (double)delta.y, (double)delta.x );
  147. }
  148. /**
  149. * Function AdjustDimensionDetails
  150. * Calculate coordinates of segments used to draw the dimension.
  151. */
  152. void AdjustDimensionDetails();
  153. void GetUnits( EDA_UNITS_T& aUnits, bool& aUseMils ) const
  154. {
  155. aUnits = m_Unit;
  156. aUseMils = m_UseMils;
  157. }
  158. void SetUnits( EDA_UNITS_T aUnits, bool aUseMils )
  159. {
  160. m_Unit = aUnits;
  161. m_UseMils = aUseMils;
  162. }
  163. void SetText( const wxString& NewText );
  164. const wxString GetText() const;
  165. TEXTE_PCB& Text() { return m_Text; }
  166. TEXTE_PCB& Text() const { return *(const_cast<TEXTE_PCB*> (&m_Text)); }
  167. void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
  168. GR_DRAWMODE aColorMode, const wxPoint& offset = ZeroOffset ) override;
  169. /**
  170. * Function Move
  171. * @param offset : moving vector
  172. */
  173. void Move( const wxPoint& offset ) override;
  174. void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
  175. void Flip( const wxPoint& aCentre ) override;
  176. /**
  177. * Function Mirror
  178. * Mirror the Dimension , relative to a given horizontal axis
  179. * the text is not mirrored. only its position (and angle) is mirrored
  180. * the layer is not changed
  181. * @param axis_pos : vertical axis position
  182. */
  183. void Mirror( const wxPoint& axis_pos );
  184. void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override;
  185. bool HitTest( const wxPoint& aPosition ) const override;
  186. bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const override;
  187. wxString GetClass() const override
  188. {
  189. return wxT( "DIMENSION" );
  190. }
  191. // Virtual function
  192. const EDA_RECT GetBoundingBox() const override;
  193. wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
  194. BITMAP_DEF GetMenuImage() const override;
  195. EDA_ITEM* Clone() const override;
  196. virtual const BOX2I ViewBBox() const override;
  197. virtual void SwapData( BOARD_ITEM* aImage ) override;
  198. #if defined(DEBUG)
  199. virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  200. #endif
  201. };
  202. #endif // DIMENSION_H_