Real IFC2X3/IFC4 import tested. Full BIM authoring/export remains out of scope; 349-second building import performance remains to optimize.
36 lines
3.2 KiB
JavaScript
36 lines
3.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 { loadWasmProbe } from './wasm-probe-runtime.mjs';
|
|
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
|
const output=path.join(root,'docs/current/user-tests-20260915',`ifc-native-${new Date().toISOString().replace(/[:.]/g,'-')}`);
|
|
fs.mkdirSync(output,{recursive:true});
|
|
const fixture=path.join(root,'FreeCADBaseLib/sources/src/Qt-5.15.13/qt3d/src/3rdparty/assimp/src/test/models/IFC/AC14-FZK-Haus.ifc');
|
|
const log=message=>fs.appendFileSync(path.join(output,'native.log'),String(message)+'\n');
|
|
const results=[];
|
|
console.log(output);
|
|
try {
|
|
const {kernel}=await loadWasmProbe(path.join(root,'freecad-source/build-web/configure/bin'),'FreeCADWebPartBoxProbe',{print:log,printErr:log});
|
|
const dispatch=(command,parameters,document='IfcValidation')=>{
|
|
const started=performance.now();
|
|
const reply=JSON.parse(kernel.ccall('fc_web_dispatch_json','string',['string'],[JSON.stringify({cmd:'part.viewCommand',args:{schema:'freecad-web/document-view/v1',owner:'PartBox',document,command,parameters:{...parameters,documentId:document}}})]));
|
|
results.push({command,seconds:(performance.now()-started)/1000,reply});
|
|
fs.writeFileSync(path.join(output,'results.json'),JSON.stringify(results,null,2)+'\n');
|
|
console.log(JSON.stringify({command,ok:reply.ok,error:reply.error,seconds:results.at(-1).seconds}));
|
|
assert.equal(reply.ok,true,JSON.stringify(reply));return reply.result;
|
|
};
|
|
const opened=dispatch('Std_Open',{operation:'open',files:[{filename:'AC14-FZK-Haus.ifc',fileData:fs.readFileSync(fixture).toString('base64')}]});
|
|
assert.equal(opened.errors.length,0,JSON.stringify(opened.errors));
|
|
assert.ok(opened.opened[0].documents[0].objectCount>20);
|
|
const doc=opened.activeDocument;
|
|
const inspect=dispatch('Std_CommandLine',{operation:'submit',source:`import json; print(json.dumps({'objects':len(App.getDocument('${doc}').Objects),'shapes':sum(1 for o in App.getDocument('${doc}').Objects if hasattr(o,'Shape') and not o.Shape.isNull()),'groups':sum(1 for o in App.getDocument('${doc}').Objects if hasattr(o,'Group')),'properties':sum(1 for o in App.getDocument('${doc}').Objects if 'IfcPropertySets' in o.PropertiesList),'volume':sum(o.Shape.Volume for o in App.getDocument('${doc}').Objects if hasattr(o,'Shape'))}))`},doc);
|
|
assert.equal(inspect.stderr,'');
|
|
const state=JSON.parse(inspect.stdout.trim());assert.ok(state.shapes>20);assert.ok(state.groups>=3);assert.ok(state.volume>0);
|
|
const saved=dispatch('Std_SaveAs',{filename:'/tmp/IfcValidation.FCStd'},doc);
|
|
assert.ok(saved.files[0].contentsBase64.length>1000);
|
|
fs.writeFileSync(path.join(output,'IfcValidation.FCStd'),Buffer.from(saved.files[0].contentsBase64,'base64'));
|
|
fs.writeFileSync(path.join(output,'summary.json'),JSON.stringify({status:'passed',state,scope:'Native IFC import and FCStd save; not browser acceptance'},null,2)+'\n');
|
|
} catch(error) {fs.writeFileSync(path.join(output,'failure.json'),JSON.stringify({status:'failed',error:String(error)},null,2)+'\n');console.error(String(error));process.exitCode=1;}
|
|
process.exit(process.exitCode??0);
|