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 The 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#include <gal/color4d.h>
36#include <stroke_params.h>
37
38#include <list>
39#include <memory>
40#include <vector>
41
42class EDA_ITEM;
43class EDA_SHAPE;
44
49{
50public:
51 IMPORTED_STROKE( double aWidth = 0, LINE_STYLE aPlotStyle = LINE_STYLE::DEFAULT,
53 m_width( aWidth ),
54 m_plotstyle( aPlotStyle ), m_color( aColor )
55 {
56 }
57
58 double GetWidth() const { return m_width; }
59 void SetWidth( double aWidth ) { m_width = aWidth; }
60
62 void SetPlotStyle( LINE_STYLE aPlotStyle ) { m_plotstyle = aPlotStyle; }
63
64 KIGFX::COLOR4D GetColor() const { return m_color; }
65 void SetColor( const KIGFX::COLOR4D& aColor ) { m_color = aColor; }
66
67private:
68 double m_width;
71};
72
77{
78public:
80 {
83 };
84
86
88 {
89 }
90
94 void SetPlugin( std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> aPlugin )
95 {
96 m_plugin = std::move( aPlugin );
97
98 if( m_plugin )
99 m_plugin->SetImporter( this );
100 }
101
106 bool Load( const wxString& aFileName );
107
108
117 bool Import( const VECTOR2D& aScale = VECTOR2D( 1.0, 1.0 ) );
118
124 const wxString& GetMessages() const
125 {
126 return m_plugin->GetMessages();
127 }
128
129 void ReportMsg( const wxString& aMessage )
130 {
131 m_plugin->ReportMsg( aMessage );
132 }
133
139 double GetImageWidthMM() const
140 {
141 return m_originalWidth;
142 }
143
149 double GetImageHeightMM() const
150 {
151 return m_originalHeight;
152 }
153
157 void SetLineWidthMM( double aWidth )
158 {
159 m_lineWidth = aWidth;
160 }
161
165 double GetLineWidthMM() const
166 {
167 return m_lineWidth;
168 }
169
174 {
175 return m_scale;
176 }
177
182 {
183 return m_offsetCoordmm;
184 }
185
189 void SetImportOffsetMM( const VECTOR2D& aOffset )
190 {
191 m_offsetCoordmm = aOffset;
192 }
193
199 void SetScale( const VECTOR2D& aScale )
200 {
201 m_scale = aScale;
202 }
203
208 {
209 return m_millimeterToIu;
210 }
211
216 {
217 return m_scale * m_millimeterToIu;
218 }
219
223 std::list<std::unique_ptr<EDA_ITEM>>& GetItems()
224 {
225 return m_items;
226 }
227
232 {
233 m_items.clear();
234 }
235
237 static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX = 1;
238
239 virtual void NewShape( POLY_FILL_RULE aFillRule = PF_NONZERO );
240
248 virtual void AddLine( const VECTOR2D& aOrigin, const VECTOR2D& aEnd,
249 const IMPORTED_STROKE& aStroke ) = 0;
250
258 virtual void AddCircle( const VECTOR2D& aCenter, double aRadius, const IMPORTED_STROKE& aStroke,
259 bool aFilled, const COLOR4D& aFillColor ) = 0;
260
270 virtual void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, const EDA_ANGLE& aAngle,
271 const IMPORTED_STROKE& aStroke ) = 0;
272
281 virtual void AddPolygon( const std::vector<VECTOR2D>& aVertices, const IMPORTED_STROKE& aStroke,
282 bool aFilled, const COLOR4D& aFillColor ) = 0;
283
297 virtual void AddText( const VECTOR2D& aOrigin, const wxString& aText, double aHeight,
298 double aWidth, double aThickness, double aOrientation,
299 GR_TEXT_H_ALIGN_T aHJustify, GR_TEXT_V_ALIGN_T aVJustify,
300 const COLOR4D& aColor ) = 0;
301
311 virtual void AddSpline( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
312 const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd,
313 const IMPORTED_STROKE& aStroke ) = 0;
314
315protected:
317 void addItem( std::unique_ptr<EDA_ITEM> aItem );
318
324 bool setupSplineOrLine( EDA_SHAPE& aShape, int aAccuracy );
325
328
331
332 std::vector<POLY_FILL_RULE> m_shapeFillRules;
333
334private:
336 std::list<std::unique_ptr<EDA_ITEM>> m_items;
337
339 std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> m_plugin;
340
343
346
354
357};
358
359#endif /* GRAPHICS_IMPORTER_H */
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
Interface that creates objects representing shapes for a given data model.
double m_originalHeight
Total image Height.
virtual void AddArc(const VECTOR2D &aCenter, const VECTOR2D &aStart, const EDA_ANGLE &aAngle, const IMPORTED_STROKE &aStroke)=0
Create an object representing an arc.
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
Default line thickness (in mm).
virtual void AddPolygon(const std::vector< VECTOR2D > &aVertices, const IMPORTED_STROKE &aStroke, bool aFilled, const COLOR4D &aFillColor)=0
Create an object representing a polygon.
virtual void NewShape(POLY_FILL_RULE aFillRule=PF_NONZERO)
virtual ~GRAPHICS_IMPORTER()
VECTOR2D m_scale
Scale factor applied to the imported graphics.
std::vector< POLY_FILL_RULE > m_shapeFillRules
const wxString & GetMessages() const
Collect warning and error messages after loading/importing.
virtual void AddLine(const VECTOR2D &aOrigin, const VECTOR2D &aEnd, const IMPORTED_STROKE &aStroke)=0
Create an object representing a line segment.
std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > m_plugin
Plugin used to load a file.
void ReportMsg(const wxString &aMessage)
VECTOR2D GetScale() const
double GetMillimeterToIuFactor()
void SetImportOffsetMM(const VECTOR2D &aOffset)
Set the offset in millimeters to add to coordinates when importing graphic items.
void SetScale(const VECTOR2D &aScale)
Set the scale factor affecting the imported shapes.
bool Import(const VECTOR2D &aScale=VECTOR2D(1.0, 1.0))
Import shapes from loaded file.
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, const COLOR4D &aColor)=0
Create an object representing a text.
double GetLineWidthMM() const
Return the line width used for importing the outlines (in mm).
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).
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.
VECTOR2D m_offsetCoordmm
Offset (in mm) for imported coordinates.
double m_millimeterToIu
Factor to convert millimeters to Internal Units.
bool setupSplineOrLine(EDA_SHAPE &aShape, int aAccuracy)
Configure a shape as a spline or a line segment if it's degenerate.
const VECTOR2D & GetImportOffsetMM() const
double m_originalWidth
Total image width.
virtual void AddCircle(const VECTOR2D &aCenter, double aRadius, const IMPORTED_STROKE &aStroke, bool aFilled, const COLOR4D &aFillColor)=0
Create an object representing a circle.
double GetImageHeightMM() const
Get original image Height.
std::list< std::unique_ptr< EDA_ITEM > > m_items
List of imported items.
VECTOR2D ImportScalingFactor() const
virtual void AddSpline(const VECTOR2D &aStart, const VECTOR2D &aBezierControl1, const VECTOR2D &aBezierControl2, const VECTOR2D &aEnd, const IMPORTED_STROKE &aStroke)=0
Create an object representing an arc.
double m_lineWidth
Default line thickness for the imported graphics.
A clone of IMPORTED_STROKE, but with floating-point width.
void SetWidth(double aWidth)
LINE_STYLE GetPlotStyle() const
KIGFX::COLOR4D m_color
LINE_STYLE m_plotstyle
double GetWidth() const
void SetColor(const KIGFX::COLOR4D &aColor)
void SetPlotStyle(LINE_STYLE aPlotStyle)
KIGFX::COLOR4D GetColor() const
IMPORTED_STROKE(double aWidth=0, LINE_STYLE aPlotStyle=LINE_STYLE::DEFAULT, const KIGFX::COLOR4D &aColor=KIGFX::COLOR4D::UNSPECIFIED)
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition: color4d.h:398
LINE_STYLE
Dashed line types.
Definition: stroke_params.h:46
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:694