KiCad PCB EDA Suite
eda_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) 2013 Jean-Pierre Charras, jpe.charras at wanadoo.fr
5  * Copyright (C) 2004-2017 KiCad Developers, see change_log.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 EDA_TEXT_H_
26 #define EDA_TEXT_H_
27 
28 #include <trigo.h> // NORMALIZE_ANGLE_POS( angle );
29 #include <common.h> // wxStringSplit
30 #include <gr_basic.h> // EDA_DRAW_MODE_T
31 #include <base_struct.h> // EDA_RECT
32 #include "kicad_string.h"
33 
34 class SHAPE_POLY_SET;
35 
36 // part of the kicad_plugin.h family of defines.
37 // See kicad_plugin.h for the choice of the value
38 // When set when calling EDA_TEXT::Format, disable writing the "hide" keyword in save file
39 #define CTL_OMIT_HIDE (1 << 6)
40 
41 
42 // Graphic Text justify:
43 // Values -1,0,1 are used in computations, do not change them
48 };
49 
50 
55 };
56 
57 
58 /* Options to draw items with thickness ( segments, arcs, circles, texts...) */
60  FILLED = true, // normal mode: solid segments
61  SKETCH = false // sketch mode: draw segments outlines only
62 };
63 
64 
69 #define DEFAULT_SIZE_TEXT 50 // default text height (in mils, i.e. 1/1000")
70 #define DIM_ANCRE_TEXTE 2 // Anchor size for text
71 
72 
80 {
81  TEXT_EFFECTS( int aSetOfBits = 0 ) :
82  bits( aSetOfBits ),
85  penwidth( 0 ),
86  angle( 0.0 )
87  {}
88 
89  short bits;
90  signed char hjustify;
91  signed char vjustify;
92  wxSize size;
93  int penwidth;
94  double angle;
95  wxPoint pos;
96 
97  void Bit( int aBit, bool aValue ) { aValue ? bits |= (1<<aBit) : bits &= ~(1<<aBit); }
98  bool Bit( int aBit ) const { return bits & (1<<aBit); }
99 };
100 
101 
109 class EDA_TEXT
110 {
111 public:
112  EDA_TEXT( const wxString& text = wxEmptyString );
113 
114  EDA_TEXT( const EDA_TEXT& aText );
115 
116  virtual ~EDA_TEXT();
117 
124  virtual const wxString& GetText() const { return m_text; }
125 
129  virtual wxString GetShownText() const { return m_shown_text; }
130 
133  wxString ShortenedShownText() const;
134 
135  virtual void SetText( const wxString& aText );
136 
142  void SetThickness( int aNewThickness ) { m_e.penwidth = aNewThickness; };
143 
148  int GetThickness() const { return m_e.penwidth; };
149 
150  void SetTextAngle( double aAngle )
151  {
152  // Higher level classes may be more restrictive than this by
153  // overloading SetTextAngle() (probably non-virtual) or merely
154  // calling EDA_TEXT::SetTextAngle() after clamping aAngle
155  // before calling this lowest inline accessor.
156  m_e.angle = aAngle;
157  }
158  double GetTextAngle() const { return m_e.angle; }
159 
160  double GetTextAngleDegrees() const { return GetTextAngle() / 10.0; }
161  double GetTextAngleRadians() const { return GetTextAngle() * M_PI/1800; }
162 
163  void SetItalic( bool isItalic ) { m_e.Bit( TE_ITALIC, isItalic ); }
164  bool IsItalic() const { return m_e.Bit( TE_ITALIC ); }
165 
166  void SetBold( bool aBold ) { m_e.Bit( TE_BOLD, aBold); }
167  bool IsBold() const { return m_e.Bit( TE_BOLD ); }
168 
169  void SetVisible( bool aVisible ) { m_e.Bit( TE_VISIBLE, aVisible ); }
170  bool IsVisible() const { return m_e.Bit( TE_VISIBLE ); }
171 
172  void SetMirrored( bool isMirrored ) { m_e.Bit( TE_MIRROR, isMirrored ); }
173  bool IsMirrored() const { return m_e.Bit( TE_MIRROR ); }
174 
181  void SetMultilineAllowed( bool aAllow ) { m_e.Bit( TE_MULTILINE, aAllow ); }
182  bool IsMultilineAllowed() const { return m_e.Bit( TE_MULTILINE ); }
183 
186 
187  void SetHorizJustify( EDA_TEXT_HJUSTIFY_T aType ) { m_e.hjustify = aType; };
188  void SetVertJustify( EDA_TEXT_VJUSTIFY_T aType ) { m_e.vjustify = aType; };
189 
196  void SetEffects( const EDA_TEXT& aSrc );
197 
204  void SwapEffects( EDA_TEXT& aTradingPartner );
205 
206  void SwapText( EDA_TEXT& aTradingPartner );
207 
208  void CopyText( const EDA_TEXT& aSrc );
209 
218  bool Replace( wxFindReplaceData& aSearchData );
219 
220  bool IsDefaultFormatting() const;
221 
222  void SetTextSize( const wxSize& aNewSize ) { m_e.size = aNewSize; };
223  const wxSize& GetTextSize() const { return m_e.size; };
224 
225  void SetTextWidth( int aWidth ) { m_e.size.x = aWidth; }
226  int GetTextWidth() const { return m_e.size.x; }
227 
228  void SetTextHeight( int aHeight ) { m_e.size.y = aHeight; }
229  int GetTextHeight() const { return m_e.size.y; }
230 
231  void SetTextPos( const wxPoint& aPoint ) { m_e.pos = aPoint; }
232  const wxPoint& GetTextPos() const { return m_e.pos; }
233 
234  void SetTextX( int aX ) { m_e.pos.x = aX; }
235  void SetTextY( int aY ) { m_e.pos.y = aY; }
236 
237  void Offset( const wxPoint& aOffset ) { m_e.pos += aOffset; }
238 
239  void Empty() { m_text.Empty(); }
240 
241  static int MapOrientation( KICAD_T labelType, int aOrientation );
242  static int MapOrientation( KICAD_T fromLabelType, KICAD_T toLabelType, int aOrientation );
243 
244  static EDA_TEXT_HJUSTIFY_T MapHorizJustify( int aHorizJustify );
245 
246  static EDA_TEXT_VJUSTIFY_T MapVertJustify( int aVertJustify );
247 
255  void Print( wxDC* aDC, const wxPoint& aOffset, COLOR4D aColor,
256  EDA_DRAW_MODE_T aDisplay_mode = FILLED );
257 
264  void TransformTextShapeToSegmentList( std::vector<wxPoint>& aCornerBuffer ) const;
265 
278  int aClearanceValue ) const;
279 
287  virtual bool TextHitTest( const wxPoint& aPoint, int aAccuracy = 0 ) const;
288 
298  virtual bool TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy = 0 ) const;
299 
309  int LenSize( const wxString& aLine, int aThickness, int aMarkupFlags ) const;
310 
329  EDA_RECT GetTextBox( int aLine = -1, int aThickness = -1, bool aInvertY = false,
330  int aMarkupFlags = 0 ) const;
331 
339  int GetInterline() const;
340 
345  wxString GetTextStyleName();
346 
357  std::vector<wxPoint>& aPositions, int aLineCount ) const;
367  virtual void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const;
368 
369 private:
370  wxString m_text;
371  wxString m_shown_text; // Cache of unescaped text for efficient access
372 
373 private:
384  void printOneLineOfText( wxDC* aDC, const wxPoint& aOffset, COLOR4D aColor,
385  EDA_DRAW_MODE_T aFillMode, const wxString& aText,
386  const wxPoint& aPos );
387 
388  // Private text effects data. API above provides accessor funcs.
390 
392  enum TE_FLAGS {
393  // start at zero, sequence is irrelevant
399  };
400 };
401 
402 
403 #endif // EDA_TEXT_H_
void SetMirrored(bool isMirrored)
Definition: eda_text.h:172
void SetTextAngle(double aAngle)
Definition: eda_text.h:150
EDA_TEXT(const wxString &text=wxEmptyString)
Definition: eda_text.cpp:101
bool IsBold() const
Definition: eda_text.h:167
void Offset(const wxPoint &aOffset)
Definition: eda_text.h:237
int GetInterline() const
Return the distance between two lines of text.
Definition: eda_text.cpp:193
void SwapEffects(EDA_TEXT &aTradingPartner)
Function SwapEffects swaps the text effects of the two involved instances.
Definition: eda_text.cpp:153
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:44
bool Bit(int aBit) const
Definition: eda_text.h:98
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:185
bool IsMirrored() const
Definition: eda_text.h:173
void CopyText(const EDA_TEXT &aSrc)
Definition: eda_text.cpp:133
wxString m_shown_text
Definition: eda_text.h:371
bool IsVisible() const
Definition: eda_text.h:170
void SetEffects(const EDA_TEXT &aSrc)
Function SetEffects sets the text effects from another instance.
Definition: eda_text.cpp:140
void SetItalic(bool isItalic)
Definition: eda_text.h:163
TEXT_EFFECTS m_e
Definition: eda_text.h:389
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:231
void SetVisible(bool aVisible)
Definition: eda_text.h:169
double GetTextAngle() const
Definition: eda_text.h:158
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:148
signed char vjustify
vertical justification
Definition: eda_text.h:91
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:222
void TransformBoundingBoxWithClearanceToPolygon(SHAPE_POLY_SET *aCornerBuffer, int aClearanceValue) const
Function TransformBoundingBoxWithClearanceToPolygon Convert the text bounding box to a rectangular po...
wxPoint pos
Definition: eda_text.h:95
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
void printOneLineOfText(wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, EDA_DRAW_MODE_T aFillMode, const wxString &aText, const wxPoint &aPos)
Function printOneLineOfText Used to print each line of this EDA_TEXT, that can be multiline.
Definition: eda_text.cpp:441
wxSize size
Definition: eda_text.h:92
int GetTextHeight() const
Definition: eda_text.h:229
void SetTextX(int aX)
Definition: eda_text.h:234
bool IsItalic() const
Definition: eda_text.h:164
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels,...
Definition: eda_text.h:109
void Bit(int aBit, bool aValue)
Definition: eda_text.h:97
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:184
static EDA_TEXT_HJUSTIFY_T MapHorizJustify(int aHorizJustify)
Definition: eda_text.cpp:73
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:126
Struct TEXT_EFFECTS is a bucket for text effects.
Definition: eda_text.h:79
Class SHAPE_POLY_SET.
EDA_DRAW_MODE_T
Definition: eda_text.h:59
EDA_RECT GetTextBox(int aLine=-1, int aThickness=-1, bool aInvertY=false, int aMarkupFlags=0) const
Function GetTextBox useful in multiline texts to calculate the full text or a line area (for zones fi...
Definition: eda_text.cpp:199
const wxSize & GetTextSize() const
Definition: eda_text.h:223
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:188
short bits
any set of booleans a client uses.
Definition: eda_text.h:89
TE_FLAGS
EDA_TEXT effects bools.
Definition: eda_text.h:392
void TransformTextShapeToSegmentList(std::vector< wxPoint > &aCornerBuffer) const
Convert the text shape to a list of segment each segment is stored as 2 wxPoints: the starting point ...
Definition: eda_text.cpp:559
void Empty()
Definition: eda_text.h:239
wxString ShortenedShownText() const
Returns a shortened version (max 15 characters) of the shown text.
Definition: eda_text.cpp:178
virtual ~EDA_TEXT()
Definition: eda_text.cpp:121
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Function Format outputs the object to aFormatter in s-expression form.
Definition: eda_text.cpp:495
bool IsDefaultFormatting() const
Definition: eda_text.cpp:481
wxString m_text
Definition: eda_text.h:370
void SetMultilineAllowed(bool aAllow)
Function SetMultiLineAllowed.
Definition: eda_text.h:181
static EDA_TEXT_VJUSTIFY_T MapVertJustify(int aVertJustify)
Definition: eda_text.cpp:87
bool IsMultilineAllowed() const
Definition: eda_text.h:182
void Print(wxDC *aDC, const wxPoint &aOffset, COLOR4D aColor, EDA_DRAW_MODE_T aDisplay_mode=FILLED)
Function Print.
Definition: eda_text.cpp:376
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:51
void SetTextWidth(int aWidth)
Definition: eda_text.h:225
double GetTextAngleRadians() const
Definition: eda_text.h:161
void SwapText(EDA_TEXT &aTradingPartner)
Definition: eda_text.cpp:146
double GetTextAngleDegrees() const
Definition: eda_text.h:160
int GetTextWidth() const
Definition: eda_text.h:226
wxString GetTextStyleName()
Function GetTextStyleName.
Definition: eda_text.cpp:460
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:187
bool Replace(wxFindReplaceData &aSearchData)
Helper function used in search and replace dialog performs a text replace using the find and replace ...
Definition: eda_text.cpp:159
int LenSize(const wxString &aLine, int aThickness, int aMarkupFlags) const
Function LenSize.
Definition: eda_text.cpp:165
TEXT_EFFECTS(int aSetOfBits=0)
Definition: eda_text.h:81
static int MapOrientation(KICAD_T labelType, int aOrientation)
Definition: eda_text.cpp:47
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
virtual bool TextHitTest(const wxPoint &aPoint, int aAccuracy=0) const
Function TextHitTest Test if aPoint is within the bounds of this object.
Definition: eda_text.cpp:351
void SetTextHeight(int aHeight)
Definition: eda_text.h:228
The common library.
double angle
now: 0.1 degrees; future: degrees
Definition: eda_text.h:94
const wxPoint & GetTextPos() const
Definition: eda_text.h:232
void GetPositionsOfLinesOfMultilineText(std::vector< wxPoint > &aPositions, int aLineCount) const
Function GetPositionsOfLinesOfMultilineText Populates aPositions with the position of each line of a ...
Definition: eda_text.cpp:399
virtual wxString GetShownText() const
Returns the string actually shown after processing of the base text.
Definition: eda_text.h:129
signed char hjustify
horizontal justification
Definition: eda_text.h:90
void SetBold(bool aBold)
Definition: eda_text.h:166
virtual const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:124
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:142
void SetTextY(int aY)
Definition: eda_text.h:235
int penwidth
Definition: eda_text.h:93
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39