KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef DS_DATA_ITEM_H
22#define DS_DATA_ITEM_H
23
24#include <math/vector2d.h>
25#include <eda_text.h>
26#include <bitmap_base.h>
28
29class DS_DRAW_ITEM_TEXT; // Forward declaration
30
31#define TB_DEFAULT_TEXTSIZE 1.5 // default drawing sheet text size in mm
32
33namespace KIGFX
34{
35class VIEW;
36}
37
44{
45 RB_CORNER, // right bottom corner
46 RT_CORNER, // right top corner
47 LB_CORNER, // left bottom corner
48 LT_CORNER, // left top corner
49};
50
57
63constexpr int DS_MAX_REPEAT_COUNT = 100;
64
73{
74public:
76
77 POINT_COORD( const VECTOR2D& aPos, enum CORNER_ANCHOR aAnchor = RB_CORNER )
78 {
79 m_Pos = aPos;
80 m_Anchor = aAnchor;
81 }
82
85};
86
87
99{
100public:
108
109 DS_DATA_ITEM( DS_ITEM_TYPE aType );
110
111 virtual ~DS_DATA_ITEM();
112
113 const std::vector<DS_DRAW_ITEM_BASE*>& GetDrawItems() const { return m_drawItems; }
114
115 virtual void SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView );
116
117 void SetStart( double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor = RB_CORNER )
118 {
119 m_Pos.m_Pos.x = aPosx;
120 m_Pos.m_Pos.y = aPosy;
121 m_Pos.m_Anchor = aAnchor;
122 }
123
124 void SetEnd( double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor = RB_CORNER )
125 {
126 m_End.m_Pos.x = aPosx;
127 m_End.m_Pos.y = aPosy;
128 m_End.m_Anchor = aAnchor;
129 }
130
131 DS_ITEM_TYPE GetType() const { return m_type; }
132
137 void SetPage1Option( PAGE_OPTION aChoice ) { m_pageOption = aChoice; }
138
139 // Coordinate handling
140 const VECTOR2I GetStartPosIU( int ii = 0 ) const;
141 const VECTOR2I GetEndPosIU( int ii = 0 ) const;
142 const VECTOR2D GetStartPos( int ii = 0 ) const;
143 const VECTOR2D GetEndPos( int ii = 0 ) const;
144
145 virtual int GetPenSizeIU();
146
152 void MoveTo( const VECTOR2D& aPosition );
153
159 void MoveToIU( const VECTOR2I& aPosition );
160
166 void MoveStartPointTo( const VECTOR2D& aPosition );
167
173 void MoveStartPointToIU( const VECTOR2I& aPosition );
174
175
183 void MoveEndPointTo( const VECTOR2D& aPosition );
184
192 void MoveEndPointToIU( const VECTOR2I& aPosition );
193
197 virtual bool IsInsidePage( int ii ) const;
198
199 const wxString GetClassName() const;
200
201 wxString m_Name; // a name used in drawing sheet editor to identify items
202 wxString m_Info; // a comment, only useful in drawing sheet editor
206 int m_RepeatCount; // repeat count for duplicate items
207 VECTOR2D m_IncrementVector; // for duplicate items: move vector for position increment
209
210protected:
213
214 std::vector<DS_DRAW_ITEM_BASE*> m_drawItems;
215};
216
217
219{
220public:
222
223 void SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override;
224
225 virtual int GetPenSizeIU() override;
226
232 void AppendCorner( const VECTOR2D& aCorner )
233 {
234 m_Corners.push_back( aCorner );
235 }
236
242 {
243 m_polyIndexEnd.push_back( m_Corners.size() -1 );
244 }
245
249 int GetPolyCount() const { return (int) m_polyIndexEnd.size(); }
250
255 unsigned GetPolyIndexStart( unsigned aContour ) const
256 {
257 if( aContour == 0 )
258 return 0;
259 else
260 return m_polyIndexEnd[aContour-1] + 1;
261 }
262
267 unsigned GetPolyIndexEnd( unsigned aContour ) const
268 {
269 return m_polyIndexEnd[aContour];
270 }
271
275 const VECTOR2D GetCornerPosition( unsigned aIdx, int aRepeat = 0 ) const;
276
281 const VECTOR2I GetCornerPositionIU( unsigned aIdx, int aRepeat = 0 ) const;
282
286 void SetBoundingBox();
287
288 bool IsInsidePage( int ii ) const override;
289
290 EDA_ANGLE m_Orient; // Orientation
291 std::vector<VECTOR2D> m_Corners; // corner list
292
293private:
294 std::vector<unsigned> m_polyIndexEnd; // index of the last point of each polygon
295 VECTOR2D m_minCoord; // min coord of corners, relative to m_Pos
296 VECTOR2D m_maxCoord; // max coord of corners, relative to m_Pos
297};
298
299
301{
302public:
303 DS_DATA_ITEM_TEXT( const wxString& aTextBase );
304
305 void SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override;
306
307 virtual int GetPenSizeIU() override;
308
316 void IncrementLabel( int aIncr );
317
327
334
335public:
336 wxString m_TextBase; // The basic text, with format symbols
337 wxString m_FullText; // The expanded text, shown on screen
338 double m_Orient; // Orientation in degrees
342 bool m_Bold;
346 VECTOR2D m_BoundingBoxSize; // When not null, this is the max size of the
347 // full text. The text size will be modified
348 // to keep the full text inside this bound.
349 VECTOR2D m_ConstrainedTextSize; // Actual text size, if constrained by
350 // the m_BoundingBoxSize constraint
351};
352
353
354class BITMAP_BASE;
355
357{
358public:
361 {
362 m_ImageBitmap = aImage;
363 }
364
365 void SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override;
366
367 int GetPPI() const;
368 void SetPPI( int aBitmapPPI );
369
370public:
372};
373
374
375#endif // DS_DATA_ITEM_H
This class handle bitmap images in KiCad.
Definition bitmap_base.h:45
BITMAP_BASE * m_ImageBitmap
void SyncDrawItems(DS_DRAW_ITEM_LIST *aCollector, KIGFX::VIEW *aView) override
DS_DATA_ITEM_BITMAP(BITMAP_BASE *aImage)
void SetPPI(int aBitmapPPI)
unsigned GetPolyIndexStart(unsigned aContour) const
unsigned GetPolyIndexEnd(unsigned aContour) const
const VECTOR2I GetCornerPositionIU(unsigned aIdx, int aRepeat=0) const
void SetBoundingBox()
Calculate the bounding box of the set polygons.
virtual int GetPenSizeIU() override
void SyncDrawItems(DS_DRAW_ITEM_LIST *aCollector, KIGFX::VIEW *aView) override
void CloseContour()
Close the current contour, by storing the index of the last corner of the current polygon in m_polyIn...
bool IsInsidePage(int ii) const override
std::vector< unsigned > m_polyIndexEnd
const VECTOR2D GetCornerPosition(unsigned aIdx, int aRepeat=0) const
void AppendCorner(const VECTOR2D &aCorner)
Add a corner in corner list.
std::vector< VECTOR2D > m_Corners
bool ReplaceAntiSlashSequence()
Replace the '\''n' sequence by EOL and the sequence '\''\' by only one '\' inside m_FullText.
void SyncDrawItems(DS_DRAW_ITEM_LIST *aCollector, KIGFX::VIEW *aView) override
void IncrementLabel(int aIncr)
Build an incremented copy of m_TextBase into m_FullText.
void SetConstrainedTextSize()
Calculate m_ConstrainedTextSize from m_TextSize to keep the X size and the full Y size of the text sm...
KIFONT::FONT * m_Font
GR_TEXT_H_ALIGN_T m_Hjustify
KIGFX::COLOR4D m_TextColor
virtual int GetPenSizeIU() override
VECTOR2D m_BoundingBoxSize
VECTOR2D m_ConstrainedTextSize
DS_DATA_ITEM_TEXT(const wxString &aTextBase)
GR_TEXT_V_ALIGN_T m_Vjustify
PAGE_OPTION GetPage1Option() const
virtual ~DS_DATA_ITEM()
void SetPage1Option(PAGE_OPTION aChoice)
DS_DATA_ITEM(DS_ITEM_TYPE aType)
const VECTOR2D GetEndPos(int ii=0) const
void MoveStartPointToIU(const VECTOR2I &aPosition)
Move the starting point of the item to a new position.
const VECTOR2D GetStartPos(int ii=0) const
void MoveStartPointTo(const VECTOR2D &aPosition)
Move the starting point of the item to a new position.
void MoveEndPointTo(const VECTOR2D &aPosition)
Move the ending point of the item to a new position.
virtual int GetPenSizeIU()
void MoveEndPointToIU(const VECTOR2I &aPosition)
Move the ending point of the item to a new position.
DS_ITEM_TYPE GetType() const
void MoveTo(const VECTOR2D &aPosition)
Move item to a new position.
void MoveToIU(const VECTOR2I &aPosition)
Move item to a new position.
std::vector< DS_DRAW_ITEM_BASE * > m_drawItems
const wxString GetClassName() const
wxString m_Name
const VECTOR2I GetStartPosIU(int ii=0) const
const VECTOR2I GetEndPosIU(int ii=0) const
void SetEnd(double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor=RB_CORNER)
VECTOR2D m_IncrementVector
POINT_COORD m_Pos
void SetStart(double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor=RB_CORNER)
wxString m_Info
virtual void SyncDrawItems(DS_DRAW_ITEM_LIST *aCollector, KIGFX::VIEW *aView)
PAGE_OPTION m_pageOption
DS_ITEM_TYPE m_type
const std::vector< DS_DRAW_ITEM_BASE * > & GetDrawItems() const
virtual bool IsInsidePage(int ii) const
double m_LineWidth
POINT_COORD m_End
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
A graphic text.
FONT is an abstract base class for both outline and stroke fonts.
Definition font.h:94
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
A coordinate point.
VECTOR2D m_Pos
POINT_COORD(const VECTOR2D &aPos, enum CORNER_ANCHOR aAnchor=RB_CORNER)
PAGE_OPTION
@ FIRST_PAGE_ONLY
@ SUBSEQUENT_PAGES
@ ALL_PAGES
CORNER_ANCHOR
A coordinate is relative to a page corner.
@ RB_CORNER
@ RT_CORNER
@ LT_CORNER
@ LB_CORNER
constexpr int DS_MAX_REPEAT_COUNT
Upper bound on DS_DATA_ITEM::m_RepeatCount.
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682