/******************************************************************************
Copyright (c) 1999 Unigraphics Solutions, Inc.
Unpublished - All Rights Reserved
*******************************************************************************/
/*
The following example allows you to create a circle on an arbitrary
plane. The circle is defined by indicating a center position, followed
by a position on the circle itself. As you move the cursor to the latter
position, the motion callback (passed to
UF_UI_specify_screen_position) will render a visual representation of
the circle you're about to create, as well as a bounding box around the
circle, an arc from 15 degrees to 345 degrees with radius=1.0, and a
"rubberband" line from the circle center the cursor. This example
supports Design in Contet (that is, your Work part may be different
than your Displayed part).
*/
#include <stdio.h>
#include <uf_defs.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_csys.h>
#include <uf_vec.h>
#include <uf_disp.h>
#include <uf_curve.h>
#include <uf_mtx.h>
#include <uf_obj.h>
#include <stdlib.h>
#include <uf_view.h>
#include <math.h>
#include<iomanip>
#include <windows.h>
#include <iostream>
#include <fstream>
/* Define a motion callback to render a visual representation of
* the circle to be created, along with a bounding box around the
* circle, an arc of radius 1.0, and a "rubberband" line from the
* center to the cursor position.
*/
/*void motion_cb(double screen_pos[3] ,UF_UI_motion_cb_data_p_t motion_cb_data, void * data)
{
char str[100];
sprintf(str,"鼠标位置在t (%4.2f,%4.2f,%4.2f)",
screen_pos[0],screen_pos[1],screen_pos[2]);
uc1601(str,0);
} */
static float diameter; //=1;
static float LLA=5; //=1;
static float LLB=5; //=1;
static char tet[256]="1234";
static int ki=1;
static int xxxx1=1;
static int yyyy1=1;
static double wzjd2=1;
static double wznx=0.5;
static double wzny=0.5;
static char distance[100]={30,33,36,40,46};
static double x=0;
static double y=0;
static float k = 0;
typedef struct
{ UF_CURVE_arc_t *arc;
double abs_ctr[3];
double matrix[9];
double x_axis[3];
double y_axis[3];
} my_motion_data_t;
/* Define a motion callback to render a visual representation of
* the circle to be created, along with a bounding box around the
* circle, an arc of radius 1.0, and a "rubberband" line from the
* center to the cursor position.
*/
static void motion_cb( double *screen_pos,
UF_UI_motion_cb_data_p_t motion_cb_data,
my_motion_data_t *my_data )
{
UF_DISP_refresh();
UF_MTX3_vec_multiply( screen_pos,my_data->matrix,my_data->arc->arc_center );
UF_OBJ_disp_props_t color;
color.font=0;
color.line_width=-1;
UF_DISP_ask_closest_color_in_displayed_part(UF_DISP_RED_NAME,&color.color);
// UF_DISP_display_temporary_arc(motion_cb_data->view_tag,UF_DISP_USE_WORK_VIEW, my_data->matrix ,0, 2*PI, my_data->arc->arc_center ,diameter , &color);
double wcs_center[3];
UF_UI_set_status ("Q:单个,A:镜相四件,Z:Y轴镜相,X:X轴镜相,w:增加," ); //在ug右边状态栏 显示提示内容
if (GetAsyncKeyState(65))
{
// uc1601("你按下了A",1);
if(ki==1){
ki=4;
Sleep(100);
}
else if(ki==2){
ki=4;
Sleep(100);}
else if(ki==3){
ki=4;
Sleep(100);}
else if(ki==5){
ki=8;
Sleep(100);}
else if(ki==6){
ki=8;
Sleep(100);}
else if(ki==7){
ki=8;
Sleep(100);}
// ki=4;
UF_DISP_refresh();
}
if (GetAsyncKeyState(81))
{
// uc1601("你按下了Q",1);
if(ki==2){
ki=1;
Sleep(100);
}
else if(ki==2){
ki=1;
Sleep(100);}
else if(ki==3){
ki=1;
Sleep(100);}
else if(ki==4){
ki=1;
Sleep(100);}
else if(ki==6){
ki=5;
Sleep(100);}
else if(ki==7){
ki=5;
Sleep(100);}
else if(ki==8){
ki=5;
Sleep(100);}
// ki=1;
UF_DISP_refresh();
}
if (GetAsyncKeyState(90))
{
// uc1601("你按下了z",1);
if(ki==1){
ki=3;
Sleep(100);
}
else if(ki==2){
ki=3;
Sleep(100);}
else if(ki==4){
ki=3;
Sleep(100);}
else if(ki==5){
ki=7;
Sleep(100);}
else if(ki==6){
ki=7;
Sleep(100);}
else if(ki==8){
ki=7;
Sleep(100);}
// ki=3;
UF_DISP_refresh();
}
if (GetAsyncKeyState(88))
{
// uc1601("你按下了x",1);
if(ki==1){
ki=2;
Sleep(100);
}
else if(ki==3){
ki=2;
Sleep(100);}
else if(ki==4){
ki=2;
Sleep(100);}
else if(ki==5){
ki=6;
Sleep(100);}
else if(ki==7){
ki=6;
Sleep(100);}
else if(ki==8){
ki=6;
Sleep(100);}
// ki=2;
UF_DISP_refresh();
}
if (GetAsyncKeyState(83))
{
// uc1601("你按下了S",1);
if(ki==1){
ki=5;
Sleep(100);
}
else if(ki==2){
ki=6;
Sleep(100);}
else if(ki==3){
ki=7;
Sleep(100);}
else if(ki==4){
ki=8;
Sleep(100);}
else if(ki==5){
ki=1;
Sleep(100);}
else if(ki==6){
ki=2;
Sleep(100);}
else if(ki==7){
ki=3;
Sleep(100);}
else if(ki==8){
ki=4;
Sleep(100);}
UF_DISP_refresh();
}
/* if (GetAsyncKeyState('E'))
{
//uc1601("你按下了w",1);
diameter += 0.5;
UF_DISP_refresh();
}
*/
tag_t wcs;
UF_CSYS_ask_wcs(&wcs);
double csys_or[ 3 ] = {0,0,0};
tag_t wcs_new;
tag_t mat_id;
double abs_point[3],wcs_point[3];
UF_CSYS_create_matrix(my_data->matrix,&mat_id);
UF_CSYS_create_temp_csys(csys_or,mat_id, &wcs_new);
UF_DISP_set_display(UF_DISP_SUPPRESS_DISPLAY);
UF_CSYS_set_wcs(wcs_new);
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS, my_data->arc->arc_center,UF_CSYS_WORK_COORDS ,abs_point);
UF_CSYS_set_wcs(wcs);
UF_CSYS_map_point (UF_CSYS_WORK_COORDS ,abs_point,UF_CSYS_ROOT_WCS_COORDS, wcs_point);
UF_DISP_set_display(UF_DISP_UNSUPPRESS_DISPLAY);
double corner_pt12[3]={wcs_point[0]-LLA/2,wcs_point[1]-LLB/2,wcs_point[2]}; //定位极点
double corner_pt22[3]={wcs_point[0]-LLA/2,wcs_point[1]+LLB/2,wcs_point[2]}; //定位极点
double corner_pt32[3]={wcs_point[0]+LLA/2,wcs_point[1]+LLB/2,wcs_point[2]}; //定位极点
double corner_pt42[3]={wcs_point[0]+LLA/2,wcs_point[1]-LLB/2,wcs_point[2]}; //定位极点
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS ,corner_pt12 ,UF_CSYS_WORK_COORDS,corner_pt12);
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS ,corner_pt22 ,UF_CSYS_WORK_COORDS,corner_pt22);
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS ,corner_pt32 ,UF_CSYS_WORK_COORDS,corner_pt32);
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS ,corner_pt42 ,UF_CSYS_WORK_COORDS,corner_pt42);
UF_DISP_display_temporary_line(motion_cb_data->view_tag,UF_DISP_USE_WORK_VIEW,corner_pt12, corner_pt22, &color);
UF_DISP_display_temporary_line(motion_cb_data->view_tag,UF_DISP_USE_WORK_VIEW,corner_pt22, corner_pt32, &color);
UF_DISP_display_temporary_line(motion_cb_data->view_tag,UF_DISP_USE_WORK_VIEW,corner_pt32, corner_pt42, &color);
UF_DISP_display_temporary_line(motion_cb_data->view_tag,UF_DISP_USE_WORK_VIEW,corner_pt42, corner_pt12, &color);
// double tet_coord [ 3 ]={wcs_point[0]+diameter/2,wcs_point[1]-diameter/2,wcs_point[2]};
double tet_coord [ 3 ]={wcs_point[0],wcs_point[1],wcs_point[2]};
double char_size=6;
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS ,tet_coord ,UF_CSYS_WORK_COORDS,tet_coord);
UF_DISP_display_temporary_text( motion_cb_data->view_tag,UF_DISP_USE_WORK_VIEW,tet , tet_coord ,UF_DISP_TOPLEFT,&color,char_size, 1);
UF_CSYS_map_point (UF_CSYS_WORK_COORDS ,tet_coord ,UF_CSYS_ROOT_WCS_COORDS, tet_coord);
x=wcs_point[0];
y=wcs_point[1];
//////设置XY的坐标的整数
// IF/x>=0,wznx=0.5;
// IF/x<0,wznx=-0.5;
// IF/y>=0,wzny=0.5;
// IF/y<0,wzny=-0.5;
//////设置XY的坐标的整数
//////设置XY的坐标的整数
if(x>=0)
{
wznx=0.5;
}
if(x<0)
{
wznx=-0.5;
}
if(y>=0)
{
wzny=0.5;
}
if(y<0)
{
wzny=-0.5;
}
xxxx1=x/wzjd2+wznx;
x=xxxx1*wzjd2;
yyyy1=y/wzjd2+wzny;
y=yyyy1*wzjd2;
char name[100]="";
sprintf(name,"X = %.2f",x);
tet_coord [1]= tet_coord [1]-char_size*2;
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS ,tet_coord ,UF_CSYS_WORK_COORDS,tet_coord);
UF_DISP_display_temporary_text( motion_cb_data->view_tag,UF_DISP_USE_WORK_VIEW,name , tet_coord ,UF_DISP_TOPLEFT,&color,char_size, 1);
UF_CSYS_map_point (UF_CSYS_WORK_COORDS ,tet_coord ,UF_CSYS_ROOT_WCS_COORDS, tet_coord);
sprintf(name,"Y = %.2f",y);
tet_coord [1]= tet_coord [1]-char_size*2;
UF_CSYS_map_point (UF_CSYS_ROOT_WCS_COORDS ,tet_coord ,UF_CSYS_WORK_COORDS,tet_coord);
UF_DISP_display_temporary_text( motion_cb_data->view_tag,UF_DISP_USE_WORK_VIEW,name , tet_coord ,UF_DISP_TOPLEFT,&color,char_size, 1);
}
static int do_ugopen_api(double *vec_dat)
{
int pos_resp=-1;
tag_t saved_wcs, mtx_id, csys_id,view_tag;
double plane_matrix[9], plane_origin[3], x_vec[3], y_vec[3], arc_edge_pos[3];
double root_origin[3] = {0.0, 0.0, 0.0};
double work_origin[3];
UF_CURVE_arc_t arc;
my_motion_data_t my_data;
my_data.arc = &arc;
arc.start_angle = 0.0;
arc.end_angle = TWOPI;
UF_CSYS_ask_wcs( &saved_wcs );
UF_CSYS_ask_csys_info(saved_wcs,&mtx_id,plane_origin);
UF_CSYS_ask_matrix_values(mtx_id,plane_matrix);
UF_VEC3_copy(plane_origin,my_data.abs_ctr);
uc6434("", 4, NULL_TAG, plane_matrix);//控制是否摆正视图
UF_MTX3_x_vec( plane_matrix, x_vec );
UF_MTX3_y_vec( plane_matrix, y_vec );
UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, x_vec,UF_CSYS_WORK_COORDS, x_vec );
UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, y_vec,UF_CSYS_WORK_COORDS, y_vec );
UF_CSYS_map_point( UF_CSYS_ROOT_COORDS, root_origin,UF_CSYS_WORK_COORDS, work_origin );
UF_VEC3_sub( x_vec, work_origin, my_data.x_axis );
UF_VEC3_sub( y_vec, work_origin, my_data.y_axis );
UF_MTX3_initialize( my_data.x_axis, my_data.y_axis,my_data.matrix );
UF_CSYS_create_matrix( my_data.matrix,&arc.matrix_tag );
UF_UI_specify_screen_position("",(UF_UI_motion_fn_t)motion_cb,(void *)&my_data,arc_edge_pos,&view_tag,&pos_resp );
return pos_resp;
}
/*ARGSUSED*/
void ufusr(char *param, int *retcode, int param_len)
{
if (!UF_initialize())
{
x=0;
y=0;
diameter=8.0;
ki=4;
char buffer[256];
char buffer1[256][256];
int i=0;
std::fstream out;
out.open("C:\\LINE.dat",ios::in);
while(!out.eof())
{
i++;
out.getline(buffer,256,'\n');//getline(char *,int,char) 表示该行字符达到256个或遇到换行就结束
// tet=(buffer,256,'\1');
// uc1601(buffer,1);
strcpy(buffer1[i], buffer);
// uc1601(buffer1[i],1);
// cout<<"第"<<i<<"行内容 "<<buffer<<endl;
}
////读出数据
LLA=atof(buffer1[1]);
LLB=atof(buffer1[2]);
ki=atoi(buffer1[3]);
////读出数据
//uc1601(strcpy(ki,cbuf),1);
// char cp2 [ ] [ 38 ]={"单个指定","四面镜相"};
// int response;
// response=uc1603("", 0, cp2, 2 );
// if (response==6)ki=1;
// else ki=0;
double Direction[3];
tag_t wcs_id,matrix_id;
double csys_origin[3],mat[9];
UF_CSYS_ask_wcs(&wcs_id);
UF_CSYS_ask_csys_info(wcs_id,&matrix_id,csys_origin);
UF_CSYS_ask_matrix_values(matrix_id,mat);
UF_VEC3_copy(&mat[6],Direction);
;
if ( do_ugopen_api(Direction)!=3)
{
ofstream SaveFile("C:\\ddd.dat");
SaveFile << x;
SaveFile << endl; //写入换行符
SaveFile << y;
SaveFile << endl; //写入换行符
SaveFile << ki;
SaveFile.close();
}
}
}
int ufusr_ask_unload(void)
{
UF_DISP_refresh();
return (UF_UNLOAD_IMMEDIATELY);
}