/*************************************************************************\
* "$RCSfile: CDlgCam.hpp,v $"                                             *
***************************************************************************
* Information by CVS or VSS:                                              *
*     Last check in on: $Date: 2010/06/24 07:59:44 $                      *
*     by                $Author: schluckebier $
*     Revision        : $Revision: 1.32 $                                 *
\*************************************************************************/
/*! \file CDlgCam.hpp
*	\brief Header CDlgCam Class
**************************************************************************/

/*************************************************************************/
/*! @brief Camera settings dialog class

	See \ref CSD for details.
**************************************************************************/
class CDlgCam: public CDlg
{
public:
	//! @brief Dialog identifier of CDlgCam.
	//!
	//! They are reused as array index together with the INDEX() and ICON() macros.
	enum eDlgCam_ID
	{
		ID_SAVE = 5,			//!< SaveFile button
		ID_SAVEA,				//!< SaveFile button pressed
		ID_APPLY,				//!< Apply button
		ID_BACK,				//!< Back button
		ID_PEDIT,				//!< Edit Preset button
		ID_XXX,					//!< End marker

		ID_PAPPLY,				//!< Show Preset button
		ID_PRESEL,				//!< \e SelectBox for Preset Tools

		ID_EXP,					//!< Item for exposure time
		ID_EXP_CFR,				//!< Item for constant frame rate
		ID_EXP_FRAMET,			//!< Item for frame time
		ID_TRG_SOURCE,			//!< Item for trigger source
		ID_TRG_DELAY,			//!< Item for trigger delay
		ID_TRG_INVERT,			//!< Item for trigger invert
		ID_TRG_DIVISOR,			//!< Item for trigger encoder divisor
		ID_TRG_LVC,				//!< Item for level controlled exposure time
		ID_TRG_INTERLEAVE,		//!< Item for interleaved exposure
		ID_STROBE_DELAY,		//!< Item for strobe delay
		ID_STROBE_PULSEW,		//!< Item for strobe pulse width
		ID_STROBE_INVERT,		//!< Item for strobe invert flag
		ID_STROBE_OUTPUT,		//!< Item for strobe output selector
		ID_WND_LCMODE,			//!< Item for line camera mode
		ID_WND_LSIHEIGHT,		//!< Item for line scan image height
		ID_WND_X,				//!< Item for window x-offset
		ID_WND_Y,				//!< Item for window y-offset
		ID_WND_W,				//!< Item for window width
		ID_WND_H,				//!< Item for window height
		ID_WND_DECIM,			//!< Item for y-decimation
		ID_WND_MROI_ENABLE,		//!< Item for MROI enable flag
		ID_WND_MROI_INDEX,		//!< Item for MROI index
		ID_WND_MROI_H,			//!< Item for MROI height
		ID_WND_MROI_Y,			//!< Item for MROI y-offset
		ID_WND_MROI_HTOT,		//!< Item for MROI total height
		ID_ENLINESCANHIGHSPEEDMODE,   //!< Item for FrameCombine enable
		ID_FRAMECOMBINE_ENABLE,       //!< Item for FrameCombine enable
		ID_FRAMECOMBINE_NROFFRAMES,   //!< Item for FrameCombine NrOfFrames
		ID_FRAMECOMBINE_TIMEOUT,      //!< Item for FrameCombine timeout
		ID_FRAMECOMBINE_FORCETIMEOUT, //!< Item for FrameCombine force timeout
		ID_DO_MODE,				//!< Item for data out mode selector
		ID_DO_RESOLUTION,		//!< Item for data resolution selector
		ID_DO_DGAIN,			//!< Item for digital gain selector
		ID_DO_AGAIN,			//!< Item for analog gain selector
		ID_DO_DIGITALOFFSET,	//!< Item for digital data offset
		ID_DO_FINEGAIN,			//!< Item for fine gain
		ID_DO_FINEGAINV,		//!< Item for fine gain
		ID_LUT_MODE,			//!< Item for LUT mode
		ID_LUT_VALUE,			//!< Item for LUT value
		ID_LUT_LUT0_ENABLE,		//!< Item for LUT0 enable
		ID_LUT_LUT0_MODE,		//!< Item for LUT0 mode
		ID_LUT_LUT0_VALUE,		//!< Item for LUT0 value
		ID_LUT_LUT1_ENABLE,		//!< Item for LUT1 enable
		ID_LUT_LUT1_MODE,		//!< Item for LUT1 mode
		ID_LUT_LUT1_VALUE,		//!< Item for LUT1 value
		ID_LUT_INDEX,			//!< Item for LUT index
		ID_LUT_LOADFILE,		//!< Item for LUT file open dialog
		ID_LUT_SAVEFILE,		//!< Item for LUT file save dialog
		ID_LUT_ROI_ENABLE,		//!< Item for LUT Enable RegionLUT
		ID_LUT_LUT0_X,			//!< Item for LUT0 ROI x-position
		ID_LUT_LUT0_W,			//!< Item for LUT0 ROI width
		ID_LUT_LUT0_Y,			//!< Item for LUT0 ROI y-position
		ID_LUT_LUT0_H,			//!< Item for LUT0 ROI height
		ID_LUT_LUT0_MAX,		//!< Item for LUT0 ROI set ROI to max
		ID_LUT_LUT1_X,			//!< Item for LUT0 ROI x-position
		ID_LUT_LUT1_W,			//!< Item for LUT0 ROI width
		ID_LUT_LUT1_Y,			//!< Item for LUT0 ROI y-position
		ID_LUT_LUT1_H,			//!< Item for LUT0 ROI height
		ID_LUT_LUT1_MAX,		//!< Item for LUT0 ROI set ROI to max

		ID_FLIP_IMAGE,			//!< Item for Flip image
		ID_LINLOG_MODE,			//!< Item for LinLog mode selector
		ID_LINLOG_V1,			//!< Item for LinLog voltage 1
		ID_LINLOG_V2,			//!< Item for LinLog voltage 2
		ID_LINLOG_T1,			//!< Item for LinLog time 1
		ID_LINLOG_T2,			//!< Item for LinLog time 2
		ID_MULTISLOPE_MODE,		//!< Item for Multislope mode selector
		ID_MULTISLOPE_NRSLOPES,	//!< Item for Multislope NrSlopes
		ID_MULTISLOPE_V1,		//!< Item for Multislope voltage 1
		ID_MULTISLOPE_V2,		//!< Item for Multislope voltage 2
		ID_MULTISLOPE_T1,		//!< Item for Multislope time 1
		ID_MULTISLOPE_T2,		//!< Item for Multislope time 2
		ID_LINLOG_SKIM,			//!< Item for skim value slider
		ID_LINLOG_BLACK_OFF,	//!< Item for black level offset
		ID_CONVOLVER_ENABLE,	//!< Item for Convolver enable
		ID_CONVOLVER_PRESETS,	//!< Item for Convolver presets
		ID_CONVOLVER_OFFSET,	//!< Item for Convolver offset
		ID_CONVOLVER_SCALE,		//!< Item for Convolver scale
		ID_CONVOLVER_COEFF0,	//!< Item for Convolver coeff0
		ID_CONVOLVER_COEFF1,	//!< Item for Convolver coeff1
		ID_CONVOLVER_COEFF2,	//!< Item for Convolver coeff2
		ID_CONVOLVER_COEFF3,	//!< Item for Convolver coeff3
		ID_CONVOLVER_COEFF4,	//!< Item for Convolver coeff4
		ID_CONVOLVER_COEFF5,	//!< Item for Convolver coeff5
		ID_CONVOLVER_COEFF6,	//!< Item for Convolver coeff6
		ID_CONVOLVER_COEFF7,	//!< Item for Convolver coeff7
		ID_CONVOLVER_COEFF8,	//!< Item for Convolver coeff8
		ID_CORRECTION_MODE,		//!< Item for correction mode selector
		ID_CORRECTION_VAL_BLACK,//!< Item for correction black validation
		ID_CORRECTION_BLACK,	//!< Item for correction set black reference image
		ID_CORRECTION_VAL_GREY,	//!< Item for correction grey validation
		ID_CORRECTION_GREY,		//!< Item for correction set grey reference image
		ID_CORRECTION_CALCULATE,//!< Item for correction calculate
		ID_CORRECTION_SAVETOFLASH,//!< Item for correction save to flash
		ID_COLCORRECTION_ENABLE,      //!< Item for col correction enable
		ID_COLCORRECTION_CALCULATE,   //!< Item for col correction calculate
		ID_COLCORRECTION_SAVETOFLASH, //!< Item for col correction save to flash
		ID_PRESET_USE,			//!< Item for use preset
		ID_STATUS_LINE,			//!< Item for status line
		ID_STORE_DEFAULTS,		//!< Item for store button
		ID_RECALL_DEFAULTS,		//!< Item for recall button
		ID_FACTORY_RESET,		//!< Item for factory reset button
		ID_SEL,					//!< Item for setting sub-page selector
		ID_DSAVEA,				//!< Handle to animated save-button
		ID_EXPV,				//!< Exposure time \e EditBox
		ID_EXP_FRAMETV,			//!< Frame time \e EditBox
		ID_CORRECTION_HISTSTRETCH,//!< Histogram stretching
		ID_APPLY_I,				//!< Apply Button

		ID_PRESEL_I,			//!< \e SelectBox for Preset Tools

		ID_T_SAVE = 0,			//!< Static dialog label for save preset
		ID_T_APPLY				//!< Static dialog label for apply user hint
	};

protected:
	//! Dialog sub-page-selector values
	enum eDlgCam_SEL
	{
		SEL_EXPOSURE = 1,		//!< Sub-page: Exposure
		SEL_TRIGGER,			//!< Sub-page: Trigger
		SEL_STROBE,				//!< Sub-page: Strobe
		SEL_DATAMODE,			//!< Sub-page: Data mode
		SEL_LUT,				//!< Sub-page: LUT
		SEL_LUT_ROI,			//!< Sub-page: LUT_ROI
		SEL_WINDOW,				//!< Sub-page: Window
		SEL_LINESCAN,			//!< Sub-page: LineScan
		SEL_CHARACTERISTICS,	//!< Sub-page: LinLog or Multislope
		SEL_CONVOLVER,			//!< Sub-page: Convolver
		SEL_CORRECTION,			//!< Sub-page: Correction
		SEL_PRESET,				//!< Sub-page: Preset
		SEL_INFO				//!< Sub-page: Info
	};

private:
	CDlgCam(int x, int y, int Width, int Height);
	~CDlgCam();
	static CDlgCam *m_pThis;

public:
	static CDlgCam *CreateInstance(int x, int y, int Width, int Height);
	//! Gets CDlgCam instance.
	static CDlgCam *GetInstance() { return m_pThis; }
	static void DisposeInstance();
	int OnUserIO(int nKey);
	void UpdatePreSelBoxText();
	void Apply();

protected:
	void EnableItems();
	void PresetCopy();
	int  SaveNewPreset(const char *pDirname);
	void AddFeatureEditBox(int x, int y, int Width, CFeature *pFeature, int ID);
	void AddFeatureChoiceBox(int x, int y, int Width, CFeature *pFeature, int ID);
	void GetPresetName(char *PreName) const;

	//! Enables one feature in dialog.
	void EnableItem(int Index, CFeature *pFeature)
	{	GUI_DlgSetDItemState(m_pDlgItem[INDEX(Index)],
			(pFeature->m_bInactive) ? DLG_I_DISABLED : DLG_I_ENABLED); }

	int m_Sel;				//!< Dialog sub-page-mode
	int m_InfoOld;			//!< Old Info
	int m_PreSel;			//!< Value of selected preset in \e SelectBox
	int m_UsePreset;		//!< Use preset value
	int m_PActiveState;		//!< State of Apply Preset button
	int m_FEntries;			//!< Number of files in directory
	char m_StrTitle[32];	//!< Sub-page title-string
	char *m_DirText;		//!< Directory name
	char *m_SelPreText;		//!< Text for preset \e SelectBox
};

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