From: glenlow Date: Tue, 1 Apr 2008 16:37:51 +0000 (+0000) Subject: Win tweak panel for graph, default node and default edge attributes X-Git-Tag: LAST_LIBGRAPH~32^2~4409 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=30ecfcfb41c8759a01d24b406ad80f01008677cc;p=graphviz Win tweak panel for graph, default node and default edge attributes --- diff --git a/windows/Graph.cs b/windows/Graph.cs index 2b4b3d305..07f440b1b 100755 --- a/windows/Graph.cs +++ b/windows/Graph.cs @@ -31,6 +31,28 @@ namespace Graphviz } } + public event EventHandler Changed; + + public IDictionary Arguments + { + get { return _arguments; } + } + + public IDictionary GraphAttributes + { + get { return _graphAttributes; } + } + + public IDictionary DefaultNodeAttributes + { + get { return _defaultNodeAttributes; } + } + + public IDictionary DefaultEdgeAttributes + { + get { return _defaultEdgeAttributes; } + } + public Graph(string filename) { IntPtr file = fopen(filename, "r"); @@ -40,6 +62,12 @@ namespace Graphviz if (_graph == IntPtr.Zero) throw new Win32Exception(); fclose(file); + + _freeLastLayout = false; + _arguments = new GraphArguments(this); + _graphAttributes = new GraphDefaultAttributes(this, _graph); + _defaultNodeAttributes = new GraphDefaultAttributes(this, agprotonode(_graph)); + _defaultEdgeAttributes = new GraphDefaultAttributes(this, agprotoedge(_graph)); } public void Save(string filename) @@ -52,12 +80,6 @@ namespace Graphviz fclose(file); } - public void Layout(string engine) - { - if (gvLayout(_context, _graph, engine) != 0) - throw new Exception("bad layout"); - } - public Stream Render(string format) { unsafe { @@ -69,6 +91,26 @@ namespace Graphviz } } + public void NoteChanged(bool relayout) + { + if (relayout) { + string layout; + Arguments.TryGetValue("layout", out layout); + if (layout != null) { + if (_freeLastLayout) + gvFreeLayout(_context, _graph); + + if (gvLayout(_context, _graph, layout) != 0) + throw new Exception("bad layout"); + + _freeLastLayout = true; + } + } + + if (Changed != null) + Changed(this, EventArgs.Empty); + } + void IDisposable.Dispose() { agclose(_graph); @@ -94,6 +136,12 @@ namespace Graphviz [DllImport("libgraph-4.dll", SetLastError = true)] private static extern void agclose(IntPtr file); + [DllImport("libgraph-4.dll")] + private static extern IntPtr agprotonode(IntPtr graph); + + [DllImport("libgraph-4.dll")] + private static extern IntPtr agprotoedge(IntPtr graph); + [DllImport("libgraph-4.dll", SetLastError = true)] private static extern IntPtr agread(IntPtr file); @@ -103,6 +151,9 @@ namespace Graphviz [DllImport("libgvc-4.dll")] private static extern IntPtr gvContext(); + [DllImport("libgvc-4.dll")] + private static extern int gvFreeLayout(IntPtr context, IntPtr graph); + [DllImport("libgvc-4.dll")] private static extern int gvLayout(IntPtr context, IntPtr graph, string engine); @@ -122,6 +173,12 @@ namespace Graphviz private static extern unsafe void free(byte* pointer); private static readonly IntPtr _context = gvContext(); + private readonly IntPtr _graph; + private bool _freeLastLayout; + private readonly GraphArguments _arguments; + private readonly GraphDefaultAttributes _graphAttributes; + private readonly GraphDefaultAttributes _defaultNodeAttributes; + private readonly GraphDefaultAttributes _defaultEdgeAttributes; } }