KiCad PCB EDA Suite
worksheet_shape_builder.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-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.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 
31 #ifndef WORKSHEET_SHAPE_BUILDER_H
32 #define WORKSHEET_SHAPE_BUILDER_H
33 
34 #include <math/vector2d.h>
35 #include <eda_text.h>
36 #include <eda_text.h>
37 #include <bitmap_base.h>
38 
39 class WORKSHEET_DATAITEM; // Forward declaration
40 class TITLE_BLOCK;
41 class PAGE_INFO;
42 
43 #define TB_DEFAULT_TEXTSIZE 1.5 // default worksheet text size in mm
44 
45 /*
46  * Helper classes to handle basic graphic items used to raw/plot
47  * title blocks and frame references
48  * segments
49  * rect
50  * polygons (for logos)
51  * graphic texts
52  * bitmaps, also for logos, but they cannot be plot by SVG, GERBER
53  * and HPGL plotters (In this case, only the bounding box is plotted)
54  */
55 class WS_DRAW_ITEM_BASE // This basic class, not directly usable.
56 {
57 public:
58  enum WS_DRAW_TYPE {
60  };
61  int m_Flags; // temporary flgs used in page layout editor
62  // to locate the item;
63 
64 protected:
65  WS_DRAW_TYPE m_type; // wsg_line, wsg_rect, wsg_poly, wsg_text
67  WORKSHEET_DATAITEM* m_parent; // an unique identifier, used as link
68  // to the parent WORKSHEET_DATAITEM item,
69  // in page layout editor
70 
72  WS_DRAW_TYPE aType, COLOR4D aColor )
73  {
74  m_type = aType;
75  m_color = aColor;
76  m_parent = aParent;
77  m_Flags = 0;
78  }
79 
80 public:
81  virtual ~WS_DRAW_ITEM_BASE() {}
82 
83  // Accessors:
84  COLOR4D GetColor() const { return m_color; }
85  WS_DRAW_TYPE GetType() const { return m_type; };
86 
87  WORKSHEET_DATAITEM* GetParent() const { return m_parent; }
88 
91  virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC)
92  {
93  wxPoint offset( 0, 0 );
94  DrawWsItem( aClipBox, aDC, offset, UNSPECIFIED_DRAWMODE, COLOR4D::UNSPECIFIED );
95  }
96 
99  virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
100  GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) = 0;
101 
106  virtual bool HitTest( const wxPoint& aPosition) const = 0;
107 
112  virtual bool HitTest( const EDA_RECT& aRect ) const = 0;
113 
122  virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) = 0;
123 
130  virtual bool HitTestEndPoint( wxDC *aDC, const wxPoint& aPosition)
131  {
132  return false;
133  }
134 };
135 
136 // This class draws a thick segment
138 {
139  wxPoint m_start; // start point of line/rect
140  wxPoint m_end; // end point
142 
143 public:
145  wxPoint aStart, wxPoint aEnd,
146  int aPenWidth, COLOR4D aColor ) :
147  WS_DRAW_ITEM_BASE( aParent, wsg_line, aColor )
148  {
149  m_start = aStart;
150  m_end = aEnd;
151  m_penWidth = aPenWidth;
152  }
153 
154  // Accessors:
155  int GetPenWidth() const { return m_penWidth; }
156  const wxPoint& GetStart() const { return m_start; }
157  const wxPoint& GetEnd() const { return m_end; }
158 
161  virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
162  GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override;
163 
168  virtual bool HitTest( const wxPoint& aPosition) const override;
169 
174  virtual bool HitTest( const EDA_RECT& aRect ) const override;
175 
179  virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override;
180 
186  virtual bool HitTestEndPoint( wxDC *aDC, const wxPoint& aPosition ) override;
187 };
188 
189 // This class draws a polygon
191 {
192  wxPoint m_pos; // position of reference point, from the
193  // WORKSHEET_DATAITEM_POLYPOLYGON parent
194  // (used only in page layout editor to draw anchors)
196  bool m_fill;
197 
198 public:
199  std::vector <wxPoint> m_Corners;
200 
201 public:
203  bool aFill, int aPenWidth, COLOR4D aColor ) :
204  WS_DRAW_ITEM_BASE( aParent, wsg_poly, aColor )
205  {
206  m_penWidth = aPenWidth;
207  m_fill = aFill;
208  m_pos = aPos;
209  }
210 
211  // Accessors:
212  int GetPenWidth() const { return m_penWidth; }
213  bool IsFilled() const { return m_fill; }
214  const wxPoint GetPosition() const { return m_pos; }
215 
218  virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
219  GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override;
220 
225  virtual bool HitTest( const wxPoint& aPosition) const override;
226 
231  virtual bool HitTest( const EDA_RECT& aRect ) const override;
232 
236  virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override;
237 };
238 
239 // This class draws a not filled rectangle with thick segment
241 {
242 public:
244  wxPoint aStart, wxPoint aEnd,
245  int aPenWidth, COLOR4D aColor ) :
246  WS_DRAW_ITEM_LINE( aParent, aStart, aEnd, aPenWidth, aColor )
247  {
248  m_type = wsg_rect;
249  }
250 
253  virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
254  GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override;
255 
260  virtual bool HitTest( const wxPoint& aPosition) const override;
261 
266  virtual bool HitTest( const EDA_RECT& aRect ) const override;
267 
271  virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override;
272 
278  virtual bool HitTestEndPoint( wxDC *aDC, const wxPoint& aPosition ) override;
279 };
280 
281 // This class draws a graphic text.
282 // it is derived from an EDA_TEXT, so it handle all caracteristics
283 // of this graphic text (justification, rotation ... )
285 {
286 public:
288  wxString& aText, wxPoint aPos, wxSize aSize,
289  int aPenWidth, COLOR4D aColor,
290  bool aItalic = false, bool aBold = false );
291 
294  virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
295  GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override;
296 
297  // Accessors:
298  int GetPenWidth() { return GetThickness(); }
299 
300  void SetTextAngle( double aAngle )
301  {
303  }
304 
309  virtual bool HitTest( const wxPoint& aPosition) const override;
310 
315  virtual bool HitTest( const EDA_RECT& aRect ) const override;
316 
320  virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override;
321 };
322 
323 // This class draws a bitmap.
325 {
326  wxPoint m_pos; // position of reference point
327 
328 public:
330  :WS_DRAW_ITEM_BASE( aParent, wsg_bitmap, COLOR4D::UNSPECIFIED )
331  {
332  m_pos = aPos;
333  }
334 
336  :WS_DRAW_ITEM_BASE( NULL, wsg_bitmap, COLOR4D::UNSPECIFIED )
337  {
338  }
339 
341 
344  virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
345  GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override;
346 
351  virtual bool HitTest( const wxPoint& aPosition) const override;
352 
357  virtual bool HitTest( const EDA_RECT& aRect ) const override;
358 
362  virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override;
363 
364  const wxPoint GetPosition() const { return m_pos; }
365 };
366 
367 /*
368  * this class stores the list of graphic items:
369  * rect, lines, polygons and texts to draw/plot
370  * the title block and frame references, and parameters to
371  * draw/plot them
372  */
374 {
375 protected:
376  std::vector <WS_DRAW_ITEM_BASE*> m_graphicList; // Items to draw/plot
377  unsigned m_idx; // for GetFirst, GetNext functions
378  wxPoint m_LTmargin; // The left top margin in mils of the page layout.
379  wxPoint m_RBmargin; // The right bottom margin in mils of the page layout.
380  wxSize m_pageSize; // the page size in mils
381  double m_milsToIu; // the scalar to convert pages units ( mils)
382  // to draw/plot units.
383  int m_penSize; // The default line width for drawings.
384  // used when an item has a pen size = 0
385  int m_sheetNumber; // the value of the sheet number, for basic inscriptions
386  int m_sheetCount; // the value of the number of sheets, in schematic
387  // for basic inscriptions, in schematic
388  const TITLE_BLOCK* m_titleBlock; // for basic inscriptions
389  const wxString* m_paperFormat; // for basic inscriptions
390  wxString m_fileName; // for basic inscriptions
391  wxString m_sheetFullName; // for basic inscriptions
392  const wxString* m_sheetLayer; // for basic inscriptions
393 
394 
395 public:
397  {
398  m_idx = 0;
399  m_milsToIu = 1.0;
400  m_penSize = 1;
401  m_sheetNumber = 1;
402  m_sheetCount = 1;
403  m_sheetLayer = nullptr;
404  m_titleBlock = nullptr;
405  m_paperFormat = nullptr;
406  }
407 
409  {
410  for( unsigned ii = 0; ii < m_graphicList.size(); ii++ )
411  delete m_graphicList[ii];
412  }
413 
418  void SetFileName( const wxString& aFileName )
419  {
420  m_fileName = aFileName;
421  }
422 
427  void SetSheetName( const wxString& aSheetName )
428  {
429  m_sheetFullName = aSheetName;
430  }
431 
436  void SetSheetLayer( const wxString& aSheetLayer )
437  {
438  m_sheetLayer = &aSheetLayer;
439  }
440 
445  void SetPenSize( int aPenSize )
446  {
447  m_penSize = aPenSize;
448  }
449 
454  void SetMilsToIUfactor( double aScale )
455  {
456  m_milsToIu = aScale;
457  }
458 
463  void SetPageSize( const wxSize& aPageSize )
464  {
465  m_pageSize = aPageSize;
466  }
467 
473  void SetSheetNumber( int aSheetNumber )
474  {
475  m_sheetNumber = aSheetNumber;
476  }
477 
483  void SetSheetCount( int aSheetCount )
484  {
485  m_sheetCount = aSheetCount;
486  }
487 
494  void SetMargins( const wxPoint& aLTmargin, const wxPoint& aRBmargin )
495  {
496  m_LTmargin = aLTmargin;
497  m_RBmargin = aRBmargin;
498  }
499 
500  void Append( WS_DRAW_ITEM_BASE* aItem )
501  {
502  m_graphicList.push_back( aItem );
503  }
504 
506  {
507  m_idx = 0;
508 
509  if( m_graphicList.size() )
510  return m_graphicList[0];
511  else
512  return NULL;
513  }
514 
516  {
517  m_idx++;
518 
519  if( m_graphicList.size() > m_idx )
520  return m_graphicList[m_idx];
521  else
522  return NULL;
523  }
524 
525  void GetAllItems( std::vector<WS_DRAW_ITEM_BASE*>* aList )
526  {
527  *aList = m_graphicList;
528  }
529 
535  void Draw( EDA_RECT* aClipBox, wxDC* aDC );
536 
557  void BuildWorkSheetGraphicList( const PAGE_INFO& aPageInfo,
558  const TITLE_BLOCK& aTitleBlock,
559  COLOR4D aColor, COLOR4D aAltColor );
588  wxString BuildFullText( const wxString& aTextbase );
589 
595  void Locate(wxDC* aDC, std::vector <WS_DRAW_ITEM_BASE*>& aList, const wxPoint& aPosition);
596 };
597 
598 
604 {
605  std::vector <WORKSHEET_DATAITEM*> m_list;
606  bool m_allowVoidList; // If false, the default page layout
607  // will be loaded the first time
608  // WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList
609  // is run (useful mainly for page layout editor)
610  double m_leftMargin; // the left page margin in mm
611  double m_rightMargin; // the right page margin in mm
612  double m_topMargin; // the top page margin in mm
613  double m_bottomMargin; // the bottom page margin in mm
614 
615 public:
617  ~WORKSHEET_LAYOUT() {ClearList(); }
618 
623  static WORKSHEET_LAYOUT& GetTheInstance();
624 
631  static void SetAltInstance( WORKSHEET_LAYOUT* aLayout = NULL );
632 
633  // Accessors:
634  double GetLeftMargin() { return m_leftMargin; }
635  double GetRightMargin() { return m_rightMargin; }
636  double GetTopMargin() { return m_topMargin; }
637  double GetBottomMargin() { return m_bottomMargin; }
638 
639  void SetLeftMargin( double aMargin );
640  void SetRightMargin( double aMargin );
641  void SetTopMargin( double aMargin );
642  void SetBottomMargin( double aMargin );
643 
651  void AllowVoidList( bool Allow ) { m_allowVoidList = Allow; }
652 
657  bool VoidListAllowed() { return m_allowVoidList; }
658 
662  void ClearList();
663 
668  void Save( const wxString& aFullFileName );
669 
674  void SaveInString( wxString& aOutputString );
675 
679  void Append( WORKSHEET_DATAITEM* aItem )
680  {
681  m_list.push_back( aItem );
682  }
683 
687  void Insert( WORKSHEET_DATAITEM* aItem, unsigned aIdx );
688 
692  bool Remove( unsigned aIdx );
693 
697  bool Remove( WORKSHEET_DATAITEM* aItem );
698 
702  int GetItemIndex( WORKSHEET_DATAITEM* aItem ) const;
703 
707  WORKSHEET_DATAITEM* GetItem( unsigned aIdx ) const;
708 
712  unsigned GetCount() const { return m_list.size(); }
713 
717  void SetDefaultLayout();
718 
722  void SetEmptyLayout();
723 
727  static wxString EmptyLayout();
728 
732  static wxString DefaultLayout();
733 
743  void SetPageLayout( const wxString& aFullFileName = wxEmptyString,
744  bool Append = false );
745 
753  void SetPageLayout( const char* aPageLayout, bool aAppend = false,
754  const wxString& aSource = wxT( "Sexpr_string" ) );
755 
764  static const wxString MakeShortFileName( const wxString& aFullFileName,
765  const wxString& aProjectPath );
766 
778  static const wxString MakeFullFileName( const wxString& aShortFileName,
779  const wxString& aProjectPath );
780 };
781 
782 #endif // WORKSHEET_SHAPE_BUILDER_H
void SetTextAngle(double aAngle)
Definition: eda_text.h:169
WS_DRAW_ITEM_RECT(WORKSHEET_DATAITEM *aParent, wxPoint aStart, wxPoint aEnd, int aPenWidth, COLOR4D aColor)
const wxString * m_paperFormat
void AllowVoidList(bool Allow)
In Kicad applications, a page layout description is needed So if the list is empty, a default description is loaded, the first time a page layout is drawn.
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
void SetPenSize(int aPenSize)
Function SetPenSize Set the default pen size to draw/plot lines and texts.
const wxPoint GetPosition() const
WS_DRAW_ITEM_BASE * GetNext()
void GetAllItems(std::vector< WS_DRAW_ITEM_BASE * > *aList)
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
const TITLE_BLOCK * m_titleBlock
WS_DRAW_ITEM_POLYGON(WORKSHEET_DATAITEM *aParent, wxPoint aPos, bool aFill, int aPenWidth, COLOR4D aColor)
WS_DRAW_ITEM_BASE * GetFirst()
Definition of base KiCad text object.
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:40
const wxString * m_sheetLayer
void Append(WS_DRAW_ITEM_BASE *aItem)
WS_DRAW_ITEM_BITMAP(WORKSHEET_DATAITEM *aParent, wxPoint aPos)
static struct PcbQueue * Save
Definition: queue.cpp:56
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels...
Definition: eda_text.h:127
void SetPageSize(const wxSize &aPageSize)
Function SetPageSize Set the size of the page layout.
void Append(WORKSHEET_DATAITEM *aItem)
Add an item to the list of items.
virtual bool HitTestEndPoint(wxDC *aDC, const wxPoint &aPosition)
return true if the point aPosition is near the ending point of this item This is avirtual function wh...
void SetSheetCount(int aSheetCount)
Function SetSheetCount Set the value of the count of sheets, for basic inscriptions.
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:54
WORKSHEET_DATAITEM * GetParent() const
virtual bool HitTest(const wxPoint &aPosition) const =0
Abstract function: should exist for derived items return true if the point aPosition is on the item...
void SetMilsToIUfactor(double aScale)
Function SetMilsToIUfactor Set the scalar to convert pages units ( mils) to draw/plot units...
const wxPoint & GetEnd() const
COLOR4D GetColor() const
std::vector< wxPoint > m_Corners
WS_DRAW_ITEM_LINE(WORKSHEET_DATAITEM *aParent, wxPoint aStart, wxPoint aEnd, int aPenWidth, COLOR4D aColor)
virtual void DrawWsItem(EDA_RECT *aClipBox, wxDC *aDC)
The function to draw a WS_DRAW_ITEM.
WORKSHEET_LAYOUT handles the graphic items list to draw/plot the title block and other items (page re...
unsigned GetCount() const
void SetTextAngle(double aAngle)
WORKSHEET_DATAITEM * m_parent
std::vector< WORKSHEET_DATAITEM * > m_list
void SetSheetNumber(int aSheetNumber)
Function SetSheetNumber Set the value of the sheet number, for basic inscriptions.
std::vector< WS_DRAW_ITEM_BASE * > m_graphicList
WS_DRAW_ITEM_BASE(WORKSHEET_DATAITEM *aParent, WS_DRAW_TYPE aType, COLOR4D aColor)
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
virtual bool HitTestStartPoint(wxDC *aDC, const wxPoint &aPosition)=0
Abstract function: should exist for derived items return true if the point aPosition is near the star...
void SetMargins(const wxPoint &aLTmargin, const wxPoint &aRBmargin)
Function SetMargins Set the left top margin and the right bottom margin of the page layout...
WS_DRAW_TYPE GetType() const
T NormalizeAngle360Min(T Angle)
Normalize angle to be > -360.0 and < 360.0 Angle equal to -360 or +360 are set to 0...
Definition: trigo.h:222
const wxPoint GetPosition() const
const wxPoint & GetStart() const
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39