DXF: export color and line width.

pull/4/head
EvilSpirit 2015-12-28 16:50:38 +06:00 committed by whitequark
parent 3fdfca10f6
commit e377eb8851
3 changed files with 53 additions and 8 deletions

View File

@ -451,6 +451,14 @@ public:
c.alpha == alpha; c.alpha == alpha;
} }
uint32_t ToPackedIntBGRA(void) const {
return
blue |
(uint32_t)(green << 8) |
(uint32_t)(red << 16) |
(uint32_t)((255 - alpha) << 24);
}
uint32_t ToPackedInt(void) const { uint32_t ToPackedInt(void) const {
return return
red | red |

View File

@ -16,23 +16,34 @@ void VectorFileWriter::Dummy(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Routines for DXF export // Routines for DXF export
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class DxfWriteInterface : public DRW_Interface { class DxfWriteInterface : public DRW_Interface {
DxfFileWriter *writer; DxfFileWriter *writer;
dxfRW *dxf; dxfRW *dxf;
int currentColor;
double currentWidth;
public: public:
DxfWriteInterface(DxfFileWriter *w, dxfRW *dxfrw) : DxfWriteInterface(DxfFileWriter *w, dxfRW *dxfrw) :
writer(w), dxf(dxfrw) {} writer(w), dxf(dxfrw) {}
virtual void writeEntities() { virtual void writeEntities() {
for(SBezier *sb : writer->beziers) { for(DxfFileWriter::BezierPath &path : writer->paths) {
writeBezier(sb); currentColor = path.color;
currentWidth = path.width;
for(SBezier *sb : path.beziers) {
writeBezier(sb);
}
} }
} }
void assignEntityDefaults(DRW_Entity *entity) {
entity->color24 = currentColor;
if(currentWidth > 0.0) entity->setWidthMm(currentWidth);
}
void writeLine(const Vector &p0, const Vector &p1) { void writeLine(const Vector &p0, const Vector &p1) {
DRW_Line line; DRW_Line line;
assignEntityDefaults(&line);
line.basePoint = DRW_Coord(p0.x, p0.y, 0.0); line.basePoint = DRW_Coord(p0.x, p0.y, 0.0);
line.secPoint = DRW_Coord(p1.x, p1.y, 0.0); line.secPoint = DRW_Coord(p1.x, p1.y, 0.0);
dxf->writeLine(&line); dxf->writeLine(&line);
@ -40,6 +51,7 @@ public:
void writeArc(const Vector &c, double r, double sa, double ea) { void writeArc(const Vector &c, double r, double sa, double ea) {
DRW_Arc arc; DRW_Arc arc;
assignEntityDefaults(&arc);
arc.radious = r; arc.radious = r;
arc.basePoint = DRW_Coord(c.x, c.y, 0.0); arc.basePoint = DRW_Coord(c.x, c.y, 0.0);
arc.staangle = sa; arc.staangle = sa;
@ -90,6 +102,7 @@ public:
void writeSpline(SBezier *sb) { void writeSpline(SBezier *sb) {
bool isRational = sb->IsRational(); bool isRational = sb->IsRational();
DRW_Spline spline; DRW_Spline spline;
assignEntityDefaults(&spline);
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;
@ -128,15 +141,32 @@ public:
writeSpline(sb); writeSpline(sb);
} }
} }
void writeBezierAsPwl(SBezier &sb) {
List<Vector> lv = {};
sb.MakePwlInto(&lv, SS.ChordTolMm() / SS.exportScale);
DRW_LWPolyline polyline;
assignEntityDefaults(&polyline);
for(int i = 0; i < lv.n; i++) {
DRW_Vertex2D *vertex = new DRW_Vertex2D();
vertex->x = lv.elem[i].x;
vertex->y = lv.elem[i].y;
polyline.vertlist.push_back(vertex);
}
}
}; };
void DxfFileWriter::StartFile(void) { void DxfFileWriter::StartFile(void) {
beziers.clear(); paths.clear();
} }
void DxfFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth, void DxfFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb) bool filled, RgbaColor fillRgb)
{ {
BezierPath path = {};
path.color = strokeRgb.ToPackedIntBGRA();
path.width = lineWidth;
paths.push_back(path);
} }
void DxfFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth, void DxfFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb) bool filled, RgbaColor fillRgb)
@ -147,14 +177,14 @@ void DxfFileWriter::Triangle(STriangle *tr) {
} }
void DxfFileWriter::Bezier(SBezier *sb) { void DxfFileWriter::Bezier(SBezier *sb) {
beziers.push_back(sb); paths.back().beziers.push_back(sb);
} }
void DxfFileWriter::FinishAndCloseFile(void) { void DxfFileWriter::FinishAndCloseFile(void) {
dxfRW dxf(filename.c_str()); dxfRW dxf(filename.c_str());
DxfWriteInterface interface(this, &dxf); DxfWriteInterface interface(this, &dxf);
dxf.write(&interface, DRW::AC1012, false); dxf.write(&interface, DRW::AC1018, false);
beziers.clear(); paths.clear();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -522,7 +522,14 @@ public:
}; };
class DxfFileWriter : public VectorFileWriter { class DxfFileWriter : public VectorFileWriter {
public: public:
std::vector<SBezier *> beziers; struct BezierPath {
std::vector<SBezier *> beziers;
int color;
double width;
};
std::vector<BezierPath> paths;
void StartPath( RgbaColor strokeRgb, double lineWidth, void StartPath( RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb); bool filled, RgbaColor fillRgb);
void FinishPath(RgbaColor strokeRgb, double lineWidth, void FinishPath(RgbaColor strokeRgb, double lineWidth,