From 617d008889a6b9640bc9cf8a87d24a5ed24cb660 Mon Sep 17 00:00:00 2001
From: brynnchernosky <56202540+brynnchernosky@users.noreply.github.com>
Date: Tue, 2 May 2023 20:39:02 -0400
Subject: debug

---
 .../nodes/PhysicsBox/PhysicsSimulationBox.tsx      | 102 ++++++++++-----------
 1 file changed, 47 insertions(+), 55 deletions(-)

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

diff --git a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx
index 5335fc1ec..3cb34d5b9 100644
--- a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx
+++ b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx
@@ -33,10 +33,9 @@ import {
 import Typography from "@mui/material/Typography";
 import "./PhysicsSimulationBox.scss";
 import InputField from "./PhysicsSimulationInputField";
-// import questions from "./PhysicsSimulationQuestions.json";
-// import tutorials from "./PhysicsSimulationTutorial.json";
+import questions from "./PhysicsSimulationQuestions.json";
+import tutorials from "./PhysicsSimulationTutorial.json";
 import Wall from "./PhysicsSimulationWall";
-import IWall from "./PhysicsSimulationWall";
 import Weight from "./PhysicsSimulationWeight";
 
 interface IWallProps {
@@ -211,7 +210,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
     this.dataDoc.mass2 = this.dataDoc.mass2 ?? 1;
 
     // Setup simulation
-    this.setupSimulation()
+    this.setupSimulation(this.dataDoc.simulationType, this.dataDoc.mode)
   }
 
   componentDidUpdate() {
@@ -220,16 +219,17 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
     this.radius = 0.05*this.layoutDoc._height ?? 50;
   }
 
-  setupSimulation = () => {
-    if (this.dataDoc.simulationType != "Circular Motion") {
+  setupSimulation = (simulationType: string, mode: string) => {
+    this.dataDoc.simulationPaused = true;
+    if (simulationType != "Circular Motion") {
       this.dataDoc.startVelX = 0;
       this.dataDoc.setStartVelY = 0;
       this.dataDoc.velocityXDisplay = (0);
       this.dataDoc.velocityYDisplay = (0);
     }
-    if (this.dataDoc.mode == "Freeform") {
+    if (mode == "Freeform") {
       this.dataDoc.showForceMagnitudes = (true);
-      if (this.dataDoc.simulationType == "One Weight") {
+      if (simulationType == "One Weight") {
         this.dataDoc.showComponentForces = false;
         this.dataDoc.startPosY = (this.yMin + this.radius);
         this.dataDoc.startPosX = ((this.xMax + this.xMin) / 2 - this.radius);
@@ -252,7 +252,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
           },
         ]);
         this.dataDoc.simulationReset = (!this.dataDoc.simulationReset);
-      } else if (this.dataDoc.simulationType == "Inclined Plane") {
+      } else if (simulationType == "Inclined Plane") {
         this.changeWedgeBasedOnNewAngle(26);
         this.dataDoc.startForces = ([
           {
@@ -263,46 +263,46 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
           },
         ]);
         this.updateForcesWithFriction(Number(this.dataDoc.coefficientOfStaticFriction));
-      } else if (this.dataDoc.simulationType == "Pendulum") {
+      } else if (simulationType == "Pendulum") {
         this.setupPendulum();
-      } else if (this.dataDoc.simulationType == "Spring") {
+      } else if (simulationType == "Spring") {
         this.setupSpring();
-      } else if (this.dataDoc.simulationType == "Circular Motion") {
+      } else if (simulationType == "Circular Motion") {
         this.setupCircular(0);
-      } else if (this.dataDoc.simulationType == "Pulley") {
+      } else if (simulationType == "Pulley") {
         this.setupPulley();
-      } else if (this.dataDoc.simulationType == "Suspension") {
+      } else if (simulationType == "Suspension") {
         this.setupSuspension();
       }
-    } else if (this.dataDoc.mode == "Review") {
+    } else if (mode == "Review") {
       this.dataDoc.showComponentForces = (false);
       this.dataDoc.showForceMagnitudes = (true);
       this.dataDoc.showAcceleration = (false);
       this.dataDoc.showVelocity = (false);
       this.dataDoc.showForces= (true);
       // this.generateNewQuestion();
-      if (this.dataDoc.simulationType == "One Weight") {
+      if (simulationType == "One Weight") {
         // TODO - one weight review problems
-      } else if (this.dataDoc.simulationType == "Spring") {
+      } else if (simulationType == "Spring") {
         this.setupSpring();
         // TODO - spring review problems
-      } else if (this.dataDoc.simulationType == "Inclined Plane") {
+      } else if (simulationType == "Inclined Plane") {
         this.dataDoc.updatedForces = ([]);
         this.dataDoc.startForces = ([]);
-      } else if (this.dataDoc.simulationType == "Pendulum") {
+      } else if (simulationType == "Pendulum") {
         this.setupPendulum();
         // TODO - pendulum review problems
-      } else if (this.dataDoc.simulationType == "Circular Motion") {
+      } else if (simulationType == "Circular Motion") {
         this.setupCircular(0);
         // TODO - circular motion review problems
-      } else if (this.dataDoc.simulationType == "Pulley") {
+      } else if (simulationType == "Pulley") {
         this.setupPulley();
         // TODO - pulley tutorial review problems
-      } else if (this.dataDoc.simulationType == "Suspension") {
+      } else if (simulationType == "Suspension") {
         this.setupSuspension();
         // TODO - suspension tutorial review problems
       }
-    } else if (this.dataDoc.mode == "Tutorial") {
+    } else if (mode == "Tutorial") {
       this.dataDoc.showComponentForces = (false);
       this.dataDoc.stepNumber = (0);
       this.dataDoc.showAcceleration = (false);
@@ -1195,10 +1195,10 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
     };
     this.dataDoc.updatedForces = ([gravityForce1, tensionForce1]);
     this.dataDoc.startForces = ([gravityForce1, tensionForce1]);
-    this.dataDoc.startPosY2 = ((this.props.yMax + this.props.yMin) / 2);
-    this.dataDoc.startPosX2 = ((this.props.xMin + this.props.xMax) / 2 + 5);
-    this.dataDoc.positionYDisplay2 = (this.getDisplayYPos((this.props.yMax + this.props.yMin) / 2));
-    this.dataDoc.positionXDisplay2 = ((this.props.xMin + this.props.xMax) / 2 + 5);
+    this.dataDoc.startPosY2 = ((this.yMax + this.yMin) / 2);
+    this.dataDoc.startPosX2 = ((this.xMin + this.xMax) / 2 + 5);
+    this.dataDoc.positionYDisplay2 = (this.getDisplayYPos((this.yMax + this.yMin) / 2));
+    this.dataDoc.positionXDisplay2 = ((this.xMin + this.xMax) / 2 + 5);
     this.dataDoc.updatedForces2 = ([gravityForce2, tensionForce2]);
     this.dataDoc.startForces2 = ([gravityForce2, tensionForce2]);
     this.dataDoc.simulationReset = (!this.dataDoc.simulationReset);
@@ -1278,32 +1278,6 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
                 <LinearProgress />
               </div>
             )}
-            <div
-              style={{
-                position: "fixed",
-                top: 1 + "em",
-                left: this.xMin + 12 + "px",
-              }}
-            >
-              <div className="dropdownMenu">
-                <select
-                  value={this.dataDoc.simulationType}
-                  onChange={(event) => {
-                    this.dataDoc.simulationType = (event.target.value);
-                    this.setupSimulation()
-                  }}
-                  style={{ height: "2em", width: "100%", fontSize: "16px" }}
-                >
-                  <option value="One Weight">Projectile</option>
-                  <option value="Inclined Plane">Inclined Plane</option>
-                  <option value="Pendulum">Pendulum</option>
-                  <option value="Spring">Spring</option>
-                  <option value="Circular Motion">Circular Motion</option>
-                  <option value="Pulley">Pulley</option>
-                  <option value="Suspension">Suspension</option>
-                </select>
-              </div>
-            </div>
           </div>
           <div className="mechanicsSimulationElements">
             <Weight
@@ -1341,7 +1315,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
               springRestLength={this.dataDoc.springRestLength}
               startForces={this.dataDoc.startForces}
               startPosX={this.dataDoc.startPosX}
-              startPosY={this.dataDoc.startPosY}
+              startPosY={this.dataDoc.startPosY ?? 0}
               startVelX={this.dataDoc.startVelX}
               startVelY={this.dataDoc.startVelY}
               timestepSize={0.05}
@@ -1453,12 +1427,30 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
               </IconButton>
             )}
           </Stack>
+          <div className="dropdownMenu">
+                <select
+                  value={this.dataDoc.simulationType}
+                  onChange={(event) => {
+                    this.dataDoc.simulationType = (event.target.value);
+                    this.setupSimulation(event.target.value, this.dataDoc.mode)
+                  }}
+                  style={{ height: "2em", width: "100%", fontSize: "16px" }}
+                >
+                  <option value="One Weight">Projectile</option>
+                  <option value="Inclined Plane">Inclined Plane</option>
+                  <option value="Pendulum">Pendulum</option>
+                  <option value="Spring">Spring</option>
+                  <option value="Circular Motion">Circular Motion</option>
+                  <option value="Pulley">Pulley</option>
+                  <option value="Suspension">Suspension</option>
+                </select>
+              </div>
           <div className="dropdownMenu">
             <select
               value={this.dataDoc.mode}
               onChange={(event) => {
                 this.dataDoc.mode = (event.target.value);
-                this.setupSimulation()
+                this.setupSimulation(this.dataDoc.simulationType, event.target.value)
               }}
               style={{ height: "2em", width: "100%", fontSize: "16px" }}
             >
-- 
cgit v1.2.3-70-g09d2

