QQ登录

只需一步,快速开始

快捷登录

登录 或者 注册 请先

UG爱好者

 
搜索
查看: 2485|回复: 4
打印 上一主题 下一主题

[分享] 求助画基准曲线特征

[复制链接]

列兵

Rank: 1

2

主题

4

帖子

0

积分
跳转到指定楼层
楼主
发表于 2011-7-4 21:21:33 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
Foreign Datum Curves

In Creo Elements/Pro TOOLKIT, you create foreign datum curves using the feature creation techniques described insection `Element Trees: Principles of Feature Creation'. The header file ProForeignCurve.h contains the element tree structure and a table that maps each element to an element identifier, value type, and valid values.

The following figure shows the element tree structure for foreign datum curve creation. Note that all elements are required.


Figure 68-1: Element Tree for Foreign Datum Curve


As the element tree implies, foreign datum curve creation requires that you provide the feature type, curve type, curve class, reference coordinate system, data used in the analytical representation of the curve, and curve continuity. Creo Elements/Pro uses this information, together with an evaluation function, to create an internal representation of the curve.

Providing an Evaluation Function


Function Introduced:

ProForeignCurveEvalFunction()
In addition to building the element tree for your datum curve feature, you must provide its analytical representation to Creo Elements/Pro. This representation is made available to Creo Elements/Pro in a special function called an evaluator, or evaluation function.

The evaluation function must contain parameterized equations for the X, Y, and Z coordinates of points that define the curve. If C(X,Y,Z) is a function representing the curve in three-dimensional space, you can represent the parameterized equations for each coordinate as follows:

     X = f(t)
     Y = g(t)
     Z = h(t)

In these equations, the parameter t ranges from 0 to 1 over the extent of the curve. For example, a parametric representation of a circle of radius R lying in the XY-plane, whose center coincides with the origin, is as follows:

     X = R*cos(2*PI*t);
     Y = R*sin(2*PI*t);
     Z = 0;

In these equations, PI = 3.14159.

Creo Elements/Pro TOOLKIT provides the prototype for the evaluation function. The syntax is as follows:

typedef ProError (*ProForeignCurveEvalFunction)
(
  ProName        class,          /* input */
  wchar_t       *data_string,    /* input */
  ProSelection   csys,           /* input */
  double         curve_param,    /* input */
  ProVector      xyz_point,      /* output */
  ProVector      deriv1,         /* output */
  ProVector      deriv2          /* output */
);

The function arguments are as follows:

class--Identifies the type of curves generated by the evaluation function.
data_string--The flag that controls specific attributes of the curve.
csys--The reference coordinate system with respect to which the curve geometry is defined. Pass it to the evaluation function as a ProSelection object.
curve_param--The parameter value at which the X, Y, and Z coordinates, as well as the first and second derivatives, will be evaluated.
xyz_point--The X, Y, and Z coordinates at the value of curve_param.
deriv1--The values of the first derivatives of X, Y, and Z with respect to the parameter, at the value of curve_param.
deriv2--The values of the second derivatives of X, Y, and Z with respect to the parameter, at the value of curve_param.
All arguments are passed to the evaluation function by Creo Elements/Pro, based on the values you provide for the elements in the element tree.

A single evaluation function can be used to create a number of curve variations within a given class. The parameterized curve equations typically contain constants whose values control the shape, size, location, and orientation of the curve. You can write the evaluation function such that, depending on the value of the data_string argument, different values of those constants will be used to calculate the location of points on the curve.

Curve Continuity

Curve continuity, in a sense, defines the smoothness of intersections between the ends of the foreign curve and other geometry in the model. It also defines the continuity of three-dimensional geometry created from the curve, such as a swept surface. First-order continuity implies that the first derivatives of two adjoining curve segments are equal at the point at which the curves join. Second-order continuity is similarly defined. Depending on the curve continuity you want, the evaluator function needs to contain first and second derivatives of the parameterized curve equations.

You specify the curve continuity using the PRO_E_CURVE_CONTINUITY element in the element tree. The valid values, contained in the enumerated type ProForeignCrvCont, are as follows:

PRO_FOREIGN_CURVE_CALC_XYZ
PRO_FOREIGN_CURVE_CALC_XYZ_1_DER
PRO_FOREIGN_CURVE_CALC_XYZ_1_AND_2_DER
These values correspond to zeroth-, first-, and second-order continuity, respectively. If you use the value PRO_FOREIGN_CURVE_CALC_XYZ, Creo Elements/Pro passes NULL for deriv1 and deriv2 to the evaluation function. Similarly, if you use the value PRO_FOREIGN_CURVE_CALC_XYZ_1_DER, Creo Elements/Pro passes NULL for deriv2 to the evaluation function. Therefore, you should check for NULL values of deriv1 and deriv2 in your evaluation function before trying to assign derivative values to them.

Creo Elements/Pro calls your evaluation function multiple times for a series of values of the curve parameter, ranging from 0 to 1. The function outputs the following information:

X, Y, and Z coordinates of the curve at the specified parameter value
Values of the first and second derivatives, as needed for the desired curve continuity
These values are then used by Creo Elements/Pro to construct the curve.

Binding the Evaluation Function to a Class


Function Introduced:

ProForeignCurveClassEvalSet()
The evaluation function must be bound to a class. This is done with a call to the function ProForeignCurveClassEvalSet(). The function takes as arguments the class name and a pointer to the evaluation function. If you call ProForeignCurveClassEvalSet() and pass NULL for the evaluation function pointer, it unbinds a previously bound evaluation function from the class.

Example 1: Creating a Sinusoidal Foreign Datum Curve

The following code example shows how to use the Creo Elements/Pro TOOLKIT functions to create a sinusoidal foreign datum curve.


/*================================================================*\
FUNCTION: ProTestForeignDatumCurve()
PURPOSE:  Foreign datum curve evaluation function
\*================================================================*/
void ProTestForeignDatumCurve()
{
    wchar_t         data[PRO_NAME_SIZE];
    ProName         class;
    int             status, sel_num;
    static wchar_t  msgfil[PRO_LINE_SIZE];
    ProSelection   *p_sel_list, csys_ref, sel_model;
    ProMdl          model;
    ProModelitem    model_item;
    ProElement      elem_tree, elem_ftype, elem_crv_type,
                    elem_crv_class;
    ProElement      elem_crv_csys_ref, elem_crv_data_string,
                    elem_crv_continuity;
    ProValueData    value_data;
    ProValue        value;
    xyz_point[1] =  amplitude*(sin(wave_num*2.0*PI*curve_param));error C2064: 项不会计算为接受 1 个参数的函数????
    xyz_point[2] = 0.0;

    if (deriv1 != NULL)
    {
        deriv1[0] = wave_num*2.0*PI;
        deriv1[1] = (wave_num*2.0*PI)*amplitude *
            cos (wave_num*2.0*PI*curve_param);
        deriv1[2] = 0.0;
    }

    if (deriv2 != NULL)
    {
       deriv2[0] = 0.0;
       deriv2[1] = -(wave_num*wave_num*4.0*PI*PI) *
           amplitude*sin(wave_num*2.0*PI*curve_param);error C2064: 项不会计算为接受 1 个参数的函数????
           deriv2[2] = 0.0;
    }
    return (0);
}
void ProTestForeignDatumCurve()
{
wchar_t              data[PRO_NAME_SIZE];
ProName              class;
int                  status, sel_num;
static               wchar_t msgfil[PRO_LINE_SIZE];
ProSelection        *p_sel_list, csys_ref, sel_model;
ProMdl               model;
ProModelitem         model_item;
ProElement           elem_tree, elem_ftype, elem_crv_type, elem_crv_class;
ProElement           elem_crv_csys_ref, elem_crv_data_string,
                     elem_crv_continuity;
ProValueData         value_data;
ProValue             value;
ProFeature           crv_feature;
ProErrorlist         errors;
/*----------------------------------------------------------------*\
    Set the class type and curve data.
\*----------------------------------------------------------------*/
    ProStringToWstring (class, "SIN_CURVE");
/*----------------------------------------------------------------*\
    Bind the foreign curve evaluation function to the curve class.
\*----------------------------------------------------------------*/
    if ((status = ProForeignCurveClassEvalSet (class,
        (ProForeignCurveEvalFunction)TestCurveFunction)) !=
        PRO_TK_NO_ERROR)
    {
        printf ("ProForeignCurveClassEvalSet returned %d\n", status);
/*----------------------------------------------------------------*\
    Create the selection object for the current model to use in ProFeatureCreate().
\*----------------------------------------------------------------*/
    status = ProMdlCurrentGet (&model);
    status = ProMdlToModelitem (model, &model_item);
    status = ProSelectionAlloc (NULL, &model_item, &sel_model);

    ProMessageDisplay (msgfil, "USER Enter data set for refining curve
        (short, long, shallow, deep)");
    ProMessageStringRead (PRO_NAME_SIZE, data);

    ProStringToWstring (msgfil, "foreign_dtm_curve.txt");
    ProMessageDisplay (msgfil, "USER Select a reference coordinate
        system");
/*----------------------------------------------------------------*\
    Obtain the ProSelection object for the reference coordinate system.
\*----------------------------------------------------------------*/
    status = ProSelect ("csys", 1, NULL, NULL, NULL, NULL,
         &p_sel_list, &sel_num);
    status = ProSelectionAlloc (NULL, NULL, &csys_ref);
    status = ProSelectionCopy (p_sel_list[0], &csys_ref);
/*----------------------------------------------------------------*\
    Create the element tree.
\*----------------------------------------------------------------*/
    status = ProElementAlloc (PRO_E_FEATURE_TREE, &elem_tree);
/*----------------------------------------------------------------*\
    Allocate the feature type element.
\*----------------------------------------------------------------*/
    status = ProElementAlloc (PRO_E_FEATURE_TYPE, &elem_ftype);
/*----------------------------------------------------------------*\
    Set the value of the feature type element.
\*----------------------------------------------------------------*/
    value_data.type = PRO_VALUE_TYPE_INT;
    value_data.v.i = PRO_FEAT_CURVE;
    status = ProValueAlloc (&value);
    status = ProValueDataSet (value, &value_data);
    status = ProElementValueSet (elem_ftype, value);
/*----------------------------------------------------------------*\
    Add the feature type element as a child of the root of the tree.
\*----------------------------------------------------------------*/
    status = ProElemtreeElementAdd (elem_tree, NULL, elem_ftype);
/*----------------------------------------------------------------*\
    Allocate the curve type element.
\*----------------------------------------------------------------*/
    status = ProElementAlloc (PRO_E_CURVE_TYPE, &elem_crv_type);
/*----------------------------------------------------------------*\
    Set the value of the curve type element.
\*----------------------------------------------------------------*/
    value_data.type = PRO_VALUE_TYPE_INT;
    value_data.v.i = PRO_CURVE_TYPE_FOREIGN;
    status = ProValueAlloc (&value);
    status = ProValueDataSet (value, &value_data);
    status = ProElementValueSet (elem_crv_type, value);
/*----------------------------------------------------------------*\
    Add the curve type element as a child of the root of the tree.
\*----------------------------------------------------------------*/
    status = ProElemtreeElementAdd (elem_tree, NULL, elem_crv_type);
/*----------------------------------------------------------------*\
    Allocate the foreign curve class element.
\*----------------------------------------------------------------*/
    status = ProElementAlloc (PRO_E_FOREIGN_CURVE_CLASS,
        &elem_crv_class);
/*----------------------------------------------------------------*\
    Set the value of the foreign curve class element.
\*----------------------------------------------------------------*/
    value_data.type = PRO_VALUE_TYPE_WSTRING;
    value_data.v.w = class;
    status = ProValueAlloc (&value);
    status = ProValueDataSet (value, &value_data);
    status = ProElementValueSet (elem_crv_class, value);
/*----------------------------------------------------------------*\
    Add the foreign curve class element as a child of the root of
    the tree.
\*----------------------------------------------------------------*/
    status = ProElemtreeElementAdd (elem_tree, NULL, elem_crv_class);
/*----------------------------------------------------------------*\
    Allocate the foreign curve csys reference element.
\*----------------------------------------------------------------*/
    status = ProElementAlloc (PRO_E_FOREIGN_CURVE_CSYS_REF,
        &elem_crv_csys_ref);
/*----------------------------------------------------------------*\
    Set the value of the foreign curve csys reference element.
\*----------------------------------------------------------------*/
    value_data.type = PRO_VALUE_TYPE_SELECTION;
    value_data.v.r = csys_ref;
    status = ProValueAlloc (&value);
    status = ProValueDataSet (value, &value_data);
    status = ProElementValueSet (elem_crv_csys_ref, value);
/*----------------------------------------------------------------*\
    Add the foreign curve csys reference element as a child of the
    root of the tree.
\*----------------------------------------------------------------*/
    status = ProElemtreeElementAdd (elem_tree, NULL,
        elem_crv_csys_ref);
/*----------------------------------------------------------------*\
    Allocate the foreign curve data value element.
\*----------------------------------------------------------------*/
    status = ProElementAlloc (PRO_E_FOREIGN_CURVE_DATA_VAL,
        &elem_crv_data_string);
/*----------------------------------------------------------------*\
    Set the value of the foreign curve data value element.
\*----------------------------------------------------------------*/
    value_data.type = PRO_VALUE_TYPE_WSTRING;
    value_data.v.w = data;
    status = ProValueAlloc (&value);
    status = ProValueDataSet (value, &value_data);
    status = ProElementValueSet (elem_crv_data_string, value);
/*----------------------------------------------------------------*\
    Add the foreign curve data value element as a child of the root
    of the tree.
\*----------------------------------------------------------------*/
    status = ProElemtreeElementAdd (elem_tree, NULL,
        elem_crv_data_string);
/*----------------------------------------------------------------*\
    Allocate the foreign curve continuity element.
\*----------------------------------------------------------------*/
    status = ProElementAlloc (PRO_E_FOREIGN_CURVE_CONTINUITY,
        &elem_crv_continuity);
/*----------------------------------------------------------------*\
    Set the value of the foreign curve continuity element.
\*----------------------------------------------------------------*/
    value_data.type = PRO_VALUE_TYPE_INT;
    value_data.v.i = PRO_FOREIGN_CURVE_CALC_XYZ;
    status = ProValueAlloc (&value);
    status = ProValueDataSet (value, &value_data);
    status = ProElementValueSet (elem_crv_continuity, value);
/*----------------------------------------------------------------*\
    Add the foreign curve continuity element as a child of the root
    of the tree.
\*----------------------------------------------------------------*/
    status = ProElemtreeElementAdd (elem_tree, NULL,
        elem_crv_continuity);
/*----------------------------------------------------------------*\
    Create the foreign datum curve.
\*----------------------------------------------------------------*/
    status = ProFeatureCreate (sel_model, elem_tree, NULL, 0,
        &crv_feature, &errors);
/*----------------------------------------------------------------*\
    Free the allocated selection objects.
\*----------------------------------------------------------------*/
    ProSelectionFree (&csys_ref);
    ProSelectionFree (&sel_model);
}

有奖推广贴子: 

回复

使用道具 举报

列兵

Rank: 1

4

主题

64

帖子

0

积分
5#
发表于 2011-9-23 18:21:26 | 只看该作者
:funk::funk:
回复 支持 反对

使用道具 举报

三级士官

Rank: 3Rank: 3

52

主题

620

帖子

673

积分
地板
发表于 2011-7-5 10:42:24 | 只看该作者
南亚
回复 支持 反对

使用道具 举报

列兵

Rank: 1

13

主题

129

帖子

0

积分
板凳
发表于 2011-7-5 00:28:31 | 只看该作者
你真厉害,我是不会,我也希望有高手能帮助你。
回复 支持 反对

使用道具 举报

列兵

Rank: 1

2

主题

4

帖子

0

积分
沙发
 楼主| 发表于 2011-7-4 21:25:47 | 只看该作者
各位大哥,帮帮忙,上述程序有错误,error C2064: 项不会计算为接受 1 个参数的函数。主要是函数方程的构造和typedef ProError (*ProForeignCurveEvalFunction)
(
  ProName        class,          /* input */
  wchar_t       *data_string,    /* input */
  ProSelection   csys,           /* input */
  double         curve_param,    /* input */
  ProVector      xyz_point,      /* output */
  ProVector      deriv1,         /* output */
  ProVector      deriv2          /* output */
);
ProForeignCurveClassEvalSet()
运用上。还有这是tkuse.pdf给的例子。
请大家指点一下
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

 
 
QQ:1359218528
工作时间:
9:00-17:00
 
微信公众号
手机APP
机械社区
微信小程序

手机版|UG爱好者论坛 ( 京ICP备10217105号-2 )    论坛管理员QQ:1359218528

本站信息均由会员发表,不代表本网站立场,如侵犯了您的权利请联系管理员,邮箱:1359218528@qq.com  

Powered by UG爱好者 X3.2  © 2001-2014 Comsenz Inc. GMT+8, 2024-11-30 18:56

返回顶部