Index: Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingScenariosView.Designer.cs =================================================================== diff -u -r1347a0fbca3bf02e4143c92211f2ea8a9f2a950a -rc75cfa7735eda3d6068112b1e671245fb2956fb9 --- Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingScenariosView.Designer.cs (.../PipingScenariosView.Designer.cs) (revision 1347a0fbca3bf02e4143c92211f2ea8a9f2a950a) +++ Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingScenariosView.Designer.cs (.../PipingScenariosView.Designer.cs) (revision c75cfa7735eda3d6068112b1e671245fb2956fb9) @@ -58,7 +58,7 @@ this.lengthEffectALabel = new System.Windows.Forms.Label(); this.lengthEffectNRoundedLabel = new System.Windows.Forms.Label(); this.lengthEffectATextBox = new System.Windows.Forms.TextBox(); - this.roundedNLabel = new Core.Common.Controls.BorderedLabel(); + this.lengthEffectNRoundedTextBox = new System.Windows.Forms.TextBox(); this.labelCalculations = new System.Windows.Forms.Label(); this.dataGridViewControl = new Core.Common.Controls.DataGrid.DataGridViewControl(); this.labelTotalScenarioContribution = new System.Windows.Forms.Label(); @@ -254,15 +254,15 @@ this.lengthEffectTableLayoutPanel.Controls.Add(this.lengthEffectALabel, 0, 0); this.lengthEffectTableLayoutPanel.Controls.Add(this.lengthEffectNRoundedLabel, 0, 1); this.lengthEffectTableLayoutPanel.Controls.Add(this.lengthEffectATextBox, 1, 0); - this.lengthEffectTableLayoutPanel.Controls.Add(this.roundedNLabel, 1, 1); + this.lengthEffectTableLayoutPanel.Controls.Add(this.lengthEffectNRoundedTextBox, 1, 1); this.lengthEffectTableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; this.lengthEffectTableLayoutPanel.Location = new System.Drawing.Point(0, 52); this.lengthEffectTableLayoutPanel.Margin = new System.Windows.Forms.Padding(0, 3, 0, 3); this.lengthEffectTableLayoutPanel.Name = "lengthEffectTableLayoutPanel"; this.lengthEffectTableLayoutPanel.RowCount = 2; this.lengthEffectTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.lengthEffectTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.lengthEffectTableLayoutPanel.Size = new System.Drawing.Size(1003, 46); + this.lengthEffectTableLayoutPanel.Size = new System.Drawing.Size(1003, 52); this.lengthEffectTableLayoutPanel.TabIndex = 0; // // lengthEffectALabel @@ -282,7 +282,7 @@ this.lengthEffectNRoundedLabel.Dock = System.Windows.Forms.DockStyle.Fill; this.lengthEffectNRoundedLabel.Location = new System.Drawing.Point(3, 26); this.lengthEffectNRoundedLabel.Name = "lengthEffectNRoundedLabel"; - this.lengthEffectNRoundedLabel.Size = new System.Drawing.Size(165, 20); + this.lengthEffectNRoundedLabel.Size = new System.Drawing.Size(165, 26); this.lengthEffectNRoundedLabel.TabIndex = 1; this.lengthEffectNRoundedLabel.Text = "Lengte-effect parameter Nvak* (-)"; this.lengthEffectNRoundedLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; @@ -297,23 +297,19 @@ this.lengthEffectATextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.LengthEffectATextBoxKeyDown); this.lengthEffectATextBox.Leave += new System.EventHandler(this.LengthEffectATextBoxLeave); // - // roundedNLabel + // lengthEffectNRoundedTextBox // - this.roundedNLabel.AutoSize = false; - this.roundedNLabel.BackColor = System.Drawing.Color.White; - this.roundedNLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.roundedNLabel.Dock = System.Windows.Forms.DockStyle.Left; - this.roundedNLabel.Location = new System.Drawing.Point(174, 26); - this.roundedNLabel.Name = "roundedNLabel"; - this.roundedNLabel.Padding = new System.Windows.Forms.Padding(5, 0, 5, 0); - this.roundedNLabel.Size = new System.Drawing.Size(100, 20); - this.roundedNLabel.TabIndex = 0; - this.roundedNLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.lengthEffectNRoundedTextBox.BackColor = System.Drawing.SystemColors.Control; + this.lengthEffectNRoundedTextBox.Location = new System.Drawing.Point(174, 29); + this.lengthEffectNRoundedTextBox.Name = "lengthEffectNRoundedTextBox"; + this.lengthEffectNRoundedTextBox.ReadOnly = true; + this.lengthEffectNRoundedTextBox.Size = new System.Drawing.Size(100, 20); + this.lengthEffectNRoundedTextBox.TabIndex = 4; // // labelCalculations // this.labelCalculations.AutoSize = true; - this.labelCalculations.Location = new System.Drawing.Point(3, 101); + this.labelCalculations.Location = new System.Drawing.Point(3, 107); this.labelCalculations.Name = "labelCalculations"; this.labelCalculations.Size = new System.Drawing.Size(173, 13); this.labelCalculations.TabIndex = 0; @@ -322,11 +318,11 @@ // dataGridViewControl // this.dataGridViewControl.Dock = System.Windows.Forms.DockStyle.Fill; - this.dataGridViewControl.Location = new System.Drawing.Point(3, 117); + this.dataGridViewControl.Location = new System.Drawing.Point(3, 123); this.dataGridViewControl.MultiSelect = true; this.dataGridViewControl.Name = "dataGridViewControl"; this.dataGridViewControl.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.RowHeaderSelect; - this.dataGridViewControl.Size = new System.Drawing.Size(997, 629); + this.dataGridViewControl.Size = new System.Drawing.Size(997, 623); this.dataGridViewControl.TabIndex = 1; // // labelTotalScenarioContribution @@ -374,10 +370,10 @@ this.ResumeLayout(false); } + private System.Windows.Forms.TextBox lengthEffectNRoundedTextBox; + private System.Windows.Forms.ErrorProvider lengthEffectErrorProvider; - private Core.Common.Controls.BorderedLabel roundedNLabel; - private System.Windows.Forms.Label lengthEffectALabel; private System.Windows.Forms.Label lengthEffectNRoundedLabel; private System.Windows.Forms.TextBox lengthEffectATextBox; Index: Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingScenariosView.cs =================================================================== diff -u -r1347a0fbca3bf02e4143c92211f2ea8a9f2a950a -rc75cfa7735eda3d6068112b1e671245fb2956fb9 --- Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingScenariosView.cs (.../PipingScenariosView.cs) (revision 1347a0fbca3bf02e4143c92211f2ea8a9f2a950a) +++ Riskeer/Piping/src/Riskeer.Piping.Forms/Views/PipingScenariosView.cs (.../PipingScenariosView.cs) (revision c75cfa7735eda3d6068112b1e671245fb2956fb9) @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Globalization; using System.Linq; using System.Windows.Forms; @@ -117,6 +118,7 @@ UpdateVisibility(); UpdateLengthEffectControls(); + UpdateLengthEffectData(); } public object Data @@ -166,8 +168,12 @@ private void InitializeObservers() { - failureMechanismObserver = new Observer(UpdateSectionsListBox) + failureMechanismObserver = new Observer(() => { + UpdateSectionsListBox(); + UpdateLengthEffectControls(); + }) + { Observable = failureMechanism }; @@ -302,8 +308,8 @@ { selectedFailureMechanismSection = listBox.SelectedItem as PipingScenariosViewFailureMechanismSectionViewModel; UpdateRadioButtons(); - UpdateLengthEffectControls(); UpdateScenarioControls(); + UpdateLengthEffectData(); } private void UpdateScenarioControls() @@ -438,7 +444,7 @@ if (e.KeyCode == Keys.Escape) { ClearLengthEffectErrorMessage(); - SetLengthEffectATextBoxValue(selectedFailureMechanismSection?.ScenarioConfigurationPerSection.A ?? double.NaN); + SetLengthEffectATextBoxValue(selectedFailureMechanismSection.ScenarioConfigurationPerSection.A); e.Handled = true; } } @@ -464,6 +470,8 @@ selectedFailureMechanismSection.ScenarioConfigurationPerSection; scenarioConfigurationPerSection.A = lengthEffectA; scenarioConfigurationPerSection.NotifyObservers(); + + UpdateScenarioRows(); } catch (Exception exception) when (exception is ArgumentOutOfRangeException || exception is OverflowException @@ -476,8 +484,20 @@ 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(); - + if (selectedFailureMechanismSection != null) { SetLengthEffectATextBoxValue(selectedFailureMechanismSection.ScenarioConfigurationPerSection.A); @@ -488,14 +508,13 @@ { lengthEffectATextBox.Text = value.ToString(CultureInfo.CurrentCulture); } - - + private void SetLengthEffectErrorMessage(string errorMessage) { lengthEffectErrorProvider.SetIconPadding(lengthEffectATextBox, 5); lengthEffectErrorProvider.SetError(lengthEffectATextBox, errorMessage); } - + private void ClearLengthEffectErrorMessage() { lengthEffectErrorProvider.SetError(lengthEffectATextBox, string.Empty); Index: Riskeer/Piping/test/Riskeer.Piping.Forms.Test/Views/PipingScenariosViewTest.cs =================================================================== diff -u -r1347a0fbca3bf02e4143c92211f2ea8a9f2a950a -rc75cfa7735eda3d6068112b1e671245fb2956fb9 --- Riskeer/Piping/test/Riskeer.Piping.Forms.Test/Views/PipingScenariosViewTest.cs (.../PipingScenariosViewTest.cs) (revision 1347a0fbca3bf02e4143c92211f2ea8a9f2a950a) +++ Riskeer/Piping/test/Riskeer.Piping.Forms.Test/Views/PipingScenariosViewTest.cs (.../PipingScenariosViewTest.cs) (revision c75cfa7735eda3d6068112b1e671245fb2956fb9) @@ -258,6 +258,9 @@ var lengthEffectNRoundedLabel = (Label) new LabelTester("lengthEffectNRoundedLabel").TheObject; Assert.AreEqual("Lengte-effect parameter Nvak* (-)", lengthEffectNRoundedLabel.Text); + + var lengthEffectNRoundedTextBox = (TextBox) new ControlTester("lengthEffectNRoundedTextBox").TheObject; + Assert.IsTrue(lengthEffectNRoundedTextBox.ReadOnly); } [Test] @@ -975,6 +978,71 @@ } [Test] + public void GivenPipingScenariosViewWithSections_WhenSectionsClearedAndFailureMechanismNotifiesObserver_ThenLengthEffectControlsUpdated() + { + // Given + var failureMechanism = new PipingFailureMechanism(); + ConfigureFailureMechanism(failureMechanism); + + ShowPipingScenariosView(failureMechanism); + + // Precondition + var lengthEffectATextBox = (TextBox) new ControlTester("lengthEffectATextBox").TheObject; + Assert.IsTrue(lengthEffectATextBox.Enabled); + Assert.IsFalse(lengthEffectATextBox.ReadOnly); + + var lengthEffectNRoundedTextBox = (TextBox) new ControlTester("lengthEffectNRoundedTextBox").TheObject; + Assert.IsTrue(lengthEffectNRoundedTextBox.Enabled); + Assert.AreEqual(SystemColors.Window, lengthEffectNRoundedTextBox.BackColor); + + // When + failureMechanism.ClearAllSections(); + failureMechanism.NotifyObservers(); + + // Then + Assert.IsFalse(lengthEffectATextBox.Enabled); + Assert.IsTrue(lengthEffectATextBox.ReadOnly); + + Assert.IsFalse(lengthEffectNRoundedTextBox.Enabled); + Assert.AreEqual(SystemColors.Control, lengthEffectNRoundedTextBox.BackColor); + } + + [Test] + public void GivenPipingScenariosViewWithoutSections_WhenSectionsAddedAndFailureMechanismNotifiesObserver_ThenLengthEffectControlsUpdated() + { + // Given + var failureMechanism = new PipingFailureMechanism(); + ShowPipingScenariosView(failureMechanism); + + // Precondition + var lengthEffectATextBox = (TextBox) new ControlTester("lengthEffectATextBox").TheObject; + Assert.IsFalse(lengthEffectATextBox.Enabled); + Assert.IsTrue(lengthEffectATextBox.ReadOnly); + + var lengthEffectNRoundedTextBox = (TextBox) new ControlTester("lengthEffectNRoundedTextBox").TheObject; + Assert.IsFalse(lengthEffectNRoundedTextBox.Enabled); + Assert.AreEqual(SystemColors.Control, lengthEffectNRoundedTextBox.BackColor); + + // When + failureMechanism.SetSections(new[] + { + new FailureMechanismSection("Section 1", new[] + { + new Point2D(0.0, 0.0), + new Point2D(5.0, 0.0) + }) + }, string.Empty); + failureMechanism.NotifyObservers(); + + // Then + Assert.IsTrue(lengthEffectATextBox.Enabled); + Assert.IsFalse(lengthEffectATextBox.ReadOnly); + + Assert.IsTrue(lengthEffectNRoundedTextBox.Enabled); + Assert.AreEqual(SystemColors.Window, lengthEffectNRoundedTextBox.BackColor); + } + + [Test] public void GivenPipingScenariosView_WhenFailureMechanismNotifiesObserver_ThenSectionsListBoxCorrectlyUpdated() { // Given