|
@@ -1,14 +1,11 @@
|
|
package de.tu_darmstadt.informatik.tk.scopviz.ui;
|
|
package de.tu_darmstadt.informatik.tk.scopviz.ui;
|
|
|
|
|
|
-import java.util.Iterator;
|
|
|
|
-
|
|
|
|
-import org.graphstream.algorithm.Toolkit;
|
|
|
|
-import org.graphstream.graph.Edge;
|
|
|
|
import org.graphstream.graph.Graph;
|
|
import org.graphstream.graph.Graph;
|
|
import org.graphstream.graph.Node;
|
|
import org.graphstream.graph.Node;
|
|
import org.graphstream.ui.geom.Point3;
|
|
import org.graphstream.ui.geom.Point3;
|
|
|
|
|
|
import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
|
|
import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
|
|
|
|
+import de.tu_darmstadt.informatik.tk.scopviz.main.AuxilFunctions;
|
|
import de.tu_darmstadt.informatik.tk.scopviz.main.CreationMode;
|
|
import de.tu_darmstadt.informatik.tk.scopviz.main.CreationMode;
|
|
import de.tu_darmstadt.informatik.tk.scopviz.main.GraphManager;
|
|
import de.tu_darmstadt.informatik.tk.scopviz.main.GraphManager;
|
|
import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
|
|
import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
|
|
@@ -66,9 +63,10 @@ public class ButtonManager {
|
|
GraphManager graphManager = Main.getInstance().getGraphManager();
|
|
GraphManager graphManager = Main.getInstance().getGraphManager();
|
|
Graph graph = graphManager.getGraph();
|
|
Graph graph = graphManager.getGraph();
|
|
Point3 cursorPos = graphManager.getView().getCamera().transformPxToGu(event.getX(), event.getY());
|
|
Point3 cursorPos = graphManager.getView().getCamera().transformPxToGu(event.getX(), event.getY());
|
|
- if (Main.getInstance().getCreationMode() == CreationMode.CREATE_NONE)
|
|
|
|
- Debug.out("(" + cursorPos.x + ", " + cursorPos.y + ")");
|
|
|
|
- Debug.out(getClosestEdge(cursorPos));
|
|
|
|
|
|
+ if (Main.getInstance().getCreationMode() == CreationMode.CREATE_NONE) {
|
|
|
|
+ // TODO this is just a example usage for the Function
|
|
|
|
+ Debug.out(AuxilFunctions.getClosestEdge(cursorPos));
|
|
|
|
+ }
|
|
Node n;
|
|
Node n;
|
|
|
|
|
|
// Create node based on creation Mode
|
|
// Create node based on creation Mode
|
|
@@ -117,41 +115,6 @@ public class ButtonManager {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
- public static Edge getClosestEdge(Point3 pos) {
|
|
|
|
- //TODO get a nice Max_Value, like 5% of maxWidth/maxHeight or something similar
|
|
|
|
- return getClosestEdge(pos, Double.MAX_VALUE);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public static Edge getClosestEdge(Point3 pos, double maxDistance) {
|
|
|
|
- //TODO clean up, relocate to ... somewhere useful
|
|
|
|
- double x0 = pos.x;
|
|
|
|
- double y0 = pos.y;
|
|
|
|
- GraphManager gm = Main.getInstance().getGraphManager();
|
|
|
|
- double dist = maxDistance;
|
|
|
|
- Edge result = null;
|
|
|
|
- for (Iterator<Edge> iterator = gm.getGraph().getEdgeIterator(); iterator.hasNext();) {
|
|
|
|
- Edge edge = (Edge) iterator.next();
|
|
|
|
- double[] n1 = Toolkit.nodePosition(edge.getNode0());
|
|
|
|
- double[] n2 = Toolkit.nodePosition(edge.getNode1());
|
|
|
|
- double x1 = n1[0];
|
|
|
|
- double y1 = n1[1];
|
|
|
|
- double x2 = n2[0];
|
|
|
|
- double y2 = n2[1];
|
|
|
|
- double a = Math.sqrt(Math.pow(y2 - y0, 2) + Math.pow(x2 - x0, 2));
|
|
|
|
- double b = Math.sqrt(Math.pow(y0 - y1, 2) + Math.pow(x0 - x1, 2));
|
|
|
|
- double c = Math.sqrt(Math.pow(y2 - y1, 2) + Math.pow(x2 - x1, 2));
|
|
|
|
- double cdist = Math.abs((y2 - y1) * x0 - (x2 - x1) * y0 + x2 * y1 - y2 * x1) / c;
|
|
|
|
- double alpha = Math.acos((Math.pow(b, 2) + Math.pow(c, 2) - Math.pow(a, 2)) / (2 * b * c));
|
|
|
|
- double beta = Math.acos((Math.pow(a, 2) + Math.pow(c, 2) - Math.pow(b, 2)) / (2 * a * c));
|
|
|
|
- if (cdist < dist && alpha <= Math.PI / 2 && beta <= Math.PI / 2) {
|
|
|
|
- Debug.out("" + alpha);
|
|
|
|
- dist = cdist;
|
|
|
|
- result = edge;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return result;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public static final EventHandler<ActionEvent> underlayHandler = new EventHandler<ActionEvent>() {
|
|
public static final EventHandler<ActionEvent> underlayHandler = new EventHandler<ActionEvent>() {
|
|
|
|
|
|
@Override
|
|
@Override
|