Implement rounding of elevation (#5532)

* Implement rounding of elevation

Implement rounding of elevation based on precision stored in IfcGeometricRepresentationContext

* Move formating function to tool
This commit is contained in:
Manu Varkey
2024-10-24 15:47:47 +05:30
committed by GitHub
parent b08acd1625
commit 8d3aa98b58
2 changed files with 14 additions and 1 deletions
+3 -1
View File
@@ -35,6 +35,7 @@ import bonsai.core.tool
import bonsai.core.root
import bonsai.core.spatial
import bonsai.core.geometry
import bonsai.core.unit
import bonsai.tool as tool
import json
from math import pi
@@ -452,7 +453,8 @@ class Spatial(bonsai.core.tool.Spatial):
new.description = element.Description or ""
new.long_name = element.LongName or ""
if not element.is_a("IfcProject"):
new["elevation"] = str(ifcopenshell.util.placement.get_storey_elevation(element))
elevation = ifcopenshell.util.placement.get_storey_elevation(element)
new["elevation"] = tool.Unit.format_value(elevation)
new.is_expanded = element.id() not in cls.contracted_containers
new.level_index = level_index
children = ifcopenshell.util.element.get_parts(element)
+11
View File
@@ -18,6 +18,7 @@
import bpy
import json
import math
import ifcopenshell
import bonsai.bim.helper
import bonsai.core.tool
@@ -182,3 +183,13 @@ class Unit(bonsai.core.tool.Unit):
precision=4,
split_unit=bpy.context.scene.unit_settings.system == "IMPERIAL",
)
@classmethod
def format_value(cls, value: float) -> str:
precision = tool.Ifc.get().by_type("IfcGeometricRepresentationContext")[0].Precision
if precision:
decimal_places = math.ceil(math.log10(1/precision))
else:
precision = 1e-5
decimal_places = 5
return str(round(precision * round(value / precision), decimal_places))