mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 22:50:21 +00:00
Fix bug where adding a pset template didn't auto refresh the UI to the newly added template
This commit is contained in:
@@ -20,21 +20,20 @@ import bpy
|
|||||||
from . import ui, prop, operator
|
from . import ui, prop, operator
|
||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
operator.RefreshPsetTemplates,
|
|
||||||
operator.AddPsetFile,
|
|
||||||
operator.SavePsetTemplateFile,
|
|
||||||
operator.AddPsetTemplate,
|
|
||||||
operator.EditPsetTemplate,
|
|
||||||
operator.RemovePsetTemplate,
|
|
||||||
operator.AddPropTemplate,
|
|
||||||
operator.EditPropTemplate,
|
|
||||||
operator.RemovePropTemplate,
|
|
||||||
operator.EnableEditingPsetTemplate,
|
|
||||||
operator.DisableEditingPsetTemplate,
|
|
||||||
operator.EnableEditingPropTemplate,
|
|
||||||
operator.DeletePropEnum,
|
|
||||||
operator.AddPropEnum,
|
operator.AddPropEnum,
|
||||||
|
operator.AddPropTemplate,
|
||||||
|
operator.AddPsetFile,
|
||||||
|
operator.AddPsetTemplate,
|
||||||
|
operator.DeletePropEnum,
|
||||||
operator.DisableEditingPropTemplate,
|
operator.DisableEditingPropTemplate,
|
||||||
|
operator.DisableEditingPsetTemplate,
|
||||||
|
operator.EditPropTemplate,
|
||||||
|
operator.EditPsetTemplate,
|
||||||
|
operator.EnableEditingPropTemplate,
|
||||||
|
operator.EnableEditingPsetTemplate,
|
||||||
|
operator.RemovePropTemplate,
|
||||||
|
operator.RemovePsetTemplate,
|
||||||
|
operator.SavePsetTemplateFile,
|
||||||
prop.PsetTemplate,
|
prop.PsetTemplate,
|
||||||
prop.EnumerationValues,
|
prop.EnumerationValues,
|
||||||
prop.PropTemplate,
|
prop.PropTemplate,
|
||||||
|
|||||||
@@ -16,8 +16,11 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import os
|
||||||
import bpy
|
import bpy
|
||||||
|
import ifcopenshell
|
||||||
import blenderbim.tool as tool
|
import blenderbim.tool as tool
|
||||||
|
from blenderbim.bim.ifc import IfcStore
|
||||||
|
|
||||||
|
|
||||||
def refresh():
|
def refresh():
|
||||||
@@ -30,10 +33,51 @@ class PsetTemplatesData:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls):
|
def load(cls):
|
||||||
cls.data = {"primary_measure_type": cls.primary_measure_type()}
|
|
||||||
cls.is_loaded = True
|
cls.is_loaded = True
|
||||||
|
cls.data["primary_measure_type"] = cls.primary_measure_type()
|
||||||
|
cls.data["pset_template_files"] = cls.pset_template_files()
|
||||||
|
cls.data["pset_templates"] = cls.pset_templates()
|
||||||
|
cls.data["pset_template"] = cls.pset_template()
|
||||||
|
cls.data["prop_templates"] = cls.prop_templates()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def primary_measure_type(cls):
|
def primary_measure_type(cls):
|
||||||
schema = tool.Ifc.schema()
|
schema = tool.Ifc.schema()
|
||||||
return [(t, t, "") for t in sorted([d.name() for d in schema.declarations() if hasattr(d, "declared_type")])]
|
return [(t, t, "") for t in sorted([d.name() for d in schema.declarations() if hasattr(d, "declared_type")])]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def pset_template_files(cls):
|
||||||
|
files = os.listdir(os.path.join(bpy.context.scene.BIMProperties.data_dir, "pset"))
|
||||||
|
return [(f.replace(".ifc", ""), f.replace(".ifc", ""), "") for f in files]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def pset_templates(cls):
|
||||||
|
if not IfcStore.pset_template_file:
|
||||||
|
IfcStore.pset_template_path = os.path.join(
|
||||||
|
bpy.context.scene.BIMProperties.data_dir,
|
||||||
|
"pset",
|
||||||
|
bpy.context.scene.BIMPsetTemplateProperties.pset_template_files + ".ifc",
|
||||||
|
)
|
||||||
|
IfcStore.pset_template_file = ifcopenshell.open(IfcStore.pset_template_path)
|
||||||
|
return [(str(t.id()), t.Name, "") for t in IfcStore.pset_template_file.by_type("IfcPropertySetTemplate")]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def pset_template(cls):
|
||||||
|
props = bpy.context.scene.BIMPsetTemplateProperties
|
||||||
|
template_id = props.pset_templates
|
||||||
|
if not template_id:
|
||||||
|
return {}
|
||||||
|
info = IfcStore.pset_template_file.by_id(int(template_id)).get_info()
|
||||||
|
del info["id"]
|
||||||
|
del info["type"]
|
||||||
|
del info["OwnerHistory"]
|
||||||
|
del info["HasPropertyTemplates"]
|
||||||
|
return info
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def prop_templates(cls):
|
||||||
|
props = bpy.context.scene.BIMPsetTemplateProperties
|
||||||
|
template_id = props.pset_templates
|
||||||
|
if not template_id:
|
||||||
|
return []
|
||||||
|
return [e.get_info() for e in IfcStore.pset_template_file.by_id(int(template_id)).HasPropertyTemplates or []]
|
||||||
|
|||||||
@@ -22,24 +22,26 @@ import ifcopenshell
|
|||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
import blenderbim.bim.schema
|
import blenderbim.bim.schema
|
||||||
import blenderbim.bim.handler
|
import blenderbim.bim.handler
|
||||||
from blenderbim.bim.module.pset_template.prop import purge as purge_templates, updatePsetTemplates, getPsetTemplates
|
|
||||||
from blenderbim.bim.module.pset.prop import purge as purge_psets
|
|
||||||
from ifcopenshell.api.pset_template.data import Data
|
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
|
|
||||||
|
|
||||||
# This is just a temporary operator until
|
class Operator:
|
||||||
# @Moult performs some of his refactor-magic ;) - vulevukusej
|
|
||||||
class RefreshPsetTemplates(bpy.types.Operator):
|
|
||||||
bl_idname = "bim.refresh_psettemplates"
|
|
||||||
bl_label = "Refresh the data for PsetTemplates"
|
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
purge_templates()
|
IfcStore.begin_transaction(self)
|
||||||
purge_psets()
|
IfcStore.pset_template_file.begin_transaction()
|
||||||
|
result = self._execute(context)
|
||||||
|
IfcStore.pset_template_file.end_transaction()
|
||||||
|
IfcStore.add_transaction_operation(self)
|
||||||
|
IfcStore.end_transaction(self)
|
||||||
|
blenderbim.bim.handler.refresh_ui_data()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
def rollback(self, data):
|
||||||
|
IfcStore.pset_template_file.undo()
|
||||||
|
|
||||||
|
def commit(self, data):
|
||||||
|
IfcStore.pset_template_file.redo()
|
||||||
|
|
||||||
|
|
||||||
class AddPsetFile(bpy.types.Operator):
|
class AddPsetFile(bpy.types.Operator):
|
||||||
bl_idname = "bim.add_pset_file"
|
bl_idname = "bim.add_pset_file"
|
||||||
@@ -76,52 +78,22 @@ class AddPsetFile(bpy.types.Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class AddPsetTemplate(bpy.types.Operator):
|
class AddPsetTemplate(bpy.types.Operator, Operator):
|
||||||
bl_idname = "bim.add_pset_template"
|
bl_idname = "bim.add_pset_template"
|
||||||
bl_label = "Add Pset Template"
|
bl_label = "Add Pset Template"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
IfcStore.begin_transaction(self)
|
|
||||||
IfcStore.pset_template_file.begin_transaction()
|
|
||||||
result = self._execute(context)
|
|
||||||
IfcStore.pset_template_file.end_transaction()
|
|
||||||
IfcStore.add_transaction_operation(self)
|
|
||||||
IfcStore.end_transaction(self)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
ifcopenshell.api.run("pset_template.add_pset_template", IfcStore.pset_template_file)
|
template = ifcopenshell.api.run("pset_template.add_pset_template", IfcStore.pset_template_file)
|
||||||
Data.load(IfcStore.pset_template_file)
|
blenderbim.bim.handler.refresh_ui_data()
|
||||||
updatePsetTemplates(self, context)
|
context.scene.BIMPsetTemplateProperties.pset_templates = str(template.id())
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
def rollback(self, data):
|
|
||||||
IfcStore.pset_template_file.undo()
|
|
||||||
|
|
||||||
def commit(self, data):
|
|
||||||
IfcStore.pset_template_file.redo()
|
|
||||||
|
|
||||||
|
|
||||||
class RemovePsetTemplate(bpy.types.Operator):
|
class RemovePsetTemplate(bpy.types.Operator, Operator):
|
||||||
bl_idname = "bim.remove_pset_template"
|
bl_idname = "bim.remove_pset_template"
|
||||||
bl_label = "Remove Pset Template"
|
bl_label = "Remove Pset Template"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def poll(cls, context):
|
|
||||||
props = context.scene.BIMPsetTemplateProperties
|
|
||||||
return bool(getPsetTemplates(props, context))
|
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
IfcStore.begin_transaction(self)
|
|
||||||
IfcStore.pset_template_file.begin_transaction()
|
|
||||||
result = self._execute(context)
|
|
||||||
IfcStore.pset_template_file.end_transaction()
|
|
||||||
IfcStore.add_transaction_operation(self)
|
|
||||||
IfcStore.end_transaction(self)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
props = context.scene.BIMPsetTemplateProperties
|
props = context.scene.BIMPsetTemplateProperties
|
||||||
if props.active_pset_template_id == int(props.pset_templates):
|
if props.active_pset_template_id == int(props.pset_templates):
|
||||||
@@ -131,15 +103,6 @@ class RemovePsetTemplate(bpy.types.Operator):
|
|||||||
IfcStore.pset_template_file,
|
IfcStore.pset_template_file,
|
||||||
**{"pset_template": IfcStore.pset_template_file.by_id(int(props.pset_templates))}
|
**{"pset_template": IfcStore.pset_template_file.by_id(int(props.pset_templates))}
|
||||||
)
|
)
|
||||||
Data.load(IfcStore.pset_template_file)
|
|
||||||
updatePsetTemplates(self, context)
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
def rollback(self, data):
|
|
||||||
IfcStore.pset_template_file.undo()
|
|
||||||
|
|
||||||
def commit(self, data):
|
|
||||||
IfcStore.pset_template_file.redo()
|
|
||||||
|
|
||||||
|
|
||||||
class EnableEditingPsetTemplate(bpy.types.Operator):
|
class EnableEditingPsetTemplate(bpy.types.Operator):
|
||||||
@@ -147,20 +110,15 @@ class EnableEditingPsetTemplate(bpy.types.Operator):
|
|||||||
bl_label = "Enable Editing Pset Template"
|
bl_label = "Enable Editing Pset Template"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def poll(cls, context):
|
|
||||||
props = context.scene.BIMPsetTemplateProperties
|
|
||||||
return bool(getPsetTemplates(props, context))
|
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
props = context.scene.BIMPsetTemplateProperties
|
props = context.scene.BIMPsetTemplateProperties
|
||||||
props.active_pset_template_id = int(props.pset_templates)
|
props.active_pset_template_id = int(props.pset_templates)
|
||||||
template = Data.pset_templates[props.active_pset_template_id]
|
template = IfcStore.pset_template_file.by_id(props.active_pset_template_id)
|
||||||
props.active_pset_template.global_id = template["GlobalId"]
|
props.active_pset_template.global_id = template.GlobalId
|
||||||
props.active_pset_template.name = template["Name"] or ""
|
props.active_pset_template.name = template.Name or ""
|
||||||
props.active_pset_template.description = template["Description"] or ""
|
props.active_pset_template.description = template.Description or ""
|
||||||
props.active_pset_template.template_type = template["TemplateType"]
|
props.active_pset_template.template_type = template.TemplateType
|
||||||
props.active_pset_template.applicable_entity = template["ApplicableEntity"] or ""
|
props.active_pset_template.applicable_entity = template.ApplicableEntity or ""
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
@@ -184,20 +142,19 @@ class EnableEditingPropTemplate(bpy.types.Operator):
|
|||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
props = context.scene.BIMPsetTemplateProperties
|
props = context.scene.BIMPsetTemplateProperties
|
||||||
props.active_prop_template_id = self.prop_template
|
props.active_prop_template_id = self.prop_template
|
||||||
template = Data.prop_templates[props.active_prop_template_id]
|
template = IfcStore.pset_template_file.by_id(props.active_prop_template_id)
|
||||||
props.active_prop_template.name = template["Name"] or ""
|
props.active_prop_template.name = template.Name or ""
|
||||||
props.active_prop_template.description = template["Description"] or ""
|
props.active_prop_template.description = template.Description or ""
|
||||||
props.active_prop_template.primary_measure_type = template["PrimaryMeasureType"]
|
props.active_prop_template.primary_measure_type = template.PrimaryMeasureType
|
||||||
props.active_prop_template.template_type = template["TemplateType"]
|
props.active_prop_template.template_type = template.TemplateType
|
||||||
props.active_prop_template.enum_values.clear()
|
props.active_prop_template.enum_values.clear()
|
||||||
|
|
||||||
if template["Enumerators"]:
|
if template.Enumerators:
|
||||||
props.active_prop_template.enum_values.clear()
|
props.active_prop_template.enum_values.clear()
|
||||||
data_type = props.active_prop_template.get_value_name()
|
data_type = props.active_prop_template.get_value_name()
|
||||||
for e in template["Enumerators"].EnumerationValues:
|
for e in template.Enumerators.EnumerationValues:
|
||||||
new = props.active_prop_template.enum_values.add()
|
new = props.active_prop_template.enum_values.add()
|
||||||
setattr(new, data_type, e.wrappedValue)
|
setattr(new, data_type, e.wrappedValue)
|
||||||
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
@@ -236,20 +193,11 @@ class DisableEditingPropTemplate(bpy.types.Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class EditPsetTemplate(bpy.types.Operator):
|
class EditPsetTemplate(bpy.types.Operator, Operator):
|
||||||
bl_idname = "bim.edit_pset_template"
|
bl_idname = "bim.edit_pset_template"
|
||||||
bl_label = "Edit Pset Template"
|
bl_label = "Edit Pset Template"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
IfcStore.begin_transaction(self)
|
|
||||||
IfcStore.pset_template_file.begin_transaction()
|
|
||||||
result = self._execute(context)
|
|
||||||
IfcStore.pset_template_file.end_transaction()
|
|
||||||
IfcStore.add_transaction_operation(self)
|
|
||||||
IfcStore.end_transaction(self)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
props = context.scene.BIMPsetTemplateProperties
|
props = context.scene.BIMPsetTemplateProperties
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
@@ -265,16 +213,7 @@ class EditPsetTemplate(bpy.types.Operator):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
Data.load(IfcStore.pset_template_file)
|
|
||||||
updatePsetTemplates(self, context)
|
|
||||||
bpy.ops.bim.disable_editing_pset_template()
|
bpy.ops.bim.disable_editing_pset_template()
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
def rollback(self, data):
|
|
||||||
IfcStore.pset_template_file.undo()
|
|
||||||
|
|
||||||
def commit(self, data):
|
|
||||||
IfcStore.pset_template_file.redo()
|
|
||||||
|
|
||||||
|
|
||||||
class SavePsetTemplateFile(bpy.types.Operator):
|
class SavePsetTemplateFile(bpy.types.Operator):
|
||||||
@@ -288,20 +227,11 @@ class SavePsetTemplateFile(bpy.types.Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class AddPropTemplate(bpy.types.Operator):
|
class AddPropTemplate(bpy.types.Operator, Operator):
|
||||||
bl_idname = "bim.add_prop_template"
|
bl_idname = "bim.add_prop_template"
|
||||||
bl_label = "Add Prop Template"
|
bl_label = "Add Prop Template"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
IfcStore.begin_transaction(self)
|
|
||||||
IfcStore.pset_template_file.begin_transaction()
|
|
||||||
result = self._execute(context)
|
|
||||||
IfcStore.pset_template_file.end_transaction()
|
|
||||||
IfcStore.add_transaction_operation(self)
|
|
||||||
IfcStore.end_transaction(self)
|
|
||||||
return result
|
|
||||||
|
|
||||||
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)
|
||||||
@@ -310,31 +240,14 @@ class AddPropTemplate(bpy.types.Operator):
|
|||||||
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)}
|
||||||
)
|
)
|
||||||
Data.load(IfcStore.pset_template_file)
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
def rollback(self, data):
|
|
||||||
IfcStore.pset_template_file.undo()
|
|
||||||
|
|
||||||
def commit(self, data):
|
|
||||||
IfcStore.pset_template_file.redo()
|
|
||||||
|
|
||||||
|
|
||||||
class RemovePropTemplate(bpy.types.Operator):
|
class RemovePropTemplate(bpy.types.Operator, Operator):
|
||||||
bl_idname = "bim.remove_prop_template"
|
bl_idname = "bim.remove_prop_template"
|
||||||
bl_label = "Remove Prop Template"
|
bl_label = "Remove Prop Template"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
prop_template: bpy.props.IntProperty()
|
prop_template: bpy.props.IntProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
IfcStore.begin_transaction(self)
|
|
||||||
IfcStore.pset_template_file.begin_transaction()
|
|
||||||
result = self._execute(context)
|
|
||||||
IfcStore.pset_template_file.end_transaction()
|
|
||||||
IfcStore.add_transaction_operation(self)
|
|
||||||
IfcStore.end_transaction(self)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
props = context.scene.BIMPsetTemplateProperties
|
props = context.scene.BIMPsetTemplateProperties
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
@@ -342,30 +255,13 @@ class RemovePropTemplate(bpy.types.Operator):
|
|||||||
IfcStore.pset_template_file,
|
IfcStore.pset_template_file,
|
||||||
**{"prop_template": IfcStore.pset_template_file.by_id(self.prop_template)}
|
**{"prop_template": IfcStore.pset_template_file.by_id(self.prop_template)}
|
||||||
)
|
)
|
||||||
Data.load(IfcStore.pset_template_file)
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
def rollback(self, data):
|
|
||||||
IfcStore.pset_template_file.undo()
|
|
||||||
|
|
||||||
def commit(self, data):
|
|
||||||
IfcStore.pset_template_file.redo()
|
|
||||||
|
|
||||||
|
|
||||||
class EditPropTemplate(bpy.types.Operator):
|
class EditPropTemplate(bpy.types.Operator, Operator):
|
||||||
bl_idname = "bim.edit_prop_template"
|
bl_idname = "bim.edit_prop_template"
|
||||||
bl_label = "Edit Prop Template"
|
bl_label = "Edit Prop Template"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
IfcStore.begin_transaction(self)
|
|
||||||
IfcStore.pset_template_file.begin_transaction()
|
|
||||||
result = self._execute(context)
|
|
||||||
IfcStore.pset_template_file.end_transaction()
|
|
||||||
IfcStore.add_transaction_operation(self)
|
|
||||||
IfcStore.end_transaction(self)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
props = context.scene.BIMPsetTemplateProperties
|
props = context.scene.BIMPsetTemplateProperties
|
||||||
if props.active_prop_template.template_type == "P_ENUMERATEDVALUE":
|
if props.active_prop_template.template_type == "P_ENUMERATEDVALUE":
|
||||||
@@ -386,9 +282,7 @@ class EditPropTemplate(bpy.types.Operator):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
Data.load(IfcStore.pset_template_file)
|
|
||||||
bpy.ops.bim.disable_editing_prop_template()
|
bpy.ops.bim.disable_editing_prop_template()
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
# TODO -This will need to go into the
|
# TODO -This will need to go into the
|
||||||
# api code at some point - vulevukusej
|
# api code at some point - vulevukusej
|
||||||
@@ -404,9 +298,3 @@ class EditPropTemplate(bpy.types.Operator):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
return prop_enum
|
return prop_enum
|
||||||
|
|
||||||
def rollback(self, data):
|
|
||||||
IfcStore.pset_template_file.undo()
|
|
||||||
|
|
||||||
def commit(self, data):
|
|
||||||
IfcStore.pset_template_file.redo()
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
||||||
# Copyright (C) 2020, 2021 Dion Moult <dion@thinkmoult.com>
|
# Copyright (C) 2020-2022 Dion Moult <dion@thinkmoult.com>
|
||||||
#
|
#
|
||||||
# This file is part of BlenderBIM Add-on.
|
# This file is part of BlenderBIM Add-on.
|
||||||
#
|
#
|
||||||
@@ -33,59 +33,30 @@ from bpy.props import (
|
|||||||
FloatVectorProperty,
|
FloatVectorProperty,
|
||||||
CollectionProperty,
|
CollectionProperty,
|
||||||
)
|
)
|
||||||
from ifcopenshell.api.pset_template.data import Data
|
|
||||||
|
|
||||||
|
|
||||||
psettemplatefiles_enum = []
|
|
||||||
psettemplates_enum = []
|
|
||||||
|
|
||||||
|
|
||||||
def purge():
|
|
||||||
global psettemplatefiles_enum
|
|
||||||
global psettemplates_enum
|
|
||||||
psettemplatefiles_enum = []
|
|
||||||
psettemplates_enum = []
|
|
||||||
|
|
||||||
|
|
||||||
def updatePsetTemplateFiles(self, context):
|
def updatePsetTemplateFiles(self, context):
|
||||||
global psettemplates_enum
|
IfcStore.pset_template_file = None
|
||||||
IfcStore.pset_template_path = os.path.join(
|
PsetTemplatesData.data["pset_template_files"] = PsetTemplatesData.pset_template_files()
|
||||||
context.scene.BIMProperties.data_dir,
|
PsetTemplatesData.data["pset_templates"] = PsetTemplatesData.pset_templates()
|
||||||
"pset",
|
PsetTemplatesData.data["prop_templates"] = PsetTemplatesData.prop_templates()
|
||||||
context.scene.BIMPsetTemplateProperties.pset_template_files + ".ifc",
|
|
||||||
)
|
|
||||||
IfcStore.pset_template_file = ifcopenshell.open(IfcStore.pset_template_path)
|
|
||||||
updatePsetTemplates(self, context)
|
|
||||||
|
|
||||||
|
|
||||||
def getPsetTemplateFiles(self, context):
|
def getPsetTemplateFiles(self, context):
|
||||||
global psettemplatefiles_enum
|
if not PsetTemplatesData.is_loaded:
|
||||||
if len(psettemplatefiles_enum) < 1:
|
PsetTemplatesData.load()
|
||||||
files = os.listdir(os.path.join(context.scene.BIMProperties.data_dir, "pset"))
|
return PsetTemplatesData.data["pset_template_files"]
|
||||||
psettemplatefiles_enum.extend([(f.replace(".ifc", ""), f.replace(".ifc", ""), "") for f in files])
|
|
||||||
return psettemplatefiles_enum
|
|
||||||
|
|
||||||
|
|
||||||
def updatePsetTemplates(self, context):
|
def updatePsetTemplates(self, context):
|
||||||
global psettemplates_enum
|
PsetTemplatesData.data["pset_template"] = PsetTemplatesData.pset_template()
|
||||||
psettemplates_enum.clear()
|
PsetTemplatesData.data["prop_templates"] = PsetTemplatesData.prop_templates()
|
||||||
getPsetTemplates(self, context)
|
|
||||||
|
|
||||||
|
|
||||||
def getPsetTemplates(self, context):
|
def getPsetTemplates(self, context):
|
||||||
global psettemplates_enum
|
if not PsetTemplatesData.is_loaded:
|
||||||
if len(psettemplates_enum) < 1:
|
PsetTemplatesData.load()
|
||||||
if not IfcStore.pset_template_file:
|
return PsetTemplatesData.data["pset_templates"]
|
||||||
IfcStore.pset_template_path = os.path.join(
|
|
||||||
context.scene.BIMProperties.data_dir,
|
|
||||||
"pset",
|
|
||||||
context.scene.BIMPsetTemplateProperties.pset_template_files + ".ifc",
|
|
||||||
)
|
|
||||||
IfcStore.pset_template_file = ifcopenshell.open(IfcStore.pset_template_path)
|
|
||||||
templates = IfcStore.pset_template_file.by_type("IfcPropertySetTemplate")
|
|
||||||
psettemplates_enum.extend([(str(t.id()), t.Name, "") for t in templates])
|
|
||||||
Data.load(IfcStore.pset_template_file)
|
|
||||||
return psettemplates_enum
|
|
||||||
|
|
||||||
|
|
||||||
def get_primary_measure_type(self, context):
|
def get_primary_measure_type(self, context):
|
||||||
@@ -182,7 +153,7 @@ class BIMPsetTemplateProperties(PropertyGroup):
|
|||||||
pset_template_files: EnumProperty(
|
pset_template_files: EnumProperty(
|
||||||
items=getPsetTemplateFiles, name="Pset Template Files", update=updatePsetTemplateFiles
|
items=getPsetTemplateFiles, name="Pset Template Files", update=updatePsetTemplateFiles
|
||||||
)
|
)
|
||||||
pset_templates: EnumProperty(items=getPsetTemplates, name="Pset Template Files")
|
pset_templates: EnumProperty(items=getPsetTemplates, name="Pset Template Files", update=updatePsetTemplates)
|
||||||
active_pset_template_id: IntProperty(name="Active Pset Template Id")
|
active_pset_template_id: IntProperty(name="Active Pset Template Id")
|
||||||
active_prop_template_id: IntProperty(name="Active Prop Template Id")
|
active_prop_template_id: IntProperty(name="Active Prop Template Id")
|
||||||
active_pset_template: PointerProperty(type=PsetTemplate)
|
active_pset_template: PointerProperty(type=PsetTemplate)
|
||||||
|
|||||||
@@ -20,10 +20,7 @@ import bpy
|
|||||||
from bpy.types import Panel
|
from bpy.types import Panel
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from blenderbim.bim.helper import prop_with_search
|
from blenderbim.bim.helper import prop_with_search
|
||||||
from blenderbim.bim.module.pset_template.prop import (
|
from blenderbim.bim.module.pset_template.data import PsetTemplatesData
|
||||||
getPsetTemplates,
|
|
||||||
)
|
|
||||||
from ifcopenshell.api.pset_template.data import Data
|
|
||||||
|
|
||||||
|
|
||||||
class BIM_PT_pset_template(Panel):
|
class BIM_PT_pset_template(Panel):
|
||||||
@@ -36,23 +33,24 @@ class BIM_PT_pset_template(Panel):
|
|||||||
bl_parent_id = "BIM_PT_project_setup"
|
bl_parent_id = "BIM_PT_project_setup"
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
layout = self.layout
|
if not PsetTemplatesData.is_loaded:
|
||||||
props = context.scene.BIMPsetTemplateProperties
|
PsetTemplatesData.load()
|
||||||
|
|
||||||
row = layout.row(align=True)
|
self.props = context.scene.BIMPsetTemplateProperties
|
||||||
prop_with_search(row, props, "pset_template_files", text="")
|
|
||||||
|
row = self.layout.row(align=True)
|
||||||
|
prop_with_search(row, self.props, "pset_template_files", text="")
|
||||||
row.operator("bim.save_pset_template_file", text="", icon="EXPORT")
|
row.operator("bim.save_pset_template_file", text="", icon="EXPORT")
|
||||||
row.operator("bim.add_pset_file", icon="ADD", text="")
|
row.operator("bim.add_pset_file", icon="ADD", text="")
|
||||||
row.operator("bim.refresh_psettemplates", icon="FILE_REFRESH", text="")
|
|
||||||
|
|
||||||
row = layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
|
|
||||||
if bool(getPsetTemplates(props, context)):
|
if PsetTemplatesData.data["pset_templates"]:
|
||||||
prop_with_search(row, props, "pset_templates", text="", icon="COPY_ID")
|
prop_with_search(row, self.props, "pset_templates", text="", icon="COPY_ID")
|
||||||
else:
|
else:
|
||||||
row.label(text="No Pset Templates", icon="COPY_ID")
|
row.label(text="No Pset Templates", icon="COPY_ID")
|
||||||
|
|
||||||
if props.active_pset_template_id:
|
if self.props.active_pset_template_id:
|
||||||
row.operator("bim.edit_pset_template", text="", icon="CHECKMARK")
|
row.operator("bim.edit_pset_template", text="", icon="CHECKMARK")
|
||||||
row.operator("bim.disable_editing_pset_template", text="", icon="CANCEL")
|
row.operator("bim.disable_editing_pset_template", text="", icon="CANCEL")
|
||||||
else:
|
else:
|
||||||
@@ -60,49 +58,39 @@ class BIM_PT_pset_template(Panel):
|
|||||||
row.operator("bim.enable_editing_pset_template", text="", icon="GREASEPENCIL")
|
row.operator("bim.enable_editing_pset_template", text="", icon="GREASEPENCIL")
|
||||||
row.operator("bim.remove_pset_template", text="", icon="X")
|
row.operator("bim.remove_pset_template", text="", icon="X")
|
||||||
|
|
||||||
if not Data.is_loaded and props.pset_template_files:
|
if PsetTemplatesData.data["pset_template"]:
|
||||||
Data.load(IfcStore.pset_template_file)
|
self.draw_pset_template()
|
||||||
|
|
||||||
if not Data.pset_templates:
|
def draw_pset_template(self):
|
||||||
return
|
if self.props.active_pset_template_id:
|
||||||
|
row = self.layout.row()
|
||||||
if props.active_pset_template_id:
|
row.prop(self.props.active_pset_template, "name")
|
||||||
pset_template = Data.pset_templates[int(props.active_pset_template_id)]
|
row = self.layout.row()
|
||||||
row = layout.row()
|
row.prop(self.props.active_pset_template, "description")
|
||||||
row.prop(props.active_pset_template, "name")
|
prop_with_search(self.layout, self.props.active_pset_template, "template_type")
|
||||||
row = layout.row()
|
row = self.layout.row()
|
||||||
row.prop(props.active_pset_template, "description")
|
row.prop(self.props.active_pset_template, "applicable_entity")
|
||||||
prop_with_search(layout, props.active_pset_template, "template_type")
|
|
||||||
row = layout.row()
|
|
||||||
row.prop(props.active_pset_template, "applicable_entity")
|
|
||||||
else:
|
else:
|
||||||
pset_template = Data.pset_templates[int(props.pset_templates)]
|
for name, value in PsetTemplatesData.data["pset_template"].items():
|
||||||
for name, value in pset_template.items():
|
row = self.layout.row(align=True)
|
||||||
if name == "id" or name == "type" or name == "HasPropertyTemplates":
|
|
||||||
continue
|
|
||||||
row = layout.row(align=True)
|
|
||||||
row.label(text=name)
|
row.label(text=name)
|
||||||
row.label(text=str(value))
|
row.label(text=str(value))
|
||||||
|
|
||||||
row = layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
row.label(text="Property Templates", icon="COPY_ID")
|
row.label(text="Property Templates", icon="COPY_ID")
|
||||||
row.operator("bim.add_prop_template", icon="ADD", text="")
|
row.operator("bim.add_prop_template", icon="ADD", text="")
|
||||||
|
|
||||||
row = layout.row()
|
for prop_template in PsetTemplatesData.data["prop_templates"]:
|
||||||
row.label(text="Name | Description | PrimaryMeasureType | TemplateType")
|
row = self.layout.row(align=True)
|
||||||
|
|
||||||
for prop_template_id in pset_template["HasPropertyTemplates"]:
|
if self.props.active_prop_template_id and self.props.active_prop_template_id == prop_template["id"]:
|
||||||
prop_template = Data.prop_templates[prop_template_id]
|
row.prop(self.props.active_prop_template, "name", text="")
|
||||||
row = layout.row(align=True)
|
row.prop(self.props.active_prop_template, "description", text="")
|
||||||
|
prop_with_search(row, self.props.active_prop_template, "primary_measure_type", text="")
|
||||||
|
row.prop(self.props.active_prop_template, "template_type", text="")
|
||||||
|
|
||||||
if props.active_prop_template_id and props.active_prop_template_id == prop_template_id:
|
if self.props.active_prop_template.template_type == "P_ENUMERATEDVALUE":
|
||||||
row.prop(props.active_prop_template, "name", text="")
|
row = self.layout.row(align=True)
|
||||||
row.prop(props.active_prop_template, "description", text="")
|
|
||||||
prop_with_search(row, props.active_prop_template, "primary_measure_type", text="")
|
|
||||||
row.prop(props.active_prop_template, "template_type", text="")
|
|
||||||
|
|
||||||
if props.active_prop_template.template_type == "P_ENUMERATEDVALUE":
|
|
||||||
row = layout.row(align=True)
|
|
||||||
split = row.split(factor=0.2)
|
split = row.split(factor=0.2)
|
||||||
c = split.column()
|
c = split.column()
|
||||||
c.label(
|
c.label(
|
||||||
@@ -112,10 +100,10 @@ class BIM_PT_pset_template(Panel):
|
|||||||
c = split.column()
|
c = split.column()
|
||||||
box = c.box()
|
box = c.box()
|
||||||
grid = box.column_flow(columns=4)
|
grid = box.column_flow(columns=4)
|
||||||
value_name = props.active_prop_template.get_value_name()
|
value_name = self.props.active_prop_template.get_value_name()
|
||||||
r = grid.row()
|
r = grid.row()
|
||||||
r.operator("bim.add_prop_enum", text="Add Enum")
|
r.operator("bim.add_prop_enum", text="Add Enum")
|
||||||
for k, v in enumerate(props.active_prop_template.enum_values):
|
for k, v in enumerate(self.props.active_prop_template.enum_values):
|
||||||
r = grid.row(align=True)
|
r = grid.row(align=True)
|
||||||
r.prop(v, value_name, text="")
|
r.prop(v, value_name, text="")
|
||||||
op = r.operator("bim.delete_prop_enum", icon="X", text="")
|
op = r.operator("bim.delete_prop_enum", icon="X", text="")
|
||||||
@@ -127,12 +115,12 @@ class BIM_PT_pset_template(Panel):
|
|||||||
row.label(text=prop_template["PrimaryMeasureType"])
|
row.label(text=prop_template["PrimaryMeasureType"])
|
||||||
row.label(text=prop_template["TemplateType"])
|
row.label(text=prop_template["TemplateType"])
|
||||||
|
|
||||||
if props.active_prop_template_id and props.active_prop_template_id == prop_template_id:
|
if self.props.active_prop_template_id and self.props.active_prop_template_id == prop_template["id"]:
|
||||||
op = row.operator("bim.edit_prop_template", icon="CHECKMARK", text="")
|
op = row.operator("bim.edit_prop_template", icon="CHECKMARK", text="")
|
||||||
row.operator("bim.disable_editing_prop_template", icon="CANCEL", text="")
|
row.operator("bim.disable_editing_prop_template", icon="CANCEL", text="")
|
||||||
elif props.active_prop_template_id and props.active_prop_template_id != prop_template_id:
|
elif self.props.active_prop_template_id and self.props.active_prop_template_id != prop_template["id"]:
|
||||||
row.operator("bim.remove_prop_template", icon="X", text="").prop_template = prop_template_id
|
row.operator("bim.remove_prop_template", icon="X", text="").prop_template = prop_template["id"]
|
||||||
else:
|
else:
|
||||||
op = row.operator("bim.enable_editing_prop_template", icon="GREASEPENCIL", text="")
|
op = row.operator("bim.enable_editing_prop_template", icon="GREASEPENCIL", text="")
|
||||||
op.prop_template = prop_template_id
|
op.prop_template = prop_template["id"]
|
||||||
row.operator("bim.remove_prop_template", icon="X", text="").prop_template = prop_template_id
|
row.operator("bim.remove_prop_template", icon="X", text="").prop_template = prop_template["id"]
|
||||||
|
|||||||
@@ -150,6 +150,9 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
|
|||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(self, "should_play_chaching_sound")
|
row.prop(self, "should_play_chaching_sound")
|
||||||
|
|
||||||
|
row = layout.row()
|
||||||
|
row.prop(context.scene.BIMProjectProperties, "should_disable_undo_on_save")
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(context.scene.BIMModelProperties, "occurrence_name_style")
|
row.prop(context.scene.BIMModelProperties, "occurrence_name_style")
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
|
|||||||
Reference in New Issue
Block a user