From 4a0c5e6d55ad437fd6dbd6ce92ef6c7ca0f30099 Mon Sep 17 00:00:00 2001 From: Dario Del Piano Date: Mon, 7 Oct 2019 16:54:13 +0100 Subject: [PATCH] id= if non visual instances are passed in the url --- components/VFBMain.js | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/components/VFBMain.js b/components/VFBMain.js index 4a09a2bf5..1414b8b3a 100644 --- a/components/VFBMain.js +++ b/components/VFBMain.js @@ -233,11 +233,15 @@ export default class VFBMain extends React.Component { continue; } if (this.hasVisualType(variableIds[singleId])) { - var instance = Instances.getInstance(variableIds[singleId]); - this.resolve3D(variableIds[singleId], function () { + this.resolve3D(variableIds[singleId], function (id) { + var instance = Instances.getInstance(id); GEPPETTO.SceneController.deselectAll(); if ((instance != undefined) && (typeof instance.select === "function")) { - instance.select(); + if (this.idsFromURL.length > 0 && window.templateID !== undefined && Instances[window.templateID]) { + this.handlerInstanceUpdate(instance); + } else { + instance.select(); + } } }.bind(this)); } else { @@ -390,7 +394,7 @@ export default class VFBMain extends React.Component { var postResolve = () => { this.setSepCol(path); if (callback != undefined) { - callback(); + callback(path); } }; @@ -863,8 +867,8 @@ export default class VFBMain extends React.Component { }.bind(this); window.resolve3D = function (externalID) { - this.resolve3D(externalID, function () { - var instance = Instances.getInstance(externalID); + this.resolve3D(externalID, function (id) { + var instance = Instances.getInstance(id); if ((instance != undefined) && (typeof instance.select === "function")) { GEPPETTO.SceneController.deselectAll(); instance.select(); @@ -949,20 +953,6 @@ export default class VFBMain extends React.Component { console.log("Loading IDS to add to the scene from url"); GEPPETTO.on(GEPPETTO.Events.Model_loaded, function () { that.addVfbId(that.idsFromURL); - /* - * var loadOnDelay = new Promise(function (resolve, reject) { - * that.addVfbId(that.idsFromURL); - * while (Instances[that.idFromURL] === undefined && window.templateID === undefined) { - * setTimeout(null, 500); - * } - * resolve(true); - * }); - * loadOnDelay.then(function (reason) { - * if (reason) { - * that.handlerInstanceUpdate(Instances[that.idFromURL]); - * } - * }); - */ }); } } @@ -1046,6 +1036,7 @@ export default class VFBMain extends React.Component { }); } + // Handler created to manage all the update that relates to components of the UI handlerInstanceUpdate (instance) { let metaInstance = undefined; let parentInstance = undefined; @@ -1056,6 +1047,7 @@ export default class VFBMain extends React.Component { return; } + // Logic to determine the parent and the meta instance, used to get all the data needed if (instance.getId().indexOf("_meta") === -1 && instance.getParent() === null) { parentInstance = instance; metaInstance = parentInstance[parentInstance.getId() + "_meta"]; @@ -1067,6 +1059,17 @@ export default class VFBMain extends React.Component { this.instanceOnFocus = metaInstance; this.idOnFocus = parentInstance.getId(); + /* + * this is the core of the logic id= that we use on startup of the application from the URL. + * All the ids in the url in i= and id= are placed in the idsFromURL array, where the only id in + * id= is placed in idFromURL. In this portion of code we loop through this list, if the id on focus + * at the moment is in the list but is different from the id= that should take over term info and + * tree browser we simply remove this id from the array and return, instead if the id on focus is the + * the same that we stored in idFromURL in that case we remove this id from the array, break the loop + * and go forward to place all this information. + * Keep in mind this loop is executed only once, on startup, since the array is emptied and never + * filled again, for that reason DO NOT REUSE idsFromURL differently this logic will be broken. + */ for (var counter = 0; counter < this.idsFromURL.length; counter++) { if (this.idsFromURL[counter] === this.idOnFocus && this.idFromURL !== this.idOnFocus) { this.idsFromURL.splice(counter, 1);