Explorar o código

added new Version of multigraph export

jascha Bohne %!s(int64=8) %!d(string=hai) anos
pai
achega
b523fbedcb

+ 3 - 5
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/GraphMLExporter.java

@@ -33,10 +33,11 @@ public class GraphMLExporter {
 	 *            The Location on disk the File will be saved on
 	 */
 	public void writeGraph(final MyGraph g, final String fileName) {
-		FileSinkGraphML writer = new MyFileSinkGraphML();
+		MyFileSinkGraphML writer = new MyFileSinkGraphML();
 		if(g.isComposite()){
 			for(int i = 0; i < g.getChildren().toArray().length; i++){
-				writeGraph(g.getChildren().toArray(new MyGraph[0])[i], fileName +  "children"+i);
+				writer.exportGraphs(g.getAllSubGraphs(), fileName);
+				return;
 			}
 			return;
 		}
@@ -65,9 +66,6 @@ public class GraphMLExporter {
 			fileName = fileChooser.showSaveDialog(stage).getPath();
 			Main.getInstance().getGraphManager().setCurrentPath(fileName);
 			if (fileName != null) {
-				for(int i = 0; i < g.getChildren().toArray().length; i++){
-					writeGraph(g.getChildren().toArray(new MyGraph[0])[i], fileName + "children"+i);
-				}
 				writeGraph(g, fileName);
 			}
 		} catch (NullPointerException e) {

+ 5 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/GraphMLImporter.java

@@ -8,6 +8,7 @@ import org.graphstream.graph.Node;
 import org.graphstream.graph.implementations.SingleGraph;
 
 import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
+import de.tu_darmstadt.informatik.tk.scopviz.graphs.GraphHelper;
 import de.tu_darmstadt.informatik.tk.scopviz.graphs.MyGraph;
 import de.tu_darmstadt.informatik.tk.scopviz.main.Main;
 import de.tu_darmstadt.informatik.tk.scopviz.ui.OptionsManager;
@@ -46,6 +47,9 @@ public class GraphMLImporter {
 			System.out.println("GraphML File doesn't exist or can't be opened");
 			e.printStackTrace();
 		}
+		if(fs.wasMultiGraph()){
+			g = GraphHelper.newMerge(false, fs.getSubGraphs().toArray(new MyGraph[0]));
+		}
 		fs.removeSink(g);
 		for(Node n : g.getNodeSet()){
 			n.removeAttribute("ui.class");
@@ -109,7 +113,7 @@ public class GraphMLImporter {
 	 * 
 	 * @return the list of subgraphs
 	 */
-	public LinkedList<SingleGraph> subGraphs() {
+	public LinkedList<MyGraph> subGraphs() {
 		return fs.getSubGraphs();
 	}
 

+ 0 - 1
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/MyFileSinkGraphML.java

@@ -229,7 +229,6 @@ public class MyFileSinkGraphML extends FileSinkGraphML{
 				exportGraph(g);
 			}
 			isWritingMultigraph = false;
-			print("\t</graph>\n");
 			end();
 		} catch(IOException e){
 			e.printStackTrace();

+ 3 - 4
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/MyFileSourceGraphML.java

@@ -679,6 +679,7 @@ public class MyFileSourceGraphML extends MySourceBase implements FileSource, XML
 					currentReaderState = ReaderState.END;
 				} else if (isEvent(e, XMLEvent.START_ELEMENT, "key")) {
 					currentReaderState = ReaderState.KEYS;
+					
 				} else if (isEvent(e, XMLEvent.START_ELEMENT, "node") || isEvent(e, XMLEvent.START_ELEMENT, "edge")) {
 					currentReaderState = ReaderState.NODES_EDGES;
 				} else if (isEvent(e, XMLEvent.START_ELEMENT, "data")) {
@@ -1327,7 +1328,6 @@ public class MyFileSourceGraphML extends MySourceBase implements FileSource, XML
 
 		if (id == null)
 			throw newParseError(e, "node requires an id");
-
 		sendNodeAdded(sourceId, id);
 
 		e = getNextEvent();
@@ -1378,7 +1378,6 @@ public class MyFileSourceGraphML extends MySourceBase implements FileSource, XML
 						pushback(yEd);
 						pushback(e);
 						data = __data();
-
 						sendNodeAttributeAdded(sourceId, id, data.key.name, getValue(data));
 
 						sentAttributes.add(data.key);
@@ -1395,8 +1394,8 @@ public class MyFileSourceGraphML extends MySourceBase implements FileSource, XML
 		if (isEvent(e, XMLEvent.START_ELEMENT, "graph")) {
 			Location loc = e.getLocation();
 
-			System.err.printf("[WARNING] %d:%d graph inside node is not implemented", loc.getLineNumber(),
-					loc.getColumnNumber());
+			Debug.out(String.format("[WARNING] %d:%d graph inside node is not implemented", loc.getLineNumber(),
+					loc.getColumnNumber()),2);
 
 			pushback(e);
 			__graph();

+ 30 - 5
scopviz/src/main/java/de/tu_darmstadt/informatik/tk/scopviz/io/MySourceBase.java

@@ -48,6 +48,7 @@ import org.graphstream.stream.Source;
 import org.graphstream.stream.sync.SourceTime;
 
 import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
+import de.tu_darmstadt.informatik.tk.scopviz.graphs.MyGraph;
 
 /**
  * Base implementation of an input that provide basic sink handling.
@@ -73,6 +74,23 @@ import de.tu_darmstadt.informatik.tk.scopviz.debug.Debug;
  */
 public class MySourceBase implements Source {
 	// Attribute
+	
+	/**
+	 * if the programm is currently reading a multigraph
+	 */
+	protected boolean multiGraph = false;
+	
+	/** 
+	 * @return if the last read Graph was a multigraph
+	 */
+	public boolean wasMultiGraph(){
+		return multiGraph;
+	}
+
+	/**
+	 * the sink of the complete Graph
+	 */
+	protected Sink originalSink;
 
 	/**
 	 * Enum of the different possible Types of Elements.
@@ -116,12 +134,12 @@ public class MySourceBase implements Source {
 	/**
 	 * a List of all inner Graphs of a multigraphFile.
 	 */
-	protected LinkedList<SingleGraph> subGraphs = new LinkedList<>();
+	protected LinkedList<MyGraph> subGraphs = new LinkedList<>();
 
 	/**
 	 * all inner graphs that are currently being edited.
 	 */
-	protected Stack<SingleGraph> usedSubGraphs = new Stack<>();
+	protected Stack<MyGraph> usedSubGraphs = new Stack<>();
 
 	/**
 	 * the ID of the (last added) outer Graph.
@@ -172,6 +190,8 @@ public class MySourceBase implements Source {
 	// Command
 
 	public void addSink(Sink sink) {
+		multiGraph = false;
+		originalSink = sink;
 		addAttributeSink(sink);
 		addElementSink(sink);
 		resetSubGraphs();
@@ -1175,7 +1195,12 @@ public class MySourceBase implements Source {
 	 * called
 	 */
 	protected void newSubGraph() {
-		SingleGraph g = new SingleGraph(superID + "sub" + subGraphCounter);
+		if(subGraphCounter>1){
+			Debug.out(originalSink.toString());
+			removeSink(originalSink);
+			multiGraph = true;
+		}
+		MyGraph g = new MyGraph(superID + "sub" + subGraphCounter);
 		subGraphCounter++;
 		addSubGraphSink(g);
 		usedSubGraphs.push(g);
@@ -1186,7 +1211,7 @@ public class MySourceBase implements Source {
 	 * sinkLists
 	 */
 	protected void subGraphFinished() {
-		SingleGraph g = usedSubGraphs.pop();
+		MyGraph g = usedSubGraphs.pop();
 		removeSink(g);
 		subGraphs.add(g);
 	}
@@ -1198,7 +1223,7 @@ public class MySourceBase implements Source {
 	 * 
 	 * @return all subGraphs
 	 */
-	public LinkedList<SingleGraph> getSubGraphs() {
+	public LinkedList<MyGraph> getSubGraphs() {
 		return subGraphs;
 	}