diff --git a/src/ifcgeom/ConversionResult.h b/src/ifcgeom/ConversionResult.h index 7ce7eb46c7..773c296c5f 100644 --- a/src/ifcgeom/ConversionResult.h +++ b/src/ifcgeom/ConversionResult.h @@ -95,7 +95,8 @@ namespace IfcGeom { virtual std::shared_ptr divide(const NumberConcept& other) const = 0; virtual std::shared_ptr negate() const = 0; virtual std::shared_ptr from_double(double value) const = 0; - virtual bool equals(const NumberConcept& other) const = 0; + virtual std::shared_ptr from_int(int value) const = 0; + virtual bool equals(const NumberConcept& other) const = 0; virtual bool less_than(const NumberConcept& other) const = 0; virtual const std::type_info& type() const = 0; virtual const void* value_ptr() const = 0; @@ -165,6 +166,10 @@ namespace IfcGeom { return std::make_shared(T(v)); } + virtual std::shared_ptr from_int(int v) const { + return std::make_shared(T(v)); + } + virtual bool equals(const NumberConcept& other) const { return value == as_same(other).value; } @@ -255,10 +260,19 @@ namespace IfcGeom { return OpaqueNumber(data().negate()); } + OpaqueNumber abs() const { + auto zero = data().from_int(0); + return OpaqueNumber(data().less_than(*zero) ? data().negate() : *this); + } + OpaqueNumber same_type(double value) const { return OpaqueNumber(data().from_double(value)); } + OpaqueNumber same_type(int value) const { + return OpaqueNumber(data().from_int(value)); + } + bool equals(const OpaqueNumber& other) const { return data().equals(other.data()); } @@ -336,7 +350,7 @@ namespace IfcGeom { } } - std::vector to_doubles() const { + std::vector to_double() const { std::vector result; result.reserve(N); for (const auto& value : values_) { @@ -436,6 +450,8 @@ namespace IfcGeom { class IFC_GEOM_API ConversionResultShape { public: + virtual std::string type() const = 0; + virtual void Triangulate(ifcopenshell::geometry::Settings settings, const ifcopenshell::geometry::taxonomy::matrix4& place, Representation::Triangulation* t, int item_id, int surface_style_id, Logger& logger = Logger::Root()) const = 0; IfcGeom::Representation::Triangulation* Triangulate(const ifcopenshell::geometry::Settings& settings, Logger& logger = Logger::Root()) const; virtual void Serialize(const ifcopenshell::geometry::taxonomy::matrix4& place, std::string&) const = 0; diff --git a/src/ifcgeom/kernels/cgal/CgalConversionResult.h b/src/ifcgeom/kernels/cgal/CgalConversionResult.h index f54854ac30..22cb9c2d44 100644 --- a/src/ifcgeom/kernels/cgal/CgalConversionResult.h +++ b/src/ifcgeom/kernels/cgal/CgalConversionResult.h @@ -146,6 +146,10 @@ namespace ifcopenshell { namespace geometry { return std::make_shared(CGAL::Epeck::FT(v)); } + virtual std::shared_ptr from_int(int v) const { + return std::make_shared(CGAL::Epeck::FT(v)); + } + virtual bool equals(const NumberConcept& other) const { return value == as_same(other).value; } @@ -182,7 +186,13 @@ namespace ifcopenshell { namespace geometry { #ifndef IFOPSH_SIMPLE_KERNEL mutable boost::optional> nef_; #endif - public: + public: +#ifdef IFOPSH_SIMPLE_KERNEL + std::string type() const override { return "CgalSimpleShape"; } +#else + std::string type() const override { return "CgalShape"; } +#endif + CgalShape(const cgal_shape_t& shape, bool convex = false, Logger& logger = Logger::Root()); CgalShape(const cgal_point_t& point, bool convex = false); CgalShape(const cgal_wire_t& wire, bool convex = false); @@ -287,6 +297,8 @@ namespace ifcopenshell { namespace geometry { std::list> planes_; public: + std::string type() const override { return "CgalShapeHalfSpaceDecomposition"; } + CgalShapeHalfSpaceDecomposition(const CGAL::Nef_polyhedron_3& shape, bool is_convex) { if (is_convex) { shape_ = std::move(build_halfspace_tree_is_decomposed(shape, planes_)); diff --git a/src/ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h b/src/ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h index 70b612feba..5c25addc3b 100644 --- a/src/ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h +++ b/src/ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h @@ -45,6 +45,8 @@ namespace ifcopenshell { class IFC_GEOMLIBRARY_API OpenCascadeShape : public IfcGeom::ConversionResultShape { public: + std::string type() const override { return "OpenCascadeShape"; } + OpenCascadeShape(const TopoDS_Shape& shape) : shape_(shape) {} OpenCascadeShape(TopoDS_Shape&& shape) diff --git a/src/ifcwrap/IfcGeomWrapper.i b/src/ifcwrap/IfcGeomWrapper.i index 65655cd247..81c2a53795 100644 --- a/src/ifcwrap/IfcGeomWrapper.i +++ b/src/ifcwrap/IfcGeomWrapper.i @@ -1170,6 +1170,20 @@ ifcopenshell::geometry::taxonomy::item::ptr try_upcast(PyObject* obj0, swig_type %template(svg_loop) std::vector>; %template(svg_loops) std::vector>>; +%extend IfcGeom::OpaqueCoordinate { + %pythoncode %{ + __len__ = size + def __iter__(self): + yield from (self.get(i) for i in range(len(self))) + %} +} + +%extend IfcGeom::OpaqueNumber { + %pythoncode %{ + __abs__ = abs + %} +} + %template(OpaqueCoordinate_3) IfcGeom::OpaqueCoordinate<3>; %template(OpaqueCoordinate_4) IfcGeom::OpaqueCoordinate<4>;