next up previous contents index
Next: The Rotate Add-Method Up: Project Rotate Previous: A New User-Interface

The Rotate Setup-Method

 

Now we have everything we need to write the setup-method for our project. All method and class declarations are moved from the main program to the project file proj_rot.c:

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


/*
 * The class pointer for our new class
 */
CLASS *Rot2d = NULL;


/*
 * The add- and the init-function for the project, defined below.
 */
PROJECT *project_rotate_add();
PROJECT *project_rotate_init();

/*
 * Just to make life easier. We have to cast the functions pointers
 * because there is no type `pointer to an arbitrary function' in C.
 */
typedef void *(*FUNC)();


/*
 * List of all functions for our project. This list is passed to the
 * project in the "setup" method, the functions will be added to
 * the system when the project is used.
 */
static METHOD_DESCR rotate_methods[] = {
  { &Rot2d, "new-instance",       (FUNC)rot2d_new_instance      },
  { &Rot2d, "free",               (FUNC)rot2d_free              },
  { &Rot2d, "hardcopy",           (FUNC)rot2d_hardcopy          },
  { &Rot2d, "softcopy",           (FUNC)rot2d_softcopy          },
  { &Rot2d, "rotate-send",        (FUNC)rot2d_rotate_send       },
  { &Rot2d, "display",            (FUNC)rot2d_display           },
  { &Rot2d, "get-info",           (FUNC)rot2d_get_info          },
  { &Rot2d, "follow",             (FUNC)rot2d_follow            },
  { &Rot2d, "xdr",                (FUNC)rot2d_xdr               },
  { &Rot2d, "get-editor",         (FUNC)rot2d_get_editor        },
  { &Rot2d, "update-point",       (FUNC)rot2d_update_point      },
  { &Rot2d, "update-editor",      (FUNC)rot2d_update_editor     },
  { &Rot2d, "insert-point-send",  (FUNC)rot2d_insert_point_send },
  { &Rot2d, "delete-point-send",  (FUNC)rot2d_delete_point_send },

  { &Triang1d, "insert-point", (FUNC)triang1d_insert_point },
  { &Triang1d, "delete-point", (FUNC)triang1d_delete_point },

  { &Project, "rotate-add", (FUNC)project_rotate_add },
  { &Project, "rotate-init", (FUNC)project_rotate_init },

  { NULL, NULL, NULL }
};


PROJECT *project_rotate_setup()
{
  PROJECT *self;

  self = (PROJECT *)START_METHOD(G_INSTANCE);
  ASSURE(self, "", END_METHOD(NULL));

  /*
   * "setup" called on the project defines what classes, methods
   * and items (rulers, buttons etc) are used by the project.
   * We only add one class, therefore we don't use a class list,
   * but specify it directly. The version and date will be used
   * for the message in the manager menu.
   *
   * Note: The user-interface can not be created in this method,
   * because neither the class Rot2d is initialized nor the method
   * "get-editor" added to it. The editor is therefore added to
   * the project in the init method.
   */
  GRAPE(self, "setup")(P_Class, &Triang2d, &Rot2d, "Rot2d", sizeof(ROT2D),
                       P_MethodList, rotate_methods,
                       P_AddMethod, "rotate-add",
                       P_InitMethod, "rotate-init",
                       P_Version, 2, 0,
                       P_Date, "Aug 18, 96",
                       P_End);

  END_METHOD(self);
}

Since only one class is added P_Class is used instead of a class list. All methods were collected in a method list, their pointers have to be casted to the right type. The add- and init-method for this project were added to the list, they will be presented below.

You might have noticed that another error we made while implementing the Rot2d methods were corrected: the Rot2d method for inserting and deleting points were renamed, the missing suffix "-send" was added. All other methods remain unchanged.



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.