mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 02:02:22 +00:00
update incorporating review comments
This commit is contained in:
@@ -29,19 +29,19 @@ classes = (
|
||||
operator.GuessQuantity,
|
||||
operator.RemovePset,
|
||||
operator.TogglePsetExpansion,
|
||||
operator.AddPropertyToEdit,
|
||||
operator.RemovePropertyToEdit,
|
||||
operator.ClearList,
|
||||
operator.RenameParameters,
|
||||
operator.AddEditCustomProperty,
|
||||
operator.BIM_OT_add_property_to_edit,
|
||||
operator.BIM_OT_remove_property_to_edit,
|
||||
operator.BIM_OT_clear_list,
|
||||
operator.BIM_OT_rename_parameters,
|
||||
operator.BIM_OT_add_edit_custom_property,
|
||||
prop.PsetProperties,
|
||||
prop.MaterialPsetProperties,
|
||||
prop.TaskPsetProperties,
|
||||
prop.ResourcePsetProperties,
|
||||
prop.ProfilePsetProperties,
|
||||
prop.WorkSchedulePsetProperties,
|
||||
prop.PropertiesToRename,
|
||||
prop.PropertiesToAddOrEdit,
|
||||
prop.RenameProperties,
|
||||
prop.AddEditProperties,
|
||||
ui.BIM_PT_object_psets,
|
||||
ui.BIM_PT_object_qtos,
|
||||
ui.BIM_PT_material_psets,
|
||||
@@ -50,9 +50,9 @@ classes = (
|
||||
ui.BIM_PT_resource_psets,
|
||||
ui.BIM_PT_profile_psets,
|
||||
ui.BIM_PT_work_schedule_psets,
|
||||
ui.BIM_PT_BulkPropertyEditor,
|
||||
ui.BIM_PT_RenameParameters,
|
||||
ui.BIM_PT_AddPropertiesOrEditValues
|
||||
ui.BIM_PT_bulk_property_editor,
|
||||
ui.BIM_PT_rename_parameters,
|
||||
ui.BIM_PT_add_edit_custom_properties
|
||||
)
|
||||
|
||||
|
||||
@@ -63,8 +63,8 @@ def register():
|
||||
bpy.types.Scene.ResourcePsetProperties = bpy.props.PointerProperty(type=prop.ResourcePsetProperties)
|
||||
bpy.types.Scene.ProfilePsetProperties = bpy.props.PointerProperty(type=prop.ProfilePsetProperties)
|
||||
bpy.types.Scene.WorkSchedulePsetProperties = bpy.props.PointerProperty(type=prop.WorkSchedulePsetProperties)
|
||||
bpy.types.Scene.PropertiesToRename = bpy.props.CollectionProperty(type=prop.PropertiesToRename)
|
||||
bpy.types.Scene.PropertiesToAddOrEdit = bpy.props.CollectionProperty(type=prop.PropertiesToAddOrEdit)
|
||||
bpy.types.Scene.RenameProperties = bpy.props.CollectionProperty(type=prop.RenameProperties)
|
||||
bpy.types.Scene.AddEditProperties = bpy.props.CollectionProperty(type=prop.AddEditProperties)
|
||||
|
||||
|
||||
def unregister():
|
||||
@@ -74,5 +74,5 @@ def unregister():
|
||||
del bpy.types.Scene.ResourcePsetProperties
|
||||
del bpy.types.Scene.ProfilePsetProperties
|
||||
del bpy.types.Scene.WorkSchedulePsetProperties
|
||||
del bpy.types.Scene.PropertiesToRename
|
||||
del bpy.types.Scene.PropertiesToAddOrEdit
|
||||
del bpy.types.Scene.RenameProperties
|
||||
del bpy.types.Scene.AddEditProperties
|
||||
|
||||
@@ -101,7 +101,6 @@ class EnablePsetEditing(bpy.types.Operator):
|
||||
|
||||
def execute(self, context):
|
||||
self.props = get_pset_props(context, self.obj, self.obj_type)
|
||||
|
||||
self.props.properties.clear()
|
||||
|
||||
data = Data.psets if self.pset_id in Data.psets else Data.qtos
|
||||
@@ -376,56 +375,41 @@ class CopyPropertyToSelection(bpy.types.Operator, Operator):
|
||||
)
|
||||
|
||||
|
||||
class AddPropertyToEdit(bpy.types.Operator):
|
||||
class BIM_OT_add_property_to_edit(bpy.types.Operator):
|
||||
bl_label = "Add new row"
|
||||
bl_idname = "bim.add_property_to_edit"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
type: bpy.props.StringProperty()
|
||||
option: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
if self.type == "PropertiesToRename":
|
||||
props = context.scene.PropertiesToRename
|
||||
props.add()
|
||||
elif self.type == "PropertiesToAddOrEdit":
|
||||
props = context.scene.PropertiesToAddOrEdit
|
||||
props.add()
|
||||
getattr(context.scene, self.option).add()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class RemovePropertyToEdit(bpy.types.Operator):
|
||||
|
||||
|
||||
class BIM_OT_remove_property_to_edit(bpy.types.Operator):
|
||||
bl_label = "Remove property to be renamed"
|
||||
bl_idname = "bim.remove_property_to_edit"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
index: bpy.props.IntProperty()
|
||||
type: bpy.props.StringProperty()
|
||||
option: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
if self.type == "PropertiesToRename":
|
||||
props = context.scene.PropertiesToRename
|
||||
props.remove(self.index)
|
||||
if self.type == "PropertiesToAddOrEdit":
|
||||
props = context.scene.PropertiesToAddOrEdit
|
||||
props.remove(self.index)
|
||||
getattr(context.scene, self.option).remove()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class ClearList(bpy.types.Operator):
|
||||
|
||||
class BIM_OT_clear_list(bpy.types.Operator):
|
||||
bl_label = "Clear list of properties"
|
||||
bl_idname = "bim.clear_list"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
type: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
if self.type == "PropertiesToRename":
|
||||
props = context.scene.PropertiesToRename
|
||||
props.clear()
|
||||
if self.type == "PropertiesToAddOrEdit":
|
||||
props = context.scene.PropertiesToAddOrEdit
|
||||
props.clear()
|
||||
return {"FINISHED"}
|
||||
|
||||
option: bpy.props.StringProperty()
|
||||
|
||||
class RenameParameters(bpy.types.Operator):
|
||||
def execute(self, context):
|
||||
getattr(context.scene, self.option).clear()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class BIM_OT_rename_parameters(bpy.types.Operator):
|
||||
bl_label = "Rename Parameters"
|
||||
bl_idname = "bim.rename_parameters"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
@@ -435,7 +419,7 @@ class RenameParameters(bpy.types.Operator):
|
||||
return IfcStore.execute_ifc_operator(self, context)
|
||||
|
||||
def _execute(self, context):
|
||||
props_to_map = context.scene.PropertiesToRename
|
||||
props_to_map = context.scene.RenameProperties
|
||||
ifc_file = IfcStore.get_file()
|
||||
all_ifc_elements = ifc_file.by_type("IfcElement")
|
||||
|
||||
@@ -447,23 +431,23 @@ class RenameParameters(bpy.types.Operator):
|
||||
|
||||
self.report({'INFO'}, 'Finished applying changes')
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
def rename_property(self, property_set, properties_to_map, ifc_element):
|
||||
if property_set.is_a() == "IfcPropertySet":
|
||||
property_container = property_set.HasProperties
|
||||
elif property_set.is_a() == "IfcElementQuantity":
|
||||
property_container = property_set.Quantities
|
||||
|
||||
|
||||
for obj_prop in property_container:
|
||||
for prop2map in properties_to_map:
|
||||
if prop2map.pset_name != property_set.Name:
|
||||
continue
|
||||
if prop2map.existing_property_name == obj_prop.Name:
|
||||
obj_prop.Name = prop2map.new_property_name
|
||||
Data.load(IfcStore.get_file(), ifc_element.id())
|
||||
Data.load(IfcStore.get_file(), ifc_element.id())
|
||||
|
||||
|
||||
class AddEditCustomProperty(bpy.types.Operator):
|
||||
class BIM_OT_add_edit_custom_property(bpy.types.Operator):
|
||||
bl_label = "Add or edit a custom property"
|
||||
bl_idname = "bim.add_edit_custom_property"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
@@ -475,46 +459,28 @@ class AddEditCustomProperty(bpy.types.Operator):
|
||||
def _execute(self, context):
|
||||
self.file = IfcStore.get_file()
|
||||
selected_objects = context.selected_objects
|
||||
props = context.scene.PropertiesToAddOrEdit
|
||||
props = context.scene.AddEditProperties
|
||||
|
||||
for object in selected_objects:
|
||||
ifc_definition_id = object.BIMObjectProperties.ifc_definition_id
|
||||
for obj in selected_objects:
|
||||
ifc_definition_id = obj.BIMObjectProperties.ifc_definition_id
|
||||
if not ifc_definition_id:
|
||||
continue
|
||||
ifc_element = tool.Ifc.get().by_id(ifc_definition_id)
|
||||
psets = ifcopenshell.util.element.get_psets(ifc_element)
|
||||
|
||||
for prop in props:
|
||||
if prop.value_type == "String":
|
||||
value = prop.string_value
|
||||
elif prop.value_type == "Boolean":
|
||||
value = prop.bool_value
|
||||
elif prop.value_type == "Integer":
|
||||
value = prop.int_value
|
||||
elif prop.value_type == "Number":
|
||||
value = prop.float_value
|
||||
|
||||
if prop.pset_name not in psets:
|
||||
new_pset = ifcopenshell.api.run("pset.add_pset", self.file, product=ifc_element, name=prop.pset_name)
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=new_pset, properties={prop.property_name:value})
|
||||
|
||||
else:#1) delete the existing property first, in case the value type has also been changed, and then
|
||||
#2) re-add the property
|
||||
#TODOUpdate this code to incorporate the dion's latest commit
|
||||
self.delete_ifc_property(ifc_element, prop)
|
||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=self.file.by_id(psets[prop.pset_name]["id"]), properties={prop.property_name:value})
|
||||
|
||||
value = getattr(prop, prop.get_value_name())
|
||||
new_pset = ifcopenshell.api.run(
|
||||
"pset.add_pset",
|
||||
self.file,
|
||||
product=ifc_element,
|
||||
name=prop.pset_name
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset",
|
||||
self.file,
|
||||
pset=new_pset,
|
||||
properties={prop.property_name:value}
|
||||
)
|
||||
|
||||
self.report({'INFO'}, 'Finished applying changes')
|
||||
return {"FINISHED"}
|
||||
|
||||
def delete_ifc_property(self, element, property):
|
||||
for definition in element.IsDefinedBy:
|
||||
if definition.is_a('IfcRelDefinesByProperties'):
|
||||
prop_set = definition.RelatingPropertyDefinition
|
||||
if prop_set.Name != property.pset_name:
|
||||
continue
|
||||
for hasprop in prop_set.HasProperties:
|
||||
if hasprop.Name != property.property_name:
|
||||
continue
|
||||
self.file.remove(hasprop)
|
||||
Data.load(IfcStore.get_file(), element.id())
|
||||
return
|
||||
|
||||
@@ -173,26 +173,36 @@ class WorkSchedulePsetProperties(PropertyGroup):
|
||||
active_pset_name: StringProperty(name="Pset Name")
|
||||
properties: CollectionProperty(name="Properties", type=Attribute)
|
||||
pset_name: EnumProperty(items=getWorkSchedulePsetNames, name="Pset Name")
|
||||
|
||||
|
||||
class PropertiesToRename(PropertyGroup):
|
||||
|
||||
class RenameProperties(PropertyGroup):
|
||||
pset_name: StringProperty(name="Pset")
|
||||
existing_property_name: StringProperty(name="Existing Property Name")
|
||||
new_property_name: StringProperty(name="New Property Name")
|
||||
|
||||
|
||||
class PropertiesToAddOrEdit(PropertyGroup):
|
||||
|
||||
|
||||
class AddEditProperties(PropertyGroup):
|
||||
pset_name: StringProperty(name="Pset")
|
||||
property_name: StringProperty(name="Property")
|
||||
string_value: StringProperty(name="Value")
|
||||
bool_value: BoolProperty(name="Property Value")
|
||||
int_value: IntProperty(name="Property Value")
|
||||
float_value: FloatProperty(name="Property Value")
|
||||
value_type: EnumProperty(
|
||||
bool_value: BoolProperty(name="Value")
|
||||
int_value: IntProperty(name="Value")
|
||||
float_value: FloatProperty(name="Value")
|
||||
data_type: EnumProperty(
|
||||
items=[
|
||||
("String", "String", "" ),
|
||||
("Boolean", "True/False", "" ),
|
||||
("Integer", "Integer", "" ),
|
||||
("Number", "Number", "" )],
|
||||
default="String"
|
||||
)
|
||||
("string", "String", "" ),
|
||||
("boolean", "True/False", "" ),
|
||||
("integer", "Integer", "" ),
|
||||
("float", "Number", "" )],
|
||||
default="string"
|
||||
)
|
||||
|
||||
def get_value_name(self):
|
||||
if self.data_type == "string":
|
||||
return "string_value"
|
||||
elif self.data_type == "boolean":
|
||||
return "bool_value"
|
||||
elif self.data_type == "integer":
|
||||
return "int_value"
|
||||
elif self.data_type == "float":
|
||||
return "float_value"
|
||||
|
||||
@@ -377,7 +377,7 @@ class BIM_PT_work_schedule_psets(Panel):
|
||||
draw_psetqto_ui(context, pset["id"], pset, props, self.layout, "WorkSchedule")
|
||||
|
||||
|
||||
class BIM_PT_BulkPropertyEditor(Panel):
|
||||
class BIM_PT_bulk_property_editor(Panel):
|
||||
bl_label = "IFC Bulk Property Editor"
|
||||
bl_space_type = 'PROPERTIES'
|
||||
bl_region_type = 'WINDOW'
|
||||
@@ -385,82 +385,74 @@ class BIM_PT_BulkPropertyEditor(Panel):
|
||||
|
||||
def draw(self, context):
|
||||
pass
|
||||
|
||||
|
||||
class BIM_PT_RenameParameters(Panel):
|
||||
|
||||
class BIM_PT_rename_parameters(Panel):
|
||||
bl_label = "Rename all building elements"
|
||||
bl_space_type = 'PROPERTIES'
|
||||
bl_region_type = 'WINDOW'
|
||||
bl_context = "object"
|
||||
bl_parent_id = "BIM_PT_BulkPropertyEditor"
|
||||
bl_parent_id = "BIM_PT_bulk_property_editor"
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
bl_order = 0
|
||||
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
props = context.scene.PropertiesToRename
|
||||
props = context.scene.RenameProperties
|
||||
|
||||
if props:
|
||||
for index, property in enumerate(props):
|
||||
if props:
|
||||
for index, prop in enumerate(props):
|
||||
row = layout.row()
|
||||
row.prop(property, "pset_name", text="")
|
||||
row.prop(property, "existing_property_name", text="")
|
||||
row.prop(property, "new_property_name", text="")
|
||||
row.prop(prop, "pset_name", text="")
|
||||
row.prop(prop, "existing_property_name", text="")
|
||||
row.prop(prop, "new_property_name", text="")
|
||||
op = row.operator("bim.remove_property_to_edit",icon="PANEL_CLOSE", text="")
|
||||
op.index = index
|
||||
op.type = "properties_to_map"
|
||||
|
||||
op.option = "RenameProperties"
|
||||
|
||||
row = layout.row()
|
||||
row.label()
|
||||
op = row.operator("bim.add_property_to_edit", icon="ADD",text="")
|
||||
op.type = "PropertiesToRename"
|
||||
|
||||
if props:
|
||||
op.option = "RenameProperties"
|
||||
|
||||
if props:
|
||||
row = layout.row()
|
||||
clear = row.operator("bim.clear_list")
|
||||
clear.type = "PropertiesToRename"
|
||||
clear.option = "RenameProperties"
|
||||
row.operator("bim.rename_parameters")
|
||||
|
||||
|
||||
class BIM_PT_AddPropertiesOrEditValues(Panel):
|
||||
"""Creates a Panel in the Object properties window"""
|
||||
class BIM_PT_add_edit_custom_properties(Panel):
|
||||
bl_label = "Add/Edit Custom Properties and Values (to selected objects)"
|
||||
bl_space_type = 'PROPERTIES'
|
||||
bl_region_type = 'WINDOW'
|
||||
bl_context = "object"
|
||||
bl_parent_id = "BIM_PT_BulkPropertyEditor"
|
||||
bl_parent_id = "BIM_PT_bulk_property_editor"
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
bl_order = 1
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
props = context.scene.PropertiesToAddOrEdit
|
||||
|
||||
props = context.scene.AddEditProperties
|
||||
|
||||
if props:
|
||||
for index, property in enumerate(props):
|
||||
row = layout.row()
|
||||
row.prop(property, "pset_name", text="")
|
||||
row.prop(property, "property_name", text="")
|
||||
if property.value_type == "String":
|
||||
row.prop(property, "string_value", text="")
|
||||
elif property.value_type == "Boolean":
|
||||
row.prop(property, "bool_value", text="")
|
||||
elif property.value_type == "Integer":
|
||||
row.prop(property, "int_value", text="")
|
||||
elif property.value_type == "Number":
|
||||
row.prop(property, "float_value", text="")
|
||||
row.prop(property, "value_type", text="")
|
||||
op = row.operator("bim.remove_property_to_edit",icon="PANEL_CLOSE", text="")
|
||||
op.index = index
|
||||
op.type = "PropertiesToAddOrEdit"
|
||||
|
||||
for index, prop in enumerate(props):
|
||||
row = layout.row()
|
||||
row.prop(prop, "pset_name", text="")
|
||||
row.prop(prop, "property_name", text="")
|
||||
row.prop(prop, prop.get_value_name(), text="")
|
||||
row.prop(prop, "data_type", text="")
|
||||
op = row.operator("bim.remove_property_to_edit",icon="PANEL_CLOSE", text="")
|
||||
op.index = index
|
||||
op.option = "AddEditProperties"
|
||||
|
||||
row = layout.row()
|
||||
row.label()
|
||||
op = row.operator("bim.add_property_to_edit", icon="ADD",text="")
|
||||
op.type = "PropertiesToAddOrEdit"
|
||||
|
||||
op.option = "AddEditProperties"
|
||||
|
||||
if props:
|
||||
row = layout.row()
|
||||
clear = row.operator("bim.clear_list")
|
||||
clear.type = "PropertiesToAddOrEdit"
|
||||
clear.option = "AddEditProperties"
|
||||
op = row.operator("bim.add_edit_custom_property",icon="ADD", text="Apply Changes")
|
||||
|
||||
Reference in New Issue
Block a user