Skip to content

Commit

Permalink
Fix IfcOpenShell#4072. IDS reports now include filename.
Browse files Browse the repository at this point in the history
  • Loading branch information
Moult committed Dec 4, 2023
1 parent 8b72929 commit ff0d6c8
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 19 deletions.
27 changes: 15 additions & 12 deletions src/blenderbim/blenderbim/bim/module/tester/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -46,15 +46,18 @@ def execute(self, context):
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()
Expand Down Expand Up @@ -131,27 +134,27 @@ def execute(self, context):
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"
Expand All @@ -166,13 +169,13 @@ def execute(self, context):
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"}

Expand Down
2 changes: 2 additions & 0 deletions src/ifcpatch/ifcpatch/recipes/ConvertNestToAggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
25 changes: 19 additions & 6 deletions src/ifctester/ifctester/ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def __init__(
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"
Expand Down Expand Up @@ -112,7 +116,12 @@ def to_xml(self, filepath="output.xml"):
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:
Expand Down Expand Up @@ -175,8 +184,12 @@ def parse(self, ids_dict):
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):
Expand Down Expand Up @@ -205,7 +218,7 @@ def validate(self, ifc_file, filter_version=False):
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):
Expand All @@ -225,7 +238,7 @@ def validate(self, ifc_file, filter_version=False):
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:
Expand All @@ -249,7 +262,7 @@ def validate(self, ifc_file, filter_version=False):
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:
Expand Down
2 changes: 2 additions & 0 deletions src/ifctester/ifctester/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ def __init__(self, ids):
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
Expand Down
2 changes: 1 addition & 1 deletion src/ifctester/ifctester/templates/report.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down

0 comments on commit ff0d6c8

Please sign in to comment.