|
@@ -1,15 +1,19 @@
|
|
|
package de.tu_darmstadt.informatik.tk.scopviz.graphs;
|
|
|
|
|
|
+import java.util.Collection;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.Random;
|
|
|
|
|
|
import org.graphstream.algorithm.Toolkit;
|
|
|
import org.graphstream.graph.Edge;
|
|
|
+import org.graphstream.graph.Element;
|
|
|
import org.graphstream.graph.Node;
|
|
|
import org.graphstream.ui.geom.Point3;
|
|
|
|
|
|
+import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
|
|
|
import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
|
|
|
+import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
|
|
|
import de.tu_darmstadt.informatik.tk.scopviz.ui.OptionsManager;
|
|
|
|
|
|
public class GraphHelper {
|
|
@@ -66,7 +70,13 @@ public class GraphHelper {
|
|
|
while (searchingForId) {
|
|
|
if (target.getEdge(newId) == null) {
|
|
|
searchingForId = false;
|
|
|
- target.addEdge(newId, newIds.get(e.getSourceNode().getId()), newIds.get(e.getTargetNode().getId()));
|
|
|
+ target.addEdge(newId, newIds.get(e.getSourceNode().getId()), newIds.get(e.getTargetNode().getId()), e.isDirected());
|
|
|
+ if(e.getAttribute("originalElement") == null) {
|
|
|
+ target.getEdge(newId).addAttribute("originalElement", source.getId().concat("+#" + e.getId()));
|
|
|
+ } else {
|
|
|
+ target.getEdge(newId).addAttribute("originalElement",(Object) e.getAttribute("originalElement"));
|
|
|
+ }
|
|
|
+
|
|
|
} else {
|
|
|
newId = newId.concat(String.valueOf((char) (ran.nextInt(52) + 'a')));
|
|
|
}
|
|
@@ -90,6 +100,11 @@ public class GraphHelper {
|
|
|
searchingForId = false;
|
|
|
target.addNode(newId);
|
|
|
newIds.put(n.getId(), newId);
|
|
|
+ if(n.getAttribute("originalElement") == null) {
|
|
|
+ target.getNode(newId).addAttribute("originalElement", source.getId().concat("+#" + n.getId()));
|
|
|
+ } else {
|
|
|
+ target.getNode(newId).addAttribute("originalElement",(Object) n.getAttribute("originalElement"));
|
|
|
+ }
|
|
|
} else {
|
|
|
newId = newId.concat(String.valueOf((char) (ran.nextInt(52) + 'a')));
|
|
|
}
|
|
@@ -145,7 +160,9 @@ public class GraphHelper {
|
|
|
if (n.hasAttribute("xyz")) {
|
|
|
coords = Toolkit.nodePointPosition(n);
|
|
|
n.setAttribute("x", coords.x);
|
|
|
+ propagateAttribute(g, n, "x", coords.x);
|
|
|
n.setAttribute("y", coords.y);
|
|
|
+ propagateAttribute(g, n, "y", coords.y);
|
|
|
n.removeAttribute("xyz");
|
|
|
}
|
|
|
}
|
|
@@ -215,4 +232,131 @@ public class GraphHelper {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public static void propagateAttribute (MyGraph g, Element n, String attribute, Object value){
|
|
|
+ if(n.getAttribute("originalElement") == null){
|
|
|
+ Debug.out("Debug: Attribute originalElement does not Exist");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String origGraph = n.getAttribute("originalElement").toString().split("\\+#")[0];
|
|
|
+ String origNode = n.getAttribute("originalElement").toString().split("\\+#")[1];
|
|
|
+ Node oldNode = null;
|
|
|
+ Edge oldEdge = null;
|
|
|
+ MyGraph old = null;
|
|
|
+ Iterator<MyGraph> graphIter = g.getAllSubGraphs().iterator();
|
|
|
+ while(graphIter.hasNext()){
|
|
|
+ old = graphIter.next();
|
|
|
+ if(old.getId().equals(origGraph)){
|
|
|
+ Iterator<Node> nodeIter = old.getNodeIterator();
|
|
|
+ while (nodeIter.hasNext()){
|
|
|
+ oldNode = nodeIter.next();
|
|
|
+ if(oldNode.getId().equals(origNode)){
|
|
|
+ if(value == null){
|
|
|
+ oldNode.removeAttribute(attribute);
|
|
|
+ } else {
|
|
|
+ oldNode.addAttribute(attribute, value);
|
|
|
+ }
|
|
|
+ Debug.out("Debug: propagating successfull");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Iterator<Edge> edgeIter = old.getEdgeIterator();
|
|
|
+ while (edgeIter.hasNext()){
|
|
|
+ oldEdge = edgeIter.next();
|
|
|
+ if(oldEdge.getId().equals(origNode)){
|
|
|
+ if(value == null){
|
|
|
+ oldEdge.removeAttribute(attribute);
|
|
|
+ } else {
|
|
|
+ oldEdge.addAttribute(attribute, value);
|
|
|
+ }
|
|
|
+ Debug.out("Debug: propagating successfull");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Debug.out("WARNING: could not find the specified Element " + origNode + " in the Graph " + origGraph, 2);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Debug.out("WARNING: could not find the specified Graph " + origGraph, 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String propagateElementDeletion(MyGraph g, Collection<? extends Element> col) {
|
|
|
+ Iterator<? extends Element> elementIter = col.iterator();
|
|
|
+ while (elementIter.hasNext()){
|
|
|
+ Element e = elementIter.next();
|
|
|
+ return propagateElementDeletion(g, e);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String propagateElementDeletion(MyGraph g, Element e){
|
|
|
+ if(e.getAttribute("originalElement") == null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String origGraph = e.getAttribute("originalElement").toString().split("\\+#")[0];
|
|
|
+ String origId = e.getAttribute("originalElement").toString().split("\\+#")[1];
|
|
|
+ Iterator<MyGraph> graphIter = g.getAllSubGraphs().iterator();
|
|
|
+ while(graphIter.hasNext()){
|
|
|
+ MyGraph temp = graphIter.next();
|
|
|
+ if (temp.getId().equals(origGraph)){
|
|
|
+ if(e instanceof Node && temp.getNode(origId) != null){
|
|
|
+ temp.removeNode(origId);
|
|
|
+ return temp.getId();
|
|
|
+ } else if (e instanceof Edge && temp.getEdge(origId) != null){
|
|
|
+ temp.removeEdge(origId);
|
|
|
+ return temp.getId();
|
|
|
+ } else {
|
|
|
+ Debug.out("INFORMATION: could not Delete Element bećause it didn't exist: " + origGraph + ":" + origId ,1);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Debug.out("WARNING: could not find the specified Graph " + origGraph, 2);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String propagateElementUndeletion(MyGraph g,Element e, String newNodeId){
|
|
|
+ if(e.getAttribute("originalElement") == null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String origGraph = e.getAttribute("originalElement").toString().split("\\+#")[0];
|
|
|
+ String origId = e.getAttribute("originalElement").toString().split("\\+#")[1];
|
|
|
+ Iterator<MyGraph> graphIter = g.getAllSubGraphs().iterator();
|
|
|
+ HashMap<String, Object> attributes = new HashMap<String, Object>();
|
|
|
+ for (String s : e.getAttributeKeySet()) {
|
|
|
+ attributes.put(s, e.getAttribute(s));
|
|
|
+ }
|
|
|
+
|
|
|
+ while(graphIter.hasNext()){
|
|
|
+ MyGraph temp = graphIter.next();
|
|
|
+ if (temp.getId().equals(origGraph)){
|
|
|
+ String newId = Main.getInstance().getUnusedID(new GraphManager(temp));
|
|
|
+ if(e instanceof Node){
|
|
|
+ temp.addNode(newId);
|
|
|
+ temp.getNode(newId).addAttributes(attributes);
|
|
|
+ return temp.getId() + "+#" + newId;//the id of Graph+newNode
|
|
|
+ } else if (e instanceof Edge){
|
|
|
+ Edge ed = (Edge) e;
|
|
|
+ String sourceId = ed.getSourceNode().getAttribute("originalElement").toString()
|
|
|
+ .split("\\+#")[newNodeId.split("\\+#").length-1];
|
|
|
+ String targetId = ed.getTargetNode().getAttribute("originalElement").toString()
|
|
|
+ .split("\\+#")[newNodeId.split("\\+#").length-1];
|
|
|
+ if(temp.getNode(sourceId) == null){
|
|
|
+ sourceId = newNodeId.split("\\+#")[newNodeId.split("\\+#").length-1];
|
|
|
+ } else {
|
|
|
+ targetId = newNodeId.split("\\+#")[newNodeId.split("\\+#").length-1];
|
|
|
+ }
|
|
|
+ temp.addEdge(newId, sourceId, targetId, ed.isDirected());
|
|
|
+ temp.getEdge(newId).addAttributes(attributes);
|
|
|
+ return temp.getId() + "+#" + newId;//the id of graph+newEdge
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Debug.out("WARNING: could not find the specified Graph " + origGraph, 2);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void resetUndelete() {
|
|
|
+
|
|
|
+ }
|
|
|
}
|