mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 03:21:00 +00:00
Fix #1856. Bug where you lost your existing container or aggregation when you added a new aggregation assembly.
This commit is contained in:
@@ -17,8 +17,11 @@
|
|||||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
|
import ifcopenshell
|
||||||
|
import ifcopenshell.util.element
|
||||||
import blenderbim.tool as tool
|
import blenderbim.tool as tool
|
||||||
import blenderbim.core.aggregate as core
|
import blenderbim.core.aggregate as core
|
||||||
|
import blenderbim.core.spatial
|
||||||
import blenderbim.bim.handler
|
import blenderbim.bim.handler
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
|
|
||||||
@@ -92,10 +95,34 @@ class AddAggregate(bpy.types.Operator):
|
|||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
||||||
|
element = tool.Ifc.get_entity(obj)
|
||||||
|
if not element:
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
aggregate_collection = bpy.data.collections.new("IfcElementAssembly/Assembly")
|
aggregate_collection = bpy.data.collections.new("IfcElementAssembly/Assembly")
|
||||||
context.scene.collection.children.link(aggregate_collection)
|
context.scene.collection.children.link(aggregate_collection)
|
||||||
aggregate = bpy.data.objects.new("Assembly", None)
|
aggregate = bpy.data.objects.new("Assembly", None)
|
||||||
aggregate_collection.objects.link(aggregate)
|
aggregate_collection.objects.link(aggregate)
|
||||||
bpy.ops.bim.assign_class(obj=aggregate.name, ifc_class="IfcElementAssembly")
|
bpy.ops.bim.assign_class(obj=aggregate.name, ifc_class="IfcElementAssembly")
|
||||||
|
|
||||||
|
tool.Collector.sync(obj)
|
||||||
|
current_aggregate = ifcopenshell.util.element.get_aggregate(element)
|
||||||
|
current_container = ifcopenshell.util.element.get_container(element)
|
||||||
|
if current_aggregate:
|
||||||
|
core.assign_object(
|
||||||
|
tool.Ifc,
|
||||||
|
tool.Aggregate,
|
||||||
|
tool.Collector,
|
||||||
|
relating_obj=tool.Ifc.get_object(current_aggregate),
|
||||||
|
related_obj=aggregate,
|
||||||
|
)
|
||||||
|
elif current_container:
|
||||||
|
blenderbim.core.spatial.assign_container(
|
||||||
|
tool.Ifc,
|
||||||
|
tool.Collector,
|
||||||
|
tool.Spatial,
|
||||||
|
structure_obj=tool.Ifc.get_object(current_container),
|
||||||
|
element_obj=aggregate,
|
||||||
|
)
|
||||||
core.assign_object(tool.Ifc, tool.Aggregate, tool.Collector, relating_obj=aggregate, related_obj=obj)
|
core.assign_object(tool.Ifc, tool.Aggregate, tool.Collector, relating_obj=aggregate, related_obj=obj)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ class Brick:
|
|||||||
@interface
|
@interface
|
||||||
class Collector:
|
class Collector:
|
||||||
def assign(cls, obj): pass
|
def assign(cls, obj): pass
|
||||||
|
def sync(cls, obj): pass
|
||||||
|
|
||||||
|
|
||||||
@interface
|
@interface
|
||||||
|
|||||||
@@ -38,3 +38,44 @@ Scenario: Unassign object
|
|||||||
Then the object "IfcSite/My Site" is in the collection "IfcSite/My Site"
|
Then the object "IfcSite/My Site" is in the collection "IfcSite/My Site"
|
||||||
And the object "IfcBuildingStorey/My Storey" is in the collection "IfcBuildingStorey/My Storey"
|
And the object "IfcBuildingStorey/My Storey" is in the collection "IfcBuildingStorey/My Storey"
|
||||||
And the collection "IfcBuildingStorey/My Storey" is in the collection "IfcProject/My Project"
|
And the collection "IfcBuildingStorey/My Storey" is in the collection "IfcProject/My Project"
|
||||||
|
|
||||||
|
Scenario: Add aggregate
|
||||||
|
Given an empty IFC project
|
||||||
|
And I add a cube
|
||||||
|
And the object "Cube" is selected
|
||||||
|
And I set "scene.BIMRootProperties.ifc_class" to "IfcWall"
|
||||||
|
And I press "bim.assign_class"
|
||||||
|
And the object "IfcWall/Cube" is selected
|
||||||
|
When I press "bim.add_aggregate"
|
||||||
|
Then the object "IfcWall/Cube" is in the collection "IfcElementAssembly/Assembly"
|
||||||
|
And the object "IfcElementAssembly/Assembly" is in the collection "IfcElementAssembly/Assembly"
|
||||||
|
And the collection "IfcElementAssembly/Assembly" is in the collection "IfcProject/My Project"
|
||||||
|
|
||||||
|
Scenario: Add aggregate - with the aggregate inheriting the existing spatial collection
|
||||||
|
Given an empty IFC project
|
||||||
|
And I add a cube
|
||||||
|
And the object "Cube" is selected
|
||||||
|
And I set "scene.BIMRootProperties.ifc_class" to "IfcWall"
|
||||||
|
And I press "bim.assign_class"
|
||||||
|
And the object "IfcWall/Cube" is placed in the collection "IfcBuildingStorey/My Storey"
|
||||||
|
And the object "IfcWall/Cube" is selected
|
||||||
|
When I press "bim.add_aggregate"
|
||||||
|
Then the object "IfcWall/Cube" is in the collection "IfcElementAssembly/Assembly"
|
||||||
|
And the object "IfcElementAssembly/Assembly" is in the collection "IfcElementAssembly/Assembly"
|
||||||
|
And the collection "IfcElementAssembly/Assembly" is in the collection "IfcBuildingStorey/My Storey"
|
||||||
|
|
||||||
|
Scenario: Add aggregate - add a nested aggregate
|
||||||
|
Given an empty IFC project
|
||||||
|
And I add a cube
|
||||||
|
And the object "Cube" is selected
|
||||||
|
And I set "scene.BIMRootProperties.ifc_class" to "IfcWall"
|
||||||
|
And I press "bim.assign_class"
|
||||||
|
And the object "IfcWall/Cube" is placed in the collection "IfcBuildingStorey/My Storey"
|
||||||
|
And the object "IfcWall/Cube" is selected
|
||||||
|
When I press "bim.add_aggregate"
|
||||||
|
And the object "IfcWall/Cube" is selected
|
||||||
|
And I press "bim.add_aggregate"
|
||||||
|
Then the object "IfcWall/Cube" is in the collection "IfcElementAssembly/Assembly.001"
|
||||||
|
And the object "IfcElementAssembly/Assembly.001" is in the collection "IfcElementAssembly/Assembly.001"
|
||||||
|
And the collection "IfcElementAssembly/Assembly.001" is in the collection "IfcElementAssembly/Assembly"
|
||||||
|
And the collection "IfcElementAssembly/Assembly" is in the collection "IfcBuildingStorey/My Storey"
|
||||||
|
|||||||
Reference in New Issue
Block a user