// Copyright (C) Stichting Deltares 2018. 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.Standard; namespace Deltares.DamEngine.Data.General.Sensors { /// /// This class represents a sensor or monitoring point used in dikes. /// This entity is created for Dam Live /// public class Sensor : IName { #region Business Rules /// /// Specication to test if the value of the candidate is valid /// // internal class ContiansAtLeastOneItem : PredicateSpecification> // { // public ContiansAtLeastOneItem() // : base(x => x.Any()) // { // Description = "The sensor should contain at least one PL Line mapping."; // } // } #endregion //private readonly IGeometry geometry; private double relativeLocation; private readonly HashSet plLineTypes; private int id; private double xRd; private double yRd; private double zRd; /// /// Initializes a new instance of the class. /// public Sensor() { plLineTypes = new HashSet(); ID = -1; //geometry = new Point(0,0,0); } // public Sensor(Point point) : this() // { // if (point == null) throw new ArgumentNullException("point"); // //this.geometry = point; // // } /// /// Initializes a new instance of the class. /// /// The x. /// The y. /// The z. public Sensor(double x, double y, double z) //: this(new Point(x, y, z)) { xRd = x; yRd = y; zRd = z; } /// /// Gets or sets the ID. /// /// /// The ID should be unique. /// public int ID { get { return id; } set { id = value; } } /// /// Gets or sets the name of this sensor. /// /// /// The name string value should not be empty and unique. /// // [Specification(typeof(NotEmptySpecification))] public string Name { get; set; } /// /// Gets or sets the depth. /// /// /// The depth. /// public double Depth { get { return ZRd; } set { ZRd = value; } } /// /// Gets or sets the relative location along the profile. /// /// /// The relative location in meter. /// public double RelativeLocation { get { return relativeLocation; } set { relativeLocation = value; RelativeLocationSpecified = true; } } /// /// Gets or sets the X rd. /// /// /// The X rd. /// public double XRd { get { return xRd; } set { xRd = value; } } /// /// Gets or sets the Y rd. /// /// /// The Y rd. /// public double YRd { get { return yRd; } set { yRd = value; } } /// /// Gets or sets the Z rd. Same as Depth?? /// /// /// The Z rd. /// public double ZRd { get { return zRd; } set { zRd = value; } } /// /// Gets a value indicating whether the relative location is specified. /// /// /// true if the relative location is specified; otherwise, false. /// public bool RelativeLocationSpecified { get; private set; } private SensorType sensorType; /// /// Gets or sets the type of this sensor. /// /// /// The type. Default value is PiezoMetricHead. /// public SensorType SensorType { get { return sensorType; } set { sensorType = value; } } /// /// Gets or sets the PL line array. Used for serialization only. /// /// /// The PL line array. /// // [Specification(typeof(NotNullSpecification))] // [Specification(typeof(ContiansAtLeastOneItem))] public PlLineType[] PlLineMappings { get { return plLineTypes.ToArray(); } set { ClearPlLines(); foreach (var lineType in value) { Add(lineType); } } } /// /// Gets or sets the pl line mappings as string. /// /// /// The pl line mappings as string. /// public string PlLineMappingsAsString { get { string res = ""; foreach (var plLineType in plLineTypes) { switch (plLineType) { case PlLineType.Pl1: res = res + "1; "; break; case PlLineType.Pl2: res = res + "2; "; break; case PlLineType.Pl3: res = res + "3; "; break; case PlLineType.Pl4: res = res + "4; "; break; } } return res; } set { ClearPlLines(); var locPlLineTypes = ParseStringToPlLineTypes(value); foreach (var plLineType in locPlLineTypes) { switch (plLineType) { case 1: plLineTypes.Add(PlLineType.Pl1); break; case 2: plLineTypes.Add(PlLineType.Pl2); break; case 3: plLineTypes.Add(PlLineType.Pl3); break; case 4: plLineTypes.Add(PlLineType.Pl4); break; } } } } private List ParseStringToPlLineTypes(string value) { value = value.Trim(); var ids = new List(); var idsarr = value.Split(new Char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (var s in idsarr) { try { var val = Int32.Parse(s); ids.Add(val); } catch (Exception) { // surpress errors, just do not use value } } return ids; } /// /// Adds the specified PL line. /// /// The PL line. public void Add(PlLineType plLine) { plLineTypes.Add(plLine); } /// /// Removes the specified PL line. /// /// The PL line. public void Remove(PlLineType plLine) { plLineTypes.Remove(plLine); } /// /// Clears the PL lines list. /// public void ClearPlLines() { plLineTypes.Clear(); } /// /// Determines whether this instance is valid. /// /// /// true if this instance is valid; otherwise, false. /// // public bool IsValid() // { // return !Validator.Validate(this).Any(); // } /// /// Determines whether this instance is transient (associated with a correct ID in the context of the repository). /// /// /// true if this instance is transient; otherwise, false. /// public bool IsTransient() { return ID < 0; } /// /// Returns a that represents this instance. /// /// /// A that represents this instance. /// public override string ToString() { var name = string.IsNullOrWhiteSpace(Name) ? "name_not_set" : Name; return string.Format("[ID: {0}, Name: {1}, Depth: {2}, Type: {3}, RelativeLocation: {4}]", ID, name, Depth, SensorType, RelativeLocation); } } }