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
66{
67public:
69
70 POINT_COORD( const VECTOR2D& aPos, enum CORNER_ANCHOR aAnchor = RB_CORNER )
71 {
72 m_Pos = aPos;
73 m_Anchor = aAnchor;
74 }
75
78};
79
80
92{
93public:
101
102 DS_DATA_ITEM( DS_ITEM_TYPE aType );
103
104 virtual ~DS_DATA_ITEM();
105
106 const std::vector<DS_DRAW_ITEM_BASE*>& GetDrawItems() const { return m_drawItems; }
107
108 virtual void SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView );
109
110 void SetStart( double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor = RB_CORNER )
111 {
112 m_Pos.m_Pos.x = aPosx;
113 m_Pos.m_Pos.y = aPosy;
114 m_Pos.m_Anchor = aAnchor;
115 }
116
117 void SetEnd( double aPosx, double aPosy, enum CORNER_ANCHOR aAnchor = RB_CORNER )
118 {
119 m_End.m_Pos.x = aPosx;
120 m_End.m_Pos.y = aPosy;
121 m_End.m_Anchor = aAnchor;
122 }
123
124 DS_ITEM_TYPE GetType() const { return m_type; }
125
130 void SetPage1Option( PAGE_OPTION aChoice ) { m_pageOption = aChoice; }
131
132 // Coordinate handling
133 const VECTOR2I GetStartPosIU( int ii = 0 ) const;
134 const VECTOR2I GetEndPosIU( int ii = 0 ) const;
135 const VECTOR2D GetStartPos( int ii = 0 ) const;
136 const VECTOR2D GetEndPos( int ii = 0 ) const;
137
138 virtual int GetPenSizeIU();
139
145 void MoveTo( const VECTOR2D& aPosition );
146
152 void MoveToIU( const VECTOR2I& aPosition );
153
159 void MoveStartPointTo( const VECTOR2D& aPosition );
160
166 void MoveStartPointToIU( const VECTOR2I& aPosition );
167
168
176 void MoveEndPointTo( const VECTOR2D& aPosition );
177
185 void MoveEndPointToIU( const VECTOR2I& aPosition );
186
190 virtual bool IsInsidePage( int ii ) const;
191
192 const wxString GetClassName() const;
193
194 wxString m_Name; // a name used in drawing sheet editor to identify items
195 wxString m_Info; // a comment, only useful in drawing sheet editor
199 int m_RepeatCount; // repeat count for duplicate items
200 VECTOR2D m_IncrementVector; // for duplicate items: move vector for position increment
202
203protected:
206
207 std::vector<DS_DRAW_ITEM_BASE*> m_drawItems;
208};
209
210
212{
213public:
215
216 void SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override;
217
218 virtual int GetPenSizeIU() override;
219
225 void AppendCorner( const VECTOR2D& aCorner )
226 {
227 m_Corners.push_back( aCorner );
228 }
229
235 {
236 m_polyIndexEnd.push_back( m_Corners.size() -1 );
237 }
238
242 int GetPolyCount() const { return (int) m_polyIndexEnd.size(); }
243
248 unsigned GetPolyIndexStart( unsigned aContour ) const
249 {
250 if( aContour == 0 )
251 return 0;
252 else
253 return m_polyIndexEnd[aContour-1] + 1;
254 }
255
260 unsigned GetPolyIndexEnd( unsigned aContour ) const
261 {
262 return m_polyIndexEnd[aContour];
263 }
264
268 const VECTOR2D GetCornerPosition( unsigned aIdx, int aRepeat = 0 ) const;
269
274 const VECTOR2I GetCornerPositionIU( unsigned aIdx, int aRepeat = 0 ) const;
275
279 void SetBoundingBox();
280
281 bool IsInsidePage( int ii ) const override;
282
283 EDA_ANGLE m_Orient; // Orientation
284 std::vector<VECTOR2D> m_Corners; // corner list
285
286private:
287 std::vector<unsigned> m_polyIndexEnd; // index of the last point of each polygon
288 VECTOR2D m_minCoord; // min coord of corners, relative to m_Pos
289 VECTOR2D m_maxCoord; // max coord of corners, relative to m_Pos
290};
291
292
294{
295public:
296 DS_DATA_ITEM_TEXT( const wxString& aTextBase );
297
298 void SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override;
299
300 virtual int GetPenSizeIU() override;
301
311 void IncrementLabel( int aIncr );
312
322
329
330public:
331 wxString m_TextBase; // The basic text, with format symbols
332 wxString m_FullText; // The expanded text, shown on screen
333 double m_Orient; // Orientation in degrees
337 bool m_Bold;
341 VECTOR2D m_BoundingBoxSize; // When not null, this is the max size of the
342 // full text. The text size will be modified
343 // to keep the full text inside this bound.
344 VECTOR2D m_ConstrainedTextSize; // Actual text size, if constrained by
345 // the m_BoundingBoxSize constraint
346};
347
348
349class BITMAP_BASE;
350
352{
353public:
356 {
357 m_ImageBitmap = aImage;
358 }
359
360 void SyncDrawItems( DS_DRAW_ITEM_LIST* aCollector, KIGFX::VIEW* aView ) override;
361
362 int GetPPI() const;
363 void SetPPI( int aBitmapPPI );
364
365public:
367};
368
369
370#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)
Try to build text which is an increment of m_TextBase has meaning only if m_TextBase is a basic text ...
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
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:29
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