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 <math/matrix3x3.h>
33#include <list>
34
36{
37public:
38 virtual ~IMPORTED_SHAPE() {}
39 virtual void ImportTo( GRAPHICS_IMPORTER& aImporter ) const = 0;
40
41 virtual std::unique_ptr<IMPORTED_SHAPE> clone() const = 0;
42
43 virtual void Transform( const MATRIX3x3D& aTransform, const VECTOR2D& aTranslation ) = 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 Transform(const MATRIX3x3D& aTransform, const VECTOR2D& aTranslation) override
74 {
75 m_start = aTransform * m_start + aTranslation;
76 m_end = aTransform * m_end + aTranslation;
77 }
78
79private:
82 double m_width;
83};
84
85
87{
88public:
89 IMPORTED_CIRCLE( const VECTOR2D& aCenter, double aRadius, double aWidth, bool aFilled ) :
90 m_center( aCenter ),
91 m_radius( aRadius ),
92 m_width( aWidth ),
93 m_filled( aFilled )
94 {
95 }
96
97 void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
98 {
100 }
101
102 virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
103 {
104 return std::make_unique<IMPORTED_CIRCLE>( *this );
105 }
106
107 void Transform( const MATRIX3x3D& aTransform, const VECTOR2D& aTranslation ) override
108 {
109 VECTOR2D newCenter = ( aTransform * m_center ) + aTranslation;
110
111 VECTOR2D newRadius = VECTOR2D( m_radius, 0 );
112 newRadius = aTransform * newRadius;
113
114 m_center = newCenter;
115 m_radius = newRadius.EuclideanNorm();
116 }
117
118private:
120 double m_radius;
121 double m_width;
123};
124
125
127{
128public:
129 IMPORTED_ARC( const VECTOR2D& aCenter, const VECTOR2D& aStart, const EDA_ANGLE& aAngle,
130 double aWidth ) :
131 m_center( aCenter ),
132 m_start( aStart ),
133 m_angle( aAngle ),
134 m_width( aWidth )
135 {
136 }
137
138 void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
139 {
140 aImporter.AddArc( m_center, m_start, m_angle, m_width );
141 }
142
143 virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
144 {
145 return std::make_unique<IMPORTED_ARC>( *this );
146 }
147
148 void Transform( const MATRIX3x3D& aTransform, const VECTOR2D& aTranslation ) override
149 {
150 m_start = aTransform * m_start + aTranslation;
151 m_center = aTransform * m_center + aTranslation;
152 }
153
154private:
158 double m_width;
159};
160
161
163{
164public:
165 IMPORTED_POLYGON( const std::vector< VECTOR2D >& aVertices, double aWidth ) :
166 m_vertices( aVertices ),
167 m_width( aWidth )
168 {
169 }
170
171 void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
172 {
173 aImporter.AddPolygon( m_vertices, m_width );
174 }
175
176 virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
177 {
178 return std::make_unique<IMPORTED_POLYGON>( *this );
179 }
180
181 void Transform( const MATRIX3x3D& aTransform, const VECTOR2D& aTranslation ) override
182 {
183 for(VECTOR2D& vert : m_vertices )
184 {
185 vert = aTransform * vert + aTranslation;
186 }
187 }
188
189 std::vector<VECTOR2D>& Vertices() { return m_vertices; }
190
191 double GetWidth() const { return m_width; }
192
193private:
194 std::vector<VECTOR2D> m_vertices;
195 double m_width;
196};
197
198
200{
201public:
202 IMPORTED_TEXT( const VECTOR2D& aOrigin, const wxString& aText, double aHeight, double aWidth,
203 double aThickness, double aOrientation, GR_TEXT_H_ALIGN_T aHJustify,
204 GR_TEXT_V_ALIGN_T aVJustify ) :
205 m_origin( aOrigin ),
206 m_text( aText ),
207 m_height( aHeight ),
208 m_width( aWidth ),
209 m_thickness( aThickness ),
210 m_orientation( aOrientation ),
211 m_hJustify( aHJustify ),
212 m_vJustify( aVJustify )
213 {
214 }
215
216 void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
217 {
218 aImporter.AddText( m_origin, m_text, m_height, m_width,
220 }
221
222 virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
223 {
224 return std::make_unique<IMPORTED_TEXT>( *this );
225 }
226
227 void Transform( const MATRIX3x3D& aTransform, const VECTOR2D& aTranslation ) override
228 {
229 m_origin = aTransform * m_origin + aTranslation;
230 }
231
232private:
234 const wxString m_text;
235 double m_height;
236 double m_width;
241};
242
243
245{
246public:
247 IMPORTED_SPLINE( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
248 const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd, double aWidth ) :
249 m_start( aStart ),
250 m_bezierControl1( aBezierControl1 ),
251 m_bezierControl2( aBezierControl2 ),
252 m_end( aEnd ),
253 m_width( aWidth )
254 {
255 }
256
257 void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
258 {
260 }
261
262 virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
263 {
264 return std::make_unique<IMPORTED_SPLINE>( *this );
265 }
266
267 void Transform( const MATRIX3x3D& aTransform, const VECTOR2D& aTranslation ) override
268 {
269 m_start = aTransform * m_start + aTranslation;
270 m_bezierControl1 = aTransform * m_bezierControl1 + aTranslation;
271 m_bezierControl2 = aTransform * m_bezierControl2 + aTranslation;
272 m_end = aTransform * m_end + aTranslation;
273 }
274
275private:
280 double m_width;
281};
282
283
285{
286public:
287 void AddLine( const VECTOR2D& aStart, const VECTOR2D& aEnd, double aWidth ) override;
288
289 void AddCircle( const VECTOR2D& aCenter, double aRadius, double aWidth, bool aFilled ) override;
290
291 void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, const EDA_ANGLE& aAngle,
292 double aWidth ) override;
293
294 void AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth ) override;
295
296 void AddText( const VECTOR2D& aOrigin, const wxString& aText, double aHeight, double aWidth,
297 double aThickness, double aOrientation, GR_TEXT_H_ALIGN_T aHJustify,
298 GR_TEXT_V_ALIGN_T aVJustify ) override;
299
300 void AddSpline( const VECTOR2D& aStart, const VECTOR2D& BezierControl1,
301 const VECTOR2D& BezierControl2, const VECTOR2D& aEnd , double aWidth ) override;
302
303 void ImportTo( GRAPHICS_IMPORTER& aImporter );
304 void AddShape( std::unique_ptr<IMPORTED_SHAPE>& aShape );
305
306 std::list<std::unique_ptr<IMPORTED_SHAPE>>& GetShapes()
307 {
308 return m_shapes;
309 }
310
312 {
313 m_shapes.clear();
314 }
315
317
318protected:
320 std::list< std::unique_ptr< IMPORTED_SHAPE > > m_shapes;
321};
322
323#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.
void Transform(const MATRIX3x3D &aTransform, const VECTOR2D &aTranslation) override
IMPORTED_ARC(const VECTOR2D &aCenter, const VECTOR2D &aStart, const EDA_ANGLE &aAngle, double aWidth)
virtual std::unique_ptr< IMPORTED_SHAPE > clone() const override
void ImportTo(GRAPHICS_IMPORTER &aImporter) const override
void Transform(const MATRIX3x3D &aTransform, const VECTOR2D &aTranslation) 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
virtual std::unique_ptr< IMPORTED_SHAPE > clone() const override
void Transform(const MATRIX3x3D &aTransform, const VECTOR2D &aTranslation) override
IMPORTED_LINE(const VECTOR2D &aStart, const VECTOR2D &aEnd, double aWidth)
void ImportTo(GRAPHICS_IMPORTER &aImporter) const override
void Transform(const MATRIX3x3D &aTransform, const VECTOR2D &aTranslation) override
std::vector< VECTOR2D > & Vertices()
IMPORTED_POLYGON(const std::vector< VECTOR2D > &aVertices, double aWidth)
void ImportTo(GRAPHICS_IMPORTER &aImporter) const 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 Transform(const MATRIX3x3D &aTransform, const VECTOR2D &aTranslation)=0
virtual std::unique_ptr< IMPORTED_SHAPE > clone() const =0
void ImportTo(GRAPHICS_IMPORTER &aImporter) const override
void Transform(const MATRIX3x3D &aTransform, const VECTOR2D &aTranslation) 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 Transform(const MATRIX3x3D &aTransform, const VECTOR2D &aTranslation) 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
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:293
GR_TEXT_H_ALIGN_T
GR_TEXT_V_ALIGN_T
VECTOR2< double > VECTOR2D
Definition: vector2d.h:617