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.

155 lines
5.2 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) 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 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* parent );
  34. // Do not create a copy constructor & operator=.
  35. // The ones generated by the compiler are adequate.
  36. ~PCB_TEXTBOX();
  37. static inline bool ClassOf( const EDA_ITEM* aItem )
  38. {
  39. return aItem && PCB_TEXTBOX_T == aItem->Type();
  40. }
  41. bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
  42. {
  43. if( BOARD_ITEM::IsType( aScanTypes ) )
  44. return true;
  45. for( KICAD_T scanType : aScanTypes )
  46. {
  47. if( scanType == PCB_LOCATE_TEXT_T )
  48. return true;
  49. }
  50. return false;
  51. }
  52. wxString GetFriendlyName() const override { return _( "Text Box" ); }
  53. VECTOR2I GetTopLeft() const override;
  54. VECTOR2I GetBotRight() const override;
  55. void SetTop( int aVal ) override;
  56. void SetLeft( int aVal ) override;
  57. void SetRight( int aVal ) override;
  58. void SetBottom( int aVal ) override;
  59. int GetTextMargin() const;
  60. VECTOR2I GetDrawPos() const override;
  61. void SetTextAngle( const EDA_ANGLE& aAngle ) override;
  62. wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override;
  63. /// PCB_TEXTBOXes are always visible:
  64. void SetVisible( bool aVisible ) override { /* do nothing */}
  65. bool IsVisible() const override { return true; }
  66. bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
  67. std::vector<VECTOR2I> GetAnchorAndOppositeCorner() const;
  68. void Move( const VECTOR2I& aMoveVector ) override;
  69. void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
  70. void Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis ) override;
  71. void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override;
  72. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  73. bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override;
  74. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
  75. wxString GetClass() const override
  76. {
  77. return wxT( "PCB_TEXTBOX" );
  78. }
  79. /**
  80. * Function TransformTextToPolySet
  81. * Convert the text to a polygonSet describing the actual character strokes (one per segment).
  82. * Used in 3D viewer
  83. * Circles and arcs are approximated by segments
  84. * @param aBuffer = SHAPE_POLY_SET to store the polygon corners
  85. * @param aClearance = the clearance around the text
  86. * @param aError = the maximum error to allow when approximating curves
  87. */
  88. void TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance, int aMaxError,
  89. ERROR_LOC aErrorLoc ) const;
  90. void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
  91. int aMaxError, ERROR_LOC aErrorLoc,
  92. bool aIgnoreLineWidth = false ) const override;
  93. // @copydoc BOARD_ITEM::GetEffectiveShape
  94. virtual std::shared_ptr<SHAPE>
  95. GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
  96. FLASHING aFlash = FLASHING::DEFAULT ) const override;
  97. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
  98. BITMAPS GetMenuImage() const override;
  99. double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
  100. void ViewGetLayers( int aLayers[], int& aCount ) const override;
  101. EDA_ITEM* Clone() const override;
  102. ///< Tests whether the border is disabled, as configured by the stroke
  103. bool IsBorderEnabled() const;
  104. ///< Disables the border, this is done by changing the stroke internally
  105. void SetBorderEnabled( bool enabled );
  106. protected:
  107. bool m_borderEnabled; ///< Controls drawing the border (as defined by the stroke members)
  108. virtual void swapData( BOARD_ITEM* aImage ) override;
  109. const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
  110. };
  111. #endif // #define PCB_TEXTBOX_H