open-axiom repository from github
/*1Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.2All rights reserved.3Copyright (C) 2007-2013, 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 _FUN3D_C3637#include <stdlib.h>38#include <unistd.h>39#include <stdio.h>40#include <string.h>4142#include "open-axiom.h"43#include "viewman.h"44#include "mode.h"45#include "actions.h"4647#include "util.H1"48#include "sockio.h"49#include "fun3D.H1"50#include "make3D.H1"51#include "readView.H1"52#include "cfuns.h"5354using namespace OpenAxiom;5556void57funView3D(int viewCommand)58{5960int viewPID;61float f1,f2,f3,f4;62int i1,i2;63viewManager *viewport;6465viewPID = get_int(spadSock);6667viewport = viewports;68while ((viewport) && (viewport->PID != viewPID))69viewport = viewport->nextViewport;7071if (viewport) {72send_int(spadSock,1); /* acknowledge to spad */7374viewmanEvent.xclient.window = viewport->viewWindow;7576write(viewport->viewOut,&viewCommand,intSize);77switch (viewCommand) {78case rotate:79f1 = get_float(spadSock);80f2 = get_float(spadSock);81write(viewport->viewOut,&f1,floatSize);82write(viewport->viewOut,&f2,floatSize);83break;8485case zoom:86f1 = get_float(spadSock);87write(viewport->viewOut,&f1,floatSize);88break;8990case zoomx:91f1 = get_float(spadSock);92f2 = get_float(spadSock);93f3 = get_float(spadSock);94write(viewport->viewOut,&f1,floatSize);95write(viewport->viewOut,&f2,floatSize);96write(viewport->viewOut,&f3,floatSize);97break;9899case translate:100f1 = get_float(spadSock);101f2 = get_float(spadSock);102write(viewport->viewOut,&f1,floatSize);103write(viewport->viewOut,&f2,floatSize);104break;105106case modifyPOINT:107i1 = get_int(spadSock);108f1 = get_float(spadSock);109f2 = get_float(spadSock);110f3 = get_float(spadSock);111f4 = get_float(spadSock);112write(viewport->viewOut,&i1,intSize);113write(viewport->viewOut,&f1,floatSize);114write(viewport->viewOut,&f2,floatSize);115write(viewport->viewOut,&f3,floatSize);116write(viewport->viewOut,&f4,floatSize);117break;118119case hideControl:120i1 = get_int(spadSock);121write(viewport->viewOut,&i1,intSize);122break;123124case axesOnOff:125case perspectiveOnOff:126case region3D:127case clipRegionOnOff:128case clipSurfaceOnOff:129i1 = get_int(spadSock);130write(viewport->viewOut,&i1,intSize);131break;132133case eyeDistanceData:134case hitherPlaneData:135f1 = get_float(spadSock);136write(viewport->viewOut,&f1,floatSize);137break;138139case colorDef:140i1 = get_int(spadSock);141i2 = get_int(spadSock);142write(viewport->viewOut,&i1,intSize);143write(viewport->viewOut,&i2,intSize);144break;145146case moveViewport:147i1 = get_int(spadSock);148i2 = get_int(spadSock);149write(viewport->viewOut,&i1,intSize);150write(viewport->viewOut,&i2,intSize);151break;152153case resizeViewport:154i1 = get_int(spadSock);155i2 = get_int(spadSock);156write(viewport->viewOut,&i1,intSize);157write(viewport->viewOut,&i2,intSize);158break;159160case transparent:161case opaqueMesh:162case render:163break;164165case lightDef:166f1 = get_float(spadSock);167f2 = get_float(spadSock);168f3 = get_float(spadSock);169write(viewport->viewOut,&f1,floatSize);170write(viewport->viewOut,&f2,floatSize);171write(viewport->viewOut,&f3,floatSize);172break;173174case translucenceDef:175f1 = get_float(spadSock);176write(viewport->viewOut,&f1,floatSize);177break;178179180case changeTitle:181s1 = get_string(spadSock);182i1 = strlen(s1);183write(viewport->viewOut,&i1,intSize);184write(viewport->viewOut,s1,i1);185break;186187case writeView:188s1 = get_string(spadSock);189i1 = strlen(s1);190write(viewport->viewOut,&i1,intSize);191write(viewport->viewOut,s1,i1);192/* write out the types of things to be written */193i2 = get_int(spadSock);194write(viewport->viewOut,&i2,intSize);195while (i2) {196i2 = get_int(spadSock);197write(viewport->viewOut,&i2,intSize);198}199break;200201case diagOnOff:202i1 = get_int(spadSock);203write(viewport->viewOut,&i1,intSize);204break;205206case outlineOnOff:207i1 = get_int(spadSock);208write(viewport->viewOut,&i1,intSize);209break;210211case spadPressedAButton:212i1 = get_int(spadSock);213write(viewport->viewOut,&i1,intSize);214break;215} /* switch */216/*** get acknowledge from viewport */217218readViewport(viewport,&acknow,intSize);219send_int(spadSock,1); /* acknowledge to spad */220} else { /* if (viewport) */221send_int(spadSock,-1); /* send error value in acknowledge to spad */222}223224}225void226forkView3D(int typeOfViewport)227{228229viewManager *viewport;230int childPID, code;231int i;232233view3DStruct doView3D;234int pipe0[2],pipe1[2];235int *anIndex;236237char envAXIOM[100],runView[100];238int j,k;239LLPoint *anLLPoint;240LPoint *anLPoint;241242#ifdef DEBUG243fprintf(stderr,"Pipe calls for 3D\n");244#endif245check(pipe(pipe0));246check(pipe(pipe1));247248#ifdef DEBUG249fprintf(stderr,"Fork routine for 3D\n");250#endif251switch(childPID = check(fork())) {252253case -1:254printf("Cannot create a new process - you probably have too many things running already.\n");255return;256257case 0:258/*****************************259* child process *260*****************************/261/* map pipes from viewport manager to standard input and output */262#ifdef DEBUG263fprintf(stderr,"Mapping pipes to standard I/O in 3D\n");264#endif265check(dup2(pipe0[0],0));266check(dup2(pipe1[1],1));267close(pipe0[0]);268close(pipe0[1]);269close(pipe1[0]);270close(pipe1[1]);271272#ifdef DEBUG273fprintf(stderr,"Executing ThreeDimensionalViewport process\n");274#endif275sprintf(envAXIOM,"%s",oa_getenv("AXIOM"));276sprintf(runView,"%s%s",envAXIOM,"/lib/view3D");277check(execl(runView,runView, (char*) NULL));278fprintf(stderr,"The viewport manager could not execute view3D.\nCheck that view3D is on your PATH.\n");279exit(-1);280281default:282/******************************283* parent process *284******************************/285if (!(viewport = (viewManager *)malloc(sizeof(viewManager)))) {286printf("Ran out of memory trying to create a new viewport process.\n");287return;288}289viewport->viewType = typeOfViewport;290viewport->PID = childPID;291292/* set up pipes to child process */293close(pipe0[0]);294close(pipe1[1]);295viewport->viewIn = pipe1[0];296viewport->viewOut = pipe0[1];297298/* add new viewport to global list */299viewport->nextViewport = viewports;300viewports = viewport;301302if (viewport->viewIn <0) {303fprintf(stderr,304"The viewport manager could not create connection to a 3D viewport window. Try again.\n");305return;306} else {307308code = readViewport(viewport,&acknow,intSize);309310if (code < 0) {311fprintf(stderr,312"The viewport manager could not read from a 3D viewport window\ncode=%d\nack=%d\n",code,acknow);313return;314}315}316317makeView3DFromSpadData(&doView3D,typeOfViewport);318319/* tell the child that parent is a viewport manager */320i = no;321write(viewport->viewOut,&i,sizeof(int));322323write(viewport->viewOut,&doView3D,sizeof(view3DStruct));324325i = strlen(doView3D.title)+1;326write(viewport->viewOut,&i,intSize); /* tell the length of the title to child */327write(viewport->viewOut,doView3D.title,i); /* tell the title to the child */328write(viewport->viewOut,&(doView3D.lightVec[0]),floatSize);329write(viewport->viewOut,&(doView3D.lightVec[1]),floatSize);330write(viewport->viewOut,&(doView3D.lightVec[2]),floatSize);331332/* send generalized 3D components */333write(viewport->viewOut,&(doView3D.numOfPoints),intSize);334for (i=0; i<doView3D.numOfPoints; i++) {335write(viewport->viewOut,&(refPt(doView3D,i)->x),floatSize);336write(viewport->viewOut,&(refPt(doView3D,i)->y),floatSize);337write(viewport->viewOut,&(refPt(doView3D,i)->z),floatSize);338write(viewport->viewOut,&(refPt(doView3D,i)->c),floatSize);339}340write(viewport->viewOut,&(doView3D.lllp.numOfComponents),intSize);341anLLPoint = doView3D.lllp.llp;342for (i=0; i<doView3D.lllp.numOfComponents; i++,anLLPoint++) {343write(viewport->viewOut,&(anLLPoint->prop.closed),intSize);344write(viewport->viewOut,&(anLLPoint->prop.solid),intSize);345write(viewport->viewOut,&(anLLPoint->numOfLists),intSize);346anLPoint = anLLPoint->lp;347for (j=0; j<anLLPoint->numOfLists; j++,anLPoint++) {348write(viewport->viewOut,&(anLPoint->prop.closed),intSize);349write(viewport->viewOut,&(anLPoint->prop.solid),intSize);350write(viewport->viewOut,&(anLPoint->numOfPoints),intSize);351anIndex = anLPoint->indices;352for (k=0; k<anLPoint->numOfPoints; k++,anIndex++)353write(viewport->viewOut,anIndex,intSize);354} /* for LPoints in LLPoints (j) */355} /* for LLPoints in LLLPoints (i) */356357/*** get acknowledge from viewport */358code = readViewport(viewport,&(viewport->viewWindow),sizeof(Window));359openaxiom_sleep(1); /* wait a second...*/360send_int(spadSock,viewport->PID); /* acknowledge to spad */361362} /* switch */363364} /* forkView3D() */365366367368369