Browse Source

Clean Up 4!

Tom Troppmann 5 years ago
parent
commit
18204a9b5f

+ 0 - 16
src/ui/controller/CategoryController.java

@@ -167,22 +167,6 @@ public class CategoryController {
 		addObject(category, obj);
 	}
 
-	/**
-	 * Add new Holon Transformer.
-	 * 
-	 * @param cat
-	 *            Category
-	 * @param objName
-	 *            New Object Name
-	 * @param image
-	 *            the image Path
-	 */
-	public void addNewHolonTransformer(Category cat, String objName, String image) {
-		HolonTransformer transformer = new HolonTransformer(objName);
-		transformer.setImage(image);
-		transformer.setSav(cat.getName());
-		addObject(cat, transformer);
-	}
 
 	/**
 	 * Add new Holon Switch.

+ 17 - 30
src/ui/controller/Control.java

@@ -48,6 +48,7 @@ public class Control {
     private final ClipboardController clipboardController;
     private final HolonCanvasController holonCanvasController;
     private Model model;
+    private GUI gui;
     private SimulationManager simulationManager;
     private String autosaveDir = "";
     private String categoryDir = "";
@@ -221,15 +222,6 @@ public class Control {
         saveCategory();
     }
 
-    /**
-     * Add new Holon Transformer to a Category.
-     *
-     * @param cat Category
-     * @param obj New Object Name
-     */
-    public void addTransformer(Category cat, String obj) {
-        categoryController.addNewHolonTransformer(cat, obj, "/Images/transformer-1.png");
-    }
 
     /**
      * Add new Holon Switch to a Category.
@@ -309,7 +301,7 @@ public class Control {
      */
     public void addObjectCanvas(AbstractCpsObject object) {
         canvasController.addNewObject(object);
-        simulationManager.calculateStateForTimeStep(model.getCurIteration());
+        calculateStateForTimeStep(model.getCurIteration());
         if (!(object instanceof CpsNode)) {
             try {
                 autoSave();
@@ -552,8 +544,7 @@ public class Control {
      * current Timestep.
      */
     public void calculateStateForCurrentTimeStep() {
-        // simulationManager.reset();
-        simulationManager.calculateStateForTimeStep(model.getCurIteration());
+    	calculateStateForTimeStep(model.getCurIteration());
     }
 
     /**
@@ -563,6 +554,7 @@ public class Control {
      */
     public void calculateStateForTimeStep(int x) {
         simulationManager.calculateStateForTimeStep(x);
+        updateOutliner();
     }
 
     /**
@@ -573,24 +565,7 @@ public class Control {
         setIsSimRunning(false);
     }
 
-    /**
-     * Set the Canvas.
-     *
-     * @param can the Canvas
-     */
-    public void setCanvas(MyCanvas can) {
-        simulationManager.setCanvas(can);
-    }
 
-    
-    /**
-     * Set the GUI.
-     *
-     * @param can the Canvas
-     */
-    public void setGui(GUI gui) {
-        simulationManager.setGui(gui);
-    }
     /**
      * make an autosave.
      *
@@ -1017,10 +992,22 @@ public class Control {
 	
 	/**
      * Sets fairness Model
-     * @param mininumdemandfirst that should be used. 
+     * @param fairnessModel that should be used. 
      */
 	public void setFairnessModel(FairnessModel fairnessModel) {
 		globalController.setFairnessModel(fairnessModel);
 	}
 	
+	public void updateOutliner() {
+		gui.updateOutliners(simulationManager.getActualDecorState());
+	}
+	
+	public GUI getGui() {
+		return gui;
+	}
+
+	public void setGui(GUI gui) {
+		this.gui = gui;
+	}
+	
 }

+ 1 - 7
src/ui/controller/GlobalController.java

@@ -158,13 +158,7 @@ public class GlobalController {
 		}
 	}
 	
-	/**
-	 * Sets showConsoleLog.
-	 * @param showConsoleLog
-	 */
-	public void setShowConsoleLog(boolean showConsoleLog) {
-		model.setShowConsoleLog(showConsoleLog);
-	}
+
 	
 	/**
 	 * sets showSupplyBars

+ 4 - 221
src/ui/controller/SimulationManager.java

@@ -38,17 +38,10 @@ import javax.swing.JPanel;
 public class SimulationManager {
 	int global = 0;
 	private Model model;
-	private ArrayList<AbstractCpsObject> objectsToHandle;
-	private ArrayList<SubNet> subNets;
-	private ArrayList<CpsEdge> brokenEdges;
 	private HashMap<Integer, DecoratedState> saves = new HashMap<Integer, DecoratedState>();
 	private HashMap<Integer, VisualRepresentationalState> savesVisual = new HashMap<Integer, VisualRepresentationalState>();
-	private MyCanvas canvas;
 	private int timeStep;
-	private HashMap<Integer, Float> tagTable = new HashMap<>();
 	private FlexiblePane flexPane;
-	private GUI gui;
-	private HashMap<HolonElement, Float> flexDevicesTurnedOnThisTurn = new HashMap<>();
 
 	/**
 	 * Constructor.
@@ -57,12 +50,8 @@ public class SimulationManager {
 	 *            Model
 	 */
 	SimulationManager(Model m) {
-		canvas = null;
 		model = m;
-		subNets = new ArrayList<>();
-		brokenEdges = new ArrayList<>();
 	}
-
 	/**
 	 * calculates the flow of the edges and the supply for objects and consider old timesteps for burned cables.
 	 *
@@ -118,9 +107,6 @@ public class SimulationManager {
 		DecoratedState stateFromThisTimestep = new DecoratedState(decorNetworks, leftOverDecoratedCables, listOfDecoratedSwitches, timestep);
 		saves.put(timestep, stateFromThisTimestep);
 		savesVisual.put(timestep, new VisualRepresentationalState(stateFromThisTimestep, minimumModel));
-		canvas.repaint();
-		gui.updateOutliners(getActualDecorState());//saves.getOrDefault(timestep, null);
-		
 	}
 	/** 
 	 * Decorate a switch
@@ -220,196 +206,6 @@ public class SimulationManager {
 			}
 		}
 	}
-	/**
-	 * add all battries.getOut() from a list of battries and return them
-	 * @param aL a List of HolonBattries likely from subnet.getBatteries()
-	 * @param x TimeStep
-	 * @return 
-	 * 
-	 */
-	private float GetOutAllBatteries(ArrayList<HolonBattery> aL, int x)
-	{
-		float OutEnergy = 0;
-		for(HolonBattery hB : aL)
-		{
-			//System.out.println("Iteration: "+ x +"OutBattery: "+ hB.getOutAtTimeStep(x-1));
-			OutEnergy += hB.getOutAtTimeStep(x-1);
-		}
-		//System.out.println("Iteration: "+ x +"GetOutAllBatteries: "+ OutEnergy);
-		return OutEnergy;
-	}
-	/**
-	 * search for all flexible devices in the network and turn them on, until
-	 * energy surplus = 0 or all devices have been examined.
-	 *
-	 * This code could be compressed (cases inside over- and underproduction are
-	 * the same), but we decided that it is better readable this way
-	 *
-	 * @param subNet
-	 *            the subnet
-	 * @param energySurplus
-	 *            the current surplus of energy
-	 */
-	private void turnOnFlexibleDevices(SubNet subNet, float energySurplus,
-			int timestep) {
-		for (HolonObject holonOb : subNet.getObjects()) {
-			for (HolonElement holonEl : holonOb.getElements()) {
-
-				// if this element is flexible and active (can be considered for
-				// calculations)
-				if (holonEl.isFlexible() && holonEl.isActive()) {
-					float energyAvailableSingle = holonEl
-							.getEnergyAtTimeStep(timestep);
-					float energyAvailableMultiple = energyAvailableSingle
-							* holonEl.getAmount();
-
-					// ------------- flexible consumer / OVERPRODUCTION
-					// -------------
-					if (energyAvailableMultiple < 0 && energySurplus > 0) {
-
-						// if there is more wasted energy than energy that this
-						// device can give, give all energy available
-						if (Math.abs(energyAvailableMultiple) <= Math
-								.abs(energySurplus)) {
-							energySurplus += energyAvailableMultiple;
-							// set the new energy consumption to the maximum
-							holonEl.setEnergyPerElement(energyAvailableSingle);
-							flexDevicesTurnedOnThisTurn.put(holonEl,
-									energyAvailableMultiple);
-						}
-						// else: we just need to turn on part of the flexible
-						// energy available
-						else {
-							float energyNeeded = -energySurplus;
-							energySurplus += energyNeeded; // should give 0, but
-															// was kept this was
-															// for consistency
-							// the energy needed divided through the amount of
-							// elements
-							holonEl.setEnergyPerElement(energyNeeded
-									/ holonEl.getAmount());
-							flexDevicesTurnedOnThisTurn.put(holonEl,
-									energyNeeded);
-						}
-					}
-
-					// ------------- flexible producer / UNDERPRODUCTION
-					// -------------
-					else if (energyAvailableMultiple > 0 && energySurplus < 0) {
-
-						// if there is more energy needed than this device can
-						// give, give all the energy available
-						if (Math.abs(energyAvailableMultiple) <= Math
-								.abs(energySurplus)) {
-							energySurplus += energyAvailableMultiple;
-							// set the new energy consumption to the maximum
-							holonEl.setEnergyPerElement(energyAvailableSingle);
-							flexDevicesTurnedOnThisTurn.put(holonEl,
-									energyAvailableMultiple);
-						}
-						// else: we just need to turn on part of the flexible
-						// energy available
-						else {
-							float energyNeeded = -energySurplus;
-							int i = 0;
-							energySurplus += energyNeeded; // should give 0, but
-															// was kept this was
-															// for consistency
-							// the energy needed divided through the amount of
-							// elements
-							holonEl.setEnergyPerElement(energyNeeded
-									/ holonEl.getAmount());
-							flexDevicesTurnedOnThisTurn.put(holonEl,
-									energyNeeded);
-						}
-
-					}
-				}
-
-				if (energySurplus == 0) {
-					break;
-				}
-			}
-
-			if (energySurplus == 0) {
-				break;
-			}
-		}
-	}
-
-	/**
-	 * Set Flow Simulation.
-	 *
-	 * @param sN
-	 *            Subnet
-	 */
-	
-
-	/**
-	 * Set the Pseudo Tags.
-	 *
-	 * @param nodes
-	 *            Array of AbstractCpsObjects
-	 */
-	private void setPseudoTags(ArrayList<AbstractCpsObject> nodes,
-			ArrayList<CpsEdge> edges) {
-		for (AbstractCpsObject node : nodes) {
-			node.recalculateTags();
-			node.setPseudoTags(new ArrayList<>());
-		}
-		for (CpsEdge edge : edges) {
-			edge.recalculateTags();
-			edge.setPseudoTag(new ArrayList<>());
-		}
-	}
-
-
-
-
-	/**
-	 * copies the data of an array of Objects.
-	 *
-	 * @param toCopy
-	 *            the ArrayList of CpsObjects co Copy
-	 */
-	private void copyObjects(ArrayList<AbstractCpsObject> toCopy) {
-		for (AbstractCpsObject cps : toCopy) {
-			if (cps instanceof CpsUpperNode) {
-				copyObjects(((CpsUpperNode) cps).getNodes());
-			} else {
-				objectsToHandle.add(cps);
-			}
-		}
-	}
-
-
-
-	/**
-	 * Set the Canvas.
-	 *
-	 * @param can
-	 *            the Canvas
-	 */
-	public void setCanvas(MyCanvas can) {
-		canvas = can;
-	}
-	/**
-	 * Should be a better way to update the canvas -.-
-	 * @param can
-	 */
-	public void updateCanvas() {
-		canvas.repaint();
-	}
-	/**
-	 * Reset all Data to the current state of the Model.
-	 */
-	public void reset() {
-		objectsToHandle = new ArrayList<>();
-		copyObjects(model.getObjectsOnCanvas());
-		flexDevicesTurnedOnThisTurn = new HashMap<>();
-	}
-
-
 
 	/**
 	 * Get all Subnets.Not functional.
@@ -418,16 +214,9 @@ public class SimulationManager {
 	 */
 	@Deprecated
 	public ArrayList<SubNet> getSubNets() {
-		return subNets;
+		return new ArrayList<SubNet>();
 	}
 
-	/**
-	 * Get broken Edges
-	 */
-	// public ArrayList<CpsEdge> getBrokenEdges() {
-	// return brokenEdges;
-	// }
-
 
 
 	public FlexiblePane getFlexiblePane() {
@@ -439,25 +228,19 @@ public class SimulationManager {
 	}
 
 	
-	public DecoratedState getActualDecorStateWithOffSet(int offSet) {
-		return getDecorState(timeStep + offSet);
-	}
 	public DecoratedState getActualDecorState() {
 		return getDecorState(timeStep);
 	}
 	public VisualRepresentationalState getActualVisualRepresentationalState(){
 		return savesVisual.getOrDefault(timeStep, null);
 	}
+	
 	public DecoratedState getDecorState(int timestep) {
 		return saves.getOrDefault(timestep, null);
 	}
-
-	public void setGui(GUI gui) {
-		this.gui = gui;
+	public VisualRepresentationalState getVisualRepresentationalState(int timestep) {
+		return savesVisual.getOrDefault(timestep, null);
 	}
 
-	public HashMap<Integer, VisualRepresentationalState> getSavesVisual() {
-		return savesVisual;
-	}
 
 }

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

@@ -315,6 +315,7 @@ public class GUI implements CategoryListener {
 	GUI(Control control) {
 		this.controller = control;
 		this.model = control.getModel();
+		control.setGui(this);
 		statSplitPane = new StatisticPanel(controller);
 		model.addGraphListener(statSplitPane);
 		model.setStatPanel(statSplitPane);
@@ -324,8 +325,6 @@ public class GUI implements CategoryListener {
 		this.holonCanvas = new HolonCanvas(model, control);
 
 		control.initListener(this);
-		controller.setCanvas(canvas);
-		control.setGui(this);
 		model.setTableProperties(tableProperties);
 		algorithmMenu = new AlgorithmMenu(model, control, this);
 		initialize();
@@ -1840,9 +1839,6 @@ public class GUI implements CategoryListener {
 								if (tempCps instanceof HolonSwitch) {
 									h = new HolonSwitch(tempCps);
 								}
-								if (tempCps instanceof HolonTransformer) {
-									h = new HolonTransformer(tempCps);
-								}
 								if (tempCps instanceof HolonBattery)
 								{
 									h = new HolonBattery(tempCps);