Sample Open C API program : create smart points at equal distances along curve
작성자k2ice작성시간08.02.29조회수298 목록 댓글 0Date: 18-APR-2005
Subject: Sample Open C API program : create smart points at equal distances along curve
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_SMART_POINTS_AT_EQUAL_DISTANCES_ALONG_CURVE CCC UFUN */
#include <stdio.h>
#include <string.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_so.h>
#include <uf_obj.h>
#include <uf_curve.h>
#include <uf_object_types.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);
}
/*ARGSUSED*/
static int mask_for_curves(UF_UI_selection_p_t select, void *type)
{
UF_UI_mask_t
mask[4] = { { UF_line_type, 0, 0 },
{ UF_circle_type, 0, 0 },
{ UF_conic_type, 0, 0 },
{ UF_spline_type, 0, 0 } };
if (!UF_CALL(UF_UI_set_sel_mask(select,
UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC, 4, mask)))
return (UF_UI_SEL_SUCCESS);
else
return (UF_UI_SEL_FAILURE);
}
extern tag_t select_a_curve(char *prompt)
{
int
resp;
double
cp[3];
tag_t
object,
view;
UF_CALL(UF_UI_select_with_single_dialog("Select a curve", prompt,
UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY, mask_for_curves, NULL, &resp,
&object, cp, &view));
if (resp == UF_UI_OBJECT_SELECTED || resp == UF_UI_OBJECT_SELECTED_BY_NAME)
{
UF_CALL(UF_DISP_set_highlight(object, 0));
return object;
}
else return NULL_TAG;
}
static logical prompt_for_a_number(char *prompt, char *item, double *number)
{
int
irc,
resp;
char
menu[1][16];
double
da[1];
strcpy(&menu[0][0], item);
da[0] = *number;
resp = uc1609(prompt, menu, 1, da, &irc);
if (resp == 3 || resp == 4)
{
*number = da[0];
return TRUE;
}
else return FALSE;
}
static void create_points_at_distance_along_curve( tag_t curve, double dist )
{
tag_t
last = NULL_TAG,
offset = NULL_TAG,
start = NULL_TAG,
dist_point = NULL_TAG;
double
total_lgth = 0.0,
current_dist = dist;
UF_CALL( UF_CURVE_ask_arc_length ( curve, 0.0, 1.0,
UF_MODL_UNITS_PART, &total_lgth ));
UF_CALL( UF_SO_create_scalar_double(curve, UF_SO_update_after_modeling,
0.0, &start));
UF_CALL(UF_SO_create_point_on_curve(curve, UF_SO_update_after_modeling,
curve, start, &last));
UF_CALL(UF_SO_set_visibility_option(last, UF_SO_invisible));
while( current_dist <= total_lgth )
{
UF_CALL(UF_SO_create_scalar_double(curve, UF_SO_update_after_modeling,
current_dist, &offset ));
UF_CALL( UF_SO_create_point_along_curve(curve,
UF_SO_update_after_modeling, curve, last, offset,
UF_SO_point_along_curve_distance, FALSE, &dist_point));
UF_CALL(UF_SO_set_visibility_option( dist_point, UF_SO_visible ));
current_dist += dist;
if( dist == 0. ) return; /* otherwise this runs
forever for a zero point */
}
}
static void do_it(void)
{
tag_t
curve;
double
ip = 10.0;
while (((curve = select_a_curve("Create points along")) != NULL_TAG)
&& prompt_for_a_number("Distance Along Curve:", "Distance:", &ip))
create_points_at_distance_along_curve(curve, ip);
}
/*ARGSUSED*/
void ufusr(char *param, int *retcode, int paramLen)
{
if (UF_CALL(UF_initialize())) return;
do_it();
UF_terminate();
}
int ufusr_ask_unload(void)
{
return (UF_UNLOAD_IMMEDIATELY);
}
다음검색