From: arif Date: Tue, 26 May 2009 17:00:08 +0000 (+0000) Subject: -gvpr button activated X-Git-Tag: LAST_LIBGRAPH~32^2~2009 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d2159ff7bacb8815a7dcd85e1964e5fdf171c7a1;p=graphviz -gvpr button activated -gvpr broken pipes issue fixed few gvpr windows related bugs fixed(iddefs for mingw and vs) --- diff --git a/cmd/smyrna/gui/menucallbacks.c b/cmd/smyrna/gui/menucallbacks.c index d0b1709c8..5043ecfe4 100755 --- a/cmd/smyrna/gui/menucallbacks.c +++ b/cmd/smyrna/gui/menucallbacks.c @@ -21,6 +21,9 @@ #include "selection.h" #include "topviewsettings.h" #include "gltemplate.h" +#include +#include + //file char buf[255]; void mNewSlot(GtkWidget * widget, gpointer user_data) @@ -395,6 +398,99 @@ float GetOGLDistance(int l); void mTestgvpr(GtkWidget * widget, gpointer user_data) { // apply_gvpr(view->g[view->activeGraph],"c:/graphviz-ms/bin/makered.g"); - float vecdist=GetOGLDistance(10); - printf ("z:%f vec:%f\n",view->zoom,vecdist); + int charcnt; + char bf[512]; + char* bf2; + GtkTextBuffer * gtkbuf; + GtkTextIter* startit; + GtkTextIter* endit; + startit=gtk_text_buffer_new(NULL); + endit=gtk_text_buffer_new(NULL); + gtkbuf=gtk_text_view_get_buffer((GtkTextView*) glade_xml_get_widget(xml,"gvprtextinput")); + charcnt=gtk_text_buffer_get_char_count (gtkbuf); + gtk_text_buffer_get_start_iter (gtkbuf,startit); + gtk_text_buffer_get_end_iter (gtkbuf,endit); + + bf2=gtk_text_buffer_get_text(gtkbuf,startit,endit,0); + if(save_gvpr_program(bf2,&bf)) + apply_gvpr(view->g[view->activeGraph],bf); + +} + + + + + +/* + opens a file open dialog and load a gvpr program to gvpr script text box + if the current script is modified, user should be informed about it +*/ +void on_gvprbuttonload_clicked(GtkWidget * widget, gpointer user_data) +{ + FILE *input_file=NULL; + char* str; + agxbuf xbuf; + GtkTextBuffer * gtkbuf; /*GTK buffer from glade GUI*/ + + char c[2]; + agxbinit (&xbuf, SMALLBUF, NULL); + /*file name should be returned in xbuf*/ + if(openfiledlg(0,NULL,&xbuf)) + { + input_file = fopen(agxbuse (&xbuf), "r"); + if (input_file) + { + + while(1) + { + c[0] = fgetc(input_file); + c[1]= NULL;/*agxbuffer doesnt accept single char, probably strlen is used , FIX ME!!*/ + if(c[0] !=EOF) + agxbput (&xbuf,c); + else + break; /* ...break when EOF is reached */ + } + gtkbuf=gtk_text_view_get_buffer((GtkTextView*) glade_xml_get_widget(xml,"gvprtextinput")); + str=agxbuse (&xbuf); + printf ("%ds",strlen(str)); + if(g_utf8_validate(str,-1,NULL)) + { + gtk_text_buffer_set_text (gtkbuf,agxbuse (&xbuf),-1); + } + else + { + show_gui_warning ("File format is not UTF8!"); + } + fclose (input_file); + } + else + { + show_gui_warning ("file couldnt be opened\n"); + + } + } } + +/* + opens a file open dialog and load a gvpr program to gvpr script text box + if the current script is modified, user should be informed about it +*/ +void on_gvprbuttonsave_clicked(GtkWidget * widget, gpointer user_data) +{ + FILE *output_file=NULL; + char* str; + agxbuf xbuf; + GtkTextBuffer * gtkbuf; /*GTK buffer from glade GUI*/ + + char c[2]; + agxbinit (&xbuf, SMALLBUF, NULL); + /*file name should be returned in xbuf*/ + if(savefiledlg(0,NULL,&xbuf)) + { + output_file = fopen(agxbuse (&xbuf), "w"); + + /*Code has not been completed for this function yet*/ + } + +} + diff --git a/cmd/smyrna/gui/menucallbacks.h b/cmd/smyrna/gui/menucallbacks.h index 6f4338714..a368057b0 100755 --- a/cmd/smyrna/gui/menucallbacks.h +++ b/cmd/smyrna/gui/menucallbacks.h @@ -81,4 +81,7 @@ _BB void mTestgvpr(GtkWidget * widget, gpointer user_data); void change_cursor(GdkCursorType C); int show_close_nosavedlg(void); +/*others from settings dialog*/ +_BB void on_gvprbuttonload_clicked(GtkWidget * widget, gpointer user_data); + #endif diff --git a/cmd/smyrna/gui/toolboxcallbacks.c b/cmd/smyrna/gui/toolboxcallbacks.c index d3cd77806..0200953a8 100755 --- a/cmd/smyrna/gui/toolboxcallbacks.c +++ b/cmd/smyrna/gui/toolboxcallbacks.c @@ -73,20 +73,12 @@ void btnToolZoom_clicked(GtkWidget * widget, gpointer user_data) void btnToolZoomIn_clicked(GtkWidget * widget, gpointer user_data) { - view->zoom = view->zoom + (float)ZOOM_STEP*GetOGLDistance(250); - if (view->zoom > MAX_ZOOM) - view->zoom = (float) MAX_ZOOM; - glexpose(); - + glmotion_zoom_inc(1); } void btnToolZoomOut_clicked(GtkWidget * widget, gpointer user_data) { - view->FontSizeConst=GetOGLDistance(14); - view->zoom = view->zoom - (float)ZOOM_STEP*GetOGLDistance(250); - if (view->zoom < MIN_ZOOM) - view->zoom = MIN_ZOOM; - expose_event(view->drawing_area, NULL, NULL); + glmotion_zoom_inc(0); } void btnToolZoomFit_clicked(GtkWidget * widget, gpointer user_data) @@ -121,12 +113,6 @@ void btnToolFit_clicked(GtkWidget * widget, gpointer user_data) { float scx,scy,gcx,gcy,z; -/* printf ("graph boundry summary\n"); - printf ("---------------------\n"); - printf ("G (%f,%f) - (%f,%f)\n",view->bdxLeft/view->zoom*-1,view->bdyBottom/view->zoom - *-1,view->bdxRight/view->zoom*-1,view->bdyTop/view->zoom*-1); - printf ("Scr (%f,%f) - (%f,%f)\n",view->clipX1 ,view->clipY1 ,view->clipX2 ,view->clipY2); - printf ("Old Panx:%f\n",view->panx);*/ (view->active_camera >=0) @@ -134,10 +120,6 @@ void btnToolFit_clicked(GtkWidget * widget, gpointer user_data) -/* printf ("Z:%f BDX:%f zoom * BDX :%f\n",z,(view->bdxRight/z-view->bdxLeft/z),z*(view->bdxRight/z-view->bdxLeft/z));*/ - - - gcx=view->bdxLeft/z+(view->bdxRight/z-view->bdxLeft/z)/(float)(2.0); @@ -155,13 +137,10 @@ void btnToolFit_clicked(GtkWidget * widget, gpointer user_data) } else { - /* float GDX=(view->bdxRight/z-view->bdxLeft/z); */ - /* float SDX=(view->clipX2 -view->clipX1); */ -// printf ("GDX:%f SDX:%f \n",GDX,SDX); view->panx += (gcx-scx); view->pany += (gcy-scy); } - + view->Topview->fitin_zoom=view->zoom; glexpose(); } diff --git a/cmd/smyrna/gvprpipe.c b/cmd/smyrna/gvprpipe.c index 8e44a2d4c..8223b6f6f 100644 --- a/cmd/smyrna/gvprpipe.c +++ b/cmd/smyrna/gvprpipe.c @@ -39,30 +39,38 @@ */ static HANDLE GvprToSmyrnaWr; +static HANDLE GvprToSmyrnaWrErr; static HANDLE GvprToSmyrnaRd; +static HANDLE GvprToSmyrnaErr; static HANDLE SmyrnaToGvprWr; static HANDLE SmyrnaToGvprRd; static SECURITY_ATTRIBUTES saAttr; +static PROCESS_INFORMATION piProcInfo; + /*cgraph wrappers*/ static int cgraph_write_wrapper(void *chan, char *str) { - DWORD dwWritten; + DWORD dwWritten,lpExitCode; BOOL bSuccess = FALSE; + GetExitCodeProcess( piProcInfo.hProcess,&lpExitCode); + if (lpExitCode!=259) /*still alive?*/ + return EOF; + bSuccess = WriteFile(SmyrnaToGvprWr, str, (DWORD)strlen(str), &dwWritten, NULL); - if ( ! bSuccess ) return 0; - return dwWritten; + if ( ! bSuccess ) return EOF; + return 0; } static int cgraph_read_wrapper (void* ch,char* bf,int sz) { - DWORD dwRead; - int ind=0; - ReadFile( GvprToSmyrnaRd, bf, sz, &dwRead, NULL); - printf("read returned value:%d\n",strlen(bf)); - printf("%s\n",bf); - return dwRead; + DWORD dwRead,lpExitCode; + BOOL bSuccess = FALSE; + int ind=0; + bSuccess=ReadFile( GvprToSmyrnaRd, bf, sz, &dwRead, NULL); + if ( ! bSuccess ) return EOF; + return dwRead; } /* ErrorExit: @@ -99,6 +107,11 @@ ErrorExit(PTSTR lpszFunction) ExitProcess(1); } +static int dummyflush (void *chan) +{ + return 1; +} + static Agraph_t* ReadFromPipe() { @@ -108,6 +121,8 @@ ReadFromPipe() Agiodisc_t a; Agdisc_t disc; Agraph_t* g=0; + DWORD lpExitCode; + if (!CloseHandle(SmyrnaToGvprWr)) ErrorExit(TEXT("StdOutWr CloseHandle")); @@ -118,19 +133,21 @@ ReadFromPipe() disc.id = &AgIdDisc; disc.mem = &AgMemDisc; g=agread(NULL,&disc); +/* CloseHandle(piProcInfo.hProcess); + CloseHandle(piProcInfo.hThread);*/ + return g; } static void -CreateChildProcess(TCHAR* szCmdline,HANDLE g_hChildStd_IN_Rd,HANDLE g_hChildStd_OUT_Wr) +CreateChildProcess(TCHAR* szCmdline,HANDLE g_hChildStd_IN_Rd,HANDLE g_hChildStd_OUT_Wr,HANDLE g_hChildStd_ERR_Wr) { - PROCESS_INFORMATION piProcInfo; STARTUPINFO siStartInfo; BOOL bSuccess = FALSE; ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) ); ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) ); siStartInfo.cb = sizeof(STARTUPINFO); - siStartInfo.hStdError = g_hChildStd_OUT_Wr; +// siStartInfo.hStdError = g_hChildStd_ERR_Wr; siStartInfo.hStdOutput = g_hChildStd_OUT_Wr; siStartInfo.hStdInput = g_hChildStd_IN_Rd; siStartInfo.dwFlags |= STARTF_USESTDHANDLES; @@ -145,16 +162,17 @@ CreateChildProcess(TCHAR* szCmdline,HANDLE g_hChildStd_IN_Rd,HANDLE g_hChildStd_ NULL, // use parent's current directory &siStartInfo, // STARTUPINFO pointer &piProcInfo); // receives PROCESS_INFORMATION - if ( ! bSuccess ) + { + ErrorExit(TEXT("CreateProcess")); + + } else { - // Close handles to the child process and its primary thread. - // Some applications might keep these handles to monitor the status - // of the child process, for example. - CloseHandle(piProcInfo.hProcess); - CloseHandle(piProcInfo.hThread); +/* GetExitCodeProcess( piProcInfo.hProcess,&lpExitCode); + if (lpExitCode==259) /*still alive*/ + } } @@ -171,6 +189,8 @@ static void createpipes() ErrorExit(TEXT("StdoutRd CreatePipe")); if ( ! SetHandleInformation(GvprToSmyrnaRd, HANDLE_FLAG_INHERIT, 0) ) ErrorExit(TEXT("Stdout SetHandleInformation")); + + if (! CreatePipe(&SmyrnaToGvprRd, &SmyrnaToGvprWr, &saAttr, 0)) ErrorExit(TEXT("Stdin CreatePipe")); @@ -182,10 +202,6 @@ static void createpipes() -static int dummyflush (void *chan) -{ - return 1; -} #else #endif @@ -194,12 +210,12 @@ Agraph_t* exec_gvpr(char* filename,Agraph_t* srcGraph) { Agraph_t* G; + DWORD lpExitCode; unsigned char bf[SMALLBUF]; agxbuf xbuf; #ifdef WIN32 Agiodisc_t* xio; Agiodisc_t a; - init_security_attr(&saAttr); createpipes(); #else @@ -211,23 +227,56 @@ exec_gvpr(char* filename,Agraph_t* srcGraph) agxbput (&xbuf, filename); #ifdef WIN32 - CreateChildProcess (agxbuse (&xbuf), SmyrnaToGvprRd, GvprToSmyrnaWr); - + CreateChildProcess (agxbuse (&xbuf), SmyrnaToGvprRd, GvprToSmyrnaWr,GvprToSmyrnaWr); xio = srcGraph->clos->disc.io; a.afread = srcGraph->clos->disc.io->afread; a.putstr = cgraph_write_wrapper; a.flush = xio->flush; srcGraph->clos->disc.io = &a; - agwrite(srcGraph,NULL); + /*we need to check if there is still a pipe to write, iif child process is still alive?*/ + agwrite(srcGraph,NULL); srcGraph->clos->disc.io = xio; - G = ReadFromPipe() ; + GetExitCodeProcess( piProcInfo.hProcess,&lpExitCode); + if (lpExitCode!=259) /*still alive?*/ + G=NULL; + else + G = ReadFromPipe() ; #else pp = popen (agxbuse (&xbuf), "r+"); agwrite(srcGraph, pp); G = agread(pp, NULL) ; pclose (pp); #endif + CloseHandle(piProcInfo.hProcess); + CloseHandle(piProcInfo.hThread); return G; } +/* + saves a gvpr file as a temporary file ,returns file name's full path + +*/ +int save_gvpr_program(char* prg,char* bf) +{ + FILE *input_file=NULL; + char buf[512]; + char buf2[512]; + GetTempPath(512,buf); + if(!GetTempFileName( buf,"gvpr",NULL,buf2)) + return 0; + input_file = fopen(buf2, "w"); + strcpy(bf,buf2); + if (input_file) + { + fprintf(input_file,"%s",prg); + fclose (input_file); + return 1; + } + return 0; +} + + + + +