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-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>
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 {
36 public:
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 
46 
48 {
49 public:
50  IMPORTED_LINE( const VECTOR2D& aStart, const VECTOR2D& aEnd, double aWidth ) :
51  m_start( aStart ),
52  m_end( aEnd ),
53  m_width( aWidth )
54  {
55  }
56 
57  void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
58  {
59  aImporter.AddLine( m_start, m_end, m_width );
60  }
61 
62  virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
63  {
64  return std::make_unique<IMPORTED_LINE>( *this );
65  }
66 
67  void Translate( const VECTOR2D& aVec ) override
68  {
69  m_start += aVec;
70  m_end += aVec;
71  }
72 
73  void Scale( double scaleX, double scaleY ) override
74  {
75  m_start.x *= scaleX;
76  m_start.y *= scaleY;
77  m_end.x *= scaleX;
78  m_end.y *= scaleY;
79  }
80 
81 private:
84  double m_width;
85 };
86 
87 
89 {
90 public:
91  IMPORTED_CIRCLE( const VECTOR2D& aCenter, double aRadius, double aWidth, bool aFilled ) :
92  m_center( aCenter ),
93  m_radius( aRadius ),
94  m_width( aWidth ),
95  m_filled( aFilled )
96  {
97  }
98 
99  void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
100  {
101  aImporter.AddCircle( m_center, m_radius, m_width, m_filled );
102  }
103 
104  virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
105  {
106  return std::make_unique<IMPORTED_CIRCLE>( *this );
107  }
108 
109  void Translate( const VECTOR2D& aVec ) override
110  {
111  m_center += aVec;
112  }
113 
114  void Scale( double scaleX, double scaleY ) override
115  {
116  m_center.x *= scaleX;
117  m_center.y *= scaleY;
118 
119  // we really can't handle scalex != scaleY cleanly...it would be an ellipse
120  m_radius *= scaleX;
121  }
122 
123 private:
125  double m_radius;
126  double m_width;
127  bool m_filled;
128 };
129 
130 
132 {
133 public:
134  IMPORTED_ARC( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle, double aWidth ) :
135  m_center( aCenter ),
136  m_start( aStart ),
137  m_angle( aAngle ),
138  m_width( aWidth )
139  {
140  }
141 
142  void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
143  {
144  aImporter.AddArc( m_center, m_start, m_angle, m_width );
145  }
146 
147  virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
148  {
149  return std::make_unique<IMPORTED_ARC>( *this );
150  }
151 
152  void Translate( const VECTOR2D& aVec ) override
153  {
154  m_center += aVec;
155  m_start += aVec;
156  }
157 
158  void Scale( double scaleX, double scaleY ) override
159  {
160  m_center.x *= scaleX;
161  m_center.y *= scaleY;
162 
163  m_start.x *= scaleX;
164  m_start.y *= scaleY;
165  }
166 
167 private:
170  double m_angle;
171  double m_width;
172 };
173 
174 
176 {
177 public:
178  IMPORTED_POLYGON( const std::vector< VECTOR2D >& aVertices, double aWidth ) :
179  m_vertices( aVertices ),
180  m_width( aWidth )
181  {
182  }
183 
184  void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
185  {
186  aImporter.AddPolygon( m_vertices, m_width );
187  }
188 
189  virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
190  {
191  return std::make_unique<IMPORTED_POLYGON>( *this );
192  }
193 
194  void Translate( const VECTOR2D& aVec ) override
195  {
196  for( auto& vertex : m_vertices )
197  {
198  vertex += aVec;
199  }
200  }
201 
202  void Scale( double scaleX, double scaleY ) override
203  {
204  for( auto& vertex : m_vertices )
205  {
206  vertex.x *= scaleX;
207  vertex.y *= scaleY;
208  }
209  }
210 
211 private:
212  std::vector<VECTOR2D> m_vertices;
213  double m_width;
214 };
215 
216 
218 {
219 public:
220  IMPORTED_TEXT( const VECTOR2D& aOrigin, const wxString& aText, double aHeight, double aWidth,
221  double aThickness, double aOrientation, EDA_TEXT_HJUSTIFY_T aHJustify,
222  EDA_TEXT_VJUSTIFY_T aVJustify ) :
223  m_origin( aOrigin ),
224  m_text( aText ),
225  m_height( aHeight ),
226  m_width( aWidth ),
227  m_thickness( aThickness ),
228  m_orientation( aOrientation ),
229  m_hJustify( aHJustify ),
230  m_vJustify( aVJustify )
231  {
232  }
233 
234  void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
235  {
236  aImporter.AddText( m_origin, m_text, m_height, m_width,
238  }
239 
240  virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
241  {
242  return std::make_unique<IMPORTED_TEXT>( *this );
243  }
244 
245  void Translate( const VECTOR2D& aVec ) override
246  {
247  m_origin += aVec;
248  }
249 
250  void Scale( double scaleX, double scaleY ) override
251  {
252  m_origin.x *= scaleX;
253  m_origin.y *= scaleY;
254  }
255 
256 private:
258  const wxString m_text;
259  double m_height;
260  double m_width;
261  double m_thickness;
265 };
266 
267 
269 {
270 public:
271  IMPORTED_SPLINE( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
272  const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd, double aWidth ) :
273  m_start( aStart ),
274  m_bezierControl1( aBezierControl1 ),
275  m_bezierControl2( aBezierControl2 ),
276  m_end( aEnd ),
277  m_width( aWidth )
278  {
279  }
280 
281  void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
282  {
284  }
285 
286  virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
287  {
288  return std::make_unique<IMPORTED_SPLINE>( *this );
289  }
290 
291  void Translate( const VECTOR2D& aVec ) override
292  {
293  m_start += aVec;
294  m_bezierControl1 += aVec;
295  m_bezierControl2 += aVec;
296  m_end += aVec;
297  }
298 
299  void Scale( double scaleX, double scaleY ) override
300  {
301  m_start.x *= scaleX;
302  m_start.y *= scaleY;
303  m_bezierControl1.x *= scaleX;
304  m_bezierControl1.y *= scaleY;
305  m_bezierControl2.x *= scaleX;
306  m_bezierControl2.y *= scaleY;
307  m_end.x *= scaleX;
308  m_end.y *= scaleY;
309  }
310 
311 private:
316  double m_width;
317 };
318 
319 
321 {
322 public:
323  void AddLine( const VECTOR2D& aStart, const VECTOR2D& aEnd, double aWidth ) override;
324 
325  void AddCircle( const VECTOR2D& aCenter, double aRadius, double aWidth, bool aFilled ) override;
326 
327  void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle,
328  double aWidth ) override;
329 
330  void AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth ) override;
331 
332  void AddText( const VECTOR2D& aOrigin, const wxString& aText,
333  double aHeight, double aWidth, double aThickness, double aOrientation,
334  EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify ) override;
335 
336  void AddSpline( const VECTOR2D& aStart, const VECTOR2D& BezierControl1,
337  const VECTOR2D& BezierControl2, const VECTOR2D& aEnd , double aWidth ) override;
338 
339  void ImportTo( GRAPHICS_IMPORTER& aImporter );
340  void AddShape( std::unique_ptr<IMPORTED_SHAPE>& aShape );
341 
342  std::list<std::unique_ptr<IMPORTED_SHAPE>>& GetShapes()
343  {
344  return m_shapes;
345  }
346 
347 protected:
349  std::list< std::unique_ptr< IMPORTED_SHAPE > > m_shapes;
350 };
351 
352 #endif /* GRAPHICS_IMPORTER_BUFFER */
Interface that creates objects representing shapes for a given data model.
void Scale(double scaleX, double scaleY) override
void Scale(double scaleX, double scaleY) override
EDA_TEXT_HJUSTIFY_T m_hJustify
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:61
virtual void ImportTo(GRAPHICS_IMPORTER &aImporter) const =0
IMPORTED_CIRCLE(const VECTOR2D &aCenter, double aRadius, double aWidth, bool aFilled)
virtual void AddPolygon(const std::vector< VECTOR2D > &aVertices, double aWidth)=0
void AddLine(const VECTOR2D &aStart, const VECTOR2D &aEnd, double aWidth) override
Create an object representing a line segment.
EDA_TEXT_VJUSTIFY_T m_vJustify
virtual void Scale(double scaleX, double scaleY)=0
void Translate(const VECTOR2D &aVec) override
IMPORTED_POLYGON(const std::vector< VECTOR2D > &aVertices, double aWidth)
void AddArc(const VECTOR2D &aCenter, const VECTOR2D &aStart, double aAngle, double aWidth) override
Create an object representing an arc.
virtual void AddSpline(const VECTOR2D &aStart, const VECTOR2D &aBezierControl1, const VECTOR2D &aBezierControl2, const VECTOR2D &aEnd, double aWidth)=0
Create an object representing an arc.
IMPORTED_LINE(const VECTOR2D &aStart, const VECTOR2D &aEnd, double aWidth)
virtual void AddCircle(const VECTOR2D &aCenter, double aRadius, double aWidth, bool aFilled)=0
Create an object representing a circle.
void ImportTo(GRAPHICS_IMPORTER &aImporter) const override
void AddShape(std::unique_ptr< IMPORTED_SHAPE > &aShape)
void Translate(const VECTOR2D &aVec) override
void ImportTo(GRAPHICS_IMPORTER &aImporter) const override
void Translate(const VECTOR2D &aVec) override
virtual std::unique_ptr< IMPORTED_SHAPE > clone() const override
void AddSpline(const VECTOR2D &aStart, const VECTOR2D &BezierControl1, const VECTOR2D &BezierControl2, const VECTOR2D &aEnd, double aWidth) override
Create an object representing an arc.
std::list< std::unique_ptr< IMPORTED_SHAPE > > m_shapes
< List of imported shapes
IMPORTED_SPLINE(const VECTOR2D &aStart, const VECTOR2D &aBezierControl1, const VECTOR2D &aBezierControl2, const VECTOR2D &aEnd, double aWidth)
void AddPolygon(const std::vector< VECTOR2D > &aVertices, double aWidth) override
virtual void AddArc(const VECTOR2D &aCenter, const VECTOR2D &aStart, double aAngle, double aWidth)=0
Create an object representing an arc.
void Translate(const VECTOR2D &aVec) override
virtual std::unique_ptr< IMPORTED_SHAPE > clone() const override
void ImportTo(GRAPHICS_IMPORTER &aImporter) const override
virtual void AddText(const VECTOR2D &aOrigin, const wxString &aText, double aHeight, double aWidth, double aThickness, double aOrientation, EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify)=0
Create an object representing a text.
IMPORTED_TEXT(const VECTOR2D &aOrigin, const wxString &aText, double aHeight, double aWidth, double aThickness, double aOrientation, EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify)
void AddCircle(const VECTOR2D &aCenter, double aRadius, double aWidth, bool aFilled) override
Create an object representing a circle.
virtual std::unique_ptr< IMPORTED_SHAPE > clone() const override
void Scale(double scaleX, double scaleY) override
std::vector< VECTOR2D > m_vertices
void AddText(const VECTOR2D &aOrigin, const wxString &aText, double aHeight, double aWidth, double aThickness, double aOrientation, EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify) override
Create an object representing a text.
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:68
IMPORTED_ARC(const VECTOR2D &aCenter, const VECTOR2D &aStart, double aAngle, double aWidth)
virtual std::unique_ptr< IMPORTED_SHAPE > clone() const override
void Scale(double scaleX, double scaleY) override
virtual std::unique_ptr< IMPORTED_SHAPE > clone() const override
virtual void Translate(const VECTOR2D &aVec)=0
void Translate(const VECTOR2D &aVec) override
void ImportTo(GRAPHICS_IMPORTER &aImporter) const override
void Scale(double scaleX, double scaleY) override
std::list< std::unique_ptr< IMPORTED_SHAPE > > & GetShapes()
void Translate(const VECTOR2D &aVec) override
void ImportTo(GRAPHICS_IMPORTER &aImporter) const override
virtual void AddLine(const VECTOR2D &aOrigin, const VECTOR2D &aEnd, double aWidth)=0
Create an object representing a line segment.
void Scale(double scaleX, double scaleY) override
virtual std::unique_ptr< IMPORTED_SHAPE > clone() const override
void ImportTo(GRAPHICS_IMPORTER &aImporter)
virtual std::unique_ptr< IMPORTED_SHAPE > clone() const =0
void ImportTo(GRAPHICS_IMPORTER &aImporter) const override