Files
Web_FreeCAD_Bitbybit/scripts/freecad-property-linksublistglobal-success.py
wangdequan 54649da16c
Some checks are pending
real-verification / chrome (push) Waiting to run
real-verification / freecad-oracle (push) Waiting to run
real-verification / wasm (push) Waiting to run
feat: close link sub property codecs
2026-08-17 21:37:33 -04:00

74 lines
4.0 KiB
Python

import hashlib
import json
import os
import FreeCAD as App
import Part
FREECAD_COMMIT = "0108fd4b4850cc46e625b60e53cea7a7bbe69f8d"
OUTPUT_PATH = os.environ.get("FREECAD_PROPERTY_LINKSUBLISTGLOBAL_SUCCESS_OUTPUT", "")
def link_values(value):
result = []
for obj, sub_elements in value:
subs = [sub_elements] if isinstance(sub_elements, str) and sub_elements else list(sub_elements) if not isinstance(sub_elements, str) else []
result.append({"object": obj.Name if obj else None, "subElements": [str(item) for item in subs if str(item)]})
return result
def shape_snapshot(obj):
shape = obj.Shape
if shape.isNull():
return {"isNull": True, "solids": 0, "faces": 0, "edges": 0, "vertices": 0, "brepSha256": None}
brep = shape.exportBrepToString()
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(brep.encode("utf-8")).hexdigest()}
def snapshot(document, owner, targets):
recompute_result = bool(document.recompute())
return {
"value": link_values(owner.Support),
"propertyTypeId": owner.getTypeIdOfProperty("Support"),
"group": owner.getGroupOfProperty("Support"),
"propertyStatus": [str(item) for item in owner.getPropertyStatus("Support")],
"editorMode": [str(item) for item in owner.getEditorMode("Support")],
"ownerState": [str(item) for item in owner.State],
"statusString": str(owner.getStatusString()),
"recomputeResult": recompute_result,
"shape": shape_snapshot(owner),
"ownerOutList": [candidate.Name for candidate in owner.OutList],
"targetInLists": {target.Name: [candidate.Name for candidate in target.InList] for target in targets},
"targetShapes": {target.Name: shape_snapshot(target) for target in targets},
"objectSet": [{"name": candidate.Name, "typeId": candidate.TypeId} for candidate in document.Objects],
}
document = App.newDocument("PropertyLinkSubListGlobalSuccess")
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))
targets = [first, second]
phases = {}
owner.Support = []
phases["empty"] = snapshot(document, owner, targets)
owner.Support = [(first, "")]
phases["wholeObject"] = snapshot(document, owner, targets)
owner.Support = [(first, ("Face1", "Face2"))]
phases["sameObjectSubElements"] = snapshot(document, owner, targets)
owner.Support = [(first, ("Face1", "Face2")), (second, "Face1")]
phases["multipleObjects"] = snapshot(document, owner, targets)
report = {"schemaVersion": 1, "status": "pass", "baselineId": "freecad-1.1.1-property-linksublistglobal-success", "freecadVersion": ".".join(str(value) for value in App.Version()[:3]), "gitCommit": FREECAD_COMMIT, "propertyType": "App::PropertyLinkSubListGlobal", "caseCount": 1, "bindingBoundary": {"oracleDefault": [], "safeFirstRead": "assign-empty-list-before-read", "emptyListMeans": "no-references", "shapeBinderUsesFirstPartFeature": True, "multipleObjectReferencesPreserved": True}, "cases": [{"objectTypeId": "PartDesign::ShapeBinder", "objectName": "ShapeBinderProbe", "propertyName": "Support", "group": "", "mode": "direct-native-property-setter", "phases": phases}]}
finally:
App.closeDocument(document.Name)
if not OUTPUT_PATH:
raise RuntimeError("FREECAD_PROPERTY_LINKSUBLISTGLOBAL_SUCCESS_OUTPUT is required")
with open(OUTPUT_PATH, "w", encoding="utf-8") as handle:
json.dump(report, handle, indent=2, sort_keys=True)
handle.write("\n")
print("FREECAD_PROPERTY_LINKSUBLISTGLOBAL_SUCCESS_RESULT=" + json.dumps({"status": report["status"], "caseCount": report["caseCount"]}, sort_keys=True))