Index: Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/PropertyClasses/ClosingStructuresInputContextProperties.cs =================================================================== diff -u -rd5a0bce3d53deb3aef237c365018096e9bc83bb1 -rf3c7ae4cc9069268dba97e9dd691bf449fa393db --- Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/PropertyClasses/ClosingStructuresInputContextProperties.cs (.../ClosingStructuresInputContextProperties.cs) (revision d5a0bce3d53deb3aef237c365018096e9bc83bb1) +++ Ringtoets/ClosingStructures/src/Ringtoets.ClosingStructures.Forms/PropertyClasses/ClosingStructuresInputContextProperties.cs (.../ClosingStructuresInputContextProperties.cs) (revision f3c7ae4cc9069268dba97e9dd691bf449fa393db) @@ -178,7 +178,9 @@ get { return new NormalDistributionProperties( - DistributionPropertiesReadOnly.None, + HasStructure() + ? DistributionPropertiesReadOnly.None + : DistributionPropertiesReadOnly.All, data.WrappedData.InsideWaterLevel, PropertyChangeHandler); } @@ -284,7 +286,9 @@ get { return new NormalDistributionProperties( - DistributionPropertiesReadOnly.None, + HasStructure() + ? DistributionPropertiesReadOnly.None + : DistributionPropertiesReadOnly.All, data.WrappedData.ThresholdHeightOpenWeir, PropertyChangeHandler); } @@ -301,7 +305,9 @@ get { return new LogNormalDistributionProperties( - DistributionPropertiesReadOnly.None, + HasStructure() + ? DistributionPropertiesReadOnly.None + : DistributionPropertiesReadOnly.All, data.WrappedData.AreaFlowApertures, PropertyChangeHandler); } @@ -372,7 +378,9 @@ get { return new NormalDistributionProperties( - DistributionPropertiesReadOnly.None, + HasStructure() + ? DistributionPropertiesReadOnly.None + : DistributionPropertiesReadOnly.All, data.WrappedData.LevelCrestStructureNotClosing, PropertyChangeHandler); } Index: Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/PropertyClasses/ClosingStructuresInputContextPropertiesTest.cs =================================================================== diff -u -r37fc59cc0f3becb92e14b8263bd8e9fc71aa0e79 -rf3c7ae4cc9069268dba97e9dd691bf449fa393db --- Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/PropertyClasses/ClosingStructuresInputContextPropertiesTest.cs (.../ClosingStructuresInputContextPropertiesTest.cs) (revision 37fc59cc0f3becb92e14b8263bd8e9fc71aa0e79) +++ Ringtoets/ClosingStructures/test/Ringtoets.ClosingStructures.Forms.Test/PropertyClasses/ClosingStructuresInputContextPropertiesTest.cs (.../ClosingStructuresInputContextPropertiesTest.cs) (revision f3c7ae4cc9069268dba97e9dd691bf449fa393db) @@ -182,11 +182,7 @@ const string schematizationCategory = "Schematisatie"; const string modelSettingsCategory = "Modelinstellingen"; - var dynamicPropertyBag = new DynamicPropertyBag(properties); - PropertyDescriptorCollection dynamicProperties = dynamicPropertyBag.GetProperties(new Attribute[] - { - new BrowsableAttribute(true) - }); + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); Assert.AreEqual(22, dynamicProperties.Count); PropertyDescriptor inflowModelTypeProperty = dynamicProperties[verticalWallInflowModelTypePropertyIndex]; @@ -280,11 +276,7 @@ const string hydraulicDataCategory = "Hydraulische gegevens"; const string modelSettingsCategory = "Modelinstellingen"; - var dynamicPropertyBag = new DynamicPropertyBag(properties); - PropertyDescriptorCollection dynamicProperties = dynamicPropertyBag.GetProperties(new Attribute[] - { - new BrowsableAttribute(true) - }); + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); Assert.AreEqual(21, dynamicProperties.Count); PropertyDescriptor insideWaterLevelProperty = dynamicProperties[floodedCulvertInsideWaterLevelPropertyIndex]; @@ -387,11 +379,7 @@ const string hydraulicDataCategory = "Hydraulische gegevens"; const string modelSettingsCategory = "Modelinstellingen"; - var dynamicPropertyBag = new DynamicPropertyBag(properties); - PropertyDescriptorCollection dynamicProperties = dynamicPropertyBag.GetProperties(new Attribute[] - { - new BrowsableAttribute(true) - }); + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); Assert.AreEqual(22, dynamicProperties.Count); PropertyDescriptor insideWaterLevelProperty = dynamicProperties[lowSillInsideWaterLevelPropertyIndex]; @@ -400,13 +388,13 @@ Assert.AreEqual("Binnenwaterstand [m+NAP]", insideWaterLevelProperty.DisplayName); Assert.AreEqual("Binnenwaterstand.", insideWaterLevelProperty.Description); - PropertyDescriptor inflowModelTypeProperty = dynamicProperties[lowSillInflowModelTypePropertyIndex]; + PropertyDescriptor inflowModelTypeProperty = dynamicProperties[5]; Assert.IsInstanceOf(inflowModelTypeProperty.Converter); Assert.AreEqual(schematizationCategory, inflowModelTypeProperty.Category); Assert.AreEqual("Instroommodel", inflowModelTypeProperty.DisplayName); Assert.AreEqual("Instroommodel van het kunstwerk.", inflowModelTypeProperty.Description); - PropertyDescriptor identicalAperturesProperty = dynamicProperties[lowSillIdenticalAperturesPropertyIndex]; + PropertyDescriptor identicalAperturesProperty = dynamicProperties[7]; Assert.IsFalse(identicalAperturesProperty.IsReadOnly); Assert.AreEqual(schematizationCategory, identicalAperturesProperty.Category); Assert.AreEqual("Aantal identieke doorstroomopeningen [-]", identicalAperturesProperty.DisplayName); @@ -418,19 +406,19 @@ Assert.AreEqual("Drempelhoogte [m+NAP]", thresholdHeightOpenWeirProperty.DisplayName); Assert.AreEqual("Drempelhoogte niet gesloten kering of hoogte van de onderkant van de wand/drempel.", thresholdHeightOpenWeirProperty.Description); - PropertyDescriptor probabilityOrFrequencyOpenStructureBeforeFloodingProperty = dynamicProperties[lowSillProbabilityOrFrequencyOpenStructureBeforeFloodingPropertyIndex]; + PropertyDescriptor probabilityOrFrequencyOpenStructureBeforeFloodingProperty = dynamicProperties[13]; Assert.IsFalse(probabilityOrFrequencyOpenStructureBeforeFloodingProperty.IsReadOnly); Assert.AreEqual(schematizationCategory, probabilityOrFrequencyOpenStructureBeforeFloodingProperty.Category); Assert.AreEqual("Kans op open staan bij naderend hoogwater [1/jaar]", probabilityOrFrequencyOpenStructureBeforeFloodingProperty.DisplayName); Assert.AreEqual("Kans op open staan bij naderend hoogwater.", probabilityOrFrequencyOpenStructureBeforeFloodingProperty.Description); - PropertyDescriptor failureProbabilityOpenStructureProperty = dynamicProperties[lowSillFailureProbabilityOpenStructurePropertyIndex]; + PropertyDescriptor failureProbabilityOpenStructureProperty = dynamicProperties[14]; Assert.IsFalse(failureProbabilityOpenStructureProperty.IsReadOnly); Assert.AreEqual(schematizationCategory, failureProbabilityOpenStructureProperty.Category); Assert.AreEqual("Kans mislukken sluiting [1/jaar]", failureProbabilityOpenStructureProperty.DisplayName); Assert.AreEqual("Kans op mislukken sluiting van geopend kunstwerk.", failureProbabilityOpenStructureProperty.Description); - PropertyDescriptor failureProbabilityReparationProperty = dynamicProperties[lowSillFailureProbabilityReparationPropertyIndex]; + PropertyDescriptor failureProbabilityReparationProperty = dynamicProperties[15]; Assert.IsFalse(failureProbabilityReparationProperty.IsReadOnly); Assert.AreEqual(schematizationCategory, failureProbabilityReparationProperty.Category); Assert.AreEqual("Faalkans herstel van gefaalde situatie [1/jaar]", failureProbabilityReparationProperty.DisplayName); @@ -462,6 +450,49 @@ } [Test] + public void Constructor_WithoutStructure_CorrectReadOnlyForStructureDependentProperties() + { + // Setup + var assessmentSectionStub = mockRepository.Stub(); + var handler = mockRepository.Stub(); + mockRepository.ReplayAll(); + + var failureMechanism = new ClosingStructuresFailureMechanism(); + var calculation = new StructuresCalculation(); + + var inputContext = new ClosingStructuresInputContext(calculation.InputParameters, + calculation, + failureMechanism, + assessmentSectionStub); + + // Call + var properties = new ClosingStructuresInputContextProperties(inputContext, handler); + + // Assert + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + + PropertyDescriptor inflowModelType = dynamicProperties[5]; + Assert.IsTrue(inflowModelType.IsReadOnly); + + PropertyDescriptor identicalApertures = dynamicProperties[8]; + Assert.IsTrue(identicalApertures.IsReadOnly); + + PropertyDescriptor probabilityOrFrequencyOpenStructureBeforeFlooding = dynamicProperties[15]; + Assert.IsTrue(probabilityOrFrequencyOpenStructureBeforeFlooding.IsReadOnly); + + PropertyDescriptor failureProbabilityOpenStructure = dynamicProperties[16]; + Assert.IsTrue(failureProbabilityOpenStructure.IsReadOnly); + + PropertyDescriptor failureProbabilityReparation = dynamicProperties[17]; + Assert.IsTrue(failureProbabilityReparation.IsReadOnly); + + AssertPropertiesInState(properties.ThresholdHeightOpenWeir, true); + AssertPropertiesInState(properties.AreaFlowApertures, true); + AssertPropertiesInState(properties.LevelCrestStructureNotClosing, true); + AssertPropertiesInState(properties.InsideWaterLevel, true); + } + + [Test] public void GetAvailableForeshoreProfiles_SetInputContextInstanceWithForeshoreProfiles_ReturnForeshoreProfiles() { // Setup @@ -1108,6 +1139,7 @@ var calculation = new StructuresCalculation(); ClosingStructuresInput input = calculation.InputParameters; input.ForeshoreProfile = new TestForeshoreProfile(); + input.Structure = new TestClosingStructure(); var customHandler = new CalculationInputSetPropertyValueAfterConfirmationParameterTester(new[] { @@ -1129,8 +1161,44 @@ mockRepository.VerifyAll(); } + private static void AssertPropertiesInState(object properties, bool expectedReadOnly) + { + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + Assert.AreEqual(3, dynamicProperties.Count); + + Assert.AreEqual(expectedReadOnly, dynamicProperties[1].IsReadOnly); + Assert.AreEqual(expectedReadOnly, dynamicProperties[2].IsReadOnly); + } + #region Property indices +// #region No structure indices +// +// private const int verticalWallHydraulicBoundaryLocationPropertyIndex = 0; +// private const int verticalWallStormDurationPropertyIndex = 1; +// private const int verticalWallStructurePropertyIndex = 2; +// private const int verticalWallStructureLocationPropertyIndex = 3; +// private const int verticalWallStructureNormalOrientationPropertyIndex = 4; +// private const int verticalWallInflowModelTypePropertyIndex = 5; +// private const int verticalWallWidthFlowAperturesPropertyIndex = 6; +// private const int verticalWallIdenticalAperturesPropertyIndex = 7; +// private const int verticalWallFlowWidthAtBottomProtectionPropertyIndex = 8; +// private const int verticalWallStorageStructureAreaPropertyIndex = 9; +// private const int verticalWallAllowedLevelIncreaseStoragePropertyIndex = 10; +// private const int verticalWallLevelCrestStructureNotClosingPropertyIndex = 11; +// private const int verticalWallCriticalOvertoppingDischargePropertyIndex = 12; +// private const int verticalWallProbabilityOrFrequencyOpenStructureBeforeFloodingPropertyIndex = 13; +// private const int verticalWallFailureProbabilityOpenStructurePropertyIndex = 14; +// private const int verticalWallFailureProbabilityReparationPropertyIndex = 15; +// private const int verticalWallFailureProbabilityStructureWithErosionPropertyIndex = 16; +// private const int verticalWallForeshoreProfilePropertyIndex = 17; +// private const int verticalWallUseBreakWaterPropertyIndex = 18; +// private const int verticalWallUseForeshorePropertyIndex = 19; +// private const int verticalWallModelFactorSuperCriticalFlowPropertyIndex = 20; +// private const int verticalWallFactorStormDurationOpenStructurePropertyIndex = 21; +// +// #endregion + #region VerticalWall structures indices private const int verticalWallHydraulicBoundaryLocationPropertyIndex = 0; @@ -1165,17 +1233,12 @@ private const int lowSillInsideWaterLevelPropertyIndex = 2; private const int lowSillStructurePropertyIndex = 3; private const int lowSillStructureLocationPropertyIndex = 4; - private const int lowSillInflowModelTypePropertyIndex = 5; private const int lowSillWidthFlowAperturesPropertyIndex = 6; - private const int lowSillIdenticalAperturesPropertyIndex = 7; private const int lowSillFlowWidthAtBottomProtectionPropertyIndex = 8; private const int lowSillStorageStructureAreaPropertyIndex = 9; private const int lowSillAllowedLevelIncreaseStoragePropertyIndex = 10; private const int lowSillThresholdHeightOpenWeirPropertyIndex = 11; private const int lowSillCriticalOvertoppingDischargePropertyIndex = 12; - private const int lowSillProbabilityOrFrequencyOpenStructureBeforeFloodingPropertyIndex = 13; - private const int lowSillFailureProbabilityOpenStructurePropertyIndex = 14; - private const int lowSillFailureProbabilityReparationPropertyIndex = 15; private const int lowSillFailureProbabilityStructureWithErosionPropertyIndex = 16; private const int lowSillForeshoreProfilePropertyIndex = 17; private const int lowSillUseBreakWaterPropertyIndex = 18; Index: Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/StructuresInputBaseProperties.cs =================================================================== diff -u -re6cb95313c163aebfb0f01470855068785ce61bb -rf3c7ae4cc9069268dba97e9dd691bf449fa393db --- Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/StructuresInputBaseProperties.cs (.../StructuresInputBaseProperties.cs) (revision e6cb95313c163aebfb0f01470855068785ce61bb) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/PropertyClasses/StructuresInputBaseProperties.cs (.../StructuresInputBaseProperties.cs) (revision f3c7ae4cc9069268dba97e9dd691bf449fa393db) @@ -349,6 +349,7 @@ } } + [DynamicReadOnly] [DynamicPropertyOrder] [ResourcesCategory(typeof(Resources), nameof(Resources.Categories_Schematization))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.Structure_StructureNormalOrientation_DisplayName))] @@ -375,7 +376,9 @@ get { return new LogNormalDistributionProperties( - DistributionPropertiesReadOnly.None, + HasStructure() + ? DistributionPropertiesReadOnly.None + : DistributionPropertiesReadOnly.All, data.WrappedData.FlowWidthAtBottomProtection, PropertyChangeHandler); } @@ -391,7 +394,9 @@ get { return new NormalDistributionProperties( - DistributionPropertiesReadOnly.None, + HasStructure() + ? DistributionPropertiesReadOnly.None + : DistributionPropertiesReadOnly.All, data.WrappedData.WidthFlowApertures, PropertyChangeHandler); } @@ -407,7 +412,9 @@ get { return new VariationCoefficientLogNormalDistributionProperties( - VariationCoefficientDistributionPropertiesReadOnly.None, + HasStructure() + ? VariationCoefficientDistributionPropertiesReadOnly.None + : VariationCoefficientDistributionPropertiesReadOnly.All, data.WrappedData.StorageStructureArea, PropertyChangeHandler); } @@ -423,7 +430,9 @@ get { return new LogNormalDistributionProperties( - DistributionPropertiesReadOnly.None, + HasStructure() + ? DistributionPropertiesReadOnly.None + : DistributionPropertiesReadOnly.All, data.WrappedData.AllowedLevelIncreaseStorage, PropertyChangeHandler); } @@ -439,7 +448,9 @@ get { return new VariationCoefficientLogNormalDistributionProperties( - VariationCoefficientDistributionPropertiesReadOnly.None, + HasStructure() + ? VariationCoefficientDistributionPropertiesReadOnly.None + : VariationCoefficientDistributionPropertiesReadOnly.All, data.WrappedData.CriticalOvertoppingDischarge, PropertyChangeHandler); } @@ -550,5 +561,21 @@ } #endregion + + protected bool HasStructure() + { + return data.WrappedData.Structure != null; + } + + [DynamicReadOnlyValidationMethod] + public bool IsReadOnly(string property) + { + if (property == nameof(StructureNormalOrientation)) + { + return !HasStructure(); + } + + return false; + } } } \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/StructuresInputBasePropertiesTest.cs =================================================================== diff -u -r8cd6600dd3e505a336f657b1e63362ac3b94943c -rf3c7ae4cc9069268dba97e9dd691bf449fa393db --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/StructuresInputBasePropertiesTest.cs (.../StructuresInputBasePropertiesTest.cs) (revision 8cd6600dd3e505a336f657b1e63362ac3b94943c) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/PropertyClasses/StructuresInputBasePropertiesTest.cs (.../StructuresInputBasePropertiesTest.cs) (revision f3c7ae4cc9069268dba97e9dd691bf449fa393db) @@ -184,12 +184,7 @@ const string hydraulicDataCategory = "Hydraulische gegevens"; const string modelSettingsCategory = "Modelinstellingen"; - var dynamicPropertyBag = new DynamicPropertyBag(properties); - PropertyDescriptorCollection dynamicProperties = dynamicPropertyBag.GetProperties( - new Attribute[] - { - new BrowsableAttribute(true) - }); + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); Assert.AreEqual(15, dynamicProperties.Count); PropertyDescriptor structureProperty = dynamicProperties[constructionProperties.StructurePropertyIndex]; @@ -205,7 +200,7 @@ Assert.AreEqual("De coördinaten van de locatie van het kunstwerk in het Rijksdriehoeksstelsel.", structureLocationProperty.Description); PropertyDescriptor structureNormalOrientationProperty = dynamicProperties[constructionProperties.StructureNormalOrientationPropertyIndex]; - Assert.IsFalse(structureNormalOrientationProperty.IsReadOnly); + Assert.IsTrue(structureNormalOrientationProperty.IsReadOnly); Assert.AreEqual(schematizationCategory, structureNormalOrientationProperty.Category); Assert.AreEqual("Oriëntatie [°]", structureNormalOrientationProperty.DisplayName); Assert.AreEqual("Oriëntatie van de normaal van het kunstwerk ten opzichte van het noorden.", structureNormalOrientationProperty.Description); @@ -288,6 +283,52 @@ } [Test] + [TestCase(true)] + [TestCase(false)] + public void Constructor_WithOrWithoutStructure_CorrectReadOnlyForStructureDependentProperties(bool hasStructure) + { + // Setup + mockRepository.ReplayAll(); + + StructuresInputBaseProperties< + SimpleStructure, + SimpleStructureInput, + StructuresCalculation, + IFailureMechanism> + .ConstructionProperties constructionProperties = GetRandomConstructionProperties(); + var calculation = new StructuresCalculation(); + var inputContext = new SimpleInputContext(calculation.InputParameters, + calculation, + failureMechanism, + assessmentSection); + + if (hasStructure) + { + calculation.InputParameters.Structure = new SimpleStructure(); + } + + // Call + var properties = new SimpleStructuresInputProperties( + inputContext, + constructionProperties, + handler); + + // Assert + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + + bool expectedReadOnly = !hasStructure; + + PropertyDescriptor structureNormalOrientationProperty = dynamicProperties[constructionProperties.StructureNormalOrientationPropertyIndex]; + Assert.AreEqual(expectedReadOnly, structureNormalOrientationProperty.IsReadOnly); + + AssertPropertiesInState(properties.FlowWidthAtBottomProtection, expectedReadOnly); + AssertPropertiesInState(properties.WidthFlowApertures, expectedReadOnly); + AssertPropertiesInState(properties.StorageStructureArea, expectedReadOnly); + AssertPropertiesInState(properties.AllowedLevelIncreaseStorage, expectedReadOnly); + AssertPropertiesInState(properties.CriticalOvertoppingDischarge, expectedReadOnly); + } + + [Test] public void SelectedHydraulicBoundaryLocation_InputNoLocation_ReturnsNull() { // Setup @@ -1139,6 +1180,7 @@ var calculation = new StructuresCalculation(); SimpleStructureInput input = calculation.InputParameters; input.ForeshoreProfile = new TestForeshoreProfile(); + input.Structure = new SimpleStructure(); var customHandler = new CalculationInputSetPropertyValueAfterConfirmationParameterTester(new[] { @@ -1159,5 +1201,14 @@ mockRepository.VerifyAll(); } + + private static void AssertPropertiesInState(object properties, bool expectedReadOnly) + { + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + Assert.AreEqual(3, dynamicProperties.Count); + + Assert.AreEqual(expectedReadOnly, dynamicProperties[1].IsReadOnly); + Assert.AreEqual(expectedReadOnly, dynamicProperties[2].IsReadOnly); + } } } \ No newline at end of file Index: Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/PropertyClasses/StabilityPointStructuresInputContextPropertiesTest.cs =================================================================== diff -u -r37fc59cc0f3becb92e14b8263bd8e9fc71aa0e79 -rf3c7ae4cc9069268dba97e9dd691bf449fa393db --- Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/PropertyClasses/StabilityPointStructuresInputContextPropertiesTest.cs (.../StabilityPointStructuresInputContextPropertiesTest.cs) (revision 37fc59cc0f3becb92e14b8263bd8e9fc71aa0e79) +++ Ringtoets/StabilityPointStructures/test/Ringtoets.StabilityPointStructures.Forms.Test/PropertyClasses/StabilityPointStructuresInputContextPropertiesTest.cs (.../StabilityPointStructuresInputContextPropertiesTest.cs) (revision f3c7ae4cc9069268dba97e9dd691bf449fa393db) @@ -1543,6 +1543,7 @@ var calculation = new StructuresCalculation(); StabilityPointStructuresInput input = calculation.InputParameters; input.ForeshoreProfile = new TestForeshoreProfile(); + input.Structure = new TestStabilityPointStructure(); var customHandler = new CalculationInputSetPropertyValueAfterConfirmationParameterTester(new[] {