mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Add back support for IfcSphere
This commit is contained in:
@@ -50,6 +50,7 @@ namespace ifcopenshell { namespace geometry { namespace kernels {
|
||||
virtual bool convert_impl(const taxonomy::revolve::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
|
||||
virtual bool convert_impl(const taxonomy::bspline_surface::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
|
||||
virtual bool convert_impl(const taxonomy::cylinder::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
|
||||
virtual bool convert_impl(const taxonomy::sphere::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
|
||||
virtual bool convert_impl(const taxonomy::solid::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
|
||||
virtual bool convert_impl(const taxonomy::surface_curve_sweep::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
|
||||
virtual bool convert_impl(const taxonomy::loft::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <BRepPrimAPI_MakePrism.hxx>
|
||||
#include <BRepAlgoAPI_Common.hxx>
|
||||
#include <ShapeFix_Solid.hxx>
|
||||
#include <BRepPrimAPI_MakeSphere.hxx>
|
||||
|
||||
using namespace ifcopenshell::geometry;
|
||||
using namespace ifcopenshell::geometry::kernels;
|
||||
@@ -64,18 +65,34 @@ bool OpenCascadeKernel::convert(const taxonomy::solid::ptr solid, TopoDS_Shape&
|
||||
|
||||
result = halfspace;
|
||||
return true;
|
||||
} else if (solid->children.size() == 1
|
||||
&& solid->children[0]->children.size() == 1
|
||||
&& solid->children[0]->children[0]->basis
|
||||
&& solid->children[0]->children[0]->basis->kind() == taxonomy::SPHERE)
|
||||
{
|
||||
auto sphere = taxonomy::cast<taxonomy::sphere>(solid->children[0]->children[0]->basis);
|
||||
gp_GTrsf gtrsf;
|
||||
convert(sphere->matrix, gtrsf);
|
||||
BRepPrimAPI_MakeSphere builder(sphere->radius);
|
||||
auto s = builder.Solid();
|
||||
s.Move(gtrsf.Trsf());
|
||||
result = s;
|
||||
return true;
|
||||
}
|
||||
|
||||
for (auto& s : solid->children) {
|
||||
TopoDS_Shape shl;
|
||||
convert(s, shl);
|
||||
if (shl.ShapeType() == TopAbs_SHELL) {
|
||||
ShapeFix_Solid solid;
|
||||
S = solid.SolidFromShell(TopoDS::Shell(shl));
|
||||
} else if (solid->children.size() == 1) {
|
||||
S = shl;
|
||||
if (convert(s, shl)) {
|
||||
if (shl.ShapeType() == TopAbs_SHELL) {
|
||||
ShapeFix_Solid solid;
|
||||
S = solid.SolidFromShell(TopoDS::Shell(shl));
|
||||
} else if (solid->children.size() == 1) {
|
||||
S = shl;
|
||||
} else {
|
||||
throw std::runtime_error("Unexpected configuration of subshapes");
|
||||
}
|
||||
} else {
|
||||
throw std::runtime_error("Unexpected configuration of subshapes");
|
||||
Logger::Warning("Ignored shell", s->instance);
|
||||
}
|
||||
}
|
||||
if (!S.IsNull()) {
|
||||
|
||||
@@ -22,18 +22,14 @@
|
||||
using namespace ifcopenshell::geometry;
|
||||
|
||||
taxonomy::ptr mapping::map_impl(const IfcSchema::IfcSphere* inst) {
|
||||
// @todo
|
||||
return nullptr;
|
||||
/*
|
||||
const double r = inst->Radius() * length_unit_;
|
||||
|
||||
BRepPrimAPI_MakeSphere builder(r);
|
||||
gp_Trsf trsf;
|
||||
IfcGeom::Kernel::convert(inst->Position(),trsf);
|
||||
|
||||
// IfcCsgPrimitive3D.Position has unit scale factor
|
||||
shape = builder.Solid().Moved(trsf);
|
||||
|
||||
return true;
|
||||
*/
|
||||
auto sol = taxonomy::make<taxonomy::solid>();
|
||||
auto shl = taxonomy::make<taxonomy::shell>();
|
||||
auto fac = taxonomy::make<taxonomy::face>();
|
||||
auto spr = taxonomy::make<taxonomy::sphere>();
|
||||
spr->matrix = taxonomy::cast<taxonomy::matrix4>(map(inst->Position()));
|
||||
spr->radius = inst->Radius() * length_unit_;
|
||||
fac->basis = spr;
|
||||
shl->children.push_back(fac);
|
||||
sol->children.push_back(shl);
|
||||
return sol;
|
||||
}
|
||||
|
||||
@@ -149,6 +149,10 @@ namespace {
|
||||
throw std::runtime_error("not implemented");
|
||||
}
|
||||
|
||||
bool compare(const sphere&, const sphere&) {
|
||||
throw std::runtime_error("not implemented");
|
||||
}
|
||||
|
||||
bool compare(const surface_curve_sweep&, const surface_curve_sweep&) {
|
||||
throw std::runtime_error("not implemented");
|
||||
}
|
||||
@@ -512,7 +516,7 @@ const std::string& ifcopenshell::geometry::taxonomy::kind_to_string(kinds k) {
|
||||
using namespace std::string_literals;
|
||||
|
||||
static std::string values[] = {
|
||||
"matrix4"s, "point3"s, "direction3"s, "line"s, "circle"s, "ellipse"s, "bspline_curve"s, "offset_curve"s, "plane"s, "cylinder"s, "bspline_surface"s, "edge"s, "loop"s, "face"s, "shell"s, "solid"s, "loft"s, "extrusion"s, "revolve"s, "surface_curve_sweep"s, "node"s, "collection"s, "boolean_result"s, "piecewise_function"s, "colour"s, "style"s,
|
||||
"matrix4"s, "point3"s, "direction3"s, "line"s, "circle"s, "ellipse"s, "bspline_curve"s, "offset_curve"s, "plane"s, "cylinder"s, "sphere"s, "bspline_surface"s, "edge"s, "loop"s, "face"s, "shell"s, "solid"s, "loft"s, "extrusion"s, "revolve"s, "surface_curve_sweep"s, "node"s, "collection"s, "boolean_result"s, "piecewise_function"s, "colour"s, "style"s,
|
||||
};
|
||||
|
||||
return values[k];
|
||||
|
||||
+20
-3
@@ -90,7 +90,7 @@ typedef item const* ptr;
|
||||
topology_error(const char* const s) : std::runtime_error(s) {}
|
||||
};
|
||||
|
||||
enum kinds { MATRIX4, POINT3, DIRECTION3, LINE, CIRCLE, ELLIPSE, BSPLINE_CURVE, OFFSET_CURVE, PLANE, CYLINDER, BSPLINE_SURFACE, EDGE, LOOP, FACE, SHELL, SOLID, LOFT, EXTRUSION, REVOLVE, SURFACE_CURVE_SWEEP, NODE, COLLECTION, BOOLEAN_RESULT, PIECEWISE_FUNCTION, COLOUR, STYLE };
|
||||
enum kinds { MATRIX4, POINT3, DIRECTION3, LINE, CIRCLE, ELLIPSE, BSPLINE_CURVE, OFFSET_CURVE, PLANE, CYLINDER, SPHERE, BSPLINE_SURFACE, EDGE, LOOP, FACE, SHELL, SOLID, LOFT, EXTRUSION, REVOLVE, SURFACE_CURVE_SWEEP, NODE, COLLECTION, BOOLEAN_RESULT, PIECEWISE_FUNCTION, COLOUR, STYLE };
|
||||
|
||||
const std::string& kind_to_string(kinds k);
|
||||
|
||||
@@ -875,6 +875,23 @@ typedef item const* ptr;
|
||||
}
|
||||
};
|
||||
|
||||
struct sphere : public surface {
|
||||
DECLARE_PTR(sphere)
|
||||
|
||||
double radius;
|
||||
|
||||
virtual sphere* clone_() const { return new sphere(*this); }
|
||||
virtual kinds kind() const { return SPHERE; }
|
||||
|
||||
void print(std::ostream& o, int) const {
|
||||
o << "not implemented";
|
||||
}
|
||||
virtual size_t calc_hash() const {
|
||||
auto v = std::make_tuple(static_cast<size_t>(SPHERE), matrix->hash_components());
|
||||
return boost::hash<decltype(v)>{}(v);
|
||||
}
|
||||
};
|
||||
|
||||
struct bspline_surface : public surface {
|
||||
DECLARE_PTR(bspline_surface)
|
||||
|
||||
@@ -1037,9 +1054,9 @@ typedef item const* ptr;
|
||||
};
|
||||
|
||||
namespace impl {
|
||||
typedef std::tuple<matrix4, point3, direction3, line, circle, ellipse, bspline_curve, offset_curve, plane, cylinder, bspline_surface, edge, loop, face, shell, solid, loft, extrusion, revolve, surface_curve_sweep, node, collection, boolean_result, piecewise_function> KindsTuple;
|
||||
typedef std::tuple<matrix4, point3, direction3, line, circle, ellipse, bspline_curve, offset_curve, plane, cylinder, sphere, bspline_surface, edge, loop, face, shell, solid, loft, extrusion, revolve, surface_curve_sweep, node, collection, boolean_result, piecewise_function> KindsTuple;
|
||||
typedef std::tuple<line, circle, ellipse, bspline_curve, offset_curve, loop, edge> CurvesTuple;
|
||||
typedef std::tuple<plane, cylinder, bspline_surface> SurfacesTuple;
|
||||
typedef std::tuple<plane, cylinder, sphere, bspline_surface> SurfacesTuple;
|
||||
}
|
||||
|
||||
struct type_by_kind {
|
||||
|
||||
Reference in New Issue
Block a user