10
10
#include <math/vector2d.h>
11
11
#include <eda_text.h>
13
class WS_DRAW_ITEM_TEXT; // Forward declaration
13
class WORKSHEET_DATAITEM; // Forward declaration
15
16
#define TB_DEFAULT_TEXTSIZE 1.5 // default worksheet text size in mm
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
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
29
RB_CORNER, // right bottom corner
30
RT_CORNER, // right top corner
31
LB_CORNER, // left bottom corner
32
LT_CORNER, // left top corner
36
// The position is always relative to the corner anchor
37
// Note the coordinate is from the anchor point
38
// to the opposite corner.
45
POINT_COORD() { m_Anchor = RB_CORNER; }
46
POINT_COORD( DPOINT aPos, enum corner_anchor aAnchor = RB_CORNER )
54
// Work sheet structure type definitions.
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
75
int m_RepeatCount; // repeat count for duplicate items
76
DPOINT m_IncrementVector; // For duplicate items: move vector
77
// for position increment
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
84
static DPOINT m_LT_Corner; // cordinates of the left top corner
88
WORKSHEET_DATAITEM( WS_ItemType aType )
97
virtual ~WORKSHEET_DATAITEM() {}
99
void SetStart( double aPosx, double aPosy, enum corner_anchor aAnchor = RB_CORNER )
101
m_Pos.m_Pos.x = aPosx;
102
m_Pos.m_Pos.y = aPosy;
103
m_Pos.m_Anchor = aAnchor;
106
void SetEnd( double aPosx, double aPosy, enum corner_anchor aAnchor = RB_CORNER )
108
m_End.m_Pos.x = aPosx;
109
m_End.m_Pos.y = aPosy;
110
m_End.m_Anchor = aAnchor;
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 ); }
120
* @return true if the item is inside the rectangle defined by the
121
* 4 corners, false otherwise.
123
virtual bool IsInsidePage( int ii ) const;
126
class WORKSHEET_DATAITEM_POLYPOLYGON : public WORKSHEET_DATAITEM
129
double m_Orient; // Orientation in degrees
130
std::vector<DPOINT> m_Corners; // corner list
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
138
WORKSHEET_DATAITEM_POLYPOLYGON( );
141
* add a corner in corner list
142
* @param aCorner: the item to append
144
void AppendCorner( const DPOINT& aCorner )
146
m_Corners.push_back( aCorner );
150
* Closes the current contour, by storing the index of the last corner
151
* of the current polygon in m_polyIndexEnd.
155
m_polyIndexEnd.push_back( m_Corners.size() -1 );
159
* @return the count of contours in the poly polygon
161
int GetPolyCount() const { return (int) m_polyIndexEnd.size(); }
164
* @return the index of the first corner of the contour aCountour
165
* @param aContour = the index of the contour
167
unsigned GetPolyIndexStart( unsigned aContour) const
172
return m_polyIndexEnd[aContour-1] + 1;
176
* @return the index of the last corner of the contour aCountour
177
* @param aContour = the index of the contour
179
unsigned GetPolyIndexEnd( unsigned aContour) const
181
return m_polyIndexEnd[aContour];
185
* @return the coordinate (in mm) of the corner aIdx,
186
* for the repeated item aRepeat
188
const DPOINT GetCornerPosition( unsigned aIdx, int aRepeat = 0 ) const;
191
* @return the coordinate (in draw/plot units) of the corner aIdx,
192
* for the repeated item aRepeat
194
const wxPoint GetCornerPositionUi( unsigned aIdx, int aRepeat = 0 ) const;
197
* calculate the bounding box of the set polygons
199
void SetBoundingBox();
202
bool IsInsidePage( int ii ) const;
205
class WORKSHEET_DATAITEM_TEXT : public WORKSHEET_DATAITEM
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;
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
220
DSIZE m_ConstrainedTextSize;// Actual text size, if constrained by
221
// the m_BoundingBoxSize constraint
224
WORKSHEET_DATAITEM_TEXT( const wxChar* aTextBase );
227
* transfert the text justification and orientation
230
void TransfertSetupToGraphicText( WS_DRAW_ITEM_TEXT* aGText );
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
241
void IncrementLabel( int aIncr );
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
251
void SetConstrainedTextSize();
254
* @return true is a bold font should be selected
256
bool IsBold() { return (m_Flags & USE_BOLD) != 0; }
259
* @return true is an italic font should be selected
261
bool IsItalic() { return (m_Flags & USE_ITALIC) != 0; }
265
19
* Helper classes to handle basic graphic items used to raw/plot
266
20
* title blocks and frame references
328
149
std::vector <wxPoint> m_Corners;
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 )
334
156
m_penWidth = aPenWidth;
339
162
int GetPenWidth() { return m_penWidth; }
340
163
bool IsFilled() { return m_fill; }
164
const wxPoint& GetPosition() { return m_pos; }
166
/** The function to draw a WS_DRAW_ITEM_POLYGON
168
virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC );
172
* return true if the point aPosition is inside one polygon
174
virtual bool HitTest( const wxPoint& aPosition);
177
* return true if the point aPosition is on the starting point of this item.
179
virtual bool HitTestStartPoint( const wxPoint& aPosition);
343
182
// This class draws a not filled rectangle with thick segment
344
183
class WS_DRAW_ITEM_RECT : public WS_DRAW_ITEM_LINE
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 )
351
191
m_type = wsg_rect;
194
/** The function to draw a WS_DRAW_ITEM_RECT
196
virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC );
200
* return true if the point aPosition is on one edge of the rectangle
202
virtual bool HitTest( const wxPoint& aPosition);
205
* return true if the point aPosition is on the starting point of this item.
207
virtual bool HitTestStartPoint( const wxPoint& aPosition);
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
214
virtual bool HitTestEndPoint( const wxPoint& aPosition);
355
217
// This class draws a graphic text.
358
220
class WS_DRAW_ITEM_TEXT : public WS_DRAW_ITEM_BASE, public EDA_TEXT
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 )
366
SetTextPosition( aPos );
368
SetThickness( aPenWidth );
369
SetItalic( aItalic );
226
bool aItalic = false, bool aBold = false );
228
/** The function to draw a WS_DRAW_ITEM_TEXT
230
virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC );
374
233
int GetPenWidth() { return GetThickness(); }
237
* return true if the point aPosition is on the text
239
virtual bool HitTest( const wxPoint& aPosition);
242
* return true if the point aPosition is on the starting point of this item.
244
virtual bool HitTestStartPoint( const wxPoint& aPosition);
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:
411
* SetPenSize( aPenWidth );
412
* SetMilsToIUfactor( aScalar );
413
* SetSheetNumber( aSheetNumber );
414
* SetSheetCount( aSheetCount );
415
* SetFileName( aFileName );
416
* SetSheetName( aFullSheetName );
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".
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 );
559
452
* @return the text, after replacing the format symbols by the actual value
561
454
wxString BuildFullText( const wxString& aTextbase );
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
461
void Locate(std::vector <WS_DRAW_ITEM_BASE*>& aList, const wxPoint& aPosition);
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 ...
569
469
class WORKSHEET_LAYOUT
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
574
WORKSHEET_LAYOUT() {};
575
487
~WORKSHEET_LAYOUT() {ClearList(); }
490
* static function: returns the instance of WORKSHEET_LAYOUT
491
* used in the application
493
static WORKSHEET_LAYOUT& GetTheInstance()
579
for( unsigned ii = 0; ii < m_list.size(); ii++ )
495
extern WORKSHEET_LAYOUT wksTheInstance;
496
return wksTheInstance;
500
bool IsDefaultDescr() { return m_isDefaultDescr; }
501
void SetDefaultDescrFlag( bool aFlg ) { m_isDefaultDescr = aFlg; }
503
double GetLeftMargin() { return m_leftMargin; }
504
double GetRightMargin() { return m_rightMargin; }
505
double GetTopMargin() { return m_topMargin; }
506
double GetBottomMargin() { return m_bottomMargin; }
508
void SetLeftMargin( double aMargin );
509
void SetRightMargin( double aMargin );
510
void SetTopMargin( double aMargin );
511
void SetBottomMargin( double aMargin );
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
520
void AllowVoidList( bool Allow ) { m_allowVoidList = Allow; }
523
* @return true if an empty list is allowed
524
* (mainly allowed for page layout editor).
526
bool VoidListAllowed() { return m_allowVoidList; }
529
* erase the list of items
534
* Save the description in a file
535
* @param aFullFileName the filename of the file to created
537
void Save( const wxString& aFullFileName );
540
* Save the description in a buffer
541
* @param aOutputString = a wxString to store the S expr string
543
void SaveInString( wxString& aOutputString );
584
546
* Add an item to the list of items
610
586
void SetDefaultLayout();
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
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
597
void SetPageLayout( const wxString& aFullFileName = wxEmptyString,
598
bool Append = false );
601
* Populates the list from a S expr description stored in a string
602
* @param aPageLayout = the S expr string
604
void SetPageLayout( const char* aPageLayout, bool Append = false );
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
612
static const wxString MakeShortFileName( const wxString& aFullFileName );
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
620
static const wxString MakeFullFileName( const wxString& aShortFileName );
620
623
#endif // WORKSHEET_SHAPE_BUILDER_H