Date: 18-APR-2005
Subject: Sample Open C API program : trim curve to plane
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 TRIM_CURVE_TO_PLANE CCC UFUN */
#include <stdio.h>
#include <string.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_object_types.h>
#include <uf_obj.h>
#include <uf_disp.h>
#include <uf_modl.h>
#include <uf_vec.h>
#include <uf_curve.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);
}
static tag_t select_a_curve(char *prompt)
{
int
resp;
double
cp[3];
tag_t
object,
view;
UF_CALL(UF_UI_select_with_single_dialog(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;
}
/*ARGSUSED*/
static int mask_for_planes(UF_UI_selection_p_t select, void *type)
{
UF_UI_mask_t
mask = { UF_plane_type, 0, 0 };
if (!UF_CALL(UF_UI_set_sel_mask(select,
UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC, 1, &mask)))
return (UF_UI_SEL_SUCCESS);
else
return (UF_UI_SEL_FAILURE);
}
static tag_t select_a_plane(char *prompt)
{
int
resp;
double
cp[3];
tag_t
object,
view;
UF_CALL(UF_UI_select_with_single_dialog(prompt, "",
UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY, mask_for_planes, 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 void ask_curve_ends(tag_t curve, double start[3], double end[3])
{
double
junk[3];
UF_CALL(UF_MODL_ask_curve_props(curve, 0.0, start, junk, junk, junk,
junk, junk));
UF_CALL(UF_MODL_ask_curve_props(curve, 1.0, end, junk, junk, junk,
junk, junk));
}
static void display_temporary_colored_point(double *coords, int color)
{
UF_OBJ_disp_props_t
attrib = { 1, UF_OBJ_WHITE, UF_OBJ_NOT_BLANKED, UF_OBJ_WIDTH_NORMAL,
UF_OBJ_FONT_SOLID, FALSE};
attrib.color = color;
UF_CALL(UF_DISP_display_temporary_point(NULL_TAG, UF_DISP_USE_ACTIVE_PLUS,
coords, &attrib, UF_DISP_ASTERISK));
}
static void do_it(void)
{
tag_t
curve,
epoint,
plane,
spoint;
double
end[3],
edist,
junk[3],
sdist,
start[3];
while (((curve = select_a_curve("Select curve to extend")) != NULL_TAG)
&& ((plane = select_a_plane("Select plane to extend to")) != NULL_TAG))
{
ask_curve_ends(curve, start, end);
UF_CALL(UF_CURVE_create_point(start, &spoint));
UF_CALL(UF_MODL_ask_minimum_dist(spoint, plane, FALSE, junk,
FALSE, junk, &sdist, junk, junk));
UF_CALL(UF_OBJ_delete_object(spoint));
UF_CALL(UF_CURVE_create_point(end, &epoint));
UF_CALL(UF_MODL_ask_minimum_dist(epoint, plane, FALSE, junk,
FALSE, junk, &edist, junk, junk));
UF_CALL(UF_OBJ_delete_object(epoint));
if (edist < sdist) UF_VEC3_copy(end, start);
display_temporary_colored_point(start, UF_OBJ_YELLOW);
UF_CALL(UF_CURVE_edit_trim_curve(curve, plane, start, start,
UF_CURVE_NATURAL_SHAPE));
}
}
/*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);
}
다음검색