/* Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd. All rights reserved. Copyright (C) 2007-2008, Gabriel Dos Reis. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of The Numerical Algorithms Group Ltd. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define _SPOON2D_C #include #include #include #include "open-axiom.h" #include "viewAlone.h" #include "util.H1" #include "cfuns.h" #include "all_alone.H1" using namespace OpenAxiom; /* #define huhDEBUG */ /* #define spoonDEBUG */ void spoonView2D(void) { int i,code,pipe0[2],pipe1[2],there; char envAXIOM[100],runView[100]; sprintf(errorStr,"%s","creating pipes"); check(pipe(pipe0)); check(pipe(pipe1)); switch(fork()) { case -1: fprintf(stderr, "Cannot create a new process - probably have too many things running already.\n"); exit(-1); case 0: /************ * Child * ************/ printf("(spoon2D child) mapping of pipes to standard I/O for view2D\n"); sprintf(errorStr,"%s","(viewAlone) mapping of pipes to standard I/O for view2D"); check(dup2(pipe0[0],0)); check(dup2(pipe1[1],1)); close(pipe0[0]); close(pipe0[1]); close(pipe1[0]); close(pipe1[1]); printf("(spoon2D child) start the TwoDimensionalViewport process\n"); sprintf(errorStr,"%s","(viewAlone) execution of the TwoDimensionalViewport process"); sprintf(envAXIOM,"%s",oa_getenv("AXIOM")); sprintf(runView,"%s%s",envAXIOM,"/lib/view2D"); check(execl(runView,runView, (char*)NULL)); fprintf(stderr,"Could not execute view2D! Check that view2D is on your path variable.\n"); exit(-1); default: /************* * Parent * *************/ viewP.viewType = view2DType; /* set up pipes to child process */ close(pipe0[0]); close(pipe1[1]); viewP.viewIn = pipe1[0]; viewP.viewOut = pipe0[1]; printf("(spoon2D parent) pipes created\n"); if (viewP.viewIn <0) { fprintf(stderr," Could not connect from Viewport manager to viewport process. Try again.\n"); return; } else { code = read(viewP.viewIn,&ack,intSize); if (code < 0) { fprintf(stderr," Could not connect from Viewport manager to viewport process. Try again.\n"); return; } } printf("(spoon2D parent) making View2D data\n"); makeView2DFromFileData(&doView2D); /* tell child it is to be a stand alone program */ i = yes; fprintf(stderr," Transmitting data to viewport...\n"); write(viewP.viewOut,&i,intSize); write(viewP.viewOut,&doView2D,sizeof(view2DStruct)); i = strlen(doView2D.title)+1; write(viewP.viewOut,&i,intSize); /* tell the length of the title to child */ write(viewP.viewOut,doView2D.title,i); /* tell the title to the child, child */ for (i=0; iviewOut,&(gPtr->xmin),floatSize); write(viewP->viewOut,&(gPtr->xmax),floatSize); write(viewP->viewOut,&(gPtr->ymin),floatSize); write(viewP->viewOut,&(gPtr->ymax),floatSize); write(viewP->viewOut,&(gPtr->xNorm),floatSize); write(viewP->viewOut,&(gPtr->yNorm),floatSize); write(viewP->viewOut,&(gPtr->spadUnitX),floatSize); write(viewP->viewOut,&(gPtr->spadUnitY),floatSize); write(viewP->viewOut,&(gPtr->unitX),floatSize); write(viewP->viewOut,&(gPtr->unitY),floatSize); write(viewP->viewOut,&(gPtr->originX),floatSize); write(viewP->viewOut,&(gPtr->originY),floatSize); write(viewP->viewOut,&(gPtr->numberOfLists),intSize); llPtr = gPtr->listOfListsOfPoints; for (j=0; j<(gPtr->numberOfLists); j++) { write(viewP->viewOut,&(llPtr->numberOfPoints),intSize); p = llPtr->listOfPoints; for (k=0; k<(llPtr->numberOfPoints); k++) { write(viewP->viewOut,&(p->x),floatSize); write(viewP->viewOut,&(p->y),floatSize); write(viewP->viewOut,&(p->hue),floatSize); write(viewP->viewOut,&(p->shade),floatSize); p++; } /* for k in list of points */ write(viewP->viewOut,&(llPtr->pointColor),intSize); write(viewP->viewOut,&(llPtr->lineColor),intSize); write(viewP->viewOut,&(llPtr->pointSize),intSize); llPtr++; } /* for j in list of lists of points */ /* a state is defined for a graph if it is there */ write(viewP->viewOut,&(graphStateArray[i].scaleX),floatSize); write(viewP->viewOut,&(graphStateArray[i].scaleY),floatSize); write(viewP->viewOut,&(graphStateArray[i].deltaX),floatSize); write(viewP->viewOut,&(graphStateArray[i].deltaY),floatSize); write(viewP->viewOut,&(graphStateArray[i].pointsOn),intSize); write(viewP->viewOut,&(graphStateArray[i].connectOn),intSize); write(viewP->viewOut,&(graphStateArray[i].splineOn),intSize); write(viewP->viewOut,&(graphStateArray[i].axesOn),intSize); write(viewP->viewOut,&(graphStateArray[i].axesColor),intSize); write(viewP->viewOut,&(graphStateArray[i].unitsOn),intSize); write(viewP->viewOut,&(graphStateArray[i].unitsColor),intSize); write(viewP->viewOut,&(graphStateArray[i].showing),intSize); } /* if graph is there */ } void makeView2DFromFileData(view2DStruct *doView2D) { int i,j,k; char title[256]; FILE *graphFile; char graphFilename[256]; pointListStruct *aList; pointStruct *aPoint; printf("(spoon2D makeView2DFromFileData)\n"); fgets(title,256,viewFile); printf("(spoon2D) title=%s\n",title); if (!(doView2D->title = (char *)malloc((strlen(title)+1) * sizeof(char)))) { fprintf(stderr, "Ran out of memory (malloc) trying to get the title.\n"); exit(-1); } sprintf(doView2D->title,"%s",title); /* put in a null terminator over the newline that the fgets reads */ doView2D->title[strlen(doView2D->title)-1] = '\0'; fscanf(viewFile,"%d %d %d %d\n", &(doView2D->vX), &(doView2D->vY), &(doView2D->vW), &(doView2D->vH)); printf("(spoon2D) X=%d Y=%d W=%d H=%d \n", doView2D->vX,doView2D->vY,doView2D->vW,doView2D->vH); for (i=0; i> Out of memory trying to receive a graph.\n"); exit(-1); } graphArray[i].listOfListsOfPoints = aList; for (j=0; jnumberOfPoints)); printf("(spoon2d) number of points %d\n", aList->numberOfPoints); fscanf(graphFile,"%d %d %d\n", &(aList->pointColor), &(aList->lineColor), &(aList->pointSize)); printf("(spoon2d) pointColor=%d lineColor=%d pointSize=%d\n", aList->pointColor,aList->lineColor,aList->pointSize); if (!(aPoint = (pointStruct *)malloc(aList->numberOfPoints * sizeof(pointStruct)))) { fprintf(stderr,"viewAlone: Fatal Error>> Out of memory trying to receive a graph.\n"); exit(-1); } aList->listOfPoints = aPoint; /** point to current point list **/ for (k=0; knumberOfPoints; k++,aPoint++) { fscanf(graphFile,"%g %g %g %g\n", &(aPoint->x), &(aPoint->y), &(aPoint->hue), &(aPoint->shade)); printf("(spoon2d)k=%d x=%g y=%g hue=%g shade=%g\n", k,aPoint->x,aPoint->y,aPoint->hue,aPoint->shade); } } /* for j, aList */ fclose(graphFile); } /* else, opened up a file */ } /* if graph.key */ } /* for i */ } /* makeView2DFromFileData */