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
+4 -4
View File
@@ -417,11 +417,11 @@ std::string ColladaSerializer::differentiateSlabTypes(const IfcUtil::IfcBaseEnti
{
auto value = slab->get("PredefinedType");
if (value->isNull()) {
if (value.isNull()) {
return "_Unknown";
}
const std::string str_value = *value;
const std::string str_value = value;
std::string result;
if (str_value == "FLOOR") {
@@ -436,10 +436,10 @@ std::string ColladaSerializer::differentiateSlabTypes(const IfcUtil::IfcBaseEnti
result = "_NotDefined";
} else {
auto otype = slab->get("ObjectType");
if (otype->isNull()) {
if (otype.isNull()) {
result = "_Unknown";
} else {
result = (std::string) *otype;
result = (std::string) otype;
}
}
+16 -16
View File
@@ -451,29 +451,29 @@ void GltfSerializer::setFile(IfcParse::IfcFile* f) {
}
if (coordops) {
for (auto& coordop : *coordops) {
IfcUtil::IfcBaseClass* source_crs = *coordop->as<IfcUtil::IfcBaseEntity>()->get("SourceCRS");
IfcUtil::IfcBaseClass* source_crs = coordop->as<IfcUtil::IfcBaseEntity>()->get("SourceCRS");
if (source_crs->declaration().is("IfcGeometricRepresentationContext")) {
IfcUtil::IfcBaseClass* target_crs = *coordop->as<IfcUtil::IfcBaseEntity>()->get("TargetCRS");
IfcUtil::IfcBaseClass* target_crs = coordop->as<IfcUtil::IfcBaseEntity>()->get("TargetCRS");
auto name_attr = target_crs->as<IfcUtil::IfcBaseEntity>()->get("Name");
if (coordop->declaration().is("IfcMapConversion")) {
if (!name_attr->isNull()) {
std::string epsg_code = *name_attr;
if (!name_attr.isNull()) {
std::string epsg_code = name_attr;
crs_epsg = epsg_code;
// @todo in which unit are these?
double eastings = *coordop->as<IfcUtil::IfcBaseEntity>()->get("Eastings");
double northings = *coordop->as<IfcUtil::IfcBaseEntity>()->get("Northings");
double height = *coordop->as<IfcUtil::IfcBaseEntity>()->get("OrthogonalHeight");
double eastings = coordop->as<IfcUtil::IfcBaseEntity>()->get("Eastings");
double northings = coordop->as<IfcUtil::IfcBaseEntity>()->get("Northings");
double height = coordop->as<IfcUtil::IfcBaseEntity>()->get("OrthogonalHeight");
height = 0.;
eastings_northings_elevation = { { eastings, northings, height} };
auto xaxis_attr = coordop->as<IfcUtil::IfcBaseEntity>()->get("XAxisAbscissa");
auto yaxis_attr = coordop->as<IfcUtil::IfcBaseEntity>()->get("XAxisOrdinate");
if (!xaxis_attr->isNull() && !yaxis_attr->isNull()) {
double xaxis = *xaxis_attr;
double yaxis = *yaxis_attr;
if (!xaxis_attr.isNull() && !yaxis_attr.isNull()) {
double xaxis = xaxis_attr;
double yaxis = yaxis_attr;
crs_x_axis = { { xaxis, yaxis, 0. } };
}
@@ -490,9 +490,9 @@ void GltfSerializer::setFile(IfcParse::IfcFile* f) {
auto lat_attr = (*sites->begin())->as<IfcUtil::IfcBaseEntity>()->get("RefLatitude");
auto lon_attr = (*sites->begin())->as<IfcUtil::IfcBaseEntity>()->get("RefLongitude");
if (!lat_attr->isNull() && !lon_attr->isNull()) {
std::vector<int> lat_dms = *lat_attr;
std::vector<int> lon_dms = *lon_attr;
if (!lat_attr.isNull() && !lon_attr.isNull()) {
std::vector<int> lat_dms = lat_attr;
std::vector<int> lon_dms = lon_attr;
auto to_decimal = [](const std::vector<int>& dms) {
double val = dms[0] + dms[1] / 60. + dms[2] / 3600.;
@@ -524,10 +524,10 @@ void GltfSerializer::setFile(IfcParse::IfcFile* f) {
if (contexts && contexts->size() > 0) {
auto context = (*contexts->begin())->as<IfcUtil::IfcBaseEntity>();
auto north_attr = context->get("TrueNorth");
if (!north_attr->isNull()) {
IfcUtil::IfcBaseClass* north = *north_attr;
if (!north_attr.isNull()) {
IfcUtil::IfcBaseClass* north = north_attr;
if (north->declaration().is("IfcDirection")) {
std::vector<double> ratios = *north->as<IfcUtil::IfcBaseEntity>()->get("DirectionRatios");
std::vector<double> ratios = north->as<IfcUtil::IfcBaseEntity>()->get("DirectionRatios");
crs_x_axis = { { ratios[1], -ratios[0], 0. } };
}
}
+1 -1
View File
@@ -542,7 +542,7 @@ void HdfSerializer::write_style(surface_style_serialization& data, const ifcopen
data.name = s.name.c_str();
// @todo
data.original_name = s.name.c_str();
data.id = s.instance->data().id();
data.id = s.instance->as<IfcUtil::IfcBaseClass>()->id();
if (s.diffuse) {
data.diffuse[0] = s.diffuse.ccomponents()(0);
data.diffuse[1] = s.diffuse.ccomponents()(1);
+46 -46
View File
@@ -382,7 +382,7 @@ namespace {
for (const auto& p : o->parents()) {
if (p->type() == "IfcBuildingStorey") {
try {
double e = *p->product()->get("Elevation");
double e = p->product()->get("Elevation");
double storey_elevation = e * o->geometry().settings().get<ifcopenshell::geometry::settings::LengthUnit>().get();
return std::make_pair(p->product(), storey_elevation);
} catch (...) {
@@ -495,22 +495,22 @@ namespace {
auto rels = product->get_inverse("IsDefinedBy");
for (auto& rel : *rels) {
if (rel->declaration().is("IfcRelDefinesByProperties")) {
auto pset = (IfcUtil::IfcBaseEntity*) (IfcUtil::IfcBaseClass*) *((IfcUtil::IfcBaseEntity*) rel)->get("RelatingPropertyDefinition");
auto pset = ((IfcUtil::IfcBaseClass*) ((IfcUtil::IfcBaseEntity*) rel)->get("RelatingPropertyDefinition"))->as<IfcUtil::IfcBaseEntity>();
std::string pset_name;
if (!pset->get("Name")->isNull()) {
pset_name = (std::string) *pset->get("Name");
if (!pset->get("Name").isNull()) {
pset_name = (std::string) pset->get("Name");
}
aggregate_of_instance::ptr props = *pset->get("HasProperties");
aggregate_of_instance::ptr props = pset->get("HasProperties");
for (auto& prop : *props) {
if (prop->declaration().is("IfcPropertySingleValue")) {
std::string name = *((IfcUtil::IfcBaseEntity*) prop)->get("Name");
if (((IfcUtil::IfcBaseEntity*) prop)->get("NominalValue")->isNull()) {
std::string name = ((IfcUtil::IfcBaseEntity*) prop)->get("Name");
if (((IfcUtil::IfcBaseEntity*) prop)->get("NominalValue").isNull()) {
continue;
}
IfcUtil::IfcBaseClass* v = *((IfcUtil::IfcBaseEntity*) prop)->get("NominalValue");
auto value = v->data().getArgument(0);
if (value->type() == IfcUtil::Argument_STRING) {
std::string v_str = *value;
IfcUtil::IfcBaseClass* v = ((IfcUtil::IfcBaseEntity*) prop)->get("NominalValue");
auto value = v->data().get_attribute_value(0);
if (value.type() == IfcUtil::Argument_STRING) {
std::string v_str = value;
*output_it++ = string_property{ pset_name, name, v_str };
}
}
@@ -525,12 +525,12 @@ namespace {
auto refs = item->get_inverse("StyledByItem");
for (auto& ref : *refs) {
if (ref->declaration().is("IfcStyledItem")) {
aggregate_of_instance::ptr styles = *((IfcUtil::IfcBaseEntity*)ref)->get("Styles");
aggregate_of_instance::ptr styles = ((IfcUtil::IfcBaseEntity*)ref)->get("Styles");
for (auto& s_ : *styles) {
auto s = (IfcUtil::IfcBaseEntity*) s_;
std::vector<IfcUtil::IfcBaseEntity*> pss;
if (s->declaration().is("IfcPresentationStyleAssignment")) {
aggregate_of_instance::ptr pstyles = *s->get("Styles");
aggregate_of_instance::ptr pstyles = s->get("Styles");
for (auto& ssss : *pstyles) {
pss.push_back((IfcUtil::IfcBaseEntity*) ssss);
}
@@ -540,8 +540,8 @@ namespace {
for (auto& ps : pss) {
if (ps->declaration().is("IfcCurveStyle")) {
auto arg = ps->get("Name");
if (!arg->isNull()) {
return (std::string) *arg;
if (!arg.isNull()) {
return (std::string) arg;
}
}
}
@@ -555,8 +555,8 @@ namespace {
void SvgSerializer::write(const IfcGeom::BRepElement* brep_obj) {
boost::optional<std::string> object_type;
if (!brep_obj->product()->get("ObjectType")->isNull()) {
object_type = static_cast<std::string>(*brep_obj->product()->get("ObjectType"));
if (!brep_obj->product()->get("ObjectType").isNull()) {
object_type = static_cast<std::string>(brep_obj->product()->get("ObjectType"));
}
std::vector<boost::optional<std::vector<double>>> dash_arrays;
@@ -845,11 +845,11 @@ void SvgSerializer::write(const geometry_data& data) {
}
for (auto& rel : *rels) {
if (rel->declaration().name() == "IfcRelDefinesByType") {
IfcUtil::IfcBaseClass* ty = *((IfcUtil::IfcBaseEntity*)rel)->get("RelatingType");
IfcUtil::IfcBaseClass* ty = ((IfcUtil::IfcBaseEntity*)rel)->get("RelatingType");
const std::string& ty_entity_name = ty->declaration().name();
// Damn you, IFC
if (ty_entity_name == "IfcDoorStyle" || ty_entity_name == "IfcDoorType") {
operation_type = (std::string)*((IfcUtil::IfcBaseEntity*)ty)->get("OperationType");
operation_type = (std::string)((IfcUtil::IfcBaseEntity*)ty)->get("OperationType");
}
}
}
@@ -1273,8 +1273,8 @@ void SvgSerializer::write(const geometry_data& data) {
std::string object_type;
auto ot_arg = data.product->get("ObjectType");
if (!ot_arg->isNull()) {
object_type = (std::string) *ot_arg;
if (!ot_arg.isNull()) {
object_type = (std::string) ot_arg;
object_type.erase(std::remove_if(object_type.begin(), object_type.end(), [](char c) { return !std::isalnum(c); }), object_type.end());
}
@@ -1476,8 +1476,8 @@ void SvgSerializer::write(const geometry_data& data) {
const double lu = file->getUnit("LENGTHUNIT").second;
auto a = data.product->get("Elevation");
if (!a->isNull()) {
double elev = *a;
if (!a.isNull()) {
double elev = a;
// @nb we don't actually factor in the length unit.
// elev *= lu;
@@ -1622,8 +1622,8 @@ void SvgSerializer::write(const geometry_data& data) {
}
if (print_space_names_ && data.product->declaration().is("IfcSpace")) {
auto attr = data.product->get("LongName");
if (!attr->isNull()) {
std::string long_name = *attr;
if (!attr.isNull()) {
std::string long_name = attr;
if (!long_name.empty()) {
labels.insert(labels.begin(), long_name);
}
@@ -1851,14 +1851,14 @@ void SvgSerializer::addTextAnnotations(const drawing_key& k) {
auto ds = ann->get("Description");
auto pl = ann->get("ObjectPlacement");
if (!ot->isNull() && !nm->isNull() && !ds->isNull() && !pl->isNull()) {
auto object_type = (std::string) *ot;
auto name = (std::string) *nm;
auto desc = (std::string) *ds;
if (!ot.isNull() && !nm.isNull() && !ds.isNull() && !pl.isNull()) {
auto object_type = (std::string) ot;
auto name = (std::string) nm;
auto desc = (std::string) ds;
if (object_type == "Text") {
auto mapping = ifcopenshell::geometry::impl::mapping_implementations().construct(file, geometry_settings_);
auto item = mapping->map(*pl);
auto item = mapping->map(pl);
auto matrix = ifcopenshell::geometry::taxonomy::cast<ifcopenshell::geometry::taxonomy::matrix4>(item);
delete mapping;
if (item) {
@@ -2085,8 +2085,8 @@ void SvgSerializer::finalize() {
for (auto& s : *storeys) {
auto storey = (IfcUtil::IfcBaseEntity*) s;
auto a = storey->get("Elevation");
if (!a->isNull()) {
double elev = *a;
if (!a.isNull()) {
double elev = a;
elev *= lu;
auto svg_name = nameElement(storey);
@@ -2117,8 +2117,8 @@ void SvgSerializer::finalize() {
B.Add(C, mf.Face());
std::string name;
auto a2 = storey->get("Name");
if (!a2->isNull()) {
name = (std::string) *a2;
if (!a2.isNull()) {
name = (std::string) a2;
}
write(geometry_data{
C,{boost::none},trsf,storey,storey,elev,name,nameElement(storey)
@@ -2280,12 +2280,12 @@ std::string SvgSerializer::idElement(const IfcUtil::IfcBaseEntity* elem) {
const std::string type = elem->declaration().is("IfcBuildingStorey") ? "storey" : "product";
const std::string name =
(settings().get<ifcopenshell::geometry::settings::UseElementGuids>().get()
? static_cast<std::string>(*elem->get("GlobalId"))
: ((settings().get<ifcopenshell::geometry::settings::UseElementNames>().get() && !elem->get("Name")->isNull()))
? static_cast<std::string>(*elem->get("Name"))
? static_cast<std::string>(elem->get("GlobalId"))
: ((settings().get<ifcopenshell::geometry::settings::UseElementNames>().get() && !elem->get("Name").isNull()))
? static_cast<std::string>(elem->get("Name"))
: (settings().get<ifcopenshell::geometry::settings::UseElementStepIds>().get())
? ("id-" + boost::lexical_cast<std::string>(elem->data().id()))
: IfcParse::IfcGlobalId(*elem->get("GlobalId")).formatted());
? ("id-" + boost::lexical_cast<std::string>(elem->id()))
: IfcParse::IfcGlobalId(elem->get("GlobalId")).formatted());
return type + "-" + name;
}
@@ -2294,8 +2294,8 @@ std::string SvgSerializer::nameElement(const IfcUtil::IfcBaseEntity* elem) {
const std::string& entity = elem->declaration().name();
std::string ifc_name;
if (!elem->get("Name")->isNull()) {
ifc_name = (std::string) *elem->get("Name");
if (!elem->get("Name").isNull()) {
ifc_name = (std::string) elem->get("Name");
IfcUtil::escape_xml(ifc_name);
}
@@ -2303,7 +2303,7 @@ std::string SvgSerializer::nameElement(const IfcUtil::IfcBaseEntity* elem) {
{"id", idElement(elem)},
{"class", entity},
{namespace_prefix_ + "name", ifc_name},
{namespace_prefix_ + "guid", *elem->get("GlobalId")}
{namespace_prefix_ + "guid", elem->get("GlobalId")}
});
}
@@ -2322,8 +2322,8 @@ void SvgSerializer::setFile(IfcParse::IfcFile* f) {
if (insts) {
for (auto jt = insts->begin(); jt != insts->end(); ++jt) {
IfcUtil::IfcBaseEntity* product = (IfcUtil::IfcBaseEntity*) *jt;
if (!product->get("ObjectPlacement")->isNull()) {
auto item = mapping->map(*product->get("ObjectPlacement"));
if (!product->get("ObjectPlacement").isNull()) {
auto item = mapping->map(product->get("ObjectPlacement"));
auto matrix = ifcopenshell::geometry::taxonomy::cast<ifcopenshell::geometry::taxonomy::matrix4>(item);
gp_Trsf trsf;
if (matrix) {
@@ -2363,10 +2363,10 @@ void SvgSerializer::setSectionHeightsFromStoreys(double offset) {
if (storeys && storeys->size() > 0) {
for (auto& s : *storeys) {
auto attr_value = ((IfcUtil::IfcBaseEntity*)s)->get("Elevation");
if (!attr_value->isNull()) {
if (!attr_value.isNull()) {
double elev;
try {
elev = *attr_value;
elev = attr_value;
} catch (std::exception& e) {
Logger::Error(e);
continue;
+6 -6
View File
@@ -77,12 +77,12 @@ struct storey_sorter {
if (a_is_storey && b_is_storey) {
boost::optional<double> a_elev, b_elev;
try {
a_elev = static_cast<double>(*a->get("Elevation"));
b_elev = static_cast<double>(*b->get("Elevation"));
a_elev = static_cast<double>(a->get("Elevation"));
b_elev = static_cast<double>(b->get("Elevation"));
} catch (...) {};
if (a_elev && b_elev) {
if (std::equal_to<double>()(*a_elev, *b_elev)) {
return std::less<unsigned int>()(a->data().id(), b->data().id());
return std::less<unsigned int>()(a->id(), b->id());
} else {
return std::less<double>()(*a_elev, *b_elev);
}
@@ -90,12 +90,12 @@ struct storey_sorter {
boost::optional<std::string> a_name, b_name;
try {
a_name = static_cast<std::string>(*a->get("Name"));
b_name = static_cast<std::string>(*b->get("Name"));
a_name = static_cast<std::string>(a->get("Name"));
b_name = static_cast<std::string>(b->get("Name"));
} catch (...) {};
if (a_name && b_name) {
if (std::equal_to<std::string>()(*a_name, *b_name)) {
return std::less<unsigned int>()(a->data().id(), b->data().id());
return std::less<unsigned int>()(a->id(), b->id());
} else {
return std::less<std::string>()(*a_name, *b_name);
}
@@ -57,7 +57,7 @@ std::map<std::string, std::string> POSTFIX_SCHEMA(argument_name_map);
// Format an IFC attribute and maybe returns as string. Only literal scalar
// values are converted. Things like entity instances and lists are omitted.
boost::optional<std::string> format_attribute(ifcopenshell::geometry::abstract_mapping* mapping, const Argument* argument, IfcUtil::ArgumentType argument_type, const std::string& argument_name) {
boost::optional<std::string> format_attribute(ifcopenshell::geometry::abstract_mapping* mapping, AttributeValue argument, IfcUtil::ArgumentType argument_type, const std::string& argument_name) {
boost::optional<std::string> value;
// Hard-code lat-lon as it represents an array
@@ -65,7 +65,7 @@ boost::optional<std::string> format_attribute(ifcopenshell::geometry::abstract_m
if (argument_name == "IfcSite.RefLatitude" ||
argument_name == "IfcSite.RefLongitude")
{
std::vector<int> angle = *argument;
std::vector<int> angle = argument;
double deg;
if (angle.size() >= 3) {
deg = angle[0] + angle[1] / 60. + angle[2] / 3600.;
@@ -83,30 +83,30 @@ boost::optional<std::string> format_attribute(ifcopenshell::geometry::abstract_m
switch(argument_type) {
case IfcUtil::Argument_BOOL: {
const bool b = *argument;
const bool b = argument;
value = b ? "true" : "false";
break; }
case IfcUtil::Argument_DOUBLE: {
const double d = *argument;
const double d = argument;
std::stringstream stream;
stream << std::setprecision (std::numeric_limits< double >::max_digits10) << d;
value = stream.str();
break; }
case IfcUtil::Argument_STRING:
case IfcUtil::Argument_ENUMERATION: {
value = static_cast<std::string>(*argument);
value = static_cast<std::string>(argument);
break; }
case IfcUtil::Argument_INT: {
const int v = *argument;
const int v = argument;
std::stringstream stream;
stream << v;
value = stream.str();
break; }
case IfcUtil::Argument_ENTITY_INSTANCE: {
IfcUtil::IfcBaseClass* e = *argument;
IfcUtil::IfcBaseClass* e = argument;
if (!e->declaration().as_entity()) {
IfcUtil::IfcBaseType* f = e->as<IfcUtil::IfcBaseType>();
value = format_attribute(mapping, f->data().getArgument(0), f->data().getArgument(0)->type(), argument_name);
value = format_attribute(mapping, f->data().get_attribute_value(0), f->data().get_attribute_value(0).type(), argument_name);
} else if (e->declaration().is(IfcSchema::IfcSIUnit::Class()) || e->declaration().is(IfcSchema::IfcConversionBasedUnit::Class())) {
// Some string concatenation to have a unit name as a XML attribute.
@@ -155,13 +155,13 @@ ptree* format_entity_instance(ifcopenshell::geometry::abstract_mapping* mapping,
const unsigned n = instance->declaration().attribute_count();
for (unsigned i = 0; i < n; ++i) {
try {
instance->data().getArgument(i);
instance->data().get_attribute_value(i);
} catch (const std::exception&) {
Logger::Error("Expected " + boost::lexical_cast<std::string>(n) + " attributes for:", instance);
break;
}
const Argument* argument = instance->data().getArgument(i);
if (argument->isNull()) continue;
auto argument = instance->data().get_attribute_value(i);
if (argument.isNull()) continue;
std::string argument_name = instance->declaration().attribute_by_index(i)->name();
std::map<std::string, std::string>::const_iterator argument_name_it;
@@ -169,7 +169,7 @@ ptree* format_entity_instance(ifcopenshell::geometry::abstract_mapping* mapping,
if (argument_name_it != POSTFIX_SCHEMA(argument_name_map).end()) {
argument_name = argument_name_it->second;
}
const IfcUtil::ArgumentType argument_type = instance->data().getArgument(i)->type();
const IfcUtil::ArgumentType argument_type = instance->data().get_attribute_value(i).type();
const std::string qualified_name = instance->declaration().name() + "." + argument_name;
boost::optional<std::string> value;
@@ -202,7 +202,7 @@ ptree* format_entity_instance(ifcopenshell::geometry::abstract_mapping* mapping,
}
std::string qualify_unrooted_instance(IfcUtil::IfcBaseInterface* inst) {
return inst->declaration().name() + "_" + boost::lexical_cast<std::string>(inst->data().id());
return inst->declaration().name() + "_" + boost::lexical_cast<std::string>(inst->as<IfcUtil::IfcBaseEntity>()->id());
}
// A function to be called recursively. Template specialization is used