Переглянути джерело

Improves BoundingBoxes, better distinction between Link and Device

Andreas T. Meyer-Berg 6 роки тому
батько
коміт
7e157790d2

+ 9 - 5
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/VisualisationInteractor.java

@@ -509,7 +509,12 @@ public class VisualisationInteractor implements MouseInputListener,
 		for (SmartDevice d : model.getDevices()) {
 			if (Math.abs(d.getX() - x) < config.getDeviceVisualizationRadius()
 					&& Math.abs(d.getY() - y) < config.getDeviceVisualizationRadius()) {
-				return d;
+				/**
+				 * correct distance / radius from the smartDevice
+				 */
+				int radius = (int) Math.floor(Math.sqrt((d.getX() - x)*(d.getX() - x)+(d.getY() - y)*(d.getY() - y)));
+				if(radius <= config.getDeviceVisualizationRadius())
+					return d;
 			}
 		}
 		return null;
@@ -636,6 +641,8 @@ public class VisualisationInteractor implements MouseInputListener,
 	}
 
 	private Link getLinkVisualizationAtPosition(int x, int y) {
+		if(!config.isShowLinks())
+			return null;
 		// Check is device is inside visualization radius
 		/**
 		 * Radius of the device
@@ -653,7 +660,7 @@ public class VisualisationInteractor implements MouseInputListener,
 				// On which part of Ring ?
 				//Outside of device ?
 				int realDistance = (int)Math.round(Math.sqrt((d.getX() - x)*(d.getX() - x)+(d.getY() - y)*(d.getY() - y)));
-				if (realDistance > smallRadius && realDistance <= radius && !d.getLinks().isEmpty()) {
+				if (realDistance >= smallRadius && realDistance <= radius && !d.getLinks().isEmpty()) {
 					/**
 					 * Angle of this point. Counterclockwise, starting at 3 o' clock position
 					 */
@@ -720,8 +727,6 @@ public class VisualisationInteractor implements MouseInputListener,
 		// Just execute if Mouse Position is on the Panel
 		if (mousePos != null) {			
 			if (clickedOn == null) {
-				
-				//TODO: EditLink
 				if(clickedLink == null){
 					itemCreateLink.setText("Create Link");
 					itemCreateLink.setEnabled(false);
@@ -773,7 +778,6 @@ public class VisualisationInteractor implements MouseInputListener,
 					rightClickMenu.remove(itemEditConnection);
 					rightClickMenu.add(itemCreateConnection,editCreateConnectionIndex);
 				}
-				//TODO EditLink
 				itemCreateLink.setText("Create Link");
 				if(controller.getControllerConfiguration().getConfigurationManager().getSelectionModel().selectedDevices.contains(clickedOn)){
 					itemDeleteSelected.setEnabled(true);