mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Enable pset template prop editing on adding a new one #6019
This commit is contained in:
@@ -119,24 +119,7 @@ class EnableEditingPropTemplate(bpy.types.Operator):
|
|||||||
prop_template: bpy.props.IntProperty()
|
prop_template: bpy.props.IntProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
props = context.scene.BIMPsetTemplateProperties
|
tool.PsetTemplate.enable_editing_prop_template(tool.Ifc.get().by_id(self.prop_template))
|
||||||
props.active_prop_template_id = self.prop_template
|
|
||||||
template = IfcStore.pset_template_file.by_id(props.active_prop_template_id)
|
|
||||||
props.active_prop_template.name = template.Name or ""
|
|
||||||
props.active_prop_template.description = template.Description or ""
|
|
||||||
props.active_prop_template.primary_measure_type = template.PrimaryMeasureType or "-"
|
|
||||||
props.active_prop_template.template_type = template.TemplateType
|
|
||||||
props.active_prop_template.enum_values.clear()
|
|
||||||
|
|
||||||
if template.Enumerators:
|
|
||||||
props.active_prop_template.enum_values.clear()
|
|
||||||
data_type = props.active_prop_template.get_value_name()
|
|
||||||
for e in template.Enumerators.EnumerationValues:
|
|
||||||
new = props.active_prop_template.enum_values.add()
|
|
||||||
setattr(new, data_type, e.wrappedValue)
|
|
||||||
|
|
||||||
# Disable because of the intersecting enums in data.py.
|
|
||||||
props.active_pset_template_id = 0
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
@@ -245,7 +228,7 @@ class AddPropTemplate(bpy.types.Operator, tool.PsetTemplate.PsetTemplateOperator
|
|||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
props = context.scene.BIMPsetTemplateProperties
|
props = context.scene.BIMPsetTemplateProperties
|
||||||
pset_template_id = props.active_pset_template_id or int(props.pset_templates)
|
pset_template_id = props.active_pset_template_id or int(props.pset_templates)
|
||||||
ifcopenshell.api.run(
|
prop_template = ifcopenshell.api.run(
|
||||||
"pset_template.add_prop_template",
|
"pset_template.add_prop_template",
|
||||||
IfcStore.pset_template_file,
|
IfcStore.pset_template_file,
|
||||||
pset_template=IfcStore.pset_template_file.by_id(pset_template_id),
|
pset_template=IfcStore.pset_template_file.by_id(pset_template_id),
|
||||||
@@ -254,6 +237,7 @@ class AddPropTemplate(bpy.types.Operator, tool.PsetTemplate.PsetTemplateOperator
|
|||||||
IfcStore.pset_template_file.write(IfcStore.pset_template_path)
|
IfcStore.pset_template_file.write(IfcStore.pset_template_path)
|
||||||
bonsai.bim.handler.refresh_ui_data()
|
bonsai.bim.handler.refresh_ui_data()
|
||||||
bonsai.bim.schema.reload(tool.Ifc.get().schema)
|
bonsai.bim.schema.reload(tool.Ifc.get().schema)
|
||||||
|
tool.PsetTemplate.enable_editing_prop_template(prop_template)
|
||||||
|
|
||||||
|
|
||||||
class RemovePropTemplate(bpy.types.Operator, tool.PsetTemplate.PsetTemplateOperator):
|
class RemovePropTemplate(bpy.types.Operator, tool.PsetTemplate.PsetTemplateOperator):
|
||||||
|
|||||||
@@ -196,6 +196,14 @@ class PropTemplate(PropertyGroup):
|
|||||||
else:
|
else:
|
||||||
assert False, "Unknown data type"
|
assert False, "Unknown data type"
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
global_id: str
|
||||||
|
name: str
|
||||||
|
description: str
|
||||||
|
primary_measure_type: str
|
||||||
|
template_type: str
|
||||||
|
enum_values: bpy.types.bpy_prop_collection_idprop[EnumerationValues]
|
||||||
|
|
||||||
|
|
||||||
class BIMPsetTemplateProperties(PropertyGroup):
|
class BIMPsetTemplateProperties(PropertyGroup):
|
||||||
pset_template_files: EnumProperty(
|
pset_template_files: EnumProperty(
|
||||||
|
|||||||
@@ -95,3 +95,27 @@ class PsetTemplate(bonsai.core.tool.PsetTemplate):
|
|||||||
|
|
||||||
# Disable because of the intersecting enums in data.py.
|
# Disable because of the intersecting enums in data.py.
|
||||||
props.active_prop_template_id = 0
|
props.active_prop_template_id = 0
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def enable_editing_prop_template(cls, prop_template: ifcopenshell.entity_instance) -> None:
|
||||||
|
props = tool.PsetTemplate.get_pset_template_props()
|
||||||
|
props.active_prop_template_id = prop_template.id()
|
||||||
|
|
||||||
|
pset_template_file = IfcStore.pset_template_file
|
||||||
|
assert pset_template_file
|
||||||
|
template = pset_template_file.by_id(props.active_prop_template_id)
|
||||||
|
props.active_prop_template.name = template.Name or ""
|
||||||
|
props.active_prop_template.description = template.Description or ""
|
||||||
|
props.active_prop_template.primary_measure_type = template.PrimaryMeasureType or "-"
|
||||||
|
props.active_prop_template.template_type = template.TemplateType
|
||||||
|
props.active_prop_template.enum_values.clear()
|
||||||
|
|
||||||
|
if template.Enumerators:
|
||||||
|
props.active_prop_template.enum_values.clear()
|
||||||
|
data_type = props.active_prop_template.get_value_name()
|
||||||
|
for e in template.Enumerators.EnumerationValues:
|
||||||
|
new = props.active_prop_template.enum_values.add()
|
||||||
|
setattr(new, data_type, e.wrappedValue)
|
||||||
|
|
||||||
|
# Disable because of the intersecting enums in data.py.
|
||||||
|
props.active_pset_template_id = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user