@shapediver/viewer.session-engine.session-engine 3.15.6 → 3.15.8
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.
- package/dist/implementation/dto/Export.d.ts +2 -2
- package/dist/implementation/dto/Export.d.ts.map +1 -1
- package/dist/implementation/dto/Export.js.map +1 -1
- package/dist/implementation/dto/Parameter.d.ts +2 -2
- package/dist/implementation/dto/Parameter.d.ts.map +1 -1
- package/dist/implementation/dto/Parameter.js.map +1 -1
- package/dist/implementation/managers/UtilsManager.js +1 -1
- package/dist/implementation/managers/UtilsManager.js.map +1 -1
- package/package.json +9 -9
- package/dist/implementation/SessionEngine.d.ts +0 -291
- package/dist/implementation/SessionEngine.d.ts.map +0 -1
- package/dist/implementation/SessionEngine.js +0 -2316
- package/dist/implementation/SessionEngine.js.map +0 -1
|
@@ -1,2316 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
12
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
13
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
14
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
15
|
-
};
|
|
16
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
17
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
18
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
19
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
20
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
21
|
-
};
|
|
22
|
-
var _SessionEngine_customizationBusyModes, _SessionEngine_customizationProcess, _SessionEngine_parameterHistory, _SessionEngine_parameterHistoryCall, _SessionEngine_parameterHistoryForward;
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.SessionEngine = void 0;
|
|
25
|
-
const sdk_geometry_api_sdk_v2_1 = require("@shapediver/sdk.geometry-api-sdk-v2");
|
|
26
|
-
const viewer_settings_1 = require("@shapediver/viewer.settings");
|
|
27
|
-
const viewer_shared_global_access_objects_1 = require("@shapediver/viewer.shared.global-access-objects");
|
|
28
|
-
const viewer_shared_node_tree_1 = require("@shapediver/viewer.shared.node-tree");
|
|
29
|
-
const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
|
|
30
|
-
const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
|
|
31
|
-
const DrawingParameter_1 = require("./dto/DrawingParameter");
|
|
32
|
-
const Export_1 = require("./dto/Export");
|
|
33
|
-
const FileParameter_1 = require("./dto/FileParameter");
|
|
34
|
-
const DraggingParameter_1 = require("./dto/interaction/DraggingParameter");
|
|
35
|
-
const GumballParameter_1 = require("./dto/interaction/GumballParameter");
|
|
36
|
-
const SelectionParameter_1 = require("./dto/interaction/SelectionParameter");
|
|
37
|
-
const Output_1 = require("./dto/Output");
|
|
38
|
-
const Parameter_1 = require("./dto/Parameter");
|
|
39
|
-
const OutputDelayException_1 = require("./OutputDelayException");
|
|
40
|
-
const OutputLoader_1 = require("./OutputLoader");
|
|
41
|
-
const SessionData_1 = require("./SessionData");
|
|
42
|
-
const SessionTreeNode_1 = require("./SessionTreeNode");
|
|
43
|
-
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
44
|
-
class SessionEngine {
|
|
45
|
-
// #endregion Properties (50)
|
|
46
|
-
// #region Constructors (1)
|
|
47
|
-
/**
|
|
48
|
-
* Can be use to initialize a session with the ticket/guid and modelViewUrl and returns a scene graph node with the result.
|
|
49
|
-
* Can be use to customize the session with updated parameters to get the updated scene graph node.
|
|
50
|
-
*/
|
|
51
|
-
constructor(properties) {
|
|
52
|
-
// #region Properties (50)
|
|
53
|
-
this._converter = viewer_shared_services_1.Converter.instance;
|
|
54
|
-
this._eventEngine = viewer_shared_services_1.EventEngine.instance;
|
|
55
|
-
this._exports = {};
|
|
56
|
-
this._globalAccessObjects = viewer_shared_global_access_objects_1.GlobalAccessObjects.instance;
|
|
57
|
-
this._httpClient = viewer_shared_services_1.HttpClient.instance;
|
|
58
|
-
this._logger = viewer_shared_services_1.Logger.instance;
|
|
59
|
-
this._outputs = {};
|
|
60
|
-
this._outputsFreeze = {};
|
|
61
|
-
this._parameterValues = {};
|
|
62
|
-
this._parameters = {};
|
|
63
|
-
this._performanceEvaluator = viewer_shared_services_1.PerformanceEvaluator.instance;
|
|
64
|
-
this._sceneTree = viewer_shared_node_tree_1.Tree.instance;
|
|
65
|
-
this._sessionEngineId = viewer_shared_services_1.UuidGenerator.instance.create();
|
|
66
|
-
this._settingsEngine = new viewer_shared_services_1.SettingsEngine();
|
|
67
|
-
this._stateEngine = viewer_shared_services_1.StateEngine.instance;
|
|
68
|
-
this._uuidGenerator = viewer_shared_services_1.UuidGenerator.instance;
|
|
69
|
-
_SessionEngine_customizationBusyModes.set(this, []);
|
|
70
|
-
_SessionEngine_customizationProcess.set(this, void 0);
|
|
71
|
-
_SessionEngine_parameterHistory.set(this, []);
|
|
72
|
-
_SessionEngine_parameterHistoryCall.set(this, false);
|
|
73
|
-
_SessionEngine_parameterHistoryForward.set(this, []);
|
|
74
|
-
this._allowOutputLoading = true;
|
|
75
|
-
this._automaticSceneUpdate = true;
|
|
76
|
-
this._closeOnFailure = () => __awaiter(this, void 0, void 0, function* () { });
|
|
77
|
-
this._closed = false;
|
|
78
|
-
this._customizeOnParameterChange = false;
|
|
79
|
-
this._dataCache = {};
|
|
80
|
-
this._excludeViewports = [];
|
|
81
|
-
this._headers = {
|
|
82
|
-
"X-ShapeDiver-Origin": viewer_shared_services_1.SystemInfo.instance.origin,
|
|
83
|
-
"X-ShapeDiver-SessionEngineId": this._sessionEngineId,
|
|
84
|
-
"X-ShapeDiver-BuildVersion": "",
|
|
85
|
-
"X-ShapeDiver-BuildDate": "",
|
|
86
|
-
};
|
|
87
|
-
this._initialized = false;
|
|
88
|
-
this._loadSdtf = false;
|
|
89
|
-
this._retryCounter = 0;
|
|
90
|
-
this._updateCallback = null;
|
|
91
|
-
this._viewerSettingsVersion = viewer_settings_1.latestVersion;
|
|
92
|
-
this._viewerSettingsVersionBackend = viewer_settings_1.latestVersion;
|
|
93
|
-
this._id = properties.id;
|
|
94
|
-
this._node = new viewer_shared_node_tree_1.TreeNode(properties.id);
|
|
95
|
-
this._guid = properties.guid;
|
|
96
|
-
this._ticket = properties.ticket;
|
|
97
|
-
this._modelViewUrl = properties.modelViewUrl;
|
|
98
|
-
this._excludeViewports = properties.excludeViewports || [];
|
|
99
|
-
this._jwtToken = properties.jwtToken;
|
|
100
|
-
this._allowOutputLoading = properties.allowOutputLoading;
|
|
101
|
-
this._ignoreUnknownParams = properties.ignoreUnknownParams;
|
|
102
|
-
this._loadSdtf = properties.loadSdtf;
|
|
103
|
-
this._modelStateId = properties.modelStateId;
|
|
104
|
-
this._modelStateValidationMode = properties.modelStateValidationMode;
|
|
105
|
-
this._throwOnCustomizationError =
|
|
106
|
-
properties.throwOnCustomizationError !== undefined
|
|
107
|
-
? properties.throwOnCustomizationError
|
|
108
|
-
: false;
|
|
109
|
-
this._headers["X-ShapeDiver-BuildDate"] = properties.buildDate;
|
|
110
|
-
this._headers["X-ShapeDiver-BuildVersion"] = properties.buildVersion;
|
|
111
|
-
this._outputLoader = new OutputLoader_1.OutputLoader(this);
|
|
112
|
-
try {
|
|
113
|
-
this._sdkConfig = new sdk_geometry_api_sdk_v2_1.Configuration({
|
|
114
|
-
basePath: this._modelViewUrl,
|
|
115
|
-
accessToken: this._jwtToken,
|
|
116
|
-
baseOptions: {
|
|
117
|
-
headers: this._headers,
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
catch (e) {
|
|
122
|
-
throw this._httpClient.convertError(e);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
// #endregion Constructors (1)
|
|
126
|
-
// #region Public Getters And Setters (28)
|
|
127
|
-
get automaticSceneUpdate() {
|
|
128
|
-
return this._automaticSceneUpdate;
|
|
129
|
-
}
|
|
130
|
-
set automaticSceneUpdate(value) {
|
|
131
|
-
this._automaticSceneUpdate = value;
|
|
132
|
-
value && this._closed === false
|
|
133
|
-
? this.addToSceneTree(this._node)
|
|
134
|
-
: this.removeFromSceneTree(this._node);
|
|
135
|
-
}
|
|
136
|
-
get canUploadGLTF() {
|
|
137
|
-
try {
|
|
138
|
-
this.checkAvailability("gltf-upload");
|
|
139
|
-
return true;
|
|
140
|
-
}
|
|
141
|
-
catch (e) {
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
get customizeOnParameterChange() {
|
|
146
|
-
return this._customizeOnParameterChange;
|
|
147
|
-
}
|
|
148
|
-
set customizeOnParameterChange(value) {
|
|
149
|
-
this._customizeOnParameterChange = value;
|
|
150
|
-
}
|
|
151
|
-
get excludeViewports() {
|
|
152
|
-
return this._excludeViewports;
|
|
153
|
-
}
|
|
154
|
-
set excludeViewports(value) {
|
|
155
|
-
this._excludeViewports = JSON.parse(JSON.stringify(value));
|
|
156
|
-
this._node.excludeViewports = JSON.parse(JSON.stringify(value));
|
|
157
|
-
}
|
|
158
|
-
get exports() {
|
|
159
|
-
return this._exports;
|
|
160
|
-
}
|
|
161
|
-
get guid() {
|
|
162
|
-
return this._guid;
|
|
163
|
-
}
|
|
164
|
-
get hasStoredSettings() {
|
|
165
|
-
return this._settingsEngine.hasStoredSettings;
|
|
166
|
-
}
|
|
167
|
-
get id() {
|
|
168
|
-
return this._id;
|
|
169
|
-
}
|
|
170
|
-
get initialized() {
|
|
171
|
-
return this._initialized;
|
|
172
|
-
}
|
|
173
|
-
get jwtToken() {
|
|
174
|
-
return this._jwtToken;
|
|
175
|
-
}
|
|
176
|
-
get loadSdtf() {
|
|
177
|
-
return this._loadSdtf;
|
|
178
|
-
}
|
|
179
|
-
set loadSdtf(value) {
|
|
180
|
-
this._loadSdtf = value;
|
|
181
|
-
if (this._initialized === true && this._loadSdtf === true) {
|
|
182
|
-
(() => __awaiter(this, void 0, void 0, function* () {
|
|
183
|
-
this._outputLoader.reloadSdtf = true;
|
|
184
|
-
yield this.updateOutputs();
|
|
185
|
-
this._outputLoader.reloadSdtf = false;
|
|
186
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.SESSION.SESSION_SDTF_DELAYED_LOADED, { sessionId: this.id });
|
|
187
|
-
}))();
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
get modelState() {
|
|
191
|
-
return this._modelState;
|
|
192
|
-
}
|
|
193
|
-
get modelViewUrl() {
|
|
194
|
-
return this._modelViewUrl;
|
|
195
|
-
}
|
|
196
|
-
get node() {
|
|
197
|
-
return this._node;
|
|
198
|
-
}
|
|
199
|
-
get outputs() {
|
|
200
|
-
return this._outputs;
|
|
201
|
-
}
|
|
202
|
-
get outputsFreeze() {
|
|
203
|
-
return this._outputsFreeze;
|
|
204
|
-
}
|
|
205
|
-
get parameterValues() {
|
|
206
|
-
return this._parameterValues;
|
|
207
|
-
}
|
|
208
|
-
get parameters() {
|
|
209
|
-
return this._parameters;
|
|
210
|
-
}
|
|
211
|
-
get refreshJwtToken() {
|
|
212
|
-
return this._refreshJwtToken;
|
|
213
|
-
}
|
|
214
|
-
set refreshJwtToken(value) {
|
|
215
|
-
this._refreshJwtToken = value;
|
|
216
|
-
}
|
|
217
|
-
get settingsEngine() {
|
|
218
|
-
return this._settingsEngine;
|
|
219
|
-
}
|
|
220
|
-
get ticket() {
|
|
221
|
-
return this._ticket;
|
|
222
|
-
}
|
|
223
|
-
get updateCallback() {
|
|
224
|
-
return this._updateCallback;
|
|
225
|
-
}
|
|
226
|
-
set updateCallback(value) {
|
|
227
|
-
this._updateCallback = value;
|
|
228
|
-
}
|
|
229
|
-
get viewerSettings() {
|
|
230
|
-
return this._viewerSettings;
|
|
231
|
-
}
|
|
232
|
-
// #endregion Public Getters And Setters (28)
|
|
233
|
-
// #region Public Methods (31)
|
|
234
|
-
applySettings(response, sections) {
|
|
235
|
-
sections = sections || {};
|
|
236
|
-
if (sections.session === undefined) {
|
|
237
|
-
sections.session = {
|
|
238
|
-
parameter: { displayname: false, order: false, hidden: false },
|
|
239
|
-
export: { displayname: false, order: false, hidden: false },
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
if (sections.session.parameter === undefined)
|
|
243
|
-
sections.session.parameter = {
|
|
244
|
-
displayname: false,
|
|
245
|
-
order: false,
|
|
246
|
-
hidden: false,
|
|
247
|
-
value: false,
|
|
248
|
-
};
|
|
249
|
-
if (sections.session.export === undefined)
|
|
250
|
-
sections.session.export = {
|
|
251
|
-
displayname: false,
|
|
252
|
-
order: false,
|
|
253
|
-
hidden: false,
|
|
254
|
-
};
|
|
255
|
-
if (sections.viewport === undefined)
|
|
256
|
-
sections.viewport = {
|
|
257
|
-
ar: false,
|
|
258
|
-
scene: false,
|
|
259
|
-
camera: false,
|
|
260
|
-
light: false,
|
|
261
|
-
environment: false,
|
|
262
|
-
general: false,
|
|
263
|
-
postprocessing: false,
|
|
264
|
-
};
|
|
265
|
-
let config;
|
|
266
|
-
if (response.viewer !== undefined) {
|
|
267
|
-
config = response.viewer.config;
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
throw new viewer_shared_services_1.ShapeDiverViewerSettingsError("Session.applySettings: No config object available.");
|
|
271
|
-
}
|
|
272
|
-
try {
|
|
273
|
-
(0, viewer_settings_1.validate)(config);
|
|
274
|
-
}
|
|
275
|
-
catch (e) {
|
|
276
|
-
throw new viewer_shared_services_1.ShapeDiverViewerSettingsError("Session.applySettings: Was not able to validate config object.");
|
|
277
|
-
}
|
|
278
|
-
const settings = (0, viewer_settings_1.convert)(config, viewer_settings_1.latestVersion);
|
|
279
|
-
const exportMappingUid = {};
|
|
280
|
-
if (sections.session.export.displayname ||
|
|
281
|
-
sections.session.export.order ||
|
|
282
|
-
sections.session.export.hidden)
|
|
283
|
-
if (response.exports)
|
|
284
|
-
for (const exportId in response.exports)
|
|
285
|
-
if (response.exports[exportId].uid !== undefined)
|
|
286
|
-
exportMappingUid[response.exports[exportId].uid] =
|
|
287
|
-
exportId;
|
|
288
|
-
const currentSettings = this._settingsEngine.settings;
|
|
289
|
-
// apply parameter settings
|
|
290
|
-
if (sections.session.parameter.displayname ||
|
|
291
|
-
sections.session.parameter.order ||
|
|
292
|
-
sections.session.parameter.hidden ||
|
|
293
|
-
sections.session.parameter.value) {
|
|
294
|
-
for (const p in this.parameters) {
|
|
295
|
-
if (settings.session[p]) {
|
|
296
|
-
if (sections.session.parameter.displayname)
|
|
297
|
-
this.parameters[p].displayname =
|
|
298
|
-
settings.session[p].displayname;
|
|
299
|
-
if (sections.session.parameter.order)
|
|
300
|
-
this.parameters[p].order = settings.session[p].order;
|
|
301
|
-
if (sections.session.parameter.hidden)
|
|
302
|
-
this.parameters[p].hidden =
|
|
303
|
-
settings.session[p].hidden || false;
|
|
304
|
-
}
|
|
305
|
-
if (response.parameters &&
|
|
306
|
-
response.parameters[p] &&
|
|
307
|
-
!(this.parameters[p] instanceof FileParameter_1.FileParameter ||
|
|
308
|
-
this.parameters[p].type.startsWith("s"))) {
|
|
309
|
-
if (sections.session.parameter.value)
|
|
310
|
-
this.parameters[p].value =
|
|
311
|
-
response.parameters[p].defval !== undefined
|
|
312
|
-
? response.parameters[p].defval
|
|
313
|
-
: this.parameters[p].value;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
// apply export settings
|
|
318
|
-
if (sections.session.export.displayname ||
|
|
319
|
-
sections.session.export.order ||
|
|
320
|
-
sections.session.export.hidden) {
|
|
321
|
-
for (const p in this.exports) {
|
|
322
|
-
let idForSettings = "";
|
|
323
|
-
if (settings.session[p]) {
|
|
324
|
-
idForSettings = p;
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
const uid = this.exports[p].uid;
|
|
328
|
-
if (!uid)
|
|
329
|
-
continue;
|
|
330
|
-
if (!exportMappingUid[uid])
|
|
331
|
-
continue;
|
|
332
|
-
idForSettings = exportMappingUid[uid];
|
|
333
|
-
}
|
|
334
|
-
if (settings.session[idForSettings]) {
|
|
335
|
-
if (sections.session.export.displayname)
|
|
336
|
-
this.exports[p].displayname =
|
|
337
|
-
settings.session[idForSettings].displayname;
|
|
338
|
-
if (sections.session.export.order)
|
|
339
|
-
this.exports[p].order =
|
|
340
|
-
settings.session[idForSettings].order;
|
|
341
|
-
if (sections.session.export.hidden)
|
|
342
|
-
this.exports[p].hidden =
|
|
343
|
-
settings.session[idForSettings].hidden || false;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
// apply ar settings
|
|
348
|
-
if (sections.viewport.ar) {
|
|
349
|
-
currentSettings.ar = settings.ar;
|
|
350
|
-
currentSettings.general.transformation =
|
|
351
|
-
settings.general.transformation;
|
|
352
|
-
}
|
|
353
|
-
// apply camera settings
|
|
354
|
-
if (sections.viewport.camera)
|
|
355
|
-
currentSettings.camera = settings.camera;
|
|
356
|
-
// apply light settings
|
|
357
|
-
if (sections.viewport.light)
|
|
358
|
-
currentSettings.light = settings.light;
|
|
359
|
-
// apply scene settings
|
|
360
|
-
if (sections.viewport.scene) {
|
|
361
|
-
currentSettings.environmentGeometry.gridColor =
|
|
362
|
-
settings.environmentGeometry.gridColor;
|
|
363
|
-
currentSettings.environmentGeometry.gridVisibility =
|
|
364
|
-
settings.environmentGeometry.gridVisibility;
|
|
365
|
-
currentSettings.environmentGeometry.groundPlaneColor =
|
|
366
|
-
settings.environmentGeometry.groundPlaneColor;
|
|
367
|
-
currentSettings.environmentGeometry.groundPlaneVisibility =
|
|
368
|
-
settings.environmentGeometry.groundPlaneVisibility;
|
|
369
|
-
currentSettings.environmentGeometry.groundPlaneShadowColor =
|
|
370
|
-
settings.environmentGeometry.groundPlaneShadowColor;
|
|
371
|
-
currentSettings.environmentGeometry.groundPlaneShadowVisibility =
|
|
372
|
-
settings.environmentGeometry.groundPlaneShadowVisibility;
|
|
373
|
-
currentSettings.environmentGeometry.contactShadowVisibility =
|
|
374
|
-
settings.environmentGeometry.contactShadowVisibility;
|
|
375
|
-
currentSettings.environmentGeometry.contactShadowHeight =
|
|
376
|
-
settings.environmentGeometry.contactShadowHeight;
|
|
377
|
-
currentSettings.environmentGeometry.contactShadowBlur =
|
|
378
|
-
settings.environmentGeometry.contactShadowBlur;
|
|
379
|
-
currentSettings.environmentGeometry.contactShadowOpacity =
|
|
380
|
-
settings.environmentGeometry.contactShadowOpacity;
|
|
381
|
-
currentSettings.environmentGeometry.contactShadowDarkness =
|
|
382
|
-
settings.environmentGeometry.contactShadowDarkness;
|
|
383
|
-
currentSettings.rendering.shadows = settings.rendering.shadows;
|
|
384
|
-
currentSettings.rendering.softShadows =
|
|
385
|
-
settings.rendering.softShadows;
|
|
386
|
-
currentSettings.rendering.automaticColorAdjustment =
|
|
387
|
-
settings.rendering.automaticColorAdjustment;
|
|
388
|
-
currentSettings.rendering.textureEncoding =
|
|
389
|
-
settings.rendering.textureEncoding;
|
|
390
|
-
currentSettings.rendering.outputEncoding =
|
|
391
|
-
settings.rendering.outputEncoding;
|
|
392
|
-
currentSettings.rendering.physicallyCorrectLights =
|
|
393
|
-
settings.rendering.physicallyCorrectLights;
|
|
394
|
-
currentSettings.rendering.toneMapping =
|
|
395
|
-
settings.rendering.toneMapping;
|
|
396
|
-
currentSettings.rendering.toneMappingExposure =
|
|
397
|
-
settings.rendering.toneMappingExposure;
|
|
398
|
-
}
|
|
399
|
-
if (sections.viewport.general) {
|
|
400
|
-
currentSettings.configuration = settings.configuration;
|
|
401
|
-
currentSettings.general.pointSize = settings.general.pointSize;
|
|
402
|
-
currentSettings.material.defaultMaterialColor =
|
|
403
|
-
settings.material.defaultMaterialColor;
|
|
404
|
-
currentSettings.material.materialOverrideType =
|
|
405
|
-
settings.material.materialOverrideType;
|
|
406
|
-
}
|
|
407
|
-
// apply postprocessing settings
|
|
408
|
-
if (sections.viewport.postprocessing)
|
|
409
|
-
currentSettings.postprocessing = settings.postprocessing;
|
|
410
|
-
// apply environment settings
|
|
411
|
-
if (sections.viewport.environment) {
|
|
412
|
-
currentSettings.environment.clearAlpha =
|
|
413
|
-
settings.environment.clearAlpha;
|
|
414
|
-
currentSettings.environment.clearColor =
|
|
415
|
-
settings.environment.clearColor;
|
|
416
|
-
currentSettings.environment.map = settings.environment.map;
|
|
417
|
-
currentSettings.environment.mapAsBackground =
|
|
418
|
-
settings.environment.mapAsBackground;
|
|
419
|
-
currentSettings.environment.rotation =
|
|
420
|
-
settings.environment.rotation;
|
|
421
|
-
currentSettings.environment.blurriness =
|
|
422
|
-
settings.environment.blurriness;
|
|
423
|
-
currentSettings.environment.intensity =
|
|
424
|
-
settings.environment.intensity;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
canGoBack() {
|
|
428
|
-
// the first entry is always the one from the init call
|
|
429
|
-
// all additional entries can be undone
|
|
430
|
-
return __classPrivateFieldGet(this, _SessionEngine_parameterHistory, "f").length > 1;
|
|
431
|
-
}
|
|
432
|
-
canGoForward() {
|
|
433
|
-
return __classPrivateFieldGet(this, _SessionEngine_parameterHistoryForward, "f").length > 0;
|
|
434
|
-
}
|
|
435
|
-
cancelCustomization() {
|
|
436
|
-
if (__classPrivateFieldGet(this, _SessionEngine_customizationProcess, "f"))
|
|
437
|
-
this.removeBusyMode(__classPrivateFieldGet(this, _SessionEngine_customizationProcess, "f"));
|
|
438
|
-
for (const busyId of __classPrivateFieldGet(this, _SessionEngine_customizationBusyModes, "f")) {
|
|
439
|
-
for (const r in this._stateEngine.viewportEngines) {
|
|
440
|
-
if (this._stateEngine.viewportEngines[r] &&
|
|
441
|
-
this._stateEngine.viewportEngines[r].busy.includes(busyId))
|
|
442
|
-
this._stateEngine.viewportEngines[r].busy.splice(this._stateEngine.viewportEngines[r].busy.indexOf(busyId), 1);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
__classPrivateFieldSet(this, _SessionEngine_customizationBusyModes, [], "f");
|
|
446
|
-
__classPrivateFieldSet(this, _SessionEngine_customizationProcess, undefined, "f");
|
|
447
|
-
}
|
|
448
|
-
close(retry = false) {
|
|
449
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
450
|
-
this.checkAvailability("close");
|
|
451
|
-
try {
|
|
452
|
-
this._httpClient.removeDataLoading(this._sessionId);
|
|
453
|
-
yield new sdk_geometry_api_sdk_v2_1.SessionApi(this._sdkConfig).closeSession(this._sessionId);
|
|
454
|
-
if (this._automaticSceneUpdate)
|
|
455
|
-
this.removeFromSceneTree(this._node);
|
|
456
|
-
this._closed = true;
|
|
457
|
-
}
|
|
458
|
-
catch (e) {
|
|
459
|
-
yield this.handleError(e, retry);
|
|
460
|
-
return yield this.close(true);
|
|
461
|
-
}
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
createModelState(parameterValues = {}, omitSessionParameterValues = false, image, data, arScene, retry = false) {
|
|
465
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
466
|
-
this.checkAvailability();
|
|
467
|
-
try {
|
|
468
|
-
const promises = [];
|
|
469
|
-
// process the parameters
|
|
470
|
-
const parameterSet = {};
|
|
471
|
-
promises.push(this.uploadFileParameters(parameterValues).then(() => {
|
|
472
|
-
// create a set of the current validated parameter values
|
|
473
|
-
for (const parameterId in this.parameters) {
|
|
474
|
-
// if the parameter has not been set, we do not include it in the parameter set if the omitSessionParameterValues flag is set
|
|
475
|
-
if (!(omitSessionParameterValues === true &&
|
|
476
|
-
parameterValues[parameterId] === undefined)) {
|
|
477
|
-
parameterSet[parameterId] = (" " +
|
|
478
|
-
this.parameters[parameterId].stringify(parameterValues[parameterId])).slice(1);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
}));
|
|
482
|
-
// process the image input
|
|
483
|
-
let imageData;
|
|
484
|
-
let imageArrayBuffer;
|
|
485
|
-
if (image) {
|
|
486
|
-
promises.push(this.processImageInput(image).then((result) => {
|
|
487
|
-
imageData = result === null || result === void 0 ? void 0 : result.imageData;
|
|
488
|
-
imageArrayBuffer = result === null || result === void 0 ? void 0 : result.arrayBuffer;
|
|
489
|
-
}));
|
|
490
|
-
}
|
|
491
|
-
// process the arScene input
|
|
492
|
-
let arSceneId;
|
|
493
|
-
if (arScene) {
|
|
494
|
-
promises.push(this._converter
|
|
495
|
-
.convertToBlob(arScene)
|
|
496
|
-
.then((arSceneBlob) => new sdk_geometry_api_sdk_v2_1.GltfApi(this._sdkConfig).uploadGltf(this._sessionId, new File([arSceneBlob], "arScene.gltf", {
|
|
497
|
-
type: "model/gltf-binary",
|
|
498
|
-
}), sdk_geometry_api_sdk_v2_1.QueryGltfConversion.SCENE))
|
|
499
|
-
.then((arSceneResponseDto) => {
|
|
500
|
-
var _a;
|
|
501
|
-
arSceneId = (_a = arSceneResponseDto.data.gltf) === null || _a === void 0 ? void 0 : _a.sceneId;
|
|
502
|
-
}));
|
|
503
|
-
}
|
|
504
|
-
// wait for all promises to resolve
|
|
505
|
-
yield Promise.all(promises);
|
|
506
|
-
// create the model state
|
|
507
|
-
const response = (yield new sdk_geometry_api_sdk_v2_1.ModelStateApi(this._sdkConfig).createModelState(this._sessionId, {
|
|
508
|
-
parameters: parameterSet,
|
|
509
|
-
data: data,
|
|
510
|
-
image: imageData,
|
|
511
|
-
arSceneId: arSceneId,
|
|
512
|
-
})).data;
|
|
513
|
-
if (imageData && imageArrayBuffer)
|
|
514
|
-
yield new sdk_geometry_api_sdk_v2_1.UtilsApi(this._sdkConfig).uploadAsset(response.asset.modelState.href, imageArrayBuffer, response.asset.modelState.headers);
|
|
515
|
-
return response.modelState.id;
|
|
516
|
-
}
|
|
517
|
-
catch (e) {
|
|
518
|
-
yield this.handleError(e, retry);
|
|
519
|
-
return yield this.createModelState(parameterValues, omitSessionParameterValues, image, data, arScene, true);
|
|
520
|
-
}
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
/**
|
|
524
|
-
* Customizes the session with updated parameters to get the updated scene graph node.
|
|
525
|
-
*
|
|
526
|
-
* @param parameters the parameter set to update the session
|
|
527
|
-
* @returns promise with a scene graph node
|
|
528
|
-
*/
|
|
529
|
-
customize(force = false, waitForViewportUpdate = false) {
|
|
530
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
531
|
-
const eventId = this._uuidGenerator.create();
|
|
532
|
-
const customizationId = this._uuidGenerator.create();
|
|
533
|
-
try {
|
|
534
|
-
// we check if something changed
|
|
535
|
-
if (force === false) {
|
|
536
|
-
let changes = false;
|
|
537
|
-
for (const parameterId in this.parameters)
|
|
538
|
-
if (this.parameters[parameterId].sessionValue !==
|
|
539
|
-
this.parameters[parameterId].value)
|
|
540
|
-
changes = true;
|
|
541
|
-
if (changes === false)
|
|
542
|
-
return this.node;
|
|
543
|
-
}
|
|
544
|
-
const eventStart = {
|
|
545
|
-
type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
|
|
546
|
-
id: eventId,
|
|
547
|
-
progress: 0,
|
|
548
|
-
data: { sessionId: this.id },
|
|
549
|
-
status: "Customizing session",
|
|
550
|
-
};
|
|
551
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_START, eventStart);
|
|
552
|
-
const oldNode = this.node;
|
|
553
|
-
__classPrivateFieldSet(this, _SessionEngine_customizationProcess, customizationId, "f");
|
|
554
|
-
this._logger.debugLow(`Session(${this.id}).customize: Customizing session.`);
|
|
555
|
-
this.addBusyMode(customizationId);
|
|
556
|
-
const eventFileUpload = {
|
|
557
|
-
type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
|
|
558
|
-
id: eventId,
|
|
559
|
-
progress: 0.1,
|
|
560
|
-
data: { sessionId: this.id },
|
|
561
|
-
status: "Uploading file parameters",
|
|
562
|
-
};
|
|
563
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_PROCESS, eventFileUpload);
|
|
564
|
-
// upload file parameters
|
|
565
|
-
yield this.uploadFileParameters();
|
|
566
|
-
// OPTION TO SKIP - PART 1b
|
|
567
|
-
const cancelResult = this.cancelProcess(customizationId, eventId, viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION, 1, { sessionId: this.id });
|
|
568
|
-
if (cancelResult)
|
|
569
|
-
return cancelResult;
|
|
570
|
-
const parameterSet = {};
|
|
571
|
-
// create a set of the current validated parameter values
|
|
572
|
-
for (const parameterId in this.parameters) {
|
|
573
|
-
parameterSet[parameterId] = {
|
|
574
|
-
value: this.parameters[parameterId].value,
|
|
575
|
-
valueString: this.parameters[parameterId].stringify(),
|
|
576
|
-
};
|
|
577
|
-
}
|
|
578
|
-
// update the session engine parameter values if everything succeeded
|
|
579
|
-
for (const parameterId in this.parameters)
|
|
580
|
-
this.parameterValues[parameterId] =
|
|
581
|
-
parameterSet[parameterId].valueString;
|
|
582
|
-
this._logger.info(`Session(${this.id}).customize: Customizing session with parameters ${JSON.stringify(this.parameterValues)}.`);
|
|
583
|
-
const eventRequest = {
|
|
584
|
-
type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
|
|
585
|
-
id: eventId,
|
|
586
|
-
progress: 0.1,
|
|
587
|
-
data: { sessionId: this.id },
|
|
588
|
-
status: "Sending customization request",
|
|
589
|
-
};
|
|
590
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_PROCESS, eventRequest);
|
|
591
|
-
const oldOutputVersions = this._outputLoader.getCurrentOutputVersions();
|
|
592
|
-
const newNode = yield this.customizeInternal(() => __classPrivateFieldGet(this, _SessionEngine_customizationProcess, "f") !== customizationId, {
|
|
593
|
-
eventId,
|
|
594
|
-
type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
|
|
595
|
-
progressRange: {
|
|
596
|
-
min: 0.1,
|
|
597
|
-
max: 0.9,
|
|
598
|
-
},
|
|
599
|
-
data: { sessionId: this.id },
|
|
600
|
-
});
|
|
601
|
-
// OPTION TO SKIP - PART 2
|
|
602
|
-
const cancelResult2 = this.cancelProcess(customizationId, eventId, viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION, 1, { sessionId: this.id });
|
|
603
|
-
if (cancelResult2)
|
|
604
|
-
return cancelResult2;
|
|
605
|
-
this._warningCreator(this._responseDto.outputs, this._responseDto.exports, this._throwOnCustomizationError);
|
|
606
|
-
const newOutputVersions = this._outputLoader.getCurrentOutputVersions();
|
|
607
|
-
const eventSceneUpdate = {
|
|
608
|
-
type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
|
|
609
|
-
id: eventId,
|
|
610
|
-
progress: 0.9,
|
|
611
|
-
data: { sessionId: this.id },
|
|
612
|
-
status: "Updating scene",
|
|
613
|
-
};
|
|
614
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_PROCESS, eventSceneUpdate);
|
|
615
|
-
// call the update callbacks
|
|
616
|
-
if (waitForViewportUpdate === false) {
|
|
617
|
-
for (const outputId in this.outputs) {
|
|
618
|
-
if (oldOutputVersions[outputId] !==
|
|
619
|
-
newOutputVersions[outputId]) {
|
|
620
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.OUTPUT.OUTPUT_UPDATED, {
|
|
621
|
-
outputId: outputId,
|
|
622
|
-
outputVersion: newOutputVersions[outputId],
|
|
623
|
-
newNode: newNode.children.find((c) => c.name === outputId),
|
|
624
|
-
oldNode: oldNode.children.find((c) => c.name === outputId),
|
|
625
|
-
});
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
yield this.waitForUpdateCallbacks(newOutputVersions, oldOutputVersions, newNode, oldNode);
|
|
629
|
-
const cancelResult = this.cancelProcess(customizationId, eventId, viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION, 1, { sessionId: this.id });
|
|
630
|
-
if (cancelResult)
|
|
631
|
-
return cancelResult;
|
|
632
|
-
}
|
|
633
|
-
// if this is not a call by the goBack or goForward functions, add the parameter values to the history and delete the forward history
|
|
634
|
-
if (!__classPrivateFieldGet(this, _SessionEngine_parameterHistoryCall, "f")) {
|
|
635
|
-
__classPrivateFieldGet(this, _SessionEngine_parameterHistory, "f").push(parameterSet);
|
|
636
|
-
__classPrivateFieldSet(this, _SessionEngine_parameterHistoryForward, [], "f");
|
|
637
|
-
}
|
|
638
|
-
if (this.automaticSceneUpdate)
|
|
639
|
-
this.removeFromSceneTree(this.node);
|
|
640
|
-
this._node = newNode;
|
|
641
|
-
if (this.automaticSceneUpdate && this._closed === false)
|
|
642
|
-
this.addToSceneTree(this.node);
|
|
643
|
-
this._logger.debug(`Session(${this.id}).customize: Customization request finished, updating geometry.`);
|
|
644
|
-
// set the session values to the current ones in all parameters
|
|
645
|
-
for (const parameterId in this.parameters)
|
|
646
|
-
this.parameters[parameterId].sessionValue =
|
|
647
|
-
parameterSet[parameterId].value;
|
|
648
|
-
// set the output content to what has been updated
|
|
649
|
-
for (const outputId in this.outputs)
|
|
650
|
-
this.outputs[outputId].updateOutput(newNode.children.find((c) => c.name === outputId), oldNode.children.find((c) => c.name === outputId));
|
|
651
|
-
// set the export definitions
|
|
652
|
-
for (const exportId in this.exports)
|
|
653
|
-
this.exports[exportId].updateExport();
|
|
654
|
-
this.node.excludeViewports = JSON.parse(JSON.stringify(this._excludeViewports));
|
|
655
|
-
this.removeBusyMode(customizationId);
|
|
656
|
-
this._logger.debug(`Session(${this.id}).customize: Session customized.`);
|
|
657
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.SESSION.SESSION_CUSTOMIZED, {
|
|
658
|
-
sessionId: this.id,
|
|
659
|
-
});
|
|
660
|
-
const eventEnd = {
|
|
661
|
-
type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
|
|
662
|
-
id: eventId,
|
|
663
|
-
progress: 1,
|
|
664
|
-
data: { sessionId: this.id },
|
|
665
|
-
status: "Session customized",
|
|
666
|
-
};
|
|
667
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_END, eventEnd);
|
|
668
|
-
// update the viewports
|
|
669
|
-
if (waitForViewportUpdate) {
|
|
670
|
-
for (const r in this._stateEngine.viewportEngines)
|
|
671
|
-
if (this._stateEngine.viewportEngines[r] &&
|
|
672
|
-
!this.excludeViewports.includes(this._stateEngine.viewportEngines[r].id))
|
|
673
|
-
this._stateEngine.viewportEngines[r].update(`SessionEngine(${this.id}).customize`);
|
|
674
|
-
for (const outputId in this.outputs) {
|
|
675
|
-
if (oldOutputVersions[outputId] !==
|
|
676
|
-
newOutputVersions[outputId]) {
|
|
677
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.OUTPUT.OUTPUT_UPDATED, {
|
|
678
|
-
outputId: outputId,
|
|
679
|
-
outputVersion: newOutputVersions[outputId],
|
|
680
|
-
newNode: newNode.children.find((c) => c.name === outputId),
|
|
681
|
-
oldNode: oldNode.children.find((c) => c.name === outputId),
|
|
682
|
-
});
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
// call the update callbacks
|
|
686
|
-
yield this.waitForUpdateCallbacks(newOutputVersions, oldOutputVersions, newNode, oldNode);
|
|
687
|
-
const cancelResult = this.cancelProcess(customizationId, eventId, viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION, 1, { sessionId: this.id });
|
|
688
|
-
if (cancelResult)
|
|
689
|
-
return cancelResult;
|
|
690
|
-
}
|
|
691
|
-
if (!waitForViewportUpdate) {
|
|
692
|
-
setTimeout(() => {
|
|
693
|
-
for (const r in this._stateEngine.viewportEngines)
|
|
694
|
-
if (this._stateEngine.viewportEngines[r] &&
|
|
695
|
-
!this.excludeViewports.includes(this._stateEngine.viewportEngines[r].id))
|
|
696
|
-
this._stateEngine.viewportEngines[r].update(`SessionEngine(${this.id}).customize`);
|
|
697
|
-
}, 0);
|
|
698
|
-
}
|
|
699
|
-
return this.node;
|
|
700
|
-
}
|
|
701
|
-
catch (e) {
|
|
702
|
-
const eventCancel = {
|
|
703
|
-
type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
|
|
704
|
-
id: eventId,
|
|
705
|
-
progress: 1,
|
|
706
|
-
data: { sessionId: this.id },
|
|
707
|
-
status: "Session customization failed",
|
|
708
|
-
};
|
|
709
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_CANCEL, eventCancel);
|
|
710
|
-
this.removeBusyMode(customizationId);
|
|
711
|
-
throw this._httpClient.convertError(e);
|
|
712
|
-
}
|
|
713
|
-
});
|
|
714
|
-
}
|
|
715
|
-
customizeParallel(parameterValues, loadOutputs = true) {
|
|
716
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
717
|
-
const eventId = this._uuidGenerator.create();
|
|
718
|
-
const eventStart = {
|
|
719
|
-
type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
|
|
720
|
-
id: eventId,
|
|
721
|
-
progress: 0,
|
|
722
|
-
data: { sessionId: this.id },
|
|
723
|
-
status: "Customizing session",
|
|
724
|
-
};
|
|
725
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_START, eventStart);
|
|
726
|
-
// upload file parameters
|
|
727
|
-
yield this.uploadFileParameters(parameterValues);
|
|
728
|
-
const parameterSet = {};
|
|
729
|
-
// create a set of the current validated parameter values
|
|
730
|
-
for (const parameterId in this.parameters)
|
|
731
|
-
parameterSet[parameterId] = (" " +
|
|
732
|
-
this.parameters[parameterId].stringify(parameterValues[parameterId])).slice(1);
|
|
733
|
-
const result = yield this.customizeSession(parameterSet, () => false, {
|
|
734
|
-
eventId,
|
|
735
|
-
type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
|
|
736
|
-
progressRange: {
|
|
737
|
-
min: 0.0,
|
|
738
|
-
max: 1,
|
|
739
|
-
},
|
|
740
|
-
data: { sessionId: this.id },
|
|
741
|
-
}, true, loadOutputs);
|
|
742
|
-
if (result instanceof SessionTreeNode_1.SessionTreeNode)
|
|
743
|
-
result.excludeViewports = JSON.parse(JSON.stringify(this._excludeViewports));
|
|
744
|
-
const eventEnd = {
|
|
745
|
-
type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
|
|
746
|
-
id: eventId,
|
|
747
|
-
progress: 1,
|
|
748
|
-
data: { sessionId: this.id },
|
|
749
|
-
status: "Session customized",
|
|
750
|
-
};
|
|
751
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_END, eventEnd);
|
|
752
|
-
return result;
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
customizeWithModelState(modelState, retry = false) {
|
|
756
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
757
|
-
this.checkAvailability();
|
|
758
|
-
try {
|
|
759
|
-
// get the model state if it is not already a response
|
|
760
|
-
let response;
|
|
761
|
-
if (typeof modelState === "string") {
|
|
762
|
-
response = (yield new sdk_geometry_api_sdk_v2_1.ModelStateApi(this._sdkConfig).getModelState(modelState)).data;
|
|
763
|
-
}
|
|
764
|
-
else {
|
|
765
|
-
response = modelState;
|
|
766
|
-
}
|
|
767
|
-
if (!response.modelState)
|
|
768
|
-
return new viewer_shared_node_tree_1.TreeNode();
|
|
769
|
-
// read out the parameter values from the model state
|
|
770
|
-
for (const parameterId in response.modelState.parameters)
|
|
771
|
-
this.parameters[parameterId].value =
|
|
772
|
-
response.modelState.parameters[parameterId];
|
|
773
|
-
return this.customize();
|
|
774
|
-
}
|
|
775
|
-
catch (e) {
|
|
776
|
-
yield this.handleError(e, retry);
|
|
777
|
-
return yield this.customizeWithModelState(modelState, true);
|
|
778
|
-
}
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
getFileInfo(parameterId, fileId, retry = false) {
|
|
782
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
783
|
-
this.checkAvailability();
|
|
784
|
-
try {
|
|
785
|
-
const response = yield new sdk_geometry_api_sdk_v2_1.FileApi(this._sdkConfig).getFileMetadata(this._sessionId, parameterId, fileId);
|
|
786
|
-
const { size, filename } = (0, sdk_geometry_api_sdk_v2_1.extractFileInfo)(response.headers);
|
|
787
|
-
return {
|
|
788
|
-
parameterId: parameterId,
|
|
789
|
-
id: fileId,
|
|
790
|
-
size: size,
|
|
791
|
-
filename: filename,
|
|
792
|
-
};
|
|
793
|
-
}
|
|
794
|
-
catch (e) {
|
|
795
|
-
yield this.handleError(e, retry);
|
|
796
|
-
return yield this.getFileInfo(parameterId, fileId, true);
|
|
797
|
-
}
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
getModelState(modelStateId) {
|
|
801
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
802
|
-
this.checkAvailability();
|
|
803
|
-
try {
|
|
804
|
-
const id = modelStateId || this._modelStateId;
|
|
805
|
-
if (!id)
|
|
806
|
-
throw new viewer_shared_services_1.ShapeDiverViewerSessionError("Session.getModelState: No model state id available.");
|
|
807
|
-
const response = (yield new sdk_geometry_api_sdk_v2_1.ModelStateApi(this._sdkConfig).getModelState(id)).data;
|
|
808
|
-
return response;
|
|
809
|
-
}
|
|
810
|
-
catch (e) {
|
|
811
|
-
throw this._httpClient.convertError(e);
|
|
812
|
-
}
|
|
813
|
-
});
|
|
814
|
-
}
|
|
815
|
-
goBack() {
|
|
816
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
817
|
-
if (!this.canGoBack()) {
|
|
818
|
-
this._logger.debug(`Session(${this.id}).goBack: Cannot go further back.`);
|
|
819
|
-
return new viewer_shared_node_tree_1.TreeNode();
|
|
820
|
-
}
|
|
821
|
-
// get the current parameter set and store it in the forward history later on
|
|
822
|
-
const currentParameterSet = __classPrivateFieldGet(this, _SessionEngine_parameterHistory, "f").pop();
|
|
823
|
-
// adjust the parameters according to the last parameter set
|
|
824
|
-
const lastParameterSet = __classPrivateFieldGet(this, _SessionEngine_parameterHistory, "f")[__classPrivateFieldGet(this, _SessionEngine_parameterHistory, "f").length - 1];
|
|
825
|
-
for (const parameterId in lastParameterSet)
|
|
826
|
-
this.parameters[parameterId].value =
|
|
827
|
-
lastParameterSet[parameterId].value;
|
|
828
|
-
// call the customization function with the parameterHistoryCall value set to true
|
|
829
|
-
__classPrivateFieldSet(this, _SessionEngine_parameterHistoryCall, true, "f");
|
|
830
|
-
const node = yield this.customize();
|
|
831
|
-
__classPrivateFieldSet(this, _SessionEngine_parameterHistoryCall, false, "f");
|
|
832
|
-
// add the current (not anymore current) parameter set to the forward history
|
|
833
|
-
__classPrivateFieldGet(this, _SessionEngine_parameterHistoryForward, "f").push(currentParameterSet);
|
|
834
|
-
return node;
|
|
835
|
-
});
|
|
836
|
-
}
|
|
837
|
-
goForward() {
|
|
838
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
839
|
-
if (!this.canGoForward()) {
|
|
840
|
-
this._logger.debug(`Session(${this.id}).goForward: Cannot go further forward.`);
|
|
841
|
-
return new viewer_shared_node_tree_1.TreeNode();
|
|
842
|
-
}
|
|
843
|
-
// get the last undone parameter set and apply the values to the parameters
|
|
844
|
-
const lastParameterSet = __classPrivateFieldGet(this, _SessionEngine_parameterHistoryForward, "f").pop();
|
|
845
|
-
for (const parameterId in lastParameterSet)
|
|
846
|
-
this.parameters[parameterId].value =
|
|
847
|
-
lastParameterSet[parameterId].value;
|
|
848
|
-
// call the customization function with the parameterHistoryCall value set to true
|
|
849
|
-
__classPrivateFieldSet(this, _SessionEngine_parameterHistoryCall, true, "f");
|
|
850
|
-
const node = yield this.customize();
|
|
851
|
-
__classPrivateFieldSet(this, _SessionEngine_parameterHistoryCall, false, "f");
|
|
852
|
-
// add the current parameter set to the history
|
|
853
|
-
__classPrivateFieldGet(this, _SessionEngine_parameterHistory, "f").push(lastParameterSet);
|
|
854
|
-
return node;
|
|
855
|
-
});
|
|
856
|
-
}
|
|
857
|
-
/**
|
|
858
|
-
* Initializes the session with the ticket and modelViewUrl.
|
|
859
|
-
*
|
|
860
|
-
* @returns promise with a scene graph node
|
|
861
|
-
*/
|
|
862
|
-
init(parameterValues, retry = false) {
|
|
863
|
-
var _a, _b;
|
|
864
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
865
|
-
if (this._initialized === true)
|
|
866
|
-
throw new viewer_shared_services_1.ShapeDiverViewerSessionError("Session.init: Session already initialized.");
|
|
867
|
-
try {
|
|
868
|
-
this._performanceEvaluator.startSection("sessionResponse");
|
|
869
|
-
const parameterSet = {};
|
|
870
|
-
// the slice here is done as a way for deep copying the string values
|
|
871
|
-
for (const parameterNameOrId in parameterValues)
|
|
872
|
-
parameterSet[parameterNameOrId] = (" " + parameterValues[parameterNameOrId]).slice(1);
|
|
873
|
-
if (this._ticket) {
|
|
874
|
-
this._responseDto = (yield new sdk_geometry_api_sdk_v2_1.SessionApi(this._sdkConfig).createSessionByTicket(this._ticket, this._modelStateId, this._ignoreUnknownParams, this._modelStateValidationMode, parameterSet)).data;
|
|
875
|
-
}
|
|
876
|
-
else if (this._guid) {
|
|
877
|
-
this._responseDto = (yield new sdk_geometry_api_sdk_v2_1.SessionApi(this._sdkConfig).createSessionByModel(this._guid, this._modelStateId, this._ignoreUnknownParams, this._modelStateValidationMode, parameterSet)).data;
|
|
878
|
-
}
|
|
879
|
-
else {
|
|
880
|
-
// we should never get here
|
|
881
|
-
throw new viewer_shared_services_1.ShapeDiverViewerSessionError("Session.init: Initialization of session failed. Neither a ticket nor a guid are available.");
|
|
882
|
-
}
|
|
883
|
-
this._performanceEvaluator.endSection("sessionResponse");
|
|
884
|
-
this._viewerSettings = (_a = this._responseDto.viewer) === null || _a === void 0 ? void 0 : _a.config;
|
|
885
|
-
this._viewerSettingsVersionBackend =
|
|
886
|
-
this._responseDto.viewerSettingsVersion || viewer_settings_1.latestVersion;
|
|
887
|
-
this._sessionId = this._responseDto.sessionId;
|
|
888
|
-
this._modelId = (_b = this._responseDto.model) === null || _b === void 0 ? void 0 : _b.id;
|
|
889
|
-
this._modelState = this._responseDto.modelState;
|
|
890
|
-
this._httpClient.addDataLoading(this._sessionId, {
|
|
891
|
-
getAsset: (url) => __awaiter(this, void 0, void 0, function* () {
|
|
892
|
-
const response = yield new sdk_geometry_api_sdk_v2_1.UtilsApi(this._sdkConfig).downloadAsset(url, {
|
|
893
|
-
responseType: "arraybuffer",
|
|
894
|
-
})[0];
|
|
895
|
-
return [
|
|
896
|
-
response.data,
|
|
897
|
-
response.headers["content-type"],
|
|
898
|
-
];
|
|
899
|
-
}),
|
|
900
|
-
downloadTexture: (url) => __awaiter(this, void 0, void 0, function* () {
|
|
901
|
-
const response = yield new sdk_geometry_api_sdk_v2_1.UtilsApi(this._sdkConfig).downloadImage(this._sessionId, url, {
|
|
902
|
-
responseType: "arraybuffer",
|
|
903
|
-
});
|
|
904
|
-
return [
|
|
905
|
-
response.data,
|
|
906
|
-
response.headers["content-type"],
|
|
907
|
-
];
|
|
908
|
-
}),
|
|
909
|
-
});
|
|
910
|
-
this._settingsEngine.loadSettings(this._viewerSettings);
|
|
911
|
-
if (!this._sessionId)
|
|
912
|
-
throw new viewer_shared_services_1.ShapeDiverViewerSessionError("Session.init: Initialization of session failed. ResponseDto did not have a sessionId.");
|
|
913
|
-
if (!this._modelId)
|
|
914
|
-
throw new viewer_shared_services_1.ShapeDiverViewerSessionError("Session.init: Initialization of session failed. ResponseDto did not have a model.id.");
|
|
915
|
-
this.updateResponseDto(this._responseDto, parameterSet);
|
|
916
|
-
this._initialized = true;
|
|
917
|
-
}
|
|
918
|
-
catch (e) {
|
|
919
|
-
yield this.handleError(e, retry);
|
|
920
|
-
return yield this.init(parameterValues, true);
|
|
921
|
-
}
|
|
922
|
-
});
|
|
923
|
-
}
|
|
924
|
-
loadCachedOutputsParallel(outputMapping, taskEventInfo, retry = false) {
|
|
925
|
-
var _a;
|
|
926
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
927
|
-
this.checkAvailability();
|
|
928
|
-
// if there is already task event info, use it
|
|
929
|
-
// this happens after a retry
|
|
930
|
-
const eventId = taskEventInfo
|
|
931
|
-
? taskEventInfo.eventId
|
|
932
|
-
: this._uuidGenerator.create();
|
|
933
|
-
const eventType = taskEventInfo
|
|
934
|
-
? taskEventInfo.type
|
|
935
|
-
: viewer_shared_types_1.TASK_TYPE.SESSION_OUTPUTS_LOADING;
|
|
936
|
-
const eventData = taskEventInfo
|
|
937
|
-
? taskEventInfo.data
|
|
938
|
-
: { sessionId: this.id };
|
|
939
|
-
taskEventInfo = taskEventInfo
|
|
940
|
-
? taskEventInfo
|
|
941
|
-
: {
|
|
942
|
-
eventId,
|
|
943
|
-
type: eventType,
|
|
944
|
-
progressRange: {
|
|
945
|
-
min: 0,
|
|
946
|
-
max: 1,
|
|
947
|
-
},
|
|
948
|
-
data: eventData,
|
|
949
|
-
};
|
|
950
|
-
try {
|
|
951
|
-
// send start event if this function was called initially
|
|
952
|
-
if (!taskEventInfo) {
|
|
953
|
-
const eventStart = {
|
|
954
|
-
type: eventType,
|
|
955
|
-
id: eventId,
|
|
956
|
-
progress: 0,
|
|
957
|
-
data: eventData,
|
|
958
|
-
status: "Loading cached outputs",
|
|
959
|
-
};
|
|
960
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_START, eventStart);
|
|
961
|
-
}
|
|
962
|
-
// get the cached outputs
|
|
963
|
-
const responseDto = (yield new sdk_geometry_api_sdk_v2_1.OutputApi(this._sdkConfig).getCachedOutputs(this._sessionId, outputMapping)).data;
|
|
964
|
-
// create atomic output api objects for them
|
|
965
|
-
const outputs = {};
|
|
966
|
-
for (const outputId in responseDto.outputs) {
|
|
967
|
-
responseDto.outputs[outputId].id = outputId;
|
|
968
|
-
outputs[outputId] = new Output_1.Output(responseDto.outputs[outputId], this);
|
|
969
|
-
}
|
|
970
|
-
// process the output data
|
|
971
|
-
const node = yield this._outputLoader.loadOutputs(((_a = this._responseDto.model) === null || _a === void 0 ? void 0 : _a.name) || "model", outputs, {}, taskEventInfo, false);
|
|
972
|
-
// send the end event once done
|
|
973
|
-
const eventEnd = {
|
|
974
|
-
type: eventType,
|
|
975
|
-
id: eventId,
|
|
976
|
-
progress: 1,
|
|
977
|
-
data: eventData,
|
|
978
|
-
status: "Loaded cached outputs",
|
|
979
|
-
};
|
|
980
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_END, eventEnd);
|
|
981
|
-
// create a mapping with a dictionary for the id of the outputs
|
|
982
|
-
const outputNodeMapping = {};
|
|
983
|
-
for (const outputId in outputMapping)
|
|
984
|
-
outputNodeMapping[outputId] = node.children.find((n) => n.name === outputId);
|
|
985
|
-
return outputNodeMapping;
|
|
986
|
-
}
|
|
987
|
-
catch (e) {
|
|
988
|
-
yield this.handleError(e, retry);
|
|
989
|
-
return yield this.loadCachedOutputsParallel(outputMapping, taskEventInfo, true);
|
|
990
|
-
}
|
|
991
|
-
});
|
|
992
|
-
}
|
|
993
|
-
/**
|
|
994
|
-
* Load the outputs and return the scene graph node of the result.
|
|
995
|
-
* In case the outputs have a delay property, another customization request with the parameter set is sent.
|
|
996
|
-
*
|
|
997
|
-
* @param parameters the parameter set to update the session
|
|
998
|
-
* @param outputs the outputs to load
|
|
999
|
-
* @returns promise with a scene graph node
|
|
1000
|
-
*/
|
|
1001
|
-
loadOutputs(cancelRequest = () => false, taskEventInfo, retry = false) {
|
|
1002
|
-
var _a;
|
|
1003
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1004
|
-
this.checkAvailability();
|
|
1005
|
-
const o = Object.assign({}, this._outputs);
|
|
1006
|
-
const of = Object.assign({}, this._outputsFreeze);
|
|
1007
|
-
try {
|
|
1008
|
-
const node = yield this._outputLoader.loadOutputs(((_a = this._responseDto.model) === null || _a === void 0 ? void 0 : _a.name) || "model", o, of, taskEventInfo);
|
|
1009
|
-
node.data.push(new SessionData_1.SessionData(this._responseDto));
|
|
1010
|
-
if (cancelRequest())
|
|
1011
|
-
return node;
|
|
1012
|
-
node.excludeViewports = JSON.parse(JSON.stringify(this._excludeViewports));
|
|
1013
|
-
return node;
|
|
1014
|
-
}
|
|
1015
|
-
catch (e) {
|
|
1016
|
-
if (e instanceof OutputDelayException_1.OutputDelayException) {
|
|
1017
|
-
yield this.timeout(e.delay);
|
|
1018
|
-
}
|
|
1019
|
-
else {
|
|
1020
|
-
yield this.handleError(e, retry);
|
|
1021
|
-
if (cancelRequest())
|
|
1022
|
-
return new SessionTreeNode_1.SessionTreeNode();
|
|
1023
|
-
return yield this.loadOutputs(cancelRequest, taskEventInfo, true);
|
|
1024
|
-
}
|
|
1025
|
-
if (cancelRequest())
|
|
1026
|
-
return new SessionTreeNode_1.SessionTreeNode();
|
|
1027
|
-
const outputMapping = {};
|
|
1028
|
-
for (const output in o)
|
|
1029
|
-
outputMapping[output] = o[output].version;
|
|
1030
|
-
try {
|
|
1031
|
-
const responseDto = (yield new sdk_geometry_api_sdk_v2_1.OutputApi(this._sdkConfig).getCachedOutputs(this._sessionId, outputMapping)).data;
|
|
1032
|
-
if (cancelRequest())
|
|
1033
|
-
return new SessionTreeNode_1.SessionTreeNode();
|
|
1034
|
-
this.updateResponseDto(responseDto);
|
|
1035
|
-
return yield this.loadOutputs(cancelRequest, taskEventInfo);
|
|
1036
|
-
}
|
|
1037
|
-
catch (e) {
|
|
1038
|
-
yield this.handleError(e, retry);
|
|
1039
|
-
if (cancelRequest())
|
|
1040
|
-
return new SessionTreeNode_1.SessionTreeNode();
|
|
1041
|
-
return yield this.loadOutputs(cancelRequest, taskEventInfo, true);
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
});
|
|
1045
|
-
}
|
|
1046
|
-
/**
|
|
1047
|
-
* Load the outputs and return the scene graph node of the result.
|
|
1048
|
-
* In case the outputs have a delay property, another customization request with the parameter set is sent.
|
|
1049
|
-
*
|
|
1050
|
-
* @param parameters the parameter set to update the session
|
|
1051
|
-
* @param outputs the outputs to load
|
|
1052
|
-
* @returns promise with a scene graph node
|
|
1053
|
-
*/
|
|
1054
|
-
loadOutputsParallel(responseDto, cancelRequest = () => false, taskEventInfo, retry = false) {
|
|
1055
|
-
var _a;
|
|
1056
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1057
|
-
this.checkAvailability();
|
|
1058
|
-
const outputs = {};
|
|
1059
|
-
const outputsFreeze = {};
|
|
1060
|
-
for (const outputId in responseDto.outputs) {
|
|
1061
|
-
responseDto.outputs[outputId].id = outputId;
|
|
1062
|
-
if (this.outputsFreeze[outputId] === undefined)
|
|
1063
|
-
outputsFreeze[outputId] = false;
|
|
1064
|
-
outputs[outputId] = new Output_1.Output(responseDto.outputs[outputId], this);
|
|
1065
|
-
}
|
|
1066
|
-
try {
|
|
1067
|
-
const node = yield this._outputLoader.loadOutputs(((_a = this._responseDto.model) === null || _a === void 0 ? void 0 : _a.name) || "model", outputs, outputsFreeze, taskEventInfo, true, true);
|
|
1068
|
-
node.data.push(new SessionData_1.SessionData(responseDto));
|
|
1069
|
-
return node;
|
|
1070
|
-
}
|
|
1071
|
-
catch (e) {
|
|
1072
|
-
if (e instanceof OutputDelayException_1.OutputDelayException) {
|
|
1073
|
-
yield this.timeout(e.delay);
|
|
1074
|
-
}
|
|
1075
|
-
else {
|
|
1076
|
-
yield this.handleError(e, retry);
|
|
1077
|
-
if (cancelRequest())
|
|
1078
|
-
return new SessionTreeNode_1.SessionTreeNode();
|
|
1079
|
-
return yield this.loadOutputsParallel(responseDto, cancelRequest, taskEventInfo, true);
|
|
1080
|
-
}
|
|
1081
|
-
if (cancelRequest())
|
|
1082
|
-
return new SessionTreeNode_1.SessionTreeNode();
|
|
1083
|
-
const outputMapping = {};
|
|
1084
|
-
for (const output in outputs)
|
|
1085
|
-
outputMapping[output] = outputs[output].version;
|
|
1086
|
-
try {
|
|
1087
|
-
const responseDto = (yield new sdk_geometry_api_sdk_v2_1.OutputApi(this._sdkConfig).getCachedOutputs(this._sessionId, outputMapping)).data;
|
|
1088
|
-
if (cancelRequest())
|
|
1089
|
-
return new SessionTreeNode_1.SessionTreeNode();
|
|
1090
|
-
this.updateResponseDto(responseDto);
|
|
1091
|
-
return yield this.loadOutputsParallel(responseDto, cancelRequest, taskEventInfo);
|
|
1092
|
-
}
|
|
1093
|
-
catch (e) {
|
|
1094
|
-
yield this.handleError(e, retry);
|
|
1095
|
-
if (cancelRequest())
|
|
1096
|
-
return new SessionTreeNode_1.SessionTreeNode();
|
|
1097
|
-
return yield this.loadOutputsParallel(responseDto, cancelRequest, taskEventInfo, true);
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
});
|
|
1101
|
-
}
|
|
1102
|
-
requestExport(exportId, parameters, maxWaitTime, retry = false) {
|
|
1103
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1104
|
-
this.checkAvailability("export");
|
|
1105
|
-
try {
|
|
1106
|
-
yield this.uploadFileParameters(parameters);
|
|
1107
|
-
const requestParameterSet = this.cleanExportParameters(parameters);
|
|
1108
|
-
const responseDto = yield new sdk_geometry_api_sdk_v2_1.UtilsApi(this._sdkConfig).submitAndWaitForExport(this._sessionId, { exports: [exportId], parameters: requestParameterSet }, maxWaitTime, this._ignoreUnknownParams);
|
|
1109
|
-
this.updateResponseDto(responseDto);
|
|
1110
|
-
return this.exports[exportId];
|
|
1111
|
-
}
|
|
1112
|
-
catch (e) {
|
|
1113
|
-
yield this.handleError(e, retry);
|
|
1114
|
-
return yield this.requestExport(exportId, parameters, maxWaitTime, true);
|
|
1115
|
-
}
|
|
1116
|
-
});
|
|
1117
|
-
}
|
|
1118
|
-
requestExports(body, loadOutputs = false, maxWaitMsec, retry = false) {
|
|
1119
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1120
|
-
let processId;
|
|
1121
|
-
const eventId = this._uuidGenerator.create();
|
|
1122
|
-
// if the outputs are loaded, we treat this as a customization by sending the same events
|
|
1123
|
-
const treatInternallyAsCustomization = loadOutputs === true && this._allowOutputLoading === true;
|
|
1124
|
-
this.checkAvailability("export");
|
|
1125
|
-
try {
|
|
1126
|
-
if (treatInternallyAsCustomization) {
|
|
1127
|
-
const eventStart = {
|
|
1128
|
-
type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
|
|
1129
|
-
id: eventId,
|
|
1130
|
-
progress: 0,
|
|
1131
|
-
data: { sessionId: this.id },
|
|
1132
|
-
status: "Customizing session",
|
|
1133
|
-
};
|
|
1134
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_START, eventStart);
|
|
1135
|
-
}
|
|
1136
|
-
// activate the busy mode if outputs are loaded
|
|
1137
|
-
if (loadOutputs === true &&
|
|
1138
|
-
this._allowOutputLoading === true &&
|
|
1139
|
-
body.outputs &&
|
|
1140
|
-
Object.keys(body.outputs).length > 0) {
|
|
1141
|
-
processId = this._uuidGenerator.create();
|
|
1142
|
-
this.addBusyMode(processId);
|
|
1143
|
-
}
|
|
1144
|
-
if (treatInternallyAsCustomization) {
|
|
1145
|
-
const eventFileUpload = {
|
|
1146
|
-
type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
|
|
1147
|
-
id: eventId,
|
|
1148
|
-
progress: 0.1,
|
|
1149
|
-
data: { sessionId: this.id },
|
|
1150
|
-
status: "Uploading file parameters",
|
|
1151
|
-
};
|
|
1152
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_PROCESS, eventFileUpload);
|
|
1153
|
-
}
|
|
1154
|
-
yield this.uploadFileParameters(body.parameters);
|
|
1155
|
-
const requestParameterSet = this.cleanExportParameters(body.parameters);
|
|
1156
|
-
if (treatInternallyAsCustomization) {
|
|
1157
|
-
const eventRequest = {
|
|
1158
|
-
type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
|
|
1159
|
-
id: eventId,
|
|
1160
|
-
progress: 0.1,
|
|
1161
|
-
data: { sessionId: this.id },
|
|
1162
|
-
status: "Sending customization request",
|
|
1163
|
-
};
|
|
1164
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_PROCESS, eventRequest);
|
|
1165
|
-
}
|
|
1166
|
-
const responseDto = yield new sdk_geometry_api_sdk_v2_1.UtilsApi(this._sdkConfig).submitAndWaitForExport(this._sessionId, {
|
|
1167
|
-
exports: body.exports,
|
|
1168
|
-
parameters: requestParameterSet,
|
|
1169
|
-
outputs: body.outputs,
|
|
1170
|
-
max_wait_time: body.max_wait_time,
|
|
1171
|
-
}, maxWaitMsec, this._ignoreUnknownParams);
|
|
1172
|
-
this.updateResponseDto(responseDto);
|
|
1173
|
-
if (treatInternallyAsCustomization) {
|
|
1174
|
-
yield this.updateOutputs({
|
|
1175
|
-
eventId,
|
|
1176
|
-
type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
|
|
1177
|
-
progressRange: {
|
|
1178
|
-
min: 0.1,
|
|
1179
|
-
max: 0.9,
|
|
1180
|
-
},
|
|
1181
|
-
data: { sessionId: this.id },
|
|
1182
|
-
});
|
|
1183
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.SESSION.SESSION_CUSTOMIZED, { sessionId: this.id });
|
|
1184
|
-
const eventEnd = {
|
|
1185
|
-
type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
|
|
1186
|
-
id: eventId,
|
|
1187
|
-
progress: 1,
|
|
1188
|
-
data: { sessionId: this.id },
|
|
1189
|
-
status: "Session customized",
|
|
1190
|
-
};
|
|
1191
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_END, eventEnd);
|
|
1192
|
-
}
|
|
1193
|
-
if (processId)
|
|
1194
|
-
this.removeBusyMode(processId);
|
|
1195
|
-
return responseDto;
|
|
1196
|
-
}
|
|
1197
|
-
catch (e) {
|
|
1198
|
-
if (treatInternallyAsCustomization) {
|
|
1199
|
-
const eventCancel = {
|
|
1200
|
-
type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
|
|
1201
|
-
id: eventId,
|
|
1202
|
-
progress: 1,
|
|
1203
|
-
data: { sessionId: this.id },
|
|
1204
|
-
status: "Session customization failed",
|
|
1205
|
-
};
|
|
1206
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_CANCEL, eventCancel);
|
|
1207
|
-
}
|
|
1208
|
-
if (processId)
|
|
1209
|
-
this.removeBusyMode(processId);
|
|
1210
|
-
yield this.handleError(e, retry);
|
|
1211
|
-
return yield this.requestExports(body, loadOutputs, maxWaitMsec, true);
|
|
1212
|
-
}
|
|
1213
|
-
});
|
|
1214
|
-
}
|
|
1215
|
-
resetSettings(sections) {
|
|
1216
|
-
if (!this._responseDto)
|
|
1217
|
-
throw new viewer_shared_services_1.ShapeDiverViewerSessionError("Session.resetSettings: responseDto not available.");
|
|
1218
|
-
sections = sections || {};
|
|
1219
|
-
if (sections.session === undefined) {
|
|
1220
|
-
sections.session = {
|
|
1221
|
-
parameter: { displayname: true, order: true, hidden: true },
|
|
1222
|
-
export: { displayname: true, order: true, hidden: true },
|
|
1223
|
-
};
|
|
1224
|
-
}
|
|
1225
|
-
if (sections.session.parameter === undefined)
|
|
1226
|
-
sections.session.parameter = {
|
|
1227
|
-
displayname: true,
|
|
1228
|
-
order: true,
|
|
1229
|
-
hidden: true,
|
|
1230
|
-
value: true,
|
|
1231
|
-
};
|
|
1232
|
-
if (sections.session.export === undefined)
|
|
1233
|
-
sections.session.export = {
|
|
1234
|
-
displayname: true,
|
|
1235
|
-
order: true,
|
|
1236
|
-
hidden: true,
|
|
1237
|
-
};
|
|
1238
|
-
if (sections.viewport === undefined)
|
|
1239
|
-
sections.viewport = {
|
|
1240
|
-
ar: true,
|
|
1241
|
-
scene: true,
|
|
1242
|
-
camera: true,
|
|
1243
|
-
light: true,
|
|
1244
|
-
environment: true,
|
|
1245
|
-
general: true,
|
|
1246
|
-
postprocessing: true,
|
|
1247
|
-
};
|
|
1248
|
-
return this.applySettings(this._responseDto, sections);
|
|
1249
|
-
}
|
|
1250
|
-
saveDefaultParameterValues() {
|
|
1251
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1252
|
-
this._logger.debugLow(`Session(${this.id}).saveDefaultParameters: Saving default parameters.`);
|
|
1253
|
-
const response = yield this.saveDefaultParameters();
|
|
1254
|
-
if (response) {
|
|
1255
|
-
this._logger.debug(`Session(${this.id}).saveDefaultParameters: Saved default parameters.`);
|
|
1256
|
-
}
|
|
1257
|
-
else {
|
|
1258
|
-
throw new viewer_shared_services_1.ShapeDiverViewerSessionError(`Session(${this.id}).saveDefaultParameters: Could not save default parameters.`);
|
|
1259
|
-
}
|
|
1260
|
-
return response;
|
|
1261
|
-
});
|
|
1262
|
-
}
|
|
1263
|
-
saveDefaultParameters(retry = false) {
|
|
1264
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1265
|
-
this.checkAvailability("defaultparam", true);
|
|
1266
|
-
try {
|
|
1267
|
-
yield new sdk_geometry_api_sdk_v2_1.ModelApi(this._sdkConfig).updateParameterDefaultValues(this._modelId, this._parameterValues);
|
|
1268
|
-
return true;
|
|
1269
|
-
}
|
|
1270
|
-
catch (e) {
|
|
1271
|
-
yield this.handleError(e, retry);
|
|
1272
|
-
return yield this.saveDefaultParameters(true);
|
|
1273
|
-
}
|
|
1274
|
-
});
|
|
1275
|
-
}
|
|
1276
|
-
/**
|
|
1277
|
-
* Save the export properties for displayname, order, tooltip and hidden
|
|
1278
|
-
*
|
|
1279
|
-
* @param exports
|
|
1280
|
-
* @returns
|
|
1281
|
-
*/
|
|
1282
|
-
saveExportProperties(exports, retry = false) {
|
|
1283
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1284
|
-
this.checkAvailability("export-definition", true);
|
|
1285
|
-
try {
|
|
1286
|
-
yield new sdk_geometry_api_sdk_v2_1.ExportApi(this._sdkConfig).updateExportDefinitions(this._modelId, exports);
|
|
1287
|
-
return true;
|
|
1288
|
-
}
|
|
1289
|
-
catch (e) {
|
|
1290
|
-
yield this.handleError(e, retry);
|
|
1291
|
-
return yield this.saveExportProperties(exports, true);
|
|
1292
|
-
}
|
|
1293
|
-
});
|
|
1294
|
-
}
|
|
1295
|
-
/**
|
|
1296
|
-
* Save the output properties for displayname, order, tooltip and hidden
|
|
1297
|
-
*
|
|
1298
|
-
* @param outputs
|
|
1299
|
-
* @returns
|
|
1300
|
-
*/
|
|
1301
|
-
saveOutputProperties(outputs, retry = false) {
|
|
1302
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1303
|
-
this.checkAvailability("output-definition", true);
|
|
1304
|
-
try {
|
|
1305
|
-
yield new sdk_geometry_api_sdk_v2_1.OutputApi(this._sdkConfig).updateOutputDefinitions(this._modelId, outputs);
|
|
1306
|
-
return true;
|
|
1307
|
-
}
|
|
1308
|
-
catch (e) {
|
|
1309
|
-
yield this.handleError(e, retry);
|
|
1310
|
-
return yield this.saveOutputProperties(outputs, true);
|
|
1311
|
-
}
|
|
1312
|
-
});
|
|
1313
|
-
}
|
|
1314
|
-
/**
|
|
1315
|
-
* Save the parameter properties for displayname, order, tooltip and hidden
|
|
1316
|
-
*
|
|
1317
|
-
* @param parameters
|
|
1318
|
-
* @returns
|
|
1319
|
-
*/
|
|
1320
|
-
saveParameterProperties(parameters, retry = false) {
|
|
1321
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1322
|
-
this.checkAvailability("parameter-definition", true);
|
|
1323
|
-
try {
|
|
1324
|
-
yield new sdk_geometry_api_sdk_v2_1.ModelApi(this._sdkConfig).updateParameterDefinitions(this._modelId, parameters);
|
|
1325
|
-
return true;
|
|
1326
|
-
}
|
|
1327
|
-
catch (e) {
|
|
1328
|
-
yield this.handleError(e, retry);
|
|
1329
|
-
return yield this.saveParameterProperties(parameters, true);
|
|
1330
|
-
}
|
|
1331
|
-
});
|
|
1332
|
-
}
|
|
1333
|
-
saveSettings(json, retry = false) {
|
|
1334
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1335
|
-
this.checkAvailability("configure", true);
|
|
1336
|
-
try {
|
|
1337
|
-
(0, viewer_settings_1.validate)(json, this._viewerSettingsVersion);
|
|
1338
|
-
// if viewer settings version is higher than backend settings version
|
|
1339
|
-
// convert to backend settings version
|
|
1340
|
-
if (+this._viewerSettingsVersion >
|
|
1341
|
-
+this._viewerSettingsVersionBackend)
|
|
1342
|
-
json = (0, viewer_settings_1.convert)(json, this._viewerSettingsVersionBackend);
|
|
1343
|
-
}
|
|
1344
|
-
catch (e) {
|
|
1345
|
-
throw new viewer_shared_services_1.ShapeDiverViewerSettingsError("Session.saveSettings: Settings could not be validated. " +
|
|
1346
|
-
e.message, e);
|
|
1347
|
-
}
|
|
1348
|
-
try {
|
|
1349
|
-
yield new sdk_geometry_api_sdk_v2_1.ModelApi(this._sdkConfig).updateModelConfig(this._modelId, json);
|
|
1350
|
-
return true;
|
|
1351
|
-
}
|
|
1352
|
-
catch (e) {
|
|
1353
|
-
yield this.handleError(e, retry);
|
|
1354
|
-
return yield this.saveSettings(json, true);
|
|
1355
|
-
}
|
|
1356
|
-
});
|
|
1357
|
-
}
|
|
1358
|
-
saveUiProperties(saveInSettings = true) {
|
|
1359
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1360
|
-
this._logger.debugLow(`Session(${this.id}).saveSessionProperties: Saving session properties.`);
|
|
1361
|
-
// settings saving
|
|
1362
|
-
this._saveSessionSettings();
|
|
1363
|
-
let properties = {};
|
|
1364
|
-
for (const p in this.parameters) {
|
|
1365
|
-
properties[p] = {
|
|
1366
|
-
displayname: this.parameters[p].displayname !== undefined
|
|
1367
|
-
? this.parameters[p].displayname
|
|
1368
|
-
: "",
|
|
1369
|
-
hidden: this.parameters[p].hidden !== undefined
|
|
1370
|
-
? this.parameters[p].hidden
|
|
1371
|
-
: false,
|
|
1372
|
-
order: this.parameters[p].order !== undefined
|
|
1373
|
-
? this.parameters[p].order
|
|
1374
|
-
: 0,
|
|
1375
|
-
tooltip: this.parameters[p].tooltip !== undefined
|
|
1376
|
-
? this.parameters[p].tooltip
|
|
1377
|
-
: "",
|
|
1378
|
-
};
|
|
1379
|
-
}
|
|
1380
|
-
const responseP = Object.values(properties).length !== 0
|
|
1381
|
-
? yield this.saveParameterProperties(properties)
|
|
1382
|
-
: true;
|
|
1383
|
-
properties = {};
|
|
1384
|
-
for (const e in this.exports) {
|
|
1385
|
-
properties[e] = {
|
|
1386
|
-
displayname: this.exports[e].displayname !== undefined
|
|
1387
|
-
? this.exports[e].displayname
|
|
1388
|
-
: "",
|
|
1389
|
-
hidden: this.exports[e].hidden !== undefined
|
|
1390
|
-
? this.exports[e].hidden
|
|
1391
|
-
: false,
|
|
1392
|
-
order: this.exports[e].order !== undefined
|
|
1393
|
-
? this.exports[e].order
|
|
1394
|
-
: 0,
|
|
1395
|
-
tooltip: this.exports[e].tooltip !== undefined
|
|
1396
|
-
? this.exports[e].tooltip
|
|
1397
|
-
: "",
|
|
1398
|
-
};
|
|
1399
|
-
}
|
|
1400
|
-
const responseE = Object.values(properties).length !== 0
|
|
1401
|
-
? yield this.saveExportProperties(properties)
|
|
1402
|
-
: true;
|
|
1403
|
-
properties = {};
|
|
1404
|
-
for (const o in this.outputs) {
|
|
1405
|
-
properties[o] = {
|
|
1406
|
-
displayname: this.outputs[o].displayname !== undefined
|
|
1407
|
-
? this.outputs[o].displayname
|
|
1408
|
-
: "",
|
|
1409
|
-
hidden: this.outputs[o].hidden !== undefined
|
|
1410
|
-
? this.outputs[o].hidden
|
|
1411
|
-
: false,
|
|
1412
|
-
order: this.outputs[o].order !== undefined
|
|
1413
|
-
? this.outputs[o].order
|
|
1414
|
-
: 0,
|
|
1415
|
-
tooltip: this.outputs[o].tooltip !== undefined
|
|
1416
|
-
? this.outputs[o].tooltip
|
|
1417
|
-
: "",
|
|
1418
|
-
};
|
|
1419
|
-
}
|
|
1420
|
-
const responseO = Object.values(properties).length !== 0
|
|
1421
|
-
? yield this.saveOutputProperties(properties)
|
|
1422
|
-
: true;
|
|
1423
|
-
// save partial settings
|
|
1424
|
-
const response = saveInSettings
|
|
1425
|
-
? yield this.saveSettings(this._settingsEngine.settings)
|
|
1426
|
-
: true;
|
|
1427
|
-
if (response && responseP && responseO && responseE) {
|
|
1428
|
-
this._logger.debug(`Session(${this.id}).saveSessionProperties: Saved session properties.`);
|
|
1429
|
-
}
|
|
1430
|
-
else {
|
|
1431
|
-
this._logger.warn(`Session(${this.id}).saveSessionProperties: Could not save session properties.`);
|
|
1432
|
-
}
|
|
1433
|
-
return response && responseP && responseO && responseE;
|
|
1434
|
-
});
|
|
1435
|
-
}
|
|
1436
|
-
setJwtToken(value, retry = false) {
|
|
1437
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1438
|
-
this.checkAvailability();
|
|
1439
|
-
this._jwtToken = value;
|
|
1440
|
-
try {
|
|
1441
|
-
this._sdkConfig.accessToken = value;
|
|
1442
|
-
const responseDto = (yield new sdk_geometry_api_sdk_v2_1.SessionApi(this._sdkConfig).getSessionDefaults(this._sessionId)).data;
|
|
1443
|
-
if (this._responseDto)
|
|
1444
|
-
this._responseDto.actions = responseDto.actions;
|
|
1445
|
-
}
|
|
1446
|
-
catch (e) {
|
|
1447
|
-
yield this.handleError(e, retry);
|
|
1448
|
-
yield this.setJwtToken(value, true);
|
|
1449
|
-
}
|
|
1450
|
-
});
|
|
1451
|
-
}
|
|
1452
|
-
updateOutputs(taskEventInfo, waitForViewportUpdate = false) {
|
|
1453
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1454
|
-
const eventId = taskEventInfo
|
|
1455
|
-
? taskEventInfo.eventId
|
|
1456
|
-
: this._uuidGenerator.create();
|
|
1457
|
-
const eventType = taskEventInfo
|
|
1458
|
-
? taskEventInfo.type
|
|
1459
|
-
: viewer_shared_types_1.TASK_TYPE.SESSION_OUTPUTS_UPDATE;
|
|
1460
|
-
const eventData = taskEventInfo
|
|
1461
|
-
? taskEventInfo.data
|
|
1462
|
-
: { sessionId: this.id };
|
|
1463
|
-
if (!taskEventInfo) {
|
|
1464
|
-
const eventStart = {
|
|
1465
|
-
type: eventType,
|
|
1466
|
-
id: eventId,
|
|
1467
|
-
progress: 0,
|
|
1468
|
-
data: eventData,
|
|
1469
|
-
status: "Updating outputs",
|
|
1470
|
-
};
|
|
1471
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_START, eventStart);
|
|
1472
|
-
}
|
|
1473
|
-
const customizationId = this._uuidGenerator.create();
|
|
1474
|
-
const oldNode = this.node;
|
|
1475
|
-
__classPrivateFieldSet(this, _SessionEngine_customizationProcess, customizationId, "f");
|
|
1476
|
-
this._logger.debugLow(`Session(${this.id}).updateOutputs: Updating Outputs.`);
|
|
1477
|
-
this.addBusyMode(customizationId);
|
|
1478
|
-
const eventRequest = {
|
|
1479
|
-
type: eventType,
|
|
1480
|
-
id: eventId,
|
|
1481
|
-
progress: taskEventInfo
|
|
1482
|
-
? (taskEventInfo.progressRange.max -
|
|
1483
|
-
taskEventInfo.progressRange.min) *
|
|
1484
|
-
0.1 +
|
|
1485
|
-
taskEventInfo.progressRange.min
|
|
1486
|
-
: 0.1,
|
|
1487
|
-
data: eventData,
|
|
1488
|
-
status: "Loading outputs",
|
|
1489
|
-
};
|
|
1490
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_PROCESS, eventRequest);
|
|
1491
|
-
const oldOutputVersions = this._outputLoader.getCurrentOutputVersions();
|
|
1492
|
-
const newNode = yield this.loadOutputs(() => __classPrivateFieldGet(this, _SessionEngine_customizationProcess, "f") !== customizationId, {
|
|
1493
|
-
eventId,
|
|
1494
|
-
type: eventType,
|
|
1495
|
-
progressRange: {
|
|
1496
|
-
min: taskEventInfo
|
|
1497
|
-
? (taskEventInfo.progressRange.max -
|
|
1498
|
-
taskEventInfo.progressRange.min) *
|
|
1499
|
-
0.1 +
|
|
1500
|
-
taskEventInfo.progressRange.min
|
|
1501
|
-
: 0.1,
|
|
1502
|
-
max: taskEventInfo
|
|
1503
|
-
? (taskEventInfo.progressRange.max -
|
|
1504
|
-
taskEventInfo.progressRange.min) *
|
|
1505
|
-
0.9 +
|
|
1506
|
-
taskEventInfo.progressRange.min
|
|
1507
|
-
: 0.9,
|
|
1508
|
-
},
|
|
1509
|
-
data: eventData,
|
|
1510
|
-
});
|
|
1511
|
-
this._warningCreator(this._responseDto.outputs, this._responseDto.exports, this._throwOnCustomizationError);
|
|
1512
|
-
const newOutputVersions = this._outputLoader.getCurrentOutputVersions();
|
|
1513
|
-
const eventSceneUpdate = {
|
|
1514
|
-
type: eventType,
|
|
1515
|
-
id: eventId,
|
|
1516
|
-
progress: taskEventInfo
|
|
1517
|
-
? (taskEventInfo.progressRange.max -
|
|
1518
|
-
taskEventInfo.progressRange.min) *
|
|
1519
|
-
0.9 +
|
|
1520
|
-
taskEventInfo.progressRange.min
|
|
1521
|
-
: 0.9,
|
|
1522
|
-
data: eventData,
|
|
1523
|
-
status: "Updating scene",
|
|
1524
|
-
};
|
|
1525
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_PROCESS, eventSceneUpdate);
|
|
1526
|
-
// OPTION TO SKIP - PART 1
|
|
1527
|
-
const cancelResult = this.cancelProcess(customizationId, eventId, eventType, taskEventInfo
|
|
1528
|
-
? (taskEventInfo.progressRange.max -
|
|
1529
|
-
taskEventInfo.progressRange.min) *
|
|
1530
|
-
1 +
|
|
1531
|
-
taskEventInfo.progressRange.min
|
|
1532
|
-
: 1, eventData, newNode);
|
|
1533
|
-
if (cancelResult)
|
|
1534
|
-
return cancelResult;
|
|
1535
|
-
// call the update callbacks
|
|
1536
|
-
if (waitForViewportUpdate === false) {
|
|
1537
|
-
for (const outputId in this.outputs) {
|
|
1538
|
-
if (oldOutputVersions[outputId] !== newOutputVersions[outputId]) {
|
|
1539
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.OUTPUT.OUTPUT_UPDATED, {
|
|
1540
|
-
outputId: outputId,
|
|
1541
|
-
outputVersion: newOutputVersions[outputId],
|
|
1542
|
-
newNode: newNode.children.find((c) => c.name === outputId),
|
|
1543
|
-
oldNode: oldNode.children.find((c) => c.name === outputId),
|
|
1544
|
-
});
|
|
1545
|
-
}
|
|
1546
|
-
}
|
|
1547
|
-
yield this.waitForUpdateCallbacks(newOutputVersions, oldOutputVersions, newNode, oldNode);
|
|
1548
|
-
// OPTION TO SKIP - PART 2
|
|
1549
|
-
const cancelResult = this.cancelProcess(customizationId, eventId, eventType, taskEventInfo
|
|
1550
|
-
? (taskEventInfo.progressRange.max -
|
|
1551
|
-
taskEventInfo.progressRange.min) *
|
|
1552
|
-
1 +
|
|
1553
|
-
taskEventInfo.progressRange.min
|
|
1554
|
-
: 1, eventData, newNode);
|
|
1555
|
-
if (cancelResult)
|
|
1556
|
-
return cancelResult;
|
|
1557
|
-
}
|
|
1558
|
-
if (this.automaticSceneUpdate)
|
|
1559
|
-
this.removeFromSceneTree(this.node);
|
|
1560
|
-
this._node = newNode;
|
|
1561
|
-
if (this.automaticSceneUpdate && this._closed === false)
|
|
1562
|
-
this.addToSceneTree(this.node);
|
|
1563
|
-
this._logger.debug(`Session(${this.id}).updateOutputs: Updating outputs finished, updating geometry.`);
|
|
1564
|
-
// set the output content to what has been updated
|
|
1565
|
-
for (const outputId in this.outputs) {
|
|
1566
|
-
this.outputs[outputId].updateOutput(newNode.children.find((c) => c.name === outputId), oldNode.children.find((c) => c.name === outputId));
|
|
1567
|
-
}
|
|
1568
|
-
// set the export definitions
|
|
1569
|
-
for (const exportId in this.exports)
|
|
1570
|
-
this.exports[exportId].updateExport();
|
|
1571
|
-
this.node.excludeViewports = JSON.parse(JSON.stringify(this._excludeViewports));
|
|
1572
|
-
this.removeBusyMode(customizationId);
|
|
1573
|
-
this._logger.debug(`Session(${this.id}).updateOutputs: Updated outputs.`);
|
|
1574
|
-
if (!taskEventInfo) {
|
|
1575
|
-
const eventEnd = {
|
|
1576
|
-
type: eventType,
|
|
1577
|
-
id: eventId,
|
|
1578
|
-
progress: 1,
|
|
1579
|
-
data: eventData,
|
|
1580
|
-
status: "Outputs updated",
|
|
1581
|
-
};
|
|
1582
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_END, eventEnd);
|
|
1583
|
-
}
|
|
1584
|
-
// update the viewports
|
|
1585
|
-
if (waitForViewportUpdate) {
|
|
1586
|
-
for (const r in this._stateEngine.viewportEngines)
|
|
1587
|
-
if (this._stateEngine.viewportEngines[r] &&
|
|
1588
|
-
!this.excludeViewports.includes(this._stateEngine.viewportEngines[r].id))
|
|
1589
|
-
this._stateEngine.viewportEngines[r].update(`SessionEngine(${this.id}).updateOutputs`);
|
|
1590
|
-
for (const outputId in this.outputs) {
|
|
1591
|
-
if (oldOutputVersions[outputId] !== newOutputVersions[outputId]) {
|
|
1592
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.OUTPUT.OUTPUT_UPDATED, {
|
|
1593
|
-
outputId: outputId,
|
|
1594
|
-
outputVersion: newOutputVersions[outputId],
|
|
1595
|
-
newNode: newNode.children.find((c) => c.name === outputId),
|
|
1596
|
-
oldNode: oldNode.children.find((c) => c.name === outputId),
|
|
1597
|
-
});
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
yield this.waitForUpdateCallbacks(newOutputVersions, oldOutputVersions, newNode, oldNode);
|
|
1601
|
-
// OPTION TO SKIP - PART 3
|
|
1602
|
-
const cancelResult = this.cancelProcess(customizationId, eventId, eventType, taskEventInfo
|
|
1603
|
-
? (taskEventInfo.progressRange.max -
|
|
1604
|
-
taskEventInfo.progressRange.min) *
|
|
1605
|
-
1 +
|
|
1606
|
-
taskEventInfo.progressRange.min
|
|
1607
|
-
: 1, eventData, newNode);
|
|
1608
|
-
if (cancelResult)
|
|
1609
|
-
return cancelResult;
|
|
1610
|
-
}
|
|
1611
|
-
return this.node;
|
|
1612
|
-
});
|
|
1613
|
-
}
|
|
1614
|
-
uploadFile(parameterId, data, type, retry = false) {
|
|
1615
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1616
|
-
this.checkAvailability("file-upload");
|
|
1617
|
-
try {
|
|
1618
|
-
const result = (yield new sdk_geometry_api_sdk_v2_1.FileApi(this._sdkConfig).uploadFile(this._sessionId, {
|
|
1619
|
-
[parameterId]: {
|
|
1620
|
-
size: data.size,
|
|
1621
|
-
format: type,
|
|
1622
|
-
filename: data.name === "" ? undefined : data.name,
|
|
1623
|
-
},
|
|
1624
|
-
})).data;
|
|
1625
|
-
if (result &&
|
|
1626
|
-
result.asset &&
|
|
1627
|
-
result.asset.file &&
|
|
1628
|
-
result.asset.file[parameterId]) {
|
|
1629
|
-
const fileAsset = result.asset.file[parameterId];
|
|
1630
|
-
yield new sdk_geometry_api_sdk_v2_1.UtilsApi(this._sdkConfig).uploadAsset(fileAsset.href, yield data.arrayBuffer(), fileAsset.headers);
|
|
1631
|
-
return fileAsset.id;
|
|
1632
|
-
}
|
|
1633
|
-
else {
|
|
1634
|
-
throw new viewer_shared_services_1.ShapeDiverViewerSessionError("Session.uploadFile: Upload reply has not the required format.");
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
catch (e) {
|
|
1638
|
-
yield this.handleError(e, retry);
|
|
1639
|
-
return yield this.uploadFile(parameterId, data, type, true);
|
|
1640
|
-
}
|
|
1641
|
-
});
|
|
1642
|
-
}
|
|
1643
|
-
/**
|
|
1644
|
-
* Uploads all file parameters and returns the file parameter values.
|
|
1645
|
-
* If parameterValues is provided, the file parameter values are added to it.
|
|
1646
|
-
*
|
|
1647
|
-
* @param parameterValues
|
|
1648
|
-
* @returns
|
|
1649
|
-
*/
|
|
1650
|
-
uploadFileParameters(parameterValues) {
|
|
1651
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1652
|
-
const parameterValueSet = parameterValues !== undefined
|
|
1653
|
-
? this.getFileParameterSet(parameterValues)
|
|
1654
|
-
: undefined;
|
|
1655
|
-
const fileParameterValues = {};
|
|
1656
|
-
// load file parameter first
|
|
1657
|
-
for (const parameterId in this.parameters) {
|
|
1658
|
-
if (this.parameters[parameterId] instanceof FileParameter_1.FileParameter) {
|
|
1659
|
-
fileParameterValues[parameterId] = yield (this.parameters[parameterId]).upload(parameterValueSet
|
|
1660
|
-
? parameterValueSet[parameterId]
|
|
1661
|
-
: undefined);
|
|
1662
|
-
if (parameterValues &&
|
|
1663
|
-
parameterValues[parameterId] !== undefined) {
|
|
1664
|
-
// if a value was provided, we replace it with the returned id
|
|
1665
|
-
parameterValues[parameterId] =
|
|
1666
|
-
fileParameterValues[parameterId];
|
|
1667
|
-
// if the parameter value of the file parameter was used, set the value to the parameter
|
|
1668
|
-
if (this.parameters[parameterId].value !==
|
|
1669
|
-
fileParameterValues[parameterId])
|
|
1670
|
-
this.parameters[parameterId].value =
|
|
1671
|
-
fileParameterValues[parameterId];
|
|
1672
|
-
}
|
|
1673
|
-
else if (this.parameters[parameterId].value !==
|
|
1674
|
-
fileParameterValues[parameterId]) {
|
|
1675
|
-
this.parameters[parameterId].value =
|
|
1676
|
-
fileParameterValues[parameterId];
|
|
1677
|
-
}
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
return fileParameterValues;
|
|
1681
|
-
});
|
|
1682
|
-
}
|
|
1683
|
-
uploadGLTF(blob, conversion = sdk_geometry_api_sdk_v2_1.QueryGltfConversion.NONE, retry = false) {
|
|
1684
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1685
|
-
this.checkAvailability("gltf-upload");
|
|
1686
|
-
try {
|
|
1687
|
-
const responseDto = (yield new sdk_geometry_api_sdk_v2_1.GltfApi(this._sdkConfig).uploadGltf(this._sessionId, new File([blob], "model.gltf", {
|
|
1688
|
-
type: "model/gltf-binary",
|
|
1689
|
-
}), conversion)).data;
|
|
1690
|
-
if (!responseDto || !responseDto.gltf || !responseDto.gltf.href)
|
|
1691
|
-
throw new viewer_shared_services_1.ShapeDiverViewerSessionError("Session.uploadGLTF: Upload reply has not the required format.");
|
|
1692
|
-
return responseDto;
|
|
1693
|
-
}
|
|
1694
|
-
catch (e) {
|
|
1695
|
-
yield this.handleError(e, retry);
|
|
1696
|
-
return yield this.uploadGLTF(blob, conversion, true);
|
|
1697
|
-
}
|
|
1698
|
-
});
|
|
1699
|
-
}
|
|
1700
|
-
uploadSDTF(arrayBuffers, retry = false) {
|
|
1701
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1702
|
-
this.checkAvailability("file-upload");
|
|
1703
|
-
try {
|
|
1704
|
-
const responseDto = (yield new sdk_geometry_api_sdk_v2_1.SdtfApi(this._sdkConfig).uploadSdtf(this._sessionId, arrayBuffers.map((arrayBuffer) => {
|
|
1705
|
-
return {
|
|
1706
|
-
namespace: "pub",
|
|
1707
|
-
content_length: arrayBuffer.byteLength,
|
|
1708
|
-
content_type: sdk_geometry_api_sdk_v2_1.ReqSdtfType.MODEL_SDTF,
|
|
1709
|
-
};
|
|
1710
|
-
}))).data;
|
|
1711
|
-
if (!responseDto ||
|
|
1712
|
-
!responseDto.asset ||
|
|
1713
|
-
!responseDto.asset.sdtf ||
|
|
1714
|
-
responseDto.asset.sdtf.length !== arrayBuffers.length)
|
|
1715
|
-
throw new viewer_shared_services_1.ShapeDiverViewerSessionError("Session.uploadSDTF: Upload reply has not the required format.");
|
|
1716
|
-
const promises = arrayBuffers.map((buffer, index) => {
|
|
1717
|
-
const url = responseDto.asset.sdtf[index].href;
|
|
1718
|
-
return new sdk_geometry_api_sdk_v2_1.UtilsApi(this._sdkConfig).upload(url, buffer, sdk_geometry_api_sdk_v2_1.ReqSdtfType.MODEL_SDTF);
|
|
1719
|
-
});
|
|
1720
|
-
yield Promise.all(promises);
|
|
1721
|
-
return responseDto.asset.sdtf;
|
|
1722
|
-
}
|
|
1723
|
-
catch (e) {
|
|
1724
|
-
yield this.handleError(e, retry);
|
|
1725
|
-
return yield this.uploadSDTF(arrayBuffers, true);
|
|
1726
|
-
}
|
|
1727
|
-
});
|
|
1728
|
-
}
|
|
1729
|
-
// #endregion Public Methods (31)
|
|
1730
|
-
// #region Private Methods (18)
|
|
1731
|
-
_saveSessionSettings() {
|
|
1732
|
-
const parameters = this.parameters;
|
|
1733
|
-
const exports = this.exports;
|
|
1734
|
-
const sessionProperties = {};
|
|
1735
|
-
for (const p in parameters) {
|
|
1736
|
-
sessionProperties[p] = {
|
|
1737
|
-
order: parameters[p].order || 0,
|
|
1738
|
-
displayname: parameters[p].displayname || "",
|
|
1739
|
-
hidden: parameters[p].hidden,
|
|
1740
|
-
};
|
|
1741
|
-
}
|
|
1742
|
-
for (const e in exports) {
|
|
1743
|
-
sessionProperties[e] = {
|
|
1744
|
-
order: exports[e].order || 0,
|
|
1745
|
-
displayname: exports[e].displayname || "",
|
|
1746
|
-
hidden: exports[e].hidden,
|
|
1747
|
-
};
|
|
1748
|
-
}
|
|
1749
|
-
this._settingsEngine.session = sessionProperties;
|
|
1750
|
-
}
|
|
1751
|
-
_warningCreator(outputs, exports, throwError = false) {
|
|
1752
|
-
const outputsWithIssues = {};
|
|
1753
|
-
const exportsWithIssues = {};
|
|
1754
|
-
for (const outputId in outputs) {
|
|
1755
|
-
const outputObj = outputs[outputId];
|
|
1756
|
-
if ((throwError === false && outputObj.msg !== undefined) ||
|
|
1757
|
-
(outputObj.status_collect &&
|
|
1758
|
-
outputObj.status_collect !==
|
|
1759
|
-
sdk_geometry_api_sdk_v2_1.ResComputationStatus.SUCCESS) ||
|
|
1760
|
-
(outputObj.status_computation &&
|
|
1761
|
-
outputObj.status_computation !==
|
|
1762
|
-
sdk_geometry_api_sdk_v2_1.ResComputationStatus.SUCCESS)) {
|
|
1763
|
-
outputsWithIssues[outputId] = outputObj;
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
for (const exportId in exports) {
|
|
1767
|
-
const exportObj = exports[exportId];
|
|
1768
|
-
if ((throwError === false && exportObj.msg !== undefined) ||
|
|
1769
|
-
(exportObj.status_collect &&
|
|
1770
|
-
exportObj.status_collect !==
|
|
1771
|
-
sdk_geometry_api_sdk_v2_1.ResComputationStatus.SUCCESS) ||
|
|
1772
|
-
(exportObj.status_computation &&
|
|
1773
|
-
exportObj.status_computation !==
|
|
1774
|
-
sdk_geometry_api_sdk_v2_1.ResComputationStatus.SUCCESS)) {
|
|
1775
|
-
exportsWithIssues[exportId] = exportObj;
|
|
1776
|
-
}
|
|
1777
|
-
}
|
|
1778
|
-
if (Object.keys(outputsWithIssues).length > 0 ||
|
|
1779
|
-
Object.keys(exportsWithIssues).length > 0) {
|
|
1780
|
-
if (throwError) {
|
|
1781
|
-
throw new viewer_shared_services_1.ShapeDiverViewerCustomizationError("There was at least one output or export with issues.", { outputs: outputsWithIssues, exports: exportsWithIssues });
|
|
1782
|
-
}
|
|
1783
|
-
else {
|
|
1784
|
-
// create warning messages for outputs
|
|
1785
|
-
for (const outputId in outputsWithIssues) {
|
|
1786
|
-
let warning = "";
|
|
1787
|
-
if (outputsWithIssues[outputId].msg)
|
|
1788
|
-
warning += `\n\t- ${outputsWithIssues[outputId].msg}`;
|
|
1789
|
-
if (outputsWithIssues[outputId].status_collect &&
|
|
1790
|
-
outputsWithIssues[outputId].status_collect !==
|
|
1791
|
-
sdk_geometry_api_sdk_v2_1.ResComputationStatus.SUCCESS)
|
|
1792
|
-
warning += `\n\t- status_collect is ${outputsWithIssues[outputId].status_collect}`;
|
|
1793
|
-
if (outputsWithIssues[outputId].status_computation &&
|
|
1794
|
-
outputsWithIssues[outputId].status_computation !==
|
|
1795
|
-
sdk_geometry_api_sdk_v2_1.ResComputationStatus.SUCCESS)
|
|
1796
|
-
warning += `\n\t- status_computation is ${outputsWithIssues[outputId].status_computation}`;
|
|
1797
|
-
if (warning)
|
|
1798
|
-
this._logger.warn(`\nOutput(${outputId}):${warning}`);
|
|
1799
|
-
}
|
|
1800
|
-
// create warning messages for exports
|
|
1801
|
-
for (const exportId in exportsWithIssues) {
|
|
1802
|
-
let warning = "";
|
|
1803
|
-
if (exportsWithIssues[exportId].msg)
|
|
1804
|
-
warning += `\n\t- ${exportsWithIssues[exportId].msg}`;
|
|
1805
|
-
if (exportsWithIssues[exportId].status_collect &&
|
|
1806
|
-
exportsWithIssues[exportId].status_collect !==
|
|
1807
|
-
sdk_geometry_api_sdk_v2_1.ResComputationStatus.SUCCESS)
|
|
1808
|
-
warning += `\n\t- status_collect is ${exportsWithIssues[exportId].status_collect}`;
|
|
1809
|
-
if (exportsWithIssues[exportId].status_computation &&
|
|
1810
|
-
exportsWithIssues[exportId].status_computation !==
|
|
1811
|
-
sdk_geometry_api_sdk_v2_1.ResComputationStatus.SUCCESS)
|
|
1812
|
-
warning += `\n\t- status_computation is ${exportsWithIssues[exportId].status_computation}`;
|
|
1813
|
-
if (warning)
|
|
1814
|
-
this._logger.warn(`\nExport(${exportId}):${warning}`);
|
|
1815
|
-
}
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
addBusyMode(busyId) {
|
|
1820
|
-
for (const r in this._stateEngine.viewportEngines) {
|
|
1821
|
-
if (this._stateEngine.viewportEngines[r] &&
|
|
1822
|
-
!this.excludeViewports.includes(r)) {
|
|
1823
|
-
this._stateEngine.viewportEngines[r].busy.push(busyId);
|
|
1824
|
-
__classPrivateFieldGet(this, _SessionEngine_customizationBusyModes, "f").push(busyId);
|
|
1825
|
-
}
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
addToSceneTree(node) {
|
|
1829
|
-
this._sceneTree.addNode(node);
|
|
1830
|
-
this._sceneTree.root.updateVersion();
|
|
1831
|
-
}
|
|
1832
|
-
cancelProcess(customizationId, eventId, eventType, eventProgress, eventData, newNode = new SessionTreeNode_1.SessionTreeNode()) {
|
|
1833
|
-
if (__classPrivateFieldGet(this, _SessionEngine_customizationProcess, "f") !== customizationId) {
|
|
1834
|
-
this.removeBusyMode(customizationId);
|
|
1835
|
-
const eventCancel = {
|
|
1836
|
-
type: eventType,
|
|
1837
|
-
id: eventId,
|
|
1838
|
-
progress: eventProgress,
|
|
1839
|
-
data: eventData,
|
|
1840
|
-
status: "The request was exceeded by another customization request",
|
|
1841
|
-
};
|
|
1842
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_CANCEL, eventCancel);
|
|
1843
|
-
this._logger.debug(`Session(${this.id}).cancelProcess: The request was was exceeded by another request.`);
|
|
1844
|
-
return newNode;
|
|
1845
|
-
}
|
|
1846
|
-
else if (this._closed === true) {
|
|
1847
|
-
this.removeBusyMode(customizationId);
|
|
1848
|
-
this._logger.debug(`Session(${this.id}).cancelProcess: The session was closed during the request.`);
|
|
1849
|
-
const eventCancel = {
|
|
1850
|
-
type: viewer_shared_types_1.TASK_TYPE.SESSION_CUSTOMIZATION,
|
|
1851
|
-
id: eventId,
|
|
1852
|
-
progress: 1,
|
|
1853
|
-
data: { sessionId: this.id },
|
|
1854
|
-
status: "The session was closed during the request.",
|
|
1855
|
-
};
|
|
1856
|
-
this._eventEngine.emitEvent(viewer_shared_services_1.EVENTTYPE.TASK.TASK_CANCEL, eventCancel);
|
|
1857
|
-
return new SessionTreeNode_1.SessionTreeNode();
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
|
-
checkAvailability(action, checkForModelId = false) {
|
|
1861
|
-
var _a;
|
|
1862
|
-
if (!this._responseDto)
|
|
1863
|
-
throw new viewer_shared_services_1.ShapeDiverViewerSessionError("Session.checkAvailability: responseDto not available.");
|
|
1864
|
-
if (!this._sessionId)
|
|
1865
|
-
throw new viewer_shared_services_1.ShapeDiverViewerSessionError("Session.checkAvailability: sessionId not available.");
|
|
1866
|
-
if (checkForModelId && !this._modelId)
|
|
1867
|
-
throw new viewer_shared_services_1.ShapeDiverViewerSessionError("Session.checkAvailability: modelId not available.");
|
|
1868
|
-
if (action && !this._responseDto.actions)
|
|
1869
|
-
throw new viewer_shared_services_1.ShapeDiverViewerSessionError("Session.checkAvailability: actions not available.");
|
|
1870
|
-
const responseDtoAction = (_a = this._responseDto.actions) === null || _a === void 0 ? void 0 : _a.find((a) => a.name === action);
|
|
1871
|
-
if (action && !responseDtoAction)
|
|
1872
|
-
throw new viewer_shared_services_1.ShapeDiverViewerSessionError(`Session.checkAvailability: action ${action} not available.`);
|
|
1873
|
-
}
|
|
1874
|
-
cleanExportParameters(parameters) {
|
|
1875
|
-
const requestParameterSet = {};
|
|
1876
|
-
// first step, we convert all our names and displaynames to ids
|
|
1877
|
-
for (const parameterIdOrName in parameters) {
|
|
1878
|
-
// we prioritize id, then name and then displayname
|
|
1879
|
-
// 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)
|
|
1880
|
-
const parameterObject = Object.values(this._parameters).find((p) => p.id === parameterIdOrName ||
|
|
1881
|
-
p.name === parameterIdOrName ||
|
|
1882
|
-
p.displayname === parameterIdOrName);
|
|
1883
|
-
// in case the key of the key value pair was neither the id, name or displayname, skip
|
|
1884
|
-
if (!parameterObject)
|
|
1885
|
-
continue;
|
|
1886
|
-
// copy into new dictionary
|
|
1887
|
-
requestParameterSet[parameterObject.id] = (" " + parameterObject.stringify(parameters[parameterIdOrName])).slice(1);
|
|
1888
|
-
}
|
|
1889
|
-
// seconds step, fill all other parameter values that are currently not set
|
|
1890
|
-
const currentParameters = this.parameterValues;
|
|
1891
|
-
for (const parameterId in currentParameters) {
|
|
1892
|
-
// if already set by input values, skip
|
|
1893
|
-
if (requestParameterSet[parameterId] !== undefined)
|
|
1894
|
-
continue;
|
|
1895
|
-
// deep copy into new dictionary
|
|
1896
|
-
requestParameterSet[parameterId] = (" " + currentParameters[parameterId]).slice(1);
|
|
1897
|
-
}
|
|
1898
|
-
return requestParameterSet;
|
|
1899
|
-
}
|
|
1900
|
-
/**
|
|
1901
|
-
* Create an interaction parameter based on the parameter definition.
|
|
1902
|
-
*
|
|
1903
|
-
* @param parameter
|
|
1904
|
-
* @returns
|
|
1905
|
-
*/
|
|
1906
|
-
createInteractionParameter(parameter) {
|
|
1907
|
-
const result = (0, viewer_shared_types_1.validateInteractionParameterSettings)(parameter.settings);
|
|
1908
|
-
if (result.success) {
|
|
1909
|
-
switch (parameter.settings.type) {
|
|
1910
|
-
case "selection":
|
|
1911
|
-
return new SelectionParameter_1.SelectionParameter(parameter, this);
|
|
1912
|
-
case "gumball":
|
|
1913
|
-
return new GumballParameter_1.GumballParameter(parameter, this);
|
|
1914
|
-
case "dragging":
|
|
1915
|
-
return new DraggingParameter_1.DraggingParameter(parameter, this);
|
|
1916
|
-
}
|
|
1917
|
-
}
|
|
1918
|
-
else {
|
|
1919
|
-
this._logger.warn(`SessionEngine.createInteractionParameter: The value ${parameter.settings} is not a valid InteractionParameter: ${result.error.message}`);
|
|
1920
|
-
}
|
|
1921
|
-
return new Parameter_1.Parameter(parameter, this);
|
|
1922
|
-
}
|
|
1923
|
-
customizeInternal(cancelRequest, taskEventInfo) {
|
|
1924
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1925
|
-
return this.customizeSession(this._parameterValues, cancelRequest, taskEventInfo);
|
|
1926
|
-
});
|
|
1927
|
-
}
|
|
1928
|
-
customizeSession(parameters, cancelRequest, taskEventInfo, parallel = false, loadOutputs = true, retry = false) {
|
|
1929
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1930
|
-
this.checkAvailability("customize");
|
|
1931
|
-
try {
|
|
1932
|
-
this._performanceEvaluator.startSection("sessionResponse");
|
|
1933
|
-
const responseDto = yield new sdk_geometry_api_sdk_v2_1.UtilsApi(this._sdkConfig).submitAndWaitForOutput(this._sessionId, parameters, undefined, this._ignoreUnknownParams);
|
|
1934
|
-
this._performanceEvaluator.endSection("sessionResponse");
|
|
1935
|
-
if (loadOutputs === true && this._allowOutputLoading === true) {
|
|
1936
|
-
if (cancelRequest())
|
|
1937
|
-
return new SessionTreeNode_1.SessionTreeNode();
|
|
1938
|
-
if (parallel === true) {
|
|
1939
|
-
// special case, we load the outputs put don't add them to the scene
|
|
1940
|
-
return this.loadOutputsParallel(responseDto, cancelRequest, taskEventInfo);
|
|
1941
|
-
}
|
|
1942
|
-
else {
|
|
1943
|
-
// default case, we load the outputs and return the nodes
|
|
1944
|
-
this.updateResponseDto(responseDto);
|
|
1945
|
-
return this.loadOutputs(cancelRequest, taskEventInfo);
|
|
1946
|
-
}
|
|
1947
|
-
}
|
|
1948
|
-
else {
|
|
1949
|
-
// special case, we don't load the outputs and only return the responseDto
|
|
1950
|
-
const node = new SessionTreeNode_1.SessionTreeNode();
|
|
1951
|
-
node.data.push(new SessionData_1.SessionData(responseDto));
|
|
1952
|
-
return node;
|
|
1953
|
-
}
|
|
1954
|
-
}
|
|
1955
|
-
catch (e) {
|
|
1956
|
-
yield this.handleError(e, retry);
|
|
1957
|
-
if (cancelRequest())
|
|
1958
|
-
return new SessionTreeNode_1.SessionTreeNode();
|
|
1959
|
-
return yield this.customizeSession(parameters, cancelRequest, taskEventInfo, parallel, loadOutputs, true);
|
|
1960
|
-
}
|
|
1961
|
-
});
|
|
1962
|
-
}
|
|
1963
|
-
/**
|
|
1964
|
-
* Get all file parameters from the parameter set.
|
|
1965
|
-
* If the parameter is not set in the parameter set, the value from the parameter object is used.
|
|
1966
|
-
*
|
|
1967
|
-
* @param parameters
|
|
1968
|
-
* @returns
|
|
1969
|
-
*/
|
|
1970
|
-
getFileParameterSet(parameters) {
|
|
1971
|
-
const fileParameterSet = {};
|
|
1972
|
-
for (const parameterId in this.parameters) {
|
|
1973
|
-
if (this.parameters[parameterId] instanceof FileParameter_1.FileParameter) {
|
|
1974
|
-
fileParameterSet[parameterId] =
|
|
1975
|
-
parameters[parameterId] !== undefined
|
|
1976
|
-
? parameters[parameterId]
|
|
1977
|
-
: this.parameters[parameterId].value;
|
|
1978
|
-
}
|
|
1979
|
-
}
|
|
1980
|
-
return fileParameterSet;
|
|
1981
|
-
}
|
|
1982
|
-
handleError(err, retry = false) {
|
|
1983
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1984
|
-
if (!(err instanceof Error))
|
|
1985
|
-
throw this._httpClient.convertError(err);
|
|
1986
|
-
// Process the error
|
|
1987
|
-
const e = (0, sdk_geometry_api_sdk_v2_1.processError)(err);
|
|
1988
|
-
if (e instanceof sdk_geometry_api_sdk_v2_1.ResponseError) {
|
|
1989
|
-
if (e.type === sdk_geometry_api_sdk_v2_1.ResErrorType.SESSION_GONE_ERROR) {
|
|
1990
|
-
// case 1: the session is no longer available
|
|
1991
|
-
// we try to re-initialize the session 3 times, if that does not work, we close it
|
|
1992
|
-
this._logger.warn("The session has been closed, trying to re-initialize.");
|
|
1993
|
-
if (this._sessionId)
|
|
1994
|
-
this._httpClient.removeDataLoading(this._sessionId);
|
|
1995
|
-
if (this._retryCounter < 3) {
|
|
1996
|
-
// we retry this 3 times, the `retry` option in the init function is set to true and passed on
|
|
1997
|
-
this._retryCounter = retry ? this._retryCounter + 1 : 1;
|
|
1998
|
-
this._initialized = false;
|
|
1999
|
-
yield this.init(this.parameterValues, true);
|
|
2000
|
-
}
|
|
2001
|
-
else {
|
|
2002
|
-
// the retries were exceeded, we close the session
|
|
2003
|
-
this._logger.warn("Tried to retry the connect multiple times, bearer token still not valid. Closing Session.");
|
|
2004
|
-
// eslint-disable-next-line no-empty
|
|
2005
|
-
try {
|
|
2006
|
-
yield this._closeOnFailure();
|
|
2007
|
-
}
|
|
2008
|
-
catch (e) {
|
|
2009
|
-
/* empty */
|
|
2010
|
-
}
|
|
2011
|
-
throw this._httpClient.convertError(e);
|
|
2012
|
-
}
|
|
2013
|
-
}
|
|
2014
|
-
else if (e.type === sdk_geometry_api_sdk_v2_1.ResErrorType.JWT_VALIDATION_ERROR) {
|
|
2015
|
-
// if any of the above errors occur, we try to get a new bearer token
|
|
2016
|
-
// if we get a new one, we retry 3 times (by requiring new bearer tokens every time)
|
|
2017
|
-
if (this._retryCounter < 3) {
|
|
2018
|
-
if (this._refreshJwtToken) {
|
|
2019
|
-
yield this.setJwtToken(yield this._refreshJwtToken());
|
|
2020
|
-
this._retryCounter = retry ? this._retryCounter + 1 : 1;
|
|
2021
|
-
this._logger.warn("Re-trying with new bearer token.");
|
|
2022
|
-
}
|
|
2023
|
-
else {
|
|
2024
|
-
// no bearer tokens are supplied, we close the session
|
|
2025
|
-
this._logger.warn("No retry possible, no new bearer token was supplied. Closing Session.");
|
|
2026
|
-
// eslint-disable-next-line no-empty
|
|
2027
|
-
try {
|
|
2028
|
-
yield this._closeOnFailure();
|
|
2029
|
-
}
|
|
2030
|
-
catch (e) {
|
|
2031
|
-
/* empty */
|
|
2032
|
-
}
|
|
2033
|
-
throw this._httpClient.convertError(e);
|
|
2034
|
-
}
|
|
2035
|
-
}
|
|
2036
|
-
else {
|
|
2037
|
-
// the retries were exceeded, we close the session
|
|
2038
|
-
this._logger.warn("Tried to retry the connect multiple times, bearer token still not valid. Closing Session.");
|
|
2039
|
-
// eslint-disable-next-line no-empty
|
|
2040
|
-
try {
|
|
2041
|
-
yield this._closeOnFailure();
|
|
2042
|
-
}
|
|
2043
|
-
catch (e) {
|
|
2044
|
-
/* empty */
|
|
2045
|
-
}
|
|
2046
|
-
throw this._httpClient.convertError(e);
|
|
2047
|
-
}
|
|
2048
|
-
}
|
|
2049
|
-
else {
|
|
2050
|
-
throw this._httpClient.convertError(e);
|
|
2051
|
-
}
|
|
2052
|
-
}
|
|
2053
|
-
else {
|
|
2054
|
-
throw this._httpClient.convertError(e);
|
|
2055
|
-
}
|
|
2056
|
-
});
|
|
2057
|
-
}
|
|
2058
|
-
/**
|
|
2059
|
-
* Process the image input and return the image data and array buffer.
|
|
2060
|
-
*
|
|
2061
|
-
* In the case of the image being a Blob or File, the image data is constructed from the Blob or File.
|
|
2062
|
-
* In the case of the image being a string, we check if it is a data URL or a URL.
|
|
2063
|
-
* If it is a data URL, we convert it to a Blob and construct the image data from the Blob.
|
|
2064
|
-
* If it is a URL, we download the image and return the image data and array buffer.
|
|
2065
|
-
*
|
|
2066
|
-
* @param image
|
|
2067
|
-
* @returns
|
|
2068
|
-
*/
|
|
2069
|
-
processImageInput(image) {
|
|
2070
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2071
|
-
if (image instanceof File || image instanceof Blob)
|
|
2072
|
-
return this._converter.constructImageData(image);
|
|
2073
|
-
let imageString;
|
|
2074
|
-
if (image instanceof Promise) {
|
|
2075
|
-
imageString = yield image;
|
|
2076
|
-
}
|
|
2077
|
-
else if (typeof image === "function") {
|
|
2078
|
-
const result = image();
|
|
2079
|
-
if (result instanceof Promise) {
|
|
2080
|
-
imageString = yield result;
|
|
2081
|
-
}
|
|
2082
|
-
else {
|
|
2083
|
-
imageString = result;
|
|
2084
|
-
}
|
|
2085
|
-
}
|
|
2086
|
-
else {
|
|
2087
|
-
imageString = image;
|
|
2088
|
-
}
|
|
2089
|
-
if (imageString.startsWith("data:")) {
|
|
2090
|
-
// case where the image is a data URL
|
|
2091
|
-
const { blob, arrayBuffer } = this._converter.dataURLtoBlob(imageString);
|
|
2092
|
-
return {
|
|
2093
|
-
imageData: {
|
|
2094
|
-
format: blob.type,
|
|
2095
|
-
size: blob.size,
|
|
2096
|
-
},
|
|
2097
|
-
arrayBuffer: arrayBuffer,
|
|
2098
|
-
};
|
|
2099
|
-
}
|
|
2100
|
-
else {
|
|
2101
|
-
// case where the image is a URL
|
|
2102
|
-
const response = yield new sdk_geometry_api_sdk_v2_1.UtilsApi(this._sdkConfig).downloadImage(this._sessionId, imageString, {
|
|
2103
|
-
responseType: "arraybuffer",
|
|
2104
|
-
});
|
|
2105
|
-
const arrayBuffer = response.data;
|
|
2106
|
-
return {
|
|
2107
|
-
imageData: {
|
|
2108
|
-
format: response.headers["content-type"],
|
|
2109
|
-
size: arrayBuffer.byteLength,
|
|
2110
|
-
},
|
|
2111
|
-
arrayBuffer,
|
|
2112
|
-
};
|
|
2113
|
-
}
|
|
2114
|
-
});
|
|
2115
|
-
}
|
|
2116
|
-
removeBusyMode(busyId) {
|
|
2117
|
-
for (const r in this._stateEngine.viewportEngines) {
|
|
2118
|
-
if (this._stateEngine.viewportEngines[r] &&
|
|
2119
|
-
this._stateEngine.viewportEngines[r].busy.includes(busyId))
|
|
2120
|
-
this._stateEngine.viewportEngines[r].busy.splice(this._stateEngine.viewportEngines[r].busy.indexOf(busyId), 1);
|
|
2121
|
-
if (__classPrivateFieldGet(this, _SessionEngine_customizationBusyModes, "f").includes(busyId))
|
|
2122
|
-
__classPrivateFieldGet(this, _SessionEngine_customizationBusyModes, "f").splice(__classPrivateFieldGet(this, _SessionEngine_customizationBusyModes, "f").indexOf(busyId), 1);
|
|
2123
|
-
}
|
|
2124
|
-
}
|
|
2125
|
-
removeFromSceneTree(node) {
|
|
2126
|
-
this._sceneTree.removeNode(node);
|
|
2127
|
-
this._sceneTree.root.updateVersion();
|
|
2128
|
-
}
|
|
2129
|
-
/**
|
|
2130
|
-
* Returns a promise that resolves after the amount of milliseconds provided.
|
|
2131
|
-
*
|
|
2132
|
-
* @param ms the milliseconds
|
|
2133
|
-
* @returns promise that resolve after specified milliseconds
|
|
2134
|
-
*/
|
|
2135
|
-
timeout(ms) {
|
|
2136
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2137
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2138
|
-
});
|
|
2139
|
-
}
|
|
2140
|
-
updateResponseDto(responseDto, initialParameters) {
|
|
2141
|
-
if (!this._responseDto) {
|
|
2142
|
-
this._responseDto = responseDto;
|
|
2143
|
-
return;
|
|
2144
|
-
}
|
|
2145
|
-
// convert parameters
|
|
2146
|
-
if (responseDto.parameters) {
|
|
2147
|
-
for (const parameterId in responseDto.parameters) {
|
|
2148
|
-
this._responseDto.parameters =
|
|
2149
|
-
this._responseDto.parameters || {};
|
|
2150
|
-
this._responseDto.parameters[parameterId] =
|
|
2151
|
-
this._responseDto.parameters[parameterId] ||
|
|
2152
|
-
responseDto.parameters[parameterId];
|
|
2153
|
-
}
|
|
2154
|
-
}
|
|
2155
|
-
// convert outputs
|
|
2156
|
-
if (responseDto.outputs) {
|
|
2157
|
-
for (const outputId in responseDto.outputs) {
|
|
2158
|
-
this._responseDto.outputs = this._responseDto.outputs || {};
|
|
2159
|
-
if ("version" in responseDto.outputs[outputId] ||
|
|
2160
|
-
!(this._responseDto.outputs[outputId] &&
|
|
2161
|
-
"version" in this._responseDto.outputs[outputId]))
|
|
2162
|
-
this._responseDto.outputs[outputId] =
|
|
2163
|
-
responseDto.outputs[outputId];
|
|
2164
|
-
}
|
|
2165
|
-
}
|
|
2166
|
-
// convert exports
|
|
2167
|
-
if (responseDto.exports) {
|
|
2168
|
-
for (const exportId in responseDto.exports) {
|
|
2169
|
-
this._responseDto.exports = this._responseDto.exports || {};
|
|
2170
|
-
if ("version" in responseDto.exports[exportId] ||
|
|
2171
|
-
!(this._responseDto.exports[exportId] &&
|
|
2172
|
-
"version" in this._responseDto.exports[exportId]))
|
|
2173
|
-
this._responseDto.exports[exportId] =
|
|
2174
|
-
responseDto.exports[exportId];
|
|
2175
|
-
}
|
|
2176
|
-
}
|
|
2177
|
-
const parameterSet = {};
|
|
2178
|
-
for (const parameterId in this._responseDto.parameters) {
|
|
2179
|
-
if (this.parameters[parameterId])
|
|
2180
|
-
continue;
|
|
2181
|
-
this._responseDto.parameters[parameterId].id = parameterId;
|
|
2182
|
-
switch (true) {
|
|
2183
|
-
case this._responseDto.parameters[parameterId].type ===
|
|
2184
|
-
viewer_shared_types_1.PARAMETER_TYPE.BOOL:
|
|
2185
|
-
this.parameters[parameterId] = new Parameter_1.Parameter(this._responseDto.parameters[parameterId], this);
|
|
2186
|
-
break;
|
|
2187
|
-
case this._responseDto.parameters[parameterId].type ===
|
|
2188
|
-
viewer_shared_types_1.PARAMETER_TYPE.COLOR:
|
|
2189
|
-
this.parameters[parameterId] = new Parameter_1.Parameter(this._responseDto.parameters[parameterId], this);
|
|
2190
|
-
break;
|
|
2191
|
-
case this._responseDto.parameters[parameterId].type ===
|
|
2192
|
-
viewer_shared_types_1.PARAMETER_TYPE.FILE:
|
|
2193
|
-
this.parameters[parameterId] = new FileParameter_1.FileParameter(this._responseDto.parameters[parameterId], this);
|
|
2194
|
-
break;
|
|
2195
|
-
case this._responseDto.parameters[parameterId].type ===
|
|
2196
|
-
viewer_shared_types_1.PARAMETER_TYPE.EVEN ||
|
|
2197
|
-
this._responseDto.parameters[parameterId].type ===
|
|
2198
|
-
viewer_shared_types_1.PARAMETER_TYPE.FLOAT ||
|
|
2199
|
-
this._responseDto.parameters[parameterId].type ===
|
|
2200
|
-
viewer_shared_types_1.PARAMETER_TYPE.INT ||
|
|
2201
|
-
this._responseDto.parameters[parameterId].type ===
|
|
2202
|
-
viewer_shared_types_1.PARAMETER_TYPE.ODD:
|
|
2203
|
-
this.parameters[parameterId] = new Parameter_1.Parameter(this._responseDto.parameters[parameterId], this);
|
|
2204
|
-
break;
|
|
2205
|
-
case this._responseDto.parameters[parameterId].type ===
|
|
2206
|
-
viewer_shared_types_1.PARAMETER_TYPE.INTERACTION:
|
|
2207
|
-
this.parameters[parameterId] =
|
|
2208
|
-
this.createInteractionParameter(this._responseDto.parameters[parameterId]);
|
|
2209
|
-
break;
|
|
2210
|
-
case this._responseDto.parameters[parameterId].type ===
|
|
2211
|
-
viewer_shared_types_1.PARAMETER_TYPE.DRAWING:
|
|
2212
|
-
this.parameters[parameterId] = new DrawingParameter_1.DrawingParameter(this._responseDto.parameters[parameterId], this);
|
|
2213
|
-
break;
|
|
2214
|
-
default:
|
|
2215
|
-
this.parameters[parameterId] = new Parameter_1.Parameter(this._responseDto.parameters[parameterId], this);
|
|
2216
|
-
break;
|
|
2217
|
-
}
|
|
2218
|
-
// 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
|
|
2219
|
-
if (initialParameters) {
|
|
2220
|
-
let hasInitialValue = false;
|
|
2221
|
-
// check if the id is within the initial parameters
|
|
2222
|
-
if (initialParameters[parameterId] !== undefined) {
|
|
2223
|
-
this.parameters[parameterId].value =
|
|
2224
|
-
initialParameters[parameterId];
|
|
2225
|
-
hasInitialValue = true;
|
|
2226
|
-
}
|
|
2227
|
-
// check if the name is within the initial parameters
|
|
2228
|
-
else if (initialParameters[this.parameters[parameterId].name] !==
|
|
2229
|
-
undefined) {
|
|
2230
|
-
this.parameters[parameterId].value =
|
|
2231
|
-
initialParameters[this.parameters[parameterId].name];
|
|
2232
|
-
hasInitialValue = true;
|
|
2233
|
-
}
|
|
2234
|
-
// check if the displayname is within the initial parameters
|
|
2235
|
-
else if (this.parameters[parameterId].displayname &&
|
|
2236
|
-
initialParameters[this.parameters[parameterId].displayname] !== undefined) {
|
|
2237
|
-
this.parameters[parameterId].value =
|
|
2238
|
-
initialParameters[this.parameters[parameterId].displayname];
|
|
2239
|
-
hasInitialValue = true;
|
|
2240
|
-
}
|
|
2241
|
-
// if there is an initial value, we try to cast it to the correct type
|
|
2242
|
-
// we only do this for bool and number types, as the other types are either string or have their own parsing
|
|
2243
|
-
if (hasInitialValue) {
|
|
2244
|
-
if (this.parameters[parameterId].type ===
|
|
2245
|
-
viewer_shared_types_1.PARAMETER_TYPE.BOOL) {
|
|
2246
|
-
// cast to boolean
|
|
2247
|
-
this.parameters[parameterId].value = Boolean(this.parameters[parameterId].value);
|
|
2248
|
-
}
|
|
2249
|
-
else if (this.parameters[parameterId].type ===
|
|
2250
|
-
viewer_shared_types_1.PARAMETER_TYPE.INT ||
|
|
2251
|
-
this.parameters[parameterId].type ===
|
|
2252
|
-
viewer_shared_types_1.PARAMETER_TYPE.FLOAT ||
|
|
2253
|
-
this.parameters[parameterId].type ===
|
|
2254
|
-
viewer_shared_types_1.PARAMETER_TYPE.EVEN ||
|
|
2255
|
-
this.parameters[parameterId].type === viewer_shared_types_1.PARAMETER_TYPE.ODD) {
|
|
2256
|
-
// cast to number
|
|
2257
|
-
this.parameters[parameterId].value = Number(this.parameters[parameterId].value);
|
|
2258
|
-
}
|
|
2259
|
-
}
|
|
2260
|
-
}
|
|
2261
|
-
parameterSet[parameterId] = {
|
|
2262
|
-
value: this.parameters[parameterId].value,
|
|
2263
|
-
valueString: this.parameters[parameterId].stringify(),
|
|
2264
|
-
};
|
|
2265
|
-
if (!this.initialized)
|
|
2266
|
-
this.parameterValues[parameterId] =
|
|
2267
|
-
parameterSet[parameterId].valueString;
|
|
2268
|
-
}
|
|
2269
|
-
// store the initialization as the first parameter set in the history
|
|
2270
|
-
if (!this.initialized)
|
|
2271
|
-
__classPrivateFieldGet(this, _SessionEngine_parameterHistory, "f").push(parameterSet);
|
|
2272
|
-
for (const exportId in this._responseDto.exports) {
|
|
2273
|
-
if (this._responseDto.exports[exportId].type ===
|
|
2274
|
-
sdk_geometry_api_sdk_v2_1.ResExportDefinitionType.EMAIL ||
|
|
2275
|
-
this._responseDto.exports[exportId].type ===
|
|
2276
|
-
sdk_geometry_api_sdk_v2_1.ResExportDefinitionType.DOWNLOAD) {
|
|
2277
|
-
if (!this.exports[exportId]) {
|
|
2278
|
-
this._responseDto.exports[exportId].id = exportId;
|
|
2279
|
-
this.exports[exportId] = new Export_1.Export(this._responseDto.exports[exportId], this);
|
|
2280
|
-
}
|
|
2281
|
-
else {
|
|
2282
|
-
this.exports[exportId].updateExport(this._responseDto.exports[exportId]);
|
|
2283
|
-
}
|
|
2284
|
-
}
|
|
2285
|
-
}
|
|
2286
|
-
for (const outputId in this._responseDto.outputs) {
|
|
2287
|
-
if (!this.outputs[outputId]) {
|
|
2288
|
-
this._responseDto.outputs[outputId].id = outputId;
|
|
2289
|
-
if (this.outputsFreeze[outputId] === undefined)
|
|
2290
|
-
this.outputsFreeze[outputId] = false;
|
|
2291
|
-
this.outputs[outputId] = new Output_1.Output(this._responseDto.outputs[outputId], this);
|
|
2292
|
-
}
|
|
2293
|
-
else {
|
|
2294
|
-
this.outputs[outputId].updateOutputDefinition(this._responseDto.outputs[outputId]);
|
|
2295
|
-
}
|
|
2296
|
-
}
|
|
2297
|
-
}
|
|
2298
|
-
waitForUpdateCallbacks(newOutputVersions, oldOutputVersions, newNode, oldNode) {
|
|
2299
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
2300
|
-
// call the update callback function on the session
|
|
2301
|
-
if (this._updateCallback)
|
|
2302
|
-
yield Promise.resolve(this._updateCallback(newNode, oldNode));
|
|
2303
|
-
const promises = [];
|
|
2304
|
-
// call the update callback functions on the outputs
|
|
2305
|
-
for (const outputId in this.outputs) {
|
|
2306
|
-
if (oldOutputVersions[outputId] !== newOutputVersions[outputId]) {
|
|
2307
|
-
promises.push(this.outputs[outputId].triggerUpdateCallback(newNode.children.find((c) => c.name === outputId), oldNode.children.find((c) => c.name === outputId)));
|
|
2308
|
-
}
|
|
2309
|
-
}
|
|
2310
|
-
yield Promise.all(promises);
|
|
2311
|
-
});
|
|
2312
|
-
}
|
|
2313
|
-
}
|
|
2314
|
-
exports.SessionEngine = SessionEngine;
|
|
2315
|
-
_SessionEngine_customizationBusyModes = new WeakMap(), _SessionEngine_customizationProcess = new WeakMap(), _SessionEngine_parameterHistory = new WeakMap(), _SessionEngine_parameterHistoryCall = new WeakMap(), _SessionEngine_parameterHistoryForward = new WeakMap();
|
|
2316
|
-
//# sourceMappingURL=SessionEngine.js.map
|