///////////////////////////////////////////////////////////
// File:			rr_dlg_preproc.h
//
// Author:			Stefan Liersch
// Contact:			stefan.liersch@googlemail.com,
//					stefan.liersch@ufz.de
//
// Date:			2007-08-10
// last modified:	2007-09-02
//
//---------------------------------------------------------
// DESCRIPTION
//---------------------------------------------------------
// DIALOG for
// Preprocessing time series data for rainfall-runoff models
//
//---------------------------------------------------------
// ToDo
//---------------------------------------------------------
// 
//
///////////////////////////////////////////////////////////

//---------------------------------------------------------

#ifndef __RR_DLG_PREPROCESSING_H__
#define __RR_DLG_PREPROCESSING_H__

#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
    #pragma interface "rr_dlg_preproc"
#endif

// Include wxWidgets' headers
#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

#include "wx/datetime.h"
#include <wx/arrstr.h>

#include "saga_gui/wksp_simplefeature.h"
#include "saga_gui/res_commands.h"

#include "hydrology/rr_preprocessing.h"
#include "hydrology/pg_timeseries.h"
#include "pgsql/pgdatabase.h"	// CLU_Table, database functions
#include "pgsql/pg_lu_table.h"

//---------------------------------------------------------

class Crr_dlg_preproc : public wxDialog
{
public:
	Crr_dlg_preproc(wxWindow *parent, wxWindowID id, const wxString &title);
	Crr_dlg_preproc();

	~Crr_dlg_preproc();

	// following three functions are maybe not necessary anymore
	const char*			Get_Discharge_Name();
	wxArrayString		Get_PCP_Names();
	wxArrayString		Get_TMP_Names();

	void				Create_DLG_Weight(CTimeSeries *pTS, wxChoice *choice);

	CSG_SimpleFeature	*Get_ActiveFeature();
	CWKSP_SimpleFeature	*Get_ActiveWKSP_Shapes(CSG_SimpleFeature *pSimpleFeature);
	wxString			Get_LUT_Name(CWKSP_SimpleFeature *pWKSP_SimpleFeature, int &PK_ColumnNumber, wxString &PK_ColumnName);
	int					*Get_StationIDs(CSG_SimpleFeature *pSimpleFeature, int* ID, int &nIDs, int PK_ColumnNumber);
	void				Assign_TimeSeries(CLU_Table4Col *LUT, int nTS, CTimeSeries *ts);

	// Time Series Functions
	wxDateTime			Get_Begin(const char* tablename, const char* date_col);
	wxDateTime			Get_End(const char* tablename, const char* date_col);

private:

	void				_CreateDlg();
	void				_ZeroAll();

	// Event Table Functions
	void				_On_Button_Select_Discharge(wxCommandEvent& event);
	void				_On_Button_Select_precipitation(wxCommandEvent& event);
	void				_On_Button_Select_temperature(wxCommandEvent& event);
	void				_On_Button_Weight_TS1(wxCommandEvent& event);
	void				_On_Button_Weight_TS2(wxCommandEvent& event);
	void				_On_Button_GetTimeSeries(wxCommandEvent &event);
	void				_On_Button_OK(wxCommandEvent& event);

	//bool				_Select_Init(CSG_SimpleFeature *pSimpleFeature, CWKSP_Shapes *pWKSP_Shapes, wxString &LUT_Name,
	//							   int &PK_ColumnNumber, wxString &PK_ColumnName);

	// Time series functions
	void				_Create_TimeSeries();
	wxArrayString		_Get_TimeSeriesNames(CWKSP_SimpleFeature *pWKSP_SimpleFeature, CSG_SimpleFeature *pSimpleFeature,
											 wxString LUT_Name, int PK_ColumnNumber, wxString PK_ColumnName);

	// look up table
	CLU_Table4Col		*m_LUT_discharge,
						*m_LUT_pcp,
						*m_LUT_tmp;

	// Time series variables
	CTimeSeries			*m_pDischarge;
	CTimeSeries			*m_pPCP;
	CTimeSeries			*m_pTMP;

	// Controls
	wxTextCtrl			*m_pTextCtrl_Discharge;
	wxButton			*m_pButSelectDischarge;
	wxChoice			*m_pChoicePCP;
	wxButton			*m_pButSelectPCP;
	wxChoice			*m_pChoiceTMP;
	wxButton			*m_pButSelectTMP;
	wxButton			*m_pButOK;
	wxButton			*m_pButGetTimeSeries;
	wxBitmapButton		*m_pButWeight_TS1;
	wxBitmapButton		*m_pButWeight_TS2;

	DECLARE_EVENT_TABLE()
};


#endif /*__RR_DLG_PREPROCESSING_H__*/