马上注册登录,享用更多网站功能!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
/*****************************************************************************
**
** 6_bolt.c
**
** Description:
** Contains Unigraphics entry points for the application.
**
*****************************************************************************/
/* Include files */
#include <stdio.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_modl.h>
#include <uf_layer.h>
#include <uf_part.h>
#include <uf_curve.h>
#include <uf_view.h>
#include "6_bolt.h"
/*****************************************************************************
** Activation Methods
*****************************************************************************/
/* Explicit Activation
** This entry point is used to activate the application explicitly, as in
** "File->Execute UG/Open->User Function..." */
extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
{
/* Initialize the API environment */
int errorCode = UF_initialize();
/*基本参数*/
/*
--- GB5780-86 六角头螺栓 C级 ---
d : 5.000 ---- 螺纹基本大径
p : 0.800 ---- 螺距
c : 0.500 ---- 凸缘厚度
da : 6.000 ---- 过渡园直径
dsmax : 5.480 ---- 无螺纹杆径
dsmin : 4.520
dw : 6.700 ---- 支撑面直径
e : 8.630 ---- 对角宽度
k : 3.500 ---- 头部高度
kmin : 3.120
kmax : 3.880
k1 : 2.200 ---- 扳拧高度
r : 0.200 ---- 头下园角半径
smax : 8.000 ---- 对边宽度
smin : 7.640
l : 25.000 ---- 公称长度
lmin : 23.900
lmax : 26.100
b : 16.000 ---- 螺纹长度
lsmin : 5.000 ---- 无螺纹杆部长度
lgmax : 9.000 ---- 最末一扣完整螺纹至支撑面距离
*/
//char temp[500];
//int ret;
double fraction = 1.0;
tag_t view_tag = NULL_TAG;
double square3 = 1.732050807569; /*根号3*/
double num8_square3 = 4.618802153517; /*8除以根号3*/
double num4_square3 = 2.309401076758; /*4除以根号3*/
float smax = 8.000; /*对边宽度*/
float smax2 = 4.000; /*对边宽度的一半*/
float k=3.500; /*头部高度*/
float first_point[3] = {0.0,0.0,0.0}; /*初始点*/
/*2定义curve的初始参数*/
//tag_t line1,line2,line3,line4,line5,line6,*objects;
tag_t line[6];
//UF_CURVE_line_t sline1,sline2,sline3,sline4,sline5,sline6;
UF_CURVE_line_t sline[6];
/*3拉伸六边形的初始参数*/
int i=0;
int count = 7;
uf_list_p_t loop_list, features;
char *taper_angle = "0.0";
char *limit1[2] = {"0.0", "3.5"};
double ref_pt[3];
double direction[3] = {0.0,0.0,1.0};
//tag_t hexagon_1;
UF_FEATURE_SIGN create = UF_NULLSIGN;
/*4圆锥1的初始参数*/
UF_FEATURE_SIGN intersect = UF_UNSIGNED;
//tag_t cone_1;
double cone1_origin[3];
char * cone1_height = "5.786307";
char * cone1_diam[2] = {"20.04435", "0.0"};
/*同六边形的direction*/
/*
double direction[3];
*/
tag_t cone1_obj_1;
/*5生成圆柱体1的参数*/
UF_FEATURE_SIGN unite = UF_POSITIVE;
double cy1_origin[3];
char * cy1_height = "25.0";
char * cy1_diam = "5.0";
double cy1_direction[3] = {0.0,0.0,-1.0};
tag_t cy1_obj_1;
/*6小圆锥2和3的参数*/
UF_FEATURE_SIGN subtract =UF_NEGATIVE;
double cone2_origin[3];
double cone3_origin[3];
char * cone2_height = "1.6";
char * cone3_height = "1.6";
char * cone2_diam[2] = {"4.999", "4.1339745968"};
char * cone3_diam[2] = {"4.997", "4.1319745968"};
double cone2_direction[3] = {0.0,0.0,-1.0};
double cone3_direction[3] = {0.0,0.0,-1.0};
tag_t cone2_obj_2;
tag_t cone3_obj_3;
/*7生成圆柱体2和3的参数*/
double cy2_origin[3];
double cy3_origin[3];
char * cy2_height = "16.0";
char * cy3_height = "16.0";
char * cy2_diam = "4.1339745968";
char * cy3_diam = "4.1319745968";
double cy2_direction[3] = {0.0,0.0,-1.0};
double cy3_direction[3] = {0.0,0.0,-1.0};
tag_t cy2_obj_2;
tag_t cy3_obj_3;
//tag_t edge;
/*8倒角的参数*/
/*取圆柱体1的平面,判断参数*/
int num_faces,ii,num_mao,num_edge;
double face_param[2],face_point[3],face_u_deriv1[3];
double face_v_deriv1[3],face_u_deriv2[3],face_v_deriv2[3];
double face_normal[3],face_radii[2];
uf_list_p_t face_list;
//tag_t place_face[1];
tag_t face_tag, mao_tag,edge_tag,edge_obj_cir;
//tag_t top_face[1],
uf_list_p_t cy1_edge_list, blend1_edge_list;
int edge_type;
const char * blend1_radius = "0.2";
// uf_list_p_t blend1_edge_list;
int blend1_smooth_overflow = 0;
int blend1_cliff_overflow = 0;
int blend1_notch_overflow = 0;
double blend1_vrb_tool = 0;
tag_t blend1_feature_obj_1;
//UF_CURVE_arc_t arc_coords ;
//double point1[3];
//double point2[3];
//int vertex_count;
if ( 0 == errorCode )
{
/* TODO: Add your application code here */
/*****************************************************************************/
/*2以下是六条线的参数*/
/*line[0]*/
sline[0].start_point[0] = first_point[0];
sline[0].start_point[1] = first_point[1] + num8_square3;
sline[0].start_point[2] = first_point[2];
sline[0].end_point[0] = first_point[0] + smax2;
sline[0].end_point[1] = first_point[1] + num4_square3;
sline[0].end_point[2] = first_point[2];
/*line[1]*/
sline[1].start_point[0] = first_point[0] + smax2;
sline[1].start_point[1] = first_point[1] + num4_square3;
sline[1].start_point[2] = first_point[2];
sline[1].end_point[0] = first_point[0] + smax2;
sline[1].end_point[1] = first_point[1] - num4_square3;
sline[1].end_point[2] = first_point[2];
/*line[2]*/
sline[2].start_point[0] = first_point[0] + smax2;
sline[2].start_point[1] = first_point[1] - num4_square3;
sline[2].start_point[2] = first_point[2];
sline[2].end_point[0] = first_point[0];
sline[2].end_point[1] = first_point[1] - num8_square3;
sline[2].end_point[2] = first_point[2];
/*line[3]*/
sline[3].start_point[0] = first_point[0];
sline[3].start_point[1] = first_point[1] - num8_square3;
sline[3].start_point[2] = first_point[2];
sline[3].end_point[0] = first_point[0] - smax2;
sline[3].end_point[1] = first_point[1] - num4_square3;
sline[3].end_point[2] = first_point[2];
/*line[4]*/
sline[4].start_point[0] = first_point[0] - smax2;
sline[4].start_point[1] = first_point[1] - num4_square3;
sline[4].start_point[2] = first_point[2];
sline[4].end_point[0] = first_point[0] - smax2;
sline[4].end_point[1] = first_point[1] + num4_square3;
sline[4].end_point[2] = first_point[2];
/*line[5]*/
sline[5].start_point[0] = first_point[0] - smax2;
sline[5].start_point[1] = first_point[1] + num4_square3;
sline[5].start_point[2] = first_point[2];
sline[5].end_point[0] = first_point[0];
sline[5].end_point[1] = first_point[1] + num8_square3;
sline[5].end_point[2] = first_point[2];
//把21层作为工作层,将线放在该层
UF_LAYER_set_status (21,
UF_LAYER_WORK_LAYER );
/*2生成六边形*/
UF_CURVE_create_line([$sline[0],&line[0])]
UF_CURVE_create_line([$sline[1],&line[1])]
UF_CURVE_create_line([$sline[2],&line[2])]
UF_CURVE_create_line([$sline[3],&line[3])]
UF_CURVE_create_line([$sline[4],&line[4])]
UF_CURVE_create_line([$sline[5],&line[5])]
//设回1层为工作层
UF_LAYER_set_status (1,
UF_LAYER_WORK_LAYER );
/*3拉伸六边形*/
UF_MODL_create_list([$loop_list)]
for(i = 0; i < count; i++)
{
UF_MODL_put_list_item(loop_list, line[i]);
}
UF_MODL_create_extruded(loop_list, taper_angle, limit1, ref_pt, direction, create, [$features)]
//取出螺帽的名字
UF_MODL_ask_list_count(features, [$num_mao)]
for (ii = 0;ii < num_mao;ii++)
{
UF_MODL_ask_list_item(features,ii,[$mao_tag)]
}
/*4以下是圆锥1的参数*/
cone1_origin[0] = first_point[0];
cone1_origin[1] = first_point[1];
cone1_origin[2] = first_point[2];
/*4做圆锥体*/
UF_MODL_create_cone1(intersect, cone1_origin, cone1_height, cone1_diam, direction, [$cone1_obj_1)]
/*5生成圆柱体1的参数*/
cy1_origin[0] = first_point[0];
cy1_origin[1] = first_point[1];
cy1_origin[2] = first_point[2];
/*5做圆柱体1*/
UF_MODL_create_cyl1(unite, cy1_origin, cy1_height, cy1_diam, cy1_direction, [$cy1_obj_1)]
/*6小圆锥2和3的参数*/
cone2_origin[0] = first_point[0];
cone2_origin[1] = first_point[1];
cone2_origin[2] = first_point[2] - 7.40271573478;
cone3_origin[0] = first_point[0];
cone3_origin[1] = first_point[1];
cone3_origin[2] = first_point[2] - 7.40271573478;
/*6小圆锥2和3*/
UF_MODL_create_cone1(create, cone2_origin, cone2_height, cone2_diam, cone2_direction, [$cone2_obj_2)]
UF_MODL_create_cone1(subtract, cone3_origin, cone3_height, cone3_diam, cone3_direction, [$cone3_obj_3)]
/*7生成圆柱体2和3的参数*/
cy2_origin[0] = first_point[0];
cy2_origin[1] = first_point[1];
cy2_origin[2] = first_point[2] - 1.6 - 7.40271573478;
cy3_origin[0] = first_point[0];
cy3_origin[1] = first_point[1];
cy3_origin[2] = first_point[2] - 1.6 - 7.40271573478;
/*7圆柱体2和3*/
UF_MODL_create_cyl1(create, cy2_origin, cy2_height, cy2_diam, cy2_direction, [$cy2_obj_2)]
UF_MODL_create_cyl1(subtract, cy3_origin, cy3_height, cy3_diam, cy3_direction, [$cy3_obj_3)]
/*8倒角*/
//从体取面
UF_MODL_ask_feat_faces(mao_tag , [$face_list)]
UF_MODL_ask_list_count(face_list, [$num_faces)]
face_param[0] = 0.5;
face_param[1] = 0.5;
//ret=UF_UI_open_listing_window();
for (ii = 0;ii < num_faces;ii++)
{
UF_MODL_ask_list_item(face_list, ii, [$face_tag)]
UF_MODL_ask_face_props(face_tag,
face_param,
face_point,
face_u_deriv1,face_v_deriv1,
face_u_deriv2,face_v_deriv2,
face_normal,face_radii);
// if (face_normal[2] > 0.75)
// place_face[0] = face_tag;
// if (face_normal[1] < -0.75)
// top_face[0] = face_tag;
}
// sprintf(temp,"face_point[1]=%f\n",face_point[0]);
// sprintf(temp,"%s face_point[2]=%f\n",temp,face_point[1]);
// sprintf(temp,"%s face_point[3]=%f\n",temp,face_point[2]);
// ret=UF_UI_write_listing_window(temp);
//从面取线
UF_MODL_ask_face_edges (face_tag, [$cy1_edge_list)]
UF_MODL_ask_list_count(cy1_edge_list, [$num_edge)]
for(ii=0;ii<num_edge;ii++)
{
UF_MODL_ask_list_item(cy1_edge_list, ii, [$edge_tag)]
UF_MODL_ask_edge_type (
edge_tag,
[$edge_type)]
if(edge_type == UF_MODL_CIRCULAR_EDGE)
{
edge_obj_cir = edge_tag;
}
// sprintf(temp,"vertex_count=%f\n",point1[2]);
// UF_UI_write_listing_window(temp);
}
/*
UF_CURVE_ask_arc_data (
edge_obj_cir,
[$arc_coords )]
sprintf(temp,"%f",arc_coords.radius);
UF_UI_open_listing_window();
UF_UI_write_listing_window(temp);
*/
UF_MODL_create_list([$blend1_edge_list)]
UF_MODL_put_list_item(blend1_edge_list, edge_obj_cir);
UF_MODL_create_blend (blend1_radius, blend1_edge_list, blend1_smooth_overflow, blend1_cliff_overflow, blend1_notch_overflow, blend1_vrb_tool, [$blend1_feature_obj_1)]
//设置工作层外的其他层不可见
UF_LAYER_set_all_but_work (UF_LAYER_INACTIVE_LAYER );
//fit view
//UF_VIEW_fit_view (tag_t view_tag, double fraction );
UF_VIEW_fit_view (view_tag, fraction );
/*释放内存*/
UF_MODL_delete_list([$loop_list)]
UF_MODL_delete_list([$features)]
UF_MODL_delete_list([$face_list)]
UF_MODL_delete_list([$cy1_edge_list)]
UF_MODL_delete_list([$blend1_edge_list)]
/* Terminate the API environment */
errorCode = UF_terminate();
}
/* Print out any error messages */
PrintErrorMessage( errorCode );
}
/*****************************************************************************
** Utilities
*****************************************************************************/
/* Unload Handler
** This function specifies when to unload your application from Unigraphics.
** If your application registers a callback (from a MenuScript item or a
** User Defined Object for example), this function MUST return
** "UF_UNLOAD_UG_TERMINATE". */
extern int ufusr_ask_unload( void )
{
return( UF_UNLOAD_IMMEDIATELY );
}
/* PrintErrorMessage
**
** Prints error messages to standard error and the Unigraphics status
** line. */
static void PrintErrorMessage( int errorCode )
{
if ( 0 != errorCode )
{
/* Retrieve the associated error message */
char message[133];
UF_get_fail_message( errorCode, message );
/* Print out the message */
UF_UI_set_status( message );
fprintf( stderr, "%s\n", message );
}
} |