From 40a1e058bffc2bb040087010ef8e829fcc9a2744 Mon Sep 17 00:00:00 2001 From: arif Date: Tue, 21 Apr 2009 18:42:21 +0000 Subject: [PATCH] a lot of smyrna changes, --- cmd/smyrna/draw.c | 24 +- cmd/smyrna/glexpose.c | 10 +- cmd/smyrna/gltemplate.c | 5 +- cmd/smyrna/gui/callbacks.c | 26 +- cmd/smyrna/gui/gui.c | 292 +---------------- cmd/smyrna/gui/menucallbacks.c | 48 ++- cmd/smyrna/gui/menucallbacks.h | 1 + cmd/smyrna/gui/topviewsettings.c | 72 +++- cmd/smyrna/main.c | 61 ++++ cmd/smyrna/selection.c | 543 +++++-------------------------- cmd/smyrna/selection.h | 31 +- cmd/smyrna/smyrnadefs.h | 296 +++++++++-------- cmd/smyrna/topfisheyeview.c | 4 +- cmd/smyrna/topview.c | 361 ++++++++++++-------- cmd/smyrna/tvnodes.c | 40 +-- cmd/smyrna/viewport.c | 439 +++++-------------------- cmd/smyrna/viewport.h | 2 +- 17 files changed, 762 insertions(+), 1493 deletions(-) diff --git a/cmd/smyrna/draw.c b/cmd/smyrna/draw.c index 7463b5b7d..647fa18e5 100755 --- a/cmd/smyrna/draw.c +++ b/cmd/smyrna/draw.c @@ -125,7 +125,7 @@ static void set_options(sdot_op * op, int param) static void relocate_spline(sdot_op * sop, int param) { - Agedge_t *e; +/* Agedge_t *e; Agnode_t *tn; //tail node Agnode_t *hn; //head node int i = 0; @@ -197,7 +197,7 @@ static void relocate_spline(sdot_op * sop, int param) } } } - } + }*/ } static void DrawBeziers(xdot_op * op, int param) @@ -210,7 +210,7 @@ static void DrawBeziers(xdot_op * op, int param) int temp = 0; int filled; int i = 0; - SelectBeziers((sdot_op *) op); +// SelectBeziers((sdot_op *) op); relocate_spline((sdot_op *) op, param); if (op->kind == xd_filled_bezier) filled = 1; @@ -301,7 +301,7 @@ static void DrawEllipse(xdot_op * op, int param) y = op->u.ellipse.y - dy; xradius = (GLfloat) op->u.ellipse.w; yradius = (GLfloat) op->u.ellipse.h; - SelectEllipse((sdot_op *) op); +// SelectEllipse((sdot_op *) op); if (op->kind == xd_filled_ellipse) { if (param == 0) glColor4f(view->fillColor.R, view->fillColor.G, @@ -343,7 +343,7 @@ static void DrawPolygon(xdot_op * op, int param) { int i = 0; int filled; - SelectPolygon((sdot_op *) op); + //SelectPolygon((sdot_op *) op); set_options((sdot_op *) op, param); if (op->kind == xd_filled_polygon) { @@ -390,7 +390,7 @@ static void DrawPolyline(xdot_op * op, int param) if (param == 1) //selected glColor4f(view->selectedNodeColor.R, view->selectedNodeColor.G, view->selectedNodeColor.B, view->selectedNodeColor.A); - SelectPolyline((sdot_op *) op); + //SelectPolyline((sdot_op *) op); set_options((sdot_op *) op, param); glLineWidth(view->LineWidth); glBegin(GL_LINE_STRIP); @@ -460,13 +460,13 @@ static void SetFont(xdot_op * op, int param) static void InsertImage(xdot_op * op, int param) { - SelectImage((sdot_op *) op); + // SelectImage((sdot_op *) op); } static void EmbedText(xdot_op * op, int param) { GLfloat x; - SelectText((sdot_op *) op); +// SelectText((sdot_op *) op); set_options((sdot_op *) op, param); if (op->u.text.align == 1) x = (GLfloat) op->u.text.x - (GLfloat) (op->u.text.width / 2.0); @@ -635,7 +635,7 @@ void drawBorders(ViewInfo * view) } } -static void drawXdot(xdot * xDot, int param, void *p) +/*static void drawXdot(xdot * xDot, int param, void *p) { int id; sdot_op *ops = (sdot_op *) (xDot->ops); @@ -656,7 +656,7 @@ static void drawXdot(xdot * xDot, int param, void *p) if (OD_Preselected(p) == 1) select_object(view->g[view->activeGraph], p); OD_Preselected(p) = 0; -} +}*/ @@ -682,7 +682,7 @@ static void drawXdotwithattrs(void *e, int param) -void drawGraph(Agraph_t * g) +/*void drawGraph(Agraph_t * g) { Agnode_t *v; Agedge_t *e; @@ -726,7 +726,7 @@ void drawGraph(Agraph_t * g) view->SignalBlock = 0; } -} +}*/ /* diff --git a/cmd/smyrna/glexpose.c b/cmd/smyrna/glexpose.c index 90d294c0c..4220dc078 100644 --- a/cmd/smyrna/glexpose.c +++ b/cmd/smyrna/glexpose.c @@ -179,8 +179,8 @@ int glexpose_drawgraph(ViewInfo * view) if (view->activeGraph > -1) { - if (GD_TopView(view->g[view->activeGraph])) - { +// if (GD_TopView(view->g[view->activeGraph])) +// { if(!view->Topview->is_top_fisheye) drawTopViewGraph(view->g[view->activeGraph]); //view->Topview style dots and straight lines else @@ -192,9 +192,9 @@ int glexpose_drawgraph(ViewInfo * view) // glCompDrawEnd(); // OtkDrawAll_scene( 0); - } - else - drawGraph(view->g[view->activeGraph]); //xdot based drawing functions +// } +// else +// drawGraph(view->g[view->activeGraph]); //xdot based drawing functions glCompSetDraw(view->widgets); return 1; } diff --git a/cmd/smyrna/gltemplate.c b/cmd/smyrna/gltemplate.c index 521038bc0..a149ca6bb 100755 --- a/cmd/smyrna/gltemplate.c +++ b/cmd/smyrna/gltemplate.c @@ -341,9 +341,6 @@ static gboolean button_release_event(GtkWidget * widget, } if (view->mouse.mouse_mode == MM_MOVE) { - if (GD_TopView(view->g[view->activeGraph]) == 0) - move_nodes(view->g[view->activeGraph]); - else move_TVnodes(); } @@ -362,7 +359,7 @@ static gboolean button_release_event(GtkWidget * widget, if (event->button == 3) //right click { - if ((view->activeGraph >= 0) && (GD_TopView(view->g[view->activeGraph]))) + if (view->activeGraph >= 0) { if(view->Topview->is_top_fisheye) { diff --git a/cmd/smyrna/gui/callbacks.c b/cmd/smyrna/gui/callbacks.c index 69b4f8ad9..d136534c6 100755 --- a/cmd/smyrna/gui/callbacks.c +++ b/cmd/smyrna/gui/callbacks.c @@ -76,7 +76,7 @@ void remove_graph_clicked(GtkWidget * widget, gpointer user_data) static void btn_clicked(GtkWidget * widget, gvk_layout layout) { - GdkCursor *cursor; +/* GdkCursor *cursor; GdkWindow *w; Dlg = (GtkMessageDialog *) gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, @@ -102,7 +102,7 @@ static void btn_clicked(GtkWidget * widget, gvk_layout layout) gtk_button_set_image(GTK_BUTTON (glade_xml_get_widget(xml, "btn_neato")), gtk_image_new_from_file("c:\fonts.png")); - } + }*/ } void btn_dot_clicked(GtkWidget * widget, gpointer user_data) { @@ -156,21 +156,6 @@ void dlgOpenGraph_OK_Clicked(GtkWidget * button, gpointer data) } -void graph_select_change(GtkWidget * widget, gpointer user_data) -{ - gint active_graph; - - - if (!view->SignalBlock) { - active_graph = gtk_combo_box_get_active((GtkComboBox*) widget); - - if (active_graph > -1) { - view->activeGraph = active_graph; - refreshControls(view); - } - } -} - //dlgOpenGraph btnOK clicked void on_dlgOpenGraph_btnOK_clicked(GtkWidget * widget, gpointer user_data) { @@ -223,14 +208,9 @@ void frmObject_set_scroll(GtkWidget * widget, gpointer user_data) void frmObjectBtnOK_clicked(GtkWidget * widget, gpointer user_data) { //call function to update object values - update_object_properties(frmObjectTypeIndex, frmObjectg); - if (GD_TopView(view->g[view->activeGraph]) == 0) - do_graph_layout(view->g[view->activeGraph], 0, 1); - else { +// update_object_properties(frmObjectTypeIndex, frmObjectg); set_update_required(view->Topview); deselect_all(view->g[view->activeGraph]); - } - gtk_widget_hide(glade_xml_get_widget(xml, "frmObject")); } diff --git a/cmd/smyrna/gui/gui.c b/cmd/smyrna/gui/gui.c index ac9aada6f..1b3a74dea 100755 --- a/cmd/smyrna/gui/gui.c +++ b/cmd/smyrna/gui/gui.c @@ -149,8 +149,6 @@ GtkComboBox *get_SelectGraph(void) gtk_layout_put((GtkLayout *) gladewidget, (GtkWidget *) cb, 780, 3); //signal - g_signal_connect((gpointer) cb, "changed", - G_CALLBACK(graph_select_change), NULL); return cb; @@ -181,24 +179,9 @@ void Color_Widget_fg(int r, int g, int b, GtkWidget * widget) void load_graph_properties(Agraph_t * graph) { //dlgOpenGraph , GtkDialog - gtk_entry_set_text((GtkEntry *) - glade_xml_get_widget(xml, "entryGraphName"), - GD_GraphName(graph)); gtk_entry_set_text((GtkEntry *) glade_xml_get_widget(xml, "entryGraphFileName"), - GD_GraphFileName(graph)); - gtk_combo_box_set_active((GtkComboBox *) - glade_xml_get_widget(xml, "cbLayout"), - GD_Engine(graph)); - gtk_toggle_button_set_active((GtkToggleButton *) - glade_xml_get_widget(xml, "chkVisible"), - GD_AlwaysShow(graph)); - gtk_toggle_button_set_active((GtkToggleButton *) - glade_xml_get_widget(xml, "chkLocked"), - GD_Locked(graph)); - gtk_toggle_button_set_active((GtkToggleButton *) - glade_xml_get_widget(xml, "chkTopView"), - GD_TopView(graph)); + view->Topview->Graphdata.GraphFileName); } int update_graph_properties(Agraph_t * graph) //updates graph from gui @@ -206,34 +189,12 @@ int update_graph_properties(Agraph_t * graph) //updates graph from gui FILE *file; int respond = 0; int id = 0; - //check the graph name should not be duplicated graph names - for (id = 0; id < view->graphCount; id++) { - if (graph != view->g[id]) { - if (strcasecmp - (gtk_entry_get_text ((GtkEntry *) - glade_xml_get_widget(xml, "entryGraphName")), - GD_GraphName(view->g[id])) == - 0) { - - Dlg = (GtkMessageDialog *) gtk_message_dialog_new(NULL, - GTK_DIALOG_MODAL, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_OK, - "There is another graph with this name!"); - respond = gtk_dialog_run((GtkDialog *) Dlg); - gtk_object_destroy((GtkObject *) Dlg); - return 0; - - } - - } - } //check if file is changed if (strcasecmp (gtk_entry_get_text ((GtkEntry *) glade_xml_get_widget(xml, "entryGraphFileName")), - GD_GraphFileName(graph)) != 0) { + view->Topview->Graphdata.GraphFileName) != 0) { if ((file = @@ -279,248 +240,15 @@ int update_graph_properties(Agraph_t * graph) //updates graph from gui //if it comes so far graph deserves new values - GD_GraphName(graph) = - (char *) gtk_entry_get_text((GtkEntry *) - glade_xml_get_widget(xml, - "entryGraphName")); - GD_GraphFileName(graph) = + view->Topview->Graphdata.GraphFileName = (char *) gtk_entry_get_text((GtkEntry *) glade_xml_get_widget(xml, "entryGraphFileName")); - - GD_AlwaysShow(graph) = - gtk_toggle_button_get_active((GtkToggleButton *) - glade_xml_get_widget(xml, - "chkVisible")); - GD_Locked(graph) = - gtk_toggle_button_get_active((GtkToggleButton *) - glade_xml_get_widget(xml, - "chkLocked")); - GD_TopView(graph) = - gtk_toggle_button_get_active((GtkToggleButton *) - glade_xml_get_widget(xml, - "chkTopView")); - - - //check if the engine has been changed, if so do new layout -/* if (GD_Engine(graph) != gtk_combo_box_get_active((GtkComboBox *) - glade_xml_get_widget(xml, "cbLayout"))) { - Dlg = - (GtkMessageDialog *) gtk_message_dialog_new(NULL, - GTK_DIALOG_MODAL, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, - "You have changed the layout of the graph,this will change the graph layout\n all your position changes will be lost\n Are you sure?"); - respond = gtk_dialog_run((GtkDialog *) Dlg); - if (respond == GTK_RESPONSE_YES) - do_graph_layout(graph, - gtk_combo_box_get_active((GtkComboBox *) - glade_xml_get_widget - (xml, "cbLayout")), - 0); - gtk_object_destroy((GtkObject *) Dlg); - }*/ return 1; } -int load_object_properties(gve_element typeIndex, Agraph_t * g) //load from object to gui; -{ - //load attr from first selected object - GtkLayout *layout; - GdkColor color; - char buf[BUFSIZ]; - /* int ind=0; */ - int Y = 45; - int X = 90; - int Yinc = 25; - /* int Xinc=30; */ - /* int OriginalX= 90; */ - int OriginalY = 45; - int widget_per_page = 21; - void *obj; - char line[BUFSIZ]; - float a, b; - layout = (GtkLayout *) glade_xml_get_widget(xml, "layout4"); - frmObjectTypeIndex = typeIndex; - frmObjectg = g; - widgetcounter = 0; - //values should be set from first selected object - //according to object type (typeIndex) set the reference object - switch (typeIndex) //typeindex 0 means new object - { - case GVE_CLUSTER: //graph sub graph (cluster) - obj = GD_selectedGraphs(g)[0]; - break; - case GVE_NODE: //Node - obj = GD_selectedNodes(g)[0]; - break; - case GVE_EDGE: //Edge - obj = GD_selectedEdges(g)[0]; - break; - default : - break; - } - for (widgetcounter = 0; widgetcounter < MAXIMUM_WIDGET_COUNT; - widgetcounter++) - { - //create the labels and widget here - attr[widgetcounter].ComboValuesCount = 0; - attr[widgetcounter].ComboValues = '\0'; - - if (!AttrWidgets[widgetcounter]) - { - AttrLabels[widgetcounter] = - gtk_label_new(attr[widgetcounter].Name); - switch (attr[widgetcounter].Type) - { - case 'F': //float - AttrWidgets[widgetcounter] = - gtk_spin_button_new_with_range(0, 100, 0.001); - g_signal_connect((gpointer) AttrWidgets[widgetcounter],"value-changed", G_CALLBACK(attr_widgets_modifiedSlot),(gpointer) widgetcounter); - - break; - case 'C': //color box - AttrWidgets[widgetcounter] = gtk_color_button_new(); - gtk_widget_set_size_request(AttrWidgets[widgetcounter], 50, 23); - g_signal_connect((gpointer) AttrWidgets[widgetcounter],"color-set",G_CALLBACK(attr_widgets_modifiedSlot),(gpointer) widgetcounter); - - break; - default: //alphanumreric GTK Entry - AttrWidgets[widgetcounter] = gtk_entry_new(); - gtk_widget_set_size_request(AttrWidgets[widgetcounter],130, 23); - g_signal_connect((gpointer) AttrWidgets[widgetcounter], "changed", G_CALLBACK(attr_widgets_modifiedSlot),(gpointer) widgetcounter); - break; - } - attr[widgetcounter].attrWidget = AttrWidgets[widgetcounter]; - } - //locate widget on the GtkLayout* layout - if (attr[widgetcounter].ApplyTo[typeIndex] == 1) - { - gtk_layout_put(layout, AttrWidgets[widgetcounter], X, Y); - gtk_layout_put(layout, AttrLabels[widgetcounter], X - 80, Y); - gtk_widget_show(AttrWidgets[widgetcounter]); - gtk_widget_show(AttrLabels[widgetcounter]); - Y = Y + Yinc; - switch (attr[widgetcounter].Type) - { - case 'F': - if (agget(obj, attr[widgetcounter].Name)) - gtk_spin_button_set_value((GtkSpinButton *) AttrWidgets[widgetcounter],atof(agget(obj,attr[widgetcounter].Name))); - else - gtk_spin_button_set_value((GtkSpinButton *)AttrWidgets[widgetcounter],atof(attr[widgetcounter].Default)); - break; - case 'C': - if (agget(obj, attr[widgetcounter].Name)) - setGdkColor(&color, agget(obj, attr[widgetcounter].Name)); - else - setGdkColor(&color, attr[widgetcounter].Default); - - gtk_color_button_set_color((GtkColorButton *)AttrWidgets[widgetcounter],&color); - break; - default: - if (agget(obj, attr[widgetcounter].Name)) - gtk_entry_set_text((GtkEntry *)AttrWidgets[widgetcounter],agget(obj,attr[widgetcounter].Name)); - else - gtk_entry_set_text((GtkEntry *)AttrWidgets[widgetcounter],attr[widgetcounter].Default); - } - gtk_widget_show(AttrWidgets[widgetcounter]); - gtk_widget_show(AttrLabels[widgetcounter]); - } - else - { - gtk_widget_hide(AttrWidgets[widgetcounter]); - gtk_widget_hide(AttrLabels[widgetcounter]); - } - if (Y > widget_per_page * Yinc) - { - X = 320; - Y = OriginalY; - } - attr_widgets_modified[widgetcounter] = 0; //set to unmodified - } - - - //first part, common attributes - sprintf(buf, "%i", OD_ID(obj)); - gtk_entry_set_text((GtkEntry *)glade_xml_get_widget(xml, "objEntryName"),OD_ObjName(obj)); - gtk_entry_set_text((GtkEntry *)glade_xml_get_widget(xml, "objEntryLabel"),agnameof(obj)); - gtk_toggle_button_set_active((GtkToggleButton *)glade_xml_get_widget(xml,"frmObjectchkVisible"),OD_Visible(obj)); - gtk_toggle_button_set_active((GtkToggleButton *)glade_xml_get_widget(xml,"frmObjectchkLocked"),OD_Locked(obj)); - gtk_toggle_button_set_active((GtkToggleButton *)glade_xml_get_widget(xml,"frmObjectchkHighlighted"),OD_Highlighted(obj)); - //get the position info // show only one item is selected - if (((GD_selectedNodesCount(g) == 1) && (typeIndex == GVE_NODE)) - || ((GD_selectedEdgesCount(g) == 1) && (typeIndex == GVE_EDGE)) - || ((GD_selectedGraphsCount(g) == 1) && (typeIndex == GVE_EDGE))) - { - sprintf(line, "%s", agget(obj, "pos")); - a = (float) atof(strtok(line, ",")); - b = (float) atof(strtok(NULL, ",")); - gtk_spin_button_set_value((GtkSpinButton *)glade_xml_get_widget(xml,"frmObjectPosX"),a); - gtk_spin_button_set_value((GtkSpinButton *)glade_xml_get_widget(xml,"frmObjectPosY"),b); - gtk_spin_button_set_value((GtkSpinButton *)glade_xml_get_widget(xml,"frmObjectPosZ"),0); - gtk_widget_show(glade_xml_get_widget(xml, "frmObjectPosX")); - gtk_widget_show(glade_xml_get_widget(xml, "frmObjectPosY")); - gtk_widget_show(glade_xml_get_widget(xml, "frmObjectPosZ")); - gtk_widget_show(glade_xml_get_widget(xml, "frmObjectlabel3")); - gtk_label_set_text((GtkLabel *)glade_xml_get_widget(xml, "frmObjectPosLabelX"),"X:"); - } - else - { - gtk_widget_hide(glade_xml_get_widget(xml, "frmObjectPosX")); - gtk_widget_hide(glade_xml_get_widget(xml, "frmObjectPosY")); - gtk_widget_hide(glade_xml_get_widget(xml, "frmObjectPosZ")); - gtk_widget_hide(glade_xml_get_widget(xml, "frmObjectlabel3")); - gtk_widget_hide(glade_xml_get_widget(xml, "frmObjectPosLabelY")); - gtk_widget_hide(glade_xml_get_widget(xml, "frmObjectPosLabelZ")); - switch (typeIndex) //typeindex 0 means new object - { - case GVE_CLUSTER: //graph sub graph (cluster) - gtk_label_set_text((GtkLabel *)glade_xml_get_widget(xml,"frmObjectPosLabelX"),"Changes that you make will be applied to all selected clusters"); - break; - case GVE_NODE: //Node - gtk_label_set_text((GtkLabel *)glade_xml_get_widget(xml,"frmObjectPosLabelX"),"Changes that you make will be applied to all selected nodes!"); - break; - case GVE_EDGE: //Edge - gtk_label_set_text((GtkLabel *)glade_xml_get_widget(xml,"frmObjectPosLabelX"),"Changes that you make will be applied to all selected edges!"); - break; - default : - break; - } - } - return 1; -} -void update_object_properties(int typeIndex, Agraph_t * g) //updates objects from gui(node ,edge, cluster) -{ - int ind = 0; - for (ind = 0; ind < widgetcounter; ind++) - { - //if widget has been changed - if (attr_widgets_modified[ind] == 1) - { - switch (typeIndex) //typeindex 0 means new object - { - case GVE_CLUSTER: //graph sub graph (cluster) - change_selected_graph_attributes(g, attr[ind].Name, - get_attribute_string_value_from_widget - (&attr[ind])); - break; - case GVE_NODE: //Node - change_selected_node_attributes(g, attr[ind].Name, - get_attribute_string_value_from_widget - (&attr[ind])); - break; - case GVE_EDGE: //Edge - change_selected_edge_attributes(g, attr[ind].Name, - get_attribute_string_value_from_widget - (&attr[ind])); - break; - } - } - - } -} char *get_attribute_string_value_from_widget(attribute * att) { GdkColor color; @@ -545,11 +273,7 @@ void change_selected_graph_attributes(Agraph_t * g, char *attrname, { int ind = 0; agattr(g, AGRAPH, attrname, ""); - - for (ind = 0; ind < GD_selectedGraphsCount(g); ind++) - { - agset(GD_selectedGraphs(g)[ind], attrname, attrvalue); - } + agset(view->g[view->activeGraph],attrname,attrvalue); } @@ -559,9 +283,9 @@ void change_selected_node_attributes(Agraph_t * g, char *attrname, int ind = 0; agattr(g, AGNODE, attrname, ""); - for (ind = 0; ind < GD_selectedNodesCount(g); ind++) + for (ind = 0; ind < view->Topview->Graphdata.selectedNodesCount; ind++) { - agset(GD_selectedNodes(g)[ind], attrname, attrvalue); + agset(view->Topview->Graphdata.selectedNodes[ind], attrname, attrvalue); } } void change_selected_edge_attributes(Agraph_t * g, char *attrname, @@ -570,9 +294,9 @@ void change_selected_edge_attributes(Agraph_t * g, char *attrname, int ind = 0; agattr(g, AGEDGE, attrname, ""); - for (ind = 0; ind < GD_selectedEdgesCount(g); ind++) + for (ind = 0; ind < view->Topview->Graphdata.selectedEdgesCount; ind++) { - agset(GD_selectedEdges(g)[ind], attrname, attrvalue); + agset(view->Topview->Graphdata.selectedEdges[ind], attrname, attrvalue); } } diff --git a/cmd/smyrna/gui/menucallbacks.c b/cmd/smyrna/gui/menucallbacks.c index 1e498a8b3..c4ca24c74 100755 --- a/cmd/smyrna/gui/menucallbacks.c +++ b/cmd/smyrna/gui/menucallbacks.c @@ -48,7 +48,8 @@ void mOpenSlot(GtkWidget * widget, gpointer user_data) if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { char *filename; filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - + if (view->activeGraph == 0) + close_graph(view,0); add_graph_to_viewport_from_file(filename); g_free(filename); } @@ -68,6 +69,12 @@ void mSaveAsSlot(GtkWidget * widget, gpointer user_data) { save_as_graph(); //save with prompt } +void mCloseSlot(GtkWidget * widget, gpointer user_data) +{ + printf("mCloseSlot clicked\n"); + if (view->activeGraph == 0) + close_graph(view,0); +} void mOptionsSlot(GtkWidget * widget, gpointer user_data) { @@ -83,10 +90,11 @@ void mQuitSlot(GtkWidget * widget, gpointer user_data) #endif for (gIndex = 0; gIndex < view->graphCount; gIndex++) { view->activeGraph = gIndex; - if (GD_Modified(view->g[view->activeGraph])) { + if (view->Topview->Graphdata.Modified) + { sprintf(buf, "graph %s has been modified \n , would you like to save it before quitting the the program?", - GD_GraphName(view->g[view->activeGraph])); + view->Topview->Graphdata.GraphFileName); Dlg = (GtkMessageDialog *) gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, @@ -212,7 +220,7 @@ void mGraphPropertiesSlot(GtkWidget * widget, gpointer user_data) void mNodeFindSlot(GtkWidget * widget, gpointer user_data) { - if((view->activeGraph !=-1) && (GD_TopView(view->g[view->activeGraph]))) + if(view->activeGraph !=-1) { gtk_dialog_set_response_sensitive((GtkDialog *) glade_xml_get_widget(xml, @@ -238,36 +246,24 @@ void mNodeFindSlot(GtkWidget * widget, gpointer user_data) } -static void mPropertiesSlot(int count, gve_element element) +static void mPropertiesSlot(gve_element element) { - if (count > 0) { + if (view->activeGraph >=0 ) gtk_widget_hide(glade_xml_get_widget(xml, "frmObject")); gtk_widget_show(glade_xml_get_widget(xml, "frmObject")); - load_object_properties(element, view->g[view->activeGraph]); - } else { - char buf[BUFSIZ]; - sprintf (buf, "You need to select some %ss first!",element2s(element)); - Dlg = (GtkMessageDialog *) gtk_message_dialog_new(NULL, - GTK_DIALOG_MODAL, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_OK, - buf); - respond = gtk_dialog_run((GtkDialog *) Dlg); - gtk_widget_hide((GtkWidget *) Dlg); - - } +// load_object_properties(element, view->g[view->activeGraph]); } void mClusterPropertiesSlot(GtkWidget * widget, gpointer user_data) { - mPropertiesSlot (GD_selectedGraphsCount(view->g[view->activeGraph]),GVE_CLUSTER); + mPropertiesSlot (GVE_CLUSTER); } void mNodePropertiesSlot(GtkWidget * widget, gpointer user_data) { - mPropertiesSlot (GD_selectedNodesCount(view->g[view->activeGraph]), GVE_NODE); + mPropertiesSlot (GVE_NODE); } void mEdgePropertiesSlot(GtkWidget * widget, gpointer user_data) { - mPropertiesSlot (GD_selectedEdgesCount(view->g[view->activeGraph]), GVE_EDGE); + mPropertiesSlot (GVE_EDGE); } void mShowCodeSlot(GtkWidget * widget, gpointer user_data) @@ -277,7 +273,7 @@ static void mSlot (GtkWidget * widget, gpointer user_data, gvk_layout layout, in { /* GdkCursor *cursor; */ /* GdkWindow *w; */ - Dlg = (GtkMessageDialog *) gtk_message_dialog_new(NULL, +/* Dlg = (GtkMessageDialog *) gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, @@ -286,7 +282,7 @@ static void mSlot (GtkWidget * widget, gpointer user_data, gvk_layout layout, in respond = gtk_dialog_run((GtkDialog *) Dlg); if (respond == GTK_RESPONSE_YES) do_graph_layout(view->g[view->activeGraph], layout, 0); - gtk_object_destroy((GtkObject *) Dlg); + gtk_object_destroy((GtkObject *) Dlg);*/ return; @@ -348,7 +344,7 @@ void mSelectAllEdgesSlot(GtkWidget * widget, gpointer user_data) void mSelectAllClustersSlot(GtkWidget * widget, gpointer user_data) { - select_all_graphs(view->g[view->activeGraph]); + //select_all_graphs(view->g[view->activeGraph]); } @@ -365,7 +361,7 @@ void mUnselectAllEdgesSlot(GtkWidget * widget, gpointer user_data) void mUnselectAllClustersSlot(GtkWidget * widget, gpointer user_data) { - deselect_all_graphs(view->g[view->activeGraph]); +// deselect_all_graphs(view->g[view->activeGraph]); } void mSingleSelectSlot(GtkWidget * widget, gpointer user_data) diff --git a/cmd/smyrna/gui/menucallbacks.h b/cmd/smyrna/gui/menucallbacks.h index 78e532fdd..dbe5c544f 100755 --- a/cmd/smyrna/gui/menucallbacks.h +++ b/cmd/smyrna/gui/menucallbacks.h @@ -25,6 +25,7 @@ _BB void mNewSlot(GtkWidget * widget, gpointer user_data); _BB void mOpenSlot(GtkWidget * widget, gpointer user_data); _BB void mSaveSlot(GtkWidget * widget, gpointer user_data); _BB void mSaveAsSlot(GtkWidget * widget, gpointer user_data); +_BB void mCloseSlot(GtkWidget * widget, gpointer user_data); _BB void mOptionsSlot(GtkWidget * widget, gpointer user_data); _BB void mQuitSlot(GtkWidget * widget, gpointer user_data); diff --git a/cmd/smyrna/gui/topviewsettings.c b/cmd/smyrna/gui/topviewsettings.c index 915f525bf..e2e8b0f5e 100644 --- a/cmd/smyrna/gui/topviewsettings.c +++ b/cmd/smyrna/gui/topviewsettings.c @@ -73,7 +73,28 @@ static int get_color_button_widget_to_attribute(char *attribute, free(buf); return 1; } - +static int get_text_widget_to_attribute(char *attribute,char *widget_name,Agraph_t * g) +{ + char buf[512]; + if (strlen(attribute)> 512) + return 0; + sprintf (buf, "%s",gtk_entry_get_text ((GtkToggleButton *)glade_xml_get_widget(xml, widget_name))); + agattr(g, AGRAPH, attribute, buf); + return 1; +} +static int set_text_widget(char *attribute, char *widget_name) +{ + char* buf; + buf = agget(view->g[view->activeGraph], attribute); + if ((!buf) || (strcmp(buf, "") == 0)) + buf = agget(view->default_attributes, attribute); + if (buf) { + gtk_entry_set_text((GtkEntry*)glade_xml_get_widget(xml,widget_name),buf); + + return 1; + } + return 0; +} static int set_checkbox_widget(char *attribute, char *widget_name) { char *buf; @@ -170,18 +191,19 @@ static int set_scalebtn_widget_to_attribute(char *attribute, char *widget_name) } return 0; } -#if 0 + static int set_combobox_widget(char *attribute,char *widget_name) { char *buf; - float value; + int value; buf = agget(view->g[view->activeGraph], attribute); if ((!buf) || (strcmp(buf, "") == 0)) buf = agget(view->default_attributes, attribute); if (buf) { - gtk_combo_box_set_active( + value=(int) atof(buf); + gtk_combo_box_set_active( (GtkComboBox *) glade_xml_get_widget(xml,widget_name), (int)value); @@ -190,7 +212,7 @@ static int set_combobox_widget(char *attribute,char *widget_name) return 0; } -#endif + static int get_combobox_widget_to_attribute(char *attribute, char *widget_name, Agraph_t * g) { char buf[25]; @@ -241,6 +263,7 @@ int load_settings_from_graph(Agraph_t * g) "settingsColorBtn10"); set_color_button_widget("topologicalfisheyecoarsestcolor", "settingsColorBtn11"); + set_text_widget("topologicalfisheyelabelattribute","finenodelabelattribute",g); set_checkbox_widget("bordervisible", "settingsChkBox2"); @@ -252,6 +275,21 @@ int load_settings_from_graph(Agraph_t * g) set_checkbox_widget("drawedges", "settingsChkBox5-2"); set_checkbox_widget("drawlabels", "settingsChkBox5-3"); + + /*page 2 label settings*/ + set_combobox_widget("labelglutfont","labelfont"); + + set_color_button_widget("nodelabelcolor","nodelabelcolor"); + set_color_button_widget("edgelabelcolor","edgelabelcolor"); + set_text_widget("nodelabelattribute","labelnodeattribute"); + set_text_widget("edgelabelattribute","labeledgeattribute"); + set_checkbox_widget("labelwithdegree", "labelwithdegree"); + set_spinbtn_widget("labelnumberofnodes","labelzoomfactor"); + set_checkbox_widget("shownodelabels", "labelshownodes"); + set_checkbox_widget("showedgelabels", "labelshowedges"); + + + set_checkbox_widget("usermode", "settingsChkBox10"); set_checkbox_widget("nodesizewithdegree", "settingsChkBox11"); set_checkbox_widget("antialiasing", "settingsChkBox12"); @@ -374,6 +412,8 @@ int update_graph_from_settings(Agraph_t * g) "settingsColorBtn10", g); get_color_button_widget_to_attribute("topologicalfisheyecoarsestcolor", "settingsColorBtn11", g); + get_text_widget_to_attribute("topologicalfisheyelabelattribute","finenodelabelattribute",g); + get_checkbox_widget_to_attribute("bordervisible", "settingsChkBox2", g); @@ -390,8 +430,28 @@ int update_graph_from_settings(Agraph_t * g) get_checkbox_widget_to_attribute("drawlabels", "settingsChkBox5-3", g); + /*page 2 label settings*/ + get_combobox_widget_to_attribute("labelglutfont","labelfont", g); + + get_color_button_widget_to_attribute("nodelabelcolor","nodelabelcolor", g); + get_color_button_widget_to_attribute("edgelabelcolor","edgelabelcolor", g); + + get_text_widget_to_attribute("nodelabelattribute","labelnodeattribute",g); + get_text_widget_to_attribute("edgelabelattribute","labeledgeattribute",g); - + get_checkbox_widget_to_attribute("labelwithdegree", "labelwithdegree", g); + get_spinbtn_widget_to_attribute("labelnumberofnodes","labelzoomfactor", g); + get_checkbox_widget_to_attribute("shownodelabels", "labelshownodes", g); + get_checkbox_widget_to_attribute("showedgelabels", "labelshowedges", g); + + + + + + + + + get_checkbox_widget_to_attribute("usermode", "settingsChkBox10", g); diff --git a/cmd/smyrna/main.c b/cmd/smyrna/main.c index fb3a9ab60..223615582 100755 --- a/cmd/smyrna/main.c +++ b/cmd/smyrna/main.c @@ -51,6 +51,8 @@ static char* smyrnaDir; char* smyrnaGlade; unsigned char SmyrnaVerbose; + + char* smyrnaPath (char* suffix) { @@ -111,11 +113,70 @@ parseArgs (int argc, char *argv[], ViewInfo* view) } extern int create_font_file(char* fontdescription,float gw,float gh); extern int load_png_font(char* file_name); +static void close_cgraph(Agraph_t* g) +{ + Agnode_t *v; + for (v = agfstnode(g); v; v = agnxtnode(g, v)) + { + agdelrec(v, "temp_node_record"); + } + agclose(g); +} + + +static Agraph_t* test_cgraph(Agraph_t* g,char* filename) +{ + + Agnode_t *v; + Agedge_t *e; + FILE *input_file; + char buf[512]; + if (g) + close_cgraph(g); + + if (!(input_file = fopen(filename, "r"))) + { + g_print("Cannot open %s\n", filename); + return 0; + } + if (!(g = agread(input_file, NIL(Agdisc_t *)))) + { + g_print("Cannot read graph in %s\n", filename); + fclose (input_file); + return 0; + } + + for (v = agfstnode(g); v; v = agnxtnode(g, v)) + { + agbindrec(v, "temp_node_record", sizeof(temp_node_record), TRUE);//graph custom data + } + for (v = agfstnode(g); v; v = agnxtnode(g, v)) + { + for (e = agfstout(g, v); e; e = agnxtout(g, e)) + { + strcpy(buf, agget(aghead(e), "pos")); + } + } + + return g; +} + + + + + int main(int argc, char *argv[]) { GdkGLConfig *glconfig; char* initFileName; + Agraph_t* g=NULL; + Agraph_t* testg=NULL; + +// testg=test_cgraph(testg,"c:/4elt.gv"); +// agclose(testg); +// test_cgraph(testg,"c:/4elt.gv"); + smyrnaDir = getenv ("SMYRNA_PATH"); #ifndef _WIN32 diff --git a/cmd/smyrna/selection.c b/cmd/smyrna/selection.c index 0fbe84b25..496a0361b 100755 --- a/cmd/smyrna/selection.c +++ b/cmd/smyrna/selection.c @@ -369,248 +369,153 @@ static int point_within_polygon(xdot_op * op) //select functions -static int select_graph(Agraph_t * g, Agraph_t * G) -{ - int ind = 0; - //check if in the list - for (ind = 0; ind < GD_selectedGraphsCount(g); ind++) { - if (GD_selectedGraphs(g)[ind] == G) - return 0; - } - //for single selections i think realloc is ok, for mass selections i ll figure out something else - GD_selectedGraphs(g) = RALLOC(GD_selectedGraphsCount(g)+1, - GD_selectedGraphs(g), Agraph_t*); - GD_selectedGraphs(g)[GD_selectedGraphsCount(g)] = G; - GD_selectedGraphsCount(g)++; - OD_Selected(G) = 1; - return 1; -} -int select_node(Agraph_t * g, Agnode_t * N) +int select_node(topview_node* N) { int ind = 0; //check if in the list - for (ind = 0; ind < GD_selectedNodesCount(g); ind++) { - if (GD_selectedNodes(g)[ind] == N) + for (ind = 0; ind < view->Topview->Graphdata.selectedNodesCount; ind++) + { + if (view->Topview->Graphdata.selectedNodes[ind] == N) return 0; } //for single selections i think realloc is ok, for mass selections i ll figure out something else - GD_selectedNodes(g) = - RALLOC(GD_selectedNodesCount(g)+2,GD_selectedNodes(g), Agnode_t*); - GD_selectedNodes(g)[GD_selectedNodesCount(g)] = N; - GD_selectedNodesCount(g)++; - OD_Selected(N) = 1; + view->Topview->Graphdata.selectedNodes = + RALLOC(view->Topview->Graphdata.selectedNodesCount+2,view->Topview->Graphdata.selectedNodes, topview_node*); + view->Topview->Graphdata.selectedNodes[view->Topview->Graphdata.selectedNodesCount] = N; + view->Topview->Graphdata.selectedNodesCount++; + + N->data.Selected=1; return 1; } -int select_edge(Agraph_t * g, Agedge_t * E) +int select_edge(topview_edge* E) { int ind = 0; //check if in the list - for (ind = 0; ind < GD_selectedEdgesCount(g); ind++) { - if (GD_selectedEdges(g)[ind] == E) - return 0; + for (ind = 0; ind < view->Topview->Graphdata.selectedEdgesCount;ind++) + { + if (view->Topview->Graphdata.selectedEdges[ind] == E) + return 0; } //for single selections i think realloc is ok, for mass selections i ll figure out something else - GD_selectedEdges(g) = - RALLOC(GD_selectedEdgesCount(g)+1,GD_selectedEdges(g), Agedge_t*); - GD_selectedEdges(g)[GD_selectedEdgesCount(g)] = E; - GD_selectedEdgesCount(g)++; - OD_Selected(E) = 1; +view->Topview->Graphdata.selectedEdges = + RALLOC(view->Topview->Graphdata.selectedEdgesCount+1,view->Topview->Graphdata.selectedEdges, topview_edge*); + view->Topview->Graphdata.selectedEdges[view->Topview->Graphdata.selectedEdgesCount] = E; + view->Topview->Graphdata.selectedEdgesCount ++; + E->data.Selected=1; return 1; } -int select_object(Agraph_t * g, void *obj) -{ - switch (AGTYPE(obj)) { - case AGNODE: - select_node(g, obj); - break; - case AGEDGE: - select_edge(g, obj); - break; - case AGRAPH: - select_graph(g, obj); - break; - default: - break; - } - return 1; -} -int deselect_node(Agraph_t * g, Agnode_t * N) +int deselect_node(topview_node* N) { int ind = 0; int valid = 0; //check if in the list - for (ind = 0; ind < GD_selectedNodesCount(g); ind++) { - if (valid) - GD_selectedNodes(g)[ind - 1] = GD_selectedNodes(g)[ind]; - if (GD_selectedNodes(g)[ind] == N) - valid = 1; + for (ind = 0; ind < view->Topview->Graphdata.selectedNodesCount; ind++) + { + if (valid) + view->Topview->Graphdata.selectedNodes[ind-1]=view->Topview->Graphdata.selectedNodes[ind]; + if (view->Topview->Graphdata.selectedNodes[ind] == N) + valid = 1; } //for single selections i think realloc is ok, for mass selections i ll figure out something else - if (valid) { - GD_selectedNodes(g) = - RALLOC(GD_selectedNodesCount(g)-1,GD_selectedNodes(g), Agnode_t*); - GD_selectedNodesCount(g)--; - OD_Selected(N) = 0; - OD_SelFlag(N) = 0; - } + if (valid) + { + view->Topview->Graphdata.selectedNodes=RALLOC(view->Topview->Graphdata.selectedNodesCount-1,view->Topview->Graphdata.selectedNodes,topview_node*); + view->Topview->Graphdata.selectedNodesCount--; + N->data.Selected=0; + N->data.selectionflag=0; + } return 1; } -int deselect_edge(Agraph_t * g, Agedge_t * E) +int deselect_edge(topview_edge* E) { - int ind = 0; - int valid = 0; - //check if in the list - for (ind = 0; ind < GD_selectedEdgesCount(g); ind++) { - if (valid) - GD_selectedEdges(g)[ind-1] = GD_selectedEdges(g)[ind]; - if (GD_selectedEdges(g)[ind] == E) - valid = 1; - } - //for single selections i think realloc is ok, for mass selections i ll figure out something else - if (valid) { - GD_selectedEdges(g) = - RALLOC(GD_selectedEdgesCount(g)-1,GD_selectedEdges(g), Agedge_t*); - GD_selectedEdgesCount(g)--; - OD_Selected(E) = 0; - OD_SelFlag(E) = 0; - } - return 1; -} -static int deselect_graph(Agraph_t * g, Agraph_t * G) -{ int ind = 0; int valid = 0; //check if in the list - for (ind = 0; ind < GD_selectedGraphsCount(g); ind++) { - if (valid) - GD_selectedGraphs(g)[ind-1] = GD_selectedGraphs(g)[ind]; - if (GD_selectedGraphs(g)[ind] == G) - valid = 1; + for (ind = 0; ind < view->Topview->Graphdata.selectedEdgesCount; ind++) + { + if (valid) + view->Topview->Graphdata.selectedEdges[ind-1]=view->Topview->Graphdata.selectedEdges[ind]; + if (view->Topview->Graphdata.selectedEdges[ind] == E) + valid = 1; } //for single selections i think realloc is ok, for mass selections i ll figure out something else - if (valid) { - GD_selectedGraphs(g) = - RALLOC(GD_selectedGraphsCount(g)-1,GD_selectedGraphs(g), Agraph_t*); - GD_selectedGraphsCount(g)--; - OD_Selected(G) = 0; - OD_SelFlag(G) = 0; - } - return 1; -} -int deselect_object(Agraph_t * g, void *obj) -{ - switch (AGTYPE(obj)) { - case AGNODE: - deselect_node(g, obj); - break; - case AGEDGE: - deselect_edge(g, obj); - break; - case AGRAPH: - deselect_graph(g, obj); - break; - default: - break; - } + if (valid) + { + view->Topview->Graphdata.selectedEdges=RALLOC(view->Topview->Graphdata.selectedEdgesCount-1,view->Topview->Graphdata.selectedEdges,topview_edge*); + view->Topview->Graphdata.selectedEdgesCount--; + E->data.Selected=0; + E->data.selectionflag=0; + } return 1; + } -int select_all_nodes(Agraph_t * g) +int select_all_nodes() { - Agnode_t *n; - for (n = agfstnode(g); n; n = agnxtnode(g, n)) { - select_node(g, n); + int ind = 0; + //check if in the list + for (ind = 0; ind < view->Topview->Nodecount;ind ++) + { + select_node(&view->Topview->Nodes[ind]); } return 1; - } -int select_all_edges(Agraph_t * g) +int select_all_edges() { - Agnode_t *n; - Agedge_t *e; - - - n = agfstnode(g); - - for (n = agfstnode(g); n; n = agnxtnode(g, n)) { - for (e = agfstout(g, n); e; e = agnxtout(g, e)) { - select_edge(g, e); - } + int ind = 0; + //check if in the list + for (ind = 0; ind < view->Topview->Edges;ind ++) + { + select_edge(&view->Topview->Edges[ind]); } return 1; } -int select_all_graphs(Agraph_t * g) -{ - Agraph_t *s; - for (s = agfstsubg(g); s; s = agnxtsubg(s)) - select_graph(g, s); - return 1; -} -int deselect_all_nodes(Agraph_t * g) +int deselect_all_nodes() { - Agnode_t *n; - - - n = agfstnode(g); - - - for (n = agfstnode(g); n; n = agnxtnode(g, n)) { - deselect_node(g, n); + int ind = 0; + //check if in the list + for (ind = 0; ind < view->Topview->Nodecount;ind ++) + { + deselect_node(&view->Topview->Nodes[ind]); } return 1; - } -int deselect_all_edges(Agraph_t * g) +int deselect_all_edges() { - { - Agnode_t *n; - Agedge_t *e; - n = agfstnode(g); - for (n = agfstnode(g); n; n = agnxtnode(g, n)) { - for (e = agfstout(g, n); e; e = agnxtout(g, e)) { - deselect_edge(g, e); - } - } - return 1; + int ind = 0; + //check if in the list + for (ind = 0; ind < view->Topview->Edges;ind ++) + { + deselect_edge(&view->Topview->Edges[ind]); } - - -} -int deselect_all_graphs(Agraph_t * g) -{ - Agraph_t *s; - for (s = agfstsubg(g); s; s = agnxtsubg(s)) - deselect_graph(g, s); return 1; -} +} int select_all(Agraph_t * g) { - select_all_nodes(g); - select_all_edges(g); - select_all_graphs(g); + select_all_nodes(); + select_all_edges(); return 1; } int deselect_all(Agraph_t * g) { - deselect_all_nodes(g); - deselect_all_edges(g); - deselect_all_graphs(g); + deselect_all_nodes(); + deselect_all_edges(); return 1; } @@ -685,298 +590,6 @@ int is_point_in_rectangle(float X, float Y, float RX, float RY, float RW, } -int SelectBeziers(sdot_op * op) -{ - if (!view->Selection.Active) - return 0; - switch (view->Selection.Type) { - case 0: - if (view->Selection.AlreadySelected) - return 0; - if (spline_x_rect((xdot_op *) op)) { - if (OD_Selected(op->obj) == 0) { - OD_Selected(op->obj) = 1; - select_object(view->g[view->activeGraph], op->obj); - view->Selection.AlreadySelected = 1; - } else { - OD_Selected(op->obj) = 0; - deselect_object(view->g[view->activeGraph], op->obj); - view->Selection.AlreadySelected = 1; - } - } - break; - case 1: -#if 0 - if (OD_Selected(((xdot*)(op->parentxdot))->obj) == 1) - return 0; -#endif - if ((OD_SelFlag(op->obj) != -1) && spline_in_rect((xdot_op *) op)) { - OD_Preselected(op->obj) = 1; -// select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj); - view->Selection.AlreadySelected = 1; - } else { - OD_Preselected(op->obj) = 0; -// deselect_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj); - view->Selection.AlreadySelected = 1; - OD_SelFlag(op->obj) = -1; - } - break; - case 2: - if (OD_Selected(op->obj) == 1) - return 0; - if (spline_x_rect((xdot_op *) op)) { - OD_Selected(op->obj) = 1; - select_object(view->g[view->activeGraph], op->obj); - view->Selection.AlreadySelected = 1; - } - break; - default: - return 0; - } - return 1; - -} - -int SelectPolygon(sdot_op * op) -{ - - if (!view->Selection.Active) - return 0; - switch (view->Selection.Type) { - case 0: - if (view->Selection.AlreadySelected) - return 0; - if ((point_within_polygon((xdot_op *) op)) - || (polygon_x_rect((xdot_op *) op))) { - if (OD_Selected(op->obj) == 0) { - OD_Selected(op->obj) = 1; - select_object(view->g[view->activeGraph], op->obj); - view->Selection.AlreadySelected = 1; - } else { - OD_Selected(op->obj) = 0; - deselect_object(view->g[view->activeGraph], op->obj); - view->Selection.AlreadySelected = 1; - } - } - break; - case 1: - if (OD_Selected(op->obj) == 1) - return 0; - if ((OD_SelFlag(op->obj) != -1) && polygon_in_rect((xdot_op *) op)) { - OD_Preselected(op->obj) = 1; -// select_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj); -// view->Selection.AlreadySelected=1; - } else { - OD_Selected(op->obj) = 1; - OD_Preselected(op->obj) = 0; -// deselect_object (view->g[view->activeGraph],((xdot*)(op->parentxdot))->obj); - view->Selection.AlreadySelected = 1; - OD_SelFlag(op->obj) = -1; - } - break; - case 2: - if (OD_Selected(op->obj) == 1) - return 0; - if (polygon_x_rect((xdot_op *) op)) { - OD_Selected(op->obj) = 1; - select_object(view->g[view->activeGraph], op->obj); - view->Selection.AlreadySelected = 1; - } - break; - default: - return 0; - } - return 1; -} - -int SelectPolyline(sdot_op * op) -{ - if (!view->Selection.Active) - return 0; - switch (view->Selection.Type) { - case 0: - if (view->Selection.AlreadySelected) - return 0; - - if (polyline_x_rect((xdot_op *) op)) { - if (OD_Selected(op->obj) == 0) { - OD_Selected(op->obj) = 1; - select_object(view->g[view->activeGraph], op->obj); - view->Selection.AlreadySelected = 1; - } else { - OD_Selected(op->obj) = 0; - deselect_object(view->g[view->activeGraph], op->obj); - view->Selection.AlreadySelected = 1; - } - } - break; - case 1: - if (OD_Selected(op->obj) == 1) - return 0; - if ((OD_SelFlag(op->obj) != -1) - && polyline_in_rect((xdot_op *) op)) { - OD_Preselected(op->obj) = 1; - } else { - OD_Preselected(op->obj) = 0; - view->Selection.AlreadySelected = 1; - OD_SelFlag(op->obj) = -1; - } - - - break; - case 2: - if (OD_Selected(op->obj) == 1) - return 0; - if (polyline_x_rect((xdot_op *) op)) { - OD_Selected(op->obj) = 1; - select_object(view->g[view->activeGraph], op->obj); - view->Selection.AlreadySelected = 1; - } - break; - default: - return 0; - } - - return 1; - -} - -int SelectEllipse(sdot_op * op) -{ - if (!view->Selection.Active) - return 0; - switch (view->Selection.Type) { - case 0: - if (view->Selection.AlreadySelected) - return 0; - - if (point_within_ellipse((xdot_op *) op)) { - if (OD_Selected(op->obj) == 0) { - OD_Selected(op->obj) = 1; - select_object(view->g[view->activeGraph], op->obj); - view->Selection.AlreadySelected = 1; - - } else { - OD_Selected(op->obj) = 0; - deselect_object(view->g[view->activeGraph], op->obj); - view->Selection.AlreadySelected = 1; - - } - } else if (ellipse_x_rect((xdot_op *) op)) { - if (OD_Selected(op->obj) == 0) { - OD_Selected(op->obj) = 1; - select_object(view->g[view->activeGraph], op->obj); - view->Selection.AlreadySelected = 1; - } else { - OD_Selected(op->obj) = 0; - deselect_object(view->g[view->activeGraph], op->obj); - view->Selection.AlreadySelected = 1; - } - } - break; - case 1: - if (OD_Selected(op->obj) == 1) - return 0; - if ((OD_SelFlag(op->obj) != -1) && ellipse_in_rect((xdot_op *) op)) { - OD_Preselected(op->obj) = 1; - view->Selection.AlreadySelected = 1; - } else { - OD_Preselected(op->obj) = 0; - view->Selection.AlreadySelected = 1; - OD_SelFlag(op->obj) = -1; - } - break; - case 2: - if (OD_Selected(op->obj) == 1) - return 0; - if (ellipse_x_rect((xdot_op *) op)) { - OD_Selected(op->obj) = 1; - select_object(view->g[view->activeGraph], op->obj); - view->Selection.AlreadySelected = 1; - - } - break; - default: - return 0; - } - return 1; -} - -int SelectText(sdot_op * op) -{ - if (!view->Selection.Active) - return 0; - switch (view->Selection.Type) { - case 0: - if (view->Selection.AlreadySelected) - return 0; - if (text_x_rect(op)) { - if (OD_Selected(op->obj) == 0) - OD_Selected(op->obj) = 1; - else - OD_Selected(op->obj) = 0; - } - break; - case 1: - if (OD_Selected(op->obj) == 1) - return 0; - if (text_in_rect(op)) { - OD_Selected(op->obj) = 1; - select_object(view->g[view->activeGraph], op->obj); - view->Selection.AlreadySelected = 1; - } - break; - case 2: - if (OD_Selected(op->obj) == 1) - return 0; - if (text_x_rect(op)) { - OD_Selected(op->obj) = 1; - select_object(view->g[view->activeGraph], op->obj); - view->Selection.AlreadySelected = 1; - } - break; - default: - return 0; - } - return 1; - -} - -int SelectImage(sdot_op * op) -{ - if (!view->Selection.Active) - return 0; - switch (view->Selection.Type) { - case 0: - if (view->Selection.AlreadySelected) - return 0; - if (image_x_rect((xdot_op *) op)) { - if (OD_Selected(op->obj) == 0) { - OD_Selected(op->obj) = 1; - select_object(view->g[view->activeGraph], op->obj); - view->Selection.AlreadySelected = 1; - } else - OD_Selected(op->obj) = 0; - } - break; - case 1: - if (OD_Selected(op->obj) == 1) - return 0; - if (image_in_rect((xdot_op *) op)) - OD_Selected(op->obj) = 1; - break; - case 2: - if (OD_Selected(op->obj) == 1) - return 0; - if (image_x_rect((xdot_op *) op)) - OD_Selected(op->obj) = 1; - break; - default: - return 0; - } - return 1; - -} #if 0 static int line_intersects(float *x, float *y, float *X, float *Y) diff --git a/cmd/smyrna/selection.h b/cmd/smyrna/selection.h index d38a42880..08e663c06 100644 --- a/cmd/smyrna/selection.h +++ b/cmd/smyrna/selection.h @@ -36,23 +36,20 @@ extern int SelectPolyline(sdot_op * op); extern int SelectText(sdot_op * op); extern int SelectImage(sdot_op * op); -extern int select_node(Agraph_t * g, Agnode_t *); -extern int select_edge(Agraph_t * g, Agedge_t *); -extern int select_object(Agraph_t * g, void *obj); - -extern int deselect_object(Agraph_t * g, void *obj); -extern int deselect_node(Agraph_t * g, Agnode_t *); -extern int deselect_edge(Agraph_t * g, Agedge_t *); - -extern int select_all_nodes(Agraph_t * g); -extern int select_all_edges(Agraph_t * g); -extern int select_all_graphs(Agraph_t * g); -extern int select_all(Agraph_t * g); - -extern int deselect_all_nodes(Agraph_t * g); -extern int deselect_all_edges(Agraph_t * g); -extern int deselect_all_graphs(Agraph_t * g); -extern int deselect_all(Agraph_t * g); +extern int select_node(topview_node*); +extern int select_edge(topview_edge*); + + +extern int deselect_node(topview_node*); +extern int deselect_edge(topview_edge* ); + +extern int select_all_nodes(); +extern int select_all_edges(); +extern int select_all(); + +extern int deselect_all_nodes(); +extern int deselect_all_edges(); +extern int deselect_all(); int point_within_sphere_with_coords(float x0, float y0, float z0, float r,float x, float y,float z); float distance_to_line(float ax,float ay,float bx,float by,float cx,float cy); diff --git a/cmd/smyrna/smyrnadefs.h b/cmd/smyrna/smyrnadefs.h index 868d5d57c..041e274b4 100644 --- a/cmd/smyrna/smyrnadefs.h +++ b/cmd/smyrna/smyrnadefs.h @@ -96,6 +96,31 @@ typedef struct { #define MAX_BTN_CNT 50 +typedef enum { + VT_NONE, + VT_XDOT, + VT_TOPVIEW, + VT_TOPFISH, +} viewtype_t; + +typedef enum { + GVE_NONE = -1, + GVE_GRAPH, + GVE_CLUSTER, + GVE_NODE, + GVE_EDGE /* keep last */ +} gve_element; + +typedef enum { + GVK_NONE = -1, + GVK_DOT, + GVK_NEATO, + GVK_TWOPI, + GVK_CIRCO, + GVK_FDP, + GVK_SFDP/* keep last */ +} gvk_layout; + typedef struct { GtkButton **gtkhostbtn; int gtkhostbtncount; @@ -103,6 +128,108 @@ typedef struct { int hostactive[MAX_BTN_CNT]; //temporary static, convert to dynamic,realloc char **hostregex; } topviewdata; + + +//bind this to cgraph g +/* +#define GD_data(g) ((custom_graph_data*)AGDATA(g)) +#define GD_TopView(g) (GD_data(g)->TopView) +#define GD_Engine(g) (GD_data(g)->Engine) +#define GD_GraphFileName(g) (GD_data(g)->GraphFileName) +#define GD_GraphName(g) (GD_data(g)->GraphName) +#define GD_AlwaysShow(g) (GD_data(g)->AlwaysShow) +#define GD_Locked(g) (GD_data(g)->Locked) +#define GD_Modified(g) (GD_data(g)->Modified) +#define GD_selectedGraphs(g) (GD_data(g)->selectedGraphs) +#define GD_selectedGraphsCount(g) (GD_data(g)->selectedGraphsCount) +#define GD_selectedNodesCount(g) (GD_data(g)->selectedNodesCount) +#define GD_selectedNodes(g) (GD_data(g)->selectedNodes) +#define GD_selectedEdgesCount(g) (GD_data(g)->selectedEdgesCount) +#define GD_selectedEdges(g) (GD_data(g)->selectedEdges) +*/ + + +typedef enum { GEpixels, GEinches, GEmm } GEunit; + +typedef struct _object_data //has to be attached to every Node, Edge, Graph and cluster +{ + Agrec_t h; + int ID; + char *ObjName; + int ObjType; + int Layer; + int Visible; + int Locked; + int Highlighted; + int Selected; + int Preselected; + int NumDataCount; + float *NumData; + int StrDataCount; + char **StrData; + int selectionflag; + int param; //generic purpose param + int TVRef; //Topview reference + +} element_data; +typedef struct _temp_node_record //helper record to identofy head and tail of edges +{ + Agrec_t h; + int ID; + int TVref; //topview data structure reference +}temp_node_record; + +/*#define OD_ID(p) (((custom_object_data*)AGDATA(p))->ID) +#define OD_ObjName(p) (((custom_object_data*)AGDATA(p))->ObjName) +#define OD_ObjType(p) (((custom_object_data*)AGDATA(p))->ObjType) +#define OD_Layer(p) (((custom_object_data*)AGDATA(p))->Layer) +#define OD_Visible(p) (p->data.Visible) +#define OD_Locked(p) (((custom_object_data*)AGDATA(p))->Locked) +#define OD_Highlighted(p) (((custom_object_data*)AGDATA(p))->Highlighted) +#define OD_NumDataCount(p) (((custom_object_data*)AGDATA(p))->NumDataCount) +#define OD_NumData(p) (((custom_object_data*)AGDATA(p))->NumData) +#define OD_StrDataCount(p) (((custom_object_data*)AGDATA(p))->StrDataCount) +#define OD_StrData(p) (((custom_object_data*)AGDATA(p))->StrData) +#define OD_Selected(p) (((custom_object_data*)AGDATA(p))->Selected) +#define OD_Preselected(p) (((custom_object_data*)AGDATA(p))->Preselected) +#define OD_SelFlag(p) (((custom_object_data*)AGDATA(p))->selectionflag) +#define OD_TVRef(p) (((custom_object_data*)AGDATA(p))->TVRef)*/ + +#define OD_Visible(p) (p.data.Visible) +#define OD_Locked(p) (p.data.Locked) +#define OD_Highlighted(p) (p.data.Highlighted) + + + +typedef enum { CAM_PERSPECTIVE,CAM_ORTHO} cam_t; + +typedef struct _viewport_camera{ + float x; + float y; + float z; + + float targetx; + float targety; + float targetz; + int index; + float anglexy; + float anglexyz; + + float anglex; + float angley; + float anglez; + + + float camera_vectorx; + float camera_vectory; + float camera_vectorz; + float r; + + + cam_t type; // +} viewport_camera; + + typedef struct { Agnode_t *Node; /*original coordinates */ @@ -124,11 +251,12 @@ typedef struct { int degree; float node_alpha; int valid; + element_data data; } topview_node; typedef struct { - Agnode_t *Tnode; //Tail node - Agnode_t *Hnode; //Tail node +// topview_node *Tnode; //Tail node +// topview_node *Hnode; //Tail node Agedge_t *Edge; //edge itself float x1; float y1; @@ -136,41 +264,28 @@ typedef struct { float x2; float y2; float z2; - topview_node *Node1; - topview_node *Node2; + topview_node *Node1; //Tail + topview_node *Node2; //Head RGBColor Color; int update_required; + element_data data; } topview_edge; +typedef struct _graph_data { + Agrec_t h; + char *GraphFileName; + //graph's location, change these to move the whole graph + int Modified; //if graph has been modified after loading + float offsetx; + float offsety; + float offsetz; + topview_node **selectedNodes; + topview_edge **selectedEdges; -typedef enum { CAM_PERSPECTIVE,CAM_ORTHO} cam_t; - -typedef struct _viewport_camera{ - float x; - float y; - float z; - - float targetx; - float targety; - float targetz; - int index; - float anglexy; - float anglexyz; - - float anglex; - float angley; - float anglez; - - - float camera_vectorx; - float camera_vectory; - float camera_vectorz; - float r; - - - cam_t type; // -} viewport_camera; - + int selectedGraphsCount; + int selectedNodesCount; + int selectedEdgesCount; +} graph_data; typedef struct { topview_node *Nodes; @@ -193,6 +308,8 @@ typedef struct { int animate; topview_node** picked_nodes; int picked_node_count; + graph_data Graphdata; + int maxnodedegree; } topview; @@ -217,30 +334,7 @@ typedef struct _mouse_attr { clicked_mouse_button button; } mouse_attr; -typedef enum { - VT_NONE, - VT_XDOT, - VT_TOPVIEW, - VT_TOPFISH, -} viewtype_t; - -typedef enum { - GVE_NONE = -1, - GVE_GRAPH, - GVE_CLUSTER, - GVE_NODE, - GVE_EDGE /* keep last */ -} gve_element; -typedef enum { - GVK_NONE = -1, - GVK_DOT, - GVK_NEATO, - GVK_TWOPI, - GVK_CIRCO, - GVK_FDP, - GVK_SFDP/* keep last */ -} gvk_layout; typedef struct _attribute { char Type; @@ -254,85 +348,6 @@ typedef struct _attribute { } attribute; -//bind this to cgraph g -typedef struct _custom_graph_data { - Agrec_t h; - char *GraphName; - char *GraphFileName; - int AlwaysShow; //active or not draw it - int TopView; //default 0, 1 for topview data, dots and lines - int Locked; - gvk_layout Engine; - //graph's location, change these to move the whole graph - int Modified; //if graph has been modified after loading - float offsetx; - float offsety; - float offsetz; - - Agraph_t **selectedGraphs; //clusters , subgraphs indeed - Agnode_t **selectedNodes; - Agedge_t **selectedEdges; - - int selectedGraphsCount; - int selectedNodesCount; - int selectedEdgesCount; -} custom_graph_data; - -#define GD_data(g) ((custom_graph_data*)AGDATA(g)) -#define GD_TopView(g) (GD_data(g)->TopView) -#define GD_Engine(g) (GD_data(g)->Engine) -#define GD_GraphFileName(g) (GD_data(g)->GraphFileName) -#define GD_GraphName(g) (GD_data(g)->GraphName) -#define GD_AlwaysShow(g) (GD_data(g)->AlwaysShow) -#define GD_Locked(g) (GD_data(g)->Locked) -#define GD_Modified(g) (GD_data(g)->Modified) -#define GD_selectedGraphs(g) (GD_data(g)->selectedGraphs) -#define GD_selectedGraphsCount(g) (GD_data(g)->selectedGraphsCount) -#define GD_selectedNodesCount(g) (GD_data(g)->selectedNodesCount) -#define GD_selectedNodes(g) (GD_data(g)->selectedNodes) -#define GD_selectedEdgesCount(g) (GD_data(g)->selectedEdgesCount) -#define GD_selectedEdges(g) (GD_data(g)->selectedEdges) - -typedef enum { GEpixels, GEinches, GEmm } GEunit; - -typedef struct _custom_object_data //has to be attached to every Node, Edge, Graph and cluster -{ - Agrec_t h; - int ID; - char *ObjName; - int ObjType; - int Layer; - int Visible; - int Locked; - int Highlighted; - int Selected; - int Preselected; - int NumDataCount; - float *NumData; - int StrDataCount; - char **StrData; - int selectionflag; - int param; //generic purpose param - int TVRef; //Topview reference - -} custom_object_data; - -#define OD_ID(p) (((custom_object_data*)AGDATA(p))->ID) -#define OD_ObjName(p) (((custom_object_data*)AGDATA(p))->ObjName) -#define OD_ObjType(p) (((custom_object_data*)AGDATA(p))->ObjType) -#define OD_Layer(p) (((custom_object_data*)AGDATA(p))->Layer) -#define OD_Visible(p) (((custom_object_data*)AGDATA(p))->Visible) -#define OD_Locked(p) (((custom_object_data*)AGDATA(p))->Locked) -#define OD_Highlighted(p) (((custom_object_data*)AGDATA(p))->Highlighted) -#define OD_NumDataCount(p) (((custom_object_data*)AGDATA(p))->NumDataCount) -#define OD_NumData(p) (((custom_object_data*)AGDATA(p))->NumData) -#define OD_StrDataCount(p) (((custom_object_data*)AGDATA(p))->StrDataCount) -#define OD_StrData(p) (((custom_object_data*)AGDATA(p))->StrData) -#define OD_Selected(p) (((custom_object_data*)AGDATA(p))->Selected) -#define OD_Preselected(p) (((custom_object_data*)AGDATA(p))->Preselected) -#define OD_SelFlag(p) (((custom_object_data*)AGDATA(p))->selectionflag) -#define OD_TVRef(p) (((custom_object_data*)AGDATA(p))->TVRef) - typedef struct _selection { int Active; //0 there is no selection need to be applied char Type; //0 single selection , 1 rectangle , 2 rectangleX @@ -494,11 +509,24 @@ typedef struct _ViewInfo int drawnodes; int drawedges; int drawlabels; + int drawnodelabels; + int drawedgelabels; + + /*labelling properties*/ + void* glutfont; + glCompColor nodelabelcolor; + glCompColor edgelabelcolor; + int labelwithdegree; + int labelnumberofnodes; + int labelshownodes; + int labelshowedges; + viewtype_t dfltViewType; gvk_layout dfltEngine; GtkTextBuffer* consoleText; float FontSizeConst; glCompSet *widgets; //for novice user open gl menu + int visiblenodecount; /*helper variable to know the number of the nodes being rendered, good data to optimize speed*/ } ViewInfo; diff --git a/cmd/smyrna/topfisheyeview.c b/cmd/smyrna/topfisheyeview.c index cf5783b82..8260a296c 100644 --- a/cmd/smyrna/topfisheyeview.c +++ b/cmd/smyrna/topfisheyeview.c @@ -176,7 +176,7 @@ void fisheye_spherical(double x_focus, double y_focus, double z_focus, static v_data *makeGraph(topview * tv, int *nedges) { - int i; + int i,i2; int ne = tv->Edgecount; /* upper bound */ int nv = tv->Nodecount; v_data *graph = N_NEW(nv, v_data); @@ -210,7 +210,7 @@ static v_data *makeGraph(topview * tv, int *nedges) vp = (tp == np ? hp : tp); ne++; i_nedges++; - *edges++ = OD_TVRef(vp); + *edges++ =((temp_node_record*)AGDATA(vp))->TVref; *ewgts++ = 1; } diff --git a/cmd/smyrna/topview.c b/cmd/smyrna/topview.c index c8acf2657..a92f9140c 100755 --- a/cmd/smyrna/topview.c +++ b/cmd/smyrna/topview.c @@ -46,6 +46,7 @@ glCompSet *glcreate_gl_topview_menu(void); static void set_boundaries(topview * t); static void set_topview_options(void); static int draw_topview_label(topview_node * v, float zdepth); +static int draw_topview_edge_label(topview_edge * e, float zdepth); static int node_visible(Agnode_t * n); static int select_topview_node(topview_node * n); /* static int select_topview_edge(topview_edge * e); */ @@ -54,15 +55,44 @@ static int get_color_from_edge(topview_edge * e); static int draw_node_hint_boxes(void); static int pick_node(topview_node * n); +static void remove_recs() +{ + Agraph_t* g; + Agnode_t *v; + if(view->activeGraph < 0) + return; + g=view->g[view->activeGraph]; + for (v = agfstnode(g); v; v = agnxtnode(g, v)) + { + agdelrec(v,"temp_node_record"); + } +} void cleartopview(topview * t) { - /*clear nodes */ - free(t->Nodes); - /*clear edges */ - free(t->Edges); - free(t); + /*free attached records*/ + /*clear nodes */ + free (t->Nodes); + free (t->Edges); +// free(t); } +static void init_element_data(element_data* d) +{ + + d->Highlighted=0; + d->Layer=0; + d->Visible=1; + d->Highlighted=0; + d->Selected=0; + d->Preselected=0; + d->NumDataCount=0; + d->NumData=(float*)0; + d->StrDataCount=0; + d->StrData=(char**)0; + d->selectionflag=0; + d->param=0; + d->TVRef=-1; +} void preparetopview(Agraph_t * g, topview * t) { @@ -81,9 +111,6 @@ void preparetopview(Agraph_t * g, topview * t) float maxedgelen,minedgelen,len,edgelength; - - - maxedgelen=0; minedgelen=(float)99999999.00000; //FIX ME if you have a giant graph or fix your graph edgelength=0; @@ -93,7 +120,8 @@ void preparetopview(Agraph_t * g, topview * t) gtk_widget_hide(glade_xml_get_widget(xml, "layout6")); //hide top panel // gtk_widget_hide(glade_xml_get_widget(xml, "menubar1")); //hide menu data_type_count = 0; - d_attr1 = agget(g, "DataAttribute1"); + d_attr1=NULL; + d_attr1 = agget(g, "nodelabelattribute"); if (d_attr1) { if (!strcmp(d_attr1, "\\N")) sym = 0; @@ -106,17 +134,19 @@ void preparetopview(Agraph_t * g, topview * t) t->Edges = N_GNEW(agnedges(g), topview_edge); t->Nodes = N_GNEW(agnnodes(g), topview_node); - + t->maxnodedegree=1; /* malloc topviewdata */ - t->TopviewData = NEW(topviewdata); +// t->TopviewData = NEW(topviewdata); for (v = agfstnode(g); v; v = agnxtnode(g, v)) { - //set node TV reference - OD_TVRef(v) = ind; //view->Topview reference + + str=agget(v, "pos"); strcpy(buf, agget(v, "pos")); if (strlen(buf)) + //bind temp record; + agbindrec(v, "temp_node_record", sizeof(temp_node_record), TRUE);//graph custom data { a = (float) atof(strtok(buf, ",")); b = (float) atof(strtok(NULL, ",")); @@ -129,6 +159,10 @@ void preparetopview(Agraph_t * g, topview * t) /*initialize group index, -1 means no group */ t->Nodes[ind].GroupIndex = -1; t->Nodes[ind].Node = v; + t->Nodes[ind].data.TVRef=ind; + ((temp_node_record*)AGDATA(v))->TVref=ind; + init_element_data(&t->Nodes[ind].data); + if (agget(t->Nodes[ind].Node, "color")) { color = GetRGBColor(agget(t->Nodes[ind].Node, "color")); @@ -147,8 +181,10 @@ void preparetopview(Agraph_t * g, topview * t) t->Nodes[ind].zoom_factor = 1; t->Nodes[ind].degree = agdegree(g, v, 1, 1); + if (t->Nodes[ind].degree > t->maxnodedegree) + t->maxnodedegree=t->Nodes[ind].degree; + t->Nodes[ind].node_alpha = 1; - // (float) log((double) t->Nodes[ind].degree + (double) 0.3); if (d_attr1) { if (sym) @@ -172,11 +208,12 @@ void preparetopview(Agraph_t * g, topview * t) for (e = agfstout(g, v); e; e = agnxtout(g, e)) { - t->Edges[ind2].Hnode = aghead(e); - t->Edges[ind2].Tnode = agtail(e); + + init_element_data(&t->Edges[ind].data);/*init edge data*/ t->Edges[ind2].Edge = e; strcpy(buf, agget(aghead(e), "pos")); if (strlen(buf)) + { a = (float) atof(strtok(buf, ",")); b = (float) atof(strtok(NULL, ",")); @@ -211,51 +248,52 @@ void preparetopview(Agraph_t * g, topview * t) edgelength = edgelength + len; ind2++; } - //calculate a decent fontsize ind++; } -// calcfontsize(float totaledgelength,int totallabelsize,int edgecount,int totalnodecount) + /*calculate font size*/ view->FontSize=calcfontsize(edgelength,maxlabelsize,ind2,ind); - //attach edge node references , loop one more time + + /*attach edge node references , loop one more time*/ ind = 0; ind2 = 0; for (v = agfstnode(g); v; v = agnxtnode(g, v)) { - /* float minedgelength=0; */ - /* float maxedgelength=0; */ - //set node TV reference for (e=agfstout(g, v); e; e = agnxtout(g, e)) { - t->Edges[ind2].Node1 = - &t->Nodes[OD_TVRef(t->Edges[ind2].Tnode)]; - t->Edges[ind2].Node2 = - &t->Nodes[OD_TVRef(t->Edges[ind2].Hnode)]; + t->Edges[ind2].Node1 =&t->Nodes[((temp_node_record*)AGDATA(agtail(e)))->TVref]; + t->Edges[ind2].Node2 =&t->Nodes[((temp_node_record*)AGDATA(aghead(e)))->TVref]; ind2++; } ind++; } + /*create glcomp menu system*/ view->widgets =glcreate_gl_topview_menu(); -// view->widgets->fontset = fontset_init(); -// add_font(view->widgets->fontset,"Times 14");//wired in default font + /*set some stats for topview*/ t->Nodecount = ind; t->Edgecount = ind2; - view->fmg.fisheye_distortion_fac = 5; //need to be hooked to a widget - set_boundaries(t); - set_update_required(t); - //set componenet set's font with already loaded default font.This will be inherited by all components added to this set as default - attach_camera_widget(view); - load_host_buttons(t, g, view->widgets); - t->h = '\0'; + + /*get border values for the graph*/ + set_boundaries(t); + /*reset update required? values to false*/ + set_update_required(t); + /*for 3d graphs , camera controlling widget extension*/ + attach_camera_widget(view); + + /*for grouped data , group data viewing buttons extension*/ +// load_host_buttons(t, g, view->widgets); + /*set topologilca fisheye to NULL*/ + t->h = '\0'; if (view->dfltViewType == VT_TOPFISH) - t->is_top_fisheye = 1; + t->is_top_fisheye = 1; else - t->is_top_fisheye = 0; + t->is_top_fisheye = 0; - t->picked_node_count = 0; + /*reset picked nodes*/ + t->picked_node_count = 0; t->picked_nodes = '\0'; - + btnToolZoomFit_clicked(NULL,NULL); } /* @@ -329,29 +367,37 @@ static void enddrawcycle(Agraph_t* g) if (view->Selection.single_selected_edge) { if (!(view->mouse.button== rightmousebutton)) //right click pick mode { //left click single select mode - if (OD_Selected(view->Selection.single_selected_edge->Edge) == 0) { - OD_Selected(view->Selection.single_selected_edge->Edge) = 1; - select_object(view->g[view->activeGraph], view->Selection.single_selected_edge->Edge); - } else { - OD_Selected(view->Selection.single_selected_edge->Edge) = 1; - deselect_object(view->g[view->activeGraph], view->Selection.single_selected_edge->Edge); + if (view->Selection.single_selected_edge->data.Selected == 0) + { + view->Selection.single_selected_edge->data.Selected = 1; + select_edge(view->g[view->activeGraph], view->Selection.single_selected_edge); + } + else + { + view->Selection.single_selected_edge->data.Selected = 1; + deselect_edge(view->g[view->activeGraph], view->Selection.single_selected_edge); } } /* return 1; */ } - if (view->Selection.single_selected_node) { - if (view->mouse.button== rightmousebutton) //right click pick mode - pick_node(view->Selection.single_selected_node); - else { //left click single select mode - if (OD_Selected(view->Selection.single_selected_node->Node) == 0) { - OD_Selected(view->Selection.single_selected_node->Node) = 1; - select_object(view->g[view->activeGraph], view->Selection.single_selected_node->Node); - } else { - OD_Selected(view->Selection.single_selected_node->Node) = 1; - deselect_object(view->g[view->activeGraph], view->Selection.single_selected_node->Node); + if (view->Selection.single_selected_node) + { + if (view->mouse.button== rightmousebutton) //right click pick mode + pick_node(view->Selection.single_selected_node); + else + { //left click single select mode + if (view->Selection.single_selected_node->data.Selected == 0) + { + view->Selection.single_selected_node->data.Selected = 1; + select_node(view->Selection.single_selected_node); + } + else + { + view->Selection.single_selected_node->data.Selected = 1; + deselect_node(view->g[view->activeGraph], view->Selection.single_selected_node); } } - } + } } @@ -380,7 +426,7 @@ static int endtopviewnodes(Agraph_t* g) static int drawtopviewnodes(Agraph_t * g) { - topview_node *v; + topview_node *v; float ddx, ddy, ddz; int ind = 0; float dotsize = 0; @@ -388,6 +434,7 @@ static int drawtopviewnodes(Agraph_t * g) set_topview_options(); begintopviewnodes(g); + view->visiblenodecount=0; for (ind = 0; ((ind < view->Topview->Nodecount) && (view->drawnodes)); ind++) @@ -404,12 +451,12 @@ static int drawtopviewnodes(Agraph_t * g) v = &view->Topview->Nodes[ind]; if (!node_visible(v->Node)) continue; - + view->visiblenodecount = view->visiblenodecount + 1; select_topview_node(v); //UPDATE view->Topview data from cgraph if (v->update_required) update_topview_node_from_cgraph(v); - if (OD_Selected(v->Node) == 1) { + if (v->data.Selected == 1) { /* glColor4f(view->selectedNodeColor.R, view->selectedNodeColor.G, view->selectedNodeColor.B, @@ -490,7 +537,7 @@ static void drawtopviewedges(Agraph_t * g) continue; //select_topview_edge(e); - if (OD_Selected(e->Node1->Node) == 1) + if (e->Node1->data.Selected == 1) { //tail is selected ddx = dx; ddy = dy; @@ -501,7 +548,7 @@ static void drawtopviewedges(Agraph_t * g) ddy = 0; ddz = 0; } - if (OD_Selected(e->Node2->Node) == 1) + if (e->Node2->data.Selected == 1) { //head dddx = dx; dddy = dy; @@ -531,27 +578,66 @@ static int drawtopviewlabels(Agraph_t * g) { //drawing labels int ind = 0; - - if (view->drawlabels) { topview_node *v; - for (ind = 0; ind < view->Topview->Nodecount; ind++) { - v = &view->Topview->Nodes[ind]; + float f; + + if ((view->visiblenodecount >view->labelnumberofnodes) || (!view->labelshownodes)) + return 0; + if (view->Topview->maxnodedegree > 15) + f=15; + else + f=view->Topview->maxnodedegree; + for (ind = 0; ind < view->Topview->Nodecount; ind++) + { + + v = &view->Topview->Nodes[ind]; + + if( ((float)view->visiblenodecount > view->labelnumberofnodes * v->degree / f) && view->labelwithdegree) + continue; if (!node_visible(v->Node)) continue; draw_topview_label(v, 1); } return 1; - } - return 0; +} +static int drawtopviewedgelabels(Agraph_t * g) +{ + //drawing labels + int ind = 0; + topview_edge *e; + float f; + if ((view->visiblenodecount >view->labelnumberofnodes) || (!view->labelshowedges)) + return 0; + if (view->Topview->maxnodedegree > 15) + f=15; + else + f=view->Topview->maxnodedegree; + for (ind = 0; ind < view->Topview->Edgecount; ind++) + { + + e = &view->Topview->Edges[ind]; + + if( + (((float)view->visiblenodecount > view->labelnumberofnodes * e->Node1->degree / f) && view->labelwithdegree) + && + (((float)view->visiblenodecount > view->labelnumberofnodes * e->Node2->degree / f) && view->labelwithdegree) + ) + continue; + if( (!node_visible(e->Node1)) && (!node_visible(e->Node2)) ) + continue; + draw_topview_edge_label(e, 0.001); + } + return 1; } void drawTopViewGraph(Agraph_t * g) { drawtopviewnodes(g); - drawtopviewlabels(g); + drawtopviewlabels(g); drawtopviewedges(g); + drawtopviewedgelabels(g); enddrawcycle(g); @@ -722,10 +808,11 @@ static int select_topview_node(topview_node * n) case 1: case 2: if (view->Selection.Anti == 0) { - select_object(view->g[view->activeGraph], n->Node); + select_node(n); view->Selection.AlreadySelected = 1; } else { - deselect_object(view->g[view->activeGraph], n->Node); + + deselect_node (n); view->Selection.AlreadySelected = 1; } break; @@ -856,68 +943,59 @@ static int draw_topview_label(topview_node * v, float zdepth) float fs = 0; float ddx = 0; float ddy = 0; - if (!v->Label) - return 0; - + char* buf; if ((v->distorted_x / view->zoom * -1 > view->clipX1) && (v->distorted_x / view->zoom * -1 < view->clipX2) && (v->distorted_y / view->zoom * -1 > view->clipY1) && (v->distorted_y / view->zoom * -1 < view->clipY2)) { - fs=calculate_font_size(v); - - -/* fs = (v->degree ==1) ? - (float) (log((double) v->degree +1) *(double) 3) - : - (float) (log((double) v->degree +(double) 0.5) *(double) 3)*14;*/ - - fs =(float) (log((double) v->degree +(double) 0.7) *(double) 3)*14; - // fs=view->FontSize; - fs = fs * v->zoom_factor; - if (v->degree < 3) - fs=fs*2; - if (OD_Selected(v->Node) == 1) { - ddx = dx; - ddy = dy; - } - if ((fs / view->zoom*-1) < 15) + if (v->data.Selected == 1) + { + ddx = dx; + ddy = dy; + } + glColor4f(view->nodelabelcolor.R,view->nodelabelcolor.G,view->nodelabelcolor.B,view->nodelabelcolor.A); + buf=agget(agraphof(v->Node),"nodelabelattribute"); + if (buf) + glprintfglut(view->glutfont,(v->distorted_x - ddx),(v->distorted_y - ddy),agget(v->Node,buf)); + return 1; + } else return 0; +} +static int draw_topview_edge_label(topview_edge * e, float zdepth) +{ -// fs= 10; - fs= fs * (float)0.182; - -/*#define GLUT_BITMAP_9_BY_15 ((void*)2) -#define GLUT_BITMAP_8_BY_13 ((void*)3) -#define GLUT_BITMAP_TIMES_ROMAN_10 ((void*)4) -#define GLUT_BITMAP_TIMES_ROMAN_24 ((void*)5) -#if (GLUT_API_VERSION >= 3) -#define GLUT_BITMAP_HELVETICA_10 ((void*)6) -#define GLUT_BITMAP_HELVETICA_12 ((void*)7) -#define GLUT_BITMAP_HELVETICA_18 ((void*)8)*/ - - - -/* view->fontset->fonts[view->fontset->activefont]->fontheight=fs; - if ((log((float) v->degree) * -0.6 * view->zoom) > 0) - fontColor(view->fontset->fonts[view->fontset->activefont],(float) log((double) v->degree + (double) 1), - view->penColor.G, view->penColor.B, - view->penColor.A / (float) log((double) v->degree) * - (float) -0.4 * (float) view->zoom); - else - fontColor(view->fontset->fonts[view->fontset->activefont],(float) log((double) v->degree + (double) 1), - view->penColor.G, view->penColor.B, (float)0.7); - - fontColor(view->fontset->fonts[view->fontset->activefont],0,0,0,view->penColor.A / (float) log((double) v->degree) * - (float) -0.4 * (float) view->zoom);*/ - glColor4f(0,0.5,0.1,0.7); - glprintfglut(GLUT_BITMAP_HELVETICA_10,(v->distorted_x - ddx), - (v->distorted_y - ddy),v->Label ); + float fs = 0; + float ddx = 0; + float ddy = 0; + char* buf; + float x1,y1,x2,y2,x,y; + x1=e->Node1->distorted_x; + y1=e->Node1->distorted_y; + x2=e->Node2->distorted_x; + y2=e->Node2->distorted_y; + + + if ((x1 / view->zoom * -1 > view->clipX1) + && (x1 / view->zoom * -1 < view->clipX2) + && (y1 / view->zoom * -1 > view->clipY1) + && (y1 / view->zoom * -1 < view->clipY2)) + { - return 1; + x=(x2-x1)/2.00 + x1; + y=(y2-y1)/2.00 + y1; + if (e->data.Selected==1) + { + ddx = dx; + ddy = dy; + } + glColor4f(view->edgelabelcolor.R,view->edgelabelcolor.G,view->edgelabelcolor.B,view->edgelabelcolor.A); + buf=agget(agraphof(e->Edge),"edgelabelattribute"); + if (buf) + glprintfglut(view->glutfont,x - ddx,y - ddy,agget(e->Edge,buf)); + return 1; } else - return 0; - //vestedbb.com + return 0; } @@ -979,21 +1057,20 @@ static int get_color_from_edge(topview_edge * e) Alpha = (float) gtk_range_get_value((GtkRange *) AlphaScale); //check visibility; - if ((node_visible(e->Node1->Node)) - && (node_visible(e->Node2->Node))) + if ((node_visible(e->Node1)) + && (node_visible(e->Node2))) return_value = 1; /*if both head and tail nodes are selected use selection color for edges */ - if ((OD_Selected(e->Node1->Node)) || (OD_Selected(e->Node2->Node))) { + if ((e->Node1->data.Selected) || (e->Node2->data.Selected)) { glColor4f(view->selectedEdgeColor.R, view->selectedEdgeColor.G, view->selectedEdgeColor.B, view->selectedEdgeColor.A); return return_value; } /*if both head and tail nodes are highlighted use edge highlight color */ - - if ((OD_Highlighted(e->Node1->Node)) - && (OD_Highlighted(e->Node2->Node))) { + if ((e->Node1->data.Highlighted) + && (e->Node2->data.Highlighted)) { glColor4f(view->highlightedEdgeColor.R, view->highlightedEdgeColor.G, view->highlightedEdgeColor.B, @@ -1031,18 +1108,20 @@ static int get_color_from_edge(topview_edge * e) /*get edge's color attribute */ color_string = agget(e->Edge, "color"); - if (color_string) { - c = GetRGBColor(color_string); - glColor4f(c.R, c.G, c.B, Alpha); + if (color_string) + { + c = GetRGBColor(color_string); + glColor4f(c.R, c.G, c.B, Alpha); } else - glColor4f(e->Node1->Color.R, e->Node1->Color.G, e->Node1->Color.B, + glColor4f + (e->Node1->Color.R, e->Node1->Color.G, e->Node1->Color.B, Alpha); return return_value; } -static int node_visible(Agnode_t * n) +static int node_visible(topview_node * n) { - return OD_Visible(n); + n->data.Visible; } int move_TVnodes(void) @@ -1051,7 +1130,7 @@ int move_TVnodes(void) int ind = 0; for (ind = 0; ind < view->Topview->Nodecount; ind++) { v = &view->Topview->Nodes[ind]; - if (OD_Selected(v->Node)) { + if (v->data.Selected) { v->distorted_x = v->distorted_x - dx; v->distorted_y = v->distorted_y - dy; } @@ -1388,10 +1467,7 @@ static void menu_click_center(void *p) { if (view->active_camera == -1) /*2D mode*/ { - view->panx=0; - view->pany=0; - view->panz=0; - view->zoom=-20; + btnToolZoomFit_clicked(NULL,NULL); } else /*there is active camera , adjust it to look at the center*/ { @@ -1589,6 +1665,7 @@ glCompSet *glcreate_gl_topview_menu(void) b->panel = p; b->callbackfunc = menu_click_pan; glCompSetAddButton(s, b); + //zoom b = glCompButtonNew(85, 120, 72, 72, "adasasds", smyrna_icon_zoom, 72, 72,scientific_y); @@ -1759,8 +1836,8 @@ void select_with_regex(char* exp) { if(node_regex(v,exp)) { - OD_Selected(v->Node) = 1; - select_object(view->g[view->activeGraph], v->Node); + v->data.Selected = 1; + select_node(v); } } } diff --git a/cmd/smyrna/tvnodes.c b/cmd/smyrna/tvnodes.c index cd2ccfb6d..0d222c4e9 100755 --- a/cmd/smyrna/tvnodes.c +++ b/cmd/smyrna/tvnodes.c @@ -178,19 +178,19 @@ int validate_node(tv_node * TV_Node) //if show only highlighted if (TV_Nodes.filter.highlighted >= 0) { - if (OD_Highlighted(view->Topview->Nodes[TV_Node->index].Node)!= TV_Nodes.filter.highlighted) + if (view->Topview->Nodes[TV_Node->index].data.Highlighted!= TV_Nodes.filter.highlighted) valid = 0; } //if show only visibles if (TV_Nodes.filter.visible >= 0) { - if (OD_Visible(view->Topview->Nodes[TV_Node->index].Node)!= TV_Nodes.filter.visible) + if (view->Topview->Nodes[TV_Node->index].data.Visible!= TV_Nodes.filter.visible) valid = 0; } //if show only selected if (TV_Nodes.filter.selected >= 0) { - if (OD_Selected(view->Topview->Nodes[TV_Node->index].Node)!= TV_Nodes.filter.selected) + if (view->Topview->Nodes[TV_Node->index].data.Selected!= TV_Nodes.filter.selected) valid = 0; } return valid; @@ -220,7 +220,7 @@ static int update_node_gui_objects(tv_node * TV_Node) } gtk_widget_show((GtkWidget *) TV_Node->chkSelected); gtk_toggle_button_set_active((GtkToggleButton *) TV_Node->chkSelected, - OD_Selected(view->Topview-> Nodes[TV_Node->index].Node)); + view->Topview-> Nodes[TV_Node->index].data.Selected); //Id Label if (!TV_Node->IDLabel) { @@ -241,7 +241,7 @@ static int update_node_gui_objects(tv_node * TV_Node) gtk_widget_show((GtkWidget *) TV_Node->chkVisible); gtk_toggle_button_set_active((GtkToggleButton *) TV_Node->chkVisible, - OD_Visible(view->Topview->Nodes[TV_Node->index].Node)); + view->Topview->Nodes[TV_Node->index].data.Visible); //highlighted if (!TV_Node->chkHighlighted) { TV_Node->chkHighlighted = @@ -251,7 +251,7 @@ static int update_node_gui_objects(tv_node * TV_Node) } gtk_widget_show((GtkWidget *) TV_Node->chkHighlighted); gtk_toggle_button_set_active((GtkToggleButton*)TV_Node-> chkHighlighted, - OD_Highlighted(view->Topview->Nodes[TV_Node->index].Node)); + view->Topview->Nodes[TV_Node->index].data.Highlighted); //NAME @@ -579,31 +579,31 @@ int update_TV_data_from_gui(void) // apply if selected if (gtk_toggle_button_get_active ((GtkToggleButton *) TV_Nodes.TV_Node[i].chkSelected)) { - if (!OD_Selected(view->Topview->Nodes[index].Node)) + if (!view->Topview->Nodes[index].data.Selected) select_node(view->g[view->activeGraph], view->Topview->Nodes[index].Node); } else { - if (OD_Selected(view->Topview->Nodes[index].Node)) + if (view->Topview->Nodes[index].data.Selected) deselect_node(view->g[view->activeGraph], view->Topview->Nodes[index].Node); } // apply if Visible if (gtk_toggle_button_get_active ((GtkToggleButton *) TV_Nodes.TV_Node[i].chkVisible)) { - if (!OD_Visible(view->Topview->Nodes[index].Node)) - OD_Visible(view->Topview->Nodes[index].Node) = 1; + if (!view->Topview->Nodes[index].data.Visible) + view->Topview->Nodes[index].data.Visible = 1; } else { - if (OD_Visible(view->Topview->Nodes[index].Node)) - OD_Visible(view->Topview->Nodes[index].Node) = 0; + if (view->Topview->Nodes[index].data.Visible) + view->Topview->Nodes[index].data.Visible = 0; } // apply if Highlighted if (gtk_toggle_button_get_active ((GtkToggleButton *) TV_Nodes.TV_Node[i].chkHighlighted)) { - if (!OD_Highlighted(view->Topview->Nodes[index].Node)) - OD_Highlighted(view->Topview->Nodes[index].Node) = 1; + if (!view->Topview->Nodes[index].data.Highlighted) + view->Topview->Nodes[index].data.Highlighted = 1; } else { - if (OD_Highlighted(view->Topview->Nodes[index].Node)) - OD_Highlighted(view->Topview->Nodes[index].Node) = 0; + if (view->Topview->Nodes[index].data.Highlighted) + view->Topview->Nodes[index].data.Highlighted = 0; } //Data1 agset((void *) view->Topview->Nodes[index].Node, data_attr1, @@ -730,7 +730,7 @@ int tv_highligh_all(void) tvn.index = i; if (cache_validate_node(&tvn)) { - OD_Highlighted(view->Topview->Nodes[i].Node) = 1; + view->Topview->Nodes[i].data.Highlighted = 1; } } apply_filter_from_gui(); @@ -746,7 +746,7 @@ int tv_unhighligh_all(void) for (i = 0; i < view->Topview->Nodecount; i++) { tvn.index = i; if (cache_validate_node(&tvn)) { - OD_Highlighted(view->Topview->Nodes[i].Node) = 0; + view->Topview->Nodes[i].data.Highlighted = 0; } } apply_filter_from_gui(); @@ -761,7 +761,7 @@ int tv_show_all(void) for (i = 0; i < view->Topview->Nodecount; i++) { tvn.index = i; if (cache_validate_node(&tvn)) { - OD_Visible(view->Topview->Nodes[i].Node) = 1; + view->Topview->Nodes[i].data.Visible = 1; } } apply_filter_from_gui(); @@ -778,7 +778,7 @@ int tv_hide_all(void) for (i = 0; i < view->Topview->Nodecount; i++) { tvn.index = i; if (cache_validate_node(&tvn)) { - OD_Visible(view->Topview->Nodes[i].Node) = 0; + view->Topview->Nodes[i].data.Visible = 0; } } apply_filter_from_gui(); diff --git a/cmd/smyrna/viewport.c b/cmd/smyrna/viewport.c index db396a483..8ddac1f96 100755 --- a/cmd/smyrna/viewport.c +++ b/cmd/smyrna/viewport.c @@ -58,8 +58,8 @@ void clear_viewport(ViewInfo * view) { int ind = 0; /*free topview if there is one */ - if ((view->activeGraph >= 0) && GD_TopView(view->g[view->activeGraph])) - cleartopview(view->Topview); + if (view->activeGraph >= 0) + cleartopview(view->Topview); if (view->graphCount) { /*all cgraph graphs should be freed */ for (ind = 0; ind < view->graphCount; ind++) { @@ -69,6 +69,45 @@ void clear_viewport(ViewInfo * view) } free(view); } +static void* get_glut_font(int ind) +{ + + switch (ind) + { + case 0: + return GLUT_BITMAP_9_BY_15; + break; + case 1: + return GLUT_BITMAP_8_BY_13; + break; + case 2: + return GLUT_BITMAP_TIMES_ROMAN_10; + break; + case 3: + return GLUT_BITMAP_HELVETICA_10; + break; + case 4: + return GLUT_BITMAP_HELVETICA_12; + break; + case 5: + return GLUT_BITMAP_HELVETICA_18; + break; + default: + return GLUT_BITMAP_TIMES_ROMAN_10; + } + +} + + + +void close_graph(ViewInfo * view,int graphid) +{ + if (graphid >= 0) + cleartopview(view->Topview); + agclose(view->g[0]); + view->graphCount = view->graphCount -1; + view->activeGraph=-1; +} char *get_attribute_value(char *attr, ViewInfo * view, Agraph_t * g) { @@ -198,10 +237,30 @@ set_viewport_settings_from_template(ViewInfo * view, Agraph_t * g) atoi(get_attribute_value ("drawnodes", view, g)); view->drawedges= atoi(get_attribute_value ("drawedges", view, g)); - view->drawlabels= - atoi(get_attribute_value ("drawlabels", view, g)); + view->drawlabels=atoi(get_attribute_value ("drawlabels", view, g)); view->FontSizeConst=0; //this will be calculated later in topview.c while calculating optimum font size + view->glutfont=get_glut_font(atoi(get_attribute_value ("labelglutfont", view, g))); + colorxlate(get_attribute_value("nodelabelcolor", view, g), &cl,RGBA_DOUBLE); + view->nodelabelcolor.R=(float)cl.u.RGBA[0]; + view->nodelabelcolor.G=(float) cl.u.RGBA[1]; + view->nodelabelcolor.B=(float) cl.u.RGBA[2]; + view->nodelabelcolor.A= (float)atof(get_attribute_value("defaultnodealpha", view, g)); + colorxlate(get_attribute_value("edgelabelcolor", view, g), &cl,RGBA_DOUBLE); + view->edgelabelcolor.R=(float) cl.u.RGBA[0]; + view->edgelabelcolor.G=(float) cl.u.RGBA[1]; + view->edgelabelcolor.B=(float) cl.u.RGBA[2]; + view->edgelabelcolor.A= (float)atof(get_attribute_value("defaultedgealpha", view, g)); + view->labelwithdegree=atoi(get_attribute_value ("labelwithdegree", view, g)); + view->labelnumberofnodes=atof(get_attribute_value ("labelnumberofnodes", view, g)); + view->labelshownodes=atoi(get_attribute_value ("shownodelabels", view, g)); + view->labelshowedges=atoi(get_attribute_value ("showedgelabels", view, g)); + + + + + + //FIXME: I don't think an openGL function can be called before it // is initialized. @@ -359,79 +418,27 @@ void init_viewport(ViewInfo * view) static void load_graph_params(Agraph_t * graph) { char* s; - //file may or may have not gl edit attributes - //first defaults are set in loading function - //here file is checked for previously saved gledit attributes - if ((s = agget(graph, "GraphName"))) //Graph Name - { - GD_GraphName(graph) = N_GNEW(strlen(s)+1,char); - strcpy(GD_GraphName(graph), s); - } - if ((s = agget(graph, "AlwaysShow"))) - GD_AlwaysShow(graph) = atoi(s); - else - GD_AlwaysShow(graph) = 0; - - if (view->dfltViewType != VT_NONE) { - switch (view->dfltViewType) { - case VT_TOPVIEW : - case VT_TOPFISH : - GD_TopView(graph) = 1; - break; - case VT_XDOT : - default : - GD_TopView(graph) = 0; - break; - } - } - else if ((s = agget(graph, "TopView"))) - GD_TopView(graph) = mapbool(s); - else - GD_TopView(graph) = 0; - if ((s = agget(graph, "Locked"))) - GD_Locked(graph) = atoi(s); - else - GD_Locked(graph) = 0; - - GD_Engine(graph) = GVK_NONE; - if (view->dfltEngine != GVK_NONE) { - GD_Engine(graph) = view->dfltEngine; - } - else if ((s = agget(graph, "Engine"))) - GD_Engine(graph) = s2layout(s); - if (GD_Engine(graph) == GVK_NONE) - GD_Engine(graph) = GVK_DOT; - - GD_Modified(graph) = 0; //not modified yet - GD_selectedEdges(graph) = NULL; - GD_selectedNodes(graph) = NULL; - GD_selectedGraphs(graph) = NULL; + view->Topview->Graphdata.Modified=0; + view->Topview->Graphdata.selectedEdges=NULL; + view->Topview->Graphdata.selectedNodes=NULL; + view->Topview->Graphdata.selectedEdgesCount=0; + view->Topview->Graphdata.selectedEdgesCount=0; - GD_selectedNodesCount(graph) = 0; - GD_selectedEdgesCount(graph) = 0; - GD_selectedGraphsCount(graph) = 0; - -#if 0 - if((s = agget(graph, "xdotversion"))) - ((custom_graph_data*)AGDATA(g))->view->Topview=0; //need to check xdot version attribute - else //we dont know if it is view->Topview or simply a graph with no xdot, for testing i ll use view->Topview - ((custom_graph_data*)AGDATA(g))->view->Topview=1; -#endif } /* attach_object_custom_data_to_graph: * run once or to reset all data !! prev data is removed */ +#if 0 static int attach_object_custom_data_to_graph(Agraph_t * graph) { Agnode_t *n; Agedge_t *e; Agraph_t *s; - agbindrec(graph, "custom_graph_data", sizeof(custom_graph_data), TRUE); //graph custom data + agbindrec(graph, "custom_graph_data", sizeof(custom_graph_data), FALSE);//graph custom data init_object_custom_data(graph, graph); //attach to graph itself - n = agfstnode(graph); for (s = agfstsubg(graph); s; s = agnxtsubg(s)) @@ -446,6 +453,7 @@ static int attach_object_custom_data_to_graph(Agraph_t * graph) return 1; } +#endif /* update_graph_params: * adds gledit params @@ -454,16 +462,7 @@ static int attach_object_custom_data_to_graph(Agraph_t * graph) static void update_graph_params(Agraph_t * graph) { char tempString[100]; - - agattr(graph, AGRAPH, "GraphFileName", GD_GraphFileName(graph)); - agattr(graph, AGRAPH, "GraphName", GD_GraphName(graph)); - sprintf(tempString, "%i", GD_AlwaysShow(graph)); - agattr(graph, AGRAPH, "AlwaysShow", tempString); - sprintf(tempString, "%i", GD_TopView(graph)); - agattr(graph, AGRAPH, "TopView", tempString); - sprintf(tempString, "%i", GD_Locked(graph)); - agattr(graph, AGRAPH, "Locked", tempString); - agattr(graph, AGRAPH, "Engine", layout2s(GD_Engine(graph))); + agattr(graph, AGRAPH, "GraphFileName",view->Topview->Graphdata.GraphFileName); } /* clear_object_xdot: @@ -564,133 +563,6 @@ mkTemp (char* buf, size_t bufsz) #endif -static char* create_xdot_for_graph(Agraph_t * graph, int keeppos) -{ - static char buf[BUFSIZ]; - static char* cmd = buf; - static size_t buflen = BUFSIZ; - size_t len; - int r = 0; - FILE *output_file; - char* fix; - char* alg; - char* path; - static char xdotfile[sizeof(XDOTTEMP)]; - char dotfile[sizeof(DOTTEMP)]; - - /* The accesses below and in update_graph_params are only valid if - * custom_graph_data has been attached to the graph. - */ - int haveData = (aggetrec(graph, "custom_graph_data", TRUE) != 0); - gvk_layout engine; - - if (haveData) - update_graph_params(graph); - strcpy (dotfile, DOTTEMP); - if (mkTemp(dotfile, sizeof(dotfile))) return 0; - strcpy (xdotfile, XDOTTEMP); - if (mkTemp(xdotfile, sizeof(xdotfile))) return 0; - if (!(output_file = fopen(dotfile, "w"))) { - return 0; - } - - clear_graph_xdot(graph); - agwrite(graph, (void *) output_file); - fclose(output_file); - - if (keeppos) { - fix = " -n2"; - alg = " -Kneato"; - } - else { - char* s; - fix = ""; - engine = GVK_NONE; - if (haveData && (GD_Engine(graph) != GVK_NONE)) - engine = GD_Engine(graph); - else if (view->dfltEngine != GVK_NONE) - engine = view->dfltEngine; - else if ((s = agget(graph, "Engine"))) - engine = s2layout(s); - if (engine == GVK_NONE) - engine = GVK_DOT; - switch (engine) { - case GVK_DOT : - alg = " -Kdot"; - break; - case GVK_NEATO : - alg = " -Kneato"; - break; - case GVK_TWOPI : - alg = " -Ktwopi"; - break; - case GVK_CIRCO : - alg = " -Kcirco"; - break; - case GVK_FDP : - alg = " -Ksfdp"; - break; - case GVK_SFDP : - alg = " -Ksfdp"; - break; - default : - /* can't happen */ - break; - } - } - -#ifdef _WIN32 - path = "\"C:/graphviz-ms/bin/dot.exe\" "; -#else - path = "dot "; -#endif - - len = strlen(path) + strlen(fix) + strlen(alg) + strlen(dotfile) + - strlen(xdotfile) + sizeof(FMT); - if (len > buflen) { - buflen = len + BUFSIZ; - if (cmd == buf) cmd = N_GNEW(buflen, char); - else cmd = RALLOC (buflen, cmd, char); - } - sprintf (cmd, FMT, path, fix, alg, dotfile, xdotfile); - r = system (cmd); - unlink (dotfile); - - if (r) { // something went wrong - unlink (xdotfile); - return 0; - } - else - return xdotfile; -} - -/* - */ -static Agraph_t* -layoutGraph (Agraph_t *oldg, int keeppos, int closeold) -{ - FILE *input_file; - char *infile; - Agraph_t* newg; - - if (!(infile = create_xdot_for_graph(oldg, keeppos))) return 0; - while (!(input_file = fopen(infile, "r"))) { //HACK!!!! -// g_print("Cannot open xdot error %si\n",strerror(errno)); - - } - if (closeold) - agclose (oldg); - newg = agread(input_file, NIL(Agdisc_t *)); - refresh_borders(newg); - g_print ("xdot is being loaded\n"); - fclose (input_file); - unlink (infile); // Remove temp file - return newg; -} - -/* loadGraph: - * dont use directly, use add_graph_to_viewport_from_file instead - */ static Agraph_t *loadGraph(char *filename) { char* s; @@ -712,48 +584,15 @@ static Agraph_t *loadGraph(char *filename) /* If no position info, run layout with -Txdot */ - if (!agattr(g, AGNODE, "pos", NULL)) + if (!agattr(g, AGNODE, "pos", NULL)) { - g = layoutGraph (g, 0, 1); - if (!g) return 0; - } - /* If position info but not xdot, set Topview mode - */ - else if (!agattr(g, AGRAPH, "xdotversion", 0)) - { - agattr(g, AGRAPH, "TopView", "1"); - } - - attach_object_custom_data_to_graph(g); - load_graph_params(g); - - GD_GraphFileName(g) = strdup (filename); - -#if 0 - if(strcasecmp(agget(g, "TopView"),"1")==0) { - if(TopviewNodeCount > 0) { - Dlg=gtk_message_dialog_new (NULL, - GTK_DIALOG_MODAL, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_OK, - "For Performance issues , this program does not support multiple Topview graphs!"); - respond=gtk_dialog_run (Dlg); - gtk_object_destroy (Dlg); - agclose(g); - return 0; - } - else { - PrepareTopview(g); - } + g_print("There is no position info in %s\n", filename); + fclose (input_file); + return 0; } -#endif - if((s = agget(g, "TopView")) && (*s == '1')) - preparetopview(g, view->Topview); - else //set graph borders - { - refresh_borders(g); - scanGraph(g); //calling font caching routines once.... - } + load_graph_params(g); + view->Topview->Graphdata.GraphFileName = strdup (filename); + preparetopview(g, view->Topview); return g; } static void refresh_borders(Agraph_t* g) @@ -782,7 +621,6 @@ int add_graph_to_viewport_from_file(char *fileName) load_settings_from_graph(view->g[view->activeGraph]); update_graph_from_settings(view->g[view->activeGraph]); set_viewport_settings_from_template(view, view->g[view->activeGraph]); - refreshControls(view); return 1; } else return 0; @@ -807,62 +645,18 @@ int add_new_graph_to_viewport(void) } #endif -void refreshControls(ViewInfo * v) -{ - - int i = 0; - GtkComboBox *widget; - widget = get_SelectGraph(); - //load graph names to combobox - for (i = 0; i < v->graphCount; i++) { - gtk_combo_box_append_text(widget, GD_GraphFileName(v->g[i])); - } - view->SignalBlock = 1; //HACK - gtk_combo_box_set_active(widget, view->activeGraph); - view->SignalBlock = 0; - - - //change button colors - Color_Widget_bg("gray", glade_xml_get_widget(xml, "btnDot")); - Color_Widget_bg("gray", glade_xml_get_widget(xml, "btnNeato")); - Color_Widget_bg("gray", glade_xml_get_widget(xml, "btnTwopi")); - Color_Widget_bg("gray", glade_xml_get_widget(xml, "btnCirco")); - Color_Widget_bg("gray", glade_xml_get_widget(xml, "btnFdp")); - - - switch (GD_Engine(view->g[view->activeGraph])) { - case GVK_NONE : - break; - case GVK_DOT : - Color_Widget_bg("red", glade_xml_get_widget(xml, "btnDot")); - break; - case GVK_NEATO : - Color_Widget_bg("red", glade_xml_get_widget(xml, "btnNeato")); - break; - case GVK_TWOPI : - Color_Widget_bg("red", glade_xml_get_widget(xml, "btnTwopi")); - break; - case GVK_CIRCO : - Color_Widget_bg("red", glade_xml_get_widget(xml, "btnCirco")); - break; - case GVK_FDP : - Color_Widget_bg("red", glade_xml_get_widget(xml, "btnFdp")); - break; - } - glexpose(); -} - /* save_graph_with_file_name: * saves graph with file name; if file name is NULL save as is */ int save_graph_with_file_name(Agraph_t * graph, char *fileName) { - FILE *output_file; + + FILE *output_file; update_graph_params(graph); if (fileName) output_file = fopen(fileName, "w"); - else if (GD_GraphFileName(graph)) - output_file = fopen(GD_GraphFileName(graph), "w"); + else if (view->Topview->Graphdata.GraphFileName) + output_file = fopen(view->Topview->Graphdata.GraphFileName, "w"); else { g_print("there is no file name to save! Programmer error\n"); return 0; @@ -888,10 +682,10 @@ int save_graph(void) //check if there is an active graph if (view->activeGraph > -1) { //check if active graph has a file name - if (GD_GraphFileName(view->g[view->activeGraph])) { + if (view->Topview->Graphdata.GraphFileName) { return save_graph_with_file_name( view->g[view->activeGraph], - GD_GraphFileName(view->g[view-> activeGraph])); + view->Topview->Graphdata.GraphFileName); } else return save_as_graph(); } @@ -934,70 +728,10 @@ int save_as_graph(void) return 0; } -/* do_graph_layout: - * changes the layout. all user relocations are reset unless - * keeppos is set to 1 - * FIXME: the graph parameter is never used. - */ -int do_graph_layout(Agraph_t * graph, int Engine, int keeppos) -{ -#if 0 - Agnode_t *v; - Agedge_t *e; - Agsym_t *attr; - Dict_t *d; - int cnt; - mydata *p; -#endif - Agraph_t* oldg = view->g[view->activeGraph]; - Agraph_t* newg; - - GD_Engine(oldg) = Engine; - newg = layoutGraph (oldg, keeppos, 0); - - if (!newg) return 0; - //attaching rec for graph fields - attach_object_custom_data_to_graph(newg); - //set real file name - GD_GraphFileName(newg) = GD_GraphFileName(oldg); - load_graph_params(newg); //init glparams - //set engine - GD_Engine(newg) = GD_Engine(oldg); - GD_Modified(newg) = 1; - - clear_graph(oldg); - agclose(oldg); - view->g[view->activeGraph] = newg; - - refreshControls(view); - - return 1; -} - -/* - * Object Custom Data Functions - */ /* init_object_custom_data: * creates a custom_object_data */ -static int init_object_custom_data(Agraph_t * graph, void *obj) -{ - agdelrec(graph, "custom_object_data"); - agbindrec(obj, "custom_object_data", sizeof(custom_object_data), TRUE); - OD_ID(obj) = 0; - OD_ObjName(obj) = NULL; - OD_ObjType(obj) = AGTYPE(obj); - OD_Layer(obj) = -1; - OD_Visible(obj) = 1; - OD_Locked(obj) = 0; - OD_Highlighted(obj) = 0; - OD_NumDataCount(obj) = 0; - OD_NumData(obj) = NULL; - OD_StrDataCount(obj) = 0; - OD_StrData(obj) = NULL; - return 1; -} /* move_node: */ @@ -1106,6 +840,7 @@ static char *offset_spline(xdot * x, float dx, float dy, float headx, /* move_nodes: * move selected nodes */ +#if 0 void move_nodes(Agraph_t * g) { Agnode_t *obj; @@ -1162,7 +897,7 @@ void move_nodes(Agraph_t * g) } } } - +#endif int setGdkColor(GdkColor * c, char *color) { gvcolor_t cl; if (color != '\0') { diff --git a/cmd/smyrna/viewport.h b/cmd/smyrna/viewport.h index 3b003d082..d7ed8c978 100755 --- a/cmd/smyrna/viewport.h +++ b/cmd/smyrna/viewport.h @@ -27,12 +27,12 @@ void init_viewport(ViewInfo * view); void set_viewport_settings_from_template(ViewInfo * view, Agraph_t *); void clear_viewport(ViewInfo * view); int add_graph_to_viewport_from_file(char *fileName); +void close_graph(ViewInfo * view,int graphid); int save_graph(void); int save_graph_with_file_name(Agraph_t * graph, char *fileName); int save_as_graph(void); int do_graph_layout(Agraph_t * graph, int Engine, int keeppos); -void refreshControls(ViewInfo * v); void movenode(void *n, float dx, float dy); void glexpose(void); -- 2.40.0