<< Click to Display Table of Contents >> Navigation: User DLLs > Writing DLLs > Samples > ex_tole |
// 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
}
}