Index: Riskeer/Piping/src/Riskeer.Piping.Forms/PropertyClasses/Probabilistic/ProbabilisticSubMechanismPipingSectionSpecificOutputProperties.cs =================================================================== diff -u --- Riskeer/Piping/src/Riskeer.Piping.Forms/PropertyClasses/Probabilistic/ProbabilisticSubMechanismPipingSectionSpecificOutputProperties.cs (revision 0) +++ Riskeer/Piping/src/Riskeer.Piping.Forms/PropertyClasses/Probabilistic/ProbabilisticSubMechanismPipingSectionSpecificOutputProperties.cs (revision 46e79a0be9bdc8c879f9ec02b3ea894195da75d9) @@ -0,0 +1,146 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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.Linq; +using Core.Common.Gui.Attributes; +using Core.Common.Gui.Converters; +using Core.Common.Util.Attributes; +using Riskeer.Common.Data.IllustrationPoints; +using Riskeer.Common.Forms.PropertyClasses; +using Riskeer.Piping.Data.Probabilistic; +using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; + +namespace Riskeer.Piping.Forms.PropertyClasses.Probabilistic +{ + /// + /// ViewModel of profile specific for properties panel. + /// + public class ProbabilisticSubMechanismPipingSectionSpecificOutputProperties : ProbabilisticPipingSectionSpecificOutputProperties + { + private const int windDirectionIndex = 2; + private const int alphaValuesIndex = 3; + private const int durationsIndex = 4; + private const int illustrationPointsIndex = 5; + private readonly PartialProbabilisticSubMechanismPipingOutput subMechanismOutput; + + /// + /// Creates a new instance of . + /// + /// The output to show the properties for. + /// Thrown when is null. + public ProbabilisticSubMechanismPipingSectionSpecificOutputProperties(PartialProbabilisticSubMechanismPipingOutput output) + : base(output) + { + subMechanismOutput = output; + } + + [DynamicVisibleValidationMethod] + public bool DynamicVisibleValidationMethod(string propertyName) + { + return data.HasGeneralResult + && (propertyName.Equals(nameof(WindDirection)) + || propertyName.Equals(nameof(AlphaValues)) + || propertyName.Equals(nameof(Durations)) + || propertyName.Equals(nameof(IllustrationPoints))); + } + + private TopLevelSubMechanismIllustrationPointProperties[] GetTopLevelIllustrationPointProperties() + { + TopLevelSubMechanismIllustrationPoint[] subMechanismIllustrationPoints = subMechanismOutput.GeneralResult.TopLevelIllustrationPoints.ToArray(); + IEnumerable closingSituations = subMechanismIllustrationPoints.Select(p => p.ClosingSituation); + + return subMechanismIllustrationPoints.Select( + point => new TopLevelSubMechanismIllustrationPointProperties( + point, closingSituations)).ToArray(); + } + + private Stochast[] GetStochasts() + { + return subMechanismOutput.GeneralResult?.Stochasts.ToArray(); + } + + #region Illustration points + + [DynamicVisible] + [PropertyOrder(windDirectionIndex)] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_IllustrationPoints), 2, 2)] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.IllustrationPoint_GoverningWindDirection_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.IllustrationPoint_GoverningWindDirection_Description))] + public string WindDirection + { + get + { + return subMechanismOutput.GeneralResult?.GoverningWindDirection.Name; + } + } + + [DynamicVisible] + [PropertyOrder(alphaValuesIndex)] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_IllustrationPoints), 2, 2)] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.IllustrationPoint_AlphaValues_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.IllustrationPoint_AlphaValues_Description))] + [TypeConverter(typeof(KeyValueExpandableArrayConverter))] + [KeyValueElement(nameof(Stochast.Name), nameof(Stochast.Alpha))] + public Stochast[] AlphaValues + { + get + { + return GetStochasts(); + } + } + + [DynamicVisible] + [PropertyOrder(durationsIndex)] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_IllustrationPoints), 2, 2)] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.IllustrationPoint_Durations_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.IllustrationPoint_Durations_Description))] + [TypeConverter(typeof(KeyValueExpandableArrayConverter))] + [KeyValueElement(nameof(Stochast.Name), nameof(Stochast.Duration))] + public Stochast[] Durations + { + get + { + return GetStochasts(); + } + } + + [DynamicVisible] + [PropertyOrder(illustrationPointsIndex)] + [ResourcesCategory(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.Categories_IllustrationPoints), 2, 2)] + [ResourcesDisplayName(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.IllustrationPointProperty_IllustrationPoints_DisplayName))] + [ResourcesDescription(typeof(RiskeerCommonFormsResources), nameof(RiskeerCommonFormsResources.IllustrationPointProperty_IllustrationPoints_Description))] + [TypeConverter(typeof(ExpandableArrayConverter))] + public TopLevelSubMechanismIllustrationPointProperties[] IllustrationPoints + { + get + { + return !data.HasGeneralResult + ? new TopLevelSubMechanismIllustrationPointProperties[0] + : GetTopLevelIllustrationPointProperties(); + } + } + + #endregion + } +} \ No newline at end of file Index: Riskeer/Piping/test/Riskeer.Piping.Forms.Test/PropertyClasses/Probabilistic/ProbabilisticSubMechanismPipingSectionSpecificOutputPropertiesTest.cs =================================================================== diff -u --- Riskeer/Piping/test/Riskeer.Piping.Forms.Test/PropertyClasses/Probabilistic/ProbabilisticSubMechanismPipingSectionSpecificOutputPropertiesTest.cs (revision 0) +++ Riskeer/Piping/test/Riskeer.Piping.Forms.Test/PropertyClasses/Probabilistic/ProbabilisticSubMechanismPipingSectionSpecificOutputPropertiesTest.cs (revision 46e79a0be9bdc8c879f9ec02b3ea894195da75d9) @@ -0,0 +1,211 @@ +// Copyright (C) Stichting Deltares 2019. All rights reserved. +// +// This file is part of Riskeer. +// +// Riskeer 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 System.Linq; +using Core.Common.Gui.Converters; +using Core.Common.TestUtil; +using Core.Common.Util; +using NUnit.Framework; +using Riskeer.Common.Data.IllustrationPoints; +using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.Helpers; +using Riskeer.Common.Forms.PropertyClasses; +using Riskeer.Piping.Data.Probabilistic; +using Riskeer.Piping.Data.TestUtil; +using Riskeer.Piping.Forms.PropertyClasses.Probabilistic; + +namespace Riskeer.Piping.Forms.Test.PropertyClasses.Probabilistic +{ + [TestFixture] + public class ProbabilisticSubMechanismPipingSectionSpecificOutputPropertiesTest + { + private const int probabilityPropertyIndex = 0; + private const int reliabilityPropertyIndex = 1; + private const int windDirectionPropertyIndex = 2; + private const int alphaValuesPropertyIndex = 3; + private const int durationsPropertyIndex = 4; + private const int illustrationPointsPropertyIndex = 5; + + private const string illustrationPointsCategoryName = "Illustratiepunten"; + private const string resultCategoryName = "\tResultaat"; + + [Test] + public void Constructor_OutputNull_ThrowArgumentNullException() + { + // Call + void Call() => new ProbabilisticSubMechanismPipingSectionSpecificOutputProperties(null); + + // Assert + var exception = Assert.Throws(Call); + Assert.AreEqual("output", exception.ParamName); + } + + [Test] + public void Constructor_WithParameters_ExpectedValues() + { + // Setup + PartialProbabilisticSubMechanismPipingOutput output = PipingTestDataGenerator.GetRandomPartialProbabilisticSubMechanismPipingOutput(); + + // Call + var properties = new ProbabilisticSubMechanismPipingSectionSpecificOutputProperties(output); + + // Assert + Assert.IsInstanceOf(properties); + Assert.AreSame(output, properties.Data); + } + + [Test] + public void Constructor_HasGeneralResult_PropertiesHaveExpectedAttributesValues() + { + // Setup + PartialProbabilisticSubMechanismPipingOutput output = PipingTestDataGenerator.GetRandomPartialProbabilisticSubMechanismPipingOutput(); + + // Call + var properties = new ProbabilisticSubMechanismPipingSectionSpecificOutputProperties(output); + + // Assert + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + Assert.AreEqual(6, dynamicProperties.Count); + + PropertyDescriptor probabilityProperty = dynamicProperties[probabilityPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(probabilityProperty, + resultCategoryName, + "Faalkans [1/jaar]", + "De kans dat het toetsspoor optreedt voor deze berekening.", + true); + + PropertyDescriptor reliabilityProperty = dynamicProperties[reliabilityPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(reliabilityProperty, + resultCategoryName, + "Betrouwbaarheidsindex faalkans [-]", + "De betrouwbaarheidsindex van de faalkans voor deze berekening.", + true); + + PropertyDescriptor windDirectionProperty = dynamicProperties[windDirectionPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(windDirectionProperty, + illustrationPointsCategoryName, + "Maatgevende windrichting", + "De windrichting waarvoor de berekende betrouwbaarheidsindex het laagst is.", + true); + + PropertyDescriptor alphaValuesProperty = dynamicProperties[alphaValuesPropertyIndex]; + TestHelper.AssertTypeConverter( + nameof(ProbabilisticSubMechanismPipingSectionSpecificOutputProperties.AlphaValues)); + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(alphaValuesProperty, + illustrationPointsCategoryName, + "Invloedscoëfficiënten [-]", + "Berekende invloedscoëfficiënten voor alle beschouwde stochasten.", + true); + + PropertyDescriptor durationsProperty = dynamicProperties[durationsPropertyIndex]; + TestHelper.AssertTypeConverter( + nameof(ProbabilisticSubMechanismPipingSectionSpecificOutputProperties.Durations)); + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(durationsProperty, + illustrationPointsCategoryName, + "Tijdsduren [uur]", + "Tijdsduren waarop de stochasten betrekking hebben.", + true); + + PropertyDescriptor illustrationPointProperty = dynamicProperties[illustrationPointsPropertyIndex]; + TestHelper.AssertTypeConverter( + nameof(ProbabilisticSubMechanismPipingSectionSpecificOutputProperties.IllustrationPoints)); + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(illustrationPointProperty, + illustrationPointsCategoryName, + "Illustratiepunten", + "De lijst van illustratiepunten voor de berekening.", + true); + } + + [Test] + public void Constructor_NoGeneralResult_PropertiesHaveExpectedAttributesValues() + { + // Setup + PartialProbabilisticSubMechanismPipingOutput output = PipingTestDataGenerator.GetRandomPartialProbabilisticSubMechanismPipingOutput(null); + + // Call + var properties = new ProbabilisticSubMechanismPipingSectionSpecificOutputProperties(output); + + // Assert + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + Assert.AreEqual(2, dynamicProperties.Count); + + PropertyDescriptor probabilityProperty = dynamicProperties[probabilityPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(probabilityProperty, + resultCategoryName, + "Faalkans [1/jaar]", + "De kans dat het toetsspoor optreedt voor deze berekening.", + true); + + PropertyDescriptor reliabilityProperty = dynamicProperties[reliabilityPropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(reliabilityProperty, + resultCategoryName, + "Betrouwbaarheidsindex faalkans [-]", + "De betrouwbaarheidsindex van de faalkans voor deze berekening.", + true); + } + + [Test] + public void GetProperties_WithData_ReturnExpectedValues() + { + // Setup + PartialProbabilisticSubMechanismPipingOutput output = PipingTestDataGenerator.GetRandomPartialProbabilisticSubMechanismPipingOutput(); + + // Call + var properties = new ProbabilisticSubMechanismPipingSectionSpecificOutputProperties(output); + + // Assert + Assert.AreEqual(ProbabilityFormattingHelper.Format(StatisticsConverter.ReliabilityToProbability(output.Reliability)), properties.Probability); + Assert.AreEqual(output.Reliability, properties.Reliability, properties.Reliability.GetAccuracy()); + + GeneralResult generalResult = output.GeneralResult; + + Assert.AreEqual(generalResult.GoverningWindDirection.Name, properties.WindDirection); + + int nrOfExpectedStochasts = generalResult.Stochasts.Count(); + Assert.AreEqual(nrOfExpectedStochasts, properties.AlphaValues.Length); + Assert.AreEqual(nrOfExpectedStochasts, properties.Durations.Length); + Stochast expectedStochast = generalResult.Stochasts.First(); + Assert.AreEqual(expectedStochast.Alpha, properties.AlphaValues[0].Alpha); + Assert.AreEqual(expectedStochast.Duration, properties.Durations[0].Duration); + + int nrOfExpectedTopLevelIllustrationPoints = generalResult.TopLevelIllustrationPoints.Count(); + Assert.AreEqual(nrOfExpectedTopLevelIllustrationPoints, properties.IllustrationPoints.Length); + + CollectionAssert.AreEqual(generalResult.TopLevelIllustrationPoints, properties.IllustrationPoints.Select(i => i.Data)); + } + + [Test] + public void IllustrationPoints_WithoutGeneralResult_ReturnsEmptyTopLevelSubMechanismIllustrationPointPropertiesArray() + { + // Setup + PartialProbabilisticSubMechanismPipingOutput output = PipingTestDataGenerator.GetRandomPartialProbabilisticSubMechanismPipingOutput(null); + var properties = new ProbabilisticSubMechanismPipingSectionSpecificOutputProperties(output); + + // Call + TopLevelSubMechanismIllustrationPointProperties[] illustrationPoints = properties.IllustrationPoints; + + // Assert + CollectionAssert.IsEmpty(illustrationPoints); + } + } +} \ No newline at end of file