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
|
2021-01-27 22:15:38 +00:00
|
|
|
* Copyright (C) 2019-2021 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GRAPHICS_IMPORTER_H
|
|
|
|
#define GRAPHICS_IMPORTER_H
|
|
|
|
|
|
|
|
#include "graphics_import_mgr.h"
|
|
|
|
#include "graphics_import_plugin.h"
|
|
|
|
|
|
|
|
#include <eda_text.h>
|
|
|
|
#include <math/vector2d.h>
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class EDA_ITEM;
|
|
|
|
|
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Interface that creates objects representing shapes for a given data model.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
|
|
|
class GRAPHICS_IMPORTER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GRAPHICS_IMPORTER();
|
|
|
|
|
|
|
|
virtual ~GRAPHICS_IMPORTER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Set the import plugin used to obtain shapes from a file.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
|
|
|
void SetPlugin( std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> aPlugin )
|
|
|
|
{
|
|
|
|
m_plugin = std::move( aPlugin );
|
2019-04-03 15:29:17 +00:00
|
|
|
|
|
|
|
if( m_plugin )
|
|
|
|
m_plugin->SetImporter( this );
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Load file and get its basic data
|
2018-10-13 18:37:28 +00:00
|
|
|
*
|
|
|
|
*/
|
2021-07-27 12:22:27 +00:00
|
|
|
bool Load( const wxString& aFileName );
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Import shapes from loaded file.
|
2018-10-13 18:37:28 +00:00
|
|
|
*
|
|
|
|
* It is important to have the file loaded before importing.
|
2018-11-05 16:04:05 +00:00
|
|
|
*
|
|
|
|
* @param aScale allow import graphic items with a non 1:1 import ratio
|
|
|
|
* aScale = 1.0 to import graphics with their actual size.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
2018-11-05 16:04:05 +00:00
|
|
|
bool Import( double aScale = 1.0 );
|
|
|
|
|
|
|
|
/**
|
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 wxString& GetMessages() const
|
2018-11-05 16:04:05 +00:00
|
|
|
{
|
|
|
|
return m_plugin->GetMessages();
|
|
|
|
}
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Get original image Width.
|
2018-10-13 18:37:28 +00:00
|
|
|
*
|
2018-11-05 16:04:05 +00:00
|
|
|
* @return Width of the loaded image in mm.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
2018-11-05 16:04:05 +00:00
|
|
|
double GetImageWidthMM() const
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
|
|
|
return m_originalWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Get original image Height
|
2018-10-13 18:37:28 +00:00
|
|
|
*
|
2018-11-05 16:04:05 +00:00
|
|
|
* @return Height of the loaded image in mm.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
2018-11-05 16:04:05 +00:00
|
|
|
double GetImageHeightMM() const
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
|
|
|
return m_originalHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Set the line width for the imported outlines (in mm).
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
2018-11-05 16:04:05 +00:00
|
|
|
void SetLineWidthMM( double aWidth )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
2018-11-05 16:04:05 +00:00
|
|
|
m_lineWidth = aWidth;
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Return the line width used for importing the outlines (in mm).
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
2018-11-05 16:04:05 +00:00
|
|
|
double GetLineWidthMM() const
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
|
|
|
return m_lineWidth;
|
|
|
|
}
|
|
|
|
|
2019-04-03 15:29:17 +00:00
|
|
|
/**
|
|
|
|
* @return the scale factor affecting the imported shapes.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
|
|
|
double GetScale() const
|
|
|
|
{
|
|
|
|
return m_scale;
|
|
|
|
}
|
|
|
|
|
2019-04-03 15:29:17 +00:00
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* @return the offset in millimeters to add to coordinates when importing graphic items.
|
2018-11-05 16:04:05 +00:00
|
|
|
*/
|
|
|
|
const VECTOR2D& GetImportOffsetMM() const
|
|
|
|
{
|
|
|
|
return m_offsetCoordmm;
|
|
|
|
}
|
|
|
|
|
2019-04-03 15:29:17 +00:00
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Set the offset in millimeters to add to coordinates when importing graphic items.
|
2018-11-05 16:04:05 +00:00
|
|
|
*/
|
|
|
|
void SetImportOffsetMM( const VECTOR2D& aOffset )
|
|
|
|
{
|
|
|
|
m_offsetCoordmm = aOffset;
|
|
|
|
}
|
|
|
|
|
2019-04-03 15:29:17 +00:00
|
|
|
/**
|
|
|
|
* Set the scale factor affecting the imported shapes.
|
2021-01-27 22:15:38 +00:00
|
|
|
*
|
|
|
|
* This allows conversion between imported shapes units and millimeters.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
|
|
|
void SetScale( double aScale )
|
|
|
|
{
|
|
|
|
m_scale = aScale;
|
|
|
|
}
|
|
|
|
|
2019-04-03 15:29:17 +00:00
|
|
|
/**
|
|
|
|
* @return the conversion factor from mm to internal unit
|
2018-11-05 16:04:05 +00:00
|
|
|
*/
|
|
|
|
double GetMillimeterToIuFactor()
|
|
|
|
{
|
|
|
|
return m_millimeterToIu;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the overall scale factor to convert the imported shapes dimension to mm.
|
|
|
|
*/
|
|
|
|
double ImportScalingFactor() const
|
|
|
|
{
|
|
|
|
return m_scale * m_millimeterToIu;
|
|
|
|
}
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Return the list of objects representing the imported shapes.
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
|
|
|
std::list<std::unique_ptr<EDA_ITEM>>& GetItems()
|
|
|
|
{
|
|
|
|
return m_items;
|
|
|
|
}
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Default line thickness (in mm)
|
2018-10-13 18:37:28 +00:00
|
|
|
static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX = 1;
|
|
|
|
|
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Create an object representing a line segment.
|
|
|
|
*
|
2018-11-05 16:04:05 +00:00
|
|
|
* @param aOrigin is the segment origin point expressed in mm.
|
|
|
|
* @param aEnd is the segment end point expressed in mm.
|
|
|
|
* @param aWidth is the segment thickness in mm. Use -1 for default line thickness
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
2018-11-05 16:04:05 +00:00
|
|
|
virtual void AddLine( const VECTOR2D& aOrigin, const VECTOR2D& aEnd, double aWidth ) = 0;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Create an object representing a circle.
|
|
|
|
*
|
2018-11-05 16:04:05 +00:00
|
|
|
* @param aCenter is the circle center point expressed in mm.
|
|
|
|
* @param aRadius is the circle radius expressed in mm.
|
|
|
|
* @param aWidth is the segment thickness in mm. Use -1 for default line thickness
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
2021-01-27 22:15:38 +00:00
|
|
|
virtual void AddCircle( const VECTOR2D& aCenter, double aRadius, double aWidth,
|
|
|
|
bool aFilled ) = 0;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Create an object representing an arc.
|
|
|
|
*
|
2018-11-05 16:04:05 +00:00
|
|
|
* @param aCenter is the arc center point expressed in mm.
|
|
|
|
* @param aStart is the arc arm end point expressed in mm.
|
2018-10-13 18:37:28 +00:00
|
|
|
* Its length is the arc radius.
|
2019-01-22 18:59:43 +00:00
|
|
|
* @param aAngle is the arc angle expressed in degrees.
|
2018-11-05 16:04:05 +00:00
|
|
|
* @param aWidth is the segment thickness in mm. Use -1 for default line thickness
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
2019-04-03 15:29:17 +00:00
|
|
|
virtual void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle,
|
|
|
|
double aWidth ) = 0;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
virtual void AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth ) = 0;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Create an object representing a text.
|
|
|
|
*
|
2018-10-13 18:37:28 +00:00
|
|
|
* @param aOrigin is the text position.
|
|
|
|
* @param aText is the displayed text.
|
2018-11-05 16:04:05 +00:00
|
|
|
* @param aHeight is the text height expressed in mm.
|
|
|
|
* @param aWidth is the text width expressed in mm.
|
2019-01-22 18:59:43 +00:00
|
|
|
* @param aOrientation is the text orientation angle expressed in degrees.
|
2018-10-13 18:37:28 +00:00
|
|
|
* @param aHJustify is the text horizontal justification.
|
|
|
|
* @param aVJustify is the text vertical justification.
|
2018-11-05 16:04:05 +00:00
|
|
|
* @param aWidth is the segment thickness in mm. Use -1 for default line thickness
|
2018-10-13 18:37:28 +00:00
|
|
|
*/
|
|
|
|
virtual void AddText( const VECTOR2D& aOrigin, const wxString& aText,
|
2018-12-04 19:01:47 +00:00
|
|
|
double aHeight, double aWidth, double aThickness, double aOrientation,
|
2018-10-13 18:37:28 +00:00
|
|
|
EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify ) = 0;
|
|
|
|
|
2018-11-05 16:04:05 +00:00
|
|
|
/**
|
2019-04-03 15:29:17 +00:00
|
|
|
* Create an object representing an arc.
|
|
|
|
*
|
2018-11-05 16:04:05 +00:00
|
|
|
* @param aStart is the curve start point expressed in mm.
|
|
|
|
* @param aBezierControl1 is the first Bezier control point expressed in mm.
|
|
|
|
* @param aBezierControl2 is the second Bezier control point expressed in mm.
|
|
|
|
* @param aEnd is the curve end point expressed in mm.
|
|
|
|
* @param aWidth is the segment thickness in mm. Use -1 for default line thickness
|
|
|
|
*/
|
2018-11-01 09:47:41 +00:00
|
|
|
virtual void AddSpline( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
|
2019-04-03 15:29:17 +00:00
|
|
|
const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd,
|
|
|
|
double aWidth ) = 0;
|
2018-11-01 09:47:41 +00:00
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
protected:
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Add an item to the imported shapes list.
|
2018-10-13 18:37:28 +00:00
|
|
|
void addItem( std::unique_ptr<EDA_ITEM> aItem )
|
|
|
|
{
|
|
|
|
m_items.emplace_back( std::move( aItem ) );
|
|
|
|
}
|
|
|
|
|
2021-06-04 17:44:22 +00:00
|
|
|
///< factor to convert millimeters to Internal Units
|
|
|
|
double m_millimeterToIu;
|
|
|
|
|
|
|
|
///< Offset (in mm) for imported coordinates
|
|
|
|
VECTOR2D m_offsetCoordmm;
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
private:
|
2021-01-27 22:15:38 +00:00
|
|
|
///< List of imported items
|
2018-10-13 18:37:28 +00:00
|
|
|
std::list<std::unique_ptr<EDA_ITEM>> m_items;
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Plugin used to load a file
|
2018-10-13 18:37:28 +00:00
|
|
|
std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> m_plugin;
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Total image width
|
2018-11-05 16:04:05 +00:00
|
|
|
double m_originalWidth;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Total image Height;
|
2018-11-05 16:04:05 +00:00
|
|
|
double m_originalHeight;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2019-04-03 15:29:17 +00:00
|
|
|
/**
|
|
|
|
* Scale factor applied to the imported graphics.
|
2018-11-05 16:04:05 +00:00
|
|
|
* 1.0 does not change the size of imported items
|
|
|
|
* scale < 1.0 reduce the size of imported items
|
|
|
|
*/
|
2018-10-13 18:37:28 +00:00
|
|
|
double m_scale;
|
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Default line thickness for the imported graphics
|
2019-04-03 15:29:17 +00:00
|
|
|
double m_lineWidth;
|
2018-10-13 18:37:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GRAPHICS_IMPORTER_H */
|