mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-10 06:00:51 +00:00
Stair Modifier - support typing units in props
Example - https://i.imgur.com/XQsVge1.png
This commit is contained in:
@@ -176,6 +176,7 @@ class BIMArrayProperties(PropertyGroup):
|
|||||||
|
|
||||||
|
|
||||||
class BIMStairProperties(PropertyGroup):
|
class BIMStairProperties(PropertyGroup):
|
||||||
|
non_si_units_props = ("is_editing", "number_of_treads", "has_top_nib", "stair_type")
|
||||||
stair_types = (
|
stair_types = (
|
||||||
("CONCRETE", "Concrete", ""),
|
("CONCRETE", "Concrete", ""),
|
||||||
("WOOD/STEEL", "Wood / Steel", ""),
|
("WOOD/STEEL", "Wood / Steel", ""),
|
||||||
@@ -184,17 +185,17 @@ class BIMStairProperties(PropertyGroup):
|
|||||||
|
|
||||||
stair_added_previously: bpy.props.BoolProperty(default=False)
|
stair_added_previously: bpy.props.BoolProperty(default=False)
|
||||||
is_editing: bpy.props.IntProperty(default=-1)
|
is_editing: bpy.props.IntProperty(default=-1)
|
||||||
width: bpy.props.FloatProperty(name="Width", default=1.2, soft_min=0.01)
|
width: bpy.props.FloatProperty(name="Width", default=1.2, soft_min=0.01, subtype="DISTANCE")
|
||||||
height: bpy.props.FloatProperty(name="Height", default=1.0, soft_min=0.01)
|
height: bpy.props.FloatProperty(name="Height", default=1.0, soft_min=0.01, subtype="DISTANCE")
|
||||||
number_of_treads: bpy.props.IntProperty(name="Number of treads", default=6, soft_min=1)
|
number_of_treads: bpy.props.IntProperty(name="Number of treads", default=6, soft_min=1)
|
||||||
tread_depth: bpy.props.FloatProperty(name="Tread Depth", default=0.25, soft_min=0.01)
|
tread_depth: bpy.props.FloatProperty(name="Tread Depth", default=0.25, soft_min=0.01, subtype="DISTANCE")
|
||||||
tread_run: bpy.props.FloatProperty(name="Tread Run", default=0.3, soft_min=0.01)
|
tread_run: bpy.props.FloatProperty(name="Tread Run", default=0.3, soft_min=0.01, subtype="DISTANCE")
|
||||||
base_slab_depth: bpy.props.FloatProperty(name="Base slab depth", default=0.25, soft_min=0)
|
base_slab_depth: bpy.props.FloatProperty(name="Base slab depth", default=0.25, soft_min=0, subtype="DISTANCE")
|
||||||
top_slab_depth: bpy.props.FloatProperty(name="Top slab depth", default=0.25, soft_min=0)
|
top_slab_depth: bpy.props.FloatProperty(name="Top slab depth", default=0.25, soft_min=0, subtype="DISTANCE")
|
||||||
has_top_nib: bpy.props.BoolProperty(name="Has top nib", default=True)
|
has_top_nib: bpy.props.BoolProperty(name="Has top nib", default=True)
|
||||||
stair_type: bpy.props.EnumProperty(name="Stair type", items=stair_types, default="CONCRETE")
|
stair_type: bpy.props.EnumProperty(name="Stair type", items=stair_types, default="CONCRETE")
|
||||||
|
|
||||||
def get_props_kwargs(self):
|
def get_props_kwargs(self, convert_to_project_units=False):
|
||||||
stair_kwargs = {
|
stair_kwargs = {
|
||||||
"stair_type": self.stair_type,
|
"stair_type": self.stair_type,
|
||||||
"width": self.width,
|
"width": self.width,
|
||||||
@@ -204,27 +205,42 @@ class BIMStairProperties(PropertyGroup):
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.stair_type == "CONCRETE":
|
if self.stair_type == "CONCRETE":
|
||||||
stair_kwargs.update(
|
concrete_props = {
|
||||||
{
|
"base_slab_depth": self.base_slab_depth,
|
||||||
"base_slab_depth": self.base_slab_depth,
|
"top_slab_depth": self.top_slab_depth,
|
||||||
"top_slab_depth": self.top_slab_depth,
|
"has_top_nib": self.has_top_nib,
|
||||||
"has_top_nib": self.has_top_nib,
|
"tread_depth": self.tread_depth,
|
||||||
"tread_depth": self.tread_depth,
|
}
|
||||||
}
|
stair_kwargs.update(concrete_props)
|
||||||
)
|
|
||||||
return stair_kwargs
|
|
||||||
|
|
||||||
elif self.stair_type == "WOOD/STEEL":
|
elif self.stair_type == "WOOD/STEEL":
|
||||||
stair_kwargs.update(
|
wood_steel_props = {
|
||||||
{
|
"tread_depth": self.tread_depth,
|
||||||
"tread_depth": self.tread_depth,
|
}
|
||||||
}
|
stair_kwargs.update(wood_steel_props)
|
||||||
)
|
|
||||||
return stair_kwargs
|
|
||||||
|
|
||||||
elif self.stair_type == "GENERIC":
|
elif self.stair_type == "GENERIC":
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not convert_to_project_units:
|
||||||
return stair_kwargs
|
return stair_kwargs
|
||||||
|
|
||||||
|
si_conversion = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
|
||||||
|
for prop_name in stair_kwargs:
|
||||||
|
if prop_name in self.non_si_units_props:
|
||||||
|
continue
|
||||||
|
prop_value = stair_kwargs[prop_name]
|
||||||
|
stair_kwargs[prop_name] = prop_value / si_conversion
|
||||||
|
return stair_kwargs
|
||||||
|
|
||||||
|
def set_props_kwargs_from_ifc_data(self, kwargs):
|
||||||
|
si_conversion = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
|
||||||
|
for prop_name in kwargs:
|
||||||
|
prop_value = kwargs[prop_name]
|
||||||
|
if prop_name not in self.non_si_units_props:
|
||||||
|
prop_value = prop_value * si_conversion
|
||||||
|
setattr(self, prop_name, prop_value)
|
||||||
|
|
||||||
|
|
||||||
class BIMSverchokProperties(PropertyGroup):
|
class BIMSverchokProperties(PropertyGroup):
|
||||||
node_group: bpy.props.PointerProperty(name="Node Group", type=NodeTree)
|
node_group: bpy.props.PointerProperty(name="Node Group", type=NodeTree)
|
||||||
|
|||||||
@@ -214,14 +214,6 @@ def generate_stair_2d_profile(
|
|||||||
def update_stair_modifier(context):
|
def update_stair_modifier(context):
|
||||||
obj = context.active_object
|
obj = context.active_object
|
||||||
props_kwargs = obj.BIMStairProperties.get_props_kwargs()
|
props_kwargs = obj.BIMStairProperties.get_props_kwargs()
|
||||||
|
|
||||||
si_conversion = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
|
|
||||||
for prop_name in props_kwargs:
|
|
||||||
if prop_name in ("is_editing", "number_of_treads", "has_top_nib", "stair_type"):
|
|
||||||
continue
|
|
||||||
prop_value = props_kwargs[prop_name]
|
|
||||||
props_kwargs[prop_name] = prop_value * si_conversion
|
|
||||||
|
|
||||||
vertices, edges, faces = generate_stair_2d_profile(**props_kwargs)
|
vertices, edges, faces = generate_stair_2d_profile(**props_kwargs)
|
||||||
|
|
||||||
obj = context.object
|
obj = context.object
|
||||||
@@ -360,14 +352,7 @@ class AddStair(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
self.report({"ERROR"}, "Object has to be IfcStairFlight/IfcStairFlightType to add a stair.")
|
self.report({"ERROR"}, "Object has to be IfcStairFlight/IfcStairFlightType to add a stair.")
|
||||||
return {"CANCELLED"}
|
return {"CANCELLED"}
|
||||||
|
|
||||||
# need to make sure all default props will have correct units
|
stair_data = props.get_props_kwargs(convert_to_project_units=True)
|
||||||
if not props.stair_added_previously:
|
|
||||||
convert_property_group_from_si(
|
|
||||||
props,
|
|
||||||
skip_props=("stair_added_previously", "is_editing", "number_of_treads", "has_top_nib", "stair_type"),
|
|
||||||
)
|
|
||||||
|
|
||||||
stair_data = props.get_props_kwargs()
|
|
||||||
pset = tool.Pset.get_element_pset(element, "BBIM_Stair")
|
pset = tool.Pset.get_element_pset(element, "BBIM_Stair")
|
||||||
if not pset:
|
if not pset:
|
||||||
pset = ifcopenshell.api.run("pset.add_pset", ifc_file, product=element, name="BBIM_Stair")
|
pset = ifcopenshell.api.run("pset.add_pset", ifc_file, product=element, name="BBIM_Stair")
|
||||||
@@ -393,8 +378,7 @@ class CancelEditingStair(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
data = json.loads(ifcopenshell.util.element.get_pset(element, "BBIM_Stair", "Data"))
|
data = json.loads(ifcopenshell.util.element.get_pset(element, "BBIM_Stair", "Data"))
|
||||||
props = obj.BIMStairProperties
|
props = obj.BIMStairProperties
|
||||||
# restore previous settings since editing was canceled
|
# restore previous settings since editing was canceled
|
||||||
for prop_name in data:
|
props.set_props_kwargs_from_ifc_data(data)
|
||||||
setattr(props, prop_name, data[prop_name])
|
|
||||||
update_stair_modifier(context)
|
update_stair_modifier(context)
|
||||||
|
|
||||||
props.is_editing = -1
|
props.is_editing = -1
|
||||||
@@ -412,7 +396,7 @@ class FinishEditingStair(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
props = obj.BIMStairProperties
|
props = obj.BIMStairProperties
|
||||||
|
|
||||||
data = props.get_props_kwargs()
|
data = props.get_props_kwargs(convert_to_project_units=True)
|
||||||
props.is_editing = -1
|
props.is_editing = -1
|
||||||
update_stair_modifier(context)
|
update_stair_modifier(context)
|
||||||
|
|
||||||
@@ -436,15 +420,7 @@ class EnableEditingStair(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
data = json.loads(ifcopenshell.util.element.get_pset(element, "BBIM_Stair", "Data"))
|
data = json.loads(ifcopenshell.util.element.get_pset(element, "BBIM_Stair", "Data"))
|
||||||
# required since we could load pset from .ifc and BIMStairProperties won't be set
|
# required since we could load pset from .ifc and BIMStairProperties won't be set
|
||||||
for prop_name in data:
|
props.set_props_kwargs_from_ifc_data(data)
|
||||||
setattr(props, prop_name, data[prop_name])
|
|
||||||
|
|
||||||
# need to make sure all props that weren't used before
|
|
||||||
# will have correct units
|
|
||||||
skip_props = ("stair_added_previously", "is_editing", "number_of_treads", "has_top_nib", "stair_type")
|
|
||||||
skip_props += tuple(data.keys())
|
|
||||||
convert_property_group_from_si(props, skip_props=skip_props)
|
|
||||||
|
|
||||||
props.is_editing = 1
|
props.is_editing = 1
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user