UG二次开发之遍历相关的函数

#include "Lin_uf_cycle_obj.h"

#ifdef __cplusplus
extern "C" {
#endif



/*
UF_OBJ_set_partially_shaded
*函数说明:对一个层的所有显示体进行遍历
*函数用法:传入层号和一个链表:如体名为FALSE将过滤

		int layle=1;
		uf_list_p_t body_list;
		UF_MODL_create_list(&body_list);    

		USER_cycle_layer_sold_to_list(layle,body_list);

		int count;
		UF_MODL_ask_list_count(body_list, &count);     //查询链表
		char msg[256];
		sprintf(msg,"%d",count);
		uc1601(msg,1);
		UF_MODL_delete_list(&body_list); 
*/
extern  void USER_cycle_layer_sold_to_list(int layle,uf_list_p_t body_list,char *obj_name)
{
	
	int  type;
	int  subtype;
	tag_t body=NULL_TAG;
	char body_name[133];
	do 
	{
		UF_LAYER_cycle_by_layer(layle,&body);
		if(body !=NULL_TAG)
		{
			UF_OBJ_disp_props_t		disp_props;//定义一个结构体
			UF_OBJ_ask_display_properties (body, &disp_props);//查询体的显示属性
			if(disp_props.blank_status==UF_OBJ_NOT_BLANKED)
			{
				UF_OBJ_ask_type_and_subtype(body,&type,&subtype);
				if(70 == type && subtype==0)      //&& 逻辑与先查询出面和体 
				{
					UF_MODL_ask_body_type(body, &type);
					if(type==UF_MODL_SOLID_BODY)//如果为实体
					{
						UF_OBJ_ask_name(body,body_name);
						if(strcmp(body_name,obj_name)==0)
						{
							UF_MODL_put_list_item(body_list,body);  //写入链表
						}
					}
				}
			}
		}
	} while (body !=NULL_TAG);
}












static int allocate_memory(unsigned int nbytes, void **where)
{
	int
		resp;

	*where = UF_allocate_memory(nbytes, &resp);

	return resp;
}


static int make_an_array(uf_list_p_t *object_list, tag_t **objects)
{
	int
		ii,
		n;
	uf_list_p_t
		temp;

	UF_CALL(UF_MODL_ask_list_count(*object_list, &n));

	UF_CALL(allocate_memory(n * sizeof(tag_t), (void **)objects));
	for (ii = 0, temp = *object_list; ii < n; temp = temp->next, ii++)
		(*objects)[ii] = temp->eid;

	UF_CALL(UF_MODL_delete_list(object_list));

	return n;
}





//把向量转换成数组
extern   int make_vector_an_array(vector <tag_t> object_vector, tag_t **objects)
{
	int
		ii,
		n;
	n=object_vector.size();

	UF_CALL(allocate_memory(n * sizeof(tag_t), (void **)objects));

	for (ii = 0;ii < n;ii++)
	{
		(*objects)[ii] = object_vector[ii];

	}

	return n;
}









//遍历层,生成一个数组返回数组大小,
//最后一个为分隔符
/*
tag_t *objs;
int   n_objs=0;
n_objs=ask_all_objects_on_layer(201, &objs,'P');


*/
extern  int ask_all_objects_on_layer(int layer, tag_t **objects,char buff)
{

	int  type;
	int  subtype;
	tag_t body=NULL_TAG;
	char body_name[133];

	uf_list_p_t list;
	UF_CALL(UF_MODL_create_list(&list));
	do 
	{
		UF_CALL(UF_LAYER_cycle_by_layer(layer,&body));
		if(body !=NULL_TAG)
		{
			UF_OBJ_disp_props_t		disp_props;//定义一个结构体
			UF_CALL(UF_OBJ_ask_display_properties (body, &disp_props));//查询体的显示属性
			if(disp_props.blank_status==UF_OBJ_NOT_BLANKED)
			{
				UF_CALL(UF_OBJ_ask_type_and_subtype(body,&type,&subtype));
				if(70 == type && subtype==0)      //&& 逻辑与先查询出面和体 
				{
					UF_CALL(UF_MODL_ask_body_type(body, &type));
					if(type==UF_MODL_SOLID_BODY)//如果为实体
					{
						UF_CALL(UF_OBJ_ask_name(body,body_name));
						if(strchr(body_name,buff)!=NULL)
						{
							UF_CALL(UF_MODL_put_list_item(list,body));  //写入链表
						}
					}
				}
			}
		}
	} while (body !=NULL_TAG);


	return make_an_array(&list, objects);
}


extern  int ask_all_point_on_layer(int layer, tag_t **objects,char buff)
{

	int  type;
	int  subtype;
	tag_t pt_tag=NULL_TAG;
	char name[133];

	uf_list_p_t list;
	UF_CALL(UF_MODL_create_list(&list));
	do 
	{
		UF_CALL(UF_LAYER_cycle_by_layer(layer,&pt_tag));
		if(pt_tag !=NULL_TAG)
		{
			UF_OBJ_disp_props_t		disp_props;//定义一个结构体
			UF_CALL(UF_OBJ_ask_display_properties (pt_tag, &disp_props));//查询体的显示属性
			if(disp_props.blank_status==UF_OBJ_NOT_BLANKED)
			{
				UF_CALL(UF_OBJ_ask_type_and_subtype(pt_tag,&type,&subtype));
				if(UF_point_type ==type)   //UF_point_type   
				{				
					UF_CALL(UF_OBJ_ask_name(pt_tag,name));
					if(strchr(name,buff)!=NULL)
					{
						UF_CALL(UF_MODL_put_list_item(list,pt_tag));  //写入链表
					}
				}
			}
		}
	} while (pt_tag !=NULL_TAG);


	return make_an_array(&list, objects);
}

extern int cycle_layer_line_to_objes(int layer, tag_t **objects)
{


	uf_list_p_t list;
	UF_CALL(UF_MODL_create_list(&list));

	int  type;
	int  subtype;
	tag_t body=NULL_TAG;
	do 
	{
		UF_LAYER_cycle_by_layer(layer,&body);
		if(body !=NULL_TAG)
		{
			UF_OBJ_disp_props_t		disp_props;//定义一个结构体
			UF_OBJ_ask_display_properties (body, &disp_props);//查询体的显示属性
			if(disp_props.blank_status==UF_OBJ_NOT_BLANKED)
			{
				UF_OBJ_ask_type_and_subtype(body,&type,&subtype);
				if (type==UF_line_type)
				{
					UF_CALL(UF_MODL_put_list_item(list,body));  //写入链表	
				}
				else
				{
					char msg[133];
					sprintf(msg,"第%d层不能含有其它对象",layer);
					uc1601(msg,1);
					return 0;
				}
			}
		}
	} while (body !=NULL_TAG);



	return make_an_array(&list, objects);
}





//对一个数组进行冒泡法排序(从小到大)
extern  void sort_win_to_max(tag_t *objs,int n_objs)
{


	int i,j;
	tag_t t_tag=NULL_TAG;
	char name1[133],name2[133];

	for(i=0;i<n_objs-1;i++)
	{	
		for(j=i+1;j<n_objs;j++)
		{

			memset(name1,0,133);
			memset(name2,0,133);
			UF_CALL(UF_OBJ_ask_name(objs[i],name1));
			UF_CALL(UF_OBJ_ask_name(objs[j],name2));

			char *p1=strrchr(name1,'-')+1;
			char *p2=strrchr(name2,'-')+1;

			if(atoi(p1)>atoi(p2)&& p1!=NULL && p2!=NULL)// 如果要从大到小排序只要把>改成<号就行了
			{
				t_tag=objs[i];
				objs[i]=objs[j];
				objs[j]=t_tag;

			}
		}
	}

}




















/*
uf_list_p_t display_list;
UF_MODL_create_list(&display_list);    
Get_display_solidlist(display_list);
*/


//获取显示的实体
extern   void Get_display_solidlist(uf_list_p_t display_list)
{
	int     type1=0, type2=0, subtype=0, body_type=0; 
	int     layer_status=0;
	tag_t   displayed_part=NULL_TAG, ele_tag = NULL_TAG, solid = NULL_TAG;
	type1 = UF_solid_type;  

	//displayed_part = UF_PART_ask_display_part(); 
	displayed_part = UF_ASSEM_ask_work_part();
	do   
	{  
		UF_OBJ_cycle_objs_in_part( displayed_part, type1, &solid );  

		UF_OBJ_ask_type_and_subtype(solid, &type2, &subtype);  
		if(subtype == UF_solid_body_subtype)  
		{   
			UF_MODL_ask_body_type (solid, &body_type);  
			if(body_type==UF_MODL_SOLID_BODY)   
			{  
				UF_OBJ_disp_props_t disp_props;
				UF_OBJ_ask_display_properties (solid, &disp_props);

				UF_LAYER_ask_status (disp_props.layer,&layer_status);
				if(layer_status!=UF_LAYER_INACTIVE_LAYER)
				{
					if(disp_props.blank_status==UF_OBJ_NOT_BLANKED)
					{
						//vtOutSolid->push_back(solid);
						UF_MODL_put_list_item(display_list,solid);  //写入链表
					}
				}
			}  
		}  
	} while (solid != NULL_TAG);
}





//获取显示的实体
extern   void Get_display_solid_vector(vector <tag_t> *disp_objects)
{
	int     type1=0, type2=0, subtype=0, body_type=0; 
	int     layer_status=0;
	tag_t   displayed_part=NULL_TAG, ele_tag = NULL_TAG, solid = NULL_TAG;
	type1 = UF_solid_type;  

	//displayed_part = UF_PART_ask_display_part(); 
	displayed_part = UF_ASSEM_ask_work_part();
	do   
	{  
		UF_OBJ_cycle_objs_in_part( displayed_part, type1, &solid );  

		UF_OBJ_ask_type_and_subtype(solid, &type2, &subtype);  
		if(subtype == UF_solid_body_subtype)  
		{   
			UF_MODL_ask_body_type (solid, &body_type);  
			if(body_type==UF_MODL_SOLID_BODY)   
			{  
				UF_OBJ_disp_props_t disp_props;
				UF_OBJ_ask_display_properties (solid, &disp_props);

				UF_LAYER_ask_status (disp_props.layer,&layer_status);
				if(layer_status!=UF_LAYER_INACTIVE_LAYER)
				{
					if(disp_props.blank_status==UF_OBJ_NOT_BLANKED)
					{
						//vtOutSolid->push_back(solid);
						disp_objects->push_back(solid);
						//UF_MODL_put_list_item(display_list,solid);  //写入链表
					}
				}
			}  
		}  
	} while (solid != NULL_TAG);
}











#ifdef __cplusplus
}
#endif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值