mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 15:48:04 +00:00
Assigning a parametric profile type now auto switches from non parametric geometry to parametric geometry
This commit is contained in:
@@ -17,45 +17,84 @@
|
||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import blenderbim.core.type as subject
|
||||
from test.core.bootstrap import ifc, geometry, type
|
||||
from test.core.bootstrap import ifc, type
|
||||
|
||||
|
||||
class TestAssignType:
|
||||
def test_assigning_and_switching_preferably_to_a_body_representation(self, ifc, geometry, type):
|
||||
def test_assigning_and_switching_preferably_to_a_body_representation(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(False)
|
||||
type.get_body_representation("element").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)
|
||||
|
||||
geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation")
|
||||
geometry.get_representation_data("representation").should_be_called().will_return("data")
|
||||
geometry.change_object_data("obj", "data", is_global=False).should_be_called()
|
||||
geometry.clear_dynamic_voids("obj").should_be_called()
|
||||
|
||||
type.run_geometry_switch_representation(
|
||||
obj="obj", representation="mapped_rep", should_reload=False, 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")
|
||||
|
||||
subject.assign_type(ifc, geometry, type, element="element", type="type")
|
||||
|
||||
def test_assigning_and_switching_to_any_representation_as_a_fallback(self, ifc, geometry, type):
|
||||
def test_assigning_and_switching_to_any_representation_as_a_fallback(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(False)
|
||||
type.get_body_representation("element").should_be_called().will_return(None)
|
||||
type.get_any_representation("element").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)
|
||||
|
||||
geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation")
|
||||
geometry.get_representation_data("representation").should_be_called().will_return("data")
|
||||
geometry.change_object_data("obj", "data", is_global=False).should_be_called()
|
||||
geometry.clear_dynamic_voids("obj").should_be_called()
|
||||
|
||||
type.run_geometry_switch_representation(
|
||||
obj="obj", representation="mapped_rep", should_reload=False, 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")
|
||||
|
||||
subject.assign_type(ifc, geometry, type, element="element", type="type")
|
||||
|
||||
def test_assigning_and_not_changing_representation_if_not_available(self, ifc, type):
|
||||
def test_assigning_and_not_changing_representation_if_there_is_no_representation_to_change_to(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(False)
|
||||
type.get_body_representation("element").should_be_called().will_return(None)
|
||||
type.get_any_representation("element").should_be_called().will_return(None)
|
||||
ifc.get_object("element").should_be_called().will_return("obj")
|
||||
type.disable_editing("obj").should_be_called()
|
||||
subject.assign_type(ifc, geometry, type, element="element", type="type")
|
||||
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")
|
||||
|
||||
@@ -53,6 +53,16 @@ class TestGetAnyRepresentation(NewFile):
|
||||
assert subject.get_any_representation(element) == representation
|
||||
|
||||
|
||||
class TestGetBodyContext(NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
context = ifc.createIfcGeometricRepresentationSubContext(
|
||||
ContextType="Model", ContextIdentifier="Body", TargetView="MODEL_VIEW"
|
||||
)
|
||||
tool.Ifc.set(ifc)
|
||||
assert subject.get_body_context() == context
|
||||
|
||||
|
||||
class TestGetBodyRepresentation(NewFile):
|
||||
def test_get_product_representation(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -78,6 +88,49 @@ class TestGetBodyRepresentation(NewFile):
|
||||
assert subject.get_body_representation(element) == body_rep
|
||||
|
||||
|
||||
class TestGetIfcRepresentationClass(NewFile):
|
||||
def test_detecting_profile_set_representations(self):
|
||||
ifc = ifcopenshell.file()
|
||||
element = ifc.createIfcColumn()
|
||||
ifc.createIfcRelAssociatesMaterial(
|
||||
RelatingMaterial=ifc.createIfcMaterialProfileSetUsage(), RelatedObjects=[element]
|
||||
)
|
||||
assert subject.get_ifc_representation_class(element) == "IfcExtrudedAreaSolid/IfcMaterialProfileSetUsage"
|
||||
|
||||
def test_detecting_layer_set_representations(self):
|
||||
ifc = ifcopenshell.file()
|
||||
element = ifc.createIfcColumn()
|
||||
ifc.createIfcRelAssociatesMaterial(
|
||||
RelatingMaterial=ifc.createIfcMaterialLayerSetUsage(), RelatedObjects=[element]
|
||||
)
|
||||
assert (
|
||||
subject.get_ifc_representation_class(element)
|
||||
== "IfcExtrudedAreaSolid/IfcExtrudedAreaSolid/IfcArbitraryProfileDefWithVoids"
|
||||
)
|
||||
|
||||
def test_returning_null_for_non_parametric_represntations(self):
|
||||
ifc = ifcopenshell.file()
|
||||
assert subject.get_ifc_representation_class(ifc.createIfcColumn()) is None
|
||||
|
||||
|
||||
class TestGetProfileSetUsage(NewFile):
|
||||
def test_getting_a_profile_set_usage(self):
|
||||
ifc = ifcopenshell.file()
|
||||
element = ifc.createIfcColumn()
|
||||
assert subject.get_profile_set_usage(element) is None
|
||||
usage = ifc.createIfcMaterialProfileSetUsage()
|
||||
ifc.createIfcRelAssociatesMaterial(RelatingMaterial=usage, RelatedObjects=[element])
|
||||
assert subject.get_profile_set_usage(element) == usage
|
||||
|
||||
|
||||
class TestGetRepresentationContext(NewFile):
|
||||
def test_getting_a_profile_set_usage(self):
|
||||
ifc = ifcopenshell.file()
|
||||
context = ifc.createIfcGeometricRepresentationSubContext()
|
||||
representation = ifc.createIfcShapeRepresentation(ContextOfItems=context)
|
||||
assert subject.get_representation_context(representation) == context
|
||||
|
||||
|
||||
class TestHasDynamicVoids(NewFile):
|
||||
def test_run(self):
|
||||
obj = bpy.data.objects.new("Object", None)
|
||||
@@ -87,3 +140,23 @@ class TestHasDynamicVoids(NewFile):
|
||||
obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
|
||||
obj.modifiers.new("IfcOpeningElement", "BOOLEAN")
|
||||
assert subject.has_dynamic_voids(obj) is True
|
||||
|
||||
|
||||
class TestHasMaterialUsage(NewFile):
|
||||
def test_getting_a_profile_set_usage(self):
|
||||
ifc = ifcopenshell.file()
|
||||
element = ifc.createIfcColumn()
|
||||
assert subject.has_material_usage(element) is False
|
||||
usage = ifc.createIfcMaterialProfileSetUsage()
|
||||
ifc.createIfcRelAssociatesMaterial(RelatingMaterial=usage, RelatedObjects=[element])
|
||||
assert subject.has_material_usage(element) is True
|
||||
|
||||
|
||||
class TestRunGeometryAddRepresentation(NewFile):
|
||||
def test_nothing(self):
|
||||
pass
|
||||
|
||||
|
||||
class TestRunGeometrySwitchRepresentation(NewFile):
|
||||
def test_nothing(self):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user