ソースを参照

Improves SimulationConfigurator Reset, resets all ports:lastTrigger

Andreas T. Meyer-Berg 5 年 前
コミット
727f56deb5

+ 28 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/control/Controller.java

@@ -10,6 +10,7 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Protocol;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SimulationManager;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
 
 /**
@@ -504,6 +505,12 @@ public class Controller {
 		}
 	}
 	
+	/**
+	 * Changes the type of the connection to the new Type and updates all references
+	 * @param connection connection to be updated
+	 * @param newConnectionClass class of new type
+	 * @return newly created connection
+	 */
 	public Connection changeConnectionType(Connection connection, Class<? extends Connection> newConnectionClass) {
 		
 		Connection newCon = null;
@@ -632,7 +639,7 @@ public class Controller {
 	 * @param c Connection to be removed
 	 * @param l Link to be removed
 	 */
-	private void removeConnectionFromLink(Connection c, Link l) {
+	public void removeConnectionFromLink(Connection c, Link l) {
 		if(c!=null && c.getLink()==l){
 			c.setLink(null);
 		}
@@ -640,4 +647,24 @@ public class Controller {
 			l.removeConnection(c);		
 		}
 	}
+	
+	/**
+	 * Reset Simulation 
+	 * 
+	 * @param timestep
+	 */
+	public void resetSimulation(long timestep){
+		for(SmartDevice d: model.getDevices())
+			for(Port p:d.getPorts())
+				if(p.getLastTrigger()>timestep)
+					p.setLastTrigger(timestep);
+	}
+
+	/**
+	 * Returns the Simulation Manager of the Program
+	 * @return Simulation Manager
+	 */
+	public SimulationManager getSimulationManager() {
+		return model.getSim();
+	}
 }

+ 1 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/MenuBar.java

@@ -80,7 +80,7 @@ public class MenuBar extends JMenuBar {
 		mnSimulation = new JMenu("Simulation");
 		JMenuItem mntmConfigureSim = new JMenuItem("Configure Sim");
 		mntmConfigureSim.addActionListener(a->{
-			SimulationConfigurator sim = new SimulationConfigurator(this.model.getSim());
+			SimulationConfigurator sim = new SimulationConfigurator(controller);
 			sim.setLocationRelativeTo(this.getParent());
 			sim.setVisible(true);
 		});

+ 12 - 4
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/popups/SimulationConfigurator.java

@@ -8,10 +8,12 @@ import javax.swing.JOptionPane;
 import javax.swing.JTextField;
 import javax.swing.Timer;
 
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SimulationManager;
 
 import java.awt.Rectangle;
+
 import javax.swing.JCheckBox;
 
 /**
@@ -71,15 +73,21 @@ public class SimulationConfigurator extends JFrame {
 	 * End Time of the simulation
 	 */
 	private long endTime = 1000;
+	/**
+	 * Controller of the Application
+	 */
+	Controller controller;
 
 	/**
 	 * Create a new SimulationConfigurator Panel, which controls the given
 	 * SimulationManager
 	 * 
-	 * @param sim SimulationManager, which simulates the network
+	 * @param control Controller of the program
 	 */
-	public SimulationConfigurator(SimulationManager sim) {
-		this.sim = sim;
+	public SimulationConfigurator(Controller control) {
+		this.controller = control;
+		this.sim = controller.getSimulationManager();
+		
 		setBounds(new Rectangle(0, 0, 460, 300));
 		setResizable(false);
 		getContentPane().setLayout(null);
@@ -228,7 +236,7 @@ public class SimulationConfigurator extends JFrame {
 	 * @param args none specified
 	 */
 	public static void main(String[] args) {
-		SimulationConfigurator simConfig = new SimulationConfigurator(new SimulationManager(new Model()));
+		SimulationConfigurator simConfig = new SimulationConfigurator(new Controller(new Model()));
 		simConfig.setEnabled(true);
 		simConfig.setVisible(true);