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-2021 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 drawing sheet 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( const 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  DS_DATA_ITEM( DS_ITEM_TYPE aType );
107 
108  virtual ~DS_DATA_ITEM();
109 
110  const std::vector<DS_DRAW_ITEM_BASE*>& GetDrawItems() const { return m_drawItems; }
111 
112  virtual void SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView );
113 
114  void SetStart( double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor = RB_CORNER )
115  {
116  m_Pos.m_Pos.x = aPosx;
117  m_Pos.m_Pos.y = aPosy;
118  m_Pos.m_Anchor = aAnchor;
119  }
120 
121  void SetEnd( double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor = RB_CORNER )
122  {
123  m_End.m_Pos.x = aPosx;
124  m_End.m_Pos.y = aPosy;
125  m_End.m_Anchor = aAnchor;
126  }
127 
128  DS_ITEM_TYPE GetType() const { return m_type; }
129 
134  void SetPage1Option( PAGE_OPTION aChoice ) { m_pageOption = aChoice; }
135 
136  // Coordinate handling
137  const wxPoint GetStartPosUi( int ii = 0 ) const;
138  const wxPoint GetEndPosUi( int ii = 0 ) const;
139  const DPOINT GetStartPos( int ii = 0 ) const;
140  const DPOINT GetEndPos( int ii = 0 ) const;
141 
142  virtual int GetPenSizeUi();
143 
149  void MoveTo( const DPOINT& aPosition );
150 
156  void MoveToUi( const wxPoint& aPosition );
157 
163  void MoveStartPointTo( const DPOINT& aPosition );
164 
170  void MoveStartPointToUi( const wxPoint& aPosition );
171 
172 
180  void MoveEndPointTo( const DPOINT& aPosition );
181 
189  void MoveEndPointToUi( const wxPoint& aPosition );
190 
194  virtual bool IsInsidePage( int ii ) const;
195 
196  const wxString GetClassName() const;
197 
198  wxString m_Name; // a name used in drawing sheet editor to identify items
199  wxString m_Info; // a comment, only useful in drawing sheet editor
202  double m_LineWidth;
203  int m_RepeatCount; // repeat count for duplicate items
204  DPOINT m_IncrementVector; // for duplicate items: move vector for position increment
206 
207 protected:
210 
211  std::vector<DS_DRAW_ITEM_BASE*> m_drawItems;
212 };
213 
214 
216 {
217 public:
219 
220  void SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override;
221 
222  virtual int GetPenSizeUi() override;
223 
229  void AppendCorner( const DPOINT& aCorner )
230  {
231  m_Corners.push_back( aCorner );
232  }
233 
239  {
240  m_polyIndexEnd.push_back( m_Corners.size() -1 );
241  }
242 
246  int GetPolyCount() const { return (int) m_polyIndexEnd.size(); }
247 
252  unsigned GetPolyIndexStart( unsigned aContour ) const
253  {
254  if( aContour == 0 )
255  return 0;
256  else
257  return m_polyIndexEnd[aContour-1] + 1;
258  }
259 
264  unsigned GetPolyIndexEnd( unsigned aContour ) const
265  {
266  return m_polyIndexEnd[aContour];
267  }
268 
272  const DPOINT GetCornerPosition( unsigned aIdx, int aRepeat = 0 ) const;
273 
278  const wxPoint GetCornerPositionUi( unsigned aIdx, int aRepeat = 0 ) const;
279 
283  void SetBoundingBox();
284 
285  bool IsInsidePage( int ii ) const override;
286 
287  double m_Orient; // Orientation in degrees
288  std::vector<DPOINT> m_Corners; // corner list
289 
290 private:
291  std::vector<unsigned> m_polyIndexEnd; // index of the last point of each polygon
292  DPOINT m_minCoord; // min coord of corners, relative to m_Pos
293  DPOINT m_maxCoord; // max coord of corners, relative to m_Pos
294 };
295 
296 
298 {
299 public:
300  DS_DATA_ITEM_TEXT( const wxString& aTextBase );
301 
302  void SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override;
303 
304  virtual int GetPenSizeUi() override;
305 
315  void IncrementLabel( int aIncr );
316 
325  void SetConstrainedTextSize();
326 
333 
334 public:
335  wxString m_TextBase; // The basic text, with format symbols
336  wxString m_FullText; // The expanded text, shown on screen
337  double m_Orient; // Orientation in degrees
340  bool m_Italic;
341  bool m_Bold;
343  DSIZE m_BoundingBoxSize; // When not null, this is the max size of the
344  // full text. The text size will be modified
345  // to keep the full text inside this bound.
346  DSIZE m_ConstrainedTextSize; // Actual text size, if constrained by
347  // the m_BoundingBoxSize constraint
348 };
349 
350 
351 class BITMAP_BASE;
352 
354 {
355 public:
358  {
359  m_ImageBitmap = aImage;
360  }
361 
362  void SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override;
363 
364  int GetPPI() const;
365  void SetPPI( int aBitmapPPI );
366 
367 public:
369 };
370 
371 
372 #endif // DS_DATA_ITEM_H
wxString m_Info
Definition: ds_data_item.h:199
const DPOINT GetEndPos(int ii=0) const
unsigned GetPolyIndexStart(unsigned aContour) const
Definition: ds_data_item.h:252
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:339
const DPOINT GetStartPos(int ii=0) const
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:236
const wxPoint GetEndPosUi(int ii=0) const
int GetPolyCount() const
Definition: ds_data_item.h:246
void SetEnd(double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor=RB_CORNER)
Definition: ds_data_item.h:121
void SetBoundingBox()
Calculate the bounding box of the set polygons.
void MoveEndPointToUi(const 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:288
POINT_COORD m_End
Definition: ds_data_item.h:201
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:264
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:338
A graphic text.
Definition: ds_draw_item.h:297
virtual ~DS_DATA_ITEM()
const wxPoint GetCornerPositionUi(unsigned aIdx, int aRepeat=0) const
void MoveTo(const DPOINT &aPosition)
Move item to a new position.
DPOINT m_IncrementVector
Definition: ds_data_item.h:204
void SetStart(double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor=RB_CORNER)
Definition: ds_data_item.h:114
void SyncDrawItems(DS_DRAW_ITEM_LIST *aCollector, KIGFX::VIEW *aView) override
double m_LineWidth
Definition: ds_data_item.h:202
DS_ITEM_TYPE GetType() const
Definition: ds_data_item.h:128
std::vector< DS_DRAW_ITEM_BASE * > m_drawItems
Definition: ds_data_item.h:211
BITMAP_BASE * m_ImageBitmap
Definition: ds_data_item.h:368
const wxString GetClassName() const
DPOINT m_Pos
Definition: ds_data_item.h:80
void CloseContour()
Close the current contour, by storing the index of the last corner of the current polygon in m_polyIn...
Definition: ds_data_item.h:238
int m_IncrementLabel
Definition: ds_data_item.h:205
PAGE_OPTION m_pageOption
Definition: ds_data_item.h:209
void SetPPI(int aBitmapPPI)
POINT_COORD(const DPOINT &aPos, enum CORNER_ANCHOR aAnchor=RB_CORNER)
Definition: ds_data_item.h:74
const std::vector< DS_DRAW_ITEM_BASE * > & GetDrawItems() const
Definition: ds_data_item.h:110
A coordinate point.
Definition: ds_data_item.h:69
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:356
void SetPage1Option(PAGE_OPTION aChoice)
Definition: ds_data_item.h:134
void MoveStartPointToUi(const wxPoint &aPosition)
Move the starting point of the item to a new position.
DSIZE m_ConstrainedTextSize
Definition: ds_data_item.h:346
POINT_COORD m_Pos
Definition: ds_data_item.h:200
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
void MoveStartPointTo(const DPOINT &aPosition)
Move the starting point of the item to a new position.
std::vector< unsigned > m_polyIndexEnd
Definition: ds_data_item.h:291
void MoveEndPointTo(const DPOINT &aPosition)
Move the ending point of the item to a new position.
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
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
void MoveToUi(const wxPoint &aPosition)
Move item to a new position.
wxString m_Name
Definition: ds_data_item.h:198
PAGE_OPTION
Definition: ds_data_item.h:55
void AppendCorner(const DPOINT &aCorner)
Add a corner in corner list.
Definition: ds_data_item.h:229
void IncrementLabel(int aIncr)
Try to build text which 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:208
PAGE_OPTION GetPage1Option() const
Definition: ds_data_item.h:133
const wxPoint GetStartPosUi(int ii=0) const