Unify variant storage (#5118)

This commit is contained in:
Thomas Krijnen
2024-08-23 20:29:07 +02:00
committed by GitHub
parent e2001e82dd
commit d80bcd1a94
107 changed files with 118028 additions and 142394 deletions
+12 -12
View File
@@ -35,7 +35,7 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_represe
auto place = place_;
representation_id_builder << representation_node->instance->data().id();
representation_id_builder << representation_node->instance->as<IfcUtil::IfcBaseEntity>()->id();
IfcGeom::Representation::BRep* shape;
IfcGeom::ConversionResults shapes;
@@ -137,7 +137,7 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_represe
}
if (material_style_applied) {
representation_id_builder << "-material-" << single_material->data().id();
representation_id_builder << "-material-" << single_material->id();
}
if (settings_.get<ifcopenshell::geometry::settings::ForceSpaceTransparency>().has() && product->declaration().is("IfcSpace")) {
@@ -153,7 +153,7 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_represe
try {
IfcUtil::IfcBaseEntity* parent_object = mapping_->get_decomposing_entity(product);
if (parent_object) {
parent_id = parent_object->data().id();
parent_id = parent_object->id();
}
} catch (const std::exception& e) {
Logger::Error(e);
@@ -171,7 +171,7 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_represe
if (!settings_.get<ifcopenshell::geometry::settings::DisableOpeningSubtractions>().get() && openings && openings->size()) {
representation_id_builder << "-openings";
for (auto it = openings->begin(); it != openings->end(); ++it) {
representation_id_builder << "-" << (*it)->data().id();
representation_id_builder << "-" << (*it)->id();
}
IfcGeom::ConversionResults opened_shapes;
@@ -236,19 +236,19 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_represe
// IfcShapeRepresentation.
const IfcUtil::IfcBaseEntity *representation = representation_node->instance->as<IfcUtil::IfcBaseEntity>();
auto representation_identifier = representation->get("RepresentationIdentifier");
if (!representation_identifier->isNull()) {
context_string = (std::string) *representation_identifier;
if (!representation_identifier.isNull()) {
context_string = (std::string) representation_identifier;
}
else {
IfcUtil::IfcBaseClass *context = (IfcUtil::IfcBaseClass *) *representation->get("ContextOfItems");
IfcUtil::IfcBaseClass *context = (IfcUtil::IfcBaseClass*)representation->get("ContextOfItems");
auto context_type = context->as<IfcUtil::IfcBaseEntity>()->get("ContextType");
if (!context_type->isNull()) {
context_string = (std::string) *context_type;
if (!context_type.isNull()) {
context_string = (std::string)context_type;
}
}
auto elem = new IfcGeom::BRepElement(
product->data().id(),
product->id(),
parent_id,
name,
product_type,
@@ -340,7 +340,7 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_process
try {
IfcUtil::IfcBaseEntity* parent_object = mapping_->get_decomposing_entity(product);
if (parent_object) {
parent_id = parent_object->data().id();
parent_id = parent_object->id();
}
} catch (const std::exception& e) {
Logger::Error(e);
@@ -352,7 +352,7 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_process
const std::string context_string = brep->context();
return new IfcGeom::BRepElement(
product->data().id(),
product->id(),
parent_id,
name,
product_type,
+5 -5
View File
@@ -73,12 +73,12 @@ namespace IfcGeom {
friend bool operator < (const Element& element1, const Element& element2) {
if (element1.type() == "IfcBuildingStorey" && element2.type() == "IfcBuildingStorey") {
size_t attr_index = element1.product()->declaration().attribute_index("Elevation");
Argument* elev_attr1 = element1.product()->data().getArgument(attr_index);
Argument* elev_attr2 = element2.product()->data().getArgument(attr_index);
auto elev_attr1 = element1.product()->data().get_attribute_value(attr_index);
auto elev_attr2 = element2.product()->data().get_attribute_value(attr_index);
if (!elev_attr1->isNull() && !elev_attr2->isNull()) {
double elev1 = *elev_attr1;
double elev2 = *elev_attr2;
if (!elev_attr1.isNull() && !elev_attr2.isNull()) {
double elev1 = elev_attr1;
double elev2 = elev_attr2;
return elev1 < elev2;
}
+4 -4
View File
@@ -76,7 +76,7 @@ namespace IfcGeom {
// schema.
// @todo pass settings
ifcopenshell::geometry::Settings s;
static auto mapping = ifcopenshell::geometry::impl::mapping_implementations().construct(prod->data().file, s);
static auto mapping = ifcopenshell::geometry::impl::mapping_implementations().construct(prod->file_, s);
while ((parent = mapping->get_decomposing_entity(current, traverse_openings)) != nullptr) {
if (pred(parent)) {
return true;
@@ -138,7 +138,7 @@ namespace IfcGeom {
std::string value(IfcUtil::IfcBaseEntity* prod) const {
try {
return (std::string) *prod->get(attribute_name);
return (std::string) prod->get(attribute_name);
} catch (...) {
// Either
// (a) not an attribute name for this entity instance
@@ -184,7 +184,7 @@ namespace IfcGeom {
bool match(IfcUtil::IfcBaseEntity* prod) const {
// @todo
ifcopenshell::geometry::Settings s;
static auto mapping = ifcopenshell::geometry::impl::mapping_implementations().construct(prod->data().file, s);
static auto mapping = ifcopenshell::geometry::impl::mapping_implementations().construct(prod->file_, s);
layer_map_t layers = mapping->get_layers(prod);
return std::find_if(layers.begin(), layers.end(), wildcards_match(values)) != layers.end();
}
@@ -255,7 +255,7 @@ namespace IfcGeom {
, instance_ids_(instance_ids) {}
bool match(IfcUtil::IfcBaseEntity* prod) const {
return instance_ids_.find(prod->data().id()) != instance_ids_.end();
return instance_ids_.find(prod->id()) != instance_ids_.end();
}
bool operator()(IfcUtil::IfcBaseEntity* prod) const {
+1 -1
View File
@@ -154,7 +154,7 @@ IfcGeom::Representation::Serialization::Serialization(const BRep& brep)
surface_styles_.push_back(clr(1));
surface_styles_.push_back(clr(2));
sid = it->Style().instance ? it->Style().instance->data().id() : -1;
sid = it->Style().instance ? it->Style().instance->as<IfcUtil::IfcBaseEntity>()->id() : -1;
} else {
surface_styles_.push_back(-1.);
surface_styles_.push_back(-1.);
+4 -4
View File
@@ -518,7 +518,7 @@ namespace IfcGeom {
Logger::SetProduct(product);
IfcGeom::BRepElement* brep = static_cast<IfcGeom::BRepElement*>(decorate_with_cache_(GeometrySerializer::READ_BREP, (std::string)*product->get("GlobalId"), std::to_string(representation->instance->data().id()), [kernel, settings, product, place, representation]() {
IfcGeom::BRepElement* brep = static_cast<IfcGeom::BRepElement*>(decorate_with_cache_(GeometrySerializer::READ_BREP, (std::string)product->get("GlobalId"), std::to_string(representation->instance->as<IfcUtil::IfcBaseEntity>()->id()), [kernel, settings, product, place, representation]() {
return kernel->create_brep_for_representation_and_product(representation, product, place);
}));
@@ -539,7 +539,7 @@ namespace IfcGeom {
const IfcUtil::IfcBaseEntity* product2 = p.first;
const auto& place2 = p.second;
IfcGeom::BRepElement* brep2 = static_cast<IfcGeom::BRepElement*>(decorate_with_cache_(GeometrySerializer::READ_BREP, (std::string)*product2->get("GlobalId"), std::to_string(representation->instance->data().id()), [kernel, settings, product2, place2, representation, brep]() {
IfcGeom::BRepElement* brep2 = static_cast<IfcGeom::BRepElement*>(decorate_with_cache_(GeometrySerializer::READ_BREP, (std::string)product2->get("GlobalId"), std::to_string(representation->instance->as<IfcUtil::IfcBaseEntity>()->id()), [kernel, settings, product2, place2, representation, brep]() {
return kernel->create_brep_for_processed_representation(product2, place2, brep);
}));
if (brep2) {
@@ -746,13 +746,13 @@ namespace IfcGeom {
instance_type = ifc_product->declaration().name();
if (ifc_product->declaration().is("IfcRoot")) {
product_guid = (std::string) *ifc_product->get("GlobalId");
product_guid = (std::string) ifc_product->get("GlobalId");
product_name = ifc_product->get_value<std::string>("Name", "");
}
auto parent_object = converter_->mapping()->get_decomposing_entity(ifc_product);
if (parent_object) {
parent_id = parent_object->data().id();
parent_id = parent_object->id();
}
// fails in case of IfcProject
+2
View File
@@ -30,8 +30,10 @@ namespace geometry {
Settings settings_;
bool use_caching_ = true;
public:
abstract_mapping(Settings& s) : settings_(s) {}
virtual ~abstract_mapping() {}
virtual ifcopenshell::geometry::taxonomy::ptr map(const IfcUtil::IfcBaseInterface*) = 0;
virtual void get_representations(std::vector<geometry_conversion_task>& tasks, std::vector<filter_t>& filters) = 0;
+5 -5
View File
@@ -767,7 +767,7 @@ bool CgalKernel::convert_impl(const taxonomy::shell::ptr shell, ConversionResult
return false;
}
results.emplace_back(ConversionResult(
shell->instance->data().id(),
shell->instance->as<IfcUtil::IfcBaseEntity>()->id(),
shell->matrix,
new CgalShape(shape),
shell->surface_style
@@ -788,7 +788,7 @@ bool CgalKernel::convert_impl(const taxonomy::solid::ptr solid, ConversionResult
return false;
}
results.emplace_back(ConversionResult(
solid->instance->data().id(),
solid->instance->as<IfcUtil::IfcBaseEntity>()->id(),
solid->matrix,
new CgalShape(shape),
solid->surface_style
@@ -938,7 +938,7 @@ bool CgalKernel::convert_impl(const taxonomy::extrusion::ptr extrusion, Conversi
return false;
}
results.emplace_back(ConversionResult(
extrusion->instance->data().id(),
extrusion->instance->as<IfcUtil::IfcBaseEntity>()->id(),
extrusion->matrix,
new CgalShape(shape),
extrusion->surface_style
@@ -1814,7 +1814,7 @@ bool CgalKernel::convert_impl(const taxonomy::boolean_result::ptr br, Conversion
}
return ConversionResult(
br->instance->data().id(),
br->instance->as<IfcUtil::IfcBaseEntity>()->id(),
br->matrix,
new CgalShape(shp),
br->surface_style ? br->surface_style : first_item_style
@@ -2047,7 +2047,7 @@ bool CgalKernel::convert_impl(const taxonomy::boolean_result::ptr br, Conversion
}
results.emplace_back(ConversionResult(
br->instance->data().id(),
br->instance->as<IfcUtil::IfcBaseEntity>()->id(),
br->matrix,
new CgalShape(a_poly),
br->surface_style ? br->surface_style : first_item_style
@@ -408,7 +408,7 @@ bool IfcGeom::OpenCascadeKernel::convert_impl(const taxonomy::revolve::ptr r, If
TopoDS_Shape shape = BRepPrimAPI_MakeRevol(face, ax);
results.emplace_back(ConversionResult(
r->instance->data().id(),
r->instance->as<IfcUtil::IfcBaseEntity>()->id(),
r->matrix,
new OpenCascadeShape(shape),
r->surface_style
@@ -107,7 +107,7 @@ bool OpenCascadeKernel::convert_impl(const taxonomy::boolean_result::ptr br, Con
if (settings_.get<settings::DisableBooleanResult>().get()) {
results.emplace_back(IfcGeom::ConversionResult(
(int)br->instance->data().id(),
br->instance->as<IfcUtil::IfcBaseEntity>()->id(),
br->matrix,
new OpenCascadeShape(a),
br->surface_style ? br->surface_style : first_item_style
@@ -189,7 +189,7 @@ bool OpenCascadeKernel::convert_impl(const taxonomy::boolean_result::ptr br, Con
}
results.emplace_back(IfcGeom::ConversionResult(
(int) br->instance->data().id(),
br->instance->as<IfcUtil::IfcBaseEntity>()->id(),
br->matrix,
new OpenCascadeShape(a),
br->surface_style ? br->surface_style : first_item_style
@@ -78,7 +78,7 @@ bool OpenCascadeKernel::convert_impl(const taxonomy::extrusion::ptr extrusion, I
}
results.emplace_back(ConversionResult(
extrusion->instance->data().id(),
extrusion->instance->as<IfcUtil::IfcBaseEntity>()->id(),
extrusion->matrix,
new OpenCascadeShape(shape),
extrusion->surface_style
+1 -1
View File
@@ -528,7 +528,7 @@ bool OpenCascadeKernel::convert_impl(const taxonomy::face::ptr face, IfcGeom::Co
return false;
}
results.emplace_back(ConversionResult(
face->instance->data().id(),
face->instance->as<IfcUtil::IfcBaseEntity>()->id(),
new OpenCascadeShape(shape),
face->surface_style
));
+1 -1
View File
@@ -113,7 +113,7 @@ bool OpenCascadeKernel::convert_impl(const taxonomy::loft::ptr loft, IfcGeom::Co
return false;
}
results.emplace_back(ConversionResult(
loft->instance->data().id(),
loft->instance->as<IfcUtil::IfcBaseEntity>()->id(),
loft->matrix,
new OpenCascadeShape(shape),
loft->surface_style
+2 -2
View File
@@ -363,7 +363,7 @@ bool OpenCascadeKernel::convert_impl(const taxonomy::loop::ptr loop, IfcGeom::Co
}
results.emplace_back(ConversionResult(
loop->instance->data().id(),
loop->instance->as<IfcUtil::IfcBaseEntity>()->id(),
new OpenCascadeShape(shape),
loop->surface_style
));
@@ -374,7 +374,7 @@ bool OpenCascadeKernel::convert_impl(const taxonomy::edge::ptr edge, IfcGeom::Co
TopoDS_Wire shape = boost::get<TopoDS_Wire>(convert_curve(edge));
results.emplace_back(ConversionResult(
edge->instance->data().id(),
edge->instance->as<IfcUtil::IfcBaseEntity>()->id(),
new OpenCascadeShape(shape),
edge->surface_style
));
+1 -1
View File
@@ -112,7 +112,7 @@ bool OpenCascadeKernel::convert_impl(const taxonomy::shell::ptr shell, IfcGeom::
return false;
}
results.emplace_back(ConversionResult(
shell->instance->data().id(),
shell->instance->as<IfcUtil::IfcBaseEntity>()->id(),
shell->matrix,
new OpenCascadeShape(shape),
shell->surface_style
+1 -1
View File
@@ -107,7 +107,7 @@ bool OpenCascadeKernel::convert_impl(const taxonomy::solid::ptr solid, IfcGeom::
return false;
}
results.emplace_back(ConversionResult(
solid->instance->data().id(),
solid->instance->as<IfcUtil::IfcBaseEntity>()->id(),
solid->matrix,
new OpenCascadeShape(shape),
solid->surface_style
@@ -148,7 +148,7 @@ bool OpenCascadeKernel::convert_impl(const taxonomy::sweep_along_curve::ptr scs,
return false;
}
results.emplace_back(ConversionResult(
scs->instance->data().id(),
scs->instance->as<IfcUtil::IfcBaseEntity>()->id(),
scs->matrix,
new OpenCascadeShape(shape),
scs->surface_style
+1 -1
View File
@@ -85,7 +85,7 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCompositeCurve* inst) {
}
if (pwfs.empty()) {
aggregate_of_instance::ptr profile = inst->data().getInverse(&IfcSchema::IfcProfileDef::Class(), -1);
aggregate_of_instance::ptr profile = inst->file_->getInverse(inst->id(), &IfcSchema::IfcProfileDef::Class(), -1);
const bool force_close = profile && profile->size() > 0;
loop->closed = force_close;
loop->instance = inst;
+1 -1
View File
@@ -67,7 +67,7 @@ double translate_if_param_value(const IfcSchema::IfcCurve* crv, IfcSchema::IfcCu
// We don't care whether length- or positive length measure.
return translate_to_length_measure(crv, *param);
} else {
return *val->data().getArgument(0);
return val->data().get_attribute_value(0);
}
}
+2 -2
View File
@@ -117,9 +117,9 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcTrimmedCurve* inst) {
// or trimmed segment would be whether there are other curve segments or this
// is the only one.
boost::optional<size_t> num_segments;
auto segment = inst->data().getInverse(&IfcSchema::IfcCompositeCurveSegment::Class(), -1);
auto segment = inst->file_->getInverse(inst->id(), & IfcSchema::IfcCompositeCurveSegment::Class(), -1);
if (segment->size() == 1) {
auto comp = (*segment->begin())->data().getInverse(&IfcSchema::IfcCompositeCurve::Class(), -1);
auto comp = (*segment->begin())->file_->getInverse((*segment->begin())->id(), &IfcSchema::IfcCompositeCurve::Class(), -1);
if (comp->size() == 1) {
num_segments = (*comp->begin())->as<IfcSchema::IfcCompositeCurve>()->Segments()->size();
}
+12 -12
View File
@@ -59,7 +59,7 @@ IfcSchema::IfcProduct::list::ptr mapping::products_represented_by(const IfcSchem
// IfcProductRepresentation also lacks the INVERSE relation to IfcProduct
// Let's find the IfcProducts that reference the IfcProductRepresentation anyway
products->push((*it)->data().getInverse((&IfcSchema::IfcProduct::Class()), -1)->as<IfcSchema::IfcProduct>());
products->push((*it)->file_->getInverse((*it)->id(), &IfcSchema::IfcProduct::Class(), -1)->as<IfcSchema::IfcProduct>());
}
if (only_direct) {
@@ -81,13 +81,13 @@ IfcSchema::IfcProduct::list::ptr mapping::products_represented_by(const IfcSchem
continue;
}
IfcSchema::IfcRepresentation::list::ptr reps = item->data().getInverse((&IfcSchema::IfcRepresentation::Class()), -1)->as<IfcSchema::IfcRepresentation>();
IfcSchema::IfcRepresentation::list::ptr reps = item->file_->getInverse(item->id(), (&IfcSchema::IfcRepresentation::Class()), -1)->as<IfcSchema::IfcRepresentation>();
for (IfcSchema::IfcRepresentation::list::it jt = reps->begin(); jt != reps->end(); ++jt) {
IfcSchema::IfcRepresentation* rep = *jt;
if (rep->Items()->size() != 1) continue;
IfcSchema::IfcProductRepresentation::list::ptr prodreps_mapped = rep->OfProductRepresentation();
for (IfcSchema::IfcProductRepresentation::list::it kt = prodreps_mapped->begin(); kt != prodreps_mapped->end(); ++kt) {
IfcSchema::IfcProduct::list::ptr ps = (*kt)->data().getInverse((&IfcSchema::IfcProduct::Class()), -1)->as<IfcSchema::IfcProduct>();
IfcSchema::IfcProduct::list::ptr ps = (*kt)->file_->getInverse((*kt)->id(), (&IfcSchema::IfcProduct::Class()), -1)->as<IfcSchema::IfcProduct>();
products->push(ps);
}
}
@@ -273,7 +273,7 @@ const IfcUtil::IfcBaseEntity* mapping::get_product_type(const IfcUtil::IfcBaseEn
}
#endif
// Avoid segfault if RelatingType is unset.
if (rel->get("RelatingType")->isNull()){
if (rel->get("RelatingType").isNull()){
break;
return nullptr;
}
@@ -303,7 +303,7 @@ const IfcUtil::IfcBaseEntity* mapping::get_single_material_association(const Ifc
if (associated_material->as<IfcSchema::IfcMaterialLayerSetUsage>() || associated_material->as<IfcSchema::IfcMaterialLayerSet>()) {
IfcSchema::IfcMaterialLayerSet* layerset;
if (auto *m = associated_material->as<IfcSchema::IfcMaterialLayerSetUsage>()) {
if (m->get("ForLayerSet")->isNull()) {
if (m->get("ForLayerSet").isNull()) {
Logger::Warning("Missing ForLayerSet for:", m);
return nullptr;
}
@@ -322,7 +322,7 @@ const IfcUtil::IfcBaseEntity* mapping::get_single_material_association(const Ifc
if (associated_material->as<IfcSchema::IfcMaterialProfileSetUsage>() || associated_material->as<IfcSchema::IfcMaterialProfileSet>()) {
IfcSchema::IfcMaterialProfileSet* profileset;
if (auto* m = associated_material->as<IfcSchema::IfcMaterialProfileSetUsage>()) {
if (m->get("ForProfileSet")->isNull()) {
if (m->get("ForProfileSet").isNull()) {
Logger::Warning("Missing ForProfileSet for:", m);
return nullptr;
}
@@ -523,7 +523,7 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcMaterial* material) {
material_style->name = material->Name();
} else {
std::ostringstream oss;
oss << material->declaration().name() << "-" << material->data().id();
oss << material->declaration().name() << "-" << material->id();
material_style->name = oss.str();
}
return material_style;
@@ -553,7 +553,7 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcStyledItem* inst) {
} else {
std::ostringstream oss;
if (shading) {
oss << shading->declaration().name() << "-" << shading->data().id();
oss << shading->declaration().name() << "-" << shading->id();
} else {
oss << "-";
}
@@ -693,8 +693,8 @@ IfcUtil::IfcBaseEntity* mapping::get_decomposing_entity(const IfcUtil::IfcBaseEn
/* Parent decompositions to the RelatingObject */
if (!parent) {
aggregate_of_instance::ptr parents = product->data().getInverse((&IfcSchema::IfcRelAggregates::Class()), -1);
parents->push(product->data().getInverse((&IfcSchema::IfcRelNests::Class()), -1));
aggregate_of_instance::ptr parents = product->file_->getInverse(product->id(), (&IfcSchema::IfcRelAggregates::Class()), -1);
parents->push(product->file_->getInverse(product->id(), (&IfcSchema::IfcRelNests::Class()), -1));
for (aggregate_of_instance::it it = parents->begin(); it != parents->end(); ++it) {
IfcSchema::IfcRelDecomposes* decompose = (*it)->as<IfcSchema::IfcRelDecomposes>();
IfcUtil::IfcBaseEntity* ifc_objectdef;
@@ -827,11 +827,11 @@ void mapping::initialize_settings() {
// See if there is a context_id filter and whether the context is selected
if (settings_.get<settings::ContextIds>().has()) {
auto cids = settings_.get<settings::ContextIds>().get();
if (cids.find(context->data().id()) == cids.end()) {
if (cids.find(context->id()) == cids.end()) {
bool selected_sub_context = false;
auto subs = context->HasSubContexts();
for (auto& sub : *subs) {
if (cids.find(context->data().id()) != cids.end()) {
if (cids.find(context->id()) != cids.end()) {
selected_sub_context = true;
break;
}
+3 -1
View File
@@ -588,7 +588,9 @@ void ifcopenshell::geometry::taxonomy::trimmed_curve::print(std::ostream& o, int
}
if (this->instance) {
o << std::string(indent + 4, ' ') << this->instance->data().toString() << std::endl;
std::ostringstream oss;
this->instance->as<IfcUtil::IfcBaseClass>()->toString(oss);
o << std::string(indent + 4, ' ') << oss.str() << std::endl;
}
}