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/import.cc | |
parent | eefcd6d0b271642d470cd55bc47d1579d943938e (diff) | |
parent | 95e399e06c6522f3fa67679808a1d52815368efa (diff) |
Merge branch 'master' into epec-kernel
Diffstat (limited to 'src/import.cc')
-rw-r--r-- | src/import.cc | 55 |
1 files changed, 42 insertions, 13 deletions
diff --git a/src/import.cc b/src/import.cc index 32d4fed..2180684 100644 --- a/src/import.cc +++ b/src/import.cc @@ -28,11 +28,12 @@ #include "module.h" #include "polyset.h" -#include "context.h" +#include "evalcontext.h" #include "builtin.h" #include "dxfdata.h" #include "dxftess.h" #include "printutils.h" +#include "fileutils.h" #include "handle_dep.h" // handle_dep() #ifdef ENABLE_CGAL @@ -60,27 +61,44 @@ class ImportModule : public AbstractModule public: import_type_e type; ImportModule(import_type_e type = TYPE_UNKNOWN) : type(type) { } - virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const; + virtual AbstractNode *instantiate(const Context *ctx, const ModuleInstantiation *inst, const EvalContext *evalctx) const; }; -AbstractNode *ImportModule::evaluate(const Context *ctx, const ModuleInstantiation *inst) const +AbstractNode *ImportModule::instantiate(const Context *ctx, const ModuleInstantiation *inst, const EvalContext *evalctx) const { - std::vector<std::string> argnames; - argnames += "file", "layer", "convexity", "origin", "scale"; - std::vector<Expression*> argexpr; + AssignmentList args; + args += Assignment("file", NULL), Assignment("layer", NULL), Assignment("convexity", NULL), Assignment("origin", NULL), Assignment("scale", NULL); + args += Assignment("filename",NULL), Assignment("layername", NULL); + // FIXME: This is broken. Tag as deprecated and fix // Map old argnames to new argnames for compatibility + // To fix: + // o after c.setVariables() + // - if "filename" in evalctx: deprecated-warning && v.set_variable("file", value); + // - if "layername" in evalctx: deprecated-warning && v.set_variable("layer", value); +#if 0 std::vector<std::string> inst_argnames = inst->argnames; for (size_t i=0; i<inst_argnames.size(); i++) { if (inst_argnames[i] == "filename") inst_argnames[i] = "file"; if (inst_argnames[i] == "layername") inst_argnames[i] = "layer"; } +#endif Context c(ctx); - c.args(argnames, argexpr, inst_argnames, inst->argvalues); + c.setDocumentPath(evalctx->documentPath()); + c.setVariables(args, evalctx); +#if 0 && DEBUG + c.dump(this, inst); +#endif Value v = c.lookup_variable("file"); - std::string filename = c.getAbsolutePath(v.isUndefined() ? "" : v.toString()); + if (v.isUndefined()) { + v = c.lookup_variable("filename"); + if (!v.isUndefined()) { + PRINT("DEPRECATED: filename= is deprecated. Please use file="); + } + } + std::string filename = lookup_file(v.isUndefined() ? "" : v.toString(), inst->path(), ctx->documentPath()); import_type_e actualtype = this->type; if (actualtype == TYPE_UNKNOWN) { std::string extraw = boosty::extension_str( fs::path(filename) ); @@ -98,6 +116,12 @@ AbstractNode *ImportModule::evaluate(const Context *ctx, const ModuleInstantiati node->filename = filename; Value layerval = c.lookup_variable("layer", true); + if (layerval.isUndefined()) { + layerval = c.lookup_variable("layername"); + if (!layerval.isUndefined()) { + PRINT("DEPRECATED: layername= is deprecated. Please use layer="); + } + } node->layername = layerval.isUndefined() ? "" : layerval.toString(); node->convexity = c.lookup_variable("convexity", true).toDouble(); @@ -251,10 +275,15 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const #ifdef ENABLE_CGAL CGAL_Polyhedron poly; std::ifstream file(this->filename.c_str(), std::ios::in | std::ios::binary); - file >> poly; - file.close(); - - p = createPolySetFromPolyhedron(poly); + if (!file.good()) { + PRINTB("WARNING: Can't open import file '%s'.", this->filename); + } + else { + file >> poly; + file.close(); + + p = createPolySetFromPolyhedron(poly); + } #else PRINT("WARNING: OFF import requires CGAL."); #endif @@ -265,7 +294,7 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const p = new PolySet(); DxfData dd(this->fn, this->fs, this->fa, this->filename, this->layername, this->origin_x, this->origin_y, this->scale); p->is2d = true; - dxf_tesselate(p, dd, 0, true, false, 0); + dxf_tesselate(p, dd, 0, Vector2d(1,1), true, false, 0); dxf_border_to_ps(p, dd); } else |