The following examples are a C program and a GRIP program. You compile and link the GRIP program using GRADE, then you compile and link the User Function program using UFMENU. You then open a part that contains a line and/or a point. You execute the internal User Function program which calls the GRIP program. In the code that follows the User Function program is shown first.
#include <stdio.h>
#include <uf.h>
#include <uf_drf.h>
#include <uf_object_types.h>
void ufusr (char *param, int *retcod, int param_len)
{
/******************************************************************
* User Function calling GRIP sample program
*
* Define the argument structure needed for communication of
* parameters to GRIP for this application. Pass the parameters for
* masking and single selection. Receive the parameters concerning
* the results of single selection. Use the results to create a
* label.
*
****************************************************************/
double masks[11], pick_point[3], user_response;
tag_t object;
char select_message[133], pick_view[133];
char *grip_exe = "demo_ufun_call_grip.grx";
int status;
int grip_arg_count = 6;
UF_args_t grip_arg_list[6];
/* Define the argument list for User Function calling GRIP */
grip_arg_list[0].type = UF_TYPE_DOUBLE_ARRAY;
grip_arg_list[0].length = 11;
grip_arg_list[0].address = masks;
grip_arg_list[1].type = UF_TYPE_CHAR;
grip_arg_list[1].length = 0;
grip_arg_list[1].address = select_message;
grip_arg_list[2].type = UF_TYPE_TAG_T;
grip_arg_list[2].length = 0;
grip_arg_list[2].address = &object;
grip_arg_list[3].type = UF_TYPE_DOUBLE_ARRAY;
grip_arg_list[3].length = 3;
grip_arg_list[3].address = pick_point;
grip_arg_list[4].type = UF_TYPE_CHAR;
grip_arg_list[4].length = 0;
grip_arg_list[4].address = pick_view;
grip_arg_list[5].type = UF_TYPE_DOUBLE;
grip_arg_list[5].length = 0;
grip_arg_list[5].address = &user_response;
/* Initialize the input arguments to the GRIP program */
/* masks[0] is the count of mask types */
masks[0] = 2;
masks[1] = UF_point_type;
masks[2] = UF_line_type;
strcpy (select_message, "Select A Point Or A Line.");
/* Execute the GRIP program */
UF_initialize();
status = UF_call_grip (grip_exe, grip_arg_count, grip_arg_list);
/* Create a label if execution was successful and an object was picked */
if ( (status == 0) && (user_response >= 3) )
{
tag_t label;
double label_origin[3];
char label_text[1][133];
int lines_of_text = 1;
int leader_method = 1;
strcpy (label_text[0], pick_view);
label_origin[0] = pick_point[0];
label_origin[1] = pick_point[1] - 0.5;
label_origin[2] = 0.0;
uc5541(lines_of_text, label_text, label_origin,
leader_method,object, pick_point, &label);
}
else if (status != 0)
{
char error_message[133];
UF_get_fail_message (status, error_message);
fprintf (stderr, "UF_call_grip failed due to: %s\n",
error_message);
}
UF_terminate();
}
The following is the example GRIP program.
$$
$$ User Function calling GRIP sample program
$$
$$ Perform single selection with the specified mask and cue.
$$ Return the selected object, the pick point in absolute, the view
$$ name picked in, and the user response.
$$
$$ Input from User Function
$$ masks : selection mask
$$ masks(1) = count of object types specified
$$ masks(2..11) = object type codes
$$ selmsg: Cue for single selection
$$
$$ Output to User Function
$$ object : selected object from single selection
$$ pickpt : 3d pick point in Absolute space
$$ pickvw : view pick occurred in
$$ usresp : user response to the single selection dialog
$$
$$ Declarations
$$
gripsw / declrv
number / masks(11), pickpt(3), usresp
entity / object, abssys
string / selmsg(132), pickvw(132)
$$ Register and initialize the argument list with User Function.
ufargs / masks, selmsg, object, pickpt, pickvw, usresp
$$ Set the selection mask as requested by User Function.
mask / all
if / masks(1) > 0 AND masks(1) < 10,$
mask / masks(1+1..masks(1)+1)
$$ Perform single selection.
ident / selmsg, object, cursor, pickpt(1), pickpt(2),$
pickpt(3), usresp
jump / halt:, halt:, usresp
$$ Find the view that the selection was made in.
pickvw = &vwsel
$$ Map the pick point from the WCS to the Absolute coordinate system.
abssys = csys / 'TOP'
pickpt = map / pickpt, from, &wcs, to, abssys
$$ Return control to the User Function program.
halt: halt