More robust type switching of parametric objects

This commit is contained in:
Dion Moult
2022-10-13 22:50:59 +11:00
parent ede9c5fca5
commit 2d37d3c914
4 changed files with 30 additions and 105 deletions
@@ -262,27 +262,11 @@ class DumbSlabPlaner:
return
new_thickness = sum([l.LayerThickness for l in new_material.MaterialLayers])
material = ifcopenshell.util.element.get_material(settings["related_object"])
relating_type = settings["relating_type"]
if hasattr(relating_type, "HasPropertySets"):
psets = relating_type.HasPropertySets
if psets is not None:
for pset in psets:
if hasattr(pset, "HasProperties"):
pset_props = pset.HasProperties
if pset_props is not None:
for prop in pset_props:
if prop.Name == "LayerSetDirection":
if hasattr(prop, "NominalValue"):
nominal_value = prop.NominalValue
if hasattr(nominal_value, "wrappedValue"):
if nominal_value.wrappedValue == "AXIS2":
return
if material and material.is_a("IfcMaterialLayerSetUsage") and material.LayerSetDirection == "AXIS3":
self.change_thickness(settings["related_object"], new_thickness)
def change_thickness(self, element, thickness):
body_context = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Body", "MODEL_VIEW")
obj = IfcStore.get_element(element.id())
if not obj:
return
@@ -292,12 +276,34 @@ class DumbSlabPlaner:
return
representation = ifcopenshell.util.representation.get_representation(element, "Model", "Body", "MODEL_VIEW")
if not representation:
return
extrusion = tool.Model.get_extrusion(representation)
if not extrusion:
return
extrusion.Depth = thickness
if representation:
extrusion = tool.Model.get_extrusion(representation)
if extrusion:
extrusion.Depth = thickness
else:
new_rep = ifcopenshell.api.run(
"geometry.add_slab_representation", tool.Ifc.get(), context=body_context, depth=thickness
)
for inverse in tool.Ifc.get().get_inverse(representation):
ifcopenshell.util.element.replace_attribute(inverse, representation, new_rep)
blenderbim.core.geometry.switch_representation(
tool.Geometry,
obj=obj,
representation=new_rep,
should_reload=True,
enable_dynamic_voids=False,
is_global=True,
should_sync_changes_first=False,
)
blenderbim.core.geometry.remove_representation(tool.Ifc, tool.Geometry, obj=obj, representation=representation)
return
else:
representation = ifcopenshell.api.run(
"geometry.add_slab_representation", tool.Ifc.get(), context=body_context, depth=thickness
)
ifcopenshell.api.run(
"geometry.assign_representation", tool.Ifc.get(), product=element, representation=representation
)
blenderbim.core.geometry.switch_representation(
tool.Geometry,
@@ -678,23 +678,6 @@ class DumbWallPlaner:
if not new_material or not new_material.is_a("IfcMaterialLayerSet"):
return
material = ifcopenshell.util.element.get_material(settings["related_object"])
relating_type = settings["relating_type"]
if hasattr(relating_type, "HasPropertySets"):
psets = relating_type.HasPropertySets
if psets is not None:
for pset in psets:
if hasattr(pset, "HasProperties"):
pset_props = pset.HasProperties
if pset_props is not None:
for prop in pset_props:
if prop.Name == "LayerSetDirection":
if hasattr(prop, "NominalValue"):
nominal_value = prop.NominalValue
if hasattr(nominal_value, "wrappedValue"):
if nominal_value.wrappedValue == "AXIS3":
return
if material and material.is_a("IfcMaterialLayerSetUsage") and material.LayerSetDirection == "AXIS2":
DumbWallRecalculator().recalculate([obj])
+1 -21
View File
@@ -23,27 +23,7 @@ def assign_type(ifc, type_tool, element=None, type=None):
ifc.run("type.assign_type", related_object=element, relating_type=type)
obj = ifc.get_object(element)
if type_tool.has_material_usage(element):
representation = type_tool.get_body_representation(element)
if representation:
body_context = type_tool.get_representation_context(representation)
ifc.run("geometry.unassign_representation", product=element, representation=representation)
ifc.run("geometry.remove_representation", representation=representation)
else:
body_context = type_tool.get_body_context()
representation = type_tool.run_geometry_add_representation(
obj=obj,
context=body_context,
ifc_representation_class=type_tool.get_ifc_representation_class(element),
profile_set_usage=type_tool.get_profile_set_usage(element),
)
if representation:
type_tool.run_geometry_switch_representation(
obj=obj,
representation=representation,
should_reload=True,
enable_dynamic_voids=type_tool.has_dynamic_voids(obj),
is_global=False,
)
pass # for now, representation regeneration handled by API listeners
else:
type_data = type_tool.get_object_data(ifc.get_object(type))
if type_data:
-44
View File
@@ -39,47 +39,3 @@ class TestAssignType:
ifc.get_object("element").should_be_called().will_return("obj")
type.disable_editing("obj").should_be_called()
subject.assign_type(ifc, type, element="element", type="type")
def test_updating_an_existing_body_if_there_is_a_parametric_material_usage(self, ifc, type):
ifc.run("type.assign_type", related_object="element", relating_type="type").should_be_called()
type.has_material_usage("element").should_be_called().will_return(True)
type.get_body_representation("element").should_be_called().will_return("representation")
type.get_representation_context("representation").should_be_called().will_return("context")
ifc.run(
"geometry.unassign_representation", product="element", representation="representation"
).should_be_called()
ifc.run("geometry.remove_representation", representation="representation").should_be_called()
type.get_ifc_representation_class("element").should_be_called().will_return("class")
type.get_profile_set_usage("element").should_be_called().will_return("usage")
type.run_geometry_add_representation(
obj="obj", context="context", ifc_representation_class="class", profile_set_usage="usage"
).should_be_called().will_return("mapped_rep")
ifc.get_object("element").should_be_called().will_return("obj")
type.has_dynamic_voids("obj").should_be_called().will_return(False)
type.run_geometry_switch_representation(
obj="obj", representation="mapped_rep", should_reload=True, enable_dynamic_voids=False, is_global=False
).should_be_called()
type.disable_editing("obj").should_be_called()
subject.assign_type(ifc, type, element="element", type="type")
def test_creating_a_new_body_if_there_is_a_parametric_material_usage(self, ifc, type):
ifc.run("type.assign_type", related_object="element", relating_type="type").should_be_called()
type.has_material_usage("element").should_be_called().will_return(True)
type.get_body_representation("element").should_be_called().will_return(None)
type.get_body_context().should_be_called().will_return("context")
type.get_ifc_representation_class("element").should_be_called().will_return("class")
type.get_profile_set_usage("element").should_be_called().will_return("usage")
type.run_geometry_add_representation(
obj="obj", context="context", ifc_representation_class="class", profile_set_usage="usage"
).should_be_called().will_return("mapped_rep")
ifc.get_object("element").should_be_called().will_return("obj")
type.has_dynamic_voids("obj").should_be_called().will_return(False)
type.run_geometry_switch_representation(
obj="obj", representation="mapped_rep", should_reload=True, enable_dynamic_voids=False, is_global=False
).should_be_called()
type.disable_editing("obj").should_be_called()
subject.assign_type(ifc, type, element="element", type="type")