Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.Designer.cs =================================================================== diff -u -r641a957869c1ac248664e3646e1f16fa04587a01 -r2c3d6c0c61ee5252cacdcf66e9e616bd2c3e1ffa --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.Designer.cs (.../MacroStabilityInwardsScenariosView.Designer.cs) (revision 641a957869c1ac248664e3646e1f16fa04587a01) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.Designer.cs (.../MacroStabilityInwardsScenariosView.Designer.cs) (revision 2c3d6c0c61ee5252cacdcf66e9e616bd2c3e1ffa) @@ -22,6 +22,7 @@ using System; using System.ComponentModel; using System.Windows.Forms; +using Riskeer.Common.Forms.Controls; namespace Riskeer.MacroStabilityInwards.Forms.Views { @@ -41,6 +42,7 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); + this.lengthEffectSettingsControl = new LengthEffectSettingsControl(); this.splitContainer = new System.Windows.Forms.SplitContainer(); this.tableLayoutPanelListBox = new System.Windows.Forms.TableLayoutPanel(); this.label = new System.Windows.Forms.Label(); @@ -120,6 +122,7 @@ this.tableLayoutPanelDataGrid.Controls.Add(this.labelTotalScenarioContribution, 0, 3); this.tableLayoutPanelDataGrid.Controls.Add(this.dataGridViewControl, 0, 2); this.tableLayoutPanelDataGrid.Controls.Add(this.labelCalculations, 0, 1); + this.tableLayoutPanelDataGrid.Controls.Add(this.lengthEffectSettingsControl, 0, 0); this.tableLayoutPanelDataGrid.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanelDataGrid.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanelDataGrid.Name = "tableLayoutPanelDataGrid"; @@ -131,6 +134,16 @@ this.tableLayoutPanelDataGrid.Size = new System.Drawing.Size(1003, 797); this.tableLayoutPanelDataGrid.TabIndex = 0; // + // lengthEffectSettingsControl + // + this.lengthEffectSettingsControl.AutoSize = true; + this.lengthEffectSettingsControl.Enabled = true; + this.lengthEffectSettingsControl.Visible = true; + this.lengthEffectSettingsControl.Dock = System.Windows.Forms.DockStyle.Fill; + this.lengthEffectSettingsControl.Location = new System.Drawing.Point(3, 3); + this.lengthEffectSettingsControl.Name = "lengthEffectSettingsControl"; + this.lengthEffectSettingsControl.Size = new System.Drawing.Size(1003, 52); + // // labelTotalScenarioContribution // this.labelTotalScenarioContribution.AutoSize = true; @@ -184,19 +197,14 @@ this.ResumeLayout(false); } + private Riskeer.Common.Forms.Controls.LengthEffectSettingsControl lengthEffectSettingsControl; private System.Windows.Forms.ErrorProvider errorProvider; - private System.Windows.Forms.Label labelCalculations; - private Core.Common.Controls.DataGrid.DataGridViewControl dataGridViewControl; - private System.Windows.Forms.Label labelTotalScenarioContribution; - private System.Windows.Forms.TableLayoutPanel tableLayoutPanelDataGrid; - private System.Windows.Forms.Label label; private System.Windows.Forms.ListBox listBox; - private System.Windows.Forms.SplitContainer splitContainer; private System.Windows.Forms.TableLayoutPanel tableLayoutPanelListBox; Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.cs =================================================================== diff -u -r641a957869c1ac248664e3646e1f16fa04587a01 -r2c3d6c0c61ee5252cacdcf66e9e616bd2c3e1ffa --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.cs (.../MacroStabilityInwardsScenariosView.cs) (revision 641a957869c1ac248664e3646e1f16fa04587a01) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.cs (.../MacroStabilityInwardsScenariosView.cs) (revision 2c3d6c0c61ee5252cacdcf66e9e616bd2c3e1ffa) @@ -56,7 +56,6 @@ private IEnumerable scenarioRows; private MacroStabilityInwardsScenarioViewFailureMechanismSectionViewModel selectedFailureMechanismSection; - private int lengthEffectRoundNNrOfDecimals; /// /// Creates a new instance of . @@ -90,6 +89,7 @@ UpdateSectionsListBox(); UpdateScenarioControls(); + UpdateLengthEffectControl(); } public object Data @@ -119,14 +119,19 @@ failureMechanismObserver = new Observer(() => { UpdateSectionsListBox(); + UpdateLengthEffectControl(); }) { Observable = failureMechanism }; scenarioConfigurationsPerFailureMechanismSectionObserver = new RecursiveObserver, MacroStabilityInwardsScenarioConfigurationPerFailureMechanismSection>( - UpdateSectionsListBox, section => section) + () => + { + UpdateSectionsListBox(); + UpdateScenarioRows(); + }, section => section) { Observable = failureMechanism.ScenarioConfigurationsPerFailureMechanismSection }; @@ -187,6 +192,7 @@ { selectedFailureMechanismSection = listBox.SelectedItem as MacroStabilityInwardsScenarioViewFailureMechanismSectionViewModel; UpdateScenarioControls(); + UpdateLengthEffectControl(); } private void UpdateScenarioRows() @@ -283,5 +289,16 @@ return calculations.Select(pc => new MacroStabilityInwardsScenarioRow(pc, failureMechanism, selectedFailureMechanismSection.ScenarioConfigurationPerSection)).ToList(); } + + private void UpdateLengthEffectControl() + { + lengthEffectSettingsControl.ClearData(); + + if (selectedFailureMechanismSection != null) + { + lengthEffectSettingsControl.SetData(selectedFailureMechanismSection.ScenarioConfigurationPerSection, + failureMechanism.ProbabilityAssessmentInput.B); + } + } } } \ No newline at end of file Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsScenariosViewTest.cs =================================================================== diff -u -r8f317af3dd0e16a172df457f3d063f819b2b9970 -r2c3d6c0c61ee5252cacdcf66e9e616bd2c3e1ffa --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsScenariosViewTest.cs (.../MacroStabilityInwardsScenariosViewTest.cs) (revision 8f317af3dd0e16a172df457f3d063f819b2b9970) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.Forms.Test/Views/MacroStabilityInwardsScenariosViewTest.cs (.../MacroStabilityInwardsScenariosViewTest.cs) (revision 2c3d6c0c61ee5252cacdcf66e9e616bd2c3e1ffa) @@ -34,6 +34,7 @@ using Riskeer.Common.Data.Calculation; using Riskeer.Common.Data.FailureMechanism; using Riskeer.Common.Data.TestUtil; +using Riskeer.Common.Forms.Controls; using Riskeer.MacroStabilityInwards.Data; using Riskeer.MacroStabilityInwards.Data.TestUtil; using Riskeer.MacroStabilityInwards.Forms.PresentationObjects; @@ -158,20 +159,14 @@ } [Test] - public void Constructor_LengthEffectControlsCorrectlyInitialized() + public void Constructor_LengthEffectSettingsControlCorrectlyInitialized() { // Call ShowMacroStabilityInwardsScenariosView(new MacroStabilityInwardsFailureMechanism()); // Assert - var lengthEffectALabel = (Label) new LabelTester("parameterALabel").TheObject; - Assert.AreEqual("Lengte-effect parameter a [-]", lengthEffectALabel.Text); - - var lengthEffectNRoundedLabel = (Label) new LabelTester("lengthEffectNRoundedLabel").TheObject; - Assert.AreEqual("Lengte-effect parameter Nvak* [-]", lengthEffectNRoundedLabel.Text); - - var lengthEffectNRoundedTextBox = (TextBox) new ControlTester("lengthEffectNRoundedTextBox").TheObject; - Assert.IsFalse(lengthEffectNRoundedTextBox.Enabled); + LengthEffectSettingsControl lengthEffectSettingsControl = GetLengthEffectSettingsControl(); + Assert.IsTrue(lengthEffectSettingsControl.Visible); } [Test] @@ -337,9 +332,11 @@ var listBox = (ListBox) new ControlTester("listBox").TheObject; var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; - var parameterATextBox = (TextBox) new ControlTester("parameterATextBox").TheObject; - var lengthEffectNRoundedTextBox = (TextBox) new ControlTester("lengthEffectNRoundedTextBox").TheObject; + TextBoxTester parameterATextBox = GetParameterATextBoxTester(); + LengthEffectSettingsControl lengthEffectSettingsControl = GetLengthEffectSettingsControl(); + TextBox lengthEffectNRoundedTextBox = GetLengthEffectNRoundedTextBox(lengthEffectSettingsControl); + // Precondition Assert.AreSame(failureMechanism.Sections.First(), ((MacroStabilityInwardsScenarioViewFailureMechanismSectionViewModel) listBox.SelectedItem).Section); Assert.AreEqual("0,033", parameterATextBox.Text); @@ -366,63 +363,11 @@ } [Test] - public void GivenMacroStabilityInwardsScenariosView_WhenSettingNewAValue_ThenControlsUpdatedAndObserversNotified() + public void GivenMacroStabilityInwardsScenariosView_WhenSettingNewParameterA_ThenDataGridViewUpdated() { // Given - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - observer.Expect(o => o.UpdateObserver()); - mocks.ReplayAll(); + ShowFullyConfiguredMacroStabilityInwardsScenariosView(); - var surfaceLine = new MacroStabilityInwardsSurfaceLine("Surface line 1") - { - ReferenceLineIntersectionWorldPoint = new Point2D(0.0, 0.0) - }; - - surfaceLine.SetGeometry(new[] - { - new Point3D(0.0, 5.0, 0.0), - new Point3D(0.0, 0.0, 1.0), - new Point3D(0.0, -5.0, 0.0) - }); - - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - failureMechanism.SetSections(new[] - { - FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] - { - new Point2D(0, 0), - new Point2D(100, 0) - }) - }, string.Empty); - failureMechanism.CalculationsGroup.Children.AddRange(new[] - { - new MacroStabilityInwardsCalculationScenario - { - Name = "Calculation 1", - InputParameters = - { - SurfaceLine = surfaceLine - }, - Contribution = (RoundedDouble) 0.13701 - }, - new MacroStabilityInwardsCalculationScenario - { - Name = "Calculation 2", - InputParameters = - { - SurfaceLine = surfaceLine - }, - IsRelevant = false - } - }); - - MacroStabilityInwardsScenarioConfigurationPerFailureMechanismSection affectedConfiguration = - failureMechanism.ScenarioConfigurationsPerFailureMechanismSection.First(); - affectedConfiguration.Attach(observer); - - ShowMacroStabilityInwardsScenariosView(failureMechanism); - var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; MacroStabilityInwardsScenarioRow[] sectionResultRows = dataGridView.Rows.Cast() .Select(r => r.DataBoundItem) @@ -434,90 +379,26 @@ textBoxTester.Enter("0,7"); // Then - Assert.AreEqual(0.7, affectedConfiguration.A); - - var lengthEffectNRoundedTextBox = (TextBox) new ControlTester("lengthEffectNRoundedTextBox").TheObject; - Assert.AreEqual("2,40", lengthEffectNRoundedTextBox.Text); - MacroStabilityInwardsScenarioRow[] updatedRows = dataGridView.Rows.Cast() .Select(r => r.DataBoundItem) .Cast() .ToArray(); CollectionAssert.AreNotEquivalent(sectionResultRows, updatedRows); - - mocks.VerifyAll(); } [Test] - [SetCulture("nl-NL")] - public void GivenMacroStabilityInwardsScenariosViewWithLengthEffectError_WhenSettingValidValue_ThenErrorClearedAndLengthEffectControlsUpdated() - { - // Given - MacroStabilityInwardsScenariosView view = ShowFullyConfiguredMacroStabilityInwardsScenariosView(); - - // Precondition - var textBoxTester = new TextBoxTester("parameterATextBox"); - textBoxTester.Enter("NotADouble"); - - ErrorProvider errorProvider = GetLengthEffectErrorProvider(view); - var parameterATextBox = (TextBox) new ControlTester("parameterATextBox").TheObject; - string errorMessage = errorProvider.GetError(parameterATextBox); - Assert.IsNotEmpty(errorMessage); - - var lengthEffectNRoundedTextBox = (TextBox) new ControlTester("lengthEffectNRoundedTextBox").TheObject; - Assert.IsEmpty(lengthEffectNRoundedTextBox.Text); - - // When - textBoxTester.Enter("0,6"); - - // Then - errorMessage = errorProvider.GetError(parameterATextBox); - Assert.IsEmpty(errorMessage); - - Assert.AreEqual("0,600", parameterATextBox.Text); - Assert.AreEqual("1,96", lengthEffectNRoundedTextBox.Text); - } - - [Test] - public void GivenMacroStabilityInwardsScenariosViewWithoutLengthEffectError_WhenSettingInvalidValue_ThenErrorSetAndLengthEffectControlsUpdated() - { - // Given - MacroStabilityInwardsScenariosView view = ShowFullyConfiguredMacroStabilityInwardsScenariosView(); - - // Precondition - var parameterATextBox = (TextBox) new ControlTester("parameterATextBox").TheObject; - Assert.AreEqual("0,033", parameterATextBox.Text); - - ErrorProvider errorProvider = GetLengthEffectErrorProvider(view); - string errorMessage = errorProvider.GetError(parameterATextBox); - Assert.IsEmpty(errorMessage); - - var lengthEffectNRoundedTextBox = (TextBox) new ControlTester("lengthEffectNRoundedTextBox").TheObject; - Assert.AreEqual("1,05", lengthEffectNRoundedTextBox.Text); - - // When - var textBoxTester = new TextBoxTester("parameterATextBox"); - textBoxTester.Enter("NotADouble"); - - // Then - errorMessage = errorProvider.GetError(parameterATextBox); - Assert.IsNotEmpty(errorMessage); - - Assert.IsEmpty(lengthEffectNRoundedTextBox.Text); - } - - [Test] public void GivenMacroStabilityInwardsScenariosViewWithLengthEffectError_WhenSelectingDifferentItemInSectionsListBox_ThenErrorCleared() { // Setup - MacroStabilityInwardsScenariosView view = ShowFullyConfiguredMacroStabilityInwardsScenariosView(); + ShowFullyConfiguredMacroStabilityInwardsScenariosView(); - var textBoxTester = new TextBoxTester("parameterATextBox"); + TextBoxTester textBoxTester = GetParameterATextBoxTester(); textBoxTester.Enter("NotADouble"); // Precondition - ErrorProvider errorProvider = GetLengthEffectErrorProvider(view); - var parameterATextBox = (TextBox) new ControlTester("parameterATextBox").TheObject; + LengthEffectSettingsControl lengthEffectSettingsControl = GetLengthEffectSettingsControl(); + ErrorProvider errorProvider = GetLengthEffectErrorProvider(lengthEffectSettingsControl); + var parameterATextBox = (TextBox) textBoxTester.TheObject; string errorMessage = errorProvider.GetError(parameterATextBox); Assert.IsNotEmpty(errorMessage); @@ -531,62 +412,19 @@ } [Test] - [SetCulture("nl-NL")] - public void GivenMacroStabilityInwardsScenariosView_WhenSettingInvalidValueAndEscPressed_ThenLengthEffectControlsSetToInitialValues() + public void GivenMacroStabilityInwardsScenariosViewWithSections_WhenSectionsClearedAndFailureMechanismNotifiesObserver_ThenLengthEffectSettingsControlUpdated() { // Given - const double initialValue = 0.5; - const string initialValueText = "0,500"; - - var mocks = new MockRepository(); - var observer = mocks.StrictMock(); - mocks.ReplayAll(); - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); - ConfigureFailureMechanism(failureMechanism); - MacroStabilityInwardsScenarioConfigurationPerFailureMechanismSection firstConfigurationPerSection = - failureMechanism.ScenarioConfigurationsPerFailureMechanismSection.First(); - firstConfigurationPerSection.A = (RoundedDouble) initialValue; - - ShowMacroStabilityInwardsScenariosView(failureMechanism); - - var textBoxTester = new ControlTester("parameterATextBox"); - const Keys keyData = Keys.Escape; - - var parameterATextBox = (TextBox) new ControlTester("parameterATextBox").TheObject; - parameterATextBox.TextChanged += (sender, args) => - { - textBoxTester.FireEvent("KeyDown", new KeyEventArgs(keyData)); - }; - - // Precondition - Assert.AreEqual(initialValueText, parameterATextBox.Text); - - failureMechanism.AssemblyResult.Attach(observer); - - // When - parameterATextBox.Text = "NotAProbability"; - - // Then - Assert.AreEqual(initialValueText, parameterATextBox.Text); - Assert.AreEqual(initialValue, firstConfigurationPerSection.A); - - mocks.VerifyAll(); - } - - [Test] - public void GivenMacroStabilityInwardsScenariosViewWithSections_WhenSectionsClearedAndFailureMechanismNotifiesObserver_ThenLengthEffectControlsUpdated() - { - // Given - var failureMechanism = new MacroStabilityInwardsFailureMechanism(); ShowFullyConfiguredMacroStabilityInwardsScenariosView(failureMechanism); // Precondition - var parameterATextBox = (TextBox) new ControlTester("parameterATextBox").TheObject; + var parameterATextBox = (TextBox) GetParameterATextBoxTester().TheObject; Assert.IsTrue(parameterATextBox.Enabled); Assert.IsNotEmpty(parameterATextBox.Text); - var lengthEffectNRoundedTextBox = (TextBox) new ControlTester("lengthEffectNRoundedTextBox").TheObject; + LengthEffectSettingsControl lengthEffectSettingsControl = GetLengthEffectSettingsControl(); + TextBox lengthEffectNRoundedTextBox = GetLengthEffectNRoundedTextBox(lengthEffectSettingsControl); Assert.IsNotEmpty(lengthEffectNRoundedTextBox.Text); // When @@ -601,18 +439,19 @@ } [Test] - public void GivenMacroStabilityInwardsScenariosViewWithoutSections_WhenSectionsAddedAndFailureMechanismNotifiesObserver_ThenLengthEffectControlsUpdated() + public void GivenMacroStabilityInwardsScenariosViewWithoutSections_WhenSectionsAddedAndFailureMechanismNotifiesObserver_ThenLengthEffectSettingsControlUpdated() { // Given var failureMechanism = new MacroStabilityInwardsFailureMechanism(); ShowMacroStabilityInwardsScenariosView(failureMechanism); // Precondition - var parameterATextBox = (TextBox) new ControlTester("parameterATextBox").TheObject; + var parameterATextBox = (TextBox) GetParameterATextBoxTester().TheObject; Assert.IsFalse(parameterATextBox.Enabled); Assert.IsEmpty(parameterATextBox.Text); - var lengthEffectNRoundedTextBox = (TextBox) new ControlTester("lengthEffectNRoundedTextBox").TheObject; + LengthEffectSettingsControl lengthEffectSettingsControl = GetLengthEffectSettingsControl(); + TextBox lengthEffectNRoundedTextBox = GetLengthEffectNRoundedTextBox(lengthEffectSettingsControl); Assert.IsEmpty(lengthEffectNRoundedTextBox.Text); // When @@ -1223,7 +1062,7 @@ surfaceLine1, surfaceLine2 }, string.Empty); - + FailureMechanismTestHelper.SetSections(failureMechanism, new[] { new FailureMechanismSection("Section 1", new[] @@ -1284,14 +1123,34 @@ return scenarioView; } + #region Control helpers + private static ErrorProvider GetErrorProvider(MacroStabilityInwardsScenariosView view) { return TypeUtils.GetField(view, "errorProvider"); } - private static ErrorProvider GetLengthEffectErrorProvider(MacroStabilityInwardsScenariosView view) + private static ErrorProvider GetLengthEffectErrorProvider(LengthEffectSettingsControl settingsControl) { - return TypeUtils.GetField(view, "lengthEffectErrorProvider"); + return TypeUtils.GetField(settingsControl, "lengthEffectErrorProvider"); } + + private static TextBoxTester GetParameterATextBoxTester() + { + return new TextBoxTester("parameterATextBox"); + } + + private static TextBox GetLengthEffectNRoundedTextBox(LengthEffectSettingsControl settingsControl) + { + var tableLayoutPanel = (TableLayoutPanel) settingsControl.Controls["tableLayoutPanel"]; + return (TextBox) tableLayoutPanel.GetControlFromPosition(1, 1); + } + + private static LengthEffectSettingsControl GetLengthEffectSettingsControl() + { + return (LengthEffectSettingsControl) new ControlTester("lengthEffectSettingsControl").TheObject; + } + + #endregion } } \ No newline at end of file