static void attach (GeglOperation *operation) { GeglNode *gegl = operation->node; GeglNode *output, *color, *crop; output = gegl_node_get_output_proxy (gegl, "output"); color = gegl_node_new_child (gegl, "operation", "gegl:color", NULL); crop = gegl_node_new_child (gegl, "operation", "gegl:crop", NULL); gegl_operation_meta_watch_node (operation, color); gegl_operation_meta_watch_node (operation, crop); gegl_node_link_many (color, crop, output, NULL); gegl_operation_meta_redirect (operation, "color", color, "value"); gegl_operation_meta_redirect (operation, "x", crop, "x"); gegl_operation_meta_redirect (operation, "y", crop, "y"); gegl_operation_meta_redirect (operation, "width", crop, "width"); gegl_operation_meta_redirect (operation, "height", crop, "height"); }
void gegl_operation_meta_watch_nodes (GeglOperation *operation, GeglNode *node, ...) { va_list var_args; va_start (var_args, node); while (node) { gegl_operation_meta_watch_node (operation, node); node = va_arg (var_args, GeglNode *); } va_end (var_args); }
static void attach (GeglOperation *operation) { JsonOp *self = (JsonOp *)operation; GeglNode *gegl = operation->node; JsonArray *connections; GList *l; // Processes JsonObject *root = self->json_root; JsonObject *processes = json_object_get_object_member(root, "processes"); GList *process_names = json_object_get_members(processes); for (l = process_names; l != NULL; l = l->next) { const gchar *name = l->data; JsonObject *proc = json_object_get_object_member(processes, name); const gchar *component = json_object_get_string_member(proc, "component"); gchar *opname = component2geglop(component); GeglNode *node = gegl_node_new_child (gegl, "operation", opname, NULL); gegl_operation_meta_watch_node (operation, node); g_assert(node); g_hash_table_insert(self->nodes, (gpointer)g_strdup(name), (gpointer)node); g_free(opname); } g_list_free(process_names); // Connections connections = json_object_get_array_member(root, "connections"); g_assert(connections); for (int i=0; i<json_array_get_length(connections); i++) { JsonObject *conn = json_array_get_object_element(connections, i); JsonObject *tgt = json_object_get_object_member(conn, "tgt"); const gchar *tgt_proc = json_object_get_string_member(tgt, "process"); const gchar *tgt_port = json_object_get_string_member(tgt, "port"); GeglNode *tgt_node = g_hash_table_lookup(self->nodes, tgt_proc); JsonNode *srcnode; g_assert(tgt_node); srcnode = json_object_get_member(conn, "src"); if (srcnode) { // Connection JsonObject *src = json_object_get_object_member(conn, "src"); const gchar *src_proc = json_object_get_string_member(src, "process"); const gchar *src_port = json_object_get_string_member(src, "port"); GeglNode *src_node = g_hash_table_lookup(self->nodes, src_proc); g_assert(src_node); gegl_node_connect_to (src_node, src_port, tgt_node, tgt_port); } else { // IIP JsonNode *datanode = json_object_get_member(conn, "data"); GValue value = G_VALUE_INIT; GParamSpec *paramspec; g_assert(JSON_NODE_HOLDS_VALUE(datanode)); json_node_get_value(datanode, &value); paramspec = gegl_node_find_property(tgt_node, tgt_port); set_prop(tgt_node, tgt_port, paramspec, &value); g_value_unset(&value); } } // Exported ports if (json_object_has_member(root, "inports")) { JsonObject *inports = json_object_get_object_member(root, "inports"); GList *inport_names = json_object_get_members(inports); for (l = inport_names; l != NULL; l = l->next) { const gchar *name = l->data; JsonObject *conn = json_object_get_object_member(inports, name); const gchar *proc = json_object_get_string_member(conn, "process"); const gchar *port = json_object_get_string_member(conn, "port"); GeglNode *node = g_hash_table_lookup(self->nodes, proc); g_assert(node); if (g_strcmp0(name, "input") == 0) { GeglNode *input = gegl_node_get_input_proxy (gegl, "input"); gegl_node_connect_to (input, "output", node, "input"); } else { gegl_operation_meta_redirect (operation, name, node, port); } } g_list_free(inport_names); } if (json_object_has_member(root, "outports")) { JsonObject *outports = json_object_get_object_member(root, "outports"); GList *outport_names = json_object_get_members(outports); for (l = outport_names; l != NULL; l = l->next) { const gchar *name = l->data; JsonObject *conn = json_object_get_object_member(outports, name); const gchar *proc = json_object_get_string_member(conn, "process"); const gchar *port = json_object_get_string_member(conn, "port"); GeglNode *node = g_hash_table_lookup(self->nodes, proc); g_assert(node); if (g_strcmp0(name, "output") == 0) { GeglNode *proxy = gegl_node_get_output_proxy (gegl, "output"); gegl_node_connect_to (node, port, proxy, "input"); } else { g_warning("Unsupported output '%s' exported in .json file", name); } } g_list_free(outport_names); } }