Henrik Kunzelmann пре 3 година
родитељ
комит
13e63eddba
4 измењених фајлова са 59 додато и 79 уклоњено
  1. 11 0
      src/classes/Position.java
  2. 1 1
      src/holeg/HolegGateway.java
  3. 27 47
      src/ui/view/GroupNodeCanvas.java
  4. 20 31
      src/ui/view/MyCanvas.java

+ 11 - 0
src/classes/Position.java

@@ -32,6 +32,13 @@ public class Position {
 		this.x = (int)p.getX();
 		this.y = (int)p.getY();
 	}
+
+	public Position(Vector2d vector)
+	{
+		this.x = Math.round(vector.getX());
+		this.y = Math.round(vector.getY());
+	}
+
 	/**
 	 * Default constructor without defined position.
 	 */
@@ -91,4 +98,8 @@ public class Position {
 	public String toString() {
 		return "Position[x=" + x + ",y="+ y +"]";
 	}
+
+	public Vector2d toVector() {
+		return new Vector2d(x, y);
+	}
 }

+ 1 - 1
src/holeg/HolegGateway.java

@@ -54,7 +54,7 @@ public class HolegGateway {
             SimpleGridNode b = canvasToGrid.get(cable.getModel().getB());
             if (a == null || b == null)
                 continue;
-            SimpleGridEdge edge = gridBuilder.connect(a, b, cable.getModel().getRealLength());
+            SimpleGridEdge edge = gridBuilder.connect(a, b, Math.max(1, cable.getModel().getRealLength()));
             edge.overrideImpedance = new ComplexNumber(cable.getModel().getOverrideResistance(), cable.getModel().getOverrideReactance());
             edge.overrideShuntSusceptance = cable.getModel().getOverrideShuntSusceptance();
             edge.tag = cable;

+ 27 - 47
src/ui/view/GroupNodeCanvas.java

@@ -82,6 +82,7 @@ public class GroupNodeCanvas extends AbstractCanvas implements MouseListener, Mo
             }
         }
 
+        showConnectionInformation = true;
         showedInformation[0] = true;
         showedInformation[1] = true;
         showedInformation[4] = true;
@@ -438,53 +439,32 @@ public class GroupNodeCanvas extends AbstractCanvas implements MouseListener, Mo
 		return percentages;
 	}
 	private void paintExitCable(Graphics2D g, ExitCable eCable) {
-		if(eCable.getStart() == null || eCable.getFinish() == null) {
-			System.out.println("Null wrong exitcable");
-			System.out.println(" wrongCable: " + " start:"  +eCable.getStart() + " end:"  +eCable.getFinish() + " state:" + eCable.getState());
-			return;
-		}
-		Position start = eCable.getStart().getPosition();
-		Position end = eCable.getFinish().getPosition();
-		float currentEnergy = eCable.getCable().getFlowEnergy();
-		float capacity = eCable.getCable().getModel().getCapacity();
-		boolean unlimited = eCable.getCable().getModel().isUnlimitedCapacity();
-		switch(eCable.getCable().getState()) {
-		case Burned:
-			g.setColor(Color.RED);
-			g.setStroke(new BasicStroke(2));
-			break;
-		case Working:
-			g.setColor(new Color(13, 175, 28));
-			g.setStroke(new BasicStroke(unlimited?2f:(currentEnergy / capacity * 2f) + 1));
-			break;
-		}
-		switch(eCable.getState()) {
-		case DOWN:
-		case DOWNDOWN:
-			g.drawLine(start.x, start.y, end.x, end.y);
-			Position middle = new Position((start.x + end.x) / 2, (start.y + end.y) / 2);
-			g.setFont(new Font("TimesRoman", Font.PLAIN, Math.max((int) (controller.getScale() / 3.5f), 10) )); 
-			g.drawString(currentEnergy + "/" + (unlimited?"\u221E":capacity) , middle.x, middle.y);
-			break;
-		case DOWNUP:
-		case UP:
-			Vector2d vStart = new Vector2d(start.x, start.y);
-			Vector2d vEnd = new Vector2d(end.x, end.y);
-			float stretchFactor = 4 * model.getScale();
-			stretchFactor =  (stretchFactor > vStart.getDistance(vEnd))? vStart.getDistance(vEnd) : stretchFactor;
-			Vector2d vPosition = vStart.add((vEnd.subtract(vStart)).normalize().multiply(stretchFactor));
-			Position result = new Position(Math.round(vPosition.getX()),Math.round(vPosition.getY()));
-			g.drawLine(start.x, start.y, result.x, result.y);
-			Position middle1 = new Position((start.x +result.x) / 2, (start.y + +result.y) / 2);
-			g.setFont(new Font("TimesRoman", Font.PLAIN, Math.max((int) (controller.getScale() / 3.5f), 10) )); 
-			g.drawString(currentEnergy + "/" + (unlimited?"\u221E":capacity) , middle1.x, middle1.y);
-			drawCanvasObject(g, "/Images/arrowUp.png" , result);
-			break;
-		default:
-			System.out.println("Error");
-			break;
-		}
-	}
+        if (eCable.getStart() == null || eCable.getFinish() == null) {
+            System.out.println("Null wrong exitcable");
+            System.out.println(" wrongCable: " + " start:" + eCable.getStart() + " end:" + eCable.getFinish() + " state:" + eCable.getState());
+            return;
+        }
+        Position start = eCable.getStart().getPosition();
+        Position end = eCable.getFinish().getPosition();
+
+        switch (eCable.getState()) {
+            case DOWNUP:
+            case UP:
+                Vector2d vStart = start.toVector();
+                Vector2d vEnd = end.toVector();
+                float stretchFactor = Math.min(4 * model.getScale(),  vStart.getDistance(vEnd));
+                Vector2d vPosition = vStart.add(vEnd.subtract(vStart).normalize().multiply(stretchFactor));
+
+                Position newEnd = new Position(vPosition);
+                MyCanvas.paintExitCable(controller, g, start, newEnd, eCable, showConnectionInformation);
+                drawCanvasObject(g, "/Images/arrowUp.png", newEnd);
+                break;
+            default:
+                MyCanvas.paintExitCable(controller, g, eCable, showConnectionInformation);
+                break;
+        }
+    }
+
 	private void paintSupplyBar(Graphics2D g, float percentage, Color color, Position pos) {
 		// +1, -2, -1 little Adjustment for pixel perfect alignment
 		int barWidth = (int) (controller.getScale());

+ 20 - 31
src/ui/view/MyCanvas.java

@@ -5,6 +5,7 @@ import classes.*;
 import com.google.gson.JsonParseException;
 
 import holeg.HolegPowerFlowContext;
+import javafx.geometry.Pos;
 import ui.controller.Control;
 import ui.controller.SingletonControl;
 import ui.controller.UpdateController;
@@ -334,13 +335,6 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
 		this.addMouseListener(this);
 		this.addMouseMotionListener(this);
 	}
-
-	/**
-	 * Paints all Components on the Canvas.
-	 *
-	 * @param g
-	 *            Graphics
-	 */
 	
 	private Color getStateColor(HolonObjectState state) {
 		switch(state) {
@@ -398,7 +392,7 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
 				pos.y - controller.getScaleDiv2(),
 				controller.getScale(), controller.getScale() , null);
 	}
-	
+
 	public static void paintCable(Control controller, Graphics2D g, DecoratedCable cable, boolean isSelected, boolean showConnectionInformation) {
 		// Find cable start/end
 		AbstractCanvasObject a = cable.getModel().getA();
@@ -406,6 +400,10 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
 		Position start = a.getPosition();
 		Position end = b.getPosition();
 
+		paintCable(controller, g, a, b, start, end, cable, isSelected, showConnectionInformation);
+	}
+	
+	public static void paintCable(Control controller, Graphics2D g, AbstractCanvasObject a, AbstractCanvasObject b, Position start, Position end, DecoratedCable cable, boolean isSelected, boolean showConnectionInformation) {
 		// Find cable state
 		float currentEnergy = Math.abs(cable.getFlowEnergy());
 		float capacity = cable.getModel().getCapacity();
@@ -420,9 +418,8 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
 				g.setStroke(new BasicStroke(unlimited ? 2f : (Math.min(currentEnergy / capacity, 1) * 2f) + 1));
 				break;
 		}
-		if (isSelected) {
+		if (isSelected)
 			g.setColor(Color.lightGray);
-		}
 
 		// Check if we should draw arrow or line
 		if (cable.getFlowEnergy() > 2)
@@ -466,27 +463,19 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
 		drawCanvasObject(g, dSwitch.getState() == SwitchState.Open ? HolonSwitch.getSwitchOpenImage(): HolonSwitch.getSwitchClosedImage() , dSwitch.getModel().getPosition());
 	}
 	
-	private void paintExitCable(Graphics2D g, ExitCable eCable) {
-		Position start = eCable.getStart().getPosition();
-		Position end = eCable.getFinish().getPosition();
-		float currentEnergy = eCable.getCable().getFlowEnergy();
-		float capacity = eCable.getCable().getModel().getCapacity();
-		boolean unlimited = eCable.getCable().getModel().isUnlimitedCapacity();
-		switch(eCable.getCable().getState()) {
-		case Burned:
-			g.setColor(Color.RED);
-			g.setStroke(new BasicStroke(2));
-			break;
-		case Working:
-			g.setColor(new Color(13, 175, 28));
-			g.setStroke(new BasicStroke(unlimited?2f:(currentEnergy / capacity * 2f) + 1));
-			break;
-		}
-		g.drawLine(start.x, start.y, end.x, end.y);
-		Position middle = new Position((start.x + end.x) / 2, (start.y + end.y) / 2);
-		g.setFont(new Font("TimesRoman", Font.PLAIN, Math.max((int) (controller.getScale() / 3.5f), 10) )); 
-		g.drawString(currentEnergy + "/" + (unlimited?"\u221E":capacity) , middle.x, middle.y);
+	public static void paintExitCable(Control controller, Graphics2D g, ExitCable eCable, boolean showConnectionInformation) {
+		AbstractCanvasObject a = eCable.getStart();
+		AbstractCanvasObject b = eCable.getFinish();
+		paintExitCable(controller, g, a.getPosition(), b.getPosition(), eCable, showConnectionInformation);
 	}
+
+	public static void paintExitCable(Control controller, Graphics2D g, Position start, Position end, ExitCable eCable, boolean showConnectionInformation) {
+		AbstractCanvasObject a = eCable.getStart();
+		AbstractCanvasObject b = eCable.getFinish();
+		// End and start are reversed
+		paintCable(controller, g, a, b, end, start, eCable.getCable(), false, showConnectionInformation);
+	}
+
 	private void paintGroupNode(Graphics2D g, DecoratedGroupNode dGroupNode) {
 		Position pos = dGroupNode.getModel().getPosition();
 		g.setColor(Color.lightGray);
@@ -608,7 +597,7 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
 		VisualRepresentationalState  visualState = controller.getSimManager().getActualVisualRepresentationalState();
 		//VisualState Representation:
 		for(ExitCable cable : visualState.getExitCableList()) {
-			paintExitCable(g2d, cable);
+			paintExitCable(controller, g2d, cable, showConnectionInformation);
 		}
 		for(DecoratedCable cable : visualState.getCableList()) {
 			paintCable(controller, g2d, cable, selectedEdges.contains(cable.getModel()), showConnectionInformation);