~cern-kicad/kicad/kicad-pns-tom

« back to all changes in this revision

Viewing changes to include/class_worksheet_dataitem.h

  • Committer: Maciej Suminski
  • Date: 2013-08-02 13:57:24 UTC
  • mfrom: (4024.1.238 kicad)
  • mto: This revision was merged to the branch mainline in revision 4221.
  • Revision ID: maciej.suminski@cern.ch-20130802135724-gix6orezshkukodv
Upstream merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @file class_worksheet_dataitem.h
 
3
 * @brief description of graphic items and texts to build a title block
 
4
 */
 
5
 
 
6
#ifndef  CLASS_WORKSHEET_DATA_ITEM_H
 
7
#define  CLASS_WORKSHEET_DATA_ITEM_H
 
8
 
 
9
#include <math/vector2d.h>
 
10
#include <eda_text.h>
 
11
 
 
12
class WS_DRAW_ITEM_TEXT;            // Forward declaration
 
13
 
 
14
#define TB_DEFAULT_TEXTSIZE 1.5     // default worksheet text size in mm
 
15
 
 
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
 
31
 
 
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
 
35
enum corner_anchor
 
36
{
 
37
    RB_CORNER,      // right bottom corner
 
38
    RT_CORNER,      // right top corner
 
39
    LB_CORNER,      // left bottom corner
 
40
    LT_CORNER,      // left top corner
 
41
};
 
42
 
 
43
// a coordinate point
 
44
// The position is always relative to the corner anchor
 
45
// Note the coordinate is from the anchor point
 
46
// to the opposite corner.
 
47
class POINT_COORD
 
48
{
 
49
public:
 
50
    DPOINT            m_Pos;
 
51
    int               m_Anchor;
 
52
public:
 
53
    POINT_COORD() { m_Anchor = RB_CORNER; }
 
54
    POINT_COORD( DPOINT aPos, enum corner_anchor aAnchor = RB_CORNER )
 
55
    {
 
56
        m_Pos = aPos;
 
57
        m_Anchor = aAnchor;
 
58
    }
 
59
};
 
60
 
 
61
 
 
62
// Work sheet structure type definitions.
 
63
// Basic items are:
 
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
 
70
{
 
71
public:
 
72
    enum WS_ItemType {
 
73
        WS_TEXT,
 
74
        WS_SEGMENT,
 
75
        WS_RECT,
 
76
        WS_POLYPOLYGON
 
77
    };
 
78
 
 
79
protected:
 
80
    WS_ItemType       m_type;
 
81
    int               m_flags;
 
82
 
 
83
public:
 
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
 
87
                                            // layout editor
 
88
    POINT_COORD       m_Pos;
 
89
    POINT_COORD       m_End;
 
90
    double            m_LineWidth;
 
91
    int               m_RepeatCount;        // repeat count for duplicate items
 
92
    DPOINT            m_IncrementVector;    // For duplicate items: move vector
 
93
                                            // for position increment
 
94
    int               m_IncrementLabel;
 
95
 
 
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
 
102
                                            // (ws units)
 
103
    static DPOINT     m_LT_Corner;          // cordinates of the left top corner
 
104
                                            // (ws units)
 
105
    static double     m_DefaultLineWidth;   // Default line width,
 
106
                                            // when not defined inside a line
 
107
                                            // or a rect
 
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
 
119
 
 
120
 
 
121
public:
 
122
    WORKSHEET_DATAITEM( WS_ItemType aType );
 
123
 
 
124
    virtual ~WORKSHEET_DATAITEM() {}
 
125
 
 
126
    void SetStart( double aPosx, double aPosy, enum corner_anchor aAnchor = RB_CORNER )
 
127
    {
 
128
        m_Pos.m_Pos.x = aPosx;
 
129
        m_Pos.m_Pos.y = aPosy;
 
130
        m_Pos.m_Anchor = aAnchor;
 
131
    }
 
132
 
 
133
    void SetEnd( double aPosx, double aPosy, enum corner_anchor aAnchor = RB_CORNER )
 
134
    {
 
135
        m_End.m_Pos.x = aPosx;
 
136
        m_End.m_Pos.y = aPosy;
 
137
        m_End.m_Anchor = aAnchor;
 
138
    }
 
139
 
 
140
    // Accessors:
 
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; }
 
145
 
 
146
    /**
 
147
     * @return true if the item has a end point (segment; rect)
 
148
     * of false (text, polugon)
 
149
     */
 
150
    virtual bool HasEndPoint() { return true; }
 
151
 
 
152
    /**
 
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
 
156
     */
 
157
    int GetPage1Option();
 
158
 
 
159
    /**
 
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
 
164
     */
 
165
    void SetPage1Option( int aChoice );
 
166
 
 
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()
 
173
    {
 
174
        if( m_LineWidth )
 
175
            return KiROUND( m_LineWidth * m_WSunits2Iu );
 
176
        else
 
177
            return KiROUND( m_DefaultLineWidth * m_WSunits2Iu );
 
178
    }
 
179
 
 
180
    static int GetMarkerSizeUi()
 
181
    {
 
182
        return KiROUND( 0.5 * m_WSunits2Iu );
 
183
    }
 
184
 
 
185
    /**
 
186
     * move item to a new position
 
187
     * @param aPosition = the new position of item, in mm
 
188
     */
 
189
    void MoveTo( DPOINT aPosition );
 
190
 
 
191
    /**
 
192
     * move item to a new position
 
193
     * @param aPosition = the new position of the starting point in graphic units
 
194
     */
 
195
    void MoveToUi( wxPoint aPosition );
 
196
 
 
197
    /**
 
198
     * move the starting point of the item to a new position
 
199
     * @param aPosition = the new position of the starting point, in mm
 
200
     */
 
201
    void MoveStartPointTo( DPOINT aPosition );
 
202
 
 
203
    /**
 
204
     * move the starting point of the item to a new position
 
205
     * @param aPosition = the new position of item in graphic units
 
206
     */
 
207
    void MoveStartPointToUi( wxPoint aPosition );
 
208
 
 
209
 
 
210
    /**
 
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
 
215
     */
 
216
    void MoveEndPointTo( DPOINT aPosition );
 
217
 
 
218
    /**
 
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
 
223
     */
 
224
    void MoveEndPointToUi( wxPoint aPosition );
 
225
 
 
226
    /**
 
227
     * @return true if the item is inside the rectangle defined by the
 
228
     * 4 corners, false otherwise.
 
229
     */
 
230
    virtual bool IsInsidePage( int ii ) const;
 
231
 
 
232
    const wxString GetClassName() const;
 
233
 
 
234
    /**
 
235
     * @return true if the selected state on ON
 
236
     */
 
237
    bool IsSelected() { return (m_flags & SELECTED_STATE) != 0; }
 
238
 
 
239
    /**
 
240
     * Function SetSelected
 
241
     * Toggles on/off the selected flag (used in edition functions
 
242
     * @param aState = the flag value
 
243
     */
 
244
    void SetSelected( bool aState )
 
245
    {
 
246
        if( aState )
 
247
            m_flags |= SELECTED_STATE;
 
248
        else
 
249
            m_flags &= ~SELECTED_STATE;
 
250
    }
 
251
 
 
252
    bool UseAltColor() {return m_flags & USE_ALT_COLOR; }
 
253
 
 
254
    EDA_COLOR_T GetItemColor()
 
255
    {
 
256
        if( IsSelected() )
 
257
            return m_SelectedColor;
 
258
 
 
259
        if( UseAltColor() )
 
260
            return m_AltColor;
 
261
 
 
262
        return m_Color;
 
263
    }
 
264
};
 
265
 
 
266
class WORKSHEET_DATAITEM_POLYPOLYGON : public WORKSHEET_DATAITEM
 
267
{
 
268
public:
 
269
    double            m_Orient;             //  Orientation in degrees
 
270
    std::vector<DPOINT> m_Corners;          // corner list
 
271
 
 
272
private:
 
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
 
276
 
 
277
public:
 
278
    WORKSHEET_DATAITEM_POLYPOLYGON( );
 
279
 
 
280
    virtual int GetPenSizeUi()
 
281
    {
 
282
        return KiROUND( m_LineWidth * m_WSunits2Iu );
 
283
    }
 
284
 
 
285
   /**
 
286
     * @return false  (no end point)
 
287
     */
 
288
    virtual bool HasEndPoint() { return false; };
 
289
 
 
290
    /**
 
291
     * add a corner in corner list
 
292
     * @param aCorner: the item to append
 
293
     */
 
294
    void AppendCorner( const DPOINT& aCorner )
 
295
    {
 
296
        m_Corners.push_back( aCorner );
 
297
    }
 
298
 
 
299
    /**
 
300
     * Closes the current contour, by storing the index of the last corner
 
301
     * of the current polygon in m_polyIndexEnd.
 
302
     */
 
303
    void CloseContour()
 
304
    {
 
305
        m_polyIndexEnd.push_back( m_Corners.size() -1 );
 
306
    }
 
307
 
 
308
    /**
 
309
     * @return the count of contours in the poly polygon
 
310
     */
 
311
    int GetPolyCount() const { return (int) m_polyIndexEnd.size(); }
 
312
 
 
313
    /**
 
314
     * @return the index of the first corner of the contour aCountour
 
315
     * @param aContour = the index of the contour
 
316
     */
 
317
    unsigned GetPolyIndexStart( unsigned aContour) const
 
318
    {
 
319
        if( aContour == 0 )
 
320
            return 0;
 
321
        else
 
322
            return m_polyIndexEnd[aContour-1] + 1;
 
323
    }
 
324
 
 
325
    /**
 
326
     * @return the index of the last corner of the contour aCountour
 
327
     * @param aContour = the index of the contour
 
328
     */
 
329
    unsigned GetPolyIndexEnd( unsigned aContour) const
 
330
    {
 
331
        return m_polyIndexEnd[aContour];
 
332
    }
 
333
 
 
334
    /**
 
335
     * @return the coordinate (in mm) of the corner aIdx,
 
336
     * for the repeated item aRepeat
 
337
     */
 
338
    const DPOINT GetCornerPosition( unsigned aIdx, int aRepeat = 0 ) const;
 
339
 
 
340
    /**
 
341
     * @return the coordinate (in draw/plot units) of the corner aIdx,
 
342
     * for the repeated item aRepeat
 
343
     */
 
344
    const wxPoint GetCornerPositionUi( unsigned aIdx, int aRepeat = 0 ) const;
 
345
 
 
346
    /**
 
347
     * calculate the bounding box of the set  polygons
 
348
     */
 
349
    void SetBoundingBox();
 
350
 
 
351
    bool IsInsidePage( int ii ) const;
 
352
};
 
353
 
 
354
class WORKSHEET_DATAITEM_TEXT : public WORKSHEET_DATAITEM
 
355
{
 
356
public:
 
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;
 
362
    DSIZE             m_TextSize;
 
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
 
367
                                            // bound.
 
368
    DSIZE             m_ConstrainedTextSize;// Actual text size, if constrained by
 
369
                                            // the m_BoundingBoxSize constraint
 
370
 
 
371
 
 
372
public:
 
373
    WORKSHEET_DATAITEM_TEXT( const wxChar* aTextBase );
 
374
 
 
375
    /**
 
376
     * @return false  (no end point)
 
377
     */
 
378
    virtual bool HasEndPoint() { return false; };
 
379
 
 
380
    virtual int GetPenSizeUi()
 
381
    {
 
382
        if( m_LineWidth )
 
383
            return KiROUND( m_LineWidth * m_WSunits2Iu );
 
384
        else
 
385
            return KiROUND( m_DefaultTextThickness * m_WSunits2Iu );
 
386
    }
 
387
 
 
388
    /**
 
389
     * move item to a new position
 
390
     * @param aPosition = the new position of item
 
391
     */
 
392
    void MoveTo( DPOINT aPosition );
 
393
 
 
394
    /**
 
395
     * transfert the text justification and orientation
 
396
     * to aGText
 
397
     */
 
398
    void TransfertSetupToGraphicText(  WS_DRAW_ITEM_TEXT* aGText );
 
399
 
 
400
    /**
 
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
 
408
     */
 
409
    void IncrementLabel( int aIncr );
 
410
 
 
411
    /**
 
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
 
418
     */
 
419
    void SetConstrainedTextSize();
 
420
 
 
421
    /**
 
422
     * @return true is a bold font should be selected
 
423
     */
 
424
    bool IsBold() { return (m_flags & USE_BOLD) != 0; }
 
425
 
 
426
    /**
 
427
     * Function SetBold
 
428
     * Toggles on/off the bold option flag
 
429
     * @param aState = the bold option value
 
430
     */
 
431
    void SetBold( bool aState )
 
432
    {
 
433
        if( aState )
 
434
            m_flags |= USE_BOLD;
 
435
        else
 
436
            m_flags &= ~USE_BOLD;
 
437
    }
 
438
 
 
439
    /**
 
440
     * @return true is an italic font should be selected
 
441
     */
 
442
    bool IsItalic() const { return (m_flags & USE_ITALIC) != 0; }
 
443
 
 
444
    /**
 
445
     * Function SetItalic
 
446
     * Toggles on/off the italic option flag
 
447
     * @param aState = the italic option value
 
448
     */
 
449
    void SetItalic( bool aState )
 
450
    {
 
451
        if( aState )
 
452
            m_flags |= USE_ITALIC;
 
453
        else
 
454
            m_flags &= ~USE_ITALIC;
 
455
    }
 
456
};
 
457
 
 
458
#endif      // CLASS_WORKSHEET_DATA_ITEM_H