/*************************************************************************\
* "$RCSfile: CCamFeatures.cpp,v $"                                        *
***************************************************************************
* Information by CVS or VSS:                                              *
*     Last check in on: $Date: 2009/11/25 16:29:13 $                      *
*     by                $Author: schluckebier $
*     Revision        : $Revision: 1.3 $                                 *
\*************************************************************************/
/*! \file CCamFeatures.cpp
*	\brief Implementation CCamFeatures Class
**************************************************************************/

#include "VIC_PS.h"
#include "CFeature.hpp"
#include "CCamFeatures.hpp"
#include "CRegion.h"
#include "CLog.hpp"
#include "CPSApp.hpp"
#include "CDlg.hpp"
#include "CDlgCam.hpp"

CCamFeatures *CCamFeatures::m_pThis = NULL;	//!< The one and only CCamFeatures instance

/*************************************************************************/
CCamFeatures::CCamFeatures()
/*************************************************************************/
/*! @brief Constructor.

	Creates a list of all camera features.
**************************************************************************/
{
	int FeatPos = 0;

	// Exposure
	m_pExposureTime = new CFeature("ExposureTime", true, false);
	m_FeatList[FeatPos++] = m_pExposureTime;
	m_pFrameTime = new CFeature("FrameTime", true, false);
	m_FeatList[FeatPos++] = m_pFrameTime;
	m_pTriggerCFR = new CFeature("Trigger.CFR", true, false);
	m_FeatList[FeatPos++] = m_pTriggerCFR;

	// Window settings
	m_pWindowX = new CFeatureWindow("Window.X", false, false);
	m_FeatList[FeatPos++] = m_pWindowX;
	m_pWindowY = new CFeatureWindow("Window.Y", false, false);
	m_FeatList[FeatPos++] = m_pWindowY;
	m_pWindowW = new CFeatureWindow("Window.W", false, false);
	m_FeatList[FeatPos++] = m_pWindowW;
	m_pWindowH = new CFeatureWindow("Window.H", false, false);
	m_FeatList[FeatPos++] = m_pWindowH;
	m_pDecimationY = new CFeatureWindow("Decimation.Y", false, false);
	m_FeatList[FeatPos++] = m_pDecimationY;
	m_pMROIEnable = new CFeatureWindow("MROI.Enable", false, false);
	m_FeatList[FeatPos++] = m_pMROIEnable;
	m_pMROIIndex = new CFeature("MROI.Index", true, false);
	m_FeatList[FeatPos++] = m_pMROIIndex;
	m_pMROIY = new CFeature("MROI.Y", true, false);
	m_FeatList[FeatPos++] = m_pMROIY;
	m_pMROIH = new CFeature("MROI.H", true, false);
	m_FeatList[FeatPos++] = m_pMROIH;
	m_pMROIHtot = new CFeature("MROI.Htot", true, false);
	m_FeatList[FeatPos++] = m_pMROIHtot;

	//LineScan
	m_pLineCamMode = new CFeature("LineCamMode", false, true);
	m_FeatList[FeatPos++] = m_pLineCamMode;
	m_pLSImageHeight = new CFeature("LSImageHeight", false, true);
	m_FeatList[FeatPos++] = m_pLSImageHeight;

	m_pEnLinescanHighSpeedMode = new CFeatureWindow("EnLinescanHighSpeedMode", false, false);
	m_FeatList[FeatPos++] = m_pEnLinescanHighSpeedMode;
	m_pFrameCombineEnable = new CFeatureWindow("FrameCombine.Enable", false, false);
	m_FeatList[FeatPos++] = m_pFrameCombineEnable;
	m_pFrameCombineNrOfFrames = new CFeatureWindow("FrameCombine.NrOfFrames", false, false);
	m_FeatList[FeatPos++] = m_pFrameCombineNrOfFrames;
	m_pFrameCombineTimeout = new CFeature("FrameCombine.Timeout", true, false);
	m_FeatList[FeatPos++] = m_pFrameCombineTimeout;
	m_pFrameCombineForceTimeout = new CFeature("FrameCombine.ForceTimeout", true, false);
	m_FeatList[FeatPos++] = m_pFrameCombineForceTimeout;

	// Trigger
	m_pTriggerSource = new CFeatureTrigger("Trigger.Source", false, false);
	m_FeatList[FeatPos++] = m_pTriggerSource;
	m_pTriggerDelay = new CFeature("Trigger.Delay", true, false);
	m_FeatList[FeatPos++] = m_pTriggerDelay;
	m_pTriggerInvert = new CFeature("Trigger.Invert", true, false);
	m_FeatList[FeatPos++] = m_pTriggerInvert;
	m_pTriggerDivisor = new CFeature("FG_TriggerDivisor", false, true);
	m_FeatList[FeatPos++] = m_pTriggerDivisor;
	m_pTriggerLevelControlled = new CFeature("Trigger.LevelControlled", true, false);
	m_FeatList[FeatPos++] = m_pTriggerLevelControlled;
	m_pStrobeOutput = new CFeature("FG_StrobeOutput", false, true);
	m_FeatList[FeatPos++] = m_pStrobeOutput;
	m_pStrobeDelay = new CFeature("Strobe.Delay", true, false);
	m_FeatList[FeatPos++] = m_pStrobeDelay;
	m_pStrobePulseWidth = new CFeature("Strobe.PulseWidth", true, false);
	m_FeatList[FeatPos++] = m_pStrobePulseWidth;
	m_pStrobeInvert = new CFeature("Strobe.Invert", true, false);
	m_FeatList[FeatPos++] = m_pStrobeInvert;

	// Data mode
	m_pDataOutMode = new CFeature("DataOutMode", true, false);
	m_FeatList[FeatPos++] = m_pDataOutMode;
	m_pDataResolution = new CFeatureResolution("DataResolution", false, false);
	m_FeatList[FeatPos++] = m_pDataResolution;
	m_pDigitalGain = new CFeature("DigitalGain", true, false);
	m_FeatList[FeatPos++] = m_pDigitalGain;
	m_pAnalogGain = new CFeature("AnalogGain", true, false);
	m_FeatList[FeatPos++] = m_pAnalogGain;
	m_pFlipImage = new CFeature("FlipImage", true, false);
	m_FeatList[FeatPos++] = m_pFlipImage;
	m_pDigitalOffset = new CFeature("DigitalOffset", true, false);
	m_FeatList[FeatPos++] = m_pDigitalOffset;
	m_pFineGain = new CFeature("FineGain", true, false);
	m_FeatList[FeatPos++] = m_pFineGain;

	// LUT
	m_pLUTMode = new CFeature("LUT.Mode", true, false);
	m_FeatList[FeatPos++] = m_pLUTMode;
	m_pLUTValue = new CFeature("LUT.Value", true, false);
	m_FeatList[FeatPos++] = m_pLUTValue;
	m_pLUTFileRead1 = new CFeature("LUT.FileRead1", true, false);
	m_FeatList[FeatPos++] = m_pLUTFileRead1;
	m_pLUTFileSave1 = new CFeature("LUT.FileSave1", true, false);
	m_FeatList[FeatPos++] = m_pLUTFileSave1;
	m_pLUT0Enable = new CFeature("LUT0.Enable", true, false);
	m_FeatList[FeatPos++] = m_pLUT0Enable;
	m_pLUT0Mode = new CFeature("LUT0.Mode", true, false);
	m_FeatList[FeatPos++] = m_pLUT0Mode;
	m_pLUT0Value = new CFeature("LUT0.Value", true, false);
	m_FeatList[FeatPos++] = m_pLUT0Value;
	m_pLUT1Enable = new CFeature("LUT1.Enable", true, false);
	m_FeatList[FeatPos++] = m_pLUT1Enable;
	m_pLUT1Mode = new CFeature("LUT1.Mode", true, false);
	m_FeatList[FeatPos++] = m_pLUT1Mode;
	m_pLUT1Value = new CFeature("LUT1.Value", true, false);
	m_FeatList[FeatPos++] = m_pLUT1Value;
	m_pLUTIndex = new CFeature("LUT.Index", true, false);
	m_FeatList[FeatPos++] = m_pLUTIndex;
	m_pLUTEnRegionLUT = new CFeature("LUT.EnRegionLUT", true, false);
	m_FeatList[FeatPos++] = m_pLUTEnRegionLUT;
	m_pLUT0X = new CFeature("LUT0.X", true, false);
	m_FeatList[FeatPos++] = m_pLUT0X;
	m_pLUT0W = new CFeature("LUT0.W", true, false);
	m_FeatList[FeatPos++] = m_pLUT0W;
	m_pLUT0Y = new CFeature("LUT0.Y", true, false);
	m_FeatList[FeatPos++] = m_pLUT0Y;
	m_pLUT0H = new CFeature("LUT0.H", true, false);
	m_FeatList[FeatPos++] = m_pLUT0H;
	m_pLUT0Max = new CFeature("LUT0.Max", true, false);
	m_FeatList[FeatPos++] = m_pLUT0Max;
	m_pLUT1X = new CFeature("LUT1.X", true, false);
	m_FeatList[FeatPos++] = m_pLUT1X;
	m_pLUT1W = new CFeature("LUT1.W", true, false);
	m_FeatList[FeatPos++] = m_pLUT1W;
	m_pLUT1Y = new CFeature("LUT1.Y", true, false);
	m_FeatList[FeatPos++] = m_pLUT1Y;
	m_pLUT1H = new CFeature("LUT1.H", true, false);
	m_FeatList[FeatPos++] = m_pLUT1H;
	m_pLUT1Max = new CFeature("LUT1.Max", true, false);
	m_FeatList[FeatPos++] = m_pLUT1Max;
	// Characteristics
	m_pLinlogMode = new CFeature("LinLog.Mode", true, false);
	m_FeatList[FeatPos++] = m_pLinlogMode;
	m_pLinlogValue1 = new CFeature("LinLog.Value1", true, false);
	m_FeatList[FeatPos++] = m_pLinlogValue1;
	m_pLinlogValue2 = new CFeature("LinLog.Value2", true, false);
	m_FeatList[FeatPos++] = m_pLinlogValue2;
	m_pLinlogTime1 = new CFeature("LinLog.Time1", true, false);
	m_FeatList[FeatPos++] = m_pLinlogTime1;
	m_pLinlogTime2 = new CFeature("LinLog.Time2", true, false);
	m_FeatList[FeatPos++] = m_pLinlogTime2;
	m_pSkim = new CFeature("Skim", true, false);
	m_FeatList[FeatPos++] = m_pSkim;

	m_pMultislopeMode = new CFeature("Multislope.Mode", true, false);
	m_FeatList[FeatPos++] = m_pMultislopeMode;
	m_pMultislopeNrSlopes = new CFeature("Multislope.NrSlopes", true, false);
	m_FeatList[FeatPos++] = m_pMultislopeNrSlopes;
	m_pMultislopeValue1 = new CFeature("Multislope.Value1", true, false);
	m_FeatList[FeatPos++] = m_pMultislopeValue1;
	m_pMultislopeValue2 = new CFeature("Multislope.Value2", true, false);
	m_FeatList[FeatPos++] = m_pMultislopeValue2;
	m_pMultislopeTime1 = new CFeature("Multislope.Time1", true, false);
	m_FeatList[FeatPos++] = m_pMultislopeTime1;
	m_pMultislopeTime2 = new CFeature("Multislope.Time2", true, false);
	m_FeatList[FeatPos++] = m_pMultislopeTime2;

	m_pBlacklevelOffset = new CFeature("Voltages.BlackLevelOffset", true, false);
	m_FeatList[FeatPos++] = m_pBlacklevelOffset;
	m_pTriggerInterleave = new CFeature("Trigger.Interleave", true, false);
	m_FeatList[FeatPos++] = m_pTriggerInterleave;

	// Convolver
	m_pConvolverEnable = new CFeature("Convolver_3x3_0.Enable", true, false);
	m_FeatList[FeatPos++] = m_pConvolverEnable;
	m_pConvolverPresets = new CFeature("Convolver_3x3_0.Presets", true, false);
	m_FeatList[FeatPos++] = m_pConvolverPresets;
	m_pConvolverOffset = new CFeature("Convolver_3x3_0.Offset", true, false);
	m_FeatList[FeatPos++] = m_pConvolverOffset;
	m_pConvolverScale = new CFeature("Convolver_3x3_0.Scale", true, false);
	m_FeatList[FeatPos++] = m_pConvolverScale;
	m_pConvolverCoeff0 = new CFeature("Convolver_3x3_0.Coeff0", true, false);
	m_FeatList[FeatPos++] = m_pConvolverCoeff0;
	m_pConvolverCoeff1 = new CFeature("Convolver_3x3_0.Coeff1", true, false);
	m_FeatList[FeatPos++] = m_pConvolverCoeff1;
	m_pConvolverCoeff2 = new CFeature("Convolver_3x3_0.Coeff2", true, false);
	m_FeatList[FeatPos++] = m_pConvolverCoeff2;
	m_pConvolverCoeff3 = new CFeature("Convolver_3x3_0.Coeff3", true, false);
	m_FeatList[FeatPos++] = m_pConvolverCoeff3;
	m_pConvolverCoeff4 = new CFeature("Convolver_3x3_0.Coeff4", true, false);
	m_FeatList[FeatPos++] = m_pConvolverCoeff4;
	m_pConvolverCoeff5 = new CFeature("Convolver_3x3_0.Coeff5", true, false);
	m_FeatList[FeatPos++] = m_pConvolverCoeff5;
	m_pConvolverCoeff6 = new CFeature("Convolver_3x3_0.Coeff6", true, false);
	m_FeatList[FeatPos++] = m_pConvolverCoeff6;
	m_pConvolverCoeff7 = new CFeature("Convolver_3x3_0.Coeff7", true, false);
	m_FeatList[FeatPos++] = m_pConvolverCoeff7;
	m_pConvolverCoeff8 = new CFeature("Convolver_3x3_0.Coeff8", true, false);
	m_FeatList[FeatPos++] = m_pConvolverCoeff8;

	// Correction
	m_pCorrectionMode = new CFeature("Correction.Mode", true, false);
	m_FeatList[FeatPos++] = m_pCorrectionMode;
	m_pCorrectionValidationBlack = new CFeature("Correction.ValidationBlack", true, false);
	m_FeatList[FeatPos++] = m_pCorrectionValidationBlack;
	m_pCorrectionSetBlackRef = new CFeature("Correction.SetBlackRef", true, false);
	m_FeatList[FeatPos++] = m_pCorrectionSetBlackRef;
	m_pCorrectionValidationGrey = new CFeature("Correction.ValidationGrey", true, false);
	m_FeatList[FeatPos++] = m_pCorrectionValidationGrey;
	m_pCorrectionSetGreyRef = new CFeature("Correction.SetGreyRef", true, false);
	m_FeatList[FeatPos++] = m_pCorrectionSetGreyRef;
	m_pCorrectionCalculate = new CFeature("Correction.Calculate", true, false);
	m_FeatList[FeatPos++] = m_pCorrectionCalculate;
	m_pCorrectionSaveToFlash = new CFeature("Correction.SaveToFlash", true, false);
	m_FeatList[FeatPos++] = m_pCorrectionSaveToFlash;
	m_pColCorrectionEnable = new CFeature("ColCorrection.Enable", true, false);
	m_FeatList[FeatPos++] = m_pColCorrectionEnable;
	m_pColCorrectionCalculate = new CFeature("ColCorrection.Calculate", true, false);
	m_FeatList[FeatPos++] = m_pColCorrectionCalculate;
	m_pColCorrectionSaveToFlash = new CFeature("ColCorrection.SaveToFlash", true, false);
	m_FeatList[FeatPos++] = m_pColCorrectionSaveToFlash;

	// Info
	m_pInfoTypecode = new CFeature("Info.Typecode", true, false);
	m_FeatList[FeatPos++] = m_pInfoTypecode;
	m_pInfoSerial = new CFeature("Info.Serial", true, false);
	m_FeatList[FeatPos++] = m_pInfoSerial;
	m_pInfoFPGASensor = new CFeature("Info.FPGASensor", true, false);
	m_FeatList[FeatPos++] = m_pInfoFPGASensor;
	m_pInfoFPGAAdc = new CFeature("Info.FPGAAdc", true, false);
	m_FeatList[FeatPos++] = m_pInfoFPGAAdc;
	m_pInfouC = new CFeature("Info.uC", true, false);
	m_FeatList[FeatPos++] = m_pInfouC;

	m_pStoreDefaults = new CFeature("StoreDefaults", true, false);
	m_FeatList[FeatPos++] = m_pStoreDefaults;
	m_pFactoryReset = new CFeature("FactoryReset", true, false);
	m_FeatList[FeatPos++] = m_pFactoryReset;
	m_pAverageValue = new CFeature("Average.Value", true, false);
	m_FeatList[FeatPos++] = m_pAverageValue;

	m_pStatusLine = new CFeature("EnStatusLine", true, false);
	m_FeatList[FeatPos++] = m_pStatusLine;
	m_pCameraName = new CFeature("CameraName", true, false);
	m_FeatList[FeatPos++] = m_pCameraName;

	// IMAGO serialNo, serial of DSP-module and Altera FPGA
	m_pPSCSerial = new CFeature("PSCSerial", false, true);
	m_FeatList[FeatPos++] = m_pPSCSerial;
	m_pDSPModuleSerial = new CFeature("DSPModuleSerial", false, true);
	m_FeatList[FeatPos++] = m_pDSPModuleSerial;
	m_pAlteraFPGA = new CFeature("AlteraFPGA", false, true);
	m_FeatList[FeatPos++] = m_pAlteraFPGA;
	m_pMacAddr = new CFeature("MACAddress", false, true);
	m_FeatList[FeatPos++] = m_pMacAddr;

	// End of list
	m_FeatList[FeatPos] = NULL;

	m_pDataResolution->CalcCameraModel();
}

/*************************************************************************/
CCamFeatures::~CCamFeatures()
/*************************************************************************/
/*! @brief Destructor.
**************************************************************************/
{
	int i = 0;

	while (m_FeatList[i])
	{
		delete m_FeatList[i];
		i++;
	}
}

/*************************************************************************/
CCamFeatures *CCamFeatures::CreateInstance()
/*************************************************************************/
/*! @brief Creates CCamFeatures instance.
	@return Pointer to CCamFeatures instance
**************************************************************************/
{
	if (m_pThis == NULL)
		m_pThis = new CCamFeatures();
	return m_pThis;
}

/*************************************************************************/
void CCamFeatures::DisposeInstance()
/*************************************************************************/
/*! @brief Disposes CCamFeatures instance.
**************************************************************************/
{
	if (m_pThis)
		delete m_pThis;
	m_pThis = NULL;
}

/*************************************************************************/
void CCamFeatures::UpdateAllFeatures()
/*************************************************************************/
/*! @brief Updates all features with its event from current to the camera.
	
	Each feature will be updated with its value in current preset to the
	camera, which means value is written to camera and read from camera.
**************************************************************************/
{
	CPSApp *pApp = CPSApp::GetInstance();
	const bool RestartGrabtask = pApp->IsGrabTaskActive();
	Config *pCI = pApp->GetCurrentIni();

	if (RestartGrabtask)
		pApp->StopGrabTask();

	// Window settings
	m_pWindowX->UpdateValue(pCI);
	m_pWindowW->UpdateValue(pCI);
	m_pWindowY->UpdateValue(pCI);
	m_pWindowH->UpdateValue(pCI);
	m_pDecimationY->UpdateValue(pCI);
	m_pMROIEnable->UpdateValue(pCI);
	m_pMROIIndex->UpdateValue(pCI);
	m_pMROIY->UpdateValue(pCI);
	m_pMROIH->UpdateValue(pCI);
	m_pLSImageHeight->UpdateValue(pCI);

	m_pLineCamMode->UpdateValue(pCI);
	if (m_pLineCamMode->m_Value)
	{
		pApp->m_CamReg.m_Height = m_pLSImageHeight->m_Value;// 1024;//CamHeight;
		m_pWindowH->m_bInactive = true;
		m_pLSImageHeight->m_bInactive = false;
	}
	else
	{
		m_pWindowH->m_bInactive = false;
		m_pLSImageHeight->m_bInactive = true;
	}
	// Linescan
	m_pEnLinescanHighSpeedMode->UpdateValue(pCI);
	m_pFrameCombineEnable->UpdateValue(pCI);
	m_pFrameCombineNrOfFrames->UpdateValue(pCI);
	m_pFrameCombineTimeout->UpdateValue(pCI);

	// Exposure
	m_pTriggerCFR->UpdateValue(pCI);
	m_pExposureTime->UpdateValue(pCI);
	m_pFrameTime->UpdateValue(pCI);
	m_pFrameTime->m_bInactive = (m_pTriggerCFR->m_Value) ? false : true;

	// Trigger
	m_pTriggerSource->UpdateValue(pCI);
	m_pTriggerDelay->UpdateValue(pCI);
	m_pTriggerInvert->UpdateValue(pCI);
	m_pTriggerLevelControlled->UpdateValue(pCI);
	m_pTriggerInterleave->UpdateValue(pCI);
	m_pTriggerDivisor->UpdateValue(pCI);
	m_pStrobeInvert->UpdateValue(pCI);
	m_pStrobeOutput->UpdateValue(pCI);
	m_pStrobeDelay->UpdateValue(pCI);
	m_pStrobePulseWidth->UpdateValue(pCI);

	// Data mode
	m_pDataOutMode->UpdateValue(pCI);
	m_pDataResolution->UpdateValue(pCI);
	m_pDigitalGain->UpdateValue(pCI);
	m_pAnalogGain->UpdateValue(pCI);
	m_pDigitalOffset->UpdateValue(pCI);
	m_pFineGain->UpdateValue(pCI);
	m_pFlipImage->UpdateValue(pCI);

	//LUT
	m_pLUTMode->UpdateValue(pCI);
	m_pLUT0Enable->UpdateValue(pCI);
	m_pLUT0Mode->UpdateValue(pCI);
	m_pLUT1Enable->UpdateValue(pCI);
	m_pLUT1Mode->UpdateValue(pCI);
	m_pLUTIndex->UpdateValue(pCI);
	m_pLUTEnRegionLUT->UpdateValue(pCI);
	m_pLUT0X->UpdateValue(pCI);
	m_pLUT0W->UpdateValue(pCI);
	m_pLUT0Y->UpdateValue(pCI);
	m_pLUT0H->UpdateValue(pCI);
	m_pLUT1X->UpdateValue(pCI);
	m_pLUT1W->UpdateValue(pCI);
	m_pLUT1Y->UpdateValue(pCI);
	m_pLUT1H->UpdateValue(pCI);

	// Convolver
	m_pConvolverEnable->UpdateValue(pCI);
	m_pConvolverOffset->UpdateValue(pCI);
	m_pConvolverScale->UpdateValue(pCI);
	m_pConvolverCoeff0->UpdateValue(pCI);
	m_pConvolverCoeff1->UpdateValue(pCI);
	m_pConvolverCoeff2->UpdateValue(pCI);
	m_pConvolverCoeff3->UpdateValue(pCI);
	m_pConvolverCoeff4->UpdateValue(pCI);
	m_pConvolverCoeff5->UpdateValue(pCI);
	m_pConvolverCoeff6->UpdateValue(pCI);
	m_pConvolverCoeff7->UpdateValue(pCI);
	m_pConvolverCoeff8->UpdateValue(pCI);

	// Characteristics
	m_pLinlogMode->UpdateValue(pCI);
	m_pSkim->UpdateValue(pCI);
	m_pLinlogValue1->UpdateValue(pCI);
	m_pLinlogValue2->UpdateValue(pCI);
	m_pLinlogTime1->UpdateValue(pCI);
	m_pLinlogTime2->UpdateValue(pCI);
	m_pMultislopeMode->UpdateValue(pCI);
	m_pMultislopeNrSlopes->UpdateValue(pCI);
	m_pMultislopeValue1->UpdateValue(pCI);
	m_pMultislopeValue2->UpdateValue(pCI);
	m_pMultislopeTime1->UpdateValue(pCI);
	m_pMultislopeTime2->UpdateValue(pCI);
	m_pBlacklevelOffset->UpdateValue(pCI);

	// Correction
	m_pCorrectionMode->UpdateValue(pCI);
	m_pColCorrectionEnable->UpdateValue(pCI);

	m_pStatusLine->UpdateValue(pCI);

	if (RestartGrabtask)
		pApp->StartGrabTask();
}

/*************************************************************************/
void CCamFeatures::ApplyCamDlg(int Id)
/*************************************************************************/
/*! @brief Apply CDlgCam data to camera.
	@param Id Item Id
**************************************************************************/
{
	CPSApp *pApp = CPSApp::GetInstance();
	const bool RestartGrabtask = pApp->IsGrabTaskActive();
	int CamHeight;
	bool bFlag = true;

	if (RestartGrabtask)
		pApp->StopGrabTask();

	switch (Id)
	{
	// Window
	case CDlgCam::ID_WND_X:
		m_pWindowX->UpdateValue();
		m_pWindowW->Event();
		m_pFrameTime->Event();
		break;
	case CDlgCam::ID_WND_W:
		m_pWindowW->UpdateValue();
		m_pWindowX->Event();
		m_pFrameTime->Event();
		break;
	case CDlgCam::ID_WND_Y:
		m_pWindowY->UpdateValue();
		m_pWindowH->Event();
		m_pFrameTime->Event();
		break;
	case CDlgCam::ID_WND_H:
		m_pWindowH->UpdateValue();
		m_pWindowY->Event();
		m_pFrameTime->Event();
		break;
	case CDlgCam::ID_WND_DECIM:
		m_pDecimationY->UpdateValue();
		m_pFrameTime->Event();
		break;
	case CDlgCam::ID_WND_MROI_Y:
		m_pMROIY->UpdateValue();
		m_pMROIH->Event();
		m_pMROIHtot->Event();
		break;
	case CDlgCam::ID_WND_MROI_H:
		m_pMROIH->UpdateValue();
		m_pMROIHtot->Event();
		break;
	// LineScan
	case CDlgCam::ID_WND_LCMODE:
	case CDlgCam::ID_WND_LSIHEIGHT:
		if (m_pLineCamMode->m_Value)
		{
			m_pLSImageHeight->m_bInactive = false;
			CamHeight = m_pLSImageHeight->GetValue();
			m_pLSImageHeight->UpdateValue();
			m_pMROIEnable->SetValue(0);
			m_pMROIEnable->UpdateValue();
			m_pWindowH->SetValue(1);
			m_pWindowH->UpdateValue();
			m_pWindowH->m_bInactive = true;
			m_pWindowY->SetValue(500);
			m_pWindowY->UpdateValue();
			m_pTriggerCFR->SetValue(1);
			m_pTriggerCFR->UpdateValue();
			if (m_pExposureTime->GetValue() > 1000)
				m_pExposureTime->SetValue(999);
			m_pExposureTime->UpdateValue();
			if (m_pFrameTime->GetValue() > 1000)
				m_pFrameTime->SetValue(999);
			m_pFrameTime->UpdateValue();
		}
		else
		{
			m_pLSImageHeight->m_bInactive = true;
			m_pWindowY->SetValue(0);
			m_pWindowY->UpdateValue();
			m_pWindowH->m_bInactive = false;
			m_pWindowH->SetValue(1024);
			m_pWindowH->UpdateValue();
		}
		m_pMROIIndex->Event();
		m_pWindowY->Event();
		m_pWindowH->Event();
		m_pMROIY->Event();
		m_pMROIH->Event();
		m_pDecimationY->Event();
		m_pFrameTime->Event();
		m_pLineCamMode->SetValue(m_pLineCamMode->m_Value);
		if (m_pLineCamMode->m_Value)
		{
			m_pWindowH->m_bInactive = true;
			pApp->m_CamReg.m_Height = CamHeight;
			pApp->m_CamReg.m_Bottom = pApp->m_CamReg.m_Top+CamHeight;
		}
		else
		{
			m_pWindowH->m_bInactive = false;
		}
		break;
	case CDlgCam::ID_FRAMECOMBINE_NROFFRAMES:
		m_pFrameCombineNrOfFrames->UpdateValue();
		break;
	// Data format
	case CDlgCam::ID_DO_FINEGAINV:
		m_pFineGain->SetValue(m_FineGainV);
		break;
	case CDlgCam::ID_DO_RESOLUTION:
		m_pDataResolution->UpdateValue();
		break;
	// LUT
	case CDlgCam::ID_LUT_VALUE:
		m_pLUTValue->UpdateValue();
		break;
	case CDlgCam::ID_LUT_LUT0_VALUE:
		m_pLUT0Value->UpdateValue();
		break;
	case CDlgCam::ID_LUT_LUT1_VALUE:
		m_pLUT1Value->UpdateValue();
		break;
	case CDlgCam::ID_LUT_LUT0_X:
		m_pLUT0X->UpdateValue();
		m_pLUT0W->Event();
		break;
	case CDlgCam::ID_LUT_LUT0_W:
		m_pLUT0W->UpdateValue();
		m_pLUT0X->Event();
		break;
	case CDlgCam::ID_LUT_LUT0_Y:
		m_pLUT0Y->UpdateValue();
		m_pLUT0H->Event();
		break;
	case CDlgCam::ID_LUT_LUT0_H:
		m_pLUT0H->UpdateValue();
		m_pLUT0Y->Event();
		break;
	case CDlgCam::ID_LUT_LUT1_X:
		m_pLUT1X->UpdateValue();
		m_pLUT1W->Event();
		break;
	case CDlgCam::ID_LUT_LUT1_W:
		m_pLUT1W->UpdateValue();
		m_pLUT1X->Event();
		break;
	case CDlgCam::ID_LUT_LUT1_Y:
		m_pLUT1Y->UpdateValue();
		m_pLUT1H->Event();
		break;
	case CDlgCam::ID_LUT_LUT1_H:
		m_pLUT1H->UpdateValue();
		m_pLUT1Y->Event();
		break;
		// Trigger
	case CDlgCam::ID_TRG_DELAY:
		m_pTriggerDelay->UpdateValue();
		break;
	// Trigger
	case CDlgCam::ID_TRG_DIVISOR:
		m_pTriggerDivisor->UpdateValue();
		break;
	// Strobe
	case CDlgCam::ID_STROBE_DELAY:
		m_pStrobeDelay->UpdateValue();
		break;
	case CDlgCam::ID_STROBE_PULSEW:
		m_pStrobePulseWidth->UpdateValue();
		break;
	// Characteristics
	case CDlgCam::ID_LINLOG_V1:
		m_pLinlogValue1->UpdateValue();
		m_pLinlogValue2->Event();
		m_pSkim->Event();
		break;
	case CDlgCam::ID_LINLOG_V2:
		m_pLinlogValue2->UpdateValue();
		break;
	case CDlgCam::ID_LINLOG_T1:
		m_pLinlogTime1->UpdateValue();
		break;
	case CDlgCam::ID_LINLOG_T2:
		m_pLinlogTime2->UpdateValue();
		m_pLinlogTime1->Event();
		break;
	case CDlgCam::ID_MULTISLOPE_NRSLOPES:
		m_pMultislopeNrSlopes->UpdateValue();
		m_pMultislopeValue2->Event();
		m_pMultislopeTime2->Event();
		break;
	case CDlgCam::ID_MULTISLOPE_V1:
		m_pMultislopeValue1->UpdateValue();
		m_pMultislopeValue2->Event();
		break;
	case CDlgCam::ID_MULTISLOPE_V2:
		m_pMultislopeValue2->UpdateValue();
		break;
	case CDlgCam::ID_MULTISLOPE_T1:
		m_pMultislopeTime1->UpdateValue();
		m_pMultislopeTime2->Event();
		break;
	case CDlgCam::ID_MULTISLOPE_T2:
		m_pMultislopeTime2->UpdateValue();
		break;
	// Exposure
	case CDlgCam::ID_EXPV:
		m_pExposureTime->SetValue(m_ExpV);
		m_pFrameTime->Event();
		break;
	case CDlgCam::ID_EXP_FRAMETV:
		m_pFrameTime->SetValue(m_FrameTV);
		break;
	default:
		bFlag = false;
		break;
	}
	if (bFlag)
		CDlgCam::GetInstance()->Apply();

	if (RestartGrabtask)
		pApp->StartGrabTask();
}

/*************************************************************************/
