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, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef GRAPHICS_IMPORTER_H
24#define GRAPHICS_IMPORTER_H
25
26#include "graphics_import_mgr.h"
28
29#include <eda_text.h>
30#include <math/vector2d.h>
31#include <gal/color4d.h>
32#include <stroke_params.h>
33
34#include <list>
35#include <memory>
36#include <vector>
37
38class EDA_ITEM;
39class EDA_SHAPE;
40
45{
46public:
47 IMPORTED_STROKE( double aWidth = 0, LINE_STYLE aPlotStyle = LINE_STYLE::DEFAULT,
49 m_width( aWidth ),
50 m_plotstyle( aPlotStyle ), m_color( aColor )
51 {
52 }
53
54 double GetWidth() const { return m_width; }
55 void SetWidth( double aWidth ) { m_width = aWidth; }
56
58 void SetPlotStyle( LINE_STYLE aPlotStyle ) { m_plotstyle = aPlotStyle; }
59
60 KIGFX::COLOR4D GetColor() const { return m_color; }
61 void SetColor( const KIGFX::COLOR4D& aColor ) { m_color = aColor; }
62
63private:
64 double m_width;
67};
68
73{
74public:
80
82
84 {
85 }
86
90 void SetPlugin( std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> aPlugin )
91 {
92 m_plugin = std::move( aPlugin );
93
94 if( m_plugin )
95 m_plugin->SetImporter( this );
96 }
97
102 bool Load( const wxString& aFileName );
103
104
113 bool Import( const VECTOR2D& aScale = VECTOR2D( 1.0, 1.0 ) );
114
120 const wxString& GetMessages() const
121 {
122 return m_plugin->GetMessages();
123 }
124
125 void ReportMsg( const wxString& aMessage )
126 {
127 m_plugin->ReportMsg( aMessage );
128 }
129
135 double GetImageWidthMM() const
136 {
137 return m_originalWidth;
138 }
139
145 double GetImageHeightMM() const
146 {
147 return m_originalHeight;
148 }
149
153 void SetLineWidthMM( double aWidth )
154 {
155 m_lineWidth = aWidth;
156 }
157
161 double GetLineWidthMM() const
162 {
163 return m_lineWidth;
164 }
165
170 {
171 return m_scale;
172 }
173
178 {
179 return m_offsetCoordmm;
180 }
181
185 void SetImportOffsetMM( const VECTOR2D& aOffset )
186 {
187 m_offsetCoordmm = aOffset;
188 }
189
195 void SetScale( const VECTOR2D& aScale )
196 {
197 m_scale = aScale;
198 }
199
204 {
205 return m_millimeterToIu;
206 }
207
212 {
213 return m_scale * m_millimeterToIu;
214 }
215
219 std::list<std::unique_ptr<EDA_ITEM>>& GetItems()
220 {
221 return m_items;
222 }
223
228 {
229 m_items.clear();
230 }
231
233 static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX = 1;
234
235 virtual void NewShape( POLY_FILL_RULE aFillRule = PF_NONZERO );
236
242 virtual bool CanImportSourceLayer( const wxString& ) const { return true; }
243
247 virtual void SetCurrentSourceLayer( const wxString& ) {}
248
256 virtual void AddLine( const VECTOR2D& aOrigin, const VECTOR2D& aEnd,
257 const IMPORTED_STROKE& aStroke ) = 0;
258
266 virtual void AddCircle( const VECTOR2D& aCenter, double aRadius, const IMPORTED_STROKE& aStroke,
267 bool aFilled, const COLOR4D& aFillColor ) = 0;
268
278 virtual void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, const EDA_ANGLE& aAngle,
279 const IMPORTED_STROKE& aStroke ) = 0;
280
289 virtual void AddPolygon( const std::vector<VECTOR2D>& aVertices, const IMPORTED_STROKE& aStroke,
290 bool aFilled, const COLOR4D& aFillColor ) = 0;
291
305 virtual void AddText( const VECTOR2D& aOrigin, const wxString& aText, double aHeight,
306 double aWidth, double aThickness, double aOrientation,
307 GR_TEXT_H_ALIGN_T aHJustify, GR_TEXT_V_ALIGN_T aVJustify,
308 const COLOR4D& aColor ) = 0;
309
319 virtual void AddSpline( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
320 const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd,
321 const IMPORTED_STROKE& aStroke ) = 0;
322
332 virtual void AddEllipse( const VECTOR2D& aCenter, double aMajorRadius, double aMinorRadius,
333 const EDA_ANGLE& aRotation, const IMPORTED_STROKE& aStroke, bool aFilled,
334 const COLOR4D& aFillColor = COLOR4D::UNSPECIFIED ) = 0;
335
347 virtual void AddEllipseArc( const VECTOR2D& aCenter, double aMajorRadius, double aMinorRadius,
348 const EDA_ANGLE& aRotation, const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aEndAngle,
349 const IMPORTED_STROKE& aStroke ) = 0;
350
351protected:
353 void addItem( std::unique_ptr<EDA_ITEM> aItem );
354
360 bool setupSplineOrLine( EDA_SHAPE& aShape, int aAccuracy );
361
364
367
368 std::vector<POLY_FILL_RULE> m_shapeFillRules;
369
370private:
372 std::list<std::unique_ptr<EDA_ITEM>> m_items;
373
375 std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> m_plugin;
376
379
382
390
393};
394
395#endif /* GRAPHICS_IMPORTER_H */
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:398
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
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 AddEllipse(const VECTOR2D &aCenter, double aMajorRadius, double aMinorRadius, const EDA_ANGLE &aRotation, const IMPORTED_STROKE &aStroke, bool aFilled, const COLOR4D &aFillColor=COLOR4D::UNSPECIFIED)=0
Create an object representing a closed ellipse.
virtual void NewShape(POLY_FILL_RULE aFillRule=PF_NONZERO)
VECTOR2D m_scale
Scale factor applied to the imported graphics.
std::vector< POLY_FILL_RULE > m_shapeFillRules
virtual void SetCurrentSourceLayer(const wxString &)
Set the source layer for the next buffered shape to be imported.
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
virtual void AddEllipseArc(const VECTOR2D &aCenter, double aMajorRadius, double aMinorRadius, const EDA_ANGLE &aRotation, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aEndAngle, const IMPORTED_STROKE &aStroke)=0
Create an object representing an elliptical arc.
void SetImportOffsetMM(const VECTOR2D &aOffset)
Set the offset in millimeters to add to coordinates when importing graphic items.
virtual bool CanImportSourceLayer(const wxString &) const
Return true if shapes from a given source layer should be imported.
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
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:101
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.
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:682