Przeglądaj źródła

Merged Jascha and Jan, Operator Multigraph now (afaik) bug free!

Jan Enders 7 lat temu
rodzic
commit
7333a227f1

+ 27 - 15
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/graphs/GraphManager.java

@@ -374,7 +374,7 @@ public class GraphManager {
 		}
 		g.addNode(n.getId());
 		g.getNode(n.getId()).addAttributes(attributes);
-		if (activeSubGraph != null) {
+		if (activeSubGraph != null && !activeSubGraph.equals(g)) {
 			activeSubGraph.addNode(n.getId());
 			activeSubGraph.getNode(n.getId()).addAttributes(attributes);
 			g.getNode(n.getId()).addAttribute("originalElement", activeSubGraph.getId() + "+#" + n.getId());
@@ -524,21 +524,33 @@ public class GraphManager {
 		if (getGraph().getNode(from).hasEdgeBetween(to))
 			return false;
 		String newID = Main.getInstance().getUnusedID();
-		Edge e;
-		if (Main.getInstance().getCreationMode() == CreationMode.CREATE_DIRECTED_EDGE) {
-			e = getGraph().addEdge(newID, from, to, true);
-			Debug.out("Created an directed edge with Id " + newID + " between " + from + " and " + to);
-		} else {
-			e = getGraph().addEdge(newID, from, to);
-			Debug.out("Created an undirected edge with Id " + newID + " between " + from + " and " + to);
-		}
+
+		boolean isDirected = (Main.getInstance().getCreationMode() == CreationMode.CREATE_DIRECTED_EDGE);
+		Node sourceNode = g.getNode(from);
+		Node targetNode = g.getNode(to);
 		
-		Debug.out(activeSubGraph);
-		if (activeSubGraph != null) {
-			Debug.out("edge creation");
-			activeSubGraph.addEdge(e.getId(), e.getSourceNode().getAttribute("originalElement").toString().split("\\+#")[1]
-					, e.getTargetNode().getAttribute("originalElement").toString().split("\\+#")[1], e.isDirected());
-			g.getEdge(e.getId()).addAttribute("originalElement", activeSubGraph.getId() + "+#" + e.getId());
+		if (activeSubGraph != null && !activeSubGraph.equals(g)) {
+			
+			if (sourceNode.getAttribute("originalGraph").equals(activeSubGraph.getId())
+					&& targetNode.getAttribute("originalGraph").equals(activeSubGraph.getId())) {
+				
+				g.addEdge(newID, from, to, isDirected);
+				activeSubGraph.addEdge(newID, from.substring(activeSubGraph.getId().length()), to.substring(activeSubGraph.getId().length()), isDirected);
+				g.getEdge(newID).addAttribute("originalElement", activeSubGraph.getId() + "+#" + newID);
+				
+			} else {
+				if (sourceNode.getAttribute("originalGraph").equals(targetNode.getAttribute("originalGraph"))){
+					Debug.out("Can Only add edges to currently active Subgraph!", 2);
+				} else {
+					Debug.out("Can not create Edge between Nodes of different Subgraphs!", 2);
+				}
+				return false;
+			}
+			
+		} else {
+			
+			g.addEdge(newID, from, to, isDirected);
+			
 		}
 
 		selectEdge(newID);

+ 15 - 12
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/ButtonManager.java

@@ -492,22 +492,27 @@ public final class ButtonManager {
 	 * MapViewFunctions.changeMapView(); }
 	 */
 	public static void setupOpGraphComboBox() {
-		controller.opGraphSelectionBox.getItems().clear();
-		GraphManager operatorManager = GraphDisplayManager.getGraphManager(Layer.OPERATOR);
-		for (MyGraph g : operatorManager.getGraph().getAllSubGraphs().stream().filter((g) -> !g.isComposite())
-				.collect(Collectors.toList())) {
-			controller.opGraphSelectionBox.getItems().add(g.getId());
-		}
-		controller.opGraphSelectionBox.getItems().add("Add...");
 
-	}
+		Platform.runLater(() -> {
+
+			controller.opGraphSelectionBox.getItems().clear();
+
+			GraphManager operatorManager = GraphDisplayManager.getGraphManager(Layer.OPERATOR);
+			for (MyGraph g : operatorManager.getGraph().getAllSubGraphs().stream().filter((g) -> !g.isComposite())
+					.collect(Collectors.toList())) {
+				controller.opGraphSelectionBox.getItems().add(g.getId());
+			}
+			controller.opGraphSelectionBox.getItems().add("Add...");
+			controller.opGraphSelectionBox.setValue(controller.opGraphSelectionBox.getItems().get(0));
+		});
 
-	public static void addToOpGraphComboBox(String id) {
-		controller.opGraphSelectionBox.getItems().add(controller.opGraphSelectionBox.getItems().size() - 1, id);
 	}
 
 	public static void opGraphSelectedAction(ActionEvent v) {
 
+		if (controller.opGraphSelectionBox.getValue() == null || controller.opGraphSelectionBox.getValue().equals("")) {
+			return;
+		}
 		if (controller.opGraphSelectionBox.getValue().equals("Add...")) {
 			MenuBarManager.addAction(v);
 			Platform.runLater(() -> controller.opGraphSelectionBox.setValue(controller.opGraphSelectionBox.getItems()
@@ -515,8 +520,6 @@ public final class ButtonManager {
 		} else {
 			GraphDisplayManager.getGraphManager(Layer.OPERATOR)
 					.setActiveSubGraph(controller.opGraphSelectionBox.getValue());
-			// FIXME: aktuell zu bearbeitenden graphen im GraphManager setzen
-			// (erfordert Jaschas Implementierung)!
 		}
 	}
 

+ 3 - 3
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/ui/MenuBarManager.java

@@ -1,7 +1,6 @@
 package de.tu_darmstadt.informatik.tk.scopviz.ui;
 
 import de.tu_darmstadt.informatik.tk.scopviz.graphs.GraphManager;
-import de.tu_darmstadt.informatik.tk.scopviz.graphs.MyGraph;
 import de.tu_darmstadt.informatik.tk.scopviz.io.GraphMLExporter;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Layer;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
@@ -41,6 +40,7 @@ public final class MenuBarManager {
 			GraphDisplayManager.readMapping();
 		} else {
 			GraphDisplayManager.addGraph(Main.getInstance().getPrimaryStage(), true);
+			ButtonManager.setupOpGraphComboBox();
 		}
 	}
 
@@ -48,8 +48,8 @@ public final class MenuBarManager {
 	 * Handler for the "add" MenuItem.
 	 */
 	public static final void addAction(ActionEvent event) {
-		MyGraph newGraph = GraphDisplayManager.addGraph(Main.getInstance().getPrimaryStage(), false);
-		ButtonManager.addToOpGraphComboBox(newGraph.getId());
+		GraphDisplayManager.addGraph(Main.getInstance().getPrimaryStage(), false);
+		ButtonManager.setupOpGraphComboBox();
 	}
 
 	/**