@shapediver/viewer.session-engine.session-engine 2.10.1-rc.0 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/implementation/OutputDelayException.js +5 -1
  2. package/dist/implementation/OutputDelayException.js.map +1 -1
  3. package/dist/implementation/OutputLoader.d.ts +4 -1
  4. package/dist/implementation/OutputLoader.d.ts.map +1 -1
  5. package/dist/implementation/OutputLoader.js +41 -30
  6. package/dist/implementation/OutputLoader.js.map +1 -1
  7. package/dist/implementation/SessionData.js +6 -2
  8. package/dist/implementation/SessionData.js.map +1 -1
  9. package/dist/implementation/SessionEngine.d.ts +22 -12
  10. package/dist/implementation/SessionEngine.d.ts.map +1 -1
  11. package/dist/implementation/SessionEngine.js +442 -301
  12. package/dist/implementation/SessionEngine.js.map +1 -1
  13. package/dist/implementation/SessionOutputData.js +6 -2
  14. package/dist/implementation/SessionOutputData.js.map +1 -1
  15. package/dist/implementation/SessionTreeNode.js +6 -2
  16. package/dist/implementation/SessionTreeNode.js.map +1 -1
  17. package/dist/implementation/dto/Export.js +17 -13
  18. package/dist/implementation/dto/Export.js.map +1 -1
  19. package/dist/implementation/dto/FileParameter.js +34 -7
  20. package/dist/implementation/dto/FileParameter.js.map +1 -1
  21. package/dist/implementation/dto/Output.d.ts +6 -6
  22. package/dist/implementation/dto/Output.d.ts.map +1 -1
  23. package/dist/implementation/dto/Output.js +21 -14
  24. package/dist/implementation/dto/Output.js.map +1 -1
  25. package/dist/implementation/dto/Parameter.js +60 -33
  26. package/dist/implementation/dto/Parameter.js.map +1 -1
  27. package/dist/index.js +20 -11
  28. package/dist/index.js.map +1 -1
  29. package/dist/interfaces/ISessionData.js +2 -1
  30. package/dist/interfaces/ISessionEngine.d.ts +12 -8
  31. package/dist/interfaces/ISessionEngine.d.ts.map +1 -1
  32. package/dist/interfaces/ISessionEngine.js +7 -5
  33. package/dist/interfaces/ISessionEngine.js.map +1 -1
  34. package/dist/interfaces/ISessionOutputData.js +2 -1
  35. package/dist/interfaces/ISessionTreeNode.js +2 -1
  36. package/dist/interfaces/dto/IExport.js +2 -1
  37. package/dist/interfaces/dto/IFileParameter.js +2 -1
  38. package/dist/interfaces/dto/IOutput.d.ts +1 -1
  39. package/dist/interfaces/dto/IOutput.d.ts.map +1 -1
  40. package/dist/interfaces/dto/IOutput.js +2 -1
  41. package/dist/interfaces/dto/IParameter.js +2 -1
  42. package/package.json +9 -9
  43. package/src/implementation/OutputLoader.ts +16 -5
  44. package/src/implementation/SessionEngine.ts +682 -500
  45. package/src/implementation/dto/Output.ts +16 -15
  46. package/src/interfaces/ISessionEngine.ts +51 -44
  47. package/src/interfaces/dto/IOutput.ts +1 -1
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -19,21 +20,24 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
19
20
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
20
21
  };
21
22
  var _SessionEngine_customizationProcess, _SessionEngine_parameterHistory, _SessionEngine_parameterHistoryCall, _SessionEngine_parameterHistoryForward;
22
- import { HttpClient, PerformanceEvaluator, UuidGenerator, SystemInfo, Logger, ShapeDiverViewerSessionError, SettingsEngine, EVENTTYPE, EventEngine, StateEngine, ShapeDiverViewerSettingsError } from '@shapediver/viewer.shared.services';
23
- import { OutputDelayException } from './OutputDelayException';
24
- import { OutputLoader } from './OutputLoader';
25
- import { SessionTreeNode } from './SessionTreeNode';
26
- import { PARAMETER_TYPE } from '../interfaces/ISessionEngine';
27
- import { SessionData } from './SessionData';
28
- import { create, ShapeDiverResponseErrorType, ShapeDiverRequestGltfUploadQueryConversion, ShapeDiverResponseExportDefinitionType, ShapeDiverSdkConfigType, ShapeDiverResponseModelComputationStatus, isGBResponseError } from '@shapediver/sdk.geometry-api-sdk-v2';
29
- import { Tree, TreeNode } from '@shapediver/viewer.shared.node-tree';
30
- import { TASK_TYPE } from '@shapediver/viewer.shared.types';
31
- import { FileParameter } from './dto/FileParameter';
32
- import { Parameter } from './dto/Parameter';
33
- import { Export } from './dto/Export';
34
- import { Output } from './dto/Output';
35
- import { convert, latestVersion, validate } from '@shapediver/viewer.settings';
36
- export class SessionEngine {
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.SessionEngine = void 0;
25
+ const viewer_settings_1 = require("@shapediver/viewer.settings");
26
+ const sdk_geometry_api_sdk_v2_1 = require("@shapediver/sdk.geometry-api-sdk-v2");
27
+ const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
28
+ const Export_1 = require("./dto/Export");
29
+ const FileParameter_1 = require("./dto/FileParameter");
30
+ const ISessionEngine_1 = require("../interfaces/ISessionEngine");
31
+ const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
32
+ const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
33
+ const Output_1 = require("./dto/Output");
34
+ const OutputDelayException_1 = require("./OutputDelayException");
35
+ const OutputLoader_1 = require("./OutputLoader");
36
+ const Parameter_1 = require("./dto/Parameter");
37
+ const SessionData_1 = require("./SessionData");
38
+ const SessionTreeNode_1 = require("./SessionTreeNode");
39
+ /* eslint-disable @typescript-eslint/no-empty-function */
40
+ class SessionEngine {
37
41
  // #endregion Properties (43)
38
42
  // #region Constructors (1)
39
43
  /**
@@ -42,20 +46,20 @@ export class SessionEngine {
42
46
  */
43
47
  constructor(properties) {
44
48
  // #region Properties (43)
45
- this._eventEngine = EventEngine.instance;
49
+ this._eventEngine = viewer_shared_services_1.EventEngine.instance;
46
50
  this._exports = {};
47
- this._httpClient = HttpClient.instance;
48
- this._logger = Logger.instance;
51
+ this._httpClient = viewer_shared_services_1.HttpClient.instance;
52
+ this._logger = viewer_shared_services_1.Logger.instance;
49
53
  this._outputs = {};
50
54
  this._outputsFreeze = {};
51
55
  this._parameterValues = {};
52
56
  this._parameters = {};
53
- this._performanceEvaluator = PerformanceEvaluator.instance;
54
- this._sceneTree = Tree.instance;
55
- this._sessionEngineId = (UuidGenerator.instance).create();
56
- this._settingsEngine = new SettingsEngine();
57
- this._stateEngine = StateEngine.instance;
58
- this._uuidGenerator = UuidGenerator.instance;
57
+ this._performanceEvaluator = viewer_shared_services_1.PerformanceEvaluator.instance;
58
+ this._sceneTree = viewer_shared_node_tree_1.Tree.instance;
59
+ this._sessionEngineId = (viewer_shared_services_1.UuidGenerator.instance).create();
60
+ this._settingsEngine = new viewer_shared_services_1.SettingsEngine();
61
+ this._stateEngine = viewer_shared_services_1.StateEngine.instance;
62
+ this._uuidGenerator = viewer_shared_services_1.UuidGenerator.instance;
59
63
  _SessionEngine_customizationProcess.set(this, void 0);
60
64
  _SessionEngine_parameterHistory.set(this, []);
61
65
  _SessionEngine_parameterHistoryCall.set(this, false);
@@ -67,18 +71,18 @@ export class SessionEngine {
67
71
  this._dataCache = {};
68
72
  this._excludeViewports = [];
69
73
  this._headers = {
70
- "X-ShapeDiver-Origin": (SystemInfo.instance).origin,
71
- "X-ShapeDiver-SessionEngineId": this._sessionEngineId,
72
- "X-ShapeDiver-BuildVersion": '',
73
- "X-ShapeDiver-BuildDate": ''
74
+ 'X-ShapeDiver-Origin': (viewer_shared_services_1.SystemInfo.instance).origin,
75
+ 'X-ShapeDiver-SessionEngineId': this._sessionEngineId,
76
+ 'X-ShapeDiver-BuildVersion': '',
77
+ 'X-ShapeDiver-BuildDate': ''
74
78
  };
75
79
  this._initialized = false;
76
80
  this._retryCounter = 0;
77
81
  this._updateCallback = null;
78
- this._viewerSettingsVersion = latestVersion;
79
- this._viewerSettingsVersionBackend = latestVersion;
82
+ this._viewerSettingsVersion = viewer_settings_1.latestVersion;
83
+ this._viewerSettingsVersionBackend = viewer_settings_1.latestVersion;
80
84
  this._id = properties.id;
81
- this._node = new TreeNode(properties.id);
85
+ this._node = new viewer_shared_node_tree_1.TreeNode(properties.id);
82
86
  this._guid = properties.guid;
83
87
  this._ticket = properties.ticket;
84
88
  this._modelViewUrl = properties.modelViewUrl;
@@ -86,17 +90,17 @@ export class SessionEngine {
86
90
  this._jwtToken = properties.jwtToken;
87
91
  this._headers['X-ShapeDiver-BuildDate'] = properties.buildDate;
88
92
  this._headers['X-ShapeDiver-BuildVersion'] = properties.buildVersion;
89
- this._outputLoader = new OutputLoader(this);
93
+ this._outputLoader = new OutputLoader_1.OutputLoader(this);
90
94
  try {
91
- this._sdk = create(this._modelViewUrl, this._jwtToken);
92
- this._sdk.setConfigurationValue(ShapeDiverSdkConfigType.REQUEST_HEADERS, this._headers);
95
+ this._sdk = (0, sdk_geometry_api_sdk_v2_1.create)(this._modelViewUrl, this._jwtToken);
96
+ this._sdk.setConfigurationValue(sdk_geometry_api_sdk_v2_1.ShapeDiverSdkConfigType.REQUEST_HEADERS, this._headers);
93
97
  }
94
98
  catch (e) {
95
99
  throw this._httpClient.convertError(e);
96
100
  }
97
101
  }
98
102
  // #endregion Constructors (1)
99
- // #region Public Accessors (24)
103
+ // #region Public Accessors (25)
100
104
  get automaticSceneUpdate() {
101
105
  return this._automaticSceneUpdate;
102
106
  }
@@ -180,8 +184,8 @@ export class SessionEngine {
180
184
  get viewerSettings() {
181
185
  return this._viewerSettings;
182
186
  }
183
- // #endregion Public Accessors (24)
184
- // #region Public Methods (24)
187
+ // #endregion Public Accessors (25)
188
+ // #region Public Methods (27)
185
189
  applySettings(response, sections) {
186
190
  sections = sections || {};
187
191
  if (sections.session === undefined) {
@@ -201,25 +205,25 @@ export class SessionEngine {
201
205
  config = response.viewer.config;
202
206
  }
203
207
  else {
204
- throw new ShapeDiverViewerSettingsError('Session.applySettings: No config object available.');
208
+ throw new viewer_shared_services_1.ShapeDiverViewerSettingsError('Session.applySettings: No config object available.');
205
209
  }
206
210
  try {
207
- validate(config);
211
+ (0, viewer_settings_1.validate)(config);
208
212
  }
209
213
  catch (e) {
210
- throw new ShapeDiverViewerSettingsError('Session.applySettings: Was not able to validate config object.');
214
+ throw new viewer_shared_services_1.ShapeDiverViewerSettingsError('Session.applySettings: Was not able to validate config object.');
211
215
  }
212
- const settings = convert(config, latestVersion);
216
+ const settings = (0, viewer_settings_1.convert)(config, viewer_settings_1.latestVersion);
213
217
  const exportMappingUid = {};
214
218
  if (sections.session.export.displayname || sections.session.export.order || sections.session.export.hidden)
215
219
  if (response.exports)
216
- for (let exportId in response.exports)
220
+ for (const exportId in response.exports)
217
221
  if (response.exports[exportId].uid !== undefined)
218
222
  exportMappingUid[response.exports[exportId].uid] = exportId;
219
223
  const currentSettings = this._settingsEngine.settings;
220
224
  // apply parameter settings
221
225
  if (sections.session.parameter.displayname || sections.session.parameter.order || sections.session.parameter.hidden || sections.session.parameter.value) {
222
- for (let p in this.parameters) {
226
+ for (const p in this.parameters) {
223
227
  if (settings.session[p]) {
224
228
  if (sections.session.parameter.displayname)
225
229
  this.parameters[p].displayname = settings.session[p].displayname;
@@ -228,7 +232,7 @@ export class SessionEngine {
228
232
  if (sections.session.parameter.hidden)
229
233
  this.parameters[p].hidden = settings.session[p].hidden || false;
230
234
  }
231
- if (response.parameters && response.parameters[p]) {
235
+ if (response.parameters && response.parameters[p] && !((this.parameters[p] instanceof FileParameter_1.FileParameter) || this.parameters[p].type.startsWith('s'))) {
232
236
  if (sections.session.parameter.value)
233
237
  this.parameters[p].value = response.parameters[p].defval !== undefined ? response.parameters[p].defval : this.parameters[p].value;
234
238
  }
@@ -236,7 +240,7 @@ export class SessionEngine {
236
240
  }
237
241
  // apply export settings
238
242
  if (sections.session.export.displayname || sections.session.export.order || sections.session.export.hidden) {
239
- for (let p in this.exports) {
243
+ for (const p in this.exports) {
240
244
  let idForSettings = '';
241
245
  if (settings.session[p]) {
242
246
  idForSettings = p;
@@ -314,6 +318,14 @@ export class SessionEngine {
314
318
  canGoForward() {
315
319
  return __classPrivateFieldGet(this, _SessionEngine_parameterHistoryForward, "f").length > 0;
316
320
  }
321
+ cancelCustomization() {
322
+ if (__classPrivateFieldGet(this, _SessionEngine_customizationProcess, "f")) {
323
+ for (const r in this._stateEngine.renderingEngines)
324
+ if (this._stateEngine.renderingEngines[r].busy.includes(__classPrivateFieldGet(this, _SessionEngine_customizationProcess, "f")))
325
+ this._stateEngine.renderingEngines[r].busy.splice(this._stateEngine.renderingEngines[r].busy.indexOf(__classPrivateFieldGet(this, _SessionEngine_customizationProcess, "f")), 1);
326
+ }
327
+ __classPrivateFieldSet(this, _SessionEngine_customizationProcess, undefined, "f");
328
+ }
317
329
  close(retry = false) {
318
330
  return __awaiter(this, void 0, void 0, function* () {
319
331
  this.checkAvailability('close');
@@ -336,7 +348,7 @@ export class SessionEngine {
336
348
  * @param parameters the parameter set to update the session
337
349
  * @returns promise with a scene graph node
338
350
  */
339
- customize(force = false) {
351
+ customize(force = false, waitForViewportUpdate = false) {
340
352
  return __awaiter(this, void 0, void 0, function* () {
341
353
  const eventId = this._uuidGenerator.create();
342
354
  const customizationId = this._uuidGenerator.create();
@@ -350,61 +362,31 @@ export class SessionEngine {
350
362
  if (changes === false)
351
363
  return this.node;
352
364
  }
353
- const eventStart = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 0, data: { sessionId: this.id }, status: 'Customizing session' };
354
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_START, eventStart);
365
+ const eventStart = { type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 0, data: { sessionId: this.id }, status: 'Customizing session' };
366
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_START, eventStart);
355
367
  const oldNode = this.node.cloneInstance();
356
368
  __classPrivateFieldSet(this, _SessionEngine_customizationProcess, customizationId, "f");
357
369
  this._logger.debugLow(`Session(${this.id}).customize: Customizing session.`);
358
- for (let r in this._stateEngine.renderingEngines)
370
+ for (const r in this._stateEngine.renderingEngines)
359
371
  if (!this.excludeViewports.includes(r))
360
372
  this._stateEngine.renderingEngines[r].busy.push(customizationId);
361
- const eventFileUpload = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 0.1, data: { sessionId: this.id }, status: 'Uploading file parameters' };
362
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_PROCESS, eventFileUpload);
373
+ const eventFileUpload = { type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 0.1, data: { sessionId: this.id }, status: 'Uploading file parameters' };
374
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_PROCESS, eventFileUpload);
363
375
  const fileParameterIds = {};
364
376
  // load file parameter first
365
377
  for (const parameterId in this.parameters) {
366
- if (this.parameters[parameterId] instanceof FileParameter) {
378
+ if (this.parameters[parameterId] instanceof FileParameter_1.FileParameter) {
367
379
  fileParameterIds[parameterId] = yield this.parameters[parameterId].upload();
368
380
  // OPTION TO SKIP - PART 1a
369
- if (__classPrivateFieldGet(this, _SessionEngine_customizationProcess, "f") !== customizationId) {
370
- for (let r in this._stateEngine.renderingEngines)
371
- if (this._stateEngine.renderingEngines[r].busy.includes(customizationId))
372
- this._stateEngine.renderingEngines[r].busy.splice(this._stateEngine.renderingEngines[r].busy.indexOf(customizationId), 1);
373
- this._logger.debug(`Session(${this.id}).customize: Session customization was exceeded by other customization request.`);
374
- const eventCancel1a = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Session customization was exceeded by other customization request' };
375
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_CANCEL, eventCancel1a);
376
- return new SessionTreeNode();
377
- }
378
- else if (this._closed === true) {
379
- for (let r in this._stateEngine.renderingEngines)
380
- if (this._stateEngine.renderingEngines[r].busy.includes(customizationId))
381
- this._stateEngine.renderingEngines[r].busy.splice(this._stateEngine.renderingEngines[r].busy.indexOf(customizationId), 1);
382
- this._logger.debug(`Session(${this.id}).customize: Session was closed during customization request.`);
383
- const eventCancel1a = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Session was closed during customization request' };
384
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_CANCEL, eventCancel1a);
385
- return new SessionTreeNode();
386
- }
381
+ const cancelResult = this.cancelProcess(customizationId, eventId, viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION, 1, { sessionId: this.id });
382
+ if (cancelResult)
383
+ return cancelResult;
387
384
  }
388
385
  }
389
386
  // OPTION TO SKIP - PART 1b
390
- if (__classPrivateFieldGet(this, _SessionEngine_customizationProcess, "f") !== customizationId) {
391
- for (let r in this._stateEngine.renderingEngines)
392
- if (this._stateEngine.renderingEngines[r].busy.includes(customizationId))
393
- this._stateEngine.renderingEngines[r].busy.splice(this._stateEngine.renderingEngines[r].busy.indexOf(customizationId), 1);
394
- const eventCancel1b = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Session customization was exceeded by other customization request' };
395
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_CANCEL, eventCancel1b);
396
- this._logger.debug(`Session(${this.id}).customize: Session customization was exceeded by other customization request.`);
397
- return new SessionTreeNode();
398
- }
399
- else if (this._closed === true) {
400
- for (let r in this._stateEngine.renderingEngines)
401
- if (this._stateEngine.renderingEngines[r].busy.includes(customizationId))
402
- this._stateEngine.renderingEngines[r].busy.splice(this._stateEngine.renderingEngines[r].busy.indexOf(customizationId), 1);
403
- this._logger.debug(`Session(${this.id}).customize: Session was closed during customization request.`);
404
- const eventCancel1b = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Session was closed during customization request' };
405
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_CANCEL, eventCancel1b);
406
- return new SessionTreeNode();
407
- }
387
+ const cancelResult = this.cancelProcess(customizationId, eventId, viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION, 1, { sessionId: this.id });
388
+ if (cancelResult)
389
+ return cancelResult;
408
390
  // assign the uploaded parameters
409
391
  for (const parameterId in fileParameterIds)
410
392
  this.parameters[parameterId].value = fileParameterIds[parameterId];
@@ -420,37 +402,41 @@ export class SessionEngine {
420
402
  for (const parameterId in this.parameters)
421
403
  this.parameterValues[parameterId] = parameterSet[parameterId].valueString;
422
404
  this._logger.info(`Session(${this.id}).customize: Customizing session with parameters ${JSON.stringify(this.parameterValues)}.`);
423
- const eventRequest = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 0.1, data: { sessionId: this.id }, status: 'Sending customization request' };
424
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_PROCESS, eventRequest);
405
+ const eventRequest = { type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 0.1, data: { sessionId: this.id }, status: 'Sending customization request' };
406
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_PROCESS, eventRequest);
407
+ const oldOutputVersions = this._outputLoader.getCurrentOutputVersions();
425
408
  const newNode = yield this.customizeInternal(() => __classPrivateFieldGet(this, _SessionEngine_customizationProcess, "f") !== customizationId, {
426
409
  eventId,
427
- type: TASK_TYPE.SESSION_CUSTOMIZATION,
410
+ type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
428
411
  progressRange: {
429
412
  min: 0.1,
430
413
  max: 0.9
431
414
  },
432
415
  data: { sessionId: this.id }
433
416
  });
434
- const eventSceneUpdate = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 0.9, data: { sessionId: this.id }, status: 'Updating scene' };
435
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_PROCESS, eventSceneUpdate);
436
417
  // OPTION TO SKIP - PART 2
437
- if (__classPrivateFieldGet(this, _SessionEngine_customizationProcess, "f") !== customizationId) {
438
- for (let r in this._stateEngine.renderingEngines)
439
- if (this._stateEngine.renderingEngines[r].busy.includes(customizationId))
440
- this._stateEngine.renderingEngines[r].busy.splice(this._stateEngine.renderingEngines[r].busy.indexOf(customizationId), 1);
441
- const eventCancel2 = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Session customization was exceeded by other customization request' };
442
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_CANCEL, eventCancel2);
443
- this._logger.debug(`Session(${this.id}).customize: Session customization was exceeded by other customization request.`);
444
- return newNode;
445
- }
446
- else if (this._closed === true) { // I get a TS warning here that the type of _closed is "false", I think TS doesn't get that there is a promise inbetween
447
- for (let r in this._stateEngine.renderingEngines)
448
- if (this._stateEngine.renderingEngines[r].busy.includes(customizationId))
449
- this._stateEngine.renderingEngines[r].busy.splice(this._stateEngine.renderingEngines[r].busy.indexOf(customizationId), 1);
450
- this._logger.debug(`Session(${this.id}).customize: Session was closed during customization request.`);
451
- const eventCancel2 = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Session was closed during customization request' };
452
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_CANCEL, eventCancel2);
453
- return new SessionTreeNode();
418
+ const cancelResult2 = this.cancelProcess(customizationId, eventId, viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION, 1, { sessionId: this.id });
419
+ if (cancelResult2)
420
+ return cancelResult2;
421
+ const newOutputVersions = this._outputLoader.getCurrentOutputVersions();
422
+ const eventSceneUpdate = { type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 0.9, data: { sessionId: this.id }, status: 'Updating scene' };
423
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_PROCESS, eventSceneUpdate);
424
+ // call the update callbacks
425
+ if (waitForViewportUpdate === false) {
426
+ for (const outputId in this.outputs) {
427
+ if (oldOutputVersions[outputId] !== newOutputVersions[outputId]) {
428
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.OUTPUT.OUTPUT_UPDATED, {
429
+ outputId: outputId,
430
+ outputVersion: newOutputVersions[outputId],
431
+ newNode: newNode.children.find(c => c.name === outputId),
432
+ oldNode: oldNode.children.find(c => c.name === outputId)
433
+ });
434
+ }
435
+ }
436
+ yield this.waitForUpdateCallbacks(newOutputVersions, oldOutputVersions, newNode, oldNode);
437
+ const cancelResult = this.cancelProcess(customizationId, eventId, viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION, 1, { sessionId: this.id });
438
+ if (cancelResult)
439
+ return cancelResult;
454
440
  }
455
441
  // if this is not a call by the goBack or goForward functions, add the parameter values to the history and delete the forward history
456
442
  if (!__classPrivateFieldGet(this, _SessionEngine_parameterHistoryCall, "f")) {
@@ -474,64 +460,83 @@ export class SessionEngine {
474
460
  this.exports[exportId].updateExport();
475
461
  this._warningCreator();
476
462
  this.node.excludeViewports = JSON.parse(JSON.stringify(this._excludeViewports));
477
- for (let r in this._stateEngine.renderingEngines)
463
+ for (const r in this._stateEngine.renderingEngines)
478
464
  if (this._stateEngine.renderingEngines[r].busy.includes(customizationId))
479
465
  this._stateEngine.renderingEngines[r].busy.splice(this._stateEngine.renderingEngines[r].busy.indexOf(customizationId), 1);
480
466
  this._logger.debug(`Session(${this.id}).customize: Session customized.`);
481
- this._eventEngine.emitEvent(EVENTTYPE.SESSION.SESSION_CUSTOMIZED, { sessionId: this.id });
482
- const eventEnd = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Session customized' };
483
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_END, eventEnd);
467
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.SESSION.SESSION_CUSTOMIZED, { sessionId: this.id });
468
+ const eventEnd = { type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Session customized' };
469
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_END, eventEnd);
484
470
  // update the viewports
485
- for (let r in this._stateEngine.renderingEngines)
486
- if (!this.excludeViewports.includes(this._stateEngine.renderingEngines[r].id))
487
- this._stateEngine.renderingEngines[r].update(`SessionEngine(${this.id}).customize`);
488
- // call the update callback function on the session
489
- if (this._updateCallback)
490
- this._updateCallback(newNode, oldNode);
491
- // call the update callback functions on the outputs
492
- for (const outputId in this.outputs)
493
- this.outputs[outputId].triggerUpdateCallback(newNode.children.find(c => c.name === outputId), oldNode.children.find(c => c.name === outputId));
471
+ if (waitForViewportUpdate) {
472
+ for (const r in this._stateEngine.renderingEngines)
473
+ if (!this.excludeViewports.includes(this._stateEngine.renderingEngines[r].id))
474
+ this._stateEngine.renderingEngines[r].update(`SessionEngine(${this.id}).customize`);
475
+ for (const outputId in this.outputs) {
476
+ if (oldOutputVersions[outputId] !== newOutputVersions[outputId]) {
477
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.OUTPUT.OUTPUT_UPDATED, {
478
+ outputId: outputId,
479
+ outputVersion: newOutputVersions[outputId],
480
+ newNode: newNode.children.find(c => c.name === outputId),
481
+ oldNode: oldNode.children.find(c => c.name === outputId)
482
+ });
483
+ }
484
+ }
485
+ // call the update callbacks
486
+ yield this.waitForUpdateCallbacks(newOutputVersions, oldOutputVersions, newNode, oldNode);
487
+ const cancelResult = this.cancelProcess(customizationId, eventId, viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION, 1, { sessionId: this.id });
488
+ if (cancelResult)
489
+ return cancelResult;
490
+ }
491
+ if (!waitForViewportUpdate) {
492
+ setTimeout(() => {
493
+ for (const r in this._stateEngine.renderingEngines)
494
+ if (!this.excludeViewports.includes(this._stateEngine.renderingEngines[r].id))
495
+ this._stateEngine.renderingEngines[r].update(`SessionEngine(${this.id}).customize`);
496
+ }, 0);
497
+ }
494
498
  return this.node;
495
499
  }
496
500
  catch (e) {
497
- const eventCancel = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Session customization failed' };
498
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_CANCEL, eventCancel);
499
- for (let r in this._stateEngine.renderingEngines)
501
+ const eventCancel = { type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Session customization failed' };
502
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_CANCEL, eventCancel);
503
+ for (const r in this._stateEngine.renderingEngines)
500
504
  if (this._stateEngine.renderingEngines[r].busy.includes(customizationId))
501
505
  this._stateEngine.renderingEngines[r].busy.splice(this._stateEngine.renderingEngines[r].busy.indexOf(customizationId), 1);
502
506
  throw this._httpClient.convertError(e);
503
507
  }
504
508
  });
505
509
  }
506
- customizeParallel(parameterValues) {
510
+ customizeParallel(parameterValues, loadOutputs = true) {
507
511
  return __awaiter(this, void 0, void 0, function* () {
508
512
  const eventId = this._uuidGenerator.create();
509
- const eventStart = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 0, data: { sessionId: this.id }, status: 'Customizing session' };
510
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_START, eventStart);
513
+ const eventStart = { type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 0, data: { sessionId: this.id }, status: 'Customizing session' };
514
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_START, eventStart);
511
515
  const parameterSet = {};
512
516
  // create a set of the current validated parameter values
513
517
  for (const parameterId in this.parameters)
514
518
  parameterSet[parameterId] = parameterValues[parameterId] !== undefined ? (' ' + parameterValues[parameterId]).slice(1) : this.parameters[parameterId].stringify();
515
- const newNode = yield this.customizeSession(parameterSet, () => false, {
519
+ const result = yield this.customizeSession(parameterSet, () => false, {
516
520
  eventId,
517
- type: TASK_TYPE.SESSION_CUSTOMIZATION,
521
+ type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
518
522
  progressRange: {
519
523
  min: 0.0,
520
524
  max: 1
521
525
  },
522
526
  data: { sessionId: this.id }
523
- }, true);
524
- newNode.excludeViewports = JSON.parse(JSON.stringify(this._excludeViewports));
525
- const eventEnd = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Session customized' };
526
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_END, eventEnd);
527
- return newNode;
527
+ }, true, loadOutputs);
528
+ if (result instanceof SessionTreeNode_1.SessionTreeNode)
529
+ result.excludeViewports = JSON.parse(JSON.stringify(this._excludeViewports));
530
+ const eventEnd = { type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Session customized' };
531
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_END, eventEnd);
532
+ return result;
528
533
  });
529
534
  }
530
535
  goBack() {
531
536
  return __awaiter(this, void 0, void 0, function* () {
532
537
  if (!this.canGoBack()) {
533
538
  this._logger.debug(`Session(${this.id}).goBack: Cannot go further back.`);
534
- return new TreeNode();
539
+ return new viewer_shared_node_tree_1.TreeNode();
535
540
  }
536
541
  // get the current parameter set and store it in the forward history later on
537
542
  const currentParameterSet = __classPrivateFieldGet(this, _SessionEngine_parameterHistory, "f").pop();
@@ -552,7 +557,7 @@ export class SessionEngine {
552
557
  return __awaiter(this, void 0, void 0, function* () {
553
558
  if (!this.canGoForward()) {
554
559
  this._logger.debug(`Session(${this.id}).goForward: Cannot go further forward.`);
555
- return new TreeNode();
560
+ return new viewer_shared_node_tree_1.TreeNode();
556
561
  }
557
562
  // get the last undone parameter set and apply the values to the parameters
558
563
  const lastParameterSet = __classPrivateFieldGet(this, _SessionEngine_parameterHistoryForward, "f").pop();
@@ -576,7 +581,7 @@ export class SessionEngine {
576
581
  var _a, _b;
577
582
  return __awaiter(this, void 0, void 0, function* () {
578
583
  if (this._initialized === true)
579
- throw new ShapeDiverViewerSessionError('Session.init: Session already initialized.');
584
+ throw new viewer_shared_services_1.ShapeDiverViewerSessionError('Session.init: Session already initialized.');
580
585
  try {
581
586
  this._performanceEvaluator.startSection('sessionResponse');
582
587
  const parameterSet = {};
@@ -591,11 +596,11 @@ export class SessionEngine {
591
596
  }
592
597
  else {
593
598
  // we should never get here
594
- throw new ShapeDiverViewerSessionError(`Session.init: Initialization of session failed. Neither a ticket nor a guid are available.`);
599
+ throw new viewer_shared_services_1.ShapeDiverViewerSessionError('Session.init: Initialization of session failed. Neither a ticket nor a guid are available.');
595
600
  }
596
601
  this._performanceEvaluator.endSection('sessionResponse');
597
602
  this._viewerSettings = (_a = this._responseDto.viewer) === null || _a === void 0 ? void 0 : _a.config;
598
- this._viewerSettingsVersionBackend = this._responseDto.viewerSettingsVersion || latestVersion;
603
+ this._viewerSettingsVersionBackend = this._responseDto.viewerSettingsVersion || viewer_settings_1.latestVersion;
599
604
  this._sessionId = this._responseDto.sessionId;
600
605
  this._modelId = (_b = this._responseDto.model) === null || _b === void 0 ? void 0 : _b.id;
601
606
  this._httpClient.addDataLoading(this._sessionId, {
@@ -604,9 +609,9 @@ export class SessionEngine {
604
609
  });
605
610
  this._settingsEngine.loadSettings(this._viewerSettings);
606
611
  if (!this._sessionId)
607
- throw new ShapeDiverViewerSessionError(`Session.init: Initialization of session failed. ResponseDto did not have a sessionId.`);
612
+ throw new viewer_shared_services_1.ShapeDiverViewerSessionError('Session.init: Initialization of session failed. ResponseDto did not have a sessionId.');
608
613
  if (!this._modelId)
609
- throw new ShapeDiverViewerSessionError(`Session.init: Initialization of session failed. ResponseDto did not have a model.id.`);
614
+ throw new viewer_shared_services_1.ShapeDiverViewerSessionError('Session.init: Initialization of session failed. ResponseDto did not have a model.id.');
610
615
  this.updateResponseDto(this._responseDto, parameterSet);
611
616
  this._initialized = true;
612
617
  }
@@ -616,6 +621,55 @@ export class SessionEngine {
616
621
  }
617
622
  });
618
623
  }
624
+ loadCachedOutputsParallel(outputMapping, taskEventInfo, retry = false) {
625
+ var _a;
626
+ return __awaiter(this, void 0, void 0, function* () {
627
+ this.checkAvailability();
628
+ // if there is already task event info, use it
629
+ // this happens after a retry
630
+ const eventId = taskEventInfo ? taskEventInfo.eventId : this._uuidGenerator.create();
631
+ const eventType = taskEventInfo ? taskEventInfo.type : viewer_shared_types_1.TASK_TYPE.SESSION_OUTPUTS_LOADING;
632
+ const eventData = taskEventInfo ? taskEventInfo.data : { sessionId: this.id };
633
+ taskEventInfo = taskEventInfo ? taskEventInfo : {
634
+ eventId,
635
+ type: eventType,
636
+ progressRange: {
637
+ min: 0,
638
+ max: 1
639
+ },
640
+ data: eventData
641
+ };
642
+ try {
643
+ // send start event if this function was called initially
644
+ if (!taskEventInfo) {
645
+ const eventStart = { type: eventType, id: eventId, progress: 0, data: eventData, status: 'Loading cached outputs' };
646
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_START, eventStart);
647
+ }
648
+ // get the cached outputs
649
+ const responseDto = yield this._sdk.output.getCache(this._sessionId, outputMapping);
650
+ // create atomic output api objects for them
651
+ const outputs = {};
652
+ for (const outputId in responseDto.outputs) {
653
+ responseDto.outputs[outputId].id = outputId;
654
+ outputs[outputId] = new Output_1.Output(responseDto.outputs[outputId], this);
655
+ }
656
+ // process the output data
657
+ const node = yield this._outputLoader.loadOutputs(((_a = this._responseDto.model) === null || _a === void 0 ? void 0 : _a.name) || 'model', outputs, {}, taskEventInfo, false);
658
+ // send the end event once done
659
+ const eventEnd = { type: eventType, id: eventId, progress: 1, data: eventData, status: 'Loaded cached outputs' };
660
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_END, eventEnd);
661
+ // create a mapping with a dictionary for the id of the outputs
662
+ const outputNodeMapping = {};
663
+ for (const outputId in outputMapping)
664
+ outputNodeMapping[outputId] = node.children.find(n => n.name === outputId);
665
+ return outputNodeMapping;
666
+ }
667
+ catch (e) {
668
+ yield this.handleError(e, retry);
669
+ return yield this.loadCachedOutputsParallel(outputMapping, taskEventInfo, true);
670
+ }
671
+ });
672
+ }
619
673
  /**
620
674
  * Load the outputs and return the scene graph node of the result.
621
675
  * In case the outputs have a delay property, another customization request with the parameter set is sent.
@@ -624,50 +678,47 @@ export class SessionEngine {
624
678
  * @param outputs the outputs to load
625
679
  * @returns promise with a scene graph node
626
680
  */
627
- loadOutputsParallel(responseDto, cancelRequest = () => false, taskEventInfo, retry = false) {
681
+ loadOutputs(cancelRequest = () => false, taskEventInfo, retry = false) {
628
682
  var _a;
629
683
  return __awaiter(this, void 0, void 0, function* () {
630
684
  this.checkAvailability();
631
- let outputs = {};
632
- let outputsFreeze = {};
633
- for (let outputId in responseDto.outputs) {
634
- responseDto.outputs[outputId].id = outputId;
635
- if (this.outputsFreeze[outputId] === undefined)
636
- outputsFreeze[outputId] = false;
637
- outputs[outputId] = new Output(responseDto.outputs[outputId], this);
638
- }
685
+ const o = Object.assign({}, this._outputs);
686
+ const of = Object.assign({}, this._outputsFreeze);
639
687
  try {
640
- const node = yield this._outputLoader.loadOutputs(((_a = this._responseDto.model) === null || _a === void 0 ? void 0 : _a.name) || 'model', outputs, outputsFreeze, taskEventInfo);
641
- node.data.push(new SessionData(responseDto));
688
+ const node = yield this._outputLoader.loadOutputs(((_a = this._responseDto.model) === null || _a === void 0 ? void 0 : _a.name) || 'model', o, of, taskEventInfo);
689
+ node.data.push(new SessionData_1.SessionData(this._responseDto));
690
+ if (cancelRequest())
691
+ return node;
692
+ node.excludeViewports = JSON.parse(JSON.stringify(this._excludeViewports));
642
693
  return node;
643
694
  }
644
695
  catch (e) {
645
- if (e instanceof OutputDelayException) {
696
+ if (e instanceof OutputDelayException_1.OutputDelayException) {
646
697
  yield this.timeout(e.delay);
647
698
  }
648
699
  else {
649
700
  yield this.handleError(e, retry);
650
701
  if (cancelRequest())
651
- return new SessionTreeNode();
652
- return yield this.loadOutputsParallel(responseDto, cancelRequest, taskEventInfo, true);
702
+ return new SessionTreeNode_1.SessionTreeNode();
703
+ return yield this.loadOutputs(cancelRequest, taskEventInfo, true);
653
704
  }
654
705
  if (cancelRequest())
655
- return new SessionTreeNode();
656
- let outputMapping = {};
657
- for (let output in outputs)
658
- outputMapping[output] = outputs[output].version;
706
+ return new SessionTreeNode_1.SessionTreeNode();
707
+ const outputMapping = {};
708
+ for (const output in o)
709
+ outputMapping[output] = o[output].version;
659
710
  try {
660
711
  const responseDto = yield this._sdk.output.getCache(this._sessionId, outputMapping);
661
712
  if (cancelRequest())
662
- return new SessionTreeNode();
713
+ return new SessionTreeNode_1.SessionTreeNode();
663
714
  this.updateResponseDto(responseDto);
664
- return yield this.loadOutputsParallel(responseDto, cancelRequest, taskEventInfo);
715
+ return yield this.loadOutputs(cancelRequest, taskEventInfo);
665
716
  }
666
717
  catch (e) {
667
718
  yield this.handleError(e, retry);
668
719
  if (cancelRequest())
669
- return new SessionTreeNode();
670
- return yield this.loadOutputsParallel(responseDto, cancelRequest, taskEventInfo, true);
720
+ return new SessionTreeNode_1.SessionTreeNode();
721
+ return yield this.loadOutputs(cancelRequest, taskEventInfo, true);
671
722
  }
672
723
  }
673
724
  });
@@ -680,52 +731,50 @@ export class SessionEngine {
680
731
  * @param outputs the outputs to load
681
732
  * @returns promise with a scene graph node
682
733
  */
683
- loadOutputs(cancelRequest = () => false, taskEventInfo, retry = false) {
734
+ loadOutputsParallel(responseDto, cancelRequest = () => false, taskEventInfo, retry = false) {
684
735
  var _a;
685
736
  return __awaiter(this, void 0, void 0, function* () {
686
737
  this.checkAvailability();
687
- const o = Object.assign({}, this._outputs);
688
- const of = Object.assign({}, this._outputsFreeze);
738
+ const outputs = {};
739
+ const outputsFreeze = {};
740
+ for (const outputId in responseDto.outputs) {
741
+ responseDto.outputs[outputId].id = outputId;
742
+ if (this.outputsFreeze[outputId] === undefined)
743
+ outputsFreeze[outputId] = false;
744
+ outputs[outputId] = new Output_1.Output(responseDto.outputs[outputId], this);
745
+ }
689
746
  try {
690
- const node = yield this._outputLoader.loadOutputs(((_a = this._responseDto.model) === null || _a === void 0 ? void 0 : _a.name) || 'model', o, of, taskEventInfo);
691
- node.data.push(new SessionData(this._responseDto));
692
- if (cancelRequest())
693
- return node;
694
- if (this._automaticSceneUpdate)
695
- this.removeFromSceneTree(this._node);
696
- this._node = node;
697
- if (this._automaticSceneUpdate && this._closed === false)
698
- this.addToSceneTree(this._node);
699
- this.node.excludeViewports = JSON.parse(JSON.stringify(this._excludeViewports));
747
+ const node = yield this._outputLoader.loadOutputs(((_a = this._responseDto.model) === null || _a === void 0 ? void 0 : _a.name) || 'model', outputs, outputsFreeze, taskEventInfo);
748
+ node.data.push(new SessionData_1.SessionData(responseDto));
700
749
  return node;
701
750
  }
702
751
  catch (e) {
703
- if (e instanceof OutputDelayException) {
752
+ if (e instanceof OutputDelayException_1.OutputDelayException) {
704
753
  yield this.timeout(e.delay);
705
754
  }
706
755
  else {
707
756
  yield this.handleError(e, retry);
708
757
  if (cancelRequest())
709
- return new SessionTreeNode();
710
- return yield this.loadOutputs(cancelRequest, taskEventInfo, true);
758
+ return new SessionTreeNode_1.SessionTreeNode();
759
+ return yield this.loadOutputsParallel(responseDto, cancelRequest, taskEventInfo, true);
711
760
  }
712
761
  if (cancelRequest())
713
- return new SessionTreeNode();
714
- let outputMapping = {};
715
- for (let output in o)
716
- outputMapping[output] = o[output].version;
762
+ return new SessionTreeNode_1.SessionTreeNode();
763
+ const outputMapping = {};
764
+ for (const output in outputs)
765
+ outputMapping[output] = outputs[output].version;
717
766
  try {
718
767
  const responseDto = yield this._sdk.output.getCache(this._sessionId, outputMapping);
719
768
  if (cancelRequest())
720
- return new SessionTreeNode();
769
+ return new SessionTreeNode_1.SessionTreeNode();
721
770
  this.updateResponseDto(responseDto);
722
- return yield this.loadOutputs(cancelRequest, taskEventInfo);
771
+ return yield this.loadOutputsParallel(responseDto, cancelRequest, taskEventInfo);
723
772
  }
724
773
  catch (e) {
725
774
  yield this.handleError(e, retry);
726
775
  if (cancelRequest())
727
- return new SessionTreeNode();
728
- return yield this.loadOutputs(cancelRequest, taskEventInfo, true);
776
+ return new SessionTreeNode_1.SessionTreeNode();
777
+ return yield this.loadOutputsParallel(responseDto, cancelRequest, taskEventInfo, true);
729
778
  }
730
779
  }
731
780
  });
@@ -734,27 +783,7 @@ export class SessionEngine {
734
783
  return __awaiter(this, void 0, void 0, function* () {
735
784
  this.checkAvailability('export');
736
785
  try {
737
- const requestParameterSet = {};
738
- // first step, we convert all our names and displaynames to ids
739
- for (const parameterIdOrName in parameters) {
740
- // we prioritize id, then name and then displayname
741
- // if there are two parameters with the same name or displayname, we take the one that is found first (no way for us to evaluate which one the user meant)
742
- const parameterObject = Object.values(this._parameters).find(p => p.id === parameterIdOrName || p.name === parameterIdOrName || p.displayname === parameterIdOrName);
743
- // in case the key of the key value pair was neither the id, name or displayname, skip
744
- if (!parameterObject)
745
- continue;
746
- // deep copy into new dictionary
747
- requestParameterSet[parameterObject.id] = (' ' + parameters[parameterIdOrName]).slice(1);
748
- }
749
- // seconds step, fill all other parameter values that are currently not set
750
- const currentParameters = this.parameterValues;
751
- for (const parameterId in currentParameters) {
752
- // if already set by input values, skip
753
- if (requestParameterSet[parameterId] !== undefined)
754
- continue;
755
- // deep copy into new dictionary
756
- requestParameterSet[parameterId] = (' ' + currentParameters[parameterId]).slice(1);
757
- }
786
+ const requestParameterSet = this.cleanExportParameters(parameters);
758
787
  const responseDto = yield this._sdk.utils.submitAndWaitForExport(this._sdk, this._sessionId, { exports: { id: exportId }, parameters: requestParameterSet }, maxWaitTime);
759
788
  this.updateResponseDto(responseDto);
760
789
  return this.exports[exportId];
@@ -765,9 +794,24 @@ export class SessionEngine {
765
794
  }
766
795
  });
767
796
  }
797
+ requestExports(body, maxWaitMsec, retry = false) {
798
+ return __awaiter(this, void 0, void 0, function* () {
799
+ this.checkAvailability('export');
800
+ try {
801
+ const requestParameterSet = this.cleanExportParameters(body.parameters);
802
+ const responseDto = yield this._sdk.utils.submitAndWaitForExport(this._sdk, this._sessionId, { exports: body.exports, parameters: requestParameterSet, outputs: body.outputs, max_wait_time: body.max_wait_time }, maxWaitMsec);
803
+ this.updateResponseDto(responseDto);
804
+ return responseDto;
805
+ }
806
+ catch (e) {
807
+ yield this.handleError(e, retry);
808
+ return yield this.requestExports(body, maxWaitMsec, true);
809
+ }
810
+ });
811
+ }
768
812
  resetSettings(sections) {
769
813
  if (!this._responseDto)
770
- throw new ShapeDiverViewerSessionError(`Session.resetSettings: responseDto not available.`);
814
+ throw new viewer_shared_services_1.ShapeDiverViewerSessionError('Session.resetSettings: responseDto not available.');
771
815
  sections = sections || {};
772
816
  if (sections.session === undefined) {
773
817
  sections.session = {
@@ -791,7 +835,7 @@ export class SessionEngine {
791
835
  this._logger.debug(`Session(${this.id}).saveDefaultParameters: Saved default parameters.`);
792
836
  }
793
837
  else {
794
- throw new ShapeDiverViewerSessionError(`Session(${this.id}).saveDefaultParameters: Could not save default parameters.`);
838
+ throw new viewer_shared_services_1.ShapeDiverViewerSessionError(`Session(${this.id}).saveDefaultParameters: Could not save default parameters.`);
795
839
  }
796
840
  return response;
797
841
  });
@@ -870,14 +914,14 @@ export class SessionEngine {
870
914
  return __awaiter(this, void 0, void 0, function* () {
871
915
  this.checkAvailability('configure', true);
872
916
  try {
873
- validate(json, this._viewerSettingsVersion);
917
+ (0, viewer_settings_1.validate)(json, this._viewerSettingsVersion);
874
918
  // if viewer settings version is higher than backend settings version
875
919
  // convert to backend settings version
876
920
  if (+this._viewerSettingsVersion > +this._viewerSettingsVersionBackend)
877
- json = convert(json, this._viewerSettingsVersionBackend);
921
+ json = (0, viewer_settings_1.convert)(json, this._viewerSettingsVersionBackend);
878
922
  }
879
923
  catch (e) {
880
- throw new ShapeDiverViewerSettingsError('Session.saveSettings: Settings could not be validated. ' + e.message, e);
924
+ throw new viewer_shared_services_1.ShapeDiverViewerSettingsError('Session.saveSettings: Settings could not be validated. ' + e.message, e);
881
925
  }
882
926
  try {
883
927
  yield this._sdk.model.updateConfig(this._modelId, json);
@@ -895,7 +939,7 @@ export class SessionEngine {
895
939
  // settings saving
896
940
  this._saveSessionSettings();
897
941
  let properties = {};
898
- for (let p in this.parameters) {
942
+ for (const p in this.parameters) {
899
943
  properties[p] = {
900
944
  displayname: this.parameters[p].displayname !== undefined ? this.parameters[p].displayname : '',
901
945
  hidden: this.parameters[p].hidden !== undefined ? this.parameters[p].hidden : false,
@@ -905,7 +949,7 @@ export class SessionEngine {
905
949
  }
906
950
  const responseP = Object.values(properties).length !== 0 ? yield this.saveParameterProperties(properties) : true;
907
951
  properties = {};
908
- for (let e in this.exports) {
952
+ for (const e in this.exports) {
909
953
  properties[e] = {
910
954
  displayname: this.exports[e].displayname !== undefined ? this.exports[e].displayname : '',
911
955
  hidden: this.exports[e].hidden !== undefined ? this.exports[e].hidden : false,
@@ -915,7 +959,7 @@ export class SessionEngine {
915
959
  }
916
960
  const responseE = Object.values(properties).length !== 0 ? yield this.saveExportProperties(properties) : true;
917
961
  properties = {};
918
- for (let o in this.outputs) {
962
+ for (const o in this.outputs) {
919
963
  properties[o] = {
920
964
  displayname: this.outputs[o].displayname !== undefined ? this.outputs[o].displayname : '',
921
965
  hidden: this.outputs[o].hidden !== undefined ? this.outputs[o].hidden : false,
@@ -940,7 +984,7 @@ export class SessionEngine {
940
984
  this.checkAvailability();
941
985
  this._jwtToken = value;
942
986
  try {
943
- this._sdk.setConfigurationValue(ShapeDiverSdkConfigType.JWT_TOKEN, value);
987
+ this._sdk.setConfigurationValue(sdk_geometry_api_sdk_v2_1.ShapeDiverSdkConfigType.JWT_TOKEN, value);
944
988
  const responseDto = yield this._sdk.session.default(this._sessionId);
945
989
  if (this._responseDto)
946
990
  this._responseDto.actions = responseDto.actions;
@@ -950,24 +994,25 @@ export class SessionEngine {
950
994
  }
951
995
  });
952
996
  }
953
- updateOutputs(taskEventInfo) {
997
+ updateOutputs(taskEventInfo, waitForViewportUpdate = false) {
954
998
  return __awaiter(this, void 0, void 0, function* () {
955
999
  const eventId = taskEventInfo ? taskEventInfo.eventId : this._uuidGenerator.create();
956
- const eventType = taskEventInfo ? taskEventInfo.type : TASK_TYPE.SESSION_OUTPUTS_UPDATE;
1000
+ const eventType = taskEventInfo ? taskEventInfo.type : viewer_shared_types_1.TASK_TYPE.SESSION_OUTPUTS_UPDATE;
957
1001
  const eventData = taskEventInfo ? taskEventInfo.data : { sessionId: this.id };
958
1002
  if (!taskEventInfo) {
959
1003
  const eventStart = { type: eventType, id: eventId, progress: 0, data: eventData, status: 'Updating outputs' };
960
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_START, eventStart);
1004
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_START, eventStart);
961
1005
  }
962
1006
  const customizationId = this._uuidGenerator.create();
963
1007
  const oldNode = this.node.cloneInstance();
964
1008
  __classPrivateFieldSet(this, _SessionEngine_customizationProcess, customizationId, "f");
965
1009
  this._logger.debugLow(`Session(${this.id}).updateOutputs: Updating Outputs.`);
966
- for (let r in this._stateEngine.renderingEngines)
1010
+ for (const r in this._stateEngine.renderingEngines)
967
1011
  if (!this.excludeViewports.includes(r))
968
1012
  this._stateEngine.renderingEngines[r].busy.push(customizationId);
969
1013
  const eventRequest = { type: eventType, id: eventId, progress: taskEventInfo ? (taskEventInfo.progressRange.max - taskEventInfo.progressRange.min) * 0.1 + taskEventInfo.progressRange.min : 0.1, data: eventData, status: 'Loading outputs' };
970
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_PROCESS, eventRequest);
1014
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_PROCESS, eventRequest);
1015
+ const oldOutputVersions = this._outputLoader.getCurrentOutputVersions();
971
1016
  const newNode = yield this.loadOutputs(() => __classPrivateFieldGet(this, _SessionEngine_customizationProcess, "f") !== customizationId, {
972
1017
  eventId,
973
1018
  type: eventType,
@@ -977,26 +1022,30 @@ export class SessionEngine {
977
1022
  },
978
1023
  data: eventData
979
1024
  });
1025
+ const newOutputVersions = this._outputLoader.getCurrentOutputVersions();
980
1026
  const eventSceneUpdate = { type: eventType, id: eventId, progress: taskEventInfo ? (taskEventInfo.progressRange.max - taskEventInfo.progressRange.min) * 0.9 + taskEventInfo.progressRange.min : 0.9, data: eventData, status: 'Updating scene' };
981
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_PROCESS, eventSceneUpdate);
1027
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_PROCESS, eventSceneUpdate);
982
1028
  // OPTION TO SKIP - PART 1
983
- if (__classPrivateFieldGet(this, _SessionEngine_customizationProcess, "f") !== customizationId) {
984
- for (let r in this._stateEngine.renderingEngines)
985
- if (this._stateEngine.renderingEngines[r].busy.includes(customizationId))
986
- this._stateEngine.renderingEngines[r].busy.splice(this._stateEngine.renderingEngines[r].busy.indexOf(customizationId), 1);
987
- const eventCancel1 = { type: eventType, id: eventId, progress: taskEventInfo ? (taskEventInfo.progressRange.max - taskEventInfo.progressRange.min) * 1 + taskEventInfo.progressRange.min : 1, data: eventData, status: 'Output updating was exceeded by other customization request' };
988
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_CANCEL, eventCancel1);
989
- this._logger.debug(`Session(${this.id}).updateOutputs: Output updating was exceeded by other request.`);
990
- return newNode;
991
- }
992
- else if (this._closed === true) {
993
- for (let r in this._stateEngine.renderingEngines)
994
- if (this._stateEngine.renderingEngines[r].busy.includes(customizationId))
995
- this._stateEngine.renderingEngines[r].busy.splice(this._stateEngine.renderingEngines[r].busy.indexOf(customizationId), 1);
996
- this._logger.debug(`Session(${this.id}).customize: Session was closed during customization request.`);
997
- const eventCancel1a = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Session was closed during customization request' };
998
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_CANCEL, eventCancel1a);
999
- return new SessionTreeNode();
1029
+ const cancelResult = this.cancelProcess(customizationId, eventId, eventType, taskEventInfo ? (taskEventInfo.progressRange.max - taskEventInfo.progressRange.min) * 1 + taskEventInfo.progressRange.min : 1, eventData, newNode);
1030
+ if (cancelResult)
1031
+ return cancelResult;
1032
+ // call the update callbacks
1033
+ if (waitForViewportUpdate === false) {
1034
+ for (const outputId in this.outputs) {
1035
+ if (oldOutputVersions[outputId] !== newOutputVersions[outputId]) {
1036
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.OUTPUT.OUTPUT_UPDATED, {
1037
+ outputId: outputId,
1038
+ outputVersion: newOutputVersions[outputId],
1039
+ newNode: newNode.children.find(c => c.name === outputId),
1040
+ oldNode: oldNode.children.find(c => c.name === outputId)
1041
+ });
1042
+ }
1043
+ }
1044
+ yield this.waitForUpdateCallbacks(newOutputVersions, oldOutputVersions, newNode, oldNode);
1045
+ // OPTION TO SKIP - PART 2
1046
+ const cancelResult = this.cancelProcess(customizationId, eventId, eventType, taskEventInfo ? (taskEventInfo.progressRange.max - taskEventInfo.progressRange.min) * 1 + taskEventInfo.progressRange.min : 1, eventData, newNode);
1047
+ if (cancelResult)
1048
+ return cancelResult;
1000
1049
  }
1001
1050
  if (this.automaticSceneUpdate)
1002
1051
  this.removeFromSceneTree(this.node);
@@ -1013,24 +1062,35 @@ export class SessionEngine {
1013
1062
  this.exports[exportId].updateExport();
1014
1063
  this._warningCreator();
1015
1064
  this.node.excludeViewports = JSON.parse(JSON.stringify(this._excludeViewports));
1016
- for (let r in this._stateEngine.renderingEngines)
1065
+ for (const r in this._stateEngine.renderingEngines)
1017
1066
  if (this._stateEngine.renderingEngines[r].busy.includes(customizationId))
1018
1067
  this._stateEngine.renderingEngines[r].busy.splice(this._stateEngine.renderingEngines[r].busy.indexOf(customizationId), 1);
1019
1068
  this._logger.debug(`Session(${this.id}).updateOutputs: Updated outputs.`);
1020
1069
  if (!taskEventInfo) {
1021
1070
  const eventEnd = { type: eventType, id: eventId, progress: 1, data: eventData, status: 'Outputs updated' };
1022
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_END, eventEnd);
1071
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_END, eventEnd);
1023
1072
  }
1024
1073
  // update the viewports
1025
- for (let r in this._stateEngine.renderingEngines)
1026
- if (!this.excludeViewports.includes(this._stateEngine.renderingEngines[r].id))
1027
- this._stateEngine.renderingEngines[r].update(`SessionEngine(${this.id}).customize`);
1028
- // call the update callback function on the session
1029
- if (this._updateCallback)
1030
- this._updateCallback(newNode, oldNode);
1031
- // call the update callback functions on the outputs
1032
- for (const outputId in this.outputs)
1033
- this.outputs[outputId].triggerUpdateCallback(newNode.children.find(c => c.name === outputId), oldNode.children.find(c => c.name === outputId));
1074
+ if (waitForViewportUpdate) {
1075
+ for (const r in this._stateEngine.renderingEngines)
1076
+ if (!this.excludeViewports.includes(this._stateEngine.renderingEngines[r].id))
1077
+ this._stateEngine.renderingEngines[r].update(`SessionEngine(${this.id}).updateOutputs`);
1078
+ for (const outputId in this.outputs) {
1079
+ if (oldOutputVersions[outputId] !== newOutputVersions[outputId]) {
1080
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.OUTPUT.OUTPUT_UPDATED, {
1081
+ outputId: outputId,
1082
+ outputVersion: newOutputVersions[outputId],
1083
+ newNode: newNode.children.find(c => c.name === outputId),
1084
+ oldNode: oldNode.children.find(c => c.name === outputId)
1085
+ });
1086
+ }
1087
+ }
1088
+ yield this.waitForUpdateCallbacks(newOutputVersions, oldOutputVersions, newNode, oldNode);
1089
+ // OPTION TO SKIP - PART 3
1090
+ const cancelResult = this.cancelProcess(customizationId, eventId, eventType, taskEventInfo ? (taskEventInfo.progressRange.max - taskEventInfo.progressRange.min) * 1 + taskEventInfo.progressRange.min : 1, eventData, newNode);
1091
+ if (cancelResult)
1092
+ return cancelResult;
1093
+ }
1034
1094
  return this.node;
1035
1095
  });
1036
1096
  }
@@ -1047,7 +1107,7 @@ export class SessionEngine {
1047
1107
  return fileAsset.id;
1048
1108
  }
1049
1109
  else {
1050
- throw new ShapeDiverViewerSessionError(`Session.uploadFile: Upload reply has not the required format.`);
1110
+ throw new viewer_shared_services_1.ShapeDiverViewerSessionError('Session.uploadFile: Upload reply has not the required format.');
1051
1111
  }
1052
1112
  }
1053
1113
  catch (e) {
@@ -1056,13 +1116,13 @@ export class SessionEngine {
1056
1116
  }
1057
1117
  });
1058
1118
  }
1059
- uploadGLTF(blob, conversion = ShapeDiverRequestGltfUploadQueryConversion.NONE, retry = false) {
1119
+ uploadGLTF(blob, conversion = sdk_geometry_api_sdk_v2_1.ShapeDiverRequestGltfUploadQueryConversion.NONE, retry = false) {
1060
1120
  return __awaiter(this, void 0, void 0, function* () {
1061
1121
  this.checkAvailability('gltf-upload');
1062
1122
  try {
1063
1123
  const responseDto = yield this._sdk.gltf.upload(this._sessionId, yield blob.arrayBuffer(), 'model/gltf-binary', conversion);
1064
1124
  if (!responseDto || !responseDto.gltf || !responseDto.gltf.href)
1065
- throw new ShapeDiverViewerSessionError(`Session.uploadGLTF: Upload reply has not the required format.`);
1125
+ throw new viewer_shared_services_1.ShapeDiverViewerSessionError('Session.uploadGLTF: Upload reply has not the required format.');
1066
1126
  return responseDto;
1067
1127
  }
1068
1128
  catch (e) {
@@ -1071,20 +1131,20 @@ export class SessionEngine {
1071
1131
  }
1072
1132
  });
1073
1133
  }
1074
- // #endregion Public Methods (24)
1075
- // #region Private Methods (10)
1134
+ // #endregion Public Methods (27)
1135
+ // #region Private Methods (13)
1076
1136
  _saveSessionSettings() {
1077
1137
  const parameters = this.parameters;
1078
1138
  const exports = this.exports;
1079
1139
  const sessionProperties = {};
1080
- for (let p in parameters) {
1140
+ for (const p in parameters) {
1081
1141
  sessionProperties[p] = {
1082
1142
  order: parameters[p].order || 0,
1083
1143
  displayname: parameters[p].displayname || '',
1084
1144
  hidden: parameters[p].hidden
1085
1145
  };
1086
1146
  }
1087
- for (let e in exports) {
1147
+ for (const e in exports) {
1088
1148
  sessionProperties[e] = {
1089
1149
  order: exports[e].order || 0,
1090
1150
  displayname: exports[e].displayname || '',
@@ -1093,10 +1153,10 @@ export class SessionEngine {
1093
1153
  }
1094
1154
  this._settingsEngine.session = sessionProperties;
1095
1155
  let orderedOutputs = [];
1096
- for (let o in this.outputs)
1156
+ for (const o in this.outputs)
1097
1157
  orderedOutputs.push(this.outputs[o]);
1098
1158
  orderedOutputs.sort((a, b) => ((a.order || Infinity) - (b.order || Infinity)));
1099
- let zerosOutputs = orderedOutputs.filter(x => x.order === 0);
1159
+ const zerosOutputs = orderedOutputs.filter(x => x.order === 0);
1100
1160
  orderedOutputs = orderedOutputs.filter((el) => { return !zerosOutputs.includes(el); });
1101
1161
  orderedOutputs = zerosOutputs.concat(orderedOutputs);
1102
1162
  const controlOrderOutputs = orderedOutputs.map((value) => { return value.id; });
@@ -1112,9 +1172,9 @@ export class SessionEngine {
1112
1172
  let warning = '';
1113
1173
  if (this.outputs[outputId].msg)
1114
1174
  warning += `\n\t- ${this.outputs[outputId].msg}`;
1115
- if (this.outputs[outputId].status_collect && this.outputs[outputId].status_collect !== ShapeDiverResponseModelComputationStatus.SUCCESS)
1175
+ if (this.outputs[outputId].status_collect && this.outputs[outputId].status_collect !== sdk_geometry_api_sdk_v2_1.ShapeDiverResponseModelComputationStatus.SUCCESS)
1116
1176
  warning += `\n\t- status_collect is ${this.outputs[outputId].status_collect}`;
1117
- if (this.outputs[outputId].status_computation && this.outputs[outputId].status_computation !== ShapeDiverResponseModelComputationStatus.SUCCESS)
1177
+ if (this.outputs[outputId].status_computation && this.outputs[outputId].status_computation !== sdk_geometry_api_sdk_v2_1.ShapeDiverResponseModelComputationStatus.SUCCESS)
1118
1178
  warning += `\n\t- status_computation is ${this.outputs[outputId].status_computation}`;
1119
1179
  if (warning)
1120
1180
  this._logger.warn(`\nOutput(${outputId}):${warning}`);
@@ -1124,9 +1184,9 @@ export class SessionEngine {
1124
1184
  let warning = '';
1125
1185
  if (this.exports[exportId].msg)
1126
1186
  warning += `\n\t- ${this.exports[exportId].msg}`;
1127
- if (this.exports[exportId].status_collect && this.exports[exportId].status_collect !== ShapeDiverResponseModelComputationStatus.SUCCESS)
1187
+ if (this.exports[exportId].status_collect && this.exports[exportId].status_collect !== sdk_geometry_api_sdk_v2_1.ShapeDiverResponseModelComputationStatus.SUCCESS)
1128
1188
  warning += `\n\t- status_collect is ${this.exports[exportId].status_collect}`;
1129
- if (this.exports[exportId].status_computation && this.exports[exportId].status_computation !== ShapeDiverResponseModelComputationStatus.SUCCESS)
1189
+ if (this.exports[exportId].status_computation && this.exports[exportId].status_computation !== sdk_geometry_api_sdk_v2_1.ShapeDiverResponseModelComputationStatus.SUCCESS)
1130
1190
  warning += `\n\t- status_computation is ${this.exports[exportId].status_computation}`;
1131
1191
  if (warning)
1132
1192
  this._logger.warn(`\nExport(${exportId}):${warning}`);
@@ -1136,53 +1196,115 @@ export class SessionEngine {
1136
1196
  this._sceneTree.addNode(node);
1137
1197
  this._sceneTree.root.updateVersion();
1138
1198
  }
1199
+ cancelProcess(customizationId, eventId, eventType, eventProgress, eventData, newNode = new SessionTreeNode_1.SessionTreeNode()) {
1200
+ if (__classPrivateFieldGet(this, _SessionEngine_customizationProcess, "f") !== customizationId) {
1201
+ for (const r in this._stateEngine.renderingEngines)
1202
+ if (this._stateEngine.renderingEngines[r].busy.includes(customizationId))
1203
+ this._stateEngine.renderingEngines[r].busy.splice(this._stateEngine.renderingEngines[r].busy.indexOf(customizationId), 1);
1204
+ const eventCancel = {
1205
+ type: eventType,
1206
+ id: eventId,
1207
+ progress: eventProgress,
1208
+ data: eventData,
1209
+ status: 'The request was exceeded by another customization request'
1210
+ };
1211
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_CANCEL, eventCancel);
1212
+ this._logger.debug(`Session(${this.id}).cancelProcess: The request was was exceeded by another request.`);
1213
+ return newNode;
1214
+ }
1215
+ else if (this._closed === true) {
1216
+ for (const r in this._stateEngine.renderingEngines)
1217
+ if (this._stateEngine.renderingEngines[r].busy.includes(customizationId))
1218
+ this._stateEngine.renderingEngines[r].busy.splice(this._stateEngine.renderingEngines[r].busy.indexOf(customizationId), 1);
1219
+ this._logger.debug(`Session(${this.id}).cancelProcess: The session was closed during the request.`);
1220
+ const eventCancel = { type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'The session was closed during the request.' };
1221
+ this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_CANCEL, eventCancel);
1222
+ return new SessionTreeNode_1.SessionTreeNode();
1223
+ }
1224
+ }
1139
1225
  checkAvailability(action, checkForModelId = false) {
1140
1226
  var _a;
1141
1227
  if (!this._responseDto)
1142
- throw new ShapeDiverViewerSessionError(`Session.checkAvailability: responseDto not available.`);
1228
+ throw new viewer_shared_services_1.ShapeDiverViewerSessionError('Session.checkAvailability: responseDto not available.');
1143
1229
  if (!this._sessionId)
1144
- throw new ShapeDiverViewerSessionError(`Session.checkAvailability: sessionId not available.`);
1230
+ throw new viewer_shared_services_1.ShapeDiverViewerSessionError('Session.checkAvailability: sessionId not available.');
1145
1231
  if (checkForModelId && !this._modelId)
1146
- throw new ShapeDiverViewerSessionError(`Session.checkAvailability: modelId not available.`);
1232
+ throw new viewer_shared_services_1.ShapeDiverViewerSessionError('Session.checkAvailability: modelId not available.');
1147
1233
  if (action && !this._responseDto.actions)
1148
- throw new ShapeDiverViewerSessionError(`Session.checkAvailability: actions not available.`);
1234
+ throw new viewer_shared_services_1.ShapeDiverViewerSessionError('Session.checkAvailability: actions not available.');
1149
1235
  const responseDtoAction = (_a = this._responseDto.actions) === null || _a === void 0 ? void 0 : _a.find(a => a.name === action);
1150
1236
  if (action && !responseDtoAction)
1151
- throw new ShapeDiverViewerSessionError(`Session.checkAvailability: action ${action} not available.`);
1237
+ throw new viewer_shared_services_1.ShapeDiverViewerSessionError(`Session.checkAvailability: action ${action} not available.`);
1238
+ }
1239
+ cleanExportParameters(parameters) {
1240
+ const requestParameterSet = {};
1241
+ // first step, we convert all our names and displaynames to ids
1242
+ for (const parameterIdOrName in parameters) {
1243
+ // we prioritize id, then name and then displayname
1244
+ // if there are two parameters with the same name or displayname, we take the one that is found first (no way for us to evaluate which one the user meant)
1245
+ const parameterObject = Object.values(this._parameters).find(p => p.id === parameterIdOrName || p.name === parameterIdOrName || p.displayname === parameterIdOrName);
1246
+ // in case the key of the key value pair was neither the id, name or displayname, skip
1247
+ if (!parameterObject)
1248
+ continue;
1249
+ // copy into new dictionary
1250
+ requestParameterSet[parameterObject.id] = parameters[parameterIdOrName];
1251
+ }
1252
+ // seconds step, fill all other parameter values that are currently not set
1253
+ const currentParameters = this.parameterValues;
1254
+ for (const parameterId in currentParameters) {
1255
+ // if already set by input values, skip
1256
+ if (requestParameterSet[parameterId] !== undefined)
1257
+ continue;
1258
+ // deep copy into new dictionary
1259
+ requestParameterSet[parameterId] = (' ' + currentParameters[parameterId]).slice(1);
1260
+ }
1261
+ return requestParameterSet;
1152
1262
  }
1153
1263
  customizeInternal(cancelRequest, taskEventInfo) {
1154
1264
  return __awaiter(this, void 0, void 0, function* () {
1155
1265
  return this.customizeSession(this._parameterValues, cancelRequest, taskEventInfo);
1156
1266
  });
1157
1267
  }
1158
- customizeSession(parameters, cancelRequest, taskEventInfo, parallel = false, retry = false) {
1268
+ customizeSession(parameters, cancelRequest, taskEventInfo, parallel = false, loadOutputs = true, retry = false) {
1159
1269
  return __awaiter(this, void 0, void 0, function* () {
1160
1270
  this.checkAvailability('customize');
1161
1271
  try {
1162
1272
  this._performanceEvaluator.startSection('sessionResponse');
1163
1273
  const responseDto = yield this._sdk.utils.submitAndWaitForCustomization(this._sdk, this._sessionId, parameters);
1164
1274
  this._performanceEvaluator.endSection('sessionResponse');
1165
- if (cancelRequest())
1166
- return new SessionTreeNode();
1167
- if (parallel === false)
1168
- this.updateResponseDto(responseDto);
1169
- return parallel === false ? this.loadOutputs(cancelRequest, taskEventInfo) : this.loadOutputsParallel(responseDto, cancelRequest, taskEventInfo);
1275
+ if (loadOutputs === true) {
1276
+ if (cancelRequest())
1277
+ return new SessionTreeNode_1.SessionTreeNode();
1278
+ if (parallel === true) {
1279
+ // special case, we load the outputs put don't add them to the scene
1280
+ return this.loadOutputsParallel(responseDto, cancelRequest, taskEventInfo);
1281
+ }
1282
+ else {
1283
+ // default case, we load the outputs and return the nodes
1284
+ this.updateResponseDto(responseDto);
1285
+ return this.loadOutputs(cancelRequest, taskEventInfo);
1286
+ }
1287
+ }
1288
+ else {
1289
+ // special case, we don't load the outputs and only return the responseDto
1290
+ return responseDto;
1291
+ }
1170
1292
  }
1171
1293
  catch (e) {
1172
1294
  yield this.handleError(e, retry);
1173
1295
  if (cancelRequest())
1174
- return new SessionTreeNode();
1175
- return yield this.customizeSession(parameters, cancelRequest, taskEventInfo, parallel, true);
1296
+ return new SessionTreeNode_1.SessionTreeNode();
1297
+ return yield this.customizeSession(parameters, cancelRequest, taskEventInfo, parallel, loadOutputs, true);
1176
1298
  }
1177
1299
  });
1178
1300
  }
1179
1301
  handleError(e, retry = false) {
1180
1302
  return __awaiter(this, void 0, void 0, function* () {
1181
- if (isGBResponseError(e)) {
1182
- if (e.error === ShapeDiverResponseErrorType.SESSION_GONE_ERROR) {
1303
+ if ((0, sdk_geometry_api_sdk_v2_1.isGBResponseError)(e)) {
1304
+ if (e.error === sdk_geometry_api_sdk_v2_1.ShapeDiverResponseErrorType.SESSION_GONE_ERROR) {
1183
1305
  // case 1: the session is no longer available
1184
1306
  // we try to re-initialize the session 3 times, if that does not work, we close it
1185
- this._logger.warn(`The session has been closed, trying to re-initialize.`);
1307
+ this._logger.warn('The session has been closed, trying to re-initialize.');
1186
1308
  if (this._sessionId)
1187
1309
  this._httpClient.removeDataLoading(this._sessionId);
1188
1310
  if (this._retryCounter < 3) {
@@ -1194,6 +1316,7 @@ export class SessionEngine {
1194
1316
  else {
1195
1317
  // the retries were exceeded, we close the session
1196
1318
  this._logger.warn('Tried to retry the connect multiple times, bearer token still not valid. Closing Session.');
1319
+ // eslint-disable-next-line no-empty
1197
1320
  try {
1198
1321
  yield this._closeOnFailure();
1199
1322
  }
@@ -1201,7 +1324,7 @@ export class SessionEngine {
1201
1324
  throw this._httpClient.convertError(e);
1202
1325
  }
1203
1326
  }
1204
- else if (e.error === ShapeDiverResponseErrorType.JWT_VALIDATION_ERROR) {
1327
+ else if (e.error === sdk_geometry_api_sdk_v2_1.ShapeDiverResponseErrorType.JWT_VALIDATION_ERROR) {
1205
1328
  // if any of the above errors occur, we try to get a new bearer token
1206
1329
  // if we get a new one, we retry 3 times (by requiring new bearer tokens every time)
1207
1330
  if (this._retryCounter < 3) {
@@ -1213,6 +1336,7 @@ export class SessionEngine {
1213
1336
  else {
1214
1337
  // no bearer tokens are supplied, we close the session
1215
1338
  this._logger.warn('No retry possible, no new bearer token was supplied. Closing Session.');
1339
+ // eslint-disable-next-line no-empty
1216
1340
  try {
1217
1341
  yield this._closeOnFailure();
1218
1342
  }
@@ -1223,6 +1347,7 @@ export class SessionEngine {
1223
1347
  else {
1224
1348
  // the retries were exceeded, we close the session
1225
1349
  this._logger.warn('Tried to retry the connect multiple times, bearer token still not valid. Closing Session.');
1350
+ // eslint-disable-next-line no-empty
1226
1351
  try {
1227
1352
  yield this._closeOnFailure();
1228
1353
  }
@@ -1261,14 +1386,14 @@ export class SessionEngine {
1261
1386
  }
1262
1387
  // convert parameters
1263
1388
  if (responseDto.parameters) {
1264
- for (let parameterId in responseDto.parameters) {
1389
+ for (const parameterId in responseDto.parameters) {
1265
1390
  this._responseDto.parameters = this._responseDto.parameters || {};
1266
1391
  this._responseDto.parameters[parameterId] = this._responseDto.parameters[parameterId] || responseDto.parameters[parameterId];
1267
1392
  }
1268
1393
  }
1269
1394
  // convert outputs
1270
1395
  if (responseDto.outputs) {
1271
- for (let outputId in responseDto.outputs) {
1396
+ for (const outputId in responseDto.outputs) {
1272
1397
  this._responseDto.outputs = this._responseDto.outputs || {};
1273
1398
  if ('version' in responseDto.outputs[outputId] || !(this._responseDto.outputs[outputId] && 'version' in this._responseDto.outputs[outputId]))
1274
1399
  this._responseDto.outputs[outputId] = responseDto.outputs[outputId];
@@ -1276,32 +1401,32 @@ export class SessionEngine {
1276
1401
  }
1277
1402
  // convert exports
1278
1403
  if (responseDto.exports) {
1279
- for (let exportId in responseDto.exports) {
1404
+ for (const exportId in responseDto.exports) {
1280
1405
  this._responseDto.exports = this._responseDto.exports || {};
1281
1406
  if ('version' in responseDto.exports[exportId] || !(this._responseDto.exports[exportId] && 'version' in this._responseDto.exports[exportId]))
1282
1407
  this._responseDto.exports[exportId] = responseDto.exports[exportId];
1283
1408
  }
1284
1409
  }
1285
1410
  const parameterSet = {};
1286
- for (let parameterId in this._responseDto.parameters) {
1411
+ for (const parameterId in this._responseDto.parameters) {
1287
1412
  if (this.parameters[parameterId])
1288
1413
  continue;
1289
1414
  this._responseDto.parameters[parameterId].id = parameterId;
1290
1415
  switch (true) {
1291
- case this._responseDto.parameters[parameterId].type === PARAMETER_TYPE.BOOL:
1292
- this.parameters[parameterId] = new Parameter(this._responseDto.parameters[parameterId], this);
1416
+ case this._responseDto.parameters[parameterId].type === ISessionEngine_1.PARAMETER_TYPE.BOOL:
1417
+ this.parameters[parameterId] = new Parameter_1.Parameter(this._responseDto.parameters[parameterId], this);
1293
1418
  break;
1294
- case this._responseDto.parameters[parameterId].type === PARAMETER_TYPE.COLOR:
1295
- this.parameters[parameterId] = new Parameter(this._responseDto.parameters[parameterId], this);
1419
+ case this._responseDto.parameters[parameterId].type === ISessionEngine_1.PARAMETER_TYPE.COLOR:
1420
+ this.parameters[parameterId] = new Parameter_1.Parameter(this._responseDto.parameters[parameterId], this);
1296
1421
  break;
1297
- case this._responseDto.parameters[parameterId].type === PARAMETER_TYPE.FILE:
1298
- this.parameters[parameterId] = new FileParameter(this._responseDto.parameters[parameterId], this);
1422
+ case this._responseDto.parameters[parameterId].type === ISessionEngine_1.PARAMETER_TYPE.FILE:
1423
+ this.parameters[parameterId] = new FileParameter_1.FileParameter(this._responseDto.parameters[parameterId], this);
1299
1424
  break;
1300
- case this._responseDto.parameters[parameterId].type === PARAMETER_TYPE.EVEN || this._responseDto.parameters[parameterId].type === PARAMETER_TYPE.FLOAT || this._responseDto.parameters[parameterId].type === PARAMETER_TYPE.INT || this._responseDto.parameters[parameterId].type === PARAMETER_TYPE.ODD:
1301
- this.parameters[parameterId] = new Parameter(this._responseDto.parameters[parameterId], this);
1425
+ case this._responseDto.parameters[parameterId].type === ISessionEngine_1.PARAMETER_TYPE.EVEN || this._responseDto.parameters[parameterId].type === ISessionEngine_1.PARAMETER_TYPE.FLOAT || this._responseDto.parameters[parameterId].type === ISessionEngine_1.PARAMETER_TYPE.INT || this._responseDto.parameters[parameterId].type === ISessionEngine_1.PARAMETER_TYPE.ODD:
1426
+ this.parameters[parameterId] = new Parameter_1.Parameter(this._responseDto.parameters[parameterId], this);
1302
1427
  break;
1303
1428
  default:
1304
- this.parameters[parameterId] = new Parameter(this._responseDto.parameters[parameterId], this);
1429
+ this.parameters[parameterId] = new Parameter_1.Parameter(this._responseDto.parameters[parameterId], this);
1305
1430
  break;
1306
1431
  }
1307
1432
  // we don't have to do larger restrictions for this as the backend would have already thrown an error if the values were not correct
@@ -1330,29 +1455,45 @@ export class SessionEngine {
1330
1455
  // store the initialization as the first parameter set in the history
1331
1456
  if (!this.initialized)
1332
1457
  __classPrivateFieldGet(this, _SessionEngine_parameterHistory, "f").push(parameterSet);
1333
- for (let exportId in this._responseDto.exports) {
1334
- if (this._responseDto.exports[exportId].type === ShapeDiverResponseExportDefinitionType.EMAIL || this._responseDto.exports[exportId].type === ShapeDiverResponseExportDefinitionType.DOWNLOAD) {
1458
+ for (const exportId in this._responseDto.exports) {
1459
+ if (this._responseDto.exports[exportId].type === sdk_geometry_api_sdk_v2_1.ShapeDiverResponseExportDefinitionType.EMAIL || this._responseDto.exports[exportId].type === sdk_geometry_api_sdk_v2_1.ShapeDiverResponseExportDefinitionType.DOWNLOAD) {
1335
1460
  if (!this.exports[exportId]) {
1336
1461
  this._responseDto.exports[exportId].id = exportId;
1337
- this.exports[exportId] = new Export(this._responseDto.exports[exportId], this);
1462
+ this.exports[exportId] = new Export_1.Export(this._responseDto.exports[exportId], this);
1338
1463
  }
1339
1464
  else {
1340
1465
  this.exports[exportId].updateExportDefinition(this._responseDto.exports[exportId]);
1341
1466
  }
1342
1467
  }
1343
1468
  }
1344
- for (let outputId in this._responseDto.outputs) {
1469
+ for (const outputId in this._responseDto.outputs) {
1345
1470
  if (!this.outputs[outputId]) {
1346
1471
  this._responseDto.outputs[outputId].id = outputId;
1347
1472
  if (this.outputsFreeze[outputId] === undefined)
1348
1473
  this.outputsFreeze[outputId] = false;
1349
- this.outputs[outputId] = new Output(this._responseDto.outputs[outputId], this);
1474
+ this.outputs[outputId] = new Output_1.Output(this._responseDto.outputs[outputId], this);
1350
1475
  }
1351
1476
  else {
1352
1477
  this.outputs[outputId].updateOutputDefinition(this._responseDto.outputs[outputId]);
1353
1478
  }
1354
1479
  }
1355
1480
  }
1481
+ waitForUpdateCallbacks(newOutputVersions, oldOutputVersions, newNode, oldNode) {
1482
+ return __awaiter(this, void 0, void 0, function* () {
1483
+ // call the update callback function on the session
1484
+ if (this._updateCallback)
1485
+ yield Promise.resolve(this._updateCallback(newNode, oldNode));
1486
+ const promises = [];
1487
+ // call the update callback functions on the outputs
1488
+ for (const outputId in this.outputs) {
1489
+ if (oldOutputVersions[outputId] !== newOutputVersions[outputId]) {
1490
+ promises.push(this.outputs[outputId].triggerUpdateCallback(newNode.children.find(c => c.name === outputId), oldNode.children.find(c => c.name === outputId)));
1491
+ }
1492
+ }
1493
+ yield Promise.all(promises);
1494
+ });
1495
+ }
1356
1496
  }
1497
+ exports.SessionEngine = SessionEngine;
1357
1498
  _SessionEngine_customizationProcess = new WeakMap(), _SessionEngine_parameterHistory = new WeakMap(), _SessionEngine_parameterHistoryCall = new WeakMap(), _SessionEngine_parameterHistoryForward = new WeakMap();
1358
1499
  //# sourceMappingURL=SessionEngine.js.map