Prechádzať zdrojové kódy

spezieller state für edges wenn mit uppernode verbunden

dominik.rieder 7 rokov pred
rodič
commit
dd28b5b59c

+ 12 - 7
src/classes/CpsEdge.java

@@ -31,11 +31,13 @@ public class CpsEdge {
 	boolean isWorking;
 	
 	/*
-	 * Is true when a Connection to an Group Object, is connected inside the Group. 
+	 * 0 = not connected to an upper node
+	 * 1 = connected to an uppder node & connected inside
+	 * 2 = connected to an upper node but not inside 
 	 * Is false when not
 	 */
 	@Expose
-	boolean isConnected;
+	int isConnected;
 	// for internal use --> flow of electricity (simulation state)
 	ArrayList<Integer> tags;
 	// for internal use --> flow of electricity (simulation state)
@@ -84,7 +86,7 @@ public class CpsEdge {
 		this.maxCapacity = maxCap;
 		flow = 0;
 		isWorking = true;
-		isConnected = true;
+		isConnected = 0;
 		pseudoTags = new ArrayList<Integer>();
 	}
 
@@ -138,10 +140,10 @@ public class CpsEdge {
 	 */
 
 	public void calculateState(boolean simMode) {
-		if (flow > maxCapacity && maxCapacity != -1) {
+		if (flow > maxCapacity && maxCapacity != -1 && maxCapacity != -2) {
 			isWorking = false;
 		} else {
-			if (!simMode && (flow <= maxCapacity || maxCapacity == -1)) {
+			if (!simMode && (flow <= maxCapacity || maxCapacity == -1 || maxCapacity == -2)) {
 				isWorking = true;
 			}
 		}
@@ -276,12 +278,15 @@ public class CpsEdge {
 		}
 	}
 	
-	public boolean getConnected(){
+	public int getConnected(){
 		return isConnected;
 	}
 	
-	public void setConnected(boolean state){
+	public void setConnected(int state){
 		isConnected = state;
+		if(state == 1){
+			maxCapacity = -2;
+		}
 	}
 
 }

+ 3 - 3
src/ui/controller/SimulationManager.java

@@ -450,11 +450,11 @@ public class SimulationManager {
 					sN = buildSubNet(b, visited, sN);
 				}
 				if(a instanceof CpsUpperNode && a.getID() != cps.getID()){
-					edge.setConnected(false);
+					edge.setConnected(2);
 					checkForConnectedStates(b, (CpsUpperNode)a, edge);
 				}
 				if(b instanceof CpsUpperNode && b.getID() != cps.getID()){
-					edge.setConnected(false);
+					edge.setConnected(2);
 					checkForConnectedStates(a, (CpsUpperNode)b, edge);
 				}
 			}
@@ -587,7 +587,7 @@ public class SimulationManager {
 				if(tmp instanceof CpsUpperNode){
 					checkForConnectedStates(cps, (CpsUpperNode)tmp, theEdge);
 				}else{
-					theEdge.setConnected(true);
+					theEdge.setConnected(1);
 					break;
 				}
 			}

+ 13 - 5
src/ui/view/MyCanvas.java

@@ -417,7 +417,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		for (CpsEdge con : model.getEdgesOnCanvas()) {
 			if (con.getA().getID() != model.getSelectedObjectID() && con.getB().getID() != model.getSelectedObjectID()
 					&& con != edgeHighlight) {
-				if (con.getConnected()) {
+				if (con.getConnected() == 0) {
 					if (con.getState()) {
 						g2.setColor(Color.GREEN);
 						if (con.getCapacity() != -1) {
@@ -435,14 +435,16 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 						con.getA().getPosition().y + controller.getScaleDiv2(),
 						con.getB().getPosition().x + controller.getScaleDiv2(),
 						con.getB().getPosition().y + controller.getScaleDiv2());
-
+				
 				if (con.getCapacity() == -1) {
 					maxCap = Character.toString('\u221e');
+				} else if (con.getCapacity() == -2){
+					maxCap = "???";
 				} else {
 					maxCap = String.valueOf(con.getCapacity());
 				}
 				if (showedInformation[0]) {
-					if (con.getConnected()) {
+					if (con.getConnected() == 0 || con.getConnected() == 1) {
 						g2.drawString(con.getFlow() + "/" + maxCap,
 								(con.getA().getPosition().x + con.getB().getPosition().x) / 2
 										+ controller.getScaleDiv2(),
@@ -477,14 +479,17 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 							con.getA().getPosition().y + controller.getScaleDiv2(),
 							con.getB().getPosition().x + controller.getScaleDiv2(),
 							con.getB().getPosition().y + controller.getScaleDiv2());
-
+					
+					
 					if (con.getCapacity() == -1) {
 						maxCap = Character.toString('\u221e');
+					} else if (con.getCapacity() == -2) {
+						maxCap = "???";
 					} else {
 						maxCap = String.valueOf(con.getCapacity());
 					}
 					if (showedInformation[0]) {
-						if (con.getConnected()) {
+						if (con.getConnected() == 0 || con.getConnected() == 1) {
 							g2.drawString(con.getFlow() + "/" + maxCap,
 									(con.getA().getPosition().x + con.getB().getPosition().x) / 2
 											+ controller.getScaleDiv2(),
@@ -511,9 +516,12 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 					edgeHighlight.getA().getPosition().y + controller.getScaleDiv2(),
 					edgeHighlight.getB().getPosition().x + controller.getScaleDiv2(),
 					edgeHighlight.getB().getPosition().y + controller.getScaleDiv2());
+			
 
 			if (edgeHighlight.getCapacity() == -1) {
 				maxCap = Character.toString('\u221e');
+			} else if (edgeHighlight.getCapacity() == -2) {
+				maxCap = "???";
 			} else {
 				maxCap = String.valueOf(edgeHighlight.getCapacity());
 			}

+ 13 - 4
src/ui/view/UpperNodeCanvas.java

@@ -462,7 +462,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 		for (CpsEdge con : upperNode.getNodeEdges()) {
 			if (con.getA().getID() != model.getSelectedObjectID() && con.getB().getID() != model.getSelectedObjectID()
 					&& con != edgeHighlight) {
-				if(con.getConnected()){
+				if(con.getConnected() == 0){
 					if (con.getState()) {
 						g2.setColor(Color.GREEN);
 						if (con.getCapacity() != -1) {
@@ -481,13 +481,16 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 						con.getB().getPosition().x + controller.getScaleDiv2(),
 						con.getB().getPosition().y + controller.getScaleDiv2());
 
+				
 				if (con.getCapacity() == -1) {
 					maxCap = Character.toString('\u221e');
+				} else if (con.getCapacity() == -2) {
+					maxCap = "???";
 				} else {
 					maxCap = String.valueOf(con.getCapacity());
 				}
 				if (showedInformation[0]) {
-					if(con.getConnected()){
+					if(con.getConnected() == 0 || con.getConnected() == 1){
 						g2.drawString(con.getFlow() + "/" + maxCap,
 								(con.getA().getPosition().x + con.getB().getPosition().x) / 2 + controller.getScaleDiv2(),
 								(con.getA().getPosition().y + con.getB().getPosition().y) / 2 + controller.getScaleDiv2());
@@ -519,13 +522,16 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 							con.getB().getPosition().x + controller.getScaleDiv2(),
 							con.getB().getPosition().y + controller.getScaleDiv2());
 
+					
 					if (con.getCapacity() == -1) {
 						maxCap = Character.toString('\u221e');
+					} else if (con.getCapacity() == -2) {
+						maxCap = "???";
 					} else {
 						maxCap = String.valueOf(con.getCapacity());
 					}
 					if (showedInformation[0]) {
-						if(con.getConnected()){
+						if(con.getConnected() == 0 || con.getConnected() == 1){
 							g2.drawString(con.getFlow() + "/" + maxCap,
 									(con.getA().getPosition().x + con.getB().getPosition().x) / 2
 										+ controller.getScaleDiv2(),
@@ -552,9 +558,12 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 					edgeHighlight.getA().getPosition().y + controller.getScaleDiv2(),
 					edgeHighlight.getB().getPosition().x + controller.getScaleDiv2(),
 					edgeHighlight.getB().getPosition().y + controller.getScaleDiv2());
-
+			
+			
 			if (edgeHighlight.getCapacity() == -1) {
 				maxCap = Character.toString('\u221e');
+			} else if (edgeHighlight.getCapacity() == -2) {
+				maxCap = "???";
 			} else {
 				maxCap = String.valueOf(edgeHighlight.getCapacity());
 			}