Exemple #1
0
/* Callback for the sound-choice.  Only used to hide/show the
   "reverse" button, and only if we have sound */
void snd_cho_cb(FL_OBJECT *a, long l)
{
#ifdef AUDIO_DEVICE
  const char *ch;

  ch = fl_get_choice_text( a );
  if ( !strcmp(ch, EXTERNALLY_STR ) ) 
    fl_hide_object( rev_but );
  else 
    fl_show_object( rev_but );
  
#endif
}
Exemple #2
0
void SpinnWheel( int stop )
{
#include "wheel.xpm"  /* here we find the static char *wheel?[]  */
  static int state;

  fl_free_pixmap_pixmap( wheel_pxm );
  fl_hide_object( wheel_pxm );

  if ( stop ) 
    return;

  switch ( state )
    { 
    default :
    case 0 : 
      fl_set_pixmap_data( wheel_pxm, wheel0 );
      state = 1;
      break;
    case 1 :
      fl_set_pixmap_data( wheel_pxm, wheel1 );
      state = 2;
      break;
    case 2 :
      fl_set_pixmap_data( wheel_pxm, wheel2 );
      state = 3;
      break;
    case 3 :
      fl_set_pixmap_data( wheel_pxm, wheel3 );
      state = 0;
      break;
    }  

  /* the hide/show and XFlush seems to be necessary to get 
     the right effect */
  fl_show_object( wheel_pxm );
  XFlush( fl_get_display() ); 

}
void DistributionChoiceCB(FL_OBJECT *p0, long p1) {
  FL_OBJECT *ap = the_gui->AEntry;
  FL_OBJECT *bp = the_gui->BEntry;

  switch (fl_get_choice(p0)) {
  case 0:
    cout << "No choice" << endl;
    break;
  case Uniform:			// uniform in the interval [a,b]
    fl_set_object_label(ap,"Minimum");
    fl_set_input(ap,"10.0");
    fl_set_object_label(bp,"Maximum");
    fl_set_input(bp,"90.0");
    fl_show_object(ap);
    fl_show_object(bp);
    break;
  case Binomial:		// binomial
    fl_set_object_label(ap,"p");
    fl_set_input(ap,"0.5");
    fl_set_object_label(bp,"n");
    fl_set_input(bp,"10.0");
    fl_show_object(ap);
    fl_show_object(bp);
    break;
  case CDF:			// CDF -- file will set range in a, b entries
    fl_set_object_label(ap,"lo");
    fl_set_input(ap,"<>");
    fl_set_object_label(bp,"hi");
    fl_set_input(bp,"<>");
    fl_show_object(ap);
    fl_show_object(bp);
    break;
  case Exponential:		// exponential; no params
    fl_hide_object(ap);
    fl_hide_object(bp);
    break;
  case Gamma:			// Time to wait for N events
    fl_set_object_label(ap,"Mean");
    fl_set_input(ap,"1");
    fl_set_object_label(bp,"Std Dev");
    fl_set_input(bp,"1");
    fl_show_object(ap);
    fl_show_object(bp);
    break;
  case LogNormal:		// lognormal with mean = a and std dev = b
    fl_set_object_label(ap,"Mean");
    fl_set_input(ap,"50.0");
    fl_set_object_label(bp,"Std Dev");
    fl_set_input(bp,"10.0");
    fl_show_object(ap);
    fl_show_object(bp);
    break;
  case LogNormalLog:		// lognormal with mean = exp(a) and std dev = exp(b)
    fl_set_object_label(ap,"Log Mean");
    fl_set_input(ap,"3.0");
    fl_set_object_label(bp,"Log Std Dev");
    fl_set_input(bp,"0.5");
    fl_show_object(ap);
    fl_show_object(bp);
    break;
  case Normal:			// normal with mean = a and std dev = b
    fl_set_object_label(ap,"Mean");
    fl_set_input(ap,"50.0");
    fl_set_object_label(bp,"Std Dev");
    fl_set_input(bp,"10.0");
    fl_show_object(ap);
    fl_show_object(bp);
    break;
  case Poisson:			// poisson with lambda = a
    fl_set_object_label(ap,"Lambda");
    fl_set_input(ap,"1.0");
    fl_show_object(ap);
    fl_hide_object(bp);
    break;
  }
}
Exemple #4
0
int
change_object( FL_OBJECT * obj,
               int         all )
{
    FL_OBJECT *retobj;
    FD_generic_attrib *ui = fd_generic_attrib;
    FL_FORM * spec_form = NULL;

    attrib_init( ui );

    /* Save current attributes for later restore */

    curobj = obj;
    save_edited_object( obj );

    /* Show only required parts */

    if ( all )
    {
        fl_show_object( ui->labelobj  );
        fl_show_object( ui->scobj     );
        fl_show_object( ui->nameobj   );
        fl_show_object( ui->cbnameobj );
        fl_show_object( ui->argobj    );

        if ( ( spec_form = create_spec_form( curobj ) ) )
        {
            FL_OBJECT *t;

            t = fl_addto_tabfolder( fd_attrib->attrib_folder,
                                    "Spec", spec_form );
            fl_set_object_shortcut( t, "#S", 1 );
        }
    }
    else
    {
        fl_hide_object( ui->labelobj  );
        fl_hide_object( ui->scobj     );
        fl_hide_object( ui->nameobj   );
        fl_hide_object( ui->cbnameobj );
        fl_hide_object( ui->argobj    );
    }

    /* Show attributes of the current object */

    show_attributes( obj );

    /* Do interaction */

    fl_deactivate_all_forms( );

    /* Disable selection */

    no_selection = 1;

    fl_show_form( fd_attrib->attrib, FL_PLACE_GEOMETRY, FL_FULLBORDER,
                  "Attributes" );
    fl_set_app_mainform( fd_attrib->attrib );

    /* Both cancel and readyobj should have their own callbacks, so we don't
       need to call fl_do_forms(), but since attribute editing can't be
       invoked for more than one item at a time we need to block the
       process_xevent. TODO */

    do
    {
        XEvent xev;

        retobj = fl_do_forms( );
        if ( retobj == FL_EVENT )
            fl_XNextEvent( &xev );
    } while ( ! (    (    retobj == fd_attrib->readyobj
                       && validate_attributes( curobj ) )
                  || retobj == fd_attrib->cancelobj ) );

    if ( retobj == fd_attrib->cancelobj )
    {
        restore_edited_object( obj );
        redraw_the_form( 0 );
    }
    else
    {
        reread_spec_form( obj );
        readback_attributes( obj );
        spec_to_superspec( obj );
    }

    cleanup_saved_object( );

    fl_set_app_mainform( fd_control->control );
    fl_set_folder_bynumber( fd_attrib->attrib_folder, 1 );
    if ( spec_form )
        fl_delete_folder( fd_attrib->attrib_folder, spec_form );
    fl_hide_form( fd_attrib->attrib );
    fl_activate_all_forms( );

    no_selection = 0;

    return retobj == fd_attrib->readyobj;
}
void PlotButtonCB(FL_OBJECT *p0, long p1) {
  FL_OBJECT *np = the_gui->NEntry;
  FL_OBJECT *sp = the_gui->ProgressSlider;
  FL_OBJECT *cp = the_gui->DistributionChoice;
  FL_OBJECT *xyp = the_gui->xyplot;
  RNG *rng = CreateRNG();
  int n = atoi(fl_get_input(np));
  double r;
  int i, j;
  int distrib[NB];
  float xv[NB];
  float yv[NB];
  int di;
  float dx;
  unsigned long xl;
  double sum, sumsq;
  static char *mstring = new char[80];
  static char *sdstring = new char[80];
  int ymax;
  double xmin, xmax;

  if (rng == NULL)
    return;

  for (i=0; i<NB; i++)
    distrib[i] = 0;
  sum = sumsq = 0.0;
  ymax = 0;
  
  if (n >= PROGRESS_THRESHOLD) {
    di = n/100;			// update slider every 'di' points
    fl_set_slider_value(sp,0.0);
    fl_show_object(sp);
  }
  else
    di = 0;			// n too small; don't draw slider

  xmin = atof(fl_get_input(the_gui->MinEntry));
  xmax = atof(fl_get_input(the_gui->MaxEntry));

  for (i=0; i<n; i++) {
    r = ++(*rng);		// get a sample from current distribution
    sum += r;
    sumsq += r*r;

    j = fl_get_choice(cp);
    if ((j == Binomial) || (j == Poisson))
      r *= 10.0;		// spread out integer values so we can see them
    
    if (j == CDF)		// 'dx' is a value added to each sample
      dx = 0.0005;		// the CDF demo RNG returns values that are exactly
    else			// on the divide between two bins, and roundoff
      dx = 0.0;			// errors lead to funny looking plots....

    j = floor((r+dx-xmin)*NB/(xmax-xmin));
    
    if ((j >= 0) && (j < NB)) {
      distrib[j] += 1;
      if (distrib[j] > ymax)
	ymax = distrib[j];
    }
    if (di && ((i%di)==0))
      fl_set_slider_value(sp,(double)i/(double)n);
  }

  fl_hide_object(sp);		// all done; put away the slider

  // Bins filled; transfer to x and y vectors and plot.  The xyplot
  // widget will scale x and y automatically.

  fl_delete_xyplot_text(xyp,mstring);
  fl_delete_xyplot_text(xyp,sdstring);

  for (i=0; i<NB; i++) {
    xv[i] = (float)i*(xmax-xmin)/NB + xmin;
    yv[i] = (float)distrib[i];
  }

  if (xmin == xmax)
    fl_set_xyplot_xbounds(xyp,xmin+1.0,xmax); 	// auto-scale if min>max
  else
    fl_set_xyplot_xbounds(xyp,xmin,xmax);
  fl_set_xyplot_data(xyp, xv, yv, NB, "", "", "");

  // compute, display sample mean and sample standard deviation

  double dn = double(n);
  double mean = sum/dn;
  double sd = sqrt(dn*((sumsq/dn)-mean*mean)/(dn-1));

  sprintf(mstring,"Sample Mean =  %f",mean);
  sprintf(sdstring,"Standard Dev = %f",sd);

  // The (x,y) coords of the string are defined in terms of scaled plot
  // units.  If the right edge of the x scale is at 100, put the text
  // at 80.  Put the top string near the top of the plot, and the bottom
  // string 10% lower.

  double y1 = double(ymax) - .05*(double(ymax));
  double y2 = double(ymax) - .10*(double(ymax));

  fl_add_xyplot_text(xyp,(xmax-xmin)*0.8+xmin,y1,mstring,FL_ALIGN_CENTER,FL_BLACK);
  fl_add_xyplot_text(xyp,(xmax-xmin)*0.8+xmin,y2,sdstring,FL_ALIGN_CENTER,FL_BLACK);
  
  delete rng;			// some RNGs allocate internal tables....
}