KiCad PCB EDA Suite
graphics_importer_buffer.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) 2017 CERN
5 * Copyright (C) 2018-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Janito Vaqueiro Ferreira Filho <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#ifndef GRAPHICS_IMPORTER_BUFFER_H
28#define GRAPHICS_IMPORTER_BUFFER_H
29
30#include "graphics_importer.h"
31
32#include <list>
33
35{
36public:
37 virtual ~IMPORTED_SHAPE() {}
38 virtual void ImportTo( GRAPHICS_IMPORTER& aImporter ) const = 0;
39
40 virtual std::unique_ptr<IMPORTED_SHAPE> clone() const = 0;
41
42 virtual void Translate( const VECTOR2D& aVec ) = 0;
43 virtual void Scale( double scaleX, double scaleY ) = 0;
44
45 void SetParentShapeIndex( int aIndex ) { m_parentShapeIndex = aIndex; }
47
48protected:
50};
51
52
54{
55public:
56 IMPORTED_LINE( const VECTOR2D& aStart, const VECTOR2D& aEnd, double aWidth ) :
57 m_start( aStart ),
58 m_end( aEnd ),
59 m_width( aWidth )
60 {
61 }
62
63 void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
64 {
65 aImporter.AddLine( m_start, m_end, m_width );
66 }
67
68 virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
69 {
70 return std::make_unique<IMPORTED_LINE>( *this );
71 }
72
73 void Translate( const VECTOR2D& aVec ) override
74 {
75 m_start += aVec;
76 m_end += aVec;
77 }
78
79 void Scale( double scaleX, double scaleY ) override
80 {
81 m_start.x *= scaleX;
82 m_start.y *= scaleY;
83 m_end.x *= scaleX;
84 m_end.y *= scaleY;
85 }
86
87private:
90 double m_width;
91};
92
93
95{
96public:
97 IMPORTED_CIRCLE( const VECTOR2D& aCenter, double aRadius, double aWidth, bool aFilled ) :
98 m_center( aCenter ),
99 m_radius( aRadius ),
100 m_width( aWidth ),
101 m_filled( aFilled )
102 {
103 }
104
105 void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
106 {
108 }
109
110 virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
111 {
112 return std::make_unique<IMPORTED_CIRCLE>( *this );
113 }
114
115 void Translate( const VECTOR2D& aVec ) override
116 {
117 m_center += aVec;
118 }
119
120 void Scale( double scaleX, double scaleY ) override
121 {
122 m_center.x *= scaleX;
123 m_center.y *= scaleY;
124
125 // we really can't handle scalex != scaleY cleanly...it would be an ellipse
126 m_radius *= scaleX;
127 }
128
129private:
131 double m_radius;
132 double m_width;
134};
135
136
138{
139public:
140 IMPORTED_ARC( const VECTOR2D& aCenter, const VECTOR2D& aStart, const EDA_ANGLE& aAngle,
141 double aWidth ) :
142 m_center( aCenter ),
143 m_start( aStart ),
144 m_angle( aAngle ),
145 m_width( aWidth )
146 {
147 }
148
149 void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
150 {
151 aImporter.AddArc( m_center, m_start, m_angle, m_width );
152 }
153
154 virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
155 {
156 return std::make_unique<IMPORTED_ARC>( *this );
157 }
158
159 void Translate( const VECTOR2D& aVec ) override
160 {
161 m_center += aVec;
162 m_start += aVec;
163 }
164
165 void Scale( double scaleX, double scaleY ) override
166 {
167 m_center.x *= scaleX;
168 m_center.y *= scaleY;
169
170 m_start.x *= scaleX;
171 m_start.y *= scaleY;
172 }
173
174private:
178 double m_width;
179};
180
181
183{
184public:
185 IMPORTED_POLYGON( const std::vector< VECTOR2D >& aVertices, double aWidth ) :
186 m_vertices( aVertices ),
187 m_width( aWidth )
188 {
189 }
190
191 void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
192 {
193 aImporter.AddPolygon( m_vertices, m_width );
194 }
195
196 virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
197 {
198 return std::make_unique<IMPORTED_POLYGON>( *this );
199 }
200
201 void Translate( const VECTOR2D& aVec ) override
202 {
203 for( auto& vertex : m_vertices )
204 {
205 vertex += aVec;
206 }
207 }
208
209 void Scale( double scaleX, double scaleY ) override
210 {
211 for( auto& vertex : m_vertices )
212 {
213 vertex.x *= scaleX;
214 vertex.y *= scaleY;
215 }
216 }
217
218 std::vector<VECTOR2D>& Vertices() { return m_vertices; }
219
220 int GetWidth() const { return m_width; }
221
222private:
223 std::vector<VECTOR2D> m_vertices;
224 double m_width;
225};
226
227
229{
230public:
231 IMPORTED_TEXT( const VECTOR2D& aOrigin, const wxString& aText, double aHeight, double aWidth,
232 double aThickness, double aOrientation, GR_TEXT_H_ALIGN_T aHJustify,
233 GR_TEXT_V_ALIGN_T aVJustify ) :
234 m_origin( aOrigin ),
235 m_text( aText ),
236 m_height( aHeight ),
237 m_width( aWidth ),
238 m_thickness( aThickness ),
239 m_orientation( aOrientation ),
240 m_hJustify( aHJustify ),
241 m_vJustify( aVJustify )
242 {
243 }
244
245 void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
246 {
247 aImporter.AddText( m_origin, m_text, m_height, m_width,
249 }
250
251 virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
252 {
253 return std::make_unique<IMPORTED_TEXT>( *this );
254 }
255
256 void Translate( const VECTOR2D& aVec ) override
257 {
258 m_origin += aVec;
259 }
260
261 void Scale( double scaleX, double scaleY ) override
262 {
263 m_origin.x *= scaleX;
264 m_origin.y *= scaleY;
265 }
266
267private:
269 const wxString m_text;
270 double m_height;
271 double m_width;
276};
277
278
280{
281public:
282 IMPORTED_SPLINE( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
283 const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd, double aWidth ) :
284 m_start( aStart ),
285 m_bezierControl1( aBezierControl1 ),
286 m_bezierControl2( aBezierControl2 ),
287 m_end( aEnd ),
288 m_width( aWidth )
289 {
290 }
291
292 void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
293 {
295 }
296
297 virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
298 {
299 return std::make_unique<IMPORTED_SPLINE>( *this );
300 }
301
302 void Translate( const VECTOR2D& aVec ) override
303 {
304 m_start += aVec;
305 m_bezierControl1 += aVec;
306 m_bezierControl2 += aVec;
307 m_end += aVec;
308 }
309
310 void Scale( double scaleX, double scaleY ) override
311 {
312 m_start.x *= scaleX;
313 m_start.y *= scaleY;
314 m_bezierControl1.x *= scaleX;
315 m_bezierControl1.y *= scaleY;
316 m_bezierControl2.x *= scaleX;
317 m_bezierControl2.y *= scaleY;
318 m_end.x *= scaleX;
319 m_end.y *= scaleY;
320 }
321
322private:
327 double m_width;
328};
329
330
332{
333public:
334 void AddLine( const VECTOR2D& aStart, const VECTOR2D& aEnd, double aWidth ) override;
335
336 void AddCircle( const VECTOR2D& aCenter, double aRadius, double aWidth, bool aFilled ) override;
337
338 void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, const EDA_ANGLE& aAngle,
339 double aWidth ) override;
340
341 void AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth ) override;
342
343 void AddText( const VECTOR2D& aOrigin, const wxString& aText, double aHeight, double aWidth,
344 double aThickness, double aOrientation, GR_TEXT_H_ALIGN_T aHJustify,
345 GR_TEXT_V_ALIGN_T aVJustify ) override;
346
347 void AddSpline( const VECTOR2D& aStart, const VECTOR2D& BezierControl1,
348 const VECTOR2D& BezierControl2, const VECTOR2D& aEnd , double aWidth ) override;
349
350 void ImportTo( GRAPHICS_IMPORTER& aImporter );
351 void AddShape( std::unique_ptr<IMPORTED_SHAPE>& aShape );
352
353 std::list<std::unique_ptr<IMPORTED_SHAPE>>& GetShapes()
354 {
355 return m_shapes;
356 }
357
359 {
360 m_shapes.clear();
361 }
362
364
365protected:
367 std::list< std::unique_ptr< IMPORTED_SHAPE > > m_shapes;
368};
369
370#endif /* GRAPHICS_IMPORTER_BUFFER */
std::list< std::unique_ptr< IMPORTED_SHAPE > > & GetShapes()
void AddCircle(const VECTOR2D &aCenter, double aRadius, double aWidth, bool aFilled) override
Create an object representing a circle.
void AddSpline(const VECTOR2D &aStart, const VECTOR2D &BezierControl1, const VECTOR2D &BezierControl2, const VECTOR2D &aEnd, double aWidth) override
Create an object representing an arc.
void ImportTo(GRAPHICS_IMPORTER &aImporter)
void AddArc(const VECTOR2D &aCenter, const VECTOR2D &aStart, const EDA_ANGLE &aAngle, double aWidth) override
Create an object representing an arc.
void AddPolygon(const std::vector< VECTOR2D > &aVertices, double aWidth) override
std::list< std::unique_ptr< IMPORTED_SHAPE > > m_shapes
< List of imported shapes
void AddText(const VECTOR2D &aOrigin, const wxString &aText, double aHeight, double aWidth, double aThickness, double aOrientation, GR_TEXT_H_ALIGN_T aHJustify, GR_TEXT_V_ALIGN_T aVJustify) override
Create an object representing a text.
void AddShape(std::unique_ptr< IMPORTED_SHAPE > &aShape)
void AddLine(const VECTOR2D &aStart, const VECTOR2D &aEnd, double aWidth) override
Create an object representing a line segment.
Interface that creates objects representing shapes for a given data model.
virtual void AddSpline(const VECTOR2D &aStart, const VECTOR2D &aBezierControl1, const VECTOR2D &aBezierControl2, const VECTOR2D &aEnd, double aWidth)=0
Create an object representing an arc.
virtual void AddLine(const VECTOR2D &aOrigin, const VECTOR2D &aEnd, double aWidth)=0
Create an object representing a line segment.
virtual void AddArc(const VECTOR2D &aCenter, const VECTOR2D &aStart, const EDA_ANGLE &aAngle, double aWidth)=0
Create an object representing an arc.
virtual void AddText(const VECTOR2D &aOrigin, const wxString &aText, double aHeight, double aWidth, double aThickness, double aOrientation, GR_TEXT_H_ALIGN_T aHJustify, GR_TEXT_V_ALIGN_T aVJustify)=0
Create an object representing a text.
virtual void AddPolygon(const std::vector< VECTOR2D > &aVertices, double aWidth)=0
virtual void AddCircle(const VECTOR2D &aCenter, double aRadius, double aWidth, bool aFilled)=0
Create an object representing a circle.
IMPORTED_ARC(const VECTOR2D &aCenter, const VECTOR2D &aStart, const EDA_ANGLE &aAngle, double aWidth)
void Translate(const VECTOR2D &aVec) override
virtual std::unique_ptr< IMPORTED_SHAPE > clone() const override
void Scale(double scaleX, double scaleY) override
void ImportTo(GRAPHICS_IMPORTER &aImporter) const override
void Scale(double scaleX, double scaleY) override
IMPORTED_CIRCLE(const VECTOR2D &aCenter, double aRadius, double aWidth, bool aFilled)
void ImportTo(GRAPHICS_IMPORTER &aImporter) const override
virtual std::unique_ptr< IMPORTED_SHAPE > clone() const override
void Translate(const VECTOR2D &aVec) override
virtual std::unique_ptr< IMPORTED_SHAPE > clone() const override
void Scale(double scaleX, double scaleY) override
void Translate(const VECTOR2D &aVec) override
IMPORTED_LINE(const VECTOR2D &aStart, const VECTOR2D &aEnd, double aWidth)
void ImportTo(GRAPHICS_IMPORTER &aImporter) const override
void Translate(const VECTOR2D &aVec) override
std::vector< VECTOR2D > & Vertices()
IMPORTED_POLYGON(const std::vector< VECTOR2D > &aVertices, double aWidth)
void ImportTo(GRAPHICS_IMPORTER &aImporter) const override
void Scale(double scaleX, double scaleY) override
std::vector< VECTOR2D > m_vertices
virtual std::unique_ptr< IMPORTED_SHAPE > clone() const override
int GetParentShapeIndex() const
virtual void ImportTo(GRAPHICS_IMPORTER &aImporter) const =0
void SetParentShapeIndex(int aIndex)
virtual void Translate(const VECTOR2D &aVec)=0
virtual void Scale(double scaleX, double scaleY)=0
virtual std::unique_ptr< IMPORTED_SHAPE > clone() const =0
void ImportTo(GRAPHICS_IMPORTER &aImporter) const override
virtual std::unique_ptr< IMPORTED_SHAPE > clone() const override
IMPORTED_SPLINE(const VECTOR2D &aStart, const VECTOR2D &aBezierControl1, const VECTOR2D &aBezierControl2, const VECTOR2D &aEnd, double aWidth)
void Translate(const VECTOR2D &aVec) override
void Scale(double scaleX, double scaleY) override
void Scale(double scaleX, double scaleY) override
IMPORTED_TEXT(const VECTOR2D &aOrigin, const wxString &aText, double aHeight, double aWidth, double aThickness, double aOrientation, GR_TEXT_H_ALIGN_T aHJustify, GR_TEXT_V_ALIGN_T aVJustify)
GR_TEXT_H_ALIGN_T m_hJustify
GR_TEXT_V_ALIGN_T m_vJustify
virtual std::unique_ptr< IMPORTED_SHAPE > clone() const override
void ImportTo(GRAPHICS_IMPORTER &aImporter) const override
void Translate(const VECTOR2D &aVec) override
GR_TEXT_H_ALIGN_T
GR_TEXT_V_ALIGN_T