mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Merge branch 'master' into layerset_slicing
This commit is contained in:
@@ -195,43 +195,46 @@ int main(int argc, char** argv) {
|
||||
file.addBuildingProduct(north_wall);
|
||||
file.setSurfaceColour(north_wall->Representation(), wall_colour);
|
||||
|
||||
IfcSchema::IfcShapeRepresentation* clipped_wall_body_rep = file.addEmptyRepresentation();
|
||||
file.addBox(clipped_wall_body_rep, 5000, 360, 6000);
|
||||
// The east wall geometry is clipped using two IfcHalfSpaceSolids, created from an
|
||||
// 'axis 3d placement' that specifies the plane against which the geometry is clipped.
|
||||
file.clipRepresentation(clipped_wall_body_rep, file.addPlacement3d(-2500, 0, 3000, -1, 0, 1), false);
|
||||
file.clipRepresentation(clipped_wall_body_rep, file.addPlacement3d(2500, 0, 3000, 1, 0, 1), false);
|
||||
// Two identical representations are created for the two remaining walls. Mapped items
|
||||
// are not used, because it is not allowed by the standard for wall body representations.
|
||||
// MappedItems are not allowed for Axis representations as per CV-2x3-161
|
||||
IfcSchema::IfcProductDefinitionShape* clipped_wall_body_reps[2];
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
IfcSchema::IfcShapeRepresentation* body = file.addEmptyRepresentation();
|
||||
file.addBox(body, 5000, 360, 6000);
|
||||
// The wall geometry is clipped using two IfcHalfSpaceSolids, created from an
|
||||
// 'axis 3d placement' that specifies the plane against which the geometry is clipped.
|
||||
file.clipRepresentation(body, file.addPlacement3d(-2500, 0, 3000, -1, 0, 1), false);
|
||||
file.clipRepresentation(body, file.addPlacement3d(2500, 0, 3000, 1, 0, 1), false);
|
||||
file.setSurfaceColour(body, wall_colour);
|
||||
|
||||
IfcSchema::IfcShapeRepresentation* axis = file.addEmptyRepresentation("Axis", "Curve2D");
|
||||
file.addAxis(axis, 5000);
|
||||
|
||||
IfcSchema::IfcRepresentation::list::ptr reps(new IfcSchema::IfcRepresentation::list);
|
||||
reps->push(body);
|
||||
reps->push(axis);
|
||||
clipped_wall_body_reps[i] = new IfcSchema::IfcProductDefinitionShape(null, null, reps);
|
||||
}
|
||||
|
||||
// Now create a wall on the east of the building, again starting with just a box shape
|
||||
IfcSchema::IfcWallStandardCase* east_wall = new IfcSchema::IfcWallStandardCase(guid(), file.getSingle<IfcSchema::IfcOwnerHistory>(),
|
||||
S("East wall"), null, null, file.addLocalPlacement(storey_placement, 4820, 2500, 0, 0, 0, 1, 0, 1, 0), file.addMappedItem(clipped_wall_body_rep), null
|
||||
S("East wall"), null, null, file.addLocalPlacement(storey_placement, 4820, 2500, 0, 0, 0, 1, 0, 1, 0), clipped_wall_body_reps[0], null
|
||||
#ifdef USE_IFC4
|
||||
, IfcSchema::IfcWallTypeEnum::IfcWallType_STANDARD
|
||||
#endif
|
||||
);
|
||||
file.addBuildingProduct(east_wall);
|
||||
|
||||
file.setSurfaceColour(clipped_wall_body_rep, wall_colour);
|
||||
|
||||
// The east wall is copied to the west location of the house
|
||||
IfcSchema::IfcWallStandardCase* west_wall = new IfcSchema::IfcWallStandardCase(guid(), file.getSingle<IfcSchema::IfcOwnerHistory>(),
|
||||
S("West wall"), null, null, file.addLocalPlacement(storey_placement, -4820, 2500, 0, 0, 0, 1, 0, -1, 0), file.addMappedItem(clipped_wall_body_rep), null
|
||||
S("West wall"), null, null, file.addLocalPlacement(storey_placement, -4820, 2500, 0, 0, 0, 1, 0, -1, 0), clipped_wall_body_reps[1], null
|
||||
#ifdef USE_IFC4
|
||||
, IfcSchema::IfcWallTypeEnum::IfcWallType_STANDARD
|
||||
#endif
|
||||
);
|
||||
file.addBuildingProduct(west_wall);
|
||||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
// CV-2x3-161: MappedItems are not allowed for Axis representations
|
||||
IfcSchema::IfcWallStandardCase* wall = i == 0 ? east_wall : west_wall;
|
||||
IfcSchema::IfcShapeRepresentation* wall_axis_rep = file.addEmptyRepresentation("Axis", "Curve2D");
|
||||
file.addAxis(wall_axis_rep, 5000);
|
||||
IfcSchema::IfcRepresentation::list::ptr reps = wall->Representation()->Representations();
|
||||
reps->push(wall_axis_rep);
|
||||
wall->Representation()->setRepresentations(reps);
|
||||
}
|
||||
|
||||
// The west wall is assigned an opening element we created for the south wall, opening elements are
|
||||
// not shared accross building elements, even if they share the same representation. Hence, the east
|
||||
// wall will not feature this opening.
|
||||
|
||||
@@ -40,19 +40,7 @@ void OpenCascadeBasedSerializer::write(const IfcGeom::BRepElement<double>* o) {
|
||||
for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = o->geometry().begin(); it != o->geometry().end(); ++ it) {
|
||||
gp_GTrsf gtrsf = it->Placement();
|
||||
|
||||
const std::vector<double>& matrix = o->transformation().matrix().data();
|
||||
|
||||
// Convert the matrix back into a transformation object. The tolerance values
|
||||
// are taken into consideration to reconstruct the form of the transformation.
|
||||
gp_Trsf o_trsf;
|
||||
o_trsf.SetValues(
|
||||
matrix[0], matrix[3], matrix[6], matrix[ 9],
|
||||
matrix[1], matrix[4], matrix[7], matrix[10],
|
||||
matrix[2], matrix[5], matrix[8], matrix[11]
|
||||
#if OCC_VERSION_HEX < 0x60800
|
||||
, Precision::Angular(), Precision::Confusion()
|
||||
#endif
|
||||
);
|
||||
const gp_Trsf& o_trsf = o->transformation().data();
|
||||
gtrsf.PreMultiply(o_trsf);
|
||||
|
||||
const TopoDS_Shape& s = it->Shape();
|
||||
|
||||
@@ -217,17 +217,7 @@ void SvgSerializer::write(const IfcGeom::BRepElement<double>* o) {
|
||||
for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = o->geometry().begin(); it != o->geometry().end(); ++ it) {
|
||||
gp_GTrsf gtrsf = it->Placement();
|
||||
|
||||
gp_Trsf o_trsf;
|
||||
const std::vector<double>& matrix = o->transformation().matrix().data();
|
||||
o_trsf.SetValues(
|
||||
matrix[0], matrix[3], matrix[6], matrix[ 9],
|
||||
matrix[1], matrix[4], matrix[7], matrix[10],
|
||||
matrix[2], matrix[5], matrix[8], matrix[11]
|
||||
#if OCC_VERSION_HEX < 0x60800
|
||||
, Precision::Angular(), Precision::Confusion()
|
||||
#endif
|
||||
);
|
||||
gtrsf.PreMultiply(o_trsf);
|
||||
const gp_Trsf& o_trsf = o->transformation().data();
|
||||
const TopoDS_Shape& s = it->Shape();
|
||||
|
||||
bool trsf_valid = false;
|
||||
|
||||
@@ -24,6 +24,15 @@ using namespace IfcSchema;
|
||||
using namespace IfcUtil;
|
||||
|
||||
bool IfcGeom::Kernel::convert_shapes(const IfcBaseClass* l, IfcRepresentationShapeItems& r) {
|
||||
if (shape_type(l) != ST_SHAPELIST) {
|
||||
TopoDS_Shape shp;
|
||||
if (convert_shape(l, shp)) {
|
||||
r.push_back(IfcGeom::IfcRepresentationShapeItem(shp, get_style(l->as<IfcSchema::IfcRepresentationItem>())));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#include "IfcRegisterConvertShapes.h"
|
||||
Logger::Message(Logger::LOG_ERROR,"No operation defined for:",l->entity);
|
||||
return false;
|
||||
|
||||
@@ -52,8 +52,14 @@ def get_bounding_box_center(bbox):
|
||||
def create_shape_from_serialization(brep_object):
|
||||
brep_data, occ_shape = None, None
|
||||
|
||||
try: brep_data = brep_object.geometry.brep_data
|
||||
except: pass
|
||||
is_product_shape = True
|
||||
try:
|
||||
brep_data = brep_object.geometry.brep_data
|
||||
except:
|
||||
try:
|
||||
brep_data = brep_object.brep_data
|
||||
is_product_shape = False
|
||||
except: pass
|
||||
if not brep_data: return tuple(brep_object, None)
|
||||
|
||||
try:
|
||||
@@ -62,5 +68,8 @@ def create_shape_from_serialization(brep_object):
|
||||
occ_shape = ss.Shape(ss.NbShapes())
|
||||
except: pass
|
||||
|
||||
return tuple(brep_object, occ_shape)
|
||||
if is_product_shape:
|
||||
return tuple(brep_object, occ_shape)
|
||||
else:
|
||||
return occ_shape
|
||||
|
||||
|
||||
@@ -72,17 +72,35 @@
|
||||
}
|
||||
}
|
||||
|
||||
// A visitor
|
||||
%{
|
||||
struct ShapeRTTI : public boost::static_visitor<PyObject*>
|
||||
{
|
||||
PyObject* operator()(IfcGeom::Element<double>* elem) const {
|
||||
IfcGeom::SerializedElement<double>* serialized_elem = dynamic_cast<IfcGeom::SerializedElement<double>*>(elem);
|
||||
IfcGeom::TriangulationElement<double>* triangulation_elem = dynamic_cast<IfcGeom::TriangulationElement<double>*>(elem);
|
||||
if (triangulation_elem) {
|
||||
return SWIG_NewPointerObj(SWIG_as_voidptr(triangulation_elem), SWIGTYPE_p_IfcGeom__TriangulationElementT_double_t, SWIG_POINTER_OWN);
|
||||
} else if (serialized_elem) {
|
||||
return SWIG_NewPointerObj(SWIG_as_voidptr(serialized_elem), SWIGTYPE_p_IfcGeom__SerializedElementT_double_t, SWIG_POINTER_OWN);
|
||||
}
|
||||
}
|
||||
PyObject* operator()(IfcGeom::Representation::Representation* representation) const {
|
||||
IfcGeom::Representation::Serialization* serialized_representation = dynamic_cast<IfcGeom::Representation::Serialization*>(representation);
|
||||
IfcGeom::Representation::Triangulation<double>* triangulated_representation = dynamic_cast<IfcGeom::Representation::Triangulation<double>*>(representation);
|
||||
if (serialized_representation) {
|
||||
return SWIG_NewPointerObj(SWIG_as_voidptr(serialized_representation), SWIGTYPE_p_IfcGeom__Representation__Serialization, SWIG_POINTER_OWN);
|
||||
} else if (triangulated_representation) {
|
||||
return SWIG_NewPointerObj(SWIG_as_voidptr(triangulated_representation), SWIGTYPE_p_IfcGeom__Representation__TriangulationT_double_t, SWIG_POINTER_OWN);
|
||||
}
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
// Note that these elements ARE to be owned by SWIG/Python
|
||||
%typemap(out) boost::variant<IfcGeom::Element<double>*, IfcGeom::Representation::Representation*> {
|
||||
// See which type is set and return appropriate
|
||||
IfcGeom::Element<double>* elem = boost::get<IfcGeom::Element<double>*>($1);
|
||||
IfcGeom::SerializedElement<double>* serialized_elem = dynamic_cast<IfcGeom::SerializedElement<double>*>(elem);
|
||||
IfcGeom::TriangulationElement<double>* triangulation_elem = dynamic_cast<IfcGeom::TriangulationElement<double>*>(elem);
|
||||
if (triangulation_elem) {
|
||||
$result = SWIG_NewPointerObj(SWIG_as_voidptr(triangulation_elem), SWIGTYPE_p_IfcGeom__TriangulationElementT_double_t, SWIG_POINTER_OWN);
|
||||
} else if (serialized_elem) {
|
||||
$result = SWIG_NewPointerObj(SWIG_as_voidptr(serialized_elem), SWIGTYPE_p_IfcGeom__SerializedElementT_double_t, SWIG_POINTER_OWN);
|
||||
}
|
||||
$result = boost::apply_visitor(ShapeRTTI(), $1);
|
||||
}
|
||||
|
||||
// This does not seem to work:
|
||||
@@ -218,25 +236,25 @@
|
||||
|
||||
%inline %{
|
||||
boost::variant<IfcGeom::Element<double>*, IfcGeom::Representation::Representation*> create_shape(IfcGeom::IteratorSettings& settings, IfcParse::IfcLateBoundEntity* instance, IfcParse::IfcLateBoundEntity* representation = 0) {
|
||||
IfcParse::IfcFile* file = instance->entity->file;
|
||||
IfcSchema::IfcProject::list::ptr projects = file->entitiesByType<IfcSchema::IfcProject>();
|
||||
if (projects->size() != 1) {
|
||||
throw IfcParse::IfcException("Not a single IfcProject instance");
|
||||
}
|
||||
IfcSchema::IfcProject* project = *projects->begin();
|
||||
|
||||
IfcGeom::Kernel kernel;
|
||||
kernel.setValue(IfcGeom::Kernel::GV_MAX_FACES_TO_SEW, settings.sew_shells() ? 1000 : -1);
|
||||
kernel.setValue(IfcGeom::Kernel::GV_DIMENSIONALITY, (settings.include_curves() ? (settings.exclude_solids_and_surfaces() ? -1. : 0.) : +1.));
|
||||
std::pair<std::string, double> length_unit = kernel.initializeUnits(project->UnitsInContext());
|
||||
|
||||
if (instance->is(IfcSchema::Type::IfcProduct)) {
|
||||
if (representation) {
|
||||
if (!representation->is(IfcSchema::Type::IfcRepresentation)) {
|
||||
throw IfcParse::IfcException("Supplied representation not of type IfcRepresentation");
|
||||
}
|
||||
}
|
||||
|
||||
IfcParse::IfcFile* file = instance->entity->file;
|
||||
|
||||
IfcSchema::IfcProject::list::ptr projects = file->entitiesByType<IfcSchema::IfcProject>();
|
||||
if (projects->size() != 1) {
|
||||
throw IfcParse::IfcException("Not a single IfcProject instance");
|
||||
}
|
||||
IfcSchema::IfcProject* project = *projects->begin();
|
||||
|
||||
IfcGeom::Kernel kernel;
|
||||
kernel.setValue(IfcGeom::Kernel::GV_MAX_FACES_TO_SEW, settings.sew_shells() ? 1000 : -1);
|
||||
kernel.setValue(IfcGeom::Kernel::GV_DIMENSIONALITY, (settings.include_curves() ? (settings.exclude_solids_and_surfaces() ? -1. : 0.) : +1.));
|
||||
|
||||
|
||||
IfcSchema::IfcProduct* product = (IfcSchema::IfcProduct*) instance;
|
||||
|
||||
if (!representation && !product->hasRepresentation()) {
|
||||
@@ -318,7 +336,6 @@
|
||||
if (context->hasPrecision()) {
|
||||
precision = context->Precision();
|
||||
}
|
||||
std::pair<std::string, double> length_unit = kernel.initializeUnits(project->UnitsInContext());
|
||||
precision *= length_unit.second;
|
||||
|
||||
// Some arbitrary factor that has proven to work better for the models in the set of test files.
|
||||
@@ -342,7 +359,28 @@
|
||||
throw IfcParse::IfcException("No element to return based on provided settings");
|
||||
}
|
||||
} else {
|
||||
throw IfcParse::IfcException("Only obtaining representations for IfcProduct instances is currently supported");
|
||||
if (!representation) {
|
||||
if (instance->is(IfcSchema::Type::IfcRepresentationItem) || instance->is(IfcSchema::Type::IfcRepresentation)) {
|
||||
IfcGeom::IfcRepresentationShapeItems shapes;
|
||||
if (kernel.convert_shapes(instance, shapes)) {
|
||||
IfcGeom::ElementSettings element_settings(settings, kernel.getValue(IfcGeom::Kernel::GV_LENGTH_UNIT), IfcSchema::Type::ToString(instance->type()));
|
||||
IfcGeom::Representation::BRep brep(element_settings, instance->entity->id(), shapes);
|
||||
try {
|
||||
if (settings.use_brep_data()) {
|
||||
return new IfcGeom::Representation::Serialization(brep);
|
||||
} else if (!settings.disable_triangulation()) {
|
||||
return new IfcGeom::Representation::Triangulation<double>(brep);
|
||||
}
|
||||
} catch (...) {
|
||||
throw IfcParse::IfcException("Error during shape serialization");
|
||||
}
|
||||
} else {
|
||||
throw IfcParse::IfcException("Geometrical element not understood");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw IfcParse::IfcException("Invalid additional representation specified");
|
||||
}
|
||||
}
|
||||
}
|
||||
%}
|
||||
|
||||
Reference in New Issue
Block a user