KiCad PCB EDA Suite
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  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef GRAPHICS_IMPORTER_H
26 #define GRAPHICS_IMPORTER_H
27 
28 #include "graphics_import_mgr.h"
29 #include "graphics_import_plugin.h"
30 
31 #include <eda_text.h>
32 #include <math/vector2d.h>
33 
34 #include <list>
35 #include <memory>
36 #include <vector>
37 
38 class EDA_ITEM;
39 
44 {
45 public:
47 
49  {
50  }
51 
55  void SetPlugin( std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> aPlugin )
56  {
57  m_plugin = std::move( aPlugin );
58  }
59 
64  bool Load( const wxString &aFileName );
65 
66 
75  bool Import( double aScale = 1.0 );
76 
81  const std::string& GetMessages() const
82  {
83  return m_plugin->GetMessages();
84  }
85 
86 
92  double GetImageWidthMM() const
93  {
94  return m_originalWidth;
95  }
96 
102  double GetImageHeightMM() const
103  {
104  return m_originalHeight;
105  }
106 
107 
111  void SetLineWidthMM( double aWidth )
112  {
113  m_lineWidth = aWidth;
114  }
115 
119  double GetLineWidthMM() const
120  {
121  return m_lineWidth;
122  }
123 
126  double GetScale() const
127  {
128  return m_scale;
129  }
130 
135  {
136  return m_offsetCoordmm;
137  }
138 
142  void SetImportOffsetMM( const VECTOR2D& aOffset )
143  {
144  m_offsetCoordmm = aOffset;
145  }
146 
150  void SetScale( double aScale )
151  {
152  m_scale = aScale;
153  }
154 
158  {
159  return m_millimeterToIu;
160  }
161 
162 
166  double ImportScalingFactor() const
167  {
168  return m_scale * m_millimeterToIu;
169  }
170 
174  std::list<std::unique_ptr<EDA_ITEM>>& GetItems()
175  {
176  return m_items;
177  }
178 
180  static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX = 1;
181 
182  // Methods to be implemented by derived graphics importers
183 
190  virtual void AddLine( const VECTOR2D& aOrigin, const VECTOR2D& aEnd, double aWidth ) = 0;
191 
198  virtual void AddCircle( const VECTOR2D& aCenter, double aRadius, double aWidth ) = 0;
199 
208  virtual void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle, double aWidth ) = 0;
209 
210  virtual void AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth ) = 0;
211 
223  virtual void AddText( const VECTOR2D& aOrigin, const wxString& aText,
224  double aHeight, double aWidth, double aThickness, double aOrientation,
225  EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify ) = 0;
226 
235  virtual void AddSpline( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
236  const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd, double aWidth ) = 0;
237 
238 protected:
240  void addItem( std::unique_ptr<EDA_ITEM> aItem )
241  {
242  m_items.emplace_back( std::move( aItem ) );
243  }
244 
245 private:
247  std::list<std::unique_ptr<EDA_ITEM>> m_items;
248 
250  std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> m_plugin;
251 
254 
257 
259  double m_lineWidth;
260 
265  double m_scale;
266 
267 protected:
270 
273 };
274 
275 #endif /* GRAPHICS_IMPORTER_H */
Interface that creates objects representing shapes for a given data model.
virtual ~GRAPHICS_IMPORTER()
std::list< std::unique_ptr< EDA_ITEM > > & GetItems()
@breif Returns the list of objects representing the imported shapes.
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:62
double ImportScalingFactor() const
virtual void AddPolygon(const std::vector< VECTOR2D > &aVertices, double aWidth)=0
double GetScale() const
double GetImageHeightMM() const
Get original image Height.
const std::string & GetMessages() const
collect warning and error messages after loading/importing.
virtual void AddSpline(const VECTOR2D &aStart, const VECTOR2D &aBezierControl1, const VECTOR2D &aBezierControl2, const VECTOR2D &aEnd, double aWidth)=0
Creates an object representing an arc.
static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX
Default line thickness (in mm)
void SetPlugin(std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > aPlugin)
Sets the import plugin used to obtain shapes from a file.
void SetImportOffsetMM(const VECTOR2D &aOffset)
Set the offset to add to coordinates when importing graphic items.
bool Load(const wxString &aFileName)
Load file and get its basic data.
Definition of base KiCad text object.
virtual void AddCircle(const VECTOR2D &aCenter, double aRadius, double aWidth)=0
Creates an object representing a circle.
void SetScale(double aScale)
Set the scale factor affecting the imported shapes.
double m_millimeterToIu
factor to convert millimeters to Internal Units
double m_lineWidth
Default line thickness for the imported graphics
double GetMillimeterToIuFactor()
double m_originalWidth
Total image width
double GetImageWidthMM() const
Get original image Wigth.
bool Import(double aScale=1.0)
Imports shapes from loaded file.
virtual void AddArc(const VECTOR2D &aCenter, const VECTOR2D &aStart, double aAngle, double aWidth)=0
Creates an object representing an arc.
VECTOR2D m_offsetCoordmm
Offset (in mm) for imported coordinates
std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > m_plugin
Plugin used to load a file
virtual void AddText(const VECTOR2D &aOrigin, const wxString &aText, double aHeight, double aWidth, double aThickness, double aOrientation, EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify)=0
Creates an object representing a text.
double m_scale
Scale factor applied to the imported graphics.
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:69
void SetLineWidthMM(double aWidth)
Sets the line width for the imported outlines (in mm).
void addItem(std::unique_ptr< EDA_ITEM > aItem)
Adds an item to the imported shapes list.
double GetLineWidthMM() const
Returns the line width used for importing the outlines (in mm).
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
const VECTOR2D & GetImportOffsetMM() const
virtual void AddLine(const VECTOR2D &aOrigin, const VECTOR2D &aEnd, double aWidth)=0
Creates an object representing a line segment.
double m_originalHeight
Total image Height;
std::list< std::unique_ptr< EDA_ITEM > > m_items
List of imported items