static void gegl_dot_add_graph (GString *string, GeglNode *node, const gchar *label) { GeglNode *graph = node; g_string_append_printf (string, "subgraph cluster_%s%p { graph [ label=\"%s %p\" fontsize=\"10\" ranksep=\"0.3\" nodesep=\"0.3\"]; node [ fontsize=\"10\" ];\n", label, node, label, node); { GSList *nodes = gegl_node_get_children (graph); GSList *entry = nodes; while (entry) { GeglNode *node = entry->data; if (node->is_graph) { gchar *name = g_strdup (gegl_node_get_debug_name (node)); gchar *p = name; while (*p) { if (*p == ' ' || *p == '-') *p = '_'; p++; } gegl_dot_add_graph (string, node, name); g_free (name); } else { gegl_dot_util_add_node (string, node); } entry = g_slist_next (entry); } g_slist_free (nodes); } { GSList *nodes = gegl_node_get_children (graph); GSList *entry = nodes; while (entry) { GeglNode *node = entry->data; gegl_dot_util_add_node_sink_edges (string, node); entry = g_slist_next (entry); } g_slist_free (nodes); } g_string_append_printf (string, "}\n"); }
static void print_info(GeglNode* gegl) { GSList *list = gegl_node_get_children(gegl); for(;list != NULL; list = list->next) { GeglNode* node = GEGL_NODE(list->data); g_print("Node %s\n", gegl_node_get_operation(node)); if(gegl_node_get_pad(node, "output") == NULL) { g_print("Output pad is NULL\n"); } /* GeglNode** nodes; const gchar** pads; gint num = gegl_node_get_consumers(node, "output", &nodes, &pads); g_print("%s: %d consumer(s)\n", gegl_node_get_operation(node), num); int i; for(i = 0; i < num; i++) { g_print("Connection: (%s to %s)\n", gegl_node_get_operation(node), gegl_node_get_operation(nodes[0]), pads[0]); } g_print("\n");*/ } }
void layer_set_graph(GeglEditorLayer* self, GeglNode* gegl) { //properly dispose of old gegl graph self->gegl = gegl; gegl_editor_remove_all_nodes(self->editor); GSList *list = gegl_node_get_children(gegl); for(;list != NULL; list = list->next) { GeglNode* node = GEGL_NODE(list->data); g_print("Loading %s\n", gegl_node_get_operation(node)); layer_add_gegl_node(self, node); } list = gegl_node_get_children(gegl); for(list = g_slist_reverse(list); list != NULL; list = list->next) { GeglNode* node = GEGL_NODE(list->data); gint from = get_editor_node_id(self, node); GeglNode** nodes; const gchar** pads; if(!gegl_node_has_pad(node, "output")) { break;} gint num = gegl_node_get_consumers(node, "output", &nodes, &pads); int i; g_print("%s: %d consumer(s)\n", gegl_node_get_operation(node), num); for(i = 0; i < num; i++) { gint to = get_editor_node_id(self, nodes[i]); g_print("Connecting to consumer (%s to %s): output->%s\n", gegl_node_get_operation(node), gegl_node_get_operation(nodes[0]), pads[0]); gegl_editor_add_connection(self->editor, from, to, "output", pads[0]); } } }
/* Loading an empty graph should result a valid GeglNode with no children. * * Kind-of a sanity test, should run before other tests. */ static void test_load_empty_graph (void) { const gchar * const xml = "<?xml version='1.0' encoding='UTF-8'?>\n<gegl>\n</gegl>\n"; GeglNode *graph; GSList *children; graph = gegl_node_new_from_xml(xml, ""); g_assert(graph); children = gegl_node_get_children(graph); g_assert_cmpuint(g_slist_length(children), ==, 0); g_slist_free(children); g_object_unref(graph); }
/* Loading a graph with X child nodes should result in * a GeglNode with X children, where the bottom-most node * is child 0. * * Note: Properties are not tested. */ static void test_load_multiple_nodes (void) { const gchar * const xml = \ "<?xml version='1.0' encoding='UTF-8'?>\n\ <gegl>\n\ <node operation='gegl:invert-linear'>\n\ </node>\n\ <node operation='gegl:crop'>\n\ <params>\n\ <param name='x'>0</param>\n\ <param name='y'>0</param>\n\ <param name='width'>0</param>\n\ <param name='height'>0</param>\n\ </params>\n\ </node>\n\ </gegl>\n"; GeglNode *graph, *node; GSList *children; gchar *op_name; graph = gegl_node_new_from_xml(xml, ""); g_assert(graph); children = gegl_node_get_children(graph); g_assert_cmpuint(g_slist_length(children), ==, 2); node = GEGL_NODE(g_slist_nth_data(children, 0)); gegl_node_get(node, "operation", &op_name, NULL); g_assert_cmpstr(op_name, ==, "gegl:crop"); g_free(op_name); node = GEGL_NODE(g_slist_nth_data(children, 1)); gegl_node_get(node, "operation", &op_name, NULL); g_assert_cmpstr(op_name, ==, "gegl:invert-linear"); g_free(op_name); g_slist_free(children); g_object_unref(graph); }