Event-driven Programming: Toolkit-Based Analysis
This section describes the functions that enable you to create analysis and analysis feature objects in a Creo Parametric solid.
Overview
Creo Behavioral Modeling allows the creation of two types of objects in a Creo Parametric solid:
•  Analysis
•  Analysis Feature
In Creo Parametric you can create an analysis using the commands under the Analysis tab. Analyses show the results of certain standard types of measurement or calculation, for example, curvature of an edge or surface, or the center of gravity of a solid. Users can name an analysis and store it in the solid, along with the references to the geometry items it analyses. The analysis is then reevaluated automatically upon each model regeneration, and can be queried at any time using the Analysis command. Such an analysis is stored separately from the features and geometry items in the solid.
An analysis feature is a feature that uses an analysis to determine the values of its feature parameters and the shape of its geometry items. An analysis feature is a variety of datum feature and is created using the Creo Parametric Datum command. An example of the use of an analysis feature is the creation of a coordinate system datum at the center of gravity of a solid, aligned with its axes of inertia. Another example is a pair of datum points at the closest points of two parts in an assembly.
Creo TOOLKIT analysis functions allow definition of analyses and analysis features whose computations are performed by callback functions provided by the Creo TOOLKIT application. This means that Creo TOOLKIT can be used to make analysis computations, and determine feature geometry, in ways not native to Creo Parametric. We refer to the analyses and analysis features defined by Creo TOOLKIT as toolkit-based; this stresses the fact that the computations could be performed by a separate Creo TOOLKIT application.
Creo TOOLKIT users should practice using standard Creo Parametric analyses and analysis features before studying toolkit-based analyses.
The functions and data structures specific to toolkit-based analysis features are declared in the header file ProAnalysis.h.
Interactive Creation of Toolkit-Based Analysis
If a Creo TOOLKIT application registers a Toolkit-Based Analysis type, the Analysis menu on the Creo Parametric toolbar contains an extra button labeled Toolkit-Based. Click this button to see the Toolkit-Based dialog box.
The selector at the top of the dialog box shows the types of external analysis registered by the Creo TOOLKIT application.
When you have chosen the type, click the Analysis UI button; this calls the Creo TOOLKIT callback, which prompts the user for the information needed by the analysis. When you have answered all the prompts, click Compute.
Compute performs the analysis and displays the resulting text, if any, in the text area of the dialog box. It may also display some graphics.
When you have clicked Compute, you may also click Info, which displays the output text in an information window.
The Saved Analyses and Close buttons behave as for standard analyses.
Interactive Creation of Toolkit-Based Analysis Feature
In Creo Parametric, under the Analysis tab, in the Manage group, select the Analysis command. This displays the Creo Parametric ANALYSIS dialog box, which leads the user through the definition of the elements of the analysis feature. If a Creo TOOLKIT application is running and has registered at least one type of toolkit-based analysis, there will be an additional button labeled Toolkit-Based in the Type section.
Set the name of the analysis first, set the type to Toolkit-Based Analysis, and continue to the next step, which is called “Definition”. The Toolkit-Based dialog box appears. This behaves exactly as for an external analysis, until you click the Close button. It then returns to the ANALYSIS dialog box, to allow you to continue specifying the feature elements.
The remaining elements are Result Params and Result Datums. These behave exactly as for standard analysis features, except that the parameters and datums are defined by the Creo TOOLKIT application. One or other may be absent if the toolkit-based analysis defines no parameters or no datums.
Storage of Toolkit-Based Analysis Feature in Creo Parametric
A toolkit-based analysis feature is stored in Creo Parametric in exactly the same way as any other feature. It appears in the model tree as a feature of type Analysis, and all the regular Feature commands can be used on it.
The references to existing geometry that the feature needs to calculate its own parameters and geometry are given to Creo Parametric by the Creo TOOLKIT application in the form of ProSelection structures. Creo Parametric stores these references, using the standard method for storing feature references. This means that the Creo TOOLKIT application does not need to store this information, and that the feature automatically has the correct behavior for the following Creo Parametric functions:
•  Feature Regeneration—Creo Parametric knows from the feature references what other features it depends on, and therefore whether the features needs to be included in a particular regeneration.
•  Rerouting Features
•  Patterning Features
The Creo TOOLKIT application may also give Creo Parametric the values of any variables that control the geometry, and Creo Parametric stores them as feature dimensions in the new feature. The Creo TOOLKIT application can then read the current dimension values when recomputing the feature geometry. This means the feature correctly responds to dimension changes as a result of, for example, being driven by a relation.
The Creo TOOLKIT application must store as external data any information about toolkit-based analysis features that is not stored as either geometry references or dimensions.
Registering a Toolkit-Based Analysis with Creo Parametric
Function Introduced:
The function ProAnalysisTypeRegister() registers a toolkit-based analysis with Creo Parametric by specifying its type name and the set of callback functions to be used when creating it and performing the computation. Call this function in user_initialize().
If called correctly, both the Analysis command and the ANALYSIS dialog box used in creating an analysis feature will include the button Toolkit-Based as the analysis type. Refer to the sections Interactive Creation of Toolkit-Based Analysis and Interactive Creation of Toolkit-Based Analysis Feature for more information on creating these objects.
Analysis Callbacks
When registering a Toolkit-Based Analysis type, callbacks must be provided for each of the following 13 types:
•  ui
•  dims
•  infoalloc
•  infofree
•  compcheck
•  compute
•  display
•  output
•  savecheck
•  infosave
•  inforetrieve
•  infocopy
•  result
Each callback is passed an argument of the ProAnalysis type, which is an opaque handle and identifies the analysis information stored by Creo Parametric.
The following table explains when the callbacks are called, and how each one should be used.
When Creo Parametric creates a toolkit-based analysis or analysis feature:
Callback
Description
infoalloc
Allocate memory for the Creo TOOLKIT application information about the toolkit-based analysis.
ui
Creo TOOLKIT prompts the user for inputs that define the analysisfor example, select a surface datum point on which to position a csys.
compcheck
Tell Creo Parametric whether the computation can be performed. If the Creo TOOLKIT application cannot perform the computation (for example, because input data is unavailable), it returns an error and the regeneration fails.
compute
Perform the analysis computation and store the results in memory.
display
Display graphics showing the computation result.
output
Pass a set of text lines to Creo Parametric for display in the ANALYSIS dialog box to show the result of the computation.
infocopy
Copy the application information from an existing analysis to a new one. Call infocopy during creation because of the way in which Creo Parametric handles feature creation.
dims
Creo TOOLKIT gives Creo Parametric a list of double values needed to calculate the geometry. Creo Parametric stores these as model dimensions.
result
Creo TOOLKIT gives Creo Parametric a description of the feature parameters and geometry items that result from the computation of the analysis. Creo Parametric may also call this callback when it needs to know only the number and names of parameters and datums; an example is when the user selects Feature Info. For more details, refer to the section Results Data.
When the Creo Parametric user saves the analysis to the solid:
Callback
Description
savecheck
Tell Creo Parametric whether the description of the analysis can be saved.
infosave
Give Creo Parametric a list of geometry items referenced by the analysis. Creo Parametric stores these using its own internal mechanism for storing references. The references appear in the model as feature references, and are used to determine the relationship of the feature to other features, and therefore when the feature needs to be regenerated.
OR
Store any other data as external data.
When the Creo Parametric user retrieves a solid containing analyses:
Callback
Description
inforetrieve
Creo Parametric provides an array of ProSelection objects representing the geometry references it stored with the analysis. (This means that the Creo TOOLKIT application does not need to save these references between sessionsCreo Parametric uses its own mechanism.)
When the Creo Parametric user leaves the ANALYSIS dialog box without saving the new analysis, or erases a solid containing a toolkit-based analysis:
Callback
Description
infofree
The Creo TOOLKIT application frees the memory used by its internal description of the analysis.
Many of the callbacks will be called during other commands in Creo Parametric whenever the toolkit-based analysis or analysis feature is affected.
Creo Toolkit Analysis Information
Functions Introduced:
The Creo TOOLKIT application must keep its own description of the analysis in memory in order to perform the computation. This memory is allocated, filled, and freed in the callbacks provided, as described in the section Analysis Callbacks.
The callback-calling sequence may vary depending upon exactly what the Creo Parametric user does. This means Creo TOOLKIT applications should not use global variables to pass the “current” analysis from one callback to another.
Instead of such variables, Creo Parametric can store a pointer to the Creo TOOLKIT data stored inside the ProAnalysis object. Use function ProAnalysisTypeGet() to return the type of a specified analysis. The infoalloc callback should end with a call to ProAnalysisInfoSet(), which gives Creo Parametric the pointer to the new description. Every other callback that needs to use this data should call ProAnalysisInfoGet() to get a pointer to the application data for the analysis object, rather than assume this by context.
Creo Parametric cannot access the user data, nor can it provide general storage of this data in the Creo Parametric file when the solid is saved. As explained in the section Analysis Callbacks earlier, the callbacks infosave and inforetrieve respectively give to Creo Parametric, and return after retrieval, geometry references contained in the information; double values can be stored as dimensions. Note that any other information the application needs to store should be saved and retrieved inside infosave and inforetrieve using Creo TOOLKIT external data.
Results Data
This section describes in more detail the data given to Creo Parametric by the Creo TOOLKIT application as the output from the results callback.
The output consists of two arrays, one for the feature parameters, the other for the feature geometry. Each of these is a ProArray allocated by Creo Parametric before calling the callback.
The structure for a feature parameter is:
typedef struct analysis_param
{
    ProName       name;
    ProBoolean    create;
    ProLine       description;
    ProParamvalue *values;
} ProAnalysisParameter;
The name is that of the feature parameter that will be created. The create flag shows the default setting of the Create option for the parameter in the ANALYSIS dialog box. The description appears alongside the parameter in the ANALYSIS dialog box. The array of values should have only a single item in it in the current release. The structure ProParamvalue is the same one used for accessing user parameters through the functions in ProParameter.h and ProParamvalue.h. The value type must be “double” in the current release.
The structure for a geometry item is:
typedef struct analysis_geom
{
    ProName name;
    ProBoolean create;
    ProAnalysisEntityType type;
    ProAnalysisEntity *shapes;
} ProAnalysisGeomitem;
The name is given to the resulting datum (NOT to the feature), but with a numerical suffix to ensure that the name is unique in the Creo Parametric model. The create flag is exactly as for parameters.
The entity type is an enum which is a subset of the object types in ProType. The types supported by this release are:
PRO_ANALYSIS_CURVE
Curve
PRO_ANALYSIS_CSYS
Coord csys
PRO_ANALYSIS_POINT
Datum point
PRO_ANALYSIS_COMP_CRV
Composite curve
PRO_ANALYSIS_SURFACE
Surface
Array “shapes” contains any number of geometric entities of the same type. The union that represents an entity shape is:
typedef union
{
    ProAnalysisSrfData    *surface;
    ProQuiltdata          *quilt;
    ProCurvedata          *curve;
    ProCsysdata           csys;
} ProAnalysisEntity;
The fields in this union all have types that are generic geometry types in Creo TOOLKIT, and are declared in the appropriate headers: ProSurfacedata.h, ProQuiltdata.h, ProCurvedata.h, ProCsysdata.h, ProEdgedata.h. The first three fields, although they are pointers, are not opaque: in spawn mode or asynchronous mode they point to memory in the Creo TOOLKIT process, not in the Creo Parametric process. It is recommended that you build these structures using the functions in the corresponding header files, for example, ProCurvedataAlloc(), ProLinedataInit(), and so on.
ProAnalysisSrfData Structure
The ProAnalysisSrfData structure is used to define a datum surface from a toolkit-based analysis feature. This structure consists of:
typedef struct  ProAnalysisSrfData
{
      ProEdgedata    *edge_data;
      ProSurfacedata *pro_surface;
} ProAnalysisSrfData;
The ProSurfacedata* structure contains the surface shape, parameters, and a populated ProContourdata structure referencing the boundary edges. The ProEdgedata* member should be a ProArray of edge geometric data whose ids are referenced by the contour data in the surface data structure.
Function Introduced:
The function ProAnalysissrfdataAlloc() allocates the ProAnalysisSrfData data structure.
Example 1: Offset Coordinate System Datum
The sample code in the file UgExtAnalysisSurfcsys.c located at <creo_toolkit_loadpoint>/protk_appls/pt_userguide/ptu_ext_analysis shows a Creo TOOLKIT application that defines a toolkit-based analysis that builds a coordinate system datum at an offset from a surface point. The Z axis can be an inward or an outward normal to the surface, the X and Y axes are aligned with the UV mesh lines in the surface, and the origin can be offset in the Z direction. The offset value is stored as a feature dimension.
Analysis Attributes
Functions Introduced:
These functions allow you to get and set certain attributes on a toolkit-based analysis. The only attribute defined in the current release is PROANALYSIS_COMPUTE_OFF. If this is set, the compute and result callbacks will not be called during regeneration of the model. If the toolkit-based analysis belongs to a feature, the geometry of the feature will be frozen until the PROANALYSIS_COMPUTE_OFF is unset again. If the feature geometry includes a surface curve, the 3D location of the curve will be recalculated during regeneration in accordance with the existing UV curves definition but using the new geometry of the surface. This means the curve remains in the surface even if the surface moves while COMPUTE_OFF is TRUE.
Use the PROANALYSIS_COMPUTE_OFF attribute to temporarily turn off the toolkit-based analysis to save time when making other changes to the model.
Visiting Saved Toolkit-Based Analyses
Functions Introduced:
The function ProSolidAnalysisVisit() visits a saved toolkit-based analysis in a part or assembly. It does not visit standard saved analyses, nor toolkit-based analyses in features.
The function ProAnalysisNameGet() provides the name under which a toolkit-based analysis is saved.
Visiting Toolkit-Based Analyses Features
Functions Introduced:
To visit analyses in analysis features, use ProSolidFeatureVisit(), filter for features whose type is PRO_FEAT_ANALYSIS, and call ProFeatureAnalysisGet() on each feature.
Using the Model without Creo Toolkit
If a model contains external analyses or external analysis features of a type defined by a Creo TOOLKIT application, and that model is retrieved into Creo Parametric while the Creo TOOLKIT application is not running, Creo Parametric will not attempt to recompute those analyses during regeneration. Saved toolkit-based analyses will retain their old values, and toolkit-based analysis features will have their geometry frozen.
If a Creo TOOLKIT application is terminated during a Creo Parametric session, any toolkit-based analysis types it registered will be automatically deregistered, and any analyses that use those types will be frozen.