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-2011, 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 _MAIN2D_C
37
#include "openaxiom-c-macros.h"
38
39
#include <string.h>
40
#include <stdlib.h>
41
#include <stdio.h>
42
#include <unistd.h>
43
#include <signal.h>
44
45
#include "cfuns.h"
46
#include "header2.h"
47
#include "bsdsignal.h"
48
#include "globals2.h"
49
#include "all_2d.H1"
50
#include "Gfun.H1"
51
#include "util.H1"
52
#include "XSpadFill.h"
53
54
using namespace OpenAxiom;
55
56
57
/**********************/
58
/** global variables **/
59
/**********************/
60
Window rtWindow,viewman;
61
Display *dsply;
62
XFontStruct *globalFont,
63
*buttonFont,
64
*headerFont,
65
*titleFont,
66
*graphFont,
67
*unitFont,
68
*serverFont;
69
GC globalGC1,
70
globalGC2,
71
anotherGC,
72
globGC,
73
trashGC,
74
controlMessageGC,
75
graphGC,
76
unitGC,
77
processGC;
78
XGCValues gcVals;
79
HashTable *table;
80
Colormap colorMap;
81
82
XrmDatabase rDB; /* Resource database */
83
84
85
char scaleXReport[5],
86
scaleYReport[5],
87
deltaXReport[5],
88
deltaYReport[5],
89
errorStr[80],
90
filename[256], /** For writing viewport data out to a file **/
91
*xDefault; /** used for accessing .XDefaults **/
92
const char* s;
93
94
95
unsigned long *spadColors;
96
unsigned long foregroundColor, backgroundColor;
97
98
int followMouse = no,
99
viewportKeyNum = 0,
100
scrn,
101
Socket = 1,
102
ack = 1,
103
someInt,
104
drawMore,
105
spadMode=no, /* yes if receiving OpenAxiom command and calling drawViewport */
106
spadDraw=no, /* yes if drawing viewport because of a OpenAxiom command */
107
pointsON = yes, /* these would affect the choices in buttons.c */
108
connectON = yes,
109
splineON = no,
110
axesON = yes,
111
unitsON = no,
112
zoomXON = yes,
113
zoomYON = yes,
114
transXON = yes,
115
transYON = yes,
116
currentGraph = 0, /* last graph selected */
117
queriedGraph = 0, /* current graph queried */
118
picking=0,
119
dropping=0,
120
viewAloned, /** if not connected to OpenAxiom **/
121
mono,
122
totalColors,
123
totalSolid,
124
totalDithered,
125
maxGreyShade,
126
totalHues,
127
totalSolidShades,
128
totalDitheredAndSolids,
129
totalShades;
130
/* totalShades is initially set to totalShadesConst (probably 8).
131
If X cannot allocate 8 shades for each hue, totalShades is
132
decremented. There is currently only a check for this value
133
to be positive. ---> something to add: change over to monochrome
134
if totalShades=0. Just modify the spadcolors.c file.
135
spadcolors.c has been modified so that it returns the value for
136
totalShades. Since the return value had previously been unused,
137
a modification in this way ensures continued support of other
138
routines calling this function (e.g. hyperDoc stuff). */
139
140
viewPoints *viewport;
141
controlPanelStruct *control;
142
jmp_buf jumpFlag;
143
graphStruct graphArray[maxGraphs];
144
graphStateStruct graphStateArray[maxGraphs],
145
graphStateBackupArray[maxGraphs];
146
xPointStruct xPointsArray[maxGraphs];
147
float aspectR = 1.0;
148
/* global ps variables */
149
int psInit=no; /* need to call globalInitPs() each run */
150
GCptr GChead=NULL; /* ptr to head of ps GC linked list */
151
char *PSfilename, /* output file name used in user directory */
152
*envAXIOM; /* used as ps file pathnames */
153
154
int
155
main(void)
156
{
157
158
XGCValues controlGCVals;
159
int i;
160
view2DStruct viewData;
161
162
char property[256];
163
char *prop = &property[0];
164
char *str_type[20];
165
XrmValue value;
166
167
168
/**** Set up display ****/
169
if ((dsply = XOpenDisplay(oa_getenv("DISPLAY"))) == NULL)
170
fprintf(stderr,"Could not open the display.\n");
171
scrn = DefaultScreen(dsply);
172
rtWindow = RootWindow(dsply,scrn);
173
174
/**** link Xwindows to viewports - X10 feature ****/
175
table = XCreateAssocTable(nbuckets);
176
177
/**** Create OpenAxiom color map ****/
178
totalColors = XInitSpadFill(dsply,scrn,&colorMap,
179
&totalHues,&totalSolidShades,
180
&totalDitheredAndSolids,&totalShades);
181
182
if (totalColors < 0) {
183
fprintf(stderr,">>Error: Could not allocate all the necessary colors.\n");
184
exitWithAck(RootWindow(dsply,scrn),Window,-1);
185
}
186
187
mergeDatabases();
188
189
190
/*** Determine whether monochrome or color is used ***/
191
if (XrmGetResource(rDB,"Axiom.2D.monochrome","",str_type,&value) == True)
192
(void) strncpy(prop,value.addr,(int)value.size);
193
else
194
(void) strcpy(prop, "off");
195
196
mono = ((totalSolid == 2) || (strcmp(prop,"on") == 0));
197
198
if (XrmGetResource(rDB,"Axiom.2D.inverse","",str_type,&value) == True)
199
(void) strncpy(prop,value.addr,(int)value.size);
200
else
201
(void) strcpy(prop, "off");
202
203
if (mono)
204
if (strcmp(prop,"on") == 0) { /* 0 if equal (inverse video) */
205
foregroundColor = WhitePixel(dsply,scrn);
206
backgroundColor = BlackPixel(dsply,scrn);
207
} else { /* off (no inverse video) */
208
foregroundColor = BlackPixel(dsply,scrn);
209
backgroundColor = WhitePixel(dsply,scrn);
210
}
211
else /* inverse of inverse in color (for some strange reason) */
212
if (strcmp(prop,"on") == 0) { /* 0 if equal (inverse video) */
213
foregroundColor = WhitePixel(dsply,scrn);
214
backgroundColor = BlackPixel(dsply,scrn);
215
} else { /* off (no inverse video) */
216
foregroundColor = BlackPixel(dsply,scrn);
217
backgroundColor = WhitePixel(dsply,scrn);
218
}
219
220
221
/* read default file name for postScript output */
222
if (XrmGetResource(rDB,
223
"Axiom.2D.postscriptFile",
224
"",
225
str_type, &value) == True)
226
(void) strncpy(prop,value.addr,(int)value.size);
227
else
228
(void) strcpy(prop, "axiom2D.ps");
229
230
PSfilename = (char *)malloc(strlen(prop)+1);
231
strcpy(PSfilename,prop);
232
233
234
235
/**** Open global fonts ****/
236
serverFont = XQueryFont(dsply,XGContextFromGC(DefaultGC(dsply,scrn)));
237
238
if (XrmGetResource(rDB,
239
"Axiom.2D.messageFont",
240
"Axiom.2D.Font",
241
str_type, &value) == True)
242
(void) strncpy(prop,value.addr,(int)value.size);
243
else
244
(void) strcpy(prop,messageFontDefault);
245
if ((globalFont = XLoadQueryFont(dsply, prop)) == NULL) {
246
fprintf(stderr,
247
"Warning: could not get the %s font for messageFont\n",prop);
248
globalFont = serverFont;
249
}
250
251
if (XrmGetResource(rDB,
252
"Axiom.2D.buttonFont",
253
"Axiom.2D.Font",
254
str_type, &value) == True)
255
(void) strncpy(prop,value.addr,(int)value.size);
256
else
257
(void) strcpy(prop,buttonFontDefault);
258
if ((buttonFont = XLoadQueryFont(dsply, prop)) == NULL) {
259
fprintf(stderr,
260
"Warning: could not get the %s font for buttonFont\n",prop);
261
buttonFont = serverFont;
262
}
263
264
if (XrmGetResource(rDB,
265
"Axiom.2D.headerFont",
266
"Axiom.2D.Font",
267
str_type, &value) == True)
268
(void) strncpy(prop,value.addr,(int)value.size);
269
else
270
(void) strcpy(prop,headerFontDefault);
271
272
if ((headerFont = XLoadQueryFont(dsply, prop)) == NULL) {
273
fprintf(stderr,
274
"Warning: could not get the %s font for headerFont\n",prop);
275
headerFont = serverFont;
276
}
277
278
if (XrmGetResource(rDB,
279
"Axiom.2D.titleFont",
280
"Axiom.2D.Font",
281
str_type,&value) == True)
282
(void) strncpy(prop,value.addr,(int)value.size);
283
else
284
(void) strcpy(prop,titleFontDefault);
285
286
if ((titleFont = XLoadQueryFont(dsply, prop)) == NULL) {
287
fprintf(stderr,
288
"Warning: could not get the %s font for titleFont\n",prop);
289
titleFont = serverFont;
290
}
291
292
if (XrmGetResource(rDB,
293
"Axiom.2D.graphFont",
294
"Axiom.2D.Font",
295
str_type,&value) == True)
296
(void) strncpy(prop,value.addr,(int)value.size);
297
else
298
(void) strcpy(prop,graphFontDefault);
299
300
if ((graphFont = XLoadQueryFont(dsply, prop)) == NULL) {
301
fprintf(stderr,
302
"Warning: could not get the %s font for graphFont\n",prop);
303
graphFont = serverFont;
304
}
305
306
if (XrmGetResource(rDB,
307
"Axiom.2D.unitFont",
308
"Axiom.2D.Font",
309
str_type,&value) == True)
310
(void) strncpy(prop,value.addr,(int)value.size);
311
else
312
(void) strcpy(prop,unitFontDefault);
313
314
if ((unitFont = XLoadQueryFont(dsply, prop)) == NULL) {
315
fprintf(stderr,
316
"Warning: could not get the %s font for unitFont\n",prop);
317
unitFont = serverFont;
318
}
319
320
321
/**** Create widely used Graphic Contexts ****/
322
PSGlobalInit();
323
/* must initiate before using any G/PS functions
324
need character name: used as postscript GC variable
325
need to create ps GCs for all GCs used by drawings in viewWindow */
326
327
/* globalGC1 */
328
329
controlGCVals.foreground = monoColor(axesColorDefault);
330
controlGCVals.background = backgroundColor;
331
globalGC1 = XCreateGC(dsply,rtWindow,GCForeground | GCBackground ,
332
&controlGCVals);
333
carefullySetFont(globalGC1,globalFont);
334
335
336
/* create the equivalent GCs for ps */
337
PSCreateContext(globalGC1, "globalGC1", psNormalWidth, psButtCap,
338
psMiterJoin, psWhite, psBlack);
339
340
/* controlMessageGC */
341
342
controlGCVals.foreground = controlMessageColor;
343
controlMessageGC = XCreateGC(dsply,rtWindow,GCForeground | GCBackground
344
,&controlGCVals);
345
carefullySetFont(controlMessageGC,globalFont);
346
347
/* globalGC2 */
348
349
controlGCVals.foreground = monoColor(labelColor);
350
controlGCVals.background = backgroundColor;
351
globalGC2 = XCreateGC(dsply,rtWindow,GCForeground | GCBackground,
352
&controlGCVals);
353
carefullySetFont(globalGC2,buttonFont);
354
PSCreateContext(globalGC2, "globalGC2", psNormalWidth, psButtCap,
355
psMiterJoin, psWhite, psBlack);
356
357
/* trashGC */
358
359
trashGC = XCreateGC(dsply,rtWindow,0,&controlGCVals);
360
carefullySetFont(trashGC,buttonFont);
361
PSCreateContext(trashGC, "trashGC", psNormalWidth, psButtCap,
362
psMiterJoin, psWhite, psBlack);
363
364
/* globGC */
365
366
globGC = XCreateGC(dsply,rtWindow,0,&controlGCVals);
367
carefullySetFont(globGC,headerFont);
368
PSCreateContext(globGC, "globGC", psNormalWidth, psButtCap,
369
psMiterJoin, psWhite, psBlack);
370
371
/* anotherGC */
372
373
controlGCVals.line_width = colorWidth;
374
anotherGC = XCreateGC(dsply,rtWindow,GCBackground,&controlGCVals);
375
carefullySetFont(anotherGC,titleFont);
376
PSCreateContext(anotherGC, "anotherGC", psNormalWidth, psButtCap,
377
psMiterJoin, psWhite, psBlack);
378
379
/* processGC */
380
381
gcVals.background = backgroundColor;
382
processGC = XCreateGC(dsply,rtWindow,GCBackground ,&gcVals);
383
carefullySetFont(processGC,buttonFont);
384
385
/* graphGC */
386
387
graphGC = XCreateGC(dsply,rtWindow,GCBackground,&gcVals);
388
carefullySetFont(graphGC,graphFont);
389
PSCreateContext(graphGC, "graphGC", psNormalWidth, psButtCap,
390
psMiterJoin, psWhite, psBlack);
391
392
/* unitGC */
393
394
unitGC = XCreateGC(dsply,rtWindow,GCBackground ,&gcVals);
395
carefullySetFont(unitGC,unitFont);
396
PSCreateContext(unitGC, "unitGC", psNormalWidth, psButtCap,
397
psMiterJoin, psWhite, psBlack);
398
399
/**** Initialize Graph States ****/
400
401
for (i=0; i<maxGraphs; i++) {
402
graphStateArray[i].scaleX = 0.9;
403
graphStateArray[i].scaleY = 0.9;
404
graphStateArray[i].deltaX = 0.0;
405
graphStateArray[i].deltaY = 0.0;
406
graphStateArray[i].centerX = 0.0;
407
graphStateArray[i].centerY = 0.0;
408
graphStateArray[i].pointsOn = yes;
409
graphStateArray[i].connectOn = yes;
410
graphStateArray[i].splineOn = no;
411
graphStateArray[i].axesOn = yes;
412
graphStateArray[i].unitsOn = no;
413
graphStateArray[i].showing = no;
414
graphStateArray[i].selected = no;
415
graphStateBackupArray[i] = graphStateArray[i];
416
}
417
418
/**** Get Data from the Viewport Manager ****/
419
420
i = 123;
421
check(write(Socket,&i,intSize));
422
423
/* Check if I am getting stuff from OpenAxiom or, if I am viewAlone. */
424
readViewman(&viewAloned,intSize);
425
readViewman(&viewData,sizeof(view2DStruct));
426
readViewman(&i,intSize);
427
428
if (!(viewData.title = (char *)malloc(i))) {
429
fprintf(stderr,
430
"ERROR: Ran out of memory trying to receive the title.\n");
431
exitWithAck(RootWindow(dsply,scrn),Window,-1);
432
}
433
readViewman(viewData.title,i);
434
435
for (i=0; i<maxGraphs; i++) {
436
readViewman(&(graphArray[i].key),intSize);
437
if (graphArray[i].key) { /** this graph slot has data **/
438
getGraphFromViewman(i);
439
} /* if graph exists (graphArray[i].key is not zero) */
440
} /* for i in graphs */
441
442
viewport = makeView2D(&viewData);
443
control = viewport->controlPanel;
444
445
bsdSignal(SIGTERM,goodbye,DontRestartSystemCalls);
446
447
/* send acknowledgement to viewport manager */
448
i = 345;
449
check(write(Socket,&(viewport->viewWindow),sizeof(Window)));
450
451
processEvents();
452
453
goodbye(-1);
454
return(0); /* control never reaches here but compiler complains */
455
} /* main() */
456
457
void
458
mergeDatabases(void)
459
{
460
/* using global
461
rDB
462
dsply
463
*/
464
XrmDatabase homeDB,serverDB,applicationDB;
465
char filenamebuf[1024];
466
char *filename = &filenamebuf[0];
467
const char *classname = "OpenAxiom";
468
char name[255];
469
470
(void) XrmInitialize();
471
(void) strcpy(name, "/usr/lib/X11/app-defaults/");
472
(void) strcat(name, classname);
473
applicationDB = XrmGetFileDatabase(name);
474
(void) XrmMergeDatabases(applicationDB, &rDB);
475
476
if (XResourceManagerString(dsply) != NULL)
477
serverDB = XrmGetStringDatabase(XResourceManagerString(dsply));
478
else {
479
(void) strcpy(filename,oa_getenv("HOME"));
480
(void) strcat(filename,"/.Xdefaults");
481
serverDB = XrmGetFileDatabase(filename);
482
}
483
XrmMergeDatabases(serverDB,&rDB);
484
if ( oa_getenv ("XENVIRONMENT") == NULL) {
485
int len;
486
(void) strcpy(filename,oa_getenv("HOME"));
487
(void) strcat(filename,"/.Xdefaults-");
488
len = strlen(filename);
489
(void) gethostname(filename+len,1024-len);
490
}
491
else
492
(void) strcpy (filename,oa_getenv ("XENVIRONMENT"));
493
494
homeDB = XrmGetFileDatabase(filename);
495
XrmMergeDatabases(homeDB,&rDB);
496
}
497
498
499