From: arif Date: Thu, 23 Apr 2009 18:06:03 +0000 (+0000) Subject: graph modified dialog implemented , BYTE defined in smyrnadefs , cleaned up test... X-Git-Tag: LAST_LIBGRAPH~32^2~2144 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e43ab0a91ebb90f64c1be529aeb1fad2fa48df1b;p=graphviz graph modified dialog implemented , BYTE defined in smyrnadefs , cleaned up test code in main --- diff --git a/cmd/smyrna/gui/menucallbacks.c b/cmd/smyrna/gui/menucallbacks.c index e595ccc74..8ee07e46f 100755 --- a/cmd/smyrna/gui/menucallbacks.c +++ b/cmd/smyrna/gui/menucallbacks.c @@ -82,44 +82,32 @@ void mOptionsSlot(GtkWidget * widget, gpointer user_data) void mQuitSlot(GtkWidget * widget, gpointer user_data) { - //1 check all graphs 1 by 1 to see any unsaved - int respond; - int gIndex; -#ifdef UNUSED - int active_graph = view->activeGraph; //stores the active graph in case quit aborted -#endif - for (gIndex = 0; gIndex < view->graphCount; gIndex++) { - view->activeGraph = gIndex; - if (view->Topview->Graphdata.Modified) - { - sprintf(buf, - "graph %s has been modified \n , would you like to save it before quitting the the program?", - view->Topview->Graphdata.GraphFileName); - Dlg = - (GtkMessageDialog *) gtk_message_dialog_new(NULL, - GTK_DIALOG_MODAL, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_NONE, - buf); - gtk_dialog_add_button((GtkDialog *) Dlg, "YES", 100); - gtk_dialog_add_button((GtkDialog *) Dlg, "NO", 101); - gtk_dialog_add_button((GtkDialog *) Dlg, "Cancel", 102); - - respond = gtk_dialog_run((GtkDialog *) Dlg); - if (respond == 100) //save and continue - { - if (!save_graph()) - break; - } - if (respond == 102) //save and continue - { - break; - } - } - } - gtk_main_quit(); + if (close_graph(view,view->activeGraph)); + gtk_main_quit(); } +int show_close_nosavedlg(void) +{ + GtkWidget *dialog; + char buf[512]; + int rv; /*return value*/ + sprintf(buf,"%s has been modified. Do you want to save it before closing?",view->Topview->Graphdata.GraphFileName); + dialog = gtk_message_dialog_new(NULL, + GTK_DIALOG_MODAL, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + buf); + + gtk_window_set_title(GTK_WINDOW(dialog), "Smyrna Warning"); + gtk_dialog_add_button(dialog,"Yes",0); + gtk_dialog_add_button(dialog,"No",1); + gtk_dialog_add_button(dialog,"Cancel",2); + rv=gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + return rv; +} + + //edit void mCutSlot(GtkWidget * widget, gpointer user_data) diff --git a/cmd/smyrna/main.c b/cmd/smyrna/main.c index 9fa995ed2..4eb030e63 100755 --- a/cmd/smyrna/main.c +++ b/cmd/smyrna/main.c @@ -129,62 +129,6 @@ static void close_cgraph(Agraph_t* 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; -} -static void test_md5() -{ - char buf[512]; - BYTE digest[16]; - md5_state_t pms; - int ind=0; - - strcpy(buf,"sdfsdfsdfasdf asdfas dasdf asdf asdfas fsd asd fasdf asd fasdf sda fsdf asdf sda fasfsdf sdf sdf"); - /* Initialize the algorithm. */ - md5_init(&pms); - for (ind =0 ; ind < 1500000 ; ind ++) - { - md5_append(&pms,buf,32); - } - md5_finish(&pms,digest); - for (ind=0;ind < 16;ind ++) - { - printf ("%x ",digest[ind]); - } -} @@ -196,15 +140,6 @@ 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"); - test_md5(); - - - smyrnaDir = getenv ("SMYRNA_PATH"); #ifndef _WIN32 if (!smyrnaDir) diff --git a/cmd/smyrna/smyrnadefs.h b/cmd/smyrna/smyrnadefs.h index 7a286411f..b211ceae4 100644 --- a/cmd/smyrna/smyrnadefs.h +++ b/cmd/smyrna/smyrnadefs.h @@ -44,6 +44,8 @@ #include "glcompset.h" #include "hier.h" +typedef unsigned char BYTE; + #define IS_TEST_MODE_ON 0 #define DEFAULT_MAGNIFIER_WIDTH 300 #define DEFAULT_MAGNIFIER_HEIGHT 225 diff --git a/cmd/smyrna/viewport.c b/cmd/smyrna/viewport.c index 39871feff..bef23b77a 100755 --- a/cmd/smyrna/viewport.c +++ b/cmd/smyrna/viewport.c @@ -62,14 +62,9 @@ void clear_viewport(ViewInfo * view) /*free topview if there is one */ if (view->activeGraph >= 0) cleartopview(view->Topview); - if (view->graphCount) { - /*all cgraph graphs should be freed */ - for (ind = 0; ind < view->graphCount; ind++) { - agclose(view->g[ind]); - } - /*frees itself */ - } - free(view); + if (view->graphCount) + agclose(view->g[view->activeGraph]); + init_viewport(view); } static void* get_glut_font(int ind) { @@ -99,7 +94,7 @@ static void* get_glut_font(int ind) } } -static fill_key(BYTE* b,BYTE* data) +static void fill_key(BYTE* b,BYTE* data) { int ind=0; for (ind=0;ind < 16;ind ++) @@ -108,30 +103,56 @@ static fill_key(BYTE* b,BYTE* data) } } +static int compare_keys(BYTE* b1,BYTE* b2) +{ + /*1 keys are equal*/ + /*0 not equal*/ + + int ind=0; + int eq=1; + for (ind=0;ind < 16;ind ++) + { + if (b1[ind] != b2[ind]) + { + eq=0; + } + } + return eq; +} -void close_graph(ViewInfo * view,int graphid) +int close_graph(ViewInfo * view,int graphid) { int ind=0; int modified=0; - /*check if graph has been modified*/ + if (view->activeGraph < 0) + return 1; fill_key(view->final_key,get_md5_key(view->g[graphid])); - printf ("graph original identification:"); - for (ind=0;ind < 16;ind ++) - { - printf ("%x ",view->orig_key[ind]); - } - printf ("graph final identification:"); - for (ind=0;ind < 16;ind ++) + if (!compare_keys(view->final_key,view->orig_key)) + view->Topview->Graphdata.Modified=1; + if (view->Topview->Graphdata.Modified) { - printf ("%x ",view->final_key[ind]); - } + switch (show_close_nosavedlg()) + { + case 0: /*save and close*/ + save_graph(); + clear_viewport(view); + return 1; + break; + case 1:/*dont save but close*/ + clear_viewport(view); + return 1; + break; + case 2:/*cancel do nothing*/ + return 0; + break; + default: + break; + } + } + clear_viewport(view); + return 1; - 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) @@ -977,9 +998,12 @@ void glexpose(void) { expose_event(view->drawing_area, NULL, NULL); } int gl_main_expose(void) { - if(view->Topview->animate==1) - expose_event(view->drawing_area, NULL, NULL); - return 1; + if (view->activeGraph >= 0) + { + if(view->Topview->animate==1) + expose_event(view->drawing_area, NULL, NULL); + return 1; + } } @@ -1001,3 +1025,5 @@ void please_dont_wait(void) gtk_widget_hide(glade_xml_get_widget(xml, "frmWait")); } + + diff --git a/cmd/smyrna/viewport.h b/cmd/smyrna/viewport.h index 924bb84d6..3e14974b4 100755 --- a/cmd/smyrna/viewport.h +++ b/cmd/smyrna/viewport.h @@ -27,7 +27,7 @@ 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 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);