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
133 double GetImageWidthMM() const
134 {
135 return m_originalWidth;
136 }
137
143 double GetImageHeightMM() const
144 {
145 return m_originalHeight;
146 }
147
151 void SetLineWidthMM( double aWidth )
152 {
153 m_lineWidth = aWidth;
154 }
155
159 double GetLineWidthMM() const
160 {
161 return m_lineWidth;
162 }
163
168 {
169 return m_scale;
170 }
171
176 {
177 return m_offsetCoordmm;
178 }
179
183 void SetImportOffsetMM( const VECTOR2D& aOffset )
184 {
185 m_offsetCoordmm = aOffset;
186 }
187
193 void SetScale( const VECTOR2D& aScale )
194 {
195 m_scale = aScale;
196 }
197
202 {
203 return m_millimeterToIu;
204 }
205
210 {
211 return m_scale * m_millimeterToIu;
212 }
213
217 std::list<std::unique_ptr<EDA_ITEM>>& GetItems()
218 {
219 return m_items;
220 }
221
226 {
227 m_items.clear();
228 }
229
231 static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX = 1;
232
233 virtual void NewShape( POLY_FILL_RULE aFillRule = PF_NONZERO );
234
242 virtual void AddLine( const VECTOR2D& aOrigin, const VECTOR2D& aEnd,
243 const IMPORTED_STROKE& aStroke ) = 0;
244
252 virtual void AddCircle( const VECTOR2D& aCenter, double aRadius, const IMPORTED_STROKE& aStroke,
253 bool aFilled, const COLOR4D& aFillColor ) = 0;
254
264 virtual void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, const EDA_ANGLE& aAngle,
265 const IMPORTED_STROKE& aStroke ) = 0;
266
275 virtual void AddPolygon( const std::vector<VECTOR2D>& aVertices, const IMPORTED_STROKE& aStroke,
276 bool aFilled, const COLOR4D& aFillColor ) = 0;
277
291 virtual void AddText( const VECTOR2D& aOrigin, const wxString& aText, double aHeight,
292 double aWidth, double aThickness, double aOrientation,
293 GR_TEXT_H_ALIGN_T aHJustify, GR_TEXT_V_ALIGN_T aVJustify,
294 const COLOR4D& aColor ) = 0;
295
305 virtual void AddSpline( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
306 const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd,
307 const IMPORTED_STROKE& aStroke ) = 0;
308
309protected:
311 void addItem( std::unique_ptr<EDA_ITEM> aItem )
312 {
313 m_items.emplace_back( std::move( aItem ) );
314 }
315
318
321
322 std::vector<POLY_FILL_RULE> m_shapeFillRules;
323
324private:
326 std::list<std::unique_ptr<EDA_ITEM>> m_items;
327
329 std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> m_plugin;
330
333
336
343
346};
347
348#endif /* GRAPHICS_IMPORTER_H */
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:88
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.
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:48
GR_TEXT_H_ALIGN_T
GR_TEXT_V_ALIGN_T
VECTOR2< double > VECTOR2D
Definition: vector2d.h:601