| 64 | |
| 65 | |
| 66 | class FacetDocGenerator: |
| 67 | def __init__(self): |
| 68 | self.facet = None |
| 69 | self.testcases = {} |
| 70 | |
| 71 | def __call__(self, name, *, facet, inst, expected): |
| 72 | if not name: |
| 73 | return |
| 74 | |
| 75 | result = "pass" if expected is True else "fail" |
| 76 | |
| 77 | ifc = inst.wrapped_data.file |
| 78 | if "GlobalId" not in name: |
| 79 | regenerate_guids(ifc) |
| 80 | |
| 81 | # Validate the file created and loop over the issues, fixing them one by one. |
| 82 | l = validate.json_logger() |
| 83 | validate.validate(ifc, l) |
| 84 | for issue in l.statements: |
| 85 | if "GlobalId" in issue["message"]: |
| 86 | issue["instance"].GlobalId = ifcopenshell.guid.new() |
| 87 | elif "PredefinedType" in issue["message"]: |
| 88 | ty = re.findall("\\(.+?\\)", issue["message"])[0][1:-1].split(", ")[0] |
| 89 | issue["instance"].PredefinedType = ty |
| 90 | elif "IfcMaterialList" in issue["message"]: |
| 91 | issue["instance"].Materials = [ifc.createIfcMaterial("Concrete", None, "CONCRETE")] |
| 92 | else: |
| 93 | raise Exception("About to emit invalid example data:", issue) |
| 94 | |
| 95 | # ifc_text = "\n".join([f"{e} /* Testcase */" if e == inst else str(e) for e in f]) |
| 96 | lines = ifc.wrapped_data.to_string().split("\n")[7:-3] |
| 97 | ifc_text = "\n".join([f"{l} /* Testcase */" if f"#{inst.id()}=" in l else l for l in lines]) |
| 98 | basename = f"{result}-" + re.sub("[^0-9a-zA-Z]", "_", name.lower()) |
| 99 | |
| 100 | # Write IFC to disk |
| 101 | ifc.write(os.path.join(outdir, "testcases", self.facet, f"{basename}.ifc")) |
| 102 | |
| 103 | # Create an IDS with the applicability selecting exactly |
| 104 | # the entity type passed to us in `inst`. |
| 105 | specs = ids.Ids(title=name) |
| 106 | |
| 107 | # todo: to resume IFC2X3 we need to ensure that entities and attributes are consistent with that schema in order to pass audit |
| 108 | spec = ids.Specification(name=name, minOccurs=1, ifcVersion=["IFC4"]) |
| 109 | spec.applicability.append(ids.Entity(name=inst.is_a().upper())) |
| 110 | spec.requirements.append(facet) |
| 111 | specs.specifications.append(spec) |
| 112 | |
| 113 | # Write IDS to disk |
| 114 | with open(os.path.join(outdir, "testcases", self.facet, f"{basename}.ids"), "w", encoding="utf-8") as ids_file: |
| 115 | ids_file.write(specs.to_string()) |
| 116 | |
| 117 | xml_text = "\n".join( |
| 118 | l |
| 119 | for l in parseString(specs.to_string()) |
| 120 | .getElementsByTagName("requirements")[0] |
| 121 | .childNodes[1] |
| 122 | .toprettyxml() |
| 123 | .split("\n") |