mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-09 21:53:40 +00:00
Handle missing or invalid unit and precision information more gracefully during IfcGeomObject initialization
This commit is contained in:
@@ -598,6 +598,9 @@ double UnitPrefixToValue( IfcSchema::IfcSIPrefix::IfcSIPrefix v ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void IfcGeomObjects::InitPrecision() {
|
void IfcGeomObjects::InitPrecision() {
|
||||||
|
IfcGeom::SetValue(IfcGeom::GV_PRECISION, 0.00001);
|
||||||
|
|
||||||
|
try {
|
||||||
IfcSchema::IfcGeometricRepresentationContext::list rep_contexts = ifc_file->EntitiesByType<IfcSchema::IfcGeometricRepresentationContext>();
|
IfcSchema::IfcGeometricRepresentationContext::list rep_contexts = ifc_file->EntitiesByType<IfcSchema::IfcGeometricRepresentationContext>();
|
||||||
// Currently, IfcGeometricRepresentationContext aren't used as much as they should be
|
// Currently, IfcGeometricRepresentationContext aren't used as much as they should be
|
||||||
// in the evaluation of shape representations, hence, we try to find the one with the
|
// in the evaluation of shape representations, hence, we try to find the one with the
|
||||||
@@ -621,6 +624,11 @@ void IfcGeomObjects::InitPrecision() {
|
|||||||
if (any_precision_encountered) {
|
if (any_precision_encountered) {
|
||||||
IfcGeom::SetValue(IfcGeom::GV_PRECISION, lowest_precision_encountered);
|
IfcGeom::SetValue(IfcGeom::GV_PRECISION, lowest_precision_encountered);
|
||||||
}
|
}
|
||||||
|
} catch (const IfcParse::IfcException& ex) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Failed to determine precision value '" << ex.what() << "'";
|
||||||
|
Logger::Message(Logger::LOG_ERROR, ss.str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string unit_name = "METER";
|
static std::string unit_name = "METER";
|
||||||
@@ -633,10 +641,13 @@ void IfcGeomObjects::InitUnits() {
|
|||||||
|
|
||||||
IfcSchema::IfcUnitAssignment::list unit_assignments = ifc_file->EntitiesByType<IfcSchema::IfcUnitAssignment>();
|
IfcSchema::IfcUnitAssignment::list unit_assignments = ifc_file->EntitiesByType<IfcSchema::IfcUnitAssignment>();
|
||||||
IfcUtil::IfcAbstractSelect::list units = IfcUtil::IfcAbstractSelect::list();
|
IfcUtil::IfcAbstractSelect::list units = IfcUtil::IfcAbstractSelect::list();
|
||||||
|
try {
|
||||||
if ( unit_assignments->Size() ) {
|
if ( unit_assignments->Size() ) {
|
||||||
IfcSchema::IfcUnitAssignment::ptr unit_assignment = *unit_assignments->begin();
|
IfcSchema::IfcUnitAssignment::ptr unit_assignment = *unit_assignments->begin();
|
||||||
units = unit_assignment->Units();
|
units = unit_assignment->Units();
|
||||||
}
|
}
|
||||||
|
} catch (const IfcParse::IfcException&) {}
|
||||||
|
|
||||||
if (!units) {
|
if (!units) {
|
||||||
// No units eh... Since tolerances and deflection are specified internally in meters
|
// No units eh... Since tolerances and deflection are specified internally in meters
|
||||||
// we will try to find another indication of the model size.
|
// we will try to find another indication of the model size.
|
||||||
@@ -644,12 +655,18 @@ void IfcGeomObjects::InitUnits() {
|
|||||||
if ( ! extrusions->Size() ) return;
|
if ( ! extrusions->Size() ) return;
|
||||||
double max_height = -1.0f;
|
double max_height = -1.0f;
|
||||||
for ( IfcSchema::IfcExtrudedAreaSolid::it it = extrusions->begin(); it != extrusions->end(); ++ it ) {
|
for ( IfcSchema::IfcExtrudedAreaSolid::it it = extrusions->begin(); it != extrusions->end(); ++ it ) {
|
||||||
|
try {
|
||||||
const double depth = (*it)->Depth();
|
const double depth = (*it)->Depth();
|
||||||
if ( depth > max_height ) max_height = depth;
|
if ( depth > max_height ) max_height = depth;
|
||||||
|
} catch (const IfcParse::IfcException&) {}
|
||||||
|
}
|
||||||
|
if ( max_height > 100.0f ) {
|
||||||
|
IfcGeom::SetValue(IfcGeom::GV_LENGTH_UNIT,0.001);
|
||||||
|
Logger::Message(Logger::LOG_NOTICE, "Guessed length unit to be in millimeters based on extrusion depth");
|
||||||
}
|
}
|
||||||
if ( max_height > 100.0f ) IfcGeom::SetValue(IfcGeom::GV_LENGTH_UNIT,0.001);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for ( IfcUtil::IfcAbstractSelect::it it = units->begin(); it != units->end(); ++ it ) {
|
for ( IfcUtil::IfcAbstractSelect::it it = units->begin(); it != units->end(); ++ it ) {
|
||||||
std::string current_unit_name = "";
|
std::string current_unit_name = "";
|
||||||
@@ -691,8 +708,10 @@ void IfcGeomObjects::InitUnits() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch ( IfcParse::IfcException ex ) {
|
} catch (const IfcParse::IfcException& ex) {
|
||||||
Logger::Message(Logger::LOG_ERROR,ex.what());
|
std::stringstream ss;
|
||||||
|
ss << "Failed to determine unit information '" << ex.what() << "'";
|
||||||
|
Logger::Message(Logger::LOG_ERROR, ss.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user