mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
WIP implement add/remove material. See #1222.
This commit is contained in:
@@ -2,6 +2,8 @@ import bpy
|
||||
from . import ui, prop, operator
|
||||
|
||||
classes = (
|
||||
operator.AddMaterial,
|
||||
operator.RemoveMaterial,
|
||||
operator.AssignMaterial,
|
||||
operator.UnassignMaterial,
|
||||
operator.AddConstituent,
|
||||
@@ -17,6 +19,7 @@ classes = (
|
||||
operator.DisableEditingMaterialSetItem,
|
||||
operator.EditMaterialSetItem,
|
||||
prop.BIMObjectMaterialProperties,
|
||||
ui.BIM_PT_material,
|
||||
ui.BIM_PT_object_material,
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import ifcopenshell
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, settings=None):
|
||||
self.file = file
|
||||
self.settings = {"Name": "Unnamed"}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
return self.file.create_entity("IfcMaterial", **{"Name": self.settings["Name"] or "Unnamed"})
|
||||
@@ -1,4 +1,6 @@
|
||||
import bpy
|
||||
import blenderbim.bim.module.material.add_material as add_material
|
||||
import blenderbim.bim.module.material.remove_material as remove_material
|
||||
import blenderbim.bim.module.material.assign_material as assign_material
|
||||
import blenderbim.bim.module.material.unassign_material as unassign_material
|
||||
import blenderbim.bim.module.material.add_constituent as add_constituent
|
||||
@@ -13,6 +15,34 @@ from blenderbim.bim.ifc import IfcStore
|
||||
from blenderbim.bim.module.material.data import Data
|
||||
|
||||
|
||||
class AddMaterial(bpy.types.Operator):
|
||||
bl_idname = "bim.add_material"
|
||||
bl_label = "Add Material"
|
||||
obj: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
obj = bpy.data.materials.get(self.obj) if self.obj else bpy.context.active_object.active_material
|
||||
self.file = IfcStore.get_file()
|
||||
result = add_material.Usecase(self.file, {"Name": obj.name}).execute()
|
||||
obj.BIMObjectProperties.ifc_definition_id = result.id()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class RemoveMaterial(bpy.types.Operator):
|
||||
bl_idname = "bim.remove_material"
|
||||
bl_label = "Remove Material"
|
||||
obj: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
obj = bpy.data.materials.get(self.obj) if self.obj else bpy.context.active_object.active_material
|
||||
self.file = IfcStore.get_file()
|
||||
result = remove_material.Usecase(
|
||||
self.file, {"material": self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)}
|
||||
).execute()
|
||||
obj.BIMObjectProperties.ifc_definition_id = 0
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class AssignMaterial(bpy.types.Operator):
|
||||
bl_idname = "bim.assign_material"
|
||||
bl_label = "Assign Material"
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import ifcopenshell
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, settings=None):
|
||||
self.file = file
|
||||
self.settings = {"material": None}
|
||||
for key, value in settings.items():
|
||||
self.settings[key] = value
|
||||
|
||||
def execute(self):
|
||||
inverse_elements = self.file.get_inverse(self.settings["material"])
|
||||
self.file.remove(self.settings["material"])
|
||||
# TODO: this is probably not robust enough
|
||||
for inverse in inverse_elements:
|
||||
if inverse.is_a("IfcMaterialConstituent"):
|
||||
self.file.remove(inverse)
|
||||
elif inverse.is_a("IfcMaterialLayer"):
|
||||
self.file.remove(inverse)
|
||||
elif inverse.is_a("IfcMaterialProfile"):
|
||||
self.file.remove(inverse)
|
||||
elif inverse.is_a("IfcRelAssociatesMaterial"):
|
||||
self.file.remove(inverse)
|
||||
@@ -3,6 +3,21 @@ from blenderbim.bim.module.material.data import Data
|
||||
from blenderbim.bim.ifc import IfcStore
|
||||
|
||||
|
||||
class BIM_PT_material(Panel):
|
||||
bl_label = "IFC Material"
|
||||
bl_idname = "BIM_PT_material"
|
||||
bl_space_type = "PROPERTIES"
|
||||
bl_region_type = "WINDOW"
|
||||
bl_context = "material"
|
||||
|
||||
def draw(self, context):
|
||||
row = self.layout.row()
|
||||
if bool(context.active_object.active_material.BIMObjectProperties.ifc_definition_id):
|
||||
row.operator("bim.remove_material", icon="X", text="Remove IFC Material")
|
||||
else:
|
||||
row.operator("bim.add_material", icon="ADD", text="Create IFC Material")
|
||||
|
||||
|
||||
class BIM_PT_object_material(Panel):
|
||||
bl_label = "IFC Object Material"
|
||||
bl_idname = "BIM_PT_object_material"
|
||||
|
||||
@@ -31,13 +31,11 @@ def getPsetNames(self, context):
|
||||
|
||||
def getMaterialPsetNames(self, context):
|
||||
global psetnames
|
||||
if "/" in context.active_object.name:
|
||||
ifc_class = "IfcMaterial"
|
||||
if ifc_class not in psetnames:
|
||||
psets = blenderbim.bim.schema.ifc.psetqto.get_applicable(ifc_class, pset_only=True)
|
||||
psetnames[ifc_class] = [(p.Name, p.Name, "") for p in psets]
|
||||
return psetnames[ifc_class]
|
||||
return []
|
||||
ifc_class = "IfcMaterial"
|
||||
if ifc_class not in psetnames:
|
||||
psets = blenderbim.bim.schema.ifc.psetqto.get_applicable(ifc_class, pset_only=True)
|
||||
psetnames[ifc_class] = [(p.Name, p.Name, "") for p in psets]
|
||||
return psetnames[ifc_class]
|
||||
|
||||
|
||||
def getQtoNames(self, context):
|
||||
|
||||
Reference in New Issue
Block a user