summaryrefslogtreecommitdiff
path: root/src/dxfdim.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/dxfdim.cc')
-rw-r--r--src/dxfdim.cc63
1 files changed, 38 insertions, 25 deletions
diff --git a/src/dxfdim.cc b/src/dxfdim.cc
index 1ed37fa..fbc24c4 100644
--- a/src/dxfdim.cc
+++ b/src/dxfdim.cc
@@ -30,7 +30,7 @@
#include "dxfdata.h"
#include "builtin.h"
#include "printutils.h"
-#include "context.h"
+#include "evalcontext.h"
#include "mathc99.h"
#include <sstream>
@@ -40,7 +40,7 @@ boost::unordered_map<std::string,Value> dxf_dim_cache;
boost::unordered_map<std::string,Value> dxf_cross_cache;
namespace fs = boost::filesystem;
-Value builtin_dxf_dim(const Context *ctx, const std::vector<std::string> &argnames, const std::vector<Value> &args)
+Value builtin_dxf_dim(const Context *ctx, const EvalContext *evalctx)
{
std::string filename;
std::string layername;
@@ -49,23 +49,33 @@ Value builtin_dxf_dim(const Context *ctx, const std::vector<std::string> &argnam
double yorigin = 0;
double scale = 1;
- for (size_t i = 0; i < argnames.size() && i < args.size(); i++) {
- if (argnames[i] == "file")
- filename = ctx->getAbsolutePath(args[i].toString());
- if (argnames[i] == "layer")
- layername = args[i].toString();
- if (argnames[i] == "origin")
- args[i].getVec2(xorigin, yorigin);
- if (argnames[i] == "scale")
- args[i].getDouble(scale);
- if (argnames[i] == "name")
- name = args[i].toString();
+ // FIXME: We don't lookup the file relative to where this function was instantiated
+ // since the path is only available for ModuleInstantiations, not function expressions.
+ // See issue #217
+ for (size_t i = 0; i < evalctx->eval_arguments.size(); i++) {
+ if (evalctx->eval_arguments[i].first == "file")
+ filename = ctx->getAbsolutePath(evalctx->eval_arguments[i].second.toString());
+ if (evalctx->eval_arguments[i].first == "layer")
+ layername = evalctx->eval_arguments[i].second.toString();
+ if (evalctx->eval_arguments[i].first == "origin")
+ evalctx->eval_arguments[i].second.getVec2(xorigin, yorigin);
+ if (evalctx->eval_arguments[i].first == "scale")
+ evalctx->eval_arguments[i].second.getDouble(scale);
+ if (evalctx->eval_arguments[i].first == "name")
+ name = evalctx->eval_arguments[i].second.toString();
}
std::stringstream keystream;
+ fs::path filepath(filename);
+ uintmax_t filesize = -1;
+ time_t lastwritetime = -1;
+ if (fs::exists(filepath) && fs::is_regular_file(filepath)) {
+ filesize = fs::file_size(filepath);
+ lastwritetime = fs::last_write_time(filepath);
+ }
keystream << filename << "|" << layername << "|" << name << "|" << xorigin
- << "|" << yorigin <<"|" << scale << "|" << fs::last_write_time(filename)
- << "|" << fs::file_size(filename);
+ << "|" << yorigin <<"|" << scale << "|" << lastwritetime
+ << "|" << filesize;
std::string key = keystream.str();
if (dxf_dim_cache.find(key) != dxf_dim_cache.end())
return dxf_dim_cache.find(key)->second;
@@ -125,7 +135,7 @@ Value builtin_dxf_dim(const Context *ctx, const std::vector<std::string> &argnam
return Value();
}
-Value builtin_dxf_cross(const Context *ctx, const std::vector<std::string> &argnames, const std::vector<Value> &args)
+Value builtin_dxf_cross(const Context *ctx, const EvalContext *evalctx)
{
std::string filename;
std::string layername;
@@ -133,15 +143,18 @@ Value builtin_dxf_cross(const Context *ctx, const std::vector<std::string> &argn
double yorigin = 0;
double scale = 1;
- for (size_t i = 0; i < argnames.size() && i < args.size(); i++) {
- if (argnames[i] == "file")
- filename = ctx->getAbsolutePath(args[i].toString());
- if (argnames[i] == "layer")
- layername = args[i].toString();
- if (argnames[i] == "origin")
- args[i].getVec2(xorigin, yorigin);
- if (argnames[i] == "scale")
- args[i].getDouble(scale);
+ // FIXME: We don't lookup the file relative to where this function was instantiated
+ // since the path is only available for ModuleInstantiations, not function expressions.
+ // See isse #217
+ for (size_t i = 0; i < evalctx->eval_arguments.size(); i++) {
+ if (evalctx->eval_arguments[i].first == "file")
+ filename = ctx->getAbsolutePath(evalctx->eval_arguments[i].second.toString());
+ if (evalctx->eval_arguments[i].first == "layer")
+ layername = evalctx->eval_arguments[i].second.toString();
+ if (evalctx->eval_arguments[i].first == "origin")
+ evalctx->eval_arguments[i].second.getVec2(xorigin, yorigin);
+ if (evalctx->eval_arguments[i].first == "scale")
+ evalctx->eval_arguments[i].second.getDouble(scale);
}
std::stringstream keystream;
contact: Jan Huwald // Impressum