summaryrefslogtreecommitdiff
path: root/src/surface.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/surface.cc')
-rw-r--r--src/surface.cc39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/surface.cc b/src/surface.cc
index 92b661f..94d039e 100644
--- a/src/surface.cc
+++ b/src/surface.cc
@@ -32,8 +32,10 @@
#include "dxftess.h"
#include "printutils.h"
#include "openscad.h" // handle_dep()
+#include "visitor.h"
#include <QFile>
+#include <sstream>
class SurfaceModule : public AbstractModule
{
@@ -45,12 +47,17 @@ public:
class SurfaceNode : public AbstractPolyNode
{
public:
+ SurfaceNode(const ModuleInstantiation *mi) : AbstractPolyNode(mi) { }
+ virtual Response accept(class State &state, Visitor &visitor) const {
+ return visitor.visit(state, *this);
+ }
+ virtual std::string toString() const;
+ virtual std::string name() const { return "surface"; }
+
QString filename;
bool center;
int convexity;
- SurfaceNode(const ModuleInstantiation *mi) : AbstractPolyNode(mi) { }
- virtual PolySet *render_polyset(render_mode_e mode) const;
- virtual QString dump(QString indent) const;
+ virtual PolySet *evaluate_polyset(render_mode_e mode, class PolySetEvaluator *) const;
};
AbstractNode *SurfaceModule::evaluate(const Context *ctx, const ModuleInstantiation *inst) const
@@ -65,7 +72,7 @@ AbstractNode *SurfaceModule::evaluate(const Context *ctx, const ModuleInstantiat
Context c(ctx);
c.args(argnames, argexpr, inst->argnames, inst->argvalues);
- node->filename = c.get_absolute_path(c.lookup_variable("file").text);
+ node->filename = c.get_absolute_path(QString::fromStdString(c.lookup_variable("file").text));
Value center = c.lookup_variable("center", true);
if (center.type == Value::BOOL) {
@@ -85,14 +92,15 @@ void register_builtin_surface()
builtin_modules["surface"] = new SurfaceModule();
}
-PolySet *SurfaceNode::render_polyset(render_mode_e) const
+PolySet *SurfaceNode::evaluate_polyset(render_mode_e, class PolySetEvaluator *) const
{
+ PolySet *p = new PolySet();
handle_dep(filename);
QFile f(filename);
if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
- PRINTF("WARNING: Can't open DXF file `%s'.", filename.toAscii().data());
- return NULL;
+ PRINTF("WARNING: Can't open DAT file `%s'.", filename.toAscii().data());
+ return p;
}
int lines = 0, columns = 0;
@@ -119,7 +127,6 @@ PolySet *SurfaceNode::render_polyset(render_mode_e) const
lines++;
}
- PolySet *p = new PolySet();
p->convexity = convexity;
double ox = center ? -columns/2.0 : 0;
@@ -198,14 +205,12 @@ PolySet *SurfaceNode::render_polyset(render_mode_e) const
return p;
}
-QString SurfaceNode::dump(QString indent) const
+std::string SurfaceNode::toString() const
{
- if (dump_cache.isEmpty()) {
- QString text;
- text.sprintf("surface(file = \"%s\", center = %s);\n",
- filename.toAscii().data(), center ? "true" : "false");
- ((AbstractNode*)this)->dump_cache = indent + QString("n%1: ").arg(idx) + text;
- }
- return dump_cache;
-}
+ std::stringstream stream;
+ stream << this->name() << "(file = \"" << this->filename
+ << "\", center = " << (this->center ? "true" : "false") << ")";
+
+ return stream.str();
+}
contact: Jan Huwald // Impressum