KiCad PCB EDA Suite
Loading...
Searching...
No Matches
graphics_importer.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) 2016 CERN
5 * Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Maciej Suminski <[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_H
28#define GRAPHICS_IMPORTER_H
29
30#include "graphics_import_mgr.h"
32
33#include <eda_text.h>
34#include <math/vector2d.h>
35
36#include <list>
37#include <memory>
38#include <vector>
39
40class EDA_ITEM;
41
46{
47public:
49 {
52 };
53
55
57 {
58 }
59
63 void SetPlugin( std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> aPlugin )
64 {
65 m_plugin = std::move( aPlugin );
66
67 if( m_plugin )
68 m_plugin->SetImporter( this );
69 }
70
75 bool Load( const wxString& aFileName );
76
77
86 bool Import( double aScale = 1.0 );
87
93 const wxString& GetMessages() const
94 {
95 return m_plugin->GetMessages();
96 }
97
103 double GetImageWidthMM() const
104 {
105 return m_originalWidth;
106 }
107
113 double GetImageHeightMM() const
114 {
115 return m_originalHeight;
116 }
117
121 void SetLineWidthMM( double aWidth )
122 {
123 m_lineWidth = aWidth;
124 }
125
129 double GetLineWidthMM() const
130 {
131 return m_lineWidth;
132 }
133
137 double GetScale() const
138 {
139 return m_scale;
140 }
141
146 {
147 return m_offsetCoordmm;
148 }
149
153 void SetImportOffsetMM( const VECTOR2D& aOffset )
154 {
155 m_offsetCoordmm = aOffset;
156 }
157
163 void SetScale( double aScale )
164 {
165 m_scale = aScale;
166 }
167
172 {
173 return m_millimeterToIu;
174 }
175
179 double ImportScalingFactor() const
180 {
181 return m_scale * m_millimeterToIu;
182 }
183
187 std::list<std::unique_ptr<EDA_ITEM>>& GetItems()
188 {
189 return m_items;
190 }
191
196 {
197 m_items.clear();
198 }
199
201 static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX = 1;
202
203 virtual void NewShape( POLY_FILL_RULE aFillRule = PF_NONZERO );
204
212 virtual void AddLine( const VECTOR2D& aOrigin, const VECTOR2D& aEnd, double aWidth ) = 0;
213
221 virtual void AddCircle( const VECTOR2D& aCenter, double aRadius, double aWidth,
222 bool aFilled ) = 0;
223
233 virtual void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, const EDA_ANGLE& aAngle,
234 double aWidth ) = 0;
235
236 virtual void AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth ) = 0;
237
250 virtual void AddText( const VECTOR2D& aOrigin, const wxString& aText, double aHeight,
251 double aWidth, double aThickness, double aOrientation,
252 GR_TEXT_H_ALIGN_T aHJustify, GR_TEXT_V_ALIGN_T aVJustify ) = 0;
253
263 virtual void AddSpline( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
264 const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd,
265 double aWidth ) = 0;
266
267protected:
269 void addItem( std::unique_ptr<EDA_ITEM> aItem )
270 {
271 m_items.emplace_back( std::move( aItem ) );
272 }
273
276
279
280 std::vector<POLY_FILL_RULE> m_shapeFillRules;
281
282private:
284 std::list<std::unique_ptr<EDA_ITEM>> m_items;
285
287 std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> m_plugin;
288
291
294
300 double m_scale;
301
304};
305
306#endif /* GRAPHICS_IMPORTER_H */
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
Interface that creates objects representing shapes for a given data model.
void SetPlugin(std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > aPlugin)
Set the import plugin used to obtain shapes from a file.
void ClearItems()
Empties out the imported shapes list.
double GetImageWidthMM() const
Get original image Width.
static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX
virtual void NewShape(POLY_FILL_RULE aFillRule=PF_NONZERO)
virtual ~GRAPHICS_IMPORTER()
virtual void AddSpline(const VECTOR2D &aStart, const VECTOR2D &aBezierControl1, const VECTOR2D &aBezierControl2, const VECTOR2D &aEnd, double aWidth)=0
Create an object representing an arc.
std::vector< POLY_FILL_RULE > m_shapeFillRules
double m_scale
Scale factor applied to the imported graphics.
virtual void AddLine(const VECTOR2D &aOrigin, const VECTOR2D &aEnd, double aWidth)=0
Create an object representing a line segment.
const wxString & GetMessages() const
Collect warning and error messages after loading/importing.
std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > m_plugin
Total image width.
double GetMillimeterToIuFactor()
void SetImportOffsetMM(const VECTOR2D &aOffset)
Set the offset in millimeters to add to coordinates when importing graphic items.
double ImportScalingFactor() const
double GetLineWidthMM() const
Return the line width used for importing the outlines (in mm).
bool Import(double aScale=1.0)
Import shapes from loaded file.
std::list< std::unique_ptr< EDA_ITEM > > & GetItems()
Return the list of objects representing the imported shapes.
void SetLineWidthMM(double aWidth)
Set the line width for the imported outlines (in mm).
double GetScale() const
virtual void AddArc(const VECTOR2D &aCenter, const VECTOR2D &aStart, const EDA_ANGLE &aAngle, double aWidth)=0
Create an object representing an arc.
void addItem(std::unique_ptr< EDA_ITEM > aItem)
< Add an item to the imported shapes list.
bool Load(const wxString &aFileName)
Load file and get its basic data.
void SetScale(double aScale)
Set the scale factor affecting the imported shapes.
double m_millimeterToIu
Offset (in mm) for imported coordinates.
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.
const VECTOR2D & GetImportOffsetMM() const
double m_originalWidth
Total image Height;.
virtual void AddPolygon(const std::vector< VECTOR2D > &aVertices, double aWidth)=0
double GetImageHeightMM() const
Get original image Height.
std::list< std::unique_ptr< EDA_ITEM > > m_items
< List of imported items
virtual void AddCircle(const VECTOR2D &aCenter, double aRadius, double aWidth, bool aFilled)=0
Create an object representing a circle.
GR_TEXT_H_ALIGN_T
GR_TEXT_V_ALIGN_T