Commit 8c96cbb7 authored by Dennis Gläser's avatar Dennis Gläser
Browse files

Merge branch 'feature/python-shape-wrapper-conversion' into 'master'

[python][brepwrapper] add ctor from shape wrapper

See merge request tools/frackit!209
parents 2cea4ea0 0b0d6a5d
Pipeline #3532 passed with stages
in 11 minutes and 48 seconds
......@@ -20,8 +20,10 @@
#include <type_traits>
#include <stdexcept>
#include <BRep_Builder.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Solid.hxx>
#include <TopoDS_Shell.hxx>
......@@ -45,6 +47,28 @@ public:
BRepWrapper(const Shape& shape) : shape_(shape) {}
BRepWrapper(Shape&& shape) : shape_(std::move(shape)) {}
//! construction from wrapper around shape
template<class OtherShape,
std::enable_if_t<std::is_same_v<OtherShape, TopoDS_Shape>, int> = 0>
BRepWrapper(const BRepWrapper<OtherShape>& wrapper)
if constexpr (std::is_same_v<S, TopoDS_Solid>)
shape_ = TopoDS::Solid(wrapper.get());
else if constexpr (std::is_same_v<S, TopoDS_Shell>)
shape_ = TopoDS::Shell(wrapper.get());
else if constexpr (std::is_same_v<S, TopoDS_Face>)
shape_ = TopoDS::Face(wrapper.get());
else if constexpr (std::is_same_v<S, TopoDS_Wire>)
shape_ = TopoDS::Wire(wrapper.get());
else if constexpr (std::is_same_v<S, TopoDS_Edge>)
shape_ = TopoDS::Edge(wrapper.get());
else if constexpr (std::is_same_v<S, TopoDS_Vertex>)
shape_ = TopoDS::Vertex(wrapper.get());
throw std::runtime_error("Incompatible wrapper type");
const Shape& get() const { return shape_; }
std::string name() const { return geometryName(get()) + "_Wrapper"; }
......@@ -41,9 +41,9 @@ namespace Detail {
// add constructor from other shape wrappers
namespace py = pybind11;
if constexpr(std::is_same_v<Shape, TopoDS_Shape>)
namespace py = pybind11;
cls.def(py::init<ShapeWrapper>(), "construction from another brep wrapper");
cls.def(py::init<VertexWrapper>(), "construction from another brep wrapper");
cls.def(py::init<EdgeWrapper>(), "construction from another brep wrapper");
......@@ -53,6 +53,8 @@ namespace Detail {
cls.def(py::init<SolidWrapper>(), "construction from another brep wrapper");
cls.def(py::init<CompoundWrapper>(), "construction from another brep wrapper");
else if constexpr(!std::is_same_v<Shape, TopoDS_Compound>)
cls.def(py::init<ShapeWrapper>(), "construction from a brep shape wrapper");
void registerCompoundWrapper(pybind11::module& module)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment