浏览代码

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons

jess 8 年之前
父节点
当前提交
3ff11af8d1

+ 0 - 6
src/ui/controller/Control.java

@@ -500,9 +500,6 @@ public class Control {
 	public void calculateStateForCurrentTimeStep() {
 		simulationManager.reset();
 		simulationManager.calculateStateForTimeStep(model.getCurIteration());
-		if (model.getIsSimulation()) {
-			runAlgorithm(model, this);
-		}
 	}
 
 	/**
@@ -514,9 +511,6 @@ public class Control {
 	public void calculateStateForTimeStep(int x) {
 		simulationManager.reset();
 		simulationManager.calculateStateForTimeStep(x);
-		if (model.getIsSimulation()) {
-			runAlgorithm(model, this);
-		}
 	}
 
 	/**

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

@@ -28,7 +28,6 @@ public class SimulationManager {
 	private int timeStep;
 	private boolean simMode;
 	private HashMap<Integer, Float> tagTable = new HashMap<Integer, Float>();
-
 	/**
 	 * Constructor.
 	 * 
@@ -90,6 +89,7 @@ public class SimulationManager {
 			}
 		}
 		canvas.repaint();
+		//printNet();
 	}
 
 	/**
@@ -159,7 +159,7 @@ public class SimulationManager {
 								if(((HolonSwitch)tmp).getState(timeStep)){
 									producers.add(tmp);
 								}
-							}else{
+							}else if(!(tmp instanceof CpsUpperNode)){
 								producers.add(tmp);
 							}
 						}
@@ -198,15 +198,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 +396,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 +446,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 +514,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);
 			}
 		}
 	}

+ 3 - 1
src/ui/view/GUI.java

@@ -1306,7 +1306,6 @@ public class GUI<E> implements CategoryListener {
 		canvas.addMouseListener(new MouseAdapter() {
 			@Override
 			public void mousePressed(MouseEvent e) {
-				selectedElements.clear();
 				holonEleNamesDisplayed = Languages.getLanguage()[25];
 				// If any empty space is clicked
 				if (temp == null || temp.getID() != model.getSelectedObjectID()) {
@@ -1615,6 +1614,9 @@ public class GUI<E> implements CategoryListener {
 			@Override
 			public void stateChanged(ChangeEvent e) {
 				int i = model.getCurIteration();
+				if (model.getIsSimulation()) {
+					controller.runAlgorithm(model, controller);
+				}
 				controller.calculateStateForTimeStep(i);
 				contentPane.updateUI();
 				unitGraph.repaint();

+ 15 - 12
src/ui/view/MyCanvas.java

@@ -111,6 +111,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 	 */
 	public MyCanvas(Model mod, Control control) {
 		this.add(objectTT);
+		objectTT.setVisible(false);
 		this.controller = control;
 		this.model = mod;
 
@@ -435,10 +436,10 @@ 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){
+				} else if (con.getCapacity() == -2) {
 					maxCap = "???";
 				} else {
 					maxCap = String.valueOf(con.getCapacity());
@@ -479,8 +480,7 @@ 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) {
@@ -516,7 +516,6 @@ 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');
@@ -642,7 +641,13 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 				controller.addTextToConsole(", ID:", Color.BLACK, 12, false, false, false);
 				controller.addTextToConsole("" + cps.getID(), Color.RED, 12, true, false, true);
 				dragging = true;
-				controller.setSelectedObjectID(tempCps.getID());
+				if (e.isControlDown() && tempCps != null) {
+					if (model.getSelectedCpsObjects().contains(tempCps)) {
+						controller.deleteSelectedObject(tempCps);
+					} else {
+						controller.addSelectedObject(tempCps);
+					}
+				}
 				// If drawing an Edge (CTRL down)
 				if (tempCps.getClass() == HolonObject.class) {
 					HolonObject tempObj = ((HolonObject) tempCps);
@@ -854,20 +859,18 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		// Everytghing for the tooltip :)
 		boolean on = false;
 		for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
-
 			cx = cps.getPosition().x;
 			cy = cps.getPosition().y;
 			if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
-
 				objectTT.setLocation(cx, cy + controller.getScale());
 				objectTT.setTipText(cps.getName() + ", " + cps.getID());
-
 				on = true;
 			}
 		}
-		if (!on) {
-			objectTT.setTipText("");
-			objectTT.setLocation(-200, -200);
+		if (on) {
+			objectTT.setVisible(true);
+		} else {
+			objectTT.setVisible(false);
 		}
 	}
 

+ 5 - 3
src/ui/view/UpperNodeCanvas.java

@@ -122,6 +122,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 	 */
 	public UpperNodeCanvas(Model mod, Control control, CpsUpperNode UpperNode, String parentPath) {
 		//this.add(objectTT);
+		objectTT.setVisible(false);
 		this.controller = control;
 		this.model = mod;
 		this.upperNode = UpperNode;
@@ -1114,9 +1115,10 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 			count++;
 		}
 
-		if (!on) {
-			objectTT.setTipText("");
-			// objectTT.setLocation(-200, -200);
+		if (on) {
+			objectTT.setVisible(true);
+		} else {
+			objectTT.setVisible(false);
 		}
 
 	}