Personal tools
You are here: Home / cmgui / Wiki / Writing new computed fields for cmgui
Navigation
Log in


Forgot your password?
 

Writing new computed fields for cmgui

Introduction

This page is a guide to writing a new computed field, along with all the different routines required. The easiest way to write a computed field is to use code for an existing computed field as your starting point and then modify it. Start with the computed field that is closest to the one you want to write. This guide is written using the sin computed field as an example of syntax etc.

Define a class for your computed field

The class definition for your computed field indicates what functionality it provides. Some of the smaller function definitions are actually included within the class definition, the larger ones are implemented after the definition. This class inherits from the Computed_field_core (defined in computed_field_private.hpp). The Computed_field_Core class provides a large list of virtual functions common to all computed fields. The Computed_field_core also holds a Computed_field object, which is a data structure to hold field information (field name, values etc).

Syntax:

class Computed_field_sin : public Computed_field_core

The class definition will include prototypes of all the field specific member functions. This class will have a destructor and constructor object as well as several functions that are required to give the field specific behaviour. The required functions provide the ability to

  • construct a new computed field object:

    Computed_field_sin(Computed_field *field) : Computed_field_core(field)
    
  • destroy a computed field object (if not specified a default destructor will be created):

    ~Computed_field_sin()
    
  • make a copy of the computed field object:

    Computed_field_core *copy(Computed_field* new_parent)
    
  • get the type of the computed field object:

    char *get_type_string()
    
  • compare the computed field against another to check if they are the same:

    int compare(Computed_field_core* other_field)
    
  • evaulate the field at a location:

    int evaluate_cache_at_location(Field_location* location);
    
  • list out the options used to create the field:

    int list();
    
  • get the command string used to create the field:

    char* get_command_string();
    

Implement class member functions

Routines must be written to do all of the above tasks. The naming of these functions should be consistent across all fields as the code relies on functions like the copy function to have the same name for every field.

Write package methods

Example code:

int Computed_field_register_types_trigonometry(
      struct Computed_field_package *computed_field_package);




int Computed_field_set_type_sin(struct Computed_field *field,
      struct Computed_field *source_field)


int Computed_field_get_type_sin(struct Computed_field *field,
      struct Computed_field **source_field)


int define_Computed_field_type_sin(struct Parse_state *state,
      void *field_void,void *computed_field_component_operations_package_void)