Index: Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsFailureMechanismSectionResultRow.cs =================================================================== diff -u -rcb5473dc9372632b858565eef6a48a1efb6f14a2 -r74df3b2f37b578eb5f0d5c8d33379d965805bb8e --- Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsFailureMechanismSectionResultRow.cs (.../MacroStabilityInwardsFailureMechanismSectionResultRow.cs) (revision cb5473dc9372632b858565eef6a48a1efb6f14a2) +++ Ringtoets/MacroStabilityInwards/src/Ringtoets.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsFailureMechanismSectionResultRow.cs (.../MacroStabilityInwardsFailureMechanismSectionResultRow.cs) (revision 74df3b2f37b578eb5f0d5c8d33379d965805bb8e) @@ -22,11 +22,18 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Linq; +using Core.Common.Controls.DataGrid; +using Ringtoets.AssemblyTool.Data; using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.Calculation; +using Ringtoets.Common.Data.Exceptions; +using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.TypeConverters; using Ringtoets.Common.Forms.Views; using Ringtoets.Common.Primitives; using Ringtoets.MacroStabilityInwards.Data; +using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.MacroStabilityInwards.Forms.Views { @@ -36,10 +43,25 @@ /// public class MacroStabilityInwardsFailureMechanismSectionResultRow : FailureMechanismSectionResultRow { - private const double tolerance = 1e-6; + 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 IEnumerable calculations; private readonly MacroStabilityInwardsFailureMechanism failureMechanism; private readonly IAssessmentSection assessmentSection; + private FailureMechanismSectionAssemblyCategoryGroup simpleAssemblyCategoryGroup; + private FailureMechanismSectionAssemblyCategoryGroup detailedAssemblyCategoryGroup; + private FailureMechanismSectionAssemblyCategoryGroup tailorMadeAssemblyCategoryGroup; + private FailureMechanismSectionAssemblyCategoryGroup combinedAssemblyCategoryGroup; /// /// Creates a new instance of . @@ -49,11 +71,16 @@ /// All calculations in the failure mechanism. /// The failure mechanism the section result belongs to. /// The assessment section the section result belongs to. + /// The property values required to create an instance of + /// . /// Throw when any parameter is null. + /// Thrown when + /// is a valid value, but unsupported. internal MacroStabilityInwardsFailureMechanismSectionResultRow(MacroStabilityInwardsFailureMechanismSectionResult sectionResult, IEnumerable calculations, MacroStabilityInwardsFailureMechanism failureMechanism, - IAssessmentSection assessmentSection) + IAssessmentSection assessmentSection, + ConstructionProperties constructionProperties) : base(sectionResult) { if (calculations == null) @@ -71,14 +98,37 @@ throw new ArgumentNullException(nameof(assessmentSection)); } + if (constructionProperties == null) + { + throw new ArgumentNullException(nameof(constructionProperties)); + } + this.calculations = calculations; 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. /// + /// Thrown when + /// is a valid value, but unsupported. public SimpleAssessmentResultType SimpleAssessmentResult { get @@ -88,17 +138,67 @@ set { SectionResult.SimpleAssessmentResult = value; - SectionResult.NotifyObservers(); + UpdateInternalData(); } } /// + /// Gets or sets the value representing the detailed assessment result. + /// + /// Thrown when + /// is a valid value, but unsupported. + public DetailedAssessmentProbabilityOnlyResultType DetailedAssessmentResult + { + get + { + return SectionResult.DetailedAssessmentResult; + } + set + { + SectionResult.DetailedAssessmentResult = value; + UpdateInternalData(); + } + } + + /// + /// Gets the detailed assessment probability a of the . + /// + [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] + public double DetailedAssessmentProbability + { + get + { + return SectionResult.GetDetailedAssessmentProbability(calculations, failureMechanism, assessmentSection); + } + } + + /// + /// Gets or sets the value representing the tailor made assessment result. + /// + /// Thrown when + /// is a valid value, but unsupported. + 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. + /// Thrown when is + /// not in the range [0,1]. + /// Thrown when + /// is a valid value, but unsupported. [TypeConverter(typeof(NoProbabilityValueDoubleConverter))] - public double AssessmentLayerThree + public double TailorMadeAssessmentProbability { get { @@ -107,32 +207,384 @@ set { SectionResult.TailorMadeAssessmentProbability = value; + UpdateInternalData(); } } /// - /// Gets the detailed assessment probability a of the . + /// 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 DetailedAssessmentProbability + 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.GetDetailedAssessmentProbability(calculations, failureMechanism, assessmentSection); + return SectionResult.UseManualAssemblyProbability; } + set + { + SectionResult.UseManualAssemblyProbability = value; + UpdateInternalData(); + } } /// - /// Gets the that is the source of this row. + /// Gets or sets the manually entered assembly probability. /// - public MacroStabilityInwardsFailureMechanismSectionResult GetSectionResult + /// 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; + return SectionResult.ManualAssemblyProbability; } + set + { + SectionResult.ManualAssemblyProbability = value; + UpdateInternalData(); + } } - public override void Update() {} + /// + /// Thrown when + /// is a valid value, but unsupported. + public override void Update() + { + UpdateDerivedData(); + UpdateColumnStateDefinitions(); + UpdateDetailedAssessmentProbabilityError(); + } + + private void UpdateDetailedAssessmentProbabilityError() + { + if (FailureMechanismSectionResultRowHelper.SimpleAssessmentIsSufficient(SimpleAssessmentResult) + || !FailureMechanismSectionResultRowHelper.DetailedAssessmentResultIsProbability(DetailedAssessmentResult) + || UseManualAssemblyProbability) + { + ColumnStateDefinitions[detailedAssessmentProbabilityIndex].ErrorText = string.Empty; + } + else + { + ColumnStateDefinitions[detailedAssessmentProbabilityIndex].ErrorText = GetDetailedAssessmentProbabilityError(); + } + } + + private string GetDetailedAssessmentProbabilityError() + { + MacroStabilityInwardsCalculationScenario[] relevantScenarios = SectionResult.GetCalculationScenarios(calculations).ToArray(); + bool relevantScenarioAvailable = relevantScenarios.Length != 0; + + if (!relevantScenarioAvailable) + { + return RingtoetsCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Not_any_calculation_set; + } + + if (Math.Abs(SectionResult.GetTotalContribution(relevantScenarios) - 1.0) > 1e-6) + { + return RingtoetsCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Scenario_contribution_for_this_section_not_100; + } + + CalculationScenarioStatus calculationScenarioStatus = SectionResult.GetCalculationScenarioStatus(relevantScenarios); + if (calculationScenarioStatus == CalculationScenarioStatus.NotCalculated) + { + return RingtoetsCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_Not_all_calculations_have_been_executed; + } + + if (double.IsNaN(SectionResult.GetDetailedAssessmentProbability(calculations, failureMechanism, assessmentSection))) + { + return RingtoetsCommonFormsResources.FailureMechanismResultView_DataGridViewCellFormatting_All_calculations_must_have_valid_output; + } + + return string.Empty; + } + + 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 = MacroStabilityInwardsFailureMechanismSectionResultAssemblyFactory.AssembleSimpleAssessment(SectionResult).Group; + } + catch (AssemblyException e) + { + simpleAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; + ColumnStateDefinitions[simpleAssemblyCategoryGroupIndex].ErrorText = e.Message; + } + } + + private void TryGetDetailedAssemblyCategoryGroup() + { + try + { + detailedAssemblyCategoryGroup = MacroStabilityInwardsFailureMechanismSectionResultAssemblyFactory.AssembleDetailedAssessment( + SectionResult, + calculations, + failureMechanism, + assessmentSection).Group; + } + catch (AssemblyException e) + { + detailedAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; + ColumnStateDefinitions[detailedAssemblyCategoryGroupIndex].ErrorText = e.Message; + } + } + + private void TryGetTailorMadeAssemblyCategoryGroup() + { + try + { + tailorMadeAssemblyCategoryGroup = MacroStabilityInwardsFailureMechanismSectionResultAssemblyFactory.AssembleTailorMadeAssessment( + SectionResult, + failureMechanism, + assessmentSection).Group; + } + catch (AssemblyException e) + { + tailorMadeAssemblyCategoryGroup = FailureMechanismSectionAssemblyCategoryGroup.None; + ColumnStateDefinitions[tailorMadeAssemblyCategoryGroupIndex].ErrorText = e.Message; + } + } + + private void TryGetCombinedAssemblyCategoryGroup() + { + try + { + FailureMechanismSectionAssembly combinedAssembly = + MacroStabilityInwardsFailureMechanismSectionResultAssemblyFactory.AssembleCombinedAssessment( + SectionResult, + calculations, + 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; + } + } + + /// + /// Updates the column state definitions. + /// + /// Thrown when + /// is a valid value, but unsupported. + private void UpdateColumnStateDefinitions() + { + bool simpleAssessmentSufficient = FailureMechanismSectionResultRowHelper.SimpleAssessmentIsSufficient(SimpleAssessmentResult); + + FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[simpleAssessmentResultIndex], UseManualAssemblyProbability); + FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[detailedAssessmentResultIndex], simpleAssessmentSufficient + || UseManualAssemblyProbability); + if (simpleAssessmentSufficient + || !FailureMechanismSectionResultRowHelper.DetailedAssessmentResultIsProbability(DetailedAssessmentResult) + || UseManualAssemblyProbability) + { + FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[detailedAssessmentProbabilityIndex]); + } + else + { + FailureMechanismSectionResultRowHelper.EnableColumn(ColumnStateDefinitions[detailedAssessmentProbabilityIndex], true); + } + + FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[tailorMadeAssessmentResultIndex], + simpleAssessmentSufficient + || UseManualAssemblyProbability); + FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[tailorMadeAssessmentProbabilityIndex], + simpleAssessmentSufficient + || !FailureMechanismSectionResultRowHelper.TailorMadeAssessmentResultIsProbability(TailorMadeAssessmentResult) + || UseManualAssemblyProbability); + + if (UseManualAssemblyProbability) + { + FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[simpleAssemblyCategoryGroupIndex]); + FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[detailedAssemblyCategoryGroupIndex]); + FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[tailorMadeAssemblyCategoryGroupIndex]); + FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[combinedAssemblyCategoryGroupIndex]); + FailureMechanismSectionResultRowHelper.DisableColumn(ColumnStateDefinitions[combinedAssemblyProbabilityIndex]); + } + else + { + FailureMechanismSectionResultRowHelper.SetAssemblyCategoryGroupStyle(ColumnStateDefinitions[simpleAssemblyCategoryGroupIndex], + simpleAssemblyCategoryGroup); + FailureMechanismSectionResultRowHelper.SetAssemblyCategoryGroupStyle(ColumnStateDefinitions[detailedAssemblyCategoryGroupIndex], + detailedAssemblyCategoryGroup); + FailureMechanismSectionResultRowHelper.SetAssemblyCategoryGroupStyle(ColumnStateDefinitions[tailorMadeAssemblyCategoryGroupIndex], + tailorMadeAssemblyCategoryGroup); + FailureMechanismSectionResultRowHelper.SetAssemblyCategoryGroupStyle(ColumnStateDefinitions[combinedAssemblyCategoryGroupIndex], + combinedAssemblyCategoryGroup); + FailureMechanismSectionResultRowHelper.EnableColumn(ColumnStateDefinitions[combinedAssemblyProbabilityIndex], true); + } + + FailureMechanismSectionResultRowHelper.SetColumnState(ColumnStateDefinitions[manualAssemblyProbabilityIndex], !UseManualAssemblyProbability); + } + + /// + /// 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; } + } } } \ No newline at end of file