38 lines
1.7 KiB
JavaScript
38 lines
1.7 KiB
JavaScript
import fs from 'node:fs';
|
|
import { loadWasmProbe } from './wasm-probe-runtime.mjs';
|
|
|
|
let kernel;
|
|
try {
|
|
({ kernel } = await loadWasmProbe('web/public/kernel', 'FreeCADWebDocumentProbe'));
|
|
const dispatch = (cmd, args) => JSON.parse(kernel.ccall('fc_web_dispatch_json', 'string', ['string'], [JSON.stringify({ cmd, args })]));
|
|
dispatch('part.document', { document: 'FillingDiagnostic', action: 'create' });
|
|
const response = dispatch('part.documentViewCommand', { owner: 'DocumentProbe', document: 'FillingDiagnostic',
|
|
command: 'Std_CommandLine', parameters: { operation: 'submit', source: 'exec(' + JSON.stringify(`
|
|
import Part, json
|
|
box=Part.makeBox(10,10,10)
|
|
edges=Part.__sortEdges__(box.Edges[:4])
|
|
fresh=[]
|
|
for edge in edges:
|
|
copy=edge.Curve.toShape(edge.FirstParameter,edge.LastParameter)
|
|
if edge.Orientation=='Reversed': copy.reverse()
|
|
fresh.append(copy)
|
|
results=[]
|
|
for name,values in [('original',edges),('copied',[e.copy() for e in edges]),('wire',Part.Wire(edges).Edges),('fresh-curves',fresh)]:
|
|
try:
|
|
face=Part.makeFilledFace(values)
|
|
diagnostic=''
|
|
try: face.check()
|
|
except Exception as error: diagnostic=str(error)
|
|
valid=face.isValid()
|
|
face=face.copy()
|
|
fixed=face.fix(1e-7,1e-7,1e-5)
|
|
results.append(dict(name=name,valid=valid,diagnostic=diagnostic,fixed=fixed,after=face.isValid(),area=face.Area))
|
|
except Exception as error: results.append(dict(name=name,error=str(error)))
|
|
print(json.dumps(results))
|
|
`) + ')' } });
|
|
fs.writeFileSync('docs/current/part-builder-filling-diagnostic.json', JSON.stringify(response, null, 2));
|
|
console.log(JSON.stringify(response));
|
|
if (!response.ok || response.result?.stderr) process.exitCode = 1;
|
|
} finally { kernel?.PThread?.terminateAllThreads(); }
|
|
process.exit(process.exitCode ?? 0);
|