From bf3fb9634c44bcd28a4e2faede72052daa1f966c Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Fri, 30 Sep 2011 03:11:28 +0200 Subject: Renamed some files and classnames for clarification diff --git a/openscad.pro b/openscad.pro index 6e79b29..765ff6b 100644 --- a/openscad.pro +++ b/openscad.pro @@ -139,8 +139,8 @@ HEADERS += src/renderer.h \ src/module.h \ src/node.h \ src/csgnode.h \ - src/dxflinextrudenode.h \ - src/dxfrotextrudenode.h \ + src/linearextrudenode.h \ + src/rotateextrudenode.h \ src/projectionnode.h \ src/cgaladvnode.h \ src/importnode.h \ @@ -197,8 +197,8 @@ SOURCES += src/openscad.cc \ src/dxftess-glu.cc \ src/dxftess-cgal.cc \ src/dxfdim.cc \ - src/dxflinextrude.cc \ - src/dxfrotextrude.cc \ + src/linearextrude.cc \ + src/rotateextrude.cc \ src/highlighter.cc \ src/printutils.cc \ src/Preferences.cc \ diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc index b019ad5..7f62d0a 100644 --- a/src/PolySetCGALEvaluator.cc +++ b/src/PolySetCGALEvaluator.cc @@ -4,8 +4,8 @@ #include "polyset.h" #include "CGALEvaluator.h" #include "projectionnode.h" -#include "dxflinextrudenode.h" -#include "dxfrotextrudenode.h" +#include "linearextrudenode.h" +#include "rotateextrudenode.h" #include "cgaladvnode.h" #include "rendernode.h" #include "dxfdata.h" @@ -251,7 +251,7 @@ static void add_slice(PolySet *ps, const DxfData &dxf, DxfData::Path &path, doub } } -PolySet *PolySetCGALEvaluator::evaluatePolySet(const DxfLinearExtrudeNode &node) +PolySet *PolySetCGALEvaluator::evaluatePolySet(const LinearExtrudeNode &node) { DxfData *dxf; @@ -283,7 +283,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const DxfLinearExtrudeNode &node) return ps; } -PolySet *PolySetCGALEvaluator::extrudeDxfData(const DxfLinearExtrudeNode &node, DxfData &dxf) +PolySet *PolySetCGALEvaluator::extrudeDxfData(const LinearExtrudeNode &node, DxfData &dxf) { PolySet *ps = new PolySet(); ps->convexity = node.convexity; @@ -349,7 +349,7 @@ PolySet *PolySetCGALEvaluator::extrudeDxfData(const DxfLinearExtrudeNode &node, return ps; } -PolySet *PolySetCGALEvaluator::evaluatePolySet(const DxfRotateExtrudeNode &node) +PolySet *PolySetCGALEvaluator::evaluatePolySet(const RotateExtrudeNode &node) { DxfData *dxf; @@ -398,7 +398,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const RenderNode &node) return ps; } -PolySet *PolySetCGALEvaluator::rotateDxfData(const DxfRotateExtrudeNode &node, DxfData &dxf) +PolySet *PolySetCGALEvaluator::rotateDxfData(const RotateExtrudeNode &node, DxfData &dxf) { PolySet *ps = new PolySet(); ps->convexity = node.convexity; diff --git a/src/PolySetCGALEvaluator.h b/src/PolySetCGALEvaluator.h index 2aa5b13..dddcfc5 100644 --- a/src/PolySetCGALEvaluator.h +++ b/src/PolySetCGALEvaluator.h @@ -13,14 +13,14 @@ public: PolySetCGALEvaluator(class CGALEvaluator &cgalevaluator); virtual ~PolySetCGALEvaluator() { } virtual PolySet *evaluatePolySet(const ProjectionNode &node); - virtual PolySet *evaluatePolySet(const DxfLinearExtrudeNode &node); - virtual PolySet *evaluatePolySet(const DxfRotateExtrudeNode &node); + virtual PolySet *evaluatePolySet(const LinearExtrudeNode &node); + virtual PolySet *evaluatePolySet(const RotateExtrudeNode &node); virtual PolySet *evaluatePolySet(const CgaladvNode &node); virtual PolySet *evaluatePolySet(const RenderNode &node); protected: - PolySet *extrudeDxfData(const DxfLinearExtrudeNode &node, class DxfData &dxf); - PolySet *rotateDxfData(const DxfRotateExtrudeNode &node, class DxfData &dxf); + PolySet *extrudeDxfData(const LinearExtrudeNode &node, class DxfData &dxf); + PolySet *rotateDxfData(const RotateExtrudeNode &node, class DxfData &dxf); CGALEvaluator &cgalevaluator; }; diff --git a/src/PolySetEvaluator.h b/src/PolySetEvaluator.h index 833b079..8d7d1a8 100644 --- a/src/PolySetEvaluator.h +++ b/src/PolySetEvaluator.h @@ -16,8 +16,8 @@ public: virtual shared_ptr getPolySet(const class AbstractNode &, bool cache); virtual PolySet *evaluatePolySet(const class ProjectionNode &) { return NULL; } - virtual PolySet *evaluatePolySet(const class DxfLinearExtrudeNode &) { return NULL; } - virtual PolySet *evaluatePolySet(const class DxfRotateExtrudeNode &) { return NULL; } + virtual PolySet *evaluatePolySet(const class LinearExtrudeNode &) { return NULL; } + virtual PolySet *evaluatePolySet(const class RotateExtrudeNode &) { return NULL; } virtual PolySet *evaluatePolySet(const class CgaladvNode &) { return NULL; } virtual PolySet *evaluatePolySet(const class RenderNode &) { return NULL; } diff --git a/src/dxflinextrude.cc b/src/dxflinextrude.cc deleted file mode 100644 index 8bb246f..0000000 --- a/src/dxflinextrude.cc +++ /dev/null @@ -1,167 +0,0 @@ -/* - * OpenSCAD (www.openscad.org) - * Copyright (C) 2009-2011 Clifford Wolf and - * Marius Kintel - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * As a special exception, you have permission to link this program - * with the CGAL library and distribute executables, as long as you - * follow the requirements of the GNU GPL in regard to all of the - * software in the executable aside from CGAL. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include "dxflinextrudenode.h" - -#include "module.h" -#include "context.h" -#include "printutils.h" -#include "builtin.h" -#include "dxfdata.h" -#include "dxftess.h" -#include "polyset.h" -#include "progress.h" -#include "visitor.h" -#include "PolySetEvaluator.h" -#include "openscad.h" // get_fragments_from_r() - -#include -#include -using namespace boost::assign; // bring 'operator+=()' into scope - -#include - -class DxfLinearExtrudeModule : public AbstractModule -{ -public: - DxfLinearExtrudeModule() { } - virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const; -}; - -AbstractNode *DxfLinearExtrudeModule::evaluate(const Context *ctx, const ModuleInstantiation *inst) const -{ - DxfLinearExtrudeNode *node = new DxfLinearExtrudeNode(inst); - - std::vector argnames; - argnames += "file", "layer", "height", "origin", "scale", "center", "twist", "slices"; - std::vector argexpr; - - Context c(ctx); - c.args(argnames, argexpr, inst->argnames, inst->argvalues); - - node->fn = c.lookup_variable("$fn").num; - node->fs = c.lookup_variable("$fs").num; - node->fa = c.lookup_variable("$fa").num; - - Value file = c.lookup_variable("file"); - Value layer = c.lookup_variable("layer", true); - Value height = c.lookup_variable("height", true); - Value convexity = c.lookup_variable("convexity", true); - Value origin = c.lookup_variable("origin", true); - Value scale = c.lookup_variable("scale", true); - Value center = c.lookup_variable("center", true); - Value twist = c.lookup_variable("twist", true); - Value slices = c.lookup_variable("slices", true); - - if (!file.text.empty()) { - PRINTF("DEPRECATED: Support for reading files in linear_extrude will be removed in future releases. Use a child import() instead."); - node->filename = c.getAbsolutePath(file.text); - } - - node->layername = layer.text; - node->height = height.num; - node->convexity = (int)convexity.num; - origin.getv2(node->origin_x, node->origin_y); - node->scale = scale.num; - - if (center.type == Value::BOOL) - node->center = center.b; - - if (node->height <= 0) - node->height = 100; - - if (node->convexity <= 0) - node->convexity = 1; - - if (node->scale <= 0) - node->scale = 1; - - if (twist.type == Value::NUMBER) { - node->twist = twist.num; - if (slices.type == Value::NUMBER) { - node->slices = (int)slices.num; - } else { - node->slices = (int)fmax(2, fabs(get_fragments_from_r(node->height, - node->fn, node->fs, node->fa) * node->twist / 360)); - } - node->has_twist = true; - } - - if (node->filename.empty()) { - std::vector evaluatednodes = inst->evaluateChildren(); - node->children.insert(node->children.end(), evaluatednodes.begin(), evaluatednodes.end()); - } - - return node; -} - -void register_builtin_dxf_linear_extrude() -{ - builtin_modules["dxf_linear_extrude"] = new DxfLinearExtrudeModule(); - builtin_modules["linear_extrude"] = new DxfLinearExtrudeModule(); -} - -PolySet *DxfLinearExtrudeNode::evaluate_polyset(PolySetEvaluator *evaluator) const -{ - if (!evaluator) { - PRINTF("WARNING: No suitable PolySetEvaluator found for %s module!", this->name().c_str()); - return NULL; - } - - print_messages_push(); - - PolySet *ps = evaluator->evaluatePolySet(*this); - - print_messages_pop(); - - return ps; -} - -std::string DxfLinearExtrudeNode::toString() const -{ - std::stringstream stream; - - stream << this->name() << "("; - if (!this->filename.empty()) { // Ignore deprecated parameters if empty - stream << - "file = \"" << this->filename << "\", " - "cache = \"" << QFileInfo(QString::fromStdString(this->filename)) << "\", " - "layer = \"" << this->layername << "\", " - "origin = [ " << this->origin_x << " " << this->origin_y << " ], " - "scale = " << this->scale << ", "; - } - stream << - "height = " << std::dec << this->height << ", " - "center = " << (this->center?"true":"false") << ", " - "convexity = " << this->convexity; - - if (this->has_twist) { - stream << ", twist = " << this->twist << ", slices = " << this->slices; - } - stream << ", $fn = " << this->fn << ", $fa = " << this->fa << ", $fs = " << this->fs << ")"; - - return stream.str(); -} diff --git a/src/dxflinextrudenode.h b/src/dxflinextrudenode.h deleted file mode 100644 index 360fd28..0000000 --- a/src/dxflinextrudenode.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef DXFLINEXTRUDENODE_H_ -#define DXFLINEXTRUDENODE_H_ - -#include "node.h" -#include "visitor.h" - -class DxfLinearExtrudeNode : public AbstractPolyNode -{ -public: - DxfLinearExtrudeNode(const ModuleInstantiation *mi) : AbstractPolyNode(mi) { - convexity = slices = 0; - fn = fs = fa = height = twist = 0; - origin_x = origin_y = scale = 0; - center = has_twist = false; - } - 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 "linear_extrude"; } - - int convexity, slices; - double fn, fs, fa, height, twist; - double origin_x, origin_y, scale; - bool center, has_twist; - std::string filename, layername; - virtual PolySet *evaluate_polyset(class PolySetEvaluator *) const; -}; - -#endif diff --git a/src/dxfrotextrude.cc b/src/dxfrotextrude.cc deleted file mode 100644 index 646b643..0000000 --- a/src/dxfrotextrude.cc +++ /dev/null @@ -1,137 +0,0 @@ -/* - * OpenSCAD (www.openscad.org) - * Copyright (C) 2009-2011 Clifford Wolf and - * Marius Kintel - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * As a special exception, you have permission to link this program - * with the CGAL library and distribute executables, as long as you - * follow the requirements of the GNU GPL in regard to all of the - * software in the executable aside from CGAL. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include "dxfrotextrudenode.h" -#include "module.h" -#include "context.h" -#include "printutils.h" -#include "builtin.h" -#include "polyset.h" -#include "dxfdata.h" -#include "progress.h" -#include "visitor.h" -#include "PolySetEvaluator.h" -#include "openscad.h" // get_fragments_from_r() - -#include -#include -using namespace boost::assign; // bring 'operator+=()' into scope - -#include - -class DxfRotateExtrudeModule : public AbstractModule -{ -public: - DxfRotateExtrudeModule() { } - virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const; -}; - -AbstractNode *DxfRotateExtrudeModule::evaluate(const Context *ctx, const ModuleInstantiation *inst) const -{ - DxfRotateExtrudeNode *node = new DxfRotateExtrudeNode(inst); - - std::vector argnames; - argnames += "file", "layer", "origin", "scale"; - std::vector argexpr; - - Context c(ctx); - c.args(argnames, argexpr, inst->argnames, inst->argvalues); - - node->fn = c.lookup_variable("$fn").num; - node->fs = c.lookup_variable("$fs").num; - node->fa = c.lookup_variable("$fa").num; - - Value file = c.lookup_variable("file"); - Value layer = c.lookup_variable("layer", true); - Value convexity = c.lookup_variable("convexity", true); - Value origin = c.lookup_variable("origin", true); - Value scale = c.lookup_variable("scale", true); - - if (!file.text.empty()) { - PRINTF("DEPRECATED: Support for reading files in rotate_extrude will be removed in future releases. Use a child import() instead."); - node->filename = c.getAbsolutePath(file.text); - } - - node->layername = layer.text; - node->convexity = (int)convexity.num; - origin.getv2(node->origin_x, node->origin_y); - node->scale = scale.num; - - if (node->convexity <= 0) - node->convexity = 1; - - if (node->scale <= 0) - node->scale = 1; - - if (node->filename.empty()) { - std::vector evaluatednodes = inst->evaluateChildren(); - node->children.insert(node->children.end(), evaluatednodes.begin(), evaluatednodes.end()); - } - - return node; -} - -void register_builtin_dxf_rotate_extrude() -{ - builtin_modules["dxf_rotate_extrude"] = new DxfRotateExtrudeModule(); - builtin_modules["rotate_extrude"] = new DxfRotateExtrudeModule(); -} - -PolySet *DxfRotateExtrudeNode::evaluate_polyset(PolySetEvaluator *evaluator) const -{ - if (!evaluator) { - PRINTF("WARNING: No suitable PolySetEvaluator found for %s module!", this->name().c_str()); - return NULL; - } - - print_messages_push(); - - PolySet *ps = evaluator->evaluatePolySet(*this); - - print_messages_pop(); - - return ps; -} - -std::string DxfRotateExtrudeNode::toString() const -{ - std::stringstream stream; - - stream << this->name() << "("; - if (!this->filename.empty()) { // Ignore deprecated parameters if empty - stream << - "file = \"" << this->filename << "\", " - "cache = \"" << QFileInfo(QString::fromStdString(this->filename)) << "\", " - "layer = \"" << this->layername << "\", " - "origin = [ " << std::dec << this->origin_x << " " << this->origin_y << " ], " - "scale = " << this->scale << ", "; - } - stream << - "convexity = " << this->convexity << ", " - "$fn = " << this->fn << ", $fa = " << this->fa << ", $fs = " << this->fs << ")"; - - return stream.str(); -} diff --git a/src/dxfrotextrudenode.h b/src/dxfrotextrudenode.h deleted file mode 100644 index e0ade82..0000000 --- a/src/dxfrotextrudenode.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef DXFROTEXTRUDENODE_H_ -#define DXFROTEXTRUDENODE_H_ - -#include "node.h" -#include "visitor.h" - -class DxfRotateExtrudeNode : public AbstractPolyNode -{ -public: - DxfRotateExtrudeNode(const ModuleInstantiation *mi) : AbstractPolyNode(mi) { - convexity = 0; - fn = fs = fa = 0; - origin_x = origin_y = scale = 0; - } - 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 "rotate_extrude"; } - - int convexity; - double fn, fs, fa; - double origin_x, origin_y, scale; - std::string filename, layername; - virtual PolySet *evaluate_polyset(class PolySetEvaluator *) const; -}; - -#endif diff --git a/src/linearextrude.cc b/src/linearextrude.cc new file mode 100644 index 0000000..4ce87db --- /dev/null +++ b/src/linearextrude.cc @@ -0,0 +1,167 @@ +/* + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf and + * Marius Kintel + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * As a special exception, you have permission to link this program + * with the CGAL library and distribute executables, as long as you + * follow the requirements of the GNU GPL in regard to all of the + * software in the executable aside from CGAL. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "linearextrudenode.h" + +#include "module.h" +#include "context.h" +#include "printutils.h" +#include "builtin.h" +#include "dxfdata.h" +#include "dxftess.h" +#include "polyset.h" +#include "progress.h" +#include "visitor.h" +#include "PolySetEvaluator.h" +#include "openscad.h" // get_fragments_from_r() + +#include +#include +using namespace boost::assign; // bring 'operator+=()' into scope + +#include + +class LinearExtrudeModule : public AbstractModule +{ +public: + LinearExtrudeModule() { } + virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const; +}; + +AbstractNode *LinearExtrudeModule::evaluate(const Context *ctx, const ModuleInstantiation *inst) const +{ + LinearExtrudeNode *node = new LinearExtrudeNode(inst); + + std::vector argnames; + argnames += "file", "layer", "height", "origin", "scale", "center", "twist", "slices"; + std::vector argexpr; + + Context c(ctx); + c.args(argnames, argexpr, inst->argnames, inst->argvalues); + + node->fn = c.lookup_variable("$fn").num; + node->fs = c.lookup_variable("$fs").num; + node->fa = c.lookup_variable("$fa").num; + + Value file = c.lookup_variable("file"); + Value layer = c.lookup_variable("layer", true); + Value height = c.lookup_variable("height", true); + Value convexity = c.lookup_variable("convexity", true); + Value origin = c.lookup_variable("origin", true); + Value scale = c.lookup_variable("scale", true); + Value center = c.lookup_variable("center", true); + Value twist = c.lookup_variable("twist", true); + Value slices = c.lookup_variable("slices", true); + + if (!file.text.empty()) { + PRINTF("DEPRECATED: Support for reading files in linear_extrude will be removed in future releases. Use a child import() instead."); + node->filename = c.getAbsolutePath(file.text); + } + + node->layername = layer.text; + node->height = height.num; + node->convexity = (int)convexity.num; + origin.getv2(node->origin_x, node->origin_y); + node->scale = scale.num; + + if (center.type == Value::BOOL) + node->center = center.b; + + if (node->height <= 0) + node->height = 100; + + if (node->convexity <= 0) + node->convexity = 1; + + if (node->scale <= 0) + node->scale = 1; + + if (twist.type == Value::NUMBER) { + node->twist = twist.num; + if (slices.type == Value::NUMBER) { + node->slices = (int)slices.num; + } else { + node->slices = (int)fmax(2, fabs(get_fragments_from_r(node->height, + node->fn, node->fs, node->fa) * node->twist / 360)); + } + node->has_twist = true; + } + + if (node->filename.empty()) { + std::vector evaluatednodes = inst->evaluateChildren(); + node->children.insert(node->children.end(), evaluatednodes.begin(), evaluatednodes.end()); + } + + return node; +} + +void register_builtin_dxf_linear_extrude() +{ + builtin_modules["dxf_linear_extrude"] = new LinearExtrudeModule(); + builtin_modules["linear_extrude"] = new LinearExtrudeModule(); +} + +PolySet *LinearExtrudeNode::evaluate_polyset(PolySetEvaluator *evaluator) const +{ + if (!evaluator) { + PRINTF("WARNING: No suitable PolySetEvaluator found for %s module!", this->name().c_str()); + return NULL; + } + + print_messages_push(); + + PolySet *ps = evaluator->evaluatePolySet(*this); + + print_messages_pop(); + + return ps; +} + +std::string LinearExtrudeNode::toString() const +{ + std::stringstream stream; + + stream << this->name() << "("; + if (!this->filename.empty()) { // Ignore deprecated parameters if empty + stream << + "file = \"" << this->filename << "\", " + "cache = \"" << QFileInfo(QString::fromStdString(this->filename)) << "\", " + "layer = \"" << this->layername << "\", " + "origin = [ " << this->origin_x << " " << this->origin_y << " ], " + "scale = " << this->scale << ", "; + } + stream << + "height = " << std::dec << this->height << ", " + "center = " << (this->center?"true":"false") << ", " + "convexity = " << this->convexity; + + if (this->has_twist) { + stream << ", twist = " << this->twist << ", slices = " << this->slices; + } + stream << ", $fn = " << this->fn << ", $fa = " << this->fa << ", $fs = " << this->fs << ")"; + + return stream.str(); +} diff --git a/src/linearextrudenode.h b/src/linearextrudenode.h new file mode 100644 index 0000000..503f1bd --- /dev/null +++ b/src/linearextrudenode.h @@ -0,0 +1,30 @@ +#ifndef LINEAREXTRUDENODE_H_ +#define LINEAREXTRUDENODE_H_ + +#include "node.h" +#include "visitor.h" + +class LinearExtrudeNode : public AbstractPolyNode +{ +public: + LinearExtrudeNode(const ModuleInstantiation *mi) : AbstractPolyNode(mi) { + convexity = slices = 0; + fn = fs = fa = height = twist = 0; + origin_x = origin_y = scale = 0; + center = has_twist = false; + } + 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 "linear_extrude"; } + + int convexity, slices; + double fn, fs, fa, height, twist; + double origin_x, origin_y, scale; + bool center, has_twist; + std::string filename, layername; + virtual PolySet *evaluate_polyset(class PolySetEvaluator *) const; +}; + +#endif diff --git a/src/rotateextrude.cc b/src/rotateextrude.cc new file mode 100644 index 0000000..3a6eb55 --- /dev/null +++ b/src/rotateextrude.cc @@ -0,0 +1,137 @@ +/* + * OpenSCAD (www.openscad.org) + * Copyright (C) 2009-2011 Clifford Wolf and + * Marius Kintel + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * As a special exception, you have permission to link this program + * with the CGAL library and distribute executables, as long as you + * follow the requirements of the GNU GPL in regard to all of the + * software in the executable aside from CGAL. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "rotateextrudenode.h" +#include "module.h" +#include "context.h" +#include "printutils.h" +#include "builtin.h" +#include "polyset.h" +#include "dxfdata.h" +#include "progress.h" +#include "visitor.h" +#include "PolySetEvaluator.h" +#include "openscad.h" // get_fragments_from_r() + +#include +#include +using namespace boost::assign; // bring 'operator+=()' into scope + +#include + +class RotateExtrudeModule : public AbstractModule +{ +public: + RotateExtrudeModule() { } + virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const; +}; + +AbstractNode *RotateExtrudeModule::evaluate(const Context *ctx, const ModuleInstantiation *inst) const +{ + RotateExtrudeNode *node = new RotateExtrudeNode(inst); + + std::vector argnames; + argnames += "file", "layer", "origin", "scale"; + std::vector argexpr; + + Context c(ctx); + c.args(argnames, argexpr, inst->argnames, inst->argvalues); + + node->fn = c.lookup_variable("$fn").num; + node->fs = c.lookup_variable("$fs").num; + node->fa = c.lookup_variable("$fa").num; + + Value file = c.lookup_variable("file"); + Value layer = c.lookup_variable("layer", true); + Value convexity = c.lookup_variable("convexity", true); + Value origin = c.lookup_variable("origin", true); + Value scale = c.lookup_variable("scale", true); + + if (!file.text.empty()) { + PRINTF("DEPRECATED: Support for reading files in rotate_extrude will be removed in future releases. Use a child import() instead."); + node->filename = c.getAbsolutePath(file.text); + } + + node->layername = layer.text; + node->convexity = (int)convexity.num; + origin.getv2(node->origin_x, node->origin_y); + node->scale = scale.num; + + if (node->convexity <= 0) + node->convexity = 1; + + if (node->scale <= 0) + node->scale = 1; + + if (node->filename.empty()) { + std::vector evaluatednodes = inst->evaluateChildren(); + node->children.insert(node->children.end(), evaluatednodes.begin(), evaluatednodes.end()); + } + + return node; +} + +void register_builtin_dxf_rotate_extrude() +{ + builtin_modules["dxf_rotate_extrude"] = new RotateExtrudeModule(); + builtin_modules["rotate_extrude"] = new RotateExtrudeModule(); +} + +PolySet *RotateExtrudeNode::evaluate_polyset(PolySetEvaluator *evaluator) const +{ + if (!evaluator) { + PRINTF("WARNING: No suitable PolySetEvaluator found for %s module!", this->name().c_str()); + return NULL; + } + + print_messages_push(); + + PolySet *ps = evaluator->evaluatePolySet(*this); + + print_messages_pop(); + + return ps; +} + +std::string RotateExtrudeNode::toString() const +{ + std::stringstream stream; + + stream << this->name() << "("; + if (!this->filename.empty()) { // Ignore deprecated parameters if empty + stream << + "file = \"" << this->filename << "\", " + "cache = \"" << QFileInfo(QString::fromStdString(this->filename)) << "\", " + "layer = \"" << this->layername << "\", " + "origin = [ " << std::dec << this->origin_x << " " << this->origin_y << " ], " + "scale = " << this->scale << ", "; + } + stream << + "convexity = " << this->convexity << ", " + "$fn = " << this->fn << ", $fa = " << this->fa << ", $fs = " << this->fs << ")"; + + return stream.str(); +} diff --git a/src/rotateextrudenode.h b/src/rotateextrudenode.h new file mode 100644 index 0000000..613d44b --- /dev/null +++ b/src/rotateextrudenode.h @@ -0,0 +1,28 @@ +#ifndef ROTATEEXTRUDENODE_H_ +#define ROTATEEXTRUDENODE_H_ + +#include "node.h" +#include "visitor.h" + +class RotateExtrudeNode : public AbstractPolyNode +{ +public: + RotateExtrudeNode(const ModuleInstantiation *mi) : AbstractPolyNode(mi) { + convexity = 0; + fn = fs = fa = 0; + origin_x = origin_y = scale = 0; + } + 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 "rotate_extrude"; } + + int convexity; + double fn, fs, fa; + double origin_x, origin_y, scale; + std::string filename, layername; + virtual PolySet *evaluate_polyset(class PolySetEvaluator *) const; +}; + +#endif diff --git a/src/visitor.h b/src/visitor.h index f4846b8..fe350f8 100644 --- a/src/visitor.h +++ b/src/visitor.h @@ -22,10 +22,10 @@ public: virtual Response visit(class State &state, const class CsgNode &node) { return visit(state, (const class AbstractNode &)node); } - virtual Response visit(class State &state, const class DxfLinearExtrudeNode &node) { + virtual Response visit(class State &state, const class LinearExtrudeNode &node) { return visit(state, (const class AbstractPolyNode &)node); } - virtual Response visit(class State &state, const class DxfRotateExtrudeNode &node) { + virtual Response visit(class State &state, const class RotateExtrudeNode &node) { return visit(state, (const class AbstractPolyNode &)node); } virtual Response visit(class State &state, const class ImportNode &node) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b92ee22..4b6a9dd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -103,8 +103,8 @@ set(COMMON_SOURCES ../src/dxfdata.cc ../src/dxftess.cc ../src/dxfdim.cc - ../src/dxflinextrude.cc - ../src/dxfrotextrude.cc + ../src/linearextrude.cc + ../src/rotateextrude.cc ../src/printutils.cc ../src/progress.cc ../src/nodedumper.cc -- cgit v0.10.1