Fix #4072. IDS reports now include filename.

This commit is contained in:
Dion Moult
2023-12-04 17:26:57 +11:00
parent 8b72929d22
commit ff0d6c810f
5 changed files with 39 additions and 19 deletions
@@ -16,7 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import os
import os
import bpy
import time
import tempfile
@@ -46,15 +46,18 @@ class ExecuteIfcTester(bpy.types.Operator, tool.Ifc.Operator):
start = time.time()
output = os.path.join(dirpath, "{}.html".format(props.specs))
filepath = None
if props.should_load_from_memory and tool.Ifc.get():
ifc = tool.Ifc.get()
filepath = tool.Ifc.get_path()
else:
ifc = ifcopenshell.open(props.ifc_file)
filepath = props.ifc_file
specs = ifctester.ids.open(props.specs)
print("Finished loading:", time.time() - start)
start = time.time()
specs.validate(ifc)
specs.validate(ifc, filepath=filepath)
print("Finished validating:", time.time() - start)
start = time.time()
@@ -131,27 +134,27 @@ class SelectRequirement(bpy.types.Operator):
props.n_entities = len(failed_entities)
props.has_entities = True if props.n_entities > 0 else False
props.failed_entities.clear()
for e in failed_entities:
new_entity = props.failed_entities.add()
new_entity.ifc_id = e["id"]
new_entity.element = f'{e["class"]} | {e["name"]}'
new_entity.reason = e["reason"]
if props.flag:
area = next(area for area in context.screen.areas if area.type == "VIEW_3D")
area.spaces[0].shading.color_type = "OBJECT"
area.spaces[0].shading.show_xray = True
failed_ids = [ e["id"] for e in failed_entities ]
failed_ids = [e["id"] for e in failed_entities]
for obj in context.scene.objects:
if obj.BIMObjectProperties.ifc_definition_id in failed_ids:
obj.color = (1,0,0,1)
obj.color = (1, 0, 0, 1)
else:
obj.color = (1,1,1,1)
obj.color = (1, 1, 1, 1)
return {"FINISHED"}
class SelectFailedEntities(bpy.types.Operator):
bl_idname = "bim.select_failed_entities"
bl_label = "Select Failed Entities"
@@ -166,13 +169,13 @@ class SelectFailedEntities(bpy.types.Operator):
failed_entities = report[self.spec_index]["requirements"][self.req_index]["failed_entities"]
props.n_entities = len(failed_entities)
props.has_entities = True if props.n_entities > 0 else False
failed_ids = [ e["id"] for e in failed_entities ]
failed_ids = [e["id"] for e in failed_entities]
for obj in context.scene.objects:
if obj.BIMObjectProperties.ifc_definition_id in failed_ids:
obj.select_set(True)
else:
obj.select_set(False)
obj.select_set(False)
return {"FINISHED"}
@@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with IfcPatch. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
class Patcher:
def __init__(self, src, file, logger):
+19 -6
View File
@@ -55,6 +55,10 @@ class Ids:
purpose=None,
milestone=None,
):
# Not part of the IDS spec, but very useful in practice
self.filepath = None
self.filename = None
self.specifications = []
self.info = {}
self.info["title"] = title or "Untitled"
@@ -112,7 +116,12 @@ class Ids:
ET.ElementTree(get_schema().encode(self.asdict())).write(filepath, encoding="utf-8", xml_declaration=True)
return get_schema().is_valid(filepath)
def validate(self, ifc_file, filter_version=False):
def validate(self, ifc_file, filter_version=False, filepath=None):
if filepath:
self.filepath = filepath
self.filename = os.path.basename(filepath)
else:
self.filepath = self.filename = None
get_pset.cache_clear()
get_psets.cache_clear()
for specification in self.specifications:
@@ -175,8 +184,12 @@ class Specification:
self.minOccurs = ids_dict["@minOccurs"]
self.maxOccurs = ids_dict["@maxOccurs"]
self.ifcVersion = ids_dict["@ifcVersion"]
self.applicability = self.parse_clause(ids_dict["applicability"]) if ids_dict.get("applicability") is not None else []
self.requirements = self.parse_clause(ids_dict["requirements"]) if ids_dict.get("requirements") is not None else []
self.applicability = (
self.parse_clause(ids_dict["applicability"]) if ids_dict.get("applicability") is not None else []
)
self.requirements = (
self.parse_clause(ids_dict["requirements"]) if ids_dict.get("requirements") is not None else []
)
return self
def parse_clause(self, clause):
@@ -205,7 +218,7 @@ class Specification:
return
elements = None
# This is a broadphase filter of applicability. We almost never want to
# test every single class in an IFC model.
for i, facet in enumerate(self.applicability):
@@ -225,7 +238,7 @@ class Specification:
for facet in self.requirements:
result = facet(element)
if self.maxOccurs == 0:
prohibited = bool(result)
prohibited = bool(result)
else:
prohibited = not bool(result)
if prohibited:
@@ -249,7 +262,7 @@ class Specification:
facet.status = False
elif self.failed_entities:
self.status = False
elif self.minOccurs == 0 and self.maxOccurs != 0:
elif self.minOccurs == 0 and self.maxOccurs != 0:
if self.failed_entities:
self.status = False
elif self.maxOccurs == 0:
+2
View File
@@ -163,6 +163,8 @@ class Json(Reporter):
def report(self):
self.results["title"] = self.ids.info.get("title", "Untitled IDS")
self.results["date"] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
self.results["filepath"] = self.ids.filepath
self.results["filename"] = self.ids.filename
total_specifications = 0
total_specifications_pass = 0
total_requirements = 0
@@ -71,7 +71,7 @@
<body>
<header>
<h1>{{title}}</h1>
<p><strong>{{date}}</strong></p>
<p><strong>{{#filename}}{{filename}}<br />{{/filename}}{{date}}</strong></p>
</header>
<h2>Summary</h2>
<div class="container">