2010-01-30 10:41:55 +03: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>
|
2010-01-30 10:41:55 +03: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.
|
|
|
|
*
|
2010-01-30 10:41:55 +03: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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-03-02 21:22:31 +03:00
|
|
|
#include "projectionnode.h"
|
2010-01-30 10:41:55 +03:00
|
|
|
#include "module.h"
|
2013-04-09 08:28:16 +04:00
|
|
|
#include "evalcontext.h"
|
2010-01-30 10:41:55 +03:00
|
|
|
#include "printutils.h"
|
|
|
|
#include "builtin.h"
|
2010-03-02 21:22:31 +03:00
|
|
|
#include "visitor.h"
|
2013-03-28 01:50:25 +04:00
|
|
|
#include "polyset.h"
|
2010-01-30 10:41:55 +03:00
|
|
|
|
|
|
|
#include <assert.h>
|
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
|
2010-01-30 10:41:55 +03:00
|
|
|
|
|
|
|
class ProjectionModule : public AbstractModule
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ProjectionModule() { }
|
2014-11-17 08:57:36 +03:00
|
|
|
virtual AbstractNode *instantiate(const Context *ctx, const ModuleInstantiation *inst, EvalContext *evalctx) const;
|
2010-01-30 10:41:55 +03:00
|
|
|
};
|
|
|
|
|
2014-11-17 08:57:36 +03:00
|
|
|
AbstractNode *ProjectionModule::instantiate(const Context *ctx, const ModuleInstantiation *inst, EvalContext *evalctx) const
|
2010-01-30 10:41:55 +03:00
|
|
|
{
|
|
|
|
ProjectionNode *node = new ProjectionNode(inst);
|
|
|
|
|
2013-04-19 02:34:14 +04:00
|
|
|
AssignmentList args;
|
2014-03-23 22:38:28 +04:00
|
|
|
args += Assignment("cut");
|
2010-01-30 10:41:55 +03:00
|
|
|
|
|
|
|
Context c(ctx);
|
2013-04-19 02:34:14 +04:00
|
|
|
c.setVariables(args, evalctx);
|
2014-11-25 08:45:00 +03:00
|
|
|
inst->scope.apply(*evalctx);
|
2010-01-30 10:41:55 +03:00
|
|
|
|
2014-11-23 08:59:17 +03:00
|
|
|
ValuePtr convexity = c.lookup_variable("convexity", true);
|
|
|
|
ValuePtr cut = c.lookup_variable("cut", true);
|
2010-01-30 10:41:55 +03:00
|
|
|
|
2014-11-23 08:59:17 +03:00
|
|
|
node->convexity = (int)convexity->toDouble();
|
2010-01-30 10:41:55 +03:00
|
|
|
|
2014-11-23 08:59:17 +03:00
|
|
|
if (cut->type() == Value::BOOL)
|
|
|
|
node->cut_mode = cut->toBool();
|
2010-01-30 10:41:55 +03:00
|
|
|
|
2013-04-20 01:52:01 +04:00
|
|
|
std::vector<AbstractNode *> instantiatednodes = inst->instantiateChildren(evalctx);
|
|
|
|
node->children.insert(node->children.end(), instantiatednodes.begin(), instantiatednodes.end());
|
2010-01-30 10:41:55 +03:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2010-03-02 21:22:31 +03:00
|
|
|
std::string ProjectionNode::toString() const
|
|
|
|
{
|
|
|
|
std::stringstream stream;
|
|
|
|
|
|
|
|
stream << "projection(cut = " << (this->cut_mode ? "true" : "false")
|
|
|
|
<< ", convexity = " << this->convexity << ")";
|
|
|
|
|
|
|
|
return stream.str();
|
|
|
|
}
|
2010-04-12 04:16:36 +04:00
|
|
|
|
|
|
|
void register_builtin_projection()
|
|
|
|
{
|
2011-11-06 21:37:12 +04:00
|
|
|
Builtins::init("projection", new ProjectionModule());
|
2010-04-12 04:16:36 +04:00
|
|
|
}
|