mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-24 20:50:02 +00:00
Fix bug where adding a representation to a type instance didn't share meshes
This commit is contained in:
@@ -66,6 +66,7 @@ def add_representation(
|
|||||||
ifc.run("geometry.assign_representation", product=element, representation=representation)
|
ifc.run("geometry.assign_representation", product=element, representation=representation)
|
||||||
|
|
||||||
data = geometry.duplicate_object_data(obj)
|
data = geometry.duplicate_object_data(obj)
|
||||||
|
geometry.change_object_data(obj, data, is_global=True)
|
||||||
name = geometry.get_representation_name(representation)
|
name = geometry.get_representation_name(representation)
|
||||||
geometry.rename_object(data, name)
|
geometry.rename_object(data, name)
|
||||||
geometry.link(representation, data)
|
geometry.link(representation, data)
|
||||||
|
|||||||
@@ -63,8 +63,7 @@ class Geometry(blenderbim.core.tool.Geometry):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def duplicate_object_data(cls, obj):
|
def duplicate_object_data(cls, obj):
|
||||||
obj.data = obj.data.copy()
|
return obj.data.copy()
|
||||||
return obj.data
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_cartesian_point_coordinate_offset(cls, obj):
|
def get_cartesian_point_coordinate_offset(cls, obj):
|
||||||
|
|||||||
@@ -18,10 +18,29 @@ Scenario: Add representation
|
|||||||
And I set "scene.BIMRootProperties.ifc_class" to "IfcWall"
|
And I set "scene.BIMRootProperties.ifc_class" to "IfcWall"
|
||||||
And I press "bim.assign_class"
|
And I press "bim.assign_class"
|
||||||
And the object "IfcWall/Cube" is selected
|
And the object "IfcWall/Cube" is selected
|
||||||
|
Then the object "IfcWall/Cube" has a "Tessellation" representation of "Model/Body/MODEL_VIEW"
|
||||||
When the variable "context" is "{ifc}.by_type('IfcGeometricRepresentationSubContext')[-1].id()"
|
When the variable "context" is "{ifc}.by_type('IfcGeometricRepresentationSubContext')[-1].id()"
|
||||||
And I set "scene.BIMProperties.contexts" to "{context}"
|
And I set "scene.BIMProperties.contexts" to "{context}"
|
||||||
And I press "bim.add_representation"
|
And I press "bim.add_representation"
|
||||||
Then nothing happens
|
Then the object "IfcWall/Cube" has a "Annotation2D" representation of "Plan/Annotation/PLAN_VIEW"
|
||||||
|
|
||||||
|
Scenario: Add representation - add a new representation to a typed instance
|
||||||
|
Given an empty IFC project
|
||||||
|
And I add a cube
|
||||||
|
And the object "Cube" is selected
|
||||||
|
And I set "scene.BIMRootProperties.ifc_product" to "IfcElementType"
|
||||||
|
And I set "scene.BIMRootProperties.ifc_class" to "IfcWallType"
|
||||||
|
And I press "bim.assign_class"
|
||||||
|
And I press "bim.add_type_instance"
|
||||||
|
And I press "bim.add_type_instance"
|
||||||
|
Then the object "IfcWall/Instance" has a "MappedRepresentation" representation of "Model/Body/MODEL_VIEW"
|
||||||
|
And the object "IfcWall/Instance.001" has a "MappedRepresentation" representation of "Model/Body/MODEL_VIEW"
|
||||||
|
When the object "IfcWall/Instance" is selected
|
||||||
|
And the variable "context" is "{ifc}.by_type('IfcGeometricRepresentationSubContext')[-1].id()"
|
||||||
|
And I set "scene.BIMProperties.contexts" to "{context}"
|
||||||
|
And I press "bim.add_representation"
|
||||||
|
Then the object "IfcWall/Instance" has a "MappedRepresentation" representation of "Plan/Annotation/PLAN_VIEW"
|
||||||
|
And the object "IfcWall/Instance.001" has a "MappedRepresentation" representation of "Plan/Annotation/PLAN_VIEW"
|
||||||
|
|
||||||
Scenario: Switch representation
|
Scenario: Switch representation
|
||||||
Given an empty IFC project
|
Given an empty IFC project
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ class TestAddRepresentation:
|
|||||||
|
|
||||||
# Update mesh
|
# Update mesh
|
||||||
geometry.duplicate_object_data("obj").should_be_called().will_return("data")
|
geometry.duplicate_object_data("obj").should_be_called().will_return("data")
|
||||||
|
geometry.change_object_data("obj", "data", is_global=True).should_be_called()
|
||||||
geometry.get_representation_name("representation").should_be_called().will_return("name")
|
geometry.get_representation_name("representation").should_be_called().will_return("name")
|
||||||
geometry.rename_object("data", "name").should_be_called()
|
geometry.rename_object("data", "name").should_be_called()
|
||||||
geometry.link("representation", "data").should_be_called()
|
geometry.link("representation", "data").should_be_called()
|
||||||
@@ -124,6 +125,7 @@ class TestAddRepresentation:
|
|||||||
|
|
||||||
# Update mesh
|
# Update mesh
|
||||||
geometry.duplicate_object_data("obj").should_be_called().will_return("data")
|
geometry.duplicate_object_data("obj").should_be_called().will_return("data")
|
||||||
|
geometry.change_object_data("obj", "data", is_global=True).should_be_called()
|
||||||
geometry.get_representation_name("representation").should_be_called().will_return("name")
|
geometry.get_representation_name("representation").should_be_called().will_return("name")
|
||||||
geometry.rename_object("data", "name").should_be_called()
|
geometry.rename_object("data", "name").should_be_called()
|
||||||
geometry.link("representation", "data").should_be_called()
|
geometry.link("representation", "data").should_be_called()
|
||||||
|
|||||||
@@ -112,9 +112,9 @@ class TestDuplicateObjectData(NewFile):
|
|||||||
def test_run(self):
|
def test_run(self):
|
||||||
data = bpy.data.meshes.new("Mesh")
|
data = bpy.data.meshes.new("Mesh")
|
||||||
obj = bpy.data.objects.new("Object", data)
|
obj = bpy.data.objects.new("Object", data)
|
||||||
assert subject.duplicate_object_data(obj) == obj.data
|
new_data = subject.duplicate_object_data(obj)
|
||||||
assert obj.data != data
|
assert obj.data == data
|
||||||
assert isinstance(obj.data, bpy.types.Mesh)
|
assert isinstance(new_data, bpy.types.Mesh)
|
||||||
|
|
||||||
|
|
||||||
class TestGetObjectData(NewFile):
|
class TestGetObjectData(NewFile):
|
||||||
|
|||||||
Reference in New Issue
Block a user