"""CC0 original paired native-container check. No physical scan is used. Run with FreeCADCmd and a fresh SCANNER_HISTORY_OUTPUT directory. Supply the existing authored 5 mm parametric fixture as SCANNER_HISTORY_INPUT. Previous inputs/results are never overwritten or cleaned. """ from pathlib import Path from datetime import datetime,timezone import csv,hashlib,json,math,os,shutil,sys import FreeCAD as App import Part out=Path(os.environ['SCANNER_HISTORY_OUTPUT']).resolve() source=Path(os.environ['SCANNER_HISTORY_INPUT']).resolve() assert not out.exists(),'Choose a fresh output directory and preserve prior results' assert source.is_file() and source.suffix.lower()=='.fcstd' out.mkdir(parents=True);checks=[] digest=lambda p:hashlib.sha256(p.read_bytes()).hexdigest() source_sha=digest(source) input_copy=out/'plate-with-parameters-5mm.FCStd';shutil.copy2(source,input_copy) assert digest(input_copy)==source_sha param=App.openDocument(str(input_copy)) assert param.HoleProfile.FullyConstrained and param.PlateProfile.FullyConstrained assert abs(param.HoleProfile.getDatum(1).Value-5.0)<1e-7 def shape_record(shape,diameter): assert shape.isValid() and len(shape.Solids)==1 bounds=[shape.BoundBox.XLength,shape.BoundBox.YLength,shape.BoundBox.ZLength] expected=80*50*6-math.pi*(diameter/2)**2*6 assert all(abs(a-b)<1e-7 for a,b in zip(bounds,[80,50,6])) assert abs(shape.Volume-expected)<1e-6 return {'valid_solid':True,'solids':1,'bounds_mm':bounds,'volume_mm3':shape.Volume,'expected_volume_mm3':expected,'hole_diameter_mm':diameter} baseline=shape_record(param.HolePocket.Shape,5) checks.append({'stage':'open_original_parametric_project','native_history_available':True,'named_parameter':'HoleProfile.Constraints.HoleDiameter',**baseline}) plain=App.newDocument('NativeContainerGeometryOnly') plain.Label='Geometry-only native file - authored counterexample' plain.CreatedBy='3D Scanner Match' plain.Comment='Original synthetic geometry, not a scan. No original feature tree or named hole parameter is included.' plain.License='CC0-1.0';plain.LicenseURL='https://creativecommons.org/publicdomain/zero/1.0/' feature=plain.addObject('Part::Feature','DeliveredSolid');feature.Shape=param.HolePocket.Shape.copy() plain.recompute();plain_path=out/'plate-geometry-only-5mm.FCStd';plain.saveAs(str(plain_path)) plain_sha=digest(plain_path) baseline_difference=param.HolePocket.Shape.cut(feature.Shape).Volume+feature.Shape.cut(param.HolePocket.Shape).Volume assert baseline_difference<1e-6 checks.append({'stage':'save_geometry_only_native_project','native_history_available':False,'symmetric_difference_volume_mm3':baseline_difference,'objects':[{'name':o.Name,'type':o.TypeId} for o in plain.Objects],**shape_record(feature.Shape,5)}) reopen_path=out/'retained-reopen-geometry-only.FCStd';shutil.copy2(plain_path,reopen_path) assert digest(reopen_path)==plain_sha reopened=App.openDocument(str(reopen_path));assert reopened.Name!=plain.Name and reopened.Name!=param.Name shape=reopened.DeliveredSolid.Shape reopen_difference=param.HolePocket.Shape.cut(shape).Volume+shape.cut(param.HolePocket.Shape).Volume assert reopen_difference<1e-6 checks.append({'stage':'independent_document_open_geometry_only','byte_identical_reopen_input':True,'native_history_available':False,'symmetric_difference_volume_mm3':reopen_difference,**shape_record(shape,5)}) missing_parameter=False try: reopened.HoleProfile.setDatum(1,App.Units.Quantity('7 mm')) except AttributeError: missing_parameter=True assert missing_parameter and reopened.getObject('HoleProfile') is None checks.append({'stage':'requested_named_parameter_edit','result':'EXPECTED_UNAVAILABLE','reason':'This native project has one Part::Feature and no HoleProfile sketch or named HoleDiameter constraint.','geometry_still_valid':shape.isValid(),'native_history_available':False}) # A directly editable solid still supports a new geometric operation even # though the original named-parameter task is unavailable in this file. tool=Part.makeCylinder(3.5,10,App.Vector(0,0,-2),App.Vector(0,0,1)) edited=shape.cut(tool) edited_record=shape_record(edited,7) checks.append({'stage':'direct_boolean_hole_edit','operation':'Subtract a 7 mm cylinder from the existing 5 mm hole','native_history_recovered':False,**edited_record}) edited_doc=App.newDocument('GeometryOnlyDirectEdit') edited_feature=edited_doc.addObject('Part::Feature','DirectEditedSolid');edited_feature.Shape=edited;edited_doc.recompute() step_path=out/'plate-direct-edit-7mm.step';Part.export([edited_feature],str(step_path)) imported=Part.Shape();imported.read(str(step_path)) checks.append({'stage':'edited_STEP_reimport','native_feature_history_test':False,**shape_record(imported,7)}) param.HoleProfile.setDatum(1,App.Units.Quantity('7 mm'));param.recompute() parameter_shape=param.HolePocket.Shape assert param.HoleProfile.FullyConstrained and param.PlateProfile.FullyConstrained difference=parameter_shape.cut(edited).Volume+edited.cut(parameter_shape).Volume assert difference<1e-6 checks.append({'stage':'native_parameter_edit_matches_direct_geometry','named_parameter_task_available':True,'symmetric_difference_volume_mm3':difference,'comparison_kernel':'Same OCCT kernel; not independent metrology validation',**shape_record(parameter_shape,7)}) assert digest(source)==source_sha and digest(input_copy)==source_sha and digest(plain_path)==plain_sha and digest(reopen_path)==plain_sha checks.append({'stage':'source_and_saved_native_bytes_preserved','original_parametric_source_sha256':source_sha,'geometry_only_native_sha256':plain_sha,'saved_geometry_stays_5mm':True,'edits_performed_in_memory':True}) files=[{'file':p.name,'bytes':p.stat().st_size,'sha256':digest(p)} for p in [input_copy,plain_path,step_path]] report={'status':'PASS','performed_at_utc':datetime.now(timezone.utc).isoformat(),'application':'FreeCAD','version':App.Version(),'python':sys.version,'occt':getattr(Part,'OCC_VERSION','not exposed'),'units':'mm','execution':'Windows FreeCADCmd, background API checks','original_geometry':{'bounds_min_mm':[-40,-25,0],'bounds_max_mm':[40,25,6],'hole_center_xy_mm':[0,0],'hole_axis':'global Z'},'checks':checks,'files':files,'native_extensions_of_both_inputs':'FCStd','publisher_hardware_test':False,'real_scan_reconstruction':False,'gui_test':False,'independent_kernel_test':False,'license':'CC0-1.0 original fixture/code; FreeCAD separately licensed','limits':['Only these authored files and operations in this exact FreeCAD build were checked.','Identical geometry and a native extension do not establish the required named parameter or dependency tree.','A new Boolean operation is a direct geometric edit, not recovery of original construction history.','STEP reimport and geometric comparison use the same OCCT kernel. No physical tolerance, scanner suitability or GUI usability is inferred.']} (out/'file-check.json').write_text(json.dumps(report,indent=2)+'\n',encoding='utf-8') with (out/'file-check.csv').open('w',encoding='utf-8',newline='') as f: fields=['stage','result','native_history_available','named_parameter_task_available','hole_diameter_mm','valid_solid','solids','bounds_mm','volume_mm3','reason'] writer=csv.DictWriter(f,fieldnames=fields);writer.writeheader() for row in checks:writer.writerow({key:json.dumps(row[key]) if isinstance(row.get(key),(list,dict)) else row.get(key,'') for key in fields}) print(json.dumps({'status':'PASS','checks':len(checks),'native_geometry_only_file':plain_path.name,'direct_edit_STEP':step_path.name,'physical_scans':0,'GUI_tests':0}));sys.stdout.flush()