// Copyright (C) Stichting Deltares 2018. 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.Runtime.InteropServices; using System.Text; namespace Deltares.DamEngine.Calculators.Interfaces { public 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)); } } }