ex_tole

<< Click to Display Table of Contents >>

Navigation:  User DLLs > Writing DLLs > Samples >

ex_tole

The sample ex_tole.dsp is a Visual C++ project file that provides a simple example of a user-written tolerance routine. By building the DLL module for this project and loading the resulting DLL file into 3DCS, the user-dll GUI for tolerance will show the loaded routine in the user-routines pulldown. The code from the file userfunc.cpp for this project is shown below. The name that will appear in the pulldown for the user-dll tolerance GUI's user-routines will be "Example Tolerance" as defined in the code below. The routine utilizes the wpTOLECAL_s (from dcs_ufnc.h) structure to read the model data and subsequently calculate a point deviation perpendicular to two non-parallel input direction vectors.

 

// dcs headers

#include "dcs_defn.h"

#include "dcs_ufnc.h"

#"userfunc.h"

 

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

/* Implement your tolerance routines here */

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

 

// This is an example tolerance .dll function that deviates points in the direction

// perpendicular to two non-parallel input direction vectors. The random values that

// are passed to this function are computed based on the tolerance distribution and mode.

 

char dcsToleName1[] = "Example Tolerance";

 

char* dcsGetToleFuncName1() { return dcsToleName1;}

 

void userToleFunc1(dcsDataPtr* pDataPtr)

{

wpTOLECAL_s* pTolePtr = (wpTOLECAL_s*)pDataPtr; // tolerance object pointer

if (pTolePtr == wpNULL)

{

dcsApiLogWrite("Example Tolerance Error: **** NULL input\n");

return;

}

 

int dirNum = pTolePtr->m_NumDirVec; // number of direction vectors

if (dirNum < 2)

{

dcsApiLogWrite("Example Tolerance Error: **** Not enough directions\n");

return;

}

 

int ptNum = pTolePtr->m_NumPt3Vec; // number of points

if (ptNum < 1)

{

dcsApiLogWrite("Example Tolerance Error: **** Not enough points\n");

return;

}

 

int ranValNum = tlGlbGetRandomValNum(pTolePtr);//pTolePtr->m_NumRanVal; // number of random values

if (ranValNum < 1)

{

dcsApiLogWrite("Example Tolerance Error: **** Not enough random parameters\n");

return;

}

 

// get direction vectors

wpVEC3D_s dirVec1 = tlGlbGetDirVec(pTolePtr, 0);

wpVEC3D_s dirVec2 = tlGlbGetDirVec(pTolePtr, 1);

 

// get deviation vector

wpVEC3D_s devVec;

 

int retv = wpGlbNormalVec3D(dirVec1, dirVec2, &devVec);

if (retv == 0)

{

dcsApiLogWrite("Example Tolerance Error: **** Parallel input directions\n");

return; // reject parallel direction vectors

}

 

// compute deviations for the tolerances

int ii;

double value;

wpVEC3D_s vec;

 

for (ii = 0; ii < ptNum; ii++)

{

value = tlGlbGetRandomMagVal(pTolePtr, ii); // get random value

vec = devVec; // get deviation vector

wpGlbMultiplyVec3D(&vec, value); // apply random value

 

tlGlbSetDeltaVec(pTolePtr, ii, vec); // pass deviation vector back to 3-Dcs

}

}