|
@@ -15,18 +15,19 @@ import java.awt.geom.Path2D;
|
|
import java.awt.geom.Point2D;
|
|
import java.awt.geom.Point2D;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.LinkedList;
|
|
import java.util.LinkedList;
|
|
|
|
+import java.util.List;
|
|
import java.util.ListIterator;
|
|
import java.util.ListIterator;
|
|
import java.util.Optional;
|
|
import java.util.Optional;
|
|
|
|
+import java.util.Set;
|
|
|
|
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JPanel;
|
|
|
|
|
|
import classes.HolonElement;
|
|
import classes.HolonElement;
|
|
-import interfaces.GraphEditable;
|
|
|
|
import interfaces.GraphEditable.GraphType;
|
|
import interfaces.GraphEditable.GraphType;
|
|
-import interfaces.LocalMode;
|
|
|
|
import interfaces.TimelineDependent;
|
|
import interfaces.TimelineDependent;
|
|
import ui.controller.Control;
|
|
import ui.controller.Control;
|
|
import ui.model.Model;
|
|
import ui.model.Model;
|
|
|
|
+import utility.Maths;
|
|
import utility.Vector2Int;
|
|
import utility.Vector2Int;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -52,6 +53,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
private static final Color editDotColor = new Color(255, 119, 0);
|
|
private static final Color editDotColor = new Color(255, 119, 0);
|
|
private static final Color[] seriesColorArray = { Color.blue, Color.cyan, Color.black, Color.green, Color.gray,
|
|
private static final Color[] seriesColorArray = { Color.blue, Color.cyan, Color.black, Color.green, Color.gray,
|
|
Color.magenta, Color.yellow, Color.PINK, Color.red };
|
|
Color.magenta, Color.yellow, Color.PINK, Color.red };
|
|
|
|
+ private static final Color globalCurveColor = new Color(255, 30, 30);
|
|
|
|
|
|
// Intern Variables
|
|
// Intern Variables
|
|
private class Series {
|
|
private class Series {
|
|
@@ -64,8 +66,17 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
private ArrayList<Series> seriesList = new ArrayList<Series>();
|
|
private ArrayList<Series> seriesList = new ArrayList<Series>();
|
|
private Vector2Int editPosition;
|
|
private Vector2Int editPosition;
|
|
private Optional<Series> actualSeries;
|
|
private Optional<Series> actualSeries;
|
|
- private boolean editMode = false;
|
|
|
|
|
|
|
|
|
|
+ private class GlobalCurve {
|
|
|
|
+ public LinkedList<UnitGraphPoint> points = new LinkedList<UnitGraphPoint>();
|
|
|
|
+ public float minEnergy;
|
|
|
|
+ public float maxEnergy;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Optional<GlobalCurve> globalCurve = Optional.empty();
|
|
|
|
+ private boolean editMode = false;
|
|
|
|
+ private Set<HolonElement> elements;
|
|
|
|
+
|
|
private enum EditPointType {
|
|
private enum EditPointType {
|
|
Normal, StartPoint, EndPoint
|
|
Normal, StartPoint, EndPoint
|
|
};
|
|
};
|
|
@@ -112,6 +123,46 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
repaint();
|
|
repaint();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void setGlobalCurve(Set<HolonElement> elements) {
|
|
|
|
+ // TODO debug timing -> if to long async
|
|
|
|
+ if(elements.isEmpty()) {
|
|
|
|
+ this.globalCurve = Optional.empty();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ GlobalCurve curve = new GlobalCurve();
|
|
|
|
+ curve.maxEnergy = elements.stream().map(ele -> ele.getEnergy()).filter(energy -> energy > 0).reduce(0.0f,
|
|
|
|
+ Float::sum);
|
|
|
|
+ curve.minEnergy = elements.stream().map(ele -> ele.getEnergy()).filter(energy -> energy < 0).reduce(0.0f,
|
|
|
|
+ Float::sum);
|
|
|
|
+
|
|
|
|
+ float[] sample = new float[model.getMaxIterations()];
|
|
|
|
+ // sample energy
|
|
|
|
+ for (HolonElement element : elements) {
|
|
|
|
+ for (int i = 0; i < model.getMaxIterations(); i++) {
|
|
|
|
+ sample[i] += element.getEnergyAtTimeStep(i);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // sample curve
|
|
|
|
+ for (int i = 0; i < model.getMaxIterations(); i++) {
|
|
|
|
+ curve.points.add(new UnitGraphPoint((double) i / (double)model.getMaxIterations(),
|
|
|
|
+ Maths.inverseLinearInterpolation(curve.minEnergy, curve.maxEnergy, sample[i]), false));
|
|
|
|
+ }
|
|
|
|
+ // update displayPosition
|
|
|
|
+ for (UnitGraphPoint p : curve.points) {
|
|
|
|
+ p.calcDisplayedPosition(border, widthWithBorder, heightWithBorder);
|
|
|
|
+ }
|
|
|
|
+ // set global curve
|
|
|
|
+ this.globalCurve = Optional.of(curve);
|
|
|
|
+ this.elements = elements;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void updateGlobalCurve() {
|
|
|
|
+ setGlobalCurve(this.elements);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Paints the Graph, the Grid, the actual Line from the currentIteration
|
|
* Paints the Graph, the Grid, the actual Line from the currentIteration
|
|
*
|
|
*
|
|
@@ -134,6 +185,10 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
g2D.setColor(dotColor);
|
|
g2D.setColor(dotColor);
|
|
g2D.setStroke(new BasicStroke(1));
|
|
g2D.setStroke(new BasicStroke(1));
|
|
drawCurrentIterartionLine(g2D);
|
|
drawCurrentIterartionLine(g2D);
|
|
|
|
+ this.globalCurve.ifPresent(curve -> {
|
|
|
|
+ g2D.setColor(globalCurveColor);
|
|
|
|
+ drawDoubleGraph(g2D, curve.points);
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
// Draw Methods only to let the User see the changes. Nothing its saved here or
|
|
// Draw Methods only to let the User see the changes. Nothing its saved here or
|
|
@@ -154,25 +209,24 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
case boolGraph:
|
|
case boolGraph:
|
|
if (editMode) {
|
|
if (editMode) {
|
|
drawBoolGraphInEditMode(g, series);
|
|
drawBoolGraphInEditMode(g, series);
|
|
- drawSnappingHintFlag = true;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
|
|
+ drawSnappingHintFlag = true;
|
|
|
|
+ } else
|
|
drawBoolGraph(g, series);
|
|
drawBoolGraph(g, series);
|
|
break;
|
|
break;
|
|
case doubleGraph:
|
|
case doubleGraph:
|
|
if (editMode)
|
|
if (editMode)
|
|
drawDoubleGraphInEditMode(g, series);
|
|
drawDoubleGraphInEditMode(g, series);
|
|
else
|
|
else
|
|
- drawDoubleGraph(g, series);
|
|
|
|
|
|
+ drawDoubleGraph(g, series.points);
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
throw new UnsupportedOperationException();
|
|
throw new UnsupportedOperationException();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if(drawSnappingHintFlag) {
|
|
|
|
|
|
+ if (drawSnappingHintFlag) {
|
|
drawSnappingHint(g);
|
|
drawSnappingHint(g);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -238,8 +292,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
private void drawCurrentIterartionLine(Graphics2D g) {
|
|
private void drawCurrentIterartionLine(Graphics2D g) {
|
|
int cur = model.getCurrentIteration();
|
|
int cur = model.getCurrentIteration();
|
|
int max = model.getMaxIterations();
|
|
int max = model.getMaxIterations();
|
|
- if(isLocalPeriedDifferentInSeries()){
|
|
|
|
- for(Series series: seriesList) {
|
|
|
|
|
|
+ if (isLocalPeriedDifferentInSeries()) {
|
|
|
|
+ for (Series series : seriesList) {
|
|
double where;
|
|
double where;
|
|
if (!series.element.isUsingLocalPeriod()) {
|
|
if (!series.element.isUsingLocalPeriod()) {
|
|
where = ((double) cur) / ((double) max);
|
|
where = ((double) cur) / ((double) max);
|
|
@@ -248,12 +302,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
where = ((double) cur % lPeriod) / ((double) lPeriod);
|
|
where = ((double) cur % lPeriod) / ((double) lPeriod);
|
|
}
|
|
}
|
|
Vector2Int oben = new Vector2Int(border + (int) (where * widthWithBorder), 0);
|
|
Vector2Int oben = new Vector2Int(border + (int) (where * widthWithBorder), 0);
|
|
- Vector2Int unten = new Vector2Int(border + (int) (where * widthWithBorder), 2 * border + heightWithBorder);
|
|
|
|
|
|
+ Vector2Int unten = new Vector2Int(border + (int) (where * widthWithBorder),
|
|
|
|
+ 2 * border + heightWithBorder);
|
|
g.setColor(series.color);
|
|
g.setColor(series.color);
|
|
drawLine(g, oben, unten);
|
|
drawLine(g, oben, unten);
|
|
}
|
|
}
|
|
- }
|
|
|
|
- else {
|
|
|
|
|
|
+ } else {
|
|
double where;
|
|
double where;
|
|
if (!isUsingLocalPeriod()) {
|
|
if (!isUsingLocalPeriod()) {
|
|
where = ((double) cur) / ((double) max);
|
|
where = ((double) cur) / ((double) max);
|
|
@@ -266,7 +320,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
g.setColor(dotColor);
|
|
g.setColor(dotColor);
|
|
drawLine(g, oben, unten);
|
|
drawLine(g, oben, unten);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -463,10 +517,10 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
*
|
|
*
|
|
* @param g2D to draw.
|
|
* @param g2D to draw.
|
|
*/
|
|
*/
|
|
- private void drawDoubleGraph(Graphics2D g, Series series) {
|
|
|
|
- if (series.points.isEmpty())
|
|
|
|
|
|
+ private void drawDoubleGraph(Graphics2D g, List<UnitGraphPoint> points) {
|
|
|
|
+ if (points.isEmpty())
|
|
return;
|
|
return;
|
|
- ListIterator<UnitGraphPoint> iter = series.points.listIterator();
|
|
|
|
|
|
+ ListIterator<UnitGraphPoint> iter = points.listIterator();
|
|
Vector2Int actual = iter.next().displayedPosition;
|
|
Vector2Int actual = iter.next().displayedPosition;
|
|
Path2D.Double path = this.initBezier(actual);
|
|
Path2D.Double path = this.initBezier(actual);
|
|
while (iter.hasNext()) {
|
|
while (iter.hasNext()) {
|
|
@@ -546,6 +600,12 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
p.calcDisplayedPosition(border, widthWithBorder, heightWithBorder);
|
|
p.calcDisplayedPosition(border, widthWithBorder, heightWithBorder);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ this.globalCurve.ifPresent(curve -> {
|
|
|
|
+ for (UnitGraphPoint p : curve.points) {
|
|
|
|
+ p.calcDisplayedPosition(border, widthWithBorder, heightWithBorder);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -767,6 +827,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
public void mouseDragged(MouseEvent e) {
|
|
public void mouseDragged(MouseEvent e) {
|
|
actualSeries.ifPresent(series -> {
|
|
actualSeries.ifPresent(series -> {
|
|
updateEditPointPosition(new Vector2Int(e.getPoint().x, e.getPoint().y), this.editPointType, series.type);
|
|
updateEditPointPosition(new Vector2Int(e.getPoint().x, e.getPoint().y), this.editPointType, series.type);
|
|
|
|
+ updateGlobalCurve();
|
|
repaint();
|
|
repaint();
|
|
});
|
|
});
|
|
|
|
|
|
@@ -830,9 +891,10 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
this.insertNewGraphPoint(series, editPosition);
|
|
this.insertNewGraphPoint(series, editPosition);
|
|
}
|
|
}
|
|
editMode = false;
|
|
editMode = false;
|
|
- repaint();
|
|
|
|
}
|
|
}
|
|
saveGraph();
|
|
saveGraph();
|
|
|
|
+ updateGlobalCurve();
|
|
|
|
+ repaint();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -887,10 +949,9 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
public boolean isLocalPeriedDifferentInSeries() {
|
|
public boolean isLocalPeriedDifferentInSeries() {
|
|
return seriesList.stream().map(series -> series.element.getLocalPeriod()).distinct().count() > 1;
|
|
return seriesList.stream().map(series -> series.element.getLocalPeriod()).distinct().count() > 1;
|
|
}
|
|
}
|
|
|
|
+
|
|
public int getFirstLocalPeriod() {
|
|
public int getFirstLocalPeriod() {
|
|
- int period = 0;
|
|
|
|
- //seriesList.stream().findFirst().ifPresentOrElse(series -> return series.element.getLocalPeriod(), () -> period = LocalMode.STANDARD_GRAPH_ACCURACY);
|
|
|
|
- return period;
|
|
|
|
|
|
+ return seriesList.isEmpty() ? 0 : seriesList.get(0).element.getLocalPeriod();
|
|
}
|
|
}
|
|
|
|
|
|
public boolean isUsingLocalPeriod() {
|
|
public boolean isUsingLocalPeriod() {
|