//-----------------------------------------------------------------------------
#ifndef DeviceConfigureFrameH
#define DeviceConfigureFrameH DeviceConfigureFrameH
//-----------------------------------------------------------------------------
#include "DevCtrl.h"
#include <mvIMPACT_CPP/mvIMPACT_acquire.h>
#ifdef BUILD_WITH_PLUGIN_SUPPORT
#	include <mvPluginManager/Include/mvPluginManager.h>
#endif // #ifdef BUILD_WITH_PLUGIN_SUPPORT
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/notebook.h>
#include <wx/spinctrl.h>

class DevicePropertyHandler;
class ImageAnalysisPlotCanvas;
class ImageCanvas;
class InfoPlotCanvas;

class wxConfigBase;
class wxNotebook;
class wxPropertyGrid;
class wxPropertyGridEvent;
class wxSlider;
class wxSplitterEvent;
class wxSplitterWindow;
class wxSpinCtrl;

DECLARE_EVENT_TYPE(imageReadyEvent, -1)
DECLARE_EVENT_TYPE(imageSkippedEvent, -2)
DECLARE_EVENT_TYPE(toggleDisplayArea, -3)
DECLARE_EVENT_TYPE(liveModeAborted, -4)
DECLARE_EVENT_TYPE(eventNotified, -5)
DECLARE_EVENT_TYPE(sequenceReadyEvent, -6)
DECLARE_EVENT_TYPE(imageInfoEvent, -7)
DECLARE_EVENT_TYPE(refreshAOIControls, -8)
DECLARE_EVENT_TYPE(refreshCurrentPixelData, -9)

//-----------------------------------------------------------------------------
struct ImageAnalysisPlotControls
//-----------------------------------------------------------------------------
{
	wxCheckBox*					m_pCBAOIFullMode;
	wxSpinCtrl*					m_pSCAOIx;
	wxSpinCtrl*					m_pSCAOIy;
	wxSpinCtrl*					m_pSCAOIw;
	wxSpinCtrl*					m_pSCAOIh;
	wxSpinCtrl*					m_pSCDrawStart_percent;
	wxSpinCtrl*					m_pSCDrawWindow_percent;
	wxSpinCtrl*					m_pSCDrawStepWidth;
	wxSpinCtrl*					m_pSCUpdateSpeed;
	wxSpinCtrl*					m_pSCGridStepsX;
	wxSpinCtrl*					m_pSCGridStepsY;
	wxNotebook*					m_pNBDisplayMethod;
	ImageAnalysisPlotCanvas*	m_pPlotCanvas;
	void						Load( wxConfigBase* pConfig );
	void						Save( wxConfigBase* pConfig );
	void						UpdateControls( void );
	explicit ImageAnalysisPlotControls() : m_pCBAOIFullMode(0),
		m_pSCAOIx(0), m_pSCAOIy(0), m_pSCAOIw(0), m_pSCAOIh(0), m_pSCDrawStart_percent(0),
		m_pSCDrawWindow_percent(0), m_pSCDrawStepWidth(0), m_pSCUpdateSpeed(0), 
		m_pSCGridStepsX(0), m_pSCGridStepsY(0), m_pNBDisplayMethod(0), m_pPlotCanvas(0) {}
};

class MonitorDisplay;

//-----------------------------------------------------------------------------
class PropViewFrame : public wxFrame
//-----------------------------------------------------------------------------
{
public:
	explicit PropViewFrame( const wxString& title, const wxPoint& pos, const wxSize& size, int argc, wxChar** argv );
	~PropViewFrame();
	bool SetCurrentImage( const wxString& fileName );
protected:
	// event handlers (these functions should _not_ be virtual)
	void OnAbout( wxCommandEvent& e );
	void OnActivateDisplay( wxCommandEvent& e );
	void OnBtnAbort( wxCommandEvent& e );
	void OnBtnLive( wxCommandEvent& e );
	void OnBtnRecord( wxCommandEvent& e );
	void OnIncDecRecordDisplay( wxCommandEvent& e );
	void OnUseDevice( wxCommandEvent& e );
	void OnBtnSnap( wxCommandEvent& e );
	void OnAnalysisPlotCBAOIFullMode( wxCommandEvent& e );
	void OnCBEnableInfoPlot( wxCommandEvent& );
	void OnClose( wxCloseEvent& e );
	void OnConnectedOnly( wxCommandEvent& e );
	void OnContinuousRecording( wxCommandEvent& e );
	void OnDevComboTextChanged( wxCommandEvent& e );
	void OnEventNotified( wxCommandEvent& e );
	void OnExportActiveDevice( wxCommandEvent& e );
	void OnFitToDisplay( wxCommandEvent& e );
	void OnAnalysisPlotAOIxChanged( wxSpinEvent& e );
	void OnAnalysisPlotAOIxTextChanged( wxCommandEvent& e );
	void OnAnalysisPlotAOIyChanged( wxSpinEvent& e );
	void OnAnalysisPlotAOIyTextChanged( wxCommandEvent& e );
	void OnAnalysisPlotAOIwChanged( wxSpinEvent& e );
	void OnAnalysisPlotAOIwTextChanged( wxCommandEvent& e );
	void OnAnalysisPlotAOIhChanged( wxSpinEvent& e );
	void OnAnalysisPlotAOIhTextChanged( wxCommandEvent& e );
	void OnAnalysisPlotDrawStartChanged( wxSpinEvent& e );
	void OnAnalysisPlotDrawStartTextChanged( wxCommandEvent& e );
	void OnAnalysisPlotDrawWindowChanged( wxSpinEvent& e );
	void OnAnalysisPlotDrawWindowTextChanged( wxCommandEvent& e );
	void OnAnalysisPlotDrawStepWidthChanged( wxSpinEvent& e );
	void OnAnalysisPlotDrawStepWidthTextChanged( wxCommandEvent& e );
	void OnAnalysisPlotGridXStepsChanged( wxSpinEvent& e );
	void OnAnalysisPlotGridXStepsTextChanged( wxCommandEvent& e );
	void OnAnalysisPlotGridYStepsChanged( wxSpinEvent& e );
	void OnAnalysisPlotGridYStepsTextChanged( wxCommandEvent& e );
	void OnAnalysisPlotUpdateSpeedChanged( wxSpinEvent& e );
	void OnAnalysisPlotUpdateSpeedTextChanged( wxCommandEvent& e );
	void OnImageInfo( wxCommandEvent& e );
	void OnImageReady( wxCommandEvent& e );
	void OnImageSkipped( wxCommandEvent& e );
	void OnImportActiveDevice( wxCommandEvent& e );
	void OnInfoPlot_PlotSelectionComboTextChanged( wxCommandEvent& e );
	void OnInfoPlotUpdateHistoryDepthChanged( wxSpinEvent& e );
	void OnInfoPlotUpdateHistoryDepthTextChanged( wxCommandEvent& e );
	void OnInfoPlotUpdateSpeedChanged( wxSpinEvent& e );
	void OnInfoPlotUpdateSpeedTextChanged( wxCommandEvent& e );
	void OnLiveModeAborted( wxCommandEvent& e );
	void OnLoadCurrentProduct( wxCommandEvent& e );
	void OnLoadActiveDevice( wxCommandEvent& e );
	void OnLoadFromDefault( wxCommandEvent& e );
	void OnManageSettings( wxCommandEvent& e );
	void OnNotebookPageChanged( wxNotebookEvent& e );
	void OnNBDisplayMethodPageChanged( wxNotebookEvent& e );
	void OnPopUpMethExec( wxCommandEvent& e );
	void OnPopUpPropRestoreDefault( wxCommandEvent& e );
	void OnPopUpPropAppendValue( wxCommandEvent& e );
	void OnPopUpPropDeleteValue( wxCommandEvent& e );
	void OnPopUpPropSetMultiple_FixedValue( wxCommandEvent& e );
	void OnPopUpPropSetMultiple_FromToRange( wxCommandEvent& e );
	void OnPropertyChanged( wxPropertyGridEvent& e );
	void OnPropertyRightClicked( wxPropertyGridEvent& e );
	void OnQuit( wxCommandEvent& e );
	void OnRefreshAOIControls( wxCommandEvent& e );
	void OnRefreshCurrentPixelData( wxCommandEvent& e );
	void OnSaveActiveDevice( wxCommandEvent& e );
	void OnSaveCurrentProduct( wxCommandEvent& e );
	void OnLoadImage( wxCommandEvent& e );
	void OnSaveImage( wxCommandEvent& e );
	void OnSaveImageSequence( wxCommandEvent& e );
	void OnSaveToDefault( wxCommandEvent& e );
	void OnSaveSystemToDefault( wxCommandEvent& e );
	void OnSequenceReady( wxCommandEvent& e );
	void OnSettings_Analysis_ShowControls( wxCommandEvent& );
	void OnSettingsPropGrid_Show( wxCommandEvent& );
	void OnSettingsPropGrid_DisplayPropIndicesAsHex( wxCommandEvent& );
	void OnSettingsPropGrid_StandardView( wxCommandEvent& );
	void OnSettingsPropGrid_DevelopersView( wxCommandEvent& );
	void OnSetupCaptureQueueDepth( wxCommandEvent& e );
	void OnSetupRecordSequenceSize( wxCommandEvent& e );
	void OnShowDisplayMessagesAsOverlay( wxCommandEvent& e );
	void OnShowIncompleteFrames( wxCommandEvent& e );
	void OnShowRequestInfosAsOverlay( wxCommandEvent& e );
	void OnShowMonitorDisplay( wxCommandEvent& e );
	void OnShowStatusBar( wxCommandEvent& e );
	void OnShowToolBar( wxCommandEvent& e );
	void OnSize( wxSizeEvent& e );
	void OnSLRecordDisplay( wxScrollEvent& e );
	void OnSplitterSashPosChanged( wxSplitterEvent& e );
	void OnTimer( wxTimerEvent& e );
	void OnToggleDisplayWindowSize( wxCommandEvent& e );
	void OnUpdateDeviceList( wxCommandEvent& e );
	void SetupDlgControls( void );
private:
	//-----------------------------------------------------------------------------
	enum TTimerEvent
	//-----------------------------------------------------------------------------
	{
		teListUpdate
	};
	//-----------------------------------------------------------------------------
	// IDs for the controls and the menu commands
	enum TMenuItem
	//-----------------------------------------------------------------------------
	{
		miQuit = 1,
		miHelp_About,
		miAction_UseDevice,
		miAction_Settings_Save_ToDefault,
		miAction_Settings_Save_CurrentProduct,
		miAction_Settings_Save_SystemToDefault,
		miAction_Settings_Save_ActiveDevice,
		miAction_Settings_Save_ExportActiveDevice,
		miAction_Settings_Load_FromDefault,
		miAction_Settings_Load_CurrentProduct,
		miAction_Settings_Load_ActiveDevice,
		miAction_Settings_Load_ImportActiveDevice,
		miAction_Settings_Manage,
		miAction_LoadImage,
		miAction_SaveImage,
		miAction_SaveImageSequence,
		miAction_UpdateDeviceList,
		miPopUpMethExec,
		miPopUpPropRestoreDefault,
		miPopUpPropAppendValue,
		miPopUpPropDeleteValue,
		miPopUpPropSetMultiple,
		miPopUpPropSetMultiple_FixedValue,
		miPopUpPropSetMultiple_FromToRange,
		miCapture_Live,
		miCapture_Snap,
		miCapture_Abort,
		miCapture_Record,
		miCapture_Forward,
		miCapture_Backward,
		miCapture_SetupCaptureQueueDepth,
		miSettings_PropGrid_Show,
		miSettings_PropGrid_DisplayPropIndicesAsHex,
		miSettings_PropGrid_StandardView,
		miSettings_PropGrid_DevelopersView,
		miSettings_Display_Active,
		miSettings_Display_FitToScreen,
		miSettings_Display_ShowMonitorImage,
		miSettings_Display_ShowOverlayMessages,
		miSettings_Display_ShowRequestInfoAsOverlay,
		miSettings_Display_ShowIncompleteFrames,
		miSettings_Recording_SilentMode,
		miSettings_Recording_Continuous,
		miSettings_Recording_SetupSequenceSize,
		miSettings_ShowToolBar,
		miSettings_ShowStatusBar,
		miSettings_ShowConnectedDevicesOnly,
		miSettings_Analysis_ShowControls
	};
	//-----------------------------------------------------------------------------
	enum TWidgetIDs
	//-----------------------------------------------------------------------------
	{
		widBtnAbort = 1,
		widBtnLive,
		widBtnUseDevice,
		widBtnSnap,
		widStatusBar,
		widVerSplitter,
		widDevCombo,
		widHorSplitter,
		widLogHistogramSplitter,
		widMainFrame,
		widPropGrid,
		widInfoPlot_PlotSelectionCombo,
		widCBEnableInfoPlot,
		widSCInfoPlotUpdateSpeed,
		widSCInfoPlotHistoryDepth,
		widSLRecordDisplay,
		widNotebook,

		widPixelHistogram = 0x100,
		widNoiseHistogram = 0x200,
		widLineProfile = 0x300,
		widVectorScope = 0x400
	};
	//-----------------------------------------------------------------------------
	enum TImageAnalysisPlotIDs
	//-----------------------------------------------------------------------------
	{
		iapidCBAOIFullMode,
		iapidSCAOIx,
		iapidSCAOIy,
		iapidSCAOIw,
		iapidSCAOIh,
		iapidSCDrawStart_percent,
		iapidSCDrawWindow_percent,
		iapidSCDrawStepWidth,
		iapidSCGridStepsX,
		iapidSCGridStepsY,
		iapidSCUpdateSpeed,
		iapidNBDisplayMethod
	};
	//-----------------------------------------------------------------------------
	enum TImageAnalysisPlot
	//-----------------------------------------------------------------------------
	{
		iapPixelHistogram,
		iapNoiseHistogram,
		iapLineProfile,
		iapVectorScope,
		iapLAST
	};
	//-----------------------------------------------------------------------------
	enum
	//-----------------------------------------------------------------------------
	{
		TIMER_PERIOD = 750
	};
	//-----------------------------------------------------------------------------
	enum TStatusBarField
	//-----------------------------------------------------------------------------
	{
		sbfFPS,
		sbfFrameCount,
		sbfImageFormat,
		sbfErrorCount,
		sbfExposeTime,
		sbfGain,
		sbfPixelData,
		NO_OF_STATUSBAR_FIELDS
	};
	ImageAnalysisPlotControls			m_ImageAnalysisPlots[iapLAST];
	wxScrolledWindow* CreateImageAnalysisPlotControls( wxWindow* pParent, int windowIDOffset );
	bool								m_boCloseDeviceInProgress;
	bool								m_boDisplayWindowMaximized;
	bool								m_boShutdownInProgress;
	bool								m_boUpdateAOIInProgress;
	bool								m_boCurrentImageIsFromFile;
	RequestData							m_CurrentRequestData;
	int									m_CurrentImageAnalysisControlIndex;
	unsigned int						m_DeviceListChangedCounter;
	int									m_HorizontalSplitterPos;
	wxTimer								m_ListUpdateTimer;
	const wxString						m_NoDevStr;
	wxCheckBox*							m_pCBEnableInfoPlot;
	wxTextCtrl*							m_pTCTimestampAsTime;
	wxComboBox*							m_pDevCombo;
	wxSlider*							m_pRecordDisplaySlider;
	DevicePropertyHandler*				m_pDevPropHandler;
	ImageCanvas*						m_pDisplayArea;
	MonitorDisplay*						m_pMonitorImage;
	wxSplitterWindow*					m_pHorizontalSplitter;
	InfoPlotCanvas*						m_pInfoPlotArea;
	wxComboBox*							m_pInfoPlotSelectionCombo;
	wxTextCtrl*							m_pLogWindow;
	wxNotebook*							m_pLowerRightWindow;
#ifdef BUILD_WITH_PLUGIN_SUPPORT
	PluginManager						m_pluginManager;
#endif // #ifdef BUILD_WITH_PLUGIN_SUPPORT
	wxMenuItem*							m_pMIAction_Use;
	wxMenuItem*							m_pMIAction_Settings_Save_ToDefault;
	wxMenuItem*							m_pMIAction_Settings_Save_SystemToDefault;
	wxMenuItem*							m_pMIAction_Settings_Save_CurrentProduct;
	wxMenuItem*							m_pMIAction_Settings_Save_ActiveDevice;
	wxMenuItem*							m_pMIAction_Settings_Save_ExportActiveDevice;
	wxMenuItem*							m_pMIAction_Settings_Load_FromDefault;
	wxMenuItem*							m_pMIAction_Settings_Load_CurrentProduct;
	wxMenuItem*							m_pMIAction_Settings_Load_ActiveDevice;
	wxMenuItem*							m_pMIAction_Settings_Load_ImportActiveDevice;
	wxMenuItem*							m_pMIAction_Settings_Manage;
	wxMenuItem*							m_pMIAction_LoadImage;
	wxMenuItem*							m_pMIAction_SaveImage;
	wxMenuItem*							m_pMIAction_SaveImageSequence;
	wxMenuItem*							m_pMIAction_UpdateDeviceList;
	wxMenuItem*							m_pMICapture_Live;
	wxMenuItem*							m_pMICapture_Snap;
	wxMenuItem*							m_pMICapture_Abort;
	wxMenuItem*							m_pMICapture_Record;
	wxMenuItem*							m_pMICapture_Forward;
	wxMenuItem*							m_pMICapture_Backward;
	wxMenuItem*							m_pMICapture_SetupCaptureQueueDepth;
	wxMenuItem*							m_pMISettings_Display_Active;
	wxMenuItem*							m_pMISettings_Display_FitToScreen;
	wxMenuItem*							m_pMISettings_Display_ShowMonitorImage;
	wxMenuItem*							m_pMISettings_Display_ShowMessagesAsOverlay;
	wxMenuItem*							m_pMISettings_Display_ShowRequestInfoAsOverlay;
	wxMenuItem*							m_pMISettings_Display_ShowIncompleteFrames;
	wxMenuItem*							m_pMISettings_Recording_SlientMode;
	wxMenuItem*							m_pMISettings_Recording_Continuous;
	wxMenuItem*							m_pMISettings_Recording_SetupSequenceSize;
	wxMenuItem*							m_pMISettings_ShowConnectedOnly;
	wxMenuItem*							m_pMISettings_Analysis_ShowControls;
	wxMenuItem*							m_pMISettings_Analysis_SynchroniseAOIs;
	wxMenuItem*							m_pMISettings_PropGrid_Show;
	wxMenuItem*							m_pMISettings_PropGrid_DisplayPropIndicesAsHex;
	wxMenuItem*							m_pMISettings_PropGrid_StandardView;
	wxMenuItem*							m_pMISettings_PropGrid_DevelopersView;
	wxMenuItem*							m_pMISettings_ShowToolBar;
	wxMenuItem*							m_pMISettings_ShowStatusBar;
	wxPanel*							m_pPanel;
	wxPropertyGrid*						m_pPropGrid;
	wxSpinCtrl*							m_pSCInfoPlotHistoryDepth;
	wxSpinCtrl*							m_pSCInfoPlotUpdateSpeed;
	wxStatusBar*						m_pStatusBar;
	wxToolBar*							m_pToolBar;
	wxSplitterWindow*					m_pVerticalSplitter;
	int									m_VerticalSplitterPos;
	DevicePropertyHandler::TViewMode	m_ViewMode;
	void								Abort( void );
	void								AnalysisPlotUpdateSpeedChanged( void );
	void								ConfigureAnalysisPlot( const wxRect* pAOI = 0 );
	void								ConfigureAOI( ImageAnalysisPlotControls& controls, const wxRect& rect );
	void								ConfigureAOIControlLimits( ImageAnalysisPlotControls& controls );
	void								ConfigureLive( void );
	void								ConfigureSplitter( wxSplitterWindow* pSplitter, wxWindow* pWindowToRemove, wxWindow* pWindowToShow );
	void								ConfigureStatusBar( bool boShow );
	void								ConfigureToolBar( bool boShow );
	void								Deinit( void );
	ImageAnalysisPlotCanvas*			DeselectAnalysisPlot( void );
	int									GetAnalysisControlIndex( void ) const;
	int									GetAnalysisControlIndex( int windowID ) const;
	void								RefreshCurrentPixelData( void );
	template<class _Ty>
	void RegisterAnalysisPlot( int index, const wxColour& AOIColour );
	void								SaveImage( const wxString& filenameAndPath, int fileFilterIndex );
	void								SetupDisplayLogSplitter( bool boForceSplit = false );
	void								SetupUpdateFrequencies( bool boCurrentValue );
	void								SetupVerSplitter( bool boSplit );
	void								UpdateDeviceComboBox( void );
	void								UpdateDeviceFromComboBox( void );
	void								UpdateData( bool boShowInfo = false );
	void								UpdateStatusBar( void );
	void								UpdateTitle( void );
	void								UpdatePropGridSplitter( void );
	void								ToggleCurrentDevice( void );
	void								WriteLogMessage( const wxString& msg, const wxTextAttr& style = wxTextAttr(*wxBLACK) );
	void								WriteErrorMessage( const wxString& msg );
	// any class wishing to process wxWidgets events must use this macro
	DECLARE_EVENT_TABLE()
};

#endif // DeviceConfigureFrameH
