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( const wxPoint& aPosition) = 0;
123 
130  virtual bool HitTestEndPoint( 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( const wxPoint& aPosition) override;
180 
186  virtual bool HitTestEndPoint( 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( 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( const wxPoint& aPosition) override;
272 
278  virtual bool HitTestEndPoint( 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( 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( const wxPoint& aPosition) override;
363 
364  const wxPoint GetPosition() { 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  const 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 = 0;
404  m_titleBlock = NULL;
405  m_paperFormat = NULL;
406  m_sheetFullName = NULL;
407  }
408 
410  {
411  for( unsigned ii = 0; ii < m_graphicList.size(); ii++ )
412  delete m_graphicList[ii];
413  }
414 
419  void SetFileName( const wxString & aFileName )
420  {
421  m_fileName = aFileName;
422  }
423 
428  void SetSheetName( const wxString & aSheetName )
429  {
430  m_sheetFullName = &aSheetName;
431  }
432 
437  void SetSheetLayer( const wxString & aSheetLayer )
438  {
439  m_sheetLayer = &aSheetLayer;
440  }
441 
446  void SetPenSize( int aPenSize )
447  {
448  m_penSize = aPenSize;
449  }
450 
455  void SetMilsToIUfactor( double aScale )
456  {
457  m_milsToIu = aScale;
458  }
459 
464  void SetPageSize( const wxSize& aPageSize )
465  {
466  m_pageSize = aPageSize;
467  }
468 
474  void SetSheetNumber( int aSheetNumber )
475  {
476  m_sheetNumber = aSheetNumber;
477  }
478 
484  void SetSheetCount( int aSheetCount )
485  {
486  m_sheetCount = aSheetCount;
487  }
488 
495  void SetMargins( const wxPoint& aLTmargin, const wxPoint& aRBmargin )
496  {
497  m_LTmargin = aLTmargin;
498  m_RBmargin = aRBmargin;
499  }
500 
501  void Append( WS_DRAW_ITEM_BASE* aItem )
502  {
503  m_graphicList.push_back( aItem );
504  }
505 
507  {
508  m_idx = 0;
509 
510  if( m_graphicList.size() )
511  return m_graphicList[0];
512  else
513  return NULL;
514  }
515 
517  {
518  m_idx++;
519 
520  if( m_graphicList.size() > m_idx )
521  return m_graphicList[m_idx];
522  else
523  return NULL;
524  }
525 
526  void GetAllItems( std::vector<WS_DRAW_ITEM_BASE*>* aList )
527  {
528  *aList = m_graphicList;
529  }
530 
536  void Draw( EDA_RECT* aClipBox, wxDC* aDC );
537 
558  void BuildWorkSheetGraphicList( const PAGE_INFO& aPageInfo,
559  const TITLE_BLOCK& aTitleBlock,
560  COLOR4D aColor, COLOR4D aAltColor );
589  wxString BuildFullText( const wxString& aTextbase );
590 
596  void Locate(std::vector <WS_DRAW_ITEM_BASE*>& aList, const wxPoint& aPosition);
597 };
598 
599 
605 {
606  std::vector <WORKSHEET_DATAITEM*> m_list;
607  bool m_allowVoidList; // If false, the default page layout
608  // will be loaded the first time
609  // WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList
610  // is run (useful mainly for page layout editor)
611  double m_leftMargin; // the left page margin in mm
612  double m_rightMargin; // the right page margin in mm
613  double m_topMargin; // the top page margin in mm
614  double m_bottomMargin; // the bottom page margin in mm
615 
616 public:
618  ~WORKSHEET_LAYOUT() {ClearList(); }
619 
624  static WORKSHEET_LAYOUT& GetTheInstance();
625 
632  static void SetAltInstance( WORKSHEET_LAYOUT* aLayout = NULL );
633 
634  // Accessors:
635  double GetLeftMargin() { return m_leftMargin; }
636  double GetRightMargin() { return m_rightMargin; }
637  double GetTopMargin() { return m_topMargin; }
638  double GetBottomMargin() { return m_bottomMargin; }
639 
640  void SetLeftMargin( double aMargin );
641  void SetRightMargin( double aMargin );
642  void SetTopMargin( double aMargin );
643  void SetBottomMargin( double aMargin );
644 
652  void AllowVoidList( bool Allow ) { m_allowVoidList = Allow; }
653 
658  bool VoidListAllowed() { return m_allowVoidList; }
659 
663  void ClearList();
664 
669  void Save( const wxString& aFullFileName );
670 
675  void SaveInString( wxString& aOutputString );
676 
680  void Append( WORKSHEET_DATAITEM* aItem )
681  {
682  m_list.push_back( aItem );
683  }
684 
688  void Insert( WORKSHEET_DATAITEM* aItem, unsigned aIdx );
689 
693  bool Remove( unsigned aIdx );
694 
698  bool Remove( WORKSHEET_DATAITEM* aItem );
699 
703  int GetItemIndex( WORKSHEET_DATAITEM* aItem ) const;
704 
708  WORKSHEET_DATAITEM* GetItem( unsigned aIdx ) const;
709 
713  unsigned GetCount() const { return m_list.size(); }
714 
718  void SetDefaultLayout();
719 
723  void SetEmptyLayout();
724 
728  static wxString EmptyLayout();
729 
733  static wxString DefaultLayout();
734 
744  void SetPageLayout( const wxString& aFullFileName = wxEmptyString,
745  bool Append = false );
746 
754  void SetPageLayout( const char* aPageLayout, bool aAppend = false,
755  const wxString& aSource = wxT( "Sexpr_string" ) );
756 
765  static const wxString MakeShortFileName( const wxString& aFullFileName,
766  const wxString& aProjectPath );
767 
779  static const wxString MakeFullFileName( const wxString& aShortFileName,
780  const wxString& aProjectPath );
781 };
782 
783 #endif // WORKSHEET_SHAPE_BUILDER_H
void SetTextAngle(double aAngle)
Definition: eda_text.h:154
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.
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:39
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:112
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.
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:49
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)
const wxString * m_sheetFullName
virtual bool HitTestStartPoint(const wxPoint &aPosition)=0
Abstract function: should exist for derived items return true if the point aPosition is near the star...
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
void SetMargins(const wxPoint &aLTmargin, const wxPoint &aRBmargin)
Function SetMargins Set the left top margin and the right bottom margin of the page layout...
virtual bool HitTestEndPoint(const wxPoint &aPosition)
return true if the point aPosition is near the ending point of this item This is avirtual function wh...
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