// Copyright (C) Stichting Deltares 2023. All rights reserved. // // This file is part of the Dam Engine. // // The Dam Engine is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero 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 Affero General Public License for more details. // // You should have received a copy of the GNU Affero 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 Deltares.DamEngine.Data.General; using Deltares.DamEngine.Data.General.PlLines; using Deltares.DamEngine.Data.General.Sensors; namespace Deltares.DamEngine.Calculators.PlLinesCreator { internal class SensorPlLineCreator { private readonly IDictionary creators = new Dictionary(); /// /// Initializes a new instance of the class. /// /// The 'concrete' creator. /// The type. public SensorPlLineCreator(IPlLineCreator creator, PlLineType type) { creators.Add(type, creator); } /// /// Initializes a new instance of the class. /// /// The 'concrete' creators. public SensorPlLineCreator(IEnumerable> creators) { foreach (Tuple creator in creators) { this.creators.Add(creator.Item1, creator.Item2); } } /// /// Creates an instance of a SensorPlLineCreator for Pl1. Pl3, Pl4. /// /// The sensor location. /// The sensor values. /// public static SensorPlLineCreator CreateInstance(SensorLocation sensorLocation, IDictionary sensorValues) { return CreateInstance(sensorLocation, sensorValues, new[] { PlLineType.Pl1, PlLineType.Pl3, PlLineType.Pl4, }); } /// /// Creates an instance of a SensorPlLineCreator. /// /// The sensor location. /// The sensor values. /// /// public static SensorPlLineCreator CreateInstance(SensorLocation sensorLocation, IDictionary sensorValues, IEnumerable lineTypes) { IPlLineCreator c1 = new SensorPlLine1Creator(sensorLocation, sensorValues); IPlLineCreator c3 = new SensorPlLine3Creator(sensorLocation, sensorValues); IPlLineCreator c4 = new SensorPlLine4Creator(sensorLocation, sensorValues); var tuples = new List>(); foreach (PlLineType lineType in lineTypes) { switch (lineType) { case PlLineType.Pl1: tuples.Add(new Tuple(lineType, c1)); break; case PlLineType.Pl2: // ignore break; case PlLineType.Pl3: tuples.Add(new Tuple(lineType, c3)); break; case PlLineType.Pl4: tuples.Add(new Tuple(lineType, c4)); break; default: throw new ArgumentOutOfRangeException(); } } if (!lineTypes.Contains(PlLineType.Pl3) && sensorLocation.SourceTypePl3 == DataSourceTypeSensors.LocationData) { tuples.Add(new Tuple(PlLineType.Pl3, c3)); } if (!lineTypes.Contains(PlLineType.Pl4) && sensorLocation.SourceTypePl4 == DataSourceTypeSensors.LocationData) { tuples.Add(new Tuple(PlLineType.Pl4, c4)); } return new SensorPlLineCreator(tuples); } /// /// Creates all PL lines. /// /// A PlLines set public PlLines CreateAllPlLines() { var lines = new PlLines(); foreach (KeyValuePair item in creators) { IPlLineCreator creator = item.Value; PlLine PlLine = creator.CreatePlLine(); lines.Lines[PlLine.PlLineType] = PlLine; } return lines; } /// /// Creates a PL line of the given type. /// /// The type of the PL line. /// A PlLine instance public PlLine CreatePlLine(PlLineType type) { if (!creators.ContainsKey(type) || creators[type] == null) { throw new NotSupportedException("Creation of type " + type + " currently not supported"); } return creators[type].CreatePlLine(); } } }