// Copyright (C) Stichting Deltares 2019. 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 Deltares.DamEngine.Data.General.Sensors;
using Deltares.DamEngine.Data.General;
using Deltares.DamEngine.Data.General.Sensors.Specifications;
namespace Deltares.DamEngine.Calculators.PlLinesCreator
{
internal class SensorPlLine3Creator : SensorPlLine3Or4CreatorBase
{
///
/// Initializes a new instance of the class.
///
/// The sensor location.
/// The sensor values.
public SensorPlLine3Creator(SensorLocation sensorLocation, IDictionary sensorValues)
: base(sensorLocation, sensorValues, PlLineType.Pl3)
{
}
///
/// Gets the start z level of the PL line
///
///
/// The start level is based on the Pl3 configuration (location data or sensor)
/// and the position of the first sensor
///
///
protected override double GetStartLevel()
{
double currentLevel;
bool useLocationAsDataSource = new UseLocationAsDataSource().IsSatisfiedBy(SensorLocation.SourceTypePl3);
if (useLocationAsDataSource)
{
if (!SensorLocation.HeadPl3.HasValue)
throw new PlLinesCreatorException("Pl3 head has no value defined on this location");
currentLevel = SensorLocation.HeadPl3.Value;
}
else
{
try
{
currentLevel = WaterLevelAtRiver;
}
catch (Exception e)
{
throw new PlLinesCreatorException("There was an error trying to read the water level", e);
}
}
return currentLevel;
}
}
}