2
* @file class_worksheet_dataitem.h
3
* @brief description of graphic items and texts to build a title block
6
#ifndef CLASS_WORKSHEET_DATA_ITEM_H
7
#define CLASS_WORKSHEET_DATA_ITEM_H
9
#include <math/vector2d.h>
12
class WS_DRAW_ITEM_TEXT; // Forward declaration
14
#define TB_DEFAULT_TEXTSIZE 1.5 // default worksheet text size in mm
16
// Text attributes set in m_flags (ORed bits)
17
#define USE_BOLD 1 // has meaning for texts
18
#define USE_THICK_LINE 1 // equivalent to bold for lines
19
#define USE_ITALIC (1<<1) // has meaning for texts
20
#define USE_ALT_COLOR (1<<2)
21
#define SELECTED_STATE (1<<3) // When set, use the hight light color to draw item
22
#define LOCATE_STARTPOINT (1<<4) // Used in locate function:set by locate function
23
// if the start point is located
24
#define LOCATE_ENDPOINT (1<<5) // Used in locate function:set by locate function
25
// if the end point is located
26
#define PAGE1OPTION (3<<6) // flag to manage items drawn or not drawn only
27
// on page 1: NONE = item on all pages
28
#define PAGE1OPTION_NONE (0<<6) // NONE = item on all pages
29
#define PAGE1OPTION_PAGE1ONLY (1<<6) // = item only on page 1
30
#define PAGE1OPTION_NOTONPAGE1 (2<<6) // = item on all pages but page 1
32
// A coordinate is relative to a page corner.
33
// Any of the 4 corners can be a reference.
34
// The default is the right bottom corner
37
RB_CORNER, // right bottom corner
38
RT_CORNER, // right top corner
39
LB_CORNER, // left bottom corner
40
LT_CORNER, // left top corner
44
// The position is always relative to the corner anchor
45
// Note the coordinate is from the anchor point
46
// to the opposite corner.
53
POINT_COORD() { m_Anchor = RB_CORNER; }
54
POINT_COORD( DPOINT aPos, enum corner_anchor aAnchor = RB_CORNER )
62
// Work sheet structure type definitions.
64
// * segment and rect (defined by 2 points)
65
// * text (defined by a coordinate), the text and its justifications
66
// * poly polygon defined by a coordinate, and a set of list of corners
67
// ( because we use it for logos, there are more than one polygon
68
// in this description
69
class WORKSHEET_DATAITEM
84
wxString m_Name; // a item name used in page layout
85
// editor to identify items
86
wxString m_Info; // a comment, only useful in page
91
int m_RepeatCount; // repeat count for duplicate items
92
DPOINT m_IncrementVector; // For duplicate items: move vector
93
// for position increment
96
// These variables are static, because these values are common to all
97
// instances of WORKSHEET_DATAITEM.
98
// They are default or common values.
99
static double m_WSunits2Iu; // conversion factor between
100
// ws units (mils) and draw/plot units
101
static DPOINT m_RB_Corner; // cordinates of the right bottom corner
103
static DPOINT m_LT_Corner; // cordinates of the left top corner
105
static double m_DefaultLineWidth; // Default line width,
106
// when not defined inside a line
108
static DSIZE m_DefaultTextSize; // Default text size,
109
// when not defined inside a tbtext
110
static double m_DefaultTextThickness;// Default text thickness,
111
// when not defined inside a tbtext
112
static bool m_SpecialMode; // Used in page layout editor
113
// When set to true, base texts
114
// instead of full texts are displayed
115
static EDA_COLOR_T m_Color; // the default color to draw items
116
static EDA_COLOR_T m_AltColor; // an alternate color to draw items
117
static EDA_COLOR_T m_SelectedColor; // the color to draw selected items
118
// (used in page layout editor
122
WORKSHEET_DATAITEM( WS_ItemType aType );
124
virtual ~WORKSHEET_DATAITEM() {}
126
void SetStart( double aPosx, double aPosy, enum corner_anchor aAnchor = RB_CORNER )
128
m_Pos.m_Pos.x = aPosx;
129
m_Pos.m_Pos.y = aPosy;
130
m_Pos.m_Anchor = aAnchor;
133
void SetEnd( double aPosx, double aPosy, enum corner_anchor aAnchor = RB_CORNER )
135
m_End.m_Pos.x = aPosx;
136
m_End.m_Pos.y = aPosy;
137
m_End.m_Anchor = aAnchor;
141
WS_ItemType GetType() const { return m_type; }
142
int GetFlags() const { return m_flags; }
143
void SetFlags( int aMask ) { m_flags |= aMask; }
144
void ClearFlags( int aMask ) { m_flags &= ~aMask; }
147
* @return true if the item has a end point (segment; rect)
148
* of false (text, polugon)
150
virtual bool HasEndPoint() { return true; }
153
* @return 0 if the item has no specific option for page 1
154
* 1 if the item is only on page 1
155
* -1 if the item is not on page 1
157
int GetPage1Option();
160
* Set the option for page 1
161
* @param aChoice = 0 if the item has no specific option for page 1
162
* > 0 if the item is only on page 1
163
* < 0 if the item is not on page 1
165
void SetPage1Option( int aChoice );
167
// Coordinate handling
168
const wxPoint GetStartPosUi( int ii = 0 ) const;
169
const wxPoint GetEndPosUi( int ii = 0 ) const;
170
const DPOINT GetStartPos( int ii = 0 ) const;
171
const DPOINT GetEndPos( int ii = 0 ) const;
172
virtual int GetPenSizeUi()
175
return KiROUND( m_LineWidth * m_WSunits2Iu );
177
return KiROUND( m_DefaultLineWidth * m_WSunits2Iu );
180
static int GetMarkerSizeUi()
182
return KiROUND( 0.5 * m_WSunits2Iu );
186
* move item to a new position
187
* @param aPosition = the new position of item, in mm
189
void MoveTo( DPOINT aPosition );
192
* move item to a new position
193
* @param aPosition = the new position of the starting point in graphic units
195
void MoveToUi( wxPoint aPosition );
198
* move the starting point of the item to a new position
199
* @param aPosition = the new position of the starting point, in mm
201
void MoveStartPointTo( DPOINT aPosition );
204
* move the starting point of the item to a new position
205
* @param aPosition = the new position of item in graphic units
207
void MoveStartPointToUi( wxPoint aPosition );
211
* move the ending point of the item to a new position
212
* has meaning only for items defined by 2 points
213
* (segments and rectangles)
214
* @param aPosition = the new position of the ending point, in mm
216
void MoveEndPointTo( DPOINT aPosition );
219
* move the ending point of the item to a new position
220
* has meaning only for items defined by 2 points
221
* (segments and rectangles)
222
* @param aPosition = the new position of the ending point in graphic units
224
void MoveEndPointToUi( wxPoint aPosition );
227
* @return true if the item is inside the rectangle defined by the
228
* 4 corners, false otherwise.
230
virtual bool IsInsidePage( int ii ) const;
232
const wxString GetClassName() const;
235
* @return true if the selected state on ON
237
bool IsSelected() { return (m_flags & SELECTED_STATE) != 0; }
240
* Function SetSelected
241
* Toggles on/off the selected flag (used in edition functions
242
* @param aState = the flag value
244
void SetSelected( bool aState )
247
m_flags |= SELECTED_STATE;
249
m_flags &= ~SELECTED_STATE;
252
bool UseAltColor() {return m_flags & USE_ALT_COLOR; }
254
EDA_COLOR_T GetItemColor()
257
return m_SelectedColor;
266
class WORKSHEET_DATAITEM_POLYPOLYGON : public WORKSHEET_DATAITEM
269
double m_Orient; // Orientation in degrees
270
std::vector<DPOINT> m_Corners; // corner list
273
std::vector<unsigned> m_polyIndexEnd; // index of the last point of each polygon
274
DPOINT m_minCoord; // min coord of corners, relative to m_Pos
275
DPOINT m_maxCoord; // max coord of corners, relative to m_Pos
278
WORKSHEET_DATAITEM_POLYPOLYGON( );
280
virtual int GetPenSizeUi()
282
return KiROUND( m_LineWidth * m_WSunits2Iu );
286
* @return false (no end point)
288
virtual bool HasEndPoint() { return false; };
291
* add a corner in corner list
292
* @param aCorner: the item to append
294
void AppendCorner( const DPOINT& aCorner )
296
m_Corners.push_back( aCorner );
300
* Closes the current contour, by storing the index of the last corner
301
* of the current polygon in m_polyIndexEnd.
305
m_polyIndexEnd.push_back( m_Corners.size() -1 );
309
* @return the count of contours in the poly polygon
311
int GetPolyCount() const { return (int) m_polyIndexEnd.size(); }
314
* @return the index of the first corner of the contour aCountour
315
* @param aContour = the index of the contour
317
unsigned GetPolyIndexStart( unsigned aContour) const
322
return m_polyIndexEnd[aContour-1] + 1;
326
* @return the index of the last corner of the contour aCountour
327
* @param aContour = the index of the contour
329
unsigned GetPolyIndexEnd( unsigned aContour) const
331
return m_polyIndexEnd[aContour];
335
* @return the coordinate (in mm) of the corner aIdx,
336
* for the repeated item aRepeat
338
const DPOINT GetCornerPosition( unsigned aIdx, int aRepeat = 0 ) const;
341
* @return the coordinate (in draw/plot units) of the corner aIdx,
342
* for the repeated item aRepeat
344
const wxPoint GetCornerPositionUi( unsigned aIdx, int aRepeat = 0 ) const;
347
* calculate the bounding box of the set polygons
349
void SetBoundingBox();
351
bool IsInsidePage( int ii ) const;
354
class WORKSHEET_DATAITEM_TEXT : public WORKSHEET_DATAITEM
357
wxString m_TextBase; // The basic text, with format symbols
358
wxString m_FullText; // The expanded text, shown on screen
359
double m_Orient; // Orientation in degrees
360
enum EDA_TEXT_HJUSTIFY_T m_Hjustify;
361
enum EDA_TEXT_VJUSTIFY_T m_Vjustify;
363
DSIZE m_BoundingBoxSize; // When not null, this is the max
364
// size of the full text.
365
// the text size will be modified
366
// to keep the full text insite this
368
DSIZE m_ConstrainedTextSize;// Actual text size, if constrained by
369
// the m_BoundingBoxSize constraint
373
WORKSHEET_DATAITEM_TEXT( const wxChar* aTextBase );
376
* @return false (no end point)
378
virtual bool HasEndPoint() { return false; };
380
virtual int GetPenSizeUi()
383
return KiROUND( m_LineWidth * m_WSunits2Iu );
385
return KiROUND( m_DefaultTextThickness * m_WSunits2Iu );
389
* move item to a new position
390
* @param aPosition = the new position of item
392
void MoveTo( DPOINT aPosition );
395
* transfert the text justification and orientation
398
void TransfertSetupToGraphicText( WS_DRAW_ITEM_TEXT* aGText );
401
* Try to build text wihich is an increment of m_TextBase
402
* has meaning only if m_TextBase is a basic text (one char)
403
* If the basic char is a digit, build a number
404
* If the basic char is a letter, use the letter with ascii code
405
* aIncr + (basic char ascc code)
406
* @param aIncr = the increment value
407
* return the incremented label in m_FullText
409
void IncrementLabel( int aIncr );
412
* Calculates m_ConstrainedTextSize from m_TextSize
413
* to keep the X size and the full Y size of the text
414
* smaller than m_BoundingBoxSize
415
* if m_BoundingBoxSize.x or m_BoundingBoxSize.y > 0
416
* if m_BoundingBoxSize.x or m_BoundingBoxSize.y == 0
417
* the corresponding text size is not constrained
419
void SetConstrainedTextSize();
422
* @return true is a bold font should be selected
424
bool IsBold() { return (m_flags & USE_BOLD) != 0; }
428
* Toggles on/off the bold option flag
429
* @param aState = the bold option value
431
void SetBold( bool aState )
436
m_flags &= ~USE_BOLD;
440
* @return true is an italic font should be selected
442
bool IsItalic() const { return (m_flags & USE_ITALIC) != 0; }
446
* Toggles on/off the italic option flag
447
* @param aState = the italic option value
449
void SetItalic( bool aState )
452
m_flags |= USE_ITALIC;
454
m_flags &= ~USE_ITALIC;
458
#endif // CLASS_WORKSHEET_DATA_ITEM_H