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

« back to all changes in this revision

Viewing changes to include/worksheet_shape_builder.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:
10
10
#include <math/vector2d.h>
11
11
#include <eda_text.h>
12
12
 
13
 
class WS_DRAW_ITEM_TEXT;        // Forward declaration
 
13
class WORKSHEET_DATAITEM;        // Forward declaration
 
14
class TITLE_BLOCK;
14
15
 
15
16
#define TB_DEFAULT_TEXTSIZE             1.5  // default worksheet text size in mm
16
17
 
17
 
// Text attributes set in m_Flags (ORed bits)
18
 
 #define USE_BOLD 1             // has meaning for texts
19
 
 #define USE_THICK_LINE 1       // equivalent to bold for lines
20
 
 #define USE_ITALIC 2           // has meaning for texts
21
 
 #define USE_TEXT_COLOR 4
22
 
 #define SET_UPPER_LIMIT 8      // Flag used to calculate variable position items
23
 
 
24
 
// A coordinate is relative to a page corner.
25
 
// Any of the 4 corners can be a reference.
26
 
// The default is the right bottom corner
27
 
enum corner_anchor
28
 
{
29
 
    RB_CORNER,      // right bottom corner
30
 
    RT_CORNER,      // right top corner
31
 
    LB_CORNER,      // left bottom corner
32
 
    LT_CORNER,      // left top corner
33
 
};
34
 
 
35
 
// a coordinate point
36
 
// The position is always relative to the corner anchor
37
 
// Note the coordinate is from the anchor point
38
 
// to the opposite corner.
39
 
class POINT_COORD
40
 
{
41
 
public:
42
 
    DPOINT            m_Pos;
43
 
    int               m_Anchor;
44
 
public:
45
 
    POINT_COORD() { m_Anchor = RB_CORNER; }
46
 
    POINT_COORD( DPOINT aPos, enum corner_anchor aAnchor = RB_CORNER )
47
 
    {
48
 
        m_Pos = aPos;
49
 
        m_Anchor = aAnchor;
50
 
    }
51
 
};
52
 
 
53
 
 
54
 
// Work sheet structure type definitions.
55
 
// Basic items are:
56
 
// * segment and rect (defined by 2 points)
57
 
// * text (defined by a coordinate), the text and its justifications
58
 
// * poly polygon defined by a coordinate, and a set of list of corners
59
 
//   ( because we use it for logos, there are more than one polygon
60
 
//   in this description
61
 
class WORKSHEET_DATAITEM
62
 
{
63
 
public:
64
 
    enum WS_ItemType {
65
 
        WS_TEXT,
66
 
        WS_SEGMENT,
67
 
        WS_RECT,
68
 
        WS_POLYPOLYGON
69
 
    };
70
 
    WS_ItemType       m_Type;
71
 
    POINT_COORD       m_Pos;
72
 
    POINT_COORD       m_End;
73
 
    double            m_LineWidth;
74
 
    int               m_Flags;
75
 
    int               m_RepeatCount;        // repeat count for duplicate items
76
 
    DPOINT            m_IncrementVector;    // For duplicate items: move vector
77
 
                                            // for position increment
78
 
    int               m_IncrementLabel;
79
 
 
80
 
    static double     m_WSunits2Iu;         // conversion factor between
81
 
                                            // ws units (mils) and draw/plot units
82
 
    static DPOINT     m_RB_Corner;          // cordinates of the right bottom corner
83
 
                                            // (ws units)
84
 
    static DPOINT     m_LT_Corner;          // cordinates of the left top corner
85
 
                                            // (ws units)
86
 
 
87
 
public:
88
 
    WORKSHEET_DATAITEM( WS_ItemType aType )
89
 
    {
90
 
        m_Type = aType;
91
 
        m_Flags = 0;
92
 
        m_RepeatCount = 1;
93
 
        m_IncrementLabel = 0;
94
 
        m_LineWidth = 0.0;
95
 
    }
96
 
 
97
 
    virtual ~WORKSHEET_DATAITEM() {}
98
 
 
99
 
    void SetStart( double aPosx, double aPosy, enum corner_anchor aAnchor = RB_CORNER )
100
 
    {
101
 
        m_Pos.m_Pos.x = aPosx;
102
 
        m_Pos.m_Pos.y = aPosy;
103
 
        m_Pos.m_Anchor = aAnchor;
104
 
    }
105
 
 
106
 
    void SetEnd( double aPosx, double aPosy, enum corner_anchor aAnchor = RB_CORNER )
107
 
    {
108
 
        m_End.m_Pos.x = aPosx;
109
 
        m_End.m_Pos.y = aPosy;
110
 
        m_End.m_Anchor = aAnchor;
111
 
    }
112
 
 
113
 
    const wxPoint GetStartPosUi( int ii = 0 ) const;
114
 
    const wxPoint GetEndPosUi( int ii = 0 ) const;
115
 
    const DPOINT GetStartPos( int ii = 0 ) const;
116
 
    const DPOINT GetEndPos( int ii = 0 ) const;
117
 
    int GetPenSizeUi() {return KiROUND( m_LineWidth * m_WSunits2Iu ); }
118
 
 
119
 
    /**
120
 
     * @return true if the item is inside the rectangle defined by the
121
 
     * 4 corners, false otherwise.
122
 
     */
123
 
    virtual bool IsInsidePage( int ii ) const;
124
 
};
125
 
 
126
 
class WORKSHEET_DATAITEM_POLYPOLYGON : public WORKSHEET_DATAITEM
127
 
{
128
 
public:
129
 
    double            m_Orient;             //  Orientation in degrees
130
 
    std::vector<DPOINT> m_Corners;          // corner list
131
 
 
132
 
private:
133
 
    std::vector<unsigned> m_polyIndexEnd;   // index of the last point of each polygon
134
 
    DPOINT            m_minCoord;           // min coord of corners, relative to m_Pos
135
 
    DPOINT            m_maxCoord;           // max coord of corners, relative to m_Pos
136
 
 
137
 
public:
138
 
    WORKSHEET_DATAITEM_POLYPOLYGON( );
139
 
 
140
 
    /**
141
 
     * add a corner in corner list
142
 
     * @param aCorner: the item to append
143
 
     */
144
 
    void AppendCorner( const DPOINT& aCorner )
145
 
    {
146
 
        m_Corners.push_back( aCorner );
147
 
    }
148
 
 
149
 
    /**
150
 
     * Closes the current contour, by storing the index of the last corner
151
 
     * of the current polygon in m_polyIndexEnd.
152
 
     */
153
 
    void CloseContour()
154
 
    {
155
 
        m_polyIndexEnd.push_back( m_Corners.size() -1 );
156
 
    }
157
 
 
158
 
    /**
159
 
     * @return the count of contours in the poly polygon
160
 
     */
161
 
    int GetPolyCount() const { return (int) m_polyIndexEnd.size(); }
162
 
 
163
 
    /**
164
 
     * @return the index of the first corner of the contour aCountour
165
 
     * @param aContour = the index of the contour
166
 
     */
167
 
    unsigned GetPolyIndexStart( unsigned aContour) const
168
 
    {
169
 
        if( aContour == 0 )
170
 
            return 0;
171
 
        else
172
 
            return m_polyIndexEnd[aContour-1] + 1;
173
 
    }
174
 
 
175
 
    /**
176
 
     * @return the index of the last corner of the contour aCountour
177
 
     * @param aContour = the index of the contour
178
 
     */
179
 
    unsigned GetPolyIndexEnd( unsigned aContour) const
180
 
    {
181
 
        return m_polyIndexEnd[aContour];
182
 
    }
183
 
 
184
 
    /**
185
 
     * @return the coordinate (in mm) of the corner aIdx,
186
 
     * for the repeated item aRepeat
187
 
     */
188
 
    const DPOINT GetCornerPosition( unsigned aIdx, int aRepeat = 0 ) const;
189
 
 
190
 
    /**
191
 
     * @return the coordinate (in draw/plot units) of the corner aIdx,
192
 
     * for the repeated item aRepeat
193
 
     */
194
 
    const wxPoint GetCornerPositionUi( unsigned aIdx, int aRepeat = 0 ) const;
195
 
 
196
 
    /**
197
 
     * calculate the bounding box of the set  polygons
198
 
     */
199
 
    void SetBoundingBox();
200
 
 
201
 
 
202
 
    bool IsInsidePage( int ii ) const;
203
 
};
204
 
 
205
 
class WORKSHEET_DATAITEM_TEXT : public WORKSHEET_DATAITEM
206
 
{
207
 
public:
208
 
    wxString          m_TextBase;           // The basic text, with format symbols
209
 
    wxString          m_FullText;           // The expanded text, shown on screen
210
 
    int               m_IncrementLabel;
211
 
    double            m_Orient;             //  Orientation in degrees
212
 
    enum EDA_TEXT_HJUSTIFY_T m_Hjustify;
213
 
    enum EDA_TEXT_VJUSTIFY_T m_Vjustify;
214
 
    DSIZE             m_TextSize;
215
 
    DSIZE             m_BoundingBoxSize;    // When not null, this is the max
216
 
                                            // size of the full text.
217
 
                                            // the text size will be modified
218
 
                                            // to keep the full text insite this
219
 
                                            // bound.
220
 
    DSIZE             m_ConstrainedTextSize;// Actual text size, if constrained by
221
 
                                            // the m_BoundingBoxSize constraint
222
 
 
223
 
public:
224
 
    WORKSHEET_DATAITEM_TEXT( const wxChar* aTextBase );
225
 
 
226
 
    /**
227
 
     * transfert the text justification and orientation
228
 
     * to aGText
229
 
     */
230
 
    void TransfertSetupToGraphicText(  WS_DRAW_ITEM_TEXT* aGText );
231
 
 
232
 
    /**
233
 
     * Try to build text wihich is an increment of m_TextBase
234
 
     * has meaning only if m_TextBase is a basic text (one char)
235
 
     * If the basic char is a digit, build a number
236
 
     * If the basic char is a letter, use the letter with ascii code
237
 
     * aIncr + (basic char ascc code)
238
 
     * @param aIncr = the increment value
239
 
     * return the incremented label in m_FullText
240
 
     */
241
 
    void IncrementLabel( int aIncr );
242
 
 
243
 
    /**
244
 
     * Calculates m_ConstrainedTextSize from m_TextSize
245
 
     * to keep the X size and the full Y size of the text
246
 
     * smaller than m_BoundingBoxSize
247
 
     * if m_BoundingBoxSize.x or m_BoundingBoxSize.y > 0
248
 
     * if m_BoundingBoxSize.x or m_BoundingBoxSize.y == 0
249
 
     * the corresponding text size is not constrained
250
 
     */
251
 
    void SetConstrainedTextSize();
252
 
 
253
 
    /**
254
 
     * @return true is a bold font should be selected
255
 
     */
256
 
    bool IsBold() { return (m_Flags & USE_BOLD) != 0; }
257
 
 
258
 
    /**
259
 
     * @return true is an italic font should be selected
260
 
     */
261
 
    bool IsItalic() { return (m_Flags & USE_ITALIC) != 0; }
262
 
};
263
 
 
264
18
/*
265
19
 * Helper classes to handle basic graphic items used to raw/plot
266
20
 * title blocks and frame references
275
29
    enum WS_DRAW_TYPE {
276
30
        wsg_line, wsg_rect, wsg_poly, wsg_text
277
31
    };
 
32
    int m_Flags;                    // temporary flgs used in page layout editor
 
33
                                    // to locate the item;
278
34
 
279
35
protected:
280
36
    WS_DRAW_TYPE    m_type; // wsg_line, wsg_rect, wsg_poly, wsg_text
281
37
    EDA_COLOR_T     m_color;
 
38
    WORKSHEET_DATAITEM*  m_parent;  // an unique identifier, used as link
 
39
                                    // to the parent WORKSHEET_DATAITEM item,
 
40
                                    // in page layout editor
282
41
 
283
42
protected:
284
 
    WS_DRAW_ITEM_BASE( WS_DRAW_TYPE aType, EDA_COLOR_T aColor )
 
43
    WS_DRAW_ITEM_BASE( WORKSHEET_DATAITEM*  aParent,
 
44
                       WS_DRAW_TYPE aType, EDA_COLOR_T aColor )
285
45
    {
286
46
        m_type  = aType;
287
47
        m_color = aColor;
 
48
        m_parent = aParent;
 
49
        m_Flags = 0;
288
50
    }
289
51
 
290
52
public:
293
55
    // Accessors:
294
56
    EDA_COLOR_T GetColor() { return m_color; }
295
57
    WS_DRAW_TYPE GetType() { return m_type; };
 
58
 
 
59
    WORKSHEET_DATAITEM* GetParent() { return m_parent; }
 
60
 
 
61
    /** The function to draw a WS_DRAW_ITEM
 
62
     */
 
63
    virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC ) = 0;
 
64
 
 
65
    /**
 
66
     * Abstract function: should exist for derived items
 
67
     * return true if the point aPosition is on the item
 
68
     */
 
69
    virtual bool HitTest( const wxPoint& aPosition) = 0;
 
70
 
 
71
    /**
 
72
     * Abstract function: should exist for derived items
 
73
     * return true if the point aPosition is near the starting point of this item,
 
74
     * for items defined by 2 points (segments, rect)
 
75
     * or the position of the item, for items having only one point
 
76
     * (texts or polygons)
 
77
     * the maxi dist is WORKSHEET_DATAITEM::GetMarkerSizeUi()/2
 
78
     */
 
79
    virtual bool HitTestStartPoint( const wxPoint& aPosition) = 0;
 
80
 
 
81
    /**
 
82
     * return true if the point aPosition is near the ending point of this item
 
83
     * This is avirtual function which should be overriden for items defien by
 
84
     * 2 points
 
85
     * the maxi dist is WORKSHEET_DATAITEM::GetMarkerSizeUi()/2
 
86
     */
 
87
    virtual bool HitTestEndPoint( const wxPoint& aPosition)
 
88
    {
 
89
        return false;
 
90
    }
296
91
};
297
92
 
298
93
// This class draws a thick segment
303
98
    int     m_penWidth;
304
99
 
305
100
public:
306
 
    WS_DRAW_ITEM_LINE( wxPoint aStart, wxPoint aEnd,
 
101
    WS_DRAW_ITEM_LINE( WORKSHEET_DATAITEM* aParent,
 
102
                       wxPoint aStart, wxPoint aEnd,
307
103
                       int aPenWidth, EDA_COLOR_T aColor ) :
308
 
        WS_DRAW_ITEM_BASE( wsg_line, aColor )
 
104
        WS_DRAW_ITEM_BASE( aParent, wsg_line, aColor )
309
105
    {
310
106
        m_start     = aStart;
311
107
        m_end       = aEnd;
316
112
    int GetPenWidth() { return m_penWidth; }
317
113
    const wxPoint&  GetStart() { return m_start; }
318
114
    const wxPoint&  GetEnd() { return m_end; }
 
115
 
 
116
    /** The function to draw a WS_DRAW_ITEM_LINE
 
117
     */
 
118
    virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC );
 
119
 
 
120
    /**
 
121
     * Virtual function
 
122
     * return true if the point aPosition is on the line
 
123
     */
 
124
    virtual bool HitTest( const wxPoint& aPosition);
 
125
 
 
126
    /**
 
127
     * return true if the point aPosition is on the starting point of this item.
 
128
     */
 
129
    virtual bool HitTestStartPoint( const wxPoint& aPosition);
 
130
 
 
131
    /**
 
132
     * return true if the point aPosition is on the ending point of this item
 
133
     * This is avirtual function which should be overriden for items defien by
 
134
     * 2 points
 
135
     */
 
136
    virtual bool HitTestEndPoint( const wxPoint& aPosition);
319
137
};
320
138
 
321
139
// This class draws a polygon
322
140
class WS_DRAW_ITEM_POLYGON : public WS_DRAW_ITEM_BASE
323
141
{
 
142
    wxPoint m_pos;      // position of reference point, from the
 
143
                        // WORKSHEET_DATAITEM_POLYPOLYGON parent
 
144
                        // (used only in page layout editor to draw anchors)
324
145
    int m_penWidth;
325
146
    bool m_fill;
326
147
 
328
149
    std::vector <wxPoint> m_Corners;
329
150
 
330
151
public:
331
 
    WS_DRAW_ITEM_POLYGON( bool aFill, int aPenWidth, EDA_COLOR_T aColor ) :
332
 
        WS_DRAW_ITEM_BASE( wsg_poly, aColor )
 
152
    WS_DRAW_ITEM_POLYGON( WORKSHEET_DATAITEM* aParent, wxPoint aPos,
 
153
                          bool aFill, int aPenWidth, EDA_COLOR_T aColor ) :
 
154
        WS_DRAW_ITEM_BASE( aParent, wsg_poly, aColor )
333
155
    {
334
156
        m_penWidth = aPenWidth;
335
157
        m_fill = aFill;
 
158
        m_pos = aPos;
336
159
    }
337
160
 
338
161
    // Accessors:
339
162
    int GetPenWidth() { return m_penWidth; }
340
163
    bool IsFilled() { return m_fill; }
 
164
    const wxPoint& GetPosition() { return m_pos; }
 
165
 
 
166
    /** The function to draw a WS_DRAW_ITEM_POLYGON
 
167
     */
 
168
    virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC );
 
169
 
 
170
    /**
 
171
     * Virtual function
 
172
     * return true if the point aPosition is inside one polygon
 
173
     */
 
174
    virtual bool HitTest( const wxPoint& aPosition);
 
175
 
 
176
    /**
 
177
     * return true if the point aPosition is on the starting point of this item.
 
178
     */
 
179
    virtual bool HitTestStartPoint( const wxPoint& aPosition);
341
180
};
342
181
 
343
182
// This class draws a not filled rectangle with thick segment
344
183
class WS_DRAW_ITEM_RECT : public WS_DRAW_ITEM_LINE
345
184
{
346
185
public:
347
 
    WS_DRAW_ITEM_RECT( wxPoint aStart, wxPoint aEnd,
 
186
    WS_DRAW_ITEM_RECT( WORKSHEET_DATAITEM* aParent,
 
187
                       wxPoint aStart, wxPoint aEnd,
348
188
                       int aPenWidth, EDA_COLOR_T aColor ) :
349
 
        WS_DRAW_ITEM_LINE( aStart, aEnd, aPenWidth, aColor )
 
189
        WS_DRAW_ITEM_LINE( aParent, aStart, aEnd, aPenWidth, aColor )
350
190
    {
351
191
        m_type = wsg_rect;
352
192
    }
 
193
 
 
194
    /** The function to draw a WS_DRAW_ITEM_RECT
 
195
     */
 
196
    virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC );
 
197
 
 
198
    /**
 
199
     * Virtual function
 
200
     * return true if the point aPosition is on one edge of the rectangle
 
201
     */
 
202
    virtual bool HitTest( const wxPoint& aPosition);
 
203
 
 
204
    /**
 
205
     * return true if the point aPosition is on the starting point of this item.
 
206
     */
 
207
    virtual bool HitTestStartPoint( const wxPoint& aPosition);
 
208
 
 
209
    /**
 
210
     * return true if the point aPosition is on the ending point of this item
 
211
     * This is avirtual function which should be overriden for items defien by
 
212
     * 2 points
 
213
     */
 
214
    virtual bool HitTestEndPoint( const wxPoint& aPosition);
353
215
};
354
216
 
355
217
// This class draws a graphic text.
358
220
class WS_DRAW_ITEM_TEXT : public WS_DRAW_ITEM_BASE, public EDA_TEXT
359
221
{
360
222
public:
361
 
    WS_DRAW_ITEM_TEXT( wxString& aText, wxPoint aPos, wxSize aSize,
 
223
    WS_DRAW_ITEM_TEXT( WORKSHEET_DATAITEM* aParent,
 
224
                       wxString& aText, wxPoint aPos, wxSize aSize,
362
225
                       int aPenWidth, EDA_COLOR_T aColor,
363
 
                       bool aItalic = false, bool aBold = false ) :
364
 
        WS_DRAW_ITEM_BASE( wsg_text, aColor ), EDA_TEXT( aText )
365
 
    {
366
 
        SetTextPosition( aPos );
367
 
        SetSize( aSize );
368
 
        SetThickness( aPenWidth );
369
 
        SetItalic( aItalic );
370
 
        SetBold( aBold );
371
 
    }
 
226
                       bool aItalic = false, bool aBold = false );
 
227
 
 
228
    /** The function to draw a WS_DRAW_ITEM_TEXT
 
229
     */
 
230
    virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC );
372
231
 
373
232
    // Accessors:
374
233
    int GetPenWidth() { return GetThickness(); }
 
234
 
 
235
    /**
 
236
     * Virtual function
 
237
     * return true if the point aPosition is on the text
 
238
     */
 
239
    virtual bool HitTest( const wxPoint& aPosition);
 
240
 
 
241
    /**
 
242
     * return true if the point aPosition is on the starting point of this item.
 
243
     */
 
244
    virtual bool HitTestStartPoint( const wxPoint& aPosition);
375
245
};
376
246
 
377
247
/*
382
252
 */
383
253
class WS_DRAW_ITEM_LIST
384
254
{
 
255
protected:
385
256
    std::vector <WS_DRAW_ITEM_BASE*> m_graphicList;     // Items to draw/plot
386
257
    unsigned m_idx;             // for GetFirst, GetNext functions
387
258
    wxPoint  m_LTmargin;        // The left top margin in mils of the page layout.
420
291
            delete m_graphicList[ii];
421
292
    }
422
293
 
423
 
    /* Function SetPenSize
424
 
     * Set the defualt pen size to draw/plot lines and texts
 
294
    /**
 
295
     * Set the filename to draw/plot
 
296
     * @param aFileName = the text to display by the "filename" format
 
297
     */
 
298
    void SetFileName( const wxString & aFileName )
 
299
    {
 
300
        m_fileName = &aFileName;
 
301
    }
 
302
 
 
303
    /**
 
304
     * Set the sheet name to draw/plot
 
305
     * @param aSheetName = the text to draw/plot by the "sheetname" format
 
306
     */
 
307
    void SetSheetName( const wxString & aSheetName )
 
308
    {
 
309
        m_sheetFullName = &aSheetName;
 
310
    }
 
311
 
 
312
    /** Function SetPenSize
 
313
     * Set the default pen size to draw/plot lines and texts
425
314
     * @param aPenSize the thickness of lines
426
315
     */
427
316
    void SetPenSize( int aPenSize )
429
318
        m_penSize = aPenSize;
430
319
    }
431
320
 
432
 
    /* Function SetMilsToIUfactor
 
321
    /** Function SetMilsToIUfactor
433
322
     * Set the scalar to convert pages units ( mils) to draw/plot units
434
323
     * @param aScale the conversion factor
435
324
     */
438
327
        m_milsToIu = aScale;
439
328
    }
440
329
 
441
 
    /* Function SetPageSize
 
330
    /** Function SetPageSize
442
331
     * Set the size of the page layout
443
332
     * @param aPageSize size (in mils) of the page layout.
444
333
     */
467
356
        m_sheetCount = aSheetCount;
468
357
    }
469
358
 
470
 
    /* Function SetMargins
 
359
    /** Function SetMargins
471
360
     * Set the left top margin and the right bottom margin
472
361
     * of the page layout
473
362
     * @param aLTmargin The left top margin of the page layout.
505
394
    }
506
395
 
507
396
    /**
508
 
     * Draws the item list crated by BuildWorkSheetGraphicList
 
397
     * Draws the item list created by BuildWorkSheetGraphicList
509
398
     * @param aClipBox = the clipping rect, or NULL if no clipping
510
399
     * @param aDC = the current Device Context
511
400
     */
515
404
     * Function BuildWorkSheetGraphicList is a core function for
516
405
     * drawing or plotting the page layout with
517
406
     * the frame and the basic inscriptions.
518
 
     * It fills the list of basic graphic items to draw or plot.
 
407
     * It populates the list of basic graphic items to draw or plot.
519
408
     * currently lines, rect, polygons and texts
 
409
     * before calling this function, some parameters should be initialized:
 
410
     * by calling:
 
411
     *   SetPenSize( aPenWidth );
 
412
     *   SetMilsToIUfactor( aScalar );
 
413
     *   SetSheetNumber( aSheetNumber );
 
414
     *   SetSheetCount( aSheetCount );
 
415
     *   SetFileName( aFileName );
 
416
     *   SetSheetName( aFullSheetName );
520
417
     *
521
 
     * @param aPaperFormat The paper size type, for basic inscriptions.
522
 
     * @param aFileName The file name, for basic inscriptions.
523
 
     * @param aSheetPathHumanReadable The human readable sheet path.
 
418
     * @param aPageInfo The PAGE_INFO, for page size, margins...
524
419
     * @param aTitleBlock The sheet title block, for basic inscriptions.
525
420
     * @param aColor The color for drawing.
526
421
     * @param aAltColor The color for items which need to be "hightlighted".
527
422
     */
528
 
    void BuildWorkSheetGraphicList( const wxString& aPaperFormat,
529
 
                                    const wxString& aFileName,
530
 
                                    const wxString& aSheetPathHumanReadable,
 
423
    void BuildWorkSheetGraphicList( const PAGE_INFO& aPageInfo,
531
424
                                    const TITLE_BLOCK& aTitleBlock,
532
425
                                    EDA_COLOR_T aColor, EDA_COLOR_T aAltColor );
533
426
    /**
559
452
     * @return the text, after replacing the format symbols by the actual value
560
453
     */
561
454
    wxString BuildFullText( const wxString& aTextbase );
 
455
 
 
456
    /**
 
457
     * Locate graphic items in m_graphicList at location aPosition
 
458
     * @param aList = the list of items found
 
459
     * @param aPosition the position (in user units) to locate items
 
460
     */
 
461
    void Locate(std::vector <WS_DRAW_ITEM_BASE*>& aList, const wxPoint& aPosition);
562
462
};
563
463
 
564
464
 
565
465
/**
566
 
 * WORKSHEET_LAYOUT handles the grpahic items list to draw/plot
 
466
 * WORKSHEET_LAYOUT handles the graphic items list to draw/plot
567
467
 * the title block and other items (page references ...
568
468
 */
569
469
class WORKSHEET_LAYOUT
570
470
{
571
471
    std::vector <WORKSHEET_DATAITEM*> m_list;
 
472
    bool m_allowVoidList;   // If false, the default page layout
 
473
                            // will be loaded the first time
 
474
                            // WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList
 
475
                            // is run (useful mainly for page layout editor)
 
476
    double m_leftMargin;    // the left page margin in mm
 
477
    double m_rightMargin;   // the right page margin in mm
 
478
    double m_topMargin;     // the top page margin in mm
 
479
    double m_bottomMargin;  // the bottom page margin in mm
 
480
    bool   m_isDefaultDescr;    // true if the internal default descr is loaded
 
481
                                // mainly used in Kicad GOST version, until
 
482
                                // a GOST page descr file is available
 
483
                                // to force the GOST default title block
572
484
 
573
485
public:
574
 
    WORKSHEET_LAYOUT() {};
 
486
    WORKSHEET_LAYOUT();
575
487
    ~WORKSHEET_LAYOUT() {ClearList(); }
576
488
 
577
 
    void ClearList()
 
489
    /**
 
490
     * static function: returns the instance of WORKSHEET_LAYOUT
 
491
     * used in the application
 
492
     */
 
493
    static WORKSHEET_LAYOUT& GetTheInstance()
578
494
    {
579
 
        for( unsigned ii = 0; ii < m_list.size(); ii++ )
580
 
            delete m_list[ii];
 
495
        extern WORKSHEET_LAYOUT wksTheInstance;
 
496
        return wksTheInstance;
581
497
    }
582
498
 
 
499
    // Accessors:
 
500
    bool IsDefaultDescr() { return m_isDefaultDescr; }
 
501
    void SetDefaultDescrFlag( bool aFlg ) { m_isDefaultDescr = aFlg; }
 
502
 
 
503
    double GetLeftMargin() { return m_leftMargin; }
 
504
    double GetRightMargin() { return m_rightMargin; }
 
505
    double GetTopMargin() { return m_topMargin; }
 
506
    double GetBottomMargin() { return m_bottomMargin; }
 
507
 
 
508
    void SetLeftMargin( double aMargin );
 
509
    void SetRightMargin( double aMargin );
 
510
    void SetTopMargin( double aMargin );
 
511
    void SetBottomMargin( double aMargin );
 
512
 
 
513
    /**
 
514
     * In Kicad applications, a page layout description is needed
 
515
     * So if the list is empty, a default description is loaded,
 
516
     * the first time a page layout is drawn.
 
517
     * However, in page layout editor, an empty list is acceptable.
 
518
     * AllowVoidList allows or not the empty list
 
519
     */
 
520
    void AllowVoidList( bool Allow ) { m_allowVoidList = Allow; }
 
521
 
 
522
    /**
 
523
     * @return true if an empty list is allowed
 
524
     * (mainly allowed for page layout editor).
 
525
     */
 
526
    bool VoidListAllowed() { return m_allowVoidList; }
 
527
 
 
528
    /**
 
529
     * erase the list of items
 
530
     */
 
531
    void ClearList();
 
532
 
 
533
    /**
 
534
     * Save the description in a file
 
535
     * @param aFullFileName the filename of the file to created
 
536
     */
 
537
    void Save( const wxString& aFullFileName );
 
538
 
 
539
    /**
 
540
     * Save the description in a buffer
 
541
     * @param aOutputString = a wxString to store the S expr string
 
542
     */
 
543
    void SaveInString( wxString& aOutputString );
 
544
 
583
545
    /**
584
546
     * Add an item to the list of items
585
547
     */
589
551
    }
590
552
 
591
553
    /**
 
554
     *Insert an item to the list of items at position aIdx
 
555
     */
 
556
    void Insert( WORKSHEET_DATAITEM* aItem, unsigned aIdx );
 
557
 
 
558
    /**
 
559
     *Remove the item to the list of items at position aIdx
 
560
     */
 
561
    bool  Remove( unsigned aIdx );
 
562
 
 
563
    /**
 
564
     *Remove the item to the list of items at position aIdx
 
565
     */
 
566
    bool  Remove( WORKSHEET_DATAITEM* aItem );
 
567
 
 
568
    /**
 
569
     * @return the index of aItem, or -1 if does not exist
 
570
     */
 
571
    int GetItemIndex( WORKSHEET_DATAITEM* aItem ) const;
 
572
 
 
573
    /**
592
574
     * @return the item from its index aIdx, or NULL if does not exist
593
575
     */
594
 
    WORKSHEET_DATAITEM* GetItem( unsigned aIdx ) const
595
 
    {
596
 
        if( aIdx < m_list.size() )
597
 
            return m_list[aIdx];
598
 
        else
599
 
            return NULL;
600
 
    }
 
576
    WORKSHEET_DATAITEM* GetItem( unsigned aIdx ) const;
601
577
 
602
578
    /**
603
579
     * @return the item count
610
586
    void SetDefaultLayout();
611
587
 
612
588
    /**
613
 
     * Fills the list with a custom layout, or
 
589
     * Populates the list with a custom layout, or
614
590
     * the default layout, if no custom layout available
615
 
     */
616
 
    void SetLayout();
617
 
 
 
591
     * @param aFullFileName = the custom page layout description file.
 
592
     * if empty, loads the file defined by KICAD_WKSFILE
 
593
     * and if its is not defined, uses the default internal description
 
594
     * @param Append = if true: do not delete old layout, and load only
 
595
       aFullFileName.
 
596
     */
 
597
    void SetPageLayout( const wxString& aFullFileName = wxEmptyString,
 
598
                        bool Append = false );
 
599
 
 
600
    /**
 
601
     * Populates the list from a S expr description stored in a string
 
602
     * @param aPageLayout = the S expr string
 
603
     */
 
604
    void SetPageLayout( const char* aPageLayout, bool Append = false );
 
605
 
 
606
    /**
 
607
     * @return a short filename  from a full filename:
 
608
     * if the path is the current path, or if the path
 
609
     * is the same as kicad.pro (in template), returns the shortname
 
610
     * else do nothing and returns a full filename
 
611
     */
 
612
    static const wxString MakeShortFileName( const wxString& aFullFileName );
 
613
 
 
614
    /**
 
615
     * @return a full filename from a short filename,
 
616
     * if the short filename path is void
 
617
     * In this case the path is the same as kicad.pro (in template)
 
618
     * else return the short filename (which have an absolute os relative path
 
619
      */
 
620
    static const wxString MakeFullFileName( const wxString& aShortFileName );
618
621
};
619
622
 
620
623
#endif      // WORKSHEET_SHAPE_BUILDER_H