diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/PolySetCGALEvaluator.cc | 13 | ||||
-rw-r--r-- | src/cgaladv.cc | 7 | ||||
-rw-r--r-- | src/color.cc | 7 | ||||
-rw-r--r-- | src/control.cc | 38 | ||||
-rw-r--r-- | src/dxflinextrude.cc | 7 | ||||
-rw-r--r-- | src/dxfrotextrude.cc | 7 | ||||
-rw-r--r-- | src/mainwin.cc | 3 | ||||
-rw-r--r-- | src/module.cc | 51 | ||||
-rw-r--r-- | src/module.h | 2 | ||||
-rw-r--r-- | src/projection.cc | 7 | ||||
-rw-r--r-- | src/render.cc | 7 | ||||
-rw-r--r-- | src/transform.cc | 7 |
12 files changed, 68 insertions, 88 deletions
diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc index 652881f..8c5c2f9 100644 --- a/src/PolySetCGALEvaluator.cc +++ b/src/PolySetCGALEvaluator.cc @@ -11,6 +11,7 @@ #include "printutils.h" #include "openscad.h" // get_fragments_from_r() +#include <boost/foreach.hpp> PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node, AbstractPolyNode::render_mode_e) { @@ -251,7 +252,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const DxfLinearExtrudeNode &node, // Before extruding, union all (2D) children nodes // to a single DxfData, then tesselate this into a PolySet CGAL_Nef_polyhedron sum; - foreach (AbstractNode * v, node.getChildren()) { + BOOST_FOREACH (AbstractNode * v, node.getChildren()) { if (v->modinst->tag_background) continue; CGAL_Nef_polyhedron N = this->cgalevaluator.evaluateCGALMesh(*v); if (sum.empty()) sum = N.copy(); @@ -348,7 +349,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const DxfRotateExtrudeNode &node, // Before extruding, union all (2D) children nodes // to a single DxfData, then tesselate this into a PolySet CGAL_Nef_polyhedron sum; - foreach (AbstractNode * v, node.getChildren()) { + BOOST_FOREACH (AbstractNode * v, node.getChildren()) { if (v->modinst->tag_background) continue; CGAL_Nef_polyhedron N = this->cgalevaluator.evaluateCGALMesh(*v); if (sum.empty()) sum = N.copy(); @@ -371,10 +372,10 @@ PolySet *PolySetCGALEvaluator::rotateDxfData(const DxfRotateExtrudeNode &node, D PolySet *ps = new PolySet(); ps->convexity = node.convexity; - for (int i = 0; i < dxf.paths.size(); i++) + for (size_t i = 0; i < dxf.paths.size(); i++) { double max_x = 0; - for (int j = 0; j < dxf.paths[i].indices.size(); j++) { + for (size_t j = 0; j < dxf.paths[i].indices.size(); j++) { max_x = fmax(max_x, dxf.points[dxf.paths[i].indices[j]][0]); } @@ -384,13 +385,13 @@ PolySet *PolySetCGALEvaluator::rotateDxfData(const DxfRotateExtrudeNode &node, D points = new double**[fragments]; for (int j=0; j < fragments; j++) { points[j] = new double*[dxf.paths[i].indices.size()]; - for (int k=0; k < dxf.paths[i].indices.size(); k++) + for (size_t k=0; k < dxf.paths[i].indices.size(); k++) points[j][k] = new double[3]; } for (int j = 0; j < fragments; j++) { double a = (j*2*M_PI) / fragments; - for (int k = 0; k < dxf.paths[i].indices.size(); k++) { + for (size_t k = 0; k < dxf.paths[i].indices.size(); k++) { if (dxf.points[dxf.paths[i].indices[k]][0] == 0) { points[j][k][0] = 0; points[j][k][1] = 0; diff --git a/src/cgaladv.cc b/src/cgaladv.cc index 908000d..6c4c222 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -130,11 +130,8 @@ AbstractNode *CgaladvModule::evaluate(const Context *ctx, const ModuleInstantiat if (node->level <= 1) node->level = 1; - foreach (ModuleInstantiation *v, inst->children) { - AbstractNode *n = v->evaluate(inst->ctx); - if (n) - node->children.push_back(n); - } + std::vector<AbstractNode *> evaluatednodes = inst->evaluateChildren(); + node->children.insert(node->children.end(), evaluatednodes.begin(), evaluatednodes.end()); return node; } diff --git a/src/color.cc b/src/color.cc index c64745c..a65a8e4 100644 --- a/src/color.cc +++ b/src/color.cc @@ -82,11 +82,8 @@ AbstractNode *ColorModule::evaluate(const Context *ctx, const ModuleInstantiatio node->color[3] = alpha.num; } - foreach (ModuleInstantiation *v, inst->children) { - AbstractNode *n = v->evaluate(inst->ctx); - if (n != NULL) - node->children.push_back(n); - } + std::vector<AbstractNode *> evaluatednodes = inst->evaluateChildren(); + node->children.insert(node->children.end(), evaluatednodes.begin(), evaluatednodes.end()); return node; } diff --git a/src/control.cc b/src/control.cc index 6eaff58..36689a0 100644 --- a/src/control.cc +++ b/src/control.cc @@ -48,10 +48,9 @@ public: virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const; }; -void for_eval(AbstractNode *node, size_t l, +void for_eval(AbstractNode &node, const ModuleInstantiation &inst, size_t l, const std::vector<std::string> &call_argnames, const std::vector<Value> &call_argvalues, - const std::vector<ModuleInstantiation*> &arg_children, const Context *arg_context) { if (call_argnames.size() > l) { @@ -70,24 +69,22 @@ void for_eval(AbstractNode *node, size_t l, if (range_step > 0 && (range_begin-range_end)/range_step < 10000) { for (double i = range_begin; i <= range_end; i += range_step) { c.set_variable(it_name, Value(i)); - for_eval(node, l+1, call_argnames, call_argvalues, arg_children, &c); + for_eval(node, inst, l+1, call_argnames, call_argvalues, &c); } } } else if (it_values.type == Value::VECTOR) { for (size_t i = 0; i < it_values.vec.size(); i++) { c.set_variable(it_name, *it_values.vec[i]); - for_eval(node, l+1, call_argnames, call_argvalues, arg_children, &c); + for_eval(node, inst, l+1, call_argnames, call_argvalues, &c); } } else { - for_eval(node, l+1, call_argnames, call_argvalues, arg_children, &c); + for_eval(node, inst, l+1, call_argnames, call_argvalues, &c); } } else { - foreach (ModuleInstantiation *v, arg_children) { - AbstractNode *n = v->evaluate(arg_context); - if (n != NULL) node->children.push_back(n); - } + std::vector<AbstractNode *> evaluatednodes = inst.evaluateChildren(arg_context); + node.children.insert(node.children.end(), evaluatednodes.begin(), evaluatednodes.end()); } } @@ -139,34 +136,25 @@ AbstractNode *ControlModule::evaluate(const Context*, const ModuleInstantiation if (!inst->argnames[i].empty()) c.set_variable(inst->argnames[i], inst->argvalues[i]); } - foreach (ModuleInstantiation *v, inst->children) { - AbstractNode *n = v->evaluate(&c); - if (n != NULL) - node->children.push_back(n); - } + std::vector<AbstractNode *> evaluatednodes = inst->evaluateChildren(); + node->children.insert(node->children.end(), evaluatednodes.begin(), evaluatednodes.end()); } if (type == FOR || type == INT_FOR) { - for_eval(node, 0, inst->argnames, inst->argvalues, inst->children, inst->ctx); + for_eval(*node, *inst, 0, inst->argnames, inst->argvalues, inst->ctx); } if (type == IF) { const IfElseModuleInstantiation *ifelse = dynamic_cast<const IfElseModuleInstantiation*>(inst); if (ifelse->argvalues.size() > 0 && ifelse->argvalues[0].type == Value::BOOL && ifelse->argvalues[0].b) { - foreach (ModuleInstantiation *v, ifelse->children) { - AbstractNode *n = v->evaluate(ifelse->ctx); - if (n != NULL) - node->children.push_back(n); - } + std::vector<AbstractNode *> evaluatednodes = ifelse->evaluateChildren(); + node->children.insert(node->children.end(), evaluatednodes.begin(), evaluatednodes.end()); } else { - foreach (ModuleInstantiation *v, ifelse->else_children) { - AbstractNode *n = v->evaluate(ifelse->ctx); - if (n != NULL) - node->children.push_back(n); - } + std::vector<AbstractNode *> evaluatednodes = ifelse->evaluateElseChildren(); + node->children.insert(node->children.end(), evaluatednodes.begin(), evaluatednodes.end()); } } diff --git a/src/dxflinextrude.cc b/src/dxflinextrude.cc index 94792ef..14d69c4 100644 --- a/src/dxflinextrude.cc +++ b/src/dxflinextrude.cc @@ -109,11 +109,8 @@ AbstractNode *DxfLinearExtrudeModule::evaluate(const Context *ctx, const ModuleI } if (node->filename.empty()) { - foreach (ModuleInstantiation *v, inst->children) { - AbstractNode *n = v->evaluate(inst->ctx); - if (n) - node->children.push_back(n); - } + std::vector<AbstractNode *> evaluatednodes = inst->evaluateChildren(); + node->children.insert(node->children.end(), evaluatednodes.begin(), evaluatednodes.end()); } return node; diff --git a/src/dxfrotextrude.cc b/src/dxfrotextrude.cc index 44a70a5..338a73e 100644 --- a/src/dxfrotextrude.cc +++ b/src/dxfrotextrude.cc @@ -85,11 +85,8 @@ AbstractNode *DxfRotateExtrudeModule::evaluate(const Context *ctx, const ModuleI node->scale = 1; if (node->filename.empty()) { - foreach (ModuleInstantiation *v, inst->children) { - AbstractNode *n = v->evaluate(inst->ctx); - if (n) - node->children.push_back(n); - } + std::vector<AbstractNode *> evaluatednodes = inst->evaluateChildren(); + node->children.insert(node->children.end(), evaluatednodes.begin(), evaluatednodes.end()); } return node; diff --git a/src/mainwin.cc b/src/mainwin.cc index c112d55..170bb05 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -76,6 +76,7 @@ #endif #include <algorithm> +#include <boost/foreach.hpp> #include <boost/lambda/lambda.hpp> #include <boost/lambda/bind.hpp> using namespace boost::lambda; @@ -578,7 +579,7 @@ void MainWindow::load() AbstractNode *MainWindow::find_root_tag(AbstractNode *n) { - foreach(AbstractNode *v, n->children) { + BOOST_FOREACH (AbstractNode *v, n->children) { if (v->modinst->tag_root) return v; if (AbstractNode *vroot = find_root_tag(v)) return vroot; } diff --git a/src/module.cc b/src/module.cc index 2852c4e..365eff5 100644 --- a/src/module.cc +++ b/src/module.cc @@ -42,11 +42,7 @@ AbstractNode *AbstractModule::evaluate(const Context*, const ModuleInstantiation { AbstractNode *node = new AbstractNode(inst); - foreach (ModuleInstantiation *v, inst->children) { - AbstractNode *n = v->evaluate(inst->ctx); - if (n) - node->children.push_back(n); - } + node->children = inst->evaluateChildren(); return node; } @@ -60,16 +56,13 @@ std::string AbstractModule::dump(const std::string &indent, const std::string &n ModuleInstantiation::~ModuleInstantiation() { - foreach (Expression *v, argexpr) - delete v; - foreach (ModuleInstantiation *v, children) - delete v; + BOOST_FOREACH (Expression *v, argexpr) delete v; + BOOST_FOREACH (ModuleInstantiation *v, children) delete v; } IfElseModuleInstantiation::~IfElseModuleInstantiation() { - foreach (ModuleInstantiation *v, else_children) - delete v; + BOOST_FOREACH (ModuleInstantiation *v, else_children) delete v; } std::string ModuleInstantiation::dump(const std::string &indent) const @@ -106,7 +99,7 @@ AbstractNode *ModuleInstantiation::evaluate(const Context *ctx) const } else { ModuleInstantiation *that = (ModuleInstantiation*)this; that->argvalues.clear(); - foreach (Expression *v, that->argexpr) { + BOOST_FOREACH (Expression *v, that->argexpr) { that->argvalues.push_back(v->evaluate(ctx)); } that->ctx = ctx; @@ -117,18 +110,34 @@ AbstractNode *ModuleInstantiation::evaluate(const Context *ctx) const return node; } -Module::~Module() +std::vector<AbstractNode*> ModuleInstantiation::evaluateChildren(const Context *ctx) const { - foreach (Expression *v, assignments_expr) - delete v; - BOOST_FOREACH(FunctionContainer::value_type &f, functions) { - delete f.second; + if (!ctx) ctx = this->ctx; + std::vector<AbstractNode*> childnodes; + BOOST_FOREACH (ModuleInstantiation *v, this->children) { + AbstractNode *n = v->evaluate(this->ctx); + if (n != NULL) childnodes.push_back(n); } - BOOST_FOREACH(AbstractModuleContainer::value_type &m, modules) { - delete m.second; + return childnodes; +} + +std::vector<AbstractNode*> IfElseModuleInstantiation::evaluateElseChildren(const Context *ctx) const +{ + if (!ctx) ctx = this->ctx; + std::vector<AbstractNode*> childnodes; + BOOST_FOREACH (ModuleInstantiation *v, this->else_children) { + AbstractNode *n = v->evaluate(this->ctx); + if (n != NULL) childnodes.push_back(n); } - foreach (ModuleInstantiation *v, children) - delete v; + return childnodes; +} + +Module::~Module() +{ + BOOST_FOREACH (Expression *v, assignments_expr) delete v; + BOOST_FOREACH (FunctionContainer::value_type &f, functions) delete f.second; + BOOST_FOREACH (AbstractModuleContainer::value_type &m, modules) delete m.second; + BOOST_FOREACH (ModuleInstantiation *v, children) delete v; } AbstractNode *Module::evaluate(const Context *ctx, const ModuleInstantiation *inst) const diff --git a/src/module.h b/src/module.h index 5262bfc..c28ab34 100644 --- a/src/module.h +++ b/src/module.h @@ -26,11 +26,13 @@ public: std::string dump(const std::string &indent) const; class AbstractNode *evaluate(const Context *ctx) const; + std::vector<AbstractNode*> evaluateChildren(const Context *ctx = NULL) const; }; class IfElseModuleInstantiation : public ModuleInstantiation { public: virtual ~IfElseModuleInstantiation(); + std::vector<AbstractNode*> evaluateElseChildren(const Context *ctx = NULL) const; std::vector<ModuleInstantiation*> else_children; }; diff --git a/src/projection.cc b/src/projection.cc index ce702e4..5a7ea6e 100644 --- a/src/projection.cc +++ b/src/projection.cc @@ -73,11 +73,8 @@ AbstractNode *ProjectionModule::evaluate(const Context *ctx, const ModuleInstant if (cut.type == Value::BOOL) node->cut_mode = cut.b; - foreach (ModuleInstantiation *v, inst->children) { - AbstractNode *n = v->evaluate(inst->ctx); - if (n) - node->children.push_back(n); - } + std::vector<AbstractNode *> evaluatednodes = inst->evaluateChildren(); + node->children.insert(node->children.end(), evaluatednodes.begin(), evaluatednodes.end()); return node; } diff --git a/src/render.cc b/src/render.cc index 15b4863..48a8535 100644 --- a/src/render.cc +++ b/src/render.cc @@ -62,11 +62,8 @@ AbstractNode *RenderModule::evaluate(const Context *ctx, const ModuleInstantiati if (v.type == Value::NUMBER) node->convexity = (int)v.num; - foreach (ModuleInstantiation *v, inst->children) { - AbstractNode *n = v->evaluate(inst->ctx); - if (n != NULL) - node->children.push_back(n); - } + std::vector<AbstractNode *> evaluatednodes = inst->evaluateChildren(); + node->children.insert(node->children.end(), evaluatednodes.begin(), evaluatednodes.end()); return node; } diff --git a/src/transform.cc b/src/transform.cc index 8975fd5..3308e0c 100644 --- a/src/transform.cc +++ b/src/transform.cc @@ -239,11 +239,8 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti } } - foreach (ModuleInstantiation *v, inst->children) { - AbstractNode *n = v->evaluate(inst->ctx); - if (n != NULL) - node->children.push_back(n); - } + vector<AbstractNode *> evaluatednodes = inst->evaluateChildren(); + node->children.insert(node->children.end(), evaluatednodes.begin(), evaluatednodes.end()); return node; } |