}\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
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
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
}\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
[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
[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
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