Bläddra i källkod

Simulation ohne modelation funktioniert fast komplet

dominik.rieder 7 år sedan
förälder
incheckning
6f810e925c
3 ändrade filer med 39 tillägg och 4 borttagningar
  1. 10 2
      src/ui/controller/Control.java
  2. 23 0
      src/ui/controller/SimulationManager.java
  3. 6 2
      src/ui/view/TimePanel.java

+ 10 - 2
src/ui/controller/Control.java

@@ -496,7 +496,7 @@ public class Control {
 	 * current Timestep.
 	 */
 	public void calculateStateForCurrentTimeStep() {
-		simulationManager.reset();
+		//simulationManager.reset();
 		simulationManager.calculateStateForTimeStep(model.getCurIteration());
 	}
 
@@ -507,9 +507,17 @@ public class Control {
 	 *            current Iteration
 	 */
 	public void calculateStateForTimeStep(int x) {
-		simulationManager.reset();
+		//simulationManager.reset();
 		simulationManager.calculateStateForTimeStep(x);
 	}
+	
+	/**
+	 * resets the whole State of the simulation 
+	 * including a reset of all Edges to the default "is working" state
+	 */
+	public void resetSimulation(){
+		simulationManager.resetSimulation();
+	}
 
 	/**
 	 * Set the Canvas.

+ 23 - 0
src/ui/controller/SimulationManager.java

@@ -24,6 +24,7 @@ public class SimulationManager {
 	private ArrayList<AbstractCpsObject> objectsToHandle;
 	private ArrayList<CpsEdge> allConnections;
 	private ArrayList<SubNet> subNets;
+	private ArrayList<CpsEdge> brokenEdges;
 	private MyCanvas canvas;
 	private int timeStep;
 	private HashMap<Integer, Float> tagTable = new HashMap<Integer, Float>();
@@ -37,6 +38,7 @@ public class SimulationManager {
 		canvas = null;
 		model = m;
 		subNets = new ArrayList<SubNet>();
+		brokenEdges = new ArrayList<CpsEdge>();
 	}
 
 	/**
@@ -46,6 +48,7 @@ public class SimulationManager {
 	 *            current Iteration
 	 */
 	public void calculateStateForTimeStep(int x) {
+		reset();
 		timeStep = x;
 		searchForSubNets();
 		for (SubNet singleSubNet : subNets) {
@@ -353,6 +356,7 @@ public class SimulationManager {
 	 */
 	public void searchForSubNets() {
 		subNets = new ArrayList<SubNet>();
+		brokenEdges.clear();
 		boolean end = false;
 		int i = 0;
 		AbstractCpsObject cps;
@@ -423,6 +427,8 @@ public class SimulationManager {
 					edge.setConnected(2);
 					checkForConnectedStates(a, (CpsUpperNode)b, edge);
 				}
+			}else{
+				brokenEdges.add(edge);
 			}
 		}
 		return sN;
@@ -526,6 +532,23 @@ public class SimulationManager {
 		objectsToHandle = new ArrayList<AbstractCpsObject>();
 		copyObjects(model.getObjectsOnCanvas());
 	}
+	
+	/**
+	 * Resets the State of all Edges
+	 */
+	public void resetEdges(){
+		for(CpsEdge e: brokenEdges){
+			e.setState(true);
+		}
+	}
+	
+	/**
+	 * Resets the State for the whole Simulation Model
+	 */
+	public void resetSimulation(){
+		reset();
+		resetEdges();
+	}
 
 	/**
 	 * Get all Subnets.

+ 6 - 2
src/ui/view/TimePanel.java

@@ -134,7 +134,8 @@ public class TimePanel extends JPanel {
 			public void actionPerformed(ActionEvent ae) {
 				timeSlider.setValue(timeSlider.getMinimum());
 				controller.setCurIteration(timeSlider.getValue());
-				controller.calculateStateForCurrentTimeStep();
+				//controller.calculateStateForCurrentTimeStep();
+				controller.resetSimulation();
 			}
 		});
 		timeForwardBtn.setToolTipText(Languages.getLanguage()[91]);
@@ -166,7 +167,10 @@ public class TimePanel extends JPanel {
 
 		timeBtnPanel.add(playBtn);
 		timeBtnPanel.add(timeResetBtn);
-		timeBtnPanel.add(timeBackwardBtn);
+		/*
+		 * the backwards button isnt used anymore
+		 */
+		//timeBtnPanel.add(timeBackwardBtn);
 		timeBtnPanel.add(timeForwardBtn);
 
 		this.add(timeBtnPanel, BorderLayout.WEST);