OBJECTS

Objects are used to store series of plotting commands. In combination with viewports, objects can be used to scale and move these list. Objects can be nested. That is, a display list can contain calls to other objects. All windows have a history list, that contains all the objects that have been called (displayed) in that particular window. In this way, windows can update themselves when needed.

Objects can be stored on disk in a system-independent way. The object-by-name routines are used to accomplish this. Files are written in big-endian byte order, no matter what byte order the computer uses. Many objects can be stored in one file. The objects are stored in reusable blocks and can be modified and deleted. Compression is optional. All objects have a label attached that is stored in a btree structure. This index is stored in the same file.

Functions


g_open_object

int g_open_object(int object_id)

Description:

Open an object with the number object_id. All plotting commands that are given after this call are now stored in this object (= display-list). Calls to g_open_object() can be nested.

Inputs:

object_id - The object identifier ID. Can be any positive number.

Returns:

If successfull object_id is returned. G_ERROR is returned if object_id already exists.

Example:

void TestColor(void)
{
     char *colornames[] = {
     "G_BLACK",
     "G_BLUE",
     "G_GREEN",
     "G_CYAN",
     "G_RED",
     "G_MAGENTA",
     "G_BROWN",
     "G_LIGHTGRAY",
     "G_DARKGRAY",
     "G_LIGHTBLUE",
     "G_LIGHTGREEN",
     "G_LIGHTCYAN",
     "G_LIGHTRED",
     "G_LIGHTMAGENTA",
     "G_YELLOW",
     "G_WHITE"};
     int i,id;
     id = g_unique_object();
     g_open_object(id);
     g_set_linestyle(G_SOLID);
     g_set_linewidth(3);
     g_set_viewport(1, 0.0, 0.0, 1.0, 1.0);
     g_set_world(1,0,0,100,100);
     g_select_viewport(1);
     for (i=0; i< g_get_palettesize(); i++) {
          g_set_foreground(G_BLACK);
          g_moveto(10,5*i + 11);
          g_label(colornames[i]);
          g_set_foreground(i);
          g_moveto(10,5*i + 10);
          g_lineto(90,5*i + 10);
     }
     g_close_object(id);
     g_call_object(id);
}

g_close_object

int g_close_object(int object_id)

Description:

Close the object with the number object_id. All plotting commands that are given after the last object has been closed are now executed directly.

Inputs:

object_id - The object identifier ID.

Returns:

If successfull object_id is returned. G_ERROR is returned if object_id does not exists or is already closed.

g_append_object

int g_append_object(int object_id)

Description:

Reopen an object with the number object_id. All plotting commands that are given after this call are now appended to this object.

Inputs:

object_id - The object identifier ID.

Returns:

If successfull'object_id is returned. G_ERROR is returned if'object_id does not exists, or is already open.

g_delete_object

int g_delete_object(int object_id)

Description:

Delete an object with the number'object_id. If the opject is open, it is closed before it is deleted.

Inputs:

object_id - The object identifier ID.

Returns:

If successfull object_id is returned. G_ERROR is returned if object_id does not exists.

g_is_object

int g_is_object(int object_id)

Description:

Determine if an object with the identifier object_id exists.

Inputs:

object_id - The object identifier ID.

Returns:

If successfull object_id is returned. G_ERROR is returned if object_id does not exists.

g_unique_object

int g_unique_object(void)

Description:

Return an unused object number. It is good practice to use this call every time when a new object is created.

Returns:

An unused object identifier.

g_set_objectstatus

int g_set_objectstatus(int object_id, int status)

Description:

Set the status of object object_id. If an object is awake, its list of plotting commands is executed when a call to g_call_object() is made. If an object sleeps, it will not execute its plotting commands.

Inputs:

object_id - The object identifier ID.

status -

G_AWAKE - The object is active. This is the default.

G_SLEEP - Sets the object to inactive. The object still exists, but will not been displayed.

Returns:

If successfull G_OK is returned. G_ERROR is returned if object_id does not exists.

g_call_object

int g_call_object(int object_id)

Description:

Display the object object_id (play back the display list). If the object status is G_SLEEP the object will not be displayed.

Inputs:

object_id - The object identifier ID.

Returns:

If successfull object_id is returned. G_ERROR is returned if object_id does not exists.

g_count_objects

int g_count_objects(void)

Description:

Return the number of existing objects.

g_list_objects

void g_list_objects(int *id, int *status)

Description:

List the status of all the objects. The number of the objects is returned in the array id, and the status (G_SLEEP or G_AWAKE) in the array status. The user has to allocate the memory for the arrays. Use g_count_objects() to determine the size of the arrays.

Outputs:

id - Returns an array that contains the object_id of all the objects.

status - Returns a corresponding array with the status G_SLEEP or G_AWAKE.


g_open_object_byname

int g_open_object_byname(int object_id, char *label)

Description:

Open an object with the number object_id, and the name
label
. All plotting commands that are given after this call are now stored in this object (= display-list). Calls to g_open_object_byname() can be nested.

Inputs:

object_id - The object identifier ID. Can be any positive number. If object_id is 0, a unique id is generated.

label - The object identifier label. Has up to 32 significant characters.

Returns:

If successfull object_id is returned. G_ERROR is returned if object_id already exists.

g_close_object_byname

int g_close_object_byname(char *label)

Description:

Close the object with the name label. All plotting commands that are given after the last object has been closed are now executed directly.

Inputs:

label - The object identifier label. Has up to 32 significant characters.

Returns:

If successfull object_id is returned. G_ERROR is returned if object_id does not exists or is already closed.

g_append_object_byname

int g_append_object_byname(char *label)

Description:

Reopen an object with the name label. All plotting commands that are given after this call are now appended to this object.

Inputs:

label - The object identifier label. Has up to 32 significant characters.

Returns:

If successfull object_id is returned. G_ERROR is returned if object_id does not exists, or is already open.

g_delete_object_byname

int g_delete_object_byname(char *label)

Description:

Delete an object with the name label. If the opject is open, it is closed before it is deleted.

Inputs:

label - The object identifier label. Has up to 32 significant characters.

Returns:

If successfull object_id is returned. G_ERROR is returned if object_id does not exists.

g_set_objectstatus_byname

int g_set_objectstatus_byname(char *label, int status)

Description:

Set the status of object with the name label. If an object is awake, its list of plotting commands is executed when a call to g_call_object() is made. If an object sleeps, it will not execute its plotting commands.

Inputs:

label - The object identifier label. Has up to 32 significant characters.

status -

G_AWAKE - The object is active. This is the default.

G_SLEEP - Sets the object to inactive. The object still exists, but will not been displayed.

Returns:

If successfull object_id is returned. G_ERROR is returned if object_id does not exists.

g_call_object_byname

int g_call_object_byname(char *label)

Description:

Display the object`label (play back the display list). If the object status is G_SLEEP the object will not be displayed.

Inputs:

label - The object identifier label. Has up to 32 significant characters.

Returns:

If successfull object_id is returned. G_ERROR is returned if object_id does not exists.

g_count_objects_byname

int g_count_objects_byname(void)

Description:

Return the number of existing objects that have a label attached.

g_list_objects_byname

void g_list_objects_byname(char **list)

Description:

List the names of all the objects. The user has to allocate the memory for the list, BUT NOT FOR THE LABELS THAT WILL BE ATTACED TO LIST. The list contains pointers to the actual labels in the object management system. NEVER modify or free a member of the list. Use g_count_objects_byname() to determine the size of list.

Outputs:

list - Returns an array that contains the lables of all the objects that have a name.

g_get_object_id

int g_get_object_id(char *label)

Description:

Return the object ID that corresponds to the name label.

Returns:

The identifier ID of the object, or G_ERROR if an error occurs.

g_get_object_name

char *g_get_object_name(int id)

Description:

Return the object label that corresponds to the object identifier ID id. This label is a pointer to the actual label in the object management system. NEVER modify or free this label.

Returns:

A pointer to the label of the object, or NULL if the object has no label.

g_create_object_file

void g_create_object_file(char *name, char *ident)

Description:

Create an object-file on disk with the name name. The file is written in big-endian byte order, no matter what byte order the program is in. The objects are stored in reusable blocks and have a label attached that is stored in a btree structure.

Inputs:

name - The name of the file on disk.

ident - A 16 byte identifier, that can be used for version controll.


g_open_object_file

int g_open_object_file(char *name, int write_enabled)

Description:

Open an object-file on disk with the name name.

Inputs:

name - The name of the file on disk.

write_enabled - FALSE if the file is to be opened read-only, TRUE otherwise.

Returns:

The file handle that is used to read or write to the file, and G_ERROR on error.

g_close_object_file

void g_close_object_file(int file_id)

Description:

Close an object-file on disk.

Inputs:

file_id - the file_handle of the object_file.

g_get_object_file_ident

char *g_get_object_file_ident(int file_id)

Description:

Return the identifier string of the file file_id (16 bytes).

Inputs:

file_id - the file_handle of the object_file.

g_read_fileobject

int g_read_fileobject(int file_id, int obj_id, char *label, int with_children, int replace)

Description:

Read an object from disk by the name label and store it in an object with the name label, and the identifier ID obj_id. If obj_id is 0, an unique number will be generated. If`replace is TRUE and obj_id is 0, and an object with the name label does already exists, obj_id will get the old number.

Inputs:

file_id - The file handle of the object file.

obj_id - The identifier ID for the new object.

label - The label of the object, as it is stored on disk. Has up to 32 significant characters.

with_children - If TRUE, objects that are called from object label, will also be loaded if present in the file file_id.

replace - If TRUE, objects that are already present will be overwritten by label if they have the same name as `label' (or its children).

Returns:

G_OK on success and G_ERROR otherwise.

Example:

    char *s, *list[100], label[33];
    int fp, num_items = 0, result, obj_id;
    s = g_popup_getfilename(win_id, "Get object file", "*.gp");
    if (s) {
        if ((fp = g_open_object_file(s, FALSE)) == G_ERROR)
            return;
        if (g_first_fileobject(fp, label)!= G_ERROR) 
        do {
            printf("Object name is: %s\n",label);
            list[num_items] = (char*) malloc(33);
            strcpy(list[num_items], label);
            num_items++;          
            if (num_items == 100)
                break;
        }  while (g_next_fileobject(fp, label)!= G_ERROR);                 
        if (num_items == 0) {
            g_close_object_file(fp);
            return;
        }
        result = g_popup_listbox(win_id,"Objects in File", "Select Object", 
                                 num_items, list, 1, 8);
        if (result) {
            obj_id = g_unique_object();
            printf("Calling Object: %s id = %d\n",list[result-1], obj_id);
            g_read_fileobject(fp, obj_id, list[result-1], TRUE, TRUE);
            g_call_object(obj_id);
        }
        while (num_items) {
            free(list[num_items-1]);
            num_items--;
        }
        g_close_object_file(fp);
    }

g_write_fileobject

int g_write_fileobject(int file_id, char *label, int with_children, int replace)

Description:

Write object label to disk.

Inputs:

file_id - The file handle of the object file.

label - The label of the. Has up to 32 significant characters.

with_children - If TRUE, objects that are called from object `label', will also be stored on disk.

replace - If TRUE, objects that are already present in file_id will be overwritten by label if they have the same name as label (or its children).

Returns:

G_OK on success and G_ERROR otherwise.

Example:

    int num_items, j;
    int do_compression = TRUE;
    char *list[100];
    num_items = g_count_objects_byname();
    g_list_objects_byname(list);
    for (j=0;j <num_items;j++)
        printf("%s\n", list[j]);
    result = g_popup_listbox(win_id,"Objects in File", "Select Object", 
                                 num_items, list, 1, 8);
    if (result) {
        int fp;
        char *s;
        s = g_popup_saveas(win_id, "Object File", "gna.gp");
        if (s) {
            printf("Writing Object: %s\n",list[result-1]);
            if ((fp = g_open_object_file(s, TRUE)) == G_ERROR) {
                g_create_object_file(s,"GENTEST", do_compression);
                fp = g_open_object_file(s, TRUE);
            }
            g_write_fileobject(fp, list[result-1], TRUE, TRUE);
            g_close_object_file(fp);
        }
   }

g_erase_fileobject

int g_erase_fileobject(int file_id, char *label)

Description:

Delete an object from disk by the name label.

Inputs:

file_id - The file handle of the object file.

label - The label of the object, as it is stored on disk. Has up to 32 significant characters.

Returns:

G_OK on success and G_ERROR otherwise.

g_first_fileobject

int g_first_fileobject(int file_id, char *label)

Description:

Returns the label of the first object in the file file_id.

Inputs:

file_id - The file handle of the object file.

label - The label of the object, as it is stored on disk. There has to be room to store 33 characters. the user is resposible to allocate memory for label, before this function is called.

Returns:

G_OK on success and G_ERROR otherwise.

g_next_fileobject

int g_next_fileobject(int file_id, char *label)

Description:

Returns the label of the next object in the file file_id.

Inputs:

file_id - The file handle of the object file.

label - The label of the object, as it is stored on disk. There has to be room to store 33 characters. the user is resposible to allocate memory for label, before this function is called.

Returns:

G_OK on success and G_ERROR otherwise.

g_prev_fileobject

int g_prev_fileobject(int file_id, char *label)

Description:

Returns the label of the previous object in the file file_id.

Inputs:

file_id - The file handle of the object file.

label - The label of the object, as it is stored on disk. There has to be room to store 33 characters. the user is resposible to allocate memory for label, before this function is called.

Returns:

G_OK on success and G_ERROR otherwise.

g_last_fileobject

int g_last_fileobject(int file_id, char *label)

Description:

Returns the label of the last object in the file file_id.

Inputs:

file_id - The file handle of the object file.

label - The label of the object, as it is stored on disk. There has to be room to store 33 characters. the user is resposible to allocate memory for label, before this function is called.

Returns:

G_OK on success and G_ERROR otherwise.