// Copyright (C) Stichting Deltares 2024. 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.Windows.Forms;
using Deltares.Dam.Data;
using Deltares.Standard.EventPublisher;
using Deltares.Standard.EventPublisher.Enum;
using Deltares.Standard.Forms;
using Deltares.Standard.Forms.DExpress;
namespace Deltares.Dam.Forms
{
public partial class DamProjectCalculationSpecificationPropertyControl : UserControl, IPropertyControl
{
private DamProjectCalculationSpecification damProjectCalculationSpecification;
private DamProjectData damProjectData;
private bool firstEdit;
public DamProjectCalculationSpecificationPropertyControl()
{
InitializeComponent();
// Make sure PropertyEditorReactionType is set to Ignore (Design time this does NOT work TODO for Grid component).
Grid.PropertyEditorReactionType = PropertyEditorReactionType.Ignore;
Name = "Calculation";
BindSupport.Bind(this, Grid, p => p.DamCalculationSpecifications);
DataEventPublisher.OnSelectionChanged += DataEventPublisher_OnSubSelectionChanged;
DataEventPublisher.OnAfterChange += DataEventPublisher_OnAfterChange;
FormsSupport.RepairRightAnchoredControls(this);
FormsSupport.AdjustSizeToContents(damProjectCalculationOptionsPropertyControl1);
firstEdit = true;
}
private void DataEventPublisher_OnAfterChange(object sender, PublishEventArgs e)
{
var specification = sender as DamFailureMechanismeCalculationSpecification;
if (specification != null && damProjectCalculationSpecification != null)
{
damProjectCalculationSpecification.CurrentSpecification = specification;
SetSelectedDamCalculationSpecification();
}
}
private void SetSelectedDamCalculationSpecification()
{
DamFailureMechanismeCalculationSpecification selection = damProjectCalculationSpecification.CurrentSpecification;
if (selection != null)
{
selection.FailureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.Specification = selection;
BindSupport.Assign(damProjectCalculationOptionsPropertyControl1, selection);
if (firstEdit)
{
// Ensure that all edits of the damProjectCalculationOptionsPropertyControl1 are updated at start
damProjectCalculationOptionsPropertyControl1.SelectedObject = selection;
}
if (selection.FailureMechanismSystemType != FailureMechanismSystemType.Piping && firstEdit)
{
// this is a hack to force update on ill placed edits.
Width += 1;
firstEdit = false;
}
}
}
private void DataEventPublisher_OnSubSelectionChanged(object sender, PublishEventArgs e)
{
if (((SelectionEventArgs) e).PropertyEditorReactionType == PropertyEditorReactionType.Ignore &&
sender is DamFailureMechanismeCalculationSpecification item &&
damProjectCalculationSpecification.DamCalculationSpecifications.Contains(item))
{
damProjectCalculationSpecification.CurrentSpecification = item;
SetSelectedDamCalculationSpecification();
}
}
#region IPropertyControl Members
public bool IsVisible =>
damProjectData != null &&
(damProjectData.DamProjectType == DamProjectType.Calamity ||
damProjectData.DamProjectType == DamProjectType.Design ||
damProjectData.DamProjectType == DamProjectType.DamLiveConfiguration);
public object SelectedObject
{
get
{
return damProjectData;
}
set
{
var data = value as DamProjectData;
if (data != null)
{
damProjectData = data;
damProjectCalculationSpecification = damProjectData.DamProjectCalculationSpecification;
BindSupport.Assign(this, damProjectCalculationSpecification);
SetSelectedDamCalculationSpecification();
if (damProjectData.DamProjectType == DamProjectType.Design)
{
Grid.ShowToolbar = false;
}
}
}
}
#endregion
}
}