75 lines
4.0 KiB
Python
75 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_MUTATION_OUTPUT", "")
|
|
|
|
|
|
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, targets):
|
|
return {
|
|
"value": value_of(owner),
|
|
"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()),
|
|
"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("PropertyLinkSubListGlobalMutation")
|
|
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]
|
|
baseline_value = [(first, ("Face1", "Face2")), (second, "Face1")]
|
|
owner.Support = baseline_value
|
|
document.recompute()
|
|
before = snapshot(document, owner, targets)
|
|
|
|
owner.Support = [(second, "")]
|
|
touched_after_edit = snapshot(document, owner, targets)
|
|
edit_recompute_result = bool(document.recompute())
|
|
edited = snapshot(document, owner, targets)
|
|
|
|
owner.Support = baseline_value
|
|
touched_after_restore = snapshot(document, owner, targets)
|
|
restore_recompute_result = bool(document.recompute())
|
|
restored = snapshot(document, owner, targets)
|
|
|
|
case = {"objectTypeId": owner.TypeId, "objectName": owner.Name, "propertyName": "Support", "before": before, "touchedAfterEdit": touched_after_edit, "edited": edited, "touchedAfterRestore": touched_after_restore, "restored": restored, "editRecomputeResult": edit_recompute_result, "restoreRecomputeResult": restore_recompute_result, "valueRestored": before["value"] == restored["value"], "semanticStateRestored": before == restored}
|
|
finally:
|
|
App.closeDocument(document.Name)
|
|
|
|
report = {"schemaVersion": 1, "status": "pass", "baselineId": "freecad-1.1.1-property-linksublistglobal-mutation", "freecadVersion": ".".join(str(value) for value in App.Version()[:3]), "gitCommit": FREECAD_COMMIT, "propertyType": "App::PropertyLinkSubListGlobal", "caseCount": 1, "case": case}
|
|
if not OUTPUT_PATH:
|
|
raise RuntimeError("FREECAD_PROPERTY_LINKSUBLISTGLOBAL_MUTATION_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_MUTATION_RESULT=" + json.dumps({"status": report["status"], "caseCount": report["caseCount"], "restored": case["semanticStateRestored"]}, sort_keys=True))
|