|
@@ -1,8 +1,6 @@
|
|
|
package de.tu_darmstadt.tk.SmartHomeNetworkSim.control;
|
|
|
|
|
|
import java.util.Collection;
|
|
|
-import java.util.Iterator;
|
|
|
-import java.util.LinkedList;
|
|
|
import java.util.Observer;
|
|
|
|
|
|
import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Connection;
|
|
@@ -22,7 +20,7 @@ public class Controller {
|
|
|
/**
|
|
|
* {@link Model} which stores the smart home model
|
|
|
*/
|
|
|
- private Model model;
|
|
|
+ Model model;
|
|
|
|
|
|
/**
|
|
|
* Controller for Import of user defined java classes
|
|
@@ -89,12 +87,10 @@ public class Controller {
|
|
|
* new y position
|
|
|
* @param z
|
|
|
* new z position
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#moveSmartDevice(SmartDevice,int,int,int)} instead
|
|
|
*/
|
|
|
public void moveSmartDevice(SmartDevice device, int x, int y, int z) {
|
|
|
- device.setX(x);
|
|
|
- device.setY(y);
|
|
|
- device.setZ(z);
|
|
|
-
|
|
|
+ networkController.moveSmartDevice(device, x, y, z);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -107,9 +103,10 @@ public class Controller {
|
|
|
* the new height to set
|
|
|
* @param depth
|
|
|
* the new depth to set
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController#setDimension(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,int,int,int)} instead
|
|
|
*/
|
|
|
public void setDimension(int width, int height, int depth) {
|
|
|
- setDimension(width, height, depth, false);
|
|
|
+ settingsController.setDimension(width, height, depth);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -124,57 +121,18 @@ public class Controller {
|
|
|
* the new depth to set
|
|
|
* @param stretchModel
|
|
|
* true, if smartDevice positions should be stretched
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController#setDimension(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,int,int,int,boolean)} instead
|
|
|
*/
|
|
|
public void setDimension(int width, int height, int depth, boolean stretchModel) {
|
|
|
- // Don't allow to small Models
|
|
|
- if (width < 400)
|
|
|
- width = 400;
|
|
|
- if (height < 400)
|
|
|
- height = 400;
|
|
|
- if (depth < 400)
|
|
|
- depth = 400;
|
|
|
-
|
|
|
- if (stretchModel) {
|
|
|
- /**
|
|
|
- * Factor that changes the x position. Example: 1 -> positions stay
|
|
|
- * the same 0.5 -> x position is halved 2 -> x position is doubled
|
|
|
- */
|
|
|
- double width_factor = ((double) width) / ((double) model.getWidth());
|
|
|
- /**
|
|
|
- * Factor that changes the y position. Example: 1 -> positions stay
|
|
|
- * the same 0.5 -> y position is halved 2 -> y position is doubled
|
|
|
- */
|
|
|
- double height_factor = ((double) height) / ((double) model.getHeight());
|
|
|
- /**
|
|
|
- * Factor that changes the z position. Example: 1 -> positions stay
|
|
|
- * the same 0.5 -> z position is halved 2 -> z position is doubled
|
|
|
- */
|
|
|
- double depth_factor = ((double) depth) / ((double) model.getDepth());
|
|
|
- // Update all device positions
|
|
|
- for (SmartDevice d : model.getDevices()) {
|
|
|
- if (width_factor != 1.0)
|
|
|
- d.setX(scalePos(d.getX(), width_factor, width));
|
|
|
- if (height_factor != 1.0)
|
|
|
- d.setY(scalePos(d.getY(), height_factor, height));
|
|
|
- if (depth_factor != 1.0)
|
|
|
- d.setZ(scalePos(d.getZ(), depth_factor, depth));
|
|
|
- }
|
|
|
- }
|
|
|
- model.setWidth(width);
|
|
|
- model.setHeight(height);
|
|
|
- model.setDepth(depth);
|
|
|
+ settingsController.setDimension(width, height, depth, stretchModel);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Validate all device positions, move all devices into the bounds, if they are outside the visualization
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#validateDevicePosition(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller)} instead
|
|
|
*/
|
|
|
public void validateDevicePosition() {
|
|
|
- // Update all device positions
|
|
|
- for (SmartDevice d : model.getDevices()) {
|
|
|
- d.setX(scalePos(d.getX(), 1.0, getWidth()));
|
|
|
- d.setY(scalePos(d.getY(), 1.0, getHeight()));
|
|
|
- d.setZ(scalePos(d.getZ(), 1.0, getDepth()));
|
|
|
- }
|
|
|
+ networkController.validateDevicePosition();
|
|
|
}
|
|
|
/**
|
|
|
* Calculates the new scaled position, which should be in Bounds:
|
|
@@ -188,19 +146,10 @@ public class Controller {
|
|
|
* @param upperBound
|
|
|
* upper bound of the frame, which should not be exceeded
|
|
|
* @return new position that was calculated
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController#scalePos(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,int,double,int)} instead
|
|
|
*/
|
|
|
- private int scalePos(int oldPosition, double factor, int upperBound) {
|
|
|
- /**
|
|
|
- * New Position that should be validated and returned
|
|
|
- */
|
|
|
- int newPosition = (int) Math.round(factor * oldPosition);
|
|
|
- // Update if it moves out of the frame
|
|
|
- if (newPosition < getDevice_visualization_radius())
|
|
|
- newPosition = getDevice_visualization_radius();
|
|
|
- if (newPosition >= upperBound - getDevice_visualization_radius())
|
|
|
- newPosition = upperBound - getDevice_visualization_radius();
|
|
|
-
|
|
|
- return newPosition;
|
|
|
+ int scalePos(int oldPosition, double factor, int upperBound) {
|
|
|
+ return settingsController.scalePos(oldPosition, factor, upperBound);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -209,15 +158,10 @@ public class Controller {
|
|
|
*
|
|
|
* @param sd
|
|
|
* SmartDevice which should be added to the model
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#addSmartDevice(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,SmartDevice)} instead
|
|
|
*/
|
|
|
public void addSmartDevice(SmartDevice sd) {
|
|
|
- if (model.getDevices().contains(sd))
|
|
|
- return;
|
|
|
- model.addDevices(sd);
|
|
|
- // validate Position
|
|
|
- sd.setX(scalePos(sd.getX(), 1.0, model.getWidth()));
|
|
|
- sd.setY(scalePos(sd.getY(), 1.0, model.getHeight()));
|
|
|
- sd.setZ(scalePos(sd.getZ(), 1.0, model.getDepth()));
|
|
|
+ networkController.addSmartDevice(sd);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -232,13 +176,10 @@ public class Controller {
|
|
|
* position on the y-Axis
|
|
|
* @param z_pos
|
|
|
* position on the z-Axis
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#createSmartDevice(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,String,int,int,int)} instead
|
|
|
*/
|
|
|
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);
|
|
|
+ networkController.createSmartDevice(name, x_pos, y_pos, z_pos);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -247,48 +188,10 @@ public class Controller {
|
|
|
*
|
|
|
* @param toDelete
|
|
|
* the SmartDevice to delete
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#deleteSmartDevice(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,SmartDevice)} instead
|
|
|
*/
|
|
|
public void deleteSmartDevice(SmartDevice toDelete) {
|
|
|
- if (toDelete == null)
|
|
|
- return;
|
|
|
-
|
|
|
- // Delete Connections
|
|
|
- for (Port p : toDelete.getPorts()) {
|
|
|
- //Skip ports that are not connected
|
|
|
- if(p.getConnection()==null)continue;
|
|
|
- this.removeDeviceFromConnection(p, p.getConnection());
|
|
|
-
|
|
|
- /**
|
|
|
- * Connection of the current port
|
|
|
- *
|
|
|
- Connection c = p.getConnection();
|
|
|
-
|
|
|
- //remove from protocol
|
|
|
- if(c.getProtocol()!=null)
|
|
|
- c.getProtocol().removeDevice(p);
|
|
|
-
|
|
|
- //remove from connection
|
|
|
- c.removeSmartDevice(p);
|
|
|
- if (c.getStatus()==Connection.FINISHED||c.getStatus()==Connection.TERMINATED) {
|
|
|
- //if connection terminated - remove rest of ports
|
|
|
- for (Port sd : c.getParticipants()) {
|
|
|
- if (sd != null && sd != p)
|
|
|
- sd.getOwner().removePort(sd);
|
|
|
- }
|
|
|
- }*/
|
|
|
- }
|
|
|
-
|
|
|
- // Remove from Links
|
|
|
- LinkedList<Link> links = new LinkedList<Link>(toDelete.getLinks());
|
|
|
- for (Link link : links)
|
|
|
- removeSmartDeviceFromLink(toDelete, link);
|
|
|
- links.clear();
|
|
|
- // Remove Links from Device
|
|
|
- toDelete.getLinks().clear();
|
|
|
-
|
|
|
- //Remove all ports from the device
|
|
|
- toDelete.getPorts().clear();
|
|
|
- model.getDevices().remove(toDelete);
|
|
|
+ networkController.deleteSmartDevice(toDelete);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -296,15 +199,10 @@ public class Controller {
|
|
|
*
|
|
|
* @param toRemove the Device that should be removed from the link
|
|
|
* @param link the Link, which contains the SmartDevice
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#removeSmartDeviceFromLink(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,SmartDevice,Link)} instead
|
|
|
*/
|
|
|
public void removeSmartDeviceFromLink(SmartDevice toRemove, Link link) {
|
|
|
- if(link != null){
|
|
|
- link.removeDevice(toRemove);
|
|
|
- if(link.getDevices().size()==0)
|
|
|
- deleteLink(link);
|
|
|
- }
|
|
|
- if(toRemove!=null)
|
|
|
- toRemove.removeLink(link);
|
|
|
+ networkController.removeSmartDeviceFromLink(toRemove, link);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -335,101 +233,118 @@ public class Controller {
|
|
|
|
|
|
/**
|
|
|
* @return the width
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController#getWidth(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller)} instead
|
|
|
*/
|
|
|
public int getWidth() {
|
|
|
- return model.getWidth();
|
|
|
+ return settingsController.getWidth();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param width the width to set
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController#setWidth(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,int)} instead
|
|
|
*/
|
|
|
public void setWidth(int width) {
|
|
|
- model.setWidth(width);
|
|
|
+ settingsController.setWidth(width);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @return the height
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController#getHeight(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller)} instead
|
|
|
*/
|
|
|
public int getHeight() {
|
|
|
- return model.getHeight();
|
|
|
+ return settingsController.getHeight();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param height the height to set
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController#setHeight(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,int)} instead
|
|
|
*/
|
|
|
public void setHeight(int height) {
|
|
|
- model.setHeight(height);
|
|
|
+ settingsController.setHeight(height);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @return the depth
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.ImportController#getDepth(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller)} instead
|
|
|
*/
|
|
|
public int getDepth() {
|
|
|
- return model.getDepth();
|
|
|
+ return settingsController.getDepth();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param depth the depth to set
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.SettingsController#setDepth(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,int)} instead
|
|
|
*/
|
|
|
public void setDepth(int depth) {
|
|
|
- model.setDepth(depth);
|
|
|
+ settingsController.setDepth(depth);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @return the device_visualization_radius
|
|
|
+ * @deprecated
|
|
|
*/
|
|
|
- private int getDevice_visualization_radius() {
|
|
|
+ int getDevice_visualization_radius() {
|
|
|
return settingsController.getDeviceVisualizationRadius();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Adds Link to the model
|
|
|
* @param link link to add
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#addLink(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Link)} instead
|
|
|
*/
|
|
|
public void addLink(Link link){
|
|
|
- model.addConnectionNetwork(link);
|
|
|
+ networkController.addLink(link);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Removes Link from the Model
|
|
|
* @param link link to remove
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#removeLink(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Link)} instead
|
|
|
*/
|
|
|
public void removeLink(Link link){
|
|
|
- model.getConnectionNetworks().remove(link);
|
|
|
+ networkController.removeLink(link);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#getLinks(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller)} instead
|
|
|
+ */
|
|
|
public Collection<Link> getLinks(){
|
|
|
- return model.getConnectionNetworks();
|
|
|
+ return networkController.getLinks();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#addConnection(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Connection)} instead
|
|
|
+ */
|
|
|
public void addConnection(Connection connection){
|
|
|
- model.addConnection(connection);
|
|
|
+ networkController.addConnection(connection);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#removeConnection(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Connection)} instead
|
|
|
+ */
|
|
|
public void removeConnection(Connection connection){
|
|
|
- model.getConnections().remove(connection);
|
|
|
+ networkController.removeConnection(connection);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#getConnections(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller)} instead
|
|
|
+ */
|
|
|
public Collection<Connection> getConnections(){
|
|
|
- return model.getConnections();
|
|
|
+ return networkController.getConnections();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#addLinkToDevice(Link,SmartDevice)} instead
|
|
|
+ */
|
|
|
public void addLinkToDevice(Link newLink, SmartDevice smartDevice) {
|
|
|
- if(!newLink.getDevices().contains(smartDevice)){
|
|
|
- newLink.addDevice(smartDevice);
|
|
|
- smartDevice.addLink(newLink);
|
|
|
- }
|
|
|
-
|
|
|
+ networkController.addLinkToDevice(newLink, smartDevice);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#removeLinkFromDevice(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Link,SmartDevice)} instead
|
|
|
+ */
|
|
|
public void removeLinkFromDevice(Link link, SmartDevice smartDevice) {
|
|
|
- if(smartDevice!=null)
|
|
|
- smartDevice.removeLink(link);
|
|
|
- if(link!=null){
|
|
|
- link.removeDevice(smartDevice);
|
|
|
- if(link.getDevices().size()==0)
|
|
|
- deleteLink(link);
|
|
|
- }
|
|
|
+ networkController.removeLinkFromDevice(link, smartDevice);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -440,55 +355,20 @@ public class Controller {
|
|
|
* @param device device which should be added
|
|
|
* @param newRole new role of the device
|
|
|
* @return true if new role was set, false if not
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#changeRoleOfDevice(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Protocol,Connection,Port,int)} instead
|
|
|
*/
|
|
|
public boolean changeRoleOfDevice(Protocol protocol, Connection con, Port device, int newRole){
|
|
|
- if(newRole < 0 || newRole >= protocol.getNumberOfRoles()){
|
|
|
- protocol.removeDevice(device);
|
|
|
- removeDeviceFromConnection(device, con);
|
|
|
- return false;
|
|
|
- } else if(protocol.getDevicesWithRole(newRole).contains(device)){
|
|
|
- if(!con.getParticipants().contains(device))
|
|
|
- con.addSmartDevice(device);
|
|
|
- if(device.getConnection()!=con)
|
|
|
- device.setConnection(con);
|
|
|
- return true;
|
|
|
- }
|
|
|
- else{
|
|
|
- protocol.removeDevice(device);
|
|
|
- boolean added = protocol.addDeviceOfRole(device, newRole);
|
|
|
- if(added){
|
|
|
- if(!con.getParticipants().contains(device))
|
|
|
- con.addSmartDevice(device);
|
|
|
- if(device.getConnection()!=con)
|
|
|
- device.setConnection(con);
|
|
|
- return true;
|
|
|
- }else{
|
|
|
- if(con.getParticipants().contains(device))
|
|
|
- con.removeSmartDevice(device);
|
|
|
- if(device.getConnection()!=null)
|
|
|
- device.setConnection(null);
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
+ return networkController.changeRoleOfDevice(protocol, con, device, newRole);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Removes Device p from the Connection
|
|
|
* @param p Port/Device to remove
|
|
|
* @param connection connection, which should remove the device
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#removeDeviceFromConnection(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Port,Connection)} instead
|
|
|
*/
|
|
|
public void removeDeviceFromConnection(Port p, Connection connection){
|
|
|
- if(connection != null){
|
|
|
- connection.removeSmartDevice(p);
|
|
|
- connection.getProtocol().removeDevice(p);
|
|
|
- //TODO: Protocol ?
|
|
|
- if(connection.getProtocol()!=null)
|
|
|
- connection.getProtocol().removeDevice(p);
|
|
|
- if(connection.getParticipants().size() == 0)
|
|
|
- deleteConnection(connection);
|
|
|
- }
|
|
|
- if(p!=null)
|
|
|
- p.setConnection(null);
|
|
|
+ networkController.removeDeviceFromConnection(p, connection);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -497,25 +377,10 @@ public class Controller {
|
|
|
* @param connection Connection
|
|
|
* @param role new role of the device (See {@link Protocol} Roles)
|
|
|
* @return true, if the device was added
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#addDeviceToConnection(Port,Connection,int)} instead
|
|
|
*/
|
|
|
public boolean addDeviceToConnection(Port p, Connection connection, int role){
|
|
|
- if(connection.getProtocol().getDevicesWithRole(role).contains(p) || connection.getProtocol().addDeviceOfRole(p, role)){
|
|
|
- //If port already has the role, or it could be assigned - just check the fields
|
|
|
- if(!connection.getParticipants().contains(p))
|
|
|
- connection.addSmartDevice(p);
|
|
|
- if(p.getConnection()!=connection)
|
|
|
- p.setConnection(connection);
|
|
|
- return true;
|
|
|
- }else {
|
|
|
- //Device could not be added -> Remove
|
|
|
- if(p.getConnection()==connection)
|
|
|
- p.setConnection(null);
|
|
|
- if(connection.getParticipants().contains(p))
|
|
|
- connection.removeSmartDevice(p);
|
|
|
- if(connection.getProtocol().getDevices().contains(p))
|
|
|
- connection.getProtocol().removeDevice(p);
|
|
|
- return false;
|
|
|
- }
|
|
|
+ return networkController.addDeviceToConnection(p, connection, role);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -523,22 +388,10 @@ public class Controller {
|
|
|
* @param connection
|
|
|
* @param newLink
|
|
|
* @return true on successful change, false on failure & restore
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#changeLinkOfConnection(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Connection,Link)} instead
|
|
|
*/
|
|
|
public boolean changeLinkOfConnection(Connection connection, Link newLink) {
|
|
|
- if(newLink != null){
|
|
|
- connection.getLink().removeConnection(connection);
|
|
|
- connection.setLink(newLink);
|
|
|
- for(Port p:connection.getParticipants()){
|
|
|
- if(p.getOwner()!=null&& !newLink.getDevices().contains(p.getOwner())){
|
|
|
- this.addLinkToDevice(newLink, p.getOwner());
|
|
|
- }
|
|
|
- }
|
|
|
- connection.setLink(newLink);
|
|
|
- newLink.addConnection(connection);
|
|
|
- return true;
|
|
|
- }else{
|
|
|
- return false;
|
|
|
- }
|
|
|
+ return networkController.changeLinkOfConnection(connection, newLink);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -546,144 +399,60 @@ public class Controller {
|
|
|
* @param connection connection to be updated
|
|
|
* @param newConnectionClass class of new type
|
|
|
* @return newly created connection
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#changeConnectionType(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Connection,Class<? extends Connection>)} instead
|
|
|
*/
|
|
|
public Connection changeConnectionType(Connection connection, Class<? extends Connection> newConnectionClass) {
|
|
|
-
|
|
|
- Connection newCon = null;
|
|
|
- try{
|
|
|
- newCon = newConnectionClass.newInstance();
|
|
|
- newCon.setProtocol(connection.getProtocol());
|
|
|
- newCon.setLink(connection.getLink());
|
|
|
- connection.getLink().addConnection(newCon);
|
|
|
- newCon.setStatus(connection.getStatus());
|
|
|
- newCon.setPacketLossProbability(connection.getPacketLossProbability());
|
|
|
- newCon.setName(connection.getName());
|
|
|
- for (Iterator<Port> p = connection.getParticipants().iterator(); p.hasNext();) {
|
|
|
- Port type = (Port) p.next();
|
|
|
- newCon.addSmartDevice(type);
|
|
|
- type.setConnection(newCon);
|
|
|
-
|
|
|
- }
|
|
|
- }catch(Exception e){
|
|
|
- System.out.println("Error while changing protocol: "+e.toString());
|
|
|
- /**
|
|
|
- * Restore old connection on Failure
|
|
|
- */
|
|
|
- if(newCon != null){
|
|
|
- newCon.setProtocol(null);
|
|
|
- if(newCon.getLink()!=null)
|
|
|
- newCon.getLink().removeConnection(newCon);
|
|
|
- newCon.setLink(null);
|
|
|
- for (Iterator<Port> p = connection.getParticipants().iterator(); p.hasNext();) {
|
|
|
- Port type = (Port) p.next();
|
|
|
- if(type.getConnection()!=connection)
|
|
|
- type.setConnection(connection);
|
|
|
- newCon.removeSmartDevice(type);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
- if(this.getConnections().contains(connection)){
|
|
|
- this.removeConnection(connection);
|
|
|
- }
|
|
|
- this.addConnection(newCon);
|
|
|
- getControllerConfiguration().getConfigurationManager().getSelectionModel().clickedConnection.clear();
|
|
|
-
|
|
|
-
|
|
|
- connection.setLink(null);
|
|
|
- connection.setProtocol(null);
|
|
|
- connection.setStatus(Connection.TERMINATED);
|
|
|
- connection.setName("deleted");
|
|
|
- for(Port p: newCon.getParticipants()){
|
|
|
- connection.removeSmartDevice(p);
|
|
|
- }
|
|
|
-
|
|
|
- notifyObservers();
|
|
|
-
|
|
|
- return newCon;
|
|
|
+ return networkController.changeConnectionType(connection, newConnectionClass);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Deletes the network model, removes all Devices, Connections and Links
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#deleteNetworkModel(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller)} instead
|
|
|
*/
|
|
|
public void deleteNetworkModel(){
|
|
|
- /**
|
|
|
- * Devices which should be deleted
|
|
|
- */
|
|
|
- LinkedList<SmartDevice> devicesToDelete = new LinkedList<SmartDevice>(model.getDevices());
|
|
|
- for(SmartDevice d: devicesToDelete)
|
|
|
- deleteSmartDevice(d);
|
|
|
- devicesToDelete.clear();
|
|
|
- /**
|
|
|
- * Connections which should be deleted
|
|
|
- */
|
|
|
- LinkedList<Connection> connectionsToDelete = new LinkedList<Connection>(model.getConnections());
|
|
|
- for(Connection c: connectionsToDelete)
|
|
|
- deleteConnection(c);
|
|
|
- connectionsToDelete.clear();
|
|
|
- /**
|
|
|
- * Links which should be delted
|
|
|
- */
|
|
|
- LinkedList<Link> linksToDelete = new LinkedList<Link>(model.getConnectionNetworks());
|
|
|
- for(Link l: model.getConnectionNetworks())
|
|
|
- deleteLink(l);
|
|
|
- linksToDelete.clear();
|
|
|
- /**
|
|
|
- * Update the GUI
|
|
|
- */
|
|
|
- notifyObservers();
|
|
|
+ networkController.deleteNetworkModel();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Deletes the Connection c and all references
|
|
|
* @param c Connection to be deleted
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#deleteConnection(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Connection)} instead
|
|
|
*/
|
|
|
public void deleteConnection(Connection c) {
|
|
|
- if(c == null)return;
|
|
|
- LinkedList<Port> ports = new LinkedList<Port>(c.getParticipants());
|
|
|
- for(Port p:ports)
|
|
|
- removeDeviceFromConnection(p, c);
|
|
|
- ports.clear();
|
|
|
- removeConnectionFromLink(c, c.getLink());
|
|
|
- c.setStatus(Connection.TERMINATED);
|
|
|
- removeConnection(c);
|
|
|
+ networkController.deleteConnection(c);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Deletes Link l and all references
|
|
|
* @param l Link to be deleted
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#deleteLink(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Link)} instead
|
|
|
*/
|
|
|
public void deleteLink(Link l) {
|
|
|
- if(l==null)return;
|
|
|
- LinkedList<SmartDevice> devices = new LinkedList<SmartDevice>(l.getDevices());
|
|
|
- for(SmartDevice d : devices)
|
|
|
- removeLinkFromDevice(l, d);
|
|
|
- devices.clear();
|
|
|
- LinkedList<Connection> connections = new LinkedList<Connection>(l.getConnections());
|
|
|
- for(Connection c:connections)
|
|
|
- removeConnectionFromLink(c,l);
|
|
|
- connections.clear();
|
|
|
- l.getPackets().clear();
|
|
|
- removeLink(l);
|
|
|
+ networkController.deleteLink(l);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Removes Connection from Link
|
|
|
* @param c Connection to be removed
|
|
|
* @param l Link to be removed
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#removeConnectionFromLink(Connection,Link)} instead
|
|
|
*/
|
|
|
public void removeConnectionFromLink(Connection c, Link l) {
|
|
|
- if(c!=null && c.getLink()==l){
|
|
|
- c.setLink(null);
|
|
|
- }
|
|
|
- if(l!=null){
|
|
|
- l.removeConnection(c);
|
|
|
- }
|
|
|
+ networkController.removeConnectionFromLink(c, l);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Changes the type of the link to new type, specified by the given Link-class
|
|
|
+ * @param oldLink oldLink, whose attributes will b copied to the new Link
|
|
|
+ * @param newType Type/Class of the new Link
|
|
|
+ * @return newly created Link, null on failure/error
|
|
|
+ * @deprecated Use {@link de.tu_darmstadt.tk.SmartHomeNetworkSim.control.NetworkController#changeLinkType(de.tu_darmstadt.tk.SmartHomeNetworkSim.control.Controller,Link,Class<? extends Link>)} instead
|
|
|
+ */
|
|
|
+ public Link changeLinkType(Link oldLink, Class<? extends Link> newType) {
|
|
|
+ return networkController.changeLinkType(oldLink, newType);
|
|
|
}
|
|
|
|
|
|
+ // TODO: Maybe Settings controller ?
|
|
|
/**
|
|
|
* Reset Simulation
|
|
|
*
|
|
@@ -695,7 +464,7 @@ public class Controller {
|
|
|
if(p.getLastTrigger()>timestep)
|
|
|
p.setLastTrigger(timestep);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Returns the Simulation Manager of the Program
|
|
|
* @return Simulation Manager
|
|
@@ -703,42 +472,4 @@ public class Controller {
|
|
|
public SimulationManager getSimulationManager() {
|
|
|
return model.getSim();
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * Changes the type of the link to new type, specified by the given Link-class
|
|
|
- * @param oldLink oldLink, whose attributes will b copied to the new Link
|
|
|
- * @param newType Type/Class of the new Link
|
|
|
- * @return newly created Link, null on failure/error
|
|
|
- */
|
|
|
- public Link changeLinkType(Link oldLink, Class<? extends Link> newType) {
|
|
|
- if(newType == null)
|
|
|
- return null;
|
|
|
- /**
|
|
|
- * New Link which was created
|
|
|
- */
|
|
|
- Link newLink = null;
|
|
|
- try{
|
|
|
- newLink = newType.newInstance();
|
|
|
- }catch(Exception e){
|
|
|
- return null;
|
|
|
- }
|
|
|
- if (newLink == null) {
|
|
|
- return null;
|
|
|
- }else {
|
|
|
- // Set old Name
|
|
|
- newLink.setName(oldLink.getName());
|
|
|
- // Add to Mode
|
|
|
- if(getLinks().contains(oldLink)){
|
|
|
- removeLink(oldLink);
|
|
|
- addLink(newLink);
|
|
|
- }
|
|
|
- // Add devices to the new Link
|
|
|
- LinkedList<SmartDevice> devices= new LinkedList<>(oldLink.getDevices());
|
|
|
- for(SmartDevice device:devices){
|
|
|
- removeLinkFromDevice(oldLink, device);
|
|
|
- addLinkToDevice(newLink, device);
|
|
|
- }
|
|
|
- return newLink;
|
|
|
- }
|
|
|
- }
|
|
|
}
|