Fix issue with calculated params in stair ui

it was displaying incorrect data when stair was just loaded because it was relying on BIMStairProperties in ui.py
This commit is contained in:
Andrej730
2023-11-01 17:33:00 +05:00
parent 7c694e5b3e
commit 8b23c615c3
2 changed files with 27 additions and 10 deletions
@@ -314,6 +314,7 @@ class StairData:
if not cls.data["pset_data"]:
return
cls.data["general_params"] = cls.general_params()
cls.data["calculated_params"] = cls.calculated_params()
@classmethod
def pset_data(cls):
@@ -330,6 +331,28 @@ class StairData:
general_params[prop_readable_name] = prop_value
return general_params
@classmethod
def calculated_params(cls):
props = bpy.context.active_object.BIMStairProperties
if props.is_editing:
si_conversion = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
number_of_treads = props.number_of_treads
height = props.height / si_conversion
tread_run = props.tread_run / si_conversion
else:
data = cls.data["pset_data"]["data_dict"]
number_of_treads = data["number_of_treads"]
height = data["height"]
tread_run = data["tread_run"]
calculated_params = {}
number_of_rises = number_of_treads + 1
calculated_params["Number of risers"] = number_of_rises
calculated_params["Tread rise"] = round(height / number_of_rises, 5)
calculated_params["Length"] = round(tread_run * number_of_rises, 5)
return calculated_params
class SverchokData:
data = {}
@@ -278,16 +278,10 @@ class BIM_PT_stair(bpy.types.Panel):
row.label(text=str(prop_value))
# calculated properties
number_of_rises = props.number_of_treads + 1
row = self.layout.row(align=True)
row.label(text="Number of risers")
row.label(text=str(number_of_rises))
row = self.layout.row(align=True)
row.label(text="Tread rise")
row.label(text=str(round(props.height / number_of_rises, 5)))
row = self.layout.row(align=True)
row.label(text="Length")
row.label(text=str(round(props.tread_run * number_of_rises, 5)))
for prop_name, prop_value in StairData.data["calculated_params"].items():
row = self.layout.row(align=True)
row.label(text=prop_name)
row.label(text=str(prop_value))
else:
row = self.layout.row()
row.label(text="No Stair Found")