summaryrefslogtreecommitdiff
path: root/src/import.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/import.cc')
-rw-r--r--src/import.cc121
1 files changed, 67 insertions, 54 deletions
diff --git a/src/import.cc b/src/import.cc
index a924e24..4586237 100644
--- a/src/import.cc
+++ b/src/import.cc
@@ -24,8 +24,9 @@
*
*/
+#include "importnode.h"
+
#include "module.h"
-#include "node.h"
#include "polyset.h"
#include "context.h"
#include "builtin.h"
@@ -37,12 +38,8 @@
#include <QFile>
#include <sys/types.h>
#include <sys/stat.h>
-
-enum import_type_e {
- TYPE_STL,
- TYPE_OFF,
- TYPE_DXF
-};
+#include <sstream>
+#include <assert.h>
class ImportModule : public AbstractModule
{
@@ -52,26 +49,12 @@ public:
virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const;
};
-class ImportNode : public AbstractPolyNode
-{
-public:
- import_type_e type;
- QString filename;
- QString layername;
- int convexity;
- double fn, fs, fa;
- double origin_x, origin_y, scale;
- ImportNode(const ModuleInstantiation *mi, import_type_e type) : AbstractPolyNode(mi), type(type) { }
- virtual PolySet *render_polyset(render_mode_e mode) const;
- virtual QString dump(QString indent) const;
-};
-
AbstractNode *ImportModule::evaluate(const Context *ctx, const ModuleInstantiation *inst) const
{
ImportNode *node = new ImportNode(inst, type);
QVector<QString> argnames;
- if (type == TYPE_DXF) {
+ if (this->type == TYPE_DXF) {
argnames = QVector<QString>() << "file" << "layer" << "convexity" << "origin" << "scale";
} else {
argnames = QVector<QString>() << "file" << "convexity";
@@ -94,8 +77,10 @@ AbstractNode *ImportModule::evaluate(const Context *ctx, const ModuleInstantiati
node->fs = c.lookup_variable("$fs").num;
node->fa = c.lookup_variable("$fa").num;
- node->filename = c.get_absolute_path(c.lookup_variable("file").text);
- node->layername = c.lookup_variable("layer", true).text;
+ Value v = c.lookup_variable("file");
+ node->filename = c.get_absolute_path(QString::fromStdString(v.text));
+// node->filename = c.get_absolute_path(QString::fromStdString(c.lookup_variable("file").text));
+ node->layername = QString::fromStdString(c.lookup_variable("layer", true).text);
node->convexity = c.lookup_variable("convexity", true).num;
if (node->convexity <= 0)
@@ -120,17 +105,17 @@ void register_builtin_import()
builtin_modules["import_dxf"] = new ImportModule(TYPE_DXF);
}
-PolySet *ImportNode::render_polyset(render_mode_e) const
+PolySet *ImportNode::render_polyset(render_mode_e, class PolySetRenderer *) const
{
PolySet *p = new PolySet();
- p->convexity = convexity;
+ p->convexity = this->convexity;
- if (type == TYPE_STL)
+ if (this->type == TYPE_STL)
{
- handle_dep(filename);
- QFile f(filename);
+ handle_dep(this->filename);
+ QFile f(this->filename);
if (!f.open(QIODevice::ReadOnly)) {
- PRINTF("WARNING: Can't open import file `%s'.", filename.toAscii().data());
+ PRINTF("WARNING: Can't open import file `%s'.", this->filename.toAscii().data());
return p;
}
@@ -202,14 +187,14 @@ PolySet *ImportNode::render_polyset(render_mode_e) const
}
}
- if (type == TYPE_OFF)
+ if (this->type == TYPE_OFF)
{
PRINTF("WARNING: OFF import is not implemented yet.");
}
- if (type == TYPE_DXF)
+ if (this->type == TYPE_DXF)
{
- DxfData dd(fn, fs, fa, filename, layername, origin_x, origin_y, scale);
+ 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_border_to_ps(p, &dd);
@@ -218,28 +203,56 @@ PolySet *ImportNode::render_polyset(render_mode_e) const
return p;
}
-QString ImportNode::dump(QString indent) const
+std::string ImportNode::toString() const
{
- if (dump_cache.isEmpty()) {
- QString text;
- struct stat st;
- memset(&st, 0, sizeof(struct stat));
- stat(filename.toAscii().data(), &st);
- if (type == TYPE_STL)
- text.sprintf("import_stl(file = \"%s\", cache = \"%x.%x\", convexity = %d);\n",
- filename.toAscii().data(), (int)st.st_mtime, (int)st.st_size, convexity);
- if (type == TYPE_OFF)
- text.sprintf("import_off(file = \"%s\", cache = \"%x.%x\", convexity = %d);\n",
- filename.toAscii().data(), (int)st.st_mtime, (int)st.st_size, convexity);
- if (type == TYPE_DXF)
- text.sprintf("import_dxf(file = \"%s\", cache = \"%x.%x\", layer = \"%s\", "
- "origin = [ %g %g ], scale = %g, convexity = %d, "
- "$fn = %g, $fa = %g, $fs = %g);\n",
- filename.toAscii().data(), (int)st.st_mtime, (int)st.st_size,
- layername.toAscii().data(), origin_x, origin_y, scale, convexity,
- fn, fa, fs);
- ((AbstractNode*)this)->dump_cache = indent + QString("n%1: ").arg(idx) + text;
+ std::stringstream stream;
+
+ QString text;
+ struct stat st;
+ memset(&st, 0, sizeof(struct stat));
+ stat(this->filename.toAscii().data(), &st);
+
+ stream << this->name();
+ switch (this->type) {
+ case TYPE_STL:
+ 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 << "(file = \"" << this->filename << "\", "
+ "cache = \"" << std::hex << (int)st.st_mtime << "." << (int)st.st_size << "\", "
+ "convexity = " << std::dec << this->convexity << ")";
+ break;
+ case TYPE_DXF:
+ 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 << " ], "
+ "scale = " << this->scale << ", "
+ "convexity = " << this->convexity << ", "
+ "$fn = " << this->fn << ", $fa = " << this->fa << ", $fs = " << this->fs << ")";
+ break;
+ default:
+ assert(false);
}
- return dump_cache;
+
+ 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);
+ }
+}
contact: Jan Huwald // Impressum