From 94bf4599aa0258d1d401a43e51c6d9da60b59cf5 Mon Sep 17 00:00:00 2001 From: kghs-aver Date: Sun, 23 Mar 2025 19:58:28 +0530 Subject: [PATCH 1/3] Dial placement retained after closing simulation --- .../src/app/Libs/inputs/Potentiometer.ts | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts b/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts index 0c2cdf2e..6d9c0c2b 100644 --- a/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts +++ b/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts @@ -49,6 +49,10 @@ export class Potentiometer extends CircuitElement { * Stores connected LEDs */ connectedLEDs: LED[] = []; + /** + * Stores the anle + */ + private savedAngle = 0; /** * Potentiometer constructor * @param canvas Raphael Canvas (Paper) @@ -229,7 +233,15 @@ export class Potentiometer extends CircuitElement { x: attr.x + attr.width / 2 + this.tx, y: attr.y + attr.height / 2 + this.ty }; - this.elements[1].transform(`t0,0`); + // Get the saved angle from localStorage + if (this.savedAngle !== null) { + // Apply the saved rotation angle to the dial, ensuring it's centered + this.elements[1].transform(`t${this.tx},${this.ty} r${this.savedAngle} t${-this.tx},${-this.ty}`); + console.log('Restoring saved angle:', this.savedAngle); + } else { + // Default behavior if no angle is saved (first time or reset) + this.elements[1].transform(`t${this.tx},${this.ty} t${-this.tx},${-this.ty}`); + } this.elements[1].attr({ x: attr.x + this.tx, y: attr.y + this.ty @@ -298,12 +310,26 @@ export class Potentiometer extends CircuitElement { * Reset transformation add add event listeners. */ closeSimulation(): void { + let rotationAngle; + rotationAngle = this.savedAngle; + console.log('Current Rotation Angle:', rotationAngle); + // Get the current transform value of the potentiometer + const transform = this.elements[1].transform(); + // If the transform includes rotation (it may be in a string or matrix form) + if (Array.isArray(transform) && transform[0][0] === 'r') { + rotationAngle = transform[0][1]; // Extract the rotation angle from the array + } + if (this.savedAngle !== rotationAngle) { + this.savedAngle = rotationAngle; // Only save the new angle if it has changed + console.log('Rotation Angle to Save:', this.savedAngle); + } const attr = this.elements[1].attr(); this.elements[1].attr({ x: attr.x - this.tx, y: attr.y - this.ty }); - this.elements[1].transform(`t${this.tx},${this.ty}`); + // Set the transform origin to center and apply rotation relative to center + this.elements[1].transform(`t${this.tx},${this.ty} r${rotationAngle}`); this.elements.undrag(); this.elements.unmousedown(); this.setClickListener(null); From 24a7b2487c6e9be34b2f8b85f8cbf600faa1214a Mon Sep 17 00:00:00 2001 From: kghs-aver Date: Mon, 24 Mar 2025 15:32:49 +0530 Subject: [PATCH 2/3] fix linting --- ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts b/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts index 6d9c0c2b..cadbe038 100644 --- a/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts +++ b/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts @@ -49,7 +49,7 @@ export class Potentiometer extends CircuitElement { * Stores connected LEDs */ connectedLEDs: LED[] = []; - /** + /** * Stores the anle */ private savedAngle = 0; @@ -329,7 +329,7 @@ export class Potentiometer extends CircuitElement { y: attr.y - this.ty }); // Set the transform origin to center and apply rotation relative to center - this.elements[1].transform(`t${this.tx},${this.ty} r${rotationAngle}`); + this.elements[1].transform(`t${this.tx},${this.ty} r${rotationAngle}`); this.elements.undrag(); this.elements.unmousedown(); this.setClickListener(null); From 3adaad74351b265ff9ba6894db15fae2b899b256 Mon Sep 17 00:00:00 2001 From: kghs-aver Date: Mon, 24 Mar 2025 15:35:15 +0530 Subject: [PATCH 3/3] fix linting --- ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts b/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts index cadbe038..d549a8b5 100644 --- a/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts +++ b/ArduinoFrontend/src/app/Libs/inputs/Potentiometer.ts @@ -329,7 +329,7 @@ export class Potentiometer extends CircuitElement { y: attr.y - this.ty }); // Set the transform origin to center and apply rotation relative to center - this.elements[1].transform(`t${this.tx},${this.ty} r${rotationAngle}`); + this.elements[1].transform(`t${this.tx},${this.ty} r${rotationAngle}`); this.elements.undrag(); this.elements.unmousedown(); this.setClickListener(null);