浏览代码

Tracking Information for all HolonObj

Edgardo Palza 8 年之前
父节点
当前提交
097f51ae70
共有 2 个文件被更改,包括 68 次插入0 次删除
  1. 63 0
      src/classes/HolonObject.java
  2. 5 0
      src/ui/view/MyCanvas.java

+ 63 - 0
src/classes/HolonObject.java

@@ -26,6 +26,10 @@ public class HolonObject extends AbstractCpsObject {
 	private HashMap<String, Integer> eleIdx;
 	/* Total of consumption */
 	private float currentEnergy;
+	/* Array for tracking Production */
+	private float[] trackingProd;
+	/* Array for tracking Consumption */
+	private float[] trackingCons;
 
 	/*
 	 * 0 = no energy, 1 = not supplied, 2 = supplied, 3 producer
@@ -44,6 +48,8 @@ public class HolonObject extends AbstractCpsObject {
 		setElements(new ArrayList<HolonElement>());
 		setEleIdx(new HashMap<String, Integer>());
 		setState();
+		setTrackingProd(new float[100]);
+		setTrackingCons(new float[100]);
 	}
 
 	/**
@@ -57,6 +63,8 @@ public class HolonObject extends AbstractCpsObject {
 		setEleIdx(MultiPurposeController.copyHashMap(((HolonObject) obj).getEleIdx()));
 		setElements(copyElements(((HolonObject) obj).getElements()));
 		setState();
+		setTrackingProd(new float[100]);
+		setTrackingCons(new float[100]);
 	}
 
 	/**
@@ -331,4 +339,59 @@ public class HolonObject extends AbstractCpsObject {
 	public Color getColor() {
 		return stateColor;
 	}
+
+	/**
+	 * Set the Array Production
+	 */
+	public void setTrackingProd(float[] arr) {
+		this.trackingProd = arr;
+	}
+
+	/**
+	 * Get the Array Production
+	 */
+	public float[] getTrackingProd() {
+		return this.trackingProd;
+	}
+
+	/**
+	 * Set the Array Consumption
+	 */
+	public void setTrackingCons(float[] arr) {
+		this.trackingCons = arr;
+	}
+
+	/**
+	 * Get the Array Consumption
+	 */
+	public float[] getTrackingCons() {
+		return this.trackingCons;
+	}
+
+	/**
+	 * If the user track any HolonObject the tracking information will be
+	 * updated. (If the HolonObject enters into the untracked state, the array
+	 * will be reseted)
+	 */
+
+	public void updateTrackingInfo() {
+		float[] tempProd = new float[100];
+		float[] tempCons = new float[100];
+		for (int i = 0; i < 100; i++) {
+			float valueProd = 0;
+			float valueCons = 0;
+			for (HolonElement e : getElements()) {
+				if (e.getActive() && e.getSign() == '+') {
+					valueProd = valueProd + e.getTotalEnergyAtTimeStep(i);
+				}
+				if (e.getActive() && e.getSign() == '-') {
+					valueCons = valueCons + e.getTotalEnergyAtTimeStep(i);
+				}
+			}
+			tempProd[i] = valueProd;
+			tempCons[i] = valueCons;
+		}
+		this.trackingProd = tempProd;
+		this.trackingCons = tempCons;
+	}
 }

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

@@ -144,6 +144,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 						}
 						if (!found) {
 							control.addTrackingObj((HolonObject) o);
+							((HolonObject) o).updateTrackingInfo();
 						}
 					}
 				}
@@ -166,7 +167,11 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 							}
 						}
 						if (found) {
+							// Removed from tracking array and tracking
+							// information reseted
 							control.removeTrackingObj((HolonObject) o);
+							((HolonObject) o).setTrackingProd(new float[100]);
+							((HolonObject) o).setTrackingCons(new float[100]);
 						}
 					}
 				}