Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvImporters/CsvImporterAquifers.cs
===================================================================
diff -u
--- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvImporters/CsvImporterAquifers.cs (revision 0)
+++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvImporters/CsvImporterAquifers.cs (revision 4926)
@@ -0,0 +1,121 @@
+// Copyright (C) Stichting Deltares 2024. All rights reserved.
+//
+// This file is part of the application DAM - UI.
+//
+// DAM - UI is free software: you can redistribute it and/or modify
+// it under the terms of the GNU 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 General Public License for more details.
+//
+// You should have received a copy of the GNU 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 System.Globalization;
+using System.IO;
+using System.Threading;
+using Deltares.Dam.Data.Importers;
+using Deltares.Standard.IO;
+using Deltares.Standard.Language;
+using LumenWorks.Framework.IO.Csv;
+
+namespace Deltares.Dam.Data.CsvImporters;
+
+public class CsvImporterAquifersException : ApplicationException
+{
+ public CsvImporterAquifersException(string message)
+ : base(message) {}
+}
+
+public class CsvImporterAquifers
+{
+ public CsvImporterAquifers(string fileName)
+ {
+ ErrorMessages.Clear();
+ ThrowHelper.ThrowIfStringArgumentNullOrEmpty(fileName, StringResourceNames.CsvFileNotValid);
+ ThrowHelper.ThrowIfFileNotExist(fileName, StringResourceNames.CsvFileNotFound);
+
+ CultureInfo oldCultureInfo = Thread.CurrentThread.CurrentCulture;
+ try
+ {
+ Thread.CurrentThread.CurrentCulture = CsvReaderUtilities.DetermineCultureForFile(fileName);
+ using (var csv = new CsvReader(new StreamReader(fileName), true, ';'))
+ {
+ string[] headers = CsvImporterHelper.GetFieldHeaders(this, csv);
+ if (headers.Length != 2)
+ {
+ string csvHeaderError = LocalizationManager.GetTranslatedText(GetType(), "csvHeaderError");
+ throw new CsvImporterAquifersException($"{fileName} : {csvHeaderError}");
+ }
+
+ const string fieldStixFilename = "stix_filename";
+ int colIndexStixFilename = CsvReaderUtilities.GetHeaderIndexByString(headers, fieldStixFilename);
+ CheckColumn(colIndexStixFilename, fileName, fieldStixFilename);
+
+ const string fieldLayerName = "layer_name";
+ int colIndexLayerName = CsvReaderUtilities.GetHeaderIndexByString(headers, fieldLayerName);
+ CheckColumn(colIndexLayerName, fileName, fieldLayerName);
+
+ var index = 1;
+ while (csv.ReadNextRecord())
+ {
+ var aquiferRecord = new AquiferRecord();
+ int colIndex = -1; // Keep track of column for error message
+ try
+ {
+ aquiferRecord.AquiferRecordId = index;
+ index++;
+
+ // Required columns
+ colIndex = colIndexStixFilename;
+ aquiferRecord.StixFileName = csv[colIndexStixFilename];
+ colIndex = colIndexLayerName;
+ aquiferRecord.LayerName = csv[colIndexLayerName];
+
+ ImportedItems.Add(aquiferRecord);
+ }
+ catch (Exception e)
+ {
+ string csvAquiferError = string.Format(LocalizationManager.GetTranslatedText(GetType(), "csvAquiferError"),
+ aquiferRecord.StixFileName, colIndex + 1);
+ ErrorMessages.Add($"Record {index} : {csvAquiferError + e.Message}");
+ }
+ }
+ }
+ }
+ finally
+ {
+ Thread.CurrentThread.CurrentCulture = oldCultureInfo;
+ }
+ }
+
+ public List ImportedItems { get; } = new();
+
+ public List ErrorMessages { get; set; } = new();
+
+ private void CheckColumn(int index, string fileName, string fieldName)
+ {
+ if (index < 0)
+ {
+ string csvHeaderFieldError = LocalizationManager.GetTranslatedText(GetType(), "csvHeaderFieldError");
+ throw new CsvImporterAquifersException($"{fileName} : {csvHeaderFieldError}{fieldName}");
+ }
+ }
+
+ public class AquiferRecord
+ {
+ public int AquiferRecordId { get; set; }
+ public string StixFileName { get; set; }
+ public string LayerName { get; set; }
+ }
+}
\ No newline at end of file
Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvImporters/CsvImporter.cs
===================================================================
diff -u -r4795 -r4926
--- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvImporters/CsvImporter.cs (.../CsvImporter.cs) (revision 4795)
+++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/CsvImporters/CsvImporter.cs (.../CsvImporter.cs) (revision 4926)
@@ -35,6 +35,7 @@
private const string locationsFileNamePart = "locations";
private const string segmentsFileNamePart = "segments";
private const string soilProfilesFileNamePart = "soilprofiles";
+ private const string aquifersFileNamePart = "aquifers";
private const string surfaceLinesFileNamePart = "surfacelines";
private const string characteristicPointFileNamePart = "characteristicpoints";
private const string scenariosFileNamePart = "scenarios";
@@ -51,6 +52,8 @@
public List CharacteristicPointsRecords { get; private set; } = new();
public List SoilProfilesRecords { get; private set; } = new();
+
+ public List AquifersRecords { get; private set; } = new();
public List SurfaceLinesRecords { get; private set; } = new();
@@ -88,6 +91,9 @@
ImportSoilProfiles(SoilProfilesFileName);
progress?.Invoke(0.2);
+ ImportAquifers(AquifersFileName);
+ progress?.Invoke(0.2);
+
ImportSurfaceLines(SurfaceLinesFileName);
// Scenario file is required for design projects and optional for the rest
if (damProjectType == DamProjectType.Design)
@@ -134,6 +140,8 @@
private string SegmentsFileName => string.Format(filePattern, ImportFolderLocation, segmentsFileNamePart);
private string SoilProfilesFileName => string.Format(filePattern, ImportFolderLocation, soilProfilesFileNamePart);
+
+ private string AquifersFileName => string.Format(filePattern, ImportFolderLocation, aquifersFileNamePart);
private string SurfaceLinesFileName => string.Format(filePattern, ImportFolderLocation, surfaceLinesFileNamePart);
@@ -246,6 +254,33 @@
}
///
+ /// Imports the aquifers.
+ ///
+ /// Name of the file.
+ private void ImportAquifers(string fileName)
+ {
+ // Only necessary for 2D-geometries
+ if (File.Exists(fileName))
+ {
+ try
+ {
+ var csvImportAquifers = new CsvImporterAquifers(fileName);
+ AquifersRecords = csvImportAquifers.ImportedItems;
+ foreach (string errorMessage in csvImportAquifers.ErrorMessages)
+ {
+ var logMessage = new LogMessage(LogMessageType.Error, this, errorMessage);
+ ErrorMessages.Add(logMessage);
+ }
+ }
+ catch (Exception e)
+ {
+ var logMessage = new LogMessage(LogMessageType.FatalError, this, e.Message);
+ ErrorMessages.Add(logMessage);
+ }
+ }
+ }
+
+ ///
/// Imports the surface lines.
///
/// Name of the file.
Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DataPlugins/DataPluginImporter.cs
===================================================================
diff -u -r4813 -r4926
--- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DataPlugins/DataPluginImporter.cs (.../DataPluginImporter.cs) (revision 4813)
+++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DataPlugins/DataPluginImporter.cs (.../DataPluginImporter.cs) (revision 4926)
@@ -1204,6 +1204,7 @@
ScenarioRecords = csvImporter.ScenariosRecords,
SegmentRecords = csvImporter.SegmentRecords,
SoilProfilerecords = csvImporter.SoilProfilesRecords,
+ AquiferRecords = csvImporter.AquifersRecords,
SurfaceLineRecords = csvImporter.SurfaceLinesRecords,
SoilRecords = csvImporter.SoilsRecords,
SigmaTauCurveRecords = csvImporter.SigmaTauCurvesRecords
Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/IO/CombineImportedData.cs
===================================================================
diff -u -r4569 -r4926
--- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/IO/CombineImportedData.cs (.../CombineImportedData.cs) (revision 4569)
+++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/IO/CombineImportedData.cs (.../CombineImportedData.cs) (revision 4926)
@@ -69,6 +69,11 @@
public IEnumerable SoilProfilerecords { get; set; }
///
+ /// The Aquifer records.
+ ///
+ public IEnumerable AquiferRecords { get; set; }
+
+ ///
/// The SurfaceLine records.
///
public IEnumerable SurfaceLineRecords { get; set; }
@@ -115,6 +120,7 @@
{
TransferLocationsData(dike);
TransferSoilProfilesData(dike);
+ TransferAquifersData(dike);
TransferSegmentData(dike);
TransferSigmaTauCurveData(dike); // Should be done before TransferSoilData(), because the SigmaTauCurveData is used there
TransferSoilData(dike);
@@ -565,6 +571,11 @@
}
}
+ private void TransferAquifersData(Dike dike)
+ {
+ // ToDo: Aquifers
+ }
+
private void TransferSurfaceLines(Dike dike)
{
if (SurfaceLineRecords == null)
Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/Translations.xml
===================================================================
diff -u -r4771 -r4926
--- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/Translations.xml (.../Translations.xml) (revision 4771)
+++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/Translations.xml (.../Translations.xml) (revision 4926)
@@ -363,6 +363,9 @@
+
aquiferRecords = csvImporterAquifers.ImportedItems;
+
+ Assert.That(aquiferRecords, Has.Count.EqualTo(5));
+ CsvImporterAquifers.AquiferRecord aquiferRecord = aquiferRecords[0];
+ Assert.That(aquiferRecord.StixFileName, Is.EqualTo("DWP_1.stix"));
+ Assert.That(aquiferRecord.LayerName, Is.EqualTo("L1"));
+ aquiferRecord = aquiferRecords[1];
+ Assert.That(aquiferRecord.StixFileName, Is.EqualTo("DWP_1.stix"));
+ Assert.That(aquiferRecord.LayerName, Is.EqualTo("L5"));
+ aquiferRecord = aquiferRecords[2];
+ Assert.That(aquiferRecord.StixFileName, Is.EqualTo("DWP_2.stix"));
+ Assert.That(aquiferRecord.LayerName, Is.EqualTo("L1"));
+ aquiferRecord = aquiferRecords[3];
+ Assert.That(aquiferRecord.StixFileName, Is.EqualTo("DWP_2.stix"));
+ Assert.That(aquiferRecord.LayerName, Is.EqualTo("L1"));
+ aquiferRecord = aquiferRecords[4];
+ Assert.That(aquiferRecord.StixFileName, Is.EqualTo("DWP_3.stix"));
+ Assert.That(aquiferRecord.LayerName, Is.EqualTo("L2"));
+ }
+
+ [Test]
+ public void AquifersImporterIllegalHeaderTest()
+ {
+ const string importFile = "aquifers.csv";
+ string testFilePath = Path.Combine(importFolder, importFile);
+ if (File.Exists(testFilePath))
+ {
+ File.Delete(testFilePath);
+ }
+
+ CreateAquifersFileWithIllegalHeader(testFilePath);
+ var ex = Assert.Throws(() => new CsvImporterAquifers(testFilePath));
+ Assert.That(ex.Message, Does.Contain("The header of the csv file is wrong."));
+ }
+
+ [Test]
+ public void AquifersImporterMissingHeaderFieldTest()
+ {
+ const string importFile = "aquifers.csv";
+ string testFilePath = Path.Combine(importFolder, importFile);
+ if (File.Exists(testFilePath))
+ {
+ File.Delete(testFilePath);
+ }
+
+ CreateAquifersFileWithIllegalHeaderField(testFilePath);
+ var ex = Assert.Throws(() => new CsvImporterAquifers(testFilePath));
+ Assert.That(ex.Message, Does.Contain("The header misses the field: layer_name"));
+ }
+
+ [Test]
public void CharacteristicPointsImporterCorrectFileTest()
{
const string importFile = "characteristicpoints.csv";
@@ -961,6 +1023,31 @@
writer.WriteLine("1DP2;-5.3;Alg-zand (0-30);True");
}
+ private static void CreateAquifersFile(string filePath)
+ {
+ using StreamWriter writer = File.CreateText(filePath);
+ writer.WriteLine("stix_filename;layer_name");
+ writer.WriteLine("DWP_1.stix;L1");
+ writer.WriteLine("DWP_1.stix;L5");
+ writer.WriteLine("DWP_2.stix;L1");
+ writer.WriteLine("DWP_2.stix;L1");
+ writer.WriteLine("DWP_3.stix;L2");
+ }
+
+ private static void CreateAquifersFileWithIllegalHeader(string filePath)
+ {
+ using StreamWriter writer = File.CreateText(filePath);
+ writer.WriteLine("stix_filename;layer_name;aaa");
+ writer.WriteLine("DWP_1.stix;L1");
+ }
+
+
+ private static void CreateAquifersFileWithIllegalHeaderField(string filePath)
+ {
+ using StreamWriter writer = File.CreateText(filePath);
+ writer.WriteLine("stix_filename;aquifer_name");
+ writer.WriteLine("DWP_1.stix;L1");
+ }
private static void CreateFullSoilsFile(string filePath)
{
using StreamWriter writer = File.CreateText(filePath);
Index: DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/IO/CombineImportedDataTest.cs
===================================================================
diff -u -r4638 -r4926
--- DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/IO/CombineImportedDataTest.cs (.../CombineImportedDataTest.cs) (revision 4638)
+++ DamClients/DamUI/trunk/src/Dam/Deltares.Dam.Tests/IO/CombineImportedDataTest.cs (.../CombineImportedDataTest.cs) (revision 4926)
@@ -103,6 +103,7 @@
SurfaceLineRecords = csvImporter.SurfaceLinesRecords,
SegmentRecords = csvImporter.SegmentRecords,
SoilProfilerecords = csvImporter.SoilProfilesRecords,
+ AquiferRecords = csvImporter.AquifersRecords,
ScenarioRecords = csvImporter.ScenariosRecords,
LocationRecords = csvImporter.LocationRecords
};
@@ -189,6 +190,7 @@
SurfaceLineRecords = csvImporter.SurfaceLinesRecords,
SegmentRecords = csvImporter.SegmentRecords,
SoilProfilerecords = csvImporter.SoilProfilesRecords,
+ AquiferRecords = csvImporter.AquifersRecords,
ScenarioRecords = csvImporter.ScenariosRecords,
SoilRecords = csvImporter.SoilsRecords,
SigmaTauCurveRecords = csvImporter.SigmaTauCurvesRecords