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-2019 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  bool Matches( wxFindReplaceData& aSearchData, void* aAuxData ) override
82  {
83  return BOARD_ITEM::Matches( GetShownText(), aSearchData );
84  }
85 
86  virtual wxPoint GetPosition() const override
87  {
88  return EDA_TEXT::GetTextPos();
89  }
90 
91  virtual void SetPosition( const wxPoint& aPos ) override
92  {
93  EDA_TEXT::SetTextPos( aPos );
94  SetLocalCoord();
95  }
96 
97  void SetTextAngle( double aAngle ) override;
98 
102  void KeepUpright( double aOldOrientation, double aNewOrientation );
103 
109  {
110  return m_keepUpright;
111  }
112 
113  void SetKeepUpright( bool aKeepUpright )
114  {
115  m_keepUpright = aKeepUpright;
116  }
117 
120  void Rotate( const wxPoint& aOffset, double aAngle ) override;
121 
123  void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
124 
125  bool IsParentFlipped() const;
126 
131  void Mirror( const wxPoint& aCentre, bool aMirrorAroundXAxis );
132 
134  void Move( const wxPoint& aMoveVector ) override;
135 
137  // reference and value from deletion, and for identification)
138  void SetType( TEXT_TYPE aType ) { m_Type = aType; }
139  TEXT_TYPE GetType() const { return m_Type; }
140 
145  void SetEffects( const FP_TEXT& aSrc )
146  {
147  EDA_TEXT::SetEffects( aSrc );
148  SetLocalCoord();
149  // SetType( aSrc.GetType() );
150  }
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  }
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  BITMAP_DEF 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
Function GetClass returns the class name.
Definition: fp_text.h:212
virtual double GetDrawRotation() const override
Definition: fp_text.cpp:247
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: fp_text.cpp:338
LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived to re...
Definition: richio.h:82
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:93
virtual void SetPosition(const wxPoint &aPos) override
Definition: fp_text.h:91
PNG memory record (file in memory).
Definition: bitmap_def.h:29
virtual const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
Definition: fp_text.cpp:344
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
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 absolute coordinates.
Definition: fp_text.cpp:198
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
Definition: fp_text.cpp:273
double ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Function ViewGetLOD() Returns the level of detail (LOD) of the item.
Definition: fp_text.cpp:367
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER) const override
Function GetEffectiveShape Some pad shapes can be complex (rounded/chamfered rectangle),...
Definition: fp_text.cpp:441
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:138
void TransformShapeWithClearanceToPolygon(SHAPE_POLY_SET &aCornerBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool aIgnoreLineWidth) const override
Function TransformShapeWithClearanceToPolygon Convert the item shape to a closed polygon Used in fill...
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
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
Definition: fp_text.cpp:356
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
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
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
Function IsType Checks 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:139
SHAPE_POLY_SET.
bool HitTest(const wxPoint &aPosition, int aAccuracy) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: fp_text.h:191
virtual bool IsType(const KICAD_T aScanTypes[]) const
Function IsType Checks whether the item is one of the listed types.
Definition: eda_item.h:250
bool m_keepUpright
if true, keep rotation angle between -90 .
Definition: fp_text.h:245
SHAPE.
Definition: shape.h:122
int GetLength() const
Definition: fp_text.cpp:192
bool HitTest(const EDA_RECT &aRect, bool aContained, int aAccuracy=0) const override
Function HitTest tests 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
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: fp_text.cpp:311
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)
Function SetEffects sets the text effects from another instance.
Definition: fp_text.h:145
const wxPoint & GetPos0() const
Definition: fp_text.h:166
EDA_UNITS
Definition: eda_units.h:38
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: fp_text.cpp:332
void SetKeepUpright(bool aKeepUpright)
Definition: fp_text.h:113
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: fp_text.cpp:235
bool IsParentFlipped() const
Definition: fp_text.cpp:164
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void SetLocalCoord()
Set relative coordinates.
Definition: fp_text.cpp:217
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
void SwapEffects(FP_TEXT &aTradingPartner)
Function SwapEffects swaps 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
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: fp_text.h:81
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:54
VIEW.
Definition: view.h:63
bool IsKeepUpright()
Definition: fp_text.h:108
virtual wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
Definition: fp_text.cpp:405
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData)
Function Matches compares the item against the search criteria in aSearchData.
Definition: eda_item.h:446
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
~FP_TEXT()
Definition: fp_text.cpp:64
KICAD_T Type() const
Function Type()
Definition: eda_item.h:181
virtual wxPoint GetPosition() const override
Definition: fp_text.h:86