Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Factories/RingtoetsGraphNodeFactory.cs =================================================================== diff -u -r95d9fe65a46c2fbd58388014f903ab9dd4d9e25c -rd31087af5b9320ee36f3f8462cc71ed5f1e25e34 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Factories/RingtoetsGraphNodeFactory.cs (.../RingtoetsGraphNodeFactory.cs) (revision 95d9fe65a46c2fbd58388014f903ab9dd4d9e25c) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Factories/RingtoetsGraphNodeFactory.cs (.../RingtoetsGraphNodeFactory.cs) (revision d31087af5b9320ee36f3f8462cc71ed5f1e25e34) @@ -36,7 +36,8 @@ { private static readonly XmlWriterSettings xmlWriterSettings = new XmlWriterSettings { - OmitXmlDeclaration = true + OmitXmlDeclaration = true, + NewLineHandling = NewLineHandling.Replace }; /// @@ -71,7 +72,7 @@ return new GraphNode(GetGraphNodeContentXml(title, content), childNodes.ToArray(), true, - new GraphNodeStyle(GraphNodeShape.Rectangle, Color.LightSkyBlue, Color.Black, 1)); + new GraphNodeStyle(GraphNodeShape.Rectangle, Color.LightGray, Color.Black, 1)); } /// @@ -91,7 +92,7 @@ return new GraphNode(GetGraphNodeContentXml(title), childNodes.ToArray(), false, - new GraphNodeStyle(GraphNodeShape.Rectangle, Color.BlanchedAlmond, Color.Black, 1)); + new GraphNodeStyle(GraphNodeShape.None, Color.BlanchedAlmond, Color.Black, 1)); } private static string GetGraphNodeContentXml(string content) Index: Ringtoets/Common/src/Ringtoets.Common.Forms/GraphNodeConverter.cs =================================================================== diff -u --- Ringtoets/Common/src/Ringtoets.Common.Forms/GraphNodeConverter.cs (revision 0) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/GraphNodeConverter.cs (revision d31087af5b9320ee36f3f8462cc71ed5f1e25e34) @@ -0,0 +1,108 @@ +// Copyright (C) Stichting Deltares 2017. 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.Collections.Generic; +using System.Linq; +using Core.Common.Base.Data; +using Core.Common.Utils; +using Core.Components.PointedTree.Data; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Forms.Factories; +using Ringtoets.Common.Forms.Helpers; +using Ringtoets.Common.Forms.Properties; + +namespace Ringtoets.Common.Forms +{ + /// + /// The converter that converts data into + /// data. + /// + internal static class GraphNodeConverter + { + /// + /// Creates a new instance of a based on the + /// . + /// + /// The to base the + /// to create on. + /// A . + /// Thrown when is null. + /// Thrown when no suitable conversion for + /// was found. + public static GraphNode Convert(IllustrationPointNode node) + { + if (node == null) + { + throw new ArgumentNullException(nameof(node)); + } + + IllustrationPointBase illustrationPoint = node.Data; + var subMechanismIllustrationPoint = illustrationPoint as SubMechanismIllustrationPoint; + if (subMechanismIllustrationPoint != null) + { + return ConvertSubMechanismIllustrationPoint(subMechanismIllustrationPoint); + } + + var faultTreeIllustrationPoint = illustrationPoint as FaultTreeIllustrationPoint; + if (faultTreeIllustrationPoint != null) + { + IEnumerable childGraphNodes = node.Children.Select(Convert); + + return ConvertFaultTreeIllustrationPoint(faultTreeIllustrationPoint, + childGraphNodes); + } + + throw new NotSupportedException($"Cannot convert {illustrationPoint.GetType()}."); + } + + private static GraphNode ConvertFaultTreeIllustrationPoint(FaultTreeIllustrationPoint illustrationPoint, + IEnumerable childGraphNodes) + { + string childRelationTitle = illustrationPoint.CombinationType == CombinationType.And + ? Resources.GraphNode_CombinationType_And + : Resources.GraphNode_CombinationType_Or; + GraphNode connectionGraphNode = RingtoetsGraphNodeFactory.CreateConnectingGraphNode(childRelationTitle, childGraphNodes); + + return RingtoetsGraphNodeFactory.CreateCompositeGraphNode( + illustrationPoint.Name, + CreateGraphNodeContent(illustrationPoint.Beta), + new[] + { + connectionGraphNode + }); + } + + private static GraphNode ConvertSubMechanismIllustrationPoint(SubMechanismIllustrationPoint illustrationPoint) + { + return RingtoetsGraphNodeFactory.CreateEndGraphNode( + illustrationPoint.Name, + CreateGraphNodeContent(illustrationPoint.Beta)); + } + + private static string CreateGraphNodeContent(RoundedDouble beta) + { + return string.Format(Resources.GraphNodeConverter_GraphNodeContent_Beta_0_Probability_1, + beta, + ProbabilityFormattingHelper.Format(StatisticsConverter.ReliabilityToProbability(beta))); + } + } +} \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs =================================================================== diff -u -r0928ad4519b95a976e691bec80b13d1a301fa865 -rd31087af5b9320ee36f3f8462cc71ed5f1e25e34 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 0928ad4519b95a976e691bec80b13d1a301fa865) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision d31087af5b9320ee36f3f8462cc71ed5f1e25e34) @@ -1594,6 +1594,35 @@ } /// + /// Looks up a localized string similar to En. + /// + public static string GraphNode_CombinationType_And { + get { + return ResourceManager.GetString("GraphNode_CombinationType_And", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Of. + /// + public static string GraphNode_CombinationType_Or { + get { + return ResourceManager.GetString("GraphNode_CombinationType_Or", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to + ///Beta = {0} + ///Pf = {1}. + /// + public static string GraphNodeConverter_GraphNodeContent_Beta_0_Probability_1 { + get { + return ResourceManager.GetString("GraphNodeConverter_GraphNodeContent_Beta_0_Probability_1", resourceCulture); + } + } + + /// /// Looks up a localized string similar to Valversnelling.. /// public static string GravitationalAcceleration_Description { Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx =================================================================== diff -u -r0928ad4519b95a976e691bec80b13d1a301fa865 -rd31087af5b9320ee36f3f8462cc71ed5f1e25e34 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision 0928ad4519b95a976e691bec80b13d1a301fa865) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Properties/Resources.resx (.../Resources.resx) (revision d31087af5b9320ee36f3f8462cc71ed5f1e25e34) @@ -1224,4 +1224,15 @@ Waarden in het illustratiepunt + + +Beta = {0} +Pf = {1} + + + En + + + Of + \ No newline at end of file Index: Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj =================================================================== diff -u -r95d9fe65a46c2fbd58388014f903ab9dd4d9e25c -rd31087af5b9320ee36f3f8462cc71ed5f1e25e34 --- Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision 95d9fe65a46c2fbd58388014f903ab9dd4d9e25c) +++ Ringtoets/Common/src/Ringtoets.Common.Forms/Ringtoets.Common.Forms.csproj (.../Ringtoets.Common.Forms.csproj) (revision d31087af5b9320ee36f3f8462cc71ed5f1e25e34) @@ -65,6 +65,7 @@ + Index: Ringtoets/Common/src/Ringtoets.Common.Service/IllustrationPoints/IllustrationPointNodeConverter.cs =================================================================== diff -u -r624182c7e9be3e758f0c6a55e360edac0892d48e -rd31087af5b9320ee36f3f8462cc71ed5f1e25e34 --- Ringtoets/Common/src/Ringtoets.Common.Service/IllustrationPoints/IllustrationPointNodeConverter.cs (.../IllustrationPointNodeConverter.cs) (revision 624182c7e9be3e758f0c6a55e360edac0892d48e) +++ Ringtoets/Common/src/Ringtoets.Common.Service/IllustrationPoints/IllustrationPointNodeConverter.cs (.../IllustrationPointNodeConverter.cs) (revision d31087af5b9320ee36f3f8462cc71ed5f1e25e34) @@ -77,7 +77,7 @@ /// /// Creates a new instance of a based on the - /// . + /// . /// /// The to base the /// to create on. Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Factories/RingtoetsGraphNodeFactoryTest.cs =================================================================== diff -u -r95d9fe65a46c2fbd58388014f903ab9dd4d9e25c -rd31087af5b9320ee36f3f8462cc71ed5f1e25e34 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Factories/RingtoetsGraphNodeFactoryTest.cs (.../RingtoetsGraphNodeFactoryTest.cs) (revision 95d9fe65a46c2fbd58388014f903ab9dd4d9e25c) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Factories/RingtoetsGraphNodeFactoryTest.cs (.../RingtoetsGraphNodeFactoryTest.cs) (revision d31087af5b9320ee36f3f8462cc71ed5f1e25e34) @@ -72,7 +72,7 @@ Assert.AreEqual(expectedContent, node.Content); Assert.IsTrue(node.IsSelectable); - var expectedStyle = new GraphNodeStyle(GraphNodeShape.Rectangle, Color.LightSkyBlue, Color.Black, 1); + var expectedStyle = new GraphNodeStyle(GraphNodeShape.Rectangle, Color.LightGray, Color.Black, 1); AssertEqualStyle(expectedStyle, node.Style); Assert.AreEqual(1, node.ChildNodes.Count()); @@ -110,7 +110,7 @@ Assert.AreEqual(expectedContent, node.Content); Assert.IsFalse(node.IsSelectable); - var expectedStyle = new GraphNodeStyle(GraphNodeShape.Rectangle, Color.BlanchedAlmond, Color.Black, 1); + var expectedStyle = new GraphNodeStyle(GraphNodeShape.None, Color.BlanchedAlmond, Color.Black, 1); AssertEqualStyle(expectedStyle, node.Style); Assert.AreEqual(1, node.ChildNodes.Count()); Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/GraphNodeConverterTest.cs =================================================================== diff -u --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/GraphNodeConverterTest.cs (revision 0) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/GraphNodeConverterTest.cs (revision d31087af5b9320ee36f3f8462cc71ed5f1e25e34) @@ -0,0 +1,213 @@ +// Copyright (C) Stichting Deltares 2017. 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.Linq; +using Core.Common.Base.Data; +using Core.Common.TestUtil; +using Core.Common.Utils; +using Core.Components.PointedTree.Data; +using NUnit.Framework; +using Ringtoets.Common.Data.IllustrationPoints; +using Ringtoets.Common.Data.TestUtil.IllustrationPoints; +using Ringtoets.Common.Forms.Helpers; + +namespace Ringtoets.Common.Forms.Test +{ + [TestFixture] + public class GraphNodeConverterTest + { + [Test] + public void Convert_NodeNull_ThrowsArgumentNullException() + { + // Call + TestDelegate test = () => GraphNodeConverter.Convert(null); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual("node", exception.ParamName); + } + + [Test] + public void Convert_InvalidTypeNodeData_ThrowsNotSupportedException() + { + // Setup + var node = new IllustrationPointNode(new TestIllustrationPoint()); + + // Call + TestDelegate test = () => GraphNodeConverter.Convert(node); + + // Assert + var exception = Assert.Throws(test); + Assert.AreEqual($"Cannot convert {node.Data.GetType()}.", exception.Message); + } + + [Test] + public void Convert_SubMechanismIllustrationPointNodeData_ReturnsExpected() + { + // Setup + const string name = "Illustration Point"; + RoundedDouble beta = new Random(7).NextRoundedDouble(); + var node = new IllustrationPointNode(new SubMechanismIllustrationPoint( + name, + beta, + Enumerable.Empty(), + Enumerable.Empty())); + + // Call + GraphNode graphNode = GraphNodeConverter.Convert(node); + + // Assert + Assert.AreEqual(CreateExpectedGraphNodeContent(name, beta), graphNode.Content); + Assert.IsTrue(graphNode.IsSelectable); + CollectionAssert.IsEmpty(graphNode.ChildNodes); + } + + [Test] + [TestCase(CombinationType.And)] + [TestCase(CombinationType.Or)] + public void Convert_FaultTreeIllustrationPointNodeDataWithoutChildren_ReturnsExpected(CombinationType combinationType) + { + // Setup + const string name = "Illustration Point"; + RoundedDouble beta = new Random(7).NextRoundedDouble(); + var node = new IllustrationPointNode(new FaultTreeIllustrationPoint( + name, + beta, + Enumerable.Empty(), + combinationType)); + + // Call + GraphNode graphNode = GraphNodeConverter.Convert(node); + + // Assert + Assert.AreEqual(CreateExpectedGraphNodeContent(name, beta), graphNode.Content); + Assert.IsTrue(graphNode.IsSelectable); + + Assert.AreEqual(1, graphNode.ChildNodes.Count()); + GraphNode childNode = graphNode.ChildNodes.First(); + Assert.AreEqual(CreateExpectedGraphConnectingNodeContent(combinationType), childNode.Content); + Assert.IsFalse(childNode.IsSelectable); + CollectionAssert.IsEmpty(childNode.ChildNodes); + } + + [Test] + public void Convert_FaultTreeIllustrationPointNodeDataWithChildren_ReturnsExpected() + { + // Setup + var random = new Random(70); + + var childFaultTreeNode = new IllustrationPointNode(new FaultTreeIllustrationPoint( + "ChildFaultTreeIllustrationPoint", + random.NextRoundedDouble(), + Enumerable.Empty(), + CombinationType.And)); + childFaultTreeNode.SetChildren(new[] + { + new IllustrationPointNode(new SubMechanismIllustrationPoint( + "ChildChildSubMechanismIllustrationPoint1", + random.NextRoundedDouble(), + Enumerable.Empty(), + Enumerable.Empty())), + new IllustrationPointNode(new SubMechanismIllustrationPoint( + "ChildChildSubMechanismIllustrationPoint2", + random.NextRoundedDouble(), + Enumerable.Empty(), + Enumerable.Empty())) + }); + + var node = new IllustrationPointNode(new FaultTreeIllustrationPoint( + "FaultTreeIllustrationPoint", + random.NextRoundedDouble(), + Enumerable.Empty(), + CombinationType.Or)); + node.SetChildren(new[] + { + new IllustrationPointNode(new SubMechanismIllustrationPoint( + "SubMechanismIllustrationPoint", + random.NextRoundedDouble(), + Enumerable.Empty(), + Enumerable.Empty())), + childFaultTreeNode + }); + + // Call + GraphNode graphNode = GraphNodeConverter.Convert(node); + + // Assert + Assert.AreEqual(CreateExpectedGraphNodeContent(node.Data.Name, node.Data.Beta), graphNode.Content); + + Assert.AreEqual(1, graphNode.ChildNodes.Count()); + GraphNode connectingNode1 = graphNode.ChildNodes.First(); + Assert.AreEqual(CreateExpectedGraphConnectingNodeContent(CombinationType.Or), connectingNode1.Content); + + Assert.AreEqual(2, connectingNode1.ChildNodes.Count()); + + IllustrationPointNode childIllustrationPointNode1 = node.Children.ElementAt(0); + GraphNode childGraphNode1 = connectingNode1.ChildNodes.ElementAt(0); + Assert.AreEqual(CreateExpectedGraphNodeContent(childIllustrationPointNode1.Data.Name, childIllustrationPointNode1.Data.Beta), + childGraphNode1.Content); + CollectionAssert.IsEmpty(childGraphNode1.ChildNodes); + + IllustrationPointNode childIllustrationPointNode2 = node.Children.ElementAt(1); + GraphNode childGraphNode2 = connectingNode1.ChildNodes.ElementAt(1); + Assert.AreEqual(CreateExpectedGraphNodeContent(childIllustrationPointNode2.Data.Name, childIllustrationPointNode2.Data.Beta), + childGraphNode2.Content); + + Assert.AreEqual(1, childGraphNode2.ChildNodes.Count()); + GraphNode connectingNode2 = childGraphNode2.ChildNodes.First(); + Assert.AreEqual(CreateExpectedGraphConnectingNodeContent(CombinationType.And), connectingNode2.Content); + + Assert.AreEqual(2, connectingNode2.ChildNodes.Count()); + + IllustrationPointNode childIllustrationPointNode21 = childIllustrationPointNode2.Children.ElementAt(0); + GraphNode childGraphNode11 = connectingNode2.ChildNodes.ElementAt(0); + Assert.AreEqual(CreateExpectedGraphNodeContent(childIllustrationPointNode21.Data.Name, childIllustrationPointNode21.Data.Beta), + childGraphNode11.Content); + CollectionAssert.IsEmpty(childGraphNode11.ChildNodes); + + IllustrationPointNode childIllustrationPointNode22 = childIllustrationPointNode2.Children.ElementAt(0); + GraphNode childGraphNode12 = connectingNode2.ChildNodes.ElementAt(0); + Assert.AreEqual(CreateExpectedGraphNodeContent(childIllustrationPointNode22.Data.Name, childIllustrationPointNode22.Data.Beta), + childGraphNode12.Content); + CollectionAssert.IsEmpty(childGraphNode12.ChildNodes); + } + + private static string CreateExpectedGraphNodeContent(string name, RoundedDouble beta) + { + RoundedDouble roundedBeta = beta.ToPrecision(5); + string probability = ProbabilityFormattingHelper.Format(StatisticsConverter.ReliabilityToProbability(beta)); + + return $"{name}{Environment.NewLine}" + + $"{Environment.NewLine}" + + $"Beta = {roundedBeta}{Environment.NewLine}" + + $"Pf = {probability}"; + } + + private static string CreateExpectedGraphConnectingNodeContent(CombinationType combinationType) + { + string name = combinationType == CombinationType.And + ? "En" + : "Of"; + return $"{name}"; + } + } +} \ No newline at end of file Index: Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj =================================================================== diff -u -r95d9fe65a46c2fbd58388014f903ab9dd4d9e25c -rd31087af5b9320ee36f3f8462cc71ed5f1e25e34 --- Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision 95d9fe65a46c2fbd58388014f903ab9dd4d9e25c) +++ Ringtoets/Common/test/Ringtoets.Common.Forms.Test/Ringtoets.Common.Forms.Test.csproj (.../Ringtoets.Common.Forms.Test.csproj) (revision d31087af5b9320ee36f3f8462cc71ed5f1e25e34) @@ -71,6 +71,7 @@ +