|
@@ -1,5 +1,7 @@
|
|
|
package de.tu_darmstadt.tk.SmartHomeNetworkSim.control;
|
|
|
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Connection;
|
|
|
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Model;
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
|
|
|
|
|
@@ -139,4 +141,47 @@ public class Controller {
|
|
|
sd.setY(scalePos(sd.getY(), 1.0, model.getHeight()));
|
|
|
sd.setZ(scalePos(sd.getZ(), 1.0, model.getDepth()));
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creates a new SmartDevice at the given Position
|
|
|
+ * @param name name of the smartDevice
|
|
|
+ * @param x_pos position on the x-Axis
|
|
|
+ * @param y_pos position on the y-Axis
|
|
|
+ * @param z_pos position on the z-Axis
|
|
|
+ */
|
|
|
+ public void createSmartDevice(String name, int x_pos, int y_pos, int z_pos){
|
|
|
+ SmartDevice sd = new SmartDevice(name);
|
|
|
+ sd.setX(scalePos(x_pos, 1.0, model.getWidth()));
|
|
|
+ sd.setY(scalePos(y_pos, 1.0, model.getHeight()));
|
|
|
+ sd.setZ(scalePos(z_pos, 1.0, model.getDepth()));
|
|
|
+ model.addDevices(sd);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Deletes the given SmartDevice toDelete, removes it from its links and connections.
|
|
|
+ * @param toDelete the SmartDevice to remove
|
|
|
+ */
|
|
|
+ public void deleteSmartDevice(SmartDevice toDelete){
|
|
|
+ if(toDelete == null) return;
|
|
|
+ //Remove from Links
|
|
|
+ for(Link link:toDelete.getLinks())
|
|
|
+ removeSmartDeviceFromLink(toDelete, link);
|
|
|
+
|
|
|
+ //Delete Connections
|
|
|
+ for(Connection c: toDelete.getConnections()){
|
|
|
+ c.removeSmartDevice(toDelete);
|
|
|
+ if(c.getSource()==null){
|
|
|
+ model.addTerminatingConnections(c);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Removes the SmartDevice from the given Link
|
|
|
+ * @param toRemove
|
|
|
+ * @param link
|
|
|
+ */
|
|
|
+ public void removeSmartDeviceFromLink(SmartDevice toRemove, Link link){
|
|
|
+ toRemove.removeLink(link);
|
|
|
+ }
|
|
|
}
|