///////////////////////////////////////////////////////////
// Author:			Stefan Liersch
// Contact:			stefan.liersch@googlemail.com,
//					stefan.liersch@ufz.de
//
// Date:			2008-09-18
// last modified:	2008-09-18
//
//---------------------------------------------------------
// DESCRIPTION
//---------------------------------------------------------
//
//---------------------------------------------------------
// ToDo
//---------------------------------------------------------
//	- 
///////////////////////////////////////////////////////////

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

#include "pg_soil_salinity_weights_dlg.h"

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

BEGIN_EVENT_TABLE(CSoilSalinityParameterWeightsDlg, wxDialog)
	EVT_BUTTON(ID_CMD_SSW_BUTTON_LOAD_DEFAULT,		_On_Button_Load_Default)
	EVT_BUTTON(ID_CMD_SSW_BUTTON_SAVE,				_On_Button_Save)
END_EVENT_TABLE()

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

CSoilSalinityParameterWeightsDlg::CSoilSalinityParameterWeightsDlg( CSoilSalinityMap* pSSMap, wxWindow* parent, wxWindowID id, const wxString& title)
	: wxDialog( parent, id, title, 
	  wxDefaultPosition, wxDefaultSize,
	  wxDEFAULT_DIALOG_STYLE),
	  CSoilSalinityDlgBase(pSSMap)
{
	_CreateDialog();
	_Load_Settings_From_DB();
}

CSoilSalinityParameterWeightsDlg::~CSoilSalinityParameterWeightsDlg()
{
	delete m_pSlider_SoilColour_local;
	delete m_pSlider_nLeaching;
	delete m_pSlider_WQ_Leaching;
	delete m_pSlider_WQ_Irrigation;
	delete m_pSlider_WV_Irrigation;
	delete m_pSlider_Evenness;
	delete m_pSlider_Morphology;
	delete m_pSlider_SoilTexture;
	delete m_pSlider_PlantGrowth;
	delete m_pSlider_GW_Salinity;
	delete m_pSlider_GW_Level;
	delete m_pSlider_nChannels;
	delete m_pSlider_Distance;
	delete m_pSlider_Maintanance;
	delete m_pButton_LoadDefault;
	delete m_pButtonSave;
	delete m_pButtonCancel;
}
//---------------------------------------------------------------------

void CSoilSalinityParameterWeightsDlg::_Load_Settings_From_DB()
{
	// set slider positions
	m_pSlider_SoilColour_local->SetValue(m_pSSMap->Get_Weight(0));
	m_pSlider_nLeaching->SetValue(m_pSSMap->Get_Weight(1));
	m_pSlider_WQ_Leaching->SetValue(m_pSSMap->Get_Weight(2));
	m_pSlider_WQ_Irrigation->SetValue(m_pSSMap->Get_Weight(3));
	m_pSlider_WV_Irrigation->SetValue(m_pSSMap->Get_Weight(4));
	m_pSlider_Evenness->SetValue(m_pSSMap->Get_Weight(5));
	m_pSlider_Morphology->SetValue(m_pSSMap->Get_Weight(6));
	m_pSlider_SoilTexture->SetValue(m_pSSMap->Get_Weight(7));
	m_pSlider_PlantGrowth->SetValue(m_pSSMap->Get_Weight(8));
	m_pSlider_GW_Salinity->SetValue(m_pSSMap->Get_Weight(9));
	m_pSlider_GW_Level->SetValue(m_pSSMap->Get_Weight(10));
	m_pSlider_nChannels->SetValue(m_pSSMap->Get_Weight(11));
	m_pSlider_Distance->SetValue(m_pSSMap->Get_Weight(12));
	m_pSlider_Maintanance->SetValue(m_pSSMap->Get_Weight(13));
}
//---------------------------------------------------------------------

void CSoilSalinityParameterWeightsDlg::_On_Button_Load_Default(wxCommandEvent &event)
{
	m_pSSMap->Set_Default_Weights();
	m_pSlider_SoilColour_local->SetValue(m_ParmWeights.SoilColourLocal);
	m_pSlider_nLeaching->SetValue(m_ParmWeights.nLeaching);
	m_pSlider_WQ_Leaching->SetValue(m_ParmWeights.WQ_Leaching);
	m_pSlider_WQ_Irrigation->SetValue(m_ParmWeights.WQ_Irrigation);
	m_pSlider_WV_Irrigation->SetValue(m_ParmWeights.WVolumeIrrigation);
	m_pSlider_Evenness->SetValue(m_ParmWeights.Evenness);
	m_pSlider_Morphology->SetValue(m_ParmWeights.Morphology);
	m_pSlider_SoilTexture->SetValue(m_ParmWeights.SoilTexture);
	m_pSlider_PlantGrowth->SetValue(m_ParmWeights.PlantGrowth);
	m_pSlider_GW_Salinity->SetValue(m_ParmWeights.GWSalinity);
	m_pSlider_GW_Level->SetValue(m_ParmWeights.GWLevel);
	m_pSlider_nChannels->SetValue(m_ParmWeights.nChannels);
	m_pSlider_Distance->SetValue(m_ParmWeights.Distance);
	m_pSlider_Maintanance->SetValue(m_ParmWeights.Maintanance);
}
//---------------------------------------------------------------------

void CSoilSalinityParameterWeightsDlg::_On_Button_Save(wxCommandEvent &event)
{
	// save current slider settings to weights table
	_Save_Settings();
}

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

void CSoilSalinityParameterWeightsDlg::_Save_Settings()
{
	vector_i weights;
	weights.resize(m_pSSMap->Get_NumberSSVariables());

	weights[0] = m_pSlider_SoilColour_local->GetValue();
	weights[1] = m_pSlider_nLeaching->GetValue();
	weights[2] = m_pSlider_WQ_Leaching->GetValue();
	weights[3] = m_pSlider_WQ_Irrigation->GetValue();
	weights[4] = m_pSlider_WV_Irrigation->GetValue();
	weights[5] = m_pSlider_Evenness->GetValue();
	weights[6] = m_pSlider_Morphology->GetValue();
	weights[7] = m_pSlider_SoilTexture->GetValue();
	weights[8] = m_pSlider_PlantGrowth->GetValue();
	weights[9] = m_pSlider_GW_Salinity->GetValue();
	weights[10] = m_pSlider_GW_Level->GetValue();
	weights[11] = m_pSlider_nChannels->GetValue();
	weights[12] = m_pSlider_Distance->GetValue();
	weights[13] = m_pSlider_Maintanance->GetValue();

	m_pSSMap->Update_Weights(weights);
}
//---------------------------------------------------------------------



//---------------------------------------------------------------------
//
//	DIALOG
//
//---------------------------------------------------------------------

void CSoilSalinityParameterWeightsDlg::_CreateDialog()
{
	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
	
	wxBoxSizer* mainSizer;
	mainSizer = new wxBoxSizer( wxVERTICAL );
	
	wxStaticBoxSizer* sbSizer4;
	sbSizer4 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, wxEmptyString ), wxVERTICAL );
	
	wxBoxSizer* bSizer16;
	bSizer16 = new wxBoxSizer( wxHORIZONTAL );
	
	wxStaticText* m_staticText13 = new wxStaticText( this, wxID_ANY, wxT("Importance"), wxDefaultPosition, wxSize( 180,-1 ), 0 );
	m_staticText13->Wrap( -1 );
	m_staticText13->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), 70, 90, 92, false, wxEmptyString ) );
	
	bSizer16->Add( m_staticText13, 0, wxALL, 10 );
	
	wxStaticText* m_staticText14 = new wxStaticText( this, wxID_ANY, wxT("min"), wxDefaultPosition, wxSize( 50,-1 ), 0 );
	m_staticText14->Wrap( -1 );
	m_staticText14->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), 70, 90, 92, false, wxEmptyString ) );
	
	bSizer16->Add( m_staticText14, 0, wxALL, 10 );
	
	wxStaticText* m_staticText15 = new wxStaticText( this, wxID_ANY, wxT("max"), wxDefaultPosition, wxDefaultSize, 0 );
	m_staticText15->Wrap( -1 );
	m_staticText15->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), 70, 90, 92, false, wxEmptyString ) );
	
	bSizer16->Add( m_staticText15, 0, wxALL, 10 );
	
	sbSizer4->Add( bSizer16, 1, wxEXPAND, 5 );
	
	wxStaticBoxSizer* sbSizer1;
	sbSizer1 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, wxT("Soil Salinity Weights (local knowledge)") ), wxVERTICAL );
	
	wxBoxSizer* bSizer2;
	bSizer2 = new wxBoxSizer( wxHORIZONTAL );
	
	wxStaticText* m_staticText1 = new wxStaticText( this, wxID_ANY, wxT("Soil Colour (local)"), wxDefaultPosition, wxSize( 170,-1 ), 0 );
	m_staticText1->Wrap( -1 );
	bSizer2->Add( m_staticText1, 0, wxALL, 5 );
	
	
	bSizer2->Add( 10, 0, 1, wxEXPAND, 5 );
	
	m_pSlider_SoilColour_local = new wxSlider( this, ID_CMD_SSW_SLIDER_SOIL_COLOUR_LOCAL, 1, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL );
	bSizer2->Add( m_pSlider_SoilColour_local, 0, wxALL, 5 );
	
	sbSizer1->Add( bSizer2, 1, wxEXPAND, 5 );
	
	wxBoxSizer* bSizer3;
	bSizer3 = new wxBoxSizer( wxHORIZONTAL );
	
	wxStaticText* m_staticText2 = new wxStaticText( this, wxID_ANY, wxT("Number of Leaching"), wxDefaultPosition, wxSize( 170,-1 ), 0 );
	m_staticText2->Wrap( -1 );
	bSizer3->Add( m_staticText2, 0, wxALL, 5 );
	
	
	bSizer3->Add( 10, 0, 1, wxEXPAND, 5 );
	
	m_pSlider_nLeaching = new wxSlider( this, ID_CMD_SSW_SLIDER_nLeaching, 1, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL );
	bSizer3->Add( m_pSlider_nLeaching, 0, wxALL, 5 );
	
	sbSizer1->Add( bSizer3, 1, wxEXPAND, 5 );
	
	wxBoxSizer* bSizer31;
	bSizer31 = new wxBoxSizer( wxHORIZONTAL );
	
	wxStaticText* m_staticText21 = new wxStaticText( this, wxID_ANY, wxT("Water quality (leaching)"), wxDefaultPosition, wxSize( 170,-1 ), 0 );
	m_staticText21->Wrap( -1 );
	bSizer31->Add( m_staticText21, 0, wxALL, 5 );
	
	
	bSizer31->Add( 10, 0, 1, wxEXPAND, 5 );
	
	m_pSlider_WQ_Leaching = new wxSlider( this, ID_CMD_SSW_SLIDER_WQ_Leaching, 1, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL );
	bSizer31->Add( m_pSlider_WQ_Leaching, 0, wxALL, 5 );
	
	sbSizer1->Add( bSizer31, 1, wxEXPAND, 5 );
	
	wxBoxSizer* bSizer311;
	bSizer311 = new wxBoxSizer( wxHORIZONTAL );
	
	wxStaticText* m_staticText211 = new wxStaticText( this, wxID_ANY, wxT("Water quality (irrigation)"), wxDefaultPosition, wxSize( 170,-1 ), 0 );
	m_staticText211->Wrap( -1 );
	bSizer311->Add( m_staticText211, 0, wxALL, 5 );
	
	
	bSizer311->Add( 10, 0, 1, wxEXPAND, 5 );
	
	m_pSlider_WQ_Irrigation = new wxSlider( this, ID_CMD_SSW_SLIDER_WQ_Irrigation, 1, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL );
	bSizer311->Add( m_pSlider_WQ_Irrigation, 0, wxALL, 5 );
	
	sbSizer1->Add( bSizer311, 1, wxEXPAND, 5 );
	
	wxBoxSizer* bSizer3111;
	bSizer3111 = new wxBoxSizer( wxHORIZONTAL );
	
	wxStaticText* m_staticText2111 = new wxStaticText( this, wxID_ANY, wxT("Water used for irrigation"), wxDefaultPosition, wxSize( 170,-1 ), 0 );
	m_staticText2111->Wrap( -1 );
	bSizer3111->Add( m_staticText2111, 0, wxALL, 5 );
	
	
	bSizer3111->Add( 10, 0, 1, wxEXPAND, 5 );
	
	m_pSlider_WV_Irrigation = new wxSlider( this, ID_CMD_SSW_SLIDER_WV_Irrigation, 1, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL );
	bSizer3111->Add( m_pSlider_WV_Irrigation, 0, wxALL, 5 );
	
	sbSizer1->Add( bSizer3111, 1, wxEXPAND, 5 );
	
	wxBoxSizer* bSizer3112;
	bSizer3112 = new wxBoxSizer( wxHORIZONTAL );
	
	wxStaticText* m_staticText2112 = new wxStaticText( this, wxID_ANY, wxT("Evenness"), wxDefaultPosition, wxSize( 170,-1 ), 0 );
	m_staticText2112->Wrap( -1 );
	bSizer3112->Add( m_staticText2112, 0, wxALL, 5 );
	
	
	bSizer3112->Add( 10, 0, 1, wxEXPAND, 5 );
	
	m_pSlider_Evenness = new wxSlider( this, ID_CMD_SSW_SLIDER_Evenness, 1, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL );
	bSizer3112->Add( m_pSlider_Evenness, 0, wxALL, 5 );
	
	sbSizer1->Add( bSizer3112, 1, wxEXPAND, 5 );
	
	wxBoxSizer* bSizer3113;
	bSizer3113 = new wxBoxSizer( wxHORIZONTAL );
	
	wxStaticText* m_staticText2113 = new wxStaticText( this, wxID_ANY, wxT("Morphology"), wxDefaultPosition, wxSize( 170,-1 ), 0 );
	m_staticText2113->Wrap( -1 );
	bSizer3113->Add( m_staticText2113, 0, wxALL, 5 );
	
	
	bSizer3113->Add( 10, 0, 1, wxEXPAND, 5 );
	
	m_pSlider_Morphology = new wxSlider( this, ID_CMD_SSW_SLIDER_Morphology, 1, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL );
	bSizer3113->Add( m_pSlider_Morphology, 0, wxALL, 5 );
	
	sbSizer1->Add( bSizer3113, 1, wxEXPAND, 5 );
	
	sbSizer4->Add( sbSizer1, 0, wxALL, 5 );
	
	wxStaticBoxSizer* sbSizer2;
	sbSizer2 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, wxT("Soil Salinity Weights (expert knowledge)") ), wxVERTICAL );
	
	wxBoxSizer* bSizer21;
	bSizer21 = new wxBoxSizer( wxHORIZONTAL );
	
	wxStaticText* m_staticText11 = new wxStaticText( this, wxID_ANY, wxT("Soil texture"), wxDefaultPosition, wxSize( 170,-1 ), 0 );
	m_staticText11->Wrap( -1 );
	bSizer21->Add( m_staticText11, 0, wxALL, 5 );
	
	
	bSizer21->Add( 10, 0, 1, wxEXPAND, 5 );
	
	m_pSlider_SoilTexture = new wxSlider( this, ID_CMD_SSW_SLIDER_SOIL_TEXTURE, 1, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL );
	bSizer21->Add( m_pSlider_SoilTexture, 0, wxALL, 5 );
	
	sbSizer2->Add( bSizer21, 1, wxEXPAND, 5 );
	
	wxBoxSizer* bSizer211;
	bSizer211 = new wxBoxSizer( wxHORIZONTAL );
	
	wxStaticText* m_staticText111 = new wxStaticText( this, wxID_ANY, wxT("Plant growth characteristics"), wxDefaultPosition, wxSize( 170,-1 ), 0 );
	m_staticText111->Wrap( -1 );
	bSizer211->Add( m_staticText111, 0, wxALL, 5 );
	
	
	bSizer211->Add( 10, 0, 1, wxEXPAND, 5 );
	
	m_pSlider_PlantGrowth = new wxSlider( this, ID_CMD_SSW_SLIDER_PLANT_GROWTH, 1, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL );
	bSizer211->Add( m_pSlider_PlantGrowth, 0, wxALL, 5 );
	
	sbSizer2->Add( bSizer211, 1, wxEXPAND, 5 );


	wxBoxSizer* bSizerGW_S;
	bSizerGW_S = new wxBoxSizer( wxHORIZONTAL );
	
	wxStaticText* m_staticText1111 = new wxStaticText( this, wxID_ANY, wxT("Ground water salinity"), wxDefaultPosition, wxSize( 170,-1 ), 0 );
	bSizerGW_S->Add( m_staticText1111, 0, wxALL, 5 );
	
	
	bSizerGW_S->Add( 10, 0, 1, wxEXPAND, 5 );
	
	m_pSlider_GW_Salinity = new wxSlider( this, ID_CMD_SSW_SLIDER_GW_SALINITY, 1, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL );
	bSizerGW_S->Add( m_pSlider_GW_Salinity, 0, wxALL, 5 );
	
	sbSizer2->Add( bSizerGW_S, 1, wxEXPAND, 5 );

	wxBoxSizer* bSizerGW_L;
	bSizerGW_L = new wxBoxSizer( wxHORIZONTAL );
	
	wxStaticText* m_staticText1112 = new wxStaticText( this, wxID_ANY, wxT("Ground water salinity"), wxDefaultPosition, wxSize( 170,-1 ), 0 );
	bSizerGW_L->Add( m_staticText1112, 0, wxALL, 5 );
	
	bSizerGW_L->Add( 10, 0, 1, wxEXPAND, 5 );
	
	m_pSlider_GW_Level = new wxSlider( this, ID_CMD_SSW_SLIDER_GW_LEVEL, 1, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL );
	bSizerGW_L->Add( m_pSlider_GW_Level, 0, wxALL, 5 );
	
	sbSizer2->Add( bSizerGW_L, 1, wxEXPAND, 5 );


	wxBoxSizer* bSizer212;
	bSizer212 = new wxBoxSizer( wxHORIZONTAL );
	
	wxStaticText* m_staticText112 = new wxStaticText( this, wxID_ANY, wxT("Number of channels"), wxDefaultPosition, wxSize( 170,-1 ), 0 );
	m_staticText112->Wrap( -1 );
	bSizer212->Add( m_staticText112, 0, wxALL, 5 );
	
	
	bSizer212->Add( 10, 0, 1, wxEXPAND, 5 );
	
	m_pSlider_nChannels = new wxSlider( this, ID_CMD_SSW_SLIDER_nCHANNELS, 1, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL );
	bSizer212->Add( m_pSlider_nChannels, 0, wxALL, 5 );
	
	sbSizer2->Add( bSizer212, 1, wxEXPAND, 5 );
	
	wxBoxSizer* bSizer213;
	bSizer213 = new wxBoxSizer( wxHORIZONTAL );
	
	wxStaticText* m_staticText113 = new wxStaticText( this, wxID_ANY, wxT("Distance to drainage network"), wxDefaultPosition, wxSize( 170,-1 ), 0 );
	m_staticText113->Wrap( -1 );
	bSizer213->Add( m_staticText113, 0, wxALL, 5 );
	
	
	bSizer213->Add( 10, 0, 1, wxEXPAND, 5 );
	
	m_pSlider_Distance = new wxSlider( this, ID_CMD_SSW_SLIDER_DISTANCE, 1, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL );
	bSizer213->Add( m_pSlider_Distance, 0, wxALL, 5 );
	
	sbSizer2->Add( bSizer213, 1, wxEXPAND, 5 );
	
	wxBoxSizer* bSizer214;
	bSizer214 = new wxBoxSizer( wxHORIZONTAL );
	
	wxStaticText* m_staticText114 = new wxStaticText( this, wxID_ANY, wxT("Maintanance of drainage network"), wxDefaultPosition, wxSize( 170,-1 ), 0 );
	m_staticText114->Wrap( -1 );
	bSizer214->Add( m_staticText114, 0, wxALL, 5 );
	
	
	bSizer214->Add( 10, 0, 1, wxEXPAND, 5 );
	
	m_pSlider_Maintanance = new wxSlider( this, ID_CMD_SSW_SLIDER_MAINTANANCE, 1, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL );
	bSizer214->Add( m_pSlider_Maintanance, 0, wxALL, 5 );
	
	sbSizer2->Add( bSizer214, 1, wxEXPAND, 5 );
	
	sbSizer4->Add( sbSizer2, 0, wxALL, 5 );
	
	wxBoxSizer* bSizer33;
	bSizer33 = new wxBoxSizer( wxHORIZONTAL );
	
	m_pButton_LoadDefault = new wxButton( this, ID_CMD_SSW_BUTTON_LOAD_DEFAULT, wxT("Load Default"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer33->Add( m_pButton_LoadDefault, 0, wxALL, 10 );
	
	m_pButtonSave = new wxButton( this, ID_CMD_SSW_BUTTON_SAVE, wxT("Save"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer33->Add( m_pButtonSave, 0, wxALL, 10 );
	
	m_pButtonCancel = new wxButton( this, wxID_CANCEL, wxT("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizer33->Add( m_pButtonCancel, 0, wxALL, 10 );
	
	sbSizer4->Add( bSizer33, 0, wxALIGN_CENTER_HORIZONTAL, 10 );
	
	mainSizer->Add( sbSizer4, 1, wxALL, 5 );
	
	this->SetSizer( mainSizer );
	this->Layout();
	mainSizer->Fit( this );
}

