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.

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