next up previous contents index
Next: Problems of the Interface Up: Interactive Elements Previous: A User-Interface for Rot2d

Putting It All Together

 

Now we have all methods we need to work with Rot2d instances. Our main program has to add the new class and its methods, to create a Rot2d instance to work on and the editor for this instance. Finally the manager is started by sending the "handle" method and we can work interactively with the instance we have created.

#include <grape.h>
#include "rot2d.h"


/*
 * Define the new class pointer, it is initialized below
 */
CLASS *Rot2d = NULL;


int main()
{
  MANAGER *mgr;
  ROT2D *rot2d;

  /*
   * First we call "new-class" to create our class Rot2d. The method
   * is send to the superclass, its parameters are the name and the
   * size of the structure, this size will be used by "new-instance"
   * to allocate memory for the instance.
   */
  Rot2d = (CLASS *)GRAPE(Triang2d, "new-class")("Rot2d", sizeof(ROT2D));
  ASSURE(Rot2d, "main: can't create class Rot2d", return 5);

  /*
   * Now add the methods for the new class and the two methods
   * we have written for the existing class Triang1d. "add-method"
   * is called on the class the method is defined on, parameters
   * are the method name and the pointer to the function. This
   * pointer is used when GRAPE()() is called to call the function
   * corresponding to the method name.
   */
  GRAPE(Rot2d, "add-method")("new-instance", rot2d_new_instance);
  GRAPE(Rot2d, "add-method")("free", rot2d_free);
  GRAPE(Rot2d, "add-method")("hardcopy", rot2d_hardcopy);
  GRAPE(Rot2d, "add-method")("softcopy", rot2d_softcopy);
  GRAPE(Rot2d, "add-method")("rotate-send", rot2d_rotate_send);
  GRAPE(Rot2d, "add-method")("display", rot2d_display);
  GRAPE(Rot2d, "add-method")("get-info", rot2d_get_info);
  GRAPE(Rot2d, "add-method")("follow", rot2d_follow);
  GRAPE(Rot2d, "add-method")("get-editor", rot2d_get_editor);
  GRAPE(Rot2d, "add-method")("update-point", rot2d_update_point);
  GRAPE(Triang1d, "add-method")("insert-point", triang1d_insert_point);
  GRAPE(Triang1d, "add-method")("delete-point", triang1d_delete_point);
  GRAPE(Rot2d, "add-method")("insert-point", rot2d_insert_point);
  GRAPE(Rot2d, "add-method")("delete-point", rot2d_delete_point);

  /*
   * Now we can create our first Rot2d instance, it is called "rot".
   * This could fail so we test the return value.
   */
  rot2d = (ROT2D *)GRAPE(Rot2d, "new-instance")("rot");
  ASSURE(rot2d, "main: can't create object", return 5);

  /*
   * Now we bind the rot2d variables to the rulers and
   * create the buttons that will send our methods.
   */
  ASSURE(GRAPE(rot2d, "get-editor")(), "main: can't create editor", return 5);

  /*
   * Since we want to work with our Rot2d instance interactively
   * we have to start the manager. This is done by calling "handle"
   * with the instance as parameter. The control will be returned
   * to this function when the exit button is pressed.
   */
  mgr = (MANAGER *)GRAPE(Manager, "get-stdmgr")();
  GRAPE(mgr, "handle")(rot2d);

  return 0;
}

The method for archiving Rot2d instances is not explained here but in the section about the GRAPE XDR archiving system, see 5.7.6.

All files for the demo program can be found in the directory demo/rot2d/basic of the GRAPE distribution, the main file is called rotate.c. If you don't know where the GRAPE files are located ask the system operator or the person who installed GRAPE on your computer.

When the program is started the rot2d instance passed to the manager in the "handle" method is the current instance. Top right and right of it you will see axis and curve, this is what the method "follow" was written for. The buttons and rulers were installed in the first option menu.



SFB 256 Universität Bonn and IAM Universität Freiburg

Copyright © by the Sonderforschungsbereich 256 at the Institut für Angewandte Mathematik, Universität Bonn.