#include "selection.h"
#include "topviewsettings.h"
#include "gltemplate.h"
+#include <const.h>
+#include <agxbuf.h>
+
//file
char buf[255];
void mNewSlot(GtkWidget * widget, gpointer user_data)
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*/
+ }
+
+}
+
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)
{
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)
-/* 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);
}
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();
}
*/
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:
ExitProcess(1);
}
+static int dummyflush (void *chan)
+{
+ return 1;
+}
+
static Agraph_t*
ReadFromPipe()
{
Agiodisc_t a;
Agdisc_t disc;
Agraph_t* g=0;
+ DWORD lpExitCode;
+
if (!CloseHandle(SmyrnaToGvprWr))
ErrorExit(TEXT("StdOutWr CloseHandle"));
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;
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*/
+
}
}
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"));
-static int dummyflush (void *chan)
-{
- return 1;
-}
#else
#endif
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
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;
+}
+
+
+
+
+