/*HEAD EXTEND_SELECTED_CURVE_BY_SPECIFIED_LENGTH CCC UFUN */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_disp.h>
#include <uf_modl.h>
#include <uf_curve.h>
#include <uf_vec.h>
#include <uf_obj.h>
#include <uf_object_types.h>
#include <uf_trns.h>
#include <uf_view.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 void map_abs2view(double c[3])
{
char
vname[30];
double
abs_mx[9] = { 0,0,0, 1,0,0, 0,1,0 },
vw[12] = { 0,0,0 },
mx[12];
int
irc;
UF_CALL(uc1653(vname));
UF_CALL(uc6433(vname, &vw[3]));
FTN(uf5940)(abs_mx, vw, mx, &irc);
FTN(uf5941)(c, mx);
}
static void map_view2abs(double c[3])
{
char
vname[30];
double
abs_mx[9] = { 0,0,0, 1,0,0, 0,1,0 },
vw[12] = { 0,0,0 },
mx[12];
int
irc;
UF_CALL(uc1653(vname));
UF_CALL(uc6433(vname, &vw[3]));
FTN(uf5940)(vw, abs_mx, mx, &irc);
FTN(uf5941)(c, mx);
}
static void ask_pos_on_obj(tag_t obj, double loc[3])
{
tag_t
line;
double
cp[3],
dist;
UF_CURVE_line_t
lp;
map_abs2view(loc);
lp.start_point[0] = loc[0];
lp.start_point[1] = loc[1];
lp.start_point[2] = loc[2] + 1000;
lp.end_point[0] = loc[0];
lp.end_point[1] = loc[1];
lp.end_point[2] = loc[2] - 1000;
map_view2abs(lp.start_point);
map_view2abs(lp.end_point);
UF_CALL(UF_DISP_set_display(FALSE));
UF_CALL(UF_CURVE_create_line(&lp, &line));
UF_CALL(UF_MODL_ask_minimum_dist(obj, line, 0, cp, 0, cp, &dist, loc, cp));
UF_CALL(UF_OBJ_delete_object(line));
UF_CALL(UF_DISP_set_display(TRUE));
}
static int ask_curve_close_end(tag_t curve, double pos[3])
{
double
dist[2],
end[3],
junk[3],
start[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));
UF_VEC3_distance(pos, start, &dist[0]);
UF_VEC3_distance(pos, end, &dist[1]);
if (dist[0] < dist[1]) return 1;
else return 2;
}
/*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_end(char *prompt, int *which_end)
{
int
resp;
tag_t
object,
view;
double
pos[3];
UF_CALL(UF_UI_select_with_single_dialog(prompt, "",
UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY, mask_for_curves, NULL, &resp,
&object, pos, &view));
if (resp == UF_UI_OBJECT_SELECTED || resp == UF_UI_OBJECT_SELECTED_BY_NAME)
{
ask_pos_on_obj(object, pos);
*which_end = ask_curve_close_end(object, pos);
UF_CALL(UF_DISP_set_highlight(object, FALSE));
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 do_it(void)
{
int
location;
tag_t
curve;
double
length = { 1.0 };
while (((curve = select_a_curve_end("Select curve to extend", &location))
!= NULL_TAG) && (prompt_for_a_number("How far", "Extend", &length)))
UF_CALL(UF_CURVE_edit_length(curve, 1, length, location,
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);
}
카페 게시글
검색이 허용된 게시물입니다.
UG/Open API Sample
Sample API program to extend selected curve by specified length
야누스21
추천 0
조회 51
04.03.17 18:07
댓글 0
다음검색