feature (WIP) : retrieve full hierarchy

Bug : the element are not at the right location
This commit is contained in:
Balleux Benjamin
2017-05-15 17:45:05 +02:00
parent 4f6e8a7d56
commit be3dbce9f4
5 changed files with 345 additions and 84 deletions
+33 -13
View File
@@ -574,14 +574,17 @@ namespace IfcGeom {
else if (current_serialization) { ret = current_serialization; }
else if (current_shape_model) { ret = current_shape_model; }
// If we want to organize the element by floors we need to get the floor of the element
// If we want to organize the element considering their hierarchy
if (settings.get(IteratorSettings::SEARCH_FLOOR))
{
// We are going to build a vector with the element parents.
// First, create the parent vector
std::vector<const IfcGeom::Element<P>*> parents;
// if the element has a parent
if (ret->parent_id() != -1)
{
const IfcGeom::Element<P>* parent_object = NULL;
bool hasParent = true;
// get the parent
@@ -591,20 +594,28 @@ namespace IfcGeom {
hasParent = false;
}
// We need to find an IfcBuildingStorey in the parent
while (parent_object != NULL && parent_object->type() != "IfcBuildingStorey" && hasParent)
// Add the previously found parent to the vector
if (hasParent) parents.insert(parents.begin(), parent_object);
// We need to find all the parents
while (parent_object != NULL && hasParent)
{
// Find the next parent
try { parent_object = getObject(parent_object->parent_id()); }
catch (std::exception e)
{
std::cout << e.what();
hasParent = false;
}
hasParent = hasParent && parent_object->parent_id() != 1;
// Add the previously found parent to the vector
if (hasParent) parents.insert(parents.begin(), parent_object);
hasParent = hasParent && parent_object->parent_id() != -1;
}
if (hasParent) { ret->SetFloor(parent_object); }
else { ret->SetFloor(NULL); } // Set it so null in order to know that we didn't found any IfcBuildingStorey type parent
// when done push the parent list in the Element object
ret->SetParents(parents);
}
}
@@ -619,38 +630,47 @@ namespace IfcGeom {
}
const Element<P>* getObject(int id) {
//std::cout << "1";
gp_Trsf trsf;
int parent_id = -1;
std::string instance_type, product_name, product_guid;
IfcSchema::IfcProduct* ifc_product = 0;
//std::cout << "2";
try {
const IfcUtil::IfcBaseClass* ifc_entity = ifc_file->entityById(id);
instance_type = IfcSchema::Type::ToString(ifc_entity->type());
if ( ifc_entity->is(IfcSchema::Type::IfcProduct) ) {
ifc_product = (IfcSchema::IfcProduct*)ifc_entity;
//std::cout << "3";
product_guid = ifc_product->GlobalId();
product_name = ifc_product->hasName() ? ifc_product->Name() : "";
parent_id = -1;
try {
//std::cout << "4";
IfcSchema::IfcObjectDefinition* parent_object = kernel.get_decomposing_entity(ifc_product);
if (parent_object) {
parent_id = parent_object->entity->id();
}
} catch (...) {}
//std::cout << "5";
try {
kernel.convert(ifc_product->ObjectPlacement(), trsf);
} catch (...) {}
}
//std::cout << "6";
} catch(...) {}
//std::cout << "7";
ElementSettings element_settings(settings, unit_magnitude, instance_type);
//std::cout << "8";
//std::cout << "id " << id << "\n";
//std::cout << "parent_id " << parent_id << "\n";
//std::cout << "product_name " << product_name << "\n";
//std::cout << "instance_type " << instance_type << "\n";
//std::cout << "product_guid " << product_guid << "\n";
Element<P>* ifc_object = new Element<P>(element_settings, id, parent_id, product_name, instance_type, product_guid, "", trsf, ifc_product);
//std::cout << "9\n";
return ifc_object;
}