///////////////////////////////////////////////////////////
// Author:			Stefan Liersch
// Contact:			stefan.liersch@googlemail.com,
//					stefan.liersch@ufz.de
//
// Date:			2008-03-14
// last modified:	2008-03-14
//
//---------------------------------------------------------
// DESCRIPTION
//---------------------------------------------------------
//
//---------------------------------------------------------
// ToDo
//---------------------------------------------------------
//	- if a new feature is selected in the dialog the selection
//		is displayed in the shape view, but not in the corresponding table
//	- the assignment of parameter 'number of leaching" is still questionable
//		and maybe too coarse yet. Additionally we might have a problem if 
//		the number of leaching was limited by water availability and not
//		due to low salinization,
//		as assumed in our equation the lower the number of leaching the lesser
//		salinized was the soil.
//	- dialog weighting factors is required
//	- delete used controls in destructor
///////////////////////////////////////////////////////////

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

#ifndef __PG_SOIL_SALINITY_DLG_H_
#define __PG_SOIL_SALINITY_DLG_H_

#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
    #pragma interface "pg_soil_salinity_dlg.h"
#endif

#include "pg_soil_salinity_dlg_base.h"
#include "soil_salinity/soil_salinity_assessment.h"
#include "pg_soil_salinity_weights_dlg.h"

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

enum cmd_id_ssa {
	ID_CMD_SSA_COMBO_ID = 10000,
	ID_CMD_SSA_COMBO_FIELD,
	ID_CMD_SSA_TXT_YEAR,
	ID_CMD_SSA_COMBO_MONTH,
	ID_CMD_SSA_COMBO_PLANT,
	ID_CMD_SSA_BUTTON_LOAD_SETTINGS,
	ID_CMD_SSA_BUTTON_WEIGHTS,

	ID_CMD_SSA_CHECK_SOIL_COLOUR_LOCAL,
	ID_CMD_SSA_SLIDER_SOIL_COLOUR_LOCAL,
	ID_CMD_SSA_CHECK_LEACHING,
	ID_CMD_SSA_COMBO_nLEACHING,
	ID_CMD_SSA_CHECK_WQ_LEACHING,
	ID_CMD_SSA_SLIDER_WATERQUALITYLEACHING,
	ID_CMD_SSA_CHECK_WQ_IRRIGATION,
	ID_CMD_SSA_SLIDER_WATERQUALITYIRRIGATION,
	ID_CMD_SSA_CHECK_WATERVOLUME_IRRIGATION,
	ID_CMD_SSA_COMBO_WATERVOLUMEIRRIGATION,
	ID_CMD_SSA_CHECK_EVENNESS,
	ID_CMD_SSA_CMD_SLIDER_EVENNESS,
	ID_CMD_SSA_CHECK_MOPRPHOLOGY,
	ID_CMD_SSA_COMBO_MORPHOLOGY,

	ID_CMD_SSA_CHECK_SOIL_TEXTURE,
	ID_CMD_SSA_SLIDER_SOIL_TEXTURE,
	ID_CMD_SSA_CHECK_PLANT_GROWTH,
	ID_CMD_SSA_SLIDER_PLANTGROWTH,
	ID_CMD_SSA_CHECK_GW_SALINITY,
	ID_CMD_SSA_SLIDER_GW_SALINITY,
	ID_CMD_SSA_CHECK_GW_LEVEL,
	ID_CMD_SSA_COMBO_GW_LEVEL,
	ID_CMD_SSA_CHECK_N_CHANNELS,
	ID_CMD_SSA_COMBO_N_CHANNELS,
	ID_CMD_SSA_CHECK_DISTANCE,
	ID_CMD_SSA_COMBO_CHANNEL_DISTANCE,
	ID_CMD_SSA_CHECK_MAINTENANCE,
	ID_CMD_SSA_COMBO_MAINTENANCE,
	ID_CMD_SSA_BUTTON_CALC_SALINITY,
	ID_CMD_SSA_TXTCTRL_SALINITY_VALUE,
	ID_CMD_SSA_TXTCTRL_MSLOW,
	ID_CMD_SSA_TXTCTRL_MSMEDIUM,
	ID_CMD_SSA_TXTCTRL_MSHIGH,
	ID_CMD_SSA_BUTTON_SAVE,
	ID_CMD_SSA_SLIDER_SHOW_SALINITY
};

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

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

class CSoilSalinityAssessmentDlg : public wxDialog, public CSoilSalinityDlgBase
{
public:
	CSoilSalinityAssessmentDlg();
	CSoilSalinityAssessmentDlg(wxWindow *parent, wxWindowID id, const wxString &title);
	CSoilSalinityAssessmentDlg(CSoilSalinityMap* pSSMap, wxWindow *parent, wxWindowID id, const wxString &title);

	~CSoilSalinityAssessmentDlg();

	//-----------------------------------------------------------------
	// PUBLIC GET FUNCTIONS
	//-----------------------------------------------------------------

	int							Get_SoilCoulourLocal()	{ return(m_pSlider_SoilColour_Local->GetValue()); }
	int							Get_nLeaching()			{ return(m_pCombo_nLeaching->GetCurrentSelection()); }
	int							Get_WaterQualityLeaching()	{ return(m_pSlider_WaterQualityLeaching->GetValue()); }
	int							Get_WaterQualityIrrigation(){ return(m_pSlider_WaterQualityIrrigation->GetValue()); }

	int							Get_SoilTexture()		{ return(m_pSlider_SoilTexture->GetValue()); } 
	int							Get_PlantGrowth()		{ return(m_pSlider_PlantGrowth->GetValue()); }

private:

	//-----------------------------------------------------------------
	// PRIVATE MEMBER VARIABLES
	//-----------------------------------------------------------------

	// m_zero_ok is necessary to avoid function call _Zero_Controls()
	// while creating the dialog
	bool						m_zero_ok;

	//-----------------------------------------------------------------
	// PRIVATE MEMBER FUNCTIONS
	//-----------------------------------------------------------------
	void						_Resize_Vectors();
	void						_Resize(int size);

	void						_Assign_Settings();
	void						_Assign_Parms();
	void						_Assign_ParmsChecked();

	double						_Assign_LeachingValue();
	double						_Assign_WaterVolumeIrrigation();
	double						_Assign_Morphology();
	double						_Assign_GW_Level();
	double						_Assign_nChannels();
	double						_Assign_3Selections(int selection);

	CSG_String					_Get_InsertString();
	CSG_String					_Get_InsertString_Settings();
	CSG_String					_Get_Message_Exist();
	CSG_String					_Get_SQL_Update_Record(int pk_colnumber);
	CSG_String					_Get_SQL_Update_Settings(int pk_colnumber);
	void						_Delete_Controls();

	int							_Get_PK_for_settings(int fid, int year, CSG_String month);
	CSG_String					_Get_SQL_Load_Settings(int pk);
	void						_Set_Settings();

	//-----------------------------------------------------------------
	// EVENT HANDLER FUNCTIONS
	//-----------------------------------------------------------------
	void						_On_Change_ID_Column(wxCommandEvent &event);
	
	void						_On_Change_Feature(wxCommandEvent& event);
	
	void						_On_Button_Load_Settings(wxCommandEvent& event);

	void						_On_Button_Weights(wxCommandEvent& event);

	void						_On_Save(wxCommandEvent& event);
	
	void						_On_Button_CalcSalinity(wxCommandEvent& event);

	void						_On_Slider_ZeroSalinityValues(wxCommandEvent& event);

	void						_On_Slider_nChannels(wxCommandEvent& even);

	//-----------------------------------------------------------------
	// DIALOG LAYOUT RELATED FUNCTIONS
	//-----------------------------------------------------------------
	void						_CreateDialog(CSG_SimpleFeature* pSimpleFeature);
	wxArrayString				_Get_Plants();
	void						_Refresh_Plants();

	bool						_Record_Exists(int &pk_colnumber);

	void						_Zero_Controls();

	void						_On_Change_nChannels();


	//-----------------------------------------------------------------
	//
	//	DIALOG CONTROLS
	//
	//-----------------------------------------------------------------

	//-----------------------------------------------------------------
	// Main Settings
	//-----------------------------------------------------------------

	wxComboBox*					m_pCombo_ID;
	
	wxComboBox*					m_pCombo_Field;
	
	wxTextCtrl*					m_pTxtCtrl_Year;
	
	wxComboBox*					m_pCombo_Month;

	wxComboBox*					m_pCombo_Plant;

	wxButton*					m_pButton_LoadSettings;

	wxButton*					m_pButton_Weights;
	//-----------------------------------------------------------------
	// Soil Salinity (local knowledge)
	//-----------------------------------------------------------------

	wxCheckBox*					m_pCheck_SoilColour;
	wxSlider*					m_pSlider_SoilColour_Local;
	
	wxCheckBox*					m_pCheck_Leaching;
	wxComboBox*					m_pCombo_nLeaching;

	wxCheckBox*					m_pCheck_WQ_Leaching;
	wxSlider*					m_pSlider_WaterQualityLeaching;
	
	wxCheckBox*					m_pCheck_WQ_Irrigation;
	wxSlider*					m_pSlider_WaterQualityIrrigation;
	
	wxCheckBox*					m_pCheck_WaterVolume_Irrigation;
	wxComboBox*					m_pCombo_WaterVolumeIrrigation;
	
	wxCheckBox*					m_pCheck_Evenness;
	wxSlider*					m_pSlider_Evenness;
	
	wxCheckBox*					m_pCheck_Morphology;
	wxComboBox*					m_pCombo_Morphology;

	//-----------------------------------------------------------------
	// Soil Salinity (expert knowledge)
	//-----------------------------------------------------------------

	wxCheckBox*					m_pCheck_SoilTexture;
	wxSlider*					m_pSlider_SoilTexture;

	wxCheckBox*					m_pCheck_PlantGrowth;
	wxSlider*					m_pSlider_PlantGrowth;

	wxCheckBox*					m_pCheck_GW_Salinity;
	wxSlider*					m_pSlider_GW_Salinity;

	wxCheckBox*					m_pCheck_GW_Level;
	wxComboBox*					m_pCombo_GW_Level;

	wxCheckBox*					m_pCheck_nChannels;
	wxComboBox*					m_pCombo_nChannels;
		
	wxCheckBox*					m_pCheck_Distance;
	wxComboBox*					m_pCombo_ChannelDistance;
	
	wxCheckBox*					m_pCheck_Maintenance;
	wxComboBox*					m_pCombo_Maintenance;

	//-----------------------------------------------------------------
	// Calculate Soil Salinity
	//-----------------------------------------------------------------

	wxButton*					m_pButton_CalcSalinity;
	
	wxTextCtrl*					m_pTxtCtrl_SalinityValue;
	
	wxTextCtrl*					m_pTxtCtrl_SalinityClass;
	
	wxTextCtrl*					m_pTxtCtrl_SalinityValueLocal;

	wxTextCtrl*					m_pTxtCtrl_SalinityValueExpert;

	wxTextCtrl*					m_pTxtCtrl_MSLow;
	
	wxTextCtrl*					m_pTxtCtrl_MSMedium;
	
	wxTextCtrl*					m_pTxtCtrl_MSHigh;

	wxSlider*					m_pSliderShowSalinity;
	//-----------------------------------------------------------------

	wxButton*					m_pButton_Save;
	wxButton*					m_pButton_Cancel;

//---------------------------------------------------------------------
	DECLARE_EVENT_TABLE()
};

#endif /* __PG_SOIL_SALINITY_DLG_H_ */