mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Advanced users can now directly edit search filter queries.
This commit is contained in:
@@ -277,15 +277,17 @@ def draw_filter(layout, props, data, module):
|
||||
if not data.is_loaded:
|
||||
data.load()
|
||||
|
||||
row = layout.row(align=True)
|
||||
row.label(text=f"{len(data.data['saved_searches'])} Saved Searches")
|
||||
if tool.Ifc.get():
|
||||
row = layout.row(align=True)
|
||||
row.label(text=f"{len(data.data['saved_searches'])} Saved Searches")
|
||||
|
||||
if data.data["saved_searches"]:
|
||||
row.operator("bim.load_search", text="", icon="IMPORT").module = module
|
||||
row.operator("bim.save_search", text="", icon="EXPORT").module = module
|
||||
if data.data["saved_searches"]:
|
||||
row.operator("bim.load_search", text="", icon="IMPORT").module = module
|
||||
row.operator("bim.save_search", text="", icon="EXPORT").module = module
|
||||
|
||||
row = layout.row(align=True)
|
||||
row.operator("bim.add_filter_group", text="Add Search Group", icon="ADD").module = module
|
||||
row.operator("bim.edit_filter_query", text="", icon="FILTER").module = module
|
||||
|
||||
for i, filter_group in enumerate(props.filter_groups):
|
||||
box = layout.box()
|
||||
|
||||
@@ -26,6 +26,7 @@ classes = (
|
||||
operator.AddFilterGroup,
|
||||
operator.AddToIfcGroup,
|
||||
operator.ColourByProperty,
|
||||
operator.EditFilterQuery,
|
||||
operator.FilterModelElements,
|
||||
operator.IfcSelector,
|
||||
operator.LoadColourscheme,
|
||||
|
||||
@@ -40,6 +40,8 @@ class SearchData:
|
||||
|
||||
@classmethod
|
||||
def saved_searches(cls):
|
||||
if not tool.Ifc.get():
|
||||
return []
|
||||
groups = tool.Ifc.get().by_type("IfcGroup")
|
||||
results = []
|
||||
for group in groups:
|
||||
|
||||
@@ -151,6 +151,44 @@ class SelectFilterElements(bpy.types.Operator):
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class EditFilterQuery(Operator, tool.Ifc.Operator):
|
||||
bl_idname = "bim.edit_filter_query"
|
||||
bl_label = "Edit Filter Query"
|
||||
bl_description = "Edit the underlying filter query for advanced users"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
query: StringProperty(name="Query")
|
||||
module: StringProperty()
|
||||
|
||||
def _execute(self, context):
|
||||
if self.query == self.old_query:
|
||||
return
|
||||
|
||||
if self.module == "search":
|
||||
props = context.scene.BIMSearchProperties
|
||||
elif self.module == "csv":
|
||||
props = context.scene.CsvProperties
|
||||
|
||||
try:
|
||||
tool.Search.import_filter_query(self.query, props.filter_groups)
|
||||
except:
|
||||
return
|
||||
|
||||
def draw(self, context):
|
||||
row = self.layout.row()
|
||||
row.prop(self, "query", text="")
|
||||
|
||||
def invoke(self, context, event):
|
||||
if self.module == "search":
|
||||
props = context.scene.BIMSearchProperties
|
||||
elif self.module == "csv":
|
||||
props = context.scene.CsvProperties
|
||||
|
||||
self.query = tool.Search.export_filter_query(props.filter_groups)
|
||||
self.old_query = self.query
|
||||
|
||||
return context.window_manager.invoke_props_dialog(self)
|
||||
|
||||
|
||||
class Search(Operator):
|
||||
bl_idname = "bim.search"
|
||||
bl_label = "Search"
|
||||
@@ -223,7 +261,7 @@ class LoadSearch(Operator, tool.Ifc.Operator):
|
||||
elif self.module == "csv":
|
||||
props = context.scene.CsvProperties
|
||||
group = tool.Ifc.get().by_id(int(context.scene.BIMSearchProperties.saved_searches))
|
||||
query = tool.Search.import_filter_query(group, props.filter_groups)
|
||||
query = tool.Search.import_filter_query(tool.Search.get_group_query(group), props.filter_groups)
|
||||
|
||||
def draw(self, context):
|
||||
props = context.scene.BIMSearchProperties
|
||||
|
||||
@@ -9,8 +9,11 @@ from ifcopenshell.util.selector import Selector
|
||||
|
||||
class Search(blenderbim.core.tool.Search):
|
||||
@classmethod
|
||||
def import_filter_query(cls, group, filter_groups):
|
||||
query = json.loads(group.Description)["query"]
|
||||
def get_group_query(cls, group):
|
||||
return json.loads(group.Description)["query"]
|
||||
|
||||
@classmethod
|
||||
def import_filter_query(cls, query, filter_groups):
|
||||
filter_groups.clear()
|
||||
transformer = ImportFilterQueryTransformer(filter_groups)
|
||||
transformer.transform(ifcopenshell.util.selector.filter_elements_grammar.parse(query))
|
||||
|
||||
Reference in New Issue
Block a user