mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 06:39:13 +00:00
Fix #1557. Surface style attributes can now be explicitly edited.
This commit is contained in:
@@ -83,7 +83,7 @@ class BIM_PT_object_attributes(Panel):
|
||||
|
||||
|
||||
class BIM_PT_material_attributes(Panel):
|
||||
bl_label = "IFC Attributes"
|
||||
bl_label = "IFC Material Attributes"
|
||||
bl_idname = "BIM_PT_material_attributes"
|
||||
bl_space_type = "PROPERTIES"
|
||||
bl_region_type = "WINDOW"
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
import bpy
|
||||
from . import ui, operator
|
||||
from . import ui, prop, operator
|
||||
|
||||
classes = (
|
||||
operator.AddStyle,
|
||||
operator.EnableEditingStyle,
|
||||
operator.DisableEditingStyle,
|
||||
operator.EditStyle,
|
||||
operator.RemoveStyle,
|
||||
operator.UpdateStyleColours,
|
||||
operator.UnlinkStyle,
|
||||
prop.BIMStyleProperties,
|
||||
ui.BIM_PT_style,
|
||||
ui.BIM_PT_style_attributes,
|
||||
)
|
||||
|
||||
|
||||
def register():
|
||||
pass
|
||||
bpy.types.Material.BIMStyleProperties = bpy.props.PointerProperty(type=prop.BIMStyleProperties)
|
||||
|
||||
|
||||
def unregister():
|
||||
pass
|
||||
del bpy.types.Material.BIMStyleProperties
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import bpy
|
||||
import ifcopenshell.api
|
||||
import blenderbim.bim.helper
|
||||
from blenderbim.bim.ifc import IfcStore
|
||||
from ifcopenshell.api.style.data import Data
|
||||
|
||||
|
||||
def get_colour_settings(material):
|
||||
@@ -18,9 +20,9 @@ def get_colour_settings(material):
|
||||
}
|
||||
|
||||
|
||||
class EditStyle(bpy.types.Operator):
|
||||
bl_idname = "bim.edit_style"
|
||||
bl_label = "Edit Style"
|
||||
class UpdateStyleColours(bpy.types.Operator):
|
||||
bl_idname = "bim.update_style_colours"
|
||||
bl_label = "Update Style Colours"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
material: bpy.props.StringProperty()
|
||||
|
||||
@@ -32,7 +34,7 @@ class EditStyle(bpy.types.Operator):
|
||||
material = bpy.data.materials.get(self.material) if self.material else bpy.context.active_object.active_material
|
||||
settings = get_colour_settings(material)
|
||||
settings["style"] = self.file.by_id(material.BIMMaterialProperties.ifc_style_id)
|
||||
ifcopenshell.api.run("style.edit_style", self.file, **settings)
|
||||
ifcopenshell.api.run("style.edit_style_colours", self.file, **settings)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
@@ -88,3 +90,54 @@ class UnlinkStyle(bpy.types.Operator):
|
||||
if "Ifc" in material.name and "/" in material.name:
|
||||
material.name = "/".join(material.name.split("/")[1:])
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class EnableEditingStyle(bpy.types.Operator):
|
||||
bl_idname = "bim.enable_editing_style"
|
||||
bl_label = "Enable Editing Style"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
material: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
material = bpy.data.materials.get(self.material) if self.material else bpy.context.active_object.active_material
|
||||
props = material.BIMStyleProperties
|
||||
while len(props.attributes) > 0:
|
||||
props.attributes.remove(0)
|
||||
|
||||
data = Data.styles[material.BIMMaterialProperties.ifc_style_id]
|
||||
blenderbim.bim.helper.import_attributes("IfcSurfaceStyle", props.attributes, data)
|
||||
props.is_editing_attributes = True
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class DisableEditingStyle(bpy.types.Operator):
|
||||
bl_idname = "bim.disable_editing_style"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
bl_label = "Disable Editing Style"
|
||||
material: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
material = bpy.data.materials.get(self.material) if self.material else bpy.context.active_object.active_material
|
||||
props = material.BIMStyleProperties
|
||||
props.is_editing_attributes = False
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class EditStyle(bpy.types.Operator):
|
||||
bl_idname = "bim.edit_style"
|
||||
bl_label = "Edit Style"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
return IfcStore.execute_ifc_operator(self, context)
|
||||
|
||||
def _execute(self, context):
|
||||
material = bpy.context.active_object.active_material
|
||||
props = material.BIMStyleProperties
|
||||
attributes = blenderbim.bim.helper.export_attributes(props.attributes)
|
||||
self.file = IfcStore.get_file()
|
||||
style = self.file.by_id(material.BIMMaterialProperties.ifc_style_id)
|
||||
ifcopenshell.api.run("style.edit_style", self.file, **{"style": style, "attributes": attributes})
|
||||
Data.load(IfcStore.get_file(), material.BIMMaterialProperties.ifc_style_id)
|
||||
bpy.ops.bim.disable_editing_style()
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import bpy
|
||||
from blenderbim.bim.ifc import IfcStore
|
||||
from blenderbim.bim.prop import StrProperty, Attribute
|
||||
from bpy.types import PropertyGroup
|
||||
from bpy.props import (
|
||||
PointerProperty,
|
||||
StringProperty,
|
||||
EnumProperty,
|
||||
BoolProperty,
|
||||
IntProperty,
|
||||
FloatProperty,
|
||||
FloatVectorProperty,
|
||||
CollectionProperty,
|
||||
)
|
||||
|
||||
class BIMStyleProperties(PropertyGroup):
|
||||
attributes: CollectionProperty(name="Attributes", type=Attribute)
|
||||
is_editing_attributes: BoolProperty(name="Is Editing Attributes")
|
||||
@@ -1,5 +1,7 @@
|
||||
import blenderbim.bim.helper
|
||||
from bpy.types import Panel
|
||||
from blenderbim.bim.ifc import IfcStore
|
||||
from ifcopenshell.api.style.data import Data
|
||||
|
||||
|
||||
class BIM_PT_style(Panel):
|
||||
@@ -21,10 +23,51 @@ class BIM_PT_style(Panel):
|
||||
props = context.active_object.active_material.BIMMaterialProperties
|
||||
row = self.layout.row(align=True)
|
||||
if props.ifc_style_id:
|
||||
row.operator("bim.edit_style", icon="GREASEPENCIL")
|
||||
row.operator("bim.update_style_colours", icon="GREASEPENCIL")
|
||||
op = row.operator("bim.unlink_style", icon="UNLINKED", text="")
|
||||
op.material = context.active_object.active_material.name
|
||||
op = row.operator("bim.remove_style", icon="X", text="")
|
||||
op.material = context.active_object.active_material.name
|
||||
else:
|
||||
row.operator("bim.add_style", icon="ADD")
|
||||
|
||||
|
||||
class BIM_PT_style_attributes(Panel):
|
||||
bl_label = "IFC Style Attributes"
|
||||
bl_idname = "BIM_PT_style_attributes"
|
||||
bl_space_type = "PROPERTIES"
|
||||
bl_region_type = "WINDOW"
|
||||
bl_context = "material"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
try:
|
||||
return bool(context.active_object.active_material.BIMMaterialProperties.ifc_style_id)
|
||||
except:
|
||||
return False
|
||||
|
||||
def draw(self, context):
|
||||
obj = context.active_object.active_material
|
||||
mprops = obj.BIMMaterialProperties
|
||||
props = obj.BIMStyleProperties
|
||||
if mprops.ifc_style_id not in Data.styles:
|
||||
Data.load(IfcStore.get_file(), mprops.ifc_style_id)
|
||||
if props.is_editing_attributes:
|
||||
row = self.layout.row(align=True)
|
||||
row.operator("bim.edit_style", icon="CHECKMARK")
|
||||
row.operator("bim.disable_editing_style", icon="CANCEL", text="")
|
||||
blenderbim.bim.helper.draw_attributes(props.attributes, self.layout)
|
||||
else:
|
||||
row = self.layout.row()
|
||||
row.operator("bim.enable_editing_style", icon="GREASEPENCIL", text="Edit")
|
||||
|
||||
row = self.layout.row(align=True)
|
||||
row.label(text="STEP ID")
|
||||
row.label(text=str(mprops.ifc_style_id))
|
||||
|
||||
for name, value in Data.styles[mprops.ifc_style_id].items():
|
||||
if name in ["id", "type", "Styles"]:
|
||||
continue
|
||||
row = self.layout.row(align=True)
|
||||
row.label(text=name)
|
||||
row.label(text=str(value))
|
||||
|
||||
Reference in New Issue
Block a user