From 0668eadc36606e1676cdb56a12d05edc80255bf8 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 3 Sep 2022 10:48:46 +1000 Subject: [PATCH] IDS doc generator now also generates a sample IDS file --- src/blenderbim/pytest.ini | 1 + .../api/classification/add_reference.py | 2 +- src/ifctester/test/ids_doc_generator.py | 31 +++++++++++++++++-- src/ifctester/test/test_facet.py | 4 +-- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/blenderbim/pytest.ini b/src/blenderbim/pytest.ini index e23cab44d1..7c45fa340d 100644 --- a/src/blenderbim/pytest.ini +++ b/src/blenderbim/pytest.ini @@ -4,6 +4,7 @@ markers = attribute bimtester brick + classification context debug demo diff --git a/src/ifcopenshell-python/ifcopenshell/api/classification/add_reference.py b/src/ifcopenshell-python/ifcopenshell/api/classification/add_reference.py index c8ebb9ab2b..1f34ac4dc1 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/classification/add_reference.py +++ b/src/ifcopenshell-python/ifcopenshell/api/classification/add_reference.py @@ -93,7 +93,7 @@ class Usecase: relationship = self.get_existing_relationship(reference) if relationship: - self.add_to_existing_relationship(reference) + self.add_to_existing_relationship(relationship) else: self.add_new_relationship(reference) diff --git a/src/ifctester/test/ids_doc_generator.py b/src/ifctester/test/ids_doc_generator.py index 83131dcbac..c3ccba5a67 100644 --- a/src/ifctester/test/ids_doc_generator.py +++ b/src/ifctester/test/ids_doc_generator.py @@ -21,6 +21,7 @@ import re import pytest import functools import ifcopenshell +import ifctester import test_facet from xml.dom.minidom import parseString from ifctester import ids @@ -62,7 +63,7 @@ class DocGenerator: basename = f"{result}-" + re.sub("[^0-9a-zA-Z]", "_", name.lower()) # Write IFC to disk - f.write(os.path.join(outdir, "files", f"{basename}.ifc")) + f.write(os.path.join(outdir, "testcases", f"{basename}.ifc")) # Create an IDS with the applicability selecting exactly # the entity type passed to us in `inst`. @@ -73,7 +74,7 @@ class DocGenerator: specs.specifications.append(spec) # Write IDS to disk - with open(os.path.join(outdir, "files", f"{basename}.ids"), "w", encoding="utf-8") as ids_file: + with open(os.path.join(outdir, "testcases", f"{basename}.ids"), "w", encoding="utf-8") as ids_file: ids_file.write(specs.to_string()) xml_text = "\n".join( @@ -122,6 +123,30 @@ for facet, testcases in test_facet.run.testcases.items(): write("~~~") write() write( - f"[Sample IDS](files/{testcase['basename']}.ids) - [Sample IFC: {testcase['id']}](files/{testcase['basename']}.ifc)" + f"[Sample IDS](testcases/{testcase['basename']}.ids) - [Sample IFC: {testcase['id']}](testcases/{testcase['basename']}.ifc)" ) write() + + +specs = ifctester.ids.Ids( + title="buildingSMART Sample IDS", + copyright="buildingSMART", + version="1.0.0", + description="These are example specifications for those learning how to use IDS", + author="foo@bar.com", + date="2022-01-01", + purpose="Contractual requirements", +) + +spec = ifctester.ids.Specification(name="Project naming", ifcVersion=["IFC4"], description="Projects shall be named correctly for the purposes of identification, project archival, and model federation.", instructions="Each discipline is responsible for naming their own project.") +specs.specifications.append(spec) +spec.applicability.append(ifctester.ids.Entity(name="IFCPROJECT")) +spec.requirements.append(ifctester.ids.Attribute(name="Name", value="TEST", instructions="The project manager shall confirm the short project code with the client based on their real estate portfolio naming scheme.")) + +spec = ifctester.ids.Specification(name="Fire rating", ifcVersion=["IFC4"], description="All objects must have a fire rating for building compliance checks and to know the protection strategies needed for any penetrations.", instructions="The architect is responsible for including this data.") +specs.specifications.append(spec) +spec.applicability.append(ifctester.ids.Entity(name="IFCWALLTYPE")) +restriction = ifctester.ids.Restriction(options="(-|[0-9]{2,3})\/(-|[0-9]{2,3})\/(-|[0-9]{2,3})", type="pattern") +spec.requirements.append(ifctester.ids.Property(propertySet="Pset_WallCommon", name="FireRating", value=restriction, instructions="Fire rating is specified using the Fire Resistance Level as defined in the Australian National Construction Code (NCC) 2019. Valid examples include -/-/-, -/120/120, and 60/60/60")) + +specs.to_xml(os.path.join(outdir, "library", "sample.ids")) diff --git a/src/ifctester/test/test_facet.py b/src/ifctester/test/test_facet.py index ad11329e46..1bd0cad9f0 100644 --- a/src/ifctester/test/test_facet.py +++ b/src/ifctester/test/test_facet.py @@ -1161,7 +1161,7 @@ class TestPartOf: group = ifcopenshell.api.run("group.add_group", ifc) facet = PartOf(entity="IfcGroup") run("", facet=facet, inst=element, expected=False) - ifcopenshell.api.run("group.assign_group", ifc, product=[element], group=group) + ifcopenshell.api.run("group.assign_group", ifc, products=[element], group=group) run("", facet=facet, inst=element, expected=True) # An IfcGroup can be passed by subtypes @@ -1169,7 +1169,7 @@ class TestPartOf: element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcElementAssembly") group = ifc.createIfcInventory() facet = PartOf(entity="IfcGroup") - ifcopenshell.api.run("group.assign_group", ifc, product=[element], group=group) + ifcopenshell.api.run("group.assign_group", ifc, products=[element], group=group) run("", facet=facet, inst=element, expected=True) # An IfcSystem only checks that a system is assigned without any other logic