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.

183 lines
6.4 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 The 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 PCB_TEXTBOX_H
  25. #define PCB_TEXTBOX_H
  26. #include <eda_text.h>
  27. #include <pcb_shape.h>
  28. class LINE_READER;
  29. class MSG_PANEL_ITEM;
  30. class PCB_TEXTBOX : public PCB_SHAPE, public EDA_TEXT
  31. {
  32. public:
  33. PCB_TEXTBOX( BOARD_ITEM* aParent, KICAD_T aType = PCB_TEXTBOX_T );
  34. // Do not create a copy constructor & operator=.
  35. // The ones generated by the compiler are adequate.
  36. ~PCB_TEXTBOX();
  37. void CopyFrom( const BOARD_ITEM* aOther ) override;
  38. static inline bool ClassOf( const EDA_ITEM* aItem )
  39. {
  40. return aItem && PCB_TEXTBOX_T == aItem->Type();
  41. }
  42. bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
  43. {
  44. if( BOARD_ITEM::IsType( aScanTypes ) )
  45. return true;
  46. for( KICAD_T scanType : aScanTypes )
  47. {
  48. if( scanType == PCB_LOCATE_TEXT_T )
  49. return true;
  50. }
  51. return false;
  52. }
  53. void Serialize( google::protobuf::Any &aContainer ) const override;
  54. bool Deserialize( const google::protobuf::Any &aContainer ) override;
  55. wxString GetFriendlyName() const override { return _( "Text Box" ); }
  56. VECTOR2I GetTopLeft() const override;
  57. VECTOR2I GetBotRight() const override;
  58. void SetTop( int aVal ) override;
  59. void SetLeft( int aVal ) override;
  60. void SetRight( int aVal ) override;
  61. void SetBottom( int aVal ) override;
  62. void StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings ) override;
  63. int GetLegacyTextMargin() const;
  64. void SetMarginLeft( int aLeft ) { m_marginLeft = aLeft; }
  65. void SetMarginTop( int aTop ) { m_marginTop = aTop; }
  66. void SetMarginRight( int aRight ) { m_marginRight = aRight; }
  67. void SetMarginBottom( int aBottom ) { m_marginBottom = aBottom; }
  68. int GetMarginLeft() const { return m_marginLeft; }
  69. int GetMarginTop() const { return m_marginTop; }
  70. int GetMarginRight() const { return m_marginRight; }
  71. int GetMarginBottom() const { return m_marginBottom; }
  72. VECTOR2I GetDrawPos() const override;
  73. VECTOR2I GetDrawPos( bool aIsFlipped ) const;
  74. void SetTextAngle( const EDA_ANGLE& aAngle ) override;
  75. wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override;
  76. bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
  77. void Move( const VECTOR2I& aMoveVector ) override;
  78. void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
  79. void Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
  80. void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
  81. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  82. bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override;
  83. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
  84. wxString GetClass() const override
  85. {
  86. return wxT( "PCB_TEXTBOX" );
  87. }
  88. /**
  89. * Function TransformTextToPolySet
  90. * Convert the text to a polygonSet describing the actual character strokes (one per segment).
  91. * Used in 3D viewer
  92. * Circles and arcs are approximated by segments
  93. * @param aBuffer = SHAPE_POLY_SET to store the polygon corners
  94. * @param aClearance = the clearance around the text
  95. * @param aError = the maximum error to allow when approximating curves
  96. */
  97. void TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance, int aMaxError,
  98. ERROR_LOC aErrorLoc ) const;
  99. void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
  100. int aMaxError, ERROR_LOC aErrorLoc,
  101. bool aIgnoreLineWidth = false ) const override;
  102. // @copydoc BOARD_ITEM::GetEffectiveShape
  103. std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
  104. FLASHING aFlash = FLASHING::DEFAULT ) const override;
  105. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
  106. BITMAPS GetMenuImage() const override;
  107. double ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const override;
  108. std::vector<int> ViewGetLayers() const override;
  109. EDA_ITEM* Clone() const override;
  110. ///< Tests whether the border is disabled, as configured by the stroke
  111. bool IsBorderEnabled() const;
  112. ///< Disables the border, this is done by changing the stroke internally
  113. void SetBorderEnabled( bool enabled );
  114. void SetBorderWidth( const int aSize );
  115. int GetBorderWidth() const { return m_stroke.GetWidth(); }
  116. double Similarity( const BOARD_ITEM& aBoardItem ) const override;
  117. bool operator==( const PCB_TEXTBOX& aOther ) const;
  118. bool operator==( const BOARD_ITEM& aBoardItem ) const override;
  119. protected:
  120. EDA_ANGLE getDrawRotation() const override { return GetDrawRotation(); }
  121. virtual void swapData( BOARD_ITEM* aImage ) override;
  122. const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
  123. protected:
  124. bool m_borderEnabled; ///< Controls drawing the border (as defined by the stroke members)
  125. private:
  126. int m_marginLeft;
  127. int m_marginTop;
  128. int m_marginRight;
  129. int m_marginBottom;
  130. };
  131. #endif // #define PCB_TEXTBOX_H