next up previous contents
Next: trial_init() Up: Writing the Standard Panel Previous: trial_open()   Contents

trial_field_manager()

This routine will be called whenever a dynamical system is loaded and immediately after the panel is first created. It should make sure that all the items in the window reflect the properties of the current dynamical system. It should also call the trial_init() routine in order to make sure that the data structure for the window is current for the selected dynamical system. If the window is not a custom window, meaning that it does not need to change when the dynamical system changes, then the procedure trial_init() may take it's place and the field manager need not exist. Here is a sample field manager to accompany the custom window we have been developing.

/*
 * trial_field_manager()
 *
 * manager for the custom panel items
 */
trial_field_manager()
{
  int	i,n_varb,status=0;
  char name[MAX_LEN_VARB_NAME], *calloc();
  static int total_fields=0;
  
  /* initialize data structure for the new dynamical system */
  status = trial_init();

  /* exit now if the window has not been created */
  if (trial_ip == NULL || status != 0) return(status);
  
  /* destroy the custom items */
  if (total_fields > 0)  
    {
      for (i=0; i<total_fields; i++) 
        {
          xv_destroy(trial_ip->varb_value[i]);
        }
      cfree((char *) trial_ip->varb_value);
      xv_destroy(trial_ip->setting1);
    }
  
  /* find out the number of variables */
  n_varb = *((int *) pm(GET, Traj_Ds_Object, Varb_Dim, NULL));
  total_fields = n_varb;

  /* allocate memory for the array of text fields */
  trial_ip->varb_value = (Xv_opaque *) calloc(n_varb, sizeof(Xv_opaque));
  if (trial_ip->varb_value == NULL)
    {
      total_fields = 0;
      system_mess_proc(1,"trial_field_manager: Memory allocation error.");
      return(-1);
    }

  /* create the window text fields, and write the label into them */
  for(i=0; i<n_varb; i++) 
    {
      trial_ip->varb_value[i] = 
              trial_win_varb_value_create(trial_ip,trial_ip->pan,i);
      pm(GET, Traj_Ds_Object, Varb_Names, i, name, NULL);
      xv_set(trial_ip->varb_value[i], PANEL_LABEL_STRING, name, NULL);
    }

  /* set up the settings item choices */
  trial_ip->setting1 = 
          trial_win_setting1_create(trial_ip, trial_ip->pan, n_varb);
  for (i=0; i<n_varb; i++)
    {
      pm(GET, Traj_Ds_Object, Varb_Names, i, name, NULL);
      xv_set(trial_ip->setting1, PANEL_CHOICE_STRING, i, name, NULL);
    }	

  /* make window tall enough  */
  window_fit(trial_ip->pan);
  window_fit(trial_ip->win);

  /* write data into the fields */
  trial_data_refresh();

  return(status);
}



root
1998-11-02