Improve prop search v2 (#2262)

* Minor fixes

* Fix #2257 : enums with a different id and name now correctly show the name in the search field

* Add prop search to template_type
This commit is contained in:
Gorgious56
2022-07-04 23:09:03 +02:00
committed by GitHub
parent 22cb7b3b67
commit c7272065e6
7 changed files with 98 additions and 82 deletions
@@ -93,6 +93,7 @@ classes = [
operator.SelectSchemaDir, operator.SelectSchemaDir,
operator.SelectURIAttribute, operator.SelectURIAttribute,
prop.StrProperty, prop.StrProperty,
operator.BIM_OT_enum_property_search, # /!\ Register AFTER prop.StrProperty
prop.ObjProperty, prop.ObjProperty,
prop.Attribute, prop.Attribute,
prop.ModuleVisibility, prop.ModuleVisibility,
@@ -94,65 +94,70 @@ def get_primary_measure_type(self, context):
return PsetTemplatesData.data["primary_measure_type"] return PsetTemplatesData.data["primary_measure_type"]
def get_template_type(self, context):
return [
(
"PSET_TYPEDRIVENONLY",
"Pset - IfcTypeObject",
"The property sets defined by this IfcPropertySetTemplate can only be assigned to subtypes of IfcTypeObject.",
),
(
"PSET_TYPEDRIVENOVERRIDE",
"Pset - IfcTypeObject - Override",
"The property sets defined by this IfcPropertySetTemplate can only be assigned to subtypes of IfcTypeObject.",
),
(
"PSET_OCCURRENCEDRIVEN",
"Pset - IfcObject",
"The property sets defined by this IfcPropertySetTemplate can only be assigned to subtypes of IfcObject.",
),
(
"PSET_PERFORMANCEDRIVEN",
"Pset - IfcPerformanceHistory",
"The property sets defined by this IfcPropertySetTemplate can only be assigned to IfcPerformanceHistory.",
),
(
"QTO_TYPEDRIVENONLY",
"Qto - IfcTypeObject",
"The element quantity defined by this IfcPropertySetTemplate can only be assigned to subtypes of IfcTypeObject.",
),
(
"QTO_TYPEDRIVENOVERRIDE",
"Qto - IfcTypeObject - Override",
"The element quantity defined by this IfcPropertySetTemplate can be assigned to subtypes of IfcTypeObject and can be overridden by an element quantity with same name at subtypes of IfcObject.",
),
(
"QTO_OCCURRENCEDRIVEN",
"Qto - IfcObject",
"The element quantity defined by this IfcPropertySetTemplate can only be assigned to subtypes of IfcObject.",
),
(
"NOTDEFINED",
"Not defined",
"No restriction provided, the property sets defined by this IfcPropertySetTemplate can be assigned to any entity, if not otherwise restricted by the ApplicableEntity attribute.",
),
]
class PsetTemplate(PropertyGroup): class PsetTemplate(PropertyGroup):
global_id: StringProperty(name="Global ID") global_id: StringProperty(name="Global ID")
name: StringProperty(name="Name") name: StringProperty(name="Name")
description: StringProperty(name="Description") description: StringProperty(name="Description")
template_type: EnumProperty( template_type: EnumProperty(items=get_template_type, name="Template Type")
items=[
(
"PSET_TYPEDRIVENONLY",
"Pset - IfcTypeObject",
"The property sets defined by this IfcPropertySetTemplate can only be assigned to subtypes of IfcTypeObject.",
),
(
"PSET_TYPEDRIVENOVERRIDE",
"Pset - IfcTypeObject - Override",
"The property sets defined by this IfcPropertySetTemplate can only be assigned to subtypes of IfcTypeObject.",
),
(
"PSET_OCCURRENCEDRIVEN",
"Pset - IfcObject",
"The property sets defined by this IfcPropertySetTemplate can only be assigned to subtypes of IfcObject.",
),
(
"PSET_PERFORMANCEDRIVEN",
"Pset - IfcPerformanceHistory",
"The property sets defined by this IfcPropertySetTemplate can only be assigned to IfcPerformanceHistory.",
),
(
"QTO_TYPEDRIVENONLY",
"Qto - IfcTypeObject",
"The element quantity defined by this IfcPropertySetTemplate can only be assigned to subtypes of IfcTypeObject.",
),
(
"QTO_TYPEDRIVENOVERRIDE",
"Qto - IfcTypeObject - Override",
"The element quantity defined by this IfcPropertySetTemplate can be assigned to subtypes of IfcTypeObject and can be overridden by an element quantity with same name at subtypes of IfcObject.",
),
(
"QTO_OCCURRENCEDRIVEN",
"Qto - IfcObject",
"The element quantity defined by this IfcPropertySetTemplate can only be assigned to subtypes of IfcObject.",
),
(
"NOTDEFINED",
"Not defined",
"No restriction provided, the property sets defined by this IfcPropertySetTemplate can be assigned to any entity, if not otherwise restricted by the ApplicableEntity attribute.",
),
],
name="Template Type",
)
applicable_entity: StringProperty(name="Applicable Entity") applicable_entity: StringProperty(name="Applicable Entity")
getter_enum = {
"template_type": lambda self, context: get_template_type(self, context),
}
class EnumerationValues(PropertyGroup): class EnumerationValues(PropertyGroup):
string_value: StringProperty(name="Value") string_value: StringProperty(name="Value")
bool_value: BoolProperty(name="Value") bool_value: BoolProperty(name="Value")
int_value: IntProperty(name="Value") int_value: IntProperty(name="Value")
float_value: FloatProperty(name="Value") float_value: FloatProperty(name="Value")
class PropTemplate(PropertyGroup): class PropTemplate(PropertyGroup):
global_id: StringProperty(name="Global ID") global_id: StringProperty(name="Global ID")
name: StringProperty(name="Name") name: StringProperty(name="Name")
@@ -170,7 +175,6 @@ class PropTemplate(PropertyGroup):
"primary_measure_type": get_primary_measure_type, "primary_measure_type": get_primary_measure_type,
} }
def get_value_name(self): def get_value_name(self):
ifc_data_type = IfcStore.get_schema().declaration_by_name(self.primary_measure_type) ifc_data_type = IfcStore.get_schema().declaration_by_name(self.primary_measure_type)
data_type = ifcopenshell.util.attribute.get_primitive_type(ifc_data_type) data_type = ifcopenshell.util.attribute.get_primitive_type(ifc_data_type)
@@ -194,7 +198,7 @@ class BIMPsetTemplateProperties(PropertyGroup):
active_pset_template: PointerProperty(type=PsetTemplate) active_pset_template: PointerProperty(type=PsetTemplate)
active_prop_template: PointerProperty(type=PropTemplate) active_prop_template: PointerProperty(type=PropTemplate)
new_template_filename: StringProperty("New TemplateFileName") new_template_filename: StringProperty("New TemplateFileName")
getter_enum = { getter_enum = {
"pset_template_files": getPsetTemplateFiles, "pset_template_files": getPsetTemplateFiles,
"pset_templates": getPsetTemplates, "pset_templates": getPsetTemplates,
@@ -72,8 +72,7 @@ class BIM_PT_pset_template(Panel):
row.prop(props.active_pset_template, "name") row.prop(props.active_pset_template, "name")
row = layout.row() row = layout.row()
row.prop(props.active_pset_template, "description") row.prop(props.active_pset_template, "description")
row = layout.row() prop_with_search(layout, props.active_pset_template, "template_type")
row.prop(props.active_pset_template, "template_type")
row = layout.row() row = layout.row()
row.prop(props.active_pset_template, "applicable_entity") row.prop(props.active_pset_template, "applicable_entity")
else: else:
@@ -26,7 +26,6 @@ classes = (
operator.EnableReassignClass, operator.EnableReassignClass,
operator.ReassignClass, operator.ReassignClass,
operator.UnlinkObject, operator.UnlinkObject,
operator.BIM_OT_enum_property_search,
prop.BIMRootProperties, prop.BIMRootProperties,
ui.BIM_PT_class, ui.BIM_PT_class,
) )
@@ -31,8 +31,6 @@ import blenderbim.core.root as core
import blenderbim.tool as tool import blenderbim.tool as tool
from ifcopenshell.api.void.data import Data as VoidData from ifcopenshell.api.void.data import Data as VoidData
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.module.root.prop import get_contexts
from blenderbim.bim.prop import StrProperty
class Operator: class Operator:
@@ -128,12 +126,13 @@ class AssignClass(bpy.types.Operator, Operator):
ifc_representation_class: bpy.props.StringProperty() ifc_representation_class: bpy.props.StringProperty()
def _execute(self, context): def _execute(self, context):
props = context.scene.BIMRootProperties
objects = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects objects = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects
ifc_class = self.ifc_class or context.scene.BIMRootProperties.ifc_class ifc_class = self.ifc_class or props.ifc_class
predefined_type = self.userdefined_type if self.predefined_type == "USERDEFINED" else self.predefined_type predefined_type = self.userdefined_type if self.predefined_type == "USERDEFINED" else self.predefined_type
ifc_context = self.context_id ifc_context = self.context_id
if not ifc_context and get_contexts(self, context): if not ifc_context and props.getter_enum["contexts"](props, context):
ifc_context = int(context.scene.BIMRootProperties.contexts or "0") or None ifc_context = int(props.contexts or "0") or None
if ifc_context: if ifc_context:
ifc_context = tool.Ifc.get().by_id(ifc_context) ifc_context = tool.Ifc.get().by_id(ifc_context)
active_object = context.active_object active_object = context.active_object
@@ -190,27 +189,3 @@ class CopyClass(bpy.types.Operator, Operator):
for obj in objects: for obj in objects:
core.copy_class(tool.Ifc, tool.Collector, tool.Geometry, tool.Root, obj=obj) core.copy_class(tool.Ifc, tool.Collector, tool.Geometry, tool.Root, obj=obj)
blenderbim.bim.handler.purge_module_data() blenderbim.bim.handler.purge_module_data()
class BIM_OT_enum_property_search(bpy.types.Operator):
bl_idname = "bim.enum_property_search"
bl_label = "Search For Property"
bl_options = {"REGISTER", "UNDO"}
prop_name: bpy.props.StringProperty()
collection: bpy.props.CollectionProperty(type=StrProperty)
def invoke(self, context, event):
self.data = context.data
getter = self.data.getter_enum.get(self.prop_name, None)
if getter is None:
return {"FINISHED"}
self.collection.clear()
for item in getter(self.data, context):
self.collection.add().name = item[0]
return context.window_manager.invoke_props_dialog(self)
def execute(self, context):
return {"FINISHED"}
def draw(self, context):
self.layout.prop_search(self.data, self.prop_name, self, "collection")
@@ -21,7 +21,6 @@ import ifcopenshell
import ifcopenshell.util.schema import ifcopenshell.util.schema
from blenderbim.bim.module.root.data import IfcClassData from blenderbim.bim.module.root.data import IfcClassData
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.prop import StrProperty
from bpy.types import PropertyGroup from bpy.types import PropertyGroup
from bpy.props import ( from bpy.props import (
PointerProperty, PointerProperty,
+39
View File
@@ -25,6 +25,7 @@ import blenderbim.bim.handler
import blenderbim.tool as tool import blenderbim.tool as tool
from . import schema from . import schema
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.prop import StrProperty
from blenderbim.bim.ui import IFCFileSelector from blenderbim.bim.ui import IFCFileSelector
from mathutils import Vector, Matrix, Euler from mathutils import Vector, Matrix, Euler
from math import radians from math import radians
@@ -523,3 +524,41 @@ class ConfigureVisibility(bpy.types.Operator):
def execute(self, context): def execute(self, context):
return {"FINISHED"} return {"FINISHED"}
def update_enum_property_search_prop(self, context):
for i, prop in enumerate(self.collection_name):
if prop.name == self.dummy_name:
setattr(context.data, self.prop_name, self.collection_identifier[i].name)
class BIM_OT_enum_property_search(bpy.types.Operator):
bl_idname = "bim.enum_property_search"
bl_label = "Search For Property"
bl_options = {"REGISTER", "UNDO"}
dummy_name: bpy.props.StringProperty(name="Property", update=update_enum_property_search_prop)
collection_name: bpy.props.CollectionProperty(type=StrProperty)
collection_identifier: bpy.props.CollectionProperty(type=StrProperty)
prop_name: bpy.props.StringProperty()
def invoke(self, context, event):
self.data = context.data
getter = self.data.getter_enum.get(self.prop_name, None)
if getter is None:
return {"FINISHED"}
self.collection_name.clear()
self.collection_identifier.clear()
for item in getter(self.data, context):
self.collection_identifier.add().name = item[0]
if item[0] == getattr(self.data, self.prop_name):
self.dummy_name = item[1] # We found the current enum value
self.collection_name.add().name = item[1]
return context.window_manager.invoke_props_dialog(self)
def execute(self, context):
return {"FINISHED"}
def draw(self, context):
# Mandatory to access context.data in update :
self.layout.context_pointer_set(name="data", data=self.data)
self.layout.prop_search(self, "dummy_name", self, "collection_name")