Skip to content
Snippets Groups Projects
partiview.cc 31.1 KiB
Newer Older
/*
 * Main program for FLTK-based partiview.
 * Stuart Levy, slevy@ncsa.uiuc.edu
 * National Center for Supercomputing Applications,
 * University of Illinois 2001.
 * This file is part of partiview, released under the
 * Illinois Open Source License; see the file LICENSE.partiview for details.
#include <stdio.h>
#include <stdlib.h>
#ifdef WIN32
# include "winjunk.h"
#endif

#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>    /* for GLuint */
#endif

 
#include "Gview.H"
#include "partiview.H"
#include "geometry.h"
#include "shmem.h"
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include <math.h>
#include <errno.h>

#include "partiviewc.h"
#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

#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

#include <FL/glut.H>		// for GLUT_MULTISAMPLE if fltk knows it
slevy's avatar
 
slevy committed
static char local_id[] = "$Id$";
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], *cp;
  int ok;
  va_list args;
  va_start(args, fmt);
  vsprintf(cmd, fmt, args);
  va_end(args);
  for(cp = cmd; isspace(*cp); cp++)
      ;
  if(*cp == '\0') return 1;	// accept null command implicitly
  ok = specks_commandstr( stp, cmd );
  else msg("Unrecognized control command: %s", cmd);
  return ok;
}


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

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

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

void pp_ui_init() {

  pp_nav_init(ppui.nav);

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

  /* 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) {
    char code[2] = { ppui.detached, '\0' };
    parti_detachview(code);
  }
slevy's avatar
 
slevy committed
}

void pp_cmd_cb( HistInput* inp, void * ) {
  if(inp->hist())
    inp->hist()->addline( inp->value(), 0 );
  const char *cp;
  for(cp = inp->value(); isspace(*cp); cp++)
      ;
  if(*cp == '\0')
      return;	// accept null command implicitly

  int ok = specks_commandstr( &ppui.st, inp->value() );
  if(!ok)
    msg("Unrecognized control command: %s", inp->value());
  ppui_refresh( ppui.st );
  parti_redraw();        
  genericslider_setparam(); //steven marx version 0.7.02 update generic slider
}


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;

  //================ marx added version 0.7.04 to support 1 button mac mouse ======================
Loading
Loading full blame...