Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dxf/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace DXF {
virtual ~Entity() {}

virtual type_t getType() const = 0;
virtual void addVertex(const cb::Vector3D &v) {THROW("Cannot add vertex");}
virtual void addVertex(const cb::Vector3D &v, double weight = 0.0) {THROW("Cannot add vertex");}
virtual void addKnot(double k) {THROW("Cannot add knot");}
};
}
16 changes: 14 additions & 2 deletions src/dxf/PolyLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,27 @@

namespace DXF {
class PolyLine : public Entity {
/* Polyline flag (bit-coded; default = 0):
* 1 = This is a closed polyline (or a polygon mesh closed in the M direction)
* 2 = Curve-fit vertices have been added
* 4 = Spline-fit vertices have been added
* 8 = This is a 3D polyline
* 16 = This is a 3D polygon mesh
* 32 = The polygon mesh is closed in the N direction
* 64 = The polyline is a polyface mesh
* 128 = The linetype pattern is generated continuously around the vertices of this polyline
*/
unsigned flags;
std::vector<cb::Vector3D> vertices;

public:
PolyLine() {}
PolyLine(unsigned flags) : flags(flags) {}

const std::vector<cb::Vector3D> &getVertices() const {return vertices;}

// From Entity
void addVertex(const cb::Vector3D &v) {vertices.push_back(v);}
void addVertex(const cb::Vector3D &v, double weight = 0.0) {vertices.push_back(v);}
unsigned getFlags() const {return flags;}
type_t getType() const {return DXF_POLYLINE;}
};
}
6 changes: 3 additions & 3 deletions src/dxf/Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void Reader::addCircle(const DL_CircleData &circle) {

void Reader::addPolyline(const DL_PolylineData &polyline) {
if (!entity.isNull()) THROW("DXF Already in DXF entity");
addEntity(entity = new PolyLine);
addEntity(entity = new PolyLine(polyline.flags));
}


Expand All @@ -97,12 +97,12 @@ void Reader::addVertex(const DL_VertexData &vertex) {

void Reader::addSpline(const DL_SplineData &spline) {
if (!entity.isNull()) THROW("DXF Already in DXF entity");
addEntity(entity = new Spline(spline.degree));
addEntity(entity = new Spline(spline.degree, spline.flags));
}


void Reader::addControlPoint(const DL_ControlPointData &ctrlPt) {
entity->addVertex(cb::Vector3D(ctrlPt.x, ctrlPt.y, ctrlPt.z));
entity->addVertex(cb::Vector3D(ctrlPt.x, ctrlPt.y, ctrlPt.z), ctrlPt.w);
}


Expand Down
15 changes: 13 additions & 2 deletions src/dxf/Spline.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,30 @@
namespace DXF {
class Spline : public Entity {
unsigned degree;
/* Spline flag (bit coded):
* 1 = Closed spline
* 2 = Periodic spline
* 4 = Rational spline
* 8 = Planar
* 16 = Linear (planar bit is also set)
*/
unsigned flags;
std::vector<cb::Vector3D> ctrlPts;
std::vector<double> weights;
std::vector<double> knots;

public:
Spline(unsigned degree) : degree(degree) {}
Spline(unsigned degree, unsigned flags) : degree(degree), flags(flags) {}

unsigned getDegree() const {return degree;}
unsigned getFlags() const {return flags;}
const std::vector<cb::Vector3D> &getControlPoints() const {return ctrlPts;}
const std::vector<double> &getWeights() const {return weights;}
const std::vector<double> &getKnots() const {return knots;}

// From Entity
void addKnot(double k) {knots.push_back(k);}
void addVertex(const cb::Vector3D &v) {ctrlPts.push_back(v);}
void addVertex(const cb::Vector3D &v, double weight = 1.0) {ctrlPts.push_back(v); weights.push_back(weight);}
type_t getType() const {return DXF_SPLINE;}
};
}
9 changes: 9 additions & 0 deletions src/tplang/DXFModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ void DXFModule::openCB(const js::Value &args, js::Sink &sink) {
case DXF::Entity::DXF_POLYLINE: {
const DXF::PolyLine &polyLine =
dynamic_cast<const DXF::PolyLine &>(entity);
/* TODO: expose other flags. */
sink.insertBoolean("isClosed", (polyLine.getFlags()&(1<<0))!=0 );
const vector<Vector3D> &vertices = polyLine.getVertices();
sink.insertList("vertices");

Expand All @@ -130,16 +132,23 @@ void DXFModule::openCB(const js::Value &args, js::Sink &sink) {
const DXF::Spline &spline = dynamic_cast<const DXF::Spline &>(entity);

sink.insert("degree", spline.getDegree());
sink.insertBoolean("isClosed", (spline.getFlags()&(1<<0))!=0 );
sink.insertBoolean("isPeriodical", (spline.getFlags()&(1<<1))!=0 );
sink.insertBoolean("isRational", (spline.getFlags()&(1<<2))!=0 );
sink.insertBoolean("isPlanar", (spline.getFlags()&(1<<3))!=0 );
sink.insertBoolean("isLinear", (spline.getFlags()&(1<<4))!=0 );

// Control points
const vector<Vector3D> &ctrlPts = spline.getControlPoints();
const std::vector<double> &weights = spline.getWeights();
sink.insertList("ctrlPts");

for (unsigned k = 0; k < ctrlPts.size(); k++) {
sink.appendDict();
sink.insert("x", ctrlPts[k].x());
sink.insert("y", ctrlPts[k].y());
sink.insert("z", ctrlPts[k].z());
sink.insert("w", weights[k]);
sink.insert("type", DXF::Entity::DXF_POINT);
sink.endDict();
}
Expand Down
Loading