Browse Source

New OutlinerWindow

Tom Troppmann 5 years ago
parent
commit
f2c0ba972e

+ 9 - 0
src/classes/CpsEdge.java

@@ -275,6 +275,15 @@ public class CpsEdge {
         }
     }
     
+    /**
+     * Check if a CpsEdge is Connected to the AbstractCpsObject.
+     * @param holonObject the AbstractCpsObject to check.
+     * @return true if either a or b is the AbstractCpsObject to check.
+     */
+    public boolean isConnectedTo(AbstractCpsObject holonObject)
+    {
+    	return (holonObject.equals(a) || holonObject.equals(b));
+    }
     @Override
     public String toString(){
     	String A = (a == null) ? "null" : a.getName();

+ 1 - 2
src/classes/HolonElement.java

@@ -256,8 +256,7 @@ public class HolonElement implements LocalMode, GraphEditable{
     /**
      * Get the energyPerElement currently(at given time step) available
      */
-    public float getAvailableEnergyAt(int timestep) {
-    	System.out.println("getAvailableEnergyAt");
+    public float getEnergyAtTimeStep(int timestep) {
     	return amount * energyPerElement * this.curveSample[IndexTranslator.getEffectiveIndex(this, timestep)];
     }
 

+ 72 - 13
src/classes/HolonObject.java

@@ -162,15 +162,6 @@ public class HolonObject extends AbstractCpsObject {
     
     
 
-	public HolonElement getMinimalConsumingElement() {
-		HolonElement min = elements.get(0);
-		for (HolonElement e : elements) {
-			if (e.getOverallEnergy() < 0 && e.getOverallEnergy() > min.getOverallEnergy()) {
-				min = e;
-			}
-		}
-		return min;
-	}
     
     /**
      * Getter for the current energy at a given timestep.
@@ -388,17 +379,17 @@ public class HolonObject extends AbstractCpsObject {
     /**
      * Calculates the minimumEnergy Needed to turn on atleast on device
      * of this HolonObject
-     * @param x Timestep of the calculation
+     * @param timestep Timestep of the calculation
      * @return minEnergy, -inf if no Devices are consuming power
      */
-    public float getMinEnergy(int x) {
+    public float getMinEnergy(int timestep) {
         if (getElements().size() == 0) {
             return Float.NEGATIVE_INFINITY;
         }
         float minConsum = Float.NEGATIVE_INFINITY;
         for (HolonElement e : getElements()) {
             if (e.isActive()) {
-                float overallEnergy = e.getOverallEnergyAtTimeStep(x);
+                float overallEnergy = e.getOverallEnergyAtTimeStep(timestep);
                 if (minConsum < 0 && (overallEnergy > minConsum && overallEnergy < 0)) {
                     minConsum = overallEnergy;
                 } 
@@ -406,7 +397,75 @@ public class HolonObject extends AbstractCpsObject {
         }
         return minConsum;
     }
-
+  
+    
+    
+    //New Methods:
+    /**
+     * This Method returns the smallest consuming HolonElement that is ACTIVE.
+     * If the HolonObject has no Consumer its return null. 
+     * @param timestep is the TimeStep to compare the HolonElements.
+     * @return The smallest consuming HolonElement or null.
+     */
+    public HolonElement getMinimumConsumingElement(int timestep){
+    	return getElements().stream().filter(element -> element.isActive() && (element.getEnergyAtTimeStep(timestep) < 0) ).max((lhs,rhs) -> Float.compare(lhs.getEnergyAtTimeStep(timestep), rhs.getEnergyAtTimeStep(timestep))).orElse(null);
+    }
+    /**
+     * This Method returns the smallest consuming HolonElement'Energy that is ACTIVE.
+     * If the HolonObject has no Consumer its return 0. 
+     * @param timestep is the TimeStep to compare the HolonElements.
+     * @return The smallest consuming HolonElement or 0.
+     */
+    public float getMinimumConsumingElementEnergy(int timestep){
+    	return getElements().stream().filter(element -> element.isActive() && (element.getEnergyAtTimeStep(timestep) < 0) ).map(element -> -element.getEnergyAtTimeStep(timestep)).min((lhs,rhs) ->Float.compare(lhs, rhs)).orElse(0.0f);
+    }
+    /** 
+     * This Method returns the Energy of a HolonObject. Its sums all Energies from the HolonElements of the HolonObject that are ACTIVE.
+     * If the HolonObject have no HolonElement its return 0;
+     * Is the returned Energy negative then the HolonObject need Energy because its consuming HolonElements need more Energy then the producing HolonElements.
+     * Is the returned Energy positive its reversed.
+     * @param timestep is the TimeStep to compare the HolonElements.
+     * @return The Energy of the HolonObject.
+     */
+    public float getEnergyAtTimeStep(int timestep)
+    {
+    	return getElements().stream().filter(element -> element.isActive()).map(element -> element.getEnergyAtTimeStep(timestep)).reduce(0.0f, (a, b) -> a + b);
+    }
+    /** 
+     * This Method returns the Energy that all HolonElements from the HolonObject produce by itself. Its sums all Energies from the HolonElements of the HolonObject that are ACTIVE and are Producer.
+     * If the HolonObject have no HolonElement its return 0;
+     * @param timestep is the TimeStep to compare the HolonElements.
+     * @return The Energy of the producing HolonElements.
+     */
+    public float getEnergySelfProducingFromProducingElements(int timestep) {
+    	return getElements().stream().filter(element -> element.isActive() && (element.getEnergyAtTimeStep(timestep) > 0)).map(element -> element.getEnergyAtTimeStep(timestep)).reduce(0.0f, (a, b) -> a + b);
+    }
+    /** 
+     * This Method returns the Energy of all HolonElements from the HolonObject that are consuming. Its sums all Energies from the HolonElements of the HolonObject that are ACTIVE and are Consumer.
+     * If the HolonObject have no HolonElement its return 0;
+     * @param timestep is the TimeStep to compare the HolonElements.
+     * @return The Energy of the consuming HolonElements.
+     */
+    public float getEnergyNeededFromConsumingElements(int timestep) {
+    	return getElements().stream().filter(element -> element.isActive() && (element.getEnergyAtTimeStep(timestep) < 0)).map(element -> -element.getEnergyAtTimeStep(timestep)).reduce(0.0f, (a, b) -> a + b);
+    }
+    
+    /**
+     * This Method calculate the amount of HolonElements that are consuming Energy and are ACTIVE.
+     * @param timestep is the TimeStep to compare the HolonElements.
+     * @return The amount of HolonElements that are consuming Energy.
+     */
+    public int countConsumingElements(int timestep) {
+    	return (int) getElements().stream().filter(element -> element.isActive() && (element.getEnergyAtTimeStep(timestep) < 0)).count();
+    }
+    /**
+     * This Method calculate the amount of HolonElements that are producing Energy and are ACTIVE.
+     * @param timestep is the TimeStep to compare the HolonElements.
+     * @return The amount of HolonElements that are producing Energy.
+     */
+    public int countProducingElements(int timestep) {
+    	return (int) getElements().stream().filter(element -> element.isActive() && (element.getEnergyAtTimeStep(timestep) > 0)).count();
+    }
     /**
      * Get the Color.
      *

+ 1 - 0
src/ui/controller/CanvasController.java

@@ -403,4 +403,5 @@ public class CanvasController {
 		model.setCanvasImageWidth(width);
 		model.setCanvasImageHeight(height);
 	}
+	
 }

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

@@ -1060,4 +1060,5 @@ public class Control {
 	public void setFairnessModel(short fairnessModel) {
 		globalController.setFairnessModel(fairnessModel);
 	}
+	
 }

+ 6 - 6
src/ui/controller/HolonCanvasController.java

@@ -103,8 +103,8 @@ public class HolonCanvasController {
 		for (AbstractCpsObject obj : objects) {
 			if (obj instanceof HolonObject) {
 				for (HolonElement ele : ((HolonObject) obj).getElements()) {
-                    if (ele.getAvailableEnergyAt(tStep) > 0 && ele.isActive()) {
-                        val += ele.getAvailableEnergyAt(tStep) * ele.getAmount();
+                    if (ele.getEnergyAtTimeStep(tStep) > 0 && ele.isActive()) {
+                        val += ele.getEnergyAtTimeStep(tStep) * ele.getAmount();
                     }
                 }
 				if (val > 0)
@@ -134,8 +134,8 @@ public class HolonCanvasController {
 		for (AbstractCpsObject obj : objects) {
 			if (obj instanceof HolonObject) {
 				for (HolonElement ele : ((HolonObject) obj).getElements()) {
-                    if (ele.getAvailableEnergyAt(tStep) < 0 && ele.isActive()) {
-                        val += ele.getAvailableEnergyAt(tStep) * ele.getAmount();
+                    if (ele.getEnergyAtTimeStep(tStep) < 0 && ele.isActive()) {
+                        val += ele.getEnergyAtTimeStep(tStep) * ele.getAmount();
                     }
                 }
 			} else if (obj instanceof CpsUpperNode) {
@@ -151,8 +151,8 @@ public class HolonCanvasController {
 		for (AbstractCpsObject obj : objects) {
 			if (obj instanceof HolonObject) {
 				for (HolonElement ele : ((HolonObject) obj).getElements()) {
-                    if (ele.getAvailableEnergyAt(tStep) > 0 && ele.isActive()) {
-                        val += ele.getAvailableEnergyAt(tStep) * ele.getAmount();
+                    if (ele.getEnergyAtTimeStep(tStep) > 0 && ele.isActive()) {
+                        val += ele.getEnergyAtTimeStep(tStep) * ele.getAmount();
                     }
                 }
 			} else if (obj instanceof CpsUpperNode) {

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

@@ -377,7 +377,7 @@ public class SimulationManager {
 				// calculations)
 				if (holonEl.isFlexible() && holonEl.isActive()) {
 					float energyAvailableSingle = holonEl
-							.getAvailableEnergyAt(timestep);
+							.getEnergyAtTimeStep(timestep);
 					float energyAvailableMultiple = energyAvailableSingle
 							* holonEl.getAmount();
 

+ 54 - 0
src/ui/model/Model.java

@@ -103,6 +103,20 @@ public class Model {
      * list.
      */
     private ArrayList<CpsEdge> edgesOnCanvas;
+    
+    
+    private ArrayList<HolonObject> holonObjectsOnCanvas = new ArrayList<HolonObject>();
+    private ArrayList<CpsNode> nodesOnCanvas= new ArrayList<CpsNode>();
+    private ArrayList<HolonSwitch> switchsOnCanvas= new ArrayList<HolonSwitch>();
+    
+    
+    
+    
+    
+    
+    
+    
+    
     /*
      * Array for all Listeners
      */
@@ -1023,4 +1037,44 @@ public class Model {
     public void setHashcodeMap(HashMap<Integer, CpsUpperNode> hashcodeMap) {
         this.hashcodeMap = hashcodeMap;
     }
+
+    
+    
+    
+    
+    
+	public ArrayList<HolonSwitch> getSwitchsOnCanvas() {
+		return switchsOnCanvas;
+	}
+
+	public void setSwitchsOnCanvas(ArrayList<HolonSwitch> switchsOnCanvas) {
+		this.switchsOnCanvas = switchsOnCanvas;
+	}
+
+	public ArrayList<CpsNode> getNodesOnCanvas() {
+		return nodesOnCanvas;
+	}
+
+	public void setNodesOnCanvas(ArrayList<CpsNode> nodesOnCanvas) {
+		this.nodesOnCanvas = nodesOnCanvas;
+	}
+
+	public ArrayList<HolonObject> getHolonObjectsOnCanvas() {
+		return holonObjectsOnCanvas;
+	}
+
+	public void setHolonObjectsOnCanvas(ArrayList<HolonObject> holonObjectsOnCanvas) {
+		this.holonObjectsOnCanvas = holonObjectsOnCanvas;
+	}
+	
+	public void defineLists() {
+		switchsOnCanvas.clear();
+		nodesOnCanvas.clear();
+		holonObjectsOnCanvas.clear();
+		for(AbstractCpsObject aCps : this.objectsOnCanvas) {
+			if(aCps instanceof HolonObject)holonObjectsOnCanvas.add((HolonObject) aCps);
+			else if(aCps instanceof CpsNode)nodesOnCanvas.add((CpsNode) aCps);
+			else if(aCps instanceof HolonSwitch)switchsOnCanvas.add((HolonSwitch) aCps);
+		}
+	}
 }

+ 10 - 0
src/ui/view/GUI.java

@@ -113,6 +113,7 @@ public class GUI implements CategoryListener {
 	private final JMenuItem mntmSave = new JMenuItem("Save");
 	private final JMenuItem mntmCanvasSize = new JMenuItem("Set View Size");
 	private final JMenuItem mntmBackground = new JMenuItem("Background Image");
+	private final JMenuItem mntmOutLiner = new JMenuItem("Outliner");
 	private final JMenuItem mntmSplitView = new JMenuItem("Split View");
 	private final JSplitPane splitPane = new JSplitPane();
 	private final JSplitPane splitPane1 = new JSplitPane();
@@ -956,6 +957,15 @@ public class GUI implements CategoryListener {
 					}
 					contentPane.updateUI();
 				});
+		
+		
+		mnNewMenuView.add(mntmOutLiner);
+		mntmOutLiner.addActionListener(actienEvent -> {
+			System.out.println("MyButton");
+			Outliner bla =new Outliner(frmCyberPhysical, model, controller, this);
+		});
+		
+		
 		mnNewMenuView.add(mntmBackground);
 
 		mntmBackground

+ 2 - 1
src/ui/view/MyCanvas.java

@@ -520,9 +520,10 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
 					propertyTable.removeRow(i);
 				}
 			}
+
 			triggerUpdateController();
 		}
-
+		
 		stopEditing();
 	}
 

+ 2 - 2
src/ui/view/StatisticGraph.java

@@ -165,7 +165,7 @@ public class StatisticGraph extends JPanel {
         float temp = 0;
         for (HolonElement e : obj.getElements()) {
             if (e.isActive()) {
-                temp = temp + e.getAvailableEnergyAt(model.getCurIteration());
+                temp = temp + e.getEnergyAtTimeStep(model.getCurIteration());
             }
         }
         return temp;
@@ -693,7 +693,7 @@ public class StatisticGraph extends JPanel {
         for (AbstractCpsObject obj : objects) {
             if (obj instanceof HolonObject) {
                 for (HolonElement ele : ((HolonObject) obj).getElements()) {
-                    if (ele.isActive() && ele.getAvailableEnergyAt(tStep) < 0 ) {
+                    if (ele.isActive() && ele.getEnergyAtTimeStep(tStep) < 0 ) {
                         val += ele.getOverallEnergyAtTimeStep(tStep);
                     }
                 }

+ 2 - 2
tests/tests/PraktikumHolonsTestClasses.java

@@ -184,8 +184,8 @@ public class PraktikumHolonsTestClasses {
 		HolonElement ele1 = new HolonElement("TV", 2, -20, IdCounterElem.nextId(),null);
 		HolonElement ele2 = new HolonElement("Fridge", 1, -50, IdCounterElem.nextId(),null);
 
-        assertTrue("Array not empty", ele1.getAvailableEnergyAt(0) == -20);
-        assertTrue("Array not empty", ele1.getAvailableEnergyAt(2) == -20);
+        assertTrue("Array not empty", ele1.getEnergyAtTimeStep(0) == -20);
+        assertTrue("Array not empty", ele1.getEnergyAtTimeStep(2) == -20);
         assertTrue("Name not correct", ele1.getEleName().equals("TV"));
         ele1.setEleName(ele2.getEleName());
 		assertTrue("Name not correct", ele1.getEleName().equals("Fridge"));