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 17:38:23 +00:00
|
|
|
* Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2021-01-27 22:15:38 +00:00
|
|
|
*
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GRAPHICS_IMPORT_PLUGIN_H
|
|
|
|
#define GRAPHICS_IMPORT_PLUGIN_H
|
|
|
|
|
2023-08-18 18:27:48 +00:00
|
|
|
#include <math/box2.h>
|
2019-09-26 20:09:09 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2018-10-13 18:37:28 +00:00
|
|
|
#include <wx/arrstr.h>
|
|
|
|
|
|
|
|
class GRAPHICS_IMPORTER;
|
|
|
|
|
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Interface for vector graphics import plugins.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
|
|
|
class GRAPHICS_IMPORT_PLUGIN
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~GRAPHICS_IMPORT_PLUGIN()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Set the receiver of the imported shapes.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
2019-04-03 15:29:17 +00:00
|
|
|
virtual void SetImporter( GRAPHICS_IMPORTER* aImporter )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
|
|
|
m_importer = aImporter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Return the plugin name.
|
2018-10-13 18:37:28 +00:00
|
|
|
*
|
|
|
|
* This string will be used as the description in the file dialog.
|
|
|
|
*/
|
|
|
|
virtual const wxString GetName() const = 0;
|
|
|
|
|
|
|
|
/**
|
2019-09-26 20:09:09 +00:00
|
|
|
* Return a vector of the file extensions handled by this plugin.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
2019-09-26 20:09:09 +00:00
|
|
|
virtual const std::vector<std::string> GetFileExtensions() const = 0;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Return a list of wildcards that contains the file extensions
|
2019-06-14 14:33:48 +00:00
|
|
|
* handled by this plugin, separated with a semi-colon.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
|
|
|
wxString GetWildcards() const
|
|
|
|
{
|
|
|
|
wxString ret;
|
|
|
|
bool first = true;
|
|
|
|
|
|
|
|
for( const auto& extension : GetFileExtensions() )
|
|
|
|
{
|
|
|
|
if( first )
|
|
|
|
first = false;
|
|
|
|
else
|
2022-02-05 13:25:43 +00:00
|
|
|
ret += wxT( ";" );
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2022-02-05 13:25:43 +00:00
|
|
|
ret += wxT( "*." ) + formatWildcardExt( extension );
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Load file for import.
|
2018-10-13 18:37:28 +00:00
|
|
|
*
|
|
|
|
* It is necessary to have the GRAPHICS_IMPORTER object set before.
|
|
|
|
*/
|
|
|
|
virtual bool Load( const wxString& aFileName ) = 0;
|
|
|
|
|
2023-08-18 17:38:23 +00:00
|
|
|
/**
|
|
|
|
* Set memory buffer with content for import.
|
|
|
|
*
|
|
|
|
* It is necessary to have the GRAPHICS_IMPORTER object set before.
|
|
|
|
*/
|
|
|
|
virtual bool LoadFromMemory( const wxMemoryBuffer& aMemBuffer ) = 0;
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Return image height from original imported file.
|
2018-10-13 18:37:28 +00:00
|
|
|
*
|
2018-11-05 16:04:05 +00:00
|
|
|
* @return Original Image height in mm.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
2018-11-05 16:04:05 +00:00
|
|
|
virtual double GetImageHeight() const = 0;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Return image width from original imported file.
|
2018-10-13 18:37:28 +00:00
|
|
|
*
|
2018-11-05 16:04:05 +00:00
|
|
|
* @return Original Image width in mm.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
2018-11-05 16:04:05 +00:00
|
|
|
virtual double GetImageWidth() const = 0;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2023-08-18 18:27:48 +00:00
|
|
|
/**
|
|
|
|
* Return image bounding box from original imported file.
|
|
|
|
*
|
|
|
|
* @return Image bounding box.
|
|
|
|
*/
|
|
|
|
virtual BOX2D GetImageBBox() const = 0;
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Actually imports the file.
|
2018-10-13 18:37:28 +00:00
|
|
|
*
|
|
|
|
* It is necessary to have loaded the file beforehand.
|
|
|
|
*/
|
2018-11-05 16:04:05 +00:00
|
|
|
virtual bool Import() = 0;
|
|
|
|
|
2019-04-03 15:29:17 +00:00
|
|
|
virtual void SetLineWidthMM( double aLineWidth ) {}
|
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Collect warning and error messages after loading/importing.
|
|
|
|
*
|
2018-11-05 16:04:05 +00:00
|
|
|
* @return the list of messages in one string. Each message ends by '\n'
|
|
|
|
*/
|
2021-03-24 04:29:00 +00:00
|
|
|
const virtual wxString& GetMessages() const = 0;
|
2018-11-05 16:04:05 +00:00
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
protected:
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Importer used to create objects representing the imported shapes.
|
2018-10-13 18:37:28 +00:00
|
|
|
GRAPHICS_IMPORTER* m_importer;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* GRAPHICS_IMPORT_PLUGIN_H */
|