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 _VIEWMAN_C36#include "openaxiom-c-macros.h"3738#include <unistd.h>39#include <sys/time.h>40#include <stdlib.h>41#include <stdio.h>42#include <string.h>43#include "viewman.h"44#include "mode.h"45#include "actions.h"46#include "viewCommand.h"47#include "bsdsignal.h"484950#include "util.H1"51#include "sockio.h"52#include "fun2D.H1"53#include "fun3D.H1"54#include "makeGraph.H1"55#include "readView.H1"56#include "cleanup.H1"57#include "sselect.H1"5859using namespace OpenAxiom;6061/************* global variables **************/6263Display *dsply;64Window root;65XEvent viewmanEvent;66viewManager *viewports,67*slot,68*stepSlot;69openaxiom_sio* spadSock;70int viewType,71viewCommand,72acknow,73graphKey = 1,74defDsply,75currentGraph,76picked = no,77viewOkay = 0,78viewError = -1,79checkClosedChild = no,80foundBrokenPipe = no;81fd_set filedes;82graphStruct *graphList;83graphStateStruct currentGraphState;84const char* s1;85char propertyBuffer[256];/* XProperty buffer */868788int89main (void)90{9192graphStruct *aGraph;93int keepLooking,code;9495bsdSignal(SIGPIPE,brokenPipe,DontRestartSystemCalls);96bsdSignal(OPENAXIOM_SIGCHLD,endChild,RestartSystemCalls);97bsdSignal(SIGTERM,goodbye,DontRestartSystemCalls);9899/* Connect up to OpenAxiom server */100spadSock = connect_to_local_server(SpadServer,ViewportServer,Forever);101if (spadSock == NULL) {102fprintf(stderr,"The viewport manager couldn't connect to OpenAxiom\n");103exit(-1);104}105#ifdef DEBUG106else107fprintf(stderr,"viewman: Connected to OpenAxiom\n");108#endif109110/******** initialize ********/111viewports = 0;112graphList = 0;113114/******** getting stuff from spad and viewports ********115********* the viewports have priority over ****116*** OpenAxiom. ***/117while (1) {118FD_ZERO(&filedes); /* zero out file descriptor */119FD_SET(spadSock->socket,&filedes);120slot = viewports;121while (slot) {122FD_SET(slot->viewIn,&filedes);123slot = slot->nextViewport;124}125126#ifdef DEBUG127fprintf(stderr,"Selection for filedes of %x \n",filedes);128#endif129code = check(superSelect(FD_SETSIZE, &filedes,0,0,0));130for (;code<=0;)131code = check(superSelect(FD_SETSIZE, &filedes,0,0,0));132133slot = viewports;134keepLooking = 1;135while (keepLooking && slot) {136if (FD_ISSET(slot->viewIn,&filedes)) {137keepLooking = 0;138#ifdef DEBUG139fprintf(stderr,"Reading child viewport...\n");140#endif141readViewport(slot,&viewCommand,intSize);142143switch (viewCommand) {144145case pick2D:146#ifdef DEBUG147fprintf(stderr,"viewman: Doing 2D pick\n");148#endif149picked = yes;150151readViewport(slot,¤tGraph,intSize); /* get the graph to pick */152readViewport(slot,¤tGraphState,sizeof(graphStateStruct));153break;154155case drop2D:156#ifdef DEBUG157fprintf(stderr,"viewman: Doing 2D drop\n");158#endif159if (picked) {160write(slot->viewOut,&viewOkay,intSize);161write(slot->viewOut,¤tGraph,intSize);162sendGraphToView2D(0,currentGraph,slot,¤tGraphState);163} else {164write(slot->viewOut,&viewError,intSize);165fprintf(stderr,"The viewport manager cannot drop a graph because nothing has been picked yet.\n");166}167break;168169case viewportClosing:170#ifdef DEBUG171fprintf(stderr,"viewman: closing viewport\n");172#endif173closeChildViewport(slot);174break;175176}; /* switch */177178}; /* if reading slot->viewIn */179stepSlot = slot;180slot = slot->nextViewport;181}; /* while */182183if (keepLooking) { /* if 1 => slots not read, read from spad */184#ifdef DEBUG185fprintf(stderr,"viewman: still looking\n");186#endif187viewType = get_int(spadSock);188if (viewType == -1) goodbye(-1);189viewCommand = get_int(spadSock);190191switch (viewType) {192193case view3DType:194#ifdef DEBUG195fprintf(stderr,"viewman: making 3D viewport\n");196#endif197if (viewCommand == makeViewport)198forkView3D(view3DType);199else200funView3D(viewCommand);201202break;203204case viewTubeType:205#ifdef DEBUG206fprintf(stderr,"viewman: viewing a tube\n");207#endif208if (viewCommand == makeViewport)209forkView3D(viewTubeType);210else211funView3D(viewCommand);212213break;214215case viewGraphType:216#ifdef DEBUG217fprintf(stderr,"viewman: making a graph\n");218#endif219if (viewCommand == makeGraph) {220aGraph = makeGraphFromSpadData();221aGraph->nextGraph = graphList;222graphList = aGraph;223}224break;225226case view2DType:227#ifdef DEBUG228fprintf(stderr,"viewman: forking 2D\n");229#endif230if (viewCommand == makeViewport) {231forkView2D();232} else {233funView2D(viewCommand);234}235break;236237} /* switch on viewType */238} /* if (keepLooking) */239} /* while (1) */240}241242243244245246