From 44033da15d2f2190545bf4fe6c7b9ecc4010e8e8 Mon Sep 17 00:00:00 2001 From: znetsixe <73483679+znetsixe@users.noreply.github.com> Date: Thu, 2 Oct 2025 17:29:31 +0200 Subject: [PATCH] Added logging data on menu and distance Added helper functionality to abort movements in state class and safeguards to NOT be able to abort in protected states. some caps removal --- src/menu/physicalPosition.js | 47 +++++++++++++++++++++++++++++----- src/predict/predictConfig.json | 4 +-- src/state/state.js | 21 ++++++++++++++- src/state/stateConfig.json | 4 +-- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/menu/physicalPosition.js b/src/menu/physicalPosition.js index e22cfb1..effbe96 100644 --- a/src/menu/physicalPosition.js +++ b/src/menu/physicalPosition.js @@ -180,33 +180,66 @@ getSaveInjectionCode(nodeName) { return ` // PhysicalPosition Save injection for ${nodeName} window.EVOLV.nodes.${nodeName}.positionMenu.saveEditor = function(node) { + console.log("=== PhysicalPosition Save Debug ==="); + const sel = document.getElementById('node-input-positionVsParent'); const hasDistanceCheck = document.getElementById('node-input-hasDistance'); const distanceInput = document.getElementById('node-input-distance'); - // Save existing position data - node.positionVsParent = sel ? sel.value : 'atEquipment'; - node.positionLabel = sel ? sel.options[sel.selectedIndex].textContent : 'At Equipment'; - node.positionIcon = sel ? sel.options[sel.selectedIndex].getAttribute('data-icon') : 'fa fa-cog'; + console.log("→ sel element found:", !!sel); + console.log("→ sel:", sel); + console.log("→ sel.value:", sel ? sel.value : "NO ELEMENT"); + console.log("→ sel.selectedIndex:", sel ? sel.selectedIndex : "NO ELEMENT"); + console.log("→ sel.options:", sel ? Array.from(sel.options).map(o => ({value: o.value, text: o.textContent})) : "NO OPTIONS"); + + if (!sel) { + console.error("→ positionMenu.saveEditor FAILED: select element not found!"); + return false; + } + + // Save existing position data + const positionValue = sel.value; + const selectedOption = sel.options[sel.selectedIndex]; + + console.log("→ positionValue:", positionValue); + console.log("→ selectedOption:", selectedOption); + console.log("→ selectedOption.textContent:", selectedOption ? selectedOption.textContent : "NO OPTION"); + console.log("→ selectedOption data-icon:", selectedOption ? selectedOption.getAttribute('data-icon') : "NO ICON"); + + node.positionVsParent = positionValue || 'atEquipment'; + node.positionLabel = selectedOption ? selectedOption.textContent : 'At Equipment'; + node.positionIcon = selectedOption ? selectedOption.getAttribute('data-icon') : 'fa fa-cog'; + + console.log("→ node.positionVsParent set to:", node.positionVsParent); + console.log("→ node.positionLabel set to:", node.positionLabel); + + // Save distance data + console.log("→ hasDistanceCheck found:", !!hasDistanceCheck); + console.log("→ hasDistanceCheck.checked:", hasDistanceCheck ? hasDistanceCheck.checked : "NO ELEMENT"); - // Save distance data (NEW) node.hasDistance = hasDistanceCheck ? hasDistanceCheck.checked : false; if (node.hasDistance && distanceInput && distanceInput.value) { + console.log("→ distanceInput.value:", distanceInput.value); node.distance = parseFloat(distanceInput.value) || 0; node.distanceUnit = 'm'; // Fixed to meters for now - + // Generate distance description based on position const contexts = window.EVOLV.nodes.${nodeName}.menuData.position.distanceContexts; const context = contexts && contexts[node.positionVsParent]; node.distanceDescription = context ? context.description : 'Distance from parent'; + + console.log("→ distance set to:", node.distance); } else { - // Clear distance data if not specified + console.log("→ clearing distance data"); delete node.distance; delete node.distanceUnit; delete node.distanceDescription; } + console.log("→ positionMenu.saveEditor result: SUCCESS"); + console.log("→ final node.positionVsParent:", node.positionVsParent); + return true; }; `; diff --git a/src/predict/predictConfig.json b/src/predict/predictConfig.json index ac778ec..53dc485 100644 --- a/src/predict/predictConfig.json +++ b/src/predict/predictConfig.json @@ -1,7 +1,7 @@ { "general": { "name": { - "default": "Interpolation Configuration", + "default": "interpolation configuration", "rules": { "type": "string", "description": "A human-readable name or label for this interpolation configuration." @@ -70,7 +70,7 @@ } }, "role": { - "default": "Interpolator", + "default": "interpolator", "rules": { "type": "string", "description": "Indicates the role of this configuration (e.g., 'Interpolator', 'DataCurve', etc.)." diff --git a/src/state/state.js b/src/state/state.js index af33641..2ad0229 100644 --- a/src/state/state.js +++ b/src/state/state.js @@ -52,6 +52,7 @@ class state{ return this.stateManager.getRunTimeHours(); } + async moveTo(targetPosition) { // Check for invalid conditions and throw errors @@ -86,14 +87,33 @@ class state{ // -------- State Transition Methods -------- // + abortCurrentMovement(reason = "group override") { + if (this.abortController && !this.abortController.signal.aborted) { + this.logger.warn(`Aborting movement: ${reason}`); + this.abortController.abort(); + } + } + async transitionToState(targetState, signal) { const fromState = this.getCurrentState(); const position = this.getCurrentPosition(); + // Define states that cannot be aborted for safety reasons + const protectedStates = ['warmingup', 'coolingdown']; + const isProtectedTransition = protectedStates.includes(fromState); + try { this.logger.debug(`Starting transition from ${fromState} to ${targetState}.`); + if( isProtectedTransition){ + //overrule signal to prevent abortion + signal = null; // Disable abortion for protected states + //spit warning + this.logger.warn(`Transition from ${fromState} to ${targetState} is protected and cannot be aborted.`); + } + + // Await the state transition and pass signal for abortion const feedback = await this.stateManager.transitionTo(targetState,signal); this.logger.info(`Statemanager: ${feedback}`); @@ -108,7 +128,6 @@ class state{ //trigger move await this.moveTo(this.delayedMove,signal); this.delayedMove = null; - this.logger.info(`moveTo : ${feedback} `); } diff --git a/src/state/stateConfig.json b/src/state/stateConfig.json index 8846c61..99d398f 100644 --- a/src/state/stateConfig.json +++ b/src/state/stateConfig.json @@ -1,7 +1,7 @@ { "general": { "name": { - "default": "State Configuration", + "default": "state configuration", "rules": { "type": "string", "description": "A human-readable name for the state configuration." @@ -65,7 +65,7 @@ } }, "role": { - "default": "StateController", + "default": "statecontroller", "rules": { "type": "string", "description": "Functional role within the system."