#2099. Materials are now sorted alphabetically.

This commit is contained in:
Dion Moult
2022-03-22 14:30:45 +11:00
parent 0bba31e5f9
commit 533111a1fb
3 changed files with 29 additions and 14 deletions
@@ -25,6 +25,7 @@ import blenderbim.tool as tool
def refresh():
MaterialsData.is_loaded = False
ObjectMaterialData.is_loaded = False
class MaterialsData:
@@ -67,3 +68,19 @@ class MaterialsData:
if tool.Ifc.get_schema() == "IFC2X3":
material_types = ["IfcMaterial", "IfcMaterialLayerSet", "IfcMaterialList"]
return [(m, m, "") for m in material_types]
class ObjectMaterialData:
data = {}
is_loaded = False
@classmethod
def load(cls):
cls.data = {
"materials": cls.materials(),
}
cls.is_loaded = True
@classmethod
def materials(cls):
return sorted([(str(m.id()), m.Name or "Unnamed", "") for m in tool.Ifc.get().by_type("IfcMaterial")], key=lambda x: x[1])
@@ -18,7 +18,7 @@
import bpy
from ifcopenshell.api.material.data import Data
from blenderbim.bim.module.material.data import MaterialsData
from blenderbim.bim.module.material.data import MaterialsData, ObjectMaterialData
from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.prop import StrProperty, Attribute
from bpy.types import PropertyGroup
@@ -33,18 +33,15 @@ from bpy.props import (
CollectionProperty,
)
materials_enum = []
materialtypes_enum = []
profileclasses_enum = []
parameterizedprofileclasses_enum = []
def purge():
global materials_enum
global materialtypes_enum
global profileclasses_enum
global parameterizedprofileclasses_enum
materials_enum = []
materialtypes_enum = []
profileclasses_enum = []
parameterizedprofileclasses_enum = []
@@ -78,12 +75,10 @@ def getParameterizedProfileClasses(self, context):
return parameterizedprofileclasses_enum
def getMaterials(self, context):
global materials_enum
if len(materials_enum) == 0 and IfcStore.get_file():
materials_enum.clear()
materials_enum = [(str(m_id), m["Name"], "") for m_id, m in Data.materials.items()]
return materials_enum
def get_materials(self, context):
if not ObjectMaterialData.is_loaded:
ObjectMaterialData.load()
return ObjectMaterialData.data["materials"]
def getMaterialTypes(self, context):
@@ -126,7 +121,7 @@ class BIMMaterialProperties(PropertyGroup):
class BIMObjectMaterialProperties(PropertyGroup):
material_type: EnumProperty(items=getMaterialTypes, name="Material Type")
material: EnumProperty(items=getMaterials, name="Material")
material: EnumProperty(items=get_materials, name="Material")
is_editing: BoolProperty(name="Is Editing", default=False)
material_set_usage_attributes: CollectionProperty(name="Material Set Usage Attributes", type=Attribute)
material_set_attributes: CollectionProperty(name="Material Set Attributes", type=Attribute)
@@ -135,7 +130,7 @@ class BIMObjectMaterialProperties(PropertyGroup):
material_set_item_profile_attributes: CollectionProperty(
name="Material Set Item Profile Attributes", type=Attribute
)
material_set_item_material: EnumProperty(items=getMaterials, name="Material")
material_set_item_material: EnumProperty(items=get_materials, name="Material")
profile_classes: EnumProperty(items=getProfileClasses, name="Profile Classes")
parameterized_profile_classes: EnumProperty(
items=getParameterizedProfileClasses, name="Parameterized Profile Classes"
@@ -22,7 +22,7 @@ from ifcopenshell.api.material.data import Data
from ifcopenshell.api.profile.data import Data as ProfileData
from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.helper import draw_attributes
from blenderbim.bim.module.material.data import MaterialsData
from blenderbim.bim.module.material.data import MaterialsData, ObjectMaterialData
class BIM_PT_materials(Panel):
@@ -119,6 +119,9 @@ class BIM_PT_object_material(Panel):
return True
def draw(self, context):
if not ObjectMaterialData.is_loaded:
ObjectMaterialData.load()
self.file = IfcStore.get_file()
self.oprops = context.active_object.BIMObjectProperties
self.props = context.active_object.BIMObjectMaterialProperties
@@ -130,7 +133,7 @@ class BIM_PT_object_material(Panel):
ProfileData.load(self.file)
self.product_data = Data.products[self.oprops.ifc_definition_id]
if not Data.materials:
if not ObjectMaterialData.data["materials"]:
row = self.layout.row(align=True)
row.label(text="No Materials Available")
row.operator("bim.add_material", icon="ADD", text="").obj = ""