|
@@ -34,6 +34,14 @@ public class GraphHelper {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ * merges the two graphs into one. every Node gets two attributes,
|
|
|
|
+ * originalGraph and originalElement which are the ids of the Graph and the
|
|
|
|
+ * graphid + "+#" + nodeid
|
|
|
|
+ *
|
|
|
|
+ * @param target the graph that the source will be merged into
|
|
|
|
+ * @param source the graph that will be merged into the traget graph
|
|
|
|
+ */
|
|
|
|
|
|
private static void mergeInto(MyGraph target, MyGraph source) {
|
|
private static void mergeInto(MyGraph target, MyGraph source) {
|
|
double targetMinX = target.getMinX();
|
|
double targetMinX = target.getMinX();
|
|
@@ -60,6 +68,14 @@ public class GraphHelper {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ * copys all edges from one Graph to another adjusting for nodeId changes.
|
|
|
|
+ * this must always be called after copyNodes.
|
|
|
|
+ *
|
|
|
|
+ * @param target the graph that the new node will be added into
|
|
|
|
+ * @param source the Graph that has the nodes to be copied
|
|
|
|
+ * @param newIds a HashMap that give the new id Values of copied Nodes
|
|
|
|
+ */
|
|
private static void copyEdges(MyGraph target, MyGraph source, HashMap<String, String> newIds) {
|
|
private static void copyEdges(MyGraph target, MyGraph source, HashMap<String, String> newIds) {
|
|
Random ran = new Random();
|
|
Random ran = new Random();
|
|
boolean searchingForId = true;
|
|
boolean searchingForId = true;
|
|
@@ -89,6 +105,15 @@ public class GraphHelper {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ * copies all Nodes from one Graph to another
|
|
|
|
+ * always must be called before copyEdges
|
|
|
|
+ *
|
|
|
|
+ * @param target the Graph that the Nodes will be copied into
|
|
|
|
+ * @param source the graph that the node will be taken from
|
|
|
|
+ * @return a HahMap to convert the old id of Nodes to new ones
|
|
|
|
+ */
|
|
private static HashMap<String, String> copyNodes(MyGraph target, MyGraph source) {
|
|
private static HashMap<String, String> copyNodes(MyGraph target, MyGraph source) {
|
|
HashMap<String, String> newIds = new HashMap<>();
|
|
HashMap<String, String> newIds = new HashMap<>();
|
|
Random ran = new Random();
|
|
Random ran = new Random();
|
|
@@ -120,6 +145,13 @@ public class GraphHelper {
|
|
return newIds;
|
|
return newIds;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ * adjusts the y coordinates of the source graph so the two are of similar size
|
|
|
|
+ * @param g the source graph with unaltered coordinates
|
|
|
|
+ * @param scalingFactor the factor that is used to ensure a roughly similiar size between the Graphs
|
|
|
|
+ * @param targetMinY the minimal y Coordinate of the target Graph
|
|
|
|
+ * @param sourceMinY the minimal y Coordinate of the source Graph
|
|
|
|
+ */
|
|
private static void adjustSourceYCoordinates(MyGraph g, double scalingFactor, double targetMinY,
|
|
private static void adjustSourceYCoordinates(MyGraph g, double scalingFactor, double targetMinY,
|
|
double sourceMinY) {
|
|
double sourceMinY) {
|
|
for (Node n : g.getNodeSet()) {
|
|
for (Node n : g.getNodeSet()) {
|
|
@@ -131,6 +163,12 @@ public class GraphHelper {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ * gives all Nodes a parameter that has the Id of the Graph they belonged to before the merge.
|
|
|
|
+ * if a node already has this attriute it will be ignored
|
|
|
|
+ *
|
|
|
|
+ * @param g the originalGraph of the Nodes
|
|
|
|
+ */
|
|
private static void graphAttribute(MyGraph g) {
|
|
private static void graphAttribute(MyGraph g) {
|
|
for (Node n : g.getNodeSet()) {
|
|
for (Node n : g.getNodeSet()) {
|
|
if (n.getAttribute("originalGraph") == null) {
|
|
if (n.getAttribute("originalGraph") == null) {
|
|
@@ -139,6 +177,13 @@ public class GraphHelper {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ * adjusts the x coordinates of the source graph so the two are of similar size
|
|
|
|
+ * @param g the source graph with unaltered coordinates
|
|
|
|
+ * @param scalingFactor the factor that is used to ensure a roughly similiar size between the Graphs
|
|
|
|
+ * @param xOffset the x distance between the graphs
|
|
|
|
+ * @param sourceMinY the minimal x Coordinate of the source Graph
|
|
|
|
+ */
|
|
private static void adjustSourceXCoordinates(MyGraph g, Double scalingFactor, Double xOffset, Double SourceMinX) {
|
|
private static void adjustSourceXCoordinates(MyGraph g, Double scalingFactor, Double xOffset, Double SourceMinX) {
|
|
for (Node n : g.getNodeSet()) {
|
|
for (Node n : g.getNodeSet()) {
|
|
Double d = (Double) n.getAttribute("x");
|
|
Double d = (Double) n.getAttribute("x");
|
|
@@ -236,6 +281,14 @@ public class GraphHelper {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ * propagates an Attribute to the Node in the Graph it originated from
|
|
|
|
+ *
|
|
|
|
+ * @param g the root of the Multigraph
|
|
|
|
+ * @param n the Element of the multigraph that was changed
|
|
|
|
+ * @param attribute the attribute that was changed
|
|
|
|
+ * @param value the value the attribute was changed to
|
|
|
|
+ */
|
|
public static void propagateAttribute(MyGraph g, Element n, String attribute, Object value) {
|
|
public static void propagateAttribute(MyGraph g, Element n, String attribute, Object value) {
|
|
if (n.getAttribute("originalElement") == null) {
|
|
if (n.getAttribute("originalElement") == null) {
|
|
Debug.out("Debug: Attribute originalElement does not Exist");
|
|
Debug.out("Debug: Attribute originalElement does not Exist");
|
|
@@ -284,6 +337,13 @@ public class GraphHelper {
|
|
Debug.out("WARNING: could not find the specified Graph " + origGraph, 2);
|
|
Debug.out("WARNING: could not find the specified Graph " + origGraph, 2);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ * propagates the deletion of a collection of Elements to the Graph the element originally came from.
|
|
|
|
+ *
|
|
|
|
+ * @param g the root graph of the multigraph
|
|
|
|
+ * @param col the collection that has to be deleted
|
|
|
|
+ * @return the id of the graph that the elements were deleted from or null if no change occurred
|
|
|
|
+ */
|
|
public static String propagateElementDeletion(MyGraph g, Collection<? extends Element> col) {
|
|
public static String propagateElementDeletion(MyGraph g, Collection<? extends Element> col) {
|
|
Iterator<? extends Element> elementIter = col.iterator();
|
|
Iterator<? extends Element> elementIter = col.iterator();
|
|
while (elementIter.hasNext()) {
|
|
while (elementIter.hasNext()) {
|
|
@@ -293,6 +353,13 @@ public class GraphHelper {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ * propagates the deletion of an Element to the Graph it originated from
|
|
|
|
+ *
|
|
|
|
+ * @param g the root graph of the multigraph
|
|
|
|
+ * @param e the element that will be deleted
|
|
|
|
+ * @return the id of the graph that the elements were deleted from or null if no change occurred
|
|
|
|
+ */
|
|
public static String propagateElementDeletion(MyGraph g, Element e) {
|
|
public static String propagateElementDeletion(MyGraph g, Element e) {
|
|
if (e.getAttribute("originalElement") == null) {
|
|
if (e.getAttribute("originalElement") == null) {
|
|
return null;
|
|
return null;
|
|
@@ -320,6 +387,13 @@ public class GraphHelper {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ * propagates the undeletion of an Element
|
|
|
|
+ * @param g the root graph of the multigraph
|
|
|
|
+ * @param e the element that will be readded
|
|
|
|
+ * @param newNodeId the new id of the undeleted Node, only important if elemen is an Edge
|
|
|
|
+ * @return the new originalElement Attribute
|
|
|
|
+ */
|
|
public static String propagateElementUndeletion(MyGraph g, Element e, String newNodeId) {
|
|
public static String propagateElementUndeletion(MyGraph g, Element e, String newNodeId) {
|
|
if (e.getAttribute("originalElement") == null) {
|
|
if (e.getAttribute("originalElement") == null) {
|
|
return null;
|
|
return null;
|
|
@@ -363,8 +437,4 @@ public class GraphHelper {
|
|
Debug.out("WARNING: could not find the specified Graph " + origGraph, 2);
|
|
Debug.out("WARNING: could not find the specified Graph " + origGraph, 2);
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
-
|
|
|
|
- public static void resetUndelete() {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
}
|
|
}
|