#include <mil.h>
#include "MetrologyInspectionTask.h"
CMetInspectionTask::CMetInspectionTask(MIL_CONST_TEXT_PTR MetContextPath, MIL_INT ColorConversion , CInspectionTask* FixtureProvider , CInspectionTask* ImageProvider )
: CHighLevelInspectionTask(MetContextPath, MmetFree, ColorConversion, FixtureProvider, ImageProvider)
{
}
CMetInspectionTask::~CMetInspectionTask()
{
}
bool CMetInspectionTask::Calculate(MIL_ID MilImage)
{
MmetCalculate(MilContext(), MilImage, MilResult(), M_DEFAULT);
return true;
}
void CMetInspectionTask::DrawGraphicalResult(MIL_ID MilGraContext, MIL_ID MilDest)
{
MgraColor(MilGraContext, M_COLOR_MAGENTA);
MmetDraw(MilGraContext, MilResult(), MilDest, M_DRAW_FEATURE, M_ALL_FEATURES, M_DEFAULT);
MgraColor(MilGraContext, M_COLOR_GREEN);
MmetDraw(MilGraContext, MilResult(), MilDest, M_DRAW_TOLERANCE, M_ALL_PASS_TOLERANCES, M_DEFAULT);
MgraColor(MilGraContext, M_COLOR_RED);
MmetDraw(MilGraContext, MilResult(), MilDest, M_DRAW_TOLERANCE, M_ALL_FAIL_TOLERANCES, M_DEFAULT);
}
void CMetInspectionTask::DrawFeatureByName(MIL_ID MilGraContext, MIL_CONST_TEXT_PTR FeatureName, MIL_ID MilDest, MIL_DOUBLE Color)
{
MIL_INT Label;
MmetName(MilContext(), M_GET_FEATURE_LABEL, M_DEFAULT, const_cast<MIL_TEXT_PTR>(FeatureName), &Label, M_DEFAULT);
if(Label)
{
MgraColor(MilGraContext, Color);
MmetDraw(MilGraContext, MilResult(), MilDest, M_DRAW_FEATURE, M_FEATURE_LABEL(Label), M_DEFAULT);
}
}
void CMetInspectionTask::DrawToleranceByName(MIL_ID MilGraContext, MIL_CONST_TEXT_PTR ToleranceName, MIL_ID MilDest, MIL_DOUBLE PassColor, MIL_DOUBLE FailColor, MIL_DOUBLE WarningColor)
{
MIL_INT Label, Status;
MmetName(MilContext(), M_GET_TOLERANCE_LABEL, M_DEFAULT, const_cast<MIL_TEXT_PTR>(ToleranceName), &Label, M_DEFAULT);
if(Label)
{
MmetGetResult(MilResult(), M_TOLERANCE_LABEL(Label), M_STATUS + M_TYPE_MIL_INT, &Status);
MIL_DOUBLE Color;
switch(Status)
{
case M_PASS : Color = PassColor;
break;
case M_WARNING: Color = WarningColor;
break;
default:
case M_FAIL : Color = FailColor;
break;
}
MgraColor(MilGraContext, Color);
MmetDraw(MilGraContext, MilResult(), MilDest, M_DRAW_TOLERANCE, M_TOLERANCE_LABEL(Label), M_DEFAULT);
}
}
MIL_INT CMetInspectionTask::GetOverallStatus() const
{
MIL_INT FeaturesStatus = M_PASS;
MIL_INT ToleranceStatus = M_PASS;
MIL_INT NbFeatureOrTolerance;
MmetGetResult(MilResult(), M_GENERAL, M_NUMBER_OF_FEATURES + M_TYPE_MIL_INT, &NbFeatureOrTolerance);
if(NbFeatureOrTolerance)
MmetGetResult(MilResult(), M_ALL_FEATURES, M_STATUS + M_TYPE_MIL_INT, &FeaturesStatus);
MmetGetResult(MilResult(), M_GENERAL, M_NUMBER_OF_TOLERANCES + M_TYPE_MIL_INT, &NbFeatureOrTolerance);
if(NbFeatureOrTolerance)
MmetGetResult(MilResult(), M_ALL_TOLERANCES, M_STATUS + M_TYPE_MIL_INT, &ToleranceStatus);
return (FeaturesStatus == M_FAIL || ToleranceStatus == M_FAIL) ? M_FAIL :
((FeaturesStatus == M_WARNING || ToleranceStatus == M_WARNING ? M_WARNING : M_PASS));
}