Date: 18-APR-2005
Subject: Sample Open C API program : create variable radius blends
Note: GTAC provides programming examples for illustration only, and
assumes that you are familiar with the programming language being
demonstrated and the tools used to create and debug procedures. GTAC
support professionals can help explain the functionality of a particular
procedure, but we will not modify these examples to provide added
functionality or construct procedures to meet your specific needs.
/*HEAD CREATE_VARIABLE_RADIUS_BLENDS CCC UFUN */
/* This sample program requires *
* point objects to be created *
* at the points on the edge *
* where various radius values *
* will be assigned */
#include <stdio.h>
#include <string.h>
#include <uf.h>
#include <uf_curve.h>
#include <uf_modl.h>
#include <uf_ui.h>
#include <uf_object_types.h>
#include <uf_part.h>
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
static int report_error( char *file, int line, char *call, int irc)
{
if (irc)
{
char err[133],
msg[133];
sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
irc, line, file);
UF_get_fail_message(irc, err);
/* NOTE: UF_print_syslog is new in V18 */
UF_print_syslog(msg, FALSE);
UF_print_syslog(err, FALSE);
UF_print_syslog("\n", FALSE);
UF_print_syslog(call, FALSE);
UF_print_syslog(";\n", FALSE);
if (!UF_UI_open_listing_window())
{
UF_UI_write_listing_window(msg);
UF_UI_write_listing_window(err);
UF_UI_write_listing_window("\n");
UF_UI_write_listing_window(call);
UF_UI_write_listing_window(";\n");
}
}
return(irc);
}
static int select_edges(char *prompt, tag_t **edges)
{
int
ii,
irc,
n;
UF_UI_selection_options_t
opts;
UF_UI_mask_t
mask;
opts.num_mask_triples = 1;
opts.mask_triples = &mask;
opts.scope = UF_UI_SEL_SCOPE_WORK_PART;
mask.object_type = UF_solid_type;
mask.object_subtype = 0;
mask.solid_type = UF_UI_SEL_FEATURE_ANY_EDGE;
UF_CALL(UF_UI_select_by_class(prompt, &opts, &irc, &n, edges));
for (ii=0; ii<n; ii++)
UF_CALL(UF_DISP_set_highlight(*(*edges + ii), FALSE));
return n;
}
static tag_t select_a_point(char *prompt)
{
double
cp[3];
int
resp;
tag_t
point,
view;
UF_UI_selection_options_t
opts;
UF_UI_mask_t
mask;
opts.num_mask_triples = 1;
opts.mask_triples = &mask;
opts.scope = UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY;
mask.object_type = UF_point_type;
mask.object_subtype = 0;
mask.solid_type = 0;
UF_CALL(UF_UI_select_single(prompt, &opts, &resp, &point, cp, &view));
if (resp == 4 || resp == 5)
{
UF_CALL(UF_DISP_set_highlight(point, 0));
return point;
}
else return NULL_TAG;
}
static int vrb_routine(tag_t eid, double points[100][3], char radii[100][256],
int smooth_overflow, int cliff_overflow,
int notch_overflow, double vrb_tol,
int *number_of_points)
{
int
num_char,
ii = 0;
tag_t
pt_tag;
UF_CALL(UF_DISP_set_highlight(eid, 1));
while((pt_tag = select_a_point("point on highlited edge")) != NULL_TAG)
{
UF_CALL(UF_CURVE_ask_point_data(pt_tag, &points[ii][0]));
uc1600("Enter radius value for point", radii[ii], &num_char);
ii ++;
}
UF_CALL(UF_DISP_set_highlight(eid, 0));
*number_of_points = ii;
return(0);
}
static uf_list_p_t make_a_list( int count, tag_t *item_array)
{
uf_list_p_t list;
int ii;
UF_CALL( UF_MODL_create_list( &list));
for( ii = 0; ii < count; ii++)
UF_CALL( UF_MODL_put_list_item( list, item_array[ii]));
return( list);
}
static void do_it(void)
{
tag_t
feat_id,
*edges;
double
vrb_tol = 0.00001;
int
num_edges,
smooth_overflow = UF_MODL_BLEND_SMOOTH_OVERFLOW,
cliff_overflow = UF_MODL_BLEND_CLIFF_OVERFLOW,
notch_overflow = UF_MODL_BLEND_NOTCH_OVERFLOW;
uf_list_p_t
edge_list;
UF_CALL(UF_MODL_register_var_blend(vrb_routine));
while ((num_edges = select_edges("select edges to blend", &edges)) > 0)
{
edge_list = make_a_list(num_edges, edges);
UF_free(edges);
UF_CALL(UF_MODL_create_blend("0.009246", edge_list, smooth_overflow,
cliff_overflow, notch_overflow, vrb_tol, &feat_id));
UF_CALL(UF_MODL_delete_list(&edge_list));
}
UF_CALL(UF_MODL_unregister_var_blend());
}
void ufusr(char *param, int *retcode, int paramLen)
{
if (!UF_CALL(UF_initialize()))
{
do_it();
UF_CALL(UF_terminate());
}
}
int ufusr_ask_unload(void)
{
return (UF_UNLOAD_IMMEDIATELY);
}