KiCad PCB EDA Suite
ds_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-2020 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 
25 #ifndef DS_DATA_ITEM_H
26 #define DS_DATA_ITEM_H
27 
28 #include <math/vector2d.h>
29 #include <eda_text.h>
30 #include <bitmap_base.h>
32 
33 class DS_DRAW_ITEM_TEXT; // Forward declaration
34 
35 #define TB_DEFAULT_TEXTSIZE 1.5 // default worksheet text size in mm
36 
37 namespace KIGFX
38 {
39 class VIEW;
40 }
41 
48 {
49  RB_CORNER, // right bottom corner
50  RT_CORNER, // right top corner
51  LB_CORNER, // left bottom corner
52  LT_CORNER, // left top corner
53 };
54 
56 {
60 };
61 
70 {
71 public:
73 
74  POINT_COORD( DPOINT aPos, enum CORNER_ANCHOR aAnchor = RB_CORNER )
75  {
76  m_Pos = aPos;
77  m_Anchor = aAnchor;
78  }
79 
81  int m_Anchor;
82 };
83 
84 
96 {
97 public:
98  enum DS_ITEM_TYPE {
104  };
105 
106 public:
107  DS_DATA_ITEM( DS_ITEM_TYPE aType );
108 
109  virtual ~DS_DATA_ITEM();
110 
111  const std::vector<DS_DRAW_ITEM_BASE*>& GetDrawItems() const { return m_drawItems; }
112 
113  virtual void SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView );
114 
115  void SetStart( double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor = RB_CORNER )
116  {
117  m_Pos.m_Pos.x = aPosx;
118  m_Pos.m_Pos.y = aPosy;
119  m_Pos.m_Anchor = aAnchor;
120  }
121 
122  void SetEnd( double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor = RB_CORNER )
123  {
124  m_End.m_Pos.x = aPosx;
125  m_End.m_Pos.y = aPosy;
126  m_End.m_Anchor = aAnchor;
127  }
128 
129  DS_ITEM_TYPE GetType() const { return m_type; }
130 
135  void SetPage1Option( PAGE_OPTION aChoice ) { m_pageOption = aChoice; }
136 
137  // Coordinate handling
138  const wxPoint GetStartPosUi( int ii = 0 ) const;
139  const wxPoint GetEndPosUi( int ii = 0 ) const;
140  const DPOINT GetStartPos( int ii = 0 ) const;
141  const DPOINT GetEndPos( int ii = 0 ) const;
142 
143  virtual int GetPenSizeUi();
144 
150  void MoveTo( DPOINT aPosition );
151 
157  void MoveToUi( wxPoint aPosition );
158 
164  void MoveStartPointTo( DPOINT aPosition );
165 
171  void MoveStartPointToUi( wxPoint aPosition );
172 
173 
181  void MoveEndPointTo( DPOINT aPosition );
182 
190  void MoveEndPointToUi( wxPoint aPosition );
191 
195  virtual bool IsInsidePage( int ii ) const;
196 
197  const wxString GetClassName() const;
198 
199 protected:
202 
203  std::vector<DS_DRAW_ITEM_BASE*> m_drawItems;
204 
205 public:
206  wxString m_Name; // a item name used in page layout
207  // editor to identify items
208  wxString m_Info; // a comment, only useful in drawing sheet editor
211  double m_LineWidth;
212  int m_RepeatCount; // repeat count for duplicate items
213  DPOINT m_IncrementVector; // For duplicate items: move vector
214  // for position increment
216 };
217 
218 
220 {
221 public:
223 
224  void SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override;
225 
226  virtual int GetPenSizeUi() override;
227 
233  void AppendCorner( const DPOINT& aCorner )
234  {
235  m_Corners.push_back( aCorner );
236  }
237 
243  {
244  m_polyIndexEnd.push_back( m_Corners.size() -1 );
245  }
246 
250  int GetPolyCount() const { return (int) m_polyIndexEnd.size(); }
251 
256  unsigned GetPolyIndexStart( unsigned aContour) const
257  {
258  if( aContour == 0 )
259  return 0;
260  else
261  return m_polyIndexEnd[aContour-1] + 1;
262  }
263 
268  unsigned GetPolyIndexEnd( unsigned aContour) const
269  {
270  return m_polyIndexEnd[aContour];
271  }
272 
276  const DPOINT GetCornerPosition( unsigned aIdx, int aRepeat = 0 ) const;
277 
282  const wxPoint GetCornerPositionUi( unsigned aIdx, int aRepeat = 0 ) const;
283 
287  void SetBoundingBox();
288 
289  bool IsInsidePage( int ii ) const override;
290 
291  double m_Orient; // Orientation in degrees
292  std::vector<DPOINT> m_Corners; // corner list
293 
294 private:
295  std::vector<unsigned> m_polyIndexEnd; // index of the last point of each polygon
296  DPOINT m_minCoord; // min coord of corners, relative to m_Pos
297  DPOINT m_maxCoord; // max coord of corners, relative to m_Pos
298 };
299 
300 
302 {
303 public:
304  DS_DATA_ITEM_TEXT( const wxString& aTextBase );
305 
306  void SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override;
307 
308  virtual int GetPenSizeUi() override;
309 
319  void IncrementLabel( int aIncr );
320 
329  void SetConstrainedTextSize();
330 
331 
338 
339 public:
340  wxString m_TextBase; // The basic text, with format symbols
341  wxString m_FullText; // The expanded text, shown on screen
342  double m_Orient; // Orientation in degrees
345  bool m_Italic;
346  bool m_Bold;
348  DSIZE m_BoundingBoxSize; // When not null, this is the max size of the
349  // full text. The text size will be modified
350  // to keep the full text inside this bound.
351  DSIZE m_ConstrainedTextSize; // Actual text size, if constrained by
352  // the m_BoundingBoxSize constraint
353 };
354 
355 
356 class BITMAP_BASE;
357 
359 {
360 public:
363  {
364  m_ImageBitmap = aImage;
365  }
366 
367  void SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override;
368 
369  int GetPPI() const;
370  void SetPPI( int aBitmapPPI );
371 
372 public:
374 };
375 
376 
377 #endif // DS_DATA_ITEM_H
wxString m_Info
Definition: ds_data_item.h:208
const DPOINT GetEndPos(int ii=0) const
unsigned GetPolyIndexStart(unsigned aContour) const
Definition: ds_data_item.h:256
bool IsInsidePage(int ii) const override
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:61
void SetConstrainedTextSize()
Calculate m_ConstrainedTextSize from m_TextSize to keep the X size and the full Y size of the text sm...
DS_DATA_ITEM(DS_ITEM_TYPE aType)
EDA_TEXT_VJUSTIFY_T m_Vjustify
Definition: ds_data_item.h:344
const DPOINT GetStartPos(int ii=0) const
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
const wxPoint GetEndPosUi(int ii=0) const
int GetPolyCount() const
Definition: ds_data_item.h:250
void SetEnd(double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor=RB_CORNER)
Definition: ds_data_item.h:122
void SetBoundingBox()
Calculate the bounding box of the set polygons.
void MoveEndPointToUi(wxPoint aPosition)
Move the ending point of the item to a new position.
virtual bool IsInsidePage(int ii) const
std::vector< DPOINT > m_Corners
Definition: ds_data_item.h:292
POINT_COORD m_End
Definition: ds_data_item.h:210
void MoveEndPointTo(DPOINT aPosition)
Move the ending point of the item to a new position.
DS_DATA_ITEM_TEXT(const wxString &aTextBase)
void SyncDrawItems(DS_DRAW_ITEM_LIST *aCollector, KIGFX::VIEW *aView) override
virtual int GetPenSizeUi() override
unsigned GetPolyIndexEnd(unsigned aContour) const
Definition: ds_data_item.h:268
virtual void SyncDrawItems(DS_DRAW_ITEM_LIST *aCollector, KIGFX::VIEW *aView)
CORNER_ANCHOR
A coordinate is relative to a page corner.
Definition: ds_data_item.h:47
This class handle bitmap images in KiCad.
Definition: bitmap_base.h:51
EDA_TEXT_HJUSTIFY_T m_Hjustify
Definition: ds_data_item.h:343
A graphic text.
Definition: ds_draw_item.h:297
virtual ~DS_DATA_ITEM()
const wxPoint GetCornerPositionUi(unsigned aIdx, int aRepeat=0) const
DPOINT m_IncrementVector
Definition: ds_data_item.h:213
void SetStart(double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor=RB_CORNER)
Definition: ds_data_item.h:115
void SyncDrawItems(DS_DRAW_ITEM_LIST *aCollector, KIGFX::VIEW *aView) override
double m_LineWidth
Definition: ds_data_item.h:211
DS_ITEM_TYPE GetType() const
Definition: ds_data_item.h:129
std::vector< DS_DRAW_ITEM_BASE * > m_drawItems
Definition: ds_data_item.h:203
BITMAP_BASE * m_ImageBitmap
Definition: ds_data_item.h:373
const wxString GetClassName() const
DPOINT m_Pos
Definition: ds_data_item.h:80
void CloseContour()
Closes the current contour, by storing the index of the last corner of the current polygon in m_polyI...
Definition: ds_data_item.h:242
void MoveTo(DPOINT aPosition)
Move item to a new position.
int m_IncrementLabel
Definition: ds_data_item.h:215
PAGE_OPTION m_pageOption
Definition: ds_data_item.h:201
void SetPPI(int aBitmapPPI)
const std::vector< DS_DRAW_ITEM_BASE * > & GetDrawItems() const
Definition: ds_data_item.h:111
A coordinate point.
Definition: ds_data_item.h:69
void MoveStartPointTo(DPOINT aPosition)
Move the starting point of the item to a new position.
const DPOINT GetCornerPosition(unsigned aIdx, int aRepeat=0) const
virtual int GetPenSizeUi() override
virtual int GetPenSizeUi()
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:68
DS_DATA_ITEM_BITMAP(BITMAP_BASE *aImage)
Definition: ds_data_item.h:361
void SetPage1Option(PAGE_OPTION aChoice)
Definition: ds_data_item.h:135
DSIZE m_ConstrainedTextSize
Definition: ds_data_item.h:351
POINT_COORD m_Pos
Definition: ds_data_item.h:209
bool ReplaceAntiSlashSequence()
Replace the '\''n' sequence by EOL and the sequence '\''\' by only one '\' inside m_FullText.
Drawing sheet structure type definitions.
Definition: ds_data_item.h:95
POINT_COORD(DPOINT aPos, enum CORNER_ANCHOR aAnchor=RB_CORNER)
Definition: ds_data_item.h:74
std::vector< unsigned > m_polyIndexEnd
Definition: ds_data_item.h:295
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
Definition: ds_draw_item.h:376
void MoveToUi(wxPoint aPosition)
Move item to a new position.
void MoveStartPointToUi(wxPoint aPosition)
Move the starting point of the item to a new position.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
wxString m_Name
Definition: ds_data_item.h:206
PAGE_OPTION
Definition: ds_data_item.h:55
void AppendCorner(const DPOINT &aCorner)
Add a corner in corner list.
Definition: ds_data_item.h:233
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 SyncDrawItems(DS_DRAW_ITEM_LIST *aCollector, KIGFX::VIEW *aView) override
DS_ITEM_TYPE m_type
Definition: ds_data_item.h:200
PAGE_OPTION GetPage1Option() const
Definition: ds_data_item.h:134
const wxPoint GetStartPosUi(int ii=0) const