* IfcGeom::Kernel::create_brep_for_representation_and_product(const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product) { IfcGeom::Representation::BRep* shape; IfcGeom::IfcRepresentationShapeItems shapes; if ( !convert_shapes(representation,shapes) ) { return 0; } int parent_id = -1; try { IfcSchema::IfcObjectDefinition* parent_object = get_decomposing_entity(product); if (parent_object) { parent_id = parent_object->entity->id(); } } catch (...) {} const std::string name = product->hasName() ? product->Name() : ""; const std::string guid = product->GlobalId(); gp_Trsf trsf; try { convert(product->ObjectPlacement(),trsf); } catch (...) {} // Does the IfcElement have any IfcOpenings? // Note that openings for IfcOpeningElements are not processed IfcSchema::IfcRelVoidsElement::list::ptr openings; if ( product->is(IfcSchema::Type::IfcElement) && !product->is(IfcSchema::Type::IfcOpeningElement) ) { IfcSchema::IfcElement* element = (IfcSchema::IfcElement*)product; openings = element->HasOpenings(); } // Is the IfcElement a decomposition of an IfcElement with any IfcOpeningElements? if ( product->is(IfcSchema::Type::IfcBuildingElementPart ) ) { IfcSchema::IfcBuildingElementPart* part = (IfcSchema::IfcBuildingElementPart*)product; #ifdef USE_IFC4 IfcSchema::IfcRelAggregates::list::ptr decomposes = part->Decomposes(); for ( IfcSchema::IfcRelAggregates::list::it it = decomposes->begin(); it != decomposes->end(); ++ it ) { #else IfcSchema::IfcRelDecomposes::list::ptr decomposes = part->Decomposes(); for ( IfcSchema::IfcRelDecomposes::list::it it = decomposes->begin(); it != decomposes->end(); ++ it ) { #endif IfcSchema::IfcObjectDefinition* obdef = (*it)->RelatingObject(); if ( obdef->is(IfcSchema::Type::IfcElement) ) { IfcSchema::IfcElement* element = (IfcSchema::IfcElement*)obdef; openings->push(element->HasOpenings()); } } } const std::string product_type = IfcSchema::Type::ToString(product->type()); ElementSettings element_settings(settings, getValue(GV_LENGTH_UNIT), product_type); if ( !settings.disable_opening_subtractions() && openings && openings->size() ) { IfcGeom::IfcRepresentationShapeItems opened_shapes; try { #if OCC_VERSION_HEX < 0x60900 const bool faster_booleans = settings.faster_booleans(); #else const bool faster_booleans = true; #endif if (faster_booleans) { bool succes = convert_openings_fast(product,openings,shapes,trsf,opened_shapes); if ( ! succes ) { opened_shapes.clear(); convert_openings(product,openings,shapes,trsf,opened_shapes); } } else { convert_openings(product,openings,shapes,trsf,opened_shapes); } } catch(...) { Logger::Message(Logger::LOG_ERROR,"Error processing openings for:",product->entity); } if ( settings.use_world_coords() ) { for ( IfcGeom::IfcRepresentationShapeItems::iterator it = opened_shapes.begin(); it != opened_shapes.end(); ++ it ) { it->prepend(trsf); } trsf = gp_Trsf(); } shape = new IfcGeom::Representation::BRep(element_settings, representation->entity->id(), opened_shapes); } else if ( settings.use_world_coords() ) { for ( IfcGeom::IfcRepresentationShapeItems::iterator it = shapes.begin(); it != shapes.end(); ++ it ) { it->prepend(trsf); } trsf = gp_Trsf(); shape = new IfcGeom::Representation::BRep(element_settings, representation->entity->id(), shapes); } else { shape = new IfcGeom::Representation::BRep(element_settings, representation->entity->id(), shapes); } std::string context_string = ""; if (representation->hasRepresentationIdentifier()) { context_string = representation->RepresentationIdentifier(); } else if (representation->ContextOfItems()->hasContextType()) { context_string = representation->ContextOfItems()->ContextType(); } return new BRepElement
(
product->entity->id(),
parent_id,
name,
product_type,
guid,
context_string,
trsf,
shape
);
}
IfcSchema::IfcObjectDefinition* IfcGeom::Kernel::get_decomposing_entity(IfcSchema::IfcProduct* product) {
IfcSchema::IfcObjectDefinition* parent = 0;
// In case of an opening element, parent to the RelatingBuildingElement
if ( product->is(IfcSchema::Type::IfcOpeningElement ) ) {
IfcSchema::IfcOpeningElement* opening = (IfcSchema::IfcOpeningElement*)product;
IfcSchema::IfcRelVoidsElement::list::ptr voids = opening->VoidsElements();
if ( voids->size() ) {
IfcSchema::IfcRelVoidsElement* ifc_void = *voids->begin();
parent = ifc_void->RelatingBuildingElement();
}
} else if ( product->is(IfcSchema::Type::IfcElement ) ) {
IfcSchema::IfcElement* element = (IfcSchema::IfcElement*)product;
IfcSchema::IfcRelFillsElement::list::ptr fills = element->FillsVoids();
// Incase of a RelatedBuildingElement parent to the opening element
if ( fills->size() ) {
for ( IfcSchema::IfcRelFillsElement::list::it it = fills->begin(); it != fills->end(); ++ it ) {
IfcSchema::IfcRelFillsElement* fill = *it;
IfcSchema::IfcObjectDefinition* ifc_objectdef = fill->RelatingOpeningElement();
if ( product == ifc_objectdef ) continue;
parent = ifc_objectdef;
}
}
// Else simply parent to the containing structure
if (!parent) {
IfcSchema::IfcRelContainedInSpatialStructure::list::ptr parents = element->ContainedInStructure();
if ( parents->size() ) {
IfcSchema::IfcRelContainedInSpatialStructure* container = *parents->begin();
parent = container->RelatingStructure();
}
}
}
// Parent decompositions to the RelatingObject
if (!parent) {
IfcEntityList::ptr parents = product->entity->getInverse(IfcSchema::Type::IfcRelAggregates, -1);
parents->push(product->entity->getInverse(IfcSchema::Type::IfcRelNests, -1));
for ( IfcEntityList::it it = parents->begin(); it != parents->end(); ++ it ) {
IfcSchema::IfcRelDecomposes* decompose = (IfcSchema::IfcRelDecomposes*)*it;
IfcSchema::IfcObjectDefinition* ifc_objectdef;
#ifdef USE_IFC4
if (decompose->is(IfcSchema::Type::IfcRelAggregates)) {
ifc_objectdef = ((IfcSchema::IfcRelAggregates*)decompose)->RelatingObject();
} else {
continue;
}
#else
ifc_objectdef = decompose->RelatingObject();
#endif
if ( product == ifc_objectdef ) continue;
parent = ifc_objectdef;
}
}
return parent;
}
template IfcGeom::BRepElement