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 
30 #ifndef EDA_TEXT_H_
31 #define EDA_TEXT_H_
32 
33 #include <trigo.h> // NORMALIZE_ANGLE_POS( angle );
34 #include <common.h> // wxStringSplit
35 #include <gr_basic.h> // EDA_DRAW_MODE_T
36 #include <base_struct.h> // EDA_RECT
37 
38 
39 // part of the kicad_plugin.h family of defines.
40 // See kicad_plugin.h for the choice of the value
41 // When set when calling EDA_TEXT::Format, disable writing the "hide" keyword in save file
42 #define CTL_OMIT_HIDE (1 << 6)
43 
44 
45 // Graphic Text justify:
46 // Values -1,0,1 are used in computations, do not change them
51 };
52 
53 
58 };
59 
60 
61 /* Options to draw items with thickness ( segments, arcs, circles, texts...) */
63  FILLED = true, // normal mode: solid segments
64  SKETCH = false // sketch mode: draw segments outlines only
65 };
66 
67 
72 #define DEFAULT_SIZE_TEXT 50 // default text height (in mils, i.e. 1/1000")
73 #define DIM_ANCRE_TEXTE 2 // Anchor size for text
74 
75 
83 {
84  TEXT_EFFECTS( int aSetOfBits = 0 ) :
85  bits( aSetOfBits ),
88  penwidth( 0 ),
89  angle( 0.0 )
90  {}
91 
92  short bits;
93  signed char hjustify;
94  signed char vjustify;
95  wxSize size;
96  int penwidth;
97  double angle;
99 
100  void Bit( int aBit, bool aValue ) { aValue ? bits |= (1<<aBit) : bits &= ~(1<<aBit); }
101  bool Bit( int aBit ) const { return bits & (1<<aBit); }
102 };
103 
104 
112 class EDA_TEXT
113 {
114 public:
115  EDA_TEXT( const wxString& text = wxEmptyString );
116 
117  // Do not create a copy constructor & operator=.
118  // The ones generated by the compiler are adequate.
119 
120  virtual ~EDA_TEXT();
121 
128  const wxString& GetText() const { return m_Text; }
129 
133  virtual wxString GetShownText() const { return m_Text; }
134 
137  wxString ShortenedShownText() const;
138 
139  virtual void SetText( const wxString& aText ) { m_Text = aText; }
140 
146  void SetThickness( int aNewThickness ) { m_e.penwidth = aNewThickness; };
147 
152  int GetThickness() const { return m_e.penwidth; };
153 
154  void SetTextAngle( double aAngle )
155  {
156  // Higher level classes may be more restrictive than this by
157  // overloading SetTextAngle() (probably non-virtual) or merely
158  // calling EDA_TEXT::SetTextAngle() after clamping aAngle
159  // before calling this lowest inline accessor.
160  m_e.angle = aAngle;
161  }
162  double GetTextAngle() const { return m_e.angle; }
163 
164  double GetTextAngleDegrees() const { return GetTextAngle() / 10.0; }
165  double GetTextAngleRadians() const { return GetTextAngle() * M_PI/1800; }
166 
167  void SetItalic( bool isItalic ) { m_e.Bit( TE_ITALIC, isItalic ); }
168  bool IsItalic() const { return m_e.Bit( TE_ITALIC ); }
169 
170  void SetBold( bool aBold ) { m_e.Bit( TE_BOLD, aBold); }
171  bool IsBold() const { return m_e.Bit( TE_BOLD ); }
172 
173  void SetVisible( bool aVisible ) { m_e.Bit( TE_VISIBLE, aVisible ); }
174  bool IsVisible() const { return m_e.Bit( TE_VISIBLE ); }
175 
176  void SetMirrored( bool isMirrored ) { m_e.Bit( TE_MIRROR, isMirrored ); }
177  bool IsMirrored() const { return m_e.Bit( TE_MIRROR ); }
178 
185  void SetMultilineAllowed( bool aAllow ) { m_e.Bit( TE_MULTILINE, aAllow ); }
186  bool IsMultilineAllowed() const { return m_e.Bit( TE_MULTILINE ); }
187 
188  EDA_TEXT_HJUSTIFY_T GetHorizJustify() const { return EDA_TEXT_HJUSTIFY_T( m_e.hjustify ); };
189  EDA_TEXT_VJUSTIFY_T GetVertJustify() const { return EDA_TEXT_VJUSTIFY_T( m_e.vjustify ); };
190 
191  void SetHorizJustify( EDA_TEXT_HJUSTIFY_T aType ) { m_e.hjustify = aType; };
192  void SetVertJustify( EDA_TEXT_VJUSTIFY_T aType ) { m_e.vjustify = aType; };
193 
200  void SetEffects( const EDA_TEXT& aSrc );
201 
208  void SwapEffects( EDA_TEXT& aTradingPartner );
209 
210  bool IsDefaultFormatting() const;
211 
212  void SetTextSize( const wxSize& aNewSize ) { m_e.size = aNewSize; };
213  const wxSize& GetTextSize() const { return m_e.size; };
214 
215  void SetTextWidth( int aWidth ) { m_e.size.x = aWidth; }
216  int GetTextWidth() const { return m_e.size.x; }
217 
218  void SetTextHeight( int aHeight ) { m_e.size.y = aHeight; }
219  int GetTextHeight() const { return m_e.size.y; }
220 
221  void SetTextPos( const wxPoint& aPoint ) { m_e.pos = aPoint; }
222  const wxPoint& GetTextPos() const { return m_e.pos; }
223 
224  void SetTextX( int aX ) { m_e.pos.x = aX; }
225  void SetTextY( int aY ) { m_e.pos.y = aY; }
226 
227  void Offset( const wxPoint& aOffset ) { m_e.pos += aOffset; }
228 
229  void Empty() { m_Text.Empty(); }
230 
241  void Draw( EDA_RECT* aClipBox, wxDC* aDC,
242  const wxPoint& aOffset, COLOR4D aColor,
243  GR_DRAWMODE aDrawMode, EDA_DRAW_MODE_T aDisplay_mode = FILLED,
244  COLOR4D aAnchor_color = COLOR4D::UNSPECIFIED );
245 
252  void TransformTextShapeToSegmentList( std::vector<wxPoint>& aCornerBuffer ) const;
253 
261  virtual bool TextHitTest( const wxPoint& aPoint, int aAccuracy = 0 ) const;
262 
272  virtual bool TextHitTest( const EDA_RECT& aRect, bool aContains = false, int aAccuracy = 0 ) const;
273 
280  int LenSize( const wxString& aLine ) const;
281 
298  EDA_RECT GetTextBox( int aLine = -1, int aThickness = -1, bool aInvertY = false ) const;
299 
313  int GetInterline( int aTextThickness = -1 ) const;
314 
319  wxString GetTextStyleName();
320 
330  void GetPositionsOfLinesOfMultilineText(
331  std::vector<wxPoint>& aPositions, int aLineCount ) const;
341  virtual void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const;
342 
343 protected:
344  wxString m_Text;
345 
346 private:
360  void drawOneLineOfText( EDA_RECT* aClipBox, wxDC* aDC,
361  const wxPoint& aOffset, COLOR4D aColor,
362  GR_DRAWMODE aDrawMode, EDA_DRAW_MODE_T aFillMode,
363  const wxString& aText, const wxPoint& aPos );
364 
365  // Private text effects data. API above provides accessor funcs.
367 
369  enum TE_FLAGS {
370  // start at zero, sequence is irrelevant
376  };
377 };
378 
379 
380 #endif // EDA_TEXT_H_
void SetMirrored(bool isMirrored)
Definition: eda_text.h:176
void SetTextAngle(double aAngle)
Definition: eda_text.h:154
void Offset(const wxPoint &aOffset)
Definition: eda_text.h:227
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:47
wxString m_Text
Definition: eda_text.h:344
bool IsMultilineAllowed() const
Definition: eda_text.h:186
const wxPoint & GetTextPos() const
Definition: eda_text.h:222
bool IsItalic() const
Definition: eda_text.h:168
void SetItalic(bool isItalic)
Definition: eda_text.h:167
TEXT_EFFECTS m_e
Definition: eda_text.h:366
int GetTextWidth() const
Definition: eda_text.h:216
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:221
void SetVisible(bool aVisible)
Definition: eda_text.h:173
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
signed char vjustify
vertical justification
Definition: eda_text.h:94
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:212
double GetTextAngleDegrees() const
Definition: eda_text.h:164
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:188
wxPoint pos
Definition: eda_text.h:98
bool IsBold() const
Definition: eda_text.h:171
double GetTextAngle() const
Definition: eda_text.h:162
wxSize size
Definition: eda_text.h:95
int GetThickness() const
Function GetThickness returns pen width.
Definition: eda_text.h:152
void SetTextX(int aX)
Definition: eda_text.h:224
virtual wxString GetShownText() const
Returns the string actually shown after processing of the base text.
Definition: eda_text.h:133
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels...
Definition: eda_text.h:112
void Bit(int aBit, bool aValue)
Definition: eda_text.h:100
Struct TEXT_EFFECTS is a bucket for text effects.
Definition: eda_text.h:82
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
EDA_DRAW_MODE_T
Definition: eda_text.h:62
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:192
short bits
any set of booleans a client uses.
Definition: eda_text.h:92
TE_FLAGS
EDA_TEXT effects bools.
Definition: eda_text.h:369
void Empty()
Definition: eda_text.h:229
void SetMultilineAllowed(bool aAllow)
Function SetMultiLineAllowed.
Definition: eda_text.h:185
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:54
void SetTextWidth(int aWidth)
Definition: eda_text.h:215
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:189
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
bool Bit(int aBit) const
Definition: eda_text.h:101
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:191
bool IsMirrored() const
Definition: eda_text.h:177
bool IsVisible() const
Definition: eda_text.h:174
TEXT_EFFECTS(int aSetOfBits=0)
Definition: eda_text.h:84
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void SetTextHeight(int aHeight)
Definition: eda_text.h:218
The common library.
int GetTextHeight() const
Definition: eda_text.h:219
double angle
now: 0.1 degrees; future: degrees
Definition: eda_text.h:97
const wxSize & GetTextSize() const
Definition: eda_text.h:213
Basic classes for most KiCad items.
signed char hjustify
horizontal justification
Definition: eda_text.h:93
double GetTextAngleRadians() const
Definition: eda_text.h:165
void SetBold(bool aBold)
Definition: eda_text.h:170
void SetThickness(int aNewThickness)
Function SetThickness sets pen width.
Definition: eda_text.h:146
void SetTextY(int aY)
Definition: eda_text.h:225
virtual void SetText(const wxString &aText)
Definition: eda_text.h:139
int penwidth
Definition: eda_text.h:96
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39