2018-10-13 18:37:28 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 CERN
|
2023-08-18 18:27:48 +00:00
|
|
|
* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
2018-10-13 18:37:28 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2020-10-14 02:46:39 +00:00
|
|
|
#include <eda_item.h>
|
2018-10-13 18:37:28 +00:00
|
|
|
#include "graphics_importer.h"
|
|
|
|
#include "graphics_import_plugin.h"
|
2023-09-25 15:20:40 +00:00
|
|
|
#include <wx/log.h>
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
GRAPHICS_IMPORTER::GRAPHICS_IMPORTER()
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2018-11-05 16:04:05 +00:00
|
|
|
m_millimeterToIu = 1.0;
|
|
|
|
m_lineWidth = DEFAULT_LINE_WIDTH_DFX;
|
2023-08-18 18:27:48 +00:00
|
|
|
m_scale = VECTOR2D( 1.0, 1.0 );
|
2018-11-05 16:04:05 +00:00
|
|
|
m_originalWidth = 0.0;
|
|
|
|
m_originalHeight = 0.0;
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-18 18:27:48 +00:00
|
|
|
bool GRAPHICS_IMPORTER::Load( const wxString& aFileName )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
|
|
|
m_items.clear();
|
|
|
|
|
|
|
|
if( !m_plugin )
|
|
|
|
{
|
2022-02-05 13:25:43 +00:00
|
|
|
wxASSERT_MSG( false, wxT( "Plugin must be set before load." ) );
|
2018-10-13 18:37:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_plugin->SetImporter( this );
|
|
|
|
|
2023-08-18 18:27:48 +00:00
|
|
|
bool ret = m_plugin->Load( aFileName );
|
|
|
|
|
|
|
|
if( ret )
|
|
|
|
{
|
|
|
|
m_originalWidth = m_plugin->GetImageWidth();
|
|
|
|
m_originalHeight = m_plugin->GetImageHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
2023-08-18 18:27:48 +00:00
|
|
|
|
|
|
|
bool GRAPHICS_IMPORTER::Import( const VECTOR2D& aScale )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
|
|
|
if( !m_plugin )
|
|
|
|
{
|
2022-02-05 13:25:43 +00:00
|
|
|
wxASSERT_MSG( false, wxT( "Plugin must be set before import." ) );
|
2018-10-13 18:37:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
SetScale( aScale );
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
m_plugin->SetImporter( this );
|
|
|
|
|
2021-05-01 18:26:47 +00:00
|
|
|
bool success = false;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
success = m_plugin->Import();
|
|
|
|
}
|
|
|
|
catch( const std::bad_alloc& )
|
|
|
|
{
|
|
|
|
// Memory exhaustion
|
|
|
|
// TODO report back an error message
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
2021-12-30 02:47:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
void GRAPHICS_IMPORTER::NewShape( POLY_FILL_RULE aFillRule )
|
|
|
|
{
|
|
|
|
m_shapeFillRules.push_back( aFillRule );
|
|
|
|
}
|