#include <mil.h>
#include <math.h>
#include "CapOrientation.h"
CCapOrientation::CCapOrientation(MIL_CONST_TEXT_PTR MeasMarkerPath,
MIL_DOUBLE ExpectedWidth,
MIL_DOUBLE WidthTolerance,
MIL_INT ColorConversion ,
CInspectionTask* FixtureProvider ,
CInspectionTask* ImageProvider )
: CMeasInspectionTask(MeasMarkerPath, ColorConversion, FixtureProvider, ImageProvider),
m_ExpectedWidth(ExpectedWidth),
m_WidthTolerance(WidthTolerance)
{
}
CCapOrientation::~CCapOrientation()
{
}
bool CCapOrientation::Calculate(MIL_ID MilImage)
{
if(CMeasInspectionTask::Calculate(MilImage))
{
MmeasGetResult(MilResult(), M_STRIPE_WIDTH, &m_Width, M_NULL);
}
return true;
}
void CCapOrientation::DrawTextResult(MIL_ID MilGraContext, MIL_ID MilDest)
{
if(GetResultStatus() == eUnknown)
{
MgraColor(MilGraContext, M_COLOR_YELLOW);
MgraText(MilGraContext, MilDest, 0, 0, MIL_TEXT("Cap orientation: UNKNOWN"));
}
else
{
if(IsResultValid() && fabs(m_ExpectedWidth - m_Width) <= m_WidthTolerance)
{
MgraColor(MilGraContext, M_COLOR_GREEN);
MgraText(MilGraContext, MilDest, 0, 0, MIL_TEXT("Cap orientation: PASS"));
}
else
{
MgraColor(MilGraContext, M_COLOR_RED);
MgraText(MilGraContext, MilDest, 0, 0, MIL_TEXT("Cap orientation: FAIL"));
}
}
MoveGraphicContextYOffset(MilGraContext, 1);
}
void CCapOrientation::DrawGraphicalResult(MIL_ID MilGraContext, MIL_ID MilDest)
{
MgraColor(MilGraContext, M_COLOR_GREEN);
MmeasDraw(MilGraContext, MilResult(), MilDest, M_DRAW_SEARCH_REGION + M_DRAW_SEARCH_DIRECTION, M_DEFAULT, M_RESULT);
MgraColor(MilGraContext, M_COLOR_MAGENTA);
MmeasDraw(MilGraContext, MilResult(), MilDest, M_DRAW_EDGES, M_DEFAULT, M_RESULT);
}