列兵
UID2466109
U币0
G币0
技术0
主题2
精华0
阅读权限10
注册时间2011-5-23
最后登录1970-1-1
在线时间0 小时
列兵
|
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);
} |
|