// Copyright (C) Stichting Deltares 2024. 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.Collections.Generic; using System.Linq; using System.Xml.Linq; using Deltares.DamEngine.Calculators.General; using Deltares.DamEngine.Data.Geotechnics; namespace Deltares.DamEngine.Calculators.KernelWrappers.Assemblers; /// /// /// public class Geometry2DSectionAssembler : DtoDocumentAssembler { /// /// Holds the Geometry2DSectionParameters xml element and attribute names /// public const string XmlElementGeometry2DSectionInput = "Geometry2DSectionInput"; public const string XmlAttributeSoilGeometry2DFilename = "SoilGeometry2DFilename"; public const string XmlAttributeXCoordinateSection = "XCoordinateSection"; /// /// /// public Geometry2DSectionAssembler() : base(XMLAttributes.XmlElementName, XMLAttributes.XmlElementNamespace, XMLAttributes.XsdEmbeddedResourcePath) {} public override Geometry2DSectionParameters CreateOutputObject(XDocument dtoObject) { var geometry2DSectionParameters = new Geometry2DSectionParameters(); // Get the dto XElement dto = (from x in dtoObject.Descendants() where x.Name.LocalName == XmlElementGeometry2DSectionInput select x).FirstOrDefault(); if (dto != null) { geometry2DSectionParameters.SoilGeometry2DName = dto.AttributeAs(XmlAttributeSoilGeometry2DFilename); geometry2DSectionParameters.XCoordinateSection = dto.AttributeAs(XmlAttributeXCoordinateSection); } // Get the dto XElement profileDto = (from x in dtoObject.Descendants() where x.Name.LocalName == XMLAttributes.XmlElementProfile select x).FirstOrDefault(); if (profileDto != null) { var soilProfile = new SoilProfile1D { Name = profileDto.AttributeAs(XMLAttributes.XmlAttributeName), BottomLevel = profileDto.AttributeAs(XMLAttributes.XmlAttributeBottomLevel) }; // Layers XElement layerCollectionElement = (from element in profileDto.Descendants() where element.Name.LocalName == XMLAttributes.XmlElementLayers select element).Single(); IEnumerable layerElementCollection = from element in layerCollectionElement.Descendants() where element.Name.LocalName == XMLAttributes.XmlElementLayer select element; foreach (XElement layerElement in layerElementCollection) { var soilLayer = new SoilLayer1D { Name = layerElement.AttributeAs("ID"), SoilName = layerElement.AttributeAs(XMLAttributes.XmlAttributeSoilID), TopLevel = layerElement.AttributeAs(XMLAttributes.XmlAttributeTopLevel) }; soilProfile.Layers.Add(soilLayer); } geometry2DSectionParameters.SoilProfile = soilProfile; } return geometry2DSectionParameters; } }