import hashlib import json import os import FreeCAD as App import Part FREECAD_COMMIT = "0108fd4b4850cc46e625b60e53cea7a7bbe69f8d" def value_of(owner): return [{"object": obj.Name if obj else None, "subElements": [str(item) for item in (sub_elements if not isinstance(sub_elements, str) else [sub_elements]) if str(item)]} for obj, sub_elements in owner.Support] def shape_snapshot(obj): shape = obj.Shape if shape.isNull(): return {"isNull": True, "solids": 0, "faces": 0, "edges": 0, "vertices": 0, "volume": 0.0, "brepSha256": None} return {"isNull": False, "solids": len(shape.Solids), "faces": len(shape.Faces), "edges": len(shape.Edges), "vertices": len(shape.Vertexes), "volume": round(float(shape.Volume), 9), "brepSha256": hashlib.sha256(shape.exportBrepToString().encode("utf-8")).hexdigest()} def snapshot(document): owner = document.getObject("ShapeBinderProbe") targets = [document.getObject("SourceBox"), document.getObject("SecondBox")] document.recompute() return {"object": {"name": owner.Name, "typeId": owner.TypeId, "propertyName": "Support", "propertyTypeId": owner.getTypeIdOfProperty("Support"), "group": owner.getGroupOfProperty("Support"), "value": value_of(owner), "propertyStatus": [str(item) for item in owner.getPropertyStatus("Support")], "editorMode": [str(item) for item in owner.getEditorMode("Support")], "state": [str(item) for item in owner.State], "statusString": str(owner.getStatusString()), "shape": shape_snapshot(owner), "outList": [item.Name for item in owner.OutList]}, "targets": {target.Name: {"typeId": target.TypeId, "inList": [item.Name for item in target.InList], "shape": shape_snapshot(target)} for target in targets}, "objectSet": [{"name": item.Name, "typeId": item.TypeId} for item in document.Objects]} def create_native(path): document = App.newDocument("PropertyLinkSubListGlobalRoundtrip") try: owner = document.addObject("PartDesign::ShapeBinder", "ShapeBinderProbe") first = document.addObject("Part::Feature", "SourceBox") first.Shape = Part.makeBox(4.0, 5.0, 6.0) second = document.addObject("Part::Feature", "SecondBox") second.Shape = Part.makeBox(2.0, 3.0, 4.0, App.Vector(10.0, 0.0, 0.0)) owner.Support = [(first, ("Face1", "Face2")), (second, "Face1")] document.recompute() document.saveAs(path) return snapshot(document) finally: App.closeDocument(document.Name) def verify_native(path, resaved_path): document = App.openDocument(path) try: reopened = snapshot(document) document.saveAs(resaved_path) finally: App.closeDocument(document.Name) document = App.openDocument(resaved_path) try: resaved = snapshot(document) finally: App.closeDocument(document.Name) return {"reopened": reopened, "resaved": resaved} mode = os.environ.get("FREECAD_PROPERTY_LINKSUBLISTGLOBAL_ROUNDTRIP_MODE", "") path = os.environ.get("FREECAD_PROPERTY_LINKSUBLISTGLOBAL_ROUNDTRIP_PATH", "") resaved_path = os.environ.get("FREECAD_PROPERTY_LINKSUBLISTGLOBAL_ROUNDTRIP_RESAVED_PATH", "") result = create_native(path) if mode == "create" else verify_native(path, resaved_path) if mode == "verify" else None if result is None: raise RuntimeError("FREECAD_PROPERTY_LINKSUBLISTGLOBAL_ROUNDTRIP_MODE must be create or verify") print("FREECAD_PROPERTY_LINKSUBLISTGLOBAL_ROUNDTRIP_RESULT=" + json.dumps({"schemaVersion": 1, "status": "pass", "baselineId": "freecad-1.1.1-property-linksublistglobal-roundtrip", "freecadVersion": ".".join(str(value) for value in App.Version()[:3]), "gitCommit": FREECAD_COMMIT, "mode": mode, "result": result}, sort_keys=True))