Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj =================================================================== diff -u -r640d98ea54ad8f801f8be35ba9019553fba6a135 -rdd2a51d0a110b707de32cca2b00994f33f877c9c --- Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision 640d98ea54ad8f801f8be35ba9019553fba6a135) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision dd2a51d0a110b707de32cca2b00994f33f877c9c) @@ -116,7 +116,6 @@ Form - @@ -266,6 +265,11 @@ Ringtoets.Common.Service False + + {6A074D65-A81C-4C1C-8E24-F36C916E4ED7} + Ringtoets.Common.Utils + False + Fisheye: Tag dd2a51d0a110b707de32cca2b00994f33f877c9c refers to a dead (removed) revision in file `Ringtoets/Common/src/Ringtoets.Common.Forms/TypeConverters/BackgroundDataConverter.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/RingtoetsBackgroundMapDataFactory.cs =================================================================== diff -u -rc2b4bf524f457472880c238cbc4ad0aa0ba589f0 -rdd2a51d0a110b707de32cca2b00994f33f877c9c --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/RingtoetsBackgroundMapDataFactory.cs (.../RingtoetsBackgroundMapDataFactory.cs) (revision c2b4bf524f457472880c238cbc4ad0aa0ba589f0) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/RingtoetsBackgroundMapDataFactory.cs (.../RingtoetsBackgroundMapDataFactory.cs) (revision dd2a51d0a110b707de32cca2b00994f33f877c9c) @@ -23,7 +23,7 @@ using System.ComponentModel; using Core.Components.Gis.Data; using Ringtoets.Common.Data.AssessmentSection; -using Ringtoets.Common.Forms.TypeConverters; +using Ringtoets.Common.Utils.TypeConverters; namespace Ringtoets.Common.Forms.Views { Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Views/RingtoetsMapControl.cs =================================================================== diff -u -r1d7f9c7875b22fe69fd5b1a32b2bc817dd6cf192 -rdd2a51d0a110b707de32cca2b00994f33f877c9c --- Ringtoets/Common/src/Ringtoets.Common.Forms/Views/RingtoetsMapControl.cs (.../RingtoetsMapControl.cs) (revision 1d7f9c7875b22fe69fd5b1a32b2bc817dd6cf192) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Views/RingtoetsMapControl.cs (.../RingtoetsMapControl.cs) (revision dd2a51d0a110b707de32cca2b00994f33f877c9c) @@ -23,7 +23,7 @@ using Core.Components.DotSpatial.Forms; using Core.Components.Gis.Data; using Ringtoets.Common.Data.AssessmentSection; -using Ringtoets.Common.Forms.TypeConverters; +using Ringtoets.Common.Utils.TypeConverters; namespace Ringtoets.Common.Forms.Views { Index: Ringtoets/Common/src/Ringtoets.Common.Utils/Ringtoets.Common.Utils.csproj =================================================================== diff -u -r9487e717f5c13a44bdf7bc60cfa7fccb9a3fd84a -rdd2a51d0a110b707de32cca2b00994f33f877c9c --- Ringtoets/Common/src/Ringtoets.Common.Utils/Ringtoets.Common.Utils.csproj (.../Ringtoets.Common.Utils.csproj) (revision 9487e717f5c13a44bdf7bc60cfa7fccb9a3fd84a) +++ Ringtoets/Common/src/Ringtoets.Common.Utils/Ringtoets.Common.Utils.csproj (.../Ringtoets.Common.Utils.csproj) (revision dd2a51d0a110b707de32cca2b00994f33f877c9c) @@ -53,6 +53,7 @@ + @@ -65,6 +66,11 @@ Core.Common.Base False + + {318BA582-88C9-4816-A54A-A7E431461DE3} + Core.Components.Gis + False + {D4200F43-3F72-4F42-AF0A-8CED416A38EC} Ringtoets.Common.Data Index: Ringtoets/Common/src/Ringtoets.Common.Utils/TypeConverters/BackgroundDataConverter.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Utils/TypeConverters/BackgroundDataConverter.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Utils/TypeConverters/BackgroundDataConverter.cs (revision dd2a51d0a110b707de32cca2b00994f33f877c9c) @@ -0,0 +1,158 @@ +// 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; +using System.ComponentModel; +using Core.Components.Gis.Data; +using Ringtoets.Common.Data.AssessmentSection; + +namespace Ringtoets.Common.Utils.TypeConverters +{ + /// + /// Converter to convert to + /// and back. + /// + public static class BackgroundDataConverter + { + /// + /// Converts to . + /// + /// The to convert. + /// The converted . + /// Thrown when + /// is null. + public static BackgroundData ConvertTo(ImageBasedMapData mapData) + { + if (mapData == null) + { + throw new ArgumentNullException(nameof(mapData)); + } + + var backgroundData = new BackgroundData + { + Name = mapData.Name, + IsConfigured = mapData.IsConfigured, + IsVisible = mapData.IsVisible, + Transparency = mapData.Transparency + }; + + var wmtsMapData = mapData as WmtsMapData; + if (wmtsMapData != null) + { + ConvertWmtsMapDataParameters(wmtsMapData, backgroundData); + } + var wellKnownMapData = mapData as WellKnownTileSourceMapData; + if (wellKnownMapData != null) + { + ConvertWellKnownMapDataParameters(wellKnownMapData, backgroundData); + } + + return backgroundData; + } + + /// + /// Converts to . + /// + /// The to convert. + /// The converted . + /// Thrown when + /// is null. + /// Thrown when + /// is not valid. + /// Thrown when + /// contains an invalid value for when the + /// is of type + /// . + public static ImageBasedMapData ConvertFrom(BackgroundData backgroundData) + { + if (backgroundData == null) + { + throw new ArgumentNullException(nameof(backgroundData)); + } + + ImageBasedMapData mapData; + + switch (backgroundData.BackgroundMapDataType) + { + case BackgroundMapDataType.Wmts: + mapData = CreateWmtsMapData(backgroundData); + break; + case BackgroundMapDataType.WellKnown: + mapData = CreateWellKnownMapdata(backgroundData); + break; + default: + throw new NotSupportedException(); + } + + mapData.Name = backgroundData.Name; + mapData.IsVisible = backgroundData.IsVisible; + mapData.Transparency = backgroundData.Transparency; + + return mapData; + } + + private static void ConvertWellKnownMapDataParameters(WellKnownTileSourceMapData mapData, BackgroundData backgroundData) + { + backgroundData.BackgroundMapDataType = BackgroundMapDataType.WellKnown; + backgroundData.Parameters[BackgroundDataIdentifiers.WellKnownTileSource] = ((int) mapData.TileSource).ToString(); + } + + private static void ConvertWmtsMapDataParameters(WmtsMapData mapData, BackgroundData backgroundData) + { + backgroundData.BackgroundMapDataType = BackgroundMapDataType.Wmts; + + if (backgroundData.IsConfigured) + { + backgroundData.Parameters[BackgroundDataIdentifiers.SourceCapabilitiesUrl] = mapData.SourceCapabilitiesUrl; + backgroundData.Parameters[BackgroundDataIdentifiers.SelectedCapabilityIdentifier] = mapData.SelectedCapabilityIdentifier; + backgroundData.Parameters[BackgroundDataIdentifiers.PreferredFormat] = mapData.PreferredFormat; + } + } + + private static WmtsMapData CreateWmtsMapData(BackgroundData backgroundData) + { + WmtsMapData wmtsMapData = WmtsMapData.CreateUnconnectedMapData(); + + if (backgroundData.IsConfigured) + { + wmtsMapData.Configure(backgroundData.Parameters[BackgroundDataIdentifiers.SourceCapabilitiesUrl], + backgroundData.Parameters[BackgroundDataIdentifiers.SelectedCapabilityIdentifier], + backgroundData.Parameters[BackgroundDataIdentifiers.PreferredFormat]); + } + return wmtsMapData; + } + + /// + /// Creates a , based upon the properties of . + /// + /// The to base the upon. + /// The newly created . + /// Thrown when + /// contains an invalid value for when the + /// is of type + /// . + private static WellKnownTileSourceMapData CreateWellKnownMapdata(BackgroundData backgroundData) + { + var tileSource = (WellKnownTileSource) Convert.ToInt32(backgroundData.Parameters[BackgroundDataIdentifiers.WellKnownTileSource]); + return new WellKnownTileSourceMapData(tileSource); + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj =================================================================== diff -u -r640d98ea54ad8f801f8be35ba9019553fba6a135 -rdd2a51d0a110b707de32cca2b00994f33f877c9c --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision 640d98ea54ad8f801f8be35ba9019553fba6a135) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision dd2a51d0a110b707de32cca2b00994f33f877c9c) @@ -107,7 +107,6 @@ - Fisheye: Tag dd2a51d0a110b707de32cca2b00994f33f877c9c refers to a dead (removed) revision in file `Ringtoets/Common/test/Ringtoets.Common.Forms.Test/TypeConverters/BackgroundDataConverterTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Ringtoets/Common/test/Ringtoets.Common.Utils.Test/Ringtoets.Common.Utils.Test.csproj =================================================================== diff -u -r24fff72c73f0e43ad9f9fcf3a616ab0f8f96e077 -rdd2a51d0a110b707de32cca2b00994f33f877c9c --- Ringtoets/Common/test/Ringtoets.Common.Utils.Test/Ringtoets.Common.Utils.Test.csproj (.../Ringtoets.Common.Utils.Test.csproj) (revision 24fff72c73f0e43ad9f9fcf3a616ab0f8f96e077) +++ Ringtoets/Common/test/Ringtoets.Common.Utils.Test/Ringtoets.Common.Utils.Test.csproj (.../Ringtoets.Common.Utils.Test.csproj) (revision dd2a51d0a110b707de32cca2b00994f33f877c9c) @@ -63,6 +63,7 @@ + @@ -79,6 +80,10 @@ {D749EE4C-CE50-4C17-BF01-9A953028C126} Core.Common.TestUtil + + {318BA582-88C9-4816-A54A-A7E431461DE3} + Core.Components.Gis + {D4200F43-3F72-4F42-AF0A-8CED416A38EC} Ringtoets.Common.Data @@ -87,6 +92,14 @@ {6A074D65-A81C-4C1C-8E24-F36C916E4ED7} Ringtoets.Common.Utils + + {4843D6E5-066F-4795-94F5-1D53932DD03C} + Ringtoets.Common.Data.TestUtil + + + {D24FA2F7-28A7-413B-AFD3-EE10E985630B} + Ringtoets.Common.Forms.TestUtil +