|
| 1 | +/* |
| 2 | + * OpenSCAD (www.openscad.org) |
| 3 | + * Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and |
| 4 | + * Marius Kintel <marius@kintel.net> |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * As a special exception, you have permission to link this program |
| 12 | + * with the CGAL library and distribute executables, as long as you |
| 13 | + * follow the requirements of the GNU GPL in regard to all of the |
| 14 | + * software in the executable aside from CGAL. |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU General Public License |
| 22 | + * along with this program; if not, write to the Free Software |
| 23 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | + * |
| 25 | + */ |
| 26 | + |
| 27 | +#include "src/geometry/linalg.h" |
| 28 | +#include "src/geometry/GeometryUtils.h" |
| 29 | +#include "src/core/primitives.h" |
| 30 | +#include "src/core/TransformNode.h" |
| 31 | +#include "src/core/RotateExtrudeNode.h" |
| 32 | +#include "src/core/LinearExtrudeNode.h" |
| 33 | +#include "src/core/CgalAdvNode.h" |
| 34 | +#include "src/core/CsgOpNode.h" |
| 35 | +#include "src/core/ColorNode.h" |
| 36 | +#include "src/core/RoofNode.h" |
| 37 | +#include "src/core/RenderNode.h" |
| 38 | +#include "src/core/SurfaceNode.h" |
| 39 | +#include "src/core/TextNode.h" |
| 40 | +#include "src/core/OffsetNode.h" |
| 41 | +#include "src/core/ProjectionNode.h" |
| 42 | +#include "src/core/ImportNode.h" |
| 43 | + |
| 44 | +std::vector<ModuleInstantiation *> modinsts_list; |
| 45 | + |
| 46 | +#define NodeCloneFunc(T) std::shared_ptr<T> clone_what(const T *node) {\ |
| 47 | + ModuleInstantiation *inst = new ModuleInstantiation(node->modinst->name() ,\ |
| 48 | + node->modinst->arguments, node->modinst->location());\ |
| 49 | + modinsts_list.push_back(inst); \ |
| 50 | + auto clone = std::make_shared<T>(*node);\ |
| 51 | + clone->modinst = inst; \ |
| 52 | + return clone;\ |
| 53 | +} |
| 54 | + |
| 55 | +#define NodeCloneUse(T) { const T *node = dynamic_cast<const T *>(this); if((node) != nullptr) clone=clone_what(node); } |
| 56 | +NodeCloneFunc(CubeNode) |
| 57 | +NodeCloneFunc(SphereNode) |
| 58 | +NodeCloneFunc(CylinderNode) |
| 59 | +NodeCloneFunc(PolyhedronNode) |
| 60 | +NodeCloneFunc(SquareNode) |
| 61 | +NodeCloneFunc(CircleNode) |
| 62 | +NodeCloneFunc(PolygonNode) |
| 63 | +NodeCloneFunc(TransformNode) |
| 64 | +NodeCloneFunc(ColorNode) |
| 65 | +NodeCloneFunc(RotateExtrudeNode) |
| 66 | +NodeCloneFunc(LinearExtrudeNode) |
| 67 | +NodeCloneFunc(CsgOpNode) |
| 68 | +NodeCloneFunc(CgalAdvNode) |
| 69 | +NodeCloneFunc(RoofNode) |
| 70 | +NodeCloneFunc(RenderNode) |
| 71 | +NodeCloneFunc(SurfaceNode) |
| 72 | +NodeCloneFunc(TextNode) |
| 73 | +NodeCloneFunc(OffsetNode) |
| 74 | +NodeCloneFunc(ProjectionNode) |
| 75 | +NodeCloneFunc(GroupNode) |
| 76 | +NodeCloneFunc(ImportNode) |
| 77 | + |
| 78 | +std::shared_ptr<AbstractNode> AbstractNode::clone(void) |
| 79 | +{ |
| 80 | + std::shared_ptr<AbstractNode> clone=nullptr; |
| 81 | + NodeCloneUse(CubeNode) |
| 82 | + NodeCloneUse(SphereNode) |
| 83 | + NodeCloneUse(CylinderNode) |
| 84 | + NodeCloneUse(PolyhedronNode) |
| 85 | + NodeCloneUse(SquareNode) |
| 86 | + NodeCloneUse(CircleNode) |
| 87 | + NodeCloneUse(PolygonNode) |
| 88 | + NodeCloneUse(TransformNode) |
| 89 | + NodeCloneUse(ColorNode) |
| 90 | + NodeCloneUse(RotateExtrudeNode) |
| 91 | + NodeCloneUse(LinearExtrudeNode) |
| 92 | + NodeCloneUse(CsgOpNode) |
| 93 | + NodeCloneUse(CgalAdvNode) |
| 94 | + NodeCloneUse(RoofNode) |
| 95 | + NodeCloneUse(RenderNode) |
| 96 | + NodeCloneUse(SurfaceNode) |
| 97 | + NodeCloneUse(TextNode) |
| 98 | + NodeCloneUse(OffsetNode) |
| 99 | + NodeCloneUse(ProjectionNode) |
| 100 | + NodeCloneUse(GroupNode) |
| 101 | + NodeCloneUse(ImportNode) |
| 102 | + if(clone != nullptr) { |
| 103 | + clone->idx = idx_counter++; |
| 104 | + clone->children.clear(); |
| 105 | + for(const auto &child: this->children) { |
| 106 | + clone->children.push_back(child->clone()); |
| 107 | + } |
| 108 | + return clone; |
| 109 | + } |
| 110 | + std::cout << "Type not defined for clone :" << typeid(this).name() << "\n\r"; |
| 111 | + return std::shared_ptr<AbstractNode>(this); |
| 112 | +} |
0 commit comments