void graph_init(graph_t* g) { /* node_t *n; */ /* edge_t *e; */ /* initialize the graph */ init_ugraph(g); /* initialize nodes */ N_height = agfindattr(g->proto->n,"height"); N_width = agfindattr(g->proto->n,"width"); N_shape = agfindattr(g->proto->n,"shape"); N_color = agfindattr(g->proto->n,"color"); N_fillcolor = agfindattr(g->proto->n,"fillcolor"); N_style = agfindattr(g->proto->n,"style"); N_fontsize = agfindattr(g->proto->n,"fontsize"); N_fontname = agfindattr(g->proto->n,"fontname"); N_fontcolor = agfindattr(g->proto->n,"fontcolor"); N_label = agfindattr(g->proto->n,"label"); N_showboxes = agfindattr(g->proto->n,"showboxes"); /* attribs for polygon shapes */ N_sides = agfindattr(g->proto->n,"sides"); N_peripheries = agfindattr(g->proto->n,"peripheries"); N_skew = agfindattr(g->proto->n,"skew"); N_orientation = agfindattr(g->proto->n,"orientation"); N_distortion = agfindattr(g->proto->n,"distortion"); N_fixed = agfindattr(g->proto->n,"fixedsize"); N_layer = agfindattr(g->proto->n,"layer"); N_group = agfindattr(g->proto->n,"group"); N_comment = agfindattr(g->proto->n,"comment"); N_vertices = agfindattr(g->proto->n,"vertices"); N_z = agfindattr(g->proto->n,"z"); /* initialize edges */ E_weight = agfindattr(g->proto->e,"weight"); E_color = agfindattr(g->proto->e,"color"); E_fontsize = agfindattr(g->proto->e,"fontsize"); E_fontname = agfindattr(g->proto->e,"fontname"); E_fontcolor = agfindattr(g->proto->e,"fontcolor"); E_label = agfindattr(g->proto->e,"label"); /* vladimir */ E_dir = agfindattr(g->proto->e,"dir"); E_arrowhead = agfindattr(g->proto->e,"arrowhead"); E_arrowtail = agfindattr(g->proto->e,"arrowtail"); E_headlabel = agfindattr(g->proto->e,"headlabel"); E_taillabel = agfindattr(g->proto->e,"taillabel"); E_labelfontsize = agfindattr(g->proto->e,"labelfontsize"); E_labelfontname = agfindattr(g->proto->e,"labelfontname"); E_labelfontcolor = agfindattr(g->proto->e,"labelfontcolor"); E_labeldistance = agfindattr(g->proto->e,"labeldistance"); E_labelangle = agfindattr(g->proto->e,"labelangle"); /* end vladimir */ E_minlen = agfindattr(g->proto->e,"minlen"); E_showboxes = agfindattr(g->proto->e,"showboxes"); E_style = agfindattr(g->proto->e,"style"); E_decorate = agfindattr(g->proto->e,"decorate"); E_arrowsz = agfindattr(g->proto->e,"arrowsize"); E_constr = agfindattr(g->proto->e,"constraint"); E_layer = agfindattr(g->proto->e,"layer"); E_comment = agfindattr(g->proto->e,"comment"); E_tailclip = agfindattr(g->proto->e,"tailclip"); E_headclip = agfindattr(g->proto->e,"headclip"); }
void init_ugraph(graph_t* g) { char *p; int i; double xf; static char *rankname[] = {"local","global","none",NULL}; static int rankcode[] = {LOCAL, GLOBAL, NOCLUST, LOCAL}; g->u.drawing = NEW(layout_t); /* set this up fairly early in case any string sizes are needed */ if ((p = agget(g,"fontpath")) || (p = getenv("DOTFONTPATH"))) { /* overide GDFONTPATH in local environment if dot * wants its own */ #ifdef HAVE_SETENV setenv("GDFONTPATH", p, 1); #else static char *buf=0; buf=(char *)realloc(buf,strlen("GDFONTPATH=")+strlen(p)+1); strcpy(buf,"GDFONTPATH="); strcat(buf,p); putenv(buf); #endif } g->u.drawing->quantum = late_float(g,agfindattr(g,"quantum"),0.0,0.0); g->u.drawing->font_scale_adj = 1.0; g->u.left_to_right = ((p = agget(g,"rankdir")) && streq(p,"LR")); do_graph_label(g); xf = late_float(g,agfindattr(g,"nodesep"),DEFAULT_NODESEP,MIN_NODESEP); g->u.nodesep = POINTS(xf); p = late_string(g,agfindattr(g,"ranksep"),NULL); if (p) { if (sscanf(p,"%lf",&xf) == 0) xf = DEFAULT_RANKSEP; else {if (xf < MIN_RANKSEP) xf = MIN_RANKSEP;} if (strstr(p,"equally")) g->u.exact_ranksep = TRUE; } else xf = DEFAULT_RANKSEP; g->u.ranksep = POINTS(xf); g->u.showboxes = late_int(g,agfindattr(g,"showboxes"),0,0); Epsilon = .0001 * agnnodes(g); getfloats2pt(g,"size",&(g->u.drawing->size)); getfloats2pt(g,"page",&(g->u.drawing->page)); getfloat(g,"epsilon",&Epsilon); getfloat(g,"nodesep",&Nodesep); getfloat(g,"nodefactor",&Nodefactor); g->u.drawing->centered = mapbool(agget(g,"center")); if ((p = agget(g,"rotate"))) g->u.drawing->landscape = (atoi(p) == 90); else { /* today we learned the importance of backward compatibilty */ if ((p = agget(g,"orientation"))) g->u.drawing->landscape = ((p[0] == 'l') || (p[0] == 'L')); } p = agget(g,"clusterrank"); CL_type = maptoken(p,rankname,rankcode); p = agget(g,"concentrate"); Concentrate = mapbool(p); Nodesep = 1.0; Nodefactor = 1.0; Initial_dist = MYHUGE; }
Agsym_t *findattr(Agedge_t *e, char *name) { if (!e || !name) return NULL; return agfindattr(e, name); }
Agsym_t *findattr(Agnode_t *n, char *name) { if (!n || !name) return NULL; return agfindattr(n, name); }
Agsym_t *findattr(Agraph_t *g, char *name) { if (!g || !name) return NULL; return agfindattr(g, name); }
gboolean cls_node_expand (ClsNode *cls_node, ClsNodeExpansionType expansion_type) { Agsym_t *sym; GString *label; gint max_label_items = 0; gint real_items_length = 0; gint var_order = -1000; gint method_order = 0; IAnjutaSymbol *node_sym; IAnjutaIterable *iter; GError *err = NULL; if (cls_node->expansion_status == expansion_type || expansion_type == CLS_NODE_COLLAPSED) return FALSE; node_sym = IANJUTA_SYMBOL (ianjuta_symbol_query_search_id (cls_node->plugin->query_id, cls_node->klass_id, &err)); if (err) { g_warning ("Symbol ID query failed: %s", err->message); g_error_free (err); err = NULL; } if (!node_sym) return FALSE; if (!(sym = agfindattr(cls_node->graph->proto->n, "shape"))) sym = agnodeattr(cls_node->graph, "shape", ""); agxset (cls_node->agnode, sym->index, "record"); if (!(sym = agfindattr(cls_node->graph->proto->n, "label"))) sym = agnodeattr(cls_node->graph, "label", ""); label = g_string_new (""); g_string_printf (label, "{%s", cls_node->sym_name); /* get members from the passed symbol node */ iter = ianjuta_symbol_query_search_members (cls_node->plugin->query_members, node_sym, &err); if (err) { g_warning ("Class members query failed: %s", err->message); g_error_free (err); err = NULL; } real_items_length = ianjuta_iterable_get_length (iter, NULL); /* set the max number of items to draw */ if (real_items_length <= NODE_HALF_DISPLAY_ELEM_NUM || expansion_type == CLS_NODE_FULL_EXPANDED) { max_label_items = real_items_length; cls_node->expansion_status = CLS_NODE_FULL_EXPANDED; } else { max_label_items = NODE_HALF_DISPLAY_ELEM_NUM; cls_node->expansion_status = CLS_NODE_SEMI_EXPANDED; } g_hash_table_remove_all (cls_node->members); if (iter && real_items_length > 0) { gint i = 0; /* First member variables */ do { const gchar *name, *args, *type_name; IAnjutaSymbol *symbol; GdkPixbuf *icon; symbol = IANJUTA_SYMBOL (iter); name = g_strdup (ianjuta_symbol_get_string (symbol, IANJUTA_SYMBOL_FIELD_NAME, NULL)); args = ianjuta_symbol_get_string (symbol, IANJUTA_SYMBOL_FIELD_SIGNATURE, NULL); icon = (GdkPixbuf*) ianjuta_symbol_get_icon (symbol, NULL); if (!args) /* Member variables */ { ClsNodeItem *cls_item = g_new0 (ClsNodeItem, 1); type_name = ianjuta_symbol_get_string (symbol, IANJUTA_SYMBOL_FIELD_TYPE_NAME, NULL); cls_item->cls_node = cls_node; cls_item->label = g_strconcat (name, " : ", type_name, NULL); cls_item->order = var_order++; if (icon) g_object_ref (icon); cls_item->icon = icon; g_hash_table_insert (cls_node->members, g_strdup (cls_item->label), cls_item); g_string_append_printf (label, "|%s", cls_item->label); /* Setup file and line */ cls_item->type_name = g_strdup (type_name); cls_item->line = ianjuta_symbol_get_int (symbol, IANJUTA_SYMBOL_FIELD_FILE_POS, NULL); cls_item->file = ianjuta_symbol_get_file (symbol, NULL); } else /* Member methods */ { ClsNodeItem *cls_item; gchar *method_key = g_strconcat (name, args, NULL); cls_item = g_hash_table_lookup (cls_node->members, method_key); if (cls_item) /* We found an entry for this method */ { IAnjutaSymbolType sym_type = ianjuta_symbol_get_sym_type (symbol, NULL); if (!(sym_type & IANJUTA_SYMBOL_TYPE_PROTOTYPE)) { /* This one is method, so take this one instead */ g_free (cls_item->args); cls_item->args = g_strdup (args); if (cls_item->file) g_object_unref (cls_item->file); cls_item->file = NULL; /* Setup file and line */ cls_item->line = ianjuta_symbol_get_int (symbol, IANJUTA_SYMBOL_FIELD_FILE_POS, NULL); cls_item->file = ianjuta_symbol_get_file (symbol, NULL); } } else /* We did not find a member entry, create a new one */ { ClsNodeItem *cls_item = g_new0 (ClsNodeItem, 1); type_name = ianjuta_symbol_get_string (symbol, IANJUTA_SYMBOL_FIELD_RETURNTYPE, NULL); cls_item->cls_node = cls_node; if (type_name) { if (strlen (args) > 2) cls_item->label = g_strconcat (name, "(...)", " : ", type_name, NULL); else cls_item->label = g_strconcat (name, "()", " : ", type_name, NULL); } else { if (strlen (args) > 2) cls_item->label = g_strconcat (name, "(...)", NULL); else cls_item->label = g_strconcat (name, "()", NULL); } cls_item->args = g_strdup (args); cls_item->type_name = g_strdup (type_name); cls_item->order = method_order++; if (icon) g_object_ref (icon); cls_item->icon = icon; g_string_append_printf (label, "|%s", cls_item->label); g_hash_table_insert (cls_node->members, method_key, cls_item); /* Setup file and line */ cls_item->line = ianjuta_symbol_get_int (symbol, IANJUTA_SYMBOL_FIELD_FILE_POS, NULL); cls_item->file = ianjuta_symbol_get_file (symbol, NULL); } } i++; } while (ianjuta_iterable_next (iter, NULL) && i < max_label_items); } if (iter) g_object_unref (iter); if (cls_node->expansion_status == CLS_NODE_SEMI_EXPANDED && real_items_length > NODE_HALF_DISPLAY_ELEM_NUM) { g_string_append_printf (label, "|%s", NODE_SHOW_ALL_MEMBERS_STR); } g_string_append_printf (label, "}"); agxset(cls_node->agnode, sym->index, label->str); /* set the margin for icons */ if (!(sym = agfindattr(cls_node->graph->proto->n, "margin"))) sym = agnodeattr(cls_node->graph, "margin", "0.11,0.055"); agxset(cls_node->agnode, sym->index, "0.3,0.03"); g_string_free (label, TRUE); return TRUE; }
/*---------------------------------------------------------------------------- * add a node to an Agraph. Check also if the node is yet in the hash_table so * that we can build the label of the node with the class-data. */ static ClsNode* cls_inherit_create_node (AnjutaClassInheritance *plugin, const IAnjutaSymbol *node_sym) { ClsNode *cls_node; Agsym_t *sym; gint font_size; const gchar *font_name; #define FONT_SIZE_STR_LEN 16 gchar font_size_str[FONT_SIZE_STR_LEN]; cls_node = g_new0 (ClsNode, 1); cls_node->graph = plugin->graph; cls_node->canvas = plugin->canvas; cls_node->plugin = plugin; cls_node->sym_manager = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell, IAnjutaSymbolManager, NULL); cls_node->sym_name = g_strdup (ianjuta_symbol_get_string (IANJUTA_SYMBOL (node_sym), IANJUTA_SYMBOL_FIELD_NAME, NULL)); cls_node->klass_id = ianjuta_symbol_get_int (IANJUTA_SYMBOL (node_sym), IANJUTA_SYMBOL_FIELD_ID, NULL); cls_node->members = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) cls_node_item_free); cls_node->expansion_status = CLS_NODE_COLLAPSED; cls_node->drawn_expansion_status = CLS_NODE_COLLAPSED; cls_node->edges_to = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)cls_node_edge_free); cls_node->edges_from = g_hash_table_new (g_direct_hash, g_direct_equal); /* let's add the node to the graph */ if ((cls_node->agnode = agnode (cls_node->graph, cls_node->sym_name)) == NULL) { cls_node_free (cls_node); return NULL; } /* set the font */ if (!(sym = agfindattr(plugin->graph->proto->n, "fontname"))) sym = agnodeattr(plugin->graph, "fontname", ""); font_name = pango_font_description_get_family (plugin->canvas->style->font_desc); agxset(cls_node->agnode, sym->index, (char*)font_name); /* set the font-size */ if (!(sym = agfindattr(plugin->graph->proto->n, "fontsize"))) sym = agnodeattr(plugin->graph, "fontsize", ""); font_size = pango_font_description_get_size (plugin->canvas->style->font_desc)/ PANGO_SCALE; /* The above font size in points is with real screen DPI, but graphviz * rendering is done at fixed INCH_TO_PIXELS_CONVERSION_FACTOR dpi. So * convert to the right font size points for graphviz. */ font_size = font_size * gdk_screen_get_resolution (gdk_screen_get_default ()) / INCH_TO_PIXELS_CONVERSION_FACTOR; snprintf (font_size_str, FONT_SIZE_STR_LEN, "%d", font_size); agxset(cls_node->agnode, sym->index, font_size_str); if (!(sym = agfindattr(plugin->graph->proto->n, "ratio"))) sym = agnodeattr(plugin->graph, "ratio", ""); agxset(cls_node->agnode, sym->index, "expand"); /* Set an attribute - in this case one that affects the visible rendering */ if (!(sym = agfindattr(plugin->graph->proto->n, "shape"))) sym = agnodeattr(plugin->graph, "shape", ""); agxset(cls_node->agnode, sym->index, "box"); if (!(sym = agfindattr(plugin->graph->proto->n, "label"))) sym = agnodeattr(plugin->graph, "label", ""); agxset(cls_node->agnode, sym->index, cls_node->sym_name); return cls_node; }