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.

242 lines
6.8 KiB

7 years ago
18 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2022 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. #ifndef SCH_TEXT_H
  25. #define SCH_TEXT_H
  26. #include <eda_text.h>
  27. #include <sch_item.h>
  28. #include <sch_field.h>
  29. #include <sch_connection.h> // for CONNECTION_TYPE
  30. class HTML_MESSAGE_BOX;
  31. /*
  32. * Spin style for text items of all kinds on schematics
  33. * Basically a higher level abstraction of rotation and justification of text
  34. */
  35. class TEXT_SPIN_STYLE
  36. {
  37. public:
  38. enum SPIN : int
  39. {
  40. LEFT = 0,
  41. UP = 1,
  42. RIGHT = 2,
  43. BOTTOM = 3
  44. };
  45. TEXT_SPIN_STYLE() = default;
  46. constexpr TEXT_SPIN_STYLE( SPIN aSpin ) : m_spin( aSpin )
  47. {
  48. }
  49. constexpr bool operator==( SPIN a ) const
  50. {
  51. return m_spin == a;
  52. }
  53. constexpr bool operator!=( SPIN a ) const
  54. {
  55. return m_spin != a;
  56. }
  57. operator int() const
  58. {
  59. return static_cast<int>( m_spin );
  60. }
  61. TEXT_SPIN_STYLE RotateCW();
  62. TEXT_SPIN_STYLE RotateCCW();
  63. /**
  64. * Mirror the label spin style across the X axis or simply swaps up and bottom.
  65. */
  66. TEXT_SPIN_STYLE MirrorX();
  67. /**
  68. * Mirror the label spin style across the Y axis or simply swaps left and right.
  69. */
  70. TEXT_SPIN_STYLE MirrorY();
  71. private:
  72. SPIN m_spin;
  73. };
  74. /*
  75. * Label and flag shapes used with text objects.
  76. */
  77. enum LABEL_FLAG_SHAPE
  78. {
  79. L_INPUT,
  80. L_OUTPUT,
  81. L_BIDI,
  82. L_TRISTATE,
  83. L_UNSPECIFIED,
  84. F_FIRST,
  85. F_DOT = F_FIRST,
  86. F_ROUND,
  87. F_DIAMOND,
  88. F_RECTANGLE
  89. };
  90. class SCH_TEXT : public SCH_ITEM, public EDA_TEXT
  91. {
  92. public:
  93. SCH_TEXT( const VECTOR2I& aPos = { 0, 0 }, const wxString& aText = wxEmptyString,
  94. KICAD_T aType = SCH_TEXT_T );
  95. SCH_TEXT( const SCH_TEXT& aText );
  96. ~SCH_TEXT() { }
  97. static inline bool ClassOf( const EDA_ITEM* aItem )
  98. {
  99. return aItem && SCH_TEXT_T == aItem->Type();
  100. }
  101. virtual wxString GetClass() const override
  102. {
  103. return wxT( "SCH_TEXT" );
  104. }
  105. wxString GetShownText( int aDepth = 0, bool aAllowExtraText = true ) const override;
  106. bool IsHypertext() const override
  107. {
  108. return HasHyperlink();
  109. }
  110. void DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const override;
  111. /**
  112. * Set a spin or rotation angle, along with specific horizontal and vertical justification
  113. * styles with each angle.
  114. *
  115. * @param aSpinStyle Spin style as per #TEXT_SPIN_STYLE storage class, may be the enum
  116. * values or int value
  117. */
  118. virtual void SetTextSpinStyle( TEXT_SPIN_STYLE aSpinStyle );
  119. TEXT_SPIN_STYLE GetTextSpinStyle() const { return m_spin_style; }
  120. virtual LABEL_FLAG_SHAPE GetShape() const { return L_UNSPECIFIED; }
  121. virtual void SetShape( LABEL_FLAG_SHAPE aShape ) { }
  122. /**
  123. * This offset depends on the orientation, the type of text, and the area required to
  124. * draw the associated graphic symbol or to put the text above a wire.
  125. *
  126. * @return the offset between the SCH_TEXT position and the text itself position
  127. */
  128. virtual VECTOR2I GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const;
  129. void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& offset ) override;
  130. void SwapData( SCH_ITEM* aItem ) override;
  131. const BOX2I GetBoundingBox() const override;
  132. bool operator<( const SCH_ITEM& aItem ) const override;
  133. int GetTextOffset( const RENDER_SETTINGS* aSettings = nullptr ) const;
  134. int GetPenWidth() const override;
  135. void Move( const VECTOR2I& aMoveVector ) override
  136. {
  137. EDA_TEXT::Offset( aMoveVector );
  138. }
  139. void MirrorHorizontally( int aCenter ) override;
  140. void MirrorVertically( int aCenter ) override;
  141. void Rotate( const VECTOR2I& aCenter ) override;
  142. virtual void Rotate90( bool aClockwise );
  143. virtual void MirrorSpinStyle( bool aLeftRight );
  144. bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
  145. {
  146. return SCH_ITEM::Matches( GetText(), aSearchData );
  147. }
  148. bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) override
  149. {
  150. return EDA_TEXT::Replace( aSearchData );
  151. }
  152. virtual bool IsReplaceable() const override { return true; }
  153. void ViewGetLayers( int aLayers[], int& aCount ) const override;
  154. wxString GetSelectMenuText( UNITS_PROVIDER* aUnitsProvider ) const override;
  155. BITMAPS GetMenuImage() const override;
  156. VECTOR2I GetPosition() const override { return EDA_TEXT::GetTextPos(); }
  157. void SetPosition( const VECTOR2I& aPosition ) override { EDA_TEXT::SetTextPos( aPosition ); }
  158. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
  159. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
  160. void Plot( PLOTTER* aPlotter, bool aBackground ) const override;
  161. EDA_ITEM* Clone() const override
  162. {
  163. return new SCH_TEXT( *this );
  164. }
  165. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  166. #if defined(DEBUG)
  167. void Show( int nestLevel, std::ostream& os ) const override;
  168. #endif
  169. static HTML_MESSAGE_BOX* ShowSyntaxHelp( wxWindow* aParentWindow );
  170. protected:
  171. KIFONT::FONT* getDrawFont() const override;
  172. protected:
  173. /**
  174. * The orientation of text and any associated drawing elements of derived objects.
  175. * - 0 is the horizontal and left justified.
  176. * - 1 is vertical and top justified.
  177. * - 2 is horizontal and right justified. It is the equivalent of the mirrored 0 orientation.
  178. * - 3 is vertical and bottom justified. It is the equivalent of the mirrored 1 orientation.
  179. *
  180. * This is a duplication of m_Orient, m_HJustified, and m_VJustified in #EDA_TEXT but is
  181. * easier to handle than 3 parameters when editing and reading and saving files.
  182. */
  183. TEXT_SPIN_STYLE m_spin_style;
  184. };
  185. #endif /* SCH_TEXT_H */