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.

153 lines
5.2 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #ifndef FP_TEXTBOX_H
  24. #define FP_TEXTBOX_H
  25. #include <eda_text.h>
  26. #include <fp_shape.h>
  27. class LINE_READER;
  28. class EDA_RECT;
  29. class FOOTPRINT;
  30. class MSG_PANEL_ITEM;
  31. class PCB_BASE_FRAME;
  32. class SHAPE;
  33. class FP_TEXTBOX : public FP_SHAPE, public EDA_TEXT
  34. {
  35. public:
  36. FP_TEXTBOX( FOOTPRINT* aParentFootprint );
  37. // Do not create a copy constructor & operator=.
  38. // The ones generated by the compiler are adequate.
  39. ~FP_TEXTBOX();
  40. static inline bool ClassOf( const EDA_ITEM* aItem )
  41. {
  42. return aItem && aItem->Type() == PCB_FP_TEXT_T;
  43. }
  44. bool IsType( const KICAD_T aScanTypes[] ) const override
  45. {
  46. if( BOARD_ITEM::IsType( aScanTypes ) )
  47. return true;
  48. for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
  49. {
  50. if( *p == PCB_LOCATE_TEXT_T )
  51. return true;
  52. }
  53. return false;
  54. }
  55. VECTOR2I GetTopLeft() const override;
  56. VECTOR2I GetBotRight() const override;
  57. void SetTop( int aVal ) override;
  58. void SetLeft( int aVal ) override;
  59. void SetRight( int aVal ) override;
  60. void SetBottom( int aVal ) override;
  61. wxString GetParentAsString() const { return m_parent->m_Uuid.AsString(); }
  62. bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override
  63. {
  64. return BOARD_ITEM::Matches( GetShownText(), aSearchData );
  65. }
  66. int GetTextMargin() const;
  67. virtual EDA_ANGLE GetDrawRotation() const override;
  68. VECTOR2I GetDrawPos() const override;
  69. std::vector<VECTOR2I> GetAnchorAndOppositeCorner() const;
  70. void Move( const VECTOR2I& aMoveVector ) override;
  71. /// Rotate text, in footprint editor
  72. /// (for instance in footprint rotation transform)
  73. void Rotate( const VECTOR2I& aOffset, const EDA_ANGLE& aAngle ) override;
  74. /// Flip entity during footprint flip
  75. void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override;
  76. /// Mirror text position in footprint editing
  77. /// the text itself is not mirrored, and the layer not modified,
  78. /// only position is mirrored.
  79. /// (use Flip to change layer to its paired and mirror the text in fp editor).
  80. void Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis );
  81. // The Pos0 accessors are for footprint-relative coordinates.
  82. void SetPos0( const VECTOR2I& aPos ) { m_Pos0 = aPos; SetDrawCoord(); }
  83. const VECTOR2I& GetPos0() const { return m_Pos0; }
  84. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  85. bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override;
  86. bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
  87. void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, PCB_LAYER_ID aLayer,
  88. int aClearance, int aError, ERROR_LOC aErrorLoc,
  89. bool aIgnoreLineWidth ) const override;
  90. void TransformTextShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
  91. PCB_LAYER_ID aLayer, int aClearanceValue,
  92. int aError, ERROR_LOC aErrorLoc ) const;
  93. // @copydoc BOARD_ITEM::GetEffectiveShape
  94. std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
  95. FLASHING aFlash = FLASHING::DEFAULT ) const override;
  96. wxString GetClass() const override
  97. {
  98. return wxT( "FP_TEXTBOX" );
  99. }
  100. wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
  101. BITMAPS GetMenuImage() const override;
  102. EDA_ITEM* Clone() const override;
  103. virtual wxString GetShownText( int aDepth = 0 ) const override;
  104. virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
  105. double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
  106. #if defined(DEBUG)
  107. virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  108. #endif
  109. private:
  110. VECTOR2I m_Pos0; ///< text coordinates relative to the footprint anchor, orient 0.
  111. ///< text coordinate ref point is the text center
  112. };
  113. #endif // FP_TEXTBOX_H