UG二次开发模板

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

UG二次开发模板
目录
第一章技巧规则 (2)
第二章函数模板 (4)
第三章功能模板 (11)
第四章 udop (24)
注:连接:Ctrl+单击鼠标左键
第一章技巧规则
1,内存原则:
【规则1】用malloc或new申请内存之后,应该立即检查指针值是否为NULL。

防止使用指针值为NULL的内存。

【规则2】不要忘记为数组和动态内存赋初值。

防止将未被初始化的内存作为右
值使用。

【规则3】避免数组或指针的下标越界,特别要当心发生“多1”或者“少1”
操作。

【规则4】动态内存的申请与释放必须配对,防止内存泄漏。

【规则5】用free或delete释放了内存之后,立即将指针设置为NULL,防止产
生“野指针”。

2,
数组要么在静态存储区被创建(如全局数组),要么在栈上被创建。

数组名对应着(而不是指向)一块内存,其地址与容量在生命期内保持不变,只有数组的内容可以改变。

指针可以随时指向任意类型的内存块,它的特征是“可变”,所以我们常用指针来操作动态内存。

指针远比数组灵活,但也更危险。

注意当数组作为函数的参数进行传递时,该数组自动退化为同类型的指针。

new/delete的功能完全覆盖了malloc/free,为什么C++不把malloc/free淘
汰出局呢?
这是因为C++程序经常要调用C函数,而C程序只能用malloc/free管理动态内存。

2,分配空间
double (*point)[3];
point = new double[count][3];
delete[]point;//正确的用法
/*delete point;//错误的用法=delete point[0]*/
3,
UF_MODL_update();//使用UF_MODL_edit时用来刷新
4 UF_UI_ONT_refresh ();//刷新导航器
头文件#include <uf_ui_ont.h>
UF_DISP_refresh();//去除临时文件
#include < uf_disp.h>
5 调试工具
1)uc1601 //显示消息对话框
头文件:#include <uf_ui.h>
用法1:
char inf[100];
sprintf(inf, "%f",);
uc1601(inf,1);
用法2:
uc1601("",1);
2)UF_UI_write_listing_window //显示文本框
头文件:#include <uf_ui.h>
char inf[100];
UF_UI_open_listing_window();
sprintf(inf, "%", );
UF_UI_write_listing_window(inf);
6,隐藏中间过程
#include < uf_disp.h>
UF_DISP_set_display(UF_DISP_SUPPRESS_DISPLAY);//打开隐藏UF_DISP_set_display(UF_DISP_UNSUPPRESS_DISPLAY); //关闭隐藏
第二章函数模板
1, uc1600 //获取字符串
头文件:#include <uf_ui.h>
int res = 0;
int len = 0;
char string[100]="";
res = uc1600( "",string , &len );//string:Input / Output
if ( res == 5 || ( res== 3 && len > 0 ) )
{
}
else
{
}
2, uc1603 //
头文件:#include <uf_ui.h>
用法1:
char title [100] = "菜单";
char items [3] [ 38 ] = { "选项1","选项2","选项3"};
choice = uc1603(title, 0, items, 3);
if (choice == 1 || choice == 2)
{
UF_terminate();
}
else
{
if (choice == )
{
}
}
用法2:
char items [3] [ 38 ] = { "选项1","选项2","选项3"};
response = uc1603( "菜单", 0, items, 3 );
switch ( response )
{
case 1:
case 2:
break;
case 4:
case 5:
}
3,选择对话框头文件
头文件1: init_proc_face
static int init_proc_face( UF_UI_selection_p_t select, void* user_data ) {
int nums = 1;
UF_UI_mask_t masks[] = {
UF_solid_type, 0, UF_UI_SEL_FEATURE_ANY_FACE};
if((UF_UI_set_sel_mask(select,
UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,
nums, masks)) == 0)
{
return (UF_UI_SEL_SUCCESS);
}
else
{
return (UF_UI_SEL_FAILURE);
}
}
头文件2: init_proc_body
static int init_proc_body(UF_UI_selection_p_t select, void* user_data) {
int num_triples = 1;
UF_UI_mask_t mask_triples[] = { UF_solid_type, 0, UF_UI_SEL_FEATURE_BODY}; /* enable only lines and edges */
if((UF_CALL(UF_UI_set_sel_mask(select,
UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,
num_triples, mask_triples))) == 0)
{
return (UF_UI_SEL_SUCCESS);
}
else
{
return (UF_UI_SEL_FAILURE);
}
}
4,UF_UI_select_with_single_dialog
头文件:#include <uf_ui.h>
char title[]="";
char cue[] = "";
int response=0;
double cursor [3];
tag_t face = NULL;
tag_t view = NULL;
if(!UF_CALL(UF_UI_select_with_single_dialog( cue, title, UF_UI_SEL_SCOPE_NO_CHANGE, init_proc_face, NULL,
&response,&face,cursor ,&view)))
{
if (response == UF_UI_OBJECT_SELECTED ||
response == UF_UI_OBJECT_SELECTED_BY_NAME)
{
printf("object tag = %d\n", face);
}
UF_DISP_set_highlight(face, 0);//关高亮
}
5,UF_UI_select_with_class_dialog
头文件:#include <uf_ui.h>
void class_sel_dlg(int *count,tag_p_t *objects)
{
char cue[] = "";
char title[] = "";
int response, sel_count, i;
tag_p_t sel_objects;
if((UF_CALL(UF_UI_select_with_class_dialog(
cue, title, UF_UI_SEL_SCOPE_NO_CHANGE,
init_proc_face, NULL, &response, &sel_count, &sel_objects))) == 0) {
printf("object count = %d\n",sel_count);
if (response == UF_UI_OK && sel_count > 0)
{
*objects=sel_objects;
*count=sel_count;
for (i=0; i<sel_count; i++)
{
printf("object tag = %d\n", sel_objects[i]);
UF_DISP_set_highlight(sel_objects[i], 0);
}
UF_free(objects);
}
}
}
6,UF_MODL_delete_object_parms//消参
头文件:
#include < uf_modl.h>
#include < uf_modl_utilities.h >
uf_list_p_t obj_list;
UF_CALL(UF_MODL_create_list(&obj_list));
UF_CALL(UF_MODL_put_list_item(obj_list, ));
UF_CALL(UF_MODL_put_list_item(obj_list, ));
UF_MODL_delete_object_parms(obj_list);
UF_MODL_delete_list(&obj_list);
UF_OBJ_delete_object();
7,UF_CURVE_create_arc//通过圆心,半径画圆
头文件:
#include < uf_csys.h>
#include < uf_curve.h>
tag_t arc, wcs_tag;
UF_CSYS_ask_wcs(&wcs_tag);
UF_CURVE_arc_t arc_coords;
UF_CSYS_ask_matrix_of_object(wcs_tag,&wcs_tag);
arc_coords.matrix_tag=wcs_tag;
arc_coords.start_angle = 0.0;
arc_coords.end_angle =360.0 * DEGRA;
arc_coords.arc_center[0] = center[0];//
arc_coords.arc_center[1] = center[1];//
arc_coords.arc_center[2] = center[2];//
arc_coords.radius = 500;
UF_CURVE_create_arc(&arc_coords,&arc_id);
8,UF_OBJ_set_name(tag,name); //设置名字
头文件#include <uf_obj.h>
9,name开关
int name_status ;
UF_DISP_ask_name_display_status(&name_status);
if (name_status==UF_DISP_NAME_DISPLAY_OFF )
{
name_status=UF_DISP_NAME_DISPLAY_ON;
}
else
{
name_status=UF_DISP_NAME_DISPLAY_OFF;
}
UF_DISP_set_name_display_status(name_status);
10,UF_OBJ_set_color(tag, color); //设置颜色
头文件#include <uf_obj.h>
11,UF_OBJ_set_layer (tag,layer); //设置层
头文件#include <uf_obj.h>
12,UF_CALL
头文件#include <uf.h>
int UF_CALL ( int errorCode )
{
if ( errorCode )
{
char message [133] = "";
UF_get_fail_message( errorCode, message );
uc1601 ( message, 1);
}
return (errorCode);
}
13, UF_PART_ask_display_part
头文件#include <uf_part.h>
tag_t part = UF_PART_ask_display_part ( );
if ( NULL == part )
{
uc1601( "", 1 );
return;
}
14,UF_OPER_create
头文件#include <uf_oper.h>
tag_t Oper_id = NULL;
UF_OPER_create ( "mill_contour", "ZLEVEL_PROFILE_YBC", &GZM_Oper_id ); 15,UF_MODL_ask_face_data//查询面的信息
头文件#include <uf_modl.h>
tag_t face;//面的ID
int type; //面的类型
double box[6];//x,y,z向最大,最小值
double radius;
double rad_data;
int norm_dir ;//法向
UF_MODL_ask_face_data(face,&type,center,
dir,box,&radius,&rad_data,&norm_dir);
16,UF_MODL_ask_minimum_dist_2//查询两物体间距离
double dis,accuracy;// accuracy:准确度
double point1[ 3 ]={0};
double point2[ 3 ]={0};
UF_CALL(UF_MODL_ask_minimum_dist_2 ( obj1, obj2, 0, NULL, 0, NULL,
& dis, point1, point1, &accuracy ));
第三章功能模板
1,制作对话框
1)进入User Interface Styler,设计好对话框,将Launch Dialog From改为Callback 保存
2)将生成的对话框文件放在模板文件夹下,以记事本格式打开XX. _template.C文件,将extern int<enter the name of your function> ( int*response )改为extern int XXX ( int *response )后保存。

3)打开VC的Templet,依次点击Tools->options->directories,将XX.h所在的文件夹包含进去。

4)在Templet.cpp中加入#include "XX_template.c"
#include "XX.h"
5)在程序内写入int response;
XXX (&response);点击F7,编译成功。

2,对话框求值,设值
UF_STYLER_item_value_type_t value;
value.item_attr=UF_STYLER_VALUE;
value.item_id=XXX; //在.h文件中定义的ID
UF_STYLER_ask_value(dialog_id,&value); //读值
/*赋值到变量中,变量在.h文件中定义,根据对话框定义不同类型:real,string,strings, integer , integers , real, reals*/
XXX =value.value.real;//赋值
value.item_id=XXX; //在.h文件中定义的ID
value.count=1;//拉伸条移动
UF_STYLER_set_value(dialog_id,&value);//设值
UF_STYLER_free_value(&value); //释放空间
3,
1),设置控件的激活状态
UF_STYLER_item_value_type_t value;
value.item_attr=UF_STYLER_SENSITIVITY; //指定设置控件的激活状态
value.item_id= XXX ; //在.h文件中定义的ID
value.value.integer=FALSE; //FALSE为不激活,TRUE为激活
UF_STYLER_set_value(dialog_id,&value);
2),设置对话框是否能选择物体
UF_UI_mask_t all_mask[] = {
UF_circle_type, 0, 0,
UF_cylinder_type, 0, 0,
UF_line_type, 0, 0
};
UF_STYLER_item_value_type_t value;
value.item_attr=UF_STYLER_SELECTION;
value.item_id=UF_STYLER_DIALOG_INDEX;
UF_STYLER_ask_value(dialog_id0,&value);
UF_UI_set_sel_type(value.value.selection,
UF_UI_SEL_TYPE_INACTIVE_SELECTION );//不能选择
// UF_UI_SEL_TYPE_SINGLE_SELECTION
//UF_UI_SEL_TYPE_SINGLE_DESELECTION
//UF_UI_SEL_TYPE_ROBUST_SELECTION 能选择
//UF_UI_SEL_TYPE_SINGLE_POSITION
//UF_UI_SEL_TYPE_RECTANGLE_POSITION
if ( ( UF_UI_set_sel_mask ( value.value.selection,
UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC, 2, all_mask ) ) ) {
return (UF_UI_CB_CONTINUE_DIALOG);
}
2,查询选择物体
UF_STYLER_item_value_type_t value;
value.item_attr=UF_STYLER_SELECTION;
value.item_id=UF_STYLER_DIALOG_INDEX;
UF_STYLER_ask_value(dialog_id0,&value);
UF_UI_ask_sel_object_list(value.value.selection,&count,&objects);
4,求三面交点
头文件
void change ( double AB [3][4], int line);
void row_change ( double AB [3][4], int row);
double xyz[3];///交点坐标
double AB [3][4] = { { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}};
double dot_product;
UF_VEC3_dot ( dir, center, &dot_product);
AB [0][0] = dir[0]; AB [0][1] = dir[1];
AB [0][2] = dir[2]; AB [0][3] = dot_product;
double dot_product1;
UF_VEC3_dot ( dir1, center1, &dot_product1);
AB [1][0] = dir1[0]; AB [1][1] = dir1[1];
AB [1][2] = dir1[2]; AB [1][3] = dot_product1;
double dot_product2;
UF_VEC3_dot ( dir2, floor_center, &dot_product2);
AB [2][0] = dir2[0]; AB [2][1] = dir2[1];
AB [2][2] = dir2[2]; AB [2][3] = dot_product2;
for ( int j = 0; j < 3; j++)
{
change ( AB, j);
row_change ( AB, j);
}
xyz [2] = AB [2][3];
xyz [1] = AB [1][3] - AB [1][2] * xyz [2];
xyz [0] = AB [0][3] - AB [0][2] * xyz [2] - AB [0][1] * xyz [1];
子函数:
void change ( double AB [3][4], int line)
{
double max = 0;
double buffer = 0;
int bj = -1;
double max_x = 0;
for ( int i = line; i < 3; i++)
{
max_x = fabs( AB [i][line]);
if ( max_x > max)
{
max = max_x;
bj = i;
}
}
for ( int j = 0; j < 4; j++)
{
buffer = AB [bj][j];
AB [bj][j] = AB [line][j];
AB [line][j] = buffer;
}
}
//初等行变换
void row_change ( double AB [3][4], int row)
{
for ( int j = row; j < 3 ; j++)
{
double divisor = AB [j][row];
if ( 0 != divisor)
{
for ( int i = row; i < 4; i++)
{
AB [j][i] = AB [j][i] / divisor;
}
}
}
for ( int k = ( row + 1); k < 3; k++)
{
if ( 0 != AB [k][row])
{
for ( int l = 0; l < 4; l++)
{
AB [k][l] = AB [k][l] - AB [row][l];
}
}
}
}
5,筛选边界
uf_loop_p_t loops_list=NULL; //回环ID
UF_MODL_ask_face_loops(face, &loops_list );//查询回环
int loops_count=0;//回环数量
UF_MODL_ask_loop_list_count(loops_list,&loops_count);//查询回环数量
for (int l_i=0; l_i<loops_count; l_i++)
{
int loops_type=0;//回环类型
uf_list_p_t edge_list=NULL;//边缘菜单指针ID
UF_MODL_ask_loop_list_item(loops_list,l_i,&loops_type,&edge_list);
if (1==loops_type)// 边界=1, 洞=2, 其他=3
{
int edge_count=0;//边缘数量
UF_MODL_ask_list_count ( edge_list, &edge_count );
tag_t edge_id=NULL;//边缘ID
for(int edge_i=0; edge_i<edge_count;edge_i++)
{
UF_MODL_ask_list_item( edge_list,edge_i,&edge_id);
UF_MODL_create_curve_from_edge(edge_id,&edge_id);
}
}
}
6,transform转移
#include <uf_trns.h>
1)平移uf5943
2)缩放uf5944
3)旋转uf5945
double matrix [ 16 ];
int status;
double angle=0;//旋转角度
uf5945(center,dir,&angle,matrix,&status);
//center物体中心,dir法向
const int objects=1;//数量
const int move=1; // 1 :复制 2 :粘贴
const int layer=-1; //0:最初层; -1: 工作层; 1 - 256 : 指定层
const int trace_curves=2; //轨迹状态, 1 开, 2 关
uf5947(matrix,&obj_tag,&n_objects,&move,
&layer,&trace_curves,NULL,NULL,&status);
4)投影uf5946
double matrix [ 16 ];
int status;
uf5946(object,matrix,&status);//object:投影面或线,dir法向
const int objects=1;//数量
const int move=1; // 1 :复制 2 :粘贴
const int layer=-1; //0:最初层; -1: 工作层; 1 - 256 : 指定层
const int trace_curves=2; //轨迹状态, 1 开, 2 关
uf5947(matrix,&obj_tag,&n_objects,&move,
&layer,&trace_curves,NULL,NULL,&status);
5)偏移相加 uf5942
7,裁剪片体
tag_t *trim_objects;
trim_objects =new tag_t[count];
trim_objects[i] =bound_id;
void trim_sheet()
{
UF_MODL_vector_t projection_method ;
projection_method.reverse_vector=0;
projection_method.vector_type=UF_MODL_VECTOR_DIRECTION;
UF_MODL_vector_defined_by_union_t dir1;
UF_MODL_vector_direction_t dir2;
dir2.xyz [0]=dir[0];
dir2.xyz [1]=dir[1];
dir2.xyz [2]=dir[2];
dir1.direction=dir2;
projection_method.defined_by=dir1;
double point_coords[3] ;
point_coords[0]=center[0];
point_coords[1]=center[1];
point_coords[2]=center[2];
int gap_point_count ;
double *gap_points;
tag_t feature_obj_eid;
UF_MODL_create_trimmed_sheet(sel_sheet,edge_count,trim_objects,&project ion_method,
0,1,point_coords,0.1,&gap_point_count,&gap_points,&feature_obj_eid);
}
8,offset偏移
char distance_str[] = {"10.0"};//偏移的距离
int num_curves;
tag_t * offset_curves;
UF_CURVE_offset_distance_data_t offset_distance;
offset_distance.distance = distance_str;
offset_distance.rough_type=1;
UF_STRING_t input_string;
input_string.id[i]=curve_id;//加入想要偏移的线
input_string.num =1; //偏移矢量方向数量
input_string.string=&string_count;//偏移线的数量
int string_dir=UF_MODL_CURVE_START_FROM_END;
input_string.dir=&string_dir;
UF_CURVE_offset_data_t offset_data;
offset_data.offset_def.distance_type1 = &offset_distance;
offset_data.input_curves = &input_string;
offset_data.approximation_tolerance = 0.01;
offset_data.string_tolerance=0.001;
offset_data.offset_def.distance_type1 = &offset_distance;
offset_data.offset_type = UF_CURVE_OFFSET_DISTANCE_TANGENT;
UF_CALL(UF_CURVE_create_offset_curve(&offset_data,
&num_curves,&offset_curves));
9,创建平面
UF_STRING_t generator;
UF_STRING_p_t ge = &generator;
UF_MODL_init_string_list(ge);
UF_MODL_create_string_list(1,12,ge);
ge->string[0] = 1;
ge->dir[0] = 1;//指定线从开始到结束
ge->id[0] = arc_id;//指定边界的id
double tol[3];
tol[0] = .001;//直线公差
tol[1] = .5 * (PI/180);//圆弧公差
tol[2] = .02;//不起作用
UF_CALL(UF_MODL_create_bplane(ge,tol,&bplane));
10,选择
1),点选择
tag_t point_tag;
double point[3];
UF_UI_POINT_base_method_t base_method=UF_UI_POINT_INFERRED ;
int point_res;
UF_CALL(UF_UI_point_construct("选择起点",&base_method,&point_tag,
point,&point_res));
if(point_res=UF_UI_OK&&NULL_TAG!=point_tag)
{
}
2),向量选择
int mode = UF_UI_INFERRED ;
int disp_flag = UF_UI_DISP_TEMP_VECTOR;
double vec[3];
double vec_pnt[3];
int res_vec = 0;
UF_initialize();
ifail = UF_UI_specify_vector( "Choose a Vector",&mode,disp_flag, vec,vec_pnt,&res_vec );
if ( ifail != 0 || res_vec!= UF_UI_OK )
{
UF_UI_ONT_refresh ();
printf( "No vector selected \n" );
}
else
{
printf( "Vect base (%f, %f, %f), direction (%f, %f, %f) \n", vec_pnt[0], vec_pnt[1], vec_pnt[2], vec[0], vec[1], vec[2] ); }
3),平面选择
tag_t plane_eid=NULL_TAG;
double orientation[9] = {0,0,0,0,0,0,0,0,0};
double origin[3] = {0,0,0};
double pts[6] = {0,0,0,0,0,0};
int i, error_code = 0;
int mode, display, response;
mode = 1;
display = 0;
UF_initialize();
error_code = UF_UI_specify_plane(
"Select Plane", &mode, display,
&response, orientation, origin, &plane_eid);
if ( !error_code && response != 1 && response != 2)
{
for (i=0; i<3; i++)
pts[i] = origin[i] + orientation[i];
for (i=3; i<6; i++)
pts[i] = origin[i-3] + orientation[i];
FTN(uf5374)(origin,pts,&pts[3],&plane_eid);
}
11,临时点,线
void display_temporary_point_line ( double point1[3], double point2[3]) {
UF_DISP_view_type_t which_views = UF_DISP_USE_WORK_VIEW;
UF_OBJ_disp_props_t color;
yer = 201;
color.color = 186;
color.blank_status = UF_OBJ_NOT_BLANKED;
color.line_width = UF_OBJ_WIDTH_NORMAL;
color.font =0;
color.highlight_status = FALSE;
UF_DISP_poly_marker_t marker_type = UF_DISP_POINT;
UF_DISP_display_temporary_point ( NULL, which_views, point1, &color, marker_type);
UF_DISP_display_temporary_point ( NULL, which_views, point2, &color, marker_type);
UF_DISP_display_temporary_line ( NULL, which_views, point1, point2, &color);
}
12,WCS与绝对坐标转换
void cycs_wcs(double point[])
{
tag_t wcs_id,matrix_id;
double matrix[ 9 ];
//wcs_origin:工作坐标系原点,vec:工作坐标系轴向量,point_origin:点到原点的矢量
double wcs_origin [3], vec[3][3],point_origin[3];
//1,得到工作坐标系
UF_CSYS_ask_wcs(&wcs_id);
UF_CSYS_ask_csys_info(wcs_id,&matrix_id,wcs_origin);
UF_CSYS_ask_matrix_values(matrix_id,matrix);
//2,得到工作坐标系轴向量
UF_MTX3_x_vec (matrix, vec[0]);
UF_MTX3_y_vec (matrix, vec[1]);
UF_MTX3_z_vec (matrix, vec[2]);
for(int i=0;i<3;i++)
{
double tol;
//3,得到点到工作坐标系原点矢量
UF_VEC3_unitize(vec[i],0.000001,&tol,vec[i]);
//4,得到点到工作坐标系原点矢量
point_origin[i]=point[i]-wcs_origin[i];
}
for(int j=0;j<3;j++)
{
UF_VEC3_dot(point_origin,vec[j],&point[j]);
}
}
13,三点求圆心
#include<iostream.h>
#include<math.h>
int main()
{
int x1,y1,x3,y3;
double a,b,c,d,e,f;
double r,k1,k2,x,y,x2,y2;
cout<<"请输入x1,y1,x2,y2,x3,y3"<<endl;
cin>>x1>>y1>>x2>>y2>>x3>>y3;
if((y1==y2)&&(y2==y3))
{
cout<<"三点不构成圆!"<<endl;
return 0;
}
if((y1!=y2)&&(y2!=y3))
{
k1=(x2-x1)/(y2-y1);
k2=(x3-x2)/(y3-y2);
}
if(k1==k2)
{
cout<<"三点不构成圆!"<<endl;
return 0;
}
a=2*(x2-x1);
b=2*(y2-y1);
c=x2*x2+y2*y2-x1*x1-y1*y1;
d=2*(x3-x2);
e=2*(y3-y2);
f=x3*x3+y3*y3-x2*x2-y2*y2;
x=(b*f-e*c)/(b*d-e*a);
y=(d*c-a*f)/(b*d-e*a);
cout<<"圆心为("<<x<<","<<y<<")"<<endl;
r=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
cout<<"半径为"<<r<<endl;
return 0;
}
14,查找圆心
UF_EVAL_p_t evaluator ;
UF_EVAL_arc_t arc ;
UF_EVAL_initialize(obj_tag,&evaluator);
UF_EVAL_ask_arc(evaluator,&arc);
UF_VEC3_copy(arc.center,point);
15, message_box
void message_box(int *res_mes)
{
UF_UI_message_buttons_s buttons;
buttons.button1=TRUE;
buttons.button2=FALSE;
buttons.button3=TRUE;
bel1="OK";
bel3="CANEL";
buttons.response1=UF_UI_OK;
buttons.response3=UF_UI_CANCEL;
char *string_msg;
char *material_msg="ALL selcted objects will be removed";
string_msg = material_msg;
UF_CALL(UF_UI_message_dialog( "",
UF_UI_MESSAGE_WARNING,
&material_msg,
1,
TRUE,
&buttons,
res_mes ));
}
16,选择过滤
static int init_add_face( UF_UI_selection_p_t select, void * client_data) {
int nums = 1;
UF_UI_mask_t masks[] = {
UF_solid_type, 0, UF_UI_SEL_FEATURE_ANY_FACE};
if(
(UF_UI_set_sel_mask(select,UF_UI_SEL_MASK_CLEAR_AND_ENABLE_SPECIFIC,num s, masks)==0)
&&(UF_UI_set_sel_procs(select,filter_proc_circle,NULL,client_data)==0) )
{
return (UF_UI_SEL_SUCCESS);
}
else
{
return (UF_UI_SEL_FAILURE);
}
}
int find_tag(
void * client_data,//用以传输过滤资料
tag_t object//现在鼠标所选物体ID
)
{
user_data *obj;
obj=(user_data*)client_data;
int find_face=true;//接受
char *string1;
string1=new char[133];
string1=UF_TAG_ask_handle_of_tag(object);
for(int i=0;i<过滤的数目;i++)
{
char *string2;
string2=new char[133];
string2=UF_TAG_ask_handle_of_tag(物体ID);
if(strcmp(string1,string2)==0)
{
find_face=FALSE;//不接受
}
delete []string2;
}
delete []string1;
return find_face;
}
第四章 udop
1,用UG打开resource\template_part\metric下的模板,复制一个用户自定义的加工方式,定义好CAM API Exit Name:UGII_BASE_XX,再点击options,customize dialog。

将Environment variable name隐藏,设置好自己的对话框风格后保存退出。

2,打开ugii_env.txt在最后加上:
UGII_BASE_XX =路径 D:\projects\test\Release\Templet.dll保存退出。

3,打开模板程序,将接口函数改为udop
头文件
#include <uf_defs.h>
#include <uf_cam.h>
#include <uf_udop.h>
#include <uf_oper.h>
#include <uf_path.h>
#include <uf.h>
#include <uf_exit.h>
#include <stdio.h>
#include <uf_ncgroup.h>
#include < uf_setup.h >
char op_name[UF_OPER_OPNAME_LEN];
UF_UDOP_id_t udop_id;
UF_UDOP_purpose_t purpose;
UF_OPER_id_t oper_id;
UF_PATH_id_t path_id;
/***** Convert UG/Open API param to CAM exit id ******/
UF_CAM_exit_id_t exit_id =(UF_CAM_exit_id_t)parm ;
/***** Using the exit_id to get the udop identifier ******/
UF_initialize();
UF_UDOP_ask_udop( exit_id, &udop_id);
/***** Using the udop_id to get the oper identifier ******/
UF_UDOP_ask_oper( udop_id, &oper_id);
/***** Using the udop_id to get the pupose of the call ******/
UF_UDOP_ask_purpose( udop_id, &purpose);
/***** Using the oper_id to get the name of the oper ******/
UF_OPER_ask_name( oper_id, op_name);
/***** Using the oper_id to get the path identifier ******/
UF_OPER_ask_path( oper_id, &path_id);
/*得到程序ID*/
tag_t setupTag;
tag_t root;
tag_t oper_tag;
UF_CALL(UF_SETUP_ask_setup( &setupTag ));
UF_CALL(UF_SETUP_ask_program_root( setupTag, &root ));
UF_CALL(UF_NCGROUP_ask_object_of_name( root, op_name,&oper_tag ));
if( purpose == UF_UDOP_USER_PARAMS )
{
int response;
XXXX (&response,oper_tag); // XXXX:对话框名
}
else if( purpose == UF_UDOP_GENERATE )
{
{
UF_PATH_linear_motion_t motion,*motion_ptr = &motion;
motion_ptr->feed_value = 0.0;
motion_ptr->feed_unit = UF_PATH_FEED_UNIT_NONE;//没有
motion_ptr->type = UF_PATH_MOTION_TYPE_RAPID;//切削
motion_ptr->feed_value=1000; //转速
motion_ptr->feed_unit=UF_PATH_FEED_UNIT_NONE ;
motion_ptr->tool_axis[0] =0.0;
motion_ptr->tool_axis[1] =0.0;
motion_ptr->tool_axis[2] =1.0;//指定刀具轴心法向
motion_ptr->position[0] =0.0;
motion_ptr->position[1] =0.5;
motion_ptr->position[2] =50; //指定刀具到达的点
UF_PATH_create_linear_motion( path_id, motion_ptr);
}
}
4,制作好对话框
1,在extern int XXXX ( int *response)添加程序id:,tag_t oper_tag
2,定义结构用以各回调函数间传递信息
1) XXXX.h添加结构
struct user_data
{
tag_t oper_tag;
};
2) XXXX.template.c
user_data obj;
obj.oper_tag=oper_tag;
if ( ( error_code = UF_STYLER_create_dialog ( "beixi.dlg",
CHANGE_cbs, /* Callbacks from dialog */
CHANGE_CB_COUNT, /* number of callbacks*/
&obj, /* This is your client data */
response ) ) != 0 )
3) 各个回调函数中得到传递的资料
user_data *obj;
obj=(user_data*)client_data;
XXX=obj.oper_tag;
3,初始化对话框
UF_STYLER_item_value_type_t value;
value.item_attr=UF_STYLER_VALUE;
UF_ATTR_value_t ATTR_value;
int ATTR_type;
ATTR_value.value.string=new char[133];//分配内存
///////////////////////////////
ATTR_type=0;
value.item_id= XXX; //需要添加数据的ID
UF_ATTR_find_attribute(oper_tag,UF_ATTR_string ,"属性名",&ATTR_type);
if(0==ATTR_type)
{
value.value.integer=2;
UF_STYLER_set_value(dialog_id,&value);
}
if(UF_ATTR_string==ATTR_type)
{
UF_ATTR_read_value(oper_tag,"属性名",UF_ATTR_string,&ATTR_value);
value.value.integer=atoi(ATTR_value.value.string);//atof
UF_STYLER_set_value(dialog_id,&value);
}
/////////////////////////////////////
delete []ATTR_value.value.string;
UF_STYLER_free_value(&value); //释放空间
4,CHANGE_ok_cb
//////////////////1,得到oper_tag
user_data *obj;
obj=(user_data*)client_data;
tag_t oper_tag;
oper_tag=obj->oper_tag;
UF_STYLER_item_value_type_t value;
value.item_attr=UF_STYLER_VALUE;
UF_ATTR_value_t ATTR_value;
ATTR_value.type = UF_ATTR_string;
ATTR_value.value.string=new char[UF_ATTR_MAX_TITLE_LEN+1];//分配内存//////////////////2,删除属性
UF_ATTR_delete_all(oper_tag,UF_ATTR_any);
/////////////////////////////3,添加输入框中的各种数值
value.item_id=XXX;
UF_STYLER_ask_value(dialog_id,&value);
sprintf(ATTR_value.value.string,"%d", value.value.integer);
UF_CALL(UF_ATTR_assign(oper_tag, "属性名",ATTR_value));
//sprintf(ATTR_value.value.string,"%f", value.value. real);
// UF_CALL(UF_ATTR_assign(oper_tag, "属性名",ATTR_value));
/////////////////////////////4,添加所选加工tag
if(0==count)
{
uc1601("未选择加工面",1);
}
if(0<count)
{
sprintf(ATTR_value.value.string,"%d", count);
UF_CALL(UF_ATTR_assign(oper_tag, "geometry_count",ATTR_value));
for (int i=0; i<count; i++)
{
char inf[133]="";
sprintf(inf,"geometry_id%d",i);
ATTR_value.value.string =
UF_TAG_ask_handle_of_tag(obj->obj[i]);
UF_CALL(UF_ATTR_assign(oper_tag,inf,ATTR_value));
}
}
////////////////////
delete []ATTR_value.value.string;
UF_STYLER_free_value(&value);
5,生成刀轨
1)查找属性
//////////////////////////////////////// 1查找int
int find_int_attribute(int *value,
char title[],
tag_t oper_tag
)
{
UF_ATTR_value_t ATTR_value;
int ATTR_type=0;
UF_CALL(UF_ATTR_find_attribute(oper_tag,UF_ATTR_string,title,&ATTR_type));
if(0==ATTR_type)
{
return ATTR_type;
UF_terminate ();
}
if(UF_ATTR_string==ATTR_type)
{
ATTR_value.value.string=new char[133];
UF_ATTR_read_value(oper_tag,title,UF_ATTR_string,&ATTR_value);
*value=atoi(ATTR_value.value.string);
delete []ATTR_value.value.string;
}
return ATTR_type;
}
////////////////////////////////// 2查找double
int find_double_attribute(double *value,
char title[],
tag_t oper_tag
)
{
UF_ATTR_value_t ATTR_value;
int ATTR_type=0;
UF_CALL(UF_ATTR_find_attribute(oper_tag,UF_ATTR_string,title,&ATTR_type)); if(0==ATTR_type)
{
return ATTR_type;
UF_terminate ();
}
if(UF_ATTR_string==ATTR_type)
{
ATTR_value.value.string=new char[133];
UF_ATTR_read_value(oper_tag,title,UF_ATTR_string,&ATTR_value);
*value=atoi(ATTR_value.value.string);
delete []ATTR_value.value.string;
}
return ATTR_type;
}
//////////////////////////////////3查找tag
int find_tag_attribute(
char title[],
tag_t *geometry_tag,
tag_t oper_tag
)
{
UF_ATTR_value_t ATTR_value;
int ATTR_type=0;
UF_CALL(UF_ATTR_find_attribute(oper_tag,UF_ATTR_string,title,&ATTR_type)); if(0==ATTR_type)
{
return ATTR_type;
UF_terminate ();
}
if(UF_ATTR_string==ATTR_type)
{
tag_t tag;
ATTR_value.value.string=new char[133];
UF_ATTR_read_value(oper_tag,title,UF_ATTR_string,&ATTR_value);
tag=UF_TAG_ask_tag_of_handle(ATTR_value.value.string);
*geometry_tag=tag;
delete []ATTR_value.value.string;
}
return ATTR_type;
}
2)///////////////////////////////主函数
int cut_num;
char title[133]="属性名";
int ATTR_type=0;
ATTR_type=find_int_attribute(&cut_num,title,oper_tag);//查找int形
if(0==ATTR_type)
{
uc1601("参数错误。

",1);
UF_terminate();
return;
}
ATTR_type=0;
double per_cut=0;
strcpy(title,"属性名");
ATTR_type=find_double_attribute(&per_cut,title,oper_tag); //查找double形
if(0==ATTR_type)
{
uc1601("参数错误。

",1);
UF_terminate();
return;
}
1,查找刀具属性
tag_t tool_id=NULL;
double tool_diam=0;
UF_OPER_ask_cutter_group(oper_tag,&tool_id);
UF_PARAM_ask_double_value(tool_id,UF_PARAM_TL_DIAMETER,&tool_diam);//查找直径
char tool_text[133];
char ch_s[10]="", ch_f[10]="",*ch_p=NULL;
double tool_s=0 ,tool_f=0;//主轴转速,进给
if(UF_CALL(UF_PARAM_ask_str_value(tool_id,1158,tool_text))==0)//属性文本{
ch_p=strstr(tool_text,"S=");
if (ch_p!=NULL)
{
int i=0;
ch_p=ch_p+2;
while((48<=*ch_p&&*ch_p<=57)||46==*ch_p)//当指针指向为数字或者小数点
{
ch_s[i]=*ch_p;
i++;
ch_p++;
}
ch_s[i]='\0';
if(i!=0)
{。

相关文档
最新文档