Event-driven Programming: Foreign Datum Curves
This section describes the Creo TOOLKIT functions that enable you to create foreign datum curves.
Foreign Datum Curves
In Creo TOOLKIT, you create foreign datum curves using the feature creation techniques described in the section 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.
Element Tree for Foreign Datum Curve
Image
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 Parametric uses this information, together with an evaluation function, to create an internal representation of the curve.
Providing an Evaluation Function
Function Introduced:
In addition to building the element tree for your datum curve feature, you must provide its analytical representation to Creo Parametric. This representation is made available to Creo Parametric 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 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 Parametric, 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 Parametric passes NULL for deriv1 and deriv2 to the evaluation function. Similarly, if you use the value PRO_FOREIGN_CURVE_CALC_XYZ_1_DER, Creo Parametric 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 Parametric 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 Parametric to construct the curve.
Binding the Evaluation Function to a Class
Function Introduced:
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.