25 lines
2.2 KiB
JavaScript
25 lines
2.2 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import assert from 'node:assert/strict';
|
|
import {fileURLToPath} from 'node:url';
|
|
import {createHash} from 'node:crypto';
|
|
import {loadWasmProbe} from './wasm-probe-runtime.mjs';
|
|
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
|
const file=path.join(root,'docs/current/user-tests-20260915/ifc-native-2026-09-15T15-50-07-990Z/IfcValidation.FCStd');
|
|
const output=path.join(root,'docs/current/user-tests-20260915/ifc-geometry-baseline.json');
|
|
const {kernel}=await loadWasmProbe(path.join(root,'freecad-source/build-web/configure/bin'),'FreeCADWebPartBoxProbe');
|
|
function call(command,parameters,document='Baseline'){
|
|
const response=JSON.parse(kernel.ccall('fc_web_dispatch_json','string',['string'],[JSON.stringify({cmd:'part.viewCommand',args:{owner:'PartBox',document,command,parameters:{...parameters,documentId:document}}})]));
|
|
assert.equal(response.ok,true,JSON.stringify(response));return response.result;
|
|
}
|
|
try {
|
|
const opened=call('Std_Open',{operation:'open',files:[{filename:'Baseline.FCStd',fileData:fs.readFileSync(file).toString('base64')}]});
|
|
assert.equal(opened.errors.length,0,JSON.stringify(opened.errors));
|
|
const doc=opened.activeDocument;
|
|
const read=call('Std_CommandLine',{operation:'submit',source:`import json; d=App.getDocument('${doc}'); print(json.dumps({'objects':len(d.Objects),'groups':sum(1 for o in d.Objects if o.isDerivedFrom('App::DocumentObjectGroup')),'features':[{'name':o.Name,'guid':o.IfcGlobalId,'volume':o.Shape.Volume,'area':o.Shape.Area,'faces':len(o.Shape.Faces),'bounds':[o.Shape.BoundBox.XMin,o.Shape.BoundBox.YMin,o.Shape.BoundBox.ZMin,o.Shape.BoundBox.XMax,o.Shape.BoundBox.YMax,o.Shape.BoundBox.ZMax]} for o in d.Objects if o.isDerivedFrom('Part::Feature')]}))`},doc);
|
|
assert.equal(read.stderr,'');const state=JSON.parse(read.stdout.trim());assert.equal(state.features.length,134);
|
|
fs.writeFileSync(output,JSON.stringify({source:file,sha256:createHash('sha256').update(fs.readFileSync(file)).digest('hex'),state},null,2)+'\n');
|
|
console.log(JSON.stringify({output,objects:state.objects,features:state.features.length,groups:state.groups}));
|
|
}catch(e){console.error(String(e));process.exitCode=1;}
|
|
process.exit(process.exitCode??0);
|