⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 geardesignutils.c

📁 Pro.TOOLKIT.Wildfire插件设计.配套光盘-141M.zip
💻 C
📖 第 1 页 / 共 2 页
字号:
/*====================================================================*\FILE	: GearDesignUtils.cPURPOSE	: Utilities for Gear Design Application Demo \*====================================================================*/#include <GearDesign.h>#include <ProToolkit.h>#include <Pro2dEntdef.h>#include <ProFeature.h>#include <UtilCollect.h>#include <UtilMath.h>#define sqr(a) ((a)*(a))typedef struct feat_by_name_find{   FeatByName *feats;   int num_feats;	 }  FeatByNameFind;static ProError status;/*=============================================================*\  Function: 	ProUtilCreateCircleSection  Purpose:	Full creating of section with one circle  Return :      \*=============================================================*/ProError ProUtilCreateCircleSection(    ProSection section,		/*In : the section */    Parameter *params)		/*In : params [0] - diameter */				/*     params [1] - vertical surface */				/*     params [2] - vertical surface */{    Pro2dCircledef circle;    Pro2dEntdef* ent;    Pro2dLinedef* line;    Pro2dPnt     point;    int brk=0;    int circle_id, circle_diam, side_id, bot_id;    ProSectionPointType pnt_types[2];    ProError err;    ProWSecerror errors;    do /* Used for exit from the middle of block */      {/*----------------------------------------------------------*\    Create entities\*----------------------------------------------------------*/	circle.type = PRO_2D_CIRCLE;		/* Align the X coordinate of the circle with the side datum plane */	err = ProSectionEntityFromProjection(section, params[1].r, &side_id);  	err = ProSectionEntityGet (section, side_id, &ent);		line = (Pro2dLinedef*) ent;		circle.center[0] = line->end1 [0];		/* Align the Y coordinate of the circle with the bottom datum plane */	err = ProSectionEntityFromProjection(section, params[2].r, &bot_id);   	err = ProSectionEntityGet (section, bot_id, &ent);		line = (Pro2dLinedef*) ent;		circle.center[1] = line->end1 [1];		circle.radius = params[0].d/2;		err = ProSectionEntityAdd(section, (Pro2dEntdef*)&circle, &circle_id);    /*----------------------------------------------------------*\    Add dimensions\*----------------------------------------------------------*/	point[0] = 0.0;	point[1] = params[0].d/2+1; 	pnt_types[0] = PRO_ENT_WHOLE;	err =ProSecdimCreate(section, &circle_id, pnt_types, 1,			     PRO_TK_DIM_DIA, point, &circle_diam);/*----------------------------------------------------------*\    Solve section\*----------------------------------------------------------*/	err = ProSecerrorAlloc(&errors);			   	err = ProSectionSolve(section, &errors);	if (err != PRO_TK_NO_ERROR)	    break;	err = ProSecerrorFree(&errors);    } while (brk);    return (err);}/*=============================================================*\  Function: 	ProUtilCreateToothSection  Purpose:	Full creating of tooth space section  Return :      \*=============================================================*/ProError ProUtilCreateToothSection(    ProSection section,		/*In : the section */    Parameter *params)		/*In : params [0] - the module m */				/*     params [1] - the number of teeth */				/*     params [2] - standart pressure angle */				/*     params [3] - for further appended */				/*     params [4] - gear side surface */{    Pro2dLinedef line;    Pro2dPnt     point, p1, p2, p3;    Pro2dCircledef *p_circle, add_circle, ded_circle, t_circle;    Pro2dArcdef arc;    int dims[2], brk=0, ring_gear, z, arc1_id, arc2_id, d_id;    int circle_id, ded_id;    ProSectionPointType pnt_types[2];    ProError err;    ProWSecerror errors;    double d, r, angle, r_base, r_t, m, an ;    do /* Used for exit from the middle of block */    {	err = ProSectionEntityFromProjection(section, params[4].r, &circle_id);	err = ProSectionEntityGet(section, circle_id, (Pro2dEntdef**)&p_circle);	r = p_circle->radius;	m = params[0].d;	z = params[1].i;	d = params[0].d * z; /* The Pitch circle radius */	ring_gear = r < d/2;	angle = params[2].d*PI/180;	r_t = d/2 * sin(angle);	r_base = d/2 * cos(angle); /* The base-circle diam */	if (ring_gear)	{	    add_circle.radius = r;	    ded_circle.radius = d/2+1.2*m;	    angle = PI/2 + angle - PI/(z*2);	}	else	{	    add_circle.radius = r;	    ded_circle.radius = d/2-1.2*m;	    angle = PI/2 - angle - PI/(z*2);	}	add_circle.center[0] = ded_circle.center[0] = p_circle -> center [0];	add_circle.center[1] = ded_circle.center[1] = p_circle -> center [1];	t_circle.center[0] = p_circle -> center [0] + r_base * cos(angle);	t_circle.center[1] = p_circle -> center [1] + r_base * sin(angle);	t_circle.radius = r_t;	ProUtilTwoCircleIntersection(&add_circle, &t_circle, p1, p2);	if (ring_gear)	{	    if (p1[0]<p2[0])		memcpy(p1, p2, sizeof(p1));	} else {	    if (p1[0]>p2[0])		memcpy(p1, p2, sizeof(p1));	}	ProUtilTwoCircleIntersection(&ded_circle, &t_circle, p2, p3);	if (ring_gear)	{	    if (p2[0]<p3[0])		memcpy(p2, p3, sizeof(p1));	} else {	    if (p2[0]>p3[0])		memcpy(p2, p3, sizeof(p1));	}/*----------------------------------------------------------*\    Create entities\*----------------------------------------------------------*/	line.type = PRO_2D_CENTER_LINE;	line.end1[0] = p_circle -> center [0];	line.end1[1] = p_circle -> center [1];	line.end2[0] = p_circle -> center [0];	line.end2[1] = p_circle -> center [1] + r;	err = ProSectionEntityAdd(section, (Pro2dEntdef*)&line, &d_id);    	arc.type =  PRO_2D_ARC;	memcpy(arc.center, t_circle.center, sizeof(arc.center));	arc.start_angle = atan2(p1[1]-arc.center[1], p1[0]-arc.center[0]);	arc.end_angle = atan2(p2[1]-arc.center[1], p2[0]-arc.center[0]);	arc.radius = r_t;	err = ProSectionEntityAdd(section, (Pro2dEntdef*)&arc, &arc1_id);    	an = PI - arc.start_angle;	arc.start_angle = PI - arc.end_angle;	arc.end_angle = an;	arc.center[0] = (2 * p_circle -> center [0] ) - arc.center[0];	err = ProSectionEntityAdd(section, (Pro2dEntdef*)&arc, &arc2_id);    	memcpy(arc.center, ded_circle.center, sizeof(arc.center));	arc.start_angle = atan2( p2[1] - arc.center [1], p2[0] - arc.center [0]);	arc.end_angle = PI - arc.start_angle;	arc.radius = ded_circle.radius;	err = ProSectionEntityAdd(section, (Pro2dEntdef*)&arc, &ded_id);    /*----------------------------------------------------------*\    Add dimensions\*----------------------------------------------------------*/	point[0] = p_circle -> center [0];	point[1] = t_circle.center[1] + 1; 	pnt_types[0] = PRO_ENT_CENTER;	pnt_types[1] = PRO_ENT_CENTER;	dims[0] = arc1_id;	dims[1] = arc2_id;	err = ProSecdimCreate(section, dims, pnt_types, 2,			     PRO_TK_DIM_PNT_PNT_HORIZ, point, &d_id);    	point[0] = 1.2 * t_circle.center[0];	point[1] = t_circle.center[1]/2;	dims[1] = circle_id;	err = ProSecdimCreate(section, dims, pnt_types, 2,			     PRO_TK_DIM_PNT_PNT_VERT, point, &d_id);	point[0] = 0;	if (ring_gear)	    point[1] = 1.2 * ded_circle.radius;	else	    point[1] = 0.8 * ded_circle.radius;	pnt_types[0] = PRO_ENT_WHOLE;	err = ProSecdimCreate(section, &ded_id, pnt_types, 1, 			      PRO_TK_DIM_RAD, point, &d_id);  	    	point[0] = p1[0] * 1.2;	point[1] = p1[1] * 1.2;	err = ProSecdimCreate(section, &arc1_id, pnt_types, 1, 			      PRO_TK_DIM_RAD, point, &d_id);  /*----------------------------------------------------------*\    Solve section\*----------------------------------------------------------*/    	err = ProSecerrorAlloc(&errors);	err = ProSectionSolve(section, &errors);	if (err != PRO_TK_NO_ERROR)	    break;	err = ProSecerrorFree(&errors);    } while (brk);    return (err);}/*=============================================================*\  Function: 	ProUtilCreateKeySection  Purpose:	Full creating of open section with tree lines  Return :      \*=============================================================*/ProError ProUtilCreateKeySection(    ProSection section,		/*In : the section */    Parameter *params)		/*In : params [0] - section width */				/*     params [1] - section height */				/*     params [2] - cyl surface */{    Pro2dLinedef line;    Pro2dPnt     point;    Pro2dCircledef *p_circle;    int dims[2], brk=0;    int left_id, right_id, top_id, bottom_id, width_id, height_id, circle_id, width2_id, height2_id,width3_id, height3_id,width4_id, height4_id;    ProSectionPointType pnt_types[2];    ProError err;    ProWSecerror errors;    double y, r;
    do /* Used for exit from the middle of block */    {

	err = ProSectionEntityFromProjection(section, params[2].r, &circle_id);        err = ProSectionEntityGet(section, circle_id, (Pro2dEntdef**)&p_circle);        r = p_circle->radius;        y = sqrt(r*r - params[0].d*params[0].d/4);/*----------------------------------------------------------*\    Create entities\*----------------------------------------------------------*/        line.type = PRO_2D_LINE;        line.end1[0] = line.end2[0] = -params[0].d/2;        line.end1[1] = y;        line.end2[1] = r + params[1].d;        err = ProSectionEntityAdd(section, (Pro2dEntdef*)&line, &left_id);        line.end1[0] = line.end2[0] = -line.end1[0];        err = ProSectionEntityAdd(section, (Pro2dEntdef*)&line, &right_id);        line.end1[0] = -line.end1[0];        line.end1[1] =  line.end2[1];        err = ProSectionEntityAdd(section, (Pro2dEntdef*)&line, &top_id);

	line.end1[0] = -params[0].d/2;
	line.end1[1] = y;
	line.end2[0] = params[0].d/2;
	line.end2[1] = y;
        err = ProSectionEntityAdd(section, (Pro2dEntdef*)&line, &bottom_id);
/*----------------------------------------------------------*\    Add dimensions\*----------------------------------------------------------*/        point[0] = 0.0;        point[1] = r + params[1].d+1;        pnt_types[0] = PRO_ENT_WHOLE;        err =ProSecdimCreate(section, &top_id, pnt_types, 1,                             PRO_TK_DIM_LINE, point, &width_id);        point[0] = params[0].d/2+1;        point[1] = (y + point[1])/2;        pnt_types[0] = pnt_types[1] = PRO_ENT_WHOLE;        dims[0] = top_id;        dims[1] = circle_id;        err = ProSecdimCreate(section, dims, pnt_types, 2,                              PRO_TK_DIM_LINE_AOC, point, &height_id);

        point[0] = 0.0;
        point[1] = r + params[1].d+1;
        pnt_types[0] = PRO_ENT_WHOLE;
        err =ProSecdimCreate(section, &top_id, pnt_types, 1,
                             PRO_TK_DIM_LINE, point, &width4_id);

        point[0] = params[0].d/2+1;
        point[1] = (y + point[1])/2;
        pnt_types[0] = pnt_types[1] = PRO_ENT_WHOLE;
        dims[0] = bottom_id;
        dims[1] = circle_id;
        err = ProSecdimCreate(section, dims, pnt_types, 2,
                              PRO_TK_DIM_LINE_AOC, point, &height4_id);

        point[0] = -1.0;
        point[1] = r + params[1].d+1;
        pnt_types[0] = pnt_types[1] = PRO_ENT_WHOLE;
        dims[0] = left_id;
        dims[1] = circle_id;
        err =ProSecdimCreate(section, dims, pnt_types, 2,
                             PRO_TK_DIM_LINE_AOC, point, &width2_id);

        point[0] = params[0].d/2+1;
        point[1] = (y + point[1])/2;
        pnt_types[0] = PRO_ENT_WHOLE;
        err = ProSecdimCreate(section, &left_id, pnt_types, 1,
                              PRO_TK_DIM_LINE, point, &height2_id);

        point[0] = 1.0;
        point[1] = r + params[1].d+1;
        pnt_types[0] = pnt_types[1] = PRO_ENT_WHOLE;
        dims[0] = right_id;
        dims[1] = circle_id;
        err =ProSecdimCreate(section, dims, pnt_types, 2,
                             PRO_TK_DIM_LINE_AOC, point, &width3_id);

        point[0] = params[0].d/2+1;
        point[1] = (y + point[1])/2;
        pnt_types[0] = PRO_ENT_WHOLE;
        err = ProSecdimCreate(section, &right_id, pnt_types, 1,
                              PRO_TK_DIM_LINE, point, &height3_id);/*----------------------------------------------------------*\    Solve section\*----------------------------------------------------------*/        err = ProSecerrorAlloc(&errors);        err = ProSectionSolve(section, &errors);	err = ProSecerrorFree(&errors);    } while (brk);
    return (err);}/*=============================================================*\  Function: 	ProUtilCreateNotchSection  Purpose:	Full creating of open section with tree lines  Return :      \*=============================================================*/ProError ProUtilCreateNotchSection(    ProSection section,		/*In : the section */    Parameter *params)		/*In : params [0] - circle diameter */				/*     params [1] - notch radius */				/*     params [2] - backplate surface */{    Pro2dArcdef arc;    Pro2dCircledef* p_circle;    Pro2dPnt     point;    int dims[2], brk=0;    int circle_id, arc_id, hor_id, vert_id, rad_id;    ProSectionPointType pnt_types[2];    ProError err;    ProWSecerror errors;    double y, x;    do /* Used for exit from the middle of block */    {	y = ((params[0].d*params[0].d)/2-params[1].d*params[1].d)/params[0].d;	x = sqrt((params[0].d*params[0].d)/4-y*y);/*----------------------------------------------------------*\    Create entities\*----------------------------------------------------------*/	err = ProSectionEntityFromProjection(section, params[2].r, &circle_id);	err = ProSectionEntityGet (section, circle_id, (Pro2dEntdef**)&p_circle);	arc.type = PRO_2D_ARC;	arc.center[0] = p_circle -> center [0];	arc.center[1] = p_circle -> center [1] + params[0].d/2;	arc.radius = params[1].d;	arc.start_angle = atan2(y-params[0].d/2, -x)+PI*2;	arc.end_angle = 3*PI - arc.start_angle;	err = ProSectionEntityAdd(section, (Pro2dEntdef*)&arc, &arc_id);    /*----------------------------------------------------------*\    Add dimensions\*----------------------------------------------------------*/	point[0] = p_circle -> center [0];	point[1] = p_circle -> center [1] + params[0].d/2 ; 	pnt_types[0] = PRO_ENT_WHOLE;	err =ProSecdimCreate(section, &arc_id, pnt_types, 1,			     PRO_TK_DIM_RAD, point, &rad_id);    	point[0] = p_circle -> center [0];	point[1] = p_circle -> center [1] + params[0].d/4;	pnt_types[0] = PRO_ENT_CENTER;	pnt_types[1] = PRO_ENT_CENTER;	dims[0] = circle_id;	dims[1] = arc_id;	err = ProSecdimCreate(section, dims, pnt_types, 2, 			      PRO_TK_DIM_PNT_PNT_HORIZ, point, &hor_id);  	point[0] = p_circle -> center [0] + 1.0;	point[1] = p_circle -> center [1] + params[0].d/4;	pnt_types[0] = PRO_ENT_CENTER;	pnt_types[1] = PRO_ENT_CENTER;	dims[0] = circle_id;	dims[1] = arc_id;vert_id = -1;printf( "point=(%f %f)\n", point[0], point[1] );	err = ProSecdimCreate(section, dims, pnt_types, 2, 			      PRO_TK_DIM_AOC_AOC_TAN_VERT, point, &vert_id);  	    /*----------------------------------------------------------*\    Solve section\*----------------------------------------------------------*/	err = ProSecerrorAlloc(&errors);	err = ProSectionSolve(section, &errors);	if (err != PRO_TK_NO_ERROR)	    break;	err = ProSecerrorFree(&errors);   } while (brk);    return (err);}/*=============================================================*\  Function: 	ProUtilCreateSketchedFeature  Purpose:	create a new feature

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -