|
@@ -4,7 +4,9 @@ import classes.*;
|
|
|
|
|
|
import com.google.gson.JsonParseException;
|
|
|
|
|
|
+import holeg.HolegGateway;
|
|
|
import holeg.HolegPowerFlowContext;
|
|
|
+import javafx.geometry.Pos;
|
|
|
import ui.controller.Control;
|
|
|
import ui.controller.SingletonControl;
|
|
|
import ui.controller.UpdateController;
|
|
@@ -41,6 +43,7 @@ import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
+import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -334,13 +337,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 +394,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 +402,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 +420,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 +465,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);
|
|
@@ -581,7 +572,7 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
g.fillRect(sx, y, x - sx, sy - y);
|
|
|
}
|
|
|
}
|
|
|
- public void paintComponent(Graphics g) {
|
|
|
+ public void paintComponent(Graphics g) {
|
|
|
super.paintComponent(g);
|
|
|
Graphics2D g2d = (Graphics2D) g;
|
|
|
g2d.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING,
|
|
@@ -595,43 +586,43 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
//<--
|
|
|
//SelectedCable
|
|
|
HashSet<Edge> selectedEdges = new HashSet<Edge>();
|
|
|
- for(AbstractCanvasObject aCps: model.getSelectedCpsObjects()) {
|
|
|
- for(Edge edge: aCps.getConnections()) {
|
|
|
+ for (AbstractCanvasObject aCps : model.getSelectedCpsObjects()) {
|
|
|
+ for (Edge edge : aCps.getConnections()) {
|
|
|
selectedEdges.add(edge);
|
|
|
}
|
|
|
}
|
|
|
- if(model.getSelectedEdge() != null) selectedEdges.add(model.getSelectedEdge());
|
|
|
+ if (model.getSelectedEdge() != null) selectedEdges.add(model.getSelectedEdge());
|
|
|
//timstep:
|
|
|
- g.setFont(new Font("TimesNewRoman", Font.PLAIN, Math.max((int) (controller.getScale() / 3.5f), 10) ));
|
|
|
+ g.setFont(new Font("TimesNewRoman", Font.PLAIN, Math.max((int) (controller.getScale() / 3.5f), 10)));
|
|
|
g2d.setColor(Color.BLACK);
|
|
|
-
|
|
|
- VisualRepresentationalState visualState = controller.getSimManager().getActualVisualRepresentationalState();
|
|
|
+
|
|
|
+ VisualRepresentationalState visualState = controller.getSimManager().getActualVisualRepresentationalState();
|
|
|
//VisualState Representation:
|
|
|
- for(ExitCable cable : visualState.getExitCableList()) {
|
|
|
- paintExitCable(g2d, cable);
|
|
|
+ for (ExitCable cable : visualState.getExitCableList()) {
|
|
|
+ paintExitCable(controller, g2d, cable, showConnectionInformation);
|
|
|
}
|
|
|
- for(DecoratedCable cable : visualState.getCableList()) {
|
|
|
+ for (DecoratedCable cable : visualState.getCableList()) {
|
|
|
paintCable(controller, g2d, cable, selectedEdges.contains(cable.getModel()), showConnectionInformation);
|
|
|
}
|
|
|
- for(DecoratedGroupNode dGroupNode : visualState.getGroupNodeList()) {
|
|
|
+ for (DecoratedGroupNode dGroupNode : visualState.getGroupNodeList()) {
|
|
|
paintGroupNode(g2d, dGroupNode);
|
|
|
}
|
|
|
- for(Consumer con: visualState.getConsumerList()) {
|
|
|
- paintConsumer(g2d, con);
|
|
|
+ for (Consumer con : visualState.getConsumerList()) {
|
|
|
+ paintConsumer(g2d, con);
|
|
|
}
|
|
|
- for(Supplier sup: visualState.getSupplierList()) {
|
|
|
- paintSupplier(g2d, sup);
|
|
|
+ for (Supplier sup : visualState.getSupplierList()) {
|
|
|
+ paintSupplier(g2d, sup);
|
|
|
}
|
|
|
- for(Passiv pas: visualState.getPassivList()) {
|
|
|
+ for (Passiv pas : visualState.getPassivList()) {
|
|
|
paintCanvasObject(g2d, pas);
|
|
|
}
|
|
|
- for(DecoratedSwitch dSwitch : visualState.getSwitchList()) {
|
|
|
+ for (DecoratedSwitch dSwitch : visualState.getSwitchList()) {
|
|
|
paintSwitch(g2d, dSwitch);
|
|
|
}
|
|
|
- for(Node node : visualState.getNodeList()) {
|
|
|
- drawCanvasObject(g2d, "/Images/node.png" , node.getPosition());
|
|
|
+ for (Node node : visualState.getNodeList()) {
|
|
|
+ drawCanvasObject(g2d, "/Images/node.png", node.getPosition());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//-->oldCode
|
|
|
if (doMark) {
|
|
|
g2d.setColor(Color.BLACK);
|
|
@@ -643,30 +634,29 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
g2d.setColor(Color.BLUE);
|
|
|
g2d.setStroke(new BasicStroke(1));
|
|
|
Color transparentGrey = new Color(128, 174, 247, 40);
|
|
|
- for(AbstractCanvasObject aCps: model.getSelectedCpsObjects()) {
|
|
|
- if(aCps instanceof Node) {
|
|
|
+ for (AbstractCanvasObject aCps : model.getSelectedCpsObjects()) {
|
|
|
+ if (aCps instanceof Node) {
|
|
|
Position pos = aCps.getPosition();
|
|
|
g2d.setColor(transparentGrey);
|
|
|
- g2d.fillOval(pos.x - (int) (controller.getScaleDiv2()), pos.y - (int) (controller.getScaleDiv2()), controller.getScale(), controller.getScale());
|
|
|
+ g2d.fillOval(pos.x - (int) (controller.getScaleDiv2()), pos.y - (int) (controller.getScaleDiv2()), controller.getScale(), controller.getScale());
|
|
|
g2d.setColor(Color.LIGHT_GRAY);
|
|
|
g2d.setStroke(new BasicStroke(2));
|
|
|
- g2d.drawOval(pos.x - (int) (controller.getScaleDiv2()), pos.y - (int) (controller.getScaleDiv2()), controller.getScale(), controller.getScale());
|
|
|
- }
|
|
|
- else {
|
|
|
+ g2d.drawOval(pos.x - (int) (controller.getScaleDiv2()), pos.y - (int) (controller.getScaleDiv2()), controller.getScale(), controller.getScale());
|
|
|
+ } else {
|
|
|
Position pos = aCps.getPosition();
|
|
|
g2d.setColor(transparentGrey);
|
|
|
- g2d.fillRect(pos.x - (int) (controller.getScaleDiv2()* 1.5f), pos.y - (int) (controller.getScaleDiv2()* 1.5f), (int) (controller.getScale()* 1.5f) , (int) (controller.getScale()* 1.5f));
|
|
|
+ g2d.fillRect(pos.x - (int) (controller.getScaleDiv2() * 1.5f), pos.y - (int) (controller.getScaleDiv2() * 1.5f), (int) (controller.getScale() * 1.5f), (int) (controller.getScale() * 1.5f));
|
|
|
g2d.setColor(Color.LIGHT_GRAY);
|
|
|
g2d.setStroke(new BasicStroke(2));
|
|
|
- g2d.drawRect(pos.x - (int) (controller.getScaleDiv2()* 1.5f), pos.y - (int) (controller.getScaleDiv2()* 1.5f), (int) (controller.getScale()* 1.5f) , (int) (controller.getScale()* 1.5f));
|
|
|
+ g2d.drawRect(pos.x - (int) (controller.getScaleDiv2() * 1.5f), pos.y - (int) (controller.getScaleDiv2() * 1.5f), (int) (controller.getScale() * 1.5f), (int) (controller.getScale() * 1.5f));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//maybeReplace:
|
|
|
- if(mayBeReplaced != null){
|
|
|
+ if (mayBeReplaced != null) {
|
|
|
g2d.setColor(Color.RED);
|
|
|
Position pos = mayBeReplaced.getPosition();
|
|
|
- g2d.drawImage(ImageImport.loadImage("/Images/replace.png") ,
|
|
|
+ g2d.drawImage(ImageImport.loadImage("/Images/replace.png"),
|
|
|
pos.x + controller.getScaleDiv2(),
|
|
|
pos.y - controller.getScale(),
|
|
|
controller.getScaleDiv2(), controller.getScaleDiv2(), null);
|
|
@@ -674,13 +664,21 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
//<-- OldCode
|
|
|
|
|
|
// Draw solver job
|
|
|
- HolegPowerFlowContext context = SingletonControl.getInstance().getControl().getSimManager().getHolegPowerFlowContext();
|
|
|
- if (context != null) {
|
|
|
+ Set<HolegPowerFlowContext> contextSet = HolegGateway.getALlContext();
|
|
|
+ if (contextSet.size() > 0) {
|
|
|
+ float maxTime = 0;
|
|
|
+ int runningCount = 0;
|
|
|
+ for (HolegPowerFlowContext context : contextSet) {
|
|
|
+ maxTime = Math.max(maxTime, context.solverTimeMilliseconds);
|
|
|
+ if (context.isSolving())
|
|
|
+ runningCount++;
|
|
|
+ }
|
|
|
+
|
|
|
g2d.setColor(Color.BLACK);
|
|
|
- if (context.isSolving())
|
|
|
- g2d.drawString("Solver running...", 4, 14);
|
|
|
+ if (runningCount > 0)
|
|
|
+ g2d.drawString(String.format("%d of %d solver running...", runningCount, contextSet.size()), 4, 14);
|
|
|
else
|
|
|
- g2d.drawString(String.format("Solver finished in %.2f ms", context.solverTimeMilliseconds), 4, 14);
|
|
|
+ g2d.drawString(String.format("Solver finished in max %.2f ms", maxTime), 4, 14);
|
|
|
}
|
|
|
}
|
|
|
|