2009-06-21 15:41:11 +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-06-21 15:41:11 +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-06-21 15:41:11 +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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-03-02 21:22:31 +03:00
|
|
|
#include "csgnode.h"
|
|
|
|
|
2013-04-09 08:28:16 +04:00
|
|
|
#include "evalcontext.h"
|
2010-01-30 07:26:05 +03:00
|
|
|
#include "module.h"
|
|
|
|
#include "csgterm.h"
|
|
|
|
#include "builtin.h"
|
2010-03-02 21:22:31 +03:00
|
|
|
#include <sstream>
|
2010-03-28 19:57:39 +04:00
|
|
|
#include <assert.h>
|
2009-06-23 02:36:36 +04:00
|
|
|
|
|
|
|
class CsgModule : public AbstractModule
|
2009-06-21 15:41:11 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-11-05 10:20:27 +04:00
|
|
|
OpenSCADOperator type;
|
|
|
|
CsgModule(OpenSCADOperator type) : type(type) { }
|
2014-11-17 08:57:36 +03:00
|
|
|
virtual AbstractNode *instantiate(const Context *ctx, const ModuleInstantiation *inst, EvalContext *evalctx) const;
|
2009-06-21 15:41:11 +04:00
|
|
|
};
|
|
|
|
|
2014-11-17 08:57:36 +03:00
|
|
|
AbstractNode *CsgModule::instantiate(const Context*, const ModuleInstantiation *inst, EvalContext *evalctx) const
|
2009-06-21 15:41:11 +04:00
|
|
|
{
|
2014-11-25 08:45:00 +03:00
|
|
|
inst->scope.apply(*evalctx);
|
2009-07-01 13:48:25 +04:00
|
|
|
CsgNode *node = new CsgNode(inst, type);
|
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());
|
2009-06-21 15:41:11 +04:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2010-03-02 21:22:31 +03:00
|
|
|
std::string CsgNode::toString() const
|
|
|
|
{
|
2010-08-28 23:21:44 +04:00
|
|
|
return this->name() + "()";
|
|
|
|
}
|
2010-03-02 21:22:31 +03:00
|
|
|
|
2010-08-28 23:21:44 +04:00
|
|
|
std::string CsgNode::name() const
|
|
|
|
{
|
2010-03-02 21:22:31 +03:00
|
|
|
switch (this->type) {
|
2013-11-05 10:20:27 +04:00
|
|
|
case OPENSCAD_UNION:
|
2010-08-28 23:21:44 +04:00
|
|
|
return "union";
|
2010-03-02 21:22:31 +03:00
|
|
|
break;
|
2013-11-05 10:20:27 +04:00
|
|
|
case OPENSCAD_DIFFERENCE:
|
2010-08-28 23:21:44 +04:00
|
|
|
return "difference";
|
2010-03-02 21:22:31 +03:00
|
|
|
break;
|
2013-11-05 10:20:27 +04:00
|
|
|
case OPENSCAD_INTERSECTION:
|
2010-08-28 23:21:44 +04:00
|
|
|
return "intersection";
|
2010-03-02 21:22:31 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
}
|
2013-05-26 07:37:26 +04:00
|
|
|
return "internal_error";
|
2010-03-02 21:22:31 +03:00
|
|
|
}
|
|
|
|
|
2009-06-30 00:30:43 +04:00
|
|
|
void register_builtin_csgops()
|
2009-06-21 15:41:11 +04:00
|
|
|
{
|
2013-11-05 10:20:27 +04:00
|
|
|
Builtins::init("union", new CsgModule(OPENSCAD_UNION));
|
|
|
|
Builtins::init("difference", new CsgModule(OPENSCAD_DIFFERENCE));
|
|
|
|
Builtins::init("intersection", new CsgModule(OPENSCAD_INTERSECTION));
|
2009-06-21 15:41:11 +04:00
|
|
|
}
|
|
|
|
|