From f5639756e2387e95b4a7a947e65db48d14c696df Mon Sep 17 00:00:00 2001 From: arif Date: Wed, 23 Apr 2008 18:14:00 +0000 Subject: [PATCH] selection enabled subgraph saving function fixed only node graphs --- cmd/smyrna/tvnodes.c | 98 ++++++++++++++++++++++++++++++++++++++++---- cmd/smyrna/tvnodes.h | 46 +++++++++++---------- 2 files changed, 114 insertions(+), 30 deletions(-) diff --git a/cmd/smyrna/tvnodes.c b/cmd/smyrna/tvnodes.c index 51df2cf57..67711b23c 100755 --- a/cmd/smyrna/tvnodes.c +++ b/cmd/smyrna/tvnodes.c @@ -77,6 +77,7 @@ void init_tv_nodes(tv_nodes * TV_Nodes) TV_Nodes->TV_Node[i].chkHighlighted = NULL; TV_Nodes->TV_Node[i].chkSelected = NULL; TV_Nodes->TV_Node[i].chkVisible = NULL; + TV_Nodes->TV_Node[i].Name = NULL; TV_Nodes->TV_Node[i].Data1 = NULL; TV_Nodes->TV_Node[i].Data2 = NULL; TV_Nodes->TV_Node[i].IDLabel = NULL; @@ -173,10 +174,13 @@ int validate_node(tv_node * TV_Node) if (data_attr2 && TV_Nodes.filter.max_data2 && agget(view->Topview->Nodes[TV_Node->index].Node, data_attr2)) { - if (agget - (view->Topview->Nodes[TV_Node->index].Node, data_attr2), - TV_Nodes.filter.min_data2) + + if (strcmp + (agget + (view->Topview->Nodes[TV_Node->index].Node, data_attr2), + TV_Nodes.filter.min_data2)) valid = 0; + } if (strlen(TV_Nodes.filter.filter_string) > 0) valid = evaluate_expresions(TV_Node, n); @@ -258,12 +262,23 @@ static int update_node_gui_objects(tv_node * TV_Node) OD_Highlighted(view->Topview->Nodes[TV_Node->index].Node)); - //DATA 1 + //NAME + if (!TV_Node->Name) { + TV_Node->Name = (GtkEntry *) gtk_entry_new(); + gtk_layout_put(layout, (GtkWidget *) TV_Node->Name, + LOCATION_X_NAME, TV_Nodes.Y); + gtk_widget_set_size_request((GtkWidget *) TV_Node->Name, 75, 23); + + } + gtk_entry_set_text(TV_Node->Name, + agnameof(view->Topview->Nodes[TV_Node->index].Node)); + gtk_widget_show((GtkWidget *) TV_Node->Name); + //DATA 1 if (!TV_Node->Data1) { TV_Node->Data1 = (GtkEntry *) gtk_entry_new(); gtk_layout_put(layout, (GtkWidget *) TV_Node->Data1, LOCATION_X_DATA1, TV_Nodes.Y); - gtk_widget_set_size_request((GtkWidget *) TV_Node->Data1, 300, 23); + gtk_widget_set_size_request((GtkWidget *) TV_Node->Data1, 200, 23); } if (data_attr1) { @@ -279,7 +294,7 @@ static int update_node_gui_objects(tv_node * TV_Node) TV_Node->Data2 = (GtkEntry *) gtk_entry_new(); gtk_layout_put(layout, (GtkWidget *) TV_Node->Data2, LOCATION_X_DATA2, TV_Nodes.Y); - gtk_widget_set_size_request((GtkWidget *) TV_Node->Data2, 300, 23); + gtk_widget_set_size_request((GtkWidget *) TV_Node->Data2, 200, 23); } if (data_attr2) { gtk_entry_set_text(TV_Node->Data2, @@ -318,6 +333,7 @@ static int hide_data_widgets() chkHighlighted); gtk_widget_hide((GtkWidget *) TV_Nodes.TV_Node[i].chkSelected); gtk_widget_hide((GtkWidget *) TV_Nodes.TV_Node[i].chkVisible); + gtk_widget_hide((GtkWidget *) TV_Nodes.TV_Node[i].Name); gtk_widget_hide((GtkWidget *) TV_Nodes.TV_Node[i].Data1); gtk_widget_hide((GtkWidget *) TV_Nodes.TV_Node[i].Data2); gtk_widget_hide((GtkWidget *) TV_Nodes.TV_Node[i].IDLabel); @@ -486,8 +502,7 @@ int prepare_page_history() TV_Nodes.activepage = -1; reset_page_History(); push_to_page_history(0); - - for (i = 0; i < view->Topview->Nodecount; i++) { + for (i = 0; i < view->Topview->Nodecount; i++) { tvn.index = i; if (validate_node(&tvn)) { count++; @@ -511,6 +526,45 @@ int prepare_page_history() set_data_attributes(); return 1; +} +/* + call this function to create a subgraph from filtered nodes and maybe edges +*/ + +int create_save_subgraph_from_filter(char* filename) +{ + + int i=0; + Agraph_t* subg = agsubg (view->g[view->activeGraph], "temp", 1); + FILE* outputfile; + for (i = 0; i < view->Topview->Nodecount; i++) + { + if (view->Topview->Nodes[i].valid==1) + { + agsubnode (subg, view->Topview->Nodes[i].Node, 1); + } + } + + if ((outputfile = fopen(filename, "w"))) + { + if(agwrite (subg, outputfile)) + { + agdelsubg (view->g[view->activeGraph], subg); + return 1; + } + else + { + agdelsubg (view->g[view->activeGraph], subg); + return 0; + } + } + else + { + agdelsubg (view->g[view->activeGraph], subg); + return 0; + } + + } int update_TV_data_from_gui() @@ -728,3 +782,31 @@ int tv_hide_all() } +int tv_save_as() +{ + GtkWidget *dialog; + dialog = gtk_file_chooser_dialog_new("Save File", + NULL, + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, + GTK_RESPONSE_ACCEPT, NULL); + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER + (dialog), TRUE); + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { + char *filename; + filename = + gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + + create_save_subgraph_from_filter(filename); + g_free(filename); + gtk_widget_destroy(dialog); + + return 1; + } else { + gtk_widget_destroy(dialog); + return 0; + } + return 0; +} diff --git a/cmd/smyrna/tvnodes.h b/cmd/smyrna/tvnodes.h index 8ec7e3524..e0f0d69fe 100755 --- a/cmd/smyrna/tvnodes.h +++ b/cmd/smyrna/tvnodes.h @@ -23,8 +23,9 @@ #define LOCATION_X_IDLABEL 45 #define LOCATION_X_CHKVISIBLE 139 #define LOCATION_X_CHKHIGHLIGHTED 202 -#define LOCATION_X_DATA1 276 -#define LOCATION_X_DATA2 600 +#define LOCATION_X_NAME 276 +#define LOCATION_X_DATA1 356 +#define LOCATION_X_DATA2 561 typedef struct token_info { int op_index; // has to @@ -67,6 +68,7 @@ typedef struct _tv_node { GtkCheckButton *chkVisible; GtkCheckButton *chkHighlighted; GtkLabel *IDLabel; + GtkEntry *Name; GtkEntry *Data1; GtkEntry *Data2; int valid; @@ -101,27 +103,27 @@ extern tv_nodes TV_Nodes; -extern void execute_tv_nodes(); -extern int set_filter(tv_filter * TV_Filter, char *MinData1, +void execute_tv_nodes(); +int set_filter(tv_filter * TV_Filter, char *MinData1, char *MaxData1, char *MinData2, char *MaxData2, char *Filter_String, int selected, int visible, int highlighted); -extern int tv_nodes_goto_page(int page); -extern int tv_nodes_next_page(); -extern int tv_nodes_prior_page(); -extern int tv_nodes_last_page(); -extern int tv_nodes_first_page(); - -extern int reset_page_History(); -extern int prepare_page_history(); -extern int update_TV_data_from_gui(); -extern int apply_filter_from_gui(); -extern int tv_select_all(); -extern int tv_unselect_all(); -extern int tv_highligh_all(); -extern int tv_unhighligh_all(); -extern int tv_show_all(); -extern int tv_hide_all(); - - +int tv_nodes_goto_page(int page); +int tv_nodes_next_page(); +int tv_nodes_prior_page(); +int tv_nodes_last_page(); +int tv_nodes_first_page(); + +int reset_page_History(); +int prepare_page_history(); +int create_save_subgraph_from_filter(char* filename); +int update_TV_data_from_gui(); +int apply_filter_from_gui(); +int tv_select_all(); +int tv_unselect_all(); +int tv_highligh_all(); +int tv_unhighligh_all(); +int tv_show_all(); +int tv_hide_all(); +int tv_save_as(); #endif -- 2.40.0