// Copyright (C) Stichting Deltares 2018. All rights reserved.
//
// This file is part of the application DAM - UI.
//
// DAM - UI is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Deltares.Dam.Data;
using Deltares.Standard;
using Deltares.Standard.EventPublisher;
using Deltares.Standard.Forms;
using Deltares.Standard.Forms.DExpress;
namespace Deltares.Dam.Forms
{
public partial class DamProjectCalculationOptionsPropertyControl : UserControl, IPropertyControl
{
private DamFailureMechanismeCalculationSpecification currentSpecification;
public DamProjectCalculationOptionsPropertyControl()
{
InitializeComponent();
BindSupport.BindTextAndValue(SearchMethodPanelControl, this.SearchMethodLabel, this.SearchMethodCombobox, p => p.SearchMethod);
BindSupport.BindTextAndValue(CircleDefinitionPanelControl, this.GridCreationLabel, this.GridCreationComboBox, p => p.GridSizeDetermination);
BindSupport.BindTextAndValue(CircleDefinitionPanelControl, this.TangentLineBishopLabel, this.TangentLineBishopComboBox, p => p.BishopTangentLinesDefinition);
BindSupport.BindTextAndValue(CircleDefinitionPanelControl, this.DistanceTangentLinesBishopLabel, this.DistanceTangentLinesBishopEdit, p => p.BishopTangentLinesDistance);
BindSupport.BindTextAndValue(this.CircleDefinitionPanelControl, this.TangentLineUpliftVanLabel, this.TangentLineUpliftVanComboBox, p => p.UpliftVanTangentLinesDefinition);
BindSupport.BindTextAndValue(this.CircleDefinitionPanelControl, this.DistanceTangentLinesUVLabel, this.DistanceTangentLinesUVEdit, p => p.UpliftVanTangentLinesDistance);
BindSupport.BindTextAndValue(CircleDefinitionPanelControl, this.LeftGridVerticalPointCountUVLabel, this.LeftGridVerticalPointCountUVEdit, p => p.UpliftVanLeftGridVerticalPointCount);
BindSupport.BindTextAndValue(CircleDefinitionPanelControl, this.LeftGridVerticalPointDistanceUVLabel, this.LeftGridVerticalPointDistanceUVEdit, p => p.UpliftVanLeftGridVerticalPointDistance);
BindSupport.BindTextAndValue(CircleDefinitionPanelControl, this.LeftGridHorizontalPointCountUVLabel, this.LeftGridHorizontalPointCountUVEdit, p => p.UpliftVanLeftGridHorizontalPointCount);
BindSupport.BindTextAndValue(CircleDefinitionPanelControl, this.LeftGridHorizontalPointDistanceUVLabel, this.LeftGridHorizontalPointDistanceUVEdit, p => p.UpliftVanLeftGridHorizontalPointDistance);
BindSupport.BindTextAndValue(CircleDefinitionPanelControl, this.RightGridVerticalPointCountUVLabel, this.RightGridVerticalPointCountUVEdit, p => p.UpliftVanRightGridVerticalPointCount);
BindSupport.BindTextAndValue(CircleDefinitionPanelControl, this.RightGridVerticalPointDistanceUVLabel, this.RightGridVerticalPointDistanceUVEdit, p => p.UpliftVanRightGridVerticalPointDistance);
BindSupport.BindTextAndValue(CircleDefinitionPanelControl, this.RightGridHorizontalPointCountUVLabel, this.RightGridHorizontalPointCountUVEdit, p => p.UpliftVanRightGridHorizontalPointCount);
BindSupport.BindTextAndValue(CircleDefinitionPanelControl, this.RightGridHorizontalPointDistanceUVLabel, this.RightGridHorizontalPointDistanceUVEdit, p => p.UpliftVanRightGridHorizontalPointDistance);
BindSupport.BindTextAndValue(CircleDefinitionPanelControl, this.GridVerticalPointCountBishopLabel, this.GridVerticalPointCountBishopEdit, p => p.BishopGridVerticalPointCount);
BindSupport.BindTextAndValue(CircleDefinitionPanelControl, this.GridVerticalPointDistanceBishopLabel, this.GridVerticalPointDistanceBishopEdit, p => p.BishopGridVerticalPointDistance);
BindSupport.BindTextAndValue(CircleDefinitionPanelControl, this.GridHorizontalPointCountBishopLabel, this.GridHorizontalPointCountBishopEdit, p => p.BishopGridHorizontalPointCount);
BindSupport.BindTextAndValue(CircleDefinitionPanelControl, this.GridHorizontalPointDistanceBishopLabel, this.GridHorizontalPointDistanceBishopEdit, p => p.BishopGridHorizontalPointDistance);
StabilityGroupControl.Text = "StabilityOptionsGroupControl";
LocalizationSupport.RegisterAndTranslate(typeof(DamProjectCalculationOptionsPropertyControl), StabilityGroupControl);
DataEventPublisher.OnAfterChange += DataEventPublisher_OnAfterChange;
FormsSupport.RepairRightAnchoredControls(this);
FormsSupport.AdjustSizeToContents(this.SearchMethodPanelControl);
FormsSupport.AdjustSizeToContents(this.CircleDefinitionPanelControl);
}
private void DataEventPublisher_OnAfterChange(object sender, PublishEventArgs e)
{
if (sender is DamFailureMechanismeCalculationSpecification)
{
currentSpecification = (DamFailureMechanismeCalculationSpecification) sender;
SetSelectedDamCalculationSpecification();
}
if (sender is DamProject)
{
var pd = (DamProject) sender;
currentSpecification = pd.DamProjectData.DamProjectCalculationSpecification.CurrentSpecification;
SetSelectedDamCalculationSpecification();
}
}
public object SelectedObject
{
get { return currentSpecification; }
set
{
if (value is DamFailureMechanismeCalculationSpecification)
{
currentSpecification = (DamFailureMechanismeCalculationSpecification) value;
BindSupport.Assign(this.SearchMethodPanelControl, currentSpecification.FailureMechanismeParamatersMStab.MStabParameters);
BindSupport.Assign(this.CircleDefinitionPanelControl, currentSpecification.FailureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition);
}
}
}
public bool IsVisible
{
get { return true; }
}
private void SetSelectedDamCalculationSpecification()
{
if (currentSpecification != null)
{
currentSpecification.FailureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.Specification =
currentSpecification;
if (SearchMethodPanelControl.InvokeRequired)
{
Action action = () => BindSupport.Assign(this.SearchMethodPanelControl, currentSpecification.FailureMechanismeParamatersMStab.MStabParameters);
SearchMethodPanelControl.Invoke(action);
}
else
{
BindSupport.Assign(this.SearchMethodPanelControl, currentSpecification.FailureMechanismeParamatersMStab.MStabParameters);
}
if (CircleDefinitionPanelControl.InvokeRequired)
{
Action action = () => BindSupport.Assign(this.CircleDefinitionPanelControl, currentSpecification.FailureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition);
CircleDefinitionPanelControl.Invoke(action);
}
else
{
BindSupport.Assign(this.CircleDefinitionPanelControl, currentSpecification.FailureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition);
}
// if (selection.FailureMechanismSystemType != FailureMechanismSystemType.Piping && firstEdit)
// {
// // this is a hack to force update on ill placed edits.
// this.Width = this.Width + 1;
// firstEdit = false;
// }
}
}
}
}