svg-flatten: Add support for line thickness to board outline exporter
This commit is contained in:
parent
046e827be1
commit
1d6d4e4f14
3 changed files with 34 additions and 5 deletions
|
|
@ -44,6 +44,12 @@ namespace gerbolyze {
|
|||
std::string m_name;
|
||||
};
|
||||
|
||||
class ApertureToken {
|
||||
public:
|
||||
ApertureToken(double size=0.0) : m_size(size) {}
|
||||
double m_size = 0.0;
|
||||
};
|
||||
|
||||
class PolygonSink {
|
||||
public:
|
||||
virtual ~PolygonSink() {}
|
||||
|
|
@ -66,6 +72,7 @@ namespace gerbolyze {
|
|||
};
|
||||
virtual PolygonSink &operator<<(const LayerNameToken &) { return *this; };
|
||||
virtual PolygonSink &operator<<(GerberPolarityToken pol) = 0;
|
||||
virtual PolygonSink &operator<<(const ApertureToken &) { return *this; };
|
||||
virtual void footer() {}
|
||||
};
|
||||
|
||||
|
|
@ -229,6 +236,7 @@ namespace gerbolyze {
|
|||
virtual ~SimpleGerberOutput() {}
|
||||
virtual SimpleGerberOutput &operator<<(const Polygon &poly);
|
||||
virtual SimpleGerberOutput &operator<<(GerberPolarityToken pol);
|
||||
virtual SimpleGerberOutput &operator<<(const ApertureToken &ap);
|
||||
virtual void header_impl(d2p origin, d2p size);
|
||||
virtual void footer_impl();
|
||||
|
||||
|
|
@ -242,6 +250,8 @@ namespace gerbolyze {
|
|||
double m_scale;
|
||||
bool m_flip_pol;
|
||||
bool m_outline_mode;
|
||||
double m_current_aperture;
|
||||
unsigned int m_aperture_num;
|
||||
};
|
||||
|
||||
class SimpleSVGOutput : public StreamPolygonSink {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,9 @@ SimpleGerberOutput::SimpleGerberOutput(ostream &out, bool only_polys, int digits
|
|||
m_offset(offset),
|
||||
m_scale(scale),
|
||||
m_flip_pol(flip_polarity),
|
||||
m_outline_mode(outline_mode)
|
||||
m_outline_mode(outline_mode),
|
||||
m_current_aperture(0.0),
|
||||
m_aperture_num(10) /* See gerber standard */
|
||||
{
|
||||
assert(1 <= digits_int && digits_int <= 9);
|
||||
assert(0 <= digits_frac && digits_frac <= 9);
|
||||
|
|
@ -59,6 +61,20 @@ void SimpleGerberOutput::header_impl(d2p origin, d2p size) {
|
|||
m_out << "D10*" << endl;
|
||||
}
|
||||
|
||||
SimpleGerberOutput& SimpleGerberOutput::operator<<(const ApertureToken &ap) {
|
||||
if (ap.m_size == m_current_aperture) {
|
||||
return *this;
|
||||
}
|
||||
m_current_aperture = ap.m_size;
|
||||
m_aperture_num += 1;
|
||||
|
||||
double size = (ap.m_size > 0.0) ? ap.m_size : 0.05;
|
||||
m_out << "%ADD" << m_aperture_num << "C," << size << "*%" << endl;
|
||||
m_out << "D" << m_aperture_num << "*" << endl;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
SimpleGerberOutput& SimpleGerberOutput::operator<<(GerberPolarityToken pol) {
|
||||
assert(pol == GRB_POL_DARK || pol == GRB_POL_CLEAR);
|
||||
|
||||
|
|
|
|||
|
|
@ -226,6 +226,8 @@ void gerbolyze::SVGDocument::export_svg_path(xform2d &mat, const RenderSettings
|
|||
/* Load path from SVG path data and transform into document units. */
|
||||
xform2d local_xf(mat);
|
||||
local_xf.transform(xform2d(node.attribute("transform").value()));
|
||||
/* FIXME transform stroke width here? */
|
||||
stroke_width = local_xf.doc2phys_dist(stroke_width);
|
||||
|
||||
PolyTree ptree_stroke;
|
||||
PolyTree ptree_fill;
|
||||
|
|
@ -307,7 +309,7 @@ void gerbolyze::SVGDocument::export_svg_path(xform2d &mat, const RenderSettings
|
|||
if (rset.outline_mode) {
|
||||
/* In outline mode, manually close polys */
|
||||
poly.push_back(poly[0]);
|
||||
*polygon_sink << poly;
|
||||
*polygon_sink << ApertureToken() << poly;
|
||||
|
||||
} else {
|
||||
offx.AddPath(poly, join_type, etClosedLine);
|
||||
|
|
@ -320,7 +322,7 @@ void gerbolyze::SVGDocument::export_svg_path(xform2d &mat, const RenderSettings
|
|||
dash_path(poly_copy, out, dasharray);
|
||||
|
||||
if (rset.outline_mode) {
|
||||
*polygon_sink << out;
|
||||
*polygon_sink << ApertureToken(stroke_width) << out;
|
||||
} else {
|
||||
offx.AddPaths(out, join_type, end_type);
|
||||
}
|
||||
|
|
@ -332,7 +334,7 @@ void gerbolyze::SVGDocument::export_svg_path(xform2d &mat, const RenderSettings
|
|||
dash_path(poly, out, dasharray);
|
||||
|
||||
if (rset.outline_mode) {
|
||||
*polygon_sink << out;
|
||||
*polygon_sink << ApertureToken(stroke_width) << out;
|
||||
} else {
|
||||
offx.AddPaths(out, join_type, end_type);
|
||||
}
|
||||
|
|
@ -373,10 +375,11 @@ void gerbolyze::SVGDocument::export_svg_path(xform2d &mat, const RenderSettings
|
|||
Paths s_polys;
|
||||
dehole_polytree(ptree, s_polys);
|
||||
|
||||
*polygon_sink << (stroke_color == GRB_DARK ? GRB_POL_DARK : GRB_POL_CLEAR) << s_polys;
|
||||
*polygon_sink << ApertureToken() << (stroke_color == GRB_DARK ? GRB_POL_DARK : GRB_POL_CLEAR) << s_polys;
|
||||
}
|
||||
}
|
||||
}
|
||||
*polygon_sink << ApertureToken();
|
||||
}
|
||||
|
||||
void gerbolyze::SVGDocument::render(const RenderSettings &rset, PolygonSink &sink, const ElementSelector *sel) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue