Index: Core/Common/src/Core.Common.Gui/Commands/ProjectCommandHandler.cs =================================================================== diff -u -rb78b6d08e4be8dfe938718d5e65085aa8bd72dcc -r1e5d9b5cfc66cb8187d534d891afef1c9080378b --- Core/Common/src/Core.Common.Gui/Commands/ProjectCommandHandler.cs (.../ProjectCommandHandler.cs) (revision b78b6d08e4be8dfe938718d5e65085aa8bd72dcc) +++ Core/Common/src/Core.Common.Gui/Commands/ProjectCommandHandler.cs (.../ProjectCommandHandler.cs) (revision 1e5d9b5cfc66cb8187d534d891afef1c9080378b) @@ -61,6 +61,7 @@ this.dataItemInfos = dataItemInfos; this.applicationSelection = applicationSelection; this.viewController = viewController; + } public void AddNewItem(object parent) @@ -69,19 +70,19 @@ { log.Error(Resources.ProjectCommandHandler_AddNewItem_There_needs_to_be_a_project_to_add_an_item); } - - using (var selectDataDialog = CreateSelectionDialogWithItems(GetSupportedDataItemInfos(parent).ToArray())) + var firstSupportedDataItemInfo = GetSupportedDataItemInfos(parent).FirstOrDefault(); + if (firstSupportedDataItemInfo == null) { - if (selectDataDialog.ShowDialog() == DialogResult.OK) - { - var newItem = GetNewDataObject(parent, selectDataDialog.SelectedItemTag as DataItemInfo); - if (newItem != null) - { - AddItemToProject(newItem); - viewController.DocumentViewController.OpenViewForData(applicationSelection.Selection); - } - } + return; } + var newItem = GetNewDataObject(parent, firstSupportedDataItemInfo); + if (newItem != null) + { + AddItemToProject(newItem); + + applicationSelection.Selection = newItem; + viewController.DocumentViewController.OpenViewForData(applicationSelection.Selection); + } } public void AddItemToProject(object newItem) @@ -90,18 +91,6 @@ projectOwner.Project.NotifyObservers(); } - private SelectItemDialog CreateSelectionDialogWithItems(IEnumerable supportedDataItemInfos) - { - var selectDataDialog = new SelectItemDialog(dialogOwner); - - foreach (var dataItemInfo in supportedDataItemInfos) - { - selectDataDialog.AddItemType(dataItemInfo.Name, dataItemInfo.Category, dataItemInfo.Image, dataItemInfo); - } - - return selectDataDialog; - } - private static object GetNewDataObject(object parent, DataItemInfo dataItemInfo) { if (dataItemInfo == null) Index: Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/IAssessmentSection.cs =================================================================== diff -u -r2715f4b30426f7295453b30cd7c1af97f060bcaa -r1e5d9b5cfc66cb8187d534d891afef1c9080378b --- Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/IAssessmentSection.cs (.../IAssessmentSection.cs) (revision 2715f4b30426f7295453b30cd7c1af97f060bcaa) +++ Ringtoets/Common/src/Ringtoets.Common.Data/AssessmentSection/IAssessmentSection.cs (.../IAssessmentSection.cs) (revision 1e5d9b5cfc66cb8187d534d891afef1c9080378b) @@ -36,7 +36,7 @@ /// /// Gets or sets the identifier of the assessment section. /// - string Id { get; } + string Id { get; set; } /// /// Gets or sets the name of the assessment section. Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/AssessmentSectionSettingsReaderTest.cs =================================================================== diff -u -r74099cffbe88647dbc4c81a3935d12cf5959b858 -r1e5d9b5cfc66cb8187d534d891afef1c9080378b --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/AssessmentSectionSettingsReaderTest.cs (.../AssessmentSectionSettingsReaderTest.cs) (revision 74099cffbe88647dbc4c81a3935d12cf5959b858) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/AssessmentSectionSettingsReaderTest.cs (.../AssessmentSectionSettingsReaderTest.cs) (revision 1e5d9b5cfc66cb8187d534d891afef1c9080378b) @@ -19,10 +19,6 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System.IO; - -using Core.Common.TestUtil; - using NUnit.Framework; namespace Ringtoets.Common.IO.Test @@ -31,7 +27,7 @@ public class AssessmentSectionSettingsReaderTest { [Test] - public void ReadSettigns_FromValidFile_ReturnAllAssessmentSectionSettings() + public void ReadSettings_FromValidFile_ReturnsAllAssessmentSectionSettings() { // Setup var reader = new AssessmentSectionSettingsReader(); Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/AssessmentSectionFromFileCommandHandler.cs =================================================================== diff -u --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/AssessmentSectionFromFileCommandHandler.cs (revision 0) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/AssessmentSectionFromFileCommandHandler.cs (revision 1e5d9b5cfc66cb8187d534d891afef1c9080378b) @@ -0,0 +1,146 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using log4net; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.IO; +using Ringtoets.Common.IO.Exceptions; +using Ringtoets.Integration.Data; +using Ringtoets.Integration.Forms.Properties; + +namespace Ringtoets.Integration.Forms +{ + /// + /// This class provides concrete implementation for . + /// + public class AssessmentSectionFromFileCommandHandler + { + private static readonly ILog log = LogManager.GetLogger(typeof(AssessmentSectionFromFileCommandHandler)); + + private readonly IWin32Window dialogParent; + private IEnumerable settings; + private IEnumerable referenceLineMetas = new List(); + + public AssessmentSectionFromFileCommandHandler(IWin32Window dialogParent) + { + this.dialogParent = dialogParent; + } + + public IAssessmentSection CreateAssessmentSectionFromFile(string folderpath) + { + ValidateAssessmentSectionSettings(); + ValidateReferenceLineMetas(folderpath); + + using (var dialog = CreateReferenceLineMetaSelectionDialogWithItems()) + { + if (dialog.ShowDialog() != DialogResult.OK) + { + return null; + } + var selectedItem = dialog.SelectedReferenceLineMeta; + return selectedItem == null ? null : CreateAssessmentSection(selectedItem, dialog.SelectedLimitValue); + } + } + + private IAssessmentSection CreateAssessmentSection(ReferenceLineMeta selectedItem, int? selectedLimitValue) + { + IAssessmentSection assessmentSection; + var settingOfSelectedAssessmentSection = settings.FirstOrDefault(s => s.AssessmentSectionId == selectedItem.AssessmentSectionId); + if (settingOfSelectedAssessmentSection == null) + { + log.Warn(Resources.AssessmentSectionFromFileCommandHandler_CreateAssessmentSection_No_settings_found_for_AssessmentSection); + assessmentSection = CreateDikeAssessmentSection(); + } + else + { + assessmentSection = (settingOfSelectedAssessmentSection.IsDune) ? + CreateDuneAssessmentSection() : + CreateDikeAssessmentSection(settingOfSelectedAssessmentSection); + } + + assessmentSection.Id = selectedItem.AssessmentSectionId; + assessmentSection.ReferenceLine = selectedItem.ReferenceLine; + + if (selectedLimitValue.HasValue) + { + assessmentSection.FailureMechanismContribution.Norm = selectedLimitValue.Value; + } + return assessmentSection; + } + + private static void SetFailureMechanismsValueN(AssessmentSection assessmentSection, int n) + { + assessmentSection.GrassCoverErosionInwards.GeneralInput.N = n; + assessmentSection.HeightStructures.GeneralInput.N = n; + } + + private ReferenceLineMetaSelectionDialog CreateReferenceLineMetaSelectionDialogWithItems() + { + return new ReferenceLineMetaSelectionDialog(dialogParent, referenceLineMetas); + } + + #region Create AssessmentSection + + private static AssessmentSection CreateDikeAssessmentSection() + { + var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); + return assessmentSection; + } + + private static AssessmentSection CreateDikeAssessmentSection(AssessmentSectionSettings settings) + { + var assessmentSection = CreateDikeAssessmentSection(); + SetFailureMechanismsValueN(assessmentSection, settings.N); + return assessmentSection; + } + + private static IAssessmentSection CreateDuneAssessmentSection() + { + return new AssessmentSection(AssessmentSectionComposition.Dune); + } + + #endregion + + #region Validators + + private void ValidateReferenceLineMetas(string folderpath) + { + var importer = new ReferenceLineMetaImporter(folderpath); + referenceLineMetas = importer.GetReferenceLineMetas().ToArray(); + + if (!referenceLineMetas.Any()) + { + throw new CriticalFileValidationException(Resources.AssessmentSectionFromFileCommandHandler_ValidateReferenceLineMetas_No_referenceLines_in_file); + } + } + + private void ValidateAssessmentSectionSettings() + { + var reader = new AssessmentSectionSettingsReader(); + settings = reader.ReadSettings(); + } + + #endregion + } +} \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -r74b9f5cca517fbccca3fe27bac059966233e432a -r1e5d9b5cfc66cb8187d534d891afef1c9080378b --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 74b9f5cca517fbccca3fe27bac059966233e432a) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 1e5d9b5cfc66cb8187d534d891afef1c9080378b) @@ -116,6 +116,26 @@ } /// + /// Looks up a localized string similar to Er zijn geen instellingen gevonden voor het geselecteerde traject. Standaardinstellingen zullen gebruikt worden.. + /// + public static string AssessmentSectionFromFileCommandHandler_CreateAssessmentSection_No_settings_found_for_AssessmentSection { + get { + return ResourceManager.GetString("AssessmentSectionFromFileCommandHandler_CreateAssessmentSection_No_settings_found" + + "_for_AssessmentSection", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Er kunnen geen trajecten gelezen worden uit het shape bestand.. + /// + public static string AssessmentSectionFromFileCommandHandler_ValidateReferenceLineMetas_No_referenceLines_in_file { + get { + return ResourceManager.GetString("AssessmentSectionFromFileCommandHandler_ValidateReferenceLineMetas_No_referenceLi" + + "nes_in_file", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Trajectkaart. /// public static string AssessmentSectionMap_DisplayName { @@ -442,8 +462,35 @@ } /// + /// Looks up a localized string similar to Identificatiecode. + /// + public static string ReferenceLineMetaSelectionDialog_ColumnHeader_AssessmentSectionId { + get { + return ResourceManager.GetString("ReferenceLineMetaSelectionDialog_ColumnHeader_AssessmentSectionId", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Ondergrens. /// + public static string ReferenceLineMetaSelectionDialog_ColumnHeader_LowerLimitValue { + get { + return ResourceManager.GetString("ReferenceLineMetaSelectionDialog_ColumnHeader_LowerLimitValue", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Signaleringswaarde. + /// + public static string ReferenceLineMetaSelectionDialog_ColumnHeader_SignalingValue { + get { + return ResourceManager.GetString("ReferenceLineMetaSelectionDialog_ColumnHeader_SignalingValue", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Ondergrens. + /// public static string ReferenceLineMetaSelectionView_LowerLimitValue_DisplayName { get { return ResourceManager.GetString("ReferenceLineMetaSelectionView_LowerLimitValue_DisplayName", resourceCulture); Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.resx =================================================================== diff -u -r74b9f5cca517fbccca3fe27bac059966233e432a -r1e5d9b5cfc66cb8187d534d891afef1c9080378b --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.resx (.../Resources.resx) (revision 74b9f5cca517fbccca3fe27bac059966233e432a) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Properties/Resources.resx (.../Resources.resx) (revision 1e5d9b5cfc66cb8187d534d891afef1c9080378b) @@ -260,4 +260,19 @@ Ondergrens + + Signaleringswaarde + + + Identificatiecode + + + Ondergrens + + + Er zijn geen instellingen gevonden voor het geselecteerde traject. Standaardinstellingen zullen gebruikt worden. + + + Er kunnen geen trajecten gelezen worden uit het shape bestand. + \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/ReferenceLineMetaSelectionDialog.Designer.cs =================================================================== diff -u -r74b9f5cca517fbccca3fe27bac059966233e432a -r1e5d9b5cfc66cb8187d534d891afef1c9080378b --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/ReferenceLineMetaSelectionDialog.Designer.cs (.../ReferenceLineMetaSelectionDialog.Designer.cs) (revision 74b9f5cca517fbccca3fe27bac059966233e432a) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/ReferenceLineMetaSelectionDialog.Designer.cs (.../ReferenceLineMetaSelectionDialog.Designer.cs) (revision 1e5d9b5cfc66cb8187d534d891afef1c9080378b) @@ -30,47 +30,99 @@ { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ReferenceLineMetaSelectionDialog)); this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); - this.Select = new System.Windows.Forms.Button(); this.Cancel = new System.Windows.Forms.Button(); + this.Ok = new System.Windows.Forms.Button(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.panel1 = new System.Windows.Forms.Panel(); + this.SelectValueLabel = new System.Windows.Forms.Label(); + this.SignalingLowerLimitComboBox = new System.Windows.Forms.ComboBox(); + this.ReferenceLineMetaDataGridViewControl = new Core.Common.Controls.DataGrid.DataGridViewControl(); this.flowLayoutPanel1.SuspendLayout(); + this.tableLayoutPanel1.SuspendLayout(); + this.panel1.SuspendLayout(); this.SuspendLayout(); // // flowLayoutPanel1 // - this.flowLayoutPanel1.Controls.Add(this.Cancel); - this.flowLayoutPanel1.Controls.Add(this.Select); resources.ApplyResources(this.flowLayoutPanel1, "flowLayoutPanel1"); + this.flowLayoutPanel1.Controls.Add(this.Cancel); + this.flowLayoutPanel1.Controls.Add(this.Ok); this.flowLayoutPanel1.Name = "flowLayoutPanel1"; // - // Select - // - resources.ApplyResources(this.Select, "Select"); - this.Select.Name = "Select"; - this.Select.UseVisualStyleBackColor = true; - this.Select.Click += new System.EventHandler(this.OkButtonOnClick); - // // Cancel // + this.Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; resources.ApplyResources(this.Cancel, "Cancel"); this.Cancel.Name = "Cancel"; this.Cancel.UseVisualStyleBackColor = true; this.Cancel.Click += new System.EventHandler(this.CancelButtonOnClick); // - // ReferenceLineSelectionDialog + // Ok // + this.Ok.DialogResult = System.Windows.Forms.DialogResult.OK; + resources.ApplyResources(this.Ok, "Ok"); + this.Ok.Name = "Ok"; + this.Ok.UseVisualStyleBackColor = true; + this.Ok.Click += new System.EventHandler(this.OkButtonOnClick); + // + // tableLayoutPanel1 + // + resources.ApplyResources(this.tableLayoutPanel1, "tableLayoutPanel1"); + this.tableLayoutPanel1.Controls.Add(this.panel1, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.ReferenceLineMetaDataGridViewControl, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.flowLayoutPanel1, 0, 2); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.Paint += new System.Windows.Forms.PaintEventHandler(this.tableLayoutPanel1_Paint); + // + // panel1 + // + resources.ApplyResources(this.panel1, "panel1"); + this.panel1.Controls.Add(this.SelectValueLabel); + this.panel1.Controls.Add(this.SignalingLowerLimitComboBox); + this.panel1.Name = "panel1"; + // + // SelectValueLabel + // + resources.ApplyResources(this.SelectValueLabel, "SelectValueLabel"); + this.SelectValueLabel.Name = "SelectValueLabel"; + // + // SignalingLowerLimitComboBox + // + this.SignalingLowerLimitComboBox.FormattingEnabled = true; + resources.ApplyResources(this.SignalingLowerLimitComboBox, "SignalingLowerLimitComboBox"); + this.SignalingLowerLimitComboBox.Name = "SignalingLowerLimitComboBox"; + // + // ReferenceLineMetaDataGridViewControl + // + resources.ApplyResources(this.ReferenceLineMetaDataGridViewControl, "ReferenceLineMetaDataGridViewControl"); + this.ReferenceLineMetaDataGridViewControl.MultiSelect = true; + this.ReferenceLineMetaDataGridViewControl.Name = "ReferenceLineMetaDataGridViewControl"; + this.ReferenceLineMetaDataGridViewControl.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.RowHeaderSelect; + // + // ReferenceLineMetaSelectionDialog + // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.flowLayoutPanel1); - this.Name = "ReferenceLineSelectionDialog"; + this.Controls.Add(this.tableLayoutPanel1); + this.Name = "ReferenceLineMetaSelectionDialog"; this.flowLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); this.ResumeLayout(false); } #endregion private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; - private System.Windows.Forms.Button Select; + private System.Windows.Forms.Button Ok; private System.Windows.Forms.Button Cancel; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.ComboBox SignalingLowerLimitComboBox; + private System.Windows.Forms.Label SelectValueLabel; + private Core.Common.Controls.DataGrid.DataGridViewControl ReferenceLineMetaDataGridViewControl; } } \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/ReferenceLineMetaSelectionDialog.cs =================================================================== diff -u -r4d27e3204b34978d3778b88a44566ba945de7e94 -r1e5d9b5cfc66cb8187d534d891afef1c9080378b --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/ReferenceLineMetaSelectionDialog.cs (.../ReferenceLineMetaSelectionDialog.cs) (revision 4d27e3204b34978d3778b88a44566ba945de7e94) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/ReferenceLineMetaSelectionDialog.cs (.../ReferenceLineMetaSelectionDialog.cs) (revision 1e5d9b5cfc66cb8187d534d891afef1c9080378b) @@ -21,10 +21,12 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Windows.Forms; using Core.Common.Controls.Dialogs; +using Core.Common.Utils.Reflection; using Ringtoets.Common.Data.AssessmentSection; -using Ringtoets.Integration.Forms.Views; +using Ringtoets.Integration.Forms.Properties; using CommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.Integration.Forms @@ -35,42 +37,116 @@ /// public partial class ReferenceLineMetaSelectionDialog : DialogBase { + private enum SignalingLowerLimit + { + SignalingValue, + LowerLimitValue + } + /// /// Creates a new instance of . /// /// The parent of the dialog. /// A list of the user can select. public ReferenceLineMetaSelectionDialog(IWin32Window dialogParent, IEnumerable referenceLineMetas) - : base(dialogParent, CommonFormsResources.SelectionDialogIcon, 300, 400) + : base(dialogParent, CommonFormsResources.SelectionDialogIcon, 410, 350) { - InitializeComponent(); - SelectionView = new ReferenceLineMetaSelectionView(referenceLineMetas) + if (referenceLineMetas == null) { - Dock = DockStyle.Fill - }; - Controls.Add(SelectionView); + throw new ArgumentNullException("referenceLineMetas"); + } + InitializeComponent(); + InitializeSignalingLowerLimitComboBox(); + InitializeReferenceLineMetaDataGridViewControl(referenceLineMetas); } public ReferenceLineMeta SelectedReferenceLineMeta { get; private set; } + public int? SelectedLimitValue { get; private set; } protected override Button GetCancelButton() { return Cancel; } - private ReferenceLineMetaSelectionView SelectionView { get; set; } + private int? GetSelectedLimitValue() + { + var selectedRow = GetSelectedReferenceLineMetaSelectionRow(); + if (selectedRow == null) + { + return null; + } + var selectedItemInComboBox = (SignalingLowerLimit) SignalingLowerLimitComboBox.SelectedValue; + return selectedItemInComboBox == SignalingLowerLimit.SignalingValue ? + selectedRow.SignalingValue : + selectedRow.LowerLimitValue; + } + + private void InitializeReferenceLineMetaDataGridViewControl(IEnumerable referenceLineMetas) + { + ReferenceLineMetaDataGridViewControl.MultiSelect = false; + ReferenceLineMetaDataGridViewControl.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + ReferenceLineMetaDataGridViewControl.AddTextBoxColumn("AssessmentSectionId", Resources.ReferenceLineMetaSelectionDialog_ColumnHeader_AssessmentSectionId); + ReferenceLineMetaDataGridViewControl.AddTextBoxColumn("SignalingValue", Resources.ReferenceLineMetaSelectionDialog_ColumnHeader_SignalingValue); + ReferenceLineMetaDataGridViewControl.AddTextBoxColumn("LowerLimitValue", Resources.ReferenceLineMetaSelectionDialog_ColumnHeader_LowerLimitValue); + ReferenceLineMetaDataGridViewControl.SetDataSource(referenceLineMetas.Select(rlm => new ReferenceLineMetaSelectionRow(rlm)).ToArray()); + } + private void OkButtonOnClick(object sender, EventArgs e) { - SelectedReferenceLineMeta = SelectionView.GetSelectedReferenceLineMeta(); - SelectedLimitValue = SelectionView.GetSelectedLimitValue(); + SetSelectionProperties(); Close(); } + private void SetSelectionProperties() + { + ReferenceLineMetaSelectionRow referenceLineMetaSelectionRow = GetSelectedReferenceLineMetaSelectionRow(); + if (referenceLineMetaSelectionRow != null) + { + SelectedReferenceLineMeta = referenceLineMetaSelectionRow.ReferenceLineMeta; + SelectedLimitValue = GetSelectedLimitValue(); + } + } + + private void InitializeSignalingLowerLimitComboBox() + { + SignalingLowerLimitComboBox.DataSource = new[] + { + Tuple.Create(SignalingLowerLimit.SignalingValue, Resources.ReferenceLineMetaSelectionView_SignalingValue_DisplayName), + Tuple.Create(SignalingLowerLimit.LowerLimitValue, Resources.ReferenceLineMetaSelectionView_LowerLimitValue_DisplayName) + }; + SignalingLowerLimitComboBox.ValueMember = TypeUtils.GetMemberName>(t => t.Item1); + SignalingLowerLimitComboBox.DisplayMember = TypeUtils.GetMemberName>(t => t.Item2); + } + + private ReferenceLineMetaSelectionRow GetSelectedReferenceLineMetaSelectionRow() + { + var selectedRow = ReferenceLineMetaDataGridViewControl.GetCurrentRow(); + return selectedRow == null ? null : (ReferenceLineMetaSelectionRow) selectedRow.DataBoundItem; + } + private void CancelButtonOnClick(object sender, EventArgs e) { Close(); } + + private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e) {} + + private class ReferenceLineMetaSelectionRow + { + public ReferenceLineMetaSelectionRow(ReferenceLineMeta referenceLineMeta) + { + AssessmentSectionId = referenceLineMeta.AssessmentSectionId; + SignalingValue = referenceLineMeta.SignalingValue ?? 0; + LowerLimitValue = referenceLineMeta.LowerLimitValue ?? 0; + ReferenceLineMeta = referenceLineMeta; + } + + public string AssessmentSectionId { get; private set; } + public int SignalingValue { get; private set; } + public int LowerLimitValue { get; private set; } + public ReferenceLineMeta ReferenceLineMeta { get; private set; } + } } } \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/ReferenceLineMetaSelectionDialog.resx =================================================================== diff -u -r74b9f5cca517fbccca3fe27bac059966233e432a -r1e5d9b5cfc66cb8187d534d891afef1c9080378b --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/ReferenceLineMetaSelectionDialog.resx (.../ReferenceLineMetaSelectionDialog.resx) (revision 74b9f5cca517fbccca3fe27bac059966233e432a) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/ReferenceLineMetaSelectionDialog.resx (.../ReferenceLineMetaSelectionDialog.resx) (revision 1e5d9b5cfc66cb8187d534d891afef1c9080378b) @@ -117,14 +117,17 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + - 206, 3 + 248, 3 75, 23 - 1 @@ -143,42 +146,42 @@ 0 - - 125, 3 + + 167, 3 - + 75, 23 - + 0 - + Selecteer - - Select + + Ok - + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + flowLayoutPanel1 - + 1 Bottom - 0, 232 + 3, 139 Yes - 284, 30 + 326, 29 0 @@ -190,27 +193,159 @@ System.Windows.Forms.FlowLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - $this + tableLayoutPanel1 + 2 + + + 1 + + + True + + + True + + + 4, 4 + + + 65, 13 + + 0 + + Kies waarde + + + SelectValueLabel + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel1 + + + 0 + + + 75, 1 + + + 121, 21 + + + 1 + + + SignalingLowerLimitComboBox + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + panel1 + + + 1 + + + 3, 3 + + + 199, 25 + + + 2 + + + panel1 + + + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tableLayoutPanel1 + + + 0 + + + Fill + + + 3, 34 + + + 326, 99 + + + 2 + + + ReferenceLineMetaDataGridViewControl + + + Core.Common.Controls.DataGrid.DataGridViewControl, Core.Common.Controls, Version=0.5.0.4220, Culture=neutral, PublicKeyToken=null + + + tableLayoutPanel1 + + + 1 + + + Fill + + + 0, 0 + + + 3 + + + 332, 171 + + + 2 + + + tableLayoutPanel1 + + + System.Windows.Forms.TableLayoutPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="panel1" Row="0" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="ReferenceLineMetaDataGridViewControl" Row="1" RowSpan="1" Column="0" ColumnSpan="1" /><Control Name="flowLayoutPanel1" Row="2" RowSpan="1" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Percent,100" /><Rows Styles="AutoSize,0,Percent,100,AutoSize,0,Absolute,20" /></TableLayoutSettings> + True 6, 13 - 284, 262 + 332, 171 + + 240, 130 + Selecteer referentielijn - ReferenceLineSelectionDialog + ReferenceLineMetaSelectionDialog - System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + Core.Common.Controls.Dialogs.DialogBase, Core.Common.Controls, Version=0.5.0.4220, Culture=neutral, PublicKeyToken=null \ No newline at end of file Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj =================================================================== diff -u -r74b9f5cca517fbccca3fe27bac059966233e432a -r1e5d9b5cfc66cb8187d534d891afef1c9080378b --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj (.../Ringtoets.Integration.Forms.csproj) (revision 74b9f5cca517fbccca3fe27bac059966233e432a) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/Ringtoets.Integration.Forms.csproj (.../Ringtoets.Integration.Forms.csproj) (revision 1e5d9b5cfc66cb8187d534d891afef1c9080378b) @@ -33,6 +33,8 @@ MinimumRecommendedRules.ruleset + + @@ -44,6 +46,7 @@ Properties\GlobalAssembly.cs + @@ -76,12 +79,6 @@ FailureMechanismContributionView.cs - - UserControl - - - ReferenceLineMetaSelectionView.cs - @@ -160,6 +157,10 @@ Core.Common.Gui False + + {E344867E-9AC9-44C8-88A5-8185681679A9} + Core.Common.IO + {f49bd8b2-332a-4c91-a196-8cce0a2c7d98} Core.Common.Utils @@ -195,6 +196,14 @@ Ringtoets.Common.Forms False + + {52BA7627-CBAB-4209-BE77-3B5F31378277} + Ringtoets.Common.IO + + + {90de728e-48ef-4665-ab38-3d88e41d9f4d} + Ringtoets.GrassCoverErosionInwards.Data + {1C0017D8-35B5-4CA0-8FC7-A83F46DBDC99} Ringtoets.HeightStructures.Data @@ -224,9 +233,6 @@ FailureMechanismContributionView.cs Designer - - ReferenceLineMetaSelectionView.cs - Fisheye: Tag 1e5d9b5cfc66cb8187d534d891afef1c9080378b refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/ReferenceLineMetaSelectionView.Designer.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1e5d9b5cfc66cb8187d534d891afef1c9080378b refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/ReferenceLineMetaSelectionView.cs'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 1e5d9b5cfc66cb8187d534d891afef1c9080378b refers to a dead (removed) revision in file `Ringtoets/Integration/src/Ringtoets.Integration.Forms/Views/ReferenceLineMetaSelectionView.resx'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -ra1ec5faebf7ccf8e67fa34a2b73cd1063ab48840 -r1e5d9b5cfc66cb8187d534d891afef1c9080378b --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision a1ec5faebf7ccf8e67fa34a2b73cd1063ab48840) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 1e5d9b5cfc66cb8187d534d891afef1c9080378b) @@ -23,6 +23,7 @@ using System.Collections; using System.Collections.Generic; using System.Drawing; +using System.IO; using System.Linq; using System.Windows.Forms; using Core.Common.Base.Data; @@ -33,6 +34,7 @@ using Core.Common.Gui; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms; +using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.Forms.ProgressDialog; using Core.Common.Gui.Plugin; using Core.Common.IO.Exceptions; @@ -49,15 +51,16 @@ using Ringtoets.Common.Forms.TreeNodeInfos; using Ringtoets.Common.Forms.Views; using Ringtoets.Common.IO; +using Ringtoets.Common.IO.Exceptions; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Forms.PresentationObjects; using Ringtoets.HydraRing.Data; using Ringtoets.HydraRing.IO; -using Ringtoets.Integration.Data; using Ringtoets.Integration.Data.StandAlone; using Ringtoets.Integration.Data.StandAlone.SectionResults; +using Ringtoets.Integration.Forms; using Ringtoets.Integration.Forms.PresentationObjects; using Ringtoets.Integration.Forms.PropertyClasses; using Ringtoets.Integration.Forms.Views; @@ -321,17 +324,43 @@ public override IEnumerable GetDataItemInfos() { - yield return new DataItemInfo + if (Gui == null) { - Name = RingtoetsFormsResources.AssessmentSection_DisplayName, - Category = RingtoetsCommonFormsResources.Ringtoets_Category, - Image = RingtoetsFormsResources.AssessmentSectionFolderIcon, - CreateData = owner => + return Enumerable.Empty(); + } + + IAssessmentSection assessmentSection; + try + { + var assessmentSectionHandler = new AssessmentSectionFromFileCommandHandler(Gui.MainWindow); + var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), "WTI", "NBPW"); + assessmentSection = assessmentSectionHandler.CreateAssessmentSectionFromFile(path); + } + catch (CriticalFileValidationException exception) + { + MessageBox.Show(exception.Message, BaseResources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); + log.Warn(exception.Message, exception.InnerException); + return Enumerable.Empty(); + } + catch (CriticalFileReadException exception) + { + log.Error(exception.Message, exception.InnerException); + return Enumerable.Empty(); + } + + return new DataItemInfo[] + { + new DataItemInfo { - var project = (Project) owner; - var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); - assessmentSection.Name = GetUniqueForAssessmentSectionName(project, assessmentSection.Name); - return assessmentSection; + Name = RingtoetsFormsResources.AssessmentSection_DisplayName, + Category = RingtoetsCommonFormsResources.Ringtoets_Category, + Image = RingtoetsFormsResources.AssessmentSectionFolderIcon, + CreateData = owner => + { + var project = (Project) owner; + assessmentSection.Name = GetUniqueForAssessmentSectionName(project, assessmentSection.Name); + return assessmentSection; + } } }; } Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/AssessmentSectionFromFileCommandHandlerTest.cs =================================================================== diff -u --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/AssessmentSectionFromFileCommandHandlerTest.cs (revision 0) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/AssessmentSectionFromFileCommandHandlerTest.cs (revision 1e5d9b5cfc66cb8187d534d891afef1c9080378b) @@ -0,0 +1,76 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets 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.IO; +using System.Windows.Forms; +using Core.Common.IO.Exceptions; +using Core.Common.TestUtil; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.IO.Exceptions; + +namespace Ringtoets.Integration.Forms.Test +{ + [TestFixture] + public class AssessmentSectionFromFileCommandHandlerTest + { + private readonly string testDataPath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, "ReferenceLineMetaImporter"); + + [Test] + public void CreateAssessmentSectionFromFile_InvalidDirectory_ThrowsCriticalFileReadException() + { + // Setup + var mockRepository = new MockRepository(); + var parentDialog = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + AssessmentSectionFromFileCommandHandler assessmentSectionFromFile = new AssessmentSectionFromFileCommandHandler(parentDialog); + + string pathToNonExistingFolder = Path.Combine(testDataPath, "I do not exist"); + + // Call + TestDelegate call = () => assessmentSectionFromFile.CreateAssessmentSectionFromFile(pathToNonExistingFolder); + + // Assert + Assert.Throws(call); + mockRepository.VerifyAll(); + } + + [Test] + public void CreateAssessmentSectionFromFile_validDirectoryWithEmptyShapeFile_ThrowsCriticalFileValidationException() + { + // Setup + var mockRepository = new MockRepository(); + var parentDialog = mockRepository.StrictMock(); + mockRepository.ReplayAll(); + AssessmentSectionFromFileCommandHandler assessmentSectionFromFile = new AssessmentSectionFromFileCommandHandler(parentDialog); + + string pathValidFolder = Path.Combine(testDataPath, "EmptyShapeFile"); + + // Call + TestDelegate call = () => assessmentSectionFromFile.CreateAssessmentSectionFromFile(pathValidFolder); + + // Assert + CriticalFileValidationException exception = Assert.Throws(call); + Assert.AreEqual("Er kunnen geen trajecten gelezen worden uit het shape bestand.", exception.Message); + mockRepository.VerifyAll(); + } + } +} \ No newline at end of file Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/ReferenceLineMetaSelectionDialogTest.cs =================================================================== diff -u -r4d27e3204b34978d3778b88a44566ba945de7e94 -r1e5d9b5cfc66cb8187d534d891afef1c9080378b --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/ReferenceLineMetaSelectionDialogTest.cs (.../ReferenceLineMetaSelectionDialogTest.cs) (revision 4d27e3204b34978d3778b88a44566ba945de7e94) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/ReferenceLineMetaSelectionDialogTest.cs (.../ReferenceLineMetaSelectionDialogTest.cs) (revision 1e5d9b5cfc66cb8187d534d891afef1c9080378b) @@ -23,10 +23,8 @@ using System.Linq; using System.Windows.Forms; using Core.Common.Controls.Dialogs; -using NUnit.Extensions.Forms; using NUnit.Framework; using Ringtoets.Common.Data.AssessmentSection; -using Ringtoets.Integration.Forms.Views; namespace Ringtoets.Integration.Forms.Test { @@ -63,7 +61,6 @@ { // Assert Assert.IsInstanceOf(dialog); - Assert.IsInstanceOf(new ControlTester("ReferenceLineMetaSelectionView", dialog).TheObject); Assert.IsNull(dialog.SelectedReferenceLineMeta); Assert.AreEqual("Selecteer referentielijn", dialog.Text); } @@ -79,8 +76,8 @@ dialog.Show(); // Assert - Assert.AreEqual(300, dialog.MinimumSize.Width); - Assert.AreEqual(400, dialog.MinimumSize.Height); + Assert.AreEqual(410, dialog.MinimumSize.Width); + Assert.AreEqual(350, dialog.MinimumSize.Height); } } } Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj =================================================================== diff -u -r74b9f5cca517fbccca3fe27bac059966233e432a -r1e5d9b5cfc66cb8187d534d891afef1c9080378b --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision 74b9f5cca517fbccca3fe27bac059966233e432a) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Ringtoets.Integration.Forms.Test.csproj (.../Ringtoets.Integration.Forms.Test.csproj) (revision 1e5d9b5cfc66cb8187d534d891afef1c9080378b) @@ -58,6 +58,7 @@ + @@ -92,7 +93,6 @@ - @@ -144,6 +144,10 @@ {30e4c2ae-719e-4d70-9fa9-668a9767fbfa} Core.Common.Gui + + {E344867E-9AC9-44C8-88A5-8185681679A9} + Core.Common.IO + {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98} Core.Common.Utils @@ -176,6 +180,10 @@ {4d840673-3812-4338-a352-84854e32b8a0} Ringtoets.Common.Forms + + {52BA7627-CBAB-4209-BE77-3B5F31378277} + Ringtoets.Common.IO + {4843D6E5-066F-4795-94F5-1D53932DD03C} Ringtoets.Common.Data.TestUtil Fisheye: Tag 1e5d9b5cfc66cb8187d534d891afef1c9080378b refers to a dead (removed) revision in file `Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/Views/ReferenceLineMetaSelectionViewTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs =================================================================== diff -u -ra1ec5faebf7ccf8e67fa34a2b73cd1063ab48840 -r1e5d9b5cfc66cb8187d534d891afef1c9080378b --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs (.../RingtoetsPluginTest.cs) (revision a1ec5faebf7ccf8e67fa34a2b73cd1063ab48840) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs (.../RingtoetsPluginTest.cs) (revision 1e5d9b5cfc66cb8187d534d891afef1c9080378b) @@ -26,7 +26,6 @@ using System.Windows.Threading; using Core.Common.Base.Data; using Core.Common.Base.IO; -using Core.Common.Base.Plugin; using Core.Common.Base.Storage; using Core.Common.Controls.TreeView; using Core.Common.Gui; @@ -431,41 +430,6 @@ Assert.AreEqual(1, importers.Count(i => i is FailureMechanismSectionsImporter)); } - [Test] - public void GetDataItemInfos_ReturnsExpectedDataItemDefinitions() - { - // Setup - var plugin = new RingtoetsPlugin(); - - // Call - var dataItemDefinitions = plugin.GetDataItemInfos().ToArray(); - - // Assert - Assert.AreEqual(1, dataItemDefinitions.Length); - - DataItemInfo assessmentSectionDataItemDefinition = dataItemDefinitions.Single(did => did.ValueType == typeof(AssessmentSection)); - Assert.AreEqual("Traject", assessmentSectionDataItemDefinition.Name); - Assert.AreEqual("Algemeen", assessmentSectionDataItemDefinition.Category); - TestHelper.AssertImagesAreEqual(RingtoetsFormsResources.AssessmentSectionFolderIcon, assessmentSectionDataItemDefinition.Image); - Assert.IsNull(assessmentSectionDataItemDefinition.AdditionalOwnerCheck); - Assert.IsInstanceOf(assessmentSectionDataItemDefinition.CreateData(new Project())); - } - - [Test] - public void WhenAddingAssessmentSection_GivenProjectHasAssessmentSection_ThenAddedAssessmentSectionHasUniqueName() - { - // Setup - var project = new Project(); - var plugin = new RingtoetsPlugin(); - AddAssessmentSectionToProject(project, plugin); - - // Call - AddAssessmentSectionToProject(project, plugin); - - // Assert - CollectionAssert.AllItemsAreUnique(project.Items.Cast().Select(section => section.Name)); - } - private static void AddAssessmentSectionToProject(Project project, RingtoetsPlugin plugin) { var itemToAdd = plugin.GetDataItemInfos()