Przeglądaj źródła

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

Teh-Hai Julian Zheng 8 lat temu
rodzic
commit
f79c9c3bd6

BIN
res/Button_Images/Thumbs.db


BIN
res/Images/Thumbs.db


+ 1 - 1
src/classes/Category.java

@@ -15,7 +15,7 @@ public class Category{
 		setObjects(new ArrayList<CpsObject>());
 		setName(name);
 		setID(-1);
-		setObjIdx(new HashMap<>());
+		setObjIdx(new HashMap<String,Integer>());
 	
 	}
 

+ 2 - 2
src/classes/HolonObject.java

@@ -28,7 +28,7 @@ public class HolonObject extends CpsObject {
 	public HolonObject(String ObjName) {
 		super(ObjName);
 		setElements(new ArrayList<HolonElement>());
-		setEleIdx(new HashMap<>());
+		setEleIdx(new HashMap<String,Integer>());
 
 	}
 
@@ -36,7 +36,7 @@ public class HolonObject extends CpsObject {
 		super(ObjName);
 		super.setName(obj);
 		setElements(new ArrayList<HolonElement>());
-		setEleIdx(new HashMap<>());
+		setEleIdx(new HashMap<String,Integer>());
 	}
 
 	public HolonObject(CpsObject obj) {

+ 23 - 0
src/classes/HolonTransformer.java

@@ -4,6 +4,9 @@ public class HolonTransformer extends CpsObject {
 
 	/* Ratio of the transformer */
 	float transformRatio;
+	
+	/*Fixed transform value */
+	float transformFixed;
 
 	/**
 	 * Constructor Set type of object (Transformer), its transform ratio and the
@@ -21,6 +24,7 @@ public class HolonTransformer extends CpsObject {
 	public HolonTransformer(CpsObject obj) {
 		super(obj);
 		this.setTransformRatio(((HolonTransformer) obj).getTransformRatio());
+		this.setTransformFixed(((HolonTransformer) obj).getTransformFixed());
 	}
 
 	/**
@@ -41,4 +45,23 @@ public class HolonTransformer extends CpsObject {
 	public float getTransformRatio() {
 		return this.transformRatio;
 	}
+	
+	/**
+	 * Set fixed Transform Value
+	 * 
+	 * @param fixed
+	 *            desired fixed Transform Value
+	 */
+	public void setTransformFixed(float fixed) {
+		this.transformFixed = fixed;
+	}
+
+	/**
+	 * Output the actual fixed Transform Value
+	 * 
+	 * @return actual fixed Transform Value
+	 */
+	public float getTransformFixed() {
+		return this.transformFixed;
+	}
 }

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

@@ -36,7 +36,7 @@ public class CanvasController {
 	 */
 	public void addNewObject(CpsObject object) {
 		object.setSav("CVS");
-		object.setConnections(new ArrayList<>());
+		object.setConnections(new ArrayList<CpsEdge>());
 		addObject(object);
 	}
 

+ 2 - 2
src/ui/controller/CategoryController.java

@@ -30,8 +30,8 @@ public class CategoryController {
 		addNewCategory("Building");
 		addNewCategory("Component");
 
-		addNewHolonObject(mpC.searchCategory("Energy"), "Power Plant", new ArrayList<>(), "/Images/power-plant.png");
-		addNewHolonObject(mpC.searchCategory("Building"), "House", new ArrayList<>(), "/Images/home-2.png");
+		addNewHolonObject(mpC.searchCategory("Energy"), "Power Plant", new ArrayList<HolonElement>(), "/Images/power-plant.png");
+		addNewHolonObject(mpC.searchCategory("Building"), "House", new ArrayList<HolonElement>(), "/Images/home-2.png");
 		addNewHolonTransformer(mpC.searchCategory("Component"), "Transformer", "/Images/transformer-1.png");
 		addNewHolonSwitch(mpC.searchCategory("Component"), "Switch", "/Images/switch-off.png");
 

+ 6 - 5
src/ui/controller/LoadController.java

@@ -14,6 +14,7 @@ import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
 import org.json.simple.parser.ParseException;
 
+import classes.Category;
 import classes.CpsEdge;
 import classes.CpsNode;
 import classes.CpsObject;
@@ -50,10 +51,10 @@ public class LoadController {
 	 */
 	public void readJSON(String path) throws IOException {
 		JSONParser parser = new JSONParser();
-		MODEL.setCgIdx(new HashMap<>());
-		MODEL.setCvsObjIdx(new HashMap<>());
-		MODEL.setCategories(new ArrayList<>());
-		MODEL.setObjectsOnCanvas(new ArrayList<>());
+		MODEL.setCgIdx(new HashMap<String,Integer>());
+		MODEL.setCvsObjIdx(new HashMap<Integer,Integer>());
+		MODEL.setCategories(new ArrayList<Category>());
+		MODEL.setObjectsOnCanvas(new ArrayList<CpsObject>());
 
 
 		ArrayList<String> obj = new ArrayList<>();
@@ -147,7 +148,7 @@ public class LoadController {
 		String type = next(i);
 
 		if (type.equals("HolonObject")) {
-			cgC.addNewHolonObject(mpC.searchCategory(next(i)), next(i), new ArrayList<>(), next(i));
+			cgC.addNewHolonObject(mpC.searchCategory(next(i)), next(i), new ArrayList<HolonElement>(), next(i));
 		} else if (type.equals("HolonTransformer")) {
 			cgC.addNewHolonTransformer(mpC.searchCategory(next(i)), next(i), next(i));
 		} else if (type.equals("HolonSwitch")) {

+ 2 - 2
src/ui/model/Model.java

@@ -70,8 +70,8 @@ public class Model {
 		setEdgesOnCanvas(new ArrayList<CpsEdge>());
 		setCategoryListeners(new LinkedList<CategoryListener>());
 		setObjectListeners(new LinkedList<ObjectListener>());
-		setCgIdx(new HashMap<>());
-		setCvsObjIdx(new HashMap<>());
+		setCgIdx(new HashMap<String,Integer>());
+		setCvsObjIdx(new HashMap<Integer,Integer>());
 
 
 	}

+ 39 - 28
src/ui/view/UnitGraph.java

@@ -85,13 +85,11 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		// Draw the Vertical Lines
 		g2.setColor(Color.BLACK);
 		for (int i = 0; i <= this.getWidth(); i += 10) {
-			g2.drawLine(i, 0,
-					i, this.getHeight());
+			g2.drawLine(i, 0, i, this.getHeight());
 		}
 
 		for (int i = 0; i <= this.getHeight(); i += 5) {
-			g2.drawLine(0, i, this.getWidth(),
-					i);
+			g2.drawLine(0, i, this.getWidth(), i);
 		}
 
 		if (arrayOfValue != null) {
@@ -122,11 +120,10 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 				(model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1), this.getHeight());
 		// Iteration Value
 		if (arrayOfValue != null) {
-				g2.drawString("" + arrayOfValue[model.getCurIteration()],
-						(model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1) +2,
-						this.getHeight()-10);
+			g2.drawString("" + arrayOfValue[model.getCurIteration()],
+					(model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1) + 2,
+					this.getHeight() - 10);
 		}
-
 		/*
 		 * // Actual Iteration Point Visualization g2.setColor(Color.RED); if
 		 * (arrayOfValue != null) { for (int i = 0; i < arrayOfValue.length;
@@ -135,6 +132,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		 * arrayOfValue[i]) * scaleY - recSize.getY() / 2), (int)
 		 * recSize.getX(), (int) recSize.getY()); } }
 		 */
+
 	}
 
 	@Override
@@ -204,7 +202,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 					}
 				}
 			}
-			//New Point
+			// New Point
 			if (!pointDrag && e.getButton() != MouseEvent.BUTTON3 && e.getX() != 0
 					&& e.getX() != this.getWidth() / scaleX) {
 				for (int i = 0; i < pointList.size(); i++) {
@@ -220,7 +218,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 					}
 				}
 			}
-			//Delete a Point
+			// Delete a Point
 			if (deletePoint && tempP.getX() != 0
 					&& (tempP.getX() != this.getWidth() / scaleX || tempP != pointList.getLast())) {
 				pointList.remove(tempP);
@@ -239,7 +237,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	}
 
 	public void componentResized(ComponentEvent e) {
-		//Wenn ein anderes Element genommen wird
+		// Wenn ein anderes Element genommen wird
 		if (init) {
 			MAXIMUM = tempElement.getEnergy();
 			init = false;
@@ -251,15 +249,15 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 
 			scaleX = this.getWidth() / width;
 			scaleY = this.getHeight() / height;
-			
-			//First time clicked on the Element
+
+			// First time clicked on the Element
 			if (pointList.isEmpty()) {
 				pointList.addFirst(new Point(0, 0));
 				pointList.addLast(new Point((int) (this.getWidth() / scaleX), 0));
 			}
 		}
-		
-		//Scale
+
+		// Scale
 		scaleX = this.getWidth() / width;
 		scaleY = this.getHeight() / height;
 		repaint();
@@ -348,8 +346,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		y1 = (int) p1.getY();
 		x2 = (int) p2.getX();
 		y2 = (int) p2.getY();
-		
-		//calculate the controllpoints
+
+		// calculate the controllpoints
 		ctrlx1 = (int) p1.getX() + ((int) p2.getX() - (int) p1.getX()) / 2;
 		ctrlx2 = (int) p2.getX() - ((int) p2.getX() - (int) p1.getX()) / 2;
 		if (y1 < y2) {
@@ -360,12 +358,15 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			ctrly2 = (int) p2.getY() + ((int) p1.getY() - (int) p2.getY()) / 10;
 		}
 
-		//set the curve
+		// set the curve
 		c.setCurve(x1 * scaleX, y1 * scaleY, ctrlx1 * scaleX, ctrly1 * scaleY, ctrlx2 * scaleX, ctrly2 * scaleY,
 				x2 * scaleX, y2 * scaleY);
 		return c;
 	}
 
+	/**
+	 * Fills the Arrays of each HolonElement
+	 */
 	public void fillArrayofValue() {
 		for (int i = 0; i < arrayOfValue.length; i++) {
 			arrayOfValue[i] = convertToValueY(getYValueAt_2((int) (i * width / (model.getIterations() - 1))));
@@ -386,7 +387,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 				Line2D l1 = new Line2D.Double(pointList.get(i).getX(), pointList.get(i).getY(),
 						pointList.get(i + 1).getX(), pointList.get(i + 1).getY());
 				Line2D l2 = new Line2D.Double(xVal, 0, xVal, height);
-				return (float) getIntersectionPoint(l1, l2).getY();
+				return getIntersectionPoint(l1, l2);
 			}
 		}
 		return 0;
@@ -410,13 +411,13 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 					c = cl;
 					// Kurve Links von "unten"
 					if (pointList.get(i).getY() >= pointList.get(i + 1).getY()) {
-						for (int j = (int) (height - 1); j >= 0; j--) {
+						for (float j = (float) (height - 1); j >= 0; j -= 0.1f) {
 							if (c.contains(xVal * scaleX, j * scaleY)) {
 								return (float) (j);
 							}
 						}
 					} else {// Kurve Links von "oben"
-						for (int j = 0; j < height; j++) {
+						for (float j = 0; j < height; j += 0.1f) {
 							if (c.contains(xVal * scaleX, j * scaleY)) {
 								return (float) (j);
 							}
@@ -426,13 +427,13 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 					c = cr;
 					// Kurve Links von "unten"
 					if (pointList.get(i).getY() >= pointList.get(i + 1).getY()) {
-						for (int j = 0; j < height; j++) {
+						for (float j = 0; j < height; j += 0.1f) {
 							if (c.contains(xVal * scaleX, j * scaleY)) {
 								return (float) (j);
 							}
 						}
 					} else {// Kurve Links von "oben"
-						for (int j = (int) (height - 1); j >= 0; j--) {
+						for (float j = (float) (height - 1); j >= 0; j -= 0.1f) {
 							if (c.contains(xVal * scaleX, j * scaleY)) {
 								return (float) (j);
 							}
@@ -444,22 +445,32 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		return getYValueAt(xVal);
 	}
 
-	public Point getIntersectionPoint(Line2D l1, Line2D l2) {
+	/**
+	 * 
+	 * @param l1,
+	 *            the first Line
+	 * @param l2,
+	 *            the second Line
+	 * 
+	 * @return The Intersection Point
+	 */
+	public float getIntersectionPoint(Line2D l1, Line2D l2) {
 		if (!l1.intersectsLine(l2)) {
-			return null;
+			return 0;// null;
 		}
 		double px = l1.getX1(), py = l1.getY1(), rx = l1.getX2() - px, ry = l1.getY2() - py;
 		double qx = l2.getX1(), qy = l2.getY1(), sx = l2.getX2() - qx, sy = l2.getY2() - qy;
 
 		double det = sx * ry - sy * rx;
 		if (det == 0) {
-			return null;
+			return 0;// null;
 		} else {
 			double z = (sx * (qy - py) + sy * (px - qx)) / det;
 			if (z < 0 || z > 1) {
-				return new Point(0, 0); // intersection at end point!
+				return 0;// new Point(0, 0); // intersection at end point!
 			}
-			return new Point((int) (px + z * rx), (int) (py + z * ry));
+			return (float) (py + z * ry);// new Point((int) (px + z * rx), (int)
+											// (py + z * ry));
 		}
 	} // end intersection line-line