Refactor export code to pass around hStyle, not uint32_t.

This commit is contained in:
whitequark 2016-04-12 23:57:49 +00:00
parent 27b403faf5
commit 11565e081d
3 changed files with 49 additions and 49 deletions

View File

@ -537,13 +537,13 @@ void VectorFileWriter::OutputLinesAndMesh(SBezierLoopSetSet *sblss, SMesh *sm) {
RgbaColor strokeRgb = Style::Color(hs, true); RgbaColor strokeRgb = Style::Color(hs, true);
RgbaColor fillRgb = Style::FillColor(hs, true); RgbaColor fillRgb = Style::FillColor(hs, true);
StartPath(strokeRgb, lineWidth, stl->filled, fillRgb, hs.v); StartPath(strokeRgb, lineWidth, stl->filled, fillRgb, hs);
for(sbl = sbls->l.First(); sbl; sbl = sbls->l.NextAfter(sbl)) { for(sbl = sbls->l.First(); sbl; sbl = sbls->l.NextAfter(sbl)) {
for(b = sbl->l.First(); b; b = sbl->l.NextAfter(b)) { for(b = sbl->l.First(); b; b = sbl->l.NextAfter(b)) {
Bezier(b); Bezier(b);
} }
} }
FinishPath(strokeRgb, lineWidth, stl->filled, fillRgb, hs.v); FinishPath(strokeRgb, lineWidth, stl->filled, fillRgb, hs);
} }
} }
FinishAndCloseFile(); FinishAndCloseFile();

View File

@ -241,8 +241,7 @@ public:
} }
} }
void assignEntityDefaults(DRW_Entity *entity, uint32_t style) { void assignEntityDefaults(DRW_Entity *entity, hStyle hs) {
hStyle hs = { style };
Style *s = Style::Get(hs); Style *s = Style::Get(hs);
entity->color24 = s->Color(hs, true).ToPackedIntBGRA(); entity->color24 = s->Color(hs, true).ToPackedIntBGRA();
entity->layer = s->DescriptionString(); entity->layer = s->DescriptionString();
@ -255,17 +254,17 @@ public:
dimension->layer = "dimensions"; dimension->layer = "dimensions";
} }
void writeLine(const Vector &p0, const Vector &p1, uint32_t style) { void writeLine(const Vector &p0, const Vector &p1, hStyle hs) {
DRW_Line line; DRW_Line line;
assignEntityDefaults(&line, style); assignEntityDefaults(&line, hs);
line.basePoint = toCoord(p0); line.basePoint = toCoord(p0);
line.secPoint = toCoord(p1); line.secPoint = toCoord(p1);
dxf->writeLine(&line); dxf->writeLine(&line);
} }
void writeArc(const Vector &c, double r, double sa, double ea, uint32_t style) { void writeArc(const Vector &c, double r, double sa, double ea, hStyle hs) {
DRW_Arc arc; DRW_Arc arc;
assignEntityDefaults(&arc, style); assignEntityDefaults(&arc, hs);
arc.radious = r; arc.radious = r;
arc.basePoint = toCoord(c); arc.basePoint = toCoord(c);
arc.staangle = sa; arc.staangle = sa;
@ -276,8 +275,9 @@ public:
void writeBezierAsPwl(SBezier *sb) { void writeBezierAsPwl(SBezier *sb) {
List<Vector> lv = {}; List<Vector> lv = {};
sb->MakePwlInto(&lv, SS.ExportChordTolMm()); sb->MakePwlInto(&lv, SS.ExportChordTolMm());
hStyle hs = { (uint32_t)sb->auxA };
DRW_LWPolyline polyline; DRW_LWPolyline polyline;
assignEntityDefaults(&polyline, sb->auxA); assignEntityDefaults(&polyline, hs);
for(int i = 0; i < lv.n; i++) { for(int i = 0; i < lv.n; i++) {
Vector *v = &lv.elem[i]; Vector *v = &lv.elem[i];
DRW_Vertex2D *vertex = new DRW_Vertex2D(); DRW_Vertex2D *vertex = new DRW_Vertex2D();
@ -316,8 +316,9 @@ public:
void writeSpline(SBezier *sb) { void writeSpline(SBezier *sb) {
bool isRational = sb->IsRational(); bool isRational = sb->IsRational();
hStyle hs = { (uint32_t)sb->auxA };
DRW_Spline spline; DRW_Spline spline;
assignEntityDefaults(&spline, sb->auxA); assignEntityDefaults(&spline, hs);
spline.flags = (isRational) ? 0x04 : 0x08; spline.flags = (isRational) ? 0x04 : 0x08;
spline.degree = sb->deg; spline.degree = sb->deg;
spline.ncontrol = sb->deg + 1; spline.ncontrol = sb->deg + 1;
@ -330,13 +331,14 @@ public:
} }
void writeBezier(SBezier *sb) { void writeBezier(SBezier *sb) {
hStyle hs = { (uint32_t)sb->auxA };
Vector c; Vector c;
Vector n = Vector::From(0.0, 0.0, 1.0); Vector n = Vector::From(0.0, 0.0, 1.0);
double r; double r;
if(sb->deg == 1) { if(sb->deg == 1) {
// Line // Line
writeLine(sb->ctrl[0], sb->ctrl[1], sb->auxA); writeLine(sb->ctrl[0], sb->ctrl[1], hs);
} else if(sb->IsInPlane(n, 0) && sb->IsCircle(n, &c, &r)) { } else if(sb->IsInPlane(n, 0) && sb->IsCircle(n, &c, &r)) {
// Circle perpendicular to camera // Circle perpendicular to camera
double theta0 = atan2(sb->ctrl[0].y - c.y, sb->ctrl[0].x - c.x); double theta0 = atan2(sb->ctrl[0].y - c.y, sb->ctrl[0].x - c.x);
@ -344,7 +346,7 @@ public:
double dtheta = WRAP_SYMMETRIC(theta1 - theta0, 2.0 * PI); double dtheta = WRAP_SYMMETRIC(theta1 - theta0, 2.0 * PI);
if(dtheta < 0.0) swap(theta0, theta1); if(dtheta < 0.0) swap(theta0, theta1);
writeArc(c, r, theta0, theta1, sb->auxA); writeArc(c, r, theta0, theta1, hs);
} else if(sb->IsRational()) { } else if(sb->IsRational()) {
// Rational bezier // Rational bezier
// We'd like to export rational beziers exactly, but the resulting DXF // We'd like to export rational beziers exactly, but the resulting DXF
@ -456,13 +458,13 @@ void DxfFileWriter::StartFile(void) {
} }
void DxfFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth, void DxfFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style) bool filled, RgbaColor fillRgb, hStyle hs)
{ {
BezierPath path = {}; BezierPath path = {};
paths.push_back(path); paths.push_back(path);
} }
void DxfFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth, void DxfFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style) bool filled, RgbaColor fillRgb, hStyle hs)
{ {
} }
@ -558,15 +560,14 @@ void EpsFileWriter::StartFile(void) {
} }
void EpsFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth, void EpsFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style) bool filled, RgbaColor fillRgb, hStyle hs)
{ {
fprintf(f, "newpath\r\n"); fprintf(f, "newpath\r\n");
prevPt = Vector::From(VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE); prevPt = Vector::From(VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE);
} }
void EpsFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth, void EpsFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style) bool filled, RgbaColor fillRgb, hStyle hs)
{ {
hStyle hs = { style };
int pattern = Style::PatternType(hs); int pattern = Style::PatternType(hs);
double stippleScale = MmToPts(Style::StippleScaleMm(hs)); double stippleScale = MmToPts(Style::StippleScaleMm(hs));
@ -790,9 +791,8 @@ void PdfFileWriter::FinishAndCloseFile(void) {
} }
void PdfFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth, void PdfFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style) bool filled, RgbaColor fillRgb, hStyle hs)
{ {
hStyle hs = { style };
int pattern = Style::PatternType(hs); int pattern = Style::PatternType(hs);
double stippleScale = MmToPts(Style::StippleScaleMm(hs)); double stippleScale = MmToPts(Style::StippleScaleMm(hs));
@ -810,7 +810,7 @@ void PdfFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
prevPt = Vector::From(VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE); prevPt = Vector::From(VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE);
} }
void PdfFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth, void PdfFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style) bool filled, RgbaColor fillRgb, hStyle hs)
{ {
if(filled) { if(filled) {
fprintf(f, "b\r\n"); fprintf(f, "b\r\n");
@ -915,20 +915,20 @@ void SvgFileWriter::StartFile(void) {
} }
void SvgFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth, void SvgFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style) bool filled, RgbaColor fillRgb, hStyle hs)
{ {
fprintf(f, "<path d='"); fprintf(f, "<path d='");
prevPt = Vector::From(VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE); prevPt = Vector::From(VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE);
} }
void SvgFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth, void SvgFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style) bool filled, RgbaColor fillRgb, hStyle hs)
{ {
std::string fill; std::string fill;
if(filled) { if(filled) {
fill = ssprintf("fill='#%02x%02x%02x'", fill = ssprintf("fill='#%02x%02x%02x'",
fillRgb.red, fillRgb.green, fillRgb.blue); fillRgb.red, fillRgb.green, fillRgb.blue);
} }
std::string cls = ssprintf("s%x", style); std::string cls = ssprintf("s%x", hs.v);
fprintf(f, "' class='%s' %s/>\r\n", cls.c_str(), fill.c_str()); fprintf(f, "' class='%s' %s/>\r\n", cls.c_str(), fill.c_str());
} }
@ -1010,11 +1010,11 @@ void HpglFileWriter::StartFile(void) {
} }
void HpglFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth, void HpglFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style) bool filled, RgbaColor fillRgb, hStyle hs)
{ {
} }
void HpglFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth, void HpglFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style) bool filled, RgbaColor fillRgb, hStyle hs)
{ {
} }
@ -1047,11 +1047,11 @@ void GCodeFileWriter::StartFile(void) {
sel = {}; sel = {};
} }
void GCodeFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth, void GCodeFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style) bool filled, RgbaColor fillRgb, hStyle hs)
{ {
} }
void GCodeFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth, void GCodeFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style) bool filled, RgbaColor fillRgb, hStyle hs)
{ {
} }
void GCodeFileWriter::Triangle(STriangle *tr) { void GCodeFileWriter::Triangle(STriangle *tr) {
@ -1115,11 +1115,11 @@ void Step2dFileWriter::Triangle(STriangle *tr) {
} }
void Step2dFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth, void Step2dFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style) bool filled, RgbaColor fillRgb, hStyle hs)
{ {
} }
void Step2dFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth, void Step2dFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style) bool filled, RgbaColor fillRgb, hStyle hs)
{ {
} }

View File

@ -522,9 +522,9 @@ public:
{ return false; } { return false; }
virtual void StartPath( RgbaColor strokeRgb, double lineWidth, virtual void StartPath( RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style) = 0; bool filled, RgbaColor fillRgb, hStyle hs) = 0;
virtual void FinishPath(RgbaColor strokeRgb, double lineWidth, virtual void FinishPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style) = 0; bool filled, RgbaColor fillRgb, hStyle hs) = 0;
virtual void Bezier(SBezier *sb) = 0; virtual void Bezier(SBezier *sb) = 0;
virtual void Triangle(STriangle *tr) = 0; virtual void Triangle(STriangle *tr) = 0;
virtual void StartFile(void) = 0; virtual void StartFile(void) = 0;
@ -543,9 +543,9 @@ public:
bool OutputConstraints(IdList<Constraint,hConstraint> *constraint); bool OutputConstraints(IdList<Constraint,hConstraint> *constraint);
void StartPath( RgbaColor strokeRgb, double lineWidth, void StartPath( RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style); bool filled, RgbaColor fillRgb, hStyle hs);
void FinishPath(RgbaColor strokeRgb, double lineWidth, void FinishPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style); bool filled, RgbaColor fillRgb, hStyle hs);
void Triangle(STriangle *tr); void Triangle(STriangle *tr);
void Bezier(SBezier *sb); void Bezier(SBezier *sb);
void StartFile(void); void StartFile(void);
@ -559,9 +559,9 @@ public:
void MaybeMoveTo(Vector s, Vector f); void MaybeMoveTo(Vector s, Vector f);
void StartPath( RgbaColor strokeRgb, double lineWidth, void StartPath( RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style); bool filled, RgbaColor fillRgb, hStyle hs);
void FinishPath(RgbaColor strokeRgb, double lineWidth, void FinishPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style); bool filled, RgbaColor fillRgb, hStyle hs);
void Triangle(STriangle *tr); void Triangle(STriangle *tr);
void Bezier(SBezier *sb); void Bezier(SBezier *sb);
void StartFile(void); void StartFile(void);
@ -576,9 +576,9 @@ public:
void MaybeMoveTo(Vector s, Vector f); void MaybeMoveTo(Vector s, Vector f);
void StartPath( RgbaColor strokeRgb, double lineWidth, void StartPath( RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style); bool filled, RgbaColor fillRgb, hStyle hs);
void FinishPath(RgbaColor strokeRgb, double lineWidth, void FinishPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style); bool filled, RgbaColor fillRgb, hStyle hs);
void Triangle(STriangle *tr); void Triangle(STriangle *tr);
void Bezier(SBezier *sb); void Bezier(SBezier *sb);
void StartFile(void); void StartFile(void);
@ -591,9 +591,9 @@ public:
void MaybeMoveTo(Vector s, Vector f); void MaybeMoveTo(Vector s, Vector f);
void StartPath( RgbaColor strokeRgb, double lineWidth, void StartPath( RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style); bool filled, RgbaColor fillRgb, hStyle hs);
void FinishPath(RgbaColor strokeRgb, double lineWidth, void FinishPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style); bool filled, RgbaColor fillRgb, hStyle hs);
void Triangle(STriangle *tr); void Triangle(STriangle *tr);
void Bezier(SBezier *sb); void Bezier(SBezier *sb);
void StartFile(void); void StartFile(void);
@ -604,9 +604,9 @@ class HpglFileWriter : public VectorFileWriter {
public: public:
static double MmToHpglUnits(double mm); static double MmToHpglUnits(double mm);
void StartPath( RgbaColor strokeRgb, double lineWidth, void StartPath( RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style); bool filled, RgbaColor fillRgb, hStyle hs);
void FinishPath(RgbaColor strokeRgb, double lineWidth, void FinishPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style); bool filled, RgbaColor fillRgb, hStyle hs);
void Triangle(STriangle *tr); void Triangle(STriangle *tr);
void Bezier(SBezier *sb); void Bezier(SBezier *sb);
void StartFile(void); void StartFile(void);
@ -616,9 +616,9 @@ public:
class Step2dFileWriter : public VectorFileWriter { class Step2dFileWriter : public VectorFileWriter {
StepFileWriter sfw; StepFileWriter sfw;
void StartPath( RgbaColor strokeRgb, double lineWidth, void StartPath( RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style); bool filled, RgbaColor fillRgb, hStyle hs);
void FinishPath(RgbaColor strokeRgb, double lineWidth, void FinishPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style); bool filled, RgbaColor fillRgb, hStyle hs);
void Triangle(STriangle *tr); void Triangle(STriangle *tr);
void Bezier(SBezier *sb); void Bezier(SBezier *sb);
void StartFile(void); void StartFile(void);
@ -629,9 +629,9 @@ class GCodeFileWriter : public VectorFileWriter {
public: public:
SEdgeList sel; SEdgeList sel;
void StartPath( RgbaColor strokeRgb, double lineWidth, void StartPath( RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style); bool filled, RgbaColor fillRgb, hStyle hs);
void FinishPath(RgbaColor strokeRgb, double lineWidth, void FinishPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb, uint32_t style); bool filled, RgbaColor fillRgb, hStyle hs);
void Triangle(STriangle *tr); void Triangle(STriangle *tr);
void Bezier(SBezier *sb); void Bezier(SBezier *sb);
void StartFile(void); void StartFile(void);