using System.Runtime.InteropServices;
using System.Text;
using Deltares.Geotechnics.IO.Importers;
using DotSpatial.Topology;
namespace Deltares.Dam.Data
{
class DGSMStabDAMInterface : DgsStandardDllInterface
{
public struct LegacyCoordinate
{
public double x;
public double z;
}
private const string DllFileName = @"DGSMStabDAM.dll";
[DllImport(DllFileName)]
static extern int GetDamLicenseType();
[DllImport(DllFileName)]
static extern int GetDamLiveLicenseType();
[DllImport(DllFileName)]
static extern int DllGetVersion(out DllVersionInfoStructure dllVersionInfoStructure);
[DllImport(DllFileName)]
static extern string GetDescription(StringBuilder errorMessage, ref int bufferSize);
[DllImport(DllFileName)]
static extern int GetErrorMessage(StringBuilder errorMessage, ref int bufferSize);
[DllImport(DllFileName)]
static extern int CreateMStabProject(string inputXmlString);
[DllImport(DllFileName)]
static extern int ConvertGeometry2DTo1D(string inputXML, StringBuilder outputXML, ref int bufferSize);
[DllImport(DllFileName)]
static extern int CreateGeometry2DData(string inputXML, StringBuilder outputXML, ref int bufferSize);
[DllImport(DllFileName)]
static extern double CalculatePipingLength(int pointCount, ref LegacyCoordinate[] headLinePoints);
///
/// Gets the type of the license for DAM.
///
///
public int DamLicenseType()
{
return (GetDamLicenseType());
}
///
/// Gets the type of the license for DAMLive.
///
///
public int DamLiveLicenseType()
{
return (GetDamLiveLicenseType());
}
///
/// Gets DllVersion
///
/// version as string
new public string GetDllVersion()
{
DllVersionInfoStructure dllInfo;
var returnValue = DllGetVersion(out dllInfo);
return dllInfo.DwBuildNumber.ToString();
}
///
/// Create ProjectFile for MStab
///
/// Error number
public int CreateProjectFile(string inputXmlString)
{
return (CreateMStabProject(inputXmlString));
}
///
/// returns ErrorMessage
///
/// Error as string
new public string ErrorMessage()
{
const int maxErrorMessageLength = 50;
int errorMessageLength = maxErrorMessageLength;
var errorMessage = new StringBuilder(maxErrorMessageLength);
int returnCode = GetErrorMessage(errorMessage, ref errorMessageLength);
if (returnCode == DllErrorOutputBufferTooSmall)
{
errorMessage = new StringBuilder(errorMessageLength);
returnCode = GetErrorMessage(errorMessage, ref errorMessageLength);
}
if (returnCode == DllErrorNone)
{
return errorMessage.ToString();
}
else
{
return "Unknow error";
}
}
///
/// converts 2D geometry to 1D
///
/// Error as integer
public int Geometry2DTo1DConversion(string inputXML, StringBuilder outputXML, ref int bufferSize)
{
return (ConvertGeometry2DTo1D(inputXML, outputXML, ref bufferSize));
}
public int CreateGeometry2DDataFromGeometry2D(string inputXML, StringBuilder outputXML, ref int bufferSize)
{
return (CreateGeometry2DData(inputXML, outputXML, ref bufferSize));
}
///
/// calculates the pipinglength
///
/// pipinglength as double
public double PipingLengthCalculation(int pointCount, ref LegacyCoordinate[] headLinePoints)
{
return (CalculatePipingLength(pointCount, ref headLinePoints));
}
}
}