Skip to content
Snippets Groups Projects
partiview.cc 25.7 KiB
Newer Older
/*
 * Main program for FLTK-based partiview.
 * Stuart Levy, slevy@ncsa.uiuc.edu
 * National Center for Supercomputing Applications,
 * University of Illinois 2001.
 */

#include <stdio.h>
#include <stdlib.h>

#ifdef WIN32
# include "winjunk.h"
#endif

#include <GL/gl.h>
#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"
#include <FL/fl_file_chooser.H>

slevy's avatar
 
slevy committed
static char local_id[] = "$Id$";
slevy's avatar
slevy committed
char *parti_detachview( char *how );

extern "C" { extern void plugin_init(); }

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 );
  return ok;
}


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

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

void pp_ui_init() {

  pp_nav_init(ppui.nav);

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

  ppui.view->eventhook = pp_viewevent_cb;
  if(getenv("CMDFONT"))
    ppui.cmdhist->scaletext( atoi( getenv("CMDFONT") ) );
slevy's avatar
slevy committed
  ppui.freewin = NULL;
  ppui.boundwin = ppui.view;
  ppui.detached = 0;
  ppui.detached = 'f';
slevy's avatar
 
slevy committed
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

slevy's avatar
 
slevy committed
}

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
  clock_set_step( ppui.clk, 0.1 * clock_speed( ppui.clk ) );
slevy's avatar
 
slevy committed

  ppui.steprow->hide();
slevy's avatar
slevy committed
  if(ppui.detached)
    parti_detachview("fullscreen");

slevy's avatar
 
slevy committed
}

void pp_cmd_cb( HistInput* inp, void * ) {
  if(inp->hist())
    inp->hist()->addline( inp->value(), 0 );
  specks_commandstr( &ppui.st, inp->value() );
  ppui_refresh( ppui.st );
}


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 *) {
  parti_object( m->text(), &ppui.st, 0 );
}

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;
slevy's avatar
 
slevy committed
  if(Fl::event_button() == FL_RIGHT_MOUSE) {
    stuffs[objno]->useme = 1;
    parti_object( b->label(), &ppui.st, 0 );
slevy's avatar
 
slevy committed
    b->value(1);
  } else {
    stuffs[objno]->useme = !stuffs[objno]->useme;
  }
  ppui_refresh( ppui.st );
}
  

void pp_slum_cb(Fl_Value_Slider* sl, struct stuff ** ) {
  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();
}

slevy's avatar
 
slevy committed
void pp_step_cb( Fl_Button * , void *stepsign ) {
slevy's avatar
 
slevy committed
  double sign = (int)stepsign;
  parti_set_running( ppui.st, 0 );
slevy's avatar
 
slevy committed
  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 );
slevy's avatar
 
slevy committed
  specks_set_timestep( ppui.st );
slevy's avatar
 
slevy committed
}

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

Loading
Loading full blame...