谁能注释一下这个程序
// geardialog 消息处理程序double m;
int z;
double kuandu;
ProGeomitem geomfront, geomtop, geomright;
ProGeomitem geomfront1, geomtop1, geomright1;
ProGeomitemlimian;
ProGeomitemzhouxian;
ProSelection sellimian;
ProSelection right;
ProSelection top;
ProSelection front;
ProSelection right1;
ProSelection top1;
ProSelection front1;
ProSelection cylinder_axis;
ProDimension *dim;
#define sqr(a) ((a)*(a))
#define PI 3.14159265358979323846
ProError ProUtilTwoCircleIntersection(Pro2dCircledef *c1, Pro2dCircledef *c2, Pro2dPnt p1,Pro2dPnt p2)
{
double d, x1, y1, sa, ca;
d = sqrt(sqr(c1->center-c2->center) + sqr(c1->center-c2->center));
if ((d<EPSM) || (d>c1->radius + c2->radius) ||
(d + c1->radius < c2->radius) || (d + c2->radius < c1->radius))
return (PRO_TK_GENERAL_ERROR);
y1 = (sqr(c1->radius) + sqr(d) - sqr(c2->radius)) / 2 /d;
x1 = sqrt(sqr(c1->radius) - sqr(y1));
sa = (c2->center-c1->center) / d;
ca = (c2->center-c1->center) / d;
p1 = y1 * sa + x1 * ca + c1->center;
p1 = y1 * ca - x1 * sa + c1->center;
p2 = y1 * sa - x1 * ca + c1->center;
p2 = y1 * ca + x1 * sa + c1->center;
return (PRO_TK_NO_ERROR);
}
int UsrCreateSection_gear(ProSection section,int index)//
{
int line_id;
Pro2dCircledef circle1;
switch (index)
{
case 1: //作圆
circle1.center=0.0;
circle1.center=0.0;
circle1.radius=(m*z+2*m)/2;//
circle1.type=PRO_2D_CIRCLE;
ProSectionEntityAdd (section,(Pro2dEntdef*)&circle1, &line_id);
break;
case 2: //齿形
ProError err;
Pro2dLinedef line;
Pro2dPnt point, p1, p2, p3;
Pro2dCircledef*p_circle,add_circle, ded_circle, t_circle;//
Pro2dArcdef arc;
int dims, brk=0, ring_gear,arc1_id, arc2_id, d_id;
int circle_id,ded_id;//
ProSectionPointType pnt_types;
ProWSecerror errors;
double d, r, angle, r_base, r_t, an ;
err =ProSectionEntityFromProjection(section, sellimian, &circle_id);
err = ProSectionEntityGet(section, circle_id, (Pro2dEntdef**)&p_circle);
r = (m*z+2*m)/2;
d = m* z;
ring_gear = r < d/2;
angle = 20*PI/180;
r_t = d/2 * sin(angle);
r_base = d/2 * cos(angle); //
add_circle.radius = r;
ded_circle.radius = d/2-1.2*m;
angle = PI/2 - angle - PI/(z*2);
add_circle.center = ded_circle.center = 0;
add_circle.center = ded_circle.center = 0;
t_circle.center = 0.0 + r_base * cos(angle);
t_circle.center = 0.0 + r_base * sin(angle);
t_circle.radius = r_t;
ProUtilTwoCircleIntersection(&add_circle, &t_circle, p1, p2);
if (p1>p2)
memcpy(p1, p2, sizeof(p1));
ProUtilTwoCircleIntersection(&ded_circle, &t_circle, p2, p3);
if (p2>p3)
memcpy(p2, p3, sizeof(p1));
line.type = PRO_2D_CENTER_LINE;
line.end1 = 0;
line.end1 = 0;
line.end2 = 0;
line.end2 = 0 + 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-arc.center, p1-arc.center);
arc.end_angle = atan2(p2-arc.center, p2-arc.center);
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 = (2 * 0 ) - arc.center;
err = ProSectionEntityAdd(section, (Pro2dEntdef*)&arc, &arc2_id);
memcpy(arc.center, ded_circle.center, sizeof(arc.center));
arc.start_angle = atan2( p2 - arc.center , p2 - arc.center );
arc.end_angle = PI - arc.start_angle;
arc.radius = ded_circle.radius;
err = ProSectionEntityAdd(section, (Pro2dEntdef*)&arc, &ded_id);
point =0.0;//
point = t_circle.center + 1;
pnt_types = PRO_ENT_CENTER;
pnt_types = PRO_ENT_CENTER;
dims = arc1_id;
dims = arc2_id;
err = ProSecdimCreate(section, dims, pnt_types, 2,PRO_TK_DIM_PNT_PNT_HORIZ, point, &d_id);
point = 1.2 * t_circle.center;
point = t_circle.center/2;
dims =circle_id;//
err = ProSecdimCreate(section, dims, pnt_types, 2,PRO_TK_DIM_PNT_PNT_VERT, point, &d_id);
point = 0;
if (ring_gear)
point = 1.2 * ded_circle.radius;
else
point = 0.8 * ded_circle.radius;
pnt_types = PRO_ENT_WHOLE;
err = ProSecdimCreate(section, &ded_id, pnt_types, 1, PRO_TK_DIM_RAD, point, &d_id);
point = p1 * 1.2;
point = p1 * 1.2;
err = ProSecdimCreate(section, &arc1_id, pnt_types, 1, PRO_TK_DIM_RAD, point, &d_id);
err = ProSecerrorAlloc(&errors);
err = ProSectionSolve(section, &errors);
if (err != PRO_TK_NO_ERROR)
break;
err = ProSecerrorFree(&errors);
break;
}
return (1);
}
ProError UserSectionBuild1_gear(ProSection section,int index)
{
ProError status=PRO_TK_NO_ERROR;
if(!UsrCreateSection_gear(section,index))//
{
AfxMessageBox(_T("Section Error!"));
return status;
}
return status ;
}
ProError UserSectionBuild_gear(ProSection section,int index )
{
ProError status;
int ent_id;
ProWSecerror serrors;
if(!UsrCreateSection_gear(section,index))//
{
return status;
}
ProSectionEntityFromProjection(section,right1 , &ent_id);
status=ProSectionEntityFromProjection(section,top1 , &ent_id);
ProSecerrorAlloc(&serrors);
status=ProSectionAutodim(section, &serrors);
return status ;
}
int UsrCreatDefDtm1_gear(ProDtmplnConstrType pro_dtmpln_def,ProName dtm_name,ProFeature *myfeature)
{
ProError status;
ProElement elem_tree,elem_type,elem_consts,elem_const,elem_const1,elem_const_type,elem_const_ref,elem_const_type1,elem_const_ref1,elem_const_ref_angle;
ProValueData value_data;
ProValue value;
ProModelitem model_modelitem;
ProSelection mdl_sel;
ProErrorlist errors;
ProSolid solid;
ProElementAlloc (PRO_E_FEATURE_TREE, &elem_tree);
ProElementAlloc (PRO_E_FEATURE_TYPE, &elem_type);
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_FEAT_DATUM;
ProValueAlloc (&value);
ProValueDataSet (value, &value_data);
ProElementValueSet (elem_type, value);
ProElemtreeElementAdd (elem_tree, NULL, elem_type);
ProElementAlloc (PRO_E_DTMPLN_CONSTRAINTS, &elem_consts);
ProElemtreeElementAdd (elem_tree, NULL, elem_consts);
ProElementAlloc (PRO_E_DTMPLN_CONSTRAINT, & elem_const);
ProElemtreeElementAdd (elem_consts, NULL, elem_const);
ProElementAlloc (PRO_E_DTMPLN_CONSTR_TYPE, &elem_const_type);
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_DTMPLN_THRU;
ProValueAlloc (&value);
ProValueDataSet (value, &value_data);
ProElementValueSet(elem_const_type, value);
ProElemtreeElementAdd (elem_const, NULL,elem_const_type);
ProElementAlloc (PRO_E_DTMPLN_CONSTR_REF, &elem_const_ref);
value_data.type = PRO_VALUE_TYPE_SELECTION;
value_data.v.r =cylinder_axis ;
ProValueAlloc (&value);
ProValueDataSet (value, &value_data);
ProElementValueSet(elem_const_ref, value);
ProElemtreeElementAdd (elem_const, NULL,elem_const_ref);
ProElementAlloc (PRO_E_DTMPLN_CONSTRAINT, & elem_const1);
ProElemtreeElementAdd (elem_consts, NULL, elem_const1);
ProElementAlloc (PRO_E_DTMPLN_CONSTR_TYPE, &elem_const_type1);
value_data.type = PRO_VALUE_TYPE_INT;
value_data.v.i = PRO_DTMPLN_ANG;
ProValueAlloc (&value);
ProValueDataSet (value, &value_data);
ProElementValueSet(elem_const_type1, value);
ProElemtreeElementAdd (elem_const1, NULL,elem_const_type1);
ProElementAlloc (PRO_E_DTMPLN_CONSTR_REF, &elem_const_ref1);
value_data.type = PRO_VALUE_TYPE_SELECTION;
value_data.v.r = right1;
ProValueAlloc (&value);
ProValueDataSet (value, &value_data);
ProElementValueSet(elem_const_ref1, value);
ProElemtreeElementAdd (elem_const1, NULL,elem_const_ref1);
ProElementAlloc (PRO_E_DTMPLN_CONSTR_REF_ANGLE, &elem_const_ref_angle);
value_data.type = PRO_VALUE_TYPE_DOUBLE;
value_data.v.d = 0.0;
ProValueAlloc (&value);
ProValueDataSet (value, &value_data);
ProElementValueSet(elem_const_ref_angle, value);
ProElemtreeElementAdd (elem_const1, NULL,elem_const_ref_angle);
ProMdlCurrentGet((ProMdl*)&solid);
ProMdlToModelitem(solid, &model_modelitem);
ProSelectionAlloc(NULL, &model_modelitem, &mdl_sel);
ProFeatureCreate (mdl_sel, elem_tree, NULL, 0,myfeature,&errors);
status=ProModelitemNameSet(myfeature,dtm_name);
status=ProFeatureRedefine(NULL, myfeature, elem_tree, NULL, 0, &errors);
ProElementFree (&elem_tree);
ProSelectionFree (&mdl_sel);return (status);
} 小弟不才,还没这水平 看到我头晕眼花的 这是一个自动生成三维图形的程序的一种一部分,我没细看大体应该是个齿轮吧,前两个函数体是描述齿轮的大体形状,因为有好多的坐标点设定,最后一个函数体是为生成三维图形而建立的特征树,应该是拉伸特征,中间的一些函数都是很简单的函数,就不说了,呵呵,自己研究吧。 画齿轮的,{:3_41:} 老天,太蓝!大海,太咸!人生,太难!工作,太烦!和你,有缘!想你,失眠!见你,太远!
我在顶贴~!~
页:
[1]