/*************************************************************************\
* "$RCSfile: CDlgCam.cpp,v $"                                             *
***************************************************************************
* Information by CVS or VSS:                                              *
*     Last check in on: $Date: 2011/09/07 16:32:43 $                      *
*     by                $Author: goebel $
*     Revision        : $Revision: 1.50 $                                 *
\*************************************************************************/
/*! \file CDlgCam.cpp
*	\brief Implementation CDlgCam Class
**************************************************************************/

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

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

/*************************************************************************/
CDlgCam::CDlgCam(int x, int y, int Width, int Height) : 
	CDlg(x, y, Width, Height, DialogId::CAM)
/*************************************************************************/
/*! @brief Constructor
**************************************************************************/
{
	CCamFeatures *pCF = CCamFeatures::GetInstance();
	int y1;

	GUI_DlgSetTitle(&m_Dlg, m_pStrings->getValue("DlgCamTitle", "Camera Properties"));

	m_FEntries = 0;
	m_DirText = (char*)VIB_MemAlloc(1024 * 8);
	m_SelPreText = (char*)VIB_MemAlloc(1024 * 8);
	m_InfoOld = m_pApp->GetInfo();// m_Info;

	// Icons are loaded from directory 
	VIB_ChDir(VIB_Drive[1], m_pApp->GetSkinPath());
	m_Icon[ID_SAVE]  = ReadIcon("B_SAVE_S.png", 64, 48);
	m_Icon[ID_SAVEA] = ReadIcon("B_SAVEA_.png", 64, 48);
	m_Icon[ID_BACK]  = ReadIcon("B_BACK_S.PNG", 64, 48);
	m_Icon[ID_APPLY] = ReadIcon("B_OK_.PNG", 64, 48);
	m_Icon[ID_PEDIT] = ReadIcon("B_EDIT.PNG", 98, 98);
	VIB_ChDir(VIB_Drive[1], "..");

	x = 8;
	y = 32;

	// Dialog sub page SEL_EXPOSURE is activated
	m_Sel = SEL_EXPOSURE;
	GUI_DlgAddSelectBox(&m_Dlg, x, y, 200, 140,
		"Exposure Control\n"
		"External Trigger\n"
		"Strobe Output\n"
		"Data Format\n"
		"LUT\n"
		"LUT ROI\n"
		"Region of interest\n"
		"LineScan\n"
		"Characteristics\n"
		"Convolver\n"
		"Shading Correction\n"
		"Preset Files\n"
		"Sensor Information\n", &m_Sel, ID_SEL);

	y += 144;
	strcpy(m_StrTitle, "Exposure Control");
	m_pApp->SetTP(TextStyle::BOLD);
	GUI_DlgAddDynamicText(&m_Dlg, x, y, m_StrTitle);
	m_pApp->SetTP(TextStyle::NORMAL);

	y += 25;
	y1 = y;

	/*********************************************************************/
	GUI_DlgSwitchPage(&m_Dlg, SEL_EXPOSURE);	// Dialog items of sub-page SEL_EXPOSURE

	y = y1;
	GUI_DlgAddLabel(&m_Dlg, x + 4, y + 4, "_Exposure time [µs]", ID_EXPV);

	y += 22;
	pCF->m_ExpV = pCF->m_pExposureTime->GetMValue();
	m_pDlgItem[ID_EXPV] =
		GUI_DlgAddVEditBox(&m_Dlg, x, y + 4, 60, &pCF->m_ExpV,
			pCF->m_pExposureTime->GetMin(), pCF->m_pExposureTime->GetMax(), ID_EXPV);
	m_pDlgItem[ID_EXP] =
		GUI_DlgAddSlider(&m_Dlg, x + 64, y + 4, 136, 20, &pCF->m_ExpV,
			pCF->m_pExposureTime->GetMin(), pCF->m_pExposureTime->GetMax(), ID_EXP);
	GUI_DlgSetSliderType(m_pDlgItem[ID_EXP], DLG_ES_LOGARITHMIC);

	y += 44;
	m_pDlgItem[ID_EXP_CFR] =
		GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "_Constant Frame Rate",
			&(pCF->m_pTriggerCFR->m_Value), ID_EXP_CFR);
	y += 28;
	GUI_DlgAddLabel(&m_Dlg, x + 4, y + 4, "_Frame time [µs]", ID_EXP_FRAMETV);
	y +=22;
	pCF->m_FrameTV = pCF->m_pFrameTime->GetMValue();
	m_pDlgItem[ID_EXP_FRAMETV] =
		GUI_DlgAddVEditBox(&m_Dlg, x, y + 4, 60, &pCF->m_FrameTV,
			pCF->m_pFrameTime->GetMin(), pCF->m_pFrameTime->GetMax(), ID_EXP_FRAMETV);

	m_pDlgItem[ID_EXP_FRAMET] =
		GUI_DlgAddSlider(&m_Dlg, x + 64, y + 4, 136, 20, &(pCF->m_pFrameTime->m_Value),
			pCF->m_pFrameTime->GetMin(), pCF->m_pFrameTime->GetMax(), ID_EXP_FRAMET);
	GUI_DlgSetSliderType(m_pDlgItem[ID_EXP_FRAMET], DLG_ES_LOGARITHMIC);

	/**********************************************************************************/
	GUI_DlgSwitchPage(&m_Dlg, SEL_TRIGGER);	// Dialog items of sub-page SEL_TRIGGER

	y = y1;
	GUI_DlgAddLabel(&m_Dlg, x + 4, y + 4, "S_ource", ID_TRG_SOURCE);
	AddFeatureChoiceBox(x + 60, y, 140, pCF->m_pTriggerSource, ID_TRG_SOURCE);
	y += 28;
	GUI_DlgAddLabel(&m_Dlg, x + 4, y + 4, "_Exposure time defined by", ID_TRG_LVC);
	y += 28;
	AddFeatureChoiceBox(x, y, 200, pCF->m_pTriggerLevelControlled, ID_TRG_LVC);
	y += 32;
	GUI_DlgAddLabel(&m_Dlg, x, y, "Trg. _Delay [µs]", ID_TRG_DELAY);
	AddFeatureEditBox(x + 116, y - 2, 84, pCF->m_pTriggerDelay, ID_TRG_DELAY);
	y += 28;
	m_pDlgItem[ID_TRG_INVERT] =
		GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "Invert _Trigger",
			&(pCF->m_pTriggerInvert->m_Value), ID_TRG_INVERT);
	if (pCF->m_pTriggerInterleave->GetIsAvailable())
	{
		y += 30;
		m_pDlgItem[ID_TRG_INTERLEAVE] =
			GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "_Interleave",
				&(pCF->m_pTriggerInterleave->m_Value), ID_TRG_INTERLEAVE);
	}
	y += 32;
	GUI_DlgAddLabel(&m_Dlg, x, y, "Trg. Di_visor", ID_TRG_DIVISOR);
	AddFeatureEditBox(x + 116, y - 2, 84, pCF->m_pTriggerDivisor, ID_TRG_DIVISOR);

	/*********************************************************************/
	GUI_DlgSwitchPage(&m_Dlg, SEL_STROBE);	// Dialog items of sub-page SEL_STROBE

	y = y1;
	GUI_DlgAddLabel(&m_Dlg, x, y, "_Delay [µs]", ID_STROBE_DELAY);
	AddFeatureEditBox(x + 116, y, 84, pCF->m_pStrobeDelay, ID_STROBE_DELAY);
	y += 28;
	GUI_DlgAddLabel(&m_Dlg, x, y, "_Width [µs]", ID_STROBE_PULSEW);
	AddFeatureEditBox(x + 116, y, 84, pCF->m_pStrobePulseWidth, ID_STROBE_PULSEW);
	y += 28;
	m_pDlgItem[ID_STROBE_INVERT] =
		GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "_Invert",
			&(pCF->m_pStrobeInvert->m_Value), ID_STROBE_INVERT);
	y += 30;
	GUI_DlgAddLabel(&m_Dlg, x + 4, y + 4, "_Output", ID_STROBE_OUTPUT);
	AddFeatureChoiceBox(x + 60, y, 140, pCF->m_pStrobeOutput, ID_STROBE_OUTPUT);

	/*********************************************************************/
	GUI_DlgSwitchPage(&m_Dlg, SEL_DATAMODE);	// Dialog items of sub-page SEL_DATAMODE

	y = y1;
	GUI_DlgAddLabel(&m_Dlg, x + 2, y + 4, "_Output Mode", ID_DO_MODE);
	AddFeatureChoiceBox(x + 98, y, 102, pCF->m_pDataOutMode, ID_DO_MODE);
	y += 28;
	GUI_DlgAddLabel(&m_Dlg, x + 2, y + 4, "_Resolution", ID_DO_RESOLUTION);
	AddFeatureChoiceBox(x + 98, y, 102, pCF->m_pDataResolution, ID_DO_RESOLUTION);
	y += 28;
	GUI_DlgAddLabel(&m_Dlg, x + 2, y + 4, "_Gain", ID_DO_DGAIN);
	AddFeatureChoiceBox(x + 98, y, 102, pCF->m_pDigitalGain, ID_DO_DGAIN);
	if (pCF->m_pDigitalOffset->GetIsAvailable())
	{
		y += 28;
		GUI_DlgAddLabel(&m_Dlg, x + 2, y + 4, "Digital_Offset", ID_DO_DIGITALOFFSET);
		AddFeatureEditBox(x+116, y, 84, pCF->m_pDigitalOffset, ID_DO_DIGITALOFFSET);
	}
	if (pCF->m_pAnalogGain->GetIsAvailable())
	{
		y += 28;
		GUI_DlgAddLabel(&m_Dlg, x + 2, y + 4, "_AnalogGain", ID_DO_AGAIN);
		AddFeatureChoiceBox(x + 98, y, 102, pCF->m_pAnalogGain, ID_DO_AGAIN);
	}

	if (pCF->m_pFineGain->GetIsAvailable())
	{
		y += 28;
		GUI_DlgAddLabel(&m_Dlg, x + 2, y + 4, "_FineGain", ID_DO_FINEGAINV);
		y +=22;
		pCF->m_FineGainV = pCF->m_pFineGain->GetMValue();
		m_pDlgItem[ID_DO_FINEGAINV] =
			GUI_DlgAddVEditBox(&m_Dlg, x, y+4, 60, &pCF->m_FineGainV,
				pCF->m_pFineGain->GetMin(), pCF->m_pFineGain->GetMax(), ID_DO_FINEGAINV);

		m_pDlgItem[ID_DO_FINEGAIN] =
			GUI_DlgAddSlider(&m_Dlg, x+64, y+4, 136, 20, &(pCF->m_pFineGain->m_Value),
				pCF->m_pFineGain->GetMin(), pCF->m_pFineGain->GetMax(), ID_DO_FINEGAIN);
	}
	y += 28;
	m_pDlgItem[ID_FLIP_IMAGE] =
		GUI_DlgAddCheckBox(&m_Dlg, x + 98, y, 102, "_FlipImage",
			&(pCF->m_pFlipImage->m_Value), ID_FLIP_IMAGE);


	/*********************************************************************/
	GUI_DlgSwitchPage(&m_Dlg, SEL_LUT);	// Dialog items of sub-page SEL_LUT

	y = y1;
	if (pCF->m_pLUTMode->GetIsAvailable())
	{
		GUI_DlgAddLabel(&m_Dlg, x + 2, y + 4, "LUT Mode", ID_LUT_MODE);
		AddFeatureChoiceBox(x + 98, y, 102, pCF->m_pLUTMode, ID_LUT_MODE);
		y += 28;
		GUI_DlgAddLabel(&m_Dlg, x + 2, y, "Value", ID_LUT_VALUE);
		AddFeatureEditBox(x + 116, y, 72, pCF->m_pLUTValue, ID_LUT_VALUE);
	}
	if (pCF->m_pLUT0Enable->GetIsAvailable())
	{
		m_pDlgItem[ID_LUT_LUT0_ENABLE] =
			GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "LUT0 Enable",
				&(pCF->m_pLUT0Enable->m_Value), ID_LUT_LUT0_ENABLE);
		y += 30;
		GUI_DlgAddLabel(&m_Dlg, x, y + 4, "LUT0 Mode", ID_LUT_LUT0_MODE);
		AddFeatureChoiceBox(x + 98, y, 102, pCF->m_pLUT0Mode, ID_LUT_LUT0_MODE);
		y += 28;
		GUI_DlgAddLabel(&m_Dlg, x, y, "LUT0 Value", ID_LUT_LUT0_VALUE);
		AddFeatureEditBox(x + 116, y, 72, pCF->m_pLUT0Value, ID_LUT_LUT0_VALUE);
		y += 28;
		m_pDlgItem[ID_LUT_LUT1_ENABLE] =
			GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "LUT1 Enable",
				&(pCF->m_pLUT1Enable->m_Value), ID_LUT_LUT1_ENABLE);
		y += 30;
		GUI_DlgAddLabel(&m_Dlg, x, y + 4, "LUT1 Mode", ID_LUT_LUT1_MODE);
		AddFeatureChoiceBox(x + 98, y, 102, pCF->m_pLUT1Mode, ID_LUT_LUT1_MODE);
		y += 28;
		GUI_DlgAddLabel(&m_Dlg, x, y, "LUT1 Value", ID_LUT_LUT1_VALUE);
		AddFeatureEditBox(x + 116, y, 72, pCF->m_pLUT1Value, ID_LUT_LUT1_VALUE);
		y += 40;
		GUI_DlgAddLabel(&m_Dlg, x, y + 4, "LUT Index", ID_LUT_INDEX);
		AddFeatureChoiceBox(x + 98, y, 102, pCF->m_pLUTIndex, ID_LUT_INDEX);
	}
	y += 32;
	m_pDlgItem[ID_LUT_LOADFILE] =
		GUI_DlgAddButton(&m_Dlg, x, y, 200, 24, "Load LUT file", ID_LUT_LOADFILE);
	y += 32;
	m_pDlgItem[ID_LUT_SAVEFILE] =
		GUI_DlgAddButton(&m_Dlg, x, y, 200, 24, "Save LUT file", ID_LUT_SAVEFILE);

	/*********************************************************************/
	GUI_DlgSwitchPage(&m_Dlg, SEL_LUT_ROI);	// Dialog items of sub-page SEL_LUT_ROI

	y = y1;
	if (pCF->m_pLUTEnRegionLUT->GetIsAvailable())
	{
		m_pDlgItem[ID_LUT_ROI_ENABLE] =
			GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "Enable Region LUT",
				&(pCF->m_pLUTEnRegionLUT->m_Value), ID_LUT_ROI_ENABLE);
		y += 28;
		GUI_DlgAddText(&m_Dlg, x, y + 4, "Region of LUT0");
		y += 28;
		GUI_DlgAddText(&m_Dlg, x,       y + 2, "X");
		GUI_DlgAddText(&m_Dlg, x + 100, y + 2, "W");
		AddFeatureEditBox(x + 16,  y, 52, pCF->m_pLUT0X, ID_LUT_LUT0_X);
		AddFeatureEditBox(x + 116, y, 52, pCF->m_pLUT0W, ID_LUT_LUT0_W);
		y += 28;
		GUI_DlgAddText(&m_Dlg, x,       y + 2, "Y");
		GUI_DlgAddText(&m_Dlg, x + 100, y + 2, "H");
		AddFeatureEditBox(x + 16,  y, 52, pCF->m_pLUT0Y, ID_LUT_LUT0_Y);
		AddFeatureEditBox(x + 116, y, 52, pCF->m_pLUT0H, ID_LUT_LUT0_H);
		y += 28;
		m_pDlgItem[ID_LUT_LUT0_MAX] =
			GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "Set ROI to max",
				&(pCF->m_pLUT0Max->m_Value), ID_LUT_LUT0_MAX);
		y += 28;
		GUI_DlgAddText(&m_Dlg, x, y + 4, "Region of LUT1");
		y += 28;
		GUI_DlgAddText(&m_Dlg, x,       y + 2, "X");
		GUI_DlgAddText(&m_Dlg, x + 100, y + 2, "W");
		AddFeatureEditBox(x + 16,  y, 52, pCF->m_pLUT1X, ID_LUT_LUT1_X);
		AddFeatureEditBox(x + 116, y, 52, pCF->m_pLUT1W, ID_LUT_LUT1_W);
		y += 28;
		GUI_DlgAddText(&m_Dlg, x,       y + 2, "Y");
		GUI_DlgAddText(&m_Dlg, x + 100, y + 2, "H");
		AddFeatureEditBox(x + 16,  y, 52, pCF->m_pLUT1Y, ID_LUT_LUT1_Y);
		AddFeatureEditBox(x + 116, y, 52, pCF->m_pLUT1H, ID_LUT_LUT1_H);
		y += 28;
		m_pDlgItem[ID_LUT_LUT1_MAX] =
			GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "Set ROI to max",
				&(pCF->m_pLUT1Max->m_Value), ID_LUT_LUT1_MAX);
	}

	/*********************************************************************/
	GUI_DlgSwitchPage(&m_Dlg, SEL_WINDOW);	// Dialog items of sub-page SEL_WINDOW

	y = y1;
	/*m_pDlgItem[ID_WND_LCMODE] =
		GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "_Line Scan Mode",
			&(pCF->m_pLineCamMode->m_Value), ID_WND_LCMODE);
	y += 28;
	GUI_DlgAddText(&m_Dlg, x, y + 2, "Line Scan Height");
	AddFeatureEditBox(x + 116, y, 52, pCF->m_pLSImageHeight, ID_WND_LSIHEIGHT);
	y += 22;*/
	GUI_DlgAddText(&m_Dlg, x, y + 4, "Region of interest");
	y += 28;
	GUI_DlgAddText(&m_Dlg, x,       y + 2, "X");
	GUI_DlgAddText(&m_Dlg, x + 100, y + 2, "W");
	AddFeatureEditBox(x + 16,  y, 52, pCF->m_pWindowX, ID_WND_X);
	AddFeatureEditBox(x + 116, y, 52, pCF->m_pWindowW, ID_WND_W);
	y += 28;
	GUI_DlgAddText(&m_Dlg, x,       y + 2, "Y");
	GUI_DlgAddText(&m_Dlg, x + 100, y + 2, "H");
	AddFeatureEditBox(x + 16,  y, 52, pCF->m_pWindowY, ID_WND_Y);
	AddFeatureEditBox(x + 116, y, 52, pCF->m_pWindowH, ID_WND_H);
	y += 28;
	GUI_DlgAddLabel(&m_Dlg, x, y + 2, "_Decimation", ID_WND_DECIM);
	AddFeatureEditBox(x + 116, y, 24, pCF->m_pDecimationY, ID_WND_DECIM);
	y += 30;
	m_pDlgItem[ID_WND_MROI_ENABLE] =
		GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "MROI _Enable",
			&(pCF->m_pMROIEnable->m_Value), ID_WND_MROI_ENABLE);

	y += 30;
	GUI_DlgAddLabel(&m_Dlg, x + 4, y + 4, "_MROI Index", ID_WND_MROI_INDEX);
	if (pCF->m_pMROIIndex->m_PropertyType == PF_MODE)
	{
		AddFeatureChoiceBox(x + 100, y, 100, pCF->m_pMROIIndex, ID_WND_MROI_INDEX);
	}
	else if (pCF->m_pMROIIndex->m_PropertyType == PF_INT)
	{
		AddFeatureEditBox(x + 116, y, 52, pCF->m_pMROIIndex, ID_WND_MROI_INDEX);
	}
	y += 30;
	GUI_DlgAddText(&m_Dlg, x,       y + 2, "Y");
	GUI_DlgAddText(&m_Dlg, x + 102, y + 2, "H");
	AddFeatureEditBox(x + 16,  y, 52, pCF->m_pMROIY, ID_WND_MROI_Y);
	AddFeatureEditBox(x + 116, y, 52, pCF->m_pMROIH, ID_WND_MROI_H);
	y += 28;
	GUI_DlgAddText(&m_Dlg, x, y + 2, "Htot");
	AddFeatureEditBox(x + 116, y, 52, pCF->m_pMROIHtot, ID_WND_MROI_HTOT);

	/*********************************************************************/
	GUI_DlgSwitchPage(&m_Dlg, SEL_LINESCAN);	// Dialog items of sub-page SEL_LINESCAN

	y = y1;
	m_pDlgItem[ID_WND_LCMODE] =
		GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "_Line Scan Mode",
			&(pCF->m_pLineCamMode->m_Value), ID_WND_LCMODE);
	y += 28;
	GUI_DlgAddText(&m_Dlg, x, y + 2, "Line Scan Height");
	AddFeatureEditBox(x + 116, y, 52, pCF->m_pLSImageHeight, ID_WND_LSIHEIGHT);

	if (pCF->m_pEnLinescanHighSpeedMode->GetIsAvailable())
	{
		y += 32;
		m_pDlgItem[ID_ENLINESCANHIGHSPEEDMODE] =
			GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "_EnLinescanHighSpeedMode",
				&(pCF->m_pEnLinescanHighSpeedMode->m_Value), ID_ENLINESCANHIGHSPEEDMODE);
		y += 32;
		GUI_DlgAddText(&m_Dlg, x, y + 4, "Frame Combine");
		y += 28;
		m_pDlgItem[ID_FRAMECOMBINE_ENABLE] =
			GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "_Enable",
				&(pCF->m_pFrameCombineEnable->m_Value), ID_FRAMECOMBINE_ENABLE);
		y += 30;
		GUI_DlgAddLabel(&m_Dlg, x + 4, y + 4, "_NrOfFrames", ID_FRAMECOMBINE_NROFFRAMES);
		AddFeatureEditBox(x + 116, y, 52, pCF->m_pFrameCombineNrOfFrames, ID_FRAMECOMBINE_NROFFRAMES);
		y += 28;
		GUI_DlgAddLabel(&m_Dlg, x + 4, y + 4, "_Timeout", ID_FRAMECOMBINE_TIMEOUT);
		AddFeatureEditBox(x + 116, y, 52, pCF->m_pFrameCombineTimeout, ID_FRAMECOMBINE_TIMEOUT);
		y += 28;
		m_pDlgItem[ID_FRAMECOMBINE_FORCETIMEOUT] =
			GUI_DlgAddButton(&m_Dlg, x, y, 200, 24, "_ForceTimeout", ID_FRAMECOMBINE_FORCETIMEOUT);
	}

	/*********************************************************************/
	GUI_DlgSwitchPage(&m_Dlg, SEL_CHARACTERISTICS);	// Dialog items of sub-page SEL_CHARACTERISTICS

	y = y1;
	if (pCF->m_pLinlogMode->GetIsAvailable())
	{
		GUI_DlgAddLabel(&m_Dlg, x + 4, y + 4, "_Mode", ID_LINLOG_MODE);
		AddFeatureChoiceBox(x+40, y, 160, pCF->m_pLinlogMode, ID_LINLOG_MODE);
		y += 32;
		GUI_DlgAddText(&m_Dlg, x, y + 2, "V1");
		AddFeatureEditBox(x + 24, y, 32, pCF->m_pLinlogValue1, ID_LINLOG_V1);
		GUI_DlgAddText(&m_Dlg, x + 100, y + 2, "T1");
		AddFeatureEditBox(x + 124, y, 52, pCF->m_pLinlogTime1, ID_LINLOG_T1);
		y += 28;
		GUI_DlgAddText(&m_Dlg, x, y + 2, "V2");
		AddFeatureEditBox(x + 24, y, 32, pCF->m_pLinlogValue2, ID_LINLOG_V2);
		GUI_DlgAddText(&m_Dlg, x + 100, y + 2, "T2");
		AddFeatureEditBox(x + 124, y, 52, pCF->m_pLinlogTime2, ID_LINLOG_T2);
		if (pCF->m_pSkim->GetIsAvailable())
		{
			y += 28;
				m_pDlgItem[ID_LINLOG_SKIM] =
					GUI_DlgAddEditSlider(&m_Dlg, x, y, 200, "S_kim", &(pCF->m_pSkim->m_Value),
						pCF->m_pSkim->GetMin(), pCF->m_pSkim->GetMax(), ID_LINLOG_SKIM);
		}
	}
	if (pCF->m_pMultislopeMode->GetIsAvailable())
	{
		GUI_DlgAddLabel(&m_Dlg, x + 4, y + 4, "_Mode", ID_MULTISLOPE_MODE);
		AddFeatureChoiceBox(x+40, y, 160, pCF->m_pMultislopeMode, ID_MULTISLOPE_MODE);
		y += 32;
		GUI_DlgAddText(&m_Dlg, x, y + 2, "NrSlopes");
		AddFeatureEditBox(x + 124, y, 32, pCF->m_pMultislopeNrSlopes, ID_MULTISLOPE_NRSLOPES);
		y += 28;
		GUI_DlgAddText(&m_Dlg, x, y + 2, "V1");
		AddFeatureEditBox(x + 24, y, 32, pCF->m_pMultislopeValue1, ID_MULTISLOPE_V1);
		GUI_DlgAddText(&m_Dlg, x + 100, y + 2, "T1");
		AddFeatureEditBox(x + 124, y, 52, pCF->m_pMultislopeTime1, ID_MULTISLOPE_T1);
		y += 28;
		GUI_DlgAddText(&m_Dlg, x, y + 2, "V2");
		AddFeatureEditBox(x + 24, y, 32, pCF->m_pMultislopeValue2, ID_MULTISLOPE_V2);
		GUI_DlgAddText(&m_Dlg, x + 100, y + 2, "T2");
		AddFeatureEditBox(x + 124, y, 52, pCF->m_pMultislopeTime2, ID_MULTISLOPE_T2);
	}
	y += 48;
	GUI_DlgAddText(&m_Dlg, x + 72, y, "Blacklevel");
	y += 20;
	m_pDlgItem[ID_LINLOG_BLACK_OFF] =
		GUI_DlgAddEditSlider(&m_Dlg, x, y, 200, "_Offset", &(pCF->m_pBlacklevelOffset->m_Value),
			pCF->m_pBlacklevelOffset->GetMin(), pCF->m_pBlacklevelOffset->GetMax(), ID_LINLOG_BLACK_OFF);

	/*********************************************************************/
	GUI_DlgSwitchPage(&m_Dlg, SEL_CONVOLVER);	// Dialog items of sub-page SEL_CONVOLVER

	y = y1;
	if (pCF->m_pConvolverEnable->GetIsAvailable())
	{
		m_pDlgItem[ID_CONVOLVER_ENABLE] =
			GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "Convolver _Enable",
				&(pCF->m_pConvolverEnable->m_Value), ID_CONVOLVER_ENABLE);
		y += 30;
		GUI_DlgAddLabel(&m_Dlg, x, y + 4, "_Presets", ID_CONVOLVER_PRESETS);
		AddFeatureChoiceBox(x + 50, y, 150, pCF->m_pConvolverPresets, ID_CONVOLVER_PRESETS);
		y += 28;
		GUI_DlgAddText(&m_Dlg, x, y + 2, "Offset");
		AddFeatureEditBox(x + 74,  y, 52, pCF->m_pConvolverOffset, ID_CONVOLVER_OFFSET);
		y += 28;
		GUI_DlgAddText(&m_Dlg, x, y + 2, "Scale");
		AddFeatureEditBox(x + 74, y, 52, pCF->m_pConvolverScale, ID_CONVOLVER_SCALE);

		y += 28;
		GUI_DlgAddText(&m_Dlg, x, y + 2, "Matrix Values:");
		y += 15;
		GUI_DlgAddText(&m_Dlg, x + 1,   y + 2, "----");
		GUI_DlgAddText(&m_Dlg, x + 176, y + 2, "----");
		y += 13;
		GUI_DlgAddText(&m_Dlg, x,       y + 2, "| Coeff0");
		GUI_DlgAddText(&m_Dlg, x + 74,  y + 2, "Coeff1");
		GUI_DlgAddText(&m_Dlg, x + 144, y + 2, "Coeff2 |");
		y += 15;
		GUI_DlgAddText(&m_Dlg, x,       y + 2, "| Coeff3");
		GUI_DlgAddText(&m_Dlg, x + 74,  y + 2, "Coeff4");
		GUI_DlgAddText(&m_Dlg, x + 144, y + 2, "Coeff5 |");
		y += 15;
		GUI_DlgAddText(&m_Dlg, x,       y + 2, "| Coeff6");
		GUI_DlgAddText(&m_Dlg, x + 74,  y + 2, "Coeff7");
		GUI_DlgAddText(&m_Dlg, x + 144, y + 2, "Coeff8 |");
		y += 13;
		GUI_DlgAddText(&m_Dlg, x + 1,   y + 2, "----");
		GUI_DlgAddText(&m_Dlg, x + 176, y + 2, "----");
		y += 28;
		AddFeatureEditBox(x + 4,   y, 52, pCF->m_pConvolverCoeff0, ID_CONVOLVER_COEFF0);
		AddFeatureEditBox(x + 74,  y, 52, pCF->m_pConvolverCoeff1, ID_CONVOLVER_COEFF1);
		AddFeatureEditBox(x + 144, y, 52, pCF->m_pConvolverCoeff2, ID_CONVOLVER_COEFF2);
		y += 28;
		AddFeatureEditBox(x + 4,   y, 52, pCF->m_pConvolverCoeff3, ID_CONVOLVER_COEFF3);
		AddFeatureEditBox(x + 74,  y, 52, pCF->m_pConvolverCoeff4, ID_CONVOLVER_COEFF4);
		AddFeatureEditBox(x + 144, y, 52, pCF->m_pConvolverCoeff5, ID_CONVOLVER_COEFF5);
		y += 28;
		AddFeatureEditBox(x + 4,   y, 52, pCF->m_pConvolverCoeff6, ID_CONVOLVER_COEFF6);
		AddFeatureEditBox(x + 74,  y, 52, pCF->m_pConvolverCoeff7, ID_CONVOLVER_COEFF7);
		AddFeatureEditBox(x + 144, y, 52, pCF->m_pConvolverCoeff8, ID_CONVOLVER_COEFF8);
	}

	/*********************************************************************/
	GUI_DlgSwitchPage(&m_Dlg, SEL_CORRECTION);	// Dialog items of sub-page SEL_CORRECTION

	y = y1;
	if (pCF->m_pCorrectionMode->GetIsAvailable())
	{
		GUI_DlgAddLabel(&m_Dlg, x + 4, y + 4, "_Mode", ID_CORRECTION_MODE);
		AddFeatureChoiceBox(x + 40, y, 160, pCF->m_pCorrectionMode, ID_CORRECTION_MODE);
		y += 24;
		GUI_DlgAddText(&m_Dlg, x + 4, y + 4, "Offset correction!");
		y += 24;
		m_pDlgItem[ID_CORRECTION_VAL_BLACK] =
			GUI_DlgAddButton(&m_Dlg, x, y, 200, 24, "Validation Black", ID_CORRECTION_VAL_BLACK);
		y += 28;
		m_pDlgItem[ID_CORRECTION_BLACK] =
			GUI_DlgAddButton(&m_Dlg, x, y, 200, 24, "Set Black Ref", ID_CORRECTION_BLACK);
		y += 24;
		GUI_DlgAddText(&m_Dlg, x + 4, y + 4, "Gain correction!");
		y += 24;
		m_pDlgItem[ID_CORRECTION_VAL_GREY] =
			GUI_DlgAddButton(&m_Dlg, x, y, 200, 24, "Validation Grey", ID_CORRECTION_VAL_GREY);
		y += 28;
		m_pDlgItem[ID_CORRECTION_GREY] =
			GUI_DlgAddButton(&m_Dlg, x, y, 200, 24, "Set Grey Ref", ID_CORRECTION_GREY);
		y += 28;
		m_pDlgItem[ID_CORRECTION_CALCULATE] =
			GUI_DlgAddButton(&m_Dlg, x, y, 200, 24, "Calculate", ID_CORRECTION_CALCULATE);
		y += 28;
		m_pDlgItem[ID_CORRECTION_SAVETOFLASH] =
			GUI_DlgAddButton(&m_Dlg, x, y, 200, 24, "Save To Flash", ID_CORRECTION_SAVETOFLASH);
	}
	if (pCF->m_pColCorrectionEnable->GetIsAvailable())
	{
		m_pDlgItem[ID_COLCORRECTION_ENABLE] =
			GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "Enable ColCorrection",
				&(pCF->m_pColCorrectionEnable->m_Value), ID_COLCORRECTION_ENABLE);
		y += 28;
		m_pDlgItem[ID_COLCORRECTION_CALCULATE] =
			GUI_DlgAddButton(&m_Dlg, x, y, 200, 24, "Calculate", ID_COLCORRECTION_CALCULATE);
		y += 28;
		m_pDlgItem[ID_COLCORRECTION_SAVETOFLASH] =
			GUI_DlgAddButton(&m_Dlg, x, y, 200, 24, "Save To Flash", ID_COLCORRECTION_SAVETOFLASH);
	}
	y += 28;
	GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "_Histogram Stretching",
		m_pApp->GetHistStretch(), ID_CORRECTION_HISTSTRETCH);

	/*********************************************************************/
	GUI_DlgSwitchPage(&m_Dlg, SEL_PRESET);	// Dialog items of sub-page SEL_PRESET

	y = y1;
	m_PreSel = 1;
	m_UsePreset = (m_pApp->m_DefaultPreset[0] == '\0') ? 0 : 1;
	m_PActiveState = DLG_I_DISABLED;
	UpdatePreSelBoxText();

	GUI_DlgAddText(&m_Dlg, x, y, "Select Preset File:");
	m_pDlgItem[ID_PRESEL_I] = GUI_DlgAddSelectBox(&m_Dlg, x, y + 22, 200, 120,
		m_SelPreText, &m_PreSel, ID_PRESEL);
	m_pDlgItem[ID_PAPPLY] = GUI_DlgAddIconButton(&m_Dlg, x, y + 22 + 124, 98, 98,
		"_Apply Pr.", m_pApp->GetIcon(IconId::OK), ID_PAPPLY);
	GUI_DlgSetDItemState(m_pDlgItem[ID_PAPPLY], DLG_I_DISABLED);
	m_pDlgItem[ID_PEDIT] = GUI_DlgAddIconButton(&m_Dlg, x + 102, y + 22 + 124, 98, 98,
		"_Edit Pr.", &m_Icon[ID_PEDIT], ID_PEDIT);
	GUI_DlgSetDItemState(m_pDlgItem[ID_PEDIT], DLG_I_DISABLED);
	y += 22 + 124 + 108;
	m_pDlgItem[ID_PRESET_USE] =
		GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "Use Preset on start", &m_UsePreset, ID_PRESET_USE);
	GUI_DlgAddDynamicText(&m_Dlg, x, y + 28, m_pApp->m_DefaultPreset);

	/*********************************************************************/
	GUI_DlgSwitchPage(&m_Dlg, SEL_INFO);	// Dialog items of sub-page SEL_INFO

	y = y1;
	GUI_DlgAddText(&m_Dlg, x, y, "--- Sensor Module ---");
	y += 20;
	GUI_DlgAddText(&m_Dlg, x, y, pCF->m_pCameraName->GetValueStr());
	y += 18;
	GUI_DlgAddText(&m_Dlg, x, y, "Typecode:");

	//sprintf(pCF->m_pInfoTypecode->GetValueStr(), "%d", pCF->m_pInfoTypecode->GetMValue());
	GUI_DlgAddText(&m_Dlg, x + 92, y, pCF->m_pInfoTypecode->GetValueStr());
	y += 18;
	GUI_DlgAddText(&m_Dlg, x, y, "Serial:");
//	sprintf(pCF->m_pInfoSerial->GetValueStr(), "%d", pCF->m_pInfoSerial->GetMValue());
	GUI_DlgAddText(&m_Dlg, x + 92, y, pCF->m_pInfoSerial->GetValueStr());
	y += 18;
	GUI_DlgAddText(&m_Dlg, x, y, "FPGA Sensor:");
	GUI_DlgAddText(&m_Dlg, x + 92, y, pCF->m_pInfoFPGASensor->GetValueStr());
	if (pCF->m_pInfoFPGAAdc->GetIsAvailable())
	{
		y += 18;
		GUI_DlgAddText(&m_Dlg, x, y, "FPGA ADC:");
		GUI_DlgAddText(&m_Dlg, x + 92, y, pCF->m_pInfoFPGAAdc->GetValueStr());
	}
	y += 18;
	GUI_DlgAddText(&m_Dlg, x, y, "µC:");
	GUI_DlgAddText(&m_Dlg, x + 92, y, pCF->m_pInfouC->GetValueStr());
	y += 28;
	m_pDlgItem[ID_STATUS_LINE] =
		GUI_DlgAddCheckBox(&m_Dlg, x, y, 200, "Status _Line",
			&(pCF->m_pStatusLine->m_Value), ID_STATUS_LINE);
	y += 28;
	m_pDlgItem[ID_STORE_DEFAULTS] =
		GUI_DlgAddButton(&m_Dlg, x, y, 200, 24, "Store as Sensor Defaults", ID_STORE_DEFAULTS);
	y += 28;
	m_pDlgItem[ID_RECALL_DEFAULTS] =
		GUI_DlgAddButton(&m_Dlg, x, y, 200, 24, "Recall Sensor Defaults", ID_RECALL_DEFAULTS);
	y += 28;
	m_pDlgItem[ID_FACTORY_RESET] =
		GUI_DlgAddButton(&m_Dlg, x, y, 200, 24, "Factory Reset", ID_FACTORY_RESET);

	/*********************************************************************/
	// Back, SaveP and Apply buttons
	GUI_DlgSwitchPage(&m_Dlg, DLG_ALLPAGES);

	y = m_Dlg.rgbDlg.Height - 56;
	m_pDlgItem[ID_DSAVEA] =
		GUI_DlgAddAnimButton(&m_Dlg, x, y, 64, 48, "_Save P",
			&m_Icon[ID_SAVE], 2, ID_SAVE);
	m_pDlgItem[ID_APPLY_I] =
		GUI_DlgAddIconButton(&m_Dlg, x + 68, y, 64, 48, "_Apply",
			&m_Icon[ID_APPLY], ID_APPLY);
	GUI_DlgSetItemState(m_pDlgItem[ID_APPLY_I], DLG_I_DISABLED);

	GUI_DlgAddIconButton(&m_Dlg, x + 136, y, 64, 48, m_pApp->GetStr(StringTable::BACK),
		&m_Icon[ID_BACK], DLG_ABORT);

	GUI_SetTxtBackCol(rgbRed);
	m_pDlgSItem[ID_T_APPLY] = GUI_DlgAddTextBox(&m_Dlg, x, y - 52,
		200, 64, " Press [BUTTON APPLY]\n   to apply changes!\n", GUI_BSDOUBLEINV);
	GUI_SetTxtBackCol(m_pApp->GetBackgroundColor());// m_ColBack);
	GUI_DlgSetSItemState(m_pDlgSItem[ID_T_APPLY], DLG_I_INVISIBLE);
	m_pDlgSItem[ID_T_SAVE] = GUI_DlgAddTextBox(&m_Dlg, x, y - 52,
		200, 64, " Preset name must have\n  [1]->[8] characters\n", GUI_BSDOUBLEINV);
	GUI_DlgSetSItemState(m_pDlgSItem[ID_T_SAVE], DLG_I_INVISIBLE);

	/*********************************************************************/
//	GUI_DlgStoreValues(&m_Dlg);
	GUI_DlgSetPage(&m_Dlg, SEL_EXPOSURE);
	EnableItems();
	GUI_SetTxtStyle(GUI_FSEXTEND);
}

/*************************************************************************/
CDlgCam::~CDlgCam()
/*************************************************************************/
/*! @brief Destructor.
**************************************************************************/
{
	VIB_MemFree(m_DirText);
	VIB_MemFree(m_SelPreText);
	for (int i = 1; i < ID_XXX; i++)
		GUI_FreeCImage(&m_Icon[i]);
}

/*************************************************************************/
CDlgCam *CDlgCam::CreateInstance(int x, int y, int Width, int Height)
/*************************************************************************/
/*! @brief Creates CDlgMain instance.
	@param x Horizontal position of dialog
	@param y Vertical position of dialog
	@param Width Width of dialog
	@param Height Height of dialog
	@return Pointer to CDlgCam instance
**************************************************************************/
{
	if (m_pThis == NULL)
		m_pThis = new CDlgCam(x, y, Width, Height);
	return m_pThis;
}

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

/*************************************************************************/
void CDlgCam::EnableItems()
/*************************************************************************/
/*! @brief Enable/disable features items.
**************************************************************************/
{
	CCamFeatures *pCF = CCamFeatures::GetInstance();

	EnableItem(ID_EXPV, pCF->m_pExposureTime);
	EnableItem(ID_EXP, pCF->m_pExposureTime);
	EnableItem(ID_EXP_CFR, pCF->m_pTriggerCFR);
	EnableItem(ID_EXP_FRAMET, pCF->m_pFrameTime);
	EnableItem(ID_EXP_FRAMETV, pCF->m_pFrameTime);

	EnableItem(ID_TRG_DELAY, pCF->m_pTriggerDelay);
	EnableItem(ID_TRG_INVERT, pCF->m_pTriggerInvert);
	EnableItem(ID_TRG_LVC, pCF->m_pTriggerLevelControlled);
	EnableItem(ID_TRG_INTERLEAVE, pCF->m_pTriggerInterleave);
	EnableItem(ID_TRG_DIVISOR, pCF->m_pTriggerDivisor);

	if (pCF->m_pLUTEnRegionLUT->GetIsAvailable())
	{
		EnableItem(ID_LUT_LUT0_X, pCF->m_pLUT0X);
		EnableItem(ID_LUT_LUT0_W, pCF->m_pLUT0W);
		EnableItem(ID_LUT_LUT0_Y, pCF->m_pLUT0Y);
		EnableItem(ID_LUT_LUT0_H, pCF->m_pLUT0H);
		EnableItem(ID_LUT_LUT0_MAX, pCF->m_pLUT0Max);
		EnableItem(ID_LUT_LUT1_X, pCF->m_pLUT1X);
		EnableItem(ID_LUT_LUT1_W, pCF->m_pLUT1W);
		EnableItem(ID_LUT_LUT1_Y, pCF->m_pLUT1Y);
		EnableItem(ID_LUT_LUT1_H, pCF->m_pLUT1H);
		EnableItem(ID_LUT_LUT1_MAX, pCF->m_pLUT1Max);
	}

	EnableItem(ID_WND_LSIHEIGHT, pCF->m_pLSImageHeight);
	EnableItem(ID_WND_Y, pCF->m_pWindowY);
	EnableItem(ID_WND_H, pCF->m_pWindowH);
	EnableItem(ID_WND_DECIM, pCF->m_pDecimationY);
	EnableItem(ID_WND_MROI_ENABLE, pCF->m_pMROIEnable);
	EnableItem(ID_WND_MROI_INDEX, pCF->m_pMROIIndex);
	EnableItem(ID_WND_MROI_Y, pCF->m_pMROIY);
	EnableItem(ID_WND_MROI_H, pCF->m_pMROIH);
	EnableItem(ID_WND_MROI_HTOT, pCF->m_pMROIHtot);

	if (pCF->m_pEnLinescanHighSpeedMode->GetIsAvailable())
	{
		EnableItem(ID_ENLINESCANHIGHSPEEDMODE, pCF->m_pEnLinescanHighSpeedMode);
		EnableItem(ID_FRAMECOMBINE_ENABLE, pCF->m_pFrameCombineEnable);
		EnableItem(ID_FRAMECOMBINE_NROFFRAMES, pCF->m_pFrameCombineNrOfFrames);
		EnableItem(ID_FRAMECOMBINE_TIMEOUT, pCF->m_pFrameCombineTimeout);
		EnableItem(ID_FRAMECOMBINE_FORCETIMEOUT, pCF->m_pFrameCombineForceTimeout);
	}

	if (pCF->m_pLinlogMode->GetIsAvailable())
	{
		EnableItem(ID_LINLOG_MODE, pCF->m_pLinlogMode);
		EnableItem(ID_LINLOG_V1, pCF->m_pLinlogValue1);
		EnableItem(ID_LINLOG_V2, pCF->m_pLinlogValue2);
		EnableItem(ID_LINLOG_T1, pCF->m_pLinlogTime1);
		EnableItem(ID_LINLOG_T2, pCF->m_pLinlogTime2);
	}
	if (pCF->m_pMultislopeMode->GetIsAvailable())
	{
		EnableItem(ID_MULTISLOPE_MODE, pCF->m_pMultislopeMode);
		EnableItem(ID_MULTISLOPE_NRSLOPES, pCF->m_pMultislopeNrSlopes);
		EnableItem(ID_MULTISLOPE_V1, pCF->m_pMultislopeValue1);
		EnableItem(ID_MULTISLOPE_V2, pCF->m_pMultislopeValue2);
		EnableItem(ID_MULTISLOPE_T1, pCF->m_pMultislopeTime1);
		EnableItem(ID_MULTISLOPE_T2, pCF->m_pMultislopeTime2);
	}
	if (pCF->m_pSkim->GetIsAvailable())
	{
		EnableItem(ID_LINLOG_SKIM, pCF->m_pSkim);
	}

	if (pCF->m_pCorrectionMode->GetIsAvailable())
	{
		EnableItem(ID_CORRECTION_MODE, pCF->m_pCorrectionMode);
		EnableItem(ID_CORRECTION_VAL_BLACK, pCF->m_pCorrectionValidationBlack);
		EnableItem(ID_CORRECTION_BLACK, pCF->m_pCorrectionSetBlackRef);
		EnableItem(ID_CORRECTION_VAL_GREY, pCF->m_pCorrectionValidationGrey);
		EnableItem(ID_CORRECTION_GREY, pCF->m_pCorrectionSetGreyRef);
		EnableItem(ID_CORRECTION_CALCULATE, pCF->m_pCorrectionCalculate);
		EnableItem(ID_CORRECTION_SAVETOFLASH, pCF->m_pCorrectionSaveToFlash);
	}
	if (pCF->m_pColCorrectionEnable->GetIsAvailable())
	{
		EnableItem(ID_COLCORRECTION_ENABLE, pCF->m_pColCorrectionEnable);
		EnableItem(ID_COLCORRECTION_CALCULATE, pCF->m_pColCorrectionCalculate);
		EnableItem(ID_COLCORRECTION_SAVETOFLASH, pCF->m_pColCorrectionSaveToFlash);
	}
	GUI_DlgSetDItemState(m_pDlgItem[ID_PAPPLY], m_PActiveState);
}

/******************************************************************************/
int CDlgCam::OnUserIO(int nKey)
/******************************************************************************/
/*! @brief This function processes the user inputs.
	@param nKey Last key code the user entered 
	@return CDlg::m_Activity (!= \p DLG_EOF if the user has made an input)
**************************************************************************/
{
	CCamFeatures *pCF = CCamFeatures::GetInstance();
	static bool bHelpVStore = false;
	int Ident;
	int ApplyNotification = DLG_I_INVISIBLE;
	int res;
	char Filename[256];

	m_Activity = 0;

	if (m_pApp->IsDlgGettingFocus(m_ID))
	{
		m_InfoOld = m_pApp->GetInfo();// m_Info;
		if (m_Sel == SEL_CORRECTION)
		{
			if (m_InfoOld != InfoType::HISTOGRAM && m_InfoOld != InfoType::HISTOGRAM_LOG)
				m_pApp->SetInfoMode(InfoType::HISTOGRAM);
			else
				m_pApp->SetInfoMode(m_InfoOld);
		}
	}

	if (m_pApp->IsDlgInFocus(m_ID))
	{
		m_Activity = GUI_DlgWork(&m_Dlg, nKey);
		Ident      = GUI_DlgGetSelectedID(&m_Dlg);

		// *** when Focus is changed **************************************
		if (m_Dlg.Focus != m_Dlg.LastFocus)
		{
			switch (Ident)
			{
			case ID_APPLY:
				bHelpVStore = false;
				break;
			//Exposure
			case ID_EXPV:
			case ID_EXP_FRAMETV:
			//Window
			case ID_WND_X:
			case ID_WND_W:
			case ID_WND_Y:
			case ID_WND_H:
			case ID_WND_DECIM:
			case ID_WND_MROI_Y:
			case ID_WND_MROI_H:
			//LineScan
			case ID_FRAMECOMBINE_NROFFRAMES:
			case ID_FRAMECOMBINE_TIMEOUT:
			//Data format
			case ID_DO_FINEGAINV:
			case ID_DO_RESOLUTION:
			// LUT
			case ID_LUT_VALUE:
			case ID_LUT_LUT0_VALUE:
			case ID_LUT_LUT1_VALUE:
			case ID_LUT_LOADFILE:
			case ID_LUT_SAVEFILE:
			//Trigger
			case ID_TRG_DELAY:
			case ID_TRG_DIVISOR:
			//Strobe
			case ID_STROBE_DELAY:
			case ID_STROBE_PULSEW:
			//Characteristics
			case ID_LINLOG_V1:
			case ID_LINLOG_V2:
			case ID_LINLOG_T1:
			case ID_LINLOG_T2:
			case ID_MULTISLOPE_NRSLOPES:
			case ID_MULTISLOPE_V1:
			case ID_MULTISLOPE_V2:
			case ID_MULTISLOPE_T1:
			case ID_MULTISLOPE_T2:
				if (bHelpVStore)
				{
					GUI_DlgRestoreValues(&m_Dlg);
					bHelpVStore = false;
				}
				else
				{
					GUI_DlgStoreValues(&m_Dlg);
					bHelpVStore = true;
				}
				break;
			default:
				if (bHelpVStore)
				{
					GUI_DlgRestoreValues(&m_Dlg);
					bHelpVStore = false;
				}
				break;
			}

			// *** Button pressed *****************************************
			switch (m_Activity)
			{	
			case ID_SAVE:
				GUI_DlgSetAnimButton(m_pDlgItem[ID_DSAVEA], 1);

				Show();
				res = SaveNewPreset("PRESET");

				GUI_DlgSetAnimButton(m_pDlgItem[ID_DSAVEA], 0);
				m_pApp->RecBackground(1);
				Show();
				if (res == 0)
				{
					UpdatePreSelBoxText();
					GUI_DlgModifySelectBoxText(m_pDlgItem[ID_PRESEL_I], m_SelPreText);
				}
				break;
			// LineScan
			case ID_FRAMECOMBINE_FORCETIMEOUT:
				pCF->m_pFrameCombineForceTimeout->SetValue(1);
				break;
			// Correction
			case ID_CORRECTION_VAL_BLACK:
				pCF->m_pCorrectionValidationBlack->SetValue(1);
				pCF->m_pCorrectionSetBlackRef->Event();
				break;
			case ID_CORRECTION_BLACK:
				pCF->m_pCorrectionSetBlackRef->SetValue(1);
				pCF->m_pCorrectionCalculate->Event();
				break;
			case ID_CORRECTION_VAL_GREY:
				pCF->m_pCorrectionValidationGrey->SetValue(1);
				pCF->m_pCorrectionSetGreyRef->Event();
				break;
			case ID_CORRECTION_GREY:
				pCF->m_pCorrectionSetGreyRef->SetValue(1);
				pCF->m_pCorrectionCalculate->Event();
				break;
			case ID_CORRECTION_CALCULATE:
				pCF->m_pCorrectionCalculate->SetValue(1);
				pCF->m_pCorrectionSaveToFlash->Event();
				pCF->m_pCorrectionSetBlackRef->Event();
				pCF->m_pCorrectionSetGreyRef->Event();
				break;
			case ID_CORRECTION_SAVETOFLASH:
				if (m_pApp->MessageBox(
					"\nThis will take about 55 seconds!\n\n", 1, "???") == 1)
				{
					pCF->m_pCorrectionSaveToFlash->SetValue(1);
					pCF->m_pCorrectionCalculate->Event();
				}
				break;
			case ID_COLCORRECTION_CALCULATE:
				pCF->m_pColCorrectionCalculate->SetValue(1);
				break;
			case ID_COLCORRECTION_SAVETOFLASH:
				pCF->m_pColCorrectionSaveToFlash->SetValue(1);
				break;
			case ID_STORE_DEFAULTS:
				if (m_pApp->MessageBox(
					"\nStore current setting as default\nin Camera module Flash?\n\n",
					1, "???") == 1)
				{
					pCF->m_pStoreDefaults->SetValue(1);
				}
				break;
			case ID_RECALL_DEFAULTS:
				if (m_pApp->MessageBox(
					"\nReset the camera and\nrecall the default parameters?\n\n",
					1, "???") == 1)
				{
					const bool RestartGrabtask = m_pApp->IsGrabTaskActive();
					CFeature **pFeatureList = pCF->GetFeatureList();

					if (RestartGrabtask)
						m_pApp->StopGrabTask();
					SetPropertyInt(m_pApp->GetCamSerialPort(), "Reset", 1);
					for (int i=0; pFeatureList[i]; i++)
					{
						pFeatureList[i]->Event();
					}
					if (RestartGrabtask)
						m_pApp->StartGrabTask();
				}
				break;
			case ID_FACTORY_RESET:
				if (m_pApp->MessageBox(
					"\nReset camera module to\nfactory default setting?\n\n", 1,
					"???") == 1)
				{
					pCF->m_pFactoryReset->SetValue(1);
				}
				break;
			case ID_APPLY:
				pCF->ApplyCamDlg(GUI_DlgGetLastID(&m_Dlg));
				break;
			default:
				GUI_DlgSetDItemState(m_pDlgItem[ID_APPLY_I], DLG_I_DISABLED);
				break;
			}
		}

		switch (m_Activity)
		{
		case DLG_ABORT: // *** when button Back is set ********************
			m_pApp->SetDlgNewFocus(DialogId::MAIN);
			m_pApp->SetInfoMode(m_InfoOld);
			GUI_DlgSetDItemState(m_pDlgItem[ID_APPLY_I], DLG_I_DISABLED);
			m_bIsVisible = false;
			break;

		case DLG_MOUSE_PRESSED:	// *** Handle mouse clicks in info and graph windows
			m_pApp->ChangeInfoArea(&m_Dlg);
			m_Activity = DLG_EOF;
			break;

		// Data format
		case ID_LUT_LOADFILE:
			m_pApp->SetTP(TextStyle::MONOSPACE);
			res = GUI_OpenFileBox(VIB_Drive[1], NULL, "Load LUT", Filename, "TXT", m_fKB);
			m_pApp->SetTP(TextStyle::NORMAL);
			m_pApp->RecBackground(1);
			if (res > 0)
			{
				sprintf(pCF->m_pLUTFileRead1->GetValueStr(), "DRV:SDC:%s", Filename);
				pCF->m_pLUTFileRead1->UpdateValue();
			}
			break;
		case ID_LUT_SAVEFILE:
			m_pApp->SetTP(TextStyle::MONOSPACE);
			res = GUI_SaveFileBox(VIB_Drive[1], NULL, "Save LUT", Filename, "TXT", m_fKB);
			m_pApp->SetTP(TextStyle::NORMAL);
			m_pApp->RecBackground(1);
			if (res > 0)
			{
				sprintf(pCF->m_pLUTFileSave1->GetValueStr(), "DRV:SDC:%s", Filename);
				pCF->m_pLUTFileSave1->UpdateValue();
			}
			break;
		// Preset
		case ID_PAPPLY:
			m_PActiveState = DLG_I_DISABLED;
			Show();
			PresetCopy();
			pCF->UpdateAllFeatures();
			break;
		case ID_PEDIT:
			UpdatePreSelBoxText();
			PresetCopy();
/*				pDlgConfig->Create(pApp->m_PresetIni, 1);
			m_pA->SetDlgNewFocus(DLG_CONFIG);
			m_bIsVisible = false;*/
			break;

		case DLG_VALUE_CHANGED: // *** when Value is changed **************
			switch (Ident)
			{
			// Trigger
			case ID_TRG_DELAY:
			case ID_TRG_DIVISOR:
			// Window
			case ID_WND_LSIHEIGHT:
			case ID_WND_X:
			case ID_WND_W:
			case ID_WND_Y:
			case ID_WND_H:
			case ID_WND_DECIM:
			case ID_WND_MROI_Y:
			case ID_WND_MROI_H:
			case ID_WND_LCMODE:
			//LineScan
			case ID_FRAMECOMBINE_NROFFRAMES:
			case ID_FRAMECOMBINE_TIMEOUT:
			// Data format
			case ID_DO_RESOLUTION:
			// LUT
			case ID_LUT_VALUE:
			case ID_LUT_LUT0_VALUE:
			case ID_LUT_LUT1_VALUE:
			case ID_LUT_LUT0_X:
			case ID_LUT_LUT0_W:
			case ID_LUT_LUT0_Y:
			case ID_LUT_LUT0_H:
			case ID_LUT_LUT1_X:
			case ID_LUT_LUT1_W:
			case ID_LUT_LUT1_Y:
			case ID_LUT_LUT1_H:
			// Strobe
			case ID_STROBE_DELAY:
			case ID_STROBE_PULSEW:
			// Characteristics
			case ID_LINLOG_V1:
			case ID_LINLOG_V2:
			case ID_LINLOG_T1:
			case ID_LINLOG_T2:
			case ID_MULTISLOPE_V1:
			case ID_MULTISLOPE_V2:
			case ID_MULTISLOPE_T1:
			case ID_MULTISLOPE_T2:
			// Exposure
			case ID_EXPV:
			case ID_EXP_FRAMETV:
			case ID_DO_FINEGAINV:
				GUI_DlgSetDItemState(m_pDlgItem[ID_APPLY_I], DLG_I_ENABLED);
				ApplyNotification = DLG_I_ENABLED;
				break;
			case ID_LINLOG_BLACK_OFF:
				pCF->m_pBlacklevelOffset->UpdateValue();
				break;
			case ID_LINLOG_SKIM:
				pCF->m_pSkim->UpdateValue();
				pCF->m_pFrameTime->Event();
				pCF->m_pTriggerInterleave->Event();
				break;
			case ID_EXP_CFR:
				pCF->m_pTriggerCFR->UpdateValue();
				pCF->m_pExposureTime->Event();
				pCF->m_pFrameTime->Event();
				break;
			case ID_EXP:
				pCF->m_pExposureTime->SetValue(pCF->m_ExpV);
				pCF->m_pFrameTime->Event();
				break;
			case ID_EXP_FRAMET:
				pCF->m_pFrameTime->UpdateValue();
				break;
			// Trigger
			case ID_TRG_SOURCE:
				pCF->m_pTriggerSource->UpdateValue();
				pCF->m_pTriggerCFR->Event();
				pCF->m_pTriggerInvert->Event();
				pCF->m_pTriggerLevelControlled->Event();
				pCF->m_pTriggerDelay->Event();
				pCF->m_pTriggerDivisor->Event();
				pCF->m_pExposureTime->Event();
				pCF->m_pFrameTime->Event();
				pCF->m_pLinlogMode->Event();
				pCF->m_pTriggerInterleave->Event();
				break;
			case ID_TRG_LVC:
				pCF->m_pTriggerLevelControlled->UpdateValue();
				pCF->m_pExposureTime->Event();
				pCF->m_pTriggerCFR->Event();
				pCF->m_pLinlogMode->Event();
				pCF->m_pLinlogValue1->Event();
				pCF->m_pLinlogValue2->Event();
				pCF->m_pLinlogTime1->Event();
				pCF->m_pLinlogTime2->Event();
				pCF->m_pTriggerInterleave->Event();
				break;
			case ID_TRG_INVERT:
				pCF->m_pTriggerInvert->UpdateValue();
				break;
			case ID_TRG_INTERLEAVE:
				pCF->m_pTriggerInterleave->UpdateValue();
				pCF->m_pExposureTime->Event();
				pCF->m_pFrameTime->Event();
				pCF->m_pSkim->Event();
				pCF->m_pTriggerLevelControlled->Event();
				break;
			// Strobe
			case ID_STROBE_INVERT:
				pCF->m_pStrobeInvert->UpdateValue();
				break;
			case ID_STROBE_OUTPUT:
				pCF->m_pStrobeOutput->UpdateValue();
				break;
			// DataFormat
			case ID_DO_MODE:
				pCF->m_pDataOutMode->UpdateValue();
				break;
			case ID_DO_DGAIN:
				pCF->m_pDigitalGain->UpdateValue();
				break;
			case ID_DO_AGAIN:
				pCF->m_pAnalogGain->UpdateValue();
				break;
			case ID_DO_DIGITALOFFSET:
				pCF->m_pDigitalOffset->UpdateValue();
				break;
			case ID_DO_FINEGAIN:
				pCF->m_pFineGain->UpdateValue();
				break;
			case ID_FLIP_IMAGE:
				pCF->m_pFlipImage->UpdateValue();
				break;
			// LUT
			case ID_LUT_MODE:
				pCF->m_pLUTMode->UpdateValue();
				break;
			case ID_LUT_LUT0_ENABLE:
				pCF->m_pLUT0Enable->UpdateValue();
				break;
			case ID_LUT_LUT0_MODE:
				pCF->m_pLUT0Mode->UpdateValue();
				break;
			case ID_LUT_LUT1_ENABLE:
				pCF->m_pLUT1Enable->UpdateValue();
				break;
			case ID_LUT_LUT1_MODE:
				pCF->m_pLUT1Mode->UpdateValue();
				break;
			case ID_LUT_INDEX:
				pCF->m_pLUTIndex->UpdateValue();
				break;
			case ID_LUT_ROI_ENABLE:
				pCF->m_pLUTEnRegionLUT->UpdateValue();
				pCF->m_pLUT0X->Event();
				pCF->m_pLUT0W->Event();
				pCF->m_pLUT0Y->Event();
				pCF->m_pLUT0H->Event();
				pCF->m_pLUT0Max->Event();
				pCF->m_pLUT1X->Event();
				pCF->m_pLUT1W->Event();
				pCF->m_pLUT1Y->Event();
				pCF->m_pLUT1H->Event();
				pCF->m_pLUT1Max->Event();
				break;
			case ID_LUT_LUT0_MAX:
				pCF->m_pLUT0Max->UpdateValue();
				pCF->m_pLUT0X->Event();
				pCF->m_pLUT0W->Event();
				pCF->m_pLUT0Y->Event();
				pCF->m_pLUT0H->Event();
				break;
			case ID_LUT_LUT1_MAX:
				pCF->m_pLUT1Max->UpdateValue();
				pCF->m_pLUT1X->Event();
				pCF->m_pLUT1W->Event();
				pCF->m_pLUT1Y->Event();
				pCF->m_pLUT1H->Event();
				break;
			// Window
			case ID_WND_MROI_ENABLE:
				pCF->m_pMROIEnable->UpdateValue();
				pCF->m_pMROIIndex->Event();
				pCF->m_pWindowY->Event();
				pCF->m_pWindowH->Event();
				pCF->m_pMROIY->Event();
				pCF->m_pMROIH->Event();
				pCF->m_pDecimationY->Event();
				pCF->m_pFrameTime->Event();
				break;
			// MROI Index
			case ID_WND_MROI_INDEX:
				pCF->m_pMROIIndex->UpdateValue();
				pCF->m_pMROIY->Event();
				pCF->m_pMROIH->Event();
				break;
			// Linescan
			case ID_ENLINESCANHIGHSPEEDMODE:
				pCF->m_pEnLinescanHighSpeedMode->UpdateValue();
				pCF->m_pFrameCombineEnable->Event();
				pCF->m_pWindowH->Event();
				pCF->m_pFrameTime->Event();
				break;
			case ID_FRAMECOMBINE_ENABLE:
				pCF->m_pFrameCombineEnable->UpdateValue();
				break;
			// Characteristics
			case ID_LINLOG_MODE:
				pCF->m_pLinlogMode->UpdateValue();
				pCF->m_pLinlogValue1->Event();
				pCF->m_pLinlogValue2->Event();
				pCF->m_pLinlogTime1->Event();
				pCF->m_pLinlogTime2->Event();
				pCF->m_pSkim->Event();
				pCF->m_pTriggerInterleave->Event();
				break;
			case ID_MULTISLOPE_MODE:
				pCF->m_pMultislopeMode->UpdateValue();
				pCF->m_pMultislopeNrSlopes->Event();
				pCF->m_pMultislopeValue1->Event();
				pCF->m_pMultislopeValue2->Event();
				pCF->m_pMultislopeTime1->Event();
				pCF->m_pMultislopeTime2->Event();
				break;
			// Convolver
			case ID_CONVOLVER_ENABLE:
				pCF->m_pConvolverEnable->UpdateValue();
				break;
			case ID_CONVOLVER_PRESETS:
				pCF->m_pConvolverPresets->UpdateValue();
				pCF->m_pConvolverOffset->Event();
				pCF->m_pConvolverScale->Event();
				pCF->m_pConvolverCoeff0->Event();
				pCF->m_pConvolverCoeff1->Event();
				pCF->m_pConvolverCoeff2->Event();
				pCF->m_pConvolverCoeff3->Event();
				pCF->m_pConvolverCoeff4->Event();
				pCF->m_pConvolverCoeff5->Event();
				pCF->m_pConvolverCoeff6->Event();
				pCF->m_pConvolverCoeff7->Event();
				pCF->m_pConvolverCoeff8->Event();
				break;
			case ID_CONVOLVER_OFFSET:
				pCF->m_pConvolverOffset->UpdateValue();
				break;
			case ID_CONVOLVER_SCALE:
				pCF->m_pConvolverScale->UpdateValue();
				break;
			case ID_CONVOLVER_COEFF0:
				pCF->m_pConvolverCoeff0->UpdateValue();
				break;
			case ID_CONVOLVER_COEFF1:
				pCF->m_pConvolverCoeff1->UpdateValue();
				break;
			case ID_CONVOLVER_COEFF2:
				pCF->m_pConvolverCoeff2->UpdateValue();
				break;
			case ID_CONVOLVER_COEFF3:
				pCF->m_pConvolverCoeff3->UpdateValue();
				break;
			case ID_CONVOLVER_COEFF4:
				pCF->m_pConvolverCoeff4->UpdateValue();
				break;
			case ID_CONVOLVER_COEFF5:
				pCF->m_pConvolverCoeff5->UpdateValue();
				break;
			case ID_CONVOLVER_COEFF6:
				pCF->m_pConvolverCoeff6->UpdateValue();
				break;
			case ID_CONVOLVER_COEFF7:
				pCF->m_pConvolverCoeff7->UpdateValue();
				break;
			case ID_CONVOLVER_COEFF8:
				pCF->m_pConvolverCoeff8->UpdateValue();
				break;
			// Correction
			case ID_CORRECTION_MODE:
				pCF->m_pCorrectionMode->UpdateValue();
				break;
			case ID_COLCORRECTION_ENABLE:
				pCF->m_pColCorrectionEnable->UpdateValue();
				break;
			case ID_PRESET_USE:
				if (m_UsePreset)
					GetPresetName(m_pApp->m_DefaultPreset);
				else
					m_pApp->m_DefaultPreset[0] = '\0';
				m_pApp->GetVicIni()->saveToIni(VIB_Drive[1], "vic_ps.ini");
				break;
			// Preset
			case ID_PRESEL:
				UpdatePreSelBoxText();
				if (m_FEntries > 0)
				{
					m_PActiveState = DLG_I_ENABLED;
//					PresetCopy();
				}
				break;
			// Main
			case ID_SEL:
				if (m_Sel == SEL_CORRECTION)
				{
					m_pApp->SetInfoMode((m_InfoOld == InfoType::HISTOGRAM_LOG) ?
						InfoType::HISTOGRAM_LOG : InfoType::HISTOGRAM);
				}
				else
					m_pApp->SetInfoMode(m_InfoOld);
				break;
			case ID_STATUS_LINE:
				pCF->m_pStatusLine->UpdateValue();
				break;
			}
			break;

		default: // *** Enter pressed *************************************
			if (nKey == KB_ENTER)
				pCF->ApplyCamDlg(GUI_DlgGetLastID(&m_Dlg));
			break;
		}

		// Here the items of the active dialog sub page are enabled or disabled
		if (m_Activity != DLG_EOF)
		{
			EnableItems();

			GUI_DlgSetPage(&m_Dlg, m_Sel);
			switch (m_Sel)
			{
			case SEL_EXPOSURE:
				strcpy(m_StrTitle, "Exposure Control");
				break;
			case SEL_TRIGGER:
				strcpy(m_StrTitle, "External Trigger");
				break;
			case SEL_STROBE:
				strcpy(m_StrTitle, "Strobe Output");
				break;
			case SEL_DATAMODE:
				strcpy(m_StrTitle, "Data Format");
				break;
			case SEL_LUT:
				strcpy(m_StrTitle, "LUT");
				break;
			case SEL_LUT_ROI:
				if (pCF->m_pLUTEnRegionLUT->GetIsAvailable())
					strcpy(m_StrTitle, "LUT ROI");
				else
					strcpy(m_StrTitle, "Feature not supported");
				break;
			case SEL_WINDOW:
				strcpy(m_StrTitle, "Region of Interest");
				break;
			case SEL_LINESCAN:
				strcpy(m_StrTitle, "LineScan");
				break;
			case SEL_CHARACTERISTICS:
				if (pCF->m_pLinlogMode->GetIsAvailable())
					strcpy(m_StrTitle, "LinLog");
				else if (pCF->m_pMultislopeMode->GetIsAvailable())
					strcpy(m_StrTitle, "Multislope");
				else
					strcpy(m_StrTitle, "Feature not supported");
				break;
			case SEL_CONVOLVER:
				if (pCF->m_pConvolverEnable->GetIsAvailable())
					strcpy(m_StrTitle, "Convolver");
				else
					strcpy(m_StrTitle, "Feature not supported");
				break;
			case SEL_CORRECTION:
				strcpy(m_StrTitle, "Shading Correction");
				break;
			case SEL_PRESET:
				strcpy(m_StrTitle, "Preset Files");
				break;
			case SEL_INFO:
				strcpy(m_StrTitle, "Sensor Information");
				break;
			}
			GUI_DlgRefresh(&m_Dlg);
		}
		GUI_DlgSetSItemState(m_pDlgSItem[ID_T_APPLY], ApplyNotification);
	}
	return m_Activity;
}

/*************************************************************************/
void CDlgCam::Apply()
/*************************************************************************/
/*! @brief Action when 'Apply' button is pressed.
**************************************************************************/
{
	GUI_DlgSetDItemState(m_pDlgItem[ID_APPLY_I], DLG_I_DISABLED);
	GUI_DlgStoreValues(&m_Dlg);
}

/*************************************************************************/
void CDlgCam::PresetCopy()
/*************************************************************************/
/*! @brief This function selects preset with name in \e SelectBox and copies
	it to the current preset.

	This function prepares the current preset with the desired preset.
**************************************************************************/
{
	char PreName[20];

	GetPresetName(PreName);
	if (m_FEntries)
		m_pApp->LoadPreset(PreName);
}

/*************************************************************************/
int CDlgCam::SaveNewPreset(const char *pDirname)
/*************************************************************************/
/*! @brief Saves current preset as new file in directory \p pDirname.

	To save a new preset, you need to call this function, it would check the 
	number [0<number<=8] of characters of preset name and if the preset name 
	exists.
	@param pDirname Pointer to directory, where preset is saved
	@par Example:
	@code
if (m_NewFName[0] == '\0')
{
	printf("No filename is given, Preset cannot be saved\n"));
	return -3;
}
else if (strlen(m_NewFName) > 8)
{
	printf("The filename length is too long, check it on 8 characters\n"));
	return -4;
}
	@endcode
**************************************************************************/
{
	int  Err, result, i;
	char ParamName[64], FileName[64], Text[64];
	Config *pCurrentIni = m_pApp->GetCurrentIni();

	if (VIB_ChDir(VIB_Drive[1], pDirname) < 0)
	{
		VIB_MkDir(VIB_Drive[1], pDirname);
		VIB_ChDir(VIB_Drive[1], pDirname);
	}

	GUI_FileBoxShowDir(0);
	m_pApp->SetTP(TextStyle::MONOSPACE);
	Err = GUI_SaveFileBox(VIB_Drive[1], NULL, "Save preset", FileName, "INI", m_fKB);
	m_pApp->SetTP(TextStyle::NORMAL);
	GUI_FileBoxShowDir(1);
	if (Err == 0)
	{
		VIB_ChDir(VIB_Drive[1], "..");
		return -1;
	}

	ParamName[0] = '\0';
	for (i = 0; i < strlen(FileName); i++)
	{
		ParamName[i] = FileName[i];
		if (FileName[i] == '.')
			break;
	}
	ParamName[i] = '\0';

	Err = VIB_FindFile2(VIB_Drive[1], FileName);

	// *** File exits ? ***
	if (Err >= 0)
	{
		std::snprintf(Text, 64, "\n%s\n%s\n\n", m_pApp->GetStr(StringTable::FILE_EXISTS), m_pApp->GetStr(StringTable::OVERWRITE));
		result = m_pApp->MessageBox(Text, 1, "Information");
		if (result == 1)
		{
			VIB_DeleteFile(VIB_Drive[1], FileName);
		}
		else
		{
			VIB_ChDir(VIB_Drive[1], "..");
			return -1;
		}
	}

	// *** Save file ***
	pCurrentIni->setValue("PresetName", ParamName);
	if (pCurrentIni->saveToIni(VIB_Drive[1], FileName) <= 0)
		m_pApp->MessageBox("\nError writing file!\n\n", 0, "Information");
	CLog::Print(m_pStrings->getValue("SFMessage001", "Preset '%s' saved\n"), FileName);
	
	VIB_ChDir(VIB_Drive[1], "..");
	return 0;
}

/*************************************************************************/
void CDlgCam::UpdatePreSelBoxText()
/*************************************************************************/
/*! @brief Builds text for preset \e SelectBox.
	
	This function is needed to update text in \e SelectBox for preset, it
	would be called when a preset is added or moved.
**************************************************************************/
{
	int j;
	char FName[20];
	Config *pConf = NULL;

	m_DirText[0] = '\0';
	m_SelPreText[0] = '\0';
	m_FEntries = 0;
	if (VIB_ChDir(VIB_Drive[1], "PRESET") == 0)
	{
		m_FEntries = VIB_ReadDirFilter(VIB_Drive[1], m_DirText, "INI");
		for (int i = 0; i < m_FEntries; i++)
		{
			for (j = 0; j < 12; j++)
				FName[j] = m_DirText[j + i * 23];
			FName[j] = '\0';
			pConf = Config::loadFromIni(VIB_Drive[1], FName, "PRESET_INI");
			if (pConf)
			{
				const char *pText = pConf->getValue("PresetName", FName);

				// Current Preset is not shown in preset SelectBox
				if (strcmp(pText, "Current") != 0 && strcmp(pText, "CURRENT .INI") != 0)
				{
					char row[128];

					std::snprintf(row, 128, "%s\n", pText);
					strcat(m_SelPreText, row);
				}
				delete pConf;
			}
		}
		VIB_ChDir(VIB_Drive[1], "..");
	}
}

/*************************************************************************/
void CDlgCam::GetPresetName(char *PreName) const
/*************************************************************************/
/*! @brief Gets name of currently selected preset.
	@param[out] PreName Preset name
**************************************************************************/
{
	int u, v;

	u = 0;
	v = 0;
	if (m_PreSel)
	{
		while (v < m_PreSel-1)
		{
			if (m_SelPreText[u] == '\n')
				v++;
			u++;
		}
		v = 0;
		while (m_SelPreText[u] != '\n')
		{
			// Selected Text in SelectBox
			PreName[v] = m_SelPreText[u];
			u++;
			v++;
		}
	}
	PreName[v] ='\0';
}

/*************************************************************************/
void CDlgCam::AddFeatureEditBox(int x, int y, int Width, CFeature *pFeature, int ID)
/*************************************************************************/
/*! @brief Add camera feature (EditBox).
**************************************************************************/
{
	m_pDlgItem[ID] =
		GUI_DlgAddVEditBox(&m_Dlg, x, y, Width, &(pFeature->m_Value),
			pFeature->GetMin(), pFeature->GetMax(), ID);
}

/*************************************************************************/
void CDlgCam::AddFeatureChoiceBox(int x, int y, int Width, CFeature *pFeature, int ID)
/*************************************************************************/
/*! @brief Add camera feature (ChoiceBox).
**************************************************************************/
{
	m_pDlgItem[ID] =
		GUI_DlgAddChoiceBox(&m_Dlg, x, y, Width, 24, pFeature->m_ModeValues,
			2, &(pFeature->m_Value), ID);
}

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