// 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; using Core.Common.Base.Geometry; using Ringtoets.MacroStabilityInwards.Primitives; namespace Ringtoets.MacroStabilityInwards.Data { /// /// This class represents a stochastic soil model which consists out of a collection of . /// A stochastic soil model contains a segment for which the model applies. /// public class StochasticSoilModel : Observable { /// /// Creates a new instance of . /// /// Database identifier of the stochastic soil model. /// Name of the segment soil model. /// Name of the segment soil model segment. public StochasticSoilModel(long id, string name, string segmentName) { Id = id; Name = name; SegmentName = segmentName; Geometry = new List(); StochasticSoilProfiles = new List(); } /// /// Gets the database identifier of the stochastic soil model. /// public long Id { get; private set; } /// /// Gets the name of the segment soil model. /// public string Name { get; private set; } /// /// /// Gets the name of the segment soil model segment. /// public string SegmentName { get; private set; } /// /// Gets the list of geometry points. /// public List Geometry { get; } /// /// Gets the list of . /// public List StochasticSoilProfiles { get; } /// /// Updates the with the properties /// from . /// /// The to /// obtain the property values from. /// Thrown when /// is null. /// Thrown when /// contains multiple profiles with the same name, and also contains a /// profile with the same name. /// public StochasticSoilModelProfileDifference Update(StochasticSoilModel fromModel) { if (fromModel == null) { throw new ArgumentNullException(nameof(fromModel)); } Id = fromModel.Id; Name = fromModel.Name; SegmentName = fromModel.SegmentName; Geometry.Clear(); foreach (Point2D point in fromModel.Geometry) { Geometry.Add(point); } var newSoilProfiles = new List(); var updatedProfiles = new List(); var addedProfiles = new List(); var removedProfiles = new List(); foreach (StochasticSoilProfile fromProfile in fromModel.StochasticSoilProfiles) { StochasticSoilProfile sameProfile = StochasticSoilProfiles.SingleOrDefault( sp => IsSame(sp, fromProfile) ); if (sameProfile != null) { if (sameProfile.Update(fromProfile)) { updatedProfiles.Add(sameProfile); } } else { StochasticSoilProfiles.Add(fromProfile); addedProfiles.Add(fromProfile); } newSoilProfiles.Add(fromProfile.SoilProfile); } foreach (StochasticSoilProfile profileToRemove in StochasticSoilProfiles.Where( sp => !newSoilProfiles.Any(newSp => IsSame(newSp, sp.SoilProfile))).ToArray()) { StochasticSoilProfiles.Remove(profileToRemove); removedProfiles.Add(profileToRemove); } return new StochasticSoilModelProfileDifference(addedProfiles, updatedProfiles, removedProfiles); } public override string ToString() { return Name; } private static bool IsSame(MacroStabilityInwardsSoilProfile macroStabilityInwardsSoilProfile, MacroStabilityInwardsSoilProfile otherMacroStabilityInwardsSoilProfile) { return macroStabilityInwardsSoilProfile.Name.Equals(otherMacroStabilityInwardsSoilProfile.Name) && macroStabilityInwardsSoilProfile.SoilProfileType.Equals(otherMacroStabilityInwardsSoilProfile.SoilProfileType); } private static bool IsSame(StochasticSoilProfile stochasticSoilProfile, StochasticSoilProfile otherStochasticSoilProfile) { return IsSame(stochasticSoilProfile.SoilProfile, otherStochasticSoilProfile.SoilProfile); } } }