mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 02:07:36 +00:00
Code review with myoualid for IFC resource module
This commit is contained in:
@@ -6,22 +6,17 @@ classes = (
|
|||||||
operator.DisableEditingResource,
|
operator.DisableEditingResource,
|
||||||
operator.EnableEditingResource,
|
operator.EnableEditingResource,
|
||||||
operator.LoadResources,
|
operator.LoadResources,
|
||||||
operator.AddCrewResource,
|
operator.AddResource,
|
||||||
operator.AddSubcontractResource,
|
|
||||||
operator.AddEquipementResource,
|
|
||||||
operator.AddLaborResource,
|
|
||||||
operator.AddProductResource,
|
|
||||||
operator.AddMaterialResource,
|
|
||||||
operator.EditResource,
|
operator.EditResource,
|
||||||
operator.RemoveResource,
|
operator.RemoveResource,
|
||||||
operator.EnableEditingNestedResource,
|
operator.LoadResourceProperties,
|
||||||
operator.LoadNestedResourceProperties,
|
operator.ExpandResource,
|
||||||
# operator.DisableNestedResourceEditingUI,
|
operator.ContractResource,
|
||||||
prop.Resource,
|
prop.Resource,
|
||||||
prop.BIMResourceProperties,
|
prop.BIMResourceProperties,
|
||||||
prop.BIMResourceTreeProperties,
|
prop.BIMResourceTreeProperties,
|
||||||
ui.BIM_PT_resources,
|
ui.BIM_PT_resources,
|
||||||
ui.BIM_UL_nested_resources,
|
ui.BIM_UL_resources,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,20 +7,37 @@ from ifcopenshell.api.resource.data import Data
|
|||||||
|
|
||||||
class LoadResources(bpy.types.Operator):
|
class LoadResources(bpy.types.Operator):
|
||||||
bl_idname = "bim.load_resources"
|
bl_idname = "bim.load_resources"
|
||||||
bl_label = "Load Work Plans"
|
bl_label = "Load Resources"
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
props = context.scene.BIMResourceProperties
|
self.props = context.scene.BIMResourceProperties
|
||||||
while len(props.resources) > 0:
|
self.tprops = context.scene.BIMResourceTreeProperties
|
||||||
props.resources.remove(0)
|
while len(self.tprops.resources) > 0:
|
||||||
for ifc_definition_id, resource in Data.resources.items():
|
self.tprops.resources.remove(0)
|
||||||
new = props.resources.add()
|
|
||||||
new.ifc_definition_id = ifc_definition_id
|
self.contracted_resources = json.loads(self.props.contracted_resources)
|
||||||
new.name = resource["Name"] or "Unnamed"
|
for resource_id, data in Data.resources.items():
|
||||||
props.is_loaded = True
|
if not data["HasContext"]:
|
||||||
bpy.ops.bim.disable_editing_resource()
|
continue
|
||||||
|
self.create_new_resource_li(resource_id, 0)
|
||||||
|
bpy.ops.bim.load_resource_properties()
|
||||||
|
self.props.is_editing = True
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
def create_new_resource_li(self, related_object_id, level_index):
|
||||||
|
resource = Data.resources[related_object_id]
|
||||||
|
new = self.tprops.resources.add()
|
||||||
|
new.ifc_definition_id = related_object_id
|
||||||
|
new.is_expanded = related_object_id not in self.contracted_resources
|
||||||
|
new.level_index = level_index
|
||||||
|
if resource["RelatedObjects"]:
|
||||||
|
new.has_children = True
|
||||||
|
if new.is_expanded:
|
||||||
|
for related_object_id in resource["RelatedObjects"]:
|
||||||
|
self.create_new_resource_li(related_object_id, level_index + 1)
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class EnableEditingResource(bpy.types.Operator):
|
class EnableEditingResource(bpy.types.Operator):
|
||||||
bl_idname = "bim.enable_editing_resource"
|
bl_idname = "bim.enable_editing_resource"
|
||||||
bl_label = "Enable Editing Resource"
|
bl_label = "Enable Editing Resource"
|
||||||
@@ -32,12 +49,11 @@ class EnableEditingResource(bpy.types.Operator):
|
|||||||
while len(self.props.resource_attributes) > 0:
|
while len(self.props.resource_attributes) > 0:
|
||||||
self.props.resource_attributes.remove(0)
|
self.props.resource_attributes.remove(0)
|
||||||
self.enable_editing_resource()
|
self.enable_editing_resource()
|
||||||
self.props.is_editing = "RESOURCE"
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
def enable_editing_resource(self):
|
def enable_editing_resource(self):
|
||||||
data = Data.resources[self.resource]
|
data = Data.resources[self.resource]
|
||||||
for attribute in IfcStore.get_schema().declaration_by_name("IfcCrewResource").all_attributes():
|
for attribute in IfcStore.get_schema().declaration_by_name(data["type"]).all_attributes():
|
||||||
data_type = ifcopenshell.util.attribute.get_primitive_type(attribute)
|
data_type = ifcopenshell.util.attribute.get_primitive_type(attribute)
|
||||||
if data_type == "entity" or isinstance(data_type, tuple):
|
if data_type == "entity" or isinstance(data_type, tuple):
|
||||||
continue
|
continue
|
||||||
@@ -54,54 +70,21 @@ class EnableEditingResource(bpy.types.Operator):
|
|||||||
new.enum_value = data[attribute.name()]
|
new.enum_value = data[attribute.name()]
|
||||||
|
|
||||||
|
|
||||||
class EnableEditingNestedResource(bpy.types.Operator):
|
class LoadResourceProperties(bpy.types.Operator):
|
||||||
bl_idname = "bim.enable_editing_nested_resources"
|
bl_idname = "bim.load_resource_properties"
|
||||||
bl_label = "Enable Editing Nested Resource"
|
bl_label = "Load Resource Properties"
|
||||||
resource: bpy.props.IntProperty()
|
resource: bpy.props.IntProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
self.props = context.scene.BIMResourceProperties
|
self.props = context.scene.BIMResourceProperties
|
||||||
self.tprops = context.scene.BIMResourceTreeProperties
|
self.tprops = context.scene.BIMResourceTreeProperties
|
||||||
self.props.active_resource_id = self.resource
|
self.props.is_resource_update_enabled = False
|
||||||
while len(self.tprops.nested_resources) > 0:
|
for item in self.tprops.resources:
|
||||||
self.tprops.nested_resources.remove(0)
|
if self.resource and item.ifc_definition_id != self.resource:
|
||||||
|
|
||||||
self.contracted_nested_resources = json.loads(self.props.contracted_nested_resources)
|
|
||||||
for related_object_id in Data.resources[self.resource]["RelatedObjects"]:
|
|
||||||
self.create_new_nested_resource_li(related_object_id, 0)
|
|
||||||
bpy.ops.bim.load_nested_resource_properties()
|
|
||||||
self.props.is_editing = "NESTED_RESOURCE"
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
def create_new_nested_resource_li(self, related_object_id, level_index):
|
|
||||||
nested_resource = Data.nested_resources[related_object_id]
|
|
||||||
new = self.tprops.nested_resources.add()
|
|
||||||
new.ifc_definition_id = related_object_id
|
|
||||||
new.is_expanded = related_object_id not in self.contracted_nested_resources
|
|
||||||
new.level_index = level_index
|
|
||||||
if nested_resource["RelatedObjects"]:
|
|
||||||
new.has_children = True
|
|
||||||
if new.is_expanded:
|
|
||||||
for related_object_id in nested_resource["RelatedObjects"]:
|
|
||||||
self.create_new_nested_resource_li(related_object_id, level_index + 1)
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class LoadNestedResourceProperties(bpy.types.Operator):
|
|
||||||
bl_idname = "bim.load_nested_resource_properties"
|
|
||||||
bl_label = "Load nested_resource Properties"
|
|
||||||
nested_resource: bpy.props.IntProperty()
|
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
self.props = context.scene.BIMResourceProperties
|
|
||||||
self.tprops = context.scene.BIMResourceTreeProperties
|
|
||||||
self.props.is_nested_resource_update_enabled = False
|
|
||||||
for item in self.tprops.nested_resources:
|
|
||||||
if self.nested_resource and item.ifc_definition_id != self.nested_resource:
|
|
||||||
continue
|
continue
|
||||||
nested_resource = Data.nested_resources[item.ifc_definition_id]
|
resource = Data.resources[item.ifc_definition_id]
|
||||||
item.name = nested_resource["Name"] or "Unnamed"
|
item.name = resource["Name"] or "Unnamed"
|
||||||
self.props.is_nested_resource_update_enabled = True
|
self.props.is_resource_update_enabled = True
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
@@ -119,102 +102,27 @@ class DisableResourceEditingUI(bpy.types.Operator):
|
|||||||
bl_label = "Disable Resources Editing UI"
|
bl_label = "Disable Resources Editing UI"
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
context.scene.BIMResourceProperties.is_loaded = False
|
context.scene.BIMResourceProperties.is_editing = False
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class AddSubcontractResource(bpy.types.Operator):
|
class AddResource(bpy.types.Operator):
|
||||||
bl_idname = "bim.add_subcontract_resource"
|
bl_idname = "bim.add_resource"
|
||||||
bl_label = "Add Subcontract Resource"
|
bl_label = "Add resource"
|
||||||
|
ifc_class: bpy.props.StringProperty()
|
||||||
resource: bpy.props.IntProperty()
|
resource: bpy.props.IntProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
if self.resource:
|
ifcopenshell.api.run(
|
||||||
ifcopenshell.api.run(
|
"resource.add_resource",
|
||||||
"resource.add_subcontract_resource",
|
|
||||||
IfcStore.get_file(),
|
IfcStore.get_file(),
|
||||||
resource=IfcStore.get_file().by_id(self.resource)
|
parent_resource=IfcStore.get_file().by_id(self.resource) if self.resource else None,
|
||||||
)
|
ifc_class=self.ifc_class,
|
||||||
else:
|
|
||||||
ifcopenshell.api.run("resource.add_subcontract_resource", IfcStore.get_file())
|
|
||||||
Data.load(IfcStore.get_file())
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class AddCrewResource(bpy.types.Operator):
|
|
||||||
bl_idname = "bim.add_crew_resource"
|
|
||||||
bl_label = "Add Crew Resource"
|
|
||||||
resource: bpy.props.IntProperty()
|
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
if self.resource:
|
|
||||||
ifcopenshell.api.run(
|
|
||||||
"resource.add_crew_resource",
|
|
||||||
IfcStore.get_file(),
|
|
||||||
resource=IfcStore.get_file().by_id(self.resource)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
ifcopenshell.api.run("resource.add_crew_resource", IfcStore.get_file())
|
|
||||||
Data.load(IfcStore.get_file())
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class AddEquipementResource(bpy.types.Operator):
|
|
||||||
bl_idname = "bim.add_equipment_resource"
|
|
||||||
bl_label = "Add Equipement Resource"
|
|
||||||
resource: bpy.props.IntProperty()
|
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
ifcopenshell.api.run(
|
|
||||||
"resource.add_equipment_resource",
|
|
||||||
IfcStore.get_file(),
|
|
||||||
resource=IfcStore.get_file().by_id(self.resource)
|
|
||||||
)
|
)
|
||||||
Data.load(IfcStore.get_file())
|
Data.load(IfcStore.get_file())
|
||||||
|
bpy.ops.bim.load_resources()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
class AddLaborResource(bpy.types.Operator):
|
|
||||||
bl_idname = "bim.add_labor_resource"
|
|
||||||
bl_label = "Add Labor Resource"
|
|
||||||
resource: bpy.props.IntProperty()
|
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
ifcopenshell.api.run(
|
|
||||||
"resource.add_labor_resource",
|
|
||||||
IfcStore.get_file(),
|
|
||||||
resource=IfcStore.get_file().by_id(self.resource)
|
|
||||||
)
|
|
||||||
Data.load(IfcStore.get_file())
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class AddMaterialResource(bpy.types.Operator):
|
|
||||||
bl_idname = "bim.add_material_resource"
|
|
||||||
bl_label = "Add Material Resource"
|
|
||||||
resource: bpy.props.IntProperty()
|
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
ifcopenshell.api.run(
|
|
||||||
"resource.add_material_resource",
|
|
||||||
IfcStore.get_file(),
|
|
||||||
resource=IfcStore.get_file().by_id(self.resource)
|
|
||||||
)
|
|
||||||
Data.load(IfcStore.get_file())
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
class AddProductResource(bpy.types.Operator):
|
|
||||||
bl_idname = "bim.add_product_resource"
|
|
||||||
bl_label = "Add Product Resource"
|
|
||||||
resource: bpy.props.IntProperty()
|
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
ifcopenshell.api.run(
|
|
||||||
"resource.add_product_resource",
|
|
||||||
IfcStore.get_file(),
|
|
||||||
resource=IfcStore.get_file().by_id(self.resource)
|
|
||||||
)
|
|
||||||
Data.load(IfcStore.get_file())
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
class EditResource(bpy.types.Operator):
|
class EditResource(bpy.types.Operator):
|
||||||
bl_idname = "bim.edit_resource"
|
bl_idname = "bim.edit_resource"
|
||||||
@@ -223,7 +131,7 @@ class EditResource(bpy.types.Operator):
|
|||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
props = context.scene.BIMResourceProperties
|
props = context.scene.BIMResourceProperties
|
||||||
attributes = {}
|
attributes = {}
|
||||||
for attribute in props.nested_resource_attributes:
|
for attribute in props.resource_attributes:
|
||||||
if attribute.is_null:
|
if attribute.is_null:
|
||||||
attributes[attribute.name] = None
|
attributes[attribute.name] = None
|
||||||
else:
|
else:
|
||||||
@@ -238,6 +146,7 @@ class EditResource(bpy.types.Operator):
|
|||||||
**{"resource": self.file.by_id(props.active_resource_id), "attributes": attributes},
|
**{"resource": self.file.by_id(props.active_resource_id), "attributes": attributes},
|
||||||
)
|
)
|
||||||
Data.load(IfcStore.get_file())
|
Data.load(IfcStore.get_file())
|
||||||
|
bpy.ops.bim.load_resource_properties(resource=props.active_resource_id)
|
||||||
bpy.ops.bim.disable_editing_resource()
|
bpy.ops.bim.disable_editing_resource()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
@@ -254,4 +163,37 @@ class RemoveResource(bpy.types.Operator):
|
|||||||
resource=IfcStore.get_file().by_id(self.resource),
|
resource=IfcStore.get_file().by_id(self.resource),
|
||||||
)
|
)
|
||||||
Data.load(IfcStore.get_file())
|
Data.load(IfcStore.get_file())
|
||||||
|
bpy.ops.bim.load_resources()
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class ExpandResource(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.expand_resource"
|
||||||
|
bl_label = "Expand Resource"
|
||||||
|
resource: bpy.props.IntProperty()
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
props = context.scene.BIMResourceProperties
|
||||||
|
self.file = IfcStore.get_file()
|
||||||
|
contracted_resources = json.loads(props.contracted_resources)
|
||||||
|
contracted_resources.remove(self.resource)
|
||||||
|
props.contracted_resources = json.dumps(contracted_resources)
|
||||||
|
Data.load(self.file)
|
||||||
|
bpy.ops.bim.load_resources()
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class ContractResource(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.contract_resource"
|
||||||
|
bl_label = "Contract Resource"
|
||||||
|
resource: bpy.props.IntProperty()
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
props = context.scene.BIMResourceProperties
|
||||||
|
self.file = IfcStore.get_file()
|
||||||
|
contracted_resources = json.loads(props.contracted_resources)
|
||||||
|
contracted_resources.append(self.resource)
|
||||||
|
props.contracted_resources = json.dumps(contracted_resources)
|
||||||
|
Data.load(self.file)
|
||||||
|
bpy.ops.bim.load_resources()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|||||||
@@ -16,27 +16,39 @@ from bpy.props import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def updateResourceName(self, context):
|
||||||
|
props = context.scene.BIMResourceProperties
|
||||||
|
if not props.is_resource_update_enabled or self.name == "Unnamed":
|
||||||
|
return
|
||||||
|
self.file = IfcStore.get_file()
|
||||||
|
ifcopenshell.api.run(
|
||||||
|
"resource.edit_resource",
|
||||||
|
self.file,
|
||||||
|
**{"resource": self.file.by_id(self.ifc_definition_id), "attributes": {"Name": self.name}},
|
||||||
|
)
|
||||||
|
Data.load(IfcStore.get_file())
|
||||||
|
if props.active_resource_id == self.ifc_definition_id:
|
||||||
|
attribute = props.resource_attributes.get("Name")
|
||||||
|
attribute.string_value = self.name
|
||||||
|
|
||||||
|
|
||||||
class Resource(PropertyGroup):
|
class Resource(PropertyGroup):
|
||||||
name: StringProperty(name="Name")
|
name: StringProperty(name="Name", update=updateResourceName)
|
||||||
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
||||||
has_children: BoolProperty(name="Has Children")
|
has_children: BoolProperty(name="Has Children")
|
||||||
is_expanded: BoolProperty(name="Is Expanded")
|
is_expanded: BoolProperty(name="Is Expanded")
|
||||||
level_index: IntProperty(name="Level Index")
|
level_index: IntProperty(name="Level Index")
|
||||||
|
|
||||||
|
|
||||||
class BIMResourceTreeProperties(PropertyGroup):
|
class BIMResourceTreeProperties(PropertyGroup):
|
||||||
nested_resources: CollectionProperty(name="nested_resources", type=Resource)
|
resources: CollectionProperty(name="Resources", type=Resource)
|
||||||
|
|
||||||
|
|
||||||
class BIMResourceProperties(PropertyGroup):
|
class BIMResourceProperties(PropertyGroup):
|
||||||
resource_attributes: CollectionProperty(name="Resource Attributes", type=Attribute)
|
resource_attributes: CollectionProperty(name="Resource Attributes", type=Attribute)
|
||||||
is_editing: StringProperty(name="Is Editing")
|
is_editing: BoolProperty(name="Is Editing")
|
||||||
active_resource_index: IntProperty(name="Active Resource Index")
|
active_resource_index: IntProperty(name="Active Resource Index")
|
||||||
active_resource_id: IntProperty(name="Active Resource Id")
|
active_resource_id: IntProperty(name="Active Resource Id")
|
||||||
active_nested_resource_index: IntProperty(name="Active nested_resource Index")
|
contracted_resources: StringProperty(name="Contracted Resources", default="[]")
|
||||||
active_nested_resource_id: IntProperty(name="Active nested_resource Id")
|
is_resource_update_enabled: BoolProperty(name="Is Resource Update Enabled", default=True)
|
||||||
nested_resource_attributes: CollectionProperty(name="nested_resource Attributes", type=Attribute)
|
|
||||||
contracted_nested_resources: StringProperty(name="Contracted nested_resource Items", default="[]")
|
|
||||||
is_nested_resource_update_enabled: BoolProperty(name="Is nested_resource Update Enabled", default=True)
|
|
||||||
resources: CollectionProperty(name="Resource", type=Resource)
|
|
||||||
is_loaded: BoolProperty(name="Is Editing")
|
is_loaded: BoolProperty(name="Is Editing")
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from bpy.types import Panel, UIList
|
|||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from ifcopenshell.api.resource.data import Data
|
from ifcopenshell.api.resource.data import Data
|
||||||
|
|
||||||
|
|
||||||
class BIM_PT_resources(Panel):
|
class BIM_PT_resources(Panel):
|
||||||
bl_label = "IFC Resources"
|
bl_label = "IFC Resources"
|
||||||
bl_idname = "BIM_PT_resources"
|
bl_idname = "BIM_PT_resources"
|
||||||
@@ -17,48 +18,54 @@ class BIM_PT_resources(Panel):
|
|||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
self.props = context.scene.BIMResourceProperties
|
self.props = context.scene.BIMResourceProperties
|
||||||
self.tprops = context.scene.BIMResourceTreeProperties
|
self.tprops = context.scene.BIMResourceTreeProperties
|
||||||
row = self.layout.row()
|
|
||||||
if self.props.is_loaded:
|
|
||||||
row.operator("bim.disable_resource_editing_ui", text="CANCEL EDITING RESOURCES", icon="CANCEL")
|
|
||||||
else:
|
|
||||||
row.operator("bim.load_resources", text="Load Resources", icon="GREASEPENCIL")
|
|
||||||
|
|
||||||
if not Data.is_loaded:
|
if not Data.is_loaded:
|
||||||
Data.load(IfcStore.get_file())
|
Data.load(IfcStore.get_file())
|
||||||
if self.props.is_loaded:
|
|
||||||
row = self.layout.row(align=True)
|
|
||||||
row.operator("bim.add_subcontract_resource", text="Add Subcontract", icon="FILE_TICK")
|
|
||||||
row.operator("bim.add_crew_resource", text="Add Crew", icon="COMMUNITY")
|
|
||||||
for resource_id, resource in Data.resources.items():
|
|
||||||
self.draw_resource_ui(resource_id, resource)
|
|
||||||
|
|
||||||
def draw_resource_ui(self, resource_id, resource):
|
row = self.layout.row(align=True)
|
||||||
row = self.layout.row()
|
row.label(text=f"{len(Data.resources)} Resources Found")
|
||||||
row.label(text=resource["Name"] or "Unnamed", icon="BOOKMARKS")
|
if self.props.is_editing:
|
||||||
if self.props.active_resource_id and self.props.active_resource_id == resource_id:
|
row.operator("bim.disable_resource_editing_ui", text="", icon="CANCEL")
|
||||||
if self.props.is_editing == "RESOURCE":
|
|
||||||
row.operator("bim.edit_resource", text="", icon="CHECKMARK")
|
|
||||||
elif self.props.is_editing == "NESTED_RESOURCE":
|
|
||||||
row.operator("bim.add_subcontract_resource", text="", icon="FILE_TICK").resource = resource_id
|
|
||||||
row.operator("bim.add_crew_resource", text="", icon="COMMUNITY").resource = resource_id
|
|
||||||
row.operator("bim.add_equipment_resource", text="", icon="TOOL_SETTINGS").resource = resource_id
|
|
||||||
row.operator("bim.add_labor_resource", text="", icon="ARMATURE_DATA").resource = resource_id
|
|
||||||
row.operator("bim.add_material_resource", text="", icon="MATERIAL").resource = resource_id
|
|
||||||
row.operator("bim.add_product_resource", text="", icon="PACKAGE").resource = resource_id
|
|
||||||
row.operator("bim.edit_resource", text="", icon="CHECKMARK")#.resource = resource_id
|
|
||||||
#TODO add if statement in operator for editing resource so that it doesnt toggle the wrong panel
|
|
||||||
row.operator("bim.disable_editing_resource", text="", icon="CANCEL")
|
|
||||||
elif self.props.active_resource_id:
|
|
||||||
row.operator("bim.remove_resource", text="", icon="X").resource = resource_id
|
|
||||||
else:
|
else:
|
||||||
row.operator("bim.enable_editing_nested_resources", text="", icon="ACTION").resource = resource_id
|
row.operator("bim.load_resources", text="", icon="GREASEPENCIL")
|
||||||
row.operator("bim.enable_editing_resource", text="", icon="GREASEPENCIL").resource = resource_id
|
|
||||||
|
|
||||||
if self.props.active_resource_id == resource_id:
|
if not self.props.is_editing:
|
||||||
if self.props.is_editing == "RESOURCE":
|
return
|
||||||
self.draw_editable_resource_ui()
|
|
||||||
elif self.props.is_editing == "NESTED_RESOURCE":
|
row = self.layout.row(align=True)
|
||||||
self.draw_editable_nested_resource_ui(resource_id)
|
op = row.operator("bim.add_resource", text="Add SubContract", icon="FILE_TICK")
|
||||||
|
op.ifc_class = "IfcSubContractResource"
|
||||||
|
op.resource = 0
|
||||||
|
op = row.operator("bim.add_resource", text="Add Crew", icon="COMMUNITY")
|
||||||
|
op.ifc_class = "IfcCrewResource"
|
||||||
|
op.resource = 0
|
||||||
|
|
||||||
|
icon_map = {
|
||||||
|
"IfcConstructionEquipmentResource": "TOOL_SETTINGS",
|
||||||
|
"IfcLaborResource": "OUTLINER_OB_ARMATURE",
|
||||||
|
"IfcConstructionMaterialResource": "MATERIAL",
|
||||||
|
"IfcConstructionProductResource": "PACKAGE",
|
||||||
|
}
|
||||||
|
|
||||||
|
total_resources = len(self.tprops.resources)
|
||||||
|
if total_resources and self.props.active_resource_index < total_resources:
|
||||||
|
row = self.layout.row(align=True)
|
||||||
|
for ifc_class, icon in icon_map.items():
|
||||||
|
label = ifc_class.replace("Ifc", "").replace("Construction", "").replace("Resource", "")
|
||||||
|
op = row.operator("bim.add_resource", text=label, icon=icon)
|
||||||
|
op.resource = self.tprops.resources[self.props.active_resource_index].ifc_definition_id
|
||||||
|
op.ifc_class = ifc_class
|
||||||
|
|
||||||
|
self.layout.template_list(
|
||||||
|
"BIM_UL_resources",
|
||||||
|
"",
|
||||||
|
self.tprops,
|
||||||
|
"resources",
|
||||||
|
self.props,
|
||||||
|
"active_resource_index",
|
||||||
|
)
|
||||||
|
if self.props.active_resource_id:
|
||||||
|
self.draw_editable_resource_ui()
|
||||||
|
|
||||||
def draw_editable_resource_ui(self):
|
def draw_editable_resource_ui(self):
|
||||||
for attribute in self.props.resource_attributes:
|
for attribute in self.props.resource_attributes:
|
||||||
@@ -76,36 +83,18 @@ class BIM_PT_resources(Panel):
|
|||||||
if attribute.is_optional:
|
if attribute.is_optional:
|
||||||
row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
|
row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
|
||||||
|
|
||||||
def draw_editable_nested_resource_ui(self, resource_id):
|
|
||||||
self.layout.template_list(
|
|
||||||
"BIM_UL_nested_resources",
|
|
||||||
"",
|
|
||||||
self.tprops,
|
|
||||||
"nested_resources",
|
|
||||||
self.props,
|
|
||||||
"active_nested_resource_index",
|
|
||||||
)
|
|
||||||
if self.props.active_nested_resource_id:
|
|
||||||
self.draw_editable_nested_resource_attributes_ui()
|
|
||||||
|
|
||||||
|
class BIM_UL_resources(UIList):
|
||||||
def draw_editable_nested_resource_attributes_ui(self):
|
|
||||||
for attribute in self.props.nested_resource_attributes:
|
|
||||||
row = self.layout.row(align=True)
|
|
||||||
if attribute.data_type == "string":
|
|
||||||
row.prop(attribute, "string_value", text=attribute.name)
|
|
||||||
elif attribute.data_type == "boolean":
|
|
||||||
row.prop(attribute, "bool_value", text=attribute.name)
|
|
||||||
elif attribute.data_type == "integer":
|
|
||||||
row.prop(attribute, "int_value", text=attribute.name)
|
|
||||||
elif attribute.data_type == "enum":
|
|
||||||
row.prop(attribute, "enum_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_nested_resources(UIList):
|
|
||||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||||
|
resource = Data.resources[item.ifc_definition_id]
|
||||||
|
icon_map = {
|
||||||
|
"IfcSubContractResource": "FILE_TICK",
|
||||||
|
"IfcCrewResource": "COMMUNITY",
|
||||||
|
"IfcConstructionEquipmentResource": "TOOL_SETTINGS",
|
||||||
|
"IfcLaborResource": "OUTLINER_OB_ARMATURE",
|
||||||
|
"IfcConstructionMaterialResource": "MATERIAL",
|
||||||
|
"IfcConstructionProductResource": "PACKAGE",
|
||||||
|
}
|
||||||
if item:
|
if item:
|
||||||
props = context.scene.BIMResourceProperties
|
props = context.scene.BIMResourceProperties
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
@@ -114,21 +103,25 @@ class BIM_UL_nested_resources(UIList):
|
|||||||
if item.has_children:
|
if item.has_children:
|
||||||
if item.is_expanded:
|
if item.is_expanded:
|
||||||
row.operator(
|
row.operator(
|
||||||
"bim.contract_nested_resource", text="", emboss=False, icon="DISCLOSURE_TRI_DOWN"
|
"bim.contract_resource", text="", emboss=False, icon="DISCLOSURE_TRI_DOWN"
|
||||||
).nested_resource = item.ifc_definition_id
|
).resource = item.ifc_definition_id
|
||||||
else:
|
else:
|
||||||
row.operator(
|
row.operator(
|
||||||
"bim.expand_nested_resource", text="", emboss=False, icon="DISCLOSURE_TRI_RIGHT"
|
"bim.expand_resource", text="", emboss=False, icon="DISCLOSURE_TRI_RIGHT"
|
||||||
).nested_resource = item.ifc_definition_id
|
).resource = item.ifc_definition_id
|
||||||
|
|
||||||
if props.active_nested_resource_id == item.ifc_definition_id:
|
|
||||||
row.operator("bim.edit_nested_resource", text="", icon="CHECKMARK")
|
|
||||||
row.operator("bim.disable_editing_nested_resource", text="", icon="CANCEL")
|
|
||||||
elif props.active_nested_resource_id:
|
|
||||||
row.operator("bim.add_nested_resource", text="", icon="ADD").nested_resource = item.ifc_definition_id
|
|
||||||
row.operator("bim.remove_nested_resource", text="", icon="X").nested_resource = item.ifc_definition_id
|
|
||||||
else:
|
else:
|
||||||
row.operator("bim.enable_editing_nested_resource_time", text="", icon="TIME").nested_resource = item.ifc_definition_id
|
row.label(text="", icon="DOT")
|
||||||
row.operator("bim.enable_editing_nested_resource", text="", icon="GREASEPENCIL").nested_resource = item.ifc_definition_id
|
row.prop(item, "name", emboss=False, text="", icon=icon_map[resource["type"]])
|
||||||
row.operator("bim.add_nested_resource", text="", icon="ADD").nested_resource = item.ifc_definition_id
|
|
||||||
row.operator("bim.remove_nested_resource", text="", icon="X").nested_resource = item.ifc_definition_id
|
if props.active_resource_id == item.ifc_definition_id:
|
||||||
|
row.operator("bim.edit_resource", text="", icon="CHECKMARK")
|
||||||
|
row.operator("bim.disable_editing_resource", text="", icon="CANCEL")
|
||||||
|
elif props.active_resource_id:
|
||||||
|
row.operator("bim.add_resource", text="", icon="ADD").resource = item.ifc_definition_id
|
||||||
|
row.operator("bim.remove_resource", text="", icon="X").resource = item.ifc_definition_id
|
||||||
|
else:
|
||||||
|
row.operator(
|
||||||
|
"bim.enable_editing_resource", text="", icon="GREASEPENCIL"
|
||||||
|
).resource = item.ifc_definition_id
|
||||||
|
|
||||||
|
row.operator("bim.remove_resource", text="", icon="X").resource = item.ifc_definition_id
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
import ifcopenshell.api
|
|
||||||
import ifcopenshell
|
|
||||||
|
|
||||||
|
|
||||||
class Usecase:
|
|
||||||
def __init__(self, file, **settings):
|
|
||||||
self.file = file
|
|
||||||
self.settings = {
|
|
||||||
"parent_resource": None,
|
|
||||||
}
|
|
||||||
for key, value in settings.items():
|
|
||||||
self.settings[key] = value
|
|
||||||
|
|
||||||
def execute(self):
|
|
||||||
equipment_resource = ifcopenshell.api.run(
|
|
||||||
"root.create_entity",
|
|
||||||
self.file,
|
|
||||||
ifc_class="IfcConstructionEquipmentResource",
|
|
||||||
name=None,
|
|
||||||
predefined_type="NOTDEFINED",
|
|
||||||
identification="none",
|
|
||||||
)
|
|
||||||
if self.settings["parent_resource"]:
|
|
||||||
ifcopenshell.api.run(
|
|
||||||
"nest.assign_object", self.file, related_object=equipment_resource, relating_object=self.settings["parent_resource"]
|
|
||||||
)
|
|
||||||
return equipment_resource
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import ifcopenshell.api
|
|
||||||
import ifcopenshell
|
|
||||||
|
|
||||||
|
|
||||||
class Usecase:
|
|
||||||
def __init__(self, file, **settings):
|
|
||||||
self.file = file
|
|
||||||
self.settings = {
|
|
||||||
"parent_resource": None,
|
|
||||||
}
|
|
||||||
for key, value in settings.items():
|
|
||||||
self.settings[key] = value
|
|
||||||
|
|
||||||
def execute(self):
|
|
||||||
labor_resource = ifcopenshell.api.run(
|
|
||||||
"root.create_entity",
|
|
||||||
self.file,
|
|
||||||
ifc_class="IfcLaborResource",
|
|
||||||
name=None,
|
|
||||||
predefined_type="NOTDEFINED",
|
|
||||||
identification="none",
|
|
||||||
)
|
|
||||||
if self.settings["parent_resource"]:
|
|
||||||
ifcopenshell.api.run(
|
|
||||||
"nest.assign_object", self.file, related_object=labor_resource, relating_object=self.settings["parent_resource"]
|
|
||||||
)
|
|
||||||
return labor_resource
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import ifcopenshell.api
|
|
||||||
import ifcopenshell
|
|
||||||
|
|
||||||
|
|
||||||
class Usecase:
|
|
||||||
def __init__(self, file, **settings):
|
|
||||||
self.file = file
|
|
||||||
self.settings = {
|
|
||||||
"parent_resource": None,
|
|
||||||
}
|
|
||||||
for key, value in settings.items():
|
|
||||||
self.settings[key] = value
|
|
||||||
|
|
||||||
def execute(self):
|
|
||||||
material_resource = ifcopenshell.api.run(
|
|
||||||
"root.create_entity",
|
|
||||||
self.file,
|
|
||||||
ifc_class="IfcConstructionMaterialResource",
|
|
||||||
name=None,
|
|
||||||
predefined_type="NOTDEFINED",
|
|
||||||
identification="none",
|
|
||||||
)
|
|
||||||
if self.settings["parent_resource"]:
|
|
||||||
ifcopenshell.api.run(
|
|
||||||
"nest.assign_object", self.file, related_object=material_resource, relating_object=self.settings["parent_resource"]
|
|
||||||
)
|
|
||||||
return material_resource
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import ifcopenshell.api
|
|
||||||
import ifcopenshell
|
|
||||||
|
|
||||||
|
|
||||||
class Usecase:
|
|
||||||
def __init__(self, file, **settings):
|
|
||||||
self.file = file
|
|
||||||
self.settings = {
|
|
||||||
"parent_resource": None,
|
|
||||||
}
|
|
||||||
for key, value in settings.items():
|
|
||||||
self.settings[key] = value
|
|
||||||
|
|
||||||
def execute(self):
|
|
||||||
product_resource = ifcopenshell.api.run(
|
|
||||||
"root.create_entity",
|
|
||||||
self.file,
|
|
||||||
ifc_class="IfcConstructionProductResource",
|
|
||||||
name=None,
|
|
||||||
predefined_type="NOTDEFINED",
|
|
||||||
identification="none",
|
|
||||||
)
|
|
||||||
if self.settings["parent_resource"]:
|
|
||||||
ifcopenshell.api.run(
|
|
||||||
"nest.assign_object", self.file, related_object=product_resource, relating_object=self.settings["parent_resource"]
|
|
||||||
)
|
|
||||||
return product_resource
|
|
||||||
+8
-9
@@ -1,6 +1,4 @@
|
|||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
import ifcopenshell.util.date
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
|
|
||||||
class Usecase:
|
class Usecase:
|
||||||
@@ -8,22 +6,23 @@ class Usecase:
|
|||||||
self.file = file
|
self.file = file
|
||||||
self.settings = {
|
self.settings = {
|
||||||
"parent_resource": None,
|
"parent_resource": None,
|
||||||
"name": "Unnamed",
|
"ifc_class": "IfcCrewResource",
|
||||||
|
"name": None,
|
||||||
"predefined_type": "NOTDEFINED",
|
"predefined_type": "NOTDEFINED",
|
||||||
}
|
}
|
||||||
for key, value in settings.items():
|
for key, value in settings.items():
|
||||||
self.settings[key] = value
|
self.settings[key] = value
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
crew_resource = ifcopenshell.api.run(
|
resource = ifcopenshell.api.run(
|
||||||
"root.create_entity",
|
"root.create_entity",
|
||||||
self.file,
|
self.file,
|
||||||
ifc_class="IfcCrewResource",
|
ifc_class=self.settings["ifc_class"],
|
||||||
predefined_type=self.settings["predefined_type"],
|
predefined_type=self.settings["predefined_type"],
|
||||||
name=self.settings["name"],
|
name=self.settings["name"],
|
||||||
)
|
)
|
||||||
# TODO: this is an ambiguity by buildingSMART: Can we nest and IfcCrewResource under an ifcCrewResource ?
|
# TODO: this is an ambiguity by buildingSMART: Can we nest an IfcCrewResource under an IfcCrewResource ?
|
||||||
# See https://forums.buildingsmart.org/t/is-the-ifcCrewResource-project-declaration-mutually-exclusive-to-aggregation-within-a-relating-ifcworkplan/3510
|
# https://forums.buildingsmart.org/t/what-are-allowed-to-be-root-level-construction-resources/3550
|
||||||
if self.settings["parent_resource"]:
|
if self.settings["parent_resource"]:
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"nest.assign_object", self.file, related_object=resource, relating_object=self.settings["parent_resource"]
|
"nest.assign_object", self.file, related_object=resource, relating_object=self.settings["parent_resource"]
|
||||||
@@ -31,6 +30,6 @@ class Usecase:
|
|||||||
else:
|
else:
|
||||||
context = self.file.by_type("IfcContext")[0]
|
context = self.file.by_type("IfcContext")[0]
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"project.assign_declaration", self.file, definition=crew_resource, relating_context=context
|
"project.assign_declaration", self.file, definition=resource, relating_context=context
|
||||||
)
|
)
|
||||||
return crew_resource
|
return resource
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import ifcopenshell.api
|
|
||||||
import ifcopenshell.util.date
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
|
|
||||||
class Usecase:
|
|
||||||
def __init__(self, file, **settings):
|
|
||||||
self.file = file
|
|
||||||
self.settings = {
|
|
||||||
"parent_resource": None,
|
|
||||||
"name": "Unnamed",
|
|
||||||
"predefined_type": "NOTDEFINED",
|
|
||||||
}
|
|
||||||
for key, value in settings.items():
|
|
||||||
self.settings[key] = value
|
|
||||||
|
|
||||||
def execute(self):
|
|
||||||
subcontract_resource = ifcopenshell.api.run(
|
|
||||||
"root.create_entity",
|
|
||||||
self.file,
|
|
||||||
ifc_class="IfcSubContractResource",
|
|
||||||
predefined_type=self.settings["predefined_type"],
|
|
||||||
name=self.settings["name"],
|
|
||||||
)
|
|
||||||
# TODO: this is an ambiguity by buildingSMART: Can we nest and IfcCrewResource under an ifcCrewResource ?
|
|
||||||
# See https://forums.buildingsmart.org/t/is-the-ifcCrewResource-project-declaration-mutually-exclusive-to-aggregation-within-a-relating-ifcworkplan/3510
|
|
||||||
if self.settings["parent_resource"]:
|
|
||||||
ifcopenshell.api.run(
|
|
||||||
"nest.assign_object", self.file, related_object=resource, relating_object=self.settings["parent_resource"]
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
context = self.file.by_type("IfcContext")[0]
|
|
||||||
ifcopenshell.api.run(
|
|
||||||
"project.assign_declaration", self.file, definition=subcontract_resource, relating_context=context
|
|
||||||
)
|
|
||||||
return subcontract_resource
|
|
||||||
@@ -21,17 +21,17 @@ class Usecase:
|
|||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
referenced_by = None
|
resource_of = None
|
||||||
if self.settings["relating_resource"].ResourceOf:
|
if self.settings["relating_resource"].ResourceOf:
|
||||||
referenced_by = self.settings["relating_resource"].ResourceOf[0]
|
resource_of = self.settings["relating_resource"].ResourceOf[0]
|
||||||
|
|
||||||
if referenced_by:
|
if resource_of:
|
||||||
related_objects = list(referenced_by.RelatedObjects)
|
related_objects = list(resource_of.RelatedObjects)
|
||||||
related_objects.append(self.settings["related_object"])
|
related_objects.append(self.settings["related_object"])
|
||||||
referenced_by.RelatedObjects = related_objects
|
resource_of.RelatedObjects = related_objects
|
||||||
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": referenced_by})
|
ifcopenshell.api.run("owner.update_owner_history", self.file, **{"element": resource_of})
|
||||||
else:
|
else:
|
||||||
referenced_by = self.file.create_entity(
|
resource_of = self.file.create_entity(
|
||||||
"IfcRelAssignsToResource",
|
"IfcRelAssignsToResource",
|
||||||
**{
|
**{
|
||||||
"GlobalId": ifcopenshell.guid.new(),
|
"GlobalId": ifcopenshell.guid.new(),
|
||||||
@@ -40,4 +40,4 @@ class Usecase:
|
|||||||
"RelatingProduct": self.settings["relating_resource"],
|
"RelatingProduct": self.settings["relating_resource"],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return referenced_by
|
return resource_of
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
import ifcopenshell.api
|
|
||||||
|
|
||||||
|
|
||||||
class Data:
|
class Data:
|
||||||
is_loaded = False
|
is_loaded = False
|
||||||
resources = {}
|
resources = {}
|
||||||
@@ -17,6 +14,7 @@ class Data:
|
|||||||
del data["OwnerHistory"]
|
del data["OwnerHistory"]
|
||||||
data["RelatedObjects"] = []
|
data["RelatedObjects"] = []
|
||||||
for rel in resource.IsNestedBy:
|
for rel in resource.IsNestedBy:
|
||||||
[data["RelatedObjects"].append(o.id()) for o in rel.RelatedObjects if o.is_a("IfcCrewResource") or o.is_a("IfcsubcontractResource")]
|
[data["RelatedObjects"].append(o.id()) for o in rel.RelatedObjects]
|
||||||
|
data["HasContext"] = resource.HasContext[0].RelatingContext.id() if resource.HasContext else None
|
||||||
cls.resources[resource.id()] = data
|
cls.resources[resource.id()] = data
|
||||||
cls.is_loaded=True
|
cls.is_loaded=True
|
||||||
|
|||||||
Reference in New Issue
Block a user