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, [email protected]
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,
211  FLASHING aFlash = FLASHING::DEFAULT ) const override;
213  wxString GetClass() const override
214  {
215  return wxT( "MTEXT" );
216  }
218  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
220  BITMAPS GetMenuImage() const override;
222  EDA_ITEM* Clone() const override;
224  virtual wxString GetShownText( int aDepth = 0 ) const override;
226  virtual const BOX2I ViewBBox() const override;
228  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
230  double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
232 #if defined(DEBUG)
233  virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
234 #endif
236 private:
237  /* Note: orientation in 1/10 deg relative to the footprint
238  * Physical orient is m_Orient + m_Parent->m_Orient
239  */
243  wxPoint m_Pos0;
249 };
251 #endif // FP_TEXT_H
wxString GetClass() const override
Return the class name.
Definition: fp_text.h:213
virtual double GetDrawRotation() const override
Definition: fp_text.cpp:239
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: fp_text.cpp:339
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:478
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:364
void KeepUpright(double aOldOrientation, double aNewOrientation)
Called when rotating the parent footprint.
Definition: fp_text.cpp:105
void TransformTextShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, PCB_LAYER_ID aLayer, int aClearanceValue, int aError, ERROR_LOC aErrorLoc) const
Definition: fp_text.cpp:452
void SwapEffects(EDA_TEXT &aTradingPartner)
Swap the text effects of the two involved instances.
Definition: eda_text.cpp:153
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
virtual void SetPosition(const wxPoint &aPos) override
Definition: fp_text.h:93
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: fp_text.cpp:345
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:49
void Move(const wxPoint &aMoveVector) override
move text in move transform, in footprint editor
Definition: fp_text.cpp:177
void SetTextAngle(double aAngle) override
Definition: fp_text.cpp:73
void SetEffects(const EDA_TEXT &aSrc)
Set the text effects from another instance.
Definition: eda_text.cpp:139
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:267
void SetDrawCoord()
Set relative coordinates.
Definition: fp_text.cpp:190
wxString AsString() const
Definition: kiid.cpp:236
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:265
double ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition: fp_text.cpp:368
void Rotate(const wxPoint &aOffset, double aAngle) override
Rotate text, in footprint editor (for instance in footprint rotation transform)
Definition: fp_text.cpp:123
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.
Definition: fp_text.cpp:473
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:164
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:357
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:140
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: fp_text.cpp:333
wxPoint m_Pos0
text coordinates relative to the footprint anchor, orient 0.
Definition: fp_text.h:243
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:137
FP_TEXT(FOOTPRINT *aParentFootprint, TEXT_TYPE text_type=TEXT_is_DIVERS)
Definition: fp_text.cpp:39
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 inside or on the boundary of this 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:182
bool m_keepUpright
if true, keep rotation angle between -90 .
Definition: fp_text.h:246
An abstract shape on 2D plane.
Definition: shape.h:116
int GetLength() const
Definition: fp_text.cpp:184
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: fp_text.cpp:446
bool HitTest(const EDA_RECT &aRect, bool aContained, int aAccuracy=0) const override
Test if aRect intersects this 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:312
0=ref, 1=val, etc.
Definition: fp_text.h:241
void SetPos0(const wxPoint &aPos)
Definition: fp_text.h:165
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:153
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:474
const wxPoint & GetPos0() const
Definition: fp_text.h:166
Definition: eda_units.h:38
void SetKeepUpright(bool aKeepUpright)
Definition: fp_text.h:115
const EDA_RECT GetBoundingBox() const override
Set absolute coordinates.
Definition: fp_text.cpp:227
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
A quick note on layer IDs:
Definition: layer_ids.h:65
bool IsParentFlipped() const
Definition: fp_text.cpp:156
Handle the component boundary box.
Definition: eda_rect.h:42
void SetLocalCoord()
Definition: fp_text.cpp:209
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:99
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:268
bool TextHitTest(const wxPoint &aPoint, int aAccuracy=0) const override
Test if aPoint is within the bounds of this object.
Definition: fp_text.cpp:79
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:53
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
virtual wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: fp_text.cpp:411
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
Definition: fp_text.cpp:68
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
virtual wxPoint GetPosition() const override
Definition: fp_text.h:88