Fix #6310. See #1227. Fix regression with layer ordering.

This commit is contained in:
Dion Moult
2025-03-16 14:17:37 +11:00
parent ed48afc633
commit ba37754068
3 changed files with 29 additions and 26 deletions
+12 -2
View File
@@ -244,8 +244,6 @@ class ObjectMaterialData:
items = [] items = []
if cls.material.is_a("IfcMaterialLayerSetUsage"): if cls.material.is_a("IfcMaterialLayerSetUsage"):
items = cls.material.ForLayerSet.MaterialLayers items = cls.material.ForLayerSet.MaterialLayers
if cls.material.DirectionSense == "POSITIVE":
items = reversed(items)
elif cls.material.is_a("IfcMaterialProfileSetUsage"): elif cls.material.is_a("IfcMaterialProfileSetUsage"):
items = cls.material.ForProfileSet.MaterialProfiles items = cls.material.ForProfileSet.MaterialProfiles
elif cls.material.is_a("IfcMaterialLayerSet"): elif cls.material.is_a("IfcMaterialLayerSet"):
@@ -300,6 +298,18 @@ class ObjectMaterialData:
else: else:
data["material"] = item.Material.Name or "Unnamed" data["material"] = item.Material.Name or "Unnamed"
results.append(data) results.append(data)
should_reverse = cls.material.DirectionSense == "POSITIVE"
last_i = len(results) - 1
for i, result in enumerate(results):
result["index"] = i
if should_reverse:
result["index_up"] = i + 1 if i != last_i else None
result["index_down"] = i - 1 if i != 0 else None
else:
result["index_down"] = i + 1 if i != last_i else None
result["index_up"] = i - 1 if i != 0 else None
if should_reverse:
return list(reversed(results))
return results return results
@classmethod @classmethod
@@ -382,7 +382,7 @@ class AddLayer(bpy.types.Operator, tool.Ifc.Operator):
class ReorderMaterialSetItem(bpy.types.Operator, tool.Ifc.Operator): class ReorderMaterialSetItem(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.reorder_material_set_item" bl_idname = "bim.reorder_material_set_item"
bl_label = "Reorder Material Set Item" bl_label = "Reorder Material Set Item"
bl_description = "The List is Ordered From Origin Point" bl_description = "Change the order of materials"
bl_options = {"REGISTER", "UNDO"} bl_options = {"REGISTER", "UNDO"}
obj: bpy.props.StringProperty() obj: bpy.props.StringProperty()
old_index: bpy.props.IntProperty() old_index: bpy.props.IntProperty()
@@ -390,17 +390,12 @@ class ReorderMaterialSetItem(bpy.types.Operator, tool.Ifc.Operator):
material_set: bpy.props.IntProperty() material_set: bpy.props.IntProperty()
def _execute(self, context): def _execute(self, context):
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
self.file = tool.Ifc.get() self.file = tool.Ifc.get()
material_set = self.file.by_id(self.material_set) ifcopenshell.api.material.reorder_set_item(
ifcopenshell.api.run(
"material.reorder_set_item",
self.file, self.file,
**{ material_set=self.file.by_id(self.material_set),
"material_set": material_set, old_index=self.old_index,
"old_index": self.old_index, new_index=self.new_index,
"new_index": self.new_index,
},
) )
+12 -14
View File
@@ -253,7 +253,7 @@ class BIM_PT_object_material(Panel):
active_object = bpy.context.active_object active_object = bpy.context.active_object
self.layerset_bounds(box, active_object, location="Top_Exterior") self.layerset_bounds(box, active_object, location="Top_Exterior")
for index, set_item in enumerate(ObjectMaterialData.data["set_items"]): for set_item in ObjectMaterialData.data["set_items"]:
if ( if (
len(self.props.material_set_item_profile_attributes) len(self.props.material_set_item_profile_attributes)
and self.props.active_material_set_item_id == set_item["id"] and self.props.active_material_set_item_id == set_item["id"]
@@ -262,9 +262,7 @@ class BIM_PT_object_material(Panel):
elif self.props.active_material_set_item_id == set_item["id"]: elif self.props.active_material_set_item_id == set_item["id"]:
self.draw_editable_set_item_ui(box, set_item) self.draw_editable_set_item_ui(box, set_item)
else: else:
self.draw_read_only_set_item_ui( self.draw_read_only_set_item_ui(box, set_item)
box, set_item, index, is_first=index == 0, is_last=index == total_items - 1
)
self.layerset_bounds(box, active_object, location="Bottom_Interior") self.layerset_bounds(box, active_object, location="Bottom_Interior")
@@ -291,7 +289,7 @@ class BIM_PT_object_material(Panel):
row = box.row() row = box.row()
prop_with_search(row, self.mprops, "profiles", icon="ITALIC", text="Profile") prop_with_search(row, self.mprops, "profiles", icon="ITALIC", text="Profile")
def draw_read_only_set_item_ui(self, box, set_item, index, is_first=False, is_last=False): def draw_read_only_set_item_ui(self, box, set_item):
if ObjectMaterialData.data["material_class"] == "IfcMaterialList": if ObjectMaterialData.data["material_class"] == "IfcMaterialList":
row = box.row(align=True) row = box.row(align=True)
row.label(text="IfcMaterial", icon="LAYER_ACTIVE") row.label(text="IfcMaterial", icon="LAYER_ACTIVE")
@@ -301,15 +299,15 @@ class BIM_PT_object_material(Panel):
row.label(text=set_item["name"], icon=set_item["icon"]) row.label(text=set_item["name"], icon=set_item["icon"])
row.label(text=set_item["material"], icon="MATERIAL") row.label(text=set_item["material"], icon="MATERIAL")
if not is_first: if set_item["index_up"] is not None:
op = row.operator(f"bim.reorder_material_set_item", icon="TRIA_UP", text="") op = row.operator("bim.reorder_material_set_item", icon="TRIA_UP", text="")
op.old_index = index op.old_index = set_item["index"]
op.new_index = index - 1 op.new_index = set_item["index_up"]
setattr(op, "material_set", ObjectMaterialData.data["set"]["id"]) setattr(op, "material_set", ObjectMaterialData.data["set"]["id"])
if not is_last: if set_item["index_down"] is not None:
op = row.operator(f"bim.reorder_material_set_item", icon="TRIA_DOWN", text="") op = row.operator("bim.reorder_material_set_item", icon="TRIA_DOWN", text="")
op.old_index = index op.old_index = set_item["index"]
op.new_index = index + 1 op.new_index = set_item["index_down"]
setattr(op, "material_set", ObjectMaterialData.data["set"]["id"]) setattr(op, "material_set", ObjectMaterialData.data["set"]["id"])
if ( if (
not self.props.active_material_set_item_id not self.props.active_material_set_item_id
@@ -329,7 +327,7 @@ class BIM_PT_object_material(Panel):
setattr(op, "list_item_set", ObjectMaterialData.data["set"]["id"]) setattr(op, "list_item_set", ObjectMaterialData.data["set"]["id"])
setattr(op, ObjectMaterialData.data["set_item_name"], set_item["id"]) setattr(op, ObjectMaterialData.data["set_item_name"], set_item["id"])
if hasattr(op, f"{ObjectMaterialData.data['set_item_name']}_index"): if hasattr(op, f"{ObjectMaterialData.data['set_item_name']}_index"):
setattr(op, f"{ObjectMaterialData.data['set_item_name']}_index", index) setattr(op, f"{ObjectMaterialData.data['set_item_name']}_index", set_item["index"])
def draw_read_only_set_ui(self): def draw_read_only_set_ui(self):
if ObjectMaterialData.data["material_class"] != "IfcMaterialList": if ObjectMaterialData.data["material_class"] != "IfcMaterialList":