WIP refactor root module properties. See #1222.

This commit is contained in:
Dion Moult
2021-01-23 12:54:27 +11:00
parent d1e2ac4c5a
commit 86e3d1e548
8 changed files with 138 additions and 111 deletions
@@ -1,5 +1,5 @@
import bpy
from . import ui, operator
from . import ui, prop, operator
classes = (
operator.EnableReassignClass,
@@ -7,13 +7,14 @@ classes = (
operator.ReassignClass,
operator.AssignClass,
operator.UnassignClass,
prop.BIMRootProperties,
ui.BIM_PT_class,
)
def register():
pass
bpy.types.Scene.BIMRootProperties = bpy.props.PointerProperty(type=prop.BIMRootProperties)
def unregister():
pass
del bpy.types.Scene.BIMRootProperties
@@ -14,6 +14,7 @@ class EnableReassignClass(bpy.types.Operator):
def execute(self, context):
obj = bpy.context.active_object
self.file = IfcStore.get_file()
ifc_class = obj.name.split("/")[0]
bpy.context.active_object.BIMObjectProperties.is_reassigning_class = True
ifc_products = [
@@ -28,11 +29,11 @@ class EnableReassignClass(bpy.types.Operator):
]
for ifc_product in ifc_products:
if ifcopenshell.util.schema.is_a(IfcStore.get_schema().declaration_by_name(ifc_class), ifc_product):
bpy.context.scene.BIMProperties.ifc_product = ifc_product
bpy.context.scene.BIMProperties.ifc_class = obj.name.split("/")[0]
predefined_type = obj.BIMObjectProperties.attributes.get("PredefinedType")
if predefined_type:
bpy.context.scene.BIMProperties.ifc_predefined_type = predefined_type.string_value
bpy.context.scene.BIMRootProperties.ifc_product = ifc_product
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
bpy.context.scene.BIMRootProperties.ifc_class = element.is_a()
if hasattr(element, "PredefinedType") and element.PredefinedType:
bpy.context.scene.BIMRootProperties.ifc_predefined_type = element.PredefinedType
return {"FINISHED"}
@@ -52,14 +53,14 @@ class ReassignClass(bpy.types.Operator):
def execute(self, context):
obj = bpy.context.active_object
self.file = IfcStore.get_file()
predefined_type = bpy.context.scene.BIMProperties.ifc_predefined_type
predefined_type = bpy.context.scene.BIMRootProperties.ifc_predefined_type
if predefined_type == "USERDEFINED":
predefined_type = bpy.context.scene.BIMProperties.ifc_userdefined_type
predefined_type = bpy.context.scene.BIMRootProperties.ifc_userdefined_type
product = reassign_class.Usecase(
self.file,
{
"product": self.file.by_id(obj.BIMObjectProperties.ifc_definition_id),
"ifc_class": bpy.context.scene.BIMProperties.ifc_class,
"ifc_class": bpy.context.scene.BIMRootProperties.ifc_class,
"predefined_type": predefined_type,
},
).execute()
@@ -0,0 +1,94 @@
import bpy
from blenderbim.bim.ifc import IfcStore
from bpy.types import PropertyGroup
from bpy.props import (
PointerProperty,
StringProperty,
EnumProperty,
BoolProperty,
IntProperty,
FloatProperty,
FloatVectorProperty,
CollectionProperty,
)
products_enum = []
classes_enum = []
types_enum = []
def getIfcPredefinedTypes(self, context):
global types_enum
file = IfcStore.get_file()
if len(types_enum) < 1 and file:
declaration = IfcStore.get_schema().declaration_by_name(self.ifc_class)
for attribute in declaration.attributes():
if attribute.name() == "PredefinedType":
types_enum.extend(
[(e, e, "") for e in attribute.type_of_attribute().declared_type().enumeration_items()]
)
break
return types_enum
def refreshClasses(self, context):
global classes_enum
classes_enum.clear()
enum = getIfcClasses(self, context)
context.scene.BIMRootProperties.ifc_class = enum[0][0]
def refreshPredefinedTypes(self, context):
global types_enum
types_enum.clear()
enum = getIfcPredefinedTypes(self, context)
context.scene.BIMRootProperties.ifc_predefined_type = enum[0][0]
def getIfcProducts(self, context):
global products_enum
file = IfcStore.get_file()
if len(products_enum) < 1:
products_enum.extend(
[
(e, e, "")
for e in [
"IfcElement",
"IfcElementType",
"IfcSpatialElement",
"IfcGroup",
"IfcStructuralItem",
"IfcContext",
"IfcAnnotation",
]
]
)
if file.schema == "IFC2X3":
products_enum[2] = ("IfcSpatialStructureElement", "IfcSpatialStructureElement", "")
return products_enum
def getIfcClasses(self, context):
global classes_enum
file = IfcStore.get_file()
if len(classes_enum) < 1 and file:
declaration = IfcStore.get_schema().declaration_by_name(self.ifc_product)
def get_classes(declaration):
results = []
if not declaration.is_abstract():
results.append(declaration.name())
for subtype in declaration.subtypes():
results.extend(get_classes(subtype))
return results
classes = get_classes(declaration)
classes_enum.extend([(c, c, "") for c in sorted(classes)])
return classes_enum
class BIMRootProperties(PropertyGroup):
ifc_product: EnumProperty(items=getIfcProducts, name="Products", update=refreshClasses)
ifc_class: EnumProperty(items=getIfcClasses, name="Class", update=refreshPredefinedTypes)
ifc_predefined_type: EnumProperty(items=getIfcPredefinedTypes, name="Predefined Type", default=None)
ifc_userdefined_type: StringProperty(name="Userdefined Type")
@@ -41,12 +41,12 @@ class BIM_PT_class(Panel):
row = self.layout.row(align=True)
op = row.operator("bim.assign_class")
op.obj = context.active_object.name
op.ifc_class = bpy.context.scene.BIMProperties.ifc_class
op.predefined_type = bpy.context.scene.BIMProperties.ifc_predefined_type
op.userdefined_type = bpy.context.scene.BIMProperties.ifc_userdefined_type
op.ifc_class = bpy.context.scene.BIMRootProperties.ifc_class
op.predefined_type = bpy.context.scene.BIMRootProperties.ifc_predefined_type
op.userdefined_type = bpy.context.scene.BIMRootProperties.ifc_userdefined_type
def draw_class_dropdowns(self):
props = bpy.context.scene.BIMProperties
props = bpy.context.scene.BIMRootProperties
row = self.layout.row()
row.prop(props, "ifc_product")
row = self.layout.row()