44#define DXF_LINE_WIDTH DO_NOT_SET_LINE_WIDTH
122 wxFAIL_MSG(
"Unhandled LINE_STYLE" );
133 int( aColor.
g * 255 ),
134 int( aColor.
b * 255 ) );
167 buf = fmt::format(
"{:.16f}", aValue );
170 while( !buf.empty() && buf[buf.size() - 1] ==
'0' )
180 double aScale,
bool aMirror )
264 "Dash Dot ____ _ ____ _\n"
288 "Dashed __ __ __ __ __\n"
333 static const char *style_name[4] = {
"KICAD",
"KICADB",
"KICADI",
"KICADBI"};
335 for(
int i = 0; i < 4; i++ )
377 "{}\n", (
int)numLayers );
388 for(
EDA_COLOR_T i =
BLACK; i < numLayers; i = static_cast<EDA_COLOR_T>(
int( i ) + 1 ) )
456 if( aCornerRadius > 0 )
480 fmt::print(
m_outputFile,
"0\nPOINT\n8\n{}\n10\n{}\n20\n{}\n",
500 fmt::print(
m_outputFile,
"0\nCIRCLE\n8\n{}\n10\n{}\n20\n{}\n40\n{}\n",
528 fmt::print(
m_outputFile,
"0\nPOINT\n8\n{}\n10\n{}\n20\n{}\n",
539 if( aCornerList.size() <= 1 )
542 unsigned last = aCornerList.size() - 1;
549 for(
unsigned ii = 1; ii < aCornerList.size(); ii++ )
550 LineTo( aCornerList[ii] );
555 if( aCornerList[last] != aCornerList[0] )
572 for(
unsigned ii = 1; ii < aCornerList.size(); ii++ )
579 for(
const VECTOR2I& corner : aCornerList )
580 bufferPolybase.
Append( corner );
594 if(
path.PointCount() < 2 )
598 last =
path.PointCount() - 1;
604 for(
int ii = 1; ii <
path.PointCount(); ii++ )
606 point =
path.CPoint( ii );
611 point =
path.CPoint( last );
614 if( endPoint != startPoint )
622 const EDA_ANGLE& aAngle,
double aRadius )
624 std::vector<VECTOR2I> pts;
631 EDA_ANGLE endAngle = startAngle - aAngle;
636 if( startAngle > endAngle )
637 std::swap( startAngle, endAngle );
640 start.
x =
KiROUND( aCenter.
x + aRadius * ( -startAngle ).Cos() );
641 start.
y =
KiROUND( aCenter.
y + aRadius * ( -startAngle ).Sin() );
642 pts.emplace_back( start );
646 end.x =
KiROUND( aCenter.
x + aRadius * ( -ii ).Cos() );
647 end.y =
KiROUND( aCenter.
y + aRadius * ( -ii ).Sin() );
648 pts.emplace_back(
end );
651 end.x =
KiROUND( aCenter.
x + aRadius * ( -endAngle ).Cos() );
652 end.y =
KiROUND( aCenter.
y + aRadius * ( -endAngle ).Sin() );
653 pts.emplace_back(
end );
661 std::set<size_t> handledArcs;
662 std::vector<VECTOR2I> cornerList;
668 size_t arcIndex = aLineChain.
ArcIndex( ii );
670 if( !handledArcs.contains( arcIndex ) )
672 handledArcs.insert( arcIndex );
677 for(
const VECTOR2I& pt : std::ranges::reverse_view( pts ) )
678 cornerList.emplace_back( pt );
684 cornerList.emplace_back( seg.
A );
685 cornerList.emplace_back( seg.
B );
689 if( aLineChain.
IsClosed() && cornerList.front() != cornerList.back() )
690 cornerList.emplace_back( aLineChain.
CPoint( 0 ) );
692 PlotPoly( cornerList, aFill, aWidth, aData );
716 fmt::print(
m_outputFile,
"0\nLINE\n8\n{}\n6\n{}\n10\n{}\n20\n{}\n11\n{}\n21\n{}\n",
747 EDA_ANGLE endAngle = startAngle - aAngle;
751 if( endAngle < startAngle )
752 std::swap( startAngle, endAngle );
760 "0\nARC\n8\n{}\n10\n{}\n20\n{}\n40\n{}\n50\n{:.8f}\n51\n{:.8f}\n",
776 std::vector<VECTOR2I> cornerList;
782 cornerList.reserve(
path.PointCount() );
784 for(
int jj = 0; jj <
path.PointCount(); jj++ )
785 cornerList.emplace_back(
path.CPoint( jj ).x,
path.CPoint( jj ).y );
788 if( cornerList[0] != cornerList[cornerList.size() - 1] )
789 cornerList.push_back( cornerList[0] );
802 const EDA_ANGLE& aAngle,
double aRadius,
int aWidth,
void* aData )
824 VECTOR2I offsetp1( p1.
x - width/2, p1.
y - width/2 );
825 VECTOR2I offsetp2( p2.
x + width/2, p2.
y + width/2 );
899 if( size.
x > size.
y )
901 std::swap( size.
x, size.
y );
923 size.
x = aPadSize.
x / 2;
924 size.
y = aPadSize.
y / 2;
976 int aCornerRadius,
const EDA_ANGLE& aOrient,
void* aData )
987 for(
int ii = 1; ii < poly.
PointCount(); ++ii )
998 for(
int cnt = 0; cnt < aPolygons->
OutlineCount(); ++cnt )
1004 for(
int ii = 1; ii < poly.
PointCount(); ++ii )
1013 const EDA_ANGLE& aPadOrient,
void* aData )
1018 for(
int ii = 0; ii < 4; ii++ )
1020 coord[ii] = aCorners[ii];
1022 coord[ii] += aPadPos;
1051 for(
unsigned i = 0; i <
string.length(); i++ )
1053 wchar_t ch =
string[i];
1064 const wxString& aText,
1072 bool aMultilineAllowed,
1078 if( aMultilineAllowed && !aText.Contains( wxT(
"\n" ) ) )
1079 aMultilineAllowed =
false;
1081 bool processSuperSub = aText.Contains( wxT(
"^{" ) ) || aText.Contains( wxT(
"_{" ) );
1088 PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic,
1089 aBold, aMultilineAllowed, aFont, aFontMetrics, aData );
1109 const wxString& aText,
1118 if( attrs.
m_Multiline && !aText.Contains( wxT(
"\n" ) ) )
1121 bool processSuperSub = aText.Contains( wxT(
"^{" ) ) || aText.Contains( wxT(
"_{" ) );
1128 PLOTTER::PlotText( aPos, aColor, aText, aAttributes, aFont, aFontMetrics, aData );
1146 int h_code = 0, v_code = 0;
1164 std::string textStyle =
"KICAD";
1168 textStyle =
"KICADBI";
1170 textStyle =
"KICADB";
1173 textStyle =
"KICADI";
1242 int braceNesting = 0;
1243 int overbarDepth = -1;
1247 for(
unsigned int i = 0; i < aText.length(); i++ )
1255 wchar_t ch = aText[i];
1264 if( aText[i] ==
'~' && i+1 < aText.length() && aText[i+1] ==
'{' )
1267 overbarDepth = braceNesting;
1273 else if( aText[i] ==
'{' )
1277 else if( aText[i] ==
'}' )
1279 if( braceNesting > 0 )
1282 if( braceNesting == overbarDepth )
static wxString getDXFColorName(const COLOR4D &aColor)
static const double DXF_OBLIQUE_ANGLE
Oblique angle for DXF native text (I don't remember if 15 degrees is the ISO value....
static const struct @110355335012326036072316124131344246226335322120 dxf_layer[NBCOLORS]
The layer/colors palette.
static std::string formatCoord(double aValue)
bool containsNonAsciiChars(const wxString &string)
Check if a given string contains non-ASCII characters.
std::vector< VECTOR2I > arcPts(const VECTOR2D &aCenter, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle, double aRadius)
static const char * getDXFLineType(LINE_STYLE aType)
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
static EDA_COLOR_T FindNearestLegacyColor(int aR, int aG, int aB)
Returns a legacy color ID that is closest to the given 8-bit RGB values.
static const COLOR4D WHITE
static const COLOR4D BLACK
void plotOneLineOfText(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const TEXT_ATTRIBUTES &aAttrs)
virtual void PlotText(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const TEXT_ATTRIBUTES &aAttributes, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, void *aData=nullptr) override
virtual void FlashPadCustom(const VECTOR2I &aPadPos, const VECTOR2I &aSize, const EDA_ANGLE &aOrient, SHAPE_POLY_SET *aPolygons, void *aData) override
virtual void ThickCircle(const VECTOR2I &pos, int diametre, int width, void *aData) override
void SetUnits(DXF_UNITS aUnit)
Set the units to use for plotting the DXF file.
virtual void SetViewport(const VECTOR2I &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the scale/position for the DXF plot.
virtual void ThickArc(const VECTOR2D &aCentre, const EDA_ANGLE &aStAngle, const EDA_ANGLE &aAngle, double aRadius, int aWidth, void *aData) override
virtual void Arc(const VECTOR2D &aCenter, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle, double aRadius, FILL_T aFill, int aWidth) override
double GetUnitScaling() const
Get the scale factor to apply to convert the device units to be in the currently set units.
virtual void FlashPadOval(const VECTOR2I &aPos, const VECTOR2I &aSize, const EDA_ANGLE &aOrient, void *aData) override
DXF oval pad: always done in sketch mode.
virtual void FlashPadRect(const VECTOR2I &aPos, const VECTOR2I &aSize, const EDA_ANGLE &aOrient, void *aData) override
DXF rectangular pad: always done in sketch mode.
virtual void ThickRect(const VECTOR2I &p1, const VECTOR2I &p2, int width, void *aData) override
virtual void FlashPadRoundRect(const VECTOR2I &aPadPos, const VECTOR2I &aSize, int aCornerRadius, const EDA_ANGLE &aOrient, void *aData) override
virtual void ThickPoly(const SHAPE_POLY_SET &aPoly, int aWidth, void *aData) override
virtual bool StartPlot(const wxString &aPageNumber) override
Open the DXF plot with a skeleton header.
unsigned int GetMeasurementDirective() const
Get the correct value for the $MEASUREMENT field given the current units.
virtual void FlashPadTrapez(const VECTOR2I &aPadPos, const VECTOR2I *aCorners, const EDA_ANGLE &aPadOrient, void *aData) override
DXF trapezoidal pad: only sketch mode is supported.
virtual void Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width) override
DXF circle: full functionality; it even does 'fills' drawing a circle with a dual-arc polyline wide a...
virtual void FlashPadCircle(const VECTOR2I &pos, int diametre, void *aData) override
DXF round pad: always done in sketch mode; it could be filled but it isn't pretty if other kinds of p...
virtual void FilledCircle(const VECTOR2I &pos, int diametre, void *aData) override
virtual void PlotPoly(const std::vector< VECTOR2I > &aCornerList, FILL_T aFill, int aWidth, void *aData=nullptr) override
DXF polygon: doesn't fill it but at least it close the filled ones DXF does not know thick outline.
unsigned int m_measurementDirective
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T fill, int width, int aCornerRadius=0) override
DXF rectangle: fill not supported.
virtual bool EndPlot() override
virtual void FlashRegularPolygon(const VECTOR2I &aShapePos, int aDiameter, int aCornerCount, const EDA_ANGLE &aOrient, void *aData) override
Flash a regular polygon.
virtual void PenTo(const VECTOR2I &pos, char plume) override
Moveto/lineto primitive, moves the 'pen' to the specified direction.
virtual void SetColor(const COLOR4D &color) override
The DXF exporter handles 'colors' as layers...
virtual void Text(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const EDA_ANGLE &aOrient, const VECTOR2I &aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, void *aData=nullptr) override
Draw text with the plotter.
virtual void ThickSegment(const VECTOR2I &start, const VECTOR2I &end, int width, void *aData) override
double m_unitScalingFactor
virtual void SetDash(int aLineWidth, LINE_STYLE aLineStyle) override
LINE_STYLE m_currentLineType
FONT is an abstract base class for both outline and stroke fonts.
A color representation with 4 components: red, green, blue, alpha.
void MoveTo(const VECTOR2I &pos)
virtual void ThickOval(const VECTOR2I &aPos, const VECTOR2I &aSize, const EDA_ANGLE &aOrient, int aWidth, void *aData)
void FinishTo(const VECTOR2I &pos)
virtual VECTOR2D userToDeviceCoordinates(const VECTOR2I &aCoordinate)
Modify coordinates according to the orientation, scale factor, and offsets trace.
virtual VECTOR2D userToDeviceSize(const VECTOR2I &size)
Modify size according to the plotter scale factors (VECTOR2I version, returns a VECTOR2D).
int GetPlotterArcHighDef() const
double m_plotScale
Plot scale - chosen by the user (even implicitly with 'fit in a4')
bool GetColorMode() const
FILE * m_outputFile
Output file.
void LineTo(const VECTOR2I &pos)
virtual void PlotText(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const TEXT_ATTRIBUTES &aAttributes, KIFONT::FONT *aFont=nullptr, const KIFONT::METRICS &aFontMetrics=KIFONT::METRICS::Default(), void *aData=nullptr)
virtual void PlotPoly(const std::vector< VECTOR2I > &aCornerList, FILL_T aFill, int aWidth, void *aData)=0
Draw a polygon ( filled or not ).
virtual void Text(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const EDA_ANGLE &aOrient, const VECTOR2I &aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, int aPenWidth, bool aItalic, bool aBold, bool aMultilineAllowed, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, void *aData=nullptr)
Draw text with the plotter.
virtual DXF_OUTLINE_MODE GetDXFPlotMode() const
EDA_ANGLE GetCentralAngle() const
Get the "central angle" of the arc - this is the angle at the point of the "pie slice".
EDA_ANGLE GetStartAngle() const
const VECTOR2I & GetCenter() const
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
const SHAPE_ARC & Arc(size_t aArc) const
bool IsClosed() const override
int PointCount() const
Return the number of points (vertices) in this line chain.
ssize_t ArcIndex(size_t aSegment) const
Return the arc index for the given segment index.
SEG Segment(int aIndex) const
Return a copy of the aIndex-th segment in the line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
int SegmentCount() const
Return the number of segments in this line chain.
bool IsArcSegment(size_t aSegment) const
Represent a set of closed polygons.
void BooleanAdd(const SHAPE_POLY_SET &b)
Perform boolean polyset union.
void Fracture()
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int NewOutline()
Creates a new empty polygon in the set and returns its index.
void Deflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError)
int OutlineCount() const
Return the number of outlines in the set.
SHAPE_POLY_SET CloneDropTriangulation() const
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
const SHAPE_LINE_CHAIN Outline() const
void SetRadius(int aRadius)
GR_TEXT_H_ALIGN_T m_Halign
GR_TEXT_V_ALIGN_T m_Valign
EDA_COLOR_T
Legacy color enumeration.
@ NBCOLORS
Number of colors.
void TransformRoundChamferedRectToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aPosition, const VECTOR2I &aSize, const EDA_ANGLE &aRotation, int aCornerRadius, double aChamferRatio, int aChamferCorners, int aInflate, int aError, ERROR_LOC aErrorLoc)
Convert a rectangle with rounded corners and/or chamfered corners to a polygon.
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
@ ROUND_ALL_CORNERS
All angles are rounded.
static constexpr EDA_ANGLE ANGLE_90
@ FILLED_SHAPE
Fill with object color.
This file contains miscellaneous commonly used macros and functions.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
LINE_STYLE
Dashed line types.
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
@ GR_TEXT_H_ALIGN_INDETERMINATE
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
@ GR_TEXT_V_ALIGN_INDETERMINATE
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D