diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cgaladv.cc | 22 | ||||
-rw-r--r-- | src/csgnode.h | 1 | ||||
-rw-r--r-- | src/csgops.cc | 13 | ||||
-rw-r--r-- | src/dxflinextrude.cc | 2 | ||||
-rw-r--r-- | src/dxflinextrudenode.h | 1 | ||||
-rw-r--r-- | src/dxfrotextrude.cc | 2 | ||||
-rw-r--r-- | src/dxfrotextrudenode.h | 1 | ||||
-rw-r--r-- | src/import.cc | 24 | ||||
-rw-r--r-- | src/importnode.h | 1 | ||||
-rw-r--r-- | src/node.cc | 18 | ||||
-rw-r--r-- | src/node.h | 5 | ||||
-rw-r--r-- | src/primitives.cc | 198 | ||||
-rw-r--r-- | src/projectionnode.h | 1 | ||||
-rw-r--r-- | src/render.cc | 2 | ||||
-rw-r--r-- | src/rendernode.h | 1 | ||||
-rw-r--r-- | src/surface.cc | 3 | ||||
-rw-r--r-- | src/transform.cc | 44 | ||||
-rw-r--r-- | src/transformnode.h | 1 |
18 files changed, 219 insertions, 121 deletions
diff --git a/src/cgaladv.cc b/src/cgaladv.cc index 0b38bc0..d71e5b0 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -63,6 +63,21 @@ public: return visitor.visit(state, *this); } virtual std::string toString() const; + virtual std::string name() const { + switch (this->type) { + case MINKOWSKI: + return "minkowski"; + break; + case GLIDE: + return "glide"; + break; + case SUBDIV: + return "subdiv"; + break; + default: + assert(false); + } + } Value path; QString subdiv_type; @@ -134,15 +149,16 @@ std::string CgaladvNode::toString() const { std::stringstream stream; + stream << this->name(); switch (type) { case MINKOWSKI: - stream << "minkowski(convexity = " << this->convexity << ")"; + stream << "(convexity = " << this->convexity << ")"; break; case GLIDE: - stream << "glide(path = " << this->path.dump() << ", convexity = " << this->convexity << ")"; + stream << "(path = " << this->path.dump() << ", convexity = " << this->convexity << ")"; break; case SUBDIV: - stream << "subdiv(level = " << this->level << ", convexity = " << this->convexity << ")"; + stream << "(level = " << this->level << ", convexity = " << this->convexity << ")"; break; default: assert(false); diff --git a/src/csgnode.h b/src/csgnode.h index d5ebfc2..2e1d9fb 100644 --- a/src/csgnode.h +++ b/src/csgnode.h @@ -19,6 +19,7 @@ public: return visitor.visit(state, *this); } virtual std::string toString() const; + virtual std::string name() const; }; #endif diff --git a/src/csgops.cc b/src/csgops.cc index bddb5a0..c7251f8 100644 --- a/src/csgops.cc +++ b/src/csgops.cc @@ -53,23 +53,24 @@ AbstractNode *CsgModule::evaluate(const Context*, const ModuleInstantiation *ins std::string CsgNode::toString() const { - std::stringstream stream; + return this->name() + "()"; +} +std::string CsgNode::name() const +{ switch (this->type) { case CSG_TYPE_UNION: - stream << "union()"; + return "union"; break; case CSG_TYPE_DIFFERENCE: - stream << "difference()"; + return "difference"; break; case CSG_TYPE_INTERSECTION: - stream << "intersection()"; + return "intersection"; break; default: assert(false); } - - return stream.str(); } void register_builtin_csgops() diff --git a/src/dxflinextrude.cc b/src/dxflinextrude.cc index 3c8d7ac..d11a875 100644 --- a/src/dxflinextrude.cc +++ b/src/dxflinextrude.cc @@ -154,7 +154,7 @@ std::string DxfLinearExtrudeNode::toString() const memset(&st, 0, sizeof(struct stat)); stat(this->filename.toAscii().data(), &st); - stream << "linear_extrude(" + stream << this->name() << "(" "file = \"" << this->filename << "\", " "cache = \"" << std::hex << (int)st.st_mtime << "." << (int)st.st_size << "\", " "layer = \"" << this->layername << "\", " diff --git a/src/dxflinextrudenode.h b/src/dxflinextrudenode.h index f333491..564ee55 100644 --- a/src/dxflinextrudenode.h +++ b/src/dxflinextrudenode.h @@ -17,6 +17,7 @@ public: return visitor.visit(state, *this); } virtual std::string toString() const; + virtual std::string name() const { return "linear_extrude"; } int convexity, slices; double fn, fs, fa, height, twist; diff --git a/src/dxfrotextrude.cc b/src/dxfrotextrude.cc index 36e6cdf..67a1c8c 100644 --- a/src/dxfrotextrude.cc +++ b/src/dxfrotextrude.cc @@ -128,7 +128,7 @@ std::string DxfRotateExtrudeNode::toString() const struct stat st; memset(&st, 0, sizeof(struct stat)); stat(filename.toAscii().data(), &st); - stream << "rotate_extrude(" + stream << this->name() << "(" "file = \"" << this->filename << "\", " "cache = \"" << std::hex << (int)st.st_mtime << "." << (int)st.st_size << "\", " "layer = \"" << this->layername << "\", " diff --git a/src/dxfrotextrudenode.h b/src/dxfrotextrudenode.h index 5c2ef2b..dbf33a6 100644 --- a/src/dxfrotextrudenode.h +++ b/src/dxfrotextrudenode.h @@ -16,6 +16,7 @@ public: return visitor.visit(state, *this); } virtual std::string toString() const; + virtual std::string name() const { return "rotate_extrude"; } int convexity; double fn, fs, fa; diff --git a/src/import.cc b/src/import.cc index b7e3d7c..f70930e 100644 --- a/src/import.cc +++ b/src/import.cc @@ -198,19 +198,20 @@ std::string ImportNode::toString() const memset(&st, 0, sizeof(struct stat)); stat(this->filename.toAscii().data(), &st); + stream << this->name(); switch (this->type) { case TYPE_STL: - stream << "import_stl(file = \"" << this->filename << "\", " + stream << "(file = \"" << this->filename << "\", " "cache = \"" << std::hex << (int)st.st_mtime << "." << (int)st.st_size << "\", " "convexity = " << std::dec << this->convexity << ")"; break; case TYPE_OFF: - stream << "import_off(file = \"" << this->filename << "\", " + stream << "(file = \"" << this->filename << "\", " "cache = \"" << std::hex << (int)st.st_mtime << "." << (int)st.st_size << "\", " "convexity = " << std::dec << this->convexity << ")"; break; case TYPE_DXF: - stream << "import_dxf(file = \"" << this->filename << "\", " + stream << "(file = \"" << this->filename << "\", " "cache = \"" << std::hex << (int)st.st_mtime << "." << (int)st.st_size << "\", " "layer = \"" << this->layername << "\", " "origin = [ " << std::dec << this->origin_x << " " << this->origin_y << " ], " @@ -224,3 +225,20 @@ std::string ImportNode::toString() const return stream.str(); } + +std::string ImportNode::name() const +{ + switch (this->type) { + case TYPE_STL: + return "import_stl"; + break; + case TYPE_OFF: + return "import_off"; + break; + case TYPE_DXF: + return "import_dxf"; + break; + default: + assert(false); + } +} diff --git a/src/importnode.h b/src/importnode.h index 111b854..b45ce22 100644 --- a/src/importnode.h +++ b/src/importnode.h @@ -18,6 +18,7 @@ public: return visitor.visit(state, *this); } virtual std::string toString() const; + virtual std::string name() const; import_type_e type; QString filename; diff --git a/src/node.cc b/src/node.cc index 96a24ba..9607b27 100644 --- a/src/node.cc +++ b/src/node.cc @@ -66,16 +66,22 @@ Response AbstractPolyNode::accept(class State &state, Visitor &visitor) const std::string AbstractNode::toString() const { - std::stringstream stream; - stream << "group()"; - return stream.str(); + return this->name() + "()"; +} + +std::string AbstractNode::name() const +{ + return "group"; } std::string AbstractIntersectionNode::toString() const { - std::stringstream stream; - stream << "intersection()"; - return stream.str(); + return this->name() + "()"; +} + +std::string AbstractIntersectionNode::name() const +{ + return "intersection_for"; } void AbstractNode::progress_prepare() @@ -29,6 +29,10 @@ public: virtual ~AbstractNode(); virtual Response accept(class State &state, class Visitor &visitor) const; virtual std::string toString() const; + /*! The 'OpenSCAD name' of this node, defaults to classname, but can be + overloaded to provide specialization for e.g. CSG nodes, primitive nodes etc. + Used for human-readable output. */ + virtual std::string name() const; // FIXME: Make return value a reference const std::list<AbstractNode*> getChildren() const { @@ -64,6 +68,7 @@ public: virtual ~AbstractIntersectionNode() { }; virtual Response accept(class State &state, class Visitor &visitor) const; virtual std::string toString() const; + virtual std::string name() const; }; class AbstractPolyNode : public AbstractNode diff --git a/src/primitives.cc b/src/primitives.cc index 7efe679..301df24 100644 --- a/src/primitives.cc +++ b/src/primitives.cc @@ -62,6 +62,34 @@ public: return visitor.visit(state, *this); } virtual std::string toString() const; + virtual std::string name() const { + switch (this->type) { + case CUBE: + return "cube"; + break; + case SPHERE: + return "sphere"; + break; + case CYLINDER: + return "cylinder"; + break; + case POLYHEDRON: + return "polyhedron"; + break; + case SQUARE: + return "square"; + break; + case CIRCLE: + return "circle"; + break; + case POLYGON: + return "polygon"; + break; + default: + assert(false && "PrimitiveNode::name(): Unknown primitive type"); + return AbstractPolyNode::name(); + } + } bool center; double x, y, z, h, r1, r2; @@ -74,7 +102,7 @@ public: AbstractNode *PrimitiveModule::evaluate(const Context *ctx, const ModuleInstantiation *inst) const { - PrimitiveNode *node = new PrimitiveNode(inst, type); + PrimitiveNode *node = new PrimitiveNode(inst, this->type); node->center = false; node->x = node->y = node->z = node->h = node->r1 = node->r2 = 1; @@ -82,26 +110,30 @@ AbstractNode *PrimitiveModule::evaluate(const Context *ctx, const ModuleInstanti QVector<QString> argnames; QVector<Expression*> argexpr; - if (type == CUBE) { + switch (this->type) { + case CUBE: argnames = QVector<QString>() << "size" << "center"; - } - if (type == SPHERE) { + break; + case SPHERE: argnames = QVector<QString>() << "r"; - } - if (type == CYLINDER) { + break; + case CYLINDER: argnames = QVector<QString>() << "h" << "r1" << "r2" << "center"; - } - if (type == POLYHEDRON) { + break; + case POLYHEDRON: argnames = QVector<QString>() << "points" << "triangles" << "convexity"; - } - if (type == SQUARE) { + break; + case SQUARE: argnames = QVector<QString>() << "size" << "center"; - } - if (type == CIRCLE) { + break; + case CIRCLE: argnames = QVector<QString>() << "r"; - } - if (type == POLYGON) { + break; + case POLYGON: argnames = QVector<QString>() << "points" << "paths" << "convexity"; + break; + default: + assert(false && "PrimitiveModule::evaluate(): Unknown node type"); } Context c(ctx); @@ -218,21 +250,21 @@ PolySet *PrimitiveNode::render_polyset(render_mode_e) const { PolySet *p = new PolySet(); - if (type == CUBE && x > 0 && y > 0 && z > 0) + if (this->type == CUBE && this->x > 0 && this->y > 0 && this->z > 0) { double x1, x2, y1, y2, z1, z2; - if (center) { - x1 = -x/2; - x2 = +x/2; - y1 = -y/2; - y2 = +y/2; - z1 = -z/2; - z2 = +z/2; + if (this->center) { + x1 = -this->x/2; + x2 = +this->x/2; + y1 = -this->y/2; + y2 = +this->y/2; + z1 = -this->z/2; + z2 = +this->z/2; } else { x1 = y1 = z1 = 0; - x2 = x; - y2 = y; - z2 = z; + x2 = this->x; + y2 = this->y; + z2 = this->z; } p->append_poly(); // top @@ -272,7 +304,7 @@ PolySet *PrimitiveNode::render_polyset(render_mode_e) const p->append_vertex(x1, y2, z2); } - if (type == SPHERE && r1 > 0) + if (this->type == SPHERE && this->r1 > 0) { struct point2d { double x, y; @@ -284,14 +316,14 @@ PolySet *PrimitiveNode::render_polyset(render_mode_e) const double r, z; }; - int rings = get_fragments_from_r(r1, fn, fs, fa); + int rings = get_fragments_from_r(this->r1, this->fn, this->fs, this->fa); ring_s ring[rings]; for (int i = 0; i < rings; i++) { double phi = (M_PI * (i + 0.5)) / rings; - ring[i].r = r1 * sin(phi); - ring[i].z = r1 * cos(phi); - ring[i].fragments = get_fragments_from_r(ring[i].r, fn, fs, fa); + ring[i].r = this->r1 * sin(phi); + ring[i].z = this->r1 * cos(phi); + ring[i].fragments = get_fragments_from_r(ring[i].r, this->fn, this->fs, this->fa); ring[i].points = new point2d[ring[i].fragments]; for (int j = 0; j < ring[i].fragments; j++) { phi = (M_PI*2*j) / ring[i].fragments; @@ -314,8 +346,7 @@ PolySet *PrimitiveNode::render_polyset(render_mode_e) const goto sphere_next_r2; if (r2i >= r2->fragments) goto sphere_next_r1; - if ((double)r1i / r1->fragments < - (double)r2i / r2->fragments) + if ((double)r1i / r1->fragments < (double)r2i / r2->fragments) { sphere_next_r1: p->append_poly(); @@ -341,17 +372,18 @@ sphere_next_r2: p->insert_vertex(ring[rings-1].points[i].x, ring[rings-1].points[i].y, ring[rings-1].z); } - if (type == CYLINDER && h > 0 && r1 >=0 && r2 >= 0 && (r1 > 0 || r2 > 0)) + if (this->type == CYLINDER && + this->h > 0 && this->r1 >=0 && this->r2 >= 0 && (this->r1 > 0 || this->r2 > 0)) { - int fragments = get_fragments_from_r(fmax(r1, r2), fn, fs, fa); + int fragments = get_fragments_from_r(fmax(this->r1, this->r2), this->fn, this->fs, this->fa); double z1, z2; - if (center) { - z1 = -h/2; - z2 = +h/2; + if (this->center) { + z1 = -this->h/2; + z2 = +this->h/2; } else { z1 = 0; - z2 = h; + z2 = this->h; } struct point2d { @@ -363,16 +395,16 @@ sphere_next_r2: for (int i=0; i<fragments; i++) { double phi = (M_PI*2*i) / fragments; - if (r1 > 0) { - circle1[i].x = r1*cos(phi); - circle1[i].y = r1*sin(phi); + if (this->r1 > 0) { + circle1[i].x = this->r1*cos(phi); + circle1[i].y = this->r1*sin(phi); } else { circle1[i].x = 0; circle1[i].y = 0; } - if (r2 > 0) { - circle2[i].x = r2*cos(phi); - circle2[i].y = r2*sin(phi); + if (this->r2 > 0) { + circle2[i].x = this->r2*cos(phi); + circle2[i].y = this->r2*sin(phi); } else { circle2[i].x = 0; circle2[i].y = 0; @@ -381,13 +413,13 @@ sphere_next_r2: for (int i=0; i<fragments; i++) { int j = (i+1) % fragments; - if (r1 > 0) { + if (this->r1 > 0) { p->append_poly(); p->insert_vertex(circle1[i].x, circle1[i].y, z1); p->insert_vertex(circle2[i].x, circle2[i].y, z2); p->insert_vertex(circle1[j].x, circle1[j].y, z1); } - if (r2 > 0) { + if (this->r2 > 0) { p->append_poly(); p->insert_vertex(circle2[i].x, circle2[i].y, z2); p->insert_vertex(circle2[j].x, circle2[j].y, z2); @@ -395,48 +427,48 @@ sphere_next_r2: } } - if (r1 > 0) { + if (this->r1 > 0) { p->append_poly(); for (int i=0; i<fragments; i++) p->insert_vertex(circle1[i].x, circle1[i].y, z1); } - if (r2 > 0) { + if (this->r2 > 0) { p->append_poly(); for (int i=0; i<fragments; i++) p->append_vertex(circle2[i].x, circle2[i].y, z2); } } - if (type == POLYHEDRON) + if (this->type == POLYHEDRON) { - p->convexity = convexity; - for (int i=0; i<triangles.vec.size(); i++) + p->convexity = this->convexity; + for (int i=0; i<this->triangles.vec.size(); i++) { p->append_poly(); - for (int j=0; j<triangles.vec[i]->vec.size(); j++) { - int pt = triangles.vec[i]->vec[j]->num; - if (pt < points.vec.size()) { + for (int j=0; j<this->triangles.vec[i]->vec.size(); j++) { + int pt = this->triangles.vec[i]->vec[j]->num; + if (pt < this->points.vec.size()) { double px, py, pz; - if (points.vec[pt]->getv3(px, py, pz)) + if (this->points.vec[pt]->getv3(px, py, pz)) p->insert_vertex(px, py, pz); } } } } - if (type == SQUARE) + if (this->type == SQUARE) { double x1, x2, y1, y2; - if (center) { - x1 = -x/2; - x2 = +x/2; - y1 = -y/2; - y2 = +y/2; + if (this->center) { + x1 = -this->x/2; + x2 = +this->x/2; + y1 = -this->y/2; + y2 = +this->y/2; } else { x1 = y1 = 0; - x2 = x; - y2 = y; + x2 = this->x; + y2 = this->y; } p->is2d = true; @@ -447,9 +479,9 @@ sphere_next_r2: p->append_vertex(x1, y2); } - if (type == CIRCLE) + if (this->type == CIRCLE) { - int fragments = get_fragments_from_r(r1, fn, fs, fa); + int fragments = get_fragments_from_r(this->r1, this->fn, this->fs, this->fa); struct point2d { double x, y; @@ -459,8 +491,8 @@ sphere_next_r2: for (int i=0; i<fragments; i++) { double phi = (M_PI*2*i) / fragments; - circle[i].x = r1*cos(phi); - circle[i].y = r1*sin(phi); + circle[i].x = this->r1*cos(phi); + circle[i].y = this->r1*sin(phi); } p->is2d = true; @@ -469,13 +501,13 @@ sphere_next_r2: p->append_vertex(circle[i].x, circle[i].y); } - if (type == POLYGON) + if (this->type == POLYGON) { DxfData dd; - for (int i=0; i<points.vec.size(); i++) { + for (int i=0; i<this->points.vec.size(); i++) { double x,y; - if (!points.vec[i]->getv2(x, y)) { + if (!this->points.vec[i]->getv2(x, y)) { PRINTF("ERROR: Unable to convert point at index %d to a vec2 of numbers", i); // FIXME: Return NULL and make sure this is checked by all callers? return p; @@ -483,10 +515,10 @@ sphere_next_r2: dd.points.append(DxfData::Point(x, y)); } - if (paths.vec.size() == 0) + if (this->paths.vec.size() == 0) { dd.paths.append(DxfData::Path()); - for (int i=0; i<points.vec.size(); i++) { + for (int i=0; i<this->points.vec.size(); i++) { assert(i < dd.points.size()); // FIXME: Not needed, but this used to be an 'if' DxfData::Point *p = &dd.points[i]; dd.paths.last().points.append(p); @@ -498,11 +530,11 @@ sphere_next_r2: } else { - for (int i=0; i<paths.vec.size(); i++) + for (int i=0; i<this->paths.vec.size(); i++) { dd.paths.append(DxfData::Path()); - for (int j=0; j<paths.vec[i]->vec.size(); j++) { - int idx = paths.vec[i]->vec[j]->num; + for (int j=0; j<this->paths.vec[i]->vec.size(); j++) { + int idx = this->paths.vec[i]->vec[j]->num; if (idx < dd.points.size()) { DxfData::Point *p = &dd.points[idx]; dd.paths.last().points.append(p); @@ -530,35 +562,37 @@ std::string PrimitiveNode::toString() const { std::stringstream stream; + stream << this->name(); + switch (this->type) { case CUBE: - stream << "cube(size = [" << this->x << ", " << this->y << ", " << this->z << "], " + stream << "(size = [" << this->x << ", " << this->y << ", " << this->z << "], " << "center = " << (center ? "true" : "false") << ")"; break; case SPHERE: - stream << "sphere($fn = " << this->fn << ", $fa = " << this->fa + stream << "($fn = " << this->fn << ", $fa = " << this->fa << ", $fs = " << this->fs << ", r = " << this->r1 << ")"; break; case CYLINDER: - stream << "cylinder($fn = " << this->fn << ", $fa = " << this->fa + stream << "($fn = " << this->fn << ", $fa = " << this->fa << ", $fs = " << this->fs << ", h = " << this->h << ", r1 = " << this->r1 << ", r2 = " << this->r2 << ", center = " << (center ? "true" : "false") << ")"; break; case POLYHEDRON: - stream << "polyhedron(points = " << this->points.dump() + stream << "(points = " << this->points.dump() << ", triangles = " << this->triangles.dump() << ", convexity = " << this->convexity << ")"; break; case SQUARE: - stream << "square(size = [" << this->x << ", " << this->y << "], " + stream << "(size = [" << this->x << ", " << this->y << "], " << "center = " << (center ? "true" : "false") << ")"; break; case CIRCLE: - stream << "circle($fn = " << this->fn << ", $fa = " << this->fa + stream << "($fn = " << this->fn << ", $fa = " << this->fa << ", $fs = " << this->fs << ", r = " << this->r1 << ")"; break; case POLYGON: - stream << "polygon(points = " << this->points.dump() << ", paths = " << this->paths.dump() << ", convexity = " << this->convexity << ")"; + stream << "(points = " << this->points.dump() << ", paths = " << this->paths.dump() << ", convexity = " << this->convexity << ")"; break; default: assert(false); diff --git a/src/projectionnode.h b/src/projectionnode.h index 3646d84..9cc7918 100644 --- a/src/projectionnode.h +++ b/src/projectionnode.h @@ -14,6 +14,7 @@ public: return visitor.visit(state, *this); } virtual std::string toString() const; + virtual std::string name() const { return "projection"; } int convexity; bool cut_mode; diff --git a/src/render.cc b/src/render.cc index 54eb9c7..b85c446 100644 --- a/src/render.cc +++ b/src/render.cc @@ -81,7 +81,7 @@ std::string RenderNode::toString() const { std::stringstream stream; - stream << "render(convexity = " << convexity << ")"; + stream << this->name() << "(convexity = " << convexity << ")"; return stream.str(); } diff --git a/src/rendernode.h b/src/rendernode.h index 99a5316..c5ebdae 100644 --- a/src/rendernode.h +++ b/src/rendernode.h @@ -12,6 +12,7 @@ public: return visitor.visit(state, *this); } virtual std::string toString() const; + virtual std::string name() const { return "render"; } int convexity; }; diff --git a/src/surface.cc b/src/surface.cc index 9b05fe9..b5f631e 100644 --- a/src/surface.cc +++ b/src/surface.cc @@ -51,6 +51,7 @@ public: return visitor.visit(state, *this); } virtual std::string toString() const; + virtual std::string name() const { return "surface"; } QString filename; bool center; @@ -207,7 +208,7 @@ std::string SurfaceNode::toString() const { std::stringstream stream; - stream << "surface(file = \"" << this->filename + stream << this->name() << "(file = \"" << this->filename << "\", center = " << (this->center ? "true" : "false") << ")"; return stream.str(); diff --git a/src/transform.cc b/src/transform.cc index 6b4d926..ccfc1aa 100644 --- a/src/transform.cc +++ b/src/transform.cc @@ -34,6 +34,7 @@ #include "printutils.h" #include "visitor.h" #include <sstream> +#include <assert.h> enum transform_type_e { SCALE, @@ -64,29 +65,33 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti QVector<QString> argnames; QVector<Expression*> argexpr; - if (type == SCALE) { + switch (this->type) { + case SCALE: argnames = QVector<QString>() << "v"; - } - if (type == ROTATE) { + break; + case ROTATE: argnames = QVector<QString>() << "a" << "v"; - } - if (type == MIRROR) { + break; + case MIRROR: argnames = QVector<QString>() << "v"; - } - if (type == TRANSLATE) { + break; + case TRANSLATE: argnames = QVector<QString>() << "v"; - } - if (type == MULTMATRIX) { + break; + case MULTMATRIX: argnames = QVector<QString>() << "m"; - } - if (type == COLOR) { + break; + case COLOR: argnames = QVector<QString>() << "c"; + break; + default: + assert(false); } Context c(ctx); c.args(argnames, argexpr, inst->argnames, inst->argvalues); - if (type == SCALE) + if (this->type == SCALE) { Value v = c.lookup_variable("v"); v.getnum(node->matrix[0]); @@ -96,7 +101,7 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti if (node->matrix[10] <= 0) node->matrix[10] = 1; } - if (type == ROTATE) + else if (this->type == ROTATE) { Value val_a = c.lookup_variable("a"); if (val_a.type == Value::VECTOR) @@ -167,7 +172,7 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti } } } - if (type == MIRROR) + else if (this->type == MIRROR) { Value val_v = c.lookup_variable("v"); double x = 1, y = 0, z = 0; @@ -194,12 +199,12 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti node->matrix[10] = 1-2*z*z; } } - if (type == TRANSLATE) + else if (this->type == TRANSLATE) { Value v = c.lookup_variable("v"); v.getv3(node->matrix[12], node->matrix[13], node->matrix[14]); } - if (type == MULTMATRIX) + else if (this->type == MULTMATRIX) { Value v = c.lookup_variable("m"); if (v.type == Value::VECTOR) { @@ -210,7 +215,7 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti } } } - if (type == COLOR) + else if (this->type == COLOR) { Value v = c.lookup_variable("c"); if (v.type == Value::VECTOR) { @@ -253,6 +258,11 @@ std::string TransformNode::toString() const return stream.str(); } +std::string TransformNode::name() const +{ + return "transform"; +} + void register_builtin_transform() { builtin_modules["scale"] = new TransformModule(SCALE); diff --git a/src/transformnode.h b/src/transformnode.h index 95057f6..9afa9be 100644 --- a/src/transformnode.h +++ b/src/transformnode.h @@ -12,6 +12,7 @@ public: return visitor.visit(state, *this); } virtual std::string toString() const; + virtual std::string name() const; double matrix[20]; }; |