nxopen文档cam案例的中文

UF_initialize();
	//检查是否新建部件文件,如果没有就新建一个
	tag_t partTag;
	partTag =  UF_PART_ask_display_part();
         if ( partTag  != null_tag )
         {
         uc1601("已打开部件文件\n",0);
          }
		 else
		 {
			 uc1601("正在创建部件文件 \n",0);
			 UF_PART_new( "samplepart", 2, &partTag );//第一个参数是新建部件名称,1是米制单位2是英制单位
			 uc1601("创建成功 \n",0);
		 }

	//初始化cam
	int error_code = 0;
	error_code=UF_CAM_init_session();
	if( error_code != 0 )
    {
         uc1601( "Failed to initialize the CAM session...", 0);
         return;
    }
	else
	{
		uc1601("成功初始化cam",0);
	}

	//查找cam的setup
	int type_count;
	char const**type_names;
	UF_CAM_opt_ask_types( &type_count, &type_names );//此函数提供可用的对象参数模板类型的名称和个数,就是mill_contour,mill_planar,mill_multi_axis等自己能建的。 
	tag_t setupTag;
	UF_SETUP_ask_setup( &setupTag );//每一个cam的菜单(setup)都有四个视图,程序,几何,机床,加工方法,下面就是依次添加这四个视图的过程

	/*********************************************************创建操作******************************************************************/
	int subtype_count = 0;
	char const **subtype_names = 0; 
	UF_CAM_opt_ask_subtypes( type_names[1], UF_CAM_OPT_STYPE_CLS_OPER, &subtype_count, &subtype_names );
	/*这个函数的第二个参数是一个类,输入其中的一个成员,即为想得到type_names[1]中的子类型(就是创建工序里的工序子类型),
	想得到的子类型类是UF_CAM_OPT_STYPE_CLS_OPER(其实还有6个,后面用),得到的子类型数?返回的子类型名称?*/

	tag_t *operTag = 0;
	operTag = (tag_t *)UF_allocate_memory( sizeof( operTag ) * subtype_count, &error_code );//分块存储并返回subtype_count的指针?
	int uchoice = 0;
	int choice = 0;
	char uOper[] [38] = {"型腔铣","轮廓铣","流线铣"};
	if ( uchoice == 0 )
		{
			/*uc1603的第一个参数是菜单标题,第二个参数=0则没有默认选项,第二个参数就是用来设定默认选项的;
			第三个参数是个字符串数组,输入按钮的文字;第四个参数是按钮的数目,最多14个按钮。
			此函数的返回值choice是:1为返回,2为取消*/
			choice = uc1603("选择型腔铣作为第一操作! - Back or Cancel to quit.", 0, uOper, 3);
		}
	else
	{
			choice = uc1603("选择轮廓铣操作! - Back or Cancel to quit.", 0, uOper, 3);
	}
	if ( choice == 1 || choice == 2 )//如果点了返回=1或者取消=2
	{
			UF_terminate();
			UF_free( operTag );
			return;
	}
	else//如果选了三个选项之一,choice=5,6,7
	{
			choice = choice - 5;//-5是因为uc1603返回的按钮值从5-18,选第一个返回5,选第二个返回6...
			uchoice = 1;
	}
	int ii = 0;
	int numop = 0;
	for( ii = 0; ii <subtype_count; ii++ )
	{
		if( strcmp( subtype_names[ii],uOper[choice] ) == 0 )//遍历子类型与用户选择铣削类型,比较两个值,如果相等则执行循环
		{
			printf("您选的是%d个选项\n", choice);
            UF_OPER_create( (char *) type_names[1], (char *)subtype_names[ii], &operTag[numop] );//此函数创建一个操作,操作类型是type_name为模板,此操作叫做subtype_names,tag是第三个参数
            printf("创建的操作是%s \n", subtype_names[ii] );
            printf("操作的tag是 %d \n", operTag[numop] );
            numop++;//numop是用来找subtype_names中的对应用户选择的操作的
		}
	}
	printf("执行第%d个操作\n", numop);
	/***************************************************************NC Program***************************************************************/

	int prog_sub_cnt = 0;
	char const **prog_sub_names;
	UF_CAM_opt_ask_subtypes( type_names[1], UF_CAM_OPT_STYPE_CLS_PROG, &prog_sub_cnt,&prog_sub_names );//同前
	if( prog_sub_cnt > 0 )
	{
		tag_t prog_null;
		if ( numop == 1 )//如果有程序模板,那么就创建一个程序组
		{
			char *uPrognam = {"UserGroup"};
			tag_t progTag = NULL_TAG;
			tag_t progRootTag;
			char reason[UF_NCGROUP_MAX_REASON_BUFSIZE];
			logical answer;
			UF_NCPROG_create( (char *)type_names[1], (char *)prog_sub_names[0], &progTag );//创建一个nc程序,第一个是程序模板,第二个是子程序名称
			UF_OBJ_set_name( progTag, uPrognam );//给程序一个名字,这个名字是显示的
			UF_SETUP_ask_program_root( setupTag, &progRootTag );//返回程序视图的根目录progRootTag,因为自己加的程序是加到这个目录里面的,setupTag是类似于这个cam环境的标识
			UF_NCGROUP_can_accept_member( progRootTag, progTag, &answer, reason );//如果自己写的程序可以加到程序根目录里面,这个函数返回answer==ture,如果不能加,就会返回false并且给出原因
			if( answer == TRUE )//能加进去
				UF_NCGROUP_accept_member( progRootTag, progTag );
			else //不能加进去的话说明用户没有创建程序组,就将这个程序加到空组里
			{			
				UF_SETUP_ask_program_null( setupTag, &prog_null );//四个视图中,每个视图都有一个空组,
				UF_NCGROUP_accept_member( prog_null, operTag[numop-1] );
			}
		}
		else if ( numop > 0 )//如果没有程序模板
		{
		 
			UF_SETUP_ask_program_null( setupTag, &prog_null );
			UF_NCGROUP_accept_member( prog_null, operTag[numop-1] );//将operTag[numop-1]加入到空组列表中
		}
	}
    /*************************************************** Method Groups *********************************************/
	int mthd_sub_cnt=0;
	const char**mthd_sub_names;
	tag_t mthdRootTag,mthdTag;
	int kk = 0;
	char *uMethod[3] = {"Roughing","Semi-Finish","Flowcut"};
	logical answer;
	char reason[UF_NCGROUP_MAX_REASON_BUFSIZE];
	tag_t mthd_null; 

	UF_CAM_opt_ask_subtypes( type_names[1], UF_CAM_OPT_STYPE_CLS_METHOD, &mthd_sub_cnt, &mthd_sub_names );//一样的套路

	if( mthd_sub_cnt > 0 )
	{
		UF_NCMTHD_create( (char *)type_names[1], (char *)mthd_sub_names[0], &mthdTag );
		UF_OBJ_set_name( mthdTag, uMethod[kk] );
		UF_SETUP_ask_mthd_root( setupTag, &mthdRootTag );
		UF_NCGROUP_can_accept_member( mthdRootTag, mthdTag, &answer, reason );
		if( answer == TRUE )
		{
			UF_NCGROUP_accept_member( mthdRootTag, mthdTag );
		}
		UF_NCGROUP_can_accept_member( mthdTag, operTag[numop-1], &answer, reason );
		if( answer == TRUE )
			UF_NCGROUP_accept_member( mthdTag, operTag[numop-1] );
		else
		{
			UF_SETUP_ask_mthd_null( setupTag, &mthd_null );
			UF_NCGROUP_accept_member( mthd_null, operTag[numop-1] );
		}
		kk++;


	}
/************************************************Geometry Groups  *********************************************************************/
	UF_CAM_opt_ask_subtypes( type_names[1], UF_CAM_OPT_STYPE_CLS_GEOM, &geom_sub_cnt,&geom_sub_names );
	if( geom_sub_cnt > 0 )
	{
		printf("Currently numop is set to %d\n", numop );
		if ( choice < 2 )
		{
			UF_NCGEOM_create( (char *)type_names[1], (char *)geom_sub_names[ll], &geomTag );
            UF_SETUP_ask_geom_root( setupTag, &geomRootTag );
            UF_NCGROUP_ask_object_of_name( geomRootTag, "WORKPIECE", &wrkp_tag );
			if ( wrkp_tag != null_tag )
			{
				UF_NCGROUP_can_accept_member( wrkp_tag, geomTag, &answer, reason );
				if( answer == TRUE )
					UF_NCGROUP_accept_member( wrkp_tag, geomTag );
				if (strcmp( geom_sub_names[ll],"MILL_GEOM") == 0 ) 
                         {
							 printf("Call ufd_camgeom_ugroup to identify workpiece...\n");
							 printf("Object count passed to workpiece %d\n", obj_count );
							 error_code = ufd_camgeom_ugroup( wrkp_tag, obj_count );
						}
				else if(strcmp( geom_sub_names[ll],"MILL_AREA" ) == 0 )
				{
					printf("Call ufd_camgeom_ugroup to identify cut area...\n");
					printf("Object count passed to cut area %d\n", obj_count );
					error_code = ufd_camgeom_ugroup( geomTag, obj_count );
                             if ( error_code != 0 )
								 {
									 printf(" Returns in error...\n");
								 }
				}
			 }
			else if (strcmp( geom_sub_names[ll],"MILL_AREA" ) == 0 )
			{
				printf("Call ufd_camgeom_ugroup to identify cut area...\n");
                            printf("Object count passed to cut area %d\n", obj_count );
                    error_code = ufd_camgeom_ugroup( geomTag, obj_count );
                             if ( error_code != 0 )
                              {
                               printf(" Returns in error...\n");
                              }
			}
		}
	}
	/**************************************************** Machine Tool  Groups ********************************************************/
	UF_CAM_opt_ask_subtypes( type_names[1], UF_CAM_OPT_STYPE_CLS_TOOL, &tool_sub_cnt, &tool_sub_names );
	 char *uTool[3] = {"Tool_1","Tool_2","Tool_3"};
	if( tool_sub_cnt > 0 )
	{
		 UF_CUTTER_create( (char *)type_names[1], (char *)tool_sub_names[0], &toolTag );
		 UF_OBJ_set_name( toolTag, uTool[jj] );
		 UF_SETUP_ask_mct_root( setupTag, &toolRootTag );
		 UF_NCGROUP_can_accept_member( toolRootTag, toolTag, &answer, reason );
		 if( answer == TRUE )
         UF_NCGROUP_accept_member( toolRootTag, toolTag );
		 UF_NCGROUP_can_accept_member( toolTag, operTag[numop-1], &answer, reason );
         if( answer == TRUE ) 
         {
			UF_NCGROUP_accept_member( toolTag, operTag[numop-1] );
         }
         else
         {
            UF_SETUP_ask_mct_null( setupTag, &tool_null );
            UF_NCGROUP_accept_member( tool_null, operTag[numop-1] );
         }
		 jj++;
		 set_tool_param( jj, toolTag );//设置刀具参数
		 /*刀具设置参数函数*/
		 static int set_tool_param( int jj, tag_t toolTag )
{
    double toolDia = 0, toolRad = 3;//diameter是直径,radius是半径?

/*                 Modify the default 5-Parameter Milling Tool         */

        switch( jj )
        {
/*                               Tool No. 1                            */
/*                             Add a 3.0 MM crad                       */
        case 1:
            {
            UF_PARAM_set_double_value( toolTag, UF_PARAM_TL_COR1_RAD, toolRad );
            break;
            }
/*                               Tool No. 2                            */
/*                             Make this a Ball Nose  球头铣刀                 */
        case 2:
            {
				//这两句话就是给UF_PARAM_TL_DIAMETER和UF_PARAM_TL_COR1_RAD赋值toolDia和toolDia/2
				/*UF_PARAM_TL_DIAMETER:直径,也可写为1000;
				UF_PARAM_TL_HEIGHT:长度(1001);
				UF_PARAM_TL_COR1_RAD:*/
            UF_PARAM_ask_double_value( toolTag, UF_PARAM_TL_DIAMETER, &toolDia );//UF_PARAM_TL_DIAMETER默认值是1000
            UF_PARAM_set_double_value( toolTag, UF_PARAM_TL_COR1_RAD, toolDia/2 );//UF_PARAM_TL_COR1_RAD是1005
            break;
            }
/*                               Tool No. 3                            */
/*                           Define a smaller Ball Nose                */
        case 3:
            {
            UF_PARAM_set_double_value( toolTag, UF_PARAM_TL_DIAMETER, 25.0 );
            UF_PARAM_set_double_value( toolTag, UF_PARAM_TL_COR1_RAD, (25.0/2) );
            break;
            }
        default:
            {
            printf( "Default...\n" );
            }
        }
        return 0;
}
	}



	UF_terminate();

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值