mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Minor refactor for modifiers
This commit is contained in:
@@ -499,12 +499,9 @@ class AddDoor(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
door_data["lining_properties"] = lining_props
|
door_data["lining_properties"] = lining_props
|
||||||
door_data["panel_properties"] = panel_props
|
door_data["panel_properties"] = panel_props
|
||||||
psets = ifcopenshell.util.element.get_psets(element)
|
pset = tool.Pset.get_element_pset(element, "BBIM_Door")
|
||||||
pset = psets.get("BBIM_Door", None)
|
|
||||||
|
|
||||||
if pset:
|
if not pset:
|
||||||
pset = tool.Ifc.get().by_id(pset["id"])
|
|
||||||
else:
|
|
||||||
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=element, name="BBIM_Door")
|
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=element, name="BBIM_Door")
|
||||||
|
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
@@ -525,8 +522,7 @@ class CancelEditingDoor(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
obj = context.active_object
|
obj = context.active_object
|
||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
psets = ifcopenshell.util.element.get_psets(element)
|
data = json.loads(tool.Pset.get_element_pset_data(element, "BBIM_Door")["Data"])
|
||||||
data = json.loads(psets["BBIM_Door"]["Data"])
|
|
||||||
props = obj.BIMDoorProperties
|
props = obj.BIMDoorProperties
|
||||||
# restore previous settings since editing was canceled
|
# restore previous settings since editing was canceled
|
||||||
for prop_name in data:
|
for prop_name in data:
|
||||||
@@ -557,8 +553,6 @@ class FinishEditingDoor(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
props = obj.BIMDoorProperties
|
props = obj.BIMDoorProperties
|
||||||
|
|
||||||
psets = ifcopenshell.util.element.get_psets(element)
|
|
||||||
pset = psets["BBIM_Door"]
|
|
||||||
door_data = props.get_general_kwargs()
|
door_data = props.get_general_kwargs()
|
||||||
lining_props = props.get_lining_kwargs()
|
lining_props = props.get_lining_kwargs()
|
||||||
panel_props = props.get_panel_kwargs()
|
panel_props = props.get_panel_kwargs()
|
||||||
@@ -570,7 +564,7 @@ class FinishEditingDoor(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
update_door_modifier_representation(context)
|
update_door_modifier_representation(context)
|
||||||
|
|
||||||
pset = tool.Ifc.get().by_id(pset["id"])
|
pset = tool.Pset.get_element_pset(element, "BBIM_Door")
|
||||||
door_data = json.dumps(door_data, default=list)
|
door_data = json.dumps(door_data, default=list)
|
||||||
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={"Data": door_data})
|
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={"Data": door_data})
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
@@ -585,8 +579,7 @@ class EnableEditingDoor(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
obj = context.active_object
|
obj = context.active_object
|
||||||
props = obj.BIMDoorProperties
|
props = obj.BIMDoorProperties
|
||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
pset = ifcopenshell.util.element.get_psets(element)
|
data = json.loads(tool.Pset.get_element_pset_data(element, "BBIM_Door")["Data"])
|
||||||
data = json.loads(pset["BBIM_Door"]["Data"])
|
|
||||||
data.update(data.pop("lining_properties"))
|
data.update(data.pop("lining_properties"))
|
||||||
data.update(data.pop("panel_properties"))
|
data.update(data.pop("panel_properties"))
|
||||||
|
|
||||||
@@ -615,8 +608,7 @@ class RemoveDoor(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
obj.BIMDoorProperties.is_editing = -1
|
obj.BIMDoorProperties.is_editing = -1
|
||||||
|
|
||||||
pset = ifcopenshell.util.element.get_psets(element)
|
pset = tool.Pset.get_element_pset(element, "BBIM_Door")
|
||||||
pset = tool.Ifc.get().by_id(pset["BBIM_Door"]["id"])
|
|
||||||
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), pset=pset)
|
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), pset=pset)
|
||||||
props.door_added_previously = True
|
props.door_added_previously = True
|
||||||
|
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ def update_stair_modifier(context):
|
|||||||
obj.data.update()
|
obj.data.update()
|
||||||
|
|
||||||
|
|
||||||
def update_ifc_stair_props(obj, psets):
|
def update_ifc_stair_props(obj):
|
||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
props = obj.BIMStairProperties
|
props = obj.BIMStairProperties
|
||||||
ifc_file = tool.Ifc.get()
|
ifc_file = tool.Ifc.get()
|
||||||
@@ -266,10 +266,8 @@ def update_ifc_stair_props(obj, psets):
|
|||||||
element.TreadLength = props.tread_depth
|
element.TreadLength = props.tread_depth
|
||||||
|
|
||||||
# update pset with ifc properties
|
# update pset with ifc properties
|
||||||
pset_common = psets.get("Pset_StairFlightCommon", None)
|
pset_common = tool.Pset.get_element_pset(element, "Pset_StairFlightCommon")
|
||||||
if pset_common:
|
if not pset_common:
|
||||||
pset_common = ifc_file.by_id(pset_common["id"])
|
|
||||||
else:
|
|
||||||
pset_common = ifcopenshell.api.run("pset.add_pset", ifc_file, product=element, name="Pset_StairFlightCommon")
|
pset_common = ifcopenshell.api.run("pset.add_pset", ifc_file, product=element, name="Pset_StairFlightCommon")
|
||||||
|
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
@@ -349,12 +347,8 @@ class AddStair(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
)
|
)
|
||||||
|
|
||||||
stair_data = props.get_props_kwargs()
|
stair_data = props.get_props_kwargs()
|
||||||
psets = ifcopenshell.util.element.get_psets(element)
|
pset = tool.Pset.get_element_pset(element, "BBIM_Stair")
|
||||||
pset = psets.get("BBIM_Stair", None)
|
if not pset:
|
||||||
|
|
||||||
if pset:
|
|
||||||
pset = ifc_file.by_id(pset["id"])
|
|
||||||
else:
|
|
||||||
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")
|
||||||
|
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
@@ -364,7 +358,7 @@ class AddStair(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
properties={"Data": json.dumps(stair_data)},
|
properties={"Data": json.dumps(stair_data)},
|
||||||
)
|
)
|
||||||
update_stair_modifier(context)
|
update_stair_modifier(context)
|
||||||
update_ifc_stair_props(obj, psets)
|
update_ifc_stair_props(obj)
|
||||||
|
|
||||||
|
|
||||||
class CancelEditingStair(bpy.types.Operator, tool.Ifc.Operator):
|
class CancelEditingStair(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
@@ -375,8 +369,7 @@ class CancelEditingStair(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
obj = context.active_object
|
obj = context.active_object
|
||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
psets = ifcopenshell.util.element.get_psets(element)
|
data = json.loads(tool.Pset.get_element_pset_data(element, "BBIM_Stair")["Data"])
|
||||||
data = json.loads(psets["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:
|
for prop_name in data:
|
||||||
@@ -398,21 +391,17 @@ 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
|
||||||
|
|
||||||
psets = ifcopenshell.util.element.get_psets(element)
|
|
||||||
pset = psets["BBIM_Stair"]
|
|
||||||
data = props.get_props_kwargs()
|
data = props.get_props_kwargs()
|
||||||
|
|
||||||
props.is_editing = -1
|
props.is_editing = -1
|
||||||
|
|
||||||
update_stair_modifier(context)
|
update_stair_modifier(context)
|
||||||
|
|
||||||
pset = tool.Ifc.get().by_id(pset["id"])
|
pset = tool.Pset.get_element_pset(element, "BBIM_Stair")
|
||||||
data = json.dumps(data)
|
data = json.dumps(data)
|
||||||
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={"Data": data})
|
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={"Data": data})
|
||||||
|
|
||||||
# update IfcStairFlight properties
|
# update IfcStairFlight properties
|
||||||
element.PredefinedType = "STRAIGHT"
|
element.PredefinedType = "STRAIGHT"
|
||||||
update_ifc_stair_props(obj, psets)
|
update_ifc_stair_props(obj)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
@@ -425,8 +414,7 @@ class EnableEditingStair(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
obj = context.active_object
|
obj = context.active_object
|
||||||
props = obj.BIMStairProperties
|
props = obj.BIMStairProperties
|
||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
pset = ifcopenshell.util.element.get_psets(element)
|
data = json.loads(tool.Pset.get_element_pset_data(element, "BBIM_Stair")["Data"])
|
||||||
data = json.loads(pset["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:
|
for prop_name in data:
|
||||||
setattr(props, prop_name, data[prop_name])
|
setattr(props, prop_name, data[prop_name])
|
||||||
@@ -452,8 +440,7 @@ class RemoveStair(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
obj.BIMStairProperties.is_editing = -1
|
obj.BIMStairProperties.is_editing = -1
|
||||||
|
|
||||||
pset = ifcopenshell.util.element.get_psets(element)
|
pset = tool.Pset.get_element_pset(element, "BBIM_Stair")
|
||||||
pset = tool.Ifc.get().by_id(pset["BBIM_Stair"]["id"])
|
|
||||||
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), pset=pset)
|
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), pset=pset)
|
||||||
props.stair_added_previously = True
|
props.stair_added_previously = True
|
||||||
|
|
||||||
|
|||||||
@@ -465,12 +465,8 @@ class AddWindow(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
window_data["lining_properties"] = lining_props
|
window_data["lining_properties"] = lining_props
|
||||||
window_data["panel_properties"] = panel_props
|
window_data["panel_properties"] = panel_props
|
||||||
psets = ifcopenshell.util.element.get_psets(element)
|
pset = tool.Pset.get_element_pset(element, "BBIM_Window")
|
||||||
pset = psets.get("BBIM_Window", None)
|
if not pset:
|
||||||
|
|
||||||
if pset:
|
|
||||||
pset = tool.Ifc.get().by_id(pset["id"])
|
|
||||||
else:
|
|
||||||
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=element, name="BBIM_Window")
|
pset = ifcopenshell.api.run("pset.add_pset", tool.Ifc.get(), product=element, name="BBIM_Window")
|
||||||
|
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
@@ -491,8 +487,7 @@ class CancelEditingWindow(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
obj = context.active_object
|
obj = context.active_object
|
||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
psets = ifcopenshell.util.element.get_psets(element)
|
data = json.loads(tool.Pset.get_element_pset_data(element, "BBIM_Window")["Data"])
|
||||||
data = json.loads(psets["BBIM_Window"]["Data"])
|
|
||||||
props = obj.BIMWindowProperties
|
props = obj.BIMWindowProperties
|
||||||
for prop_name in data:
|
for prop_name in data:
|
||||||
setattr(props, prop_name, data[prop_name])
|
setattr(props, prop_name, data[prop_name])
|
||||||
@@ -522,8 +517,6 @@ class FinishEditingWindow(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
props = obj.BIMWindowProperties
|
props = obj.BIMWindowProperties
|
||||||
|
|
||||||
psets = ifcopenshell.util.element.get_psets(element)
|
|
||||||
pset = psets["BBIM_Window"]
|
|
||||||
window_data = props.get_general_kwargs()
|
window_data = props.get_general_kwargs()
|
||||||
lining_props = props.get_lining_kwargs()
|
lining_props = props.get_lining_kwargs()
|
||||||
panel_props = props.get_panel_kwargs()
|
panel_props = props.get_panel_kwargs()
|
||||||
@@ -535,7 +528,7 @@ class FinishEditingWindow(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
update_window_modifier_representation(context)
|
update_window_modifier_representation(context)
|
||||||
|
|
||||||
pset = tool.Ifc.get().by_id(pset["id"])
|
pset = tool.Pset.get_element_pset(element, "BBIM_Window")
|
||||||
window_data = json.dumps(window_data, default=list)
|
window_data = json.dumps(window_data, default=list)
|
||||||
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={"Data": window_data})
|
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={"Data": window_data})
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
@@ -550,8 +543,7 @@ class EnableEditingWindow(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
obj = context.active_object
|
obj = context.active_object
|
||||||
props = obj.BIMWindowProperties
|
props = obj.BIMWindowProperties
|
||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
pset = ifcopenshell.util.element.get_psets(element)
|
data = json.loads(tool.Pset.get_element_pset_data(element, "BBIM_Window")["Data"])
|
||||||
data = json.loads(pset["BBIM_Window"]["Data"])
|
|
||||||
data.update(data.pop("lining_properties"))
|
data.update(data.pop("lining_properties"))
|
||||||
data.update(data.pop("panel_properties"))
|
data.update(data.pop("panel_properties"))
|
||||||
|
|
||||||
@@ -580,8 +572,7 @@ class RemoveWindow(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
obj.BIMWindowProperties.is_editing = -1
|
obj.BIMWindowProperties.is_editing = -1
|
||||||
|
|
||||||
pset = ifcopenshell.util.element.get_psets(element)
|
pset = tool.Pset.get_element_pset(element, "BBIM_Window")
|
||||||
pset = tool.Ifc.get().by_id(pset["BBIM_Window"]["id"])
|
|
||||||
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), pset=pset)
|
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), pset=pset)
|
||||||
props.window_added_previously = True
|
props.window_added_previously = True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user