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 <[email protected]>
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 
25 #include <eda_item.h>
27 
28 using namespace std;
29 
30 template <typename T, typename... Args>
31 static std::unique_ptr<T> make_shape( const Args&... aArguments )
32 {
33  return std::make_unique<T>( aArguments... );
34 }
35 
36 void GRAPHICS_IMPORTER_BUFFER::AddLine( const VECTOR2D& aStart, const VECTOR2D& aEnd, double aWidth )
37 {
38  m_shapes.push_back( make_shape< IMPORTED_LINE >( aStart, aEnd, aWidth ) );
39 }
40 
41 
42 void GRAPHICS_IMPORTER_BUFFER::AddCircle( const VECTOR2D& aCenter, double aRadius, double aWidth, bool aFilled )
43 {
44  m_shapes.push_back( make_shape<IMPORTED_CIRCLE>( aCenter, aRadius, aWidth, aFilled ) );
45 }
46 
47 
48 void GRAPHICS_IMPORTER_BUFFER::AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart,
49  double aAngle, double aWidth )
50 {
51  m_shapes.push_back( make_shape< IMPORTED_ARC >( aCenter, aStart, aAngle, aWidth ) );
52 }
53 
54 
55 void GRAPHICS_IMPORTER_BUFFER::AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth )
56 {
57  m_shapes.push_back( make_shape< IMPORTED_POLYGON >( aVertices, aWidth ) );
58 }
59 
60 
61 void GRAPHICS_IMPORTER_BUFFER::AddText( const VECTOR2D& aOrigin, const wxString& aText,
62  double aHeight, double aWidth, double aThickness, double aOrientation,
63  EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify )
64 {
65  m_shapes.push_back( make_shape< IMPORTED_TEXT >( aOrigin, aText, aHeight, aWidth,
66  aThickness, aOrientation, aHJustify, aVJustify ) );
67 }
68 
69 
70 void GRAPHICS_IMPORTER_BUFFER::AddSpline( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
71  const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd , double aWidth )
72 {
73  m_shapes.push_back( make_shape< IMPORTED_SPLINE >( aStart, aBezierControl1, aBezierControl2, aEnd, aWidth ) );
74 }
75 
76 
77 void GRAPHICS_IMPORTER_BUFFER::AddShape( std::unique_ptr<IMPORTED_SHAPE>& aShape )
78 {
79  m_shapes.push_back( std::move( aShape ) );
80 }
81 
82 
84 {
85  for( auto& shape : m_shapes )
86  shape->ImportTo( aImporter );
87 }
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:82
void AddLine(const VECTOR2D &aStart, const VECTOR2D &aEnd, double aWidth) override
Create an object representing a line segment.
void AddArc(const VECTOR2D &aCenter, const VECTOR2D &aStart, double aAngle, double aWidth) override
Create an object representing an arc.
Definition: bitmap.cpp:64
void AddShape(std::unique_ptr< IMPORTED_SHAPE > &aShape)
void AddSpline(const VECTOR2D &aStart, const VECTOR2D &BezierControl1, const VECTOR2D &BezierControl2, const VECTOR2D &aEnd, double aWidth) override
Create an object representing an arc.
void AddPolygon(const std::vector< VECTOR2D > &aVertices, double aWidth) override
void AddCircle(const VECTOR2D &aCenter, double aRadius, double aWidth, bool aFilled) override
Create 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
Create an object representing a text.
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:89
void ImportTo(GRAPHICS_IMPORTER &aImporter)