partiview.cc 29.1 KB
Newer Older
1
2
3
4
5
/*
 * Main program for FLTK-based partiview.
 * Stuart Levy, slevy@ncsa.uiuc.edu
 * National Center for Supercomputing Applications,
 * University of Illinois 2001.
6
7
 * This file is part of partiview, released under the
 * Illinois Open Source License; see the file LICENSE.partiview for details.
8
9
 */

10
11
#include <stdio.h>
#include <stdlib.h>
12
#include "config.h"
13

slevy's avatar
slevy committed
14
#ifdef WIN32
15
#include "winjunk.h"
slevy's avatar
slevy committed
16
17
#endif

18
19
20
21
22
23
24
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>    /* for GLuint */
#endif

 
25
26
27
28
29
30
31
32
33
34
#include "Gview.H"
#include "partiview.H"
#include "geometry.h"
#include "shmem.h"
#include <string.h>
#include <stdarg.h>
#include <math.h>
#include <errno.h>

#include "partiviewc.h"
35
#include "findfile.h"
36
37

#include <FL/Fl.H>
38
#include <FL/fl_draw.H>
39
40
#include "genericslider.H"  //steven marx: generic slider introduced version 0.7.02
#include <FL/Fl_Tooltip.H>  //steven marx: version 0.7.02 now using fltk-1.1.2
41
42
43
44
45
46
47

#if HAVE_OLD_FILE_CHOOSER_H
# include <FL/fl_file_chooser.H>	/* fltk 1.0.* and 1.1.rcX for X<6 */
#else
# include <FL/Fl_File_Chooser.H>	/* fltk 1.1.0rc6 and later */
#endif

48
#include <FL/glut.H>		// for GLUT_MULTISAMPLE if fltk knows it
49

50

slevy's avatar
   
slevy committed
51
static char local_id[] = "$Id$";
52

53
54
struct _ppui  ppui;

slevy's avatar
slevy committed
55
char *parti_detachview( char *how );
56
57

extern "C" { extern void plugin_init(); }
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

struct stuff *stuffs[MAXSTUFF];

static int specks_commandstr( struct stuff **stp, const char *str ) {
  if(stp == NULL || *stp == NULL || str == NULL)
    return 0;

#define MAXARGS 128
  char *av[MAXARGS];
  int ac;
  char *txt = (char *)alloca( strlen(str) + 1 );
  char *s = txt;
  strcpy(txt, str);
  for(ac = 0; ac < MAXARGS-1; ac++) {
    av[ac] = strtok(s, " \t\n");
    if(av[ac] == NULL) break;
    s = NULL;
  }
  av[ac] = NULL;
  return specks_parse_args( stp, ac,av);
}

int specks_commandfmt( struct stuff **stp, const char *fmt, ... ) {
  char cmd[1024];
  int ok;
  va_list args;
  va_start(args, fmt);
  vsprintf(cmd, fmt, args);
  va_end(args);
  ok = specks_commandstr( stp, cmd );
88
  if(ok) parti_redraw();
89
90
91
92
93
94
95
96
97
  return ok;
}


/* =================================================================== */

void pp_nav_init(Fl_Menu_Button *);
int  pp_viewevent_cb( Fl_Gview *, int ev );

98
99
int gensliderchg = 0; //steven marx: generic slider introduced version 0.7.02

100
101
102
103
void pp_ui_init() {

  pp_nav_init(ppui.nav);

104
105
106
  pp_sldtype_init(ppui.sldtype); //steven marx: version 0.7.02
  genericslider_initparam();     //steven marx: version 0.7.02

107
108
109
  /* ppui.cmd->handle_cb = pp_cmd_handle_cb;  No, this doesn't work yet */

  ppui.view->eventhook = pp_viewevent_cb;
110

111
112
  parti_inertia( 1 );

113
114
  if(getenv("CMDFONT"))
    ppui.cmdhist->scaletext( atoi( getenv("CMDFONT") ) );
slevy's avatar
slevy committed
115
116
117
  ppui.freewin = NULL;
  ppui.boundwin = ppui.view;
  ppui.detached = 0;
118
119

#ifdef DEFAULT_ELUMENS
120
  ppui.detached = 'f';
121
#endif
122
123
}

slevy's avatar
   
slevy committed
124
125
126
127
128
129
void pp_clk_init() {
  ppui.clk = NewN( SClock, 1 );
  clock_init( ppui.clk );
  clock_set_speed( ppui.clk, 1.0 );
  ppui.clk->continuous = 1;	// is this used?
  ppui.clk->walltimed = 1;
slevy's avatar
   
slevy committed
130

slevy's avatar
   
slevy committed
131
132
133
134
135
136
137
138
139
140
141
}

void pp_ui_postinit() {
  parti_set_timebase( ppui.st, 0.0 );
  parti_set_timestep( ppui.st, 0.0 );
  parti_set_running( ppui.st, 0 );
  parti_set_fwd( ppui.st, 1 );

  ppui.stepspeed->logstyle( FL_LOG_LINEAR );
  ppui.stepspeed->truebounds( 1.0e-6, 10.0 );
  ppui.stepspeed->truevalue( clock_speed( ppui.clk ) );
slevy's avatar
   
slevy committed
142
  clock_set_step( ppui.clk, 0.1 * clock_speed( ppui.clk ) );
slevy's avatar
   
slevy committed
143
144

  ppui.steprow->hide();
slevy's avatar
slevy committed
145

slevy's avatar
slevy committed
146
147
148
  if(ppui.detached)
    parti_detachview("fullscreen");

slevy's avatar
   
slevy committed
149
}
150
151

void pp_cmd_cb( HistInput* inp, void * ) {
152
153
  if(inp->hist())      
    inp->hist()->addline( inp->value(), 0 ); 
154
155
  specks_commandstr( &ppui.st, inp->value() );
  ppui_refresh( ppui.st );
156
157
  parti_redraw();        
  genericslider_setparam(); //steven marx version 0.7.02 update generic slider
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
}


static enum Gv_Nav codes[] = { GV_FLY, GV_ORBIT, GV_ROTATE, GV_TRANSLATE };
static char *navtitles[] =   {"[f]ly","[o]rbit","[r]ot","[t]ran"};

void pp_nav_init(Fl_Menu_Button *m) {
  m->add("[f]ly|[o]rbit|[r]ot|[t]ran");

  for(int i = m->size(); --i >= 0; ) 
    (((Fl_Menu_Item *)(m->menu()))[i]).labelcolor( m->labelcolor() );
}

void pp_nav_cb(Fl_Menu_Button* m, struct stuff **vst) {
  int v = m->value();
  if(v >= 0 && v < COUNT(codes))
    ppui.view->nav( codes[v] );
}   

void pp_obj_cb(Fl_Menu_Button* m, void *) {
178
  parti_object( m->text(), &ppui.st, 0 );
179
180
181
182
183
184
185
}

void pp_objtog_cb(Fl_Button* b, void *) {
  int objno = 1;
  sscanf(b->label(), "g%d", &objno);
  if(objno<0||objno>=MAXSTUFF||stuffs[objno]==NULL)
    return;
186
187
188

  //================ marx added version 0.7.04 to support 1 button mac mouse ======================
#ifndef __APPLE__
slevy's avatar
   
slevy committed
189
  if(Fl::event_button() == FL_RIGHT_MOUSE) {
190
191
192
193
194
#else
  if( (Fl::event_button() == FL_RIGHT_MOUSE) ||  ((Fl::event_button() == FL_LEFT_MOUSE) && Fl::event_alt())  ) {
#endif
 //================  end 1 button mac mouse =======================================================

slevy's avatar
   
slevy committed
195
    stuffs[objno]->useme = 1;
196
    parti_object( b->label(), &ppui.st, 0 );
slevy's avatar
   
slevy committed
197
198
199
200
    b->value(1);
  } else {
    stuffs[objno]->useme = !stuffs[objno]->useme;
  }
201
  ppui_refresh( ppui.st );
202
  parti_redraw();
203
}
204
205
206
207
208
209

void pp_genericslider_cb(Fl_Value_Slider* sl, void*) { //steven marx: version 0.7.02
  gensliderchg = 1;
  genericslider_setparam();
  gensliderchg = 0;
}
210
211

void pp_slum_cb(Fl_Value_Slider* sl, struct stuff ** ) {
212
213
214
215
216
217
218
struct stuff *st = ppui.st;
int cd = st->curdata, by = st->sizedby;
if((unsigned int)cd >= MAXFILES) cd = 0;
if((unsigned int)by >= MAXVAL+1) by = 0;
struct valdesc *vd = &st->vdesc[cd][by];
vd->lum = pow(10., sl->value());
ppui.view->redraw();
219
220
}

slevy's avatar
   
slevy committed
221
void pp_step_cb( Fl_Button * , void *stepsign ) {
222
223
224
225
226
227
228
229
230
double sign = (int)stepsign;
parti_set_running( ppui.st, 0 );
switch(Fl::event_button()) {
case FL_RIGHT_MOUSE: sign *= 10; break;
case FL_MIDDLE_MOUSE: sign *= 0.1; break;
}
clock_step( ppui.st->clk, sign );
specks_set_timestep( ppui.st );
parti_redraw();
slevy's avatar
   
slevy committed
231
232
233
}

void pp_run_cb( Fl_Button *runbtn, void *stepsign ) {
234
235
clock_set_fwd( ppui.st->clk, (int)stepsign );
parti_set_running( ppui.st, runbtn->value() );
slevy's avatar
   
slevy committed
236
237
238
}

void pp_timeinput_cb( Fl_Input *inp, void * ) {
239
double v;
slevy's avatar
   
slevy committed
240

241
242
243
244
245
246
parti_set_running( ppui.st, 0 );
if(sscanf(inp->value(), "%lf", &v)) {
clock_set_time( ppui.st->clk, v + ppui.timebasetime );
parti_set_timestep( ppui.st, v + ppui.timebasetime );
parti_redraw();
}
slevy's avatar
   
slevy committed
247
248
249
}

void pp_timebaseinput_cb( Fl_Input *inp, void * ) {
250
double newbase;
slevy's avatar
   
slevy committed
251

252
253
254
255
256
257
parti_set_running( ppui.st, 0 );
if(sscanf(inp->value(), "%lf", &newbase)) {
parti_set_timebase( ppui.st, newbase );
ppui.timebasetime = newbase;
parti_redraw();
}
slevy's avatar
   
slevy committed
258
259
260
}

void pp_jog_cb( Fl_Roller *rol, void * ) {
261
262
263
264
265
266
267
268
269
static double lastrol;
double v = rol->value();
clock_step( ppui.st->clk, v - lastrol );
lastrol = v;

parti_set_running( ppui.st, 0 );
specks_set_timestep( ppui.st );
parti_set_timestep( ppui.st, clock_time( ppui.st->clk ) );
parti_redraw();
slevy's avatar
   
slevy committed
270
271
}

slevy's avatar
slevy committed
272
void pp_feed_cb( Fl_Light_Button *, void * ) {
273
msg("can't feed yet...");
slevy's avatar
slevy committed
274
275
}

slevy's avatar
   
slevy committed
276
void pp_settrip_cb( Fl_Button *, void * ) {
277
278
279
280
281
char str[32];
ppui.timebasetime = clock_time( ppui.st->clk );
ppui.timestep->value( "0" );
sprintf(str, "%.16lg", ppui.timebasetime);
ppui.timebase->value(str);
slevy's avatar
   
slevy committed
282
283
284
}

void pp_backtrip_cb( Fl_Button *, void * ) {
285
286
287
clock_set_time( ppui.st->clk, ppui.timebasetime );
ppui.timestep->value( "0" );
parti_redraw();
slevy's avatar
   
slevy committed
288
289
290
}

void pp_stepspeed_cb( Fl_Log_Slider *spd, void * ) {
291
292
293
double speed = spd->truevalue();
clock_set_speed( ppui.st->clk, speed );
clock_set_step( ppui.st->clk, 0.1 * speed );
slevy's avatar
   
slevy committed
294
295
}

296
void pp_rdata_cb( Fl_Button *, struct stuff ** ) {
297
298
299
300
const char *result;
result = fl_file_chooser("Choose virdir .wf path", "*.wf", NULL);
if (result)
  parti_readpath( result );
301
302
303
}

void pp_playframe_cb( Fl_Counter *counter, struct stuff ** ) {
304
305
306
if(ppui.playing)
  parti_play( "0" );
parti_setframe( (int)counter->value() );
307
308
309
}

void pp_playtime_cb( Fl_Value_Slider *slider, struct stuff ** ) {
310
311
312
313
struct wfpath *path = &ppui.path;
if(ppui.playing)
  parti_play( "0" );
parti_setframe( (int) (slider->value() * path->fps + path->frame0) );
314
315
316
}

void pp_play_cb( Fl_Button *play, struct stuff ** ) {
317
318
319
320
321
322
323
324
if(Fl::event_state(FL_BUTTON3)) {
ppui.playmenu->popup();
} else {
parti_play( 
play->value() ? NULL /*play at default speed*/ 
: "0"  /*stop*/
);
}
325
326
327
}

int pp_viewevent_cb( Fl_Gview *view, int ev ) {
328
329
330
331
char snapinfo[1024];
int fno;
double bump;
struct stuff *st = ppui.st;
332

slevy's avatar
slevy committed
333
334
#define CTRL(x) ((x) & 0x1F)

335
if(ev == FL_KEYBOARD || ev == FL_SHORTCUT) {
slevy's avatar
   
slevy committed
336

337
338
if(ppui.cmdhist && ppui.cmdhist->handle_nav(ev))
  return 1;
slevy's avatar
slevy committed
339

340
341
342
343
344
345
346
347
348
349
350
351
352
switch(Fl::event_key()) {
case FL_Print:
if(view->num.has) {
ppui.snapfno = view->num.value();
view->num.has = 0;
}
fno = parti_snapshot(snapinfo);
if(fno >= 0)
  msg("Snapped %s", snapinfo);
return 1;
}
int key = Fl::event_text()[0];
switch(key) {
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
case '\t':
if(!ppui.cmdhist || !ppui.cmdhist->input())
  return 0;
ppui.cmdhist->input()->take_focus();
return 1;

case 'S':
if(view->num.has) {
float v = view->num.fvalue();
if(v == 0) {
parti_stereo("off");
} else {
if(fabs(v) < 1)		/* plausible? */
  view->stereosep( v );
parti_stereo("on");
}
view->num.has = 0;
} else {
parti_stereo( view->stereo()==GV_MONO ? "on" : "off" );
}
msg("stereo %s (focallen %g)",
     parti_stereo(NULL), view->focallen());
return 1;

case '>': bump = 1; goto step;
case '<': bump = -1;
step:
if(view->num.has)
  clock_set_step( st->clk, view->num.fvalue() );
view->num.has = 0;
clock_step( st->clk, bump );
parti_set_running( st, 0 );
/* clock_notify( st->clk );  NOTYET NOTIFY */
parti_redraw();
return 1;

case '{':
case '}':
clock_set_fwd( st->clk, key=='}' );
parti_set_running( st, 1 );
return 1;

case '~':
if(clock_running(st->clk)) {
parti_set_running( st, 0 );
} else {
int fwd = -clock_fwd( st->clk );
clock_set_fwd( st->clk, fwd );
parti_set_fwd( st, fwd );
parti_set_running( st, 1 );
}
return 1;

case 'z':
case 'Z':
if(view->num.has) {
specks_set_speed( st, view->num.fvalue() );
view->num.has = 0;
} else {
specks_set_speed( st,
  clock_speed(st->clk) * (key=='z' ? .5 : 2) );
}
clock_set_step( st->clk, 0.1 * clock_speed(st->clk) );
return 1;
slevy's avatar
slevy committed
418
    
419
420
421
422
423
424
case CTRL('K'):
  if(view->num.has) {
ppui.cmdhist->scaletext( view->num.fvalue() );
view->num.has = 0;
}
return 1;
425

426
427
428
429
430
case CTRL('T'):
  msg("%.4g fps", ppui.view->fps());
return 1;
}
}
431

432
return 0;
433
434
}

435
static int whichobjname( const char *str ) {
436
437
438
439
440
if(str == NULL) return -1;
if(str[0] == '[') str++;
int objno = -1;
sscanf(str, "g%d", &objno);
return objno;
441
442
443
}

static void fitlabel( Fl_Widget *w, int excess = 4 ) {
444
445
446
447
448
449
#ifdef __APPLE__
int width = (int)fl_width( w->label(), strlen(w->label()) ) + excess; //marx added the strlen param
w->hide();
w->size( width, w->h() );
w->show();
#else
450
451
int ofont = fl_font(), osize = fl_size();
fl_font( w->labelfont(), w->labelsize() );
452
int width = (int)fl_width( w->label()) + excess; //marx added the strlen param
453
454
455
456
w->hide();
w->size( width, w->h() );
w->show();
fl_font(ofont, osize);
457
#endif
458
459
460
461
462
}
  

void parti_set_alias( struct stuff *st, char *alias ) {

463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
if(st == NULL) return;

if(alias == NULL) alias = "";
alias = strdup(alias);
if(st->alias) free(st->alias);
st->alias = alias;

int slotno, menuno, btno;
for(slotno = 0; slotno < MAXSTUFF; slotno++) {
if(stuffs[slotno] == st) {
char lbl[32];
sprintf(lbl, "[g%d]%.24s", slotno, alias);
for(menuno = ppui.obj->size()-1; --menuno >= 0; ) {
if(whichobjname( ppui.obj->text(menuno) ) == slotno) {
ppui.obj->replace( menuno, strdup(lbl) );
break;
}
}
481

482
sprintf(lbl, alias[0]=='\0' ? "g%d" : "g%d=%.24s", slotno, alias);
483

484
485
486
487
488
489
490
491
492
493
for(btno = ppui.objtogs->children(); --btno >= 0; ) {
Fl_Button *btn = (Fl_Button *)(ppui.objtogs->child(btno));
if(btn && whichobjname( btn->label() ) == slotno) {
btn->label( strdup(lbl) );
fitlabel( btn, 8 );
break;
}
}
}
}
494
495
}

496
497
void ppui_refresh( struct stuff *st ) {

498
if(ppui.view == NULL) return;
499

500
501
/* Possibly switch selected object */
int targ = ppui.view->target();
502

503
504
505
if(targ >= 0 && targ < MAXSTUFF && stuffs[targ] != NULL && stuffs[targ] != ppui.st) {
st = ppui.st = stuffs[targ];
}
506

507
508
509
510
511
512
513
514
515
516
enum Gv_Nav nav = ppui.view->nav();
for(int navcode = 0; navcode < COUNT(codes); navcode++) {
if(codes[navcode] == nav) {
ppui.nav->value( navcode );
if(strcmp(ppui.nav->label(), navtitles[navcode])) {
ppui.nav->label( navtitles[navcode] );
ppui.toprow->parent()->redraw();
}
}
}
517

518
519
if(ppui.view->inertia()) ppui.inertiaon->set();
else ppui.inertiaon->clear();
slevy's avatar
   
slevy committed
520

521
522
523
524
525
526
int tno, maxobject = 0;

int timeshown = ppui.steprow->visible();
for(tno = 0; tno < MAXSTUFF; tno++) {
struct stuff *tst = stuffs[tno];
if(tst == NULL) continue;
527

528
maxobject = tno;
529
530


531
532
if(!timeshown && tst->clk->tmin != tst->clk->tmax) {
ppui.steprow->show();
533
ppui.steprow->parent()->hide(); // force top-level Pack to be redraw()n
534
535
536
ppui.steprow->parent()->show(); // for some reason just ->redraw() doesn't.
timeshown = 1;
}
537

538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
if(ppui.st == stuffs[tno]) {
char oname[12];
Fl_Font lfont = ppui.view->movingtarget()
  ? FL_HELVETICA_BOLD_ITALIC
: FL_HELVETICA;
sprintf(oname, "[g%d]", tno);

if(strcmp(ppui.obj->label(), oname) || lfont != ppui.obj->labelfont()) {
ppui.obj->label( strdup( oname ) );
// Iff we might actually move the target object,
// display its [gN] title in BOLD ITALICs.
ppui.obj->labelfont( lfont );
ppui.obj->parent()->redraw();
}
}
}
 
555
556
557
558
559
560
561
562
563
564
565
  if(st == NULL)
    return;

  if(ppui.objgroup->active() != st->useme) {
    if(st->useme) ppui.objgroup->activate();
    else ppui.objgroup->deactivate();
  }

  // objtogs is wrapped in a Group which is invisible by default.
  if(!ppui.objtogs->parent()->visible() && maxobject > 1) {
    ppui.objtogs->parent()->show();
566
567
    ppui.steprow->parent()->hide(); // force top-level Pack to be redraw()n
    ppui.steprow->parent()->show(); // for some reason just ->redraw() doesn't.
568
569
570
571
572
573
574
575
576
577
  }

  if(ppui.objtogs->visible()) {
    Fl_Button *b, *b0 = (Fl_Button *)ppui.objtogs->child(0);
    for(tno = 0; tno <= maxobject; tno++) {
	if(tno >= ppui.objtogs->children()) {
	    char name[8];
	    sprintf(name, "g%d", tno);
	    b = new Fl_Button( b0->x(),b0->y(),b0->w(),b0->h(), strdup(name) );
	    b->labelcolor( b0->labelcolor() );
578
579
	    b->labelfont( b0->labelfont() );
	    b->labelsize( b0->labelsize() );
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
	    b->color( b0->color() );
	    b->selection_color( b0->selection_color() );
	    b->down_box( b0->down_box() );
	    b->type( b0->type() );
	    b->callback( (Fl_Callback*)pp_objtog_cb );

	    ppui.objtogs->add( b );
	}
	b = (Fl_Button *)ppui.objtogs->child(tno);
	
	if(stuffs[tno] == NULL) {
	    if(b->visible()) b->hide();
	} else {
	    if((b->value() != 0) != stuffs[tno]->useme)
		b->value( stuffs[tno]->useme );
	    if(!b->visible()) b->show();
	}
    }
  }

  ppui.point->value( st->usepoint );
  ppui.poly->value( st->usepoly );
  ppui.label->value( st->usetext );
  ppui.texture->value( st->usetextures );
  ppui.box->value( st->useboxes!=0 );
  int boxcolor = ( st->useboxes==2 ? 1/*red*/ : 2/*green*/ );
  if(boxcolor != ppui.box->color2()) {
    ppui.box->color2( boxcolor );
    ppui.box->redraw();
  }

  int cd = st->curdata, by = st->sizedby;
  if((unsigned int)cd >= MAXFILES) cd = 0;
  if((unsigned int)by >= MAXVAL+1) by = 0;
  struct valdesc *vd = &st->vdesc[cd][by];
  float lum = vd->lum;
  if(lum <= 0) lum = 1;
  ppui.slum->value( log10( lum ) );
618
619
620
621
622
623
624
625
626
627
628
  char slumlabel[50], *ep = slumlabel;
  if(parti_get_alias(st)[0]) {
    ep = slumlabel + sprintf(slumlabel, "[%.17s] ", parti_get_alias(st));
  }
  if(by == CONSTVAL) {
    sprintf( ep, "logslum %g", vd->lmin );
  } else if(st->vdesc[cd][by].name[0]) {
    sprintf( ep, "logslum %.10s", vd->name );
  } else {
    sprintf( ep, "logslum(field%d)", by );
  }
629
  if(strcmp(ppui.slum->label(), slumlabel)) {
630
    static char slumlab[50];
631
632
633
    strcpy(slumlab, slumlabel);
    ppui.slum->label(slumlab);
    ppui.slum->parent()->redraw();
634
635
636
637
638

    //steve marx version 0.7.02 support for generic slider. provides update to generic slider label upon data group change
    int menunum = ppui.sldtype->value();
    if(menunum >= 0 && menunum < NUMSLD && menunum != SLUM)
      genericslider_setparam();
639
640
641
642
643
  }
}

void pp_viewchanged( Fl_Gview *gview, void *st ) {
  ppui_refresh( ppui.st );
slevy's avatar
slevy committed
644
645
646
#if MATT_VIRDIR
  vd_ffn();
#endif
647
648
}

649
650
void pp_hrdiag_on_cb( Fl_Menu_ *menu, void * ) {
  const Fl_Menu_Item *item = menu->mvalue();
slevy's avatar
slevy committed
651
  if(ppui.hrdiag == NULL || ppui.hrdiagwin == NULL) return;
652
  parti_hrdiag_on( item->value() );
slevy's avatar
slevy committed
653
654
}

655
656
657
658
void pp_inertia_on_cb( Fl_Menu_ *menu, void * ) {
  const Fl_Menu_Item *item = menu->mvalue();
  ppui.view->inertia( item->value() );
  msg("inertia %s", ppui.view->inertia() ? "on" : "off");
slevy's avatar
slevy committed
659
}
660
661

int msg( const char *fmt, ... ) {
662
663
664
  if(gensliderchg) //steven marx: version 0.7.02 - we don't want voluminous generic slider output
    return 1; 

665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
  char str[10240];

  va_list args;
  va_start(args, fmt);
  vsprintf(str, fmt, args);
  va_end(args);

  if(ppui.cmdhist)
    ppui.cmdhist->addline( str, 1 );

  return printf("%s\n", str);
}

void quietwarning( const char *fmt, ... ) {
  char msg[10240];
  static char avoid[] = "X_ChangeProperty: ";
  va_list args;
  va_start(args, fmt);
  vsprintf(msg, fmt, args);
  va_end(args);
  if(0!=strncmp(msg, avoid, sizeof(avoid)-1))
    fputs(msg, stderr);
}

689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
void parti_lighting() {
    static GLuint lightlist = 0;

    if(lightlist > 0) {
	glCallList( lightlist );
	return;
    }
    lightlist = glGenLists( 1 );
    glNewList( lightlist, GL_COMPILE_AND_EXECUTE );

    static GLfloat lmambient[] = { 0.1, 0.1, 0.1, 1.0 };
    static GLfloat amblight[] = { 0.1,	0.1, 0.1, 1.0 };
    static GLfloat whitelight[] = { 1, 1, 1, 1 };
    static GLfloat Ce[] = { 0, 0, 0, 1 };
    static GLfloat Ca[] = { 1, 1, 1, 1 };
    static GLfloat Cd[] = { 1, 1, 1, 1 };
    static GLfloat Cs[] = { 1, 1, 1, 1 };
    static GLfloat lightpos[3][4] = {
		0, 0, -1, 0,
		1, 0, -.5, 0,
		0, 1, 0, 0,
    };

    glShadeModel( GL_SMOOTH );

    glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE );
    glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );
    glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lmambient );
    glDisable( GL_LIGHTING );

    int i;

    for(i = 0; i < 8; i++)
	glDisable( GL_LIGHT0+i );

    for(i = 0; i < 2; i++) {
	glLightfv( GL_LIGHT0+i, GL_AMBIENT, amblight );
	glLightfv( GL_LIGHT0+i, GL_SPECULAR, whitelight );
	glLightfv( GL_LIGHT0+i, GL_DIFFUSE, whitelight );
	glLightfv( GL_LIGHT0+i, GL_POSITION, lightpos[i] );
	glEnable( GL_LIGHT0+i );
    }


    glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, Ce );
    glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, Ca );
    glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, Cd );
    glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, Cs );
    glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 32.0 );

    glColorMaterial( GL_FRONT_AND_BACK, GL_DIFFUSE );
    glDisable( GL_COLOR_MATERIAL );

    glEnable( GL_BLEND );
    glBlendFunc( GL_SRC_ALPHA,  GL_ONE_MINUS_SRC_ALPHA );
    glDisable( GL_BLEND );

    glEndList();
}
748
749
750
751
752
753
754
755

void drawjunk(Fl_Gview *view, void *obj, void *arg) {
  static Point xyz[3] = {{1,0,0}, {0,1,0}, {0,0,1}};
  static Point nxyz[3] = {{-1,0,0}, {0,-1,0}, {0,0,-1}};
  static Point zero = {0,0,0};
  static float white[3] = {1,1,1};
  float censize = parti_getcensize();
  int i;
756

slevy's avatar
slevy committed
757
758
759
  if(ppui.drawtrace)
      (*ppui.drawtrace)();

760
  parti_lighting();
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
  glDisable(GL_LIGHTING);
  if(censize > 0) {
    glPushMatrix();
    glScalef(censize,censize,censize);
    glBegin(GL_LINES);
    for(i = 0; i < 3; i++) {
	glColor3fv(xyz[i].x);
	glVertex3fv(xyz[i].x);
	glVertex3f(0,0,0);
    }
    glEnd();
    glPopMatrix();
  }

  if(censize != 0) {
    censize = fabs(censize);
    glPushMatrix();
    const Point *cen = view->center();
    glTranslatef(cen->x[0],cen->x[1],cen->x[2]);
    glScalef(censize, censize, censize);
    glBegin(GL_LINES);
    for(i = 0; i < 3; i++) {
	glColor3fv(white);
	glVertex3fv(nxyz[i].x);
	glVertex3fv(zero.x);

	glColor3fv(xyz[i].x);
	glVertex3fv(zero.x);
	glVertex3fv(xyz[i].x);
    }
    glEnd();
    glPopMatrix();
  }
}

796
void readrc( struct stuff **stp ) {
797
798
799
800
801
802
803
804
805
  char *rc = findfile( NULL, "~/.partiviewrc" );
  if(rc) specks_read( stp, rc );
  rc = findfile( NULL, "./.partiviewrc" );
  if(rc) specks_read( stp, rc );
}

static int cmdargs(int argc, char **argv, int & optind) {
  char *arg = argv[optind];
  if(!strcmp("-c", arg)) {
806
    arg = argv[optind+1];
807
808
809
810
811
812
813
    char *t = NewA(char, strlen(arg)+1);
    char *av[128];
    int ac = tokenize(arg, t, 128, av, NULL);
    specks_parse_args( &ppui.st, ac, av );
    optind += 2;
    return 1;
  }
814
815
816
817
818
  if(!strcmp("-hideui", arg)) {
    ppui.detached = 'h';
    optind++;
    return 1;
  }
slevy's avatar
slevy committed
819
  if(!strcmp("-detach", arg)) {
820
    ppui.detached = 'd';
slevy's avatar
slevy committed
821
822
823
    optind++;
    return 1;
  }
824
825
826
  if(!strcmp("-geom", arg) || !strcmp("-geometry", arg)) {
    ppui.reqwinsize = NULL;	/* override any initial "winsize" */
    			/* but let fltk parse it anyway */
827
  }
828
  return 0;
829
}
830

831
int pp_parse_args( struct stuff **, int argc, char *argv[], char *fromfname, void * ) {
832
833
834
  if(argc < 1) return 0;

  int i;
slevy's avatar
slevy committed
835
836
837
838
  if(!strcmp( argv[0], "exit" )) {
      	exit(0);

  } else if(!strcmp( argv[0], "stereo" )) {
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
	for(i = 1; i < argc; i++)
	    parti_stereo( argv[i] );

	msg("stereo %s", parti_stereo(NULL));

  } else if(!strcmp( argv[0], "winsize" )) {
	msg("winsize %s", parti_winsize( rejoinargs( 1, argc, argv ) ) );

  } else if(!strncmp( argv[0], "snapset", 7 ) || !strcmp( argv[0], "snapshot" )) {
	char *frameno = NULL, *basename = NULL;
	char *size = NULL;
	int now = (0 == strcmp(argv[0], "snapshot"));
	while(argc > 2) {
	    if(!strcmp(argv[1], "-w")) {
		size = argv[2];
	    } else if(!strcmp(argv[1], "-n")) {
		frameno = argv[2];
	    } else
		break;
	    argc -= 2, argv += 2;
	}
	if(argc > 1)
	    basename = rejoinargs( 1, argc, argv );
	parti_snapset( basename, frameno, size );
	if(now) {
	    char snapinfo[1024]; 
	    if(parti_snapshot(snapinfo) >= 0)
		msg("Snapped %s", snapinfo);
	}

  } else if(!strcmp( argv[0], "clip" )) {
	msg("%s", parti_clip( argv[1], argc>2?argv[2]:NULL ) );

  } else if(!strcmp( argv[0], "ortho" )) {
#ifdef NOTYET
	int ortho = parti_ortho( argc>1 ? argv[1] : NULL);
	float fov = parti_fov(NULL);
slevy's avatar
slevy committed
876
	msg(ortho ? "ortho on (fov %g units)" : "ortho off (fov %g degrees)");
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
#endif

  } else if(!strcmp( argv[0], "pickrange" )) {
	float pickrange = parti_pickrange( argv[1] );
	msg("pickrange %g", parti_pickrange( NULL ));

  } else if(!strcmp( argv[0], "fov" ) || !strcmp( argv[0], "fovy" )) {
	float fovy = parti_fovy( (argc>1) ? argv[1] : NULL );
	msg("fovy %g", fovy);

  } else if(!strcmp( argv[0], "subcam")) {
	int index;
	if(argc > 1) {
	    if(!strcmp(argv[1], "-") || !strcmp(argv[1], "off")) {
		parti_select_subcam(0);
	    } else {
		index = parti_make_subcam( argv[1], argc-2, (const char **)argv+2 );
		if(index > 0) {
		    parti_select_subcam(index);
		} else {
		    char *what = parti_subcam_list();
		    msg(what[0]=='\0' ?  "No subcams defined yet" :
					"Known subcams: %s", what);
		}
	    }
	}
	index = parti_current_subcam();
	if(index > 0) {
	    char params[100];
	    char *name = parti_get_subcam( index, params );
	    msg("subcam %s  %s # az el rol  L R B T", name, params);
	} else {
	    int wx, wy;
	    float hx, hy = .5 * parti_fovy(NULL);
	    sscanf( parti_winsize(NULL), "%d%*c%d", &wx, &wy );
	    if(wy == 0) wy = 1;
	    hx = atan( tan(hy*(M_PI/180))*wx / wy ) * (180/M_PI);
	    msg("subcam off  0 0 0  %g %g  %g %g # a e r   L R B T (default)",
			hx, hx, hy, hy);
	}

  } else if(!strncmp( argv[0], "focal", 5 )) {
	float focallen = parti_focal( (argc>1) ? argv[1] : NULL );
	msg("focallength %g", focallen);


  } else if(!strncmp( argv[0], "jump", 4 )) {
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
    Point xyz;
    float aer[3];
    static int stupid[3] = {1,0,2};	/* aer -> rx ry rz */
    Matrix c2w;
    parti_getc2w( &c2w );
    tfm2xyzaer( &xyz, aer, &c2w );
    if(argc>1) {
      for(i=1; i<argc && i<4+3; i++) {
	if(i-1<3) xyz.x[i-1] = getfloat(argv[i], xyz.x[i-1]);
	else aer[stupid[i-4]] = getfloat(argv[i], aer[stupid[i-4]]);
      }
      xyzaer2tfm( &c2w, &xyz, aer );
      parti_setc2w( &c2w );
    }
    msg("jump %g %g %g  %g %g %g  (XYZ RxRyRz)",
	xyz.x[0],xyz.x[1],xyz.x[2],
	aer[1],aer[0],aer[2]);
   
942
  } else if(!strncmp( argv[0], "home", 4 )) {//marx version 0.7.03
943
944
945
946
947
948
949
950
951
952
953
954
955
956
    Point xyz;
    float aer[3];
    static int stupid[3] = {1,0,2};	/* aer -> rx ry rz */
    Matrix c2w;
    parti_getc2w( &c2w );
    tfm2xyzaer( &xyz, aer, &c2w );
    if(argc>1) {
      for(i=1; i<argc && i<4+3; i++) {
	if(i-1<3) xyz.x[i-1] = getfloat(argv[i], xyz.x[i-1]);
	else aer[stupid[i-4]] = getfloat(argv[i], aer[stupid[i-4]]);
      }
      xyzaer2tfm( &c2w, &xyz, aer );
      parti_setc2w( &c2w );
      ppui.home[0] = xyz.x[0]; ppui.home[1] = xyz.x[1];  ppui.home[2]  = xyz.x[2];
957
958
959
960

    //ppui.home[3] = aer[0];   ppui.home[4] = aer[1];    ppui.home[5]  = aer[2]; bug in releases >= 0.7.03 
      ppui.home[3] = aer[1];   ppui.home[4] = aer[0];    ppui.home[5]  = aer[2]; //version 0.7.05 fix for the line above

961
962
    }
    msg("home %g %g %g  %g %g %g  (XYZ RxRyRz)", ppui.home[0], ppui.home[1], ppui.home[2], ppui.home[3], ppui.home[4], ppui.home[5]);  
963

964
  } else if(!strncmp(argv[0], "inertia", 5)) {
965
966
967
    if(argc > 1)
      ppui.view->inertia( getbool( argv[1], ppui.view->inertia() ) );
    msg("inertia %s", ppui.view->inertia() ? "on":"off");
968

969
970
971
  } else if((!strcmp( argv[0], "rdata" ) || !strcmp(argv[0], "readpath"))
		&& argc>1) {
	char *tfname = argv[1];
972
	char *realfile = findfile( fromfname, tfname );
973
974
975
976
977
978
979
	if(realfile == NULL) {
	    tfname = (char *)alloca(strlen(argv[1]) + 32);
	    sprintf(tfname, "data/record/%s%s", argv[1],
		strstr(argv[1], ".wf") ? "" : ".wf");
	    realfile = findfile( NULL, tfname+12 );
	}
	if(realfile == NULL)
980
	    realfile = findfile( fromfname, tfname );
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
	if(realfile)
	    parti_readpath( realfile );
	else
	    msg("%s: can't find \"%s\" nor data/record/... nor ...wf",
		argv[0],argv[1]);

  } else if(!strcmp( argv[0], "play" )) {
	parti_play( argc>1 ? argv[1] : NULL );

  } else if(!strcmp( argv[0], "frame" )) {
	CONST struct wfpath *pp;
	i = parti_frame( argv[1], &pp );
	msg("frame %d (of %d..%d)", pp->curframe,
		pp->frame0, pp->nframes + pp->frame0 - 1);

  } else if(!strcmp( argv[0], "interest") || !strcmp( argv[0], "int" ) ||
		!strcmp( argv[0], "center" ) ||
		!strcmp( argv[0], "cen" )) {
	Point cen;
	float censize = parti_getcensize();