35template <
typename T,
typename... Args>
36static std::unique_ptr<T>
make_shape(
const Args&... aArguments )
38 return std::make_unique<T>( aArguments... );
44 m_shapes.push_back( make_shape<IMPORTED_LINE>( aStart, aEnd, aStroke ) );
53 make_shape<IMPORTED_CIRCLE>( aCenter, aRadius, aStroke, aFilled, aFillColor ) );
60 m_shapes.push_back( make_shape<IMPORTED_ARC>( aCenter, aStart, aAngle, aStroke ) );
68 m_shapes.push_back( make_shape<IMPORTED_POLYGON>( aVertices, aStroke, aFilled, aFillColor ) );
75 double aHeight,
double aWidth,
double aThickness,
79 m_shapes.push_back( make_shape<IMPORTED_TEXT>( aOrigin, aText, aHeight, aWidth, aThickness,
80 aOrientation, aHJustify, aVJustify, aColor ) );
88 m_shapes.push_back( make_shape<IMPORTED_SPLINE>( aStart, aBezierControl1, aBezierControl2, aEnd,
95 m_shapes.push_back( std::move( aShape ) );
101 for( std::unique_ptr<IMPORTED_SHAPE>& shape :
m_shapes )
102 shape->ImportTo( aImporter );
107 std::vector<IMPORTED_POLYGON*>& aPaths,
112 double minX = std::numeric_limits<double>::max();
114 double maxX = std::numeric_limits<double>::min();
119 const double convert_scale = 1000000000.0;
125 minX = std::min( minX, v.x );
126 minY = std::min( minY, v.y );
127 maxX = std::max( maxX, v.x );
128 maxY = std::max( maxY, v.y );
132 double origW = ( maxX - minX );
133 double origH = ( maxY - minY );
134 double upscaledW, upscaledH;
138 upscaledW = convert_scale;
139 upscaledH = ( origH == 0.0f ? 0.0 : origH * convert_scale / origW );
143 upscaledH = convert_scale;
144 upscaledW = ( origW == 0.0f ? 0.0 : origW * convert_scale / origH );
147 std::vector<IMPORTED_POLYGON*> openPaths;
148 std::vector<SHAPE_LINE_CHAIN> upscaledPaths;
152 if(
path->Vertices().size() < 3 )
154 openPaths.push_back(
path );
162 int xp =
KiROUND( ( v.x - minX ) * ( upscaledW / origW ) );
163 int yp =
KiROUND( ( v.y - minY ) * ( upscaledH / origH ) );
167 upscaledPaths.push_back( lc );
174 for(
int outl = 0; outl < result.
OutlineCount(); outl++ )
177 std::vector<VECTOR2D> pts;
180 double xp = (double) ro.
CPoint( i ).
x * ( origW / upscaledW ) + minX;
181 double yp = (double) ro.
CPoint( i ).
y * ( origH / upscaledH ) + minY;
182 pts.emplace_back(
VECTOR2D( xp, yp ) );
186 std::make_unique<IMPORTED_POLYGON>( pts, aStroke, aFilled, aFillColor ) );
190 aShapes.push_back( std::make_unique<IMPORTED_POLYGON>( *openPath ) );
196 int curShapeIdx = -1;
198 bool lastFilled =
false;
199 COLOR4D lastFillColor = COLOR4D::UNSPECIFIED;
201 std::list<std::unique_ptr<IMPORTED_SHAPE>> newShapes;
202 std::vector<IMPORTED_POLYGON*> polypaths;
204 for( std::unique_ptr<IMPORTED_SHAPE>& shape :
m_shapes )
210 newShapes.push_back( shape->clone() );
216 if( index != curShapeIdx && curShapeIdx >= 0 )
219 lastFilled, lastFillColor );
228 polypaths.push_back( poly );
231 if( curShapeIdx >= 0 )
void AddCircle(const VECTOR2D &aCenter, double aRadius, const IMPORTED_STROKE &aStroke, bool aFilled, const COLOR4D &aFillColor=COLOR4D::UNSPECIFIED) override
Create an object representing a circle.
void AddSpline(const VECTOR2D &aStart, const VECTOR2D &aBezierControl1, const VECTOR2D &aBezierControl2, const VECTOR2D &aEnd, const IMPORTED_STROKE &aStroke) override
Create an object representing an arc.
void AddLine(const VECTOR2D &aStart, const VECTOR2D &aEnd, const IMPORTED_STROKE &aStroke) override
Create an object representing a line segment.
void PostprocessNestedPolygons()
void ImportTo(GRAPHICS_IMPORTER &aImporter)
void AddArc(const VECTOR2D &aCenter, const VECTOR2D &aStart, const EDA_ANGLE &aAngle, const IMPORTED_STROKE &aStroke) override
Create an object representing an arc.
void AddText(const VECTOR2D &aOrigin, const wxString &aText, double aHeight, double aWidth, double aThickness, double aOrientation, GR_TEXT_H_ALIGN_T aHJustify, GR_TEXT_V_ALIGN_T aVJustify, const COLOR4D &aColor=COLOR4D::UNSPECIFIED) override
Create an object representing a text.
std::list< std::unique_ptr< IMPORTED_SHAPE > > m_shapes
< List of imported shapes
void AddShape(std::unique_ptr< IMPORTED_SHAPE > &aShape)
void AddPolygon(const std::vector< VECTOR2D > &aVertices, const IMPORTED_STROKE &aStroke, bool aFilled, const COLOR4D &aFillColor=COLOR4D::UNSPECIFIED) override
Create an object representing a polygon.
Interface that creates objects representing shapes for a given data model.
std::vector< POLY_FILL_RULE > m_shapeFillRules
const IMPORTED_STROKE & GetStroke() const
const COLOR4D & GetFillColor() const
int GetParentShapeIndex() const
A clone of IMPORTED_STROKE, but with floating-point width.
A color representation with 4 components: red, green, blue, alpha.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
int PointCount() const
Return the number of points (vertices) in this line chain.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
static const SHAPE_POLY_SET BuildPolysetFromOrientedPaths(const std::vector< SHAPE_LINE_CHAIN > &aPaths, bool aReverseOrientation=false, bool aEvenOdd=false)
Build a SHAPE_POLY_SET from a bunch of outlines in provided in random order.
void Fracture(POLYGON_MODE aFastMode)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
int OutlineCount() const
Return the number of outlines in the set.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
static std::unique_ptr< T > make_shape(const Args &... aArguments)
static void convertPolygon(std::list< std::unique_ptr< IMPORTED_SHAPE > > &aShapes, std::vector< IMPORTED_POLYGON * > &aPaths, GRAPHICS_IMPORTER::POLY_FILL_RULE aFillRule, const IMPORTED_STROKE &aStroke, bool aFilled, const COLOR4D &aFillColor)
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
VECTOR2< double > VECTOR2D