Fix #4072. IDS reports now include filename.

This commit is contained in:
Dion Moult
2023-12-04 17:26:57 +11:00
parent 31e912cf12
commit b9f33e06bd
5 changed files with 39 additions and 19 deletions
@@ -46,15 +46,18 @@ class ExecuteIfcTester(bpy.types.Operator, tool.Ifc.Operator):
start = time.time() start = time.time()
output = os.path.join(dirpath, "{}.html".format(props.specs)) output = os.path.join(dirpath, "{}.html".format(props.specs))
filepath = None
if props.should_load_from_memory and tool.Ifc.get(): if props.should_load_from_memory and tool.Ifc.get():
ifc = tool.Ifc.get() ifc = tool.Ifc.get()
filepath = tool.Ifc.get_path()
else: else:
ifc = ifcopenshell.open(props.ifc_file) ifc = ifcopenshell.open(props.ifc_file)
filepath = props.ifc_file
specs = ifctester.ids.open(props.specs) specs = ifctester.ids.open(props.specs)
print("Finished loading:", time.time() - start) print("Finished loading:", time.time() - start)
start = time.time() start = time.time()
specs.validate(ifc) specs.validate(ifc, filepath=filepath)
print("Finished validating:", time.time() - start) print("Finished validating:", time.time() - start)
start = time.time() start = time.time()
@@ -142,16 +145,16 @@ class SelectRequirement(bpy.types.Operator):
area = next(area for area in context.screen.areas if area.type == "VIEW_3D") 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.color_type = "OBJECT"
area.spaces[0].shading.show_xray = True 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: for obj in context.scene.objects:
if obj.BIMObjectProperties.ifc_definition_id in failed_ids: if obj.BIMObjectProperties.ifc_definition_id in failed_ids:
obj.color = (1,0,0,1) obj.color = (1, 0, 0, 1)
else: else:
obj.color = (1,1,1,1) obj.color = (1, 1, 1, 1)
return {"FINISHED"} return {"FINISHED"}
class SelectFailedEntities(bpy.types.Operator): class SelectFailedEntities(bpy.types.Operator):
bl_idname = "bim.select_failed_entities" bl_idname = "bim.select_failed_entities"
bl_label = "Select Failed Entities" bl_label = "Select Failed Entities"
@@ -167,7 +170,7 @@ class SelectFailedEntities(bpy.types.Operator):
props.n_entities = len(failed_entities) props.n_entities = len(failed_entities)
props.has_entities = True if props.n_entities > 0 else False 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: for obj in context.scene.objects:
if obj.BIMObjectProperties.ifc_definition_id in failed_ids: if obj.BIMObjectProperties.ifc_definition_id in failed_ids:
obj.select_set(True) obj.select_set(True)
@@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with IfcPatch. If not, see <http://www.gnu.org/licenses/>. # along with IfcPatch. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
class Patcher: class Patcher:
def __init__(self, src, file, logger): def __init__(self, src, file, logger):
+16 -3
View File
@@ -55,6 +55,10 @@ class Ids:
purpose=None, purpose=None,
milestone=None, milestone=None,
): ):
# Not part of the IDS spec, but very useful in practice
self.filepath = None
self.filename = None
self.specifications = [] self.specifications = []
self.info = {} self.info = {}
self.info["title"] = title or "Untitled" 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) ET.ElementTree(get_schema().encode(self.asdict())).write(filepath, encoding="utf-8", xml_declaration=True)
return get_schema().is_valid(filepath) 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_pset.cache_clear()
get_psets.cache_clear() get_psets.cache_clear()
for specification in self.specifications: for specification in self.specifications:
@@ -175,8 +184,12 @@ class Specification:
self.minOccurs = ids_dict["@minOccurs"] self.minOccurs = ids_dict["@minOccurs"]
self.maxOccurs = ids_dict["@maxOccurs"] self.maxOccurs = ids_dict["@maxOccurs"]
self.ifcVersion = ids_dict["@ifcVersion"] self.ifcVersion = ids_dict["@ifcVersion"]
self.applicability = self.parse_clause(ids_dict["applicability"]) if ids_dict.get("applicability") is not None else [] self.applicability = (
self.requirements = self.parse_clause(ids_dict["requirements"]) if ids_dict.get("requirements") is not None else [] 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 return self
def parse_clause(self, clause): def parse_clause(self, clause):
+2
View File
@@ -163,6 +163,8 @@ class Json(Reporter):
def report(self): def report(self):
self.results["title"] = self.ids.info.get("title", "Untitled IDS") 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["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 = 0
total_specifications_pass = 0 total_specifications_pass = 0
total_requirements = 0 total_requirements = 0
@@ -71,7 +71,7 @@
<body> <body>
<header> <header>
<h1>{{title}}</h1> <h1>{{title}}</h1>
<p><strong>{{date}}</strong></p> <p><strong>{{#filename}}{{filename}}<br />{{/filename}}{{date}}</strong></p>
</header> </header>
<h2>Summary</h2> <h2>Summary</h2>
<div class="container"> <div class="container">