Skip to content

Commit 8e045d7

Browse files
authored
Add "hide empty Specifications" to Bonsai IFCTester (#7190)
* add filter * apply filter property * allow name filter * black . * add hide-skipped to html * rename prop * only hide optional specifications
1 parent 16fd614 commit 8e045d7

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

src/bonsai/bonsai/bim/module/tester/operator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ async def on_audit_ids(self, sid, data):
135135
try:
136136
request_id = data.get("id")
137137
ids_string = data.get("ids")
138+
props = tool.Tester.get_tester_props()
138139

139140
if not request_id:
140141
await self.emit("error", {"error": "No request ID provided"}, room=sid)
@@ -176,7 +177,7 @@ async def on_audit_ids(self, sid, data):
176177
json_report = json_reporter.to_string()
177178

178179
# HTML report
179-
html_reporter = ifctester.reporter.Html(ids)
180+
html_reporter = ifctester.reporter.Html(ids, hide_skipped=props.hide_skipped_specs)
180181
html_reporter.report()
181182
html_report = html_reporter.to_string()
182183

@@ -267,7 +268,7 @@ def execute_tester(self, ifc_data: ifcopenshell.file, ifc_path: str, specs_path:
267268
start = time.time()
268269

269270
if props.generate_html_report:
270-
engine = ifctester.reporter.Html(specs)
271+
engine = ifctester.reporter.Html(specs, props.hide_skipped_specs)
271272
engine.report()
272273
output_path = output.as_posix()
273274
engine.to_file(output_path)

src/bonsai/bonsai/bim/module/tester/prop.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class IfcTesterProperties(PropertyGroup):
8282
webapp_server_port: IntProperty(name="Webapp Server Port", default=0)
8383
webapp_is_running: BoolProperty(default=False, name="Webapp Is Running", options=set())
8484
websocket_server_port: IntProperty(name="WebSocket Server Port", default=0)
85+
hide_skipped_specs: BoolProperty(default=False, name="Hide skipped Specifications", options=set())
8586

8687
if TYPE_CHECKING:
8788
specs: MultipleFileSelect

src/bonsai/bonsai/bim/module/tester/ui.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def draw(self, context):
6262
row.prop(props, "generate_ods_report")
6363
row = self.layout.row()
6464
row.prop(props, "flag")
65-
65+
row = self.layout.row()
66+
row.prop(props, "hide_skipped_specs")
6667
if not tool.Ifc.get() or not props.should_load_from_memory:
6768
row = self.layout.row(align=True)
6869
props.ifc_files.layout_file_select(row, "*.ifc;*.ifczip;*.ifcxml", "IFC File(s)")
@@ -104,6 +105,9 @@ def draw(self, context):
104105
def draw_editable_ui(self, context: bpy.types.Context) -> None:
105106
props = tool.Tester.get_tester_props()
106107
specification = TesterData.data["specification"]
108+
is_skipped = specification["total_checks"] == 0 and specification["cardinality"] == "optional"
109+
if props.hide_skipped_specs and is_skipped:
110+
return
107111

108112
n_requirements = len(specification["requirements"])
109113

@@ -179,6 +183,34 @@ def draw_item(
179183
row.label(text=item.name, icon="CHECKMARK" if item.status else "CANCEL")
180184
row.label(text=item.description)
181185

186+
def filter_items(self, context: bpy.types.Context, data: IfcTesterProperties, propname: str):
187+
items = getattr(data, propname)
188+
filter_flags = [self.bitflag_filter_item] * len(items)
189+
190+
props = tool.Tester.get_tester_props()
191+
if props.hide_skipped_specs:
192+
for idx, item in enumerate(items):
193+
report = tool.Tester.report[idx]
194+
if report["total_checks"] != 0:
195+
filter_flags[idx] |= self.bitflag_filter_item
196+
else:
197+
filter_flags[idx] &= ~self.bitflag_filter_item
198+
199+
filter_name = self.filter_name
200+
if filter_name:
201+
name_filtered = bpy.types.UI_UL_list.filter_items_by_name(
202+
filter_name,
203+
self.bitflag_filter_item,
204+
items,
205+
"name",
206+
)
207+
if len(name_filtered) == len(filter_flags):
208+
for idx, flag in enumerate(name_filtered):
209+
if flag == 0:
210+
filter_flags[idx] &= ~self.bitflag_filter_item
211+
212+
return filter_flags, []
213+
182214

183215
class BIM_UL_tester_failed_entities(UIList):
184216
def draw_item(

src/ifctester/ifctester/reporter.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Results(TypedDict):
5555
date: str
5656
filepath: str
5757
filename: str
58+
hide_skipped: bool
5859
specifications: list[ResultsSpecification]
5960
status: bool
6061
total_specifications: int
@@ -236,9 +237,10 @@ def to_file(self, filepath: str) -> None:
236237

237238

238239
class Json(Reporter):
239-
def __init__(self, ids: Ids):
240+
def __init__(self, ids: Ids,hide_skipped = False):
240241
super().__init__(ids)
241242
self.results = Results()
243+
self.results["hide_skipped"] = hide_skipped
242244

243245
def report(self) -> Results:
244246
self.results["title"] = self.ids.info.get("title", "Untitled IDS")
@@ -435,14 +437,14 @@ def encode(self, obj):
435437

436438

437439
class Html(Json):
438-
def __init__(self, ids: Ids):
440+
def __init__(self, ids: Ids, hide_skipped: bool = False):
439441
self.entity_limit = 100
440442
super().__init__(ids)
443+
self.results["hide_skipped"] = hide_skipped
441444

442445
def report(self) -> None:
443446
super().report()
444447
for spec in self.results["specifications"]:
445-
print("checking", spec["cardinality"])
446448
if spec["cardinality"] == "optional" and spec["total_checks"] == 0:
447449
spec["is_skipped"] = True
448450
spec["is_prohibited"] = spec["cardinality"] == "prohibited"

src/ifctester/ifctester/templates/report.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
}
3535
body { font-family: 'Arial', sans-serif; padding: 10px 40px; }
3636
section { padding: 15px; border-radius: 5px; border: 1px solid #eee; margin-bottom: 15px; }
37+
{{#hide_skipped}}
38+
.specification.is-skipped { display: none; }
39+
{{/hide_skipped}}
3740
section>h2 { margin-top: 0px; }
3841
span.time { color: #999; font-style: italic; float: right; }
3942
span.step-time { float: right; color: #555; font-size: 0.8em; font-style: italic; }
@@ -96,7 +99,7 @@ <h2>Summary</h2>
9699
</p>
97100
<hr>
98101
{{#specifications}}
99-
<section style="clear: both; overflow: hidden;">
102+
<section class="specification{{#is_skipped}} is-skipped{{/is_skipped}}" style="clear: both; overflow: hidden;">
100103
<div class="info">
101104
<h2>{{name}}</h2>
102105
{{#description}}

0 commit comments

Comments
 (0)