Files
IfcOpenShell/src/ifcgeom/kernels/opencascade/extrusion.cpp
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

92 lines
2.1 KiB
C++
Raw Normal View History

2023-03-21 20:15:01 +01:00
#include "OpenCascadeKernel.h"
#include <BRepPrimAPI_MakePrism.hxx>
using namespace ifcopenshell::geometry;
using namespace ifcopenshell::geometry::kernels;
using namespace IfcGeom;
bool OpenCascadeKernel::convert(const taxonomy::extrusion::ptr extrusion, TopoDS_Shape& shape) {
2023-03-21 20:15:01 +01:00
const double& height = extrusion->depth;
2023-11-15 10:32:20 +01:00
if (height < settings_.get<settings::Precision>().get()) {
2026-03-31 15:32:36 +02:00
logger::error("Non-positive extrusion height encountered for:", extrusion->instance);
2023-03-21 20:15:01 +01:00
return false;
}
TopoDS_Shape face;
if (!convert(taxonomy::cast<taxonomy::face>(extrusion->basis), face)) {
2023-03-21 20:15:01 +01:00
return false;
}
/*
// @todo we need to decide whether the matrix is kept on the taxonomy node or
// move the TopoDS_Shape, but obviously not both.
gp_GTrsf gtrsf;
if (!convert(&extrusion->matrix, gtrsf)) {
2026-03-31 15:32:36 +02:00
logger::error("Unable to move extrusion");
2023-03-21 20:15:01 +01:00
}
auto trsf = gtrsf.Trsf();
*/
const auto& fs = extrusion->direction->ccomponents();
2023-03-21 20:15:01 +01:00
gp_Dir dir(fs(0), fs(1), fs(2));
shape.Nullify();
if (face.ShapeType() == TopAbs_COMPOUND) {
// For compounds (most likely the result of a IfcCompositeProfileDef)
// create a compound solid shape.
TopExp_Explorer exp(face, TopAbs_FACE);
TopoDS_CompSolid compound;
BRep_Builder builder;
builder.MakeCompSolid(compound);
int num_faces_extruded = 0;
for (; exp.More(); exp.Next(), ++num_faces_extruded) {
builder.Add(compound, BRepPrimAPI_MakePrism(exp.Current(), height*dir));
}
if (num_faces_extruded) {
shape = compound;
}
}
if (shape.IsNull()) {
shape = BRepPrimAPI_MakePrism(face, height*dir);
}
/*
if (!shape.IsNull()) {
// IfcSweptAreaSolid.Position (trsf) is an IfcAxis2Placement3D
// and therefore has a unit scale factor
shape.Move(trsf);
}
*/
return !shape.IsNull();
}
bool OpenCascadeKernel::convert_impl(const taxonomy::extrusion::ptr extrusion, IfcGeom::ConversionResults& results) {
2026-03-14 14:44:47 +01:00
return handle_occt_exception([&]() -> bool {
2023-03-21 20:15:01 +01:00
TopoDS_Shape shape;
if (!convert(extrusion, shape)) {
return false;
}
results.emplace_back(ConversionResult(
extrusion->instance.id(),
2023-03-21 20:15:01 +01:00
extrusion->matrix,
new OpenCascadeShape(shape),
extrusion->surface_style
));
return true;
2026-03-14 14:44:47 +01:00
});
2023-03-21 20:15:01 +01:00
}