Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
/*
2
Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.
3
All rights reserved.
4
Copyright (C) 2007-2008, Gabriel Dos Reis.
5
All rights reserved.
6
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are
9
met:
10
11
- Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
14
- Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in
16
the documentation and/or other materials provided with the
17
distribution.
18
19
- Neither the name of The Numerical Algorithms Group Ltd. nor the
20
names of its contributors may be used to endorse or promote products
21
derived from this software without specific prior written permission.
22
23
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*/
35
36
#define _SPADACTION2D_C
37
#include "openaxiom-c-macros.h"
38
39
#include <stdio.h>
40
#include <stdlib.h>
41
#include <unistd.h>
42
43
#include "header2.h"
44
45
#include "all_2d.H1"
46
#include "util.H1"
47
48
49
/******************************
50
* int readViewman(info,size) *
51
******************************/
52
53
int
54
readViewman(void * info,int size)
55
{
56
int mold = 0;
57
58
sprintf(errorStr,"%s %d %s","read of ",size,
59
" bytes from viewport manager\n");
60
mold = check(read(0,info,size));
61
return(mold);
62
63
}
64
65
/********************
66
* int spadAction() *
67
********************/
68
extern int viewAloned;
69
int
70
spadAction(void)
71
{
72
int viewCommand;
73
float f1,f2;
74
int i1,i2,i3,viewGoAhead;
75
static int ack = 1;
76
77
if (viewAloned==yes) {
78
close(0);
79
return(-1);
80
}
81
readViewman(&viewCommand,intSize);
82
83
switch (viewCommand) {
84
85
case hideControl2D:
86
readViewman(&i1,intSize);
87
if (i1) { /* show control panel */
88
if (viewport->haveControl) XUnmapWindow(dsply,control->controlWindow);
89
putControlPanelSomewhere(someInt);
90
} else { /* turn off control panel */
91
if (viewport->haveControl) {
92
viewport->haveControl = no;
93
XUnmapWindow(dsply,control->controlWindow);
94
}
95
}
96
break;
97
98
case changeTitle:
99
readViewman(&i1,intSize);
100
readViewman(viewport->title,i1);
101
viewport->title[i1] = '\0';
102
writeTitle();
103
writeControlTitle();
104
XFlush(dsply);
105
spadDraw=no;
106
break;
107
108
case writeView:
109
readViewman(&i1,intSize);
110
readViewman(filename,i1);
111
filename[i1] = '\0';
112
sprintf(errorStr,"writing of viewport data");
113
i3 = 0;
114
readViewman(&i2,intSize);
115
while (i2) {
116
i3 = i3 | (1<<i2);
117
readViewman(&i2,intSize);
118
}
119
if (writeViewport(i3) < 0)
120
fprintf(stderr," Nothing was written\n");
121
break;
122
123
case closeAll2D:
124
check(write(Socket,&ack,intSize));
125
goodbye(-1);
126
127
case ps2D:
128
readViewman(&i1,intSize);
129
buttonAction(viewCommand);
130
break;
131
132
case axesOnOff2D:
133
readViewman(&i1,intSize);
134
i1--;
135
readViewman(&i2,intSize);
136
graphStateArray[i1].axesOn = i2;
137
if (graphStateArray[i1].showing) spadDraw=yes;
138
break;
139
140
case axesColor2D:
141
readViewman(&i1,intSize);
142
i1--;
143
readViewman(&i2,intSize);
144
graphStateArray[i1].axesColor = i2;
145
if (graphStateArray[i1].showing) spadDraw=yes;
146
break;
147
148
case unitsOnOff2D:
149
readViewman(&i1,intSize);
150
i1--;
151
readViewman(&i2,intSize);
152
graphStateArray[i1].unitsOn = i2;
153
if (graphStateArray[i1].showing) spadDraw=yes;
154
break;
155
156
case unitsColor2D:
157
readViewman(&i1,intSize);
158
i1--;
159
readViewman(&i2,intSize);
160
graphStateArray[i1].unitsColor = i2;
161
if (graphStateArray[i1].showing) spadDraw=yes;
162
break;
163
164
case connectOnOff:
165
readViewman(&i1,intSize);
166
i1--;
167
readViewman(&i2,intSize);
168
graphStateArray[i1].connectOn = i2;
169
if (graphStateArray[i1].showing) spadDraw=yes;
170
break;
171
172
case pointsOnOff:
173
readViewman(&i1,intSize);
174
i1--;
175
readViewman(&i2,intSize);
176
graphStateArray[i1].pointsOn = i2;
177
if (graphStateArray[i1].showing) spadDraw=yes;
178
break;
179
180
case spline2D:
181
readViewman(&i1,intSize);
182
i1--;
183
readViewman(&i2,intSize);
184
graphStateArray[i1].splineOn = i2;
185
if (graphStateArray[i1].showing) spadDraw=yes;
186
break;
187
188
case showing2D:
189
readViewman(&i1,intSize);
190
i1--;
191
readViewman(&i2,intSize);
192
/* simulate a button press to turn display number on/off */
193
graphStateArray[i1].showing = !i2;
194
clickedOnGraph(i1,i1+graphStart);
195
break;
196
197
case scale2D:
198
readViewman(&i1,intSize);
199
i1--; /* passed index is [1..9] but internal representation is [0..8] */
200
readViewman(&f1,floatSize);
201
readViewman(&f2,floatSize);
202
graphStateArray[i1].scaleX = f1;
203
graphStateArray[i1].scaleY = f2;
204
if (graphStateArray[i1].scaleX > maxScale)
205
graphStateArray[i1].scaleX = maxScale;
206
else
207
if (graphStateArray[i1].scaleX < minScale)
208
graphStateArray[i1].scaleX = minScale;
209
if (graphStateArray[i1].scaleY > maxScale)
210
graphStateArray[i1].scaleY = maxScale;
211
else
212
if (graphStateArray[i1].scaleY < minScale)
213
graphStateArray[i1].scaleY = minScale;
214
if (graphStateArray[i1].showing) spadDraw=yes;
215
break; /* scale2D */
216
217
218
case translate2D:
219
readViewman(&i1,intSize);
220
i1--; /* passed index is [1..9] but internal representation is [0..8] */
221
readViewman(&f1,floatSize);
222
readViewman(&f2,floatSize);
223
graphStateArray[i1].centerX = f1;
224
graphStateArray[i1].centerY = f2;
225
if (graphStateArray[i1].centerX > maxDelta)
226
graphStateArray[i1].centerX = maxDelta;
227
else if (graphStateArray[i1].centerX < -maxDelta)
228
graphStateArray[i1].centerX = maxDelta;
229
if (graphStateArray[i1].centerY > maxDelta)
230
graphStateArray[i1].centerY = maxDelta;
231
else if (graphStateArray[i1].centerY < -maxDelta)
232
graphStateArray[i1].centerY = maxDelta;
233
if (graphStateArray[i1].showing) spadDraw=yes;
234
break; /* translate2D */
235
236
case moveViewport:
237
readViewman(&i1,intSize);
238
readViewman(&i2,intSize);
239
XMoveWindow(dsply,viewport->titleWindow,i1,i2);
240
XSync(dsply,False);
241
break;
242
243
case resizeViewport:
244
readViewman(&i1,intSize);
245
readViewman(&i2,intSize);
246
XResizeWindow(dsply,viewport->titleWindow,i1,i2+titleHeight);
247
XResizeWindow(dsply,viewport->viewWindow,i1,i2);
248
spadDraw=yes;
249
break;
250
251
case putGraph:
252
readViewman(&i1,intSize); /* key of graph to get */
253
readViewman(&i2,intSize); /* slot to drop graph onto 0..8*/
254
readViewman(&viewGoAhead,intSize);
255
if (viewGoAhead < 0) {
256
sprintf(control->message,"%s%d","Couldn't put into graph ",i2+1);
257
writeControlMessage();
258
} else {
259
sprintf(control->message,"%s%d","Dropped onto graph ",i2+1);
260
writeControlMessage();
261
freeGraph(i2);
262
graphArray[i2].key = i1;
263
getGraphFromViewman(i2);
264
/* simulate a button press to turn display number on and select on */
265
/* need !yes since it will be inverted */
266
graphStateArray[i2].selected = no;
267
graphStateArray[i2].connectOn = yes;
268
graphStateArray[i2].showing = !(graphStateArray[i2].showing);
269
clickedOnGraph(i2,i2+graphStart);
270
clickedOnGraphSelect(i2,i2+graphSelectStart);
271
}
272
break;
273
274
case spadPressedAButton:
275
readViewman(&i1,intSize);
276
buttonAction(i1);
277
break;
278
279
default:
280
return(-1);
281
} /* switch */
282
283
284
ack++;
285
check(write(Socket,&ack,intSize));
286
return(0);
287
288
}
289
290
291