dominik.rieder 8 years ago
parent
commit
8e39f5a524
1 changed files with 24 additions and 19 deletions
  1. 24 19
      src/ui/controller/SimulationManager.java

+ 24 - 19
src/ui/controller/SimulationManager.java

@@ -90,6 +90,7 @@ public class SimulationManager {
 			}
 		}
 		canvas.repaint();
+		printNet();
 	}
 
 	/**
@@ -159,7 +160,7 @@ public class SimulationManager {
 								if(((HolonSwitch)tmp).getState(timeStep)){
 									producers.add(tmp);
 								}
-							}else{
+							}else if(!(tmp instanceof CpsUpperNode)){
 								producers.add(tmp);
 							}
 						}
@@ -198,15 +199,18 @@ public class SimulationManager {
 									edge.addTag(tag);
 								}
 							}
-							for(Integer tag: tmp.getTag()){
-								if(!(edge.getTags().contains(tag)) && tagTable.get(tag) != null && !(edge.getPseudoTags().contains(tag))){
-									edge.setFlow(edge.getFlow() + tagTable.get(tag));
-									edge.addPseudoTag(tag);
-									changedEdges.add(edge);
+							// uppernodes do not spread energy
+							if(!(tmp instanceof CpsUpperNode)){
+								for(Integer tag: tmp.getTag()){
+									if(!(edge.getTags().contains(tag)) && tagTable.get(tag) != null && !(edge.getPseudoTags().contains(tag))){
+										edge.setFlow(edge.getFlow() + tagTable.get(tag));
+										edge.addPseudoTag(tag);
+										changedEdges.add(edge);
+									}
 								}
 							}
 							edge.calculateState(true);
-							if(edge.getState()){
+							if(edge.getState() && !(tmp instanceof CpsUpperNode)){
 								tmp.addAllPseudoTags(cps.getTag());
 								if(!newNodes.contains(tmp)){
 								newNodes.add(tmp);
@@ -393,15 +397,15 @@ public class SimulationManager {
 		if (objectsToHandle.size() > 0) {
 			while (!end) {
 				cps = objectsToHandle.get(i);
-				SubNet singleSubNet = new SubNet(new ArrayList<HolonObject>(), new ArrayList<CpsEdge>(),
-						new ArrayList<HolonSwitch>());
-				singleSubNet = buildSubNet(cps, new ArrayList<Integer>(), singleSubNet);
-				if (singleSubNet.getObjects().size() != 0) {
-					subNets.add(singleSubNet);
-				}
-				if (0 == objectsToHandle.size()) {
-					end = true;
-				}
+					SubNet singleSubNet = new SubNet(new ArrayList<HolonObject>(), new ArrayList<CpsEdge>(),
+							new ArrayList<HolonSwitch>());
+					singleSubNet = buildSubNet(cps, new ArrayList<Integer>(), singleSubNet);
+					if (singleSubNet.getObjects().size() != 0) {
+						subNets.add(singleSubNet);
+					}
+					if (0 == objectsToHandle.size()) {
+						end = true;
+					}
 			}
 		}
 	}
@@ -443,10 +447,10 @@ public class SimulationManager {
 						sN.getEdges().add(edge);
 					}
 				}
-				if (!visited.contains(a.getID()) && legitState(cps)) {
+				if (!visited.contains(a.getID()) && legitState(cps) && !(a instanceof CpsUpperNode)) {
 					sN = buildSubNet(a, visited, sN);
 				}
-				if (!visited.contains(b.getID()) && legitState(cps)) {
+				if (!visited.contains(b.getID()) && legitState(cps) && !(b instanceof CpsUpperNode)) {
 					sN = buildSubNet(b, visited, sN);
 				}
 				if(a instanceof CpsUpperNode && a.getID() != cps.getID()){
@@ -511,9 +515,10 @@ public class SimulationManager {
 	 */
 	public void copyObjects(ArrayList<AbstractCpsObject> toCopy) {
 		for (AbstractCpsObject cps : toCopy) {
-			objectsToHandle.add(cps);
 			if(cps instanceof CpsUpperNode){
 				copyObjects(((CpsUpperNode)cps).getNodes());
+			}else{
+				objectsToHandle.add(cps);
 			}
 		}
 	}