Index: Core/Components/src/Core.Components.Gis.Forms/Core.Components.Gis.Forms.csproj =================================================================== diff -u -r1eeed8168101200ec6bbfb79defc20c67a1f7edb -r08432b412fb47916669a52095d9e20afb24994c6 --- Core/Components/src/Core.Components.Gis.Forms/Core.Components.Gis.Forms.csproj (.../Core.Components.Gis.Forms.csproj) (revision 1eeed8168101200ec6bbfb79defc20c67a1f7edb) +++ Core/Components/src/Core.Components.Gis.Forms/Core.Components.Gis.Forms.csproj (.../Core.Components.Gis.Forms.csproj) (revision 08432b412fb47916669a52095d9e20afb24994c6) @@ -55,6 +55,12 @@ Resources.resx + + UserControl + + + WellKnownMapDataControl.cs + Form @@ -112,6 +118,9 @@ PublicResXFileCodeGenerator Resources.Designer.cs + + WellKnownMapDataControl.cs + WmtsConnectionDialog.cs Index: Core/Components/src/Core.Components.Gis.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -r70952faba3713dc603266d3a2bc9c00eb4397caf -r08432b412fb47916669a52095d9e20afb24994c6 --- Core/Components/src/Core.Components.Gis.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 70952faba3713dc603266d3a2bc9c00eb4397caf) +++ Core/Components/src/Core.Components.Gis.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 08432b412fb47916669a52095d9e20afb24994c6) @@ -102,6 +102,24 @@ } /// + /// Looks up a localized string similar to Bekende kaartlagen. + /// + public static string WellKnownMapDataControl_DisplayName { + get { + return ResourceManager.GetString("WellKnownMapDataControl_DisplayName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Omschrijving. + /// + public static string WellKnownTileSourceMapData_Description { + get { + return ResourceManager.GetString("WellKnownTileSourceMapData_Description", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Coördinatenstelsel. /// public static string WmtsCapability_MapLayer_CoordinateSystem { Index: Core/Components/src/Core.Components.Gis.Forms/Properties/Resources.resx =================================================================== diff -u -r70952faba3713dc603266d3a2bc9c00eb4397caf -r08432b412fb47916669a52095d9e20afb24994c6 --- Core/Components/src/Core.Components.Gis.Forms/Properties/Resources.resx (.../Resources.resx) (revision 70952faba3713dc603266d3a2bc9c00eb4397caf) +++ Core/Components/src/Core.Components.Gis.Forms/Properties/Resources.resx (.../Resources.resx) (revision 08432b412fb47916669a52095d9e20afb24994c6) @@ -148,4 +148,10 @@ Gegevens ophalen van de locatie (URL) '{0}' is mislukt. + + Bekende kaartlagen + + + Omschrijving + \ No newline at end of file Index: Core/Components/src/Core.Components.Gis.Forms/Views/IBackgroundMapDataSelectionControl.cs =================================================================== diff -u -r99f9004206bfb9de084275d749b7aeccafd6da18 -r08432b412fb47916669a52095d9e20afb24994c6 --- Core/Components/src/Core.Components.Gis.Forms/Views/IBackgroundMapDataSelectionControl.cs (.../IBackgroundMapDataSelectionControl.cs) (revision 99f9004206bfb9de084275d749b7aeccafd6da18) +++ Core/Components/src/Core.Components.Gis.Forms/Views/IBackgroundMapDataSelectionControl.cs (.../IBackgroundMapDataSelectionControl.cs) (revision 08432b412fb47916669a52095d9e20afb24994c6) @@ -41,9 +41,9 @@ string DisplayName { get; } /// - /// Gets the selected or null if none selected. + /// Gets the selected or null if none selected. /// - WmtsMapData SelectedMapData { get; } + ImageBasedMapData SelectedMapData { get; } /// /// Gets the user control. Index: Core/Components/src/Core.Components.Gis.Forms/Views/WellKnownMapDataControl.Designer.cs =================================================================== diff -u --- Core/Components/src/Core.Components.Gis.Forms/Views/WellKnownMapDataControl.Designer.cs (revision 0) +++ Core/Components/src/Core.Components.Gis.Forms/Views/WellKnownMapDataControl.Designer.cs (revision 08432b412fb47916669a52095d9e20afb24994c6) @@ -0,0 +1,79 @@ +// 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 Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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. + +namespace Core.Components.Gis.Forms.Views +{ + partial class WellKnownMapDataControl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridViewControl = new Core.Common.Controls.DataGrid.DataGridViewControl(); + this.SuspendLayout(); + // + // dataGridViewControl + // + this.dataGridViewControl.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataGridViewControl.Location = new System.Drawing.Point(0, 0); + this.dataGridViewControl.MultiSelect = false; + this.dataGridViewControl.Name = "dataGridViewControl"; + this.dataGridViewControl.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridViewControl.Size = new System.Drawing.Size(150, 150); + this.dataGridViewControl.TabIndex = 0; + // + // WellKnownMapDataControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.dataGridViewControl); + this.Name = "WellKnownMapDataControl"; + this.ResumeLayout(false); + + } + + #endregion + + private Common.Controls.DataGrid.DataGridViewControl dataGridViewControl; + } +} Index: Core/Components/src/Core.Components.Gis.Forms/Views/WellKnownMapDataControl.cs =================================================================== diff -u --- Core/Components/src/Core.Components.Gis.Forms/Views/WellKnownMapDataControl.cs (revision 0) +++ Core/Components/src/Core.Components.Gis.Forms/Views/WellKnownMapDataControl.cs (revision 08432b412fb47916669a52095d9e20afb24994c6) @@ -0,0 +1,131 @@ +// 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 Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using Core.Components.Gis.Data; +using Core.Components.Gis.Forms.Properties; + +namespace Core.Components.Gis.Forms.Views +{ + /// + /// This class represents a where a well known map data layer can be selected. + /// + public partial class WellKnownMapDataControl : UserControl, IBackgroundMapDataSelectionControl + { + public event EventHandler SelectedMapDataChanged; + + /// + /// Creates a new instance of . + /// + /// The active + /// or null if none active. + public WellKnownMapDataControl(WellKnownTileSourceMapData activeWellKnownTileSourceMapData) + { + InitializeComponent(); + InitializeDataGridView(); + InitializeEventHandlers(); + + PreSelectDataGridView(activeWellKnownTileSourceMapData); + } + + public string DisplayName + { + get + { + return Resources.WellKnownMapDataControl_DisplayName; + } + } + + public ImageBasedMapData SelectedMapData + { + get + { + return dataGridViewControl.CurrentRow?.DataBoundItem as WellKnownTileSourceMapData; + } + } + + public UserControl UserControl => this; + + private void PreSelectDataGridView(WellKnownTileSourceMapData activeWellKnownTileSourceMapData) + { + if (activeWellKnownTileSourceMapData == null) + { + return; + } + DataGridViewRow dataGridViewRow = dataGridViewControl.Rows.OfType() + .FirstOrDefault(row => IsMatch((WellKnownTileSourceMapData) row.DataBoundItem, + activeWellKnownTileSourceMapData)); + if (dataGridViewRow == null) + { + return; + } + DataGridViewCell cell = dataGridViewControl.GetCell(dataGridViewRow.Index, 0); + dataGridViewControl.SetCurrentCell(cell); + } + + private static bool IsMatch(WellKnownTileSourceMapData mapData, WellKnownTileSourceMapData otherMapData) + { + return mapData.TileSource == otherMapData.TileSource && string.Equals(mapData.Name,otherMapData.Name); + } + + #region DataGridView + + private void InitializeDataGridView() + { + dataGridViewControl.AddTextBoxColumn(nameof(WellKnownTileSourceMapData.Name), Resources.WellKnownTileSourceMapData_Description, + true, DataGridViewAutoSizeColumnMode.Fill); + UpdateDataGridViewDataSource(); + } + + private void UpdateDataGridViewDataSource() + { + WellKnownTileSourceMapData[] knownTileSourceMapDatas = GetSortedWellKnownTileSourceMapDatas(); + + dataGridViewControl.SetDataSource(knownTileSourceMapDatas); + dataGridViewControl.ClearCurrentCell(); + } + + private static WellKnownTileSourceMapData[] GetSortedWellKnownTileSourceMapDatas() + { + var enumValues = (WellKnownTileSource[]) Enum.GetValues(typeof(WellKnownTileSource)); + return enumValues.Select(enumValue => new WellKnownTileSourceMapData(enumValue)).ToList().OrderBy(w => w.Name).ToArray(); + } + + private void DataGridViewCurrentCellChangedHandler(object sender, EventArgs e) + { + SelectedMapDataChanged?.Invoke(this, e); + } + + #endregion + + #region Event handlers + + private void InitializeEventHandlers() + { + dataGridViewControl.AddCurrentCellChangedHandler(DataGridViewCurrentCellChangedHandler); + } + #endregion + + } +} \ No newline at end of file Index: Core/Components/src/Core.Components.Gis.Forms/Views/WellKnownMapDataControl.resx =================================================================== diff -u --- Core/Components/src/Core.Components.Gis.Forms/Views/WellKnownMapDataControl.resx (revision 0) +++ Core/Components/src/Core.Components.Gis.Forms/Views/WellKnownMapDataControl.resx (revision 08432b412fb47916669a52095d9e20afb24994c6) @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file Index: Core/Components/src/Core.Components.Gis.Forms/Views/WmtsLocationControl.cs =================================================================== diff -u -r47c9793a0d5c1bbaa195f6c315b39cd562ad0648 -r08432b412fb47916669a52095d9e20afb24994c6 --- Core/Components/src/Core.Components.Gis.Forms/Views/WmtsLocationControl.cs (.../WmtsLocationControl.cs) (revision 47c9793a0d5c1bbaa195f6c315b39cd562ad0648) +++ Core/Components/src/Core.Components.Gis.Forms/Views/WmtsLocationControl.cs (.../WmtsLocationControl.cs) (revision 08432b412fb47916669a52095d9e20afb24994c6) @@ -94,7 +94,7 @@ } } - public WmtsMapData SelectedMapData + public ImageBasedMapData SelectedMapData { get { Index: Core/Components/test/Core.Components.Gis.Forms.Test/Core.Components.Gis.Forms.Test.csproj =================================================================== diff -u -r1eeed8168101200ec6bbfb79defc20c67a1f7edb -r08432b412fb47916669a52095d9e20afb24994c6 --- Core/Components/test/Core.Components.Gis.Forms.Test/Core.Components.Gis.Forms.Test.csproj (.../Core.Components.Gis.Forms.Test.csproj) (revision 1eeed8168101200ec6bbfb79defc20c67a1f7edb) +++ Core/Components/test/Core.Components.Gis.Forms.Test/Core.Components.Gis.Forms.Test.csproj (.../Core.Components.Gis.Forms.Test.csproj) (revision 08432b412fb47916669a52095d9e20afb24994c6) @@ -61,6 +61,7 @@ Properties\GlobalAssembly.cs + @@ -85,6 +86,10 @@ {30e4c2ae-719e-4d70-9fa9-668a9767fbfa} Core.Common.Gui + + {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98} + Core.Common.Utils + {26214BD0-DAFB-4CFC-8EB2-80C5D53C859E} Core.Common.Gui.TestUtil Index: Core/Components/test/Core.Components.Gis.Forms.Test/Views/WellKnownMapDataControlTest.cs =================================================================== diff -u --- Core/Components/test/Core.Components.Gis.Forms.Test/Views/WellKnownMapDataControlTest.cs (revision 0) +++ Core/Components/test/Core.Components.Gis.Forms.Test/Views/WellKnownMapDataControlTest.cs (revision 08432b412fb47916669a52095d9e20afb24994c6) @@ -0,0 +1,188 @@ +// 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 Lesser 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 Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser 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; +using System.Windows.Forms; +using Core.Common.Controls.DataGrid; +using Core.Common.TestUtil; +using Core.Common.Utils.Reflection; +using Core.Components.Gis.Data; +using Core.Components.Gis.Forms.Views; +using NUnit.Extensions.Forms; +using NUnit.Framework; + +namespace Core.Components.Gis.Forms.Test.Views +{ + [TestFixture] + public class WellKnownMapDataControlTest + { + [Test] + public void Constructor_ActiveWellKnownTileSourceMapDataNull_DefaultValues() + { + // Call + using (var control = new WellKnownMapDataControl(null)) + { + // Assert + Assert.IsInstanceOf(control); + Assert.IsInstanceOf(control); + Assert.AreEqual("Bekende kaartlagen", control.DisplayName); + Assert.IsNull(control.SelectedMapData); + Assert.AreSame(control, control.UserControl); + } + } + + [Test] + public void Constructor_ValidWellKnownTileSourceMapData_ExpectedProperties() + { + // Setup + var activeWellKnownTileSourceMapData = new WellKnownTileSourceMapData(WellKnownTileSource.BingAerial); + + // Call + using (var control = new WellKnownMapDataControl(activeWellKnownTileSourceMapData)) + { + // Assert + AssertAreEqual(activeWellKnownTileSourceMapData, control.SelectedMapData); + } + } + + [Test] + public void Constructor_InvalidWellKnownTileSourceMapData_ExpectedProperties() + { + // Setup + var activeWellKnownTileSourceMapData = new WellKnownTileSourceMapData(WellKnownTileSource.BingAerial) + { + Name = "invalid" + }; + + // Call + using (var control = new WellKnownMapDataControl(activeWellKnownTileSourceMapData)) + { + // Assert + Assert.IsNull(control.SelectedMapData); + } + } + + [Test] + public void WellKnownMapDataControl_WithData_DataGridViewCorrectlyInitialized() + { + // Setup + var random = new Random(124); + var selectedWellKnownTileSourceMapData = new WellKnownTileSourceMapData(random.NextEnumValue()); + + using (var form = new Form()) + { + // Call + using (var control = new WellKnownMapDataControl(selectedWellKnownTileSourceMapData)) + { + form.Controls.Add(control); + + // Assert + var dataGridViewControl = (DataGridViewControl) new ControlTester("dataGridViewControl", form).TheObject; + DataGridViewRowCollection rows = dataGridViewControl.Rows; + Assert.AreEqual(6, rows.Count); + + string[] blaat = + { + "Bing Maps - Satelliet", + "Bing Maps - Satelliet + Wegen", + "Bing Maps - Wegen", + "Esri World - Reliëf", + "Esri World - Topografisch", + "OpenStreetMap" + }; + + string selectedWellKnownTileSourceMapDataDisplayName = TypeUtils.GetDisplayName(selectedWellKnownTileSourceMapData.TileSource); + var expectedIndex = -1; + for (var index = 0; index < blaat.Length; index++) + { + DataGridViewCellCollection cells = rows[index].Cells; + Assert.AreEqual(1, cells.Count); + Assert.AreEqual(blaat[index], cells[0].FormattedValue); + if (selectedWellKnownTileSourceMapDataDisplayName.Equals(cells[0].FormattedValue)) + { + expectedIndex = index; + } + } + + DataGridViewRow currentRow = dataGridViewControl.CurrentRow; + Assert.IsNotNull(currentRow); + Assert.AreEqual(expectedIndex, currentRow.Cells[0].RowIndex); + } + } + } + + [Test] + public void SelectedMapData_DifferentRowSelected_UpdatesSelectedMapData() + { + // Setup + var selectedWellKnownTileSourceMapData = new WellKnownTileSourceMapData(WellKnownTileSource.BingAerial); + var selectionChanged = 0; + + using (var form = new Form()) + using (var control = new WellKnownMapDataControl(selectedWellKnownTileSourceMapData)) + { + form.Controls.Add(control); + var dataGridViewControl = (DataGridViewControl) new ControlTester("dataGridViewControl", form).TheObject; + dataGridViewControl.AddCurrentCellChangedHandler((sender, args) => selectionChanged++); + DataGridViewRow row = dataGridViewControl.GetRowFromIndex(2); + + dataGridViewControl.SetCurrentCell(row.Cells[0]); + + // Call + ImageBasedMapData actualImageBasedMapData = control.SelectedMapData; + + // Assert + AssertAreEqual(row.DataBoundItem as WellKnownTileSourceMapData, actualImageBasedMapData); + Assert.AreEqual(1, selectionChanged); + } + } + + [Test] + public void Dispose_AlreadyDisposed_DoesNotThrowException() + { + // Setup + + // Call + TestDelegate call = () => + { + using (var control = new WellKnownMapDataControl(null)) + { + control.Dispose(); + } + }; + + // Assert + Assert.DoesNotThrow(call); + } + + private static void AssertAreEqual(WellKnownTileSourceMapData expected, ImageBasedMapData actual) + { + if (expected == null) + { + Assert.IsNull(actual); + return; + } + var actualWellKnownTileSourceMapData = (WellKnownTileSourceMapData) actual; + Assert.AreEqual(expected.Name, actualWellKnownTileSourceMapData.Name); + Assert.AreEqual(expected.TileSource, actualWellKnownTileSourceMapData.TileSource); + } + } +} \ No newline at end of file Index: Core/Components/test/Core.Components.Gis.Forms.Test/Views/WmtsLocationControlTest.cs =================================================================== diff -u -r40f95a6148618454e9a22e8493c288b4310a2255 -r08432b412fb47916669a52095d9e20afb24994c6 --- Core/Components/test/Core.Components.Gis.Forms.Test/Views/WmtsLocationControlTest.cs (.../WmtsLocationControlTest.cs) (revision 40f95a6148618454e9a22e8493c288b4310a2255) +++ Core/Components/test/Core.Components.Gis.Forms.Test/Views/WmtsLocationControlTest.cs (.../WmtsLocationControlTest.cs) (revision 08432b412fb47916669a52095d9e20afb24994c6) @@ -437,7 +437,7 @@ dataGridViewControl.SetCurrentCell(dataGridViewControl.GetCell(1, 0)); // Call - WmtsMapData selectedMapData = control.SelectedMapData; + WmtsMapData selectedMapData = control.SelectedMapData as WmtsMapData; // Assert Assert.IsNotNull(selectedMapData); @@ -945,17 +945,18 @@ tileSource.Name, wmtsTileSchema.Srs); } - private static void AssertAreEqual(WmtsMapData expected, WmtsMapData actual) + private static void AssertAreEqual(WmtsMapData expected, ImageBasedMapData actual) { if (expected == null) { Assert.IsNull(actual); return; } - Assert.AreEqual(expected.Name, actual.Name); - Assert.AreEqual(expected.PreferredFormat, actual.PreferredFormat); - Assert.AreEqual(expected.SelectedCapabilityIdentifier, actual.SelectedCapabilityIdentifier); - Assert.AreEqual(expected.SourceCapabilitiesUrl, actual.SourceCapabilitiesUrl); + var actualWmtsMapData = (WmtsMapData) actual; + Assert.AreEqual(expected.Name, actualWmtsMapData.Name); + Assert.AreEqual(expected.PreferredFormat, actualWmtsMapData.PreferredFormat); + Assert.AreEqual(expected.SelectedCapabilityIdentifier, actualWmtsMapData.SelectedCapabilityIdentifier); + Assert.AreEqual(expected.SourceCapabilitiesUrl, actualWmtsMapData.SourceCapabilitiesUrl); } private static WmtsLocationControl ShowFullyConfiguredWmtsLocationControl(Form form, IWmtsCapabilityFactory wmtsCapabilityFactory) Index: Ringtoets/Integration/src/Ringtoets.Integration.Forms/BackgroundMapDataSelectionDialog.cs =================================================================== diff -u -r99f9004206bfb9de084275d749b7aeccafd6da18 -r08432b412fb47916669a52095d9e20afb24994c6 --- Ringtoets/Integration/src/Ringtoets.Integration.Forms/BackgroundMapDataSelectionDialog.cs (.../BackgroundMapDataSelectionDialog.cs) (revision 99f9004206bfb9de084275d749b7aeccafd6da18) +++ Ringtoets/Integration/src/Ringtoets.Integration.Forms/BackgroundMapDataSelectionDialog.cs (.../BackgroundMapDataSelectionDialog.cs) (revision 08432b412fb47916669a52095d9e20afb24994c6) @@ -62,9 +62,9 @@ } /// - /// Gets the selected or null if none selected. + /// Gets the selected or null if none selected. /// - public WmtsMapData SelectedMapData { get; private set; } + public ImageBasedMapData SelectedMapData { get; private set; } protected override void Dispose(bool disposing) {