KiCad PCB EDA Suite
graphics_importer_buffer.cpp
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  * @author Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>
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, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
26 
27 using namespace std;
28 
29 template <typename T, typename... Args>
30 static std::unique_ptr<T> make_shape( const Args&... aArguments )
31 {
32  return std::unique_ptr<T>( new T( aArguments... ) );
33 }
34 
35 void GRAPHICS_IMPORTER_BUFFER::AddLine( const VECTOR2D& aStart, const VECTOR2D& aEnd, double aWidth )
36 {
37  m_shapes.push_back( make_shape< IMPORTED_LINE >( aStart, aEnd, aWidth ) );
38 }
39 
40 
41 void GRAPHICS_IMPORTER_BUFFER::AddCircle( const VECTOR2D& aCenter, double aRadius, double aWidth )
42 {
43  m_shapes.push_back( make_shape< IMPORTED_CIRCLE >( aCenter, aRadius, aWidth ) );
44 }
45 
46 
47 void GRAPHICS_IMPORTER_BUFFER::AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart,
48  double aAngle, double aWidth )
49 {
50  m_shapes.push_back( make_shape< IMPORTED_ARC >( aCenter, aStart, aAngle, aWidth ) );
51 }
52 
53 
54 void GRAPHICS_IMPORTER_BUFFER::AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth )
55 {
56  m_shapes.push_back( make_shape< IMPORTED_POLYGON >( aVertices, aWidth ) );
57 }
58 
59 
60 void GRAPHICS_IMPORTER_BUFFER::AddText( const VECTOR2D& aOrigin, const wxString& aText,
61  double aHeight, double aWidth, double aThickness, double aOrientation,
62  EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify )
63 {
64  m_shapes.push_back( make_shape< IMPORTED_TEXT >( aOrigin, aText, aHeight, aWidth,
65  aThickness, aOrientation, aHJustify, aVJustify ) );
66 }
67 
68 
69 void GRAPHICS_IMPORTER_BUFFER::AddSpline( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
70  const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd , double aWidth )
71 {
72  m_shapes.push_back( make_shape< IMPORTED_SPLINE >( aStart, aBezierControl1, aBezierControl2, aEnd, aWidth ) );
73 }
74 
75 
77 {
78  for( auto& shape : m_shapes )
79  shape->ImportTo( aImporter );
80 }
Interface that creates objects representing shapes for a given data model.
static std::unique_ptr< T > make_shape(const Args &... aArguments)
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:62
void AddLine(const VECTOR2D &aStart, const VECTOR2D &aEnd, double aWidth) override
Creates an object representing a line segment.
void AddArc(const VECTOR2D &aCenter, const VECTOR2D &aStart, double aAngle, double aWidth) override
Creates an object representing an arc.
Template specialization to enable wxStrings for certain containers (e.g. unordered_map)
Definition: bitmap.cpp:55
void AddSpline(const VECTOR2D &aStart, const VECTOR2D &BezierControl1, const VECTOR2D &BezierControl2, const VECTOR2D &aEnd, double aWidth) override
Creates an object representing an arc.
void AddPolygon(const std::vector< VECTOR2D > &aVertices, double aWidth) override
void AddCircle(const VECTOR2D &aCenter, double aRadius, double aWidth) override
Creates an object representing a circle.
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
Creates an object representing a text.
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:69
void ImportTo(GRAPHICS_IMPORTER &aImporter)