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.

151 lines
4.7 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-2017 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_text.h
  26. */
  27. #ifndef _LIB_TEXT_H_
  28. #define _LIB_TEXT_H_
  29. #include <eda_text.h>
  30. #include <lib_draw_item.h>
  31. /**
  32. * Define a symbol library graphical text item.
  33. * <p>
  34. * This is only a graphical text item. Field text like the reference designator,
  35. * symbol value, etc. are not LIB_TEXT items. See the #LIB_FIELD class for the
  36. * field item definition.
  37. * </p>
  38. */
  39. class LIB_TEXT : public LIB_ITEM, public EDA_TEXT
  40. {
  41. wxString m_savedText; ///< Temporary storage for the string when editing.
  42. bool m_rotate; ///< Flag to indicate a rotation occurred while editing.
  43. bool m_updateText; ///< Flag to indicate text change occurred while editing.
  44. void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, void* aData,
  45. const TRANSFORM& aTransform ) override;
  46. void CalcEdit( const wxPoint& aPosition ) override;
  47. public:
  48. LIB_TEXT( LIB_PART * aParent );
  49. // Do not create a copy constructor. The one generated by the compiler is adequate.
  50. ~LIB_TEXT() { }
  51. wxString GetClass() const override
  52. {
  53. return wxT( "LIB_TEXT" );
  54. }
  55. wxString GetTypeName() override
  56. {
  57. return _( "Text" );
  58. }
  59. void ViewGetLayers( int aLayers[], int& aCount ) const override;
  60. /**
  61. * Sets the text item string to \a aText.
  62. *
  63. * This method does more than just set the set the text string. There are special
  64. * cases when changing the text string alone is not enough. If the text item is
  65. * being moved, the name change must be delayed until the next redraw to prevent
  66. * drawing artifacts.
  67. *
  68. * @param aText - New text value.
  69. */
  70. void SetText( const wxString& aText ) override;
  71. bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
  72. bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override
  73. {
  74. return TextHitTest( aRect, aContained, aAccuracy );
  75. }
  76. int GetPenSize( ) const override;
  77. void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override;
  78. const EDA_RECT GetBoundingBox() const override;
  79. void Rotate() override;
  80. void BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) ) override;
  81. bool ContinueEdit( const wxPoint aNextPoint ) override;
  82. void EndEdit( const wxPoint& aPosition, bool aAbort = false ) override;
  83. void SetOffset( const wxPoint& aOffset ) override;
  84. bool Inside( EDA_RECT& aRect ) const override;
  85. void Move( const wxPoint& aPosition ) override;
  86. wxPoint GetPosition() const override { return EDA_TEXT::GetTextPos(); }
  87. void MirrorHorizontal( const wxPoint& aCenter ) override;
  88. void MirrorVertical( const wxPoint& aCenter ) override;
  89. void Rotate( const wxPoint& aCenter, bool aRotateCCW = true ) override;
  90. void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
  91. const TRANSFORM& aTransform ) override;
  92. int GetWidth() const override { return GetThickness(); }
  93. void SetWidth( int aWidth ) override { SetThickness( aWidth ); }
  94. wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
  95. BITMAP_DEF GetMenuImage() const override;
  96. EDA_ITEM* Clone() const override;
  97. private:
  98. /**
  99. * @copydoc LIB_ITEM::compare()
  100. *
  101. * The text specific sort order is as follows:
  102. * - Text string, case insensitive compare.
  103. * - Text horizontal (X) position.
  104. * - Text vertical (Y) position.
  105. * - Text width.
  106. * - Text height.
  107. */
  108. int compare( const LIB_ITEM& aOther ) const override;
  109. };
  110. #endif // _LIB_TEXT_H_