mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-28 11:18:18 +00:00
#2099. Materials are now sorted alphabetically.
This commit is contained in:
@@ -25,6 +25,7 @@ import blenderbim.tool as tool
|
|||||||
|
|
||||||
def refresh():
|
def refresh():
|
||||||
MaterialsData.is_loaded = False
|
MaterialsData.is_loaded = False
|
||||||
|
ObjectMaterialData.is_loaded = False
|
||||||
|
|
||||||
|
|
||||||
class MaterialsData:
|
class MaterialsData:
|
||||||
@@ -67,3 +68,19 @@ class MaterialsData:
|
|||||||
if tool.Ifc.get_schema() == "IFC2X3":
|
if tool.Ifc.get_schema() == "IFC2X3":
|
||||||
material_types = ["IfcMaterial", "IfcMaterialLayerSet", "IfcMaterialList"]
|
material_types = ["IfcMaterial", "IfcMaterialLayerSet", "IfcMaterialList"]
|
||||||
return [(m, m, "") for m in material_types]
|
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
|
import bpy
|
||||||
from ifcopenshell.api.material.data import Data
|
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.ifc import IfcStore
|
||||||
from blenderbim.bim.prop import StrProperty, Attribute
|
from blenderbim.bim.prop import StrProperty, Attribute
|
||||||
from bpy.types import PropertyGroup
|
from bpy.types import PropertyGroup
|
||||||
@@ -33,18 +33,15 @@ from bpy.props import (
|
|||||||
CollectionProperty,
|
CollectionProperty,
|
||||||
)
|
)
|
||||||
|
|
||||||
materials_enum = []
|
|
||||||
materialtypes_enum = []
|
materialtypes_enum = []
|
||||||
profileclasses_enum = []
|
profileclasses_enum = []
|
||||||
parameterizedprofileclasses_enum = []
|
parameterizedprofileclasses_enum = []
|
||||||
|
|
||||||
|
|
||||||
def purge():
|
def purge():
|
||||||
global materials_enum
|
|
||||||
global materialtypes_enum
|
global materialtypes_enum
|
||||||
global profileclasses_enum
|
global profileclasses_enum
|
||||||
global parameterizedprofileclasses_enum
|
global parameterizedprofileclasses_enum
|
||||||
materials_enum = []
|
|
||||||
materialtypes_enum = []
|
materialtypes_enum = []
|
||||||
profileclasses_enum = []
|
profileclasses_enum = []
|
||||||
parameterizedprofileclasses_enum = []
|
parameterizedprofileclasses_enum = []
|
||||||
@@ -78,12 +75,10 @@ def getParameterizedProfileClasses(self, context):
|
|||||||
return parameterizedprofileclasses_enum
|
return parameterizedprofileclasses_enum
|
||||||
|
|
||||||
|
|
||||||
def getMaterials(self, context):
|
def get_materials(self, context):
|
||||||
global materials_enum
|
if not ObjectMaterialData.is_loaded:
|
||||||
if len(materials_enum) == 0 and IfcStore.get_file():
|
ObjectMaterialData.load()
|
||||||
materials_enum.clear()
|
return ObjectMaterialData.data["materials"]
|
||||||
materials_enum = [(str(m_id), m["Name"], "") for m_id, m in Data.materials.items()]
|
|
||||||
return materials_enum
|
|
||||||
|
|
||||||
|
|
||||||
def getMaterialTypes(self, context):
|
def getMaterialTypes(self, context):
|
||||||
@@ -126,7 +121,7 @@ class BIMMaterialProperties(PropertyGroup):
|
|||||||
|
|
||||||
class BIMObjectMaterialProperties(PropertyGroup):
|
class BIMObjectMaterialProperties(PropertyGroup):
|
||||||
material_type: EnumProperty(items=getMaterialTypes, name="Material Type")
|
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)
|
is_editing: BoolProperty(name="Is Editing", default=False)
|
||||||
material_set_usage_attributes: CollectionProperty(name="Material Set Usage Attributes", type=Attribute)
|
material_set_usage_attributes: CollectionProperty(name="Material Set Usage Attributes", type=Attribute)
|
||||||
material_set_attributes: CollectionProperty(name="Material Set 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(
|
material_set_item_profile_attributes: CollectionProperty(
|
||||||
name="Material Set Item Profile Attributes", type=Attribute
|
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")
|
profile_classes: EnumProperty(items=getProfileClasses, name="Profile Classes")
|
||||||
parameterized_profile_classes: EnumProperty(
|
parameterized_profile_classes: EnumProperty(
|
||||||
items=getParameterizedProfileClasses, name="Parameterized Profile Classes"
|
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 ifcopenshell.api.profile.data import Data as ProfileData
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from blenderbim.bim.helper import draw_attributes
|
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):
|
class BIM_PT_materials(Panel):
|
||||||
@@ -119,6 +119,9 @@ class BIM_PT_object_material(Panel):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
|
if not ObjectMaterialData.is_loaded:
|
||||||
|
ObjectMaterialData.load()
|
||||||
|
|
||||||
self.file = IfcStore.get_file()
|
self.file = IfcStore.get_file()
|
||||||
self.oprops = context.active_object.BIMObjectProperties
|
self.oprops = context.active_object.BIMObjectProperties
|
||||||
self.props = context.active_object.BIMObjectMaterialProperties
|
self.props = context.active_object.BIMObjectMaterialProperties
|
||||||
@@ -130,7 +133,7 @@ class BIM_PT_object_material(Panel):
|
|||||||
ProfileData.load(self.file)
|
ProfileData.load(self.file)
|
||||||
self.product_data = Data.products[self.oprops.ifc_definition_id]
|
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 = self.layout.row(align=True)
|
||||||
row.label(text="No Materials Available")
|
row.label(text="No Materials Available")
|
||||||
row.operator("bim.add_material", icon="ADD", text="").obj = ""
|
row.operator("bim.add_material", icon="ADD", text="").obj = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user