BBIM IfcTester - option to generate ODS report

https://i.imgur.com/0JyXVK6.png
This commit is contained in:
Andrej730
2024-03-13 16:08:27 +05:00
parent e87ca960e8
commit 22c95828ce
4 changed files with 20 additions and 10 deletions
@@ -27,7 +27,7 @@ import ifctester.reporter
import ifcopenshell
import blenderbim.tool as tool
import blenderbim.bim.handler
from blenderbim.bim.module.tester.data import TesterData
from pathlib import Path
class ExecuteIfcTester(bpy.types.Operator, tool.Ifc.Operator):
@@ -44,7 +44,7 @@ class ExecuteIfcTester(bpy.types.Operator, tool.Ifc.Operator):
with tempfile.TemporaryDirectory() as dirpath:
start = time.time()
output = os.path.join(dirpath, "{}.html".format(props.specs))
output = Path(os.path.join(dirpath, "{}.html".format(props.specs)))
filepath = None
if props.should_load_from_memory and tool.Ifc.get():
@@ -65,8 +65,15 @@ class ExecuteIfcTester(bpy.types.Operator, tool.Ifc.Operator):
if props.generate_html_report:
engine = ifctester.reporter.Html(specs)
engine.report()
engine.to_file(output)
webbrowser.open("file://" + output)
output_path = output.as_posix()
engine.to_file(output_path)
webbrowser.open(f"file://{output_path}")
if props.generate_ods_report:
engine = ifctester.reporter.Ods(specs)
engine.report()
output_path = output.with_suffix(".ods").as_posix()
engine.to_file(output_path)
report = None
report = ifctester.reporter.Json(specs).report()["specifications"]
@@ -52,6 +52,7 @@ class IfcTesterProperties(PropertyGroup):
ifc_file: StringProperty(default="", name="IFC File")
should_load_from_memory: BoolProperty(default=False, name="Load from Memory")
generate_html_report: BoolProperty(default=False, name="Generate HTML report")
generate_ods_report: BoolProperty(default=False, name="Generate ODS report")
flag: BoolProperty(default=False, name="Flag Failed Entities")
active_specification_index: IntProperty(name="Active Specification Index", update=update_active_specification_index)
old_index: IntProperty(name="", default=0)
@@ -44,6 +44,8 @@ class BIM_PT_tester(Panel):
row = self.layout.row()
row.prop(props, "generate_html_report")
row = self.layout.row()
row.prop(props, "generate_ods_report")
row = self.layout.row()
row.prop(props, "flag")
if not tool.Ifc.get() or not props.should_load_from_memory:
+6 -6
View File
@@ -150,7 +150,7 @@ class Txt(Console):
def to_string(self):
print(self.text)
def to_file(self, filepath):
def to_file(self, filepath: str) -> None:
with open(filepath, "w", encoding="utf-8") as outfile:
return outfile.write(self.text)
@@ -273,7 +273,7 @@ class Json(Reporter):
return json.dumps(self.results)
def to_file(self, filepath):
def to_file(self, filepath: str) -> None:
import json
with open(filepath, "w", encoding="utf-8") as outfile:
@@ -302,7 +302,7 @@ class Html(Json):
with open(os.path.join(cwd, "templates", "report.html"), "r") as file:
return pystache.render(file.read(), self.results)
def to_file(self, filepath):
def to_file(self, filepath: str) -> None:
import pystache
with open(os.path.join(cwd, "templates", "report.html"), "r") as file:
@@ -321,7 +321,7 @@ class Ods(Json):
}
self.results = {}
def to_file(self, filepath):
def to_file(self, filepath: str) -> None:
from odf.opendocument import OpenDocumentSpreadsheet
from odf.style import Style, TableCellProperties
from odf.table import Table, TableRow, TableCell
@@ -421,7 +421,7 @@ class Ods(Json):
table.addElement(tr)
self.doc.spreadsheet.addElement(table)
self.doc.save(filepath, True)
self.doc.save(filepath, addsuffix=filepath.lower().endswith(".ods"))
class Bcf(Json):
@@ -430,7 +430,7 @@ class Bcf(Json):
{"reason": requirement.failed_reasons[i], "element": e} for i, e in enumerate(requirement.failed_entities)
]
def to_file(self, filepath):
def to_file(self, filepath: str) -> None:
from bcf.v2.bcfxml import BcfXml
unit_scale = None