Custom Features in OpenVX

 

There are two ways to create custom features from OpenVX.  In both cases, a custom feature with sub-operations is added to the history of the active part.  In the first example, when the custom feature is regenerated, the original sub-operations are replayed.  Geometry created by these operations will regenerate with the same persistent labels so that subsequent operations referencing the geometry will regen reliably.

 

In the second example, when the custom feature is regenerated, the original sub-operations are deleted and new sub-operations are recreated.  In this case, the application must supply a function for re-evaluating the custom feature.  This function must intelligently assign id's to the sub-operations so they generate persistent entity labels consistently from one regen to the next.

 

Example 1

 

  1. Create a command template (MyFeature.t) that defines the input fields for your custom features.   In the template header, set "function=CustomOp" and include the "no_repeat" keyword.
     

  2. Put the template in one of the VX installation directories or a directory referenced by vxpaths (see File > Search Path).
     

  3. Create VDATA (idxData) for the custom feature using VxDataCreate("MyFeature", &idxData).
     

  4. Add the custom feature to the active part using InExec(idxData).
     

  5. Activate the custom feature for addition of sub-operations by calling CdFtrActivate(0,NULL).
     

  6. Use InExec() to execute the sub-operations you want assigned to the active custom feature.    The VDATA's for these sub-operations should link to the input fields of the first custom feature operation using VxLogLink() or using variables defined by CdFldVariable().  
     

  7. When you are done adding sub-operations to the custom feature, call CdFtrActivate(-1,NULL) to end creation of the custom feature.
     

  8. When you "Redefine" the custom feature, you are given the option to change the inputs specified by the original custom feature template (MyFeature.t) after which the sub-operations are regenerated.   If the inputs to the sub-operations are properly linked to the inputs gathered by the custom feature template, everything should regenerate okay.

 

 

Example 2

 

The following command template should be placed in a ".t" file in one of the VX installation directories or a directory referenced by vxpaths (see File > Search Path).  It references an application-supplied function via the "custom" field.   

 

When the command template is executed, it:

 

  1. Gathers user input based on the template and puts the information in a VDATA object (idxInput),

  2. Adds a custom feature operation to the active part history and

  3. Passes the user input (idxData) to the application-supplied function (int function(int idxInput)).   

 

Operations logged by the function using InExec() are automatically added to the custom features as sub-operations.  When the function returns, custom feature creation is deactivated.  When the custom feature is regenerated or redefined, the original sub-operations are cleared and the application-supplied function is called again with the latest input data (idxInput).  The new operations created by the function are added to the original custom feature as sub-operations.  These sub-operations must be stored in the database in order for the persistent labeling strategy to work properly.  The history mechanism relies on reliable persistent labeling.

 

A pointer to the application-supplied function used to evaluate the custom feature must be logged with VX using VxSymLog("function_name",(void*)function_pointer,0.0).  This can be done in VxLibInit().

 

Command Template:

 

TEMPLATE=MakeLines

description=Create lines by connecting point pairs.

function=CustomOp

custom=MakeLines.vxm

no_repeat

 

FIELD=Points

class=point

id=1

prompt=Select points to connect.

list

options=/face/edge/curve/point/,

trigger

 

 

Application Function

 

/**********************************************************

/* PRIVATE */

static int MakeLines (int idxInput)

/*

DESCRIPTION:

Connects point pairs to create line segments.

Returns 1 if error, else 0.

*/

{

int i=0, iPntCnt=0, iErr=0, idxData, id=1;

double *dPntList=NULL;

/* make sure the point count is an even number */

if (iPntCnt%2) --iPntCnt;

/* get point coordinate input */

if (iErr=VxInpPntList(idxInput,1,3,&iPntCnt,&dPntList)) goto F_END;

/* return error if less than four points were entered */

if (iPntCnt < 4)

   {

   InGuiDspMsg("Enter at least four points.");

   iErr=1;

   goto F_END;

   }

/* log a line operation for each successive pair of points */

iPntCnt *= 3;

while (i < iPntCnt)

   {

   /* create the input data object for the "create line" operation */

   if (iErr=VxDataCreate("CdLn2Pts",&idxData)) goto F_END;

   /* load the start and end points into the input data object */

   VxLogPnt(idxData,1,3,&dPntList[i]);

   i += 3;

   VxLogPnt(idxData,2,3,&dPntList[i]);

   i += 3;

   /* specify the integer id of the next operation */

   CdOpId(id++);

   /* execute the "create line" operation */

   if (iErr=InExec(idxData)) goto F_END;

   }

F_END:;

VxMemFree((void**)&dPntList);

return(iErr);

}

 

 

Related Topics

Return to VX CAD/CAM Index