2009-07-17 04:34:15 +04:00
|
|
|
/*
|
2011-01-21 04:21:09 +03:00
|
|
|
* OpenSCAD (www.openscad.org)
|
|
|
|
* Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and
|
|
|
|
* Marius Kintel <marius@kintel.net>
|
2009-07-17 04:34:15 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2010-02-01 12:34:18 +03:00
|
|
|
* 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.
|
|
|
|
*
|
2009-07-17 04:34:15 +04:00
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-09-30 05:11:28 +04:00
|
|
|
#include "rotateextrudenode.h"
|
2010-01-30 07:26:05 +03:00
|
|
|
#include "module.h"
|
|
|
|
#include "context.h"
|
2010-01-06 13:48:51 +03:00
|
|
|
#include "printutils.h"
|
2010-01-30 07:26:05 +03:00
|
|
|
#include "builtin.h"
|
|
|
|
#include "polyset.h"
|
2010-03-02 21:22:31 +03:00
|
|
|
#include "visitor.h"
|
2011-07-31 03:58:51 +04:00
|
|
|
#include "PolySetEvaluator.h"
|
2010-01-30 07:26:05 +03:00
|
|
|
#include "openscad.h" // get_fragments_from_r()
|
2009-07-17 04:34:15 +04:00
|
|
|
|
2010-03-02 21:22:31 +03:00
|
|
|
#include <sstream>
|
2011-09-03 08:10:36 +04:00
|
|
|
#include <boost/assign/std/vector.hpp>
|
|
|
|
using namespace boost::assign; // bring 'operator+=()' into scope
|
2009-07-23 20:00:38 +04:00
|
|
|
|
2011-09-30 05:11:28 +04:00
|
|
|
class RotateExtrudeModule : public AbstractModule
|
2009-07-17 04:34:15 +04:00
|
|
|
{
|
|
|
|
public:
|
2011-09-30 05:11:28 +04:00
|
|
|
RotateExtrudeModule() { }
|
2010-01-06 22:38:45 +03:00
|
|
|
virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const;
|
2009-07-17 04:34:15 +04:00
|
|
|
};
|
|
|
|
|
2011-09-30 05:11:28 +04:00
|
|
|
AbstractNode *RotateExtrudeModule::evaluate(const Context *ctx, const ModuleInstantiation *inst) const
|
2009-07-17 04:34:15 +04:00
|
|
|
{
|
2011-09-30 05:11:28 +04:00
|
|
|
RotateExtrudeNode *node = new RotateExtrudeNode(inst);
|
2009-07-17 04:34:15 +04:00
|
|
|
|
2011-09-03 08:10:36 +04:00
|
|
|
std::vector<std::string> argnames;
|
|
|
|
argnames += "file", "layer", "origin", "scale";
|
|
|
|
std::vector<Expression*> argexpr;
|
2009-07-17 04:34:15 +04:00
|
|
|
|
|
|
|
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");
|
2009-07-20 21:45:39 +04:00
|
|
|
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);
|
2009-07-17 04:34:15 +04:00
|
|
|
|
2011-09-07 02:11:00 +04:00
|
|
|
if (!file.text.empty()) {
|
|
|
|
PRINTF("DEPRECATED: Support for reading files in rotate_extrude will be removed in future releases. Use a child import() instead.");
|
2011-09-03 20:51:29 +04:00
|
|
|
node->filename = c.getAbsolutePath(file.text);
|
2011-09-07 02:11:00 +04:00
|
|
|
}
|
2010-02-25 13:21:11 +03:00
|
|
|
|
2011-09-03 08:10:36 +04:00
|
|
|
node->layername = layer.text;
|
2009-08-10 11:18:35 +04:00
|
|
|
node->convexity = (int)convexity.num;
|
2009-07-20 21:45:39 +04:00
|
|
|
origin.getv2(node->origin_x, node->origin_y);
|
|
|
|
node->scale = scale.num;
|
2009-07-17 04:34:15 +04:00
|
|
|
|
|
|
|
if (node->convexity <= 0)
|
|
|
|
node->convexity = 1;
|
|
|
|
|
2009-07-20 21:45:39 +04:00
|
|
|
if (node->scale <= 0)
|
|
|
|
node->scale = 1;
|
|
|
|
|
2011-09-03 08:10:36 +04:00
|
|
|
if (node->filename.empty()) {
|
2011-09-04 22:35:23 +04:00
|
|
|
std::vector<AbstractNode *> evaluatednodes = inst->evaluateChildren();
|
|
|
|
node->children.insert(node->children.end(), evaluatednodes.begin(), evaluatednodes.end());
|
2010-01-07 23:49:27 +03:00
|
|
|
}
|
|
|
|
|
2009-07-17 04:34:15 +04:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2011-09-30 05:11:28 +04:00
|
|
|
PolySet *RotateExtrudeNode::evaluate_polyset(PolySetEvaluator *evaluator) const
|
2009-07-17 04:34:15 +04:00
|
|
|
{
|
2011-07-31 03:58:51 +04:00
|
|
|
if (!evaluator) {
|
|
|
|
PRINTF("WARNING: No suitable PolySetEvaluator found for %s module!", this->name().c_str());
|
2011-09-09 07:53:05 +04:00
|
|
|
return NULL;
|
2010-03-29 05:31:47 +04:00
|
|
|
}
|
|
|
|
|
2010-01-06 13:48:51 +03:00
|
|
|
print_messages_push();
|
2009-07-17 04:34:15 +04:00
|
|
|
|
2011-09-09 07:53:05 +04:00
|
|
|
PolySet *ps = evaluator->evaluatePolySet(*this);
|
2010-03-29 05:31:47 +04:00
|
|
|
|
2010-01-06 13:48:51 +03:00
|
|
|
print_messages_pop();
|
|
|
|
|
2009-07-17 04:34:15 +04:00
|
|
|
return ps;
|
|
|
|
}
|
|
|
|
|
2011-09-30 05:11:28 +04:00
|
|
|
std::string RotateExtrudeNode::toString() const
|
2010-03-02 21:22:31 +03:00
|
|
|
{
|
|
|
|
std::stringstream stream;
|
|
|
|
|
2011-09-12 05:46:13 +04:00
|
|
|
stream << this->name() << "(";
|
|
|
|
if (!this->filename.empty()) { // Ignore deprecated parameters if empty
|
|
|
|
stream <<
|
2011-11-07 06:59:40 +04:00
|
|
|
"file = " << this->filename << ", "
|
|
|
|
"layer = " << QuotedString(this->layername) << ", "
|
2011-11-06 06:25:59 +04:00
|
|
|
"origin = [" << std::dec << this->origin_x << ", " << this->origin_y << "], "
|
2011-09-12 05:46:13 +04:00
|
|
|
"scale = " << this->scale << ", ";
|
|
|
|
}
|
|
|
|
stream <<
|
2010-03-02 21:22:31 +03:00
|
|
|
"convexity = " << this->convexity << ", "
|
|
|
|
"$fn = " << this->fn << ", $fa = " << this->fa << ", $fs = " << this->fs << ")";
|
|
|
|
|
|
|
|
return stream.str();
|
|
|
|
}
|
2011-11-06 21:37:12 +04:00
|
|
|
|
|
|
|
void register_builtin_dxf_rotate_extrude()
|
|
|
|
{
|
|
|
|
Builtins::init("dxf_rotate_extrude", new RotateExtrudeModule());
|
|
|
|
Builtins::init("rotate_extrude", new RotateExtrudeModule());
|
|
|
|
}
|