//-----------------------------------------------------------------------
//
// Copyright (c) 2009 Deltares. All rights reserved.
//
// B.S.T.I.M. The
// tom.the@deltares.nl
// 03-12-2009
// Constructs a new surface line with an adjusted slope
//-----------------------------------------------------------------------
using System.Linq;
using Deltares.Geotechnics;
using Deltares.Geotechnics.SurfaceLines;
using Deltares.Standard;
using Deltares.Standard.Language;
using Deltares.Standard.Validation;
namespace Deltares.Dam.Data
{
public class SurfaceLineSlopeAdapter : SurfaceLineAdapter
{
public SurfaceLineSlopeAdapter(SurfaceLine2 surfaceLine, Location location)
: base(surfaceLine, location)
{
}
///
/// Constructs a new surface line with an adjusted slope
/// Adapt slope by moving the toe of the dike horizontally with deltaXAtToeOfSlope
///
///
///
/// The offset to shift to the right
/// The adapted surface line
public SurfaceLine2 ConstructNewSurfaceLine(double deltaXAtToeOfSlope)
{
ThrowHelper.ThrowWhenConditionIsTrue("deltaXAtToeOfSlope should be >= 0.0", () => deltaXAtToeOfSlope < 0.0);
var dikeTopAtPolder = surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeTopAtPolder);
var dikeToeAtPolder = surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeToeAtPolder);
var dikeBaseInside = surfaceLine.HasShoulderInside() ? surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.ShoulderBaseInside) : dikeToeAtPolder;
var slopeTangent = (dikeTopAtPolder.Z - dikeBaseInside.Z) /
(dikeBaseInside.X + deltaXAtToeOfSlope - dikeTopAtPolder.X);
ConstructNewSurfaceLineBySlope(slopeTangent);
return surfaceLine;
}
///
/// Constructs a new surface line with an adjusted slope
/// Adapt slope by changing the slope to the specified slopeTangent
/// The top of the dike will remain in place and the te of the dike will be moved
///
///
///
public SurfaceLine2 ConstructNewSurfaceLineBySlope(double slopeTangent)
{
ThrowHelper.ThrowWhenConditionIsTrue("Slopetangent should be >= 0.0", () => slopeTangent < 0.0);
// the given surface line must be valid to begin with.
var validationError = surfaceLine.Validate().FirstOrDefault(vr => vr.MessageType == ValidationResultType.Error);
if (validationError != null)
{
throw new SurfaceLineException(validationError.Text);
}
var orgMaxX = surfaceLine.Geometry.GetMaxX();
if (double.IsNaN(orgMaxX))
{
orgMaxX = double.MaxValue;
}
var dikeTopAtPolder = surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeTopAtPolder);
var dikeToeAtPolder = surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.DikeToeAtPolder);
var dikeBaseInside = surfaceLine.HasShoulderInside() ? surfaceLine.CharacteristicPoints.GetGeometryPoint(CharacteristicPointType.ShoulderBaseInside) : dikeToeAtPolder;
// Remove points on inside slope
surfaceLine.RemoveSegmentBetween(dikeTopAtPolder.X, dikeBaseInside.X);
// Store the ditch (if any)
var ditchDefinition = GetDitchDefinition();
// Delete the ditch from the surfaceline (if any)
RemoveExistingDitch(ditchDefinition);
// Adjust for the new slope
ReplaceBaseInsideForNewSlope(dikeTopAtPolder, slopeTangent);
// Restore Ditch (if any)
RestoreDitch(ditchDefinition);
// Check whether the surface line is extended. This is not allowed!
if (surfaceLine.Geometry.GetMaxX() > orgMaxX)
{
throw new SurfaceLineAdapterException(LocalizationManager.GetTranslatedText(this,
"SurfaceLineShoulderAdapterNewShoulderHeightTooLargeError"));
}
// Restore traffic load
RestoreTrafficLoad();
surfaceLine.SortPoints();
return surfaceLine;
}
}
}