Interface WorkingSet2DExportInterface

The WorkingSet2DExportInterface interface defines the data included in a export procedure called by DataSessionInterface.export2D or DataSessionInterface.exportSVG.

Only WorkingSetInterface may be included in a export procedure, individual geometric instance ids cannot be exported.

It consists in a WorkingSetInterface, parameters from WorkingSet3DExportInterface, an optional boolean telling the data is ghosted and a boolean telling if the geometries will ignore cut planes.

/** 
* Sample to illustrate the use of a "complete" screenshot export procedure.
*/
import {
DataSessionInterface, WorkingSetInterface, ExportJobInterface, ExportJobInterfaceSignal, InfiniteError, InfiniteEvent, InfiniteEngineInterface,
Export2DOutputFormat, Vector2, Vector4
} from 'generated_files/documentation/appinfiniteapi';

// the DataSessionInterface has been created previously and is connected
let lDataSession: DataSessionInterface;
// the working set to export as a raster screenshot
let lWorkingSetToExport : WorkingSetInterface;
// the export job to monitor
let lExportJob : ExportJobInterface | undefined = undefined;
// the infinite engine in use, created previously
let lInfiniteEngine: InfiniteEngineInterface;

// the file to download
// In this test, we will only download one file
let lFileOffset : number = -1;

// triggers a save file from the browser
const onDownloadReady = (pUrl : string) : void => {
const downloadLink = document.createElement('a');
downloadLink.target = '_blank';
// set object URL as the anchors href
downloadLink.href = pUrl;
// append the anchor to document body
document.body.appendChild(downloadLink);
// fire a click event on the anchor
downloadLink.click();
// cleanup: remove element and revoke object URL
downloadLink.remove();
};

const startExportProcedure = () : boolean =>
{
// we will try to export as png
lExportJob = lDataSession.export2D(
[{ workingSet: lWorkingSetToExport }],
{
type: 'export2DOutputFormat',
outputs: [
{
// the name inside the screenshot procedure, as multiple viewpoint may
// be set, in this case this is useless
itemName: 'screenshot',
// the resolution of the image
resolution: new Vector2(1024, 768),
// camera parameters
viewpoint: lInfiniteEngine.getCameraManager().toJSON(),
// the background color
backgroundColor: new Vector4(1, 1, 1, 1),
// PNG to get a lossless compression
dataFormat: Export2DOutputFormat.EOF_PNG
}
],
// filename without extension
filename: 'test'
}
);
// sanity check
if(lExportJob === undefined)
{
return false;
}
lExportJob.addEventListener(ExportJobInterfaceSignal.ExportJobFinished, (pEvent : InfiniteEvent) : void =>
{
// only get the URL if no error
const lError : InfiniteError | undefined = lExportJob.getLastError();
if(lError === undefined && (lFileOffset === -1))
{
lFileOffset = pEvent.attachments;
if(lExportJob.isExportSuccess(lFileOffset))
{
// trigger the URL computing
if(!lExportJob.computeDownloadURL(lFileOffset))
{
console.log('Export job failed');
}
}
}
});
// URL will be ready
lExportJob.addEventListener(ExportJobInterfaceSignal.ExportJobURLReady, () : void =>
{
const lUrl : string | undefined = lExportJob.getDownloadURL(lFileOffset);
// sanity check
if(lUrl === undefined)
{
console.log('Export job failed');
return;
}
// trigger the download from the browser
onDownloadReady(lUrl);
});
return true;
};

startExportProcedure();

or asynchronously :
/** 
* Sample to illustrate the asynchronous use of a "complete" screenshot export procedure.
*/
import { DataSessionInterface, WorkingSetInterface, ExportJobInterface, AsyncResultReason, Export2DOutputFormat, Vector2, Vector4, InfiniteEngineInterface } from 'generated_files/documentation/appinfiniteapi';

// the DataSessionInterface has been created previously and is connected
let lDataSession: DataSessionInterface;
// the working set to export as a raster screenshot
let lWorkingSetToExport : WorkingSetInterface;
// the export job to monitor
let lExportJob : ExportJobInterface | undefined = undefined;
// the infinite engine in use, created previously
let lInfiniteEngine: InfiniteEngineInterface;

// triggers a save file from the browser
const onDownloadReady = (pUrl : string) : void => {
const downloadLink = document.createElement('a');
downloadLink.target = '_blank';
// set object URL as the anchors href
downloadLink.href = pUrl;
// append the anchor to document body
document.body.appendChild(downloadLink);
// fire a click event on the anchor
downloadLink.click();
// cleanup: remove element and revoke object URL
downloadLink.remove();
};

const startExportProcedure = async () : Promise<boolean> =>
{
// we will try to export as png
lExportJob = lDataSession.export2D(
[{ workingSet: lWorkingSetToExport }],
{
type: 'export2DOutputFormat',
outputs: [
{
// the name inside the screenshot procedure, as multiple viewpoint may
// be set, in this case this is useless
itemName: 'screenshot',
// the resolution of the image
resolution: new Vector2(1024, 768),
// camera parameters
viewpoint: lInfiniteEngine.getCameraManager().toJSON(),
// the background color
backgroundColor: new Vector4(1, 1, 1, 1),
// PNG to get a lossless compression
dataFormat: Export2DOutputFormat.EOF_PNG
}
],
// filename without extension
filename: 'test'
}
);
// sanity check
if(lExportJob === undefined)
{
return false;
}
// wait for file count to be known
const lWaitForFileCount : AsyncResultReason = await lExportJob.asyncWaitForFileCount();
if(lWaitForFileCount !== AsyncResultReason.ARR_Success)
{
return false;
}
const lNbFiles: number = lExportJob.getFileCount();
console.log('The export procedure consists in ' + lNbFiles + ' files');
if(lNbFiles < 1)
{
// not enough files ?
// => should not happen
return false;
}
// wait for everything to be computed
// we could have waited for a specific file with an asyncWaitForFinished(item)
const lExportResult : AsyncResultReason = await lExportJob.asyncWaitForFinished();
if(lExportResult !== AsyncResultReason.ARR_Success)
{
return false;
}
// file is ready
// claim for a download url for file 0
console.log('retrieving file ' + lExportJob.getFilename(0));
await lExportJob.asyncGetDownloadURL(0);
const lUrl : string | undefined = lExportJob.getDownloadURL(0);
if(lUrl === undefined)
{
return false;
}
// trigger a download of the file
onDownloadReady(lUrl);
return true;
};

startExportProcedure();

/** 
* Sample to illustrate the use of a SVG export procedure.
*/
import {
DataSessionInterface, WorkingSetInterface, ExportJobInterface, ExportJobInterfaceSignal, InfiniteError, InfiniteEvent,
InfiniteEngineInterface, Vector2, ExportSVGOutputFormat
} from 'generated_files/documentation/appinfiniteapi';

// the DataSessionInterface has been created previously and is connected
let lDataSession: DataSessionInterface;
// the working set to export as a svg image
let lWorkingSetToExport : WorkingSetInterface;
// the export job to monitor
let lExportJob : ExportJobInterface | undefined = undefined;
// the infinite engine in use, created previously
let lInfiniteEngine: InfiniteEngineInterface;

// the file to download
// In this test, we will only download one file
let lFileOffset : number = -1;

// triggers a save file from the browser
const onDownloadReady = (pUrl : string) : void => {
const downloadLink = document.createElement('a');
downloadLink.target = '_blank';
// set object URL as the anchors href
downloadLink.href = pUrl;
// append the anchor to document body
document.body.appendChild(downloadLink);
// fire a click event on the anchor
downloadLink.click();
// cleanup: remove element and revoke object URL
downloadLink.remove();
};

const startExportProcedure = () : boolean =>
{
// will will try to export as svg
lExportJob = lDataSession.exportSVG(
[{ workingSet: lWorkingSetToExport }],
{
type: 'exportSVGOutputFormat',
outputs: [
{
// the name inside the screenshot procedure, as multiple viewpoint may
// be set, in this case this is useless
itemName: 'svg_screenshot',
// the page size in mm (A4 here)
pageSize: new Vector2(210, 287),
// camera parameters
viewpoint: lInfiniteEngine.getCameraManager().toJSON(),
// SVG file format
dataFormat: ExportSVGOutputFormat.EOF_SVG
}
],
// filename without extension
filename: 'test'
}
);
// sanity check
if(lExportJob === undefined)
{
return false;
}
lExportJob.addEventListener(ExportJobInterfaceSignal.ExportJobFinished, (pEvent : InfiniteEvent) : void =>
{
// only get the URL if no error
const lError : InfiniteError | undefined = lExportJob.getLastError();
if(lError === undefined && (lFileOffset === -1))
{
lFileOffset = pEvent.attachments;
if(lExportJob.isExportSuccess(lFileOffset))
{
// trigger the URL computing
if(!lExportJob.computeDownloadURL(lFileOffset))
{
console.log('Export job failed');
}
}
}
});
// URL will be ready
lExportJob.addEventListener(ExportJobInterfaceSignal.ExportJobURLReady, () : void =>
{
const lUrl : string | undefined = lExportJob.getDownloadURL(lFileOffset);
// sanity check
if(lUrl === undefined)
{
console.log('Export job failed');
return;
}
// trigger the download from the browser
onDownloadReady(lUrl);
});
return true;
};

startExportProcedure();

or asynchronously :
/** 
* Sample to illustrate the asynchronous use of a SVG export procedure.
*/
import {
DataSessionInterface, WorkingSetInterface, ExportJobInterface, AsyncResultReason,
Vector2, InfiniteEngineInterface, ExportSVGOutputFormat
} from 'generated_files/documentation/appinfiniteapi';

// the DataSessionInterface has been created previously and is connected
let lDataSession: DataSessionInterface;
// the working set to export as a svg image
let lWorkingSetToExport : WorkingSetInterface;
// the export job to monitor
let lExportJob : ExportJobInterface | undefined = undefined;
// the infinite engine in use, created previously
let lInfiniteEngine: InfiniteEngineInterface;

// triggers a save file from the browser
const onDownloadReady = (pUrl : string) : void => {
const downloadLink = document.createElement('a');
downloadLink.target = '_blank';
// set object URL as the anchors href
downloadLink.href = pUrl;
// append the anchor to document body
document.body.appendChild(downloadLink);
// fire a click event on the anchor
downloadLink.click();
// cleanup: remove element and revoke object URL
downloadLink.remove();
};

const startExportProcedure = async () : Promise<boolean> =>
{
// will will try to export as svg
lExportJob = lDataSession.exportSVG(
[{ workingSet: lWorkingSetToExport }],
{
type: 'exportSVGOutputFormat',
outputs: [
{
// the name inside the screenshot procedure, as multiple viewpoint may
// be set, in this case this is useless
itemName: 'svg_screenshot',
// the page size in mm (A4 here)
pageSize: new Vector2(210, 287),
// camera parameters
viewpoint: lInfiniteEngine.getCameraManager().toJSON(),
// SVG file format
dataFormat: ExportSVGOutputFormat.EOF_SVG
}
],
// filename without extension
filename: 'test'
}
);
// sanity check
if(lExportJob === undefined)
{
return false;
}
// wait for file count to be known
const lWaitForFileCount : AsyncResultReason = await lExportJob.asyncWaitForFileCount();
if(lWaitForFileCount !== AsyncResultReason.ARR_Success)
{
return false;
}
const lNbFiles: number = lExportJob.getFileCount();
console.log('The export procedure consists in ' + lNbFiles + ' files');
if(lNbFiles < 1)
{
// not enough files ?
// => should not happen
return false;
}
// wait for everything to be computed
// we could have waited for a specific file with an asyncWaitForFinished(item)
const lExportResult : AsyncResultReason = await lExportJob.asyncWaitForFinished();
if(lExportResult !== AsyncResultReason.ARR_Success)
{
return false;
}
// file is ready
// claim for a download url for file 0
console.log('retrieving file ' + lExportJob.getFilename(0));
await lExportJob.asyncGetDownloadURL(0);
const lUrl : string | undefined = lExportJob.getDownloadURL(0);
if(lUrl === undefined)
{
return false;
}
// trigger a download of the file
onDownloadReady(lUrl);
return true;
};

startExportProcedure();

Please make sure the destination browser supports promises before using async calls.
AsyncJobs

interface WorkingSet2DExportInterface {
    colorModifier?: Vector3 | "restoreDMUColors";
    ignoreCutPlane?: boolean;
    isGhosted?: boolean;
    transforms?: (Matrix4 | WorkingSetExplodedViewInterface)[];
    workingSet: WorkingSetInterface;
}

Hierarchy (view full)

Properties

colorModifier?: Vector3 | "restoreDMUColors"

The optional color to set to override the DMU colors. 'restoreDMUColors' is used to reset the DMU color to their origin in case a previous WorkingSet3DExportInterface would have set a specific color for the parts belonging to the intersection of the given working sets.

ignoreCutPlane?: boolean

The optional boolean to set to tell the working set should ignore cut planes. Default state is false.

isGhosted?: boolean

The optional boolean to set to tell the working set should be displayed ghosted. Default state is false.

The optional transforms to apply to each geometric instance inside this WorkingSetInterface. This may contain matrices or explosions to apply to each geometric instance inside this WorkingSetInterface.

transforms size is limited to maximum 64 items.

Note: transforms are cumulated from left to right (first transforms[0], then transforms[1], etc ....).

The given working set to export.