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.

181 lines
5.8 KiB

11 years ago
  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-2023 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_TEXT_H
  25. #define PCB_TEXT_H
  26. #include <eda_text.h>
  27. #include <board_item.h>
  28. class LINE_READER;
  29. class MSG_PANEL_ITEM;
  30. class FOOTPRINT;
  31. class PCB_TEXT : public BOARD_ITEM, public EDA_TEXT
  32. {
  33. public:
  34. PCB_TEXT( BOARD_ITEM* parent, KICAD_T idtype = PCB_TEXT_T );
  35. PCB_TEXT( FOOTPRINT* aParent );
  36. // Do not create a copy constructor & operator=.
  37. // The ones generated by the compiler are adequate.
  38. ~PCB_TEXT();
  39. static inline bool ClassOf( const EDA_ITEM* aItem )
  40. {
  41. return aItem && PCB_TEXT_T == aItem->Type();
  42. }
  43. bool IsType( const std::vector<KICAD_T>& aScanTypes ) const override
  44. {
  45. if( BOARD_ITEM::IsType( aScanTypes ) )
  46. return true;
  47. for( KICAD_T scanType : aScanTypes )
  48. {
  49. if( scanType == PCB_LOCATE_TEXT_T )
  50. return true;
  51. }
  52. return false;
  53. }
  54. void StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings ) override;
  55. /**
  56. * Called when rotating the parent footprint.
  57. */
  58. void KeepUpright( const EDA_ANGLE& aOldOrientation, const EDA_ANGLE& aNewOrientation );
  59. wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override;
  60. bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override;
  61. virtual VECTOR2I GetPosition() const override
  62. {
  63. return EDA_TEXT::GetTextPos();
  64. }
  65. virtual void SetPosition( const VECTOR2I& aPos ) override
  66. {
  67. EDA_TEXT::SetTextPos( aPos );
  68. }
  69. void Move( const VECTOR2I& aMoveVector ) override
  70. {
  71. EDA_TEXT::Offset( aMoveVector );
  72. }
  73. void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
  74. void Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis );
  75. void Flip( const VECTOR2I& aCentre, bool aFlipLeftRight ) override;
  76. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  77. bool TextHitTest( const VECTOR2I& aPoint, int aAccuracy = 0 ) const override;
  78. bool TextHitTest( const BOX2I& aRect, bool aContains, int aAccuracy = 0 ) const override;
  79. bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override
  80. {
  81. return TextHitTest( aPosition, aAccuracy );
  82. }
  83. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override
  84. {
  85. return TextHitTest( aRect, aContained, aAccuracy );
  86. }
  87. wxString GetClass() const override
  88. {
  89. return wxT( "PCB_TEXT" );
  90. }
  91. /**
  92. * Function TransformTextToPolySet
  93. * Convert the text to a polygonSet describing the actual character strokes (one per segment).
  94. * Circles and arcs are approximated by segments.
  95. * @param aBuffer SHAPE_POLY_SET to store the polygon corners
  96. * @param aClearance the clearance around the text
  97. * @param aMaxError the maximum error to allow when approximating curves
  98. */
  99. void TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance, int aMaxError,
  100. ERROR_LOC aErrorLoc ) const;
  101. void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
  102. int aMaxError, ERROR_LOC aErrorLoc,
  103. bool aIgnoreLineWidth = false ) const override;
  104. // @copydoc BOARD_ITEM::GetEffectiveShape
  105. virtual std::shared_ptr<SHAPE>
  106. GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
  107. FLASHING aFlash = FLASHING::DEFAULT ) const override;
  108. virtual wxString GetTextTypeDescription() const;
  109. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
  110. BITMAPS GetMenuImage() const override;
  111. /**
  112. * @return the text rotation for drawings and plotting the footprint rotation is taken
  113. * in account.
  114. */
  115. EDA_ANGLE GetDrawRotation() const override;
  116. const BOX2I ViewBBox() const override;
  117. void ViewGetLayers( int aLayers[], int& aCount ) const override;
  118. ///< @copydoc VIEW_ITEM::ViewGetLOD
  119. double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
  120. // Virtual function
  121. const BOX2I GetBoundingBox() const override;
  122. EDA_ITEM* Clone() const override;
  123. #if defined(DEBUG)
  124. virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  125. #endif
  126. protected:
  127. /**
  128. * Build a nominally rectangular bounding box for the rendered text. (It's not a BOX2I
  129. * because it will be a diamond shape for non-cardinally rotated text.)
  130. */
  131. void buildBoundingHull( SHAPE_POLY_SET* aBuffer, const SHAPE_POLY_SET& aRenderedText,
  132. int aClearance ) const;
  133. virtual void swapData( BOARD_ITEM* aImage ) override;
  134. int getKnockoutMargin() const;
  135. };
  136. #endif // #define PCB_TEXT_H