Base Widget Library Introduction

This chapter describes the base widget classes that are used by the widgets in the Geoscience library. The base widget classes handle a number of tasks that are common to all the specific end-user widgets, including support for hardcopy output, ability to edit and display graphic objects, ability to define a user coordinate system and draw annotation, etc.

Summary of Components

The following widget classes are described in this section:


Class Hierarchy

The INT widget library is based on a hierarchy of classes, where the subclasses inherit behavior and resources from their superclass. The following diagram illustrates the hierarchy of widgets that are subclassed from the Motif Manager widget class.


Figure 1: Widget Class Hierarchy.


Widget Interface

Widgets in the INT library can be created in exactly the same manner as Motif widgets. You can use the Xt creation functions:

    Widget XtCreateWidget (String, WidgetClass, ArgList, Cardinal);
    Widget XtVaCreateWidget (String, WidgetClass,...);

Additionally, a creation convenience function is provided by each object class. For example, you can create a Grid widget using the Xt creation function as follows:

    Widget grid_widget;

    grid_widget = XtVaCreateWidget ("grid", xintGridWidgetClass, parent,
                                    XmNwidth, 500, XmNheight, 500, NULL);

or, using the creation function provided by the Grid widget class:

    n = 0;
    XtSetArg (arg[n], XmNwidth, 500); n++;
    XtSetArg (arg[n], XmNheight, 500; n++;
    
    grid_widget = XintCreateGrid (parent, "grid", arg, n);

The parent widget can be any valid Motif composite widget.

Changing widget attributes can be accomplished with the Xt functions:

    void XtSetValues (Widget, ArgList, Cardinal);
    void XtVaSetValues (Widget,...);

For example, the following code sample changes the vertical major grid line style of a Grid widget:

    XtVaSetValues (grid_widget, XmNverticalMajorGridLineStyle, 
                   XintGRID_LINE_DASHED, NULL);


Pointer Resources

Many resources in the INT library are specified as pointers to data structures, floating point values, or data arrays. Unless specified otherwise, an internal copy of the data is made by the widget or object, so you don't need to keep the memory allocated. For example, the list of points to a polyline object is specified as an array of points using resource XmNpointArray. You can free this array after you have used it to create or modify a polyline object.

Functions XtSetValues and XtVaSetValues, when applied to a pointer resource, return the pointer to the internal widget or object data. You should not modify this data directly. This is a common error that often occurs when trying to modify a resource. The following example, which applies a horizontal translation to a rectangle object, illustrates the problem.

    Object rect_object;
    XintRectangle *rectangle, new_rectangle;
    ...
    XtVaGetValues((Widget) rect_object, XmNrectangle, &rectangle, NULL);

    /* DON'T modify structure rectangle directly; copy data first...*/
    new_rectangle = *rectangle;

    /* apply translation */
    new_rectangle.x1 += tx;
    new_rectangle.x2 += tx;
    XtVaSetValues((Widget) rect_object, XmNrectangle, &new_rectangle, NULL);
    ...


Grid Example

The following example (see file grid_1.c in directory examples) illustrates how to build a grid with multiple axes. The left and bottom annotation as well as the grid lines are handled directly by the Grid widget, the extra annotation is obtained by creating additional axis widgets. The placement of the Axis widgets is handled automatically by the Grid class (see Grid Constraint Resources section).

    #include <Xm/Xm.h>
    #include <Xm/Form.h>
    #include <Xm/Separator.h>
    #include <Xm/PushB.h>
    #include <Xint/Axis.h>
    #include <Xint/Grid.h>

    /* declare subroutines */

    static void BuildUI();

    /* declare callbacks */
    static void ExitProc();

    /* declare global variables */
    Widget toplevel_widget;

    main(argc, argv)
    int argc;
    char *argv[];
    {
       XtAppContext app_context;

       toplevel_widget = XtAppInitialize (&app_context, "Example", NULL, 0,
                                          &argc, argv, NULL, NULL, 0);

       BuildUI ();

       XtRealizeWidget(toplevel_widget);
       XtAppMainLoop(app_context);
    }

    /***
     *** BuildUI
     ***/
    static void BuildUI()
    {
          Widget form, grid, separator, exit_pb;
          float hstart = 0;
          float hend = 700;
          float vstart = 0;
          float vend = 280;
          float major = 100;
          float minor = 50;
          float start, end;
          Widget axis1, axis2;
          XmString cstring;
    
          /* create the form widget */
          form = XtVaCreateManagedWidget("form", xmFormWidgetClass,
                                         toplevel_widget, NULL);

          /* create a Grid widget */
          grid = XtVaCreateManagedWidget("grid", xintGridWidgetClass, form,
                                         XmNtitleString, "Survey Boundaries",
                                         XmNverticalAnnotationFormat, "%.0f",
                                         XmNverticalLabel, "Y Cell Number",
                                         XmNverticalLabelPlacement, 
                                                         XintPLACEMENT_LEFT,
                                         XmNverticalAnnotationPlacement, 
                                                         XintPLACEMENT_LEFT,
                                         XmNverticalMinorGridLineStyle, 
                                                         XintGRID_LINE_DASHED,
                                         XmNverticalMajorThickness, 1,
                                         XmNverticalStart, &vstart,
                                         XmNverticalEnd, &vend,
                                         XmNverticalMajorIncrement, &major,
                                         XmNverticalMinorIncrement, &minor,
                                         XmNhorizontalMinorGridLineStyle, 
                                                          XintGRID_LINE_DASHED,
                                         XmNhorizontalMajorThickness, 1,
                                         XmNhorizontalLabel, "X Cell Number",
                                         XmNhorizontalLabelPlacement, 
                                                          XintPLACEMENT_BOTTOM,
                                         XmNhorizontalAnnotationPlacement, 
                                                          XintPLACEMENT_BOTTOM,
                                         XmNhorizontalStart, &hstart,
                                         XmNhorizontalEnd, &hend,
                                         XmNhorizontalMajorIncrement, &major,
                                         XmNhorizontalMinorIncrement, &minor,
                                         XmNhorizontalMajorGridLineStyle, 
                                                          XintGRID_LINE_SOLID,
                                         XmNautoMarginAdjust, XintADJUST_ALL,
                                         XmNwidth, 650,
                                         XmNheight, 600,
                                         XmNtopAttachment, XmATTACH_FORM,
                                         XmNleftAttachment, XmATTACH_FORM,
                                         XmNrightAttachment, XmATTACH_FORM, 
                                         NULL);

          /* create axes */
          start = 0;
          end = 32000;
          major = 8000;
          minor = 4000;
          axis1 = XtVaCreateManagedWidget("axis1", xintAxisWidgetClass, grid,
                                          XmNorientation, XintVERTICAL,
                                          XmNannotationFormat, "%.0f",
                                          XmNaxisLineThickness, 1,
                                          XmNaxisOffset, 0,
                                          XmNstart, &start,
                                          XmNend, &end,
                                          XmNmajorIncrement, &major,
                                          XmNminorIncrement, &minor,
                                          XmNlabel, "Y (feet)", NULL);

          axis2 = XtVaCreateManagedWidget("axis2", xintAxisWidgetClass, grid,
                                          XmNorientation, XintHORIZONTAL,
                                          XmNannotationFormat, "%.0f",
                                          XmNaxisLineThickness, 1,
                                          XmNstart, &start,
                                          XmNend, &end,
                                          XmNmajorIncrement, &major,
                                          XmNminorIncrement, &minor,
                                          XmNaxisOffset, 0,
                                          XmNlabel, "X (feet)", NULL);
          /* create separator */
          ...
    }

The output from this example is shown below:


Figure 2: Grid Widget Example.


Scrolling

Scrolling of INT widgets can be accomplished by creating the widgets inside a Motif ScrolledWindow widget or inside an INT Scroll widget. The Scroll widget will scroll its child so that the annotation remains visible during scrolling. You can use the Scroll widget in conjunction with the Grid, Image, Seismic, Segy, Contour and EditTable widget classes. The code sample below (see example segy_2.c in directory examples) shows how to use the Scroll widget to scroll a display containing seismic traces.

    /* create a Scroll widget */

    int_scroll = XtVaCreateManagedWidget("int_scroll", xintScrollWidgetClass, 
                                         toplevel_widget,
                                         XmNwidth, 500,
                                         XmNheight, 500,
                                         XmNscrollBarExtend, False, NULL);

    /* create the segy widget */
    traces_per_inch = 7.0;
    segy_widget= XtVaCreateManagedWidget ("segy_widget", 
                                          xintSegyWidgetClass,
                                          int_scroll,
                                          XmNplotTitle,    
                                             "Segy Example with Scroll widget",
                                          XmNplotType, XintPOSITIVE_COLOR_FILL +
                                                       XintNEGATIVE_COLOR_FILL +
                                                       XintWIGGLE,
                                          XmNcolorScale, XintCOLOR_SCALE_LEFT,
                                          XmNcolormapFile, "seg.cmp",
                                          XmCColorScaleSize, 400,
                                          XmNtracesPerInch, &traces_per_inch,
                                          XmNsegyFilename, "segy1.dat",
                                          XmNautoMarginAdjust, XintADJUST_ALL, 
                                          NULL);

The output produced by this example is shown below:


Figure 3: Fixed annotation scrolling with the Scroll widget.


Hardcopy Output

Hardcopy output functions are provided for the widgets and objects defined in the Geoscience library. Using the supplied functions, an application can produce a file containing the PostScript or CGM representation of a single widget (and all the graphic objects displayed inside) or a composite of several widgets. Once the PostScript or CGM file is generated, you can use your local print/plot utilities to produce the hardcopy output.

The hardcopy mechanism supports a powerful composition mechanism which enables the application to output multiple widgets into one plot file. For example, one can automatically output a composite of several INT widgets, based on the screen layout, in one function call. It is also possible to compose the hardcopy output manually by explicitly specifying the position of each widget for the plot.

All the functions related to hardcopy output are defined in the CompBase widget class. See the CompBase reference section in this chapter for a complete description of those functions.


Object Display and Editing

The EditObject class supports the display and editing of graphical objects, including low level objects such as text, line, polygons or rectangles, as well as higher level objects such as log curves, markers or lithologies. See WellLog documentation for a complete description of the objects included in the WellLog library. See also the ChartObject Library documentation for an introduction and description of the objects contained in the GraphicObject Library.