KiCad PCB EDA Suite
ws_data_item.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-2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2019 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 
30 #ifndef WORKSHEET_DATA_ITEM_H
31 #define WORKSHEET_DATA_ITEM_H
32 
33 #include <math/vector2d.h>
34 #include <eda_text.h>
35 #include <bitmap_base.h>
36 #include <view/view.h>
37 #include "ws_draw_item.h"
38 
39 class WS_DRAW_ITEM_TEXT; // Forward declaration
40 
41 #define TB_DEFAULT_TEXTSIZE 1.5 // default worksheet text size in mm
42 
49 {
50  RB_CORNER, // right bottom corner
51  RT_CORNER, // right top corner
52  LB_CORNER, // left bottom corner
53  LT_CORNER, // left top corner
54 };
55 
57 {
61 };
62 
69 {
70 public:
72  int m_Anchor;
73 public:
75 
76  POINT_COORD( DPOINT aPos, enum CORNER_ANCHOR aAnchor = RB_CORNER )
77  {
78  m_Pos = aPos;
79  m_Anchor = aAnchor;
80  }
81 };
82 
83 
94 {
95 public:
96  enum WS_ITEM_TYPE {
102  };
103 
104 protected:
107 
108  std::vector<WS_DRAW_ITEM_BASE*> m_drawItems;
109 
110 public:
111  wxString m_Name; // a item name used in page layout
112  // editor to identify items
113  wxString m_Info; // a comment, only useful in page
114  // layout editor
117  double m_LineWidth;
118  int m_RepeatCount; // repeat count for duplicate items
119  DPOINT m_IncrementVector; // For duplicate items: move vector
120  // for position increment
122 
123 public:
124  WS_DATA_ITEM( WS_ITEM_TYPE aType );
125 
126  virtual ~WS_DATA_ITEM() {}
127 
128  const std::vector<WS_DRAW_ITEM_BASE*>& GetDrawItems() const { return m_drawItems; }
129 
130  virtual void SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView );
131 
132  void SetStart( double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor = RB_CORNER )
133  {
134  m_Pos.m_Pos.x = aPosx;
135  m_Pos.m_Pos.y = aPosy;
136  m_Pos.m_Anchor = aAnchor;
137  }
138 
139  void SetEnd( double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor = RB_CORNER )
140  {
141  m_End.m_Pos.x = aPosx;
142  m_End.m_Pos.y = aPosy;
143  m_End.m_Anchor = aAnchor;
144  }
145 
146  // Accessors:
147  WS_ITEM_TYPE GetType() const { return m_type; }
148 
154  void SetPage1Option( PAGE_OPTION aChoice ) { m_pageOption = aChoice; }
155 
156  // Coordinate handling
157  const wxPoint GetStartPosUi( int ii = 0 ) const;
158  const wxPoint GetEndPosUi( int ii = 0 ) const;
159  const DPOINT GetStartPos( int ii = 0 ) const;
160  const DPOINT GetEndPos( int ii = 0 ) const;
161 
162  virtual int GetPenSizeUi();
163 
168  void MoveTo( DPOINT aPosition );
169 
174  void MoveToUi( wxPoint aPosition );
175 
180  void MoveStartPointTo( DPOINT aPosition );
181 
186  void MoveStartPointToUi( wxPoint aPosition );
187 
188 
195  void MoveEndPointTo( DPOINT aPosition );
196 
203  void MoveEndPointToUi( wxPoint aPosition );
204 
209  virtual bool IsInsidePage( int ii ) const;
210 
211  const wxString GetClassName() const;
212 };
213 
214 
216 {
217 public:
218  double m_Orient; // Orientation in degrees
219  std::vector<DPOINT> m_Corners; // corner list
220 
221 private:
222  std::vector<unsigned> m_polyIndexEnd; // index of the last point of each polygon
223  DPOINT m_minCoord; // min coord of corners, relative to m_Pos
224  DPOINT m_maxCoord; // max coord of corners, relative to m_Pos
225 
226 public:
228 
229  void SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override;
230 
231  virtual int GetPenSizeUi() override;
232 
237  void AppendCorner( const DPOINT& aCorner )
238  {
239  m_Corners.push_back( aCorner );
240  }
241 
247  {
248  m_polyIndexEnd.push_back( m_Corners.size() -1 );
249  }
250 
254  int GetPolyCount() const { return (int) m_polyIndexEnd.size(); }
255 
260  unsigned GetPolyIndexStart( unsigned aContour) const
261  {
262  if( aContour == 0 )
263  return 0;
264  else
265  return m_polyIndexEnd[aContour-1] + 1;
266  }
267 
272  unsigned GetPolyIndexEnd( unsigned aContour) const
273  {
274  return m_polyIndexEnd[aContour];
275  }
276 
281  const DPOINT GetCornerPosition( unsigned aIdx, int aRepeat = 0 ) const;
282 
287  const wxPoint GetCornerPositionUi( unsigned aIdx, int aRepeat = 0 ) const;
288 
292  void SetBoundingBox();
293 
294  bool IsInsidePage( int ii ) const override;
295 };
296 
297 
299 {
300 public:
301  wxString m_TextBase; // The basic text, with format symbols
302  wxString m_FullText; // The expanded text, shown on screen
303  double m_Orient; // Orientation in degrees
306  bool m_Italic;
307  bool m_Bold;
309  DSIZE m_BoundingBoxSize; // When not null, this is the max
310  // size of the full text.
311  // the text size will be modified
312  // to keep the full text insite this
313  // bound.
314  DSIZE m_ConstrainedTextSize; // Actual text size, if constrained by
315  // the m_BoundingBoxSize constraint
316 
317 
318 public:
319  WS_DATA_ITEM_TEXT( const wxString& aTextBase );
320 
321  void SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override;
322 
323  virtual int GetPenSizeUi() override;
324 
329  void MoveTo( DPOINT aPosition );
330 
340  void IncrementLabel( int aIncr );
341 
350  void SetConstrainedTextSize();
351 
352 
359 };
360 
361 
362 class BITMAP_BASE;
364 {
365 public:
367 
368 public:
371  {
372  m_ImageBitmap = aImage;
373  }
374 
375  void SyncDrawItems( WS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override;
376 
377  int GetPPI() const;
378  void SetPPI( int aBitmapPPI );
379 };
380 
381 
382 #endif // WORKSHEET_DATA_ITEM_H
void SetEnd(double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor=RB_CORNER)
Definition: ws_data_item.h:139
wxString m_Name
Definition: ws_data_item.h:111
void SyncDrawItems(WS_DRAW_ITEM_LIST *aCollector, KIGFX::VIEW *aView) override
void MoveToUi(wxPoint aPosition)
move item to a new position
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:44
void MoveTo(DPOINT aPosition)
move item to a new position
void MoveEndPointToUi(wxPoint aPosition)
move the ending point of the item to a new position has meaning only for items defined by 2 points (s...
const DPOINT GetStartPos(int ii=0) const
Work sheet structure type definitions.
Definition: ws_data_item.h:93
virtual bool IsInsidePage(int ii) const
std::vector< DPOINT > m_Corners
Definition: ws_data_item.h:219
void AppendCorner(const DPOINT &aCorner)
add a corner in corner list
Definition: ws_data_item.h:237
std::vector< unsigned > m_polyIndexEnd
Definition: ws_data_item.h:222
bool IsInsidePage(int ii) const override
virtual int GetPenSizeUi() override
void IncrementLabel(int aIncr)
Try to build text wihich is an increment of m_TextBase has meaning only if m_TextBase is a basic text...
void MoveEndPointTo(DPOINT aPosition)
move the ending point of the item to a new position has meaning only for items defined by 2 points (s...
BITMAP_BASE * m_ImageBitmap
Definition: ws_data_item.h:366
POINT_COORD m_End
Definition: ws_data_item.h:116
const wxPoint GetCornerPositionUi(unsigned aIdx, int aRepeat=0) const
void SetPage1Option(PAGE_OPTION aChoice)
Definition: ws_data_item.h:154
void SyncDrawItems(WS_DRAW_ITEM_LIST *aCollector, KIGFX::VIEW *aView) override
unsigned GetPolyIndexStart(unsigned aContour) const
Definition: ws_data_item.h:260
WS_DATA_ITEM_BITMAP(BITMAP_BASE *aImage)
Definition: ws_data_item.h:369
wxString m_Info
Definition: ws_data_item.h:113
unsigned GetPolyIndexEnd(unsigned aContour) const
Definition: ws_data_item.h:272
EDA_TEXT_HJUSTIFY_T m_Hjustify
Definition: ws_data_item.h:304
void MoveStartPointTo(DPOINT aPosition)
move the starting point of the item to a new position
bool ReplaceAntiSlashSequence()
Replace the '\''n' sequence by EOL and the sequence '\''\' by only one '\' inside m_FullText.
virtual int GetPenSizeUi()
const wxPoint GetStartPosUi(int ii=0) const
const DPOINT GetEndPos(int ii=0) const
This class handle bitmap images in KiCad.
Definition: bitmap_base.h:51
CORNER_ANCHOR
A coordinate is relative to a page corner.
Definition: ws_data_item.h:48
WS_DATA_ITEM(WS_ITEM_TYPE aType)
void CloseContour()
Closes the current contour, by storing the index of the last corner of the current polygon in m_polyI...
Definition: ws_data_item.h:246
WS_ITEM_TYPE m_type
Definition: ws_data_item.h:105
DPOINT m_Pos
Definition: ws_data_item.h:71
WS_DATA_ITEM_TEXT(const wxString &aTextBase)
EDA_TEXT_VJUSTIFY_T m_Vjustify
Definition: ws_data_item.h:305
std::vector< WS_DRAW_ITEM_BASE * > m_drawItems
Definition: ws_data_item.h:108
void SyncDrawItems(WS_DRAW_ITEM_LIST *aCollector, KIGFX::VIEW *aView) override
A coordinate point The position is always relative to the corner anchor Note the coordinate is from t...
Definition: ws_data_item.h:68
const wxString GetClassName() const
DPOINT m_IncrementVector
Definition: ws_data_item.h:119
const std::vector< WS_DRAW_ITEM_BASE * > & GetDrawItems() const
Definition: ws_data_item.h:128
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:51
WS_ITEM_TYPE GetType() const
Definition: ws_data_item.h:147
void MoveStartPointToUi(wxPoint aPosition)
move the starting point of the item to a new position
virtual void SyncDrawItems(WS_DRAW_ITEM_LIST *aCollector, KIGFX::VIEW *aView)
double m_LineWidth
Definition: ws_data_item.h:117
const wxPoint GetEndPosUi(int ii=0) const
int GetPolyCount() const
Definition: ws_data_item.h:254
virtual int GetPenSizeUi() override
virtual ~WS_DATA_ITEM()
Definition: ws_data_item.h:126
POINT_COORD(DPOINT aPos, enum CORNER_ANCHOR aAnchor=RB_CORNER)
Definition: ws_data_item.h:76
DSIZE m_ConstrainedTextSize
Definition: ws_data_item.h:314
const DPOINT GetCornerPosition(unsigned aIdx, int aRepeat=0) const
void SetBoundingBox()
calculate the bounding box of the set polygons
void MoveTo(DPOINT aPosition)
move item to a new position
void SetConstrainedTextSize()
Calculates m_ConstrainedTextSize from m_TextSize to keep the X size and the full Y size of the text s...
int m_IncrementLabel
Definition: ws_data_item.h:121
void SetPPI(int aBitmapPPI)
PAGE_OPTION m_pageOption
Definition: ws_data_item.h:106
Class VIEW.
Definition: view.h:61
POINT_COORD m_Pos
Definition: ws_data_item.h:115
PAGE_OPTION GetPage1Option() const
Definition: ws_data_item.h:153
PAGE_OPTION
Definition: ws_data_item.h:56
void SetStart(double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor=RB_CORNER)
Definition: ws_data_item.h:132