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 _SPADACTION2D_C36#include "openaxiom-c-macros.h"3738#include <stdio.h>39#include <stdlib.h>40#include <unistd.h>4142#include "header2.h"4344#include "all_2d.H1"45#include "util.H1"464748/******************************49* int readViewman(info,size) *50******************************/5152int53readViewman(void * info,int size)54{55int mold = 0;5657sprintf(errorStr,"%s %d %s","read of ",size,58" bytes from viewport manager\n");59mold = check(read(0,info,size));60return(mold);6162}6364/********************65* int spadAction() *66********************/67extern int viewAloned;68int69spadAction(void)70{71int viewCommand;72float f1,f2;73int i1,i2,i3,viewGoAhead;74static int ack = 1;7576if (viewAloned==yes) {77close(0);78return(-1);79}80readViewman(&viewCommand,intSize);8182switch (viewCommand) {8384case hideControl2D:85readViewman(&i1,intSize);86if (i1) { /* show control panel */87if (viewport->haveControl) XUnmapWindow(dsply,control->controlWindow);88putControlPanelSomewhere(someInt);89} else { /* turn off control panel */90if (viewport->haveControl) {91viewport->haveControl = no;92XUnmapWindow(dsply,control->controlWindow);93}94}95break;9697case changeTitle:98readViewman(&i1,intSize);99readViewman(viewport->title,i1);100viewport->title[i1] = '\0';101writeTitle();102writeControlTitle();103XFlush(dsply);104spadDraw=no;105break;106107case writeView:108readViewman(&i1,intSize);109readViewman(filename,i1);110filename[i1] = '\0';111sprintf(errorStr,"writing of viewport data");112i3 = 0;113readViewman(&i2,intSize);114while (i2) {115i3 = i3 | (1<<i2);116readViewman(&i2,intSize);117}118if (writeViewport(i3) < 0)119fprintf(stderr," Nothing was written\n");120break;121122case closeAll2D:123check(write(Socket,&ack,intSize));124goodbye(-1);125126case ps2D:127readViewman(&i1,intSize);128buttonAction(viewCommand);129break;130131case axesOnOff2D:132readViewman(&i1,intSize);133i1--;134readViewman(&i2,intSize);135graphStateArray[i1].axesOn = i2;136if (graphStateArray[i1].showing) spadDraw=yes;137break;138139case axesColor2D:140readViewman(&i1,intSize);141i1--;142readViewman(&i2,intSize);143graphStateArray[i1].axesColor = i2;144if (graphStateArray[i1].showing) spadDraw=yes;145break;146147case unitsOnOff2D:148readViewman(&i1,intSize);149i1--;150readViewman(&i2,intSize);151graphStateArray[i1].unitsOn = i2;152if (graphStateArray[i1].showing) spadDraw=yes;153break;154155case unitsColor2D:156readViewman(&i1,intSize);157i1--;158readViewman(&i2,intSize);159graphStateArray[i1].unitsColor = i2;160if (graphStateArray[i1].showing) spadDraw=yes;161break;162163case connectOnOff:164readViewman(&i1,intSize);165i1--;166readViewman(&i2,intSize);167graphStateArray[i1].connectOn = i2;168if (graphStateArray[i1].showing) spadDraw=yes;169break;170171case pointsOnOff:172readViewman(&i1,intSize);173i1--;174readViewman(&i2,intSize);175graphStateArray[i1].pointsOn = i2;176if (graphStateArray[i1].showing) spadDraw=yes;177break;178179case spline2D:180readViewman(&i1,intSize);181i1--;182readViewman(&i2,intSize);183graphStateArray[i1].splineOn = i2;184if (graphStateArray[i1].showing) spadDraw=yes;185break;186187case showing2D:188readViewman(&i1,intSize);189i1--;190readViewman(&i2,intSize);191/* simulate a button press to turn display number on/off */192graphStateArray[i1].showing = !i2;193clickedOnGraph(i1,i1+graphStart);194break;195196case scale2D:197readViewman(&i1,intSize);198i1--; /* passed index is [1..9] but internal representation is [0..8] */199readViewman(&f1,floatSize);200readViewman(&f2,floatSize);201graphStateArray[i1].scaleX = f1;202graphStateArray[i1].scaleY = f2;203if (graphStateArray[i1].scaleX > maxScale)204graphStateArray[i1].scaleX = maxScale;205else206if (graphStateArray[i1].scaleX < minScale)207graphStateArray[i1].scaleX = minScale;208if (graphStateArray[i1].scaleY > maxScale)209graphStateArray[i1].scaleY = maxScale;210else211if (graphStateArray[i1].scaleY < minScale)212graphStateArray[i1].scaleY = minScale;213if (graphStateArray[i1].showing) spadDraw=yes;214break; /* scale2D */215216217case translate2D:218readViewman(&i1,intSize);219i1--; /* passed index is [1..9] but internal representation is [0..8] */220readViewman(&f1,floatSize);221readViewman(&f2,floatSize);222graphStateArray[i1].centerX = f1;223graphStateArray[i1].centerY = f2;224if (graphStateArray[i1].centerX > maxDelta)225graphStateArray[i1].centerX = maxDelta;226else if (graphStateArray[i1].centerX < -maxDelta)227graphStateArray[i1].centerX = maxDelta;228if (graphStateArray[i1].centerY > maxDelta)229graphStateArray[i1].centerY = maxDelta;230else if (graphStateArray[i1].centerY < -maxDelta)231graphStateArray[i1].centerY = maxDelta;232if (graphStateArray[i1].showing) spadDraw=yes;233break; /* translate2D */234235case moveViewport:236readViewman(&i1,intSize);237readViewman(&i2,intSize);238XMoveWindow(dsply,viewport->titleWindow,i1,i2);239XSync(dsply,False);240break;241242case resizeViewport:243readViewman(&i1,intSize);244readViewman(&i2,intSize);245XResizeWindow(dsply,viewport->titleWindow,i1,i2+titleHeight);246XResizeWindow(dsply,viewport->viewWindow,i1,i2);247spadDraw=yes;248break;249250case putGraph:251readViewman(&i1,intSize); /* key of graph to get */252readViewman(&i2,intSize); /* slot to drop graph onto 0..8*/253readViewman(&viewGoAhead,intSize);254if (viewGoAhead < 0) {255sprintf(control->message,"%s%d","Couldn't put into graph ",i2+1);256writeControlMessage();257} else {258sprintf(control->message,"%s%d","Dropped onto graph ",i2+1);259writeControlMessage();260freeGraph(i2);261graphArray[i2].key = i1;262getGraphFromViewman(i2);263/* simulate a button press to turn display number on and select on */264/* need !yes since it will be inverted */265graphStateArray[i2].selected = no;266graphStateArray[i2].connectOn = yes;267graphStateArray[i2].showing = !(graphStateArray[i2].showing);268clickedOnGraph(i2,i2+graphStart);269clickedOnGraphSelect(i2,i2+graphSelectStart);270}271break;272273case spadPressedAButton:274readViewman(&i1,intSize);275buttonAction(i1);276break;277278default:279return(-1);280} /* switch */281282283ack++;284check(write(Socket,&ack,intSize));285return(0);286287}288289290291