//-----------------------------------------------------------------------
//
// Copyright (c) 2009 Deltares. All rights reserved.
//
// B. Faassen
// barry.faassen@deltares.nl
// 22-6-2009
// n.a.
//-----------------------------------------------------------------------
using Deltares.Geometry;
using Deltares.Geotechnics;
using Deltares.Geotechnics.GeotechnicalGeometry;
using Deltares.Probabilistic;
using Deltares.Standard.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using Deltares.Geotechnics.Soils;
using Deltares.Geotechnics.SurfaceLines;
using Deltares.Soilbase;
namespace Deltares.Dam.Data
{
public class EntityFactory
{
#region Private lookup tables (lists)
///
/// Holds a reference to the (concrete) Location list
///
private readonly IList locations = new List();
///
/// Holds a reference to the (concrete) Segment list
///
private readonly IList segments = new List();
///
/// Holds a reference to the (concrete) SoilProfile list
///
private readonly IList soilProfiles = new List();
///
/// Holds a reference to the (concrete) SurfaceLine list
///
private readonly IList surfaceLines = new List();
///
/// Holds a reference to the (concrete) pl1Line list
///
private readonly IList pl1Lines = new List();
private readonly IList gauges = new List();
///
/// Holds a reference to the (concrete) SurfaceLine list
///
private readonly IList scenarios = new List();
///
/// Holds a reference to the (concrete) NonWaterRetainingObject list
///
private readonly IList nonWaterRetainingObjects = new List();
#endregion
#region Constructors
public EntityFactory()
: this(null, null, null, null, null, null, null)
{
}
///
///
///
/// The surface lines look up table
public EntityFactory(IEnumerable surfaceLines)
: this(null, null, null, surfaceLines, null, null, null)
{
}
///
///
///
/// The segment look up table
/// The surface lines look up table
public EntityFactory(IEnumerable segments, IEnumerable surfaceLines)
: this(null, null, segments, surfaceLines, null, null, null)
{
}
///
///
///
/// A soil profiles
/// The location look up table
/// The segment look up table
public EntityFactory(IEnumerable locations, IEnumerable soilProfiles, IEnumerable segments)
: this(locations, soilProfiles, segments, null, null, null, null)
{
}
///
///
///
/// A soil profiles
/// The location look up table
/// The segment look up table
/// The surface lines look up table
/// The pl1Lines look up table
/// The gauges look up table
/// The surface lines look up table
public EntityFactory(IEnumerable locations, IEnumerable soilProfiles, IEnumerable segments, IEnumerable surfaceLines,
IEnumerable pl1Lines, IEnumerable gauges, IEnumerable nonWaterRetainingObjects)
{
if (soilProfiles != null)
{
this.soilProfiles = soilProfiles as IList;
if (this.soilProfiles == null)
{
this.soilProfiles = new List();
this.soilProfiles.AddRangeLeavingNullElementsOut(soilProfiles);
}
else
{
this.soilProfiles.RemoveNullElements();
}
}
if (segments != null)
{
this.segments = segments as IList;
if (this.segments == null)
{
this.segments = new List();
this.segments.AddRangeLeavingNullElementsOut(segments);
}
else
{
this.segments.RemoveNullElements();
}
}
if (locations != null)
{
this.locations = locations as IList;
if (this.locations == null)
{
this.locations = new List();
this.locations.AddRangeLeavingNullElementsOut(locations);
}
else
{
this.locations.RemoveNullElements();
}
}
if (surfaceLines != null)
{
this.surfaceLines = surfaceLines as IList;
if (this.surfaceLines == null)
{
this.surfaceLines = new List();
this.surfaceLines.AddRangeLeavingNullElementsOut(surfaceLines);
}
else
{
this.surfaceLines.RemoveNullElements();
}
}
if (pl1Lines != null)
{
this.pl1Lines = pl1Lines as IList;
if (this.pl1Lines == null)
{
this.pl1Lines = new List();
this.pl1Lines.AddRangeLeavingNullElementsOut(pl1Lines);
}
else
{
this.pl1Lines.RemoveNullElements();
}
}
if (gauges != null)
{
this.gauges = gauges as IList;
if (this.gauges == null)
{
this.gauges = new List();
this.gauges.AddRangeLeavingNullElementsOut(gauges);
}
else
{
this.gauges.RemoveNullElements();
}
}
if (scenarios != null)
{
this.scenarios = scenarios as IList;
if (this.scenarios == null)
{
this.scenarios = new List();
this.scenarios.AddRangeLeavingNullElementsOut(scenarios);
}
else
{
this.scenarios.RemoveNullElements();
}
}
if (nonWaterRetainingObjects != null)
{
this.nonWaterRetainingObjects = nonWaterRetainingObjects as IList;
if (this.nonWaterRetainingObjects == null)
{
this.nonWaterRetainingObjects = new List();
this.nonWaterRetainingObjects.AddRangeLeavingNullElementsOut(nonWaterRetainingObjects);
}
else
{
this.nonWaterRetainingObjects.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; }
}
///
/// Gets a reference to the nonWaterRetainingObjects list through the interface
///
public IEnumerable NonWaterRetainingObjects
{
get { return nonWaterRetainingObjects; }
}
#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
GeometryPoint plp1 = new GeometryPoint();
plp1.X = 1;
plp1.Y = 2;
plp1.Z = 3;
GeometryPoint plp2 = new GeometryPoint();
plp2.X = 4;
plp2.Y = 5;
plp2.Z = 6;
PL1Line pL1Line = new PL1Line();
pL1Line.Points.Add(plp1);
pL1Line.Points.Add(plp2);
dike.PL1Lines.Add(pL1Line);
// Locations
Location location1 = new Location();
location1.PenetrationLength = 1.0;
location1.TrafficLoad = 13.0;
location1.DampingFactorPL3 = 0.3;
location1.DampingFactorPL4 = 0.4;
location1.PL1Line = pL1Line;
location1.Name = "Location1";
location1.XRd = 45782;
location1.YRd = 143090;
location1.PolderLevel = 0.4;
location1.HeadPL2 = 4.0;
location1.HeadPl3 = 3.0;
location1.HeadPl4 = 2.5;
location1.GrassQuality = 3.7;
location1.Direction = 2.5;
location1.IsUseOriginalPLLineAssignments = true;
location1.DikeEmbankmentMaterial = "clay";
location1.ShoulderEmbankmentMaterial = "sand";
location1.StabilityShoulderGrowSlope = 3.1;
location1.StabilityShoulderGrowDeltaX = 3.2;
location1.StabilitySlopeAdaptionDeltaX = 3.3;
location1.PlLineOffsetBelowDikeTopAtRiver = 3.4;
location1.PlLineOffsetBelowDikeTopAtPolder = 3.5;
location1.PlLineOffsetBelowShoulderBaseInside = 3.52;
location1.PlLineOffsetBelowDikeToeAtPolder = 3.54;
location1.PlLineOffsetBelowDikeCrestMiddle = 3.55;
location1.PlLineOffsetFactorBelowShoulderCrest = 0.36;
location1.IntrusionVerticalWaterPressure = IntrusionVerticalWaterPressureType.FullHydroStatic;
location1.PenetrationLength = 3.6;
location1.TrafficLoad = 3.7;
location1.SheetPileLength = 10;
location1.SheetPilePointX = 7;
location1.SheetPilePointY = 8;
location1.SheetPilePointZ = 9;
location1.DikeMaterialType = SoilType.Peat;
location1.PolderLevelLow = 0.3;
location1.BoezemLevelTp = 1.5;
location1.BoezemLevelHbp = 1.4;
location1.BoezemLevelLbp = 1.3;
location1.DredgingDepth = -1.0;
location1.MinimalCircleDepth = 1.11;
location1.LevelReductionInside = 1.12;
location1.LevelReductionOutside = 1.13;
location1.LayerHeightDistribution = DistributionType.LogNormal;
location1.LayerHeightDeviation = 1.15;
location1.DistanceToEntryPoint = 1.16;
location1.ModelFactors.RequiredProbabilityOfFailurePiping = 0.01;
location1.ModelFactors.RequiredProbabilityOfFailureStabilityInnerslope = 0.02;
location1.ModelFactors.RequiredProbabilityOfFailureStabilityOuterslope = 0.03;
location1.ModelFactors.RequiredSafetyFactorPiping = 1.11;
location1.ModelFactors.RequiredSafetyFactorStabilityInnerSlope = 1.12;
location1.ModelFactors.RequiredSafetyFactorStabilityOuterSlope = 1.13;
location1.ModelFactors.UpliftCriterionPiping = 1.14;
location1.ModelFactors.UpliftCriterionStability = 1.15;
dike.Locations.Add(location1);
Location location2 = new Location();
location2.Name = "Location2";
dike.Locations.Add(location2);
Location location3 = new Location();
location3.Name = "Location3";
dike.Locations.Add(location3);
Location location4 = new Location();
location4.Name = "Location4";
dike.Locations.Add(location4);
Location location5 = new Location();
location5.Name = "Location5";
dike.Locations.Add(location5);
// Segments
Segment segment1 = new Segment();
segment1.Name = "Segment1";
Segment 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
Soil soilClay1 = new Soil();
soilClay1.UseDefaultProbabilisticValues = false;
soilClay1.Name = "HW-OBO";
soilClay1.SoilType = SoilType.Clay;
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.DiameterD70Stochast.DistributionType = DistributionType.Beta;
soilClay1.DiameterD70Stochast.Deviation = 1e-6;
soilClay1.PermeabKxStochast.DistributionType = DistributionType.Uniform;
soilClay1.PermeabKxStochast.Deviation = 1.0;
soilClay1.WhitesConstantStochast.DistributionType = DistributionType.Exponential;
soilClay1.WhitesConstantStochast.Deviation = 1.0;
soilClay1.BeddingAngleStochast.DistributionType = DistributionType.Weibull;
soilClay1.BeddingAngleStochast.Deviation = 0.5;
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.CohesionStochast.Deviation = 1.0;
soilClay1.FrictionAngleStochast.Deviation = 1.0;
soilClay1.PnStochast.Deviation = 0.7;
soilClay1.POPStochast.Deviation = 1.0;
soilClay1.CohesionStochast.DistributionType = DistributionType.Deterministic;
soilClay1.FrictionAngleStochast.DistributionType = DistributionType.Uniform;
soilClay1.StressTableStochast.DistributionType = DistributionType.LogNormal;
soilClay1.PnStochast.DistributionType = DistributionType.Gamma;
soilClay1.POPStochast.DistributionType = DistributionType.Frechet;
soilClay1.CorrelationCPhi = 0.5;
soilClay1.POP = 4.2;
soilClay1.CohesionStochast.DesignFactor = 2.1;
soilClay1.CohesionStochast.DesignDeviation = 0.3;
soilClay1.FrictionAngleStochast.DesignFactor = 1.3;
soilClay1.FrictionAngleStochast.DesignDeviation = 0.67;
soilClay1.StressTableStochast.DesignFactor = 4.21;
soilClay1.StressTableStochast.DesignDeviation = 3.1;
soilClay1.POPStochast.DesignFactor = 1.1;
soilClay1.POPStochast.DesignDeviation = 2.2;
soilClay1.RRatioStochast.DesignFactor = 3.3;
soilClay1.RRatioStochast.DesignDeviation = 4.4;
soilClay1.SoilGroup = 11;
soilClay1.UseSoilType = true;
soilClay1.RRatio = 5.5;
dike.SoilList.Soils.Add(soilClay1);
Soil soilPeat1 = new Soil();
soilPeat1.UseDefaultProbabilisticValues = false;
soilPeat1.Name = "HW-DUN";
soilPeat1.SoilType = SoilType.Peat;
soilPeat1.AbovePhreaticLevel = 11.00;
soilPeat1.BelowPhreaticLevel = 13.00;
dike.SoilList.Soils.Add(soilPeat1);
Soil soilSand1 = new Soil();
soilSand1.UseDefaultProbabilisticValues = false;
soilSand1.Name = "Alg-zand (0-30)";
soilSand1.SoilType = SoilType.Sand;
soilSand1.AbovePhreaticLevel = 18.50;
soilSand1.BelowPhreaticLevel = 21.75;
dike.SoilList.Soils.Add(soilSand1);
Soil soilClay2 = new Soil();
soilClay2.UseDefaultProbabilisticValues = false;
soilClay2.Name = "HW-OBO1";
soilClay2.SoilType = SoilType.Clay;
soilClay2.AbovePhreaticLevel = 14.67;
soilClay2.BelowPhreaticLevel = 16.45;
dike.SoilList.Soils.Add(soilClay2);
Soil soilPeat2 = new Soil();
soilPeat2.UseDefaultProbabilisticValues = false;
soilPeat2.Name = "HW-DUN1";
soilPeat2.AbovePhreaticLevel = 11.13;
soilPeat2.BelowPhreaticLevel = 12.64;
soilPeat2.SoilType = SoilType.Peat;
dike.SoilList.Soils.Add(soilPeat2);
Soil soilSand2 = new Soil();
soilSand2.UseDefaultProbabilisticValues = false;
soilSand2.Name = "Alg-zand (0-30)1";
soilSand2.AbovePhreaticLevel = 17.92;
soilSand2.BelowPhreaticLevel = 22.08;
soilSand2.SoilType = SoilType.Sand;
dike.SoilList.Soils.Add(soilSand2);
// Soil profiles
SoilProfile1D 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;
SoilLayer1D 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);
SoilProfile1D 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
Gauge gauge1 = new Gauge()
{
Name = "G1",
Location = location1,
LocalX = 1.5,
};
dike.Gauges.Add(gauge1);
Gauge gauge2 = new Gauge()
{
Name = "G2",
Location = location4,
LocalX = 3.1,
};
dike.Gauges.Add(gauge2);
Gauge gauge3 = new Gauge()
{
Name = "G1",
Location = location3,
LocalX = 2.5,
};
dike.Gauges.Add(gauge3);
// Gauge PL lines
GaugePLLine 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);
GaugePLLine 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);
DikeCoordinateSystemConverter 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
var 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.ToString());
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;
}
public NonWaterRetainingObject CreateNonWaterRetainingObject(string NwoId, string category, string type, string phreaticAdaption, double h1, double h2, double n1,
double n2, double b, double stepSizeX, double maxDistanceFromToe)
{
ThrowHelper.ThrowIfStringArgumentNullOrEmpty(category, StringResourceNames.NonWaterRetainingObjectCategoryArgumentNullOrEmpty);
ThrowHelper.ThrowIfStringArgumentNullOrEmpty(type, StringResourceNames.NonWaterRetainingObjectTypeArgumentNullOrEmpty);
var nonWaterRetainingObject = new NonWaterRetainingObject();
nonWaterRetainingObject.NwoId = NwoId;
nonWaterRetainingObject.Category = NonWaterRetainingObjectCategory.Tree;
if (category.Equals("Main",StringComparison.OrdinalIgnoreCase))
{
nonWaterRetainingObject.Category = NonWaterRetainingObjectCategory.Main;
}
if (nonWaterRetainingObject.Category == NonWaterRetainingObjectCategory.Tree)
{
nonWaterRetainingObject.Type = NonWaterRetainingObjectType.Oak;
if (type.Equals("Alder", StringComparison.OrdinalIgnoreCase))
{
nonWaterRetainingObject.Type = NonWaterRetainingObjectType.Alder;
}
if (type.Equals("Poplar", StringComparison.OrdinalIgnoreCase))
{
nonWaterRetainingObject.Type = NonWaterRetainingObjectType.Poplar;
}
}
else
{
nonWaterRetainingObject.Type = NonWaterRetainingObjectType.WaterMain;
if (type.Equals("GasMain", StringComparison.OrdinalIgnoreCase))
{
nonWaterRetainingObject.Type = NonWaterRetainingObjectType.GasMain;
}
}
nonWaterRetainingObject.PhreaticAdaption = PhreaticAdaptionType.None;
if (phreaticAdaption.Equals("MakeEmpty", StringComparison.OrdinalIgnoreCase))
{
nonWaterRetainingObject.PhreaticAdaption = PhreaticAdaptionType.MakeEmpty;
}
nonWaterRetainingObject.H1 = h1;
nonWaterRetainingObject.H2 = h2;
nonWaterRetainingObject.N1 = n1;
nonWaterRetainingObject.N2 = n2;
nonWaterRetainingObject.B = b;
nonWaterRetainingObject.StepSizeX = stepSizeX;
nonWaterRetainingObject.MaxDistanceFromToe = maxDistanceFromToe;
return nonWaterRetainingObject;
}
///
/// 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 location object
///
/// The location id
/// The segment id
/// The surface line id
/// The rd x coordinate
/// The rd y coordinate
/// The polder level
/// A materialized object
///
/// l.Name == locationId),
StringResourceNames.EntityAlreadyExist,
c => c != null,
e => new EntityAlreadyExistException(string.Format("Location '{0}' {1}", locationId, ThrowHelper.GetResourceString(e)))
);
// Lookup the segment to associate
// if the item does not exists create one and add it to the lookup
var segment = segments.FirstOrDefault(s => s.Name == segmentId.ToString());
if (segment == null)
{
segment = new Segment() { Name = segmentId };
segments.Add(segment);
}
// Lookup the surface line to associate
// if the item does not exists create one and add it to the lookup
var surfaceLine = surfaceLines.FirstOrDefault(s => s.Name == surfaceLineId);
if (surfaceLine == null)
{
surfaceLine = new SurfaceLine2
{
Name = surfaceLineId,
CharacteristicPoints = { GeometryMustContainPoint = true },
Geometry = new LocalizedGeometryPointString()
};
surfaceLines.Add(surfaceLine);
}
// Lookup the pl1 line to associate
// if the item does not exists create one and add it to the lookup
var pl1Line = pl1Lines.FirstOrDefault(s => s.Name == pl1Id);
if (pl1Line == null)
{
pl1Line = new PL1Line() { Name = pl1Id };
pl1Lines.Add(pl1Line);
}
var location = new Location()
{
Name = locationId,
Segment = segment,
SurfaceLine2 = surfaceLine,
PL1Line = pl1Line,
};
return location;
}
///
/// 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
var surfaceLine = ThrowHelper.ThrowWhenRequiredEntityDoesntExistInLookup(
surfaceLines, surfaceLineId, s => s.Name == surfaceLineId);
var 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)
{
var 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 (int 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 = this.locations.FirstOrDefault(s => s.Name == locationID);
if (location == null)
{
throw new NonExistentLocationException(locationID, ThrowHelper.GetResourceString(StringResourceNames.NonExistentLocation));
}
Gauge gauge = this.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 = this.locations.FirstOrDefault(s => s.Name == locationId);
if (location == null)
{
throw new NonExistentLocationException(locationId, ThrowHelper.GetResourceString(StringResourceNames.NonExistentLocation));
}
Scenario scenario = new Scenario()
{
Location = location,
LocationScenarioID = locationScenarioId
};
return scenario;
}
#endregion
}
}