// Copyright (C) Stichting Deltares 2017. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets 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.ComponentModel; using Core.Common.Controls.DataGrid; using Ringtoets.AssemblyTool.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Exceptions; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.TypeConverters; using Ringtoets.Common.Forms.Views; using Ringtoets.Common.Primitives; using Ringtoets.StabilityPointStructures.Data; namespace Ringtoets.StabilityPointStructures.Forms.Views { /// /// This class represents a row of for stability point structures /// public class StabilityPointStructuresFailureMechanismSectionResultRow : FailureMechanismSectionResultRow { private readonly int simpleAssessmentResultIndex; private readonly int detailedAssessmentResultIndex; private readonly int detailedAssessmentProbabilityIndex; private readonly int tailorMadeAssessmentResultIndex; private readonly int tailorMadeAssessmentProbabilityIndex; private readonly int simpleAssemblyCategoryGroupIndex; private readonly int detailedAssemblyCategoryGroupIndex; private readonly int tailorMadeAssemblyCategoryGroupIndex; private readonly int combinedAssemblyCategoryGroupIndex; private readonly int combinedAssemblyProbabilityIndex; private readonly int manualAssemblyProbabilityIndex; private readonly StabilityPointStructuresFailureMechanism failureMechanism; private readonly IAssessmentSection assessmentSection; private FailureMechanismSectionAssemblyCategoryGroup simpleAssemblyCategoryGroup; private FailureMechanismSectionAssemblyCategoryGroup detailedAssemblyCategoryGroup; private FailureMechanismSectionAssemblyCategoryGroup tailorMadeAssemblyCategoryGroup; private FailureMechanismSectionAssemblyCategoryGroup combinedAssemblyCategoryGroup; /// /// Creates a new instance of . /// /// The to wrap /// so that it can be displayed as a row. /// The failure mechanism the result belongs to. /// The assessment section the result belongs to. /// /// The property values required to create an instance of /// . /// Thrown when any parameter is null. public StabilityPointStructuresFailureMechanismSectionResultRow(StabilityPointStructuresFailureMechanismSectionResult sectionResult, StabilityPointStructuresFailureMechanism failureMechanism, IAssessmentSection assessmentSection, ConstructionProperties constructionProperties) : base(sectionResult) { if (failureMechanism == null) { throw new ArgumentNullException(nameof(failureMechanism)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } if (constructionProperties == null) { throw new ArgumentNullException(nameof(constructionProperties)); } this.failureMechanism = failureMechanism; this.assessmentSection = assessmentSection; simpleAssessmentResultIndex = constructionProperties.SimpleAssessmentResultIndex; detailedAssessmentResultIndex = constructionProperties.DetailedAssessmentResultIndex; detailedAssessmentProbabilityIndex = constructionProperties.DetailedAssessmentProbabilityIndex; tailorMadeAssessmentResultIndex = constructionProperties.TailorMadeAssessmentResultIndex; tailorMadeAssessmentProbabilityIndex = constructionProperties.TailorMadeAssessmentProbabilityIndex; simpleAssemblyCategoryGroupIndex = constructionProperties.SimpleAssemblyCategoryGroupIndex; detailedAssemblyCategoryGroupIndex = constructionProperties.DetailedAssemblyCategoryGroupIndex; tailorMadeAssemblyCategoryGroupIndex = constructionProperties.TailorMadeAssemblyCategoryGroupIndex; combinedAssemblyCategoryGroupIndex = constructionProperties.CombinedAssemblyCategoryGroupIndex; combinedAssemblyProbabilityIndex = constructionProperties.CombinedAssemblyProbabilityIndex; manualAssemblyProbabilityIndex = constructionProperties.ManualAssemblyProbabilityIndex; CreateColumnStateDefinitions(); Update(); } /// /// Gets or sets the value representing the simple assessment result. /// public SimpleAssessmentResultValidityOnlyType SimpleAssessmentResult { get { return SectionResult.SimpleAssessmentResult; } set { SectionResult.SimpleAssessmentResult = value; UpdateInternalData(); } } /// /// Gets or sets the value representing the detailed assessment result. /// public DetailedAssessmentResultType DetailedAssessmentResult { get { return SectionResult.DetailedAssessmentResult; } set { SectionResult.DetailedAssessmentResult = value; UpdateInternalData(); } } /// /// Gets the value representing the detailed assessment probability. /// [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] public double DetailedAssessmentProbability { get { return SectionResult.GetDetailedAssessmentProbability(failureMechanism, assessmentSection); } } /// /// Gets or sets the value representing the tailor made assessment result. /// public TailorMadeAssessmentProbabilityCalculationResultType TailorMadeAssessmentResult { get { return SectionResult.TailorMadeAssessmentResult; } set { SectionResult.TailorMadeAssessmentResult = value; UpdateInternalData(); } } /// /// Gets or sets the value of the tailored assessment of safety. /// /// Thrown when /// is outside of the valid ranges. [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] public double TailorMadeAssessmentProbability { get { return SectionResult.TailorMadeAssessmentProbability; } set { SectionResult.TailorMadeAssessmentProbability = value; UpdateInternalData(); } } /// /// Gets the simple assembly category group. /// public string SimpleAssemblyCategoryGroup { get { return FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(simpleAssemblyCategoryGroup); } } /// /// Gets the detailed assembly category group. /// public string DetailedAssemblyCategoryGroup { get { return FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(detailedAssemblyCategoryGroup); } } /// /// Gets the tailor made assembly category group. /// public string TailorMadeAssemblyCategoryGroup { get { return FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(tailorMadeAssemblyCategoryGroup); } } /// /// Gets the combined assembly category group. /// public string CombinedAssemblyCategoryGroup { get { return FailureMechanismSectionResultRowHelper.GetCategoryGroupDisplayname(combinedAssemblyCategoryGroup); } } /// /// Gets the combined assembly probability. /// [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] public double CombinedAssemblyProbability { get; private set; } /// /// Gets or sets the indicator whether the combined assembly probability /// should be overwritten by . /// /// Thrown when /// is a valid value, but unsupported. public bool UseManualAssemblyProbability { get { return SectionResult.UseManualAssemblyProbability; } set { SectionResult.UseManualAssemblyProbability = value; UpdateInternalData(); } } /// /// Gets or sets the manually entered assembly probability. /// /// Thrown when is /// not in the range [0,1]. /// Thrown when /// is a valid value, but unsupported. [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] public double ManualAssemblyProbability { get { return SectionResult.ManualAssemblyProbability; } set { SectionResult.ManualAssemblyProbability = value; UpdateInternalData(); } } /// /// Gets the of the wrapped /// . /// /// null if the wrapped section result does not have a calculation /// set. Otherwise the calculation of the wrapped section result is returned. public StructuresCalculation GetSectionResultCalculation() { return SectionResult.Calculation; } public override void Update() { UpdateDerivedData(); UpdateColumnStateDefinitions(); } private void CreateColumnStateDefinitions() { ColumnStateDefinitions.Add(simpleAssessmentResultIndex, new DataGridViewColumnStateDefinition()); ColumnStateDefinitions.Add(detailedAssessmentResultIndex, new DataGridViewColumnStateDefinition()); ColumnStateDefinitions.Add(detailedAssessmentProbabilityIndex, new DataGridViewColumnStateDefinition()); ColumnStateDefinitions.Add(tailorMadeAssessmentResultIndex, new DataGridViewColumnStateDefinition()); ColumnStateDefinitions.Add(tailorMadeAssessmentProbabilityIndex, new DataGridViewColumnStateDefinition()); ColumnStateDefinitions.Add(simpleAssemblyCategoryGroupIndex, new DataGridViewColumnStateDefinition { ReadOnly = true }); ColumnStateDefinitions.Add(detailedAssemblyCategoryGroupIndex, new DataGridViewColumnStateDefinition { ReadOnly = true }); ColumnStateDefinitions.Add(tailorMadeAssemblyCategoryGroupIndex, new DataGridViewColumnStateDefinition { ReadOnly = true }); ColumnStateDefinitions.Add(combinedAssemblyCategoryGroupIndex, new DataGridViewColumnStateDefinition { ReadOnly = true }); ColumnStateDefinitions.Add(combinedAssemblyProbabilityIndex, new DataGridViewColumnStateDefinition { ReadOnly = true }); ColumnStateDefinitions.Add(manualAssemblyProbabilityIndex, new DataGridViewColumnStateDefinition()); } private void UpdateDerivedData() { ResetErrorTexts(); TryGetSimpleAssemblyCategoryGroup(); TryGetDetailedAssemblyCategoryGroup(); TryGetTailorMadeAssemblyCategoryGroup(); TryGetCombinedAssemblyCategoryGroup(); } private void ResetErrorTexts() { ColumnStateDefinitions[simpleAssemblyCategoryGroupIndex].ErrorText = string.Empty; ColumnStateDefinitions[detailedAssemblyCategoryGroupIndex].ErrorText = string.Empty; ColumnStateDefinitions[tailorMadeAssemblyCategoryGroupIndex].ErrorText = string.Empty; ColumnStateDefinitions[combinedAssemblyCategoryGroupIndex].ErrorText = string.Empty; ColumnStateDefinitions[combinedAssemblyProbabilityIndex].ErrorText = string.Empty; } private void TryGetSimpleAssemblyCategoryGroup() { try { simpleAssemblyCategoryGroup = StabilityPointStructuresFailureMechanismSectionResultAssemblyFactory.AssembleSimpleAssessment(SectionResult).Group; } catch (AssemblyException e) { simpleAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; ColumnStateDefinitions[simpleAssemblyCategoryGroupIndex].ErrorText = e.Message; } } private void TryGetDetailedAssemblyCategoryGroup() { try { detailedAssemblyCategoryGroup = StabilityPointStructuresFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssembly( SectionResult, failureMechanism, assessmentSection).Group; } catch (AssemblyException e) { detailedAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; ColumnStateDefinitions[detailedAssemblyCategoryGroupIndex].ErrorText = e.Message; } } private void TryGetTailorMadeAssemblyCategoryGroup() { try { tailorMadeAssemblyCategoryGroup = StabilityPointStructuresFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssembly( SectionResult, failureMechanism, assessmentSection).Group; } catch (AssemblyException e) { tailorMadeAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; ColumnStateDefinitions[tailorMadeAssemblyCategoryGroupIndex].ErrorText = e.Message; } } private void TryGetCombinedAssemblyCategoryGroup() { try { FailureMechanismSectionAssembly combinedAssembly = StabilityPointStructuresFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssembly( SectionResult, failureMechanism, assessmentSection); combinedAssemblyCategoryGroup = combinedAssembly.Group; CombinedAssemblyProbability = combinedAssembly.Probability; } catch (AssemblyException e) { combinedAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; CombinedAssemblyProbability = double.NaN; ColumnStateDefinitions[combinedAssemblyCategoryGroupIndex].ErrorText = e.Message; ColumnStateDefinitions[combinedAssemblyProbabilityIndex].ErrorText = e.Message; } } private void UpdateColumnStateDefinitions() { bool simpleAssessmentSufficient = FailureMechanismSectionResultRowHelper.SimpleAssessmentIsSufficient(SimpleAssessmentResult); FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[detailedAssessmentResultIndex], simpleAssessmentSufficient); if (simpleAssessmentSufficient || !FailureMechanismSectionResultRowHelper.DetailedAssessmentResultIsProbability(DetailedAssessmentResult)) { FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[detailedAssessmentProbabilityIndex]); } else { FailureMechanismSectionResultRowHelper.EnableColumn(ColumnStateDefinitions[detailedAssessmentProbabilityIndex], true); } FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[tailorMadeAssessmentResultIndex], simpleAssessmentSufficient); FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[tailorMadeAssessmentProbabilityIndex], simpleAssessmentSufficient); } /// /// Class holding the various construction parameters for . /// public class ConstructionProperties { /// /// Sets the simple assessment result index. /// public int SimpleAssessmentResultIndex { internal get; set; } /// /// Sets the detailed assessment result index. /// public int DetailedAssessmentResultIndex { internal get; set; } /// /// Sets the detailed assessment probability index. /// public int DetailedAssessmentProbabilityIndex { internal get; set; } /// /// Sets the tailor made assessment result index. /// public int TailorMadeAssessmentResultIndex { internal get; set; } /// /// Sets the tailor made assessment probability index. /// public int TailorMadeAssessmentProbabilityIndex { internal get; set; } /// /// Sets the simple assembly category group index. /// public int SimpleAssemblyCategoryGroupIndex { internal get; set; } /// /// Sets the detailed assembly category group index. /// public int DetailedAssemblyCategoryGroupIndex { internal get; set; } /// /// Sets the tailor made assembly category group index. /// public int TailorMadeAssemblyCategoryGroupIndex { internal get; set; } /// /// Sets the combined assembly category group index. /// public int CombinedAssemblyCategoryGroupIndex { internal get; set; } /// /// Sets the combined assembly probability index. /// public int CombinedAssemblyProbabilityIndex { internal get; set; } /// /// Sets the manual assembly category group index. /// public int ManualAssemblyProbabilityIndex { internal get; set; } } } }