mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 19:07:57 +00:00
You can now view, add, edit, and remove IFC groups. Useful, but also needed for #1153.
This commit is contained in:
@@ -25,6 +25,7 @@ if bpy is not None:
|
||||
"geometry": None,
|
||||
"cobie": None,
|
||||
"sequence": None,
|
||||
"group": None,
|
||||
"material": None,
|
||||
"style": None,
|
||||
"layer": None,
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import bpy
|
||||
from . import ui, prop, operator
|
||||
|
||||
classes = (
|
||||
operator.LoadGroups,
|
||||
operator.DisableGroupEditingUI,
|
||||
operator.AddGroup,
|
||||
operator.EditGroup,
|
||||
operator.RemoveGroup,
|
||||
operator.EnableEditingGroup,
|
||||
operator.DisableEditingGroup,
|
||||
prop.Group,
|
||||
prop.BIMGroupProperties,
|
||||
ui.BIM_PT_groups,
|
||||
ui.BIM_UL_groups,
|
||||
)
|
||||
|
||||
|
||||
def register():
|
||||
bpy.types.Scene.BIMGroupProperties = bpy.props.PointerProperty(type=prop.BIMGroupProperties)
|
||||
|
||||
|
||||
def unregister():
|
||||
del bpy.types.Scene.BIMGroupProperties
|
||||
@@ -0,0 +1,17 @@
|
||||
import ifcopenshell
|
||||
from blenderbim.bim.module.owner.api import create_owner_history
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, settings={}):
|
||||
self.file = file
|
||||
self.settings = {}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
return self.file.create_entity("IfcGroup", **{
|
||||
"GlobalId": ifcopenshell.guid.new(),
|
||||
"OwnerHistory": create_owner_history(),
|
||||
"Name": "Unnamed"
|
||||
})
|
||||
@@ -0,0 +1,20 @@
|
||||
from blenderbim.bim.ifc import IfcStore
|
||||
|
||||
|
||||
class Data:
|
||||
is_loaded = False
|
||||
groups = {}
|
||||
|
||||
@classmethod
|
||||
def purge(cls):
|
||||
cls.is_loaded = False
|
||||
cls.groups = {}
|
||||
|
||||
@classmethod
|
||||
def load(cls):
|
||||
cls.groups = {}
|
||||
for group in IfcStore.get_file().by_type("IfcGroup", include_subtypes=False):
|
||||
data = group.get_info()
|
||||
del data["OwnerHistory"]
|
||||
cls.groups[group.id()] = data
|
||||
cls.is_loaded=True
|
||||
@@ -0,0 +1,13 @@
|
||||
class Usecase:
|
||||
def __init__(self, file, settings=None):
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"group": None,
|
||||
"attributes": {}
|
||||
}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
for name, value in self.settings["attributes"].items():
|
||||
setattr(self.settings["group"], name, value)
|
||||
@@ -0,0 +1,113 @@
|
||||
import bpy
|
||||
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.remove_group as remove_group
|
||||
from blenderbim.bim.ifc import IfcStore
|
||||
from blenderbim.bim.module.group.data import Data
|
||||
|
||||
|
||||
class LoadGroups(bpy.types.Operator):
|
||||
bl_idname = "bim.load_groups"
|
||||
bl_label = "Load Groups"
|
||||
|
||||
def execute(self, context):
|
||||
props = context.scene.BIMGroupProperties
|
||||
while len(props.groups) > 0:
|
||||
props.groups.remove(0)
|
||||
for ifc_definition_id, group in Data.groups.items():
|
||||
new = props.groups.add()
|
||||
new.ifc_definition_id = ifc_definition_id
|
||||
new.name = group["Name"]
|
||||
props.is_editing = True
|
||||
bpy.ops.bim.disable_editing_group()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class DisableGroupEditingUI(bpy.types.Operator):
|
||||
bl_idname = "bim.disable_group_editing_ui"
|
||||
bl_label = "Disable Group Editing UI"
|
||||
|
||||
def execute(self, context):
|
||||
context.scene.BIMGroupProperties.is_editing = False
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class AddGroup(bpy.types.Operator):
|
||||
bl_idname = "bim.add_group"
|
||||
bl_label = "Add Group"
|
||||
|
||||
def execute(self, context):
|
||||
result = add_group.Usecase(IfcStore.get_file()).execute()
|
||||
Data.load()
|
||||
bpy.ops.bim.load_groups()
|
||||
bpy.ops.bim.enable_editing_group(group=result.id())
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class EditGroup(bpy.types.Operator):
|
||||
bl_idname = "bim.edit_group"
|
||||
bl_label = "Edit Group"
|
||||
|
||||
def execute(self, context):
|
||||
props = context.scene.BIMGroupProperties
|
||||
attributes = {}
|
||||
for attribute in props.group_attributes:
|
||||
if attribute.is_null:
|
||||
attributes[attribute.name] = None
|
||||
else:
|
||||
attributes[attribute.name] = attribute.string_value
|
||||
self.file = IfcStore.get_file()
|
||||
edit_group.Usecase(
|
||||
self.file, {"group": self.file.by_id(props.active_group_id), "attributes": attributes}
|
||||
).execute()
|
||||
Data.load()
|
||||
bpy.ops.bim.load_groups()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class RemoveGroup(bpy.types.Operator):
|
||||
bl_idname = "bim.remove_group"
|
||||
bl_label = "Remove Group"
|
||||
group: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
props = context.scene.BIMGroupProperties
|
||||
self.file = IfcStore.get_file()
|
||||
remove_group.Usecase(self.file, {"group": self.file.by_id(self.group)}).execute()
|
||||
Data.load()
|
||||
bpy.ops.bim.load_groups()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class EnableEditingGroup(bpy.types.Operator):
|
||||
bl_idname = "bim.enable_editing_group"
|
||||
bl_label = "Enable Editing Group"
|
||||
group: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
props = context.scene.BIMGroupProperties
|
||||
while len(props.group_attributes) > 0:
|
||||
props.group_attributes.remove(0)
|
||||
|
||||
data = Data.groups[self.group]
|
||||
|
||||
for attribute in IfcStore.get_schema().declaration_by_name("IfcGroup").all_attributes():
|
||||
data_type = str(attribute.type_of_attribute)
|
||||
if "<entity" in data_type:
|
||||
continue
|
||||
new = props.group_attributes.add()
|
||||
new.name = attribute.name()
|
||||
new.is_null = data[attribute.name()] is None
|
||||
new.is_optional = attribute.optional()
|
||||
new.string_value = "" if new.is_null else data[attribute.name()]
|
||||
props.active_group_id = self.group
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class DisableEditingGroup(bpy.types.Operator):
|
||||
bl_idname = "bim.disable_editing_group"
|
||||
bl_label = "Disable Editing Group"
|
||||
|
||||
def execute(self, context):
|
||||
context.scene.BIMGroupProperties.active_group_id = 0
|
||||
return {"FINISHED"}
|
||||
@@ -0,0 +1,26 @@
|
||||
import bpy
|
||||
from blenderbim.bim.prop import StrProperty, Attribute
|
||||
from bpy.types import PropertyGroup
|
||||
from bpy.props import (
|
||||
PointerProperty,
|
||||
StringProperty,
|
||||
EnumProperty,
|
||||
BoolProperty,
|
||||
IntProperty,
|
||||
FloatProperty,
|
||||
FloatVectorProperty,
|
||||
CollectionProperty,
|
||||
)
|
||||
|
||||
|
||||
class Group(PropertyGroup):
|
||||
name: StringProperty(name="Name")
|
||||
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
||||
|
||||
|
||||
class BIMGroupProperties(PropertyGroup):
|
||||
group_attributes: CollectionProperty(name="Group Attributes", type=Attribute)
|
||||
is_editing: BoolProperty(name="Is Editing", default=False)
|
||||
groups: CollectionProperty(name="Groups", type=Group)
|
||||
active_group_index: IntProperty(name="Active Group Index")
|
||||
active_group_id: IntProperty(name="Active Group Id")
|
||||
@@ -0,0 +1,11 @@
|
||||
class Usecase:
|
||||
def __init__(self, file, settings=None):
|
||||
self.file = file
|
||||
self.settings = {"group": None}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
for rel in self.settings["group"].IsGroupedBy or []:
|
||||
self.file.remove(rel)
|
||||
self.file.remove(self.settings["group"])
|
||||
@@ -0,0 +1,79 @@
|
||||
from bpy.types import Panel, UIList
|
||||
from blenderbim.bim.ifc import IfcStore
|
||||
from blenderbim.bim.module.group.data import Data
|
||||
|
||||
|
||||
class BIM_PT_groups(Panel):
|
||||
bl_label = "IFC Groups"
|
||||
bl_idname = "BIM_PT_groups"
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
bl_space_type = "PROPERTIES"
|
||||
bl_region_type = "WINDOW"
|
||||
bl_context = "scene"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return IfcStore.get_file()
|
||||
|
||||
def draw(self, context):
|
||||
if not Data.is_loaded:
|
||||
Data.load()
|
||||
self.props = context.scene.BIMGroupProperties
|
||||
|
||||
row = self.layout.row(align=True)
|
||||
row.label(text="{} Groups Found".format(len(Data.groups)), icon="OUTLINER")
|
||||
if self.props.is_editing:
|
||||
row.operator("bim.add_group", text="", icon="ADD")
|
||||
row.operator("bim.disable_group_editing_ui", text="", icon="CHECKMARK")
|
||||
else:
|
||||
row.operator("bim.load_groups", text="", icon="GREASEPENCIL")
|
||||
|
||||
if self.props.is_editing:
|
||||
self.layout.template_list(
|
||||
"BIM_UL_groups",
|
||||
"",
|
||||
self.props,
|
||||
"groups",
|
||||
self.props,
|
||||
"active_group_index",
|
||||
)
|
||||
|
||||
if self.props.active_group_id:
|
||||
self.draw_editable_ui(context)
|
||||
|
||||
def draw_editable_ui(self, context):
|
||||
for attribute in self.props.group_attributes:
|
||||
row = self.layout.row(align=True)
|
||||
row.prop(attribute, "string_value", text=attribute.name)
|
||||
if attribute.is_optional:
|
||||
row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
|
||||
|
||||
|
||||
|
||||
class BIM_UL_groups(UIList):
|
||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||
if item:
|
||||
row = layout.row(align=True)
|
||||
row.label(text=item.name)
|
||||
|
||||
#if context.active_object and isinstance(context.active_object.data, Mesh):
|
||||
# mprops = context.active_object.data.BIMMeshProperties
|
||||
# if (
|
||||
# mprops.ifc_definition_id in Data.items
|
||||
# and item.ifc_definition_id in Data.items[mprops.ifc_definition_id]
|
||||
# ):
|
||||
# op = row.operator("bim.unassign_presentation_layer", text="", icon="KEYFRAME_HLT", emboss=False)
|
||||
# op.layer = item.ifc_definition_id
|
||||
# else:
|
||||
# op = row.operator("bim.assign_presentation_layer", text="", icon="KEYFRAME", emboss=False)
|
||||
# op.layer = 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.disable_editing_group", text="", icon="X")
|
||||
elif context.scene.BIMGroupProperties.active_group_id:
|
||||
row.operator("bim.remove_group", text="", icon="X").group = item.ifc_definition_id
|
||||
else:
|
||||
op = row.operator("bim.enable_editing_group", text="", icon="GREASEPENCIL")
|
||||
op.group = item.ifc_definition_id
|
||||
row.operator("bim.remove_group", text="", icon="X").group = item.ifc_definition_id
|
||||
@@ -1,5 +1,3 @@
|
||||
import ifcopenshell
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, settings={}):
|
||||
self.file = file
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import bpy
|
||||
from blenderbim.bim.prop import StrProperty, Attribute
|
||||
from blenderbim.bim.module.sequence.data import Data
|
||||
from bpy.types import PropertyGroup
|
||||
from bpy.props import (
|
||||
PointerProperty,
|
||||
@@ -22,5 +21,5 @@ class Task(PropertyGroup):
|
||||
|
||||
class BIMTaskProperties(PropertyGroup):
|
||||
is_editing: BoolProperty(name="Is Editing", default=False)
|
||||
tasks: CollectionProperty(name="Available Library References", type=Task)
|
||||
tasks: CollectionProperty(name="Tasks", type=Task)
|
||||
active_task_index: IntProperty(name="Active Task Index")
|
||||
|
||||
Reference in New Issue
Block a user