37template <
typename T,
typename... Args>
38static std::unique_ptr<T>
make_shape(
const Args&... aArguments )
40 return std::make_unique<T>( aArguments... );
81 double aHeight,
double aWidth,
double aThickness,
86 aOrientation, aHJustify, aVJustify, aColor ) );
116 aEndAngle, aStroke ) );
123 if( aShape && aShape->GetSourceLayer().IsEmpty() )
126 m_shapes.push_back( std::move( aShape ) );
132 std::vector<wxString> sourceLayers;
134 for(
const std::unique_ptr<IMPORTED_SHAPE>& shape :
m_shapes )
136 const wxString& sourceLayer = shape->GetSourceLayer();
138 if( sourceLayer.IsEmpty() )
141 if( std::find( sourceLayers.begin(), sourceLayers.end(), sourceLayer ) == sourceLayers.end() )
142 sourceLayers.push_back( sourceLayer );
153 for( std::unique_ptr<IMPORTED_SHAPE>& shape :
m_shapes )
158 BOX2D box = shape->GetBoundingBox();
174 > std::numeric_limits<int>::max()
176 > std::numeric_limits<int>::max() )
178 double scale_factor = std::numeric_limits<int>::max() /
180 double max_scale = std::max( scale_factor /
boundingBox.GetSize().x,
182 aImporter.
ReportMsg( wxString::Format(
_(
"Imported graphic is too large. Maximum scale is %f" ),
192 if(
boundingBox.GetRight() * iuFactor > std::numeric_limits<int>::max()
193 ||
boundingBox.GetBottom() * iuFactor > std::numeric_limits<int>::max()
194 ||
boundingBox.GetLeft() * iuFactor < std::numeric_limits<int>::min()
195 ||
boundingBox.GetTop() * iuFactor < std::numeric_limits<int>::min() )
212 bool needsAdjustment =
false;
214 if( max_offset_x >= std::numeric_limits<int>::max() )
216 newOffset.
x -= ( max_offset_x - std::numeric_limits<int>::max() + 100.0 ) / total_scale_x;
217 needsAdjustment =
true;
219 else if( min_offset_x <= std::numeric_limits<int>::min() )
221 newOffset.
x -= ( min_offset_x - std::numeric_limits<int>::min() - 100 ) / total_scale_x;
222 needsAdjustment =
true;
225 if( max_offset_y >= std::numeric_limits<int>::max() )
227 newOffset.
y -= ( max_offset_y - std::numeric_limits<int>::max() + 100 ) / total_scale_y;
228 needsAdjustment =
true;
230 else if( min_offset_y <= std::numeric_limits<int>::min() )
232 newOffset.
y -= ( min_offset_y - std::numeric_limits<int>::min() - 100 ) / total_scale_y;
233 needsAdjustment =
true;
236 if( needsAdjustment )
238 aImporter.
ReportMsg( wxString::Format(
_(
"Import offset adjusted to (%f, %f) to fit "
239 "within numeric limits" ),
240 newOffset.
x, newOffset.
y ) );
245 for( std::unique_ptr<IMPORTED_SHAPE>& shape :
m_shapes )
251 shape->ImportTo( aImporter );
260 std::vector<IMPORTED_POLYGON*>& aPaths,
265 double minX = std::numeric_limits<double>::max();
267 double maxX = std::numeric_limits<double>::min();
272 const double convert_scale = 1000000000.0;
278 minX = std::min( minX, v.x );
279 minY = std::min( minY, v.y );
280 maxX = std::max( maxX, v.x );
281 maxY = std::max( maxY, v.y );
285 double origW = ( maxX - minX );
286 double origH = ( maxY - minY );
287 double upscaledW, upscaledH;
289 wxCHECK( origH && origW, );
293 upscaledW = convert_scale;
294 upscaledH = ( origH == 0.0f ? 0.0 : origH * convert_scale / origW );
298 upscaledH = convert_scale;
299 upscaledW = ( origW == 0.0f ? 0.0 : origW * convert_scale / origH );
302 std::vector<IMPORTED_POLYGON*> openPaths;
303 std::vector<SHAPE_LINE_CHAIN> upscaledPaths;
307 if(
path->Vertices().size() < 3 )
309 openPaths.push_back(
path );
317 int xp =
KiROUND( ( v.x - minX ) * ( upscaledW / origW ) );
318 int yp =
KiROUND( ( v.y - minY ) * ( upscaledH / origH ) );
323 upscaledPaths.push_back( lc );
327 result.BuildPolysetFromOrientedPaths( upscaledPaths,
331 for(
int outl = 0; outl <
result.OutlineCount(); outl++ )
334 std::vector<VECTOR2D> pts;
338 double xp = (double) ro.
CPoint( i ).
x * ( origW / upscaledW ) + minX;
339 double yp = (double) ro.
CPoint( i ).
y * ( origH / upscaledH ) + minY;
340 pts.emplace_back(
VECTOR2D( xp, yp ) );
343 aShapes.push_back( std::make_unique<IMPORTED_POLYGON>( pts, aStroke, aFilled, aFillColor ) );
347 aShapes.push_back( std::make_unique<IMPORTED_POLYGON>( *openPath ) );
353 int curShapeIdx = -1;
355 bool lastFilled =
false;
358 std::list<std::unique_ptr<IMPORTED_SHAPE>> newShapes;
359 std::vector<IMPORTED_POLYGON*> polypaths;
361 for( std::unique_ptr<IMPORTED_SHAPE>& shape :
m_shapes )
367 newShapes.push_back( shape->clone() );
373 if(
index != curShapeIdx && curShapeIdx >= 0 )
376 lastFilled, lastFillColor );
385 polypaths.push_back( poly );
388 if( curShapeIdx >= 0 )
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
constexpr bool IsValid() const
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
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 AddEllipse(const VECTOR2D &aCenter, double aMajorRadius, double aMinorRadius, const EDA_ANGLE &aRotation, const IMPORTED_STROKE &aStroke, bool aFilled, const COLOR4D &aFillColor=COLOR4D::UNSPECIFIED) override
Create an object representing a closed ellipse.
void PostprocessNestedPolygons()
void ImportTo(GRAPHICS_IMPORTER &aImporter)
std::vector< wxString > GetSourceLayers() const
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)
wxString m_currentSourceLayer
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.
void AddEllipseArc(const VECTOR2D &aCenter, double aMajorRadius, double aMinorRadius, const EDA_ANGLE &aRotation, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aEndAngle, const IMPORTED_STROKE &aStroke) override
Create an object representing an elliptical arc.
std::vector< POLY_FILL_RULE > m_shapeFillRules
virtual void SetCurrentSourceLayer(const wxString &)
Set the source layer for the next buffered shape to be imported.
void ReportMsg(const wxString &aMessage)
VECTOR2D GetScale() const
double GetMillimeterToIuFactor()
void SetImportOffsetMM(const VECTOR2D &aOffset)
Set the offset in millimeters to add to coordinates when importing graphic items.
virtual bool CanImportSourceLayer(const wxString &) const
Return true if shapes from a given source layer should be imported.
const VECTOR2D & GetImportOffsetMM() const
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 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)
BOX2I boundingBox(T aObject, int aLayer)
Used by SHAPE_INDEX to get the bounding box of a generic T object.
wxString result
Test unit parsing edge cases and error handling.
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
VECTOR2< double > VECTOR2D