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-2023 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;
43
48{
49public:
50 IMPORTED_STROKE( double aWidth = 0, LINE_STYLE aPlotStyle = LINE_STYLE::DEFAULT,
52 m_width( aWidth ),
53 m_plotstyle( aPlotStyle ), m_color( aColor )
54 {
55 }
56
57 double GetWidth() const { return m_width; }
58 void SetWidth( double aWidth ) { m_width = aWidth; }
59
61 void SetPlotStyle( LINE_STYLE aPlotStyle ) { m_plotstyle = aPlotStyle; }
62
63 KIGFX::COLOR4D GetColor() const { return m_color; }
64 void SetColor( const KIGFX::COLOR4D& aColor ) { m_color = aColor; }
65
66private:
67 double m_width;
70};
71
76{
77public:
79 {
82 };
83
85
87 {
88 }
89
93 void SetPlugin( std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> aPlugin )
94 {
95 m_plugin = std::move( aPlugin );
96
97 if( m_plugin )
98 m_plugin->SetImporter( this );
99 }
100
105 bool Load( const wxString& aFileName );
106
107
116 bool Import( const VECTOR2D& aScale = VECTOR2D( 1.0, 1.0 ) );
117
123 const wxString& GetMessages() const
124 {
125 return m_plugin->GetMessages();
126 }
127
128 void ReportMsg( const wxString& aMessage )
129 {
130 m_plugin->ReportMsg( aMessage );
131 }
132
138 double GetImageWidthMM() const
139 {
140 return m_originalWidth;
141 }
142
148 double GetImageHeightMM() const
149 {
150 return m_originalHeight;
151 }
152
156 void SetLineWidthMM( double aWidth )
157 {
158 m_lineWidth = aWidth;
159 }
160
164 double GetLineWidthMM() const
165 {
166 return m_lineWidth;
167 }
168
173 {
174 return m_scale;
175 }
176
181 {
182 return m_offsetCoordmm;
183 }
184
188 void SetImportOffsetMM( const VECTOR2D& aOffset )
189 {
190 m_offsetCoordmm = aOffset;
191 }
192
198 void SetScale( const VECTOR2D& aScale )
199 {
200 m_scale = aScale;
201 }
202
207 {
208 return m_millimeterToIu;
209 }
210
215 {
216 return m_scale * m_millimeterToIu;
217 }
218
222 std::list<std::unique_ptr<EDA_ITEM>>& GetItems()
223 {
224 return m_items;
225 }
226
231 {
232 m_items.clear();
233 }
234
236 static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX = 1;
237
238 virtual void NewShape( POLY_FILL_RULE aFillRule = PF_NONZERO );
239
247 virtual void AddLine( const VECTOR2D& aOrigin, const VECTOR2D& aEnd,
248 const IMPORTED_STROKE& aStroke ) = 0;
249
257 virtual void AddCircle( const VECTOR2D& aCenter, double aRadius, const IMPORTED_STROKE& aStroke,
258 bool aFilled, const COLOR4D& aFillColor ) = 0;
259
269 virtual void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, const EDA_ANGLE& aAngle,
270 const IMPORTED_STROKE& aStroke ) = 0;
271
280 virtual void AddPolygon( const std::vector<VECTOR2D>& aVertices, const IMPORTED_STROKE& aStroke,
281 bool aFilled, const COLOR4D& aFillColor ) = 0;
282
296 virtual void AddText( const VECTOR2D& aOrigin, const wxString& aText, double aHeight,
297 double aWidth, double aThickness, double aOrientation,
298 GR_TEXT_H_ALIGN_T aHJustify, GR_TEXT_V_ALIGN_T aVJustify,
299 const COLOR4D& aColor ) = 0;
300
310 virtual void AddSpline( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
311 const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd,
312 const IMPORTED_STROKE& aStroke ) = 0;
313
314protected:
316 void addItem( std::unique_ptr<EDA_ITEM> aItem )
317 {
318 m_items.emplace_back( std::move( aItem ) );
319 }
320
323
326
327 std::vector<POLY_FILL_RULE> m_shapeFillRules;
328
329private:
331 std::list<std::unique_ptr<EDA_ITEM>> m_items;
332
334 std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> m_plugin;
335
338
341
348
351};
352
353#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.
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
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
Total image width.
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.
double m_millimeterToIu
Offset (in mm) for imported coordinates.
const VECTOR2D & GetImportOffsetMM() const
double m_originalWidth
Total image Height;.
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.
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
GR_TEXT_V_ALIGN_T
VECTOR2< double > VECTOR2D
Definition: vector2d.h:690