DataGrid Object


Overview

The DataGrid object class is used to store, retrieve and manipulate two-dimensional arrays or grids of data. Each data group may contain multiple grid objects, such as multiple blocks of cells in a table. The grid is described by pointing to a defined two- dimensional array, then describing:

The type of data contained in a DataGrid Object can be float, short, integer, long, or double.


Example

The following example shows the code structure for a typical DataGrid object.

   float grid[NX*NY];
   Object grid_data;
   ...
   for (i=0; i<NX*NY; i++) grid [i] = i
        grid_data = (Object) XtVaCreateWidget("Grid",
	                         (WidgetClass)xintDataGridObjectClass, 
	                         edit,
	                         XmNgridArray, grid,
	                         XmNxCount, NX,
	                         XmNyCount, NY,
	                         XmNgridOrder, XintX_VECTOR,
	                         XmNdataGroup, data_group, NULL);


Inherited Resources and Behavior

The DataGrid object class does not inherit behavior and resources from any other object class.

The following resources are defined by the DataGrid object class:
NameTypeDefaultAccess
XmNcopyDataBooleanTrueCSG
XmNdataGroupObjectNULLCSG
XmNdataTypeintXintDATA_TYPE_FLOATCSG
XmNeditableBooleanTrueCSG
XmNgridArrayXtPointerNULLCSG
XmNgridOrderintXintX_VECTORCSG
XmNlastViewDestroyBooleanTrueCSG
XmNupdateCallbackXtCallbackListNULLCSG
XmNxCountint0CSG
XmNyCountint0CSG
XmNxRangeXintRange *NULLCSG
XmNyRangeXintRange *NULLCSG


XmNcopyData

If True, this resource will allocate memory to store a copy of the data, then free the memory allocation when the object is destroyed. If False, the widget does not create a copy of the data nor does it manage memory for this purpose.

XmNdataGroup

Specifies the object ID of the data group to which this data grid belongs. This resource must be specified if the data grid object is to be placed inside a data group.

XmNdataType

This resource specifies the data type for the array named in XmNgridArray. The resource value may be one of the following:

Resource ValueDescription
XintDATA_TYPE_FLOAT (default)Data type is float.
XintDATA_TYPE_SHORTData type is short.
XintDATA_TYPE_INTEGERData type is integer.
XintDATA_TYPE_LONGData type is long.
XintDATA_TYPE_DOUBLEData type is double.


XmNeditable

Specifies whether or not this data series can be edited when displayed in a view.

XmNgridArray

This resource specifies the name of the array containing the gridded data. The data type of the array can be defined using the XmNdataType resource.

XmNgridOrder

This resource specifies the direction in which the grid is ordered. For example, in a table with Y orientation, the array values are arranged column-by-column; in X orientation they are arranged row-by-row. The selected X or Y orientation is maintained when the data is transferred to chart views and the data is plotted accordingly.

The following constants describe the grid orientation for the XmNgridOrder resource.

Resource ValueDescription
XintX_VECTORGrid is ordered in the X direction.
XintY_VECTOR (default)Grid is ordered in the Y direction.


XmNlastViewDestroy

Specifies whether or not to automatically destroy this data object when there are no more views connected to the data. If this data object is inserted into a DataGroup, you only need to set this resource for the DataGroup object.

XmNupdateCallback

This resource allows you to attach a callback to the Grid object that is invoked each time the data has changed. See the following section for more information on this callback.

XmNxCount, XmNyCount

These resources specify the size of the grid in the X and Y directions. In a table, X count is the number of rows, and Y count is the number of columns.

XmNxRange, XmNyRange

These resources let you define the grid data range in the X or Y direction as a start and an increment. If you don't specify a value for this resource, the starting value is set to be 0 and the increment 1.

The actual start/increment values are defined through the data structure XintRange, which takes the following form:

   typedef struct {
                   float      start;
                   float      increment;
   } XintRange;

where:

MemberDescription
startStarting value.
incrementIncrement.


Callback

Callback XmNupdateCallback provides notification of changes in a grid object. This notification can be used to ensure that updates to one view are properly reflected in all other views. The callback structure takes the following form:

   typedef struct {
                   int        reason;
                   XEvent     *event;
                   Object     object;
                   int        x_start;
                   int        y_start;
                   int        x_count;
                   int        y_count;
                   float      minimum;
                   float      maximum;
   } XintDataGridUpdateCallbackStruct;

If you have multiple DataGrid or other objects in a group, this callback must be registered separately for each individual data object. If you prefer to control updates at the group level, you should register this callback only once for the DataGroup object and use the XintDataGroupUpdateCallbackStruct discussed earlier in this manual.

Structure XintDataGridUpdateCallbackStruct contains information that indicates why and how the object was modified. This information can help optimize the redrawing and updating of the appropriate views. The following ordered table lists the members of structure XintDataGridUpdateCallbackStruct:

Data TypeMemberDescription
intreasonIndicates why callback was invoked (see table below).
XEvent *eventStandard member in Motif callback structure; not used in this context (will alwa ys be NULL).
ObjectobjectID of the updated object.
intx_startStarting index of X value updated (starts at 0).
inty_startStarting index of Y value updated (starts at 0).
intx_countTotal number of X values updated.
inty_countTotal number of Y values being updated.
floatminimumNew minimum of updated values.
floatmaximumNew maximum of updated values.

Member reason provides information explaining why and how the update occurred. Possible values for member reason are:

ReasonDescription
XintCR_DATA_UPDATE XintCR_DATA_BATCHEntire data grid has been changed, no more information is available.
XintCR_DATA_REPLACEA portion of the grid (as specified by x_start, y_start, x_count and y_count) has been replaced.


Functions

The following functions are available for creating and manipulating grid data objects.

Function NameDescription
XintCreateDataGridCreates a new data grid object.
XintDataGridGetGridArrayRetrieves any part of a grid.
XintDataGridDataReplaceReplaces data in a grid.


XintCreateDataGrid

The XintCreateDataGrid function lets you create a new data grid object. The function argument list should contain any resource settings that you want to specify for the new grid object.

     Object XintCreateDataGrid(...)

WidgetparentParent of new data grid object.
char *nameName of new data grid object.
ArgListarglistList of resources to be set for this data grid.
CardinalargcountTotal number of resources being set.


XintDataGridGetGridArray

The XintDataGridGetGridArray function retrieves any part of a DataGrid object as a floating point array. You will have to free the array after it is no longer needed.

     float *XintDataGridGetGridArray (...)

ObjectobjectObject ID of the data grid in which data is being retrieved.
intx_startStarting X value in the area of the grid to be retrieved.
inty_startStarting Y value in the area of the grid to be retrieved.
intx_countTotal number of X values to be retrieved.
inty_countTotal number of Y values to be retrieved.


XintDataGridDataReplace

The XintDataGridDataReplace function lets you replace the data within a specified area of a specified grid. The function arguments let you specify a predefined array to be inserted, along with the starting x,y values and the number of values to be replaced in both the X and Y directions. The function returns False if there is a bad argument or the function cannot be performed.

     Boolean XintDataGridDataReplace (...)

ObjectobjectObject ID of the data grid in which data is being replaced.
XtPointerarrayArray containing the replacement data. The data type for this array should be the same as the type specified by XmNdataType.
intx_startStarting X value in the area of the grid being replaced.
inty_startStarting Y value in the area of the grid being replaced.
intx_countTotal number of X values being replaced.
inty_countTotal number of Y values being replaced.


Macros

Macro XintIsDataGrid returns True if the specified object is a DataGrid object.

     Boolean XintIsDataGrid (Object object)