diff options
author | Marius Kintel <marius@kintel.net> | 2013-05-24 14:16:20 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2013-05-24 14:16:20 (GMT) |
commit | 26046f6f0c4a774cbbb2af8ae7dc0e687963440c (patch) | |
tree | 38ff04fc460e8aa55134fb1ee6167fafb90a3423 /src/linearextrude.cc | |
parent | eefcd6d0b271642d470cd55bc47d1579d943938e (diff) | |
parent | 95e399e06c6522f3fa67679808a1d52815368efa (diff) |
Merge branch 'master' into epec-kernel
Diffstat (limited to 'src/linearextrude.cc')
-rw-r--r-- | src/linearextrude.cc | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/src/linearextrude.cc b/src/linearextrude.cc index 43db907..9a7365b 100644 --- a/src/linearextrude.cc +++ b/src/linearextrude.cc @@ -27,8 +27,9 @@ #include "linearextrudenode.h" #include "module.h" -#include "context.h" +#include "evalcontext.h" #include "printutils.h" +#include "fileutils.h" #include "builtin.h" #include "PolySetEvaluator.h" #include "openscad.h" // get_fragments_from_r() @@ -45,19 +46,18 @@ class LinearExtrudeModule : public AbstractModule { public: LinearExtrudeModule() { } - virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const; + virtual AbstractNode *instantiate(const Context *ctx, const ModuleInstantiation *inst, const EvalContext *evalctx) const; }; -AbstractNode *LinearExtrudeModule::evaluate(const Context *ctx, const ModuleInstantiation *inst) const +AbstractNode *LinearExtrudeModule::instantiate(const Context *ctx, const ModuleInstantiation *inst, const EvalContext *evalctx) const { LinearExtrudeNode *node = new LinearExtrudeNode(inst); - std::vector<std::string> argnames; - argnames += "file", "layer", "height", "origin", "scale", "center", "twist", "slices"; - std::vector<Expression*> argexpr; + AssignmentList args; + args += Assignment("file", NULL), Assignment("layer", NULL), Assignment("height", NULL), Assignment("origin", NULL), Assignment("scale", NULL), Assignment("center", NULL), Assignment("twist", NULL), Assignment("slices", NULL); Context c(ctx); - c.args(argnames, argexpr, inst->argnames, inst->argvalues); + c.setVariables(args, evalctx); node->fn = c.lookup_variable("$fn").toDouble(); node->fs = c.lookup_variable("$fs").toDouble(); @@ -73,25 +73,28 @@ AbstractNode *LinearExtrudeModule::evaluate(const Context *ctx, const ModuleInst Value twist = c.lookup_variable("twist", true); Value slices = c.lookup_variable("slices", true); - if (!file.isUndefined()) { + if (!file.isUndefined() && file.type() == Value::STRING) { PRINT("DEPRECATED: Support for reading files in linear_extrude will be removed in future releases. Use a child import() instead."); - node->filename = c.getAbsolutePath(file.toString()); + node->filename = lookup_file(file.toString(), inst->path(), c.documentPath()); } // if height not given, and first argument is a number, // then assume it should be the height. if (c.lookup_variable("height").isUndefined() && - inst->argnames.size() > 0 && - inst->argnames[0] == "" && - inst->argvalues[0].type() == Value::NUMBER) { - height = Value(inst->argvalues[0]); + evalctx->numArgs() > 0 && + evalctx->getArgName(0) == "" && + evalctx->getArgValue(0).type() == Value::NUMBER) { + height = evalctx->getArgValue(0); } node->layername = layer.isUndefined() ? "" : layer.toString(); node->height = height.toDouble(); node->convexity = (int)convexity.toDouble(); origin.getVec2(node->origin_x, node->origin_y); - node->scale = scale.toDouble(); + node->scale_x = node->scale_y = 1; + scale.getDouble(node->scale_x); + scale.getDouble(node->scale_y); + scale.getVec2(node->scale_x, node->scale_y); if (center.type() == Value::BOOL) node->center = center.toBool(); @@ -102,8 +105,8 @@ AbstractNode *LinearExtrudeModule::evaluate(const Context *ctx, const ModuleInst if (node->convexity <= 0) node->convexity = 1; - if (node->scale <= 0) - node->scale = 1; + if (node->scale_x < 0) node->scale_x = 0; + if (node->scale_y < 0) node->scale_y = 0; if (twist.type() == Value::NUMBER) { node->twist = twist.toDouble(); @@ -117,8 +120,8 @@ AbstractNode *LinearExtrudeModule::evaluate(const Context *ctx, const ModuleInst } if (node->filename.empty()) { - std::vector<AbstractNode *> evaluatednodes = inst->evaluateChildren(); - node->children.insert(node->children.end(), evaluatednodes.begin(), evaluatednodes.end()); + std::vector<AbstractNode *> instantiatednodes = inst->instantiateChildren(evalctx); + node->children.insert(node->children.end(), instantiatednodes.begin(), instantiatednodes.end()); } return node; @@ -151,7 +154,6 @@ std::string LinearExtrudeNode::toString() const "file = " << this->filename << ", " "layer = " << QuotedString(this->layername) << ", " "origin = [" << this->origin_x << ", " << this->origin_y << "], " - "scale = " << this->scale << ", " #ifndef OPENSCAD_TESTING // timestamp is needed for caching, but disturbs the test framework << "timestamp = " << (fs::exists(path) ? fs::last_write_time(path) : 0) << ", " @@ -166,6 +168,7 @@ std::string LinearExtrudeNode::toString() const if (this->has_twist) { stream << ", twist = " << this->twist << ", slices = " << this->slices; } + stream << ", scale = [" << this->scale_x << ", " << this->scale_y << "]"; stream << ", $fn = " << this->fn << ", $fa = " << this->fa << ", $fs = " << this->fs << ")"; return stream.str(); |