From 9c1d79ec7d6e4cb35bf7bb0fb9c07e20a29a30ce Mon Sep 17 00:00:00 2001 From: Brenden Harrell Date: Tue, 27 Jul 2021 17:45:02 -0500 Subject: [PATCH] More work on Auto Reference --- .../UI/Function-Libraries/ProtocolNode.js | 11 ++-- .../ReferenceAttachDetach.js | 2 +- .../Function-Libraries/UiObjectsFromNodes.js | 51 +++++++++++++++++-- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/Projects/Foundations/UI/Function-Libraries/ProtocolNode.js b/Projects/Foundations/UI/Function-Libraries/ProtocolNode.js index 3ce61e541..1dda672ed 100644 --- a/Projects/Foundations/UI/Function-Libraries/ProtocolNode.js +++ b/Projects/Foundations/UI/Function-Libraries/ProtocolNode.js @@ -263,21 +263,24 @@ function newFoundationsFunctionLibraryProtocolNode() { if (node.payload.referenceParentCombinedNodePath === undefined) { let attachNodePath = UI.projects.foundations.utilities.hierarchy.getNodeNameTypePath(node.payload.referenceParent) // Save path to reference parent for auto restore - savedPayload.referenceParentCombinedNodePath = { path: attachNodePath } + // savedPayload.referenceParentCombinedNodePath = { path: attachNodePath } + //console.log("this is the saved payload new save", savedPayload) } else { // Save path to reference parent for auto restore - savedPayload.referenceParentCombinedNodePath = { path: node.payload.referenceParentCombinedNodePath } + savedPayload.referenceParentCombinedNodePath = node.payload.referenceParentCombinedNodePath + console.log("this is the saved payload old save", savedPayload) } } else { /* The referenceParent property can be inherited from the previous saved payload. */ if (node.savedPayload !== undefined) { savedPayload.referenceParent = node.savedPayload.referenceParent // Save path to reference parent for auto restore - savedPayload.referenceParentCombinedNodePath = node.payload.referenceParentCombinedNodePath + savedPayload.referenceParentCombinedNodePath = node.savedPayload.referenceParentCombinedNodePath + //console.log("this is the saved payload inherited", savedPayload) } } } - console.log("this is the saved payload", savedPayload) + return savedPayload } } diff --git a/Projects/Foundations/UI/Function-Libraries/ReferenceAttachDetach.js b/Projects/Foundations/UI/Function-Libraries/ReferenceAttachDetach.js index aed3561dc..c50184947 100644 --- a/Projects/Foundations/UI/Function-Libraries/ReferenceAttachDetach.js +++ b/Projects/Foundations/UI/Function-Libraries/ReferenceAttachDetach.js @@ -21,7 +21,7 @@ function newFoundationsFunctionLibraryAttachDetach() { function storeAttachNodePath(node, attachToNode) { let attachNodePath = UI.projects.foundations.utilities.hierarchy.getNodeNameTypePath(attachToNode) // Save attach path to active payload - node.payload.referenceParentCombinedNodePath = { path: attachNodePath } + node.payload.referenceParentCombinedNodePath = attachNodePath } // Clear the path to reference parent when the reference is cleared diff --git a/Projects/Foundations/UI/Function-Libraries/UiObjectsFromNodes.js b/Projects/Foundations/UI/Function-Libraries/UiObjectsFromNodes.js index 987a87b04..ba90e4642 100644 --- a/Projects/Foundations/UI/Function-Libraries/UiObjectsFromNodes.js +++ b/Projects/Foundations/UI/Function-Libraries/UiObjectsFromNodes.js @@ -308,11 +308,54 @@ function newFoundationsFunctionLibraryUiObjectsFromNodes() { } if (node.savedPayload !== undefined) { if (node.savedPayload.referenceParent !== undefined) { // these are children recreated + // Reestablish based on Id node.payload.referenceParent = mapOfNodes.get(node.savedPayload.referenceParent.id) - if (node.payload.referenceParent === undefined) { - //console.log('[WARN]' + node.type + ' ' + node.name + ' reference parent lost during re-binding phase.') - } - } + //console.log("this is the node we tried to connect to", node.payload.referenceParent) + if (node.payload.referenceParent === undefined) { + console.log('this node failed to connect' + node.type + ' ' + node.name, node ) + let rawPath = node.savedPayload.referenceParentCombinedNodePath + if (rawPath !== undefined) { + console.log('this is a saved path',node.savedPayload.referenceParentCombinedNodePath) + // Attempt to reestablish reference based on saved path + let nodePath = [] + let headNode = UI.projects.foundations.spaces.designSpace.workspace.getHierarchyHeadsByCodeNameAndNodeType(rawPath[0][0], rawPath[0][1]) + console.log('this is our returned head node', headNode) + // Loop through saved Path and gather nodes + /*for (let i = 0; i < rawPath.length; i++) { + console.log("we are at this step in the node path", rawPath[i]) + // Loop through map of nodes to find each node in path + for (let x = 0; x < mapOfNodes.length; x++) { + let mapNode = mapOfNodes[x] + let mapNodeCodeName = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(mapNode.payload, 'codeName') + if (mapNodeCodeName === rawPath[i][0] && mapNode.type === ) { + nodePath.push(mapNode) + } + } + console.log("nodePath", nodePath) + }*/ + } + } + + // need to figure out how to check that this has failed to move to path implimentation + + + + function getMapNodeByCodeNameAndNodeType(codeName, nodeType) { + for (let i = 0; i < mapOfNodes.length; i++) { + let mapNode = mapOfNodes[i] + let mapNodeCodeName = UI.projects.foundations.utilities.nodeConfig.loadConfigProperty(mapNode.payload, 'codeName') + if (mapNodeCodeName === codeName && mapNode.type === nodeType) { + return mapNode + } + } + } + //console.log("this is the node", node, "saved path", path, "and map", mapOfNodes ) + + if (node.payload.referenceParent === undefined) { + //console.log('[WARN]' + node.type + ' ' + node.name + ' reference parent lost during re-binding phase.') + } + + } } } }