open-axiom repository from github
/*1Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.2All rights reserved.3Copyright (C) 2007-2008, Gabriel Dos Reis.4All rights reserved.56Redistribution and use in source and binary forms, with or without7modification, are permitted provided that the following conditions are8met:910- Redistributions of source code must retain the above copyright11notice, this list of conditions and the following disclaimer.1213- Redistributions in binary form must reproduce the above copyright14notice, this list of conditions and the following disclaimer in15the documentation and/or other materials provided with the16distribution.1718- Neither the name of The Numerical Algorithms Group Ltd. nor the19names of its contributors may be used to endorse or promote products20derived from this software without specific prior written permission.2122THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS23IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED24TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A25PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER26OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,27EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,28PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR29PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF30LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING31NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS32SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.33*/3435#define _SPOONCOMP_C3637#include <stdlib.h>38#include <unistd.h>39#include <string.h>4041#include "open-axiom.h"42#include "viewAlone.h"43#include "mode.h"4445#include "util.H1"46#include "cfuns.h"47#include "all_alone.H1"4849using namespace OpenAxiom;50515253/* This file forks a child process and exits the parent. It54has the same general form as ../viewman/funView3D() and so55changes there may require similar changes here. */5657void58spoonView3D(int type)59{6061int i,j,k,code,pipe0[2],pipe1[2];62char envAXIOM[100],runView[100];63LLPoint *anLLPoint;64LPoint *anLPoint;65int *anIndex;6667sprintf(errorStr,"%s","creating pipes");68check(pipe(pipe0));69check(pipe(pipe1));70switch(fork()) {71case -1:72fprintf(stderr,"can't create a child process\n");73fprintf(stderr,"you may have too many processes running\n");74exit(-1);75case 0:76/* Child */77sprintf(errorStr,"%s",78"(viewAlone) mapping of pipes to standard I/O for view3D");79check(dup2(pipe0[0],0));80check(dup2(pipe1[1],1));81close(pipe0[0]);82close(pipe0[1]);83close(pipe1[0]);84close(pipe1[1]);8586sprintf(errorStr,"%s",87"(viewAlone) execution of the ThreeDimensionalViewport process");88sprintf(envAXIOM,"%s",oa_getenv("AXIOM"));89sprintf(runView,"%s%s",envAXIOM,"/lib/view3D");90check(execl(runView,runView, (char*) NULL));91fprintf(stderr,"Could not execute view3D!\n");92exit(-1);93default:94/* Parent */9596viewP.viewType = type;9798/* set up pipes to child process */99close(pipe0[0]);100close(pipe1[1]);101viewP.viewIn = pipe1[0];102viewP.viewOut = pipe0[1];103104if (viewP.viewIn <0) {105fprintf(stderr,106"can't set up pipes to viewport process. Try again.\n");107return;108} else {109code = read(viewP.viewIn,&ack,intSize);110if (code < 0) {111fprintf(stderr,"can't read from viewport process pipe. Try again.\n");112return;113}114}115116makeView3DFromFileData(type);117/* tell child it is to be a stand alone program */118i = yes;119fprintf(stderr," Transmitting data to viewport...\n");120write(viewP.viewOut,&i,intSize);121write(viewP.viewOut,&doView3D,sizeof(view3DStruct));122i = strlen(doView3D.title)+1;123write(viewP.viewOut,&i,intSize); /* tell the length of124the title to child */125write(viewP.viewOut,doView3D.title,i); /* tell the title126to the child, child */127write(viewP.viewOut,&(doView3D.lightVec[0]),floatSize);128write(viewP.viewOut,&(doView3D.lightVec[1]),floatSize);129write(viewP.viewOut,&(doView3D.lightVec[2]),floatSize);130131write(viewP.viewOut,&(doView3D.numOfPoints),intSize);132for (i=0; i<doView3D.numOfPoints; i++) {133write(viewP.viewOut,&(refPt(doView3D,i)->x),floatSize);134write(viewP.viewOut,&(refPt(doView3D,i)->y),floatSize);135write(viewP.viewOut,&(refPt(doView3D,i)->z),floatSize);136write(viewP.viewOut,&(refPt(doView3D,i)->c),floatSize);137}138139/* send generalized 3D components */140write(viewP.viewOut,&(doView3D.lllp.numOfComponents),intSize);141anLLPoint = doView3D.lllp.llp;142for (i=0; i<doView3D.lllp.numOfComponents; i++,anLLPoint++) {143write(viewP.viewOut,&(anLLPoint->prop.closed),intSize);144write(viewP.viewOut,&(anLLPoint->prop.solid),intSize);145write(viewP.viewOut,&(anLLPoint->numOfLists),intSize);146anLPoint = anLLPoint->lp;147for (j=0; j<anLLPoint->numOfLists; j++,anLPoint++) {148write(viewP.viewOut,&(anLPoint->prop.closed),intSize);149write(viewP.viewOut,&(anLPoint->prop.solid),intSize);150write(viewP.viewOut,&(anLPoint->numOfPoints),intSize);151anIndex = anLPoint->indices;152for (k=0; k<anLPoint->numOfPoints; k++,anIndex++)153write(viewP.viewOut,anIndex,intSize);154} /* for LPoints in LLPoints (j) */155} /* for LLPoints in LLLPoints (i) */156fprintf(stderr," Done.\n");157158/*** get acknowledge from viewport */159code = read(viewP.viewIn,&(viewP.viewWindow),sizeof(Window));160openaxiom_sleep(1); /* wait a second...*/161exit(0);162163} /* switch */164165} /* spoonView3D() */166167168void169makeView3DFromFileData(int type)170{171172int i,j,k;173char title[256];174LLPoint *anLLPoint;175LPoint *anLPoint;176viewTriple *aPoint;177int *anIndex;178179/* fscanf(doView3D,""); */180/* read in the view3DStruct stuff */181/* &view3DType already read */182doView3D.typeOf3D = type;183fscanf(viewFile,"%f %f %f %f %f %f\n",184&(doView3D.xmin),185&(doView3D.xmax),186&(doView3D.ymin),187&(doView3D.ymax),188&(doView3D.zmin),189&(doView3D.zmax));190191fgets(title,256,viewFile);192if (!(doView3D.title = (char *)malloc((strlen(title)+1) *193sizeof(char)))) {194fprintf(stderr,"Ran out of memory (malloc) trying to get the title.\n");195exit(-1);196}197sprintf(doView3D.title,"%s",title);198/* put in a null terminator over the newline that the fgets reads */199doView3D.title[strlen(doView3D.title)-1] = '\0';200201fscanf(viewFile,"%f %f %f %f %f %f %f %f\n",202&(doView3D.deltaX),203&(doView3D.deltaY),204&(doView3D.scale),205&(doView3D.scaleX),206&(doView3D.scaleY),207&(doView3D.scaleZ),208&(doView3D.theta),209&(doView3D.phi));210211fscanf(viewFile,"%d %d %d %d\n",212&(doView3D.vX),213&(doView3D.vY),214&(doView3D.vW),215&(doView3D.vH));216fscanf(viewFile,"%d %d %d %d %d %d %d\n",217&(doView3D.showCP),218&(doView3D.style),219&(doView3D.AxesOn),220&(doView3D.hueOff),221&(doView3D.numOfHues),222&(doView3D.diagonals),223&(doView3D.outlineRenderOn));224fscanf(viewFile,"%f %f %f %f\n",225&(doView3D.lightVec[0]),226&(doView3D.lightVec[1]),227&(doView3D.lightVec[2]),228&(doView3D.translucency));229fscanf(viewFile,"%d %f\n",230&(doView3D.perspective),231&(doView3D.eyeDistance));232233/* get generalized 3D components */234235fscanf(viewFile,"%d\n",236&(doView3D.numOfPoints));237aPoint = doView3D.points = (viewTriple *)malloc(doView3D.numOfPoints*238sizeof(viewTriple));239for (i=0; i<doView3D.numOfPoints; i++, aPoint++)240fscanf(viewFile,"%g %g %g %g\n",241&(aPoint->x),242&(aPoint->y),243&(aPoint->z),244&(aPoint->c));245fscanf(viewFile,"%d\n",246&(doView3D.lllp.numOfComponents));247anLLPoint = doView3D.lllp.llp =248(LLPoint *)malloc(doView3D.lllp.numOfComponents*sizeof(LLPoint));249for (i=0; i<doView3D.lllp.numOfComponents; i++,anLLPoint++) {250fscanf(viewFile,"%d %d\n",251&(anLLPoint->prop.closed),252&(anLLPoint->prop.solid));253fscanf(viewFile,"%d\n",254&(anLLPoint->numOfLists));255anLPoint = anLLPoint->lp =256(LPoint *)malloc(anLLPoint->numOfLists*sizeof(LPoint));257for (j=0; j<anLLPoint->numOfLists; j++,anLPoint++) {258fscanf(viewFile,"%d %d\n",259&(anLPoint->prop.closed),260&(anLPoint->prop.solid));261fscanf(viewFile,"%d\n",262&(anLPoint->numOfPoints));263anIndex = anLPoint->indices =264(int *)malloc(anLPoint->numOfPoints*sizeof(int));265for (k=0; k<anLPoint->numOfPoints; k++,anIndex++) {266fscanf(viewFile,"%dn",anIndex);267} /* for points in LPoints (k) */268} /* for LPoints in LLPoints (j) */269} /* for LLPoints in LLLPoints (i) */270271fclose(viewFile);272doView3D.scaleDown = no ;273}274275276277