2018-10-13 18:37:28 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 CERN
|
2023-08-18 18:27:48 +00:00
|
|
|
* Copyright (C) 2018-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 Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>
|
|
|
|
*
|
|
|
|
* 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_BUFFER_H
|
|
|
|
#define GRAPHICS_IMPORTER_BUFFER_H
|
|
|
|
|
|
|
|
#include "graphics_importer.h"
|
|
|
|
|
2023-01-05 02:22:36 +00:00
|
|
|
#include <math/matrix3x3.h>
|
2018-10-13 18:37:28 +00:00
|
|
|
#include <list>
|
|
|
|
|
|
|
|
class IMPORTED_SHAPE
|
|
|
|
{
|
|
|
|
public:
|
2019-01-03 03:55:16 +00:00
|
|
|
virtual ~IMPORTED_SHAPE() {}
|
2018-10-13 18:37:28 +00:00
|
|
|
virtual void ImportTo( GRAPHICS_IMPORTER& aImporter ) const = 0;
|
2020-11-23 14:59:00 +00:00
|
|
|
|
|
|
|
virtual std::unique_ptr<IMPORTED_SHAPE> clone() const = 0;
|
|
|
|
|
2023-01-05 02:22:36 +00:00
|
|
|
virtual void Transform( const MATRIX3x3D& aTransform, const VECTOR2D& aTranslation ) = 0;
|
2021-12-30 02:47:54 +00:00
|
|
|
|
|
|
|
void SetParentShapeIndex( int aIndex ) { m_parentShapeIndex = aIndex; }
|
|
|
|
int GetParentShapeIndex() const { return m_parentShapeIndex; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int m_parentShapeIndex = -1;
|
2018-10-13 18:37:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class IMPORTED_LINE : public IMPORTED_SHAPE
|
|
|
|
{
|
|
|
|
public:
|
2023-10-09 00:54:34 +00:00
|
|
|
IMPORTED_LINE( const VECTOR2D& aStart, const VECTOR2D& aEnd, const STROKE_PARAMS& aStroke ) :
|
|
|
|
m_start( aStart ), m_end( aEnd ), m_stroke( aStroke )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
|
|
|
|
{
|
2023-10-09 00:54:34 +00:00
|
|
|
aImporter.AddLine( m_start, m_end, m_stroke );
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 14:59:00 +00:00
|
|
|
virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
|
|
|
|
{
|
|
|
|
return std::make_unique<IMPORTED_LINE>( *this );
|
|
|
|
}
|
|
|
|
|
2023-10-09 00:54:34 +00:00
|
|
|
void Transform( const MATRIX3x3D& aTransform, const VECTOR2D& aTranslation ) override
|
2020-11-23 14:59:00 +00:00
|
|
|
{
|
2023-01-05 02:22:36 +00:00
|
|
|
m_start = aTransform * m_start + aTranslation;
|
|
|
|
m_end = aTransform * m_end + aTranslation;
|
2020-11-25 05:54:44 +00:00
|
|
|
}
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
private:
|
2023-10-09 00:54:34 +00:00
|
|
|
VECTOR2D m_start;
|
|
|
|
VECTOR2D m_end;
|
|
|
|
STROKE_PARAMS m_stroke;
|
2018-10-13 18:37:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class IMPORTED_CIRCLE : public IMPORTED_SHAPE
|
|
|
|
{
|
|
|
|
public:
|
2023-10-09 00:54:34 +00:00
|
|
|
IMPORTED_CIRCLE( const VECTOR2D& aCenter, double aRadius, const STROKE_PARAMS& aStroke,
|
|
|
|
bool aFilled, const COLOR4D& aFillColor ) :
|
2020-11-16 00:04:55 +00:00
|
|
|
m_center( aCenter ),
|
2023-10-09 00:54:34 +00:00
|
|
|
m_radius( aRadius ), m_stroke( aStroke ), m_filled( aFilled ), m_fillColor( aFillColor )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
|
|
|
|
{
|
2023-10-09 00:54:34 +00:00
|
|
|
aImporter.AddCircle( m_center, m_radius, m_stroke, m_filled, m_fillColor );
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 14:59:00 +00:00
|
|
|
virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
|
|
|
|
{
|
|
|
|
return std::make_unique<IMPORTED_CIRCLE>( *this );
|
|
|
|
}
|
|
|
|
|
2023-01-05 02:22:36 +00:00
|
|
|
void Transform( const MATRIX3x3D& aTransform, const VECTOR2D& aTranslation ) override
|
2020-11-23 14:59:00 +00:00
|
|
|
{
|
2023-01-05 02:22:36 +00:00
|
|
|
VECTOR2D newCenter = ( aTransform * m_center ) + aTranslation;
|
2020-11-23 14:59:00 +00:00
|
|
|
|
2023-01-05 02:22:36 +00:00
|
|
|
VECTOR2D newRadius = VECTOR2D( m_radius, 0 );
|
|
|
|
newRadius = aTransform * newRadius;
|
2020-11-25 05:54:44 +00:00
|
|
|
|
2023-01-05 02:22:36 +00:00
|
|
|
m_center = newCenter;
|
|
|
|
m_radius = newRadius.EuclideanNorm();
|
2020-11-25 05:54:44 +00:00
|
|
|
}
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
private:
|
2023-10-09 00:54:34 +00:00
|
|
|
VECTOR2D m_center;
|
|
|
|
double m_radius;
|
|
|
|
STROKE_PARAMS m_stroke;
|
|
|
|
bool m_filled;
|
|
|
|
COLOR4D m_fillColor;
|
2018-10-13 18:37:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class IMPORTED_ARC : public IMPORTED_SHAPE
|
|
|
|
{
|
|
|
|
public:
|
2022-01-20 23:08:48 +00:00
|
|
|
IMPORTED_ARC( const VECTOR2D& aCenter, const VECTOR2D& aStart, const EDA_ANGLE& aAngle,
|
2023-10-09 00:54:34 +00:00
|
|
|
const STROKE_PARAMS& aStroke ) :
|
2020-11-16 00:04:55 +00:00
|
|
|
m_center( aCenter ),
|
2023-10-09 00:54:34 +00:00
|
|
|
m_start( aStart ), m_angle( aAngle ), m_stroke( aStroke )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
|
|
|
|
{
|
2023-10-09 00:54:34 +00:00
|
|
|
aImporter.AddArc( m_center, m_start, m_angle, m_stroke );
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 14:59:00 +00:00
|
|
|
virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
|
|
|
|
{
|
|
|
|
return std::make_unique<IMPORTED_ARC>( *this );
|
|
|
|
}
|
|
|
|
|
2023-01-05 02:22:36 +00:00
|
|
|
void Transform( const MATRIX3x3D& aTransform, const VECTOR2D& aTranslation ) override
|
2020-11-23 14:59:00 +00:00
|
|
|
{
|
2023-01-05 02:22:36 +00:00
|
|
|
m_start = aTransform * m_start + aTranslation;
|
|
|
|
m_center = aTransform * m_center + aTranslation;
|
2020-11-25 05:54:44 +00:00
|
|
|
}
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
private:
|
2023-10-09 00:54:34 +00:00
|
|
|
VECTOR2D m_center;
|
|
|
|
VECTOR2D m_start;
|
|
|
|
EDA_ANGLE m_angle;
|
|
|
|
STROKE_PARAMS m_stroke;
|
2018-10-13 18:37:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class IMPORTED_POLYGON : public IMPORTED_SHAPE
|
|
|
|
{
|
|
|
|
public:
|
2023-10-09 00:54:34 +00:00
|
|
|
IMPORTED_POLYGON( const std::vector<VECTOR2D>& aVertices, const STROKE_PARAMS& aStroke,
|
|
|
|
bool aFilled, const COLOR4D& aFillColor ) :
|
2020-11-16 00:04:55 +00:00
|
|
|
m_vertices( aVertices ),
|
2023-10-09 00:54:34 +00:00
|
|
|
m_stroke( aStroke ), m_filled( aFilled ), m_fillColor( aFillColor )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
|
|
|
|
{
|
2023-10-09 00:54:34 +00:00
|
|
|
aImporter.AddPolygon( m_vertices, m_stroke, m_filled, m_fillColor );
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 14:59:00 +00:00
|
|
|
virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
|
|
|
|
{
|
|
|
|
return std::make_unique<IMPORTED_POLYGON>( *this );
|
|
|
|
}
|
|
|
|
|
2023-01-05 02:22:36 +00:00
|
|
|
void Transform( const MATRIX3x3D& aTransform, const VECTOR2D& aTranslation ) override
|
2020-11-25 05:54:44 +00:00
|
|
|
{
|
2023-10-09 00:54:34 +00:00
|
|
|
for( VECTOR2D& vert : m_vertices )
|
2020-11-25 05:54:44 +00:00
|
|
|
{
|
2023-01-05 02:22:36 +00:00
|
|
|
vert = aTransform * vert + aTranslation;
|
2020-11-25 05:54:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-30 02:47:54 +00:00
|
|
|
std::vector<VECTOR2D>& Vertices() { return m_vertices; }
|
|
|
|
|
2023-10-09 00:54:34 +00:00
|
|
|
bool isFilled() const { return m_filled; }
|
|
|
|
|
|
|
|
const COLOR4D& GetFillColor() const { return m_fillColor; }
|
2021-12-30 02:47:54 +00:00
|
|
|
|
2023-10-09 00:54:34 +00:00
|
|
|
const STROKE_PARAMS& GetStroke() const { return m_stroke; }
|
2023-08-18 18:27:48 +00:00
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
private:
|
2020-11-23 14:59:00 +00:00
|
|
|
std::vector<VECTOR2D> m_vertices;
|
2023-10-09 00:54:34 +00:00
|
|
|
STROKE_PARAMS m_stroke;
|
|
|
|
bool m_filled;
|
|
|
|
COLOR4D m_fillColor;
|
2018-10-13 18:37:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class IMPORTED_TEXT : public IMPORTED_SHAPE
|
|
|
|
{
|
|
|
|
public:
|
2020-11-16 00:04:55 +00:00
|
|
|
IMPORTED_TEXT( const VECTOR2D& aOrigin, const wxString& aText, double aHeight, double aWidth,
|
2021-12-28 22:13:54 +00:00
|
|
|
double aThickness, double aOrientation, GR_TEXT_H_ALIGN_T aHJustify,
|
2023-08-18 18:27:48 +00:00
|
|
|
GR_TEXT_V_ALIGN_T aVJustify, const COLOR4D& aColor ) :
|
|
|
|
m_origin( aOrigin ),
|
|
|
|
m_text( aText ), m_height( aHeight ), m_width( aWidth ), m_thickness( aThickness ),
|
|
|
|
m_orientation( aOrientation ), m_hJustify( aHJustify ), m_vJustify( aVJustify ),
|
|
|
|
m_color( aColor )
|
2018-10-13 18:37:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
|
|
|
|
{
|
2023-08-18 18:27:48 +00:00
|
|
|
aImporter.AddText( m_origin, m_text, m_height, m_width, m_thickness, m_orientation,
|
|
|
|
m_hJustify, m_vJustify, m_color );
|
2018-10-13 18:37:28 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 14:59:00 +00:00
|
|
|
virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
|
|
|
|
{
|
|
|
|
return std::make_unique<IMPORTED_TEXT>( *this );
|
|
|
|
}
|
|
|
|
|
2023-01-05 02:22:36 +00:00
|
|
|
void Transform( const MATRIX3x3D& aTransform, const VECTOR2D& aTranslation ) override
|
2020-11-25 05:54:44 +00:00
|
|
|
{
|
2023-01-05 02:22:36 +00:00
|
|
|
m_origin = aTransform * m_origin + aTranslation;
|
2020-11-25 05:54:44 +00:00
|
|
|
}
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
private:
|
2020-11-23 14:59:00 +00:00
|
|
|
VECTOR2D m_origin;
|
2020-11-16 00:04:55 +00:00
|
|
|
const wxString m_text;
|
|
|
|
double m_height;
|
|
|
|
double m_width;
|
|
|
|
double m_thickness;
|
|
|
|
double m_orientation;
|
2021-12-28 22:13:54 +00:00
|
|
|
GR_TEXT_H_ALIGN_T m_hJustify;
|
|
|
|
GR_TEXT_V_ALIGN_T m_vJustify;
|
2023-08-18 18:27:48 +00:00
|
|
|
COLOR4D m_color;
|
2018-10-13 18:37:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-11-01 09:47:41 +00:00
|
|
|
class IMPORTED_SPLINE : public IMPORTED_SHAPE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
IMPORTED_SPLINE( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
|
2023-10-09 00:54:34 +00:00
|
|
|
const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd,
|
|
|
|
const STROKE_PARAMS& aStroke ) :
|
2023-08-18 18:27:48 +00:00
|
|
|
m_start( aStart ),
|
|
|
|
m_bezierControl1( aBezierControl1 ), m_bezierControl2( aBezierControl2 ), m_end( aEnd ),
|
2023-10-09 00:54:34 +00:00
|
|
|
m_stroke( aStroke )
|
2018-11-01 09:47:41 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
|
|
|
|
{
|
2023-10-09 00:54:34 +00:00
|
|
|
aImporter.AddSpline( m_start, m_bezierControl1, m_bezierControl2, m_end, m_stroke );
|
2018-11-01 09:47:41 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 14:59:00 +00:00
|
|
|
virtual std::unique_ptr<IMPORTED_SHAPE> clone() const override
|
|
|
|
{
|
|
|
|
return std::make_unique<IMPORTED_SPLINE>( *this );
|
|
|
|
}
|
|
|
|
|
2023-01-05 02:22:36 +00:00
|
|
|
void Transform( const MATRIX3x3D& aTransform, const VECTOR2D& aTranslation ) override
|
2020-11-25 05:54:44 +00:00
|
|
|
{
|
2023-01-05 02:22:36 +00:00
|
|
|
m_start = aTransform * m_start + aTranslation;
|
|
|
|
m_bezierControl1 = aTransform * m_bezierControl1 + aTranslation;
|
|
|
|
m_bezierControl2 = aTransform * m_bezierControl2 + aTranslation;
|
|
|
|
m_end = aTransform * m_end + aTranslation;
|
2020-11-25 05:54:44 +00:00
|
|
|
}
|
|
|
|
|
2018-11-01 09:47:41 +00:00
|
|
|
private:
|
2023-10-09 00:54:34 +00:00
|
|
|
VECTOR2D m_start;
|
|
|
|
VECTOR2D m_bezierControl1;
|
|
|
|
VECTOR2D m_bezierControl2;
|
|
|
|
VECTOR2D m_end;
|
|
|
|
STROKE_PARAMS m_stroke;
|
2018-11-01 09:47:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
class GRAPHICS_IMPORTER_BUFFER : public GRAPHICS_IMPORTER
|
|
|
|
{
|
|
|
|
public:
|
2023-10-09 00:54:34 +00:00
|
|
|
void AddLine( const VECTOR2D& aStart, const VECTOR2D& aEnd,
|
|
|
|
const STROKE_PARAMS& aStroke ) override;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2023-10-09 00:54:34 +00:00
|
|
|
void AddCircle( const VECTOR2D& aCenter, double aRadius, const STROKE_PARAMS& aStroke,
|
|
|
|
bool aFilled, const COLOR4D& aFillColor = COLOR4D::UNSPECIFIED ) override;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2022-01-20 23:08:48 +00:00
|
|
|
void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, const EDA_ANGLE& aAngle,
|
2023-10-09 00:54:34 +00:00
|
|
|
const STROKE_PARAMS& aStroke ) override;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2023-10-09 00:54:34 +00:00
|
|
|
void AddPolygon( const std::vector<VECTOR2D>& aVertices, const STROKE_PARAMS& aStroke,
|
|
|
|
bool aFilled, const COLOR4D& aFillColor = COLOR4D::UNSPECIFIED ) override;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2021-12-28 22:13:54 +00:00
|
|
|
void AddText( const VECTOR2D& aOrigin, const wxString& aText, double aHeight, double aWidth,
|
|
|
|
double aThickness, double aOrientation, GR_TEXT_H_ALIGN_T aHJustify,
|
2023-08-18 18:27:48 +00:00
|
|
|
GR_TEXT_V_ALIGN_T aVJustify,
|
|
|
|
const COLOR4D& aColor = COLOR4D::UNSPECIFIED ) override;
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2023-10-09 00:54:34 +00:00
|
|
|
void AddSpline( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
|
|
|
|
const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd,
|
|
|
|
const STROKE_PARAMS& aStroke ) override;
|
2018-11-01 09:47:41 +00:00
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
void ImportTo( GRAPHICS_IMPORTER& aImporter );
|
2020-11-23 14:59:00 +00:00
|
|
|
void AddShape( std::unique_ptr<IMPORTED_SHAPE>& aShape );
|
|
|
|
|
|
|
|
std::list<std::unique_ptr<IMPORTED_SHAPE>>& GetShapes()
|
|
|
|
{
|
|
|
|
return m_shapes;
|
|
|
|
}
|
2018-10-13 18:37:28 +00:00
|
|
|
|
2022-04-02 13:57:30 +00:00
|
|
|
void ClearShapes()
|
|
|
|
{
|
|
|
|
m_shapes.clear();
|
|
|
|
}
|
|
|
|
|
2021-12-30 02:47:54 +00:00
|
|
|
void PostprocessNestedPolygons();
|
|
|
|
|
2018-10-13 18:37:28 +00:00
|
|
|
protected:
|
2021-01-27 22:15:38 +00:00
|
|
|
///< List of imported shapes
|
2018-10-13 18:37:28 +00:00
|
|
|
std::list< std::unique_ptr< IMPORTED_SHAPE > > m_shapes;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GRAPHICS_IMPORTER_BUFFER */
|