Commit 9ee47338 authored by Martin Nordholts's avatar Martin Nordholts

Add a GeglVisitor for constructing graphviz dot files

svn path=/trunk/; revision=3045
parent 4b986e16
......@@ -44,6 +44,7 @@ GEGL_sources = \
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_sources = \
gegl-cpuaccel.h \
gegl-debug.h \
gegl-dot.h \
gegl-dot-visitor.h \
gegl-init.h \
gegl-instrument.h \
gegl-module.h \
......
/* 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);
}
/* 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__ */
......@@ -30,6 +30,7 @@ typedef struct _GeglFinishVisitor GeglFinishVisitor;
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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment