"""Original CC0 fixture test in FreeCAD's Python console; no scanner or GUI test. Run with FreeCADCmd reproduce.py, or exec the file in a FreeCAD Python console. Set SCANNER_CAD_INPUT to the folder containing the three named original STEP fixtures and SCANNER_CAD_OUTPUT to a fresh output directory. Never cleans files. """ import hashlib,json,math,os,sys from pathlib import Path import FreeCAD as App import Part source=Path(os.environ['SCANNER_CAD_INPUT']).resolve() out=Path(os.environ['SCANNER_CAD_OUTPUT']).resolve() assert not out.exists(),'Choose a new output directory; previous results are preserved' out.mkdir(parents=True) files=['plate-native-8mm.step','plate-direct-edit-5mm.step','plate-rebuilt-10mm.step'] checks=[] def bounds(shape):return [shape.BoundBox.XLength,shape.BoundBox.YLength,shape.BoundBox.ZLength] def digest(p):return hashlib.sha256(p.read_bytes()).hexdigest() def dimensions_ok(shape):return all(abs(a-b)<1e-7 for a,b in zip(bounds(shape),[80,50,6])) assert App.Units.Quantity('1 mm').Value==1.0 assert App.Units.Quantity('1 in').getValueAs('mm').Value==25.4 baseline=None for i,name in enumerate(files): path=source/name;shape=Part.Shape();shape.read(str(path)) assert shape.isValid() and len(shape.Solids)==1 and dimensions_ok(shape) checks.append(dict(file=name,operation='STEP import in FreeCAD',valid_brep=shape.isValid(),solids=len(shape.Solids),bounds_mm=bounds(shape),volume_mm3=shape.Volume,input_sha256=digest(path))) if i==0:baseline=shape doc=App.newDocument('SyntheticHandoff') original=doc.addObject('Part::Feature','ImportedSolid');original.Shape=baseline tool=doc.addObject('Part::Cylinder','NewCentralHole');tool.Radius=2.5;tool.Height=6 tool.Placement.Base=App.Vector(0,0,baseline.BoundBox.ZMin) cut=doc.addObject('Part::Cut','EditableBoolean');cut.Base=original;cut.Tool=tool doc.recompute() for diameter in [5,7]: tool.Radius=diameter/2;doc.recompute();shape=cut.Shape expected=math.pi*(diameter/2)**2*6 removed=baseline.Volume-shape.Volume assert shape.isValid() and len(shape.Solids)==1 and dimensions_ok(shape) assert abs(removed-expected)<1e-6 filename='plate-freecad-hole-'+str(diameter)+'mm.step';path=out/filename Part.export([cut],str(path)) again=Part.Shape();again.read(str(path)) assert again.isValid() and len(again.Solids)==1 and dimensions_ok(again) assert abs(again.Volume-shape.Volume)<1e-6 checks.append(dict(file=filename,operation='Imported solid + FreeCAD cylinder/cut; radius changed and recomputed',hole_diameter_mm=diameter,valid_brep=shape.isValid(),solids=len(shape.Solids),bounds_mm=bounds(shape),removed_volume_mm3=removed,expected_removed_volume_mm3=expected,roundtrip_volume_mm3=again.Volume,sha256=digest(path))) report=dict(status='PASS',application='FreeCAD',version=App.Version(),python=sys.version,occt=getattr(Part,'OCC_VERSION','not exposed'),execution='Windows headless FreeCADCmd; GUI workflow not exercised',units='mm; named 1-inch to 25.4-mm quantity conversion checked',datum=dict(origin_mm=[0,0,0],input_bounds_min_mm=[baseline.BoundBox.XMin,baseline.BoundBox.YMin,baseline.BoundBox.ZMin],input_bounds_max_mm=[baseline.BoundBox.XMax,baseline.BoundBox.YMax,baseline.BoundBox.ZMax],new_hole_axis='global Z',new_hole_center_xy_mm=[0,0]),checks=checks,hardware_test=False,commercial_cad_compatibility_test=False,limits=['Synthetic original geometry, not scanner data.','New FreeCAD boolean operations do not recover the original construction history from STEP.','FreeCAD and the previous readers all use OCCT; not independent-kernel validation.','Only these exact files, units and operations were checked; no guarantee for other software or real scans.']) (out/'file-check.json').write_text(json.dumps(report,indent=2),encoding='utf-8') print('SCANNER_CAD_RESULT '+json.dumps(dict(status='PASS',application='FreeCAD',version=App.Version(),checks=len(checks),output=str(out)))) App.closeDocument(doc.Name)