#include <mil.h>
#include "MetrologyAlignment.h"
static const MIL_INT NB_FEATURE_TO_DRAW = 2;
static MIL_CONST_TEXT_PTR FEATURES_TO_DRAW[NB_FEATURE_TO_DRAW] =
{
MIL_TEXT("InnerCircle"),
MIL_TEXT("OuterCircle")
};
static const MIL_INT NB_TOLERANCE_TO_DRAW = 1;
static MIL_CONST_TEXT_PTR TOLERANCES_TO_DRAW[NB_TOLERANCE_TO_DRAW] =
{
MIL_TEXT("Concentricity"),
};
CMetrologyAlignment::CMetrologyAlignment(MIL_CONST_TEXT_PTR MetContextPath, MIL_INT ColorConversion , CInspectionTask* FixtureProvider , CInspectionTask* ImageProvider )
: CMetInspectionTask(MetContextPath, ColorConversion, FixtureProvider, ImageProvider)
{
}
CMetrologyAlignment::~CMetrologyAlignment()
{
}
bool CMetrologyAlignment::Calculate(MIL_ID MilImage)
{
if(CMetInspectionTask::Calculate(MilImage))
{
MIL_INT Label;
MmetName(MilContext(), M_GET_FEATURE_LABEL, M_DEFAULT, const_cast<MIL_TEXT_PTR>(MIL_TEXT("InnerCircle")), &Label, M_DEFAULT);
MIL_INT Status;
MmetGetResult(MilResult(), M_FEATURE_LABEL(Label), M_STATUS + M_TYPE_MIL_INT, &Status);
if(Status == M_PASS)
return true;
else
return false;
}
return false;
}
void CMetrologyAlignment::SetFixture()
{
MIL_INT Label;
MmetName(MilContext(), M_GET_FEATURE_LABEL, M_DEFAULT, const_cast<MIL_TEXT_PTR>(MIL_TEXT("InnerCircle")), &Label, M_DEFAULT);
MIL_DOUBLE CenterX, CenterY;
MmetGetResult(MilResult(), M_FEATURE_LABEL(Label), M_POSITION_X, &CenterX);
MmetGetResult(MilResult(), M_FEATURE_LABEL(Label), M_POSITION_Y, &CenterY);
SetOutputFixture(M_POINT_AND_ANGLE, M_NULL, M_DEFAULT, CenterX, CenterY, 0.0, M_DEFAULT);
}
void CMetrologyAlignment::DrawGraphicalResult(MIL_ID MilGraContext, MIL_ID MilDest)
{
for(MIL_INT FeatureIdx = 0; FeatureIdx < NB_FEATURE_TO_DRAW; FeatureIdx++)
CMetInspectionTask::DrawFeatureByName(MilGraContext, FEATURES_TO_DRAW[FeatureIdx], MilDest, M_RGB888(64, 0, 128));
for(MIL_INT ToleranceIdx = 0; ToleranceIdx < NB_TOLERANCE_TO_DRAW; ToleranceIdx++)
CMetInspectionTask::DrawToleranceByName(MilGraContext, TOLERANCES_TO_DRAW[ToleranceIdx], MilDest, M_COLOR_DARK_GREEN, M_COLOR_DARK_RED, M_COLOR_DARK_YELLOW);
}
void CMetrologyAlignment::DrawTextResult(MIL_ID MilGraContext, MIL_ID MilDest)
{
if(GetResultStatus() == eUnknown)
{
MgraColor(MilGraContext, M_COLOR_YELLOW);
MgraText(MilGraContext, MilDest, 0, 0, MIL_TEXT("Lid metrology: UNKNOWN"));
}
else
{
if(IsResultValid())
{
switch(GetOverallStatus())
{
case M_PASS:
MgraColor(MilGraContext, M_COLOR_GREEN);
MgraText(MilGraContext, MilDest, 0, 0, MIL_TEXT("Lid metrology: PASS"));
break;
case M_WARNING:
MgraColor(MilGraContext, M_COLOR_YELLOW);
MgraText(MilGraContext, MilDest, 0, 0, MIL_TEXT("Lid metrology: WARNING"));
break;
default:
case M_FAIL:
MgraColor(MilGraContext, M_COLOR_RED);
MgraText(MilGraContext, MilDest, 0, 0, MIL_TEXT("Lid metrology: FAIL"));
break;
}
}
else
{
MgraColor(MilGraContext, M_COLOR_RED);
MgraText(MilGraContext, MilDest, 0, 0, MIL_TEXT("Lid metrology: FAIL"));
}
}
MoveGraphicContextYOffset(MilGraContext, 1);
}