-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallbacks.c
494 lines (420 loc) · 11.2 KB
/
callbacks.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
/* Copyright (C) 1992-1998 The Geometry Center
* Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips
*
* This file is part of Geomview.
*
* Geomview is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* Geomview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Geomview; see the file COPYING. If not, write
* to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
* USA, or visit http://www.gnu.org.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#if 0
static char copyright[] = "Copyright (C) 1992-1998 The Geometry Center\n\
Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips";
#endif
/* We include the C code generated by the forms designer (fdesign2). */
#include <stdlib.h>
/*#include "discgrpP.h"*/
#include "dgflag.h"
#include "maniview.h"
#include "forms.h"
#include "xforms-compat.h"
#include "controlpanel.h"
static int display_winid = -1,
enum_winid = -1,
load_winid = -1,
save_winid = -1,
dirdom_winid = -1,
info_winid = -1,
help_winid = -1;
#define TOGGLE(xxx, bit, button) \
xxx = fl_get_button(button) ? (xxx | bit) : (xxx & ~bit)
static int oldspace = DG_EUCLIDEAN;
int loadstuff();
void savegroup();
/* This is the callback procedure we must write. It's the interface
between our program and the forms code.
*/
void DspyattrProc(FL_OBJECT *obj, long val)
{
unsigned flag;
GeomGet((Geom *)dg, DGCR_FLAG, &flag);
TOGGLE(flag, val, obj);
GeomSet((Geom *)dg, DGCR_FLAG, flag, CR_END);
changed = CHANGED;
}
void SoftshadeProc(FL_OBJECT *obj, long val)
{
softshade = 1 - softshade;
changed = SOFTSHADE;
}
void RadiusProc(FL_OBJECT *obj, long val)
{
GeomSet((Geom *)dg, DGCR_ENUMDIST, (float)fl_get_slider_value(obj), CR_END);
changed = CHANGED;
}
void DrawRadiusProc(FL_OBJECT *obj, long val)
{
GeomSet((Geom *)dg, DGCR_DRAWDIST, (float)fl_get_slider_value(obj), CR_END);
changed = CHANGED;
}
void DisplayProc(FL_OBJECT *obj, long val)
{
unsigned flag;
GeomGet((Geom *)dg, DGCR_FLAG, &flag);
TOGGLE(flag, val, obj);
GeomSet((Geom *)dg, DGCR_FLAG, flag, CR_END);
changed = CHANGED;
}
void TileModeProc(FL_OBJECT *obj, long val)
{
tilemode = val;
fl_set_button(DirichletDomainButton, tilemode & DIRDOM_MODE );
fl_set_button(UsergeometryButton, tilemode & USER_GEOM );
}
void DDXYProc(FL_OBJECT *obj, long val)
{
HPoint3 cpoint;
GeomGet((Geom *)dg, DGCR_CPOINT, &cpoint);
cpoint.x = fl_get_positioner_xvalue(obj);
cpoint.y = fl_get_positioner_yvalue(obj);
GeomSet((Geom *)dg, DGCR_CPOINT, &cpoint, CR_END);
changed = DIRDOM | CHANGED;
}
void DDZProc(FL_OBJECT *obj, long val)
{
HPoint3 cpoint;
GeomGet((Geom *)dg, DGCR_CPOINT, &cpoint);
cpoint.z = fl_get_dial_value(obj);
GeomSet((Geom *)dg, DGCR_CPOINT, &cpoint, CR_END);
changed = DIRDOM | CHANGED;
}
void DDResetProc(FL_OBJECT *obj, long val)
{
HPoint3 cpoint;
GeomGet((Geom *)dg, DGCR_CPOINT, &cpoint);
cpoint.x = 0.0;
cpoint.y = 0.0;
cpoint.z = 0.0;
cpoint.w = 1.0;
GeomSet((Geom *)dg, DGCR_CPOINT, &cpoint, CR_END);
fl_update_from_dg();
changed = DIRDOM | CHANGED;
}
void WorddepthProc(FL_OBJECT *obj, long val)
{
GeomSet((Geom *)dg, DGCR_ENUMDEPTH, (int)fl_get_counter_value(obj), CR_END);
changed = CHANGED;
}
void DDScaleProc(FL_OBJECT *obj, long val)
{
myscale = fl_get_slider_value(obj);
if (tilemode == DIRDOM_MODE) {
GeomSet((Geom *)dg, DGCR_SCALE, myscale, CR_END);
}
changed = DIRDOM | CHANGED;
}
void Attenuation1SliderProc(FL_OBJECT *obj, long val)
{
atk[myindex][0] = fl_get_slider_value(obj);
changed = NEW_AP;
}
void Attenuation2SliderProc(FL_OBJECT *obj, long val)
{
atk[myindex][1] = fl_get_slider_value(obj);
changed = NEW_AP;
}
void Attenuation3SliderProc(FL_OBJECT *obj, long val)
{
atk[myindex][6] = fl_get_slider_value(obj);
changed = NEW_AP;
}
void DisplayButtonProc(FL_OBJECT *obj, long val)
{
if (display_winid < 0) /* not currently active */
display_winid = fl_show_form(DisplayForm,displayplacement,TRUE,"Maniview Display Window");
else {
winset(display_winid);
(void)winpop();
}
}
void EnumerateButtonProc(FL_OBJECT *obj, long val)
{
if (enum_winid < 0) /* not currently active */
enum_winid = fl_show_form(EnumForm,enumplacement,TRUE,"Maniview Enum Window");
else {
winset(enum_winid);
(void)winpop();
}
}
void TileButtonProc(FL_OBJECT *obj, long val)
{
if (dirdom_winid < 0) /* not currently active */
dirdom_winid = fl_show_form(TileForm,dirdomplacement,TRUE,"Maniview Tile Window");
else {
winset(dirdom_winid);
(void)winpop();
}
}
void HelpButtonProc(FL_OBJECT *obj, long val)
{
if (help_winid < 0) /* not currently active */
help_winid = fl_show_form(HelpForm,helpplacement,TRUE,"Maniview Help Window");
else {
winset(help_winid);
(void)winpop();
}
}
void LoadButtonProc(FL_OBJECT *obj, long val)
{
if (load_winid < 0) /* not currently active */
load_winid = fl_show_form(LoadForm,loadplacement,TRUE,"Maniview Load Window");
else {
winset(load_winid);
(void)winpop();
}
}
void SaveButtonProc(FL_OBJECT *obj, long val)
{
if (save_winid < 0) /* not currently active */
save_winid = fl_show_form(SaveForm,loadplacement,TRUE,"Maniview Save Window");
else {
winset(save_winid);
(void)winpop();
}
}
void InfoButtonProc(FL_OBJECT *obj, long val)
{
if (info_winid < 0) /* not currently active */
info_winid = fl_show_form(InfoForm,infoplacement,TRUE,"Maniview Info Window");
else {
winset(info_winid);
(void)winpop();
}
}
void QuitButtonProc(FL_OBJECT *obj, long val)
{
exit(0);
}
void HelpOKButtonProc(FL_OBJECT *obj, long val)
{
fl_hide_form(HelpForm);
help_winid = -1;
}
static int loadtypechanged = 1; /* Flag: when to change filebrowser dir? */
void LoadProc(FL_OBJECT *obj, long val)
{
loadtypechanged = 1;
if(fl_get_button(obj))
loadtype = val;
}
void LoadOKButtonProc(FL_OBJECT *obj, long val)
{
char filename[128];
IOBFILE *fp;
sprintf(filename,"%s",fl_get_input(LoadInput));
/* get new group */
if((fp = get_input_fp(filename, loadtype)) != NULL &&
loadstuff(fp, filename, loadtype)) {
fl_hide_form(LoadForm);
load_winid = -1;
} else {
strcat(filename, "?");
fl_set_input(LoadInput, filename);
}
}
void LoadShowBrowserProc(FL_OBJECT *obj, long val)
{
char dirname[512];
char *stem = getenv("GEOMDATA");
char *subdir = "geom";
char *pat = "*.dgp";
char *msg = NULL;
const char *fname;
if(stem == NULL) stem = ".";
switch(loadtype) {
case LOAD_GROUP: msg = "Select Group File"; subdir = "groups"; break;
case LOAD_CAMGEOM: msg = "Select Camera Geometry File"; pat = "*"; break;
case LOAD_GEOM: msg = "Select Geometry File"; pat = "*"; break;
}
sprintf(dirname, "%s/%s", stem, subdir);
fname = fl_show_file_selector(msg,
loadtypechanged ? dirname : NULL,
pat, NULL);
loadtypechanged = 0;
if(fname) {
fl_set_input(LoadInput, fname);
LoadOKButtonProc(LoadOKButton, 0);
}
}
void SaveOKButtonProc(FL_OBJECT *obj, long val)
{
char filename[128];
fl_hide_form(SaveForm);
save_winid = -1;
sprintf(filename,"%s",fl_get_input(SaveInput));
/* get new group */
savegroup(filename);
}
void SaveGeomButtonProc(FL_OBJECT *obj, long val)
{
unsigned flag;
GeomGet((Geom *)dg, DGCR_FLAG, &flag);
TOGGLE(flag, DG_SAVEDIRDOM, obj);
GeomSet((Geom *)dg, DGCR_FLAG, flag, CR_END);
}
void SaveGroupButtonProc(FL_OBJECT *obj, long val)
{
unsigned flag;
GeomGet((Geom *)dg, DGCR_FLAG, &flag);
TOGGLE(flag, DG_SAVEBIGLIST, obj);
GeomSet((Geom *)dg, DGCR_FLAG, flag, CR_END);
}
void DisplayOKButtonProc(FL_OBJECT *obj, long val)
{
fl_hide_form(DisplayForm);
display_winid = -1;
}
void EnumOKButtonProc(FL_OBJECT *obj, long val)
{
fl_hide_form(EnumForm);
enum_winid = -1;
}
void TileOKButtonProc(FL_OBJECT *obj, long val)
{
fl_hide_form(TileForm);
dirdom_winid = -1;
}
void InfoOKButtonProc(FL_OBJECT *obj, long val)
{
fl_hide_form(InfoForm);
info_winid = -1;
}
void LoadCancelButtonProc(FL_OBJECT *obj, long val)
{
fl_hide_form(LoadForm);
load_winid = -1;
}
void SaveCancelButtonProc(FL_OBJECT *obj, long val)
{
fl_hide_form(SaveForm);
save_winid = -1;
}
/* little routine to basically compute log base 2 of the space bit for use
as index into above atk array */
int
index_from_bit(int bit)
{
if (bit == 1) return(0);
if (bit == 2) return (1);
if (bit == 4) return (2);
else return (1);
}
IOBFILE *
get_input_fp(char *filename, int lt)
{
char *geomdata, mystr[128];
IOBFILE *myf;
if (filename == NULL) return NULL;
/* try opening the file as given */
strncpy(mystr, filename, 128);
if ( (myf = iobfopen(mystr, "rb")) == NULL) {
/* now tack on the geomdata environment variable */
geomdata = getenv("GEOMDATA");
if (geomdata == NULL) {
fprintf(stderr,"GEOMDATA environment variable not set\n");
return(NULL);
}
else {
strncpy(mystr, geomdata, 128);
if (lt & LOAD_GROUP) strcat(mystr, "/groups/");
else strcat(mystr,"/geom/");
strcat(mystr, filename);
myf = iobfopen(mystr, "rb");
}
}
if (myf == NULL) {
fprintf(stderr,"Maniview: Unable to open file %s\n", mystr);
}
return (myf);
}
int
loadstuff(IOBFILE *myf, char *filename, int lt)
{
int ok = 0;
DiscGrp *olddg = dg;
int attrib;
oldspace = space;
if (lt & (LOAD_GROUP | CHECK_PIPE) ) {
if ( (dg = (DiscGrp *) GeomFLoad(myf, filename)) == NULL) {
fprintf(stderr,"Unable to load file %s\n",filename);
goto OUT;
}
if (olddg) GeomDelete((Geom *) olddg);
GeomGet((Geom *)dg, DGCR_ATTRIBUTE, &attrib);
space = attrib & DG_METRIC_BITS;
myindex = index_from_bit(space);
if (oldspace != space ) changed = NEW_SPACE;
changed |= (CHANGED | NEW_AP );
if (changed & NEW_SPACE) fl_set_bounds();
}
else if (lt & LOAD_GEOM) {
Geom *geom = NULL;
Transform t1;
if ((geom = GeomFLoad(myf, filename)) == NULL) {
fprintf(stderr,"Unable to load file %s\n",filename);
goto OUT;
}
/* create an inst with geom, use CR_NOCOPY s.t. the Inst owns geom and
* dg owns the Inst.
*/
TmIdentity(t1);
GeomSet((Geom *)dg, CR_NOCOPY, CR_GEOM,
GeomCreate("inst", CR_NOCOPY,
CR_GEOM, geom, CR_AXIS, t1, CR_END), CR_END);
changed |= DIRDOM | CHANGED;
}
else if (lt & LOAD_CAMGEOM) {
Geom *camgeom;
if ((camgeom = GeomFLoad(myf, filename)) == NULL) {
fprintf(stderr,"Unable to load file %s\n",filename);
goto OUT;
}
GeomSet((Geom *)dg, CR_NOCOPY, DGCR_CAMGEOM, camgeom, CR_END);
changed |= CHANGED;
}
ok = 1;
OUT:
if (myf) {
if (iobfile(myf) != stdin) {
iobfclose(myf);
} else {
iobfileclose(myf);
}
}
return ok;
}
void
savegroup(char *filename)
{
if (dg) GeomSave( (Geom *) dg,filename);
}
/*
* Local Variables: ***
* mode: c ***
* c-basic-offset: 2 ***
* End: ***
*/