Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.Designer.cs =================================================================== diff -u -reaa15e0179271f292d03cd48dc2e53d997bd4b9f -r5a1b414c45cea81e1e7de86b1c98777778736b87 --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.Designer.cs (.../MacroStabilityInwardsScenariosView.Designer.cs) (revision eaa15e0179271f292d03cd48dc2e53d997bd4b9f) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.Designer.cs (.../MacroStabilityInwardsScenariosView.Designer.cs) (revision 5a1b414c45cea81e1e7de86b1c98777778736b87) @@ -70,6 +70,7 @@ // this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer.Location = new System.Drawing.Point(0, 0); + this.splitContainer.MinimumSize = new System.Drawing.Size(150, 150); this.splitContainer.Name = "splitContainer"; // // splitContainer.Panel1 @@ -80,7 +81,7 @@ // this.splitContainer.Panel2.Controls.Add(this.tableLayoutPanelDataGrid); this.splitContainer.Size = new System.Drawing.Size(1348, 797); - this.splitContainer.SplitterDistance = 449; + this.splitContainer.SplitterDistance = 341; this.splitContainer.TabIndex = 0; // // tableLayoutPanelListBox @@ -97,7 +98,7 @@ this.tableLayoutPanelListBox.RowCount = 2; this.tableLayoutPanelListBox.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tableLayoutPanelListBox.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanelListBox.Size = new System.Drawing.Size(449, 797); + this.tableLayoutPanelListBox.Size = new System.Drawing.Size(341, 797); this.tableLayoutPanelListBox.TabIndex = 0; // // label @@ -220,6 +221,8 @@ this.lengthEffectATextBox.Name = "lengthEffectATextBox"; this.lengthEffectATextBox.Size = new System.Drawing.Size(100, 20); this.lengthEffectATextBox.TabIndex = 2; + this.lengthEffectATextBox.Leave += (sender, args) => LengthEffectATextBoxLeave(sender, args); + this.lengthEffectATextBox.KeyDown += (sender, args) => LengthEffectATextBoxKeyDown(sender, args); // // lengthEffectNRoundedTextBox // Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.cs =================================================================== diff -u -r9f613c61f6adfeeee7d18bb011c5b8a13f3caeb0 -r5a1b414c45cea81e1e7de86b1c98777778736b87 --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.cs (.../MacroStabilityInwardsScenariosView.cs) (revision 9f613c61f6adfeeee7d18bb011c5b8a13f3caeb0) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.Forms/Views/MacroStabilityInwardsScenariosView.cs (.../MacroStabilityInwardsScenariosView.cs) (revision 5a1b414c45cea81e1e7de86b1c98777778736b87) @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using System.Windows.Forms; using Core.Common.Base; @@ -31,6 +32,9 @@ using Riskeer.Common.Data.AssessmentSection; using Riskeer.Common.Data.Calculation; using Riskeer.Common.Data.FailureMechanism; +using Riskeer.Common.Data.Probability; +using Riskeer.Common.Forms.Exceptions; +using Riskeer.Common.Forms.Helpers; using Riskeer.MacroStabilityInwards.Data; using Riskeer.MacroStabilityInwards.Forms.PresentationObjects; using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources; @@ -90,6 +94,9 @@ UpdateSectionsListBox(); UpdateScenarioControls(); + + UpdateLengthEffectControls(); + UpdateLengthEffectData(); } public object Data @@ -119,8 +126,8 @@ failureMechanismObserver = new Observer(() => { UpdateSectionsListBox(); - // UpdateLengthEffectControls(); - // UpdateLengthEffectData(); + UpdateLengthEffectControls(); + UpdateLengthEffectData(); }) { Observable = failureMechanism @@ -174,10 +181,10 @@ .First(sc => sc.Section == section))).ToArray(); listBox.Items.AddRange(failureMechanismSectionViewModels.Cast().ToArray()); - listBox.SelectedItem = selectedFailureMechanismSection != null - ? failureMechanismSectionViewModels.FirstOrDefault(vm => vm.Section == selectedFailureMechanismSection.Section) - ?? failureMechanismSectionViewModels.First() - : failureMechanismSectionViewModels.First(); + listBox.SelectedItem = selectedFailureMechanismSection != null + ? failureMechanismSectionViewModels.FirstOrDefault(vm => vm.Section == selectedFailureMechanismSection.Section) + ?? failureMechanismSectionViewModels.First() + : failureMechanismSectionViewModels.First(); } else { @@ -285,5 +292,105 @@ return calculations.Select(pc => new MacroStabilityInwardsScenarioRow(pc, failureMechanism, selectedFailureMechanismSection.ScenarioConfigurationPerSection)).ToList(); } + + private void LengthEffectATextBoxKeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter) + { + lengthEffectALabel.Focus(); // Focus on different component to raise a leave event on the text box + e.Handled = true; + } + + if (e.KeyCode == Keys.Escape) + { + ClearLengthEffectErrorMessage(); + SetLengthEffectData(); + e.Handled = true; + } + } + + private void LengthEffectATextBoxLeave(object sender, EventArgs e) + { + ClearLengthEffectErrorMessage(); + ProcessLengthEffectATextBox(); + } + + private void ProcessLengthEffectATextBox() + { + if (selectedFailureMechanismSection == null) + { + return; + } + + try + { + MacroStabilityInwardsScenarioConfigurationPerFailureMechanismSection scenarioConfigurationPerSection = + selectedFailureMechanismSection.ScenarioConfigurationPerSection; + scenarioConfigurationPerSection.A = RoundedDoubleParsingHelper.Parse(lengthEffectATextBox.Text, 3); + scenarioConfigurationPerSection.NotifyObservers(); + + UpdateScenarioRows(); + } + catch (Exception exception) when (exception is ArgumentOutOfRangeException + || exception is RoundedDoubleParsingException) + { + ClearNRoundedData(); + SetLengthEffectErrorMessage(exception.Message); + lengthEffectATextBox.Focus(); + } + } + + private void UpdateLengthEffectControls() + { + bool hasSection = failureMechanism.Sections.Any(); + lengthEffectATextBox.Enabled = hasSection; + lengthEffectATextBox.ReadOnly = !hasSection; + lengthEffectATextBox.Refresh(); + + lengthEffectNRoundedTextBox.Enabled = hasSection; + lengthEffectNRoundedTextBox.BackColor = hasSection ? SystemColors.Window : SystemColors.Control; + lengthEffectNRoundedTextBox.Refresh(); + } + + private void UpdateLengthEffectData() + { + ClearLengthEffectErrorMessage(); + ClearLengthEffectData(); + + if (selectedFailureMechanismSection != null) + { + SetLengthEffectData(); + } + } + + private void ClearLengthEffectData() + { + lengthEffectATextBox.Text = string.Empty; + ClearNRoundedData(); + } + + private void ClearNRoundedData() + { + lengthEffectNRoundedTextBox.Text = string.Empty; + } + + private void SetLengthEffectData() + { + lengthEffectATextBox.Text = selectedFailureMechanismSection.ScenarioConfigurationPerSection.A.ToString(); + + double n = selectedFailureMechanismSection.ScenarioConfigurationPerSection.GetN(failureMechanism.ProbabilityAssessmentInput.B); + lengthEffectNRoundedTextBox.Text = new RoundedDouble(2, n).ToString(); + } + + private void SetLengthEffectErrorMessage(string errorMessage) + { + lengthEffectErrorProvider.SetIconPadding(lengthEffectATextBox, 5); + lengthEffectErrorProvider.SetError(lengthEffectATextBox, errorMessage); + } + + private void ClearLengthEffectErrorMessage() + { + lengthEffectErrorProvider.SetError(lengthEffectATextBox, string.Empty); + } } } \ No newline at end of file