]> granicus.if.org Git - graphviz/commitdiff
Win tweak panel for graph, default node and default edge attributes
authorglenlow <devnull@localhost>
Tue, 1 Apr 2008 16:37:51 +0000 (16:37 +0000)
committerglenlow <devnull@localhost>
Tue, 1 Apr 2008 16:37:51 +0000 (16:37 +0000)
windows/Graph.cs

index 2b4b3d305cb9a358921019e06f13dc9a76742017..07f440b1b73a6064ede4abc8486ea8af47d6c2f2 100755 (executable)
@@ -31,6 +31,28 @@ namespace Graphviz
                        }\r
                }\r
                \r
+               public event EventHandler Changed;\r
+               \r
+               public IDictionary<string, string> Arguments\r
+               {\r
+                       get { return _arguments; }\r
+               }\r
+\r
+               public IDictionary<string, string> GraphAttributes\r
+               {\r
+                       get { return _graphAttributes; }\r
+               }\r
+\r
+               public IDictionary<string, string> DefaultNodeAttributes\r
+               {\r
+                       get { return _defaultNodeAttributes; }\r
+               }\r
+\r
+               public IDictionary<string, string> DefaultEdgeAttributes\r
+               {\r
+                       get { return _defaultEdgeAttributes; }\r
+               }\r
+                               \r
                public Graph(string filename)\r
                {\r
                        IntPtr file = fopen(filename, "r");\r
@@ -40,6 +62,12 @@ namespace Graphviz
                        if (_graph == IntPtr.Zero)\r
                                throw new Win32Exception();\r
                        fclose(file);\r
+                       \r
+                       _freeLastLayout = false;\r
+                       _arguments = new GraphArguments(this);\r
+                       _graphAttributes = new GraphDefaultAttributes(this, _graph);\r
+                       _defaultNodeAttributes = new GraphDefaultAttributes(this, agprotonode(_graph));\r
+                       _defaultEdgeAttributes = new GraphDefaultAttributes(this, agprotoedge(_graph));\r
                }\r
                \r
                public void Save(string filename)\r
@@ -52,12 +80,6 @@ namespace Graphviz
                        fclose(file);\r
                }\r
                \r
-               public void Layout(string engine)\r
-               {\r
-                       if (gvLayout(_context, _graph, engine) != 0)\r
-                               throw new Exception("bad layout");\r
-               }\r
-               \r
                public Stream Render(string format)\r
                {\r
                        unsafe {\r
@@ -69,6 +91,26 @@ namespace Graphviz
                        }\r
                }\r
                \r
+               public void NoteChanged(bool relayout)\r
+               {\r
+                       if (relayout) {\r
+                               string layout;\r
+                               Arguments.TryGetValue("layout", out layout);\r
+                               if (layout != null) {\r
+                                       if (_freeLastLayout)\r
+                                               gvFreeLayout(_context, _graph);\r
+                                               \r
+                                       if (gvLayout(_context, _graph, layout) != 0)\r
+                                               throw new Exception("bad layout");\r
+                                               \r
+                                       _freeLastLayout = true;\r
+                               }\r
+                       }\r
+                       \r
+                       if (Changed != null)\r
+                               Changed(this, EventArgs.Empty);\r
+               }\r
+               \r
                void IDisposable.Dispose()\r
                {\r
                        agclose(_graph);\r
@@ -94,6 +136,12 @@ namespace Graphviz
                [DllImport("libgraph-4.dll", SetLastError = true)]\r
                private static extern void agclose(IntPtr file);\r
 \r
+               [DllImport("libgraph-4.dll")]\r
+               private static extern IntPtr agprotonode(IntPtr graph);\r
+\r
+               [DllImport("libgraph-4.dll")]\r
+               private static extern IntPtr agprotoedge(IntPtr graph);\r
+\r
                [DllImport("libgraph-4.dll", SetLastError = true)]\r
                private static extern IntPtr agread(IntPtr file);\r
 \r
@@ -103,6 +151,9 @@ namespace Graphviz
                [DllImport("libgvc-4.dll")]\r
                private static extern IntPtr gvContext();\r
 \r
+               [DllImport("libgvc-4.dll")]\r
+               private static extern int gvFreeLayout(IntPtr context, IntPtr graph);\r
+\r
                [DllImport("libgvc-4.dll")]\r
                private static extern int gvLayout(IntPtr context, IntPtr graph, string engine);\r
 \r
@@ -122,6 +173,12 @@ namespace Graphviz
                private static extern unsafe void free(byte* pointer);\r
 \r
                private static readonly IntPtr _context = gvContext();\r
+               \r
                private readonly IntPtr _graph;\r
+               private bool _freeLastLayout;\r
+               private readonly GraphArguments _arguments;\r
+               private readonly GraphDefaultAttributes _graphAttributes;\r
+               private readonly GraphDefaultAttributes _defaultNodeAttributes;\r
+               private readonly GraphDefaultAttributes _defaultEdgeAttributes;\r
        }\r
 }\r