This commit is contained in:
Thomas Krijnen
2016-05-24 13:50:50 +02:00
parent 85ddae1228
commit 38d1ec7a78
4 changed files with 71 additions and 37 deletions
+16 -4
View File
@@ -27,6 +27,8 @@
#include <algorithm> #include <algorithm>
#include "../ifcparse/IfcSIPrefix.h"
using boost::property_tree::ptree; using boost::property_tree::ptree;
using namespace IfcSchema; using namespace IfcSchema;
@@ -78,9 +80,6 @@ boost::optional<std::string> format_attribute(const Argument* argument, IfcUtil:
unit_name = unit->Name(); unit_name = unit->Name();
} }
// TODO add toLower() and toUpper() string helper functions for the project
std::transform(unit_name.begin(), unit_name.end(), unit_name.begin(), ::tolower);
value = unit_name; value = unit_name;
} }
break; } break; }
@@ -252,7 +251,7 @@ void XmlSerializer::finalize() {
} }
IfcProject* project = *projects->begin(); IfcProject* project = *projects->begin();
ptree root, header, decomposition, properties; ptree root, header, units, decomposition, properties;
// Write the SPF header as XML nodes. // Write the SPF header as XML nodes.
foreach(const std::string& s, file->header().file_description().description()) { foreach(const std::string& s, file->header().file_description().description()) {
@@ -285,7 +284,20 @@ void XmlSerializer::finalize() {
format_properties(pset->HasProperties(), node); format_properties(pset->HasProperties(), node);
} }
// Write all assigned units as XML nodes.
IfcEntityList::ptr unit_assignments = project->UnitsInContext()->Units();
for (IfcEntityList::it it = unit_assignments->begin(); it != unit_assignments->end(); ++it) {
if ((*it)->is(IfcSchema::Type::IfcNamedUnit)) {
IfcSchema::IfcNamedUnit* named_unit = (*it)->as<IfcSchema::IfcNamedUnit>();
ptree& node = format_entity_instance(named_unit, units);
node.put("<xmlattr>.SI_equivalent", IfcParse::get_SI_equivalent(named_unit));
} else if ((*it)->is(IfcSchema::Type::IfcMonetaryUnit)) {
format_entity_instance((*it)->as<IfcSchema::IfcMonetaryUnit>(), units);
}
}
root.add_child("ifc.header", header); root.add_child("ifc.header", header);
root.add_child("ifc.units", units);
root.add_child("ifc.properties", properties); root.add_child("ifc.properties", properties);
root.add_child("ifc.decomposition", decomposition); root.add_child("ifc.decomposition", decomposition);
+25 -32
View File
@@ -1293,43 +1293,36 @@ std::pair<std::string, double> IfcGeom::Kernel::initializeUnits(IfcSchema::IfcUn
if (!units || !units->size()) { if (!units || !units->size()) {
Logger::Message(Logger::LOG_ERROR, "No unit information found"); Logger::Message(Logger::LOG_ERROR, "No unit information found");
} else { } else {
for ( IfcEntityList::it it = units->begin(); it != units->end(); ++ it ) { for (IfcEntityList::it it = units->begin(); it != units->end(); ++it) {
std::string current_unit_name = ""; std::string current_unit_name = "";
IfcUtil::IfcBaseClass* base = *it; IfcUtil::IfcBaseClass* base = *it;
IfcSchema::IfcSIUnit* unit = 0; IfcSchema::IfcSIUnit* unit = 0;
double value = 1.f; if (base->is(IfcSchema::Type::IfcNamedUnit)) {
if ( base->is(IfcSchema::Type::IfcConversionBasedUnit) ) { IfcSchema::IfcNamedUnit* named_unit = base->as<IfcSchema::IfcNamedUnit>();
IfcSchema::IfcConversionBasedUnit* u = (IfcSchema::IfcConversionBasedUnit*)base; if (named_unit->UnitType() == IfcSchema::IfcUnitEnum::IfcUnit_LENGTHUNIT ||
current_unit_name = u->Name(); named_unit->UnitType() == IfcSchema::IfcUnitEnum::IfcUnit_PLANEANGLEUNIT)
IfcSchema::IfcMeasureWithUnit* u2 = u->ConversionFactor(); {
IfcSchema::IfcUnit* u3 = u2->UnitComponent(); std::string current_unit_name;
if ( u3->is(IfcSchema::Type::IfcSIUnit) ) { const double current_unit_magnitude = IfcParse::get_SI_equivalent(named_unit);
unit = (IfcSchema::IfcSIUnit*) u3; if (current_unit_magnitude != 0.) {
} if (named_unit->is(IfcSchema::Type::IfcConversionBasedUnit)) {
IfcSchema::IfcValue* v = u2->ValueComponent(); IfcSchema::IfcConversionBasedUnit* u = (IfcSchema::IfcConversionBasedUnit*)base;
// Quick hack to get the numeric value from an IfcValue: current_unit_name = u->Name();
const double f = *v->entity->getArgument(0); } else if (named_unit->is(IfcSchema::Type::IfcSIUnit)) {
value *= f; IfcSchema::IfcSIUnit* si_unit = named_unit->as<IfcSchema::IfcSIUnit>();
} else if ( base->is(IfcSchema::Type::IfcSIUnit) ) { if (si_unit->hasPrefix()) {
unit = (IfcSchema::IfcSIUnit*)base; current_unit_name = IfcSchema::IfcSIPrefix::ToString(si_unit->Prefix()) + unit_name;
} }
if ( unit ) { current_unit_name += IfcSchema::IfcSIUnitName::ToString(si_unit->Name());
if ( unit->hasPrefix() ) { }
value *= IfcParse::IfcSIPrefixToValue(unit->Prefix()); if (named_unit->UnitType() == IfcSchema::IfcUnitEnum::IfcUnit_LENGTHUNIT) {
} unit_name = current_unit_name;
IfcSchema::IfcUnitEnum::IfcUnitEnum type = unit->UnitType(); unit_magnitude = current_unit_magnitude;
if ( type == IfcSchema::IfcUnitEnum::IfcUnit_LENGTHUNIT ) { setValue(IfcGeom::Kernel::GV_LENGTH_UNIT, current_unit_magnitude);
setValue(IfcGeom::Kernel::GV_LENGTH_UNIT,value); } else {
if (current_unit_name.empty()) { setValue(IfcGeom::Kernel::GV_PLANEANGLE_UNIT, current_unit_magnitude);
if (unit->hasPrefix()) {
current_unit_name = IfcSchema::IfcSIPrefix::ToString(unit->Prefix());
} }
current_unit_name += IfcSchema::IfcSIUnitName::ToString(unit->Name());
} }
unit_magnitude = value;
unit_name = current_unit_name;
} else if ( type == IfcSchema::IfcUnitEnum::IfcUnit_PLANEANGLEUNIT ) {
setValue(IfcGeom::Kernel::GV_PLANEANGLE_UNIT, value);
} }
} }
} }
+27
View File
@@ -37,3 +37,30 @@ double IfcParse::IfcSIPrefixToValue(IfcSchema::IfcSIPrefix::IfcSIPrefix v) {
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_ATTO ) return 1.e-18; else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_ATTO ) return 1.e-18;
else return 1.; else return 1.;
} }
double IfcParse::get_SI_equivalent(IfcSchema::IfcNamedUnit* named_unit) {
double scale = 1.;
IfcSchema::IfcSIUnit* si_unit = 0;
if (named_unit->is(IfcSchema::Type::IfcConversionBasedUnit)) {
IfcSchema::IfcConversionBasedUnit* conv_unit = named_unit->as<IfcSchema::IfcConversionBasedUnit>();
IfcSchema::IfcMeasureWithUnit* factor = conv_unit->ConversionFactor();
IfcSchema::IfcUnit* component = factor->UnitComponent();
if (component->is(IfcSchema::Type::IfcSIUnit)) {
si_unit = component->as<IfcSchema::IfcSIUnit>();
IfcSchema::IfcValue* v = factor->ValueComponent();
scale = *v->entity->getArgument(0);
}
} else if (named_unit->is(IfcSchema::Type::IfcSIUnit)) {
si_unit = named_unit->as<IfcSchema::IfcSIUnit>();
}
if (si_unit) {
if (si_unit->hasPrefix()) {
scale *= IfcSIPrefixToValue(si_unit->Prefix());
}
} else {
scale = 0.;
}
return scale;
}
+3 -1
View File
@@ -23,7 +23,9 @@
#include "../ifcparse/IfcParse.h" #include "../ifcparse/IfcParse.h"
namespace IfcParse { namespace IfcParse {
double IfcSIPrefixToValue(IfcSchema::IfcSIPrefix::IfcSIPrefix v); double IfcSIPrefixToValue(IfcSchema::IfcSIPrefix::IfcSIPrefix);
double get_SI_equivalent(IfcSchema::IfcNamedUnit*);
} }
#endif #endif