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  * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #ifndef GRAPHICS_IMPORTER_H
27 #define GRAPHICS_IMPORTER_H
28 
29 #include "graphics_import_mgr.h"
30 #include "graphics_import_plugin.h"
31 
32 #include <eda_text.h>
33 #include <math/vector2d.h>
34 
35 #include <list>
36 #include <memory>
37 #include <vector>
38 
39 class EDA_ITEM;
40 
45 {
46 public:
48 
50  {
51  }
52 
56  void SetPlugin( std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> aPlugin )
57  {
58  m_plugin = std::move( aPlugin );
59 
60  if( m_plugin )
61  m_plugin->SetImporter( this );
62  }
63 
68  bool Load( const wxString &aFileName );
69 
70 
79  bool Import( double aScale = 1.0 );
80 
86  const std::string& GetMessages() const
87  {
88  return m_plugin->GetMessages();
89  }
90 
96  double GetImageWidthMM() const
97  {
98  return m_originalWidth;
99  }
100 
106  double GetImageHeightMM() const
107  {
108  return m_originalHeight;
109  }
110 
114  void SetLineWidthMM( double aWidth )
115  {
116  m_lineWidth = aWidth;
117  }
118 
122  double GetLineWidthMM() const
123  {
124  return m_lineWidth;
125  }
126 
130  double GetScale() const
131  {
132  return m_scale;
133  }
134 
140  {
141  return m_offsetCoordmm;
142  }
143 
148  void SetImportOffsetMM( const VECTOR2D& aOffset )
149  {
150  m_offsetCoordmm = aOffset;
151  }
152 
157  void SetScale( double aScale )
158  {
159  m_scale = aScale;
160  }
161 
166  {
167  return m_millimeterToIu;
168  }
169 
173  double ImportScalingFactor() const
174  {
175  return m_scale * m_millimeterToIu;
176  }
177 
181  std::list<std::unique_ptr<EDA_ITEM>>& GetItems()
182  {
183  return m_items;
184  }
185 
187  static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX = 1;
188 
189  // Methods to be implemented by derived graphics importers
190 
198  virtual void AddLine( const VECTOR2D& aOrigin, const VECTOR2D& aEnd, double aWidth ) = 0;
199 
207  virtual void AddCircle( const VECTOR2D& aCenter, double aRadius, double aWidth ) = 0;
208 
218  virtual void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle,
219  double aWidth ) = 0;
220 
221  virtual void AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth ) = 0;
222 
235  virtual void AddText( const VECTOR2D& aOrigin, const wxString& aText,
236  double aHeight, double aWidth, double aThickness, double aOrientation,
237  EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify ) = 0;
238 
248  virtual void AddSpline( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
249  const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd,
250  double aWidth ) = 0;
251 
252 protected:
254  void addItem( std::unique_ptr<EDA_ITEM> aItem )
255  {
256  m_items.emplace_back( std::move( aItem ) );
257  }
258 
259 private:
261  std::list<std::unique_ptr<EDA_ITEM>> m_items;
262 
264  std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> m_plugin;
265 
268 
271 
277  double m_scale;
278 
280  double m_lineWidth;
281 
282 protected:
285 
288 };
289 
290 #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()
Return the list of objects representing the imported shapes.
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:44
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
Create 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)
Set 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.
virtual void AddCircle(const VECTOR2D &aCenter, double aRadius, double aWidth)=0
Create 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 Width.
bool Import(double aScale=1.0)
Import shapes from loaded file.
virtual void AddArc(const VECTOR2D &aCenter, const VECTOR2D &aStart, double aAngle, double aWidth)=0
Create 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
Create an object representing a text.
double m_scale
Scale factor applied to the imported graphics.
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:51
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:163
const VECTOR2D & GetImportOffsetMM() const
virtual void AddLine(const VECTOR2D &aOrigin, const VECTOR2D &aEnd, double aWidth)=0
Create 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