KiCad PCB EDA Suite
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2004 Jean-Pierre Charras,
5  * Copyright (C) 1992-2021 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
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  *
20  * or you may search the 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  */
25 #ifndef FP_TEXT_H
26 #define FP_TEXT_H
28 #include <eda_text.h>
29 #include <board_item.h>
31 class LINE_READER;
32 class EDA_RECT;
33 class FOOTPRINT;
34 class MSG_PANEL_ITEM;
35 class PCB_BASE_FRAME;
36 class SHAPE;
39 class FP_TEXT : public BOARD_ITEM, public EDA_TEXT
40 {
41 public:
48  enum TEXT_TYPE
49  {
53  };
55  FP_TEXT( FOOTPRINT* aParentFootprint, TEXT_TYPE text_type = TEXT_is_DIVERS );
57  // Do not create a copy constructor & operator=.
58  // The ones generated by the compiler are adequate.
60  ~FP_TEXT();
62  static inline bool ClassOf( const EDA_ITEM* aItem )
63  {
64  return aItem && aItem->Type() == PCB_FP_TEXT_T;
65  }
67  bool IsType( const KICAD_T aScanTypes[] ) const override
68  {
69  if( BOARD_ITEM::IsType( aScanTypes ) )
70  return true;
72  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
73  {
74  if( *p == PCB_LOCATE_TEXT_T )
75  return true;
76  }
78  return false;
79  }
81  wxString GetParentAsString() const { return m_parent->m_Uuid.AsString(); }
83  bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override
84  {
85  return BOARD_ITEM::Matches( GetShownText(), aSearchData );
86  }
88  virtual wxPoint GetPosition() const override
89  {
90  return EDA_TEXT::GetTextPos();
91  }
93  virtual void SetPosition( const wxPoint& aPos ) override
94  {
95  EDA_TEXT::SetTextPos( aPos );
96  SetLocalCoord();
97  }
99  void SetTextAngle( double aAngle ) override;
104  void KeepUpright( double aOldOrientation, double aNewOrientation );
110  bool IsKeepUpright() const
111  {
112  return m_keepUpright;
113  }
115  void SetKeepUpright( bool aKeepUpright )
116  {
117  m_keepUpright = aKeepUpright;
118  }
122  void Rotate( const wxPoint& aOffset, double aAngle ) override;
125  void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
127  bool IsParentFlipped() const;
133  void Mirror( const wxPoint& aCentre, bool aMirrorAroundXAxis );
136  void Move( const wxPoint& aMoveVector ) override;
139  // reference and value from deletion, and for identification)
140  void SetType( TEXT_TYPE aType ) { m_Type = aType; }
141  TEXT_TYPE GetType() const { return m_Type; }
146  void SetEffects( const FP_TEXT& aSrc )
147  {
148  EDA_TEXT::SetEffects( aSrc );
149  SetLocalCoord();
150  // SetType( aSrc.GetType() );
151  }
156  void SwapEffects( FP_TEXT& aTradingPartner )
157  {
158  EDA_TEXT::SwapEffects( aTradingPartner );
159  SetLocalCoord();
160  aTradingPartner.SetLocalCoord();
161  // std::swap( m_Type, aTradingPartner.m_Type );
162  }
164  // The Pos0 accessors are for footprint-relative coordinates.
165  void SetPos0( const wxPoint& aPos ) { m_Pos0 = aPos; SetDrawCoord(); }
166  const wxPoint& GetPos0() const { return m_Pos0; }
168  int GetLength() const; // text length
174  virtual double GetDrawRotation() const override;
175  double GetDrawRotationRadians() const { return GetDrawRotation() * M_PI/1800; }
177  // Virtual function
178  const EDA_RECT GetBoundingBox() const override;
181  void SetDrawCoord();
184  void SetLocalCoord();
186  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
188  bool TextHitTest( const wxPoint& aPoint, int aAccuracy = 0 ) const override;
189  bool TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy = 0 ) const override;
191  bool HitTest( const wxPoint& aPosition, int aAccuracy ) const override
192  {
193  return TextHitTest( aPosition, aAccuracy );
194  }
196  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override
197  {
198  return TextHitTest( aRect, aContained, aAccuracy );
199  }
202  int aClearance, int aError, ERROR_LOC aErrorLoc,
203  bool aIgnoreLineWidth ) const override;
206  PCB_LAYER_ID aLayer, int aClearanceValue,
207  int aError, ERROR_LOC aErrorLoc ) const;
209  // @copydoc BOARD_ITEM::GetEffectiveShape
210  virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER ) const override;
212  wxString GetClass() const override
213  {
214  return wxT( "MTEXT" );
215  }
217  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
219  BITMAP_DEF GetMenuImage() const override;
221  EDA_ITEM* Clone() const override;
223  virtual wxString GetShownText( int aDepth = 0 ) const override;
225  virtual const BOX2I ViewBBox() const override;
227  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
229  double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
231 #if defined(DEBUG)
232  virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
233 #endif
235 private:
236  /* Note: orientation in 1/10 deg relative to the footprint
237  * Physical orient is m_Orient + m_Parent->m_Orient
238  */
242  wxPoint m_Pos0;
248 };
250 #endif // FP_TEXT_H
wxString GetClass() const override
Return the class name.
Definition: fp_text.h:212
virtual double GetDrawRotation() const override
Definition: fp_text.cpp:247
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: fp_text.cpp:341
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:528
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:80
virtual bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:414
void KeepUpright(double aOldOrientation, double aNewOrientation)
Called when rotating the parent footprint.
Definition: fp_text.cpp:101
void TransformTextShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, PCB_LAYER_ID aLayer, int aClearanceValue, int aError, ERROR_LOC aErrorLoc) const
Function TransformTextShapeWithClearanceToPolygon Convert the text to a polygonSet describing the act...
void SwapEffects(EDA_TEXT &aTradingPartner)
Swap the text effects of the two involved instances.
Definition: eda_text.cpp:151
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
virtual void SetPosition(const wxPoint &aPos) override
Definition: fp_text.h:93
PNG memory record (file in memory).
Definition: bitmap_def.h:29
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: fp_text.cpp:347
bool IsKeepUpright() const
Definition: fp_text.h:110
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
void Move(const wxPoint &aMoveVector) override
move text in move transform, in footprint editor
Definition: fp_text.cpp:185
void SetTextAngle(double aAngle) override
Definition: fp_text.cpp:69
void SetEffects(const EDA_TEXT &aSrc)
Set the text effects from another instance.
Definition: eda_text.cpp:137
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:253
void SetDrawCoord()
Set relative coordinates.
Definition: fp_text.cpp:198
wxString AsString() const
Definition: kiid.cpp:213
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition: fp_text.cpp:273
double ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition: fp_text.cpp:370
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: fp_text.cpp:444
void Rotate(const wxPoint &aOffset, double aAngle) override
Rotate text, in footprint editor (for instance in footprint rotation transform)
Definition: fp_text.cpp:128
The base class for create windows for drawing purpose.
void SetType(TEXT_TYPE aType)
Definition: fp_text.h:140
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool aIgnoreLineWidth) const override
Convert the item shape to a closed polygon.
void Mirror(const wxPoint &aCentre, bool aMirrorAroundXAxis)
Mirror text position in footprint editing the text itself is not mirrored, and the layer not modified...
Definition: fp_text.cpp:172
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
Definition: fp_text.cpp:359
search types array terminator (End Of Types)
Definition: typeinfo.h:81
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:119
A quick note on layer IDs:
wxPoint m_Pos0
text coordinates relative to the footprint anchor, orient 0.
Definition: fp_text.h:242
double GetDrawRotationRadians() const
Definition: fp_text.h:175
static bool ClassOf(const EDA_ITEM *aItem)
Definition: fp_text.h:62
bool IsType(const KICAD_T aScanTypes[]) const override
Check whether the item is one of the listed types.
Definition: fp_text.h:67
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Flip entity during footprint flip.
Definition: fp_text.cpp:142
FP_TEXT(FOOTPRINT *aParentFootprint, TEXT_TYPE text_type=TEXT_is_DIVERS)
Definition: fp_text.cpp:35
TEXT_TYPE GetType() const
Definition: fp_text.h:141
Represent a set of closed polygons.
bool HitTest(const wxPoint &aPosition, int aAccuracy) const override
Test if aPosition is contained within or on the bounding box of an item.
Definition: fp_text.h:191
bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
Definition: fp_text.h:83
virtual bool IsType(const KICAD_T aScanTypes[]) const
Check whether the item is one of the listed types.
Definition: eda_item.h:232
bool m_keepUpright
if true, keep rotation angle between -90 .
Definition: fp_text.h:245
An abstract shape on 2D plane.
Definition: shape.h:116
int GetLength() const
Definition: fp_text.cpp:192
bool HitTest(const EDA_RECT &aRect, bool aContained, int aAccuracy=0) const override
Test if aRect intersects or is contained within the bounding box of an item.
Definition: fp_text.h:196
Footprint text type: there must be only one (and only one) for each of the reference value texts in o...
Definition: fp_text.h:48
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: fp_text.cpp:314
0=ref, 1=val, etc.
Definition: fp_text.h:240
void SetPos0(const wxPoint &aPos)
Definition: fp_text.h:165
void SetEffects(const FP_TEXT &aSrc)
Set the text effects from another instance.
Definition: fp_text.h:146
const KIID m_Uuid
Definition: eda_item.h:524
const wxPoint & GetPos0() const
Definition: fp_text.h:166
Definition: eda_units.h:38
BITMAP_DEF GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: fp_text.cpp:335
void SetKeepUpright(bool aKeepUpright)
Definition: fp_text.h:115
const EDA_RECT GetBoundingBox() const override
Set absolute coordinates.
Definition: fp_text.cpp:235
bool IsParentFlipped() const
Definition: fp_text.cpp:164
Handle the component boundary box.
Definition: eda_rect.h:42
void SetLocalCoord()
Definition: fp_text.cpp:217
wxString GetParentAsString() const
Definition: fp_text.h:81
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:149
void SwapEffects(FP_TEXT &aTradingPartner)
Swap the text effects of the two involved instances.
Definition: fp_text.h:156
const wxPoint & GetTextPos() const
Definition: eda_text.h:254
bool TextHitTest(const wxPoint &aPoint, int aAccuracy=0) const override
Test if aPoint is within the bounds of this object.
Definition: fp_text.cpp:75
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:54
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
virtual wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: fp_text.cpp:408
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
Definition: fp_text.cpp:64
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:162
virtual wxPoint GetPosition() const override
Definition: fp_text.h:88