#include <mil.h>
#include <math.h>
#include "LabelAlignmentInspection.h"
CLabelAlignmentInspection::CLabelAlignmentInspection(MIL_CONST_TEXT_PTR MeasContextPath, MIL_DOUBLE AngleTolerance, MIL_DOUBLE ExpectedPosY, MIL_DOUBLE PosYTolerance, MIL_INT ColorConversion , CInspectionTask* FixtureProvider , CInspectionTask* ImageProvider )
: CMeasInspectionTask(MeasContextPath, ColorConversion, FixtureProvider, ImageProvider),
m_AngleTolerance(AngleTolerance),
m_PosYTolerance(PosYTolerance),
m_ExpectedPosY(ExpectedPosY)
{
}
CLabelAlignmentInspection::~CLabelAlignmentInspection()
{
}
bool CLabelAlignmentInspection::Calculate(MIL_ID MilImage)
{
if(CMeasInspectionTask::Calculate(MilImage))
{
MmeasGetResult(MilResult(), M_ANGLE, &m_Angle, M_NULL);
MmeasGetResult(MilResult(), M_POSITION, &m_PosX, &m_PosY);
PutAngleBetweenMinus180And180(m_Angle);
return true;
}
return false;
}
void CLabelAlignmentInspection::SetFixture()
{
MIL_DOUBLE LineB, LineC;
MmeasGetResult(MilResult(), M_LINE_B, &LineB, M_NULL);
MmeasGetResult(MilResult(), M_LINE_C, &LineC, M_NULL);
SetOutputFixture(M_POINT_AND_ANGLE, M_NULL, M_DEFAULT, 0, -LineC/LineB, m_Angle, M_DEFAULT);
}
void CLabelAlignmentInspection::DrawTextResult(MIL_ID MilGraContext, MIL_ID MilDest)
{
MIL_DOUBLE PosYDiff = fabs(m_PosY - m_ExpectedPosY);
MIL_DOUBLE AngleDiff = fabs(m_Angle);
if(GetResultStatus() == eUnknown)
{
MgraColor(MilGraContext, M_COLOR_YELLOW);
MgraText(MilGraContext, MilDest, 0, 0, MIL_TEXT("Label alignment: UNKNOWN"));
}
else
{
if(IsResultValid() &&
(AngleDiff <= m_AngleTolerance) &&
(PosYDiff <= m_PosYTolerance))
{
MgraColor(MilGraContext, M_COLOR_GREEN);
MgraText(MilGraContext, MilDest, 0, 0, MIL_TEXT("Label alignment: PASS"));
}
else
{
MgraColor(MilGraContext, M_COLOR_RED);
MgraText(MilGraContext, MilDest, 0, 0, MIL_TEXT("Label alignment: FAIL"));
}
}
MoveGraphicContextYOffset(MilGraContext, 1);
}
void CLabelAlignmentInspection::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);
}