From 15c5985f0f52a4ceed3532c95106a7e9c493b080 Mon Sep 17 00:00:00 2001
From: brynnchernosky <56202540+brynnchernosky@users.noreply.github.com>
Date: Thu, 16 Feb 2023 13:38:53 -0500
Subject: debugging persistence

---
 src/client/views/nodes/PhysicsSimulationBox.tsx | 67 +++++++++++++++++--------
 1 file changed, 45 insertions(+), 22 deletions(-)

(limited to 'src/client/views/nodes/PhysicsSimulationBox.tsx')

diff --git a/src/client/views/nodes/PhysicsSimulationBox.tsx b/src/client/views/nodes/PhysicsSimulationBox.tsx
index 13b4fe0b2..25777ce18 100644
--- a/src/client/views/nodes/PhysicsSimulationBox.tsx
+++ b/src/client/views/nodes/PhysicsSimulationBox.tsx
@@ -99,30 +99,52 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
     this.dataDoc.weight = true;
     this.dataDoc.wedge = false;
     this.dataDoc.pendulum = false;
+    this.addWalls();
+    this.dataDoc.simulationReset = !this.dataDoc.simulationReset;
+  };
+
+  // Set weight defaults
+  setToWeightDefault () {
     this.dataDoc.startPosY = this.yMin+this.radius;
     this.dataDoc.startPosX = (this.xMax+this.xMin-this.radius)/2;
     this.dataDoc.updatedForces = [this.forceOfGravity];
     this.dataDoc.startForces = [this.forceOfGravity];
-    this.addWalls();
-    this.dataDoc.simulationReset = !this.dataDoc.simulationReset;
-  };
+  }
 
   // Add a wedge with a One Weight to the simulation
   addWedge () {
     this.dataDoc.weight = true;
     this.dataDoc.wedge = true;
     this.dataDoc.pendulum = false;
-    this.changeWedgeBasedOnNewAngle(26);
     this.addWalls();
-    this.dataDoc.startForces = [this.forceOfGravity];
-    this.updateForcesWithFriction(this.dataDoc.coefficientOfStaticFriction);
   };
 
+  // Set wedge defaults
+  setToWedgeDefault () {
+    this.changeWedgeBasedOnNewAngle(26);
+    this.updateForcesWithFriction(this.dataDoc.coefficientOfStaticFriction);
+    this.dataDoc.startForces = [this.forceOfGravity];
+  }
+
   // Add a simple pendulum to the simulation
   addPendulum = () => {
     this.dataDoc.weight = true;
     this.dataDoc.wedge = false;
     this.dataDoc.pendulum = true;
+    this.removeWalls();
+    let angle = this.dataDoc.pendulumAngle;
+    let mag = 9.81 * Math.cos((angle * Math.PI) / 180);
+    let forceOfTension: IForce = {
+      description: "Tension",
+      magnitude: mag,
+      directionInDegrees: 90 - angle,
+    };
+    this.dataDoc.updatedForces = [this.forceOfGravity, forceOfTension];
+    this.dataDoc.startForces = [this.forceOfGravity, forceOfTension];
+  };
+
+  // Set pendulum defaults
+  setToPendulumDefault () {
     let length = this.xMax*0.7;
     let angle = 35;
     let x = length * Math.cos(((90 - angle) * Math.PI) / 180);
@@ -132,18 +154,10 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
     this.dataDoc.startPosX = xPos;
     this.dataDoc.startPosY = yPos;
     let mag = 9.81 * Math.cos((angle * Math.PI) / 180);
-    let forceOfTension: IForce = {
-      description: "Tension",
-      magnitude: mag,
-      directionInDegrees: 90 - angle,
-    };
-    this.dataDoc.updatedForces = [this.forceOfGravity, forceOfTension];
-    this.dataDoc.startForces = [this.forceOfGravity, forceOfTension];
     this.dataDoc.pendulumAngle = angle;
     this.dataDoc.pendulumLength = length;
     this.dataDoc.adjustPendulumAngle = !this.dataDoc.adjustPendulumAngle;
-    this.removeWalls();
-  };
+  }
 
   // Update forces when coefficient of static friction changes in freeform mode
   updateForcesWithFriction (
@@ -265,7 +279,13 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
 
   componentDidMount() {
     // Add weight
-    this.addPendulum()
+    if (this.dataDoc['simulationType'] == "Inclined Plane") {
+      this.addWedge()
+    } else if (this.dataDoc['simulationType'] == "Pendulum") {
+      this.addPendulum()
+    } else if (this.dataDoc['simulationType'] == "Free Weight") {
+      this.addWeight()
+    }
 
     // Add listener for SHIFT key, which determines if sketch force arrow will be edited or deleted on click
     document.addEventListener("keydown", (e) => {
@@ -279,10 +299,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
       }
     });
 
-    // // Timer for animating the simulation
-    // setInterval(() => {
-    //   this.dataDoc.timer = this.dataDoc.timer+1;
-    // }, 60);
+    this.dataDoc['simulationPaused'] = true;
   }
 
  render () { 
@@ -351,17 +368,23 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
                 this.dataDoc.simulationReset = !this.dataDoc.simulationReset}
               } >RESET</button>
               )}
-              <button onClick={() => {
+              {this.dataDoc.simulationPaused && ( <button onClick={() => {
                 if (!this.dataDoc.pendulum && !this.dataDoc.wedge) {
                   this.addWedge()
+                  this.setToWedgeDefault()
+                  this.dataDoc['simulationType'] = "Inclined Plane"
                 }
                 else if (!this.dataDoc.pendulum && this.dataDoc.wedge) {
+                  this.setToPendulumDefault()
                   this.addPendulum()
+                  this.dataDoc['simulationType'] = "Pendulum"
                 }
                 else {
                   this.addWeight()
+                  this.setToWeightDefault()
+                  this.dataDoc['simulationType'] = "Free Weight"
                 }
-              }} >TYPE</button>
+              }} >TYPE</button>)}
               </div>
           </div>
         </div>
-- 
cgit v1.2.3-70-g09d2

