Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/EntityFactory.cs =================================================================== diff -u -r4070 -r4103 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/EntityFactory.cs (.../EntityFactory.cs) (revision 4070) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/EntityFactory.cs (.../EntityFactory.cs) (revision 4103) @@ -19,14 +19,9 @@ // 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.Geometry; -using Deltares.Geotechnics.GeotechnicalGeometry; using Deltares.Geotechnics.Soils; using Deltares.Geotechnics.SurfaceLines; -using Deltares.Soilbase; using Deltares.Standard.Extensions; namespace Deltares.Dam.Data; @@ -62,11 +57,6 @@ private readonly IList gauges = new List(); - /// - /// Holds a reference to the (concrete) SurfaceLine list - /// - private readonly IList scenarios = new List(); - #endregion #region Constructors @@ -193,611 +183,7 @@ this.gauges.RemoveNullElements(); } } - - if (scenarios != null) - { - if (scenarios == null) - { - scenarios = new List(); - scenarios.AddRangeLeavingNullElementsOut(scenarios); - } - else - { - scenarios.RemoveNullElements(); - } - } } #endregion - - #region Public lookup tables (IEnumarable collections) - - /// - /// Gets a reference to the locations list through the interface - /// - public IList Locations - { - get - { - return locations; - } - } - - /// - /// Gets a reference to the segments list through the interface - /// - public IEnumerable Segments - { - get - { - return segments; - } - } - - /// - /// Gets a reference to the soilProfiles list through the interface - /// - public IEnumerable SoilProfiles - { - get - { - return soilProfiles; - } - } - - /// - /// Gets a reference to the surfaceLines list through the interface - /// - public IEnumerable SurfaceLines - { - get - { - return surfaceLines; - } - } - - /// - /// Gets a reference to the scenarios list through the interface - /// - public IList Scenarios - { - get - { - return scenarios; - } - } - - #endregion - - #region Factory / Creational Methods - - public Dike CreateDike(string dikeId) - { - return new Dike - { - Name = dikeId - }; - } - - public Dike CreateDummyDike(string dikeId) - { - var dike = new Dike(); - dike.Name = dikeId; - dike.ShearStrengthModel = MStabShearStrength.CuGradient; - dike.SoilDatabaseName = SoilbaseDB.DefaultDatabaseName; - // PlLine - var plp1 = new GeometryPoint(); - plp1.X = 1; - plp1.Y = 2; - plp1.Z = 3; - var plp2 = new GeometryPoint(); - plp2.X = 4; - plp2.Y = 5; - plp2.Z = 6; - var pL1Line = new PL1Line(); - pL1Line.Points.Add(plp1); - pL1Line.Points.Add(plp2); - dike.PL1Lines.Add(pL1Line); - // Locations - var location1 = new Location(); - location1.DampingFactorPL3 = 0.3; - location1.DampingFactorPL4 = 0.4; - location1.PL1Line = pL1Line; - location1.Name = "Location1"; - location1.XRd = 45782; - location1.YRd = 143090; - location1.DikeEmbankmentMaterial = "clay"; - location1.ShoulderEmbankmentMaterial = "sand"; - location1.StabilityShoulderGrowSlope = 3.1; - location1.StabilityShoulderGrowDeltaX = 3.2; - location1.StabilitySlopeAdaptionDeltaX = 3.3; - location1.IntrusionVerticalWaterPressure = IntrusionVerticalWaterPressureType.FullHydroStatic; - location1.PenetrationLength = 3.6; - location1.TrafficLoad = 3.7; - location1.TL_DegreeOfConsolidation = 3.8; - location1.MinimalCircleDepth = 1.11; - location1.DistanceToEntryPoint = 1.16; - - dike.Locations.Add(location1); - var location2 = new Location(); - location2.Name = "Location2"; - dike.Locations.Add(location2); - var location3 = new Location(); - location3.Name = "Location3"; - dike.Locations.Add(location3); - var location4 = new Location(); - location4.Name = "Location4"; - dike.Locations.Add(location4); - var location5 = new Location(); - location5.Name = "Location5"; - dike.Locations.Add(location5); - - // Segments - var segment1 = new Segment(); - segment1.Name = "Segment1"; - var segment2 = new Segment(); - segment2.Name = "Segment2"; - - // Surface lines - var surfaceLine1 = new SurfaceLine2 - { - Geometry = new LocalizedGeometryPointString(), - CharacteristicPoints = - { - GeometryMustContainPoint = true - }, - Name = "SurfaceLine1" - }; - dike.SurfaceLines2.Add(surfaceLine1); - var surfaceLine2 = new SurfaceLine2 - { - Geometry = new LocalizedGeometryPointString(), - CharacteristicPoints = - { - GeometryMustContainPoint = true - }, - Name = "SurfaceLine2" - }; - dike.SurfaceLines2.Add(surfaceLine2); - - //Soils - var soilClay1 = new Soil(); - soilClay1.UseDefaultProbabilisticValues = false; - soilClay1.Name = "HW-OBO"; - soilClay1.AbovePhreaticLevel = 15.00; - soilClay1.BelowPhreaticLevel = 16.00; - soilClay1.DiameterD70 = 0.000013; - soilClay1.WhitesConstant = 1.0; - soilClay1.BeddingAngle = 1.0; - soilClay1.PermeabKx = 1.0; - soilClay1.ExcessPorePressure = 21.0; - soilClay1.PorePressureFactor = 0.8; - soilClay1.Cohesion = 12.7; - soilClay1.FrictionAngle = 11.1; - //soilClay1.StressTableName = "strtab"; - //soilClay1.StressTableNr = 3; - //soilClay1.BondStressTableName = "bondstrtab"; - //soilClay1.BondStressTableNr = 2; - soilClay1.ShearStrengthModel = ShearStrengthModel.CPhi; - soilClay1.UseDefaultProbabilisticValues = false; - soilClay1.CorrelationCPhi = 0.5; - soilClay1.POP = 4.2; - soilClay1.SoilGroup = 11; - soilClay1.RRatio = 5.5; - dike.SoilList.Soils.Add(soilClay1); - - var soilPeat1 = new Soil(); - soilPeat1.UseDefaultProbabilisticValues = false; - soilPeat1.Name = "HW-DUN"; - soilPeat1.AbovePhreaticLevel = 11.00; - soilPeat1.BelowPhreaticLevel = 13.00; - dike.SoilList.Soils.Add(soilPeat1); - var soilSand1 = new Soil(); - soilSand1.UseDefaultProbabilisticValues = false; - soilSand1.Name = "Alg-zand (0-30)"; - soilSand1.AbovePhreaticLevel = 18.50; - soilSand1.BelowPhreaticLevel = 21.75; - dike.SoilList.Soils.Add(soilSand1); - - var soilClay2 = new Soil(); - soilClay2.UseDefaultProbabilisticValues = false; - soilClay2.Name = "HW-OBO1"; - soilClay2.AbovePhreaticLevel = 14.67; - soilClay2.BelowPhreaticLevel = 16.45; - dike.SoilList.Soils.Add(soilClay2); - var soilPeat2 = new Soil(); - soilPeat2.UseDefaultProbabilisticValues = false; - soilPeat2.Name = "HW-DUN1"; - soilPeat2.AbovePhreaticLevel = 11.13; - soilPeat2.BelowPhreaticLevel = 12.64; - dike.SoilList.Soils.Add(soilPeat2); - var soilSand2 = new Soil(); - soilSand2.UseDefaultProbabilisticValues = false; - soilSand2.Name = "Alg-zand (0-30)1"; - soilSand2.AbovePhreaticLevel = 17.92; - soilSand2.BelowPhreaticLevel = 22.08; - dike.SoilList.Soils.Add(soilSand2); - - // Soil profiles - var soilProfile1 = new SoilProfile1D(); - soilProfile1.Name = "SoilProfile1"; - soilProfile1.X = 34534.34; - soilProfile1.Y = 49453.68; - soilProfile1.BottomLevel = -25.3; - soilProfile1.HasPhreaticLevel = true; - soilProfile1.PhreaticLevel = -3.54; - - var layer = new SoilLayer1D(); - layer.Id = "L1"; - layer.Name = "Layer 1"; - layer.TopLevel = -1.52; - layer.Soil = soilClay1; - layer.IsAquifer = true; - soilProfile1.Layers.Add(layer); - layer = new SoilLayer1D(); - layer.Id = "L2"; - layer.Name = "Layer 2"; - layer.TopLevel = -3.18; - layer.Soil = soilPeat1; - soilProfile1.Layers.Add(layer); - layer = new SoilLayer1D(); - layer.Id = "L3"; - layer.Name = "Layer 3"; - layer.TopLevel = -7.37; - layer.Soil = soilClay1; - layer.IsAquifer = true; - soilProfile1.Layers.Add(layer); - layer = new SoilLayer1D(); - layer.Id = "L4"; - layer.Name = "Layer 4"; - layer.TopLevel = -12.28; - layer.Soil = soilPeat1; - soilProfile1.Layers.Add(layer); - layer = new SoilLayer1D(); - layer.Id = "L5"; - layer.Name = "Layer 5"; - layer.TopLevel = -18.39; - layer.Soil = soilSand1; - soilProfile1.Layers.Add(layer); - dike.SoilProfiles.Add(soilProfile1); - - var soilProfile2 = new SoilProfile1D(); - soilProfile2.Name = "SoilProfile2"; - soilProfile2.X = 37212.54; - soilProfile2.Y = 48363.17; - soilProfile2.BottomLevel = -31.07; - soilProfile2.HasPhreaticLevel = true; - soilProfile2.PhreaticLevel = -5.92; - - layer = new SoilLayer1D(); - layer.Id = "L1"; - layer.Name = "Layer 1"; - layer.TopLevel = -3.17; - layer.Soil = soilPeat2; - soilProfile2.Layers.Add(layer); - layer = new SoilLayer1D(); - layer.Id = "L2"; - layer.Name = "Layer 2"; - layer.TopLevel = -5.22; - layer.Soil = soilClay2; - soilProfile2.Layers.Add(layer); - layer = new SoilLayer1D(); - layer.Id = "L3"; - layer.Name = "Layer 3"; - layer.TopLevel = -8.42; - layer.Soil = soilClay2; - soilProfile2.Layers.Add(layer); - layer = new SoilLayer1D(); - layer.Id = "L4"; - layer.Name = "Layer 4"; - layer.TopLevel = -11.16; - layer.Soil = soilPeat2; - soilProfile2.Layers.Add(layer); - layer = new SoilLayer1D(); - layer.Id = "L5"; - layer.Name = "Layer 5"; - layer.TopLevel = -17.23; - layer.Soil = soilClay2; - soilProfile2.Layers.Add(layer); - layer = new SoilLayer1D(); - layer.Id = "L6"; - layer.Name = "Layer 6"; - layer.TopLevel = -25.78; - layer.Soil = soilSand2; - soilProfile2.Layers.Add(layer); - dike.SoilProfiles.Add(soilProfile2); - - // Locations' Segment - location1.Segment = segment1; - location3.Segment = segment1; - location4.Segment = segment1; - location2.Segment = segment2; - location5.Segment = segment2; - - // Locations' surface lines - location1.SurfaceLine2 = surfaceLine1; - location2.SurfaceLine2 = surfaceLine2; - location3.SurfaceLine2 = surfaceLine2; - location4.SurfaceLine2 = surfaceLine1; - location5.SurfaceLine2 = surfaceLine2; - - // Segments' Soil profile probabilities - segment1.AddSoilProfileProbability(soilProfile1, 100.0, null); - segment2.AddSoilProfileProbability(soilProfile1, 32.4, null); - segment2.AddSoilProfileProbability(soilProfile2, 67.6, null); - - // Surface lines' points - surfaceLine1.EnsurePointOfType(15.3, -3.52, CharacteristicPointType.SurfaceLevelOutside); - surfaceLine1.EnsurePointOfType(19.4, -1.46, CharacteristicPointType.DikeToeAtRiver); - surfaceLine1.EnsurePointOfType(27.4, 8.56, CharacteristicPointType.DikeTopAtRiver); - surfaceLine1.EnsurePointOfType(35.2, 8.62, CharacteristicPointType.DikeTopAtPolder); - surfaceLine1.EnsurePointOfType(41.5, -3.76, CharacteristicPointType.DikeToeAtPolder); - surfaceLine1.EnsurePointOfType(85.4, -3.61, CharacteristicPointType.SurfaceLevelInside); - - surfaceLine2.EnsurePointOfType(0.0, -1.46, CharacteristicPointType.SurfaceLevelOutside); - surfaceLine2.EnsurePointOfType(19.4, -1.46, CharacteristicPointType.DikeToeAtRiver); - surfaceLine2.EnsurePointOfType(35.2, 8.62, CharacteristicPointType.DikeTopAtPolder); - surfaceLine2.EnsurePointOfType(41.5, -3.76, CharacteristicPointType.DikeToeAtPolder); - surfaceLine2.EnsurePoint(46.7, -3.82); - surfaceLine2.EnsurePoint(47.5, -4.78); - surfaceLine2.EnsurePoint(51.2, -4.82); - surfaceLine2.EnsurePoint(53.1, -3.78); - surfaceLine2.EnsurePointOfType(85.4, -3.61, CharacteristicPointType.SurfaceLevelInside); - - // Gauges - var gauge1 = new Gauge - { - Name = "G1", - Location = location1, - LocalX = 1.5 - }; - dike.Gauges.Add(gauge1); - var gauge2 = new Gauge - { - Name = "G2", - Location = location4, - LocalX = 3.1 - }; - dike.Gauges.Add(gauge2); - var gauge3 = new Gauge - { - Name = "G1", - Location = location3, - LocalX = 2.5 - }; - dike.Gauges.Add(gauge3); - - // Gauge PL lines - var gaugePLLine1 = new GaugePLLine(PLLineType.PL2); - gaugePLLine1.Points.Add(new GaugePLLinePoint(0.5, 3.2, null, null)); - gaugePLLine1.Points.Add(new GaugePLLinePoint(null, null, gauge1.Name, gauge1.Name)); - gaugePLLine1.Points.Add(new GaugePLLinePoint(null, null, gauge3.Name, gauge2.Name)); - dike.GaugePLLines.Add(gaugePLLine1); - - var gaugePLLine2 = new GaugePLLine(PLLineType.PL4); - gaugePLLine2.Points.Add(new GaugePLLinePoint(0.7, 2.5, null, null)); - gaugePLLine2.Points.Add(new GaugePLLinePoint(null, null, gauge1.Name, gauge1.Name)); - gaugePLLine2.Points.Add(new GaugePLLinePoint(null, null, gauge3.Name, gauge2.Name)); - dike.GaugePLLines.Add(gaugePLLine2); - - var dikeCoordinateSystemConverter = new DikeCoordinateSystemConverter(); - dikeCoordinateSystemConverter.CreateLocalXZObjects(dike); - return dike; - } - - /// - /// Creates an Segment object instance - /// - /// - /// The soil profile for which the probability will be set - /// The probability value - /// Returns the constructed segment object - /// - /// - public Segment CreateSegment(string segmentId, string soilProfileId, double probability, FailureMechanismSystemType? segmentFailureMechanismType, string soilGeometry2DName) - { - ThrowHelper.ThrowIfStringArgumentNullOrEmpty(segmentId, StringResourceNames.SegmentIdArgumentNullOrEmpty); - ThrowWhenNoSoilGeometry(soilProfileId, soilGeometry2DName); - ThrowWhenDoubleSoilGeometry(soilProfileId, soilGeometry2DName); - - // Lookup the segment to associate - Segment segment = segments.FirstOrDefault(s => s.Name == segmentId) ?? new Segment - { - Name = segmentId - }; - if (segments.Find(s => s.Name == segmentId) == null) - { - segments.Add(segment); - } - - // Create 1d-soilprofile if defined - if (soilProfileId != null) - { - SoilProfile1D soilProfile; - soilProfile = soilProfiles.FirstOrDefault(s => s.Name == soilProfileId); - if (soilProfile == null) - { - soilProfile = new SoilProfile1D - { - Name = soilProfileId - }; - soilProfiles.Add(soilProfile); - } - - // Add the probability value to the table - segment.AddSoilProfileProbability(soilProfile, probability, segmentFailureMechanismType); - } - - // Create 2d-soilprofile if defined - if (soilGeometry2DName != null) - { - // Add the probability value to the table - segment.AddSoilGeometry2DProbability(soilGeometry2DName, probability, segmentFailureMechanismType); - } - - return segment; - } - - /// - /// Check if either a 1D-geometry or a 2D-geometry is specified - /// - /// - /// - private void ThrowWhenNoSoilGeometry(string soilProfileId, string soilGeometry2DName) - { - ThrowHelper.ThrowWhenConditionIsTrue( - StringResourceNames.SoilProfileIdArgumentNullOrEmpty, - () => (String.IsNullOrEmpty(soilProfileId)) && (String.IsNullOrEmpty(soilGeometry2DName))); - } - - /// - /// Check if both a 1D-geometry or a 2D-geometry is specified (which is not allowed) - /// - /// - /// - private void ThrowWhenDoubleSoilGeometry(string soilProfileId, string soilGeometry2DName) - { - ThrowHelper.ThrowWhenConditionIsTrue( - StringResourceNames.SoilProfileIdArgumentNullOrEmpty, - () => (!String.IsNullOrEmpty(soilProfileId)) && (!String.IsNullOrEmpty(soilGeometry2DName))); - } - - /// - /// Creates a new surface line point which will be added to the characteristics point collection - /// - /// The ID of the surface line containing the point collections - /// The characteristic point type - /// The x value - /// The y value of the point - /// The added surfaceline point - /// The new point will only be added to the characteristic point collection when a match is found in the point collection of the surface line. An exception will be thrown if the point doesnt exist - /// - /// - /// - public GeometryPoint CreateSurfaceLinePoint(string surfaceLineId, CharacteristicPointType characteristicPointType, double x, double z) - { - ThrowHelper.ThrowIfStringArgumentNullOrEmpty(surfaceLineId, StringResourceNames.SurfaceLineIdArgumentNullOrEmpty); - - // it's required that the surface line with the given id exists if this is not the case an exception will be thrown - SurfaceLine2 surfaceLine = ThrowHelper.ThrowWhenRequiredEntityDoesntExistInLookup( - surfaceLines, surfaceLineId, s => s.Name == surfaceLineId); - - bool canAdd = (x != -1 || z != -1); // empty points will not be added - - GeometryPoint point = null; - - if (canAdd) - { - // Is required because old data has been created by the klikprogramma of Erik Vastenburg - if (characteristicPointType == CharacteristicPointType.TrafficLoadOutside) - { - const double cTolerance = 0.0051; - point = surfaceLine.Geometry.Points.FirstOrDefault(p => p.X.AlmostEquals(x, cTolerance) && p.Z.AlmostEquals(z, cTolerance)); - } - else - { - point = surfaceLine.Geometry.Points.FirstOrDefault(p => p.X.AlmostEquals(x) && p.Z.AlmostEquals(z)); - } - - if (point != null) - { - int index = FindUnannotatedGeometryPointForGivenLocation(surfaceLine, point); - if (index == -1) - { - surfaceLine.AddCharacteristicPoint(point, characteristicPointType); - } - else - { - surfaceLine.CharacteristicPoints.Annotate(index, characteristicPointType); - } - } - else - { - throw new PointNotExistsException( - surfaceLine.Name, - characteristicPointType, - point, - ThrowHelper.GetResourceString(StringResourceNames.SurfaceLinePointNotExtists)); - } - } - - return point; - } - - private static int FindUnannotatedGeometryPointForGivenLocation(SurfaceLine2 surfaceLine, GeometryPoint point) - { - int index = -1; - for (var i = 0; i < surfaceLine.CharacteristicPoints.Count; i++) - { - if (ReferenceEquals(surfaceLine.CharacteristicPoints[i].GeometryPoint, point) && - surfaceLine.CharacteristicPoints[i].CharacteristicPointType == CharacteristicPointType.None) - { - index = i; - break; - } - } - - return index; - } - - public Gauge CreateGauge(string gaugeId, string locationID, double localX) - { - ThrowHelper.ThrowIfStringArgumentNullOrEmpty(gaugeId, StringResourceNames.GaugeIdArgumentNullOrEmpty); - ThrowHelper.ThrowIfStringArgumentNullOrEmpty(locationID, StringResourceNames.LocationIdArgumentNullOrEmpty); - - Location location = locations.FirstOrDefault(s => s.Name == locationID); - if (location == null) - { - throw new NonExistentLocationException(locationID, ThrowHelper.GetResourceString(StringResourceNames.NonExistentLocation)); - } - - Gauge gauge = gauges.FirstOrDefault(s => s.Name == gaugeId && s.Location == location) ?? new Gauge - { - Name = gaugeId - }; - - gauge.Location = location; - gauge.LocalX = localX; - - return gauge; - } - - /// - /// Creates a scenario object - /// - /// The location id - /// The location's scenario id - /// A materialized object - /// - /// s.Location.Name == locationId && s.LocationScenarioID == locationScenarioId), - StringResourceNames.EntityAlreadyExist, - c => c != null, - e => new EntityAlreadyExistException(ThrowHelper.GetResourceString(e)) - ); - - // Lookup the location to associate - // if the item does not exist create one and add it to the lookup - Location location = locations.FirstOrDefault(s => s.Name == locationId); - if (location == null) - { - throw new NonExistentLocationException(locationId, ThrowHelper.GetResourceString(StringResourceNames.NonExistentLocation)); - } - - var scenario = new Scenario - { - Location = location, - LocationScenarioID = locationScenarioId - }; - - return scenario; - } - - #endregion } \ No newline at end of file