mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-17 10:59:17 +00:00
feature (WIP) : retrieve full hierarchy
Bug : the element are not at the right location
This commit is contained in:
@@ -81,8 +81,21 @@ namespace IfcGeom {
|
||||
std::string _unique_id;
|
||||
Transformation<P> _transformation;
|
||||
IfcSchema::IfcProduct* product_;
|
||||
const Element<P>* _storey;
|
||||
std::vector<const IfcGeom::Element<P>*> _parents;
|
||||
public:
|
||||
|
||||
friend bool operator == (const Element<P> & element1, const Element<P> & element2)
|
||||
{
|
||||
//std::cout << " //// Compare == " << element1.name() << element1.id() << " | " << element1.type() << " and " << element2.name() << element2.id() << " | " << element2.type() << "\n";
|
||||
return element1.id() == element2.id();
|
||||
}
|
||||
|
||||
friend bool operator < (const Element<P> & element1, const Element<P> & element2)
|
||||
{
|
||||
//std::cout << " //// Compare < " << element1.name() << element1.id() << " | " << element1.type() << " and " << element2.name() << element2.id() << " | " << element2.type() << "\n";
|
||||
return element1.id() < element2.id();
|
||||
}
|
||||
|
||||
int id() const { return _id; }
|
||||
int parent_id() const { return _parent_id; }
|
||||
const std::string& name() const { return _name; }
|
||||
@@ -92,16 +105,21 @@ namespace IfcGeom {
|
||||
const std::string& unique_id() const { return _unique_id; }
|
||||
const Transformation<P>& transformation() const { return _transformation; }
|
||||
IfcSchema::IfcProduct* product() const { return product_; }
|
||||
const Element<P>* storey() const { return _storey; }
|
||||
void SetFloor(const Element<P>* floor) { _storey = floor; }
|
||||
const std::vector<const IfcGeom::Element<P>*> parents() const { return _parents; }
|
||||
void SetParents(std::vector<const IfcGeom::Element<P>*> newparents) { _parents = newparents; }
|
||||
|
||||
Element(const ElementSettings& settings, int id, int parent_id, const std::string& name, const std::string& type,
|
||||
const std::string& guid, const std::string& context, const gp_Trsf& trsf, IfcSchema::IfcProduct *product)
|
||||
: _id(id), _parent_id(parent_id), _name(name), _type(type), _guid(guid), _context(context), _transformation(settings, trsf)
|
||||
, product_(product)
|
||||
{
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "product-" << IfcParse::IfcGlobalId(guid).formatted();
|
||||
try { oss << "product-" << IfcParse::IfcGlobalId(guid).formatted(); }
|
||||
catch (std::exception e)
|
||||
{
|
||||
oss << "product-cannotfindId";
|
||||
}
|
||||
|
||||
if (!_context.empty()) {
|
||||
std::string ctx = _context;
|
||||
std::transform(ctx.begin(), ctx.end(), ctx.begin(), ::tolower);
|
||||
@@ -109,7 +127,6 @@ namespace IfcGeom {
|
||||
oss << "-" << ctx;
|
||||
}
|
||||
_unique_id = oss.str();
|
||||
|
||||
}
|
||||
virtual ~Element() {}
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user