deprecate some prop.purge

This commit is contained in:
Andrej730
2024-11-01 14:10:07 +05:00
parent 0944f8a7cb
commit 1acf8f1ed8
6 changed files with 56 additions and 79 deletions
@@ -47,14 +47,11 @@ from bpy.props import (
diagram_scales_enum = [] diagram_scales_enum = []
sheets_enum = []
def purge(): def purge():
global diagram_scales_enum global diagram_scales_enum
global sheets_enum
diagram_scales_enum = [] diagram_scales_enum = []
sheets_enum = []
def update_target_view(self, context): def update_target_view(self, context):
@@ -28,7 +28,6 @@ import bonsai.tool as tool
import bonsai.core.style import bonsai.core.style
import bonsai.core.material as core import bonsai.core.material as core
import bonsai.bim.module.model.profile as model_profile import bonsai.bim.module.model.profile as model_profile
from bonsai.bim.module.material.prop import purge as material_prop_purge
from bonsai.bim.ifc import IfcStore from bonsai.bim.ifc import IfcStore
from typing import Any, Union from typing import Any, Union
@@ -143,7 +142,6 @@ class AddMaterial(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context): def _execute(self, context):
core.add_material(tool.Ifc, tool.Material, name=self.name, category=self.category, description=self.description) core.add_material(tool.Ifc, tool.Material, name=self.name, category=self.category, description=self.description)
material_prop_purge()
class DuplicateMaterial(bpy.types.Operator, tool.Ifc.Operator): class DuplicateMaterial(bpy.types.Operator, tool.Ifc.Operator):
@@ -155,7 +153,6 @@ class DuplicateMaterial(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context): def _execute(self, context):
material = tool.Ifc.get().by_id(self.material) material = tool.Ifc.get().by_id(self.material)
tool.Material.duplicate_material(material) tool.Material.duplicate_material(material)
material_prop_purge()
bpy.ops.bim.load_materials() bpy.ops.bim.load_materials()
@@ -168,7 +165,6 @@ class AddMaterialSet(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context): def _execute(self, context):
core.add_material_set(tool.Ifc, tool.Material, set_type=self.set_type) core.add_material_set(tool.Ifc, tool.Material, set_type=self.set_type)
material_prop_purge()
class RemoveMaterial(bpy.types.Operator, tool.Ifc.Operator): class RemoveMaterial(bpy.types.Operator, tool.Ifc.Operator):
+7 -40
View File
@@ -20,6 +20,7 @@ import bpy
from ifcopenshell.util.doc import get_entity_doc from ifcopenshell.util.doc import get_entity_doc
import bonsai.tool as tool import bonsai.tool as tool
from bonsai.bim.module.material.data import MaterialsData, ObjectMaterialData from bonsai.bim.module.material.data import MaterialsData, ObjectMaterialData
from bonsai.bim.module.profile.data import ProfileData
from bonsai.bim.ifc import IfcStore from bonsai.bim.ifc import IfcStore
from bonsai.bim.prop import StrProperty, Attribute from bonsai.bim.prop import StrProperty, Attribute
from bpy.types import PropertyGroup from bpy.types import PropertyGroup
@@ -34,51 +35,17 @@ from bpy.props import (
CollectionProperty, CollectionProperty,
) )
materialtypes_enum = []
profileclasses_enum = []
parameterizedprofileclasses_enum = []
def purge():
global materialtypes_enum
global profileclasses_enum
global parameterizedprofileclasses_enum
materialtypes_enum = []
profileclasses_enum = []
parameterizedprofileclasses_enum = []
# TODO: unsafe?
def get_profile_classes(self, context): def get_profile_classes(self, context):
global profileclasses_enum if not ProfileData.is_loaded:
if len(profileclasses_enum) == 0 and IfcStore.get_schema(): ProfileData.load()
version = tool.Ifc.get_schema() return ProfileData.data["profile_def_classes_enum"]
profileclasses_enum.clear()
profileclasses_enum = [
(t.name(), t.name(), get_entity_doc(version, t.name()).get("description", ""))
for t in IfcStore.get_schema().declaration_by_name("IfcProfileDef").subtypes()
]
return profileclasses_enum
# TODO: unsafe?
def get_parameterized_profile_classes(self, context): def get_parameterized_profile_classes(self, context):
global parameterizedprofileclasses_enum if not ProfileData.is_loaded:
if len(parameterizedprofileclasses_enum) == 0 and IfcStore.get_schema(): ProfileData.load()
version = tool.Ifc.get_schema() return ProfileData.data["profile_classes"]
parameterizedprofileclasses_enum.clear()
parameterizedprofileclasses_enum = [
(t.name(), t.name(), get_entity_doc(version, t.name()).get("description", ""))
for t in IfcStore.get_schema().declaration_by_name("IfcParameterizedProfileDef").subtypes()
]
for ifc_class in parameterizedprofileclasses_enum:
parameterizedprofileclasses_enum.extend(
[
(t.name(), t.name(), get_entity_doc(version, t.name()).get("description", ""))
for t in IfcStore.get_schema().declaration_by_name(ifc_class[0]).subtypes() or []
]
)
return parameterizedprofileclasses_enum
def get_materials(self, context): def get_materials(self, context):
@@ -41,6 +41,7 @@ class ProfileData:
"profile_classes": cls.profile_classes(), "profile_classes": cls.profile_classes(),
"is_arbitrary_profile": cls.is_arbitrary_profile(), "is_arbitrary_profile": cls.is_arbitrary_profile(),
"is_editing_arbitrary_profile": cls.is_editing_arbitrary_profile(), "is_editing_arbitrary_profile": cls.is_editing_arbitrary_profile(),
"profile_def_classes_enum": cls.profile_def_classes_enum(),
} }
cls.is_loaded = True cls.is_loaded = True
@@ -72,6 +73,14 @@ class ProfileData:
for c in sorted(classes) for c in sorted(classes)
] ]
@classmethod
def profile_def_classes_enum(cls) -> list[tuple[str, str, str]]:
version = tool.Ifc.get_schema()
return [
(t.name(), t.name(), ifcopenshell.util.doc.get_entity_doc(version, t.name()).get("description", ""))
for t in tool.Ifc.schema().declaration_by_name("IfcProfileDef").subtypes()
]
@classmethod @classmethod
def is_arbitrary_profile(cls): def is_arbitrary_profile(cls):
props = bpy.context.scene.BIMProfileProperties props = bpy.context.scene.BIMProfileProperties
@@ -45,6 +45,8 @@ class SequenceData:
"has_work_schedules": cls.has_work_schedules(), "has_work_schedules": cls.has_work_schedules(),
"has_work_calendars": cls.has_work_calendars(), "has_work_calendars": cls.has_work_calendars(),
"schedule_predefined_types_enum": cls.schedule_predefined_types_enum(), "schedule_predefined_types_enum": cls.schedule_predefined_types_enum(),
"task_columns_enum": cls.task_columns_enum(),
"tasktimecolumns_enum": cls.tasktimecolumns_enum(),
} }
cls.load_work_plans() cls.load_work_plans()
cls.load_work_schedules() cls.load_work_schedules()
@@ -259,6 +261,38 @@ class SequenceData:
break break
return results return results
@classmethod
def task_columns_enum(cls) -> list[tuple[str, str, str]]:
schema = tool.Ifc.schema()
taskcolumns_enum = []
for a in schema.declaration_by_name("IfcTask").all_attributes():
if (primitive_type := ifcopenshell.util.attribute.get_primitive_type(a)) not in (
"string",
"float",
"integer",
"boolean",
"enum",
):
continue
schema.append((f"{a.name()}/{primitive_type}", a.name(), ""))
return taskcolumns_enum
@classmethod
def tasktimecolumns_enum(cls) -> list[tuple[str, str, str]]:
schema = tool.Ifc.schema()
tasktimecolumns_enum = []
for a in schema.declaration_by_name("IfcTaskTime").all_attributes():
if (primitive_type := ifcopenshell.util.attribute.get_primitive_type(a)) not in (
"string",
"float",
"integer",
"boolean",
"enum",
):
continue
schema.append((f"{a.name()}/{primitive_type}", a.name(), ""))
return tasktimecolumns_enum
class WorkScheduleData: class WorkScheduleData:
data = {} data = {}
+6 -32
View File
@@ -41,43 +41,17 @@ from bpy.props import (
CollectionProperty, CollectionProperty,
) )
taskcolumns_enum = []
tasktimecolumns_enum = []
def purge():
global taskcolumns_enum
global tasktimecolumns_enum
taskcolumns_enum = []
tasktimecolumns_enum = []
def getTaskColumns(self, context): def getTaskColumns(self, context):
global taskcolumns_enum if not SequenceData.is_loaded:
if not len(taskcolumns_enum) and IfcStore.get_schema(): SequenceData.load()
taskcolumns_enum.extend( return SequenceData.data["taskcolumns_enum"]
[
(a.name() + "/" + ifcopenshell.util.attribute.get_primitive_type(a), a.name(), "")
for a in IfcStore.get_schema().declaration_by_name("IfcTask").all_attributes()
if ifcopenshell.util.attribute.get_primitive_type(a)
in ["string", "float", "integer", "boolean", "enum"]
]
)
return taskcolumns_enum
def getTaskTimeColumns(self, context): def getTaskTimeColumns(self, context):
global tasktimecolumns_enum if not SequenceData.is_loaded:
if not len(tasktimecolumns_enum) and IfcStore.get_schema(): SequenceData.load()
tasktimecolumns_enum.extend( return SequenceData.data["tasktimecolumns_enum"]
[
(a.name() + "/" + ifcopenshell.util.attribute.get_primitive_type(a), a.name(), "")
for a in IfcStore.get_schema().declaration_by_name("IfcTaskTime").all_attributes()
if ifcopenshell.util.attribute.get_primitive_type(a)
in ["string", "float", "integer", "boolean", "enum"]
]
)
return tasktimecolumns_enum
def getWorkSchedules(self, context): def getWorkSchedules(self, context):