KiCad PCB EDA Suite
graphics_importer.cpp
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 <[email protected]>
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#include <eda_item.h>
26#include "graphics_importer.h"
28
30{
31 m_millimeterToIu = 1.0;
33 m_scale = 1.0;
34 m_originalWidth = 0.0;
35 m_originalHeight = 0.0;
36}
37
38
39bool GRAPHICS_IMPORTER::Load( const wxString &aFileName )
40{
41 m_items.clear();
42
43 if( !m_plugin )
44 {
45 wxASSERT_MSG( false, wxT( "Plugin must be set before load." ) );
46 return false;
47 }
48
49 m_plugin->SetImporter( this );
50
51 return m_plugin->Load( aFileName );
52}
53
54bool GRAPHICS_IMPORTER::Import( double aScale )
55{
56 if( !m_plugin )
57 {
58 wxASSERT_MSG( false, wxT( "Plugin must be set before import." ) );
59 return false;
60 }
61
62 SetScale( aScale );
63
64 m_plugin->SetImporter( this );
65
66 bool success = false;
67
68 try
69 {
70 success = m_plugin->Import();
71 }
72 catch( const std::bad_alloc& )
73 {
74 // Memory exhaustion
75 // TODO report back an error message
76 return false;
77 }
78
79 return success;
80}
81
82
84{
85 m_shapeFillRules.push_back( aFillRule );
86}
static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX
virtual void NewShape(POLY_FILL_RULE aFillRule=PF_NONZERO)
std::vector< POLY_FILL_RULE > m_shapeFillRules
double m_scale
Scale factor applied to the imported graphics.
std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > m_plugin
Total image width.
bool Import(double aScale=1.0)
Import shapes from loaded file.
bool Load(const wxString &aFileName)
Load file and get its basic data.
void SetScale(double aScale)
Set the scale factor affecting the imported shapes.
double m_millimeterToIu
Offset (in mm) for imported coordinates.
double m_originalWidth
Total image Height;.
std::list< std::unique_ptr< EDA_ITEM > > m_items
< List of imported items