mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-23 10:22:47 +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:
|
if not data.is_loaded:
|
||||||
data.load()
|
data.load()
|
||||||
|
|
||||||
row = layout.row(align=True)
|
if tool.Ifc.get():
|
||||||
row.label(text=f"{len(data.data['saved_searches'])} Saved Searches")
|
row = layout.row(align=True)
|
||||||
|
row.label(text=f"{len(data.data['saved_searches'])} Saved Searches")
|
||||||
|
|
||||||
if data.data["saved_searches"]:
|
if data.data["saved_searches"]:
|
||||||
row.operator("bim.load_search", text="", icon="IMPORT").module = module
|
row.operator("bim.load_search", text="", icon="IMPORT").module = module
|
||||||
row.operator("bim.save_search", text="", icon="EXPORT").module = module
|
row.operator("bim.save_search", text="", icon="EXPORT").module = module
|
||||||
|
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.operator("bim.add_filter_group", text="Add Search Group", icon="ADD").module = module
|
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):
|
for i, filter_group in enumerate(props.filter_groups):
|
||||||
box = layout.box()
|
box = layout.box()
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ classes = (
|
|||||||
operator.AddFilterGroup,
|
operator.AddFilterGroup,
|
||||||
operator.AddToIfcGroup,
|
operator.AddToIfcGroup,
|
||||||
operator.ColourByProperty,
|
operator.ColourByProperty,
|
||||||
|
operator.EditFilterQuery,
|
||||||
operator.FilterModelElements,
|
operator.FilterModelElements,
|
||||||
operator.IfcSelector,
|
operator.IfcSelector,
|
||||||
operator.LoadColourscheme,
|
operator.LoadColourscheme,
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ class SearchData:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def saved_searches(cls):
|
def saved_searches(cls):
|
||||||
|
if not tool.Ifc.get():
|
||||||
|
return []
|
||||||
groups = tool.Ifc.get().by_type("IfcGroup")
|
groups = tool.Ifc.get().by_type("IfcGroup")
|
||||||
results = []
|
results = []
|
||||||
for group in groups:
|
for group in groups:
|
||||||
|
|||||||
@@ -151,6 +151,44 @@ class SelectFilterElements(bpy.types.Operator):
|
|||||||
return {"FINISHED"}
|
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):
|
class Search(Operator):
|
||||||
bl_idname = "bim.search"
|
bl_idname = "bim.search"
|
||||||
bl_label = "Search"
|
bl_label = "Search"
|
||||||
@@ -223,7 +261,7 @@ class LoadSearch(Operator, tool.Ifc.Operator):
|
|||||||
elif self.module == "csv":
|
elif self.module == "csv":
|
||||||
props = context.scene.CsvProperties
|
props = context.scene.CsvProperties
|
||||||
group = tool.Ifc.get().by_id(int(context.scene.BIMSearchProperties.saved_searches))
|
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):
|
def draw(self, context):
|
||||||
props = context.scene.BIMSearchProperties
|
props = context.scene.BIMSearchProperties
|
||||||
|
|||||||
@@ -9,8 +9,11 @@ from ifcopenshell.util.selector import Selector
|
|||||||
|
|
||||||
class Search(blenderbim.core.tool.Search):
|
class Search(blenderbim.core.tool.Search):
|
||||||
@classmethod
|
@classmethod
|
||||||
def import_filter_query(cls, group, filter_groups):
|
def get_group_query(cls, group):
|
||||||
query = json.loads(group.Description)["query"]
|
return json.loads(group.Description)["query"]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def import_filter_query(cls, query, filter_groups):
|
||||||
filter_groups.clear()
|
filter_groups.clear()
|
||||||
transformer = ImportFilterQueryTransformer(filter_groups)
|
transformer = ImportFilterQueryTransformer(filter_groups)
|
||||||
transformer.transform(ifcopenshell.util.selector.filter_elements_grammar.parse(query))
|
transformer.transform(ifcopenshell.util.selector.filter_elements_grammar.parse(query))
|
||||||
|
|||||||
Reference in New Issue
Block a user