gegl r3045 - trunk/gegl



Author: martinn
Date: Sat Apr 11 15:34:43 2009
New Revision: 3045
URL: http://svn.gnome.org/viewvc/gegl?rev=3045&view=rev

Log:
Add a GeglVisitor for constructing graphviz dot files

Added:
   trunk/gegl/gegl-dot-visitor.c
   trunk/gegl/gegl-dot-visitor.h
Modified:
   trunk/gegl/Makefile.am
   trunk/gegl/gegl-types-internal.h

Modified: trunk/gegl/Makefile.am
==============================================================================
--- trunk/gegl/Makefile.am	(original)
+++ trunk/gegl/Makefile.am	Sat Apr 11 15:34:43 2009
@@ -44,6 +44,7 @@
 	gegl-config.c			\
 	gegl-cpuaccel.c			\
 	gegl-dot.c			\
+	gegl-dot-visitor.c		\
 	gegl-init.c			\
 	gegl-instrument.c		\
 	gegl-utils.c			\
@@ -55,6 +56,7 @@
 	gegl-cpuaccel.h			\
 	gegl-debug.h			\
 	gegl-dot.h			\
+	gegl-dot-visitor.h		\
 	gegl-init.h			\
 	gegl-instrument.h		\
 	gegl-module.h			\

Added: trunk/gegl/gegl-dot-visitor.c
==============================================================================
--- (empty file)
+++ trunk/gegl/gegl-dot-visitor.c	Sat Apr 11 15:34:43 2009
@@ -0,0 +1,118 @@
+/* This file is part of GEGL
+ *
+ * GEGL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2009 Martin Nordholts
+ */
+
+#include "config.h"
+#include <string.h>
+#include <glib-object.h>
+
+#include "gegl.h"
+#include "gegl-types-internal.h"
+#include "gegl-dot.h"
+#include "gegl-dot-visitor.h"
+#include "graph/gegl-node.h"
+#include "graph/gegl-pad.h"
+#include "graph/gegl-visitable.h"
+
+
+struct _GeglDotVisitorPriv
+{
+  GString *string_to_append;
+};
+
+
+static void gegl_dot_visitor_class_init (GeglDotVisitorClass *klass);
+static void gegl_dot_visitor_visit_node (GeglVisitor         *self,
+                                         GeglNode            *node);
+static void gegl_dot_visitor_visit_pad  (GeglVisitor         *self,
+                                         GeglPad             *pad);
+
+
+G_DEFINE_TYPE (GeglDotVisitor, gegl_dot_visitor, GEGL_TYPE_VISITOR)
+
+
+static void
+gegl_dot_visitor_class_init (GeglDotVisitorClass *klass)
+{
+  GeglVisitorClass *visitor_class = GEGL_VISITOR_CLASS (klass);
+
+  visitor_class->visit_node = gegl_dot_visitor_visit_node;
+  visitor_class->visit_pad = gegl_dot_visitor_visit_pad;
+
+  g_type_class_add_private (klass, sizeof (GeglDotVisitorPriv));
+}
+
+static void
+gegl_dot_visitor_init (GeglDotVisitor *self)
+{
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+                                            GEGL_TYPE_DOT_VISITOR,
+                                            GeglDotVisitorPriv);
+}
+
+void
+gegl_dot_visitor_set_string_to_append (GeglDotVisitor *self,
+                                       GString        *string_to_append)
+{
+  self->priv->string_to_append = string_to_append;
+}
+
+static void
+gegl_dot_visitor_visit_node (GeglVisitor *visitor,
+                             GeglNode    *node)
+{
+  GeglDotVisitor *self = GEGL_DOT_VISITOR (visitor);
+
+  g_return_if_fail (self->priv->string_to_append != NULL);
+
+  GEGL_VISITOR_CLASS (gegl_dot_visitor_parent_class)->visit_node (visitor, node);
+
+  gegl_dot_util_add_node (self->priv->string_to_append, node);
+}
+
+static void
+gegl_dot_visitor_visit_pad (GeglVisitor *visitor,
+                            GeglPad     *pad)
+{
+  GeglDotVisitor *self = GEGL_DOT_VISITOR (visitor);
+  GSList         *pads = gegl_pad_get_depends_on (pad);
+  GSList         *iter;
+  GSList         *pad_iter;
+
+  g_return_if_fail (self->priv->string_to_append != NULL);
+
+  GEGL_VISITOR_CLASS (gegl_dot_visitor_parent_class)->visit_pad (visitor, pad);
+
+  for (pad_iter = pads; pad_iter; pad_iter = g_slist_next (pad_iter))
+    {
+      GeglPad *pad = GEGL_PAD (pad_iter->data);
+
+      /* Only use connections of input pads, otherwise we get
+       * duplicate edges in the graphviz file
+       */
+      if (!gegl_pad_is_input (pad))
+        continue;
+
+      for (iter = pad->connections; iter; iter = g_slist_next (iter))
+        {
+          GeglConnection *connection = iter->data;
+          gegl_dot_util_add_connection (self->priv->string_to_append, connection);
+        }
+    }
+
+  g_slist_free (pads);
+}

Added: trunk/gegl/gegl-dot-visitor.h
==============================================================================
--- (empty file)
+++ trunk/gegl/gegl-dot-visitor.h	Sat Apr 11 15:34:43 2009
@@ -0,0 +1,58 @@
+/* This file is part of GEGL
+ *
+ * GEGL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2009 Martin Nordholts
+ */
+
+#ifndef __GEGL_DOT_VISITOR_H__
+#define __GEGL_DOT_VISITOR_H__
+
+#include "graph/gegl-visitor.h"
+
+G_BEGIN_DECLS
+
+
+#define GEGL_TYPE_DOT_VISITOR            (gegl_dot_visitor_get_type ())
+#define GEGL_DOT_VISITOR(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEGL_TYPE_DOT_VISITOR, GeglDotVisitor))
+#define GEGL_DOT_VISITOR_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  GEGL_TYPE_DOT_VISITOR, GeglDotVisitorClass))
+#define GEGL_IS_DOT_VISITOR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEGL_TYPE_DOT_VISITOR))
+#define GEGL_IS_DOT_VISITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GEGL_TYPE_DOT_VISITOR))
+#define GEGL_DOT_VISITOR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  GEGL_TYPE_DOT_VISITOR, GeglDotVisitorClass))
+
+typedef struct _GeglDotVisitorPriv GeglDotVisitorPriv;
+typedef struct _GeglDotVisitorClass GeglDotVisitorClass;
+
+struct _GeglDotVisitor
+{
+  GeglVisitor         parent_instance;
+
+  GeglDotVisitorPriv *priv;
+};
+
+struct _GeglDotVisitorClass
+{
+  GeglVisitorClass  parent_class;
+};
+
+
+GType   gegl_dot_visitor_get_type             (void) G_GNUC_CONST;
+
+void    gegl_dot_visitor_set_string_to_append (GeglDotVisitor *dot_visitor,
+                                               GString        *string_to_append);
+
+
+G_END_DECLS
+
+#endif /* __GEGL_DOT_VISITOR_H__ */

Modified: trunk/gegl/gegl-types-internal.h
==============================================================================
--- trunk/gegl/gegl-types-internal.h	(original)
+++ trunk/gegl/gegl-types-internal.h	Sat Apr 11 15:34:43 2009
@@ -30,6 +30,7 @@
 typedef struct _GeglGraph            GeglGraph;
 typedef struct _GeglHaveVisitor      GeglHaveVisitor;
 typedef struct _GeglNeedVisitor      GeglNeedVisitor;
+typedef struct _GeglDotVisitor       GeglDotVisitor;
 #ifndef __GEGL_PLUGIN_H__
 typedef struct _GeglPad              GeglPad;
 typedef struct _GeglOperation        GeglOperation;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]