From 0b308b7e4bb620052e6493b7d5b22673436a0dbe Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 3 Dec 2019 12:18:23 +0100 Subject: [PATCH] Partial Implementation of getting plotters definition from UI --- .../FunctionLibraries/ProtocolNode.js | 1 + .../FunctionLibraries/UiObjectsFromNodes.js | 2 + FloatingSpace/UiObjectConstructor.js | 164 +++++++++++------- Panels/ProductsPanel.js | 87 ++++++++++ 4 files changed, 191 insertions(+), 63 deletions(-) diff --git a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js index f771ddd94..3ed3c191b 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js +++ b/DesignerSpace/Workspace/FunctionLibraries/ProtocolNode.js @@ -1593,6 +1593,7 @@ function newProtocolNode () { type: node.type, subType: node.subType, name: node.name, + code: node.code, modules: [] } if (node.modules !== undefined) { diff --git a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js index 5ead376f1..3552d6552 100644 --- a/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js +++ b/DesignerSpace/Workspace/FunctionLibraries/UiObjectsFromNodes.js @@ -1382,6 +1382,7 @@ function newUiObjectsFromNodes () { let object = { type: 'Plotter', name: 'New Plotter', + code: '{}', modules: [] } if (node.plotters === undefined) { @@ -1397,6 +1398,7 @@ function newUiObjectsFromNodes () { let object = { type: 'Plotter Module', name: 'New Plotter Module', + code: '{}', panels: [] } if (node.modules === undefined) { diff --git a/FloatingSpace/UiObjectConstructor.js b/FloatingSpace/UiObjectConstructor.js index 80e74b7ed..8d96c837a 100644 --- a/FloatingSpace/UiObjectConstructor.js +++ b/FloatingSpace/UiObjectConstructor.js @@ -1539,7 +1539,26 @@ function newUiObjectConstructor () { break } case 'Plotter': { + uiObject.codeEditor = newCodeEditor() + uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.codeEditor.initialize() + uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) addLeftIcons(menuItemsInitialValues, floatingObject) + menuItemsInitialValues.push( + { + action: 'Edit Plotter', + actionFunction: uiObject.codeEditor.activate, + label: 'Edit Plotter', + visible: true, + iconPathOn: 'html', + iconPathOff: 'html', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: -30, + dontShowAtFullscreen: true + } + ) menuItemsInitialValues.push( { action: 'Add Plotter Module', @@ -1550,7 +1569,7 @@ function newUiObjectConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: -20 + angle: -10 } ) menuItemsInitialValues.push( @@ -1566,68 +1585,6 @@ function newUiObjectConstructor () { rawRadius: 8, targetRadius: 0, currentRadius: 0, - angle: 0 - } - ) - menuItemsInitialValues.push( - { - action: 'Share', - actionFunction: payload.onMenuItemClick, - label: 'Share', - visible: true, - iconPathOn: 'menu-share', - iconPathOff: 'menu-share', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: 20 - } - ) - break - } - case 'Plotter Module': { - addLeftIcons(menuItemsInitialValues, floatingObject) - menuItemsInitialValues.push( - { - action: 'Add Code', - disableIfPropertyIsDefined: true, - propertyToCheckFor: 'code', - actionFunction: payload.onMenuItemClick, - label: 'Add Code', - visible: true, - relatedUiObject: 'Code', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: -30 - } - ) - menuItemsInitialValues.push( - { - action: 'Add Plotter Panel', - actionFunction: payload.onMenuItemClick, - label: 'Add Plotter Panel', - visible: true, - relatedUiObject: 'Plotter Panel', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, - angle: -10 - } - ) - menuItemsInitialValues.push( - { - action: 'Delete Plotter Module', - askConfirmation: true, - confirmationLabel: 'Confirm to Delete', - actionFunction: payload.onMenuItemClick, - label: 'Delete Plotter Module', - visible: true, - iconPathOn: 'delete', - iconPathOff: 'delete', - rawRadius: 8, - targetRadius: 0, - currentRadius: 0, angle: 10 } ) @@ -1647,6 +1604,87 @@ function newUiObjectConstructor () { ) break } + case 'Plotter Module': { + uiObject.codeEditor = newCodeEditor() + uiObject.codeEditor.isVisibleFunction = uiObject.isVisibleFunction + uiObject.codeEditor.initialize() + uiObject.codeEditor.container.connectToParent(uiObject.container, false, false, true, true, false, false, false, false) + addLeftIcons(menuItemsInitialValues, floatingObject) + menuItemsInitialValues.push( + { + action: 'Edit Plotter Module', + actionFunction: uiObject.codeEditor.activate, + label: 'Edit Plotter Module', + visible: true, + iconPathOn: 'html', + iconPathOff: 'html', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: -40, + dontShowAtFullscreen: true + } + ) + menuItemsInitialValues.push( + { + action: 'Add Code', + disableIfPropertyIsDefined: true, + propertyToCheckFor: 'code', + actionFunction: payload.onMenuItemClick, + label: 'Add Code', + visible: true, + relatedUiObject: 'Code', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: -20 + } + ) + menuItemsInitialValues.push( + { + action: 'Add Plotter Panel', + actionFunction: payload.onMenuItemClick, + label: 'Add Plotter Panel', + visible: true, + relatedUiObject: 'Plotter Panel', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 0 + } + ) + menuItemsInitialValues.push( + { + action: 'Delete Plotter Module', + askConfirmation: true, + confirmationLabel: 'Confirm to Delete', + actionFunction: payload.onMenuItemClick, + label: 'Delete Plotter Module', + visible: true, + iconPathOn: 'delete', + iconPathOff: 'delete', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 20 + } + ) + menuItemsInitialValues.push( + { + action: 'Share', + actionFunction: payload.onMenuItemClick, + label: 'Share', + visible: true, + iconPathOn: 'menu-share', + iconPathOff: 'menu-share', + rawRadius: 8, + targetRadius: 0, + currentRadius: 0, + angle: 40 + } + ) + break + } case 'Plotter Panel': { addLeftIcons(menuItemsInitialValues, floatingObject) menuItemsInitialValues.push( diff --git a/Panels/ProductsPanel.js b/Panels/ProductsPanel.js index a8a0339d8..c5a150fae 100644 --- a/Panels/ProductsPanel.js +++ b/Panels/ProductsPanel.js @@ -66,6 +66,7 @@ function newProductsPanel () { ecosystem = getUserEcosystem() } + /* For legacy plotters, we will add product cards based on the old ecosystem file */ for (let i = 0; i < ecosystem.devTeams.length; i++) { let devTeam = ecosystem.devTeams[i] @@ -83,6 +84,92 @@ function newProductsPanel () { } } + /* For new plotters defined at the UI, we will add product cards based on what we find at the workspace */ + let workspaceNode = canvas.designerSpace.workspace.workspaceNode + for (let i = 0; i < workspaceNode.rootNodes.length; i++) { + let rootNode = workspaceNode.rootNodes[i] + if (rootNode.type === 'Team') { + let teamNode = rootNode + + let team = {} + if (teamNode.code === undefined) { continue } + try { + let code = JSON.parse(teamNode.code) + team.codeName = code.codeName + } catch (err) { + continue + } + for (let j = 0; j < teamNode.indicatorBots.length; j++) { + let botNode = teamNode.indicatorBots[j] + + let bot = {} + if (botNode.code === undefined) { continue } + try { + let code = JSON.parse(botNode.code) + bot.codeName = code.codeName + } catch (err) { + continue + } + + for (let k = 0; k < botNode.products; k++) { + let productNode = botNode.products[k] + + let product = {} + if (productNode.code === undefined) { continue } + try { + let code = JSON.parse(productNode.code) + product.codeName = code.codeName + } catch (err) { + continue + } + + if (productNode.referenceParent === undefined) { continue } + let plotterModuleNode = productNode.referenceParent + + let plotterModule = {} + if (plotterModuleNode.code === undefined) { continue } + try { + let code = JSON.parse(plotterModuleNode.code) + plotterModule.codeName = code.codeName + } catch (err) { + continue + } + + if (plotterModuleNode.payload.parentNode === undefined) { continue } + let plotterNode = plotterModuleNode.payload.parentNode + + let plotter = {} + if (plotterNode.code === undefined) { continue } + try { + let code = JSON.parse(plotterNode.code) + plotter.codeName = code.codeName + } catch (err) { + continue + } + + if (plotterNode.payload.parentNode === undefined) { continue } + let plotterTeamNode = plotterNode.payload.parentNode + + let plotterTeam = {} + if (plotterTeamNode.code === undefined) { continue } + try { + let code = JSON.parse(plotterTeamNode.code) + plotterTeam.codeName = code.codeName + } catch (err) { + continue + } + + /* Conversion to fit old format */ + prduct.plotter = plotter + prduct.plotter.devTeam = plotterTeam.codeName + product.plotter.moduleName = plotterModule.codeName + + addProductCard(team, bot, product) + } + } + } + } + thisObject.container.eventHandler.listenToEvent('onMouseWheel', onMouseWheel) isInitialized = true }