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-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Maciej Suminski <maciej.suminski@cern.ch>
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"
31 #include "graphics_import_plugin.h"
32 
33 #include <eda_text.h>
34 #include <math/vector2d.h>
35 
36 #include <list>
37 #include <memory>
38 #include <vector>
39 
40 class EDA_ITEM;
41 
46 {
47 public:
49 
51  {
52  }
53 
57  void SetPlugin( std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> aPlugin )
58  {
59  m_plugin = std::move( aPlugin );
60 
61  if( m_plugin )
62  m_plugin->SetImporter( this );
63  }
64 
69  bool Load( const wxString& aFileName );
70 
71 
80  bool Import( double aScale = 1.0 );
81 
87  const wxString& GetMessages() const
88  {
89  return m_plugin->GetMessages();
90  }
91 
97  double GetImageWidthMM() const
98  {
99  return m_originalWidth;
100  }
101 
107  double GetImageHeightMM() const
108  {
109  return m_originalHeight;
110  }
111 
115  void SetLineWidthMM( double aWidth )
116  {
117  m_lineWidth = aWidth;
118  }
119 
123  double GetLineWidthMM() const
124  {
125  return m_lineWidth;
126  }
127 
131  double GetScale() const
132  {
133  return m_scale;
134  }
135 
140  {
141  return m_offsetCoordmm;
142  }
143 
147  void SetImportOffsetMM( const VECTOR2D& aOffset )
148  {
149  m_offsetCoordmm = aOffset;
150  }
151 
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 
196  virtual void AddLine( const VECTOR2D& aOrigin, const VECTOR2D& aEnd, double aWidth ) = 0;
197 
205  virtual void AddCircle( const VECTOR2D& aCenter, double aRadius, double aWidth,
206  bool aFilled ) = 0;
207 
217  virtual void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle,
218  double aWidth ) = 0;
219 
220  virtual void AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth ) = 0;
221 
234  virtual void AddText( const VECTOR2D& aOrigin, const wxString& aText,
235  double aHeight, double aWidth, double aThickness, double aOrientation,
236  EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify ) = 0;
237 
247  virtual void AddSpline( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
248  const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd,
249  double aWidth ) = 0;
250 
251 protected:
253  void addItem( std::unique_ptr<EDA_ITEM> aItem )
254  {
255  m_items.emplace_back( std::move( aItem ) );
256  }
257 
260 
263 
264 private:
266  std::list<std::unique_ptr<EDA_ITEM>> m_items;
267 
269  std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> m_plugin;
270 
273 
276 
282  double m_scale;
283 
285  double m_lineWidth;
286 };
287 
288 #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:61
double ImportScalingFactor() const
virtual void AddPolygon(const std::vector< VECTOR2D > &aVertices, double aWidth)=0
double GetScale() const
double GetImageHeightMM() const
Get original image Height.
virtual void AddSpline(const VECTOR2D &aStart, const VECTOR2D &aBezierControl1, const VECTOR2D &aBezierControl2, const VECTOR2D &aEnd, double aWidth)=0
Create an object representing an arc.
const wxString & GetMessages() const
Collect warning and error messages after loading/importing.
static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX
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 in millimeters 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, bool aFilled)=0
Create an object representing a circle.
void SetScale(double aScale)
Set the scale factor affecting the imported shapes.
double m_millimeterToIu
Offset (in mm) for imported coordinates.
double GetMillimeterToIuFactor()
double m_originalWidth
Total image Height;.
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.
std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > m_plugin
Total image width.
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:68
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.
double GetLineWidthMM() const
Return the line width used for importing the outlines (in mm).
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
const VECTOR2D & GetImportOffsetMM() const
virtual void AddLine(const VECTOR2D &aOrigin, const VECTOR2D &aEnd, double aWidth)=0
Create an object representing a line segment.
std::list< std::unique_ptr< EDA_ITEM > > m_items
< List of imported items