// Copyright (C) Stichting Deltares 2025. 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.IO; using Components.Persistence.Stability.Version2; using Components.Persistence.Stability.Version2.Data; using Deltares.Geotechnics.Soils; using DGeoSuite.Components.Persistence; namespace Deltares.Dam.StixFileReader; /// /// Read data from a stix file. /// public class StixFileReader { /// /// Reads the data from a stix file into a . /// /// The file path to read from. /// /// A . /// This only reads the names and the geometry of the soil layers. public SoilProfile2D ReadSoilProfile(string filePath, double offsetX = 0.0) { if (!File.Exists(filePath)) { throw new FileNotFoundException($"Could not find file {filePath}."); } using DGeoSuite.Components.Persistence.Reader dataModelReader = new PersistenceFactory().CreateArchiveReader(filePath); PersistableDataModel dataModel = dataModelReader.Read(); VerifyReadData(dataModel); SoilProfile2D soilProfile2D = new SoilProfile2DDataModel().Create(dataModel, offsetX); soilProfile2D.Name = Path.GetFileName(filePath); return soilProfile2D; } private static void VerifyReadData(PersistableDataModel dataModel) { if (dataModel.Info == null) { throw new DGeoSuite.Components.Persistence.StorageReadException($"Could not successfully read {typeof(PersistableDataModel)} from file."); } } }