From: ellson Date: Wed, 23 Jan 2008 20:52:43 +0000 (+0000) Subject: Add smyrna to main graphviz tree X-Git-Tag: LAST_LIBGRAPH~32^2~4852 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c3e4e539aef3052eecd74b3463d6518a197ff7fb;p=graphviz Add smyrna to main graphviz tree --- diff --git a/cmd/smyrna/.cvsignore b/cmd/smyrna/.cvsignore new file mode 100644 index 000000000..30020f6b0 --- /dev/null +++ b/cmd/smyrna/.cvsignore @@ -0,0 +1,8 @@ +*.la +*.lo +*.pc +.deps +.libs +Makefile +Makefile.in +smyrna diff --git a/cmd/smyrna/Makefile.am b/cmd/smyrna/Makefile.am new file mode 100644 index 000000000..36451c621 --- /dev/null +++ b/cmd/smyrna/Makefile.am @@ -0,0 +1,32 @@ +guidir = $(pkgdatadir)/gui +icondir = $(pkgdatadir)/icons + +AM_CPPFLAGS = \ + -DSMYRNA_GLADE=\""$(guidir)/smyrna.glade"\" \ + -DSMYRNA_FONT=\""$(guidir)/arial.tga"\" \ + -DSMYRNA_ICONSDIR=\""$(iconsdir)"\" \ + -I$(top_srcdir) \ + -I$(top_srcdir)/lib/cgraph \ + -I$(top_srcdir)/lib/cdt \ + -I$(top_srcdir)/lib/filter \ + -I$(top_srcdir)/lib/utilities \ + -I$(top_srcdir)/lib/xdot \ + -I$(top_srcdir)/lib/gui \ + -I$(top_srcdir)/lib/common \ + $(GTK_CFLAGS) $(GTKGLEXT_CFLAGS) $(GLADE_CFLAGS) $(FREETYPE2_CFLAGS) $(FONTCONFIG_CFLAGS) + +if WITH_SMYRNA +noinst_HEADERS = draw.h glTemplate.h materials.h support.h topview.h trackball.h tvnodes.h viewport.h +bin_PROGRAMS = smyrna +endif + +smyrna_SOURCES = topview.c viewport.c draw.c glTemplate.c main.c support.c template.c trackball.c tvnodes.c + +smyrna_LDADD = $(top_builddir)/lib/cgraph/libcgraph_C.la \ + $(top_builddir)/lib/cdt/libcdt_C.la \ + $(top_builddir)/lib/utilities/libutilities_C.la \ + $(top_builddir)/lib/xdot/libxdot_C.la \ + $(top_builddir)/lib/filter/libfilter_C.la \ + $(top_builddir)/lib/gui/libgui_C.la \ + $(top_builddir)/lib/common/libcommon_C.la \ + $(GTK_LIBS) $(GTKGLEXT_LIBS) $(GLADE_LIBS) $(EXPAT_LIBS) diff --git a/cmd/smyrna/draw.c b/cmd/smyrna/draw.c new file mode 100755 index 000000000..6782bda06 --- /dev/null +++ b/cmd/smyrna/draw.c @@ -0,0 +1,629 @@ +/* $Id$ $Revision$ */ +/* vim:set shiftwidth=4 ts=8: */ + +/********************************************************** +* This software is part of the graphviz package * +* http://www.graphviz.org/ * +* * +* Copyright (c) 1994-2004 AT&T Corp. * +* and is licensed under the * +* Common Public License, Version 1.0 * +* by AT&T Corp. * +* * +* Information and Software Systems Research * +* AT&T Research, Florham Park NJ * +**********************************************************/ + +/* + +XDOT DRAWING FUNCTIONS, maybe need to move them somewhere else + for now keep them at the bottom +*/ +#include "draw.h" +#include "topview.h" +//delta values +static float dx=0.0; +static float dy=0.0; + + +GLubyte rasters [24]={ + 0xc0,0x00,0xc0,0x00,0xc0,0x00,0xc0,0x00,0xc0,0x00,0xff,0x00,0xff,0x00, + 0xc0,0x00,0xc0,0x00,0xc0,0x00,0xff,0xc0,0xff,0xc0}; + + +void DrawBezier(GLfloat* xp,GLfloat* yp,GLfloat* zp, int filled,int param) +{ + /*copied from NEHE */ + //Written by: David Nikdel ( ogapo@ithink.net ) + // + + // Control points (substitute these values with your own if you like) + double Ax = xp[0]; double Ay = yp[0]; double Az = zp[0]; + double Bx = xp[1]; double By = yp[1]; double Bz = zp[1]; + double Cx = xp[2]; double Cy = yp[2]; double Cz = zp[2]; + double Dx = xp[3]; double Dy = yp[3]; double Dz = zp[3]; + double X; + double Y; + double Z; + int i = 0;//loop index + // Variable + double a = 1.0; + double b = 1.0 - a; + // Tell OGL to start drawing a line strip + glLineWidth(view.LineWidth); + if (!filled) + { + + if (param==0) + glColor4f(view.penColor.R,view.penColor.G,view.penColor.B,view.penColor.A); + if (param==1) //selected + glColor4f(view.selectColor.R,view.selectColor.G,view.selectColor.B,view.selectColor.A); + + glBegin(GL_LINE_STRIP); + } + else + { + if (param==0) + glColor4f(view.fillColor.R,view.fillColor.G,view.fillColor.B,view.penColor.A); + if (param==1) //selected + glColor4f(view.selectColor.R,view.selectColor.G,view.selectColor.B,view.selectColor.A); + glBegin(GL_POLYGON); + } + /* We will not actually draw a curve, but we will divide the curve into small + points and draw a line between each point. If the points are close enough, it + will appear as a curved line. 20 points are plenty, and since the variable goes + from 1.0 to 0.0 we must change it by 1/20 = 0.05 each time */ + for(i = 0; i <= 20; i++) + { + // Get a point on the curve + X = Ax*a*a*a + Bx*3*a*a*b + Cx*3*a*b*b + Dx*b*b*b; + Y = Ay*a*a*a + By*3*a*a*b + Cy*3*a*b*b + Dy*b*b*b; + Z = Az*a*a*a + Bz*3*a*a*b + Cz*3*a*b*b + Dz*b*b*b; + // Draw the line from point to point (assuming OGL is set up properly) + glVertex3d(X, Y, Z); + // Change the variable + a -= 0.05; + b = 1.0 - a; + } +// Tell OGL to stop drawing the line strip + glEnd(); +} + +void DrawBeziers(xdot_op* op,int param) +{ + //SEND ALL CONTROL POINTS IN 3D ARRAYS + + GLfloat tempX[4]; + GLfloat tempY[4]; + GLfloat tempZ[4]; + int temp=0; + int filled; + int i=0; + float spline_kts=0; + SelectBeziers(op); + relocate_spline(op,param); + if(op->kind == xd_filled_bezier) + filled=1; + else + filled=0; + + for (i=0;i < op->u.bezier.cnt ; i= i + 1) + { + if (temp==4) + { + DrawBezier(tempX,tempY,tempZ,filled,param); + tempX[0]=op->u.bezier.pts[i-1].x; + tempY[0]=op->u.bezier.pts[i-1].y; + tempZ[0]=op->u.bezier.pts[i-1].z; + temp=1; + tempX[temp]=op->u.bezier.pts[i].x; + tempY[temp]=op->u.bezier.pts[i].y; + tempZ[temp]=op->u.bezier.pts[i].z; + temp=temp+1; + } + else + { + tempX[temp]=op->u.bezier.pts[i].x; + tempY[temp]=op->u.bezier.pts[i].y; + tempZ[temp]=op->u.bezier.pts[i].z; + temp=temp+1; + } + } + DrawBezier(tempX,tempY,tempZ,filled,param); +} + +//function to load .raw files +void load_raw_texture ( char *file_name, int width, int height, int depth, GLenum colour_type, GLenum filter_type ) +{ + //Line 3 creates a pointer to an (as yet unallocated) array of gl unsigned bytes - + //this will store our image until we've passed it to opengl. Line 4 stores the file pointer, don't worry about that. + GLubyte *raw_bitmap ; + FILE *file; + + //The if statement from line 6-10 opens the file and reports an error if it doesn't exist. + + if ((file = fopen(file_name, "rb"))==NULL) + { + printf("File Not Found : %s\n",file_name); + exit (1); + } + + //Line 11 allocates the correct number of bytes for the size and depth of the image. Remember, our image depth will usually be 3 -- one 'channel' each for red, green and blue values. + //Lines 13-18 check if the memory was allocated correctly and quit the program if there was a problem. + + raw_bitmap = (GLubyte *) malloc ( width * height * depth * ( sizeof ( GLubyte )) ); + + if ( raw_bitmap == NULL ) + { + printf ( "Cannot allocate memory for texture\n" ); + fclose ( file ); + exit ( 1 ); + } + + //Line 19 reads the required number of bytes from the file and places them into our glubyte array. Line 20 closes the close as it isn't required anymore. + fread ( raw_bitmap , width * height * depth, 1 , file ); + fclose ( file); + + //Lines 22-25 set the texture's mapping type and environment settings. GL_TEXTURE_MAG_FILTER and GL_TEXTURE_MIN_FILTER are enumerands that let us change the way in which opengl magnifies and minifies the texture. If we passed GL_LINEAR to the function, our texture would be interpolated using bilinear filtering (in other words, it'd appear smoothed). If we passed GL_NEAREST then no smoothing would occur. By passing GL_MODULATE to the texture environment function, we tell opengl to blend the texture with the base colour of the object. Had we specified GL_DECAL or GL_REPLACE then the base colour (and therefore our lighting effect) would be replaced purely with the colours of the texture. + glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_type ); + glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_type ); + + glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + + //Line 27 passes the image to opengl using the function gluBuild2DMipmaps. + //Read a graphics book for a description of mipmaps. + //This function will also resize the texture map if it doesn't conform + //to the opengl restriction of height and width values being a power of 2. + gluBuild2DMipmaps ( GL_TEXTURE_2D, colour_type, width, height, colour_type, GL_UNSIGNED_BYTE, raw_bitmap ); + + //We don't need our texture in the temporary array anymore as it has been passed to opengl. + //We use the standard C library call 'free' to return the allocated memory. + free ( raw_bitmap ); +} + +//loads texture from bitmap files, bmp +//hopefully +int load_bitmap(char *filename) +{ +#ifdef _WIN32 + unsigned char *l_texture; + int i, j=0; + FILE *l_file; + BITMAPFILEHEADER fileheader; + BITMAPINFOHEADER infoheader; + RGBTRIPLE rgb; + l_file = fopen(filename, "r"); + if(l_file==NULL) + { + printf("file could not be loaded!.\n"); + return (-1); + } + fread(&fileheader, sizeof(fileheader), 1, l_file); + fseek(l_file, sizeof(fileheader), SEEK_SET); + fread(&infoheader, sizeof(infoheader), 1, l_file); + l_texture = (GLubyte *) malloc(infoheader.biWidth * infoheader.biHeight * 4); + memset(l_texture, 0, infoheader.biWidth * infoheader.biHeight * 4); + for (i=0; i < infoheader.biWidth*infoheader.biHeight; i++) + { + fread(&rgb, sizeof(rgb), 1, l_file); + l_texture[j+0] = rgb.rgbtRed; // Red component + l_texture[j+1] = rgb.rgbtRed; // Green component + l_texture[j+2] = rgb.rgbtBlue; // Blue component + l_texture[j+3] = 255; // Alpha value + j += 4; // Go to the next position + } + glBindTexture(GL_TEXTURE_2D, view.font_texture_count); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_REPEAT ); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glTexImage2D(GL_TEXTURE_2D, 0, 4, infoheader.biWidth, infoheader.biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, l_texture); + gluBuild2DMipmaps(GL_TEXTURE_2D, 4, infoheader.biWidth, infoheader.biHeight, GL_RGBA, GL_UNSIGNED_BYTE, l_texture); + free(l_texture); + return (view.font_texture_count); +#else + return 0; +#endif +} + +//Draws a ellpise made out of points. +//void DrawEllipse(xdot_point* xpoint,GLfloat xradius, GLfloat yradius,int filled) +void DrawEllipse(xdot_op* op,int param) +//void DrawEllipse(GLfloat x,GLfloat y,GLfloat xradius, GLfloat yradius,int filled) +{ + //if xradius and yradius are same values, output is circle + GLfloat x,y,xradius,yradius; + int i=0; + int filled; + set_options(op,param); + x=op->u.ellipse.x-dx; + y=op->u.ellipse.y-dy; + xradius=(GLfloat)op->u.ellipse.w; + yradius=(GLfloat)op->u.ellipse.h; + SelectEllipse(op); + if(op->kind == xd_filled_ellipse) + { + if (param==0) + glColor4f(view.fillColor.R,view.fillColor.G,view.fillColor.B,view.fillColor.A); + if (param==1) //selected + glColor4f(view.selectColor.R,view.selectColor.G,view.selectColor.B,view.selectColor.A); + + filled=1; + } + else + { + if (param==0) + glColor4f(view.penColor.R,view.penColor.G,view.penColor.B,view.penColor.A); + if (param==1) //selected + glColor4f(view.selectColor.R,view.selectColor.G,view.selectColor.B,view.selectColor.A); + + filled=0; + } + + glLineWidth(view.LineWidth); + if (!filled) + glBegin(GL_LINE_LOOP); + else + glBegin(GL_POLYGON); + for (i=0; i < 360; i=i+1) + { + //convert degrees into radians + float degInRad = i*DEG2RAD; + glVertex2f(x+cos(degInRad)*xradius,y+sin(degInRad)*yradius); + } + glEnd(); +} + +void DrawPolygon(xdot_op* op,int param) +//void DrawPolygon(xdot_point* xpoint,int count, int filled) +{ + int i=0; + int filled; + int select=0; + SelectPolygon(op); + set_options(op,param); + + if(op->kind == xd_filled_polygon) + { + if(param==0) + glColor4f(view.fillColor.R,view.fillColor.G,view.fillColor.B,view.fillColor.A); + if (param==1) //selected + glColor4f(view.selectColor.R,view.selectColor.G,view.selectColor.B,view.selectColor.A); + + filled=1; + } + else + { + filled=0; + if(param==0) + glColor4f(view.penColor.R,view.penColor.G,view.penColor.B,view.penColor.A); + if (param==1) //selected + glColor4f(view.selectColor.R,view.selectColor.G,view.selectColor.B,view.selectColor.A); + + } + glLineWidth(view.LineWidth); + if (!filled) + glBegin(GL_LINE_STRIP); + else + glBegin(GL_POLYGON); + for (i=0;i < op->u.polygon.cnt ; i=i+1) + { + glVertex3f(op->u.polygon.pts[i].x-dx,op->u.polygon.pts[i].y-dy,op->u.polygon.pts[i].z); + } + glVertex3f(op->u.polygon.pts[0].x-dx,op->u.polygon.pts[0].y-dy,op->u.polygon.pts[0].z); //close the polygon + glEnd(); +} + +void DrawPolyline(xdot_op* op,int param) +{ + int i=0; + int select=0; + if(param==0) + glColor4f(view.penColor.R,view.penColor.G,view.penColor.B,view.penColor.A); + if (param==1) //selected + glColor4f(view.selectColor.R,view.selectColor.G,view.selectColor.B,view.selectColor.A); + SelectPolyline(op); + set_options(op,param); + glLineWidth(view.LineWidth); + glBegin(GL_LINE_STRIP); + for (i=0;i < op->u.polyline.cnt ; i=i+1) + { + glVertex3f(op->u.polyline.pts[i].x-dx,op->u.polyline.pts[i].y-dy,op->u.polyline.pts[i].z); + } + glEnd(); +} + +void DrawBitmap(GLfloat bmpX,GLfloat bmpY,GLfloat bmpW,GLfloat bmpH) +{ + if(view.texture) + glEnable( GL_TEXTURE_2D ); + else + glDisable( GL_TEXTURE_2D ); +/* glRasterPos2d(bmpX,bmpY); + glBitmap( bmpW,bmpH,0.0,0.0,0.0,0.0, 1); */ + glBegin( GL_QUADS ); + glTexCoord2d(bmpX,bmpY); glVertex2d(bmpX,bmpY); + glTexCoord2d(bmpX+bmpW,bmpY); glVertex2d(bmpX+bmpW,bmpY); + glTexCoord2d(bmpX+bmpW,bmpY+bmpH); glVertex2d(bmpX+bmpW,bmpY+bmpH); + glTexCoord2d(bmpX,bmpY+bmpH); glVertex2d(bmpX,bmpY+bmpH); + glEnd(); + glDisable( GL_TEXTURE_2D ); +} + +void SetFillColor(xdot_op* op,int param) +{ + RGBColor c; + c=GetRGBColor(op->u.color); + view.fillColor.R=c.R; + view.fillColor.G=c.G; + view.fillColor.B=c.B; + view.fillColor.A=c.A; +} +void SetPenColor(xdot_op* op,int param) +{ + RGBColor c; + c=GetRGBColor(op->u.color); + view.penColor.R=c.R; + view.penColor.G=c.G; + view.penColor.B=c.B; + view.penColor.A=c.A; +} + +void SetStyle(xdot_op* op,int param) +{ + + +} + +void SetFont(xdot_op* op,int param) +{ +// view.FontName=ABSet(op->u.font.name); + view.FontSize=op->u.font.size; +} + +void InsertImage(xdot_op* op,int param) +{ + SelectImage(op); + +} +void EmbedText(xdot_op* op,int param) +{ + GLfloat x; + SelectText(op); + set_options(op,param); + if (op->u.text.align == 1) + x=op->u.text.x-op->u.text.width/2; + if (op->u.text.align == 0) + x=op->u.text.x; + if (op->u.text.align == -1) + x=op->u.text.x+op->u.text.width; + fontSize (view.FontSize); + if(param==0) + fontColor (view.penColor.R,view.penColor.G,view.penColor.B); + if (param==1) //selected + fontColor (view.selectColor.R,view.selectColor.G,view.selectColor.B); + + fontDrawString (x-dx,op->u.text.y-dy,op->u.text.text,op->u.text.width); +} + + +void draw_selection_box() +{ + if(view.mouse.mouse_down==1) //rectangle selection + { + glColor4f(view.Selection.SelectionColor.R,view.Selection.SelectionColor.G,view.Selection.SelectionColor.B,view.Selection.SelectionColor.A); + if(view.mouse.mouse_mode==5) + { + glEnable(GL_LINE_STIPPLE); + glLineStipple(1,15); + } + glBegin(GL_LINE_STRIP); + glVertex3f(view.GLx,view.GLy,0.001); + glVertex3f(view.GLx,view.GLy2,0.001); + glVertex3f(view.GLx2,view.GLy2,0.001); + glVertex3f(view.GLx2,view.GLy,0.001); + glVertex3f(view.GLx,view.GLy,0.001); + glEnd(); + if(view.mouse.mouse_mode==5) + glDisable(GL_LINE_STIPPLE); + + } +} + +void set_options(xdot_op* op,int param) +{ + + if ((param==1) && (view.mouse.mouse_mode==10) && (view.mouse.mouse_down==1)) //selected, if there is move move it, experimental + { + dx=view.GLx-view.GLx2; + dy=view.GLy-view.GLy2; + } + else + { + dx=0; + dy=0; + } + +} +void relocate_spline(xdot_op* op,int param) +{ + Agedge_t* e; + Agnode_t* tn; //tail node + Agnode_t* hn; //head node + int i=0; + if( AGTYPE(((xdot*)(op->parentxdot))->obj )==AGEDGE) + { + e=((xdot*)(op->parentxdot))->obj; + tn=agtail(e); + hn=aghead(e); + if ( (((custom_object_data*)AGDATA(hn))->Selected==1)&&(((custom_object_data*)AGDATA(tn))->Selected==0)) + { + set_options(op,1); + for (i=1;i < op->u.bezier.cnt-1 ; i= i + 1) + { + if((dx != 0) || (dy != 0)) + { + op->u.bezier.pts[i].x=op->u.bezier.pts[i].x-(dx*(float)i/(float)(op->u.bezier.cnt)); + op->u.bezier.pts[i].y=op->u.bezier.pts[i].y-(dy*(float)i/(float)(op->u.bezier.cnt)); + } + } + if((dx != 0) || (dy != 0)) + { + op->u.bezier.pts[op->u.bezier.cnt-1].x=op->u.bezier.pts[op->u.bezier.cnt-1].x-dx; + op->u.bezier.pts[op->u.bezier.cnt-1].y=op->u.bezier.pts[op->u.bezier.cnt-1].y-dy; + } + } + if ( (((custom_object_data*)AGDATA(hn))->Selected==0)&&(((custom_object_data*)AGDATA(tn))->Selected==1)) + { + set_options(op,1); + for ( i=op->u.bezier.cnt-1; i>0 ; i= i -1 ) + { + if((dx != 0) || (dy != 0)) + { + op->u.bezier.pts[i].x=op->u.bezier.pts[i].x-(dx*(float)(op->u.bezier.cnt-i)/(float)(op->u.bezier.cnt)); + op->u.bezier.pts[i].y=op->u.bezier.pts[i].y-(dy*(float)(op->u.bezier.cnt-i)/(float)(op->u.bezier.cnt)); + } + } + if((dx != 0) || (dy != 0)) + { + op->u.bezier.pts[0].x=op->u.bezier.pts[0].x-dx; + op->u.bezier.pts[0].y=op->u.bezier.pts[0].y-dy; + } + } + + if ( (((custom_object_data*)AGDATA(hn))->Selected==1)&&(((custom_object_data*)AGDATA(tn))->Selected==1)) + { + set_options(op,1); + for (i=0;i < op->u.bezier.cnt ; i= i + 1) + { + if((dx != 0) || (dy != 0)) + { + op->u.bezier.pts[i].x=op->u.bezier.pts[i].x-dx; + op->u.bezier.pts[i].y=op->u.bezier.pts[i].y-dy; + } + } + } + } + + + +} + +void draw_letter(GLfloat x,GLfloat y,char c) +{ + glRasterPos2i((int)x,(int)y); + glBitmap(10,12,0.0,0.0,0.0,0.0,rasters); +} +int font_display_list() +{ + int a; + a=glGenLists(6); + //draw 5 Fs + glNewList(a,GL_COMPILE); + draw_letter(0,0,0); + draw_letter(0,0,0); + draw_letter(0,0,0); + draw_letter(0,0,0); + draw_letter(0,0,0); + draw_letter(0,0,0); + glEndList(); + return a; +} +void draw_cached_letter(GLfloat x,GLfloat y,int letter) +{ +/* glPushMatrix(); + glTranslatef (view.panx+x,view.pany+y,view.zoom); + glCallList (view.fontbase+letter-1); + glPopMatrix(); */ + +} +void draw_magnifier() +{ + + if((view.mouse.mouse_mode==MM_MAGNIFIER) && (view.mouse.mouse_down)) + { + + GLfloat mg_x,mg_y,mg_z,mg_width,mg_height; + float a; + int winX,winY,winW,winH; + //converting screen pixel distaances to GL distances + view.mg.GLwidth=GetOGLDistance(view.mg.width)/2.0; + view.mg.GLheight=GetOGLDistance(view.mg.height)/2.0; + GetOGLPosRef(view.mouse.mouse_X,view.mouse.mouse_Y,&mg_x,&mg_y,&mg_z);//retrieving mouse coords as GL coordinates + view.mg.x=mg_x; + view.mg.y=mg_y; + glLineWidth(4); + local_zoom(&Topview); + //drawing the magnifier borders + glBegin(GL_LINE_STRIP); + glColor4f(0.3,0.1,0.8,1); + glVertex3f(view.mg.x-view.mg.GLwidth,view.mg.y-view.mg.GLheight,0.0); + glVertex3f(view.mg.x+view.mg.GLwidth,view.mg.y-view.mg.GLheight,0.0); + glVertex3f(view.mg.x+view.mg.GLwidth,view.mg.y+view.mg.GLheight,0.0); + glVertex3f(view.mg.x-view.mg.GLwidth,view.mg.y+view.mg.GLheight,0.0); + glVertex3f(view.mg.x-view.mg.GLwidth,view.mg.y-view.mg.GLheight,0.0); + glEnd(); + + glLineWidth(1); + } + +} + + + +void draw_fisheye_magnifier() +{ + if((view.mouse.mouse_mode==21) && (view.mouse.mouse_down)) + { + float a; + GLfloat mg_x,mg_y,mg_z,mg_width,mg_height; + a=GetOGLDistance(250); + view.fmg.R=a; + GetOGLPosRef(view.mouse.mouse_X,view.mouse.mouse_Y,&mg_x,&mg_y,&mg_z); + glColor4f(0.3,0.1,0.8,1); + if ((view.fmg.x != mg_x) || (view.fmg.y != mg_y)) + { + fisheye_polar(mg_x, mg_y,&Topview); + draw_circle(mg_x,mg_y,a); + } + view.fmg.x=mg_x; + view.fmg.y=mg_y; + + } +} + + +void draw_circle(float originX,float originY,float radius) +{ +/* draw a circle from a bunch of short lines */ + float vectorX1,vectorY1,vectorX,vectorY,angle; + vectorY1=originY+radius; + vectorX1=originX; + glLineWidth(4); + glBegin(GL_LINE_STRIP); + for(angle=0.0f;angle<=(2.1f*3.14159);angle+=0.1f) + { + vectorX=originX+(radius*(float)sin((double)angle)); + vectorY=originY+(radius*(float)cos((double)angle)); + glVertex2d(vectorX1,vectorY1); + vectorY1=vectorY; + vectorX1=vectorX; + } + glEnd(); + glLineWidth(1); + +} + +int point_within_ellips_with_coords(float ex,float ey,float ea,float eb,float px,float py) +{ + + float dx,dy; + float a; + dx = px - ex; + dy = py - ey; + a=(dx*dx)/(ea*ea) + (dy*dy)/(eb*eb); + return (a <= 1); +} + + diff --git a/cmd/smyrna/draw.h b/cmd/smyrna/draw.h new file mode 100755 index 000000000..c30ac8b45 --- /dev/null +++ b/cmd/smyrna/draw.h @@ -0,0 +1,66 @@ +/* $Id$ $Revision$ */ +/* vim:set shiftwidth=4 ts=8: */ + +/********************************************************** +* This software is part of the graphviz package * +* http://www.graphviz.org/ * +* * +* Copyright (c) 1994-2004 AT&T Corp. * +* and is licensed under the * +* Common Public License, Version 1.0 * +* by AT&T Corp. * +* * +* Information and Software Systems Research * +* AT&T Research, Florham Park NJ * +**********************************************************/ + +#ifndef DRAW_H +#define DRAW_H +#include "viewport.h" +#include +#include +#include +#include +#include + +//#include "xdot.h" + +#define ANGLE 30.0 +/* tan (ANGLE * PI / 180.0) */ +#define TANGENT 0.57735 + +#define TEXT_Z_NEAR 2.0 +#define TEXT_Z_FAR 0.0 +#define TEXT_Z_DIFF 0.005 + +static GLfloat text_z = TEXT_Z_NEAR; +static const char *text = "ABCD adasd"; +static PangoContext *ft2_context=NULL; + +//DRAWING FUNCTIONS +void DrawBezier(GLfloat* xp,GLfloat* yp,GLfloat* zp, int filled, int param); +void DrawBeziers(xdot_op* op,int param); +void DrawEllipse(xdot_op* op,int param); +void DrawPolygon(xdot_op* op,int param); +void DrawPolyline(xdot_op* op,int param); +void DrawBitmap(GLfloat bmpX,GLfloat bmpY,GLfloat bmpW,GLfloat bmpH); +void SetFillColor(xdot_op* op,int param); +void SetPenColor(xdot_op* op,int param); +void SetStyle(xdot_op* op,int param); +void SetFont(xdot_op* op,int param); +void EmbedText(xdot_op* op,int param); +void InsertImage(xdot_op* op,int param); +void load_raw_texture ( char *file_name, int width, int height, int depth, GLenum colour_type, GLenum filter_type ); //function to load .raw files +int load_bitmap(char *filename); +void draw_selection_box(); +void set_options(xdot_op*,int param); +void relocate_spline(xdot_op*,int param); +void draw_letter(GLfloat x,GLfloat y,char c); +int font_display_list(); +void draw_cached_letter(GLfloat x,GLfloat y,int letter); +void draw_magnifier(); +void draw_circle(float originX,float originY,float radius); +void draw_fisheye_magnifier(); +//int point_within_ellipse(float ex,float ey,float ea,float eb,float px,float py); +#endif + diff --git a/cmd/smyrna/glTemplate.c b/cmd/smyrna/glTemplate.c new file mode 100755 index 000000000..ad6f939ed --- /dev/null +++ b/cmd/smyrna/glTemplate.c @@ -0,0 +1,1092 @@ +/* $Id$ $Revision$ */ +/* vim:set shiftwidth=4 ts=8: */ + +/********************************************************** +* This software is part of the graphviz package * +* http://www.graphviz.org/ * +* * +* Copyright (c) 1994-2004 AT&T Corp. * +* and is licensed under the * +* Common Public License, Version 1.0 * +* by AT&T Corp. * +* * +* Information and Software Systems Research * +* AT&T Research, Florham Park NJ * +**********************************************************/ + +#include "gui.h" +#include "glTemplate.h" +#include "viewport.h" +#include "topview.h" + +xdot* testxdot; +GtkWidget *drawing_area; + +static float begin_x = 0.0; +static float begin_y = 0.0; + +static float dx = 0.0; +static float dy = 0.0; +static guint idle_id = 0; +static GLfloat w,h; +void +init_view (void) +{ + view_quat[0] = view_quat_diff[0] = 0.0; + view_quat[1] = view_quat_diff[1] = 0.0; + view_quat[2] = view_quat_diff[2] = 0.0; + view_quat[3] = view_quat_diff[3] = 1.0; + view_scale = 1.0; +} +void +examine_gl_config_attrib (GdkGLConfig *glconfig) +{ + g_print ("\nOpenGL visual configurations :\n\n"); + + g_print ("gdk_gl_config_is_rgba (glconfig) = %s\n", + gdk_gl_config_is_rgba (glconfig) ? "TRUE" : "FALSE"); + g_print ("gdk_gl_config_is_double_buffered (glconfig) = %s\n", + gdk_gl_config_is_double_buffered (glconfig) ? "TRUE" : "FALSE"); + g_print ("gdk_gl_config_is_stereo (glconfig) = %s\n", + gdk_gl_config_is_stereo (glconfig) ? "TRUE" : "FALSE"); + g_print ("gdk_gl_config_has_alpha (glconfig) = %s\n", + gdk_gl_config_has_alpha (glconfig) ? "TRUE" : "FALSE"); + g_print ("gdk_gl_config_has_depth_buffer (glconfig) = %s\n", + gdk_gl_config_has_depth_buffer (glconfig) ? "TRUE" : "FALSE"); + g_print ("gdk_gl_config_has_stencil_buffer (glconfig) = %s\n", + gdk_gl_config_has_stencil_buffer (glconfig) ? "TRUE" : "FALSE"); + g_print ("gdk_gl_config_has_accum_buffer (glconfig) = %s\n", + gdk_gl_config_has_accum_buffer (glconfig) ? "TRUE" : "FALSE"); + + g_print ("\n"); + + print_gl_config_attrib (glconfig, "GDK_GL_USE_GL", GDK_GL_USE_GL, TRUE); + print_gl_config_attrib (glconfig, "GDK_GL_BUFFER_SIZE", GDK_GL_BUFFER_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_LEVEL", GDK_GL_LEVEL, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_RGBA", GDK_GL_RGBA, TRUE); + print_gl_config_attrib (glconfig, "GDK_GL_DOUBLEBUFFER", GDK_GL_DOUBLEBUFFER, TRUE); + print_gl_config_attrib (glconfig, "GDK_GL_STEREO", GDK_GL_STEREO, TRUE); + print_gl_config_attrib (glconfig, "GDK_GL_AUX_BUFFERS", GDK_GL_AUX_BUFFERS, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_RED_SIZE", GDK_GL_RED_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_GREEN_SIZE", GDK_GL_GREEN_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_BLUE_SIZE", GDK_GL_BLUE_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_ALPHA_SIZE", GDK_GL_ALPHA_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_DEPTH_SIZE", GDK_GL_DEPTH_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_STENCIL_SIZE", GDK_GL_STENCIL_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_ACCUM_RED_SIZE", GDK_GL_ACCUM_RED_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_ACCUM_GREEN_SIZE", GDK_GL_ACCUM_GREEN_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_ACCUM_BLUE_SIZE", GDK_GL_ACCUM_BLUE_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_ACCUM_ALPHA_SIZE", GDK_GL_ACCUM_ALPHA_SIZE, FALSE); + + g_print ("\n"); +} + +void +print_gl_config_attrib (GdkGLConfig *glconfig, + const gchar *attrib_str, + int attrib, + gboolean is_boolean) +{ + int value; + + g_print ("%s = ", attrib_str); + if (gdk_gl_config_get_attrib (glconfig, attrib, &value)) + { + if (is_boolean) + g_print ("%s\n", value == TRUE ? "TRUE" : "FALSE"); + else + g_print ("%d\n", value); + } + else + g_print ("*** Cannot get %s attribute value\n", attrib_str); +} + + +static void +realize (GtkWidget *widget, + gpointer data) +{ + GdkGLContext *glcontext = gtk_widget_get_gl_context (widget); + GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget); + + GLfloat ambient[] = {0.0, 0.0, 0.0, 1.0}; + GLfloat diffuse[] = {1.0, 1.0, 1.0, 1.0}; + GLfloat position[] = {0.0, 3.0, 3.0, 0.0}; + + GLfloat lmodel_ambient[] = {0.2, 0.2, 0.2, 1.0}; + GLfloat local_view[] = {0.0}; + GLuint texture; + + + init_viewport(&view); + +// if(add_graph_to_viewport_from_file ("C:/GTK/2.0/bin/awilliams.dot")) +// if(add_graph_to_viewport_from_file ("c:/__tempfileneato.xdot")) + //load default font + // +#ifdef WIN32 +#define SMYRNA_FONT "C:/arial.tga" +// #else +// using -DSMYRNA_FONT from Makefile.am and configure.ac +#endif + + g_print("loading font....%i\n",fontLoad(SMYRNA_FONT)); + + /*** OpenGL BEGIN ***/ + if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) + return; + + glClearColor (view.bgColor.R,view.bgColor.G, view.bgColor.B,view.bgColor.A); //background color + glClearDepth (1.0); + + glLightfv (GL_LIGHT0, GL_AMBIENT, ambient); + glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse); + glLightfv (GL_LIGHT0, GL_POSITION, position); + glLightModelfv (GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + glLightModelfv (GL_LIGHT_MODEL_LOCAL_VIEWER, local_view); + + glFrontFace (GL_CW); + // glEnable (GL_LIGHTING); +// glEnable (GL_LIGHT0); + glEnable (GL_AUTO_NORMAL); + glEnable (GL_NORMALIZE); + glEnable (GL_DEPTH_TEST); + glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDepthFunc (GL_LESS); + + gdk_gl_drawable_gl_end (gldrawable); + /*** OpenGL END ***/ +//create fonts + return; +} + +static gboolean +configure_event (GtkWidget *widget, + GdkEventConfigure *event, + gpointer data) +{ + + GLfloat x,y,z; + int vPort[4]; + float aspect; + int id; + + +GdkGLContext *glcontext = gtk_widget_get_gl_context (widget); + GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget); + + + w = widget->allocation.width; + h = widget->allocation.height; + + + /*** OpenGL BEGIN ***/ + if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) + return FALSE; + + glViewport (0, 0, w, h); + + /* get current viewport */ + glGetIntegerv (GL_VIEWPORT, vPort); + /* setup various opengl things that we need */ + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + if (w > h) + { + aspect = w / h; + glFrustum (-aspect*100, aspect*100, -100.0, 100.0, 1 ,90); +// glFrustum (-aspect, aspect, -1.0, 1.0, 5.0, 90.0); +// glOrtho(-aspect*100, aspect*100, -100.0, 100.0, 5, 90); + + } + else + { + aspect = h / w; + glFrustum (-100.0, 100.0, -aspect*100, aspect*100,1, 90); +// glFrustum (-1.0, 1.0, -aspect, aspect, 5.0, 90.0); +// glOrtho(-100.0, 100.0, -aspect*100, aspect*100,5, 90); + } + + glMatrixMode (GL_MODELVIEW); + gdk_gl_drawable_gl_end (gldrawable); + + /*** OpenGL END ***/ + + + return TRUE; +} + + +static GLuint id_text=NULL; + +gboolean +expose_event (GtkWidget *widget, + GdkEventExpose *event, + gpointer data) +{ + GdkGLContext *glcontext = gtk_widget_get_gl_context (widget); + GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget); + xdot* xDot; + GLfloat x,y,z; + GLfloat m[4][4]; + + + + /*** OpenGL BEGIN ***/ + if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) + return FALSE; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glLoadIdentity (); + + /* View transformation. */ + //0 center for x -> for y to up +// glTranslatef (view.panx,view.pany,-20); +// glTranslatef (1,1,view.zoom/5); + gluLookAt(view.panx,view.pany,view.zoom*-1,view.panx,view.pany,0.0,0.0,1.0,0.0); + +// glScalef (view.zoom/2,view.zoom/2,view.zoom/2*-1); + +// add_quats (view_quat_diff, view_quat, view_quat); +// build_rotmatrix (m, view_quat); +// glMultMatrixf (&m[0][0]); + +//update view clip region values + GetOGLPosRef(1,(int)h-5,&view.clipX1,&view.clipY1,&view.clipZ1); + GetOGLPosRef((int)w-1,1,&view.clipX2,&view.clipY2,&view.clipZ2); + DrawView(); + if(((view.mouse.mouse_mode==4) || (view.mouse.mouse_mode==5))&& view.mouse.mouse_down) + draw_selection_box(); + +/* if((view.mouse_mode==10) && view.mousedown) + move_nodes(view.g[view.activeGraph],view.GLx2-view.GLx,view.GLy2-view.GLy); //move selected nodes*/ + + + + //drawing grids + if(view.gridVisible) + { + glPointSize (1); + glBegin(GL_POINTS); + glColor4f(view.grR,view.grG,view.grB,view.grA); + for (x=view.bdxLeft; x <= view.bdxRight;x=x +view.gridSize) + { + for (y=view.bdyBottom; y <=view.bdyTop ;y=y +view.gridSize) + { + glVertex3f(x,y,0); + } + } + glEnd(); + } + draw_fisheye_magnifier(); + draw_magnifier(); + /* Swap buffers */ +if (gdk_gl_drawable_is_double_buffered (gldrawable)) + gdk_gl_drawable_swap_buffers (gldrawable); + else + glFlush (); + gdk_gl_drawable_gl_end (gldrawable); + /*** OpenGL END ***/ + return TRUE; +} +static gboolean +button_press_event (GtkWidget *widget, + GdkEventButton *event, + gpointer data) +{ + if (animate) + { + if (event->button == 1) + toggle_animation (widget); + } + else + { + view_quat_diff[0] = 0.0; + view_quat_diff[1] = 0.0; + view_quat_diff[2] = 0.0; + view_quat_diff[3] = 1.0; + } + + + begin_x = event->x; + begin_y = event->y; + + + if(event->button==1) + { + view.mouse.mouse_down=1; + if(GetOGLPos(begin_x,begin_y)) + { + if (view.mouse.mouse_mode == MM_SINGLE_SELECT) //single select + { + view.Selection.Active=1; + view.Selection.Type=0; + view.Selection.AlreadySelected=0; + view.Selection.X=view.GLx-SINGLE_SELECTION_WIDTH/2; + view.Selection.Y=view.GLy-SINGLE_SELECTION_WIDTH/2; + view.Selection.W=SINGLE_SELECTION_WIDTH; + view.Selection.H=SINGLE_SELECTION_WIDTH; + expose_event (drawing_area,NULL,NULL); + } + view.prevpanx=view.panx; + view.prevpany=view.pany; + } + } + return FALSE; +} + +static gboolean +button_release_event (GtkWidget *widget, + GdkEventButton *event, + gpointer data) +{ + + if(event->button==1) //left click release + { + view.mouse.mouse_down=0; + if (view.mouse.mouse_mode==MM_PAN) //pan + { +/* view.panx=view.prevpanx-(view.GLx2-view.GLx); + view.pany=view.prevpany-(view.GLy2-view.GLy); + expose_event (drawing_area,NULL,NULL);*/ + } + + + if ((view.mouse.mouse_mode==MM_RECTANGULAR_SELECT)||(view.mouse.mouse_mode==MM_RECTANGULAR_X_SELECT)) + { + if (view.GLx <= view.GLx2) + view.Selection.X=view.GLx; + else + view.Selection.X=view.GLx2; + if(view.GLy <= view.GLy2) + view.Selection.Y=view.GLy; + else + view.Selection.Y=view.GLy2; + + view.Selection.W=view.GLx2-view.GLx; + if(view.Selection.W < 0) + view.Selection.W=view.Selection.W*-1; + view.Selection.H=view.GLy2-view.GLy; + if(view.Selection.H < 0) + view.Selection.H=view.Selection.H*-1; + if(view.mouse.mouse_mode==4) + view.Selection.Type=1; + else + view.Selection.Type=2; + view.Selection.Active=1; + expose_event (drawing_area,NULL,NULL); + } + if (view.mouse.mouse_mode==MM_MOVE) + { + if(((custom_graph_data*)AGDATA(view.g[view.activeGraph]))->TopView == 0) + move_nodes(view.g[view.activeGraph]); + else + move_TVnodes(); + + } + if ((view.mouse.mouse_mode==MM_FISHEYE_MAGNIFIER)||(view.mouse.mouse_mode==MM_MAGNIFIER)) //fisheye mag mouse release, stop distortion + { + originate_distorded_coordinates(&Topview); + expose_event (drawing_area,NULL,NULL); + } + } + dx = 0.0; + dy = 0.0; + return FALSE; +} + +static gboolean +motion_notify_event (GtkWidget *widget, + GdkEventMotion *event, + gpointer data) +{ + float w = widget->allocation.width; + float h = widget->allocation.height; + float x = event->x; + float y = event->y; + + gboolean redraw = FALSE; + + + + dx = x - begin_x; + dy = y - begin_y; + //panning + if ((event->state & GDK_BUTTON1_MASK) && (view.mouse.mouse_mode==MM_PAN)) + { + +// GetFixedOGLPos((int)x,(int)y,view.GLDepth); +// view.panx=view.prevpanx-(view.GLx2-view.GLx); +// view.pany=view.prevpany-(view.GLy2-view.GLy); + view.panx=view.panx-dx*pow(view.zoom*-1,(1/1)); + view.pany=view.pany+dy*pow(view.zoom*-1,(1/1)); + redraw = TRUE; + } + //zooming + if ((event->state & GDK_BUTTON1_MASK) && (view.mouse.mouse_mode==MM_ZOOM)) + { + view.zoom=view.zoom+dx/10*(view.zoom*-1/20); + if(view.zoom > MAX_ZOOM) + view.zoom=MAX_ZOOM; + if(view.zoom < MIN_ZOOM) + view.zoom=MIN_ZOOM; + redraw = TRUE; + + } + + + /* Rotation. */ + if ((event->state & GDK_BUTTON1_MASK) && (view.mouse.mouse_mode==MM_ROTATE)) + { + trackball (view_quat_diff, + (2.0 * begin_x - w) / w, + (h - 2.0 * begin_y) / h, + (2.0 * x - w) / w, + (h - 2.0 * y) / h); + + + redraw = TRUE; + } + + /* Scaling. */ + if (event->state & GDK_BUTTON2_MASK) + { + view_scale = view_scale * (1.0 + (y - begin_y) / h); + if (view_scale > VIEW_SCALE_MAX) + view_scale = VIEW_SCALE_MAX; + else if (view_scale < VIEW_SCALE_MIN) + view_scale = VIEW_SCALE_MIN; + + redraw = TRUE; + } + /*selection rect*/ + if ((event->state & GDK_BUTTON1_MASK) && ((view.mouse.mouse_mode==MM_RECTANGULAR_SELECT)||(view.mouse.mouse_mode==5))) + { + GetFixedOGLPos((int)x,(int)y,view.GLDepth); + redraw = TRUE; + } + if ((event->state & GDK_BUTTON1_MASK) && (view.mouse.mouse_mode==MM_MOVE)) + { + GetFixedOGLPos((int)x,(int)y,view.GLDepth); + redraw = TRUE; + } + if ((event->state & GDK_BUTTON1_MASK) && ((view.mouse.mouse_mode==MM_MAGNIFIER) + ||(view.mouse.mouse_mode==MM_FISHEYE_MAGNIFIER) )) + { + view.mouse.mouse_X=x; + view.mouse.mouse_Y=y; + redraw = TRUE; + } + + + begin_x = x; + begin_y = y; + + + if (redraw && !animate) + gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE); + return TRUE; +} + +static gboolean +key_press_event (GtkWidget *widget, + GdkEventKey *event, + gpointer data) +{ + switch (event->keyval) + { + case GDK_Escape: + gtk_main_quit (); + break; + + default: + return FALSE; + } + + return TRUE; +} + +static gboolean +idle (GtkWidget *widget) +{ + /* Invalidate the whole window. */ + gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE); + + /* Update synchronously. */ + gdk_window_process_updates (widget->window, FALSE); + + return TRUE; +} + +static void +idle_add (GtkWidget *widget) +{ + if (idle_id == 0) + { + idle_id = g_idle_add_full (GDK_PRIORITY_REDRAW, + (GSourceFunc) idle, + widget, + NULL); + } +} + +static void +idle_remove (GtkWidget *widget) +{ + if (idle_id != 0) + { + g_source_remove (idle_id); + idle_id = 0; + } +} + + + + +static gboolean +map_event (GtkWidget *widget, + GdkEvent *event, + gpointer data) +{ + if (animate) + idle_add (widget); + + return TRUE; +} + +static gboolean +unmap_event (GtkWidget *widget, + GdkEvent *event, + gpointer data) +{ + idle_remove (widget); + + return TRUE; +} + +static gboolean +visibility_notify_event (GtkWidget *widget, + GdkEventVisibility *event, + gpointer data) +{ + if (animate) + { + if (event->state == GDK_VISIBILITY_FULLY_OBSCURED) + idle_remove (widget); + else + idle_add (widget); + } + + return TRUE; +} + +/* Toggle animation.*/ +static void +toggle_animation (GtkWidget *widget) +{ + animate = !animate; + + if (animate) + { + idle_add (widget); + } + else + { + idle_remove (widget); + view_quat_diff[0] = 0.0; + view_quat_diff[1] = 0.0; + view_quat_diff[2] = 0.0; + view_quat_diff[3] = 1.0; + gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE); + } +} + +static void +change_shape (GtkMenuItem *menuitem, + const GLuint *shape) +{ + shape_current = *shape; + init_view (); +} + +static void +change_material (GtkMenuItem *menuitem, + MaterialProp *mat) +{ + mat_current = mat; +} +void +switch_Mouse (GtkMenuItem *menuitem,int mouse_mode) +{ + GdkCursor* cursor; + view.mouse.mouse_mode=mouse_mode; + +} + + +/* For popup menu. */ +static gboolean +button_press_event_popup_menu (GtkWidget *widget, + GdkEventButton *event, + gpointer data) +{ + if (event->button == 3) + { + /* Popup menu. */ + gtk_menu_popup (GTK_MENU (widget), NULL, NULL, NULL, NULL, + event->button, event->time); + return TRUE; + } + + return FALSE; +} + +/* Creates the popup menu.*/ +static GtkWidget * +create_popup_menu (GtkWidget *drawing_area) +{ + GtkWidget *shapes_menu; + GtkWidget *actions_menu; + GtkWidget *editing_menu; + GtkWidget *menu; + GtkWidget *menu_item; + int mm=0; + /*actions sub menu*/ + //PAN + +mm=MM_PAN; + actions_menu = gtk_menu_new (); + menu_item = gtk_menu_item_new_with_label ("Pan"); + gtk_menu_shell_append (GTK_MENU_SHELL (actions_menu), menu_item); + g_signal_connect (G_OBJECT (menu_item), "activate", + G_CALLBACK (switch_Mouse), (gpointer) mm); + gtk_widget_show (menu_item); +/**********/ + //ZOOM + mm=MM_ZOOM; + menu_item = gtk_menu_item_new_with_label ("Zoom"); + gtk_menu_shell_append (GTK_MENU_SHELL (actions_menu), menu_item); + g_signal_connect (G_OBJECT (menu_item), "activate", + G_CALLBACK (switch_Mouse), (gpointer) mm); + gtk_widget_show (menu_item); +/**********/ + //ROTATE + mm=MM_ROTATE; + menu_item = gtk_menu_item_new_with_label ("rotate"); + gtk_menu_shell_append (GTK_MENU_SHELL (actions_menu), menu_item); + g_signal_connect (G_OBJECT (menu_item), "activate", + G_CALLBACK (switch_Mouse), (gpointer) mm); + gtk_widget_show (menu_item); +/**********/ +/**********/ + //Single Select + mm=MM_SINGLE_SELECT; + menu_item = gtk_menu_item_new_with_label ("select"); + gtk_menu_shell_append (GTK_MENU_SHELL (actions_menu), menu_item); + g_signal_connect (G_OBJECT (menu_item), "activate", + G_CALLBACK (switch_Mouse), (gpointer) mm); + gtk_widget_show (menu_item); +/**********/ + //Rectangle Select + mm=MM_RECTANGULAR_SELECT; + menu_item = gtk_menu_item_new_with_label ("rect select"); + gtk_menu_shell_append (GTK_MENU_SHELL (actions_menu), menu_item); + g_signal_connect (G_OBJECT (menu_item), "activate", + G_CALLBACK (switch_Mouse), (gpointer) mm); + gtk_widget_show (menu_item); +/**********/ +/**********/ + //Rectangle -x Select + mm=MM_RECTANGULAR_X_SELECT; + menu_item = gtk_menu_item_new_with_label ("rect-x select"); + gtk_menu_shell_append (GTK_MENU_SHELL (actions_menu), menu_item); + g_signal_connect (G_OBJECT (menu_item), "activate", + G_CALLBACK (switch_Mouse), (gpointer) mm); + gtk_widget_show (menu_item); +/**********/ +/**********/ + //Move + mm=MM_MOVE; + menu_item = gtk_menu_item_new_with_label ("Move"); + gtk_menu_shell_append (GTK_MENU_SHELL (actions_menu), menu_item); + g_signal_connect (G_OBJECT (menu_item), "activate", + G_CALLBACK (switch_Mouse), (gpointer) mm); + gtk_widget_show (menu_item); +/**********/ + //activate magnifier + mm=MM_MAGNIFIER; //magnifier ,fisheye etc starts at 20 + menu_item = gtk_menu_item_new_with_label ("Magnifier"); + gtk_menu_shell_append (GTK_MENU_SHELL (actions_menu), menu_item); + g_signal_connect (G_OBJECT (menu_item), "activate", + G_CALLBACK (switch_Mouse), (gpointer) mm); + gtk_widget_show (menu_item); +/**********/ + //activate fisheye magnifier + mm=MM_FISHEYE_MAGNIFIER; + menu_item = gtk_menu_item_new_with_label ("Fisheye Magnifier"); + gtk_menu_shell_append (GTK_MENU_SHELL (actions_menu), menu_item); + g_signal_connect (G_OBJECT (menu_item), "activate", + G_CALLBACK (switch_Mouse), (gpointer) mm); + gtk_widget_show (menu_item); +/**********/ + editing_menu = gtk_menu_new (); + /* NODE */ + menu_item = gtk_menu_item_new_with_label ("Node"); + gtk_menu_shell_append (GTK_MENU_SHELL (editing_menu), menu_item); + g_signal_connect (G_OBJECT (menu_item), "activate", + G_CALLBACK (change_material), &mat_emerald); + gtk_widget_show (menu_item); + + /* EDGE */ + menu_item = gtk_menu_item_new_with_label ("Edge"); + gtk_menu_shell_append (GTK_MENU_SHELL (editing_menu), menu_item); + g_signal_connect (G_OBJECT (menu_item), "activate", + G_CALLBACK (change_material), &mat_jade); + gtk_widget_show (menu_item); + + + menu = gtk_menu_new (); + + /* Actions */ + menu_item = gtk_menu_item_new_with_label ("Mouse"); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), actions_menu); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); + gtk_widget_show (menu_item); + + /* NEW */ + menu_item = gtk_menu_item_new_with_label ("New"); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), editing_menu); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); + gtk_widget_show (menu_item); + + /* Quit */ + menu_item = gtk_menu_item_new_with_label ("Quit"); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); + g_signal_connect (G_OBJECT (menu_item), "activate", + G_CALLBACK (gtk_main_quit), NULL); + gtk_widget_show (menu_item); + return menu; +} + + + +extern GdkGLConfig * +configure_gl (void) +{ + GdkGLConfig *glconfig; + + /* Try double-buffered visual */ + glconfig = gdk_gl_config_new_by_mode (GDK_GL_MODE_RGB | + GDK_GL_MODE_DEPTH | + GDK_GL_MODE_DOUBLE); + if (glconfig == NULL) + { + g_print ("\n*** Cannot find the double-buffered visual.\n"); + g_print ("\n*** Trying single-buffered visual.\n"); + + /* Try single-buffered visual */ + glconfig = gdk_gl_config_new_by_mode (GDK_GL_MODE_RGB | + GDK_GL_MODE_DEPTH); + if (glconfig == NULL) + { + g_print ("*** No appropriate OpenGL-capable visual found.\n"); + exit (1); + } + } + + return glconfig; +} + + +void create_window (GdkGLConfig *glconfig,GtkWidget* vbox) +{ + gint major, minor; + + GtkWidget *window; + GtkWidget *menu; + GtkWidget *button; + /* + * Query OpenGL extension version. + */ + + gdk_gl_query_version (&major, &minor); + g_print ("\nOpenGL extension version - %d.%d\n", + major, minor); + + /* + * Configure OpenGL-capable visual. + */ + + /* Try double-buffered visual */ + + if (IS_TEST_MODE_ON) //printf some gl values, to test if your system has opengl stuff + examine_gl_config_attrib (glconfig); + /* Drawing area for drawing OpenGL scene. + */ + drawing_area = gtk_drawing_area_new (); + gtk_widget_set_size_request (drawing_area, 300, 300); + /* Set OpenGL-capability to the widget. */ + gtk_widget_set_gl_capability (drawing_area, + glconfig, + NULL, + TRUE, + GDK_GL_RGBA_TYPE); + + gtk_widget_add_events (drawing_area, + GDK_BUTTON1_MOTION_MASK | + GDK_BUTTON2_MOTION_MASK | + GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_VISIBILITY_NOTIFY_MASK); + + g_signal_connect_after (G_OBJECT (drawing_area), "realize", + G_CALLBACK (realize), NULL); + g_signal_connect (G_OBJECT (drawing_area), "configure_event", + G_CALLBACK (configure_event), NULL); + g_signal_connect (G_OBJECT (drawing_area), "expose_event", + G_CALLBACK (expose_event), NULL); + + g_signal_connect (G_OBJECT (drawing_area), "button_press_event", + G_CALLBACK (button_press_event), NULL); + g_signal_connect (G_OBJECT (drawing_area), "button_release_event", + G_CALLBACK (button_release_event), NULL); + g_signal_connect (G_OBJECT (drawing_area), "motion_notify_event", + G_CALLBACK (motion_notify_event), NULL); + + g_signal_connect (G_OBJECT (drawing_area), "map_event", + G_CALLBACK (map_event), NULL); + g_signal_connect (G_OBJECT (drawing_area), "unmap_event", + G_CALLBACK (unmap_event), NULL); + g_signal_connect (G_OBJECT (drawing_area), "visibility_notify_event", + G_CALLBACK (visibility_notify_event), NULL); + + + + + + gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0); + + gtk_widget_show (drawing_area); + + /* + * Popup menu. + */ + + menu = create_popup_menu (drawing_area); + + /* Signal handler */ + g_signal_connect_swapped (G_OBJECT (drawing_area), "button_press_event", + G_CALLBACK (button_press_event_popup_menu), menu); + +} + +//this piece of code returns the opengl coordinates of mouse coordinates +int GetOGLPos(int x, int y) +{ + GLdouble wwinX; + GLdouble wwinY; + GLdouble wwinZ; + + + int ind; + GLdouble depth[5]; + GLdouble raster[5]; + GLint viewport[4]; + GLdouble modelview[16]; + GLdouble projection[16]; + GLfloat winX, winY; + GLfloat winZ[36]; + GLdouble posX, posY, posZ; + char buffer [200]; + float kts=1; + //glTranslatef (0.0,0.0,0.0); + glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); + glGetDoublev( GL_PROJECTION_MATRIX, projection ); + glGetIntegerv( GL_VIEWPORT, viewport ); + + //draw a point to a not important location to get window coordinates + glBegin(GL_POINTS); + glVertex3f(10.00,10.00,0.00); + glEnd(); + gluProject(10.0,10.0,0.00,modelview,projection,viewport,&wwinX,&wwinY,&wwinZ ); + winX = (float)x; + winY = (float)viewport[3] - (float)y; + gluUnProject( winX, winY, wwinZ, modelview, projection, viewport, &posX, &posY, &posZ); + + view.GLx=posX; + view.GLy=posY; + view.GLz=posZ; + view.GLDepth=kts; + return 1; + +} +//some functions set the caches the depth value ,view.GLDepth +int GetFixedOGLPos(int x, int y,float kts) +{ + GLdouble wwinX; + GLdouble wwinY; + GLdouble wwinZ; + + GLint viewport[4]; + GLdouble modelview[16]; + GLdouble projection[16]; + GLfloat winX, winY; + GLdouble posX, posY, posZ; + + glBegin(GL_POINTS); + glVertex3f(10.00,10.00,0.00); + glEnd(); + + glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); + glGetDoublev( GL_PROJECTION_MATRIX, projection ); + glGetIntegerv( GL_VIEWPORT, viewport ); + + gluProject(10.0,10.0,0.00,modelview,projection,viewport,&wwinX,&wwinY,&wwinZ ); + + +// glTranslatef (0.0,0.0,0.0); + + winX = (float)x; + winY = (float)viewport[3] - (float)y; + gluUnProject( winX, winY, wwinZ, modelview, projection, viewport, &posX, &posY, &posZ); + view.GLx2=posX; + view.GLy2=posY; + view.GLz2=posZ; + return 1; + +} + +int GetOGLPosRef(int x, int y,float* X,float* Y,float* Z) +{ + + GLdouble wwinX; + GLdouble wwinY; + GLdouble wwinZ; + GLdouble posX, posY, posZ; + + + int ind; + GLdouble depth[5]; + GLdouble raster[5]; + GLint viewport[4]; + GLdouble modelview[16]; + GLdouble projection[16]; + GLfloat winX, winY; + GLfloat winZ[36]; + char buffer [200]; + float kts=1; + //glTranslatef (0.0,0.0,0.0); + glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); + glGetDoublev( GL_PROJECTION_MATRIX, projection ); + glGetIntegerv( GL_VIEWPORT, viewport ); + + //draw a point to a not important location to get window coordinates + glBegin(GL_POINTS); + glVertex3f(10.00,10.00,0.00); + glEnd(); + gluProject(10.0,10.0,0.00,modelview,projection,viewport,&wwinX,&wwinY,&wwinZ ); + winX = (float)x; + winY = (float)viewport[3] - (float)y; + gluUnProject( winX, winY, wwinZ, modelview, projection, viewport, &posX, &posY, &posZ); + + *X=posX; + *Y=posY; + *Z=posZ; + return 1; + +} + + +float GetOGLDistance(int l) +{ + + int x,y; + float* X,Y, Z; + GLdouble wwinX; + GLdouble wwinY; + GLdouble wwinZ; + GLdouble posX, posY, posZ; + GLdouble posXX, posYY, posZZ; + + + int ind; + GLdouble depth[5]; + GLdouble raster[5]; + GLint viewport[4]; + GLdouble modelview[16]; + GLdouble projection[16]; + GLfloat winX, winY; + GLfloat winZ[36]; + char buffer [200]; + float kts=1; + //glTranslatef (0.0,0.0,0.0); + glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); + glGetDoublev( GL_PROJECTION_MATRIX, projection ); + glGetIntegerv( GL_VIEWPORT, viewport ); + + //draw a point to a not important location to get window coordinates + glBegin(GL_POINTS); + glVertex3f(10.00,10.00,0.00); + glEnd(); + gluProject(10.0,10.0,0.00,modelview,projection,viewport,&wwinX,&wwinY,&wwinZ ); + x=50; + y=50; + winX = (float)x; + winY = (float)viewport[3] - (float)y; + gluUnProject( winX, winY, wwinZ, modelview, projection, viewport, &posX, &posY, &posZ); + x=x+l; + y=50; + winX = (float)x; + winY = (float)viewport[3] - (float)y; + gluUnProject( winX, winY, wwinZ, modelview, projection, viewport, &posXX, &posYY, &posZZ); + return (posXX-posX); +} + + + +//////////////////////////GGGGGG//////////////////////////////////////////////// +/////////////////////////GG/////G/////////////////////////////////////////////// +/////////////////////////GG///////////////////////////////////////////////////// +/////////////////////////GG//GGG//////////////////////////////////////////////// +/////////////////////////GG/////G/////////////////////////////////////////////// +/////////////////////////GGG////G/////////////////////////////////////////////// +///////////////////////////GGGGG//////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +//2D PRIMITIVES +//all these functions should be moved to another file +//for testing i ll ise this file + + +#if 0 +void loadDLL (char* file) +{ + if(lt_dlinit ()== 0) + { + // g_print("libltdl has been successfully initialized\n"); + + if(lt_dlopen (file)) + g_print("%s has been loaded\n", file); + else + g_print("%s failed\n", file); + } +} +#endif + +void DrawView() +{ + if(view.activeGraph > -1) + { + + if(((custom_graph_data*)AGDATA(view.g[view.activeGraph]))->TopView) + drawTopViewGraph(view.g[view.activeGraph]);//topview style dots and straight lines + else + drawGraph(view.g[view.activeGraph]);//xdot based drawing functions + } + +} + + + diff --git a/cmd/smyrna/glTemplate.h b/cmd/smyrna/glTemplate.h new file mode 100755 index 000000000..037a27380 --- /dev/null +++ b/cmd/smyrna/glTemplate.h @@ -0,0 +1,132 @@ +/* $Id$ $Revision$ */ +/* vim:set shiftwidth=4 ts=8: */ + +/********************************************************** +* This software is part of the graphviz package * +* http://www.graphviz.org/ * +* * +* Copyright (c) 1994-2004 AT&T Corp. * +* and is licensed under the * +* Common Public License, Version 1.0 * +* by AT&T Corp. * +* * +* Information and Software Systems Research * +* AT&T Research, Florham Park NJ * +**********************************************************/ + +/* + this code is used to set up a opngl window and set + some basic features (panning zooming and rotating) + Viewport.h provides a higher level control such as drawing primitives +*/ +#ifndef GL_TEMPLATE_H +#define GL_TEMPLATE_H + +#ifdef _WIN32 +#include +#endif + +#include +#include +#include +#include // Header File For The GLu32 Library +// #include +#include "materials.h" + +#include "viewport.h" + +#include +#include +#include +#include + +// #include "guifunctions.h" +#include "trackball.h" +#include "cgraph.h" +#include "xdot.h" +#include + + +#define DIG_2_RAD (G_PI / 180.0) +#define RAD_2_DIG (180.0 / G_PI) +#define ANIMATE_THRESHOLD 25.0 +#define VIEW_SCALE_MAX 2.0 +#define VIEW_SCALE_MIN 0.5 +#define NUM_SHAPES 9 +static float DEG2RAD = 3.14159/180; +static gboolean animate = FALSE; +static void toggle_animation (GtkWidget *widget); + +// solid shapes +static const GLuint shape_cube = 0; +static const GLuint shape_sphere = 1; +static const GLuint shape_cone = 2; +static const GLuint shape_torus = 3; +static const GLuint shape_tetrahedron = 4; +static const GLuint shape_octahedron = 5; +static const GLuint shape_dodecahedron = 6; +static const GLuint shape_icosahedron = 7; +static const GLuint shape_teapot = 8; +//2D shapes +static const GLuint shape_dot = 9; +static const GLuint shape_polygon = 10; +static const GLuint shape_ellipse = 11; +static const GLuint shape_spline = 12; +static const GLuint shape_text = 13; +static GLuint shape_list_base = 0; +static GLuint shape_current = 8; +static MaterialProp *mat_current = &mat_silver; +static float view_quat_diff[4] = { 0.0, 0.0, 0.0, 1.0 }; +static float view_quat[4] = { 0.0, 0.0, 0.0, 1.0 }; +static float view_scale = 1.0; +//mouse modes +#define MM_PAN 0 +#define MM_ZOOM 1 +#define MM_ROTATE 2 +#define MM_SINGLE_SELECT 3 +#define MM_RECTANGULAR_SELECT 4 +#define MM_RECTANGULAR_X_SELECT 5 +#define MM_MOVE 10 +#define MM_MAGNIFIER 20 +#define MM_FISHEYE_MAGNIFIER 21 + +void loadDLL (char* file); +extern xdot* testxdot; +extern GtkWidget *drawing_area; + +static void init_view (void); +void examine_gl_config_attrib (GdkGLConfig *glconfig); +void print_gl_config_attrib (GdkGLConfig *glconfig,const gchar *attrib_str,int attrib,gboolean is_boolean); +static void realize (GtkWidget *widget,gpointer data); +static gboolean configure_event (GtkWidget *widget,GdkEventConfigure *event, gpointer data); +gboolean expose_event (GtkWidget *widget,GdkEventExpose *event,gpointer data); + + +static gboolean button_press_event (GtkWidget *widget,GdkEventButton *event,gpointer data); +static gboolean button_release_event (GtkWidget *widget,GdkEventButton *event,gpointer data); +static gboolean motion_notify_event (GtkWidget *widget,GdkEventMotion *event,gpointer data); +static gboolean key_press_event (GtkWidget *widget, GdkEventKey *event,gpointer data); +static gboolean idle (GtkWidget *widget); + +static void idle_add (GtkWidget *widget); +static void idle_remove (GtkWidget *widget); +static gboolean map_event (GtkWidget *widget,GdkEvent *event,gpointer data); +static gboolean unmap_event (GtkWidget *widget,GdkEvent *event,gpointer data); +static gboolean visibility_notify_event (GtkWidget *widget,GdkEventVisibility *event,gpointer data); +static void toggle_animation (GtkWidget *widget); +static void change_shape (GtkMenuItem *menuitem,const GLuint *shape); +//static void change_material (GtkMenuItem *menuitem,MaterialProp *mat); +void switch_Mouse (GtkMenuItem *menuitem,int mouse_mode); +static gboolean button_press_event_popup_menu (GtkWidget *widget,GdkEventButton *event,gpointer data); +static GtkWidget *create_popup_menu (GtkWidget *drawing_area); +extern +GdkGLConfig *configure_gl (void); +void create_window (GdkGLConfig *glconfig,GtkWidget* vbox); +int GetOGLPos(int x, int y);//this piece of code returns the opengl coordinates of mouse coordinates +int GetFixedOGLPos(int x, int y,float kts); +int GetOGLPosRef(int x, int y,float* X,float* Y,float* Z); +float GetOGLDistance(int l); +void loadDLL (char* file); //for loading plugins , requires ltdl (libtool) +void DrawView();//draws view + +#endif diff --git a/cmd/smyrna/main.c b/cmd/smyrna/main.c new file mode 100755 index 000000000..c7ae107ae --- /dev/null +++ b/cmd/smyrna/main.c @@ -0,0 +1,148 @@ +/* $Id$ $Revision$ */ +/* vim:set shiftwidth=4 ts=8: */ + +/********************************************************** +* This software is part of the graphviz package * +* http://www.graphviz.org/ * +* * +* Copyright (c) 1994-2004 AT&T Corp. * +* and is licensed under the * +* Common Public License, Version 1.0 * +* by AT&T Corp. * +* * +* Information and Software Systems Research * +* AT&T Research, Florham Park NJ * +**********************************************************/ + +/* + * Initial main.c file generated by Glade. Edit as required. + * Glade will not overwrite this file. + */ + +#ifdef HAVE_CONFIG_H +# include +#endif +//windows.h for win machines +#if defined(_WIN32) && !defined(__CYGWIN__) +#define WIN32_LEAN_AND_MEAN 1 +#include +#endif +#include // Header File For Standard Input/Output ( NEW ) +#include +#include +#include +#include +#include +#include "callbacks.h" +#include "regex.h" + +// #include "topology.h" +#include + + + +#include "gui.h" +#include "menucallbacks.h" +#include "cgraph.h" +#include "abstring.h" + +#ifdef G_OS_WIN32 +/*gchar *package_prefix = PACKAGE_PREFIX; +gchar *package_data_dir = PACKAGE_DATA_DIR; +gchar *package_locale_dir = PACKAGE_LOCALE_DIR;*/ +#endif +gchar *package_prefix = ""; +gchar *package_data_dir = ""; +gchar *package_locale_dir = ""; + +//973 768 8826 +//ramy 99 win + +int +main (int argc, char *argv[]) +{ + +// DWORD t1,t2; + int i=0; + int ind=0; + regex_t a; + GdkGLConfig *glconfig; + gchar *pixmap_dir; +// HMODULE mymodule; + char lpFilename[1024]; + GtkWidget* do_widget=NULL; + char str[50]="asdasdasasdas"; + //topview test starts here************** +// c_interface_draw(5); + //testme(&str); +// if(c_interface_load_from_file("c:/4elt.dot",graph,nvtxs,nedges,coords,labels,identifiers)!=0) + // c_interface_tp(graph,nvtxs,nedges,coords,labels,identifiers,&hierarchy); +/* { + for (ind=0;ind < 100 ;ind++) + { + printf("%i: coords:(%f,%f) ",ind ,coords[0][ind],coords[1][ind]); +// printf("TVcoords:(%f,%f)\n",hierarchy.geom_graphs[1][ind].x_coord,hierarchy.geom_graphs[1][ind].y_coord); + } + }*/ + + //topview test end here ************** + load_attributes(); + +//pango test +//t1=GetTickCount(); +// pango_main("c:/normal.png"); + //**** +// t2=GetTickCount(); +// printf("recorded tickcounts %d-%d \n", t1,t2); +// printf("difference (Pango):%d \n", t2-t1); +// print_children(tree_from_filter_string("(([color=\"brown\",min=\"0\",max=\"30\"])&([color=\"sfsdf\",min=\"15\",max=\"20\"]|[color=\"qqqqq\",min=\"0\",max=\"30\"]))")); + +#ifdef G_OS_WIN32 + package_prefix = g_win32_get_package_installation_directory (NULL, NULL); + package_data_dir = g_build_filename (package_prefix, "share", NULL); + package_locale_dir = g_build_filename (package_prefix, "share", "locale", NULL); +#endif# +#ifdef ENABLE_NLS + bindtextdomain (GETTEXT_PACKAGE, package_locale_dir); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); +#endif + // mymodule=GetModuleHandle(NULL); +// GetModuleFileName(NULL,lpFilename,1024); +// printf("dir:%s\n",lpFilename); +// printf("pango version is %s\n",pango_version_string ()); + gtk_set_locale (); + gtk_init (&argc, &argv); + +#ifdef _WIN32 +#define SMYRNA_ICONSDIR "C:\\Projects\\ATT\\GTK\\GTKTest2\\GUI\\images\\" +#endif +// pixmap_dir = g_build_filename (package_data_dir, "", "pixmaps", NULL); + printf("pixmap dir:%s \n", SMYRNA_ICONSDIR); + add_pixmap_directory (SMYRNA_ICONSDIR); +// add_pixmap_directory ("C:\\Projects\\ATT\\GTK\\GTKTest2\\GUI\\images\\"); +// g_free (pixmap_dir); + + xml = glade_xml_new(SMYRNA_GLADE, NULL, NULL); + gladewidget = glade_xml_get_widget(xml, "frmMain"); + gtk_widget_show (gladewidget); + g_signal_connect ((gpointer) gladewidget, "destroy", G_CALLBACK(mQuitSlot), + NULL); + glade_xml_signal_autoconnect(xml); + + gtk_gl_init (0,0); + /* Configure OpenGL framebuffer. */ + glconfig = configure_gl (); + gladewidget = glade_xml_get_widget(xml, "vbox2"); + + + create_window (glconfig,gladewidget); + gtk_main (); + +#ifdef G_OS_WIN32 + g_free (package_prefix); + g_free (package_data_dir); + g_free (package_locale_dir); +#endif + return 0; +} diff --git a/cmd/smyrna/materials.h b/cmd/smyrna/materials.h new file mode 100755 index 000000000..1fb58019a --- /dev/null +++ b/cmd/smyrna/materials.h @@ -0,0 +1,110 @@ +/* $Id$ $Revision$ */ +/* vim:set shiftwidth=4 ts=8: */ + +/********************************************************** +* This software is part of the graphviz package * +* http://www.graphviz.org/ * +* * +* Copyright (c) 1994-2004 AT&T Corp. * +* and is licensed under the * +* Common Public License, Version 1.0 * +* by AT&T Corp. * +* * +* Information and Software Systems Research * +* AT&T Research, Florham Park NJ * +**********************************************************/ + +#ifndef MATERIALS_H +#define MATERIALS_H +typedef struct _MaterialProp +{ + GLfloat ambient[4]; + GLfloat diffuse[4]; + GLfloat specular[4]; + GLfloat shininess; +} MaterialProp; + +static MaterialProp mat_emerald = { + {0.0215, 0.1745, 0.0215, 1.0}, + {0.07568, 0.61424, 0.07568, 1.0}, + {0.633, 0.727811, 0.633, 1.0}, + 0.6 +}; + +static MaterialProp mat_jade = { + {0.135, 0.2225, 0.1575, 1.0}, + {0.54, 0.89, 0.63, 1.0}, + {0.316228, 0.316228, 0.316228, 1.0}, + 0.1 +}; + +static MaterialProp mat_obsidian = { + {0.05375, 0.05, 0.06625, 1.0}, + {0.18275, 0.17, 0.22525, 1.0}, + {0.332741, 0.328634, 0.346435, 1.0}, + 0.3 +}; + +static MaterialProp mat_pearl = { + {0.25, 0.20725, 0.20725, 1.0}, + {1.0, 0.829, 0.829, 1.0}, + {0.296648, 0.296648, 0.296648, 1.0}, + 0.088 +}; + +static MaterialProp mat_ruby = { + {0.1745, 0.01175, 0.01175, 1.0}, + {0.61424, 0.04136, 0.04136, 1.0}, + {0.727811, 0.626959, 0.626959, 1.0}, + 0.6 +}; + +static MaterialProp mat_turquoise = { + {0.1, 0.18725, 0.1745, 1.0}, + {0.396, 0.74151, 0.69102, 1.0}, + {0.297254, 0.30829, 0.306678, 1.0}, + 0.1 +}; + +static MaterialProp mat_brass = { + {0.329412, 0.223529, 0.027451, 1.0}, + {0.780392, 0.568627, 0.113725, 1.0}, + {0.992157, 0.941176, 0.807843, 1.0}, + 0.21794872 +}; + +static MaterialProp mat_bronze = { + {0.2125, 0.1275, 0.054, 1.0}, + {0.714, 0.4284, 0.18144, 1.0}, + {0.393548, 0.271906, 0.166721, 1.0}, + 0.2 +}; + +static MaterialProp mat_chrome = { + {0.25, 0.25, 0.25, 1.0}, + {0.4, 0.4, 0.4, 1.0}, + {0.774597, 0.774597, 0.774597, 1.0}, + 0.6 +}; + +static MaterialProp mat_copper = { + {0.19125, 0.0735, 0.0225, 1.0}, + {0.7038, 0.27048, 0.0828, 1.0}, + {0.256777, 0.137622, 0.086014, 1.0}, + 0.1 +}; + +static MaterialProp mat_gold = { + {0.24725, 0.1995, 0.0745, 1.0}, + {0.75164, 0.60648, 0.22648, 1.0}, + {0.628281, 0.555802, 0.366065, 1.0}, + 0.4 +}; + +static MaterialProp mat_silver = { + {0.19225, 0.19225, 0.19225, 1.0}, + {0.50754, 0.50754, 0.50754, 1.0}, + {0.508273, 0.508273, 0.508273, 1.0}, + 0.4 +}; +#endif diff --git a/cmd/smyrna/template.c b/cmd/smyrna/template.c new file mode 100755 index 000000000..75b85f655 --- /dev/null +++ b/cmd/smyrna/template.c @@ -0,0 +1,669 @@ +/************************************************************************** + * template.c + * + * Copyright (c) 2002 Alif Wahid + * + * This is a template of the essential source code to write useful but + * simple programs using GtkGLExt and Gtk. It compiles into an executable + * but obviously the lack of any OpenGL functions in this demonstrates + * the generic nature. It's heavily commented to aid beginners (especially + * tertiary students like myself). So use/change it at will. + * + * This program is in the public domain and you are using it at + * your own risk. + * + **************************************************************************/ + +/* + * Follow the GTK coding style. + * Changed idle function management codes. + * Added popup menu. + * Added quit button. + * Naofumi Yasufuku + */ + +/************************************************************************** + * Header file inclusions. + **************************************************************************/ + +#include +#include +#include + +#include +#include + +#include +/*** Use OpenGL extensions. ***/ +/* #include */ + +#ifdef G_OS_WIN32 +#define WIN32_LEAN_AND_MEAN 1 +#include +#endif + +#include +#include + + +/************************************************************************** + * The following section contains all the macro definitions. + **************************************************************************/ + +/*** + *** Change these three macros to customise the + *** default width and height of the drawing + *** area, plus the default title of the window. + ***/ +#define DEFAULT_WIDTH 200 +#define DEFAULT_HEIGHT 200 +#define DEFAULT_TITLE "GtkGLExt Template" + +#define TIMEOUT_INTERVAL 10 + + +/************************************************************************** + * Global variable declarations. + **************************************************************************/ + +static gboolean animate = FALSE; + + +/************************************************************************** + * The following section contains the function prototype declarations. + **************************************************************************/ + +static void timeout_add (GtkWidget *widget); +static void timeout_remove (GtkWidget *widget); + +static void toggle_animation (GtkWidget *widget); + +static GdkGLConfig *configure_gl (void); + +static GtkWidget *create_popup_menu (GtkWidget *drawing_area); +static GtkWidget *create_window (GdkGLConfig *glconfig); + + +/************************************************************************** + * The following section contains all the callback function definitions. + **************************************************************************/ + +/*** + *** The "realize" signal handler. All the OpenGL initialization + *** should be performed here, such as default background colour, + *** certain states etc. + ***/ +static void +realize (GtkWidget *widget, + gpointer data) +{ + GdkGLContext *glcontext = gtk_widget_get_gl_context (widget); + GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget); + + g_print ("%s: \"realize\"\n", gtk_widget_get_name (widget)); + + /*** OpenGL BEGIN ***/ + if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) + return; + + /*** Fill in the details here. ***/ + + gdk_gl_drawable_gl_end (gldrawable); + /*** OpenGL END ***/ +} + +/*** + *** The "configure_event" signal handler. Any processing required when + *** the OpenGL-capable drawing area is re-configured should be done here. + *** Almost always it will be used to resize the OpenGL viewport when + *** the window is resized. + ***/ +static gboolean +configure_event (GtkWidget *widget, + GdkEventConfigure *event, + gpointer data) +{ + GdkGLContext *glcontext = gtk_widget_get_gl_context (widget); + GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget); + + GLfloat w = widget->allocation.width; + GLfloat h = widget->allocation.height; + + g_print ("%s: \"configure_event\"\n", gtk_widget_get_name (widget)); + + /*** OpenGL BEGIN ***/ + if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) + return FALSE; + + /*** Fill in the details here. ***/ + + glViewport (0, 0, w, h); + + gdk_gl_drawable_gl_end (gldrawable); + /*** OpenGL END ***/ + + return TRUE; +} + +/*** + *** The "expose_event" signal handler. All the OpenGL re-drawing should + *** be done here. This is repeatedly called as the painting routine + *** every time the 'expose'/'draw' event is signalled. + ***/ +static gboolean +expose_event (GtkWidget *widget, + GdkEventExpose *event, + gpointer data) +{ + GdkGLContext *glcontext = gtk_widget_get_gl_context (widget); + GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget); + + g_print ("%s: \"expose_event\"\n", gtk_widget_get_name (widget)); + + /*** OpenGL BEGIN ***/ + if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) + return FALSE; + + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + /*** Fill in the details here. ***/ + + /* Swap buffers */ + if (gdk_gl_drawable_is_double_buffered (gldrawable)) + gdk_gl_drawable_swap_buffers (gldrawable); + else + glFlush (); + + gdk_gl_drawable_gl_end (gldrawable); + /*** OpenGL END ***/ + + return TRUE; +} + +/*** + *** The timeout function. Often in animations, + *** timeout functions are suitable for continous + *** frame updates. + ***/ +static gboolean +timeout (GtkWidget *widget) +{ + g_print ("."); + + /*** Fill in the details here ***/ + + /* Invalidate the whole window. */ + gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE); + + /* Update synchronously. */ + gdk_window_process_updates (widget->window, FALSE); + + return TRUE; +} + +/*** + *** The "unrealize" signal handler. Any processing required when + *** the OpenGL-capable window is unrealized should be done here. + ***/ +static void +unrealize (GtkWidget *widget, + gpointer data) +{ + GdkGLContext *glcontext = gtk_widget_get_gl_context (widget); + GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget); + + g_print ("%s: \"unrealize\"\n", gtk_widget_get_name (widget)); + + /*** OpenGL BEGIN ***/ + if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) + return; + + /*** Fill in the details here. ***/ + + gdk_gl_drawable_gl_end (gldrawable); + /*** OpenGL END ***/ +} + +/*** + *** The "motion_notify_event" signal handler. Any processing required when + *** the OpenGL-capable drawing area is under drag motion should be done here. + ***/ +static gboolean +motion_notify_event (GtkWidget *widget, + GdkEventMotion *event, + gpointer data) +{ + g_print ("%s: \"motion_notify_event\": button", gtk_widget_get_name (widget)); + + /*** Fill in the details here. ***/ + + if (event->state & GDK_BUTTON1_MASK) + { + g_print (" 1"); + } + + if (event->state & GDK_BUTTON2_MASK) + { + g_print (" 2"); + } + + if (event->state & GDK_BUTTON3_MASK) + { + g_print (" 3"); + } + + g_print ("\n"); + + return FALSE; +} + +/*** + *** The "button_press_event" signal handler. Any processing required when + *** mouse buttons (only left and middle buttons) are pressed on the OpenGL- + *** capable drawing area should be done here. + ***/ +static gboolean +button_press_event (GtkWidget *widget, + GdkEventButton *event, + gpointer data) +{ + g_print ("%s: \"button_press_event\": ", gtk_widget_get_name (widget)); + + if (event->button == 1) + { + /*** Fill in the details here. ***/ + g_print ("button 1\n"); + + return TRUE; + } + + if (event->button == 2) + { + /*** Fill in the details here. ***/ + g_print ("button 2\n"); + + return TRUE; + } + + g_print ("\n"); + + return FALSE; +} + +/* For popup menu. */ +static gboolean +button_press_event_popup_menu (GtkWidget *widget, + GdkEventButton *event, + gpointer data) +{ + g_print ("%s: \"button_press_event_popup\": ", gtk_widget_get_name (widget)); + + if (event->button == 3) + { + g_print ("button 3\n"); + + /* Popup menu. */ + gtk_menu_popup (GTK_MENU (widget), NULL, NULL, NULL, NULL, + event->button, event->time); + return TRUE; + } + + g_print ("\n"); + + return FALSE; +} + +/*** + *** The "key_press_event" signal handler. Any processing required when key + *** presses occur should be done here. + ***/ +static gboolean +key_press_event (GtkWidget *widget, + GdkEventKey *event, + gpointer data) +{ + g_print ("%s: \"key_press_event\": ", gtk_widget_get_name (widget)); + + switch (event->keyval) + { + /*** Fill in the details here. ***/ + + case GDK_a: + g_print ("a key\n"); + toggle_animation (widget); + break; + + case GDK_Escape: + g_print ("Escape key\n"); + gtk_main_quit (); + break; + + default: + g_print("\n"); + return FALSE; + } + + return TRUE; +} + + +/************************************************************************** + * The following section contains the timeout function management routines. + **************************************************************************/ + +/*** + *** Helper functions to add or remove the timeout function. + ***/ + +static guint timeout_id = 0; + +static void +timeout_add (GtkWidget *widget) +{ + if (timeout_id == 0) + { + timeout_id = g_timeout_add (TIMEOUT_INTERVAL, + (GSourceFunc) timeout, + widget); + } +} + +static void +timeout_remove (GtkWidget *widget) +{ + if (timeout_id != 0) + { + g_source_remove (timeout_id); + timeout_id = 0; + } +} + +/*** + *** The "map_event" signal handler. Any processing required when the + *** OpenGL-capable drawing area is mapped should be done here. + ***/ +static gboolean +map_event (GtkWidget *widget, + GdkEvent *event, + gpointer data) +{ + g_print ("%s: \"map_event\":\n", gtk_widget_get_name (widget)); + if (animate) + timeout_add (widget); + + return TRUE; +} + +/*** + *** The "unmap_event" signal handler. Any processing required when the + *** OpenGL-capable drawing area is unmapped should be done here. + ***/ +static gboolean +unmap_event (GtkWidget *widget, + GdkEvent *event, + gpointer data) +{ + g_print ("%s: \"unmap_event\":\n", gtk_widget_get_name (widget)); + timeout_remove (widget); + + return TRUE; +} + +/*** + *** The "visibility_notify_event" signal handler. Any processing required + *** when the OpenGL-capable drawing area is visually obscured should be + *** done here. + ***/ +static gboolean +visibility_notify_event (GtkWidget *widget, + GdkEventVisibility *event, + gpointer data) +{ + if (animate) + { + if (event->state == GDK_VISIBILITY_FULLY_OBSCURED) + timeout_remove (widget); + else + timeout_add (widget); + } + + return TRUE; +} + + +/************************************************************************** + * The following section contains some miscellaneous utility functions. + **************************************************************************/ + +/*** + *** Toggle animation. + ***/ +static void +toggle_animation (GtkWidget *widget) +{ + animate = !animate; + + if (animate) + { + timeout_add (widget); + } + else + { + timeout_remove (widget); + gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE); + } +} + + +/************************************************************************** + * The following section contains the GUI building function definitions. + **************************************************************************/ + +/*** + *** Creates the popup menu to be displayed. + ***/ +static GtkWidget * +create_popup_menu (GtkWidget *drawing_area) +{ + GtkWidget *menu; + GtkWidget *menu_item; + + menu = gtk_menu_new (); + + /* Toggle animation */ + menu_item = gtk_menu_item_new_with_label ("Toggle Animation"); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); + g_signal_connect_swapped (G_OBJECT (menu_item), "activate", + G_CALLBACK (toggle_animation), drawing_area); + gtk_widget_show (menu_item); + + /* Quit */ + menu_item = gtk_menu_item_new_with_label ("Quit"); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); + g_signal_connect (G_OBJECT (menu_item), "activate", + G_CALLBACK (gtk_main_quit), NULL); + gtk_widget_show (menu_item); + + return menu; +} + +/*** + *** Creates the simple application window with one + *** drawing area that has an OpenGL-capable visual. + ***/ +static GtkWidget * +create_window (GdkGLConfig *glconfig) +{ + GtkWidget *window; + GtkWidget *vbox; + GtkWidget *drawing_area; + GtkWidget *menu; + GtkWidget *button; + + /* + * Top-level window. + */ + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (window), DEFAULT_TITLE); + + /* Get automatically redrawn if any of their children changed allocation. */ + gtk_container_set_reallocate_redraws (GTK_CONTAINER (window), TRUE); + + /* Connect signal handlers to the window */ + g_signal_connect (G_OBJECT (window), "delete_event", + G_CALLBACK (gtk_main_quit), NULL); + + /* + * VBox. + */ + + vbox = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), vbox); + gtk_widget_show (vbox); + + /* + * Drawing area to draw OpenGL scene. + */ + + drawing_area = gtk_drawing_area_new (); + gtk_widget_set_size_request (drawing_area, DEFAULT_WIDTH, DEFAULT_HEIGHT); + + /* Set OpenGL-capability to the widget */ + gtk_widget_set_gl_capability (drawing_area, + glconfig, + NULL, + TRUE, + GDK_GL_RGBA_TYPE); + + gtk_widget_add_events (drawing_area, + GDK_BUTTON1_MOTION_MASK | + GDK_BUTTON2_MOTION_MASK | + GDK_BUTTON_PRESS_MASK | + GDK_VISIBILITY_NOTIFY_MASK); + + /* Connect signal handlers to the drawing area */ + g_signal_connect_after (G_OBJECT (drawing_area), "realize", + G_CALLBACK (realize), NULL); + g_signal_connect (G_OBJECT (drawing_area), "configure_event", + G_CALLBACK (configure_event), NULL); + g_signal_connect (G_OBJECT (drawing_area), "expose_event", + G_CALLBACK (expose_event), NULL); + g_signal_connect (G_OBJECT (drawing_area), "unrealize", + G_CALLBACK (unrealize), NULL); + + g_signal_connect (G_OBJECT (drawing_area), "motion_notify_event", + G_CALLBACK (motion_notify_event), NULL); + g_signal_connect (G_OBJECT (drawing_area), "button_press_event", + G_CALLBACK (button_press_event), NULL); + + /* key_press_event handler for top-level window */ + g_signal_connect_swapped (G_OBJECT (window), "key_press_event", + G_CALLBACK (key_press_event), drawing_area); + + /* For timeout function. */ + g_signal_connect (G_OBJECT (drawing_area), "map_event", + G_CALLBACK (map_event), NULL); + g_signal_connect (G_OBJECT (drawing_area), "unmap_event", + G_CALLBACK (unmap_event), NULL); + g_signal_connect (G_OBJECT (drawing_area), "visibility_notify_event", + G_CALLBACK (visibility_notify_event), NULL); + + gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0); + + gtk_widget_show (drawing_area); + + /* + * Popup menu. + */ + + menu = create_popup_menu (drawing_area); + + g_signal_connect_swapped (G_OBJECT (drawing_area), "button_press_event", + G_CALLBACK (button_press_event_popup_menu), menu); + + /* + * Simple quit button. + */ + + button = gtk_button_new_with_label ("Quit"); + + g_signal_connect (G_OBJECT (button), "clicked", + G_CALLBACK (gtk_main_quit), NULL); + + gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); + + gtk_widget_show (button); + + return window; +} + + +/************************************************************************** + * The following section contains utility function definitions. + **************************************************************************/ + +/*** + *** Configure the OpenGL framebuffer. + ***/ +static GdkGLConfig * +configure_gl (void) +{ + GdkGLConfig *glconfig; + + /* Try double-buffered visual */ + glconfig = gdk_gl_config_new_by_mode (GDK_GL_MODE_RGB | + GDK_GL_MODE_DEPTH | + GDK_GL_MODE_DOUBLE); + if (glconfig == NULL) + { + g_print ("\n*** Cannot find the double-buffered visual.\n"); + g_print ("\n*** Trying single-buffered visual.\n"); + + /* Try single-buffered visual */ + glconfig = gdk_gl_config_new_by_mode (GDK_GL_MODE_RGB | + GDK_GL_MODE_DEPTH); + if (glconfig == NULL) + { + g_print ("*** No appropriate OpenGL-capable visual found.\n"); + exit (1); + } + } + + return glconfig; +} + + +/************************************************************************** + * The main function is rather trivial. + **************************************************************************/ + +/*int +main (int argc, + char *argv[]) +{ + GtkWidget *window; + GdkGLConfig *glconfig; + + /* Initialize GTK. */ +/* gtk_init (&argc, &argv); + + /* Initialize GtkGLExt. */ +/* gtk_gl_init (&argc, &argv); + + /* Configure OpenGL framebuffer. */ +/* glconfig = configure_gl (); + + /* Create and show the application window. */ +/* window = create_window (glconfig); + gtk_widget_show (window); + + gtk_main (); + + return 0; +}*/ + + +/************************************************************************** + * End of file. + **************************************************************************/ diff --git a/cmd/smyrna/topview.c b/cmd/smyrna/topview.c new file mode 100755 index 000000000..7d1c1ca1d --- /dev/null +++ b/cmd/smyrna/topview.c @@ -0,0 +1,885 @@ +/* $Id$ $Revision$ */ +/* vim:set shiftwidth=4 ts=8: */ + +/********************************************************** +* This software is part of the graphviz package * +* http://www.graphviz.org/ * +* * +* Copyright (c) 1994-2004 AT&T Corp. * +* and is licensed under the * +* Common Public License, Version 1.0 * +* by AT&T Corp. * +* * +* Information and Software Systems Research * +* AT&T Research, Florham Park NJ * +**********************************************************/ + +#include "topview.h" +#include "math.h" +#include "btree.h" +topview Topview; +GtkButton** gtkhostbtn; +int gtkhostbtncount; +GtkColorButton** gtkhostcolor; +int hostactive[50]; //temporary static, convert to dynamic,realloc +char** hostregex; +int fisheye_distortion_fac; + +static int font=0; +static float dx=0.0; +static float dy=0.0; +#define NODE_ZOOM_LIMIT -25.3 +#define NODE_CIRCLE_LIMIT -7.3 +extern void PrepareTopview(Agraph_t *g) +{ + int GP_flag=0; //general purpose flag + char* str; + char* d_attr1; + char* d_attr2; + float a,b,c; + char* pch; + Agnode_t *v; + Agedge_t *e; + GtkTreeIter iter; + int ind,ind2,data_type_count; //number of columns for custom topview data ,IP ,HOST, etc + char buf[256]; + ind=0;ind2=0; + //data attributes are read from graph's attributes DataAttribute1 and DataAttribute2 + //node_data_attribute1; //for topview graphs this is the node data attribute to put as label + //node_data_attribute2; //for topview graphs this is the node data attribute to be stored and used for something else + + //data list + + /* if ( agget(g, "DataCount")) + { + data_type_count=AToInt(agget(g, "DataCount")); + }*/ + gtk_widget_hide(glade_xml_get_widget(xml, "layout6")); //hide top panel + data_type_count=0; + d_attr1=agget(g, "DataAttribute1"); + d_attr2=agget(g, "DataAttribute2"); + + + + for (v = agfstnode(g); v; v = agnxtnode(g, v)) + { + //set node TV reference + ((custom_object_data*)AGDATA(v))->TVRef=ind; //Topview reference + strcpy(buf,agget(v, "pos")); + if(strlen(buf)) + { + a=atof(strtok (buf,"," )); + b=atof(strtok (NULL,"," )); + str=strtok (NULL,"," ); + if(str) + c=atof(str); + else + c=0.0; + if (!GP_flag) + { + Topview.limits[0]=a; + Topview.limits[2]=a; + Topview.limits[1]=b; + Topview.limits[3]=b; + GP_flag=1; + } + if (a < Topview.limits[0]) + Topview.limits[0]=a; + if (a > Topview.limits[2]) + Topview.limits[2]=a; + if (b < Topview.limits[1]) + Topview.limits[1]=b; + if (b > Topview.limits[3]) + Topview.limits[3]=b; + } + Topview.Nodes[ind].GroupIndex=-1; + randomize_color(&(Topview.Nodes[ind].Color),2); + Topview.Nodes[ind].Node=v; + Topview.Nodes[ind].x=a; + Topview.Nodes[ind].y=b; + Topview.Nodes[ind].z=c; + Topview.Nodes[ind].distorted_x=a; + Topview.Nodes[ind].distorted_y=b; + Topview.Nodes[ind].zoom_factor=1; + Topview.Nodes[ind].degree=agdegree(g,v,1,1); + Topview.Nodes[ind].node_alpha=log((float)Topview.Nodes[ind].degree+0.3); + if(d_attr1) + { + str=agget(v,d_attr1); + if(str) + { + Topview.Nodes[ind].Label=strdup(str); + + } + + } + if(d_attr2) + { + str=agget(v,d_attr2); + if(str) + { + Topview.Nodes[ind].Label2=strdup(str); + //gtk_list_store_set_value(Topview.DataList,&iter,2,str); + } + } + for (e = agfstout(g,v) ; e ; e = agnxtout (g,e)) + { + Topview.Edges[ind2].Hnode=aghead(e); + Topview.Edges[ind2].Tnode=agtail(e); + Topview.Edges[ind2].Edge=e; + + strcpy(buf,agget(aghead(e), "pos")); + if(strlen(buf)) + { + a=atof(strtok (buf,"," )); + b=atof(strtok (NULL,"," )); + str=strtok (NULL,"," ); + if(str) + c=atof(str); + else + c=0.0; + + Topview.Edges[ind2].x1=a; + Topview.Edges[ind2].y1=b; + Topview.Edges[ind2].z1=b; + } + strcpy(buf,agget(agtail(e), "pos")); + if(strlen(buf)) + { + a=atof(strtok (buf,"," )); + b=atof(strtok (NULL,"," )); + str=strtok (NULL,"," ); + if(str) + c=atof(str); + else + c=0.0; + + Topview.Edges[ind2].x2=a; + Topview.Edges[ind2].y2=b; + Topview.Edges[ind2].z2=c; + } + ind2++; + } + ind++; + } + //attach edge node references loop one more time + ind=0;ind2=0; + for (v = agfstnode(g); v; v = agnxtnode(g, v)) + { + //set node TV reference + for (e = agfstout(g,v) ; e ; e = agnxtout (g,e)) + { + Topview.Edges[ind2].Node1= &Topview.Nodes[((custom_object_data*)AGDATA(Topview.Edges[ind2].Tnode))->TVRef]; + Topview.Edges[ind2].Node2= &Topview.Nodes[((custom_object_data*)AGDATA(Topview.Edges[ind2].Hnode))->TVRef]; + ind2++; + + } + ind++; + } + Topview.Nodecount=ind; + Topview.Edgecount=ind2; + fisheye_distortion_fac=5; //simdilik burda dursun , need to be hooked to a widget + set_boundries(); + set_update_required(&Topview); + set_boundries(); +// load_host_buttons(g); +} +void drawTopViewGraph(Agraph_t *g) +{ + RGBColor c; +// DWORD t1,t2; + topview_node *v; + topview_edge *e; + float ddx,ddy; + float dddx,dddy; + int ind=0; + char buf[50]; + GLfloat a,b; + if(view.zoom > NODE_ZOOM_LIMIT) + { + glPointSize(15/view.zoom*-1); + //draw nodes + set_topview_options(); + if(view.zoom < NODE_CIRCLE_LIMIT) + glBegin(GL_POINTS); + for (ind=0;ind < Topview.Nodecount;ind ++) + { + + if((Topview.Nodes[ind].x > view.clipX1) && (Topview.Nodes[ind].x < view.clipX2) &&(Topview.Nodes[ind].y > view.clipY1)&&(Topview.Nodes[ind].y < view.clipY2)) + { + if(1) + { + v=&Topview.Nodes[ind]; + if(!node_visible(v->Node)) + break; + + select_topview_node(v); + //UPDATE topview data from cgraph + if (v->update_required) + update_topview_node_from_cgraph(v); + if( ((custom_object_data*)AGDATA(v->Node))->Selected==1) + { + glColor4f(view.selectColor.R,view.selectColor.G,view.selectColor.B,view.selectColor.A); + ddx=dx;ddy=dy; + } + else //get the color from node + { + glColor4f(v->Color.R,v->Color.G,v->Color.B,v->node_alpha); + // glColor4f(1,0,0,v->node_alpha); + // glColor4f (log((double)v->degree+0.5),v->Color.G,v->Color.B,); + ddx=0;ddy=0; + } + + + if(view.zoom < NODE_CIRCLE_LIMIT) + glVertex3f(v->distorted_x-ddx,v->distorted_y-ddy,-0.01); + else + drawCircle(v->distorted_x-ddx,v->distorted_y-ddy,v->node_alpha*v->zoom_factor); + } + } + } + if(view.zoom< NODE_CIRCLE_LIMIT) + glEnd(); + for (ind=0;ind < Topview.Nodecount;ind ++) + { + + v=&Topview.Nodes[ind]; + if(!node_visible(v->Node)) + break; + + draw_topview_label(v); + + } + } + //draw edges +// glLineWidth(5/view.zoom*-1); + glBegin(GL_LINES); + set_topview_options(); + for (ind=0;ind < Topview.Edgecount;ind ++) + { + if( + ((Topview.Edges[ind].x1 > view.clipX1) && (Topview.Edges[ind].x1 < view.clipX2) &&(Topview.Edges[ind].y1 > view.clipY1)&&(Topview.Edges[ind].y1 < view.clipY2)) + || + ((Topview.Edges[ind].x2 > view.clipX1) && (Topview.Edges[ind].x2 < view.clipX2) &&(Topview.Edges[ind].y2 > view.clipY1)&&(Topview.Edges[ind].y2 < view.clipY2)) + + ) + { + e=&Topview.Edges[ind]; + select_topview_edge(e); + if( ((custom_object_data*)AGDATA(e->Node1->Node))->Selected==1) //tail is selected + { ddx=dx;ddy=dy;} + else + { ddx=0;ddy=0;} + if( ((custom_object_data*)AGDATA(e->Node2->Node))->Selected==1) //head + { dddx=dx;dddy=dy;} + else + { dddx=0;dddy=0;} + + + if(get_color_from_edge(e)) + { + glVertex3f(e->Node1->distorted_x-ddx,e->Node1->distorted_y-ddy,-0.01); + glVertex3f(e->Node2->distorted_x-dddx,e->Node2->distorted_y-dddy,-0.01); + } + } + } + glEnd(); + if((view.Selection.Active>0) && (!SignalBlock)) + { + view.Selection.Active=0; + drawTopViewGraph(g); + SignalBlock=1; + expose_event (drawing_area,NULL,NULL); + SignalBlock=0; + } + +} + + +int select_topview_node(topview_node *n) +{ + if(!view.Selection.Active) + return 0; + if(is_point_in_rectangle(n->x,n->y,view.Selection.X,view.Selection.Y,view.Selection.W,view.Selection.H)) + { + + switch (view.Selection.Type) + { + case 0: + + if ( ((custom_object_data*)AGDATA(n->Node))->Selected==0) + { + ((custom_object_data*)AGDATA(n->Node))->Selected=1; + select_object (view.g[view.activeGraph],n->Node); + } + else + { + ((custom_object_data*)AGDATA(n->Node))->Selected=1; + deselect_object (view.g[view.activeGraph],n->Node); + } + break; + + case 1: + case 2: + if(view.Selection.Anti==0) + { + select_object (view.g[view.activeGraph],n->Node); + view.Selection.AlreadySelected=1; + } + else + { + deselect_object (view.g[view.activeGraph],n->Node); + view.Selection.AlreadySelected=1; + } + break; + + } + } +} +int select_topview_edge(topview_edge *e) +{ + int r=0; + if(!view.Selection.Active) + return 0; + r=(lineintersects(e->x1,e->y1,e->x2,e->y2)); + if(r >= 0) + { + + switch (view.Selection.Type) + { + case 0: + if ( ((custom_object_data*)AGDATA(e->Edge))->Selected==0) + { + ((custom_object_data*)AGDATA(e->Edge))->Selected=1; + select_object (view.g[view.activeGraph],e->Edge); + } + else + { + ((custom_object_data*)AGDATA(e->Edge))->Selected=1; + deselect_object (view.g[view.activeGraph],e->Edge); + } + break; + +/* case 1: + case 2: + if(view.Selection.Anti==0) + { + select_object (view.g[view.activeGraph],n->Node); + view.Selection.AlreadySelected=1; + } + else + { + deselect_object (view.g[view.activeGraph],n->Node); + view.Selection.AlreadySelected=1; + } + break;*/ + + } + } + + +/* else if (view.Selection.Type==0) + { + deselect_object (view.g[view.activeGraph],n->Node); + view.Selection.AlreadySelected=1; + } */ +} +int update_topview_node_from_cgraph(topview_node* Node) +{ + //for now just color, maybe i need more later + int i=0; + char* buf; + buf=agget(Node->Node,"color"); + if(buf) + Node->Color=GetRGBColor(buf); +/* else + { + randomize_color(&(Node->Color),2); + + Node->Color.R=view.penColor.R; + Node->Color.G=view.penColor.G; + Node->Color.B=view.penColor.B; + Node->Color.A=view.penColor.A; + }*/ + Node->update_required=0; +} +int update_topview_edge_from_cgraph(topview_edge* Edge) +{ + //for now just color , maybe i need more later + int i=0; + char buf[124]; + strcpy(buf, (agget(Edge->Edge,"color")==NULL) ? "black" : agget(Edge->Edge,"color")); + if(strlen(buf) > 0) + Edge->Color=GetRGBColor(buf); + else + { + Edge->Color.R=view.penColor.R; + Edge->Color.G=view.penColor.G; + Edge->Color.B=view.penColor.B; + Edge->Color.A=view.penColor.A; + } + Edge->update_required=0; +} + + + +int set_update_required(topview* t) +{ + int i=0; + char buf[124]; + int ilimit; + ilimit= (t->Nodecount > t->Edgecount) ? t->Nodecount : t->Edgecount; + + for (i=0; i < ilimit; i ++) + { + if( t->Nodecount > i) + + t->Nodes[i].update_required=1; + if( t->Edgecount > i) + t->Edges[i].update_required=1; + } + +} + +int draw_topview_label(topview_node* v) +{ + + float fs=0; + float ddx=0; + float ddy=0; + if(!v->Label) + return 0; + if((view.zoom*-1/v->degree/v->zoom_factor) > 2) + return 0; + if((v->distorted_x > view.clipX1) && (v->distorted_x < view.clipX2) &&(v->distorted_y > view.clipY1)&&(v->distorted_y < view.clipY2)) + { + + fs=(v->degree==1) ?log((double)v->degree+1)*7:log((double)v->degree+0.5)*7; + fs=fs*v->zoom_factor; +/* if(fs > 12) + fs=24;*/ + if( ((custom_object_data*)AGDATA(v->Node))->Selected==1) + { + ddx=dx;ddy=dy; + } + + fontSize (fs); + fontColorA (log((double)v->degree+1),view.penColor.G,view.penColor.B,view.penColor.A/log((float)v->degree)*-0.6*view.zoom); +// printf("%f \n",view.penColor.A/log((float)v->degree)*-0.02*view.zoom); + fontDrawString (v->distorted_x-ddx,v->distorted_y-ddy,v->Label,fs*5); + return 1; + } + else + return 0; +} + + +int randomize_color(RGBColor* c,int brightness) +{ + float R,B,G; + float add; + R=(float)(rand() % 255) / 255.0; + G=(float)(rand() % 255) / 255.0; + B=(float)(rand() % 255) / 255.0; + add=(brightness-(R+G+B))/3; + R = R; + G = G; + B = B; + c->R=R; + c->G=G; + c->B=B; +// printf(" %f %f %f \n",R,G,B); +} + + +void drawCircle(float x,float y,float radius) +{ + int i; + if(radius <0.3) + radius=0.4; + glBegin(GL_POLYGON); + for (i=0; i < 360; i=i+10) + { + float degInRad = i*DEG2RAD; + glVertex2f(x+cos(degInRad)*radius,y+sin(degInRad)*radius); + } + + glEnd(); +} + +void set_topview_options() +{ + + if ((view.mouse.mouse_mode==10) && (view.mouse.mouse_down==1)) //selected, if there is move move it, experimental + { + dx=view.GLx-view.GLx2; + dy=view.GLy-view.GLy2; + } + else + { + dx=0; + dy=0; + } + +} +void set_boundries() +{ + GLfloat bdxLeft,bdyTop,bdzTop; //border top coordinates + GLfloat bdxRight,bdyBottom,bdzBottom; //border bottom coordinates + + view.bdxLeft=Topview.limits[0]; + view.bdyTop=Topview.limits[3]; + view.bdxRight=Topview.limits[2]; + view.bdyBottom=Topview.limits[1]; + + view.bdzTop=0; + view.bdzBottom=0; +// view.panx=view.bdxLeft; +// view.pany=view.bdyBottom; +// view.prevpanx=view.bdxLeft; +// view.prevpany=view.bdyBottom; + + printf ("graph boundries (%f,%f)/(%f,%f) \n" , view.bdxLeft,view.bdyTop,view.bdxRight,view.bdyBottom); +} + + + +int get_color_from_edge(topview_edge *e) +{ + RGBColor c; + GdkColor color; + char* color_string; + int return_value=0; + float Alpha=0; + GtkHScale* AlphaScale=glade_xml_get_widget(xml, "frmHostAlphaScale"); + Alpha=gtk_range_get_value((GtkRange*) AlphaScale); + + //check visibility; + if( (node_visible(e->Node1->Node)) + && + (node_visible(e->Node2->Node)) ) + return_value=1; + + + if( ( ((custom_object_data*)AGDATA(e->Node1->Node))->Selected==1) + && + ( ((custom_object_data*)AGDATA(e->Node2->Node))->Selected==1) + ) + { +// glColor4f(0,0,1,1); + glColor4f(view.selectColor.R,view.selectColor.G,view.selectColor.B,view.selectColor.A); + return return_value; + } + if( ( ((custom_object_data*)AGDATA(e->Node1->Node))->Highlighted==1) + && + ( ((custom_object_data*)AGDATA(e->Node2->Node))->Highlighted==1) + ) + { + glColor4f(0,0,1,1); + return return_value; + } + color_string=agget(e->Node1->Node,"fillcolor"); + //group colors + if((e->Node1->GroupIndex >=0) || (e->Node2->GroupIndex >=0)) + { + if (hostactive[e->Node1->GroupIndex]==1) + { + gtk_color_button_get_color(gtkhostcolor[e->Node1->GroupIndex],&color); + glColor4f(color.red/65535.0,color.green/65535.0,color.blue/65535.0,1); + return return_value; + }else + { + if (hostactive[e->Node2->GroupIndex]==1) + { + gtk_color_button_get_color(gtkhostcolor[e->Node2->GroupIndex],&color); + glColor4f(color.red/65535.0,color.green/65535.0,color.blue/65535.0,1); + return return_value; + } + } + + } + + + 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,Alpha); + return return_value; +} +int node_visible(Agnode_t* n) +{ + return ((custom_object_data*)AGDATA(n))->Visible; + +} +int move_TVnodes() +{ + topview_node *v; + int ind=0; + for (ind=0;ind < Topview.Nodecount;ind ++) + { + v=&Topview.Nodes[ind]; + if( ((custom_object_data*)AGDATA(v->Node))->Selected==1) + { + v->x=v->x-dx; + v->y=v->y-dy; + } + } +} +int draw_navigation_menu() +{ + + int vPort[4]; + /* get current viewport */ + glGetIntegerv (GL_VIEWPORT, vPort); + + glMatrixMode (GL_PROJECTION); + glPushMatrix (); + glLoadIdentity (); + + + glOrtho (0, vPort[2], 0, vPort[3], -1, 1); + glMatrixMode (GL_MODELVIEW); + glPushMatrix (); + glLoadIdentity (); + drawCircle(100,100,1); + + glMatrixMode (GL_PROJECTION); + glPopMatrix (); + glMatrixMode (GL_MODELVIEW); + glPopMatrix (); +} + +int load_host_buttons(Agraph_t *g) +{ + GtkLayout* layout; + int btncount=0; + int i=0; + char buf[255]; + char *str; + char hostbtncaption[50]; + char hostbtnregex[50]; + char hostbtncolorR[50]; + char hostbtncolorG[50]; + char hostbtncolorB[50]; + char hostbtncolorA[50]; + int X=10; + int Y=25; + GdkColor color; + + layout=glade_xml_get_widget(xml, "frmHostSelectionFixed"); + str='\0'; + str=agget(g, "hostbtncount"); + if (str) + btncount=atoi(str); + +// Graph [hostbtncaption1="AT&T",hostbtnregex1="*.ATT*",hostbtncolorR1="1",hostbtncolorG1="0",hostbtncolorB1="0",hostbtncolorA1="1"]; + + hostregex=malloc (sizeof(char**)*btncount); + gtkhostbtn=malloc(sizeof(GtkButton*)*btncount); + gtkhostcolor=malloc(sizeof(GtkColorButton*)*btncount); + gtkhostbtncount=btncount; + for (i=0;i < btncount ; i++) + { + sprintf(hostbtncaption,"hostbtncaption%i",i); + sprintf(hostbtnregex,"hostbtnregex%i",i); + sprintf(hostbtncolorR,"hostbtncolorR%i",i); + sprintf(hostbtncolorG,"hostbtncolorG%i",i); + sprintf(hostbtncolorB,"hostbtncolorB%i",i); + sprintf(hostbtncolorA,"hostbtncolorA%i",i); + printf ("caption:%s regex:%s Color(%s,%s,%s,%s)\n", + agget(g,hostbtncaption ), + agget(g,hostbtnregex), + agget(g,hostbtncolorR), + agget(g,hostbtncolorG), + agget(g,hostbtncolorB), + agget(g,hostbtncolorA)); + hostregex[i]=agget(g,hostbtnregex); + gtkhostbtn[i]=gtk_button_new_with_label(agget(g,hostbtncaption )); + g_signal_connect ((gpointer) gtkhostbtn[i], "clicked", G_CALLBACK(host_button_clicked_Slot),i); + + color.blue=65535*atof(agget(g,hostbtncolorB)); + color.red=65535*atof(agget(g,hostbtncolorR)); + color.green=65535*atof(agget(g,hostbtncolorG)); + + gtkhostcolor[i]=gtk_color_button_new_with_color(&color); + + gtk_color_button_set_alpha(gtkhostbtn[i],65535*atof(agget(g,hostbtncolorA))); + + + gtk_layout_put (layout,gtkhostbtn[i],X,Y); + gtk_widget_set_size_request(gtkhostbtn[i],200,35); + + gtk_layout_put (layout,gtkhostcolor[i],X+225,Y); + gtk_widget_set_size_request(gtkhostcolor[i],40,35); + + gtk_widget_show(gtkhostbtn[i]); + gtk_widget_show(gtkhostcolor[i]); + Y=Y+40; + hostactive[i]=0; + } + printf ("all regex\n"); + for (i=0;i < btncount ; i++) + { + + prepare_nodes_for_groups(i); + + } +} + +int prepare_nodes_for_groups(int groupindex) +{ + GdkColor color; + int i=0; + int count=0; + tv_node tvn; + gtk_color_button_get_color(gtkhostcolor[0],&color); + + for (i;i < Topview.Nodecount ; i++) + { + tvn.index=i; + if(validate_group_node(&tvn,hostregex[groupindex])) + { + count ++; + gtk_color_button_get_color(gtkhostcolor[groupindex],&color); + Topview.Nodes[i].GroupIndex=groupindex; + Topview.Nodes[i].GroupColor.R=color.red/65535.0; + Topview.Nodes[i].GroupColor.G=color.green/65535.0; + Topview.Nodes[i].GroupColor.B=color.blue/65535.0; + } + } + printf ("%i matches for group:%i (%s) RGB(%f,%f,%f)\n",count,groupindex,hostregex[groupindex],color.red/65535.0,color.green/65535.0,color.blue/65535.0); +} + + +int validate_group_node(tv_node* TV_Node,char* regex_string) +{ + btree_node* n=0; + char* data_attr1; + char* data_attr2; + char* data1; + char* data2; +// n=tree_from_filter_string("([IP=\"^10.*\",min=\"0\",max=\"0\"])"); + int valid=0; + n=tree_from_filter_string(regex_string); + valid=evaluate_expresions (TV_Node,n); +// delete_node(n); + return valid; +} + +void host_button_clicked_Slot(GtkWidget *widget,gpointer user_data) +{ + //negative active + int i; + if(hostactive[(int)user_data]==0) + hostactive[(int)user_data]=1; + else + hostactive[(int)user_data]=0; + printf("-----------\n"); + printf ("host%i:%i\n",(int)user_data,hostactive[(int)user_data]); + printf("-----------\n"); + for (i=0;i < gtkhostbtncount ; i++) + { + printf ("host%i:%i\n",i,hostactive[i]); + } + expose_event (drawing_area,NULL,NULL); +} +void +on_host_alpha_change (GtkWidget *widget,gpointer user_data) +{ + expose_event (drawing_area,NULL,NULL); +} + +void local_zoom(topview* t) +{ + int i; + double delx,dely,w,h,tempx,tempy; + w=view.mg.width; + h=view.mg.height; + for (i=1; i< t->Nodecount; i++) + { + if(is_point_in_rectangle(t->Nodes[i].x,t->Nodes[i].y,view.mg.x-view.mg.width,view.mg.y-view.mg.height, + view.mg.width*2,view.mg.height*2)) + { + delx=t->Nodes[i].x-view.mg.x; + dely=t->Nodes[i].y-view.mg.y; + + t->Nodes[i].distorted_x=view.mg.x+delx*view.mg.kts; + t->Nodes[i].distorted_y=view.mg.y+dely*view.mg.kts; + } + else + { + t->Nodes[i].distorted_x =t->Nodes[i].x; + t->Nodes[i].distorted_y =t->Nodes[i].y; + t->Nodes[i].zoom_factor=1; + } + } +} +void fisheye_polar(double x_focus, double y_focus,topview* t) +{ + int i; + double distance, distorted_distance, ratio,range; + + range=0; + for (i=1; i< t->Nodecount; i++) + { + if(point_within_ellips_with_coords(x_focus,y_focus,view.fmg.R,view.fmg.R,t->Nodes[i].x,t->Nodes[i].y)) + { + range = MAX(range,dist(t->Nodes[i].x,t->Nodes[i].y, x_focus, y_focus)); + } + } + + for (i=1; i< t->Nodecount; i++) + { + + if(point_within_ellips_with_coords(x_focus,y_focus,view.fmg.R,view.fmg.R,t->Nodes[i].x,t->Nodes[i].y)) + { + distance = dist(t->Nodes[i].x, t->Nodes[i].y, x_focus, y_focus); + distorted_distance = G(distance/range)*range; + if (distance!=0) { + ratio = distorted_distance/distance; + } + else { + ratio = 0; + } + t->Nodes[i].distorted_x = x_focus +(t->Nodes[i].x-x_focus)*ratio; + t->Nodes[i].distorted_y = y_focus + (t->Nodes[i].y-y_focus)*ratio; + t->Nodes[i].zoom_factor=1*distorted_distance/distance; + } + else + { + t->Nodes[i].distorted_x =t->Nodes[i].x; + t->Nodes[i].distorted_y =t->Nodes[i].y; + t->Nodes[i].zoom_factor=1; + } + } +} +void originate_distorded_coordinates(topview* t) +{ + //sets original coordinates values to distorded coords. this happens when lieft mouse click is released in geometrical fisyehey mode + int i; + for (i=1; i< t->Nodecount; i++) + { + t->Nodes[i].distorted_x =t->Nodes[i].x; + t->Nodes[i].distorted_y =t->Nodes[i].y; + t->Nodes[i].zoom_factor=1; + } +} + + + + + +double dist(double x1, double y1, double x2, double y2) +{ + return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); +} +double G(double x) +{ + // distortion function for fisheye display + return (fisheye_distortion_fac+1)*x/(fisheye_distortion_fac*x+1); +} + + diff --git a/cmd/smyrna/topview.h b/cmd/smyrna/topview.h new file mode 100755 index 000000000..db3f77092 --- /dev/null +++ b/cmd/smyrna/topview.h @@ -0,0 +1,114 @@ +/* $Id$ $Revision$ */ +/* vim:set shiftwidth=4 ts=8: */ + +/********************************************************** +* This software is part of the graphviz package * +* http://www.graphviz.org/ * +* * +* Copyright (c) 1994-2004 AT&T Corp. * +* and is licensed under the * +* Common Public License, Version 1.0 * +* by AT&T Corp. * +* * +* Information and Software Systems Research * +* AT&T Research, Florham Park NJ * +**********************************************************/ + +//Top view +#ifndef TOPVIEW_H +#define TOPVIEW_H +#define MAX_TOP_VIEW_NODE_COUNT 1000000 +#define MAX_TOP_VIEW_EDGE_COUNT 1000000 +#define UNHIGHLIGHTED_ALPHA 0.3 + +#include "viewport.h" +#include "gui.h" +#include "tvnodes.h" + +#ifdef WIN32 //this shit is needed on WIN32 to get libglade see the callback +#define _BB __declspec(dllexport) +#else +#define _BB +#endif + + +typedef struct{ + Agnode_t* Node; + GLfloat x; + GLfloat y; + GLfloat z; + + GLfloat distorted_x; //geometric fisheye coords + GLfloat distorted_y; + GLfloat distorted_z; + float zoom_factor; + int in_fish_eye; //boolean value if to apply fisheye + + RGBColor Color; + RGBColor GroupColor; + int GroupIndex; //default -1; + int update_required; + char* Label; + char* Label2; + int degree; + float node_alpha; + int valid; + +}topview_node; + +typedef struct{ + Agnode_t* Tnode; //Tail node + Agnode_t* Hnode; //Tail node + Agedge_t *Edge; //edge itself + GLfloat x1; + GLfloat y1; + GLfloat z1; + GLfloat x2; + GLfloat y2; + GLfloat z2; + topview_node* Node1; + topview_node* Node2; + RGBColor Color; + int update_required; + +}topview_edge; +typedef struct { + topview_node Nodes[MAX_TOP_VIEW_NODE_COUNT]; + topview_edge Edges[MAX_TOP_VIEW_EDGE_COUNT]; + int Nodecount; + int Edgecount; + int limits[4]; +} topview; +extern topview Topview; +extern void PrepareTopview(Agraph_t *g); +int select_topview_node(topview_node *n); +int select_topview_edge(topview_edge *e); +int update_topview_node_from_cgraph(topview_node* Node); +int update_topview_edge_from_cgraph(topview_edge* Edge); +int set_update_required(topview* t); +int draw_topview_label(topview_node* v); +int randomize_color(RGBColor* c,int brightness); +void drawCircle(float x,float y,float radius); +void set_topview_options(); +void set_boundries(); +int get_color_from_edge(topview_edge *e); +int node_visible(Agnode_t* n); +int move_TVnodes(); +int draw_navigation_menu(); +int load_host_buttons(Agraph_t *g); +void originate_distorded_coordinates(topview* t); +int prepare_nodes_for_groups(int groupindex); +int validate_group_node(tv_node* TV_Node,char* regex_string); +int click_group_button(int groupindex); +_BB void host_button_clicked_Slot(GtkWidget *widget,gpointer user_data); +_BB void on_host_alpha_change (GtkWidget *widget,gpointer user_data); +//global gui pointers for buttons and color selection boxes +extern GtkButton** gtkhostbtn; +extern int gtkhostbtncount; +extern GtkColorButton** gtkhostcolor; +extern int hostactive[50]; //temporary static, convert to dynamic,realloc +extern char** hostregex; +double dist(double x1, double y1, double x2, double y2); +double G(double x); +extern int fisheye_distortion_fac; +#endif