KiCad PCB EDA Suite
fp_text.h
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, jaen-pierre.charras@gipsa-lab.inpg.com
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
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 
25 #ifndef FP_TEXT_H
26 #define FP_TEXT_H
27 
28 #include <eda_text.h>
29 #include <board_item.h>
30 
31 class LINE_READER;
32 class EDA_RECT;
33 class FOOTPRINT;
34 class MSG_PANEL_ITEM;
35 class PCB_BASE_FRAME;
36 class SHAPE;
37 
38 
39 class FP_TEXT : public BOARD_ITEM, public EDA_TEXT
40 {
41 public:
48  enum TEXT_TYPE
49  {
53  };
54 
55  FP_TEXT( FOOTPRINT* aParentFootprint, TEXT_TYPE text_type = TEXT_is_DIVERS );
56 
57  // Do not create a copy constructor & operator=.
58  // The ones generated by the compiler are adequate.
59 
60  ~FP_TEXT();
61 
62  static inline bool ClassOf( const EDA_ITEM* aItem )
63  {
64  return aItem && aItem->Type() == PCB_FP_TEXT_T;
65  }
66 
67  bool IsType( const KICAD_T aScanTypes[] ) const override
68  {
69  if( BOARD_ITEM::IsType( aScanTypes ) )
70  return true;
71 
72  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
73  {
74  if( *p == PCB_LOCATE_TEXT_T )
75  return true;
76  }
77 
78  return false;
79  }
80 
81  wxString GetParentAsString() const { return m_parent->m_Uuid.AsString(); }
82 
83  bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override
84  {
85  return BOARD_ITEM::Matches( GetShownText(), aSearchData );
86  }
87 
88  virtual wxPoint GetPosition() const override
89  {
90  return EDA_TEXT::GetTextPos();
91  }
92 
93  virtual void SetPosition( const wxPoint& aPos ) override
94  {
95  EDA_TEXT::SetTextPos( aPos );
96  SetLocalCoord();
97  }
98 
99  void SetTextAngle( double aAngle ) override;
100 
104  void KeepUpright( double aOldOrientation, double aNewOrientation );
105 
110  bool IsKeepUpright() const
111  {
112  return m_keepUpright;
113  }
114 
115  void SetKeepUpright( bool aKeepUpright )
116  {
117  m_keepUpright = aKeepUpright;
118  }
119 
122  void Rotate( const wxPoint& aOffset, double aAngle ) override;
123 
125  void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
126 
127  bool IsParentFlipped() const;
128 
133  void Mirror( const wxPoint& aCentre, bool aMirrorAroundXAxis );
134 
136  void Move( const wxPoint& aMoveVector ) override;
137 
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; }
142 
146  void SetEffects( const FP_TEXT& aSrc )
147  {
148  EDA_TEXT::SetEffects( aSrc );
149  SetLocalCoord();
150  // SetType( aSrc.GetType() );
151  }
152 
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  }
163 
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; }
167 
168  int GetLength() const; // text length
169 
174  virtual double GetDrawRotation() const override;
175  double GetDrawRotationRadians() const { return GetDrawRotation() * M_PI/1800; }
176 
177  // Virtual function
178  const EDA_RECT GetBoundingBox() const override;
179 
181  void SetDrawCoord();
182 
184  void SetLocalCoord();
185 
186  void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
187 
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;
190 
191  bool HitTest( const wxPoint& aPosition, int aAccuracy ) const override
192  {
193  return TextHitTest( aPosition, aAccuracy );
194  }
195 
196  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override
197  {
198  return TextHitTest( aRect, aContained, aAccuracy );
199  }
200 
202  int aClearance, int aError, ERROR_LOC aErrorLoc,
203  bool aIgnoreLineWidth ) const override;
204 
206  PCB_LAYER_ID aLayer, int aClearanceValue,
207  int aError, ERROR_LOC aErrorLoc ) const;
208 
209  // @copydoc BOARD_ITEM::GetEffectiveShape
210  virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER ) const override;
211 
212  wxString GetClass() const override
213  {
214  return wxT( "MTEXT" );
215  }
216 
217  wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
218 
219  BITMAPS GetMenuImage() const override;
220 
221  EDA_ITEM* Clone() const override;
222 
223  virtual wxString GetShownText( int aDepth = 0 ) const override;
224 
225  virtual const BOX2I ViewBBox() const override;
226 
227  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
228 
229  double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override;
230 
231 #if defined(DEBUG)
232  virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
233 #endif
234 
235 private:
236  /* Note: orientation in 1/10 deg relative to the footprint
237  * Physical orient is m_Orient + m_Parent->m_Orient
238  */
239 
241 
242  wxPoint m_Pos0;
243 
246 
248 };
249 
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:239
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: fp_text.cpp:334
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:479
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:365
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
void SwapEffects(EDA_TEXT &aTradingPartner)
Swap the text effects of the two involved instances.
Definition: eda_text.cpp:143
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:340
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:80
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:129
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:246
void SetDrawCoord()
Set relative coordinates.
Definition: fp_text.cpp:190
wxString AsString() const
Definition: kiid.cpp:218
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:363
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:449
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.
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:352
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
ERROR_LOC
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
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: fp_text.cpp:328
PCB_LAYER_ID
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: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 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:183
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:184
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
TEXT_TYPE
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:307
TEXT_TYPE m_Type
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:475
const wxPoint & GetPos0() const
Definition: fp_text.h:166
EDA_UNITS
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
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
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:100
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:247
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:67
virtual wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: fp_text.cpp:414
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
~FP_TEXT()
Definition: fp_text.cpp:68
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
virtual wxPoint GetPosition() const override
Definition: fp_text.h:88