mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-23 15:16:23 +00:00
You can now assign/unassign products to groups. Part of #1153 roadmap.
This commit is contained in:
@@ -7,6 +7,8 @@ classes = (
|
|||||||
operator.AddGroup,
|
operator.AddGroup,
|
||||||
operator.EditGroup,
|
operator.EditGroup,
|
||||||
operator.RemoveGroup,
|
operator.RemoveGroup,
|
||||||
|
operator.AssignGroup,
|
||||||
|
operator.UnassignGroup,
|
||||||
operator.EnableEditingGroup,
|
operator.EnableEditingGroup,
|
||||||
operator.DisableEditingGroup,
|
operator.DisableEditingGroup,
|
||||||
prop.Group,
|
prop.Group,
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import ifcopenshell
|
||||||
|
from blenderbim.bim.module.owner.api import create_owner_history
|
||||||
|
from blenderbim.bim.module.owner.api import update_owner_history
|
||||||
|
|
||||||
|
|
||||||
|
class Usecase:
|
||||||
|
def __init__(self, file, settings=None):
|
||||||
|
self.file = file
|
||||||
|
self.settings = {
|
||||||
|
"product": None,
|
||||||
|
"group": None,
|
||||||
|
}
|
||||||
|
for key, value in settings.items():
|
||||||
|
self.settings[key] = value
|
||||||
|
|
||||||
|
def execute(self):
|
||||||
|
if not self.settings["group"].IsGroupedBy:
|
||||||
|
return self.file.create_entity("IfcRelAssignsToGroup", **{
|
||||||
|
"GlobalId": ifcopenshell.guid.new(),
|
||||||
|
"OwnerHistory": create_owner_history(),
|
||||||
|
"RelatedObjects": [self.settings["product"]],
|
||||||
|
"RelatingGroup": self.settings["group"]
|
||||||
|
})
|
||||||
|
rel = self.settings["group"].IsGroupedBy[0]
|
||||||
|
related_objects = set(rel.RelatedObjects) or set()
|
||||||
|
related_objects.add(self.settings["product"])
|
||||||
|
rel.RelatedObjects = list(related_objects)
|
||||||
|
update_owner_history(rel)
|
||||||
@@ -3,17 +3,24 @@ from blenderbim.bim.ifc import IfcStore
|
|||||||
|
|
||||||
class Data:
|
class Data:
|
||||||
is_loaded = False
|
is_loaded = False
|
||||||
|
products = {}
|
||||||
groups = {}
|
groups = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def purge(cls):
|
def purge(cls):
|
||||||
cls.is_loaded = False
|
cls.is_loaded = False
|
||||||
|
cls.products = {}
|
||||||
cls.groups = {}
|
cls.groups = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls):
|
def load(cls):
|
||||||
|
cls.products = {}
|
||||||
cls.groups = {}
|
cls.groups = {}
|
||||||
for group in IfcStore.get_file().by_type("IfcGroup", include_subtypes=False):
|
for group in IfcStore.get_file().by_type("IfcGroup", include_subtypes=False):
|
||||||
|
if group.IsGroupedBy:
|
||||||
|
for rel in group.IsGroupedBy:
|
||||||
|
for product in rel.RelatedObjects:
|
||||||
|
cls.products.setdefault(product.id(), []).append(group.id())
|
||||||
data = group.get_info()
|
data = group.get_info()
|
||||||
del data["OwnerHistory"]
|
del data["OwnerHistory"]
|
||||||
cls.groups[group.id()] = data
|
cls.groups[group.id()] = data
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import bpy
|
|||||||
import blenderbim.bim.module.group.add_group as add_group
|
import blenderbim.bim.module.group.add_group as add_group
|
||||||
import blenderbim.bim.module.group.edit_group as edit_group
|
import blenderbim.bim.module.group.edit_group as edit_group
|
||||||
import blenderbim.bim.module.group.remove_group as remove_group
|
import blenderbim.bim.module.group.remove_group as remove_group
|
||||||
|
import blenderbim.bim.module.group.assign_group as assign_group
|
||||||
|
import blenderbim.bim.module.group.unassign_group as unassign_group
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from blenderbim.bim.module.group.data import Data
|
from blenderbim.bim.module.group.data import Data
|
||||||
|
|
||||||
@@ -111,3 +113,37 @@ class DisableEditingGroup(bpy.types.Operator):
|
|||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
context.scene.BIMGroupProperties.active_group_id = 0
|
context.scene.BIMGroupProperties.active_group_id = 0
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class AssignGroup(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.assign_group"
|
||||||
|
bl_label = "Assign Group"
|
||||||
|
product: bpy.props.StringProperty()
|
||||||
|
group: bpy.props.IntProperty()
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
product = bpy.data.objects.get(self.product) if self.product else context.active_object
|
||||||
|
self.file = IfcStore.get_file()
|
||||||
|
assign_group.Usecase(self.file, {
|
||||||
|
"product": self.file.by_id(product.BIMObjectProperties.ifc_definition_id),
|
||||||
|
"group": self.file.by_id(self.group)
|
||||||
|
}).execute()
|
||||||
|
Data.load()
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class UnassignGroup(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.unassign_group"
|
||||||
|
bl_label = "Unassign Group"
|
||||||
|
product: bpy.props.StringProperty()
|
||||||
|
group: bpy.props.IntProperty()
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
product = bpy.data.objects.get(self.product) if self.product else context.active_object
|
||||||
|
self.file = IfcStore.get_file()
|
||||||
|
unassign_group.Usecase(self.file, {
|
||||||
|
"product": self.file.by_id(product.BIMObjectProperties.ifc_definition_id),
|
||||||
|
"group": self.file.by_id(self.group)
|
||||||
|
}).execute()
|
||||||
|
Data.load()
|
||||||
|
return {"FINISHED"}
|
||||||
|
|||||||
@@ -56,17 +56,17 @@ class BIM_UL_groups(UIList):
|
|||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.label(text=item.name)
|
row.label(text=item.name)
|
||||||
|
|
||||||
#if context.active_object and isinstance(context.active_object.data, Mesh):
|
if context.active_object:
|
||||||
# mprops = context.active_object.data.BIMMeshProperties
|
oprops = context.active_object.BIMObjectProperties
|
||||||
# if (
|
if (
|
||||||
# mprops.ifc_definition_id in Data.items
|
oprops.ifc_definition_id in Data.products
|
||||||
# and item.ifc_definition_id in Data.items[mprops.ifc_definition_id]
|
and item.ifc_definition_id in Data.products[oprops.ifc_definition_id]
|
||||||
# ):
|
):
|
||||||
# op = row.operator("bim.unassign_presentation_layer", text="", icon="KEYFRAME_HLT", emboss=False)
|
op = row.operator("bim.unassign_group", text="", icon="KEYFRAME_HLT", emboss=False)
|
||||||
# op.layer = item.ifc_definition_id
|
op.group = item.ifc_definition_id
|
||||||
# else:
|
else:
|
||||||
# op = row.operator("bim.assign_presentation_layer", text="", icon="KEYFRAME", emboss=False)
|
op = row.operator("bim.assign_group", text="", icon="KEYFRAME", emboss=False)
|
||||||
# op.layer = item.ifc_definition_id
|
op.group = item.ifc_definition_id
|
||||||
|
|
||||||
if context.scene.BIMGroupProperties.active_group_id == item.ifc_definition_id:
|
if context.scene.BIMGroupProperties.active_group_id == item.ifc_definition_id:
|
||||||
row.operator("bim.edit_group", text="", icon="CHECKMARK")
|
row.operator("bim.edit_group", text="", icon="CHECKMARK")
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import ifcopenshell
|
||||||
|
from blenderbim.bim.module.owner.api import update_owner_history
|
||||||
|
|
||||||
|
|
||||||
|
class Usecase:
|
||||||
|
def __init__(self, file, settings=None):
|
||||||
|
self.file = file
|
||||||
|
self.settings = {
|
||||||
|
"product": None,
|
||||||
|
"group": None,
|
||||||
|
}
|
||||||
|
for key, value in settings.items():
|
||||||
|
self.settings[key] = value
|
||||||
|
|
||||||
|
def execute(self):
|
||||||
|
if not self.settings["group"].IsGroupedBy:
|
||||||
|
return
|
||||||
|
rel = self.settings["group"].IsGroupedBy[0]
|
||||||
|
related_objects = set(rel.RelatedObjects) or set()
|
||||||
|
related_objects.remove(self.settings["product"])
|
||||||
|
if len(related_objects):
|
||||||
|
rel.RelatedObjects = list(related_objects)
|
||||||
|
update_owner_history(rel)
|
||||||
|
else:
|
||||||
|
self.file.remove(rel)
|
||||||
@@ -16,7 +16,7 @@ class Data:
|
|||||||
cls.layers = {}
|
cls.layers = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls, item_id=None):
|
def load(cls):
|
||||||
cls._file = IfcStore.get_file()
|
cls._file = IfcStore.get_file()
|
||||||
if not cls._file:
|
if not cls._file:
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user