Dazu gibt es ein Beispiel bei uganswer:
#include <stdio.h>
#include <string.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_curve.h>
#include <uf_disp.h>
#include <uf_vec.h>
#include <uf_csys.h>
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
struct rectangle_data_s {
double
origin[3],
x_axis[3],
y_axis[3],
opposite[3];
};
typedef struct rectangle_data_s rectangle_data_t, *rectangle_data_p_t;
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);
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);
}
void ask_wcs_x_and_y_axes(double *xaxis, double *yaxis)
{
tag_t
wcs,
wcs_mx;
double
axes[9],
mag,
origin[3];
UF_CALL(UF_CSYS_ask_wcs(&wcs));
UF_CALL(UF_CSYS_ask_csys_info(wcs, &wcs_mx, origin));
UF_CALL(UF_CSYS_ask_matrix_values(wcs_mx, axes));
UF_VEC3_unitize(&axes[0], 0, &mag, xaxis);
UF_VEC3_unitize(&axes[3], 0, &mag, yaxis);
}
void rubberband_rectangle_cb(double *screen_pos,
UF_UI_motion_cb_data_p_t motion_cb_data, void *client_data)
{
double
dx[3],
dy[3],
end[3],
pos[5][3],
start[3];
rectangle_data_p_t
my_data = (rectangle_data_p_t) client_data;
UF_CSYS_map_point(UF_CSYS_ROOT_COORDS, my_data->origin, UF_CSYS_ROOT_WCS_COORDS, start);
UF_CSYS_map_point(UF_CSYS_ROOT_COORDS, screen_pos, UF_CSYS_ROOT_WCS_COORDS, end);
UF_VEC3_scale( end[0] - start[0], my_data->x_axis, dx );
UF_VEC3_scale( end[1] - start[1], my_data->y_axis, dy );
UF_VEC3_copy( my_data->origin, pos[0] );
UF_VEC3_add( pos[0], dx, pos[1] );
UF_VEC3_add( pos[1], dy, pos[2] );
UF_VEC3_sub( pos[2], dx, pos[3] );
UF_VEC3_sub( pos[3], dy, pos[4] );
UF_CALL(UF_DISP_display_ogp_polyline(motion_cb_data->view_tag, pos, 5));
}
logical specify_rectangle(char *prompt, rectangle_data_p_t the_data)
{
int
resp;
tag_t
view;
char
msg[133];
sprintf(msg, "%s corner 1", prompt);
UF_CALL(UF_UI_specify_screen_position(msg, NULL, NULL, the_data->origin, &view, &resp));
if (resp != UF_UI_PICK_RESPONSE) return FALSE;
ask_wcs_x_and_y_axes(the_data->x_axis, the_data->y_axis);
sprintf(msg, "%s corner 2", prompt);
UF_CALL(UF_UI_specify_screen_position(msg, rubberband_rectangle_cb, (void *)the_data, the_data->opposite, &view, &resp));
if (resp != UF_UI_PICK_RESPONSE) return FALSE;
return TRUE;
}
void create_curve_rectangle(rectangle_data_p_t where)
{
tag_t
lines[4];
double
pos[4][3],
dx[3],
dy[3],
end[3],
start[3];
UF_CURVE_line_t
line_data = { 0,0,0, 0,0,0 };
UF_CSYS_map_point(UF_CSYS_ROOT_COORDS, where->origin, UF_CSYS_ROOT_WCS_COORDS, start);
UF_CSYS_map_point(UF_CSYS_ROOT_COORDS, where->opposite, UF_CSYS_ROOT_WCS_COORDS, end);
UF_VEC3_scale( end[0] - start[0], where->x_axis, dx );
UF_VEC3_scale( end[1] - start[1], where->y_axis, dy );
UF_VEC3_copy( where->origin, pos[0] );
UF_VEC3_add( pos[0], dx, pos[1] );
UF_VEC3_add( pos[1], dy, pos[2] );
UF_VEC3_sub( pos[2], dx, pos[3] );
UF_VEC3_copy( pos[0], line_data.start_point);
UF_VEC3_copy( pos[1], line_data.end_point);
UF_CALL(UF_CURVE_create_line(&line_data, &lines[0]));
UF_VEC3_copy( pos[1], line_data.start_point);
UF_VEC3_copy( pos[2], line_data.end_point);
UF_CALL(UF_CURVE_create_line(&line_data, &lines[1]));
UF_VEC3_copy( pos[2], line_data.start_point);
UF_VEC3_copy( pos[3], line_data.end_point);
UF_CALL(UF_CURVE_create_line(&line_data, &lines[2]));
UF_VEC3_copy( pos[3], line_data.start_point);
UF_VEC3_copy( pos[0], line_data.end_point);
UF_CALL(UF_CURVE_create_line(&line_data, &lines[3]));
}
void do_it(void)
{
rectangle_data_t
where;
while (specify_rectangle("Define rectangle", &where))
create_curve_rectangle(&where);
}
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);
}
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP