KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 * Copyright (C) 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#include <eda_item.h>
28#include "graphics_importer.h"
30#include <wx/log.h>
31
33{
34 m_millimeterToIu = 1.0;
36 m_scale = VECTOR2D( 1.0, 1.0 );
37 m_originalWidth = 0.0;
38 m_originalHeight = 0.0;
39}
40
41
42bool GRAPHICS_IMPORTER::Load( const wxString& aFileName )
43{
44 m_items.clear();
45
46 if( !m_plugin )
47 {
48 wxASSERT_MSG( false, wxT( "Plugin must be set before load." ) );
49 return false;
50 }
51
52 m_plugin->SetImporter( this );
53
54 bool ret = m_plugin->Load( aFileName );
55
56 if( ret )
57 {
58 m_originalWidth = m_plugin->GetImageWidth();
59 m_originalHeight = m_plugin->GetImageHeight();
60 }
61
62 return ret;
63}
64
65
67{
68 if( !m_plugin )
69 {
70 wxASSERT_MSG( false, wxT( "Plugin must be set before import." ) );
71 return false;
72 }
73
74 SetScale( aScale );
75
76 m_plugin->SetImporter( this );
77
78 bool success = false;
79
80 try
81 {
82 success = m_plugin->Import();
83 }
84 catch( const std::bad_alloc& )
85 {
86 // Memory exhaustion
87 // TODO report back an error message
88 return false;
89 }
90
91 return success;
92}
93
94
96{
97 m_shapeFillRules.push_back( aFillRule );
98}
static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX
virtual void NewShape(POLY_FILL_RULE aFillRule=PF_NONZERO)
VECTOR2D m_scale
Scale factor applied to the imported graphics.
std::vector< POLY_FILL_RULE > m_shapeFillRules
std::unique_ptr< GRAPHICS_IMPORT_PLUGIN > m_plugin
Total image width.
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.
bool Load(const wxString &aFileName)
Load file and get its basic data.
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
VECTOR2< double > VECTOR2D
Definition: vector2d.h:587