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 _VIEWMAN_C
37
#include "openaxiom-c-macros.h"
38
39
#include <unistd.h>
40
#include <sys/time.h>
41
#include <stdlib.h>
42
#include <stdio.h>
43
#include <string.h>
44
#include "viewman.h"
45
#include "mode.h"
46
#include "actions.h"
47
#include "viewCommand.h"
48
#include "bsdsignal.h"
49
50
51
#include "util.H1"
52
#include "sockio.h"
53
#include "fun2D.H1"
54
#include "fun3D.H1"
55
#include "makeGraph.H1"
56
#include "readView.H1"
57
#include "cleanup.H1"
58
#include "sselect.H1"
59
60
using namespace OpenAxiom;
61
62
/************* global variables **************/
63
64
Display *dsply;
65
Window root;
66
XEvent viewmanEvent;
67
viewManager *viewports,
68
*slot,
69
*stepSlot;
70
openaxiom_sio* spadSock;
71
int viewType,
72
viewCommand,
73
acknow,
74
graphKey = 1,
75
defDsply,
76
currentGraph,
77
picked = no,
78
viewOkay = 0,
79
viewError = -1,
80
checkClosedChild = no,
81
foundBrokenPipe = no;
82
fd_set filedes;
83
graphStruct *graphList;
84
graphStateStruct currentGraphState;
85
const char* s1;
86
char propertyBuffer[256];/* XProperty buffer */
87
88
89
int
90
main (void)
91
{
92
93
graphStruct *aGraph;
94
int keepLooking,code;
95
96
bsdSignal(SIGPIPE,brokenPipe,DontRestartSystemCalls);
97
bsdSignal(OPENAXIOM_SIGCHLD,endChild,RestartSystemCalls);
98
bsdSignal(SIGTERM,goodbye,DontRestartSystemCalls);
99
100
/* Connect up to OpenAxiom server */
101
spadSock = connect_to_local_server(SpadServer,ViewportServer,Forever);
102
if (spadSock == NULL) {
103
fprintf(stderr,"The viewport manager couldn't connect to OpenAxiom\n");
104
exit(-1);
105
}
106
#ifdef DEBUG
107
else
108
fprintf(stderr,"viewman: Connected to OpenAxiom\n");
109
#endif
110
111
/******** initialize ********/
112
viewports = 0;
113
graphList = 0;
114
115
/******** getting stuff from spad and viewports ********
116
********* the viewports have priority over ****
117
*** OpenAxiom. ***/
118
while (1) {
119
FD_ZERO(&filedes); /* zero out file descriptor */
120
FD_SET(spadSock->socket,&filedes);
121
slot = viewports;
122
while (slot) {
123
FD_SET(slot->viewIn,&filedes);
124
slot = slot->nextViewport;
125
}
126
127
#ifdef DEBUG
128
fprintf(stderr,"Selection for filedes of %x \n",filedes);
129
#endif
130
code = check(superSelect(FD_SETSIZE, &filedes,0,0,0));
131
for (;code<=0;)
132
code = check(superSelect(FD_SETSIZE, &filedes,0,0,0));
133
134
slot = viewports;
135
keepLooking = 1;
136
while (keepLooking && slot) {
137
if (FD_ISSET(slot->viewIn,&filedes)) {
138
keepLooking = 0;
139
#ifdef DEBUG
140
fprintf(stderr,"Reading child viewport...\n");
141
#endif
142
readViewport(slot,&viewCommand,intSize);
143
144
switch (viewCommand) {
145
146
case pick2D:
147
#ifdef DEBUG
148
fprintf(stderr,"viewman: Doing 2D pick\n");
149
#endif
150
picked = yes;
151
152
readViewport(slot,&currentGraph,intSize); /* get the graph to pick */
153
readViewport(slot,&currentGraphState,sizeof(graphStateStruct));
154
break;
155
156
case drop2D:
157
#ifdef DEBUG
158
fprintf(stderr,"viewman: Doing 2D drop\n");
159
#endif
160
if (picked) {
161
write(slot->viewOut,&viewOkay,intSize);
162
write(slot->viewOut,&currentGraph,intSize);
163
sendGraphToView2D(0,currentGraph,slot,&currentGraphState);
164
} else {
165
write(slot->viewOut,&viewError,intSize);
166
fprintf(stderr,"The viewport manager cannot drop a graph because nothing has been picked yet.\n");
167
}
168
break;
169
170
case viewportClosing:
171
#ifdef DEBUG
172
fprintf(stderr,"viewman: closing viewport\n");
173
#endif
174
closeChildViewport(slot);
175
break;
176
177
}; /* switch */
178
179
}; /* if reading slot->viewIn */
180
stepSlot = slot;
181
slot = slot->nextViewport;
182
}; /* while */
183
184
if (keepLooking) { /* if 1 => slots not read, read from spad */
185
#ifdef DEBUG
186
fprintf(stderr,"viewman: still looking\n");
187
#endif
188
viewType = get_int(spadSock);
189
if (viewType == -1) goodbye(-1);
190
viewCommand = get_int(spadSock);
191
192
switch (viewType) {
193
194
case view3DType:
195
#ifdef DEBUG
196
fprintf(stderr,"viewman: making 3D viewport\n");
197
#endif
198
if (viewCommand == makeViewport)
199
forkView3D(view3DType);
200
else
201
funView3D(viewCommand);
202
203
break;
204
205
case viewTubeType:
206
#ifdef DEBUG
207
fprintf(stderr,"viewman: viewing a tube\n");
208
#endif
209
if (viewCommand == makeViewport)
210
forkView3D(viewTubeType);
211
else
212
funView3D(viewCommand);
213
214
break;
215
216
case viewGraphType:
217
#ifdef DEBUG
218
fprintf(stderr,"viewman: making a graph\n");
219
#endif
220
if (viewCommand == makeGraph) {
221
aGraph = makeGraphFromSpadData();
222
aGraph->nextGraph = graphList;
223
graphList = aGraph;
224
}
225
break;
226
227
case view2DType:
228
#ifdef DEBUG
229
fprintf(stderr,"viewman: forking 2D\n");
230
#endif
231
if (viewCommand == makeViewport) {
232
forkView2D();
233
} else {
234
funView2D(viewCommand);
235
}
236
break;
237
238
} /* switch on viewType */
239
} /* if (keepLooking) */
240
} /* while (1) */
241
}
242
243
244
245
246