// Copyright (C) Stichting Deltares 2017. 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;
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.DamMacroStability.Assemblers
{
///
///
///
public class DAMMStabGeometry2DDataAssembler : DtoDocumentAssembler
{
#region Constant declarations
#endregion
///
/// Holds the xml element name
///
public const string XmlElementNameGeometry2DData = "Geometry2DData";
///
/// Holds the Geometry2DData xml element and attribute names
///
public const string XmlElementGeometry2DData = "Geometry2DData";
///
/// The XML element boundary
///
public const string XmlElementBoundary = "Boundary";
///
/// The XML attribute boundary index
///
public const string XmlAttributeBoundaryIndex = "BoundaryIndex";
///
/// The XML attribute soilname
///
public const string XmlAttributeSoilname = "Soilname";
///
/// The XML element surface point
///
public const string XmlElementSurfacePoint = "SurfacePoint";
///
/// The XML attribute x coord
///
public const string XmlAttributeXCoord = "XCoord";
///
/// The XML attribute y coord
///
public const string XmlAttributeYCoord = "YCoord";
///
/// Initializes a new instance of the class.
///
public DAMMStabGeometry2DDataAssembler() :
base(DamMStabAssembler.XmlElementName, DamMStabAssembler.XmlElementNamespace, DamMStabAssembler.XsdEmbeddedResourcePath)
{
}
///
/// Creates the data transfer object.
///
/// The geometry2 d data.
///
public override XDocument CreateDataTransferObject(Geometry2DData geometry2DData)
{
var doc = base.CreateDataTransferObject(geometry2DData);
XNamespace tns = ElementNamespace;
XNamespace tnsb = XmlElementNameGeometry2DData;
// Geometry2DData
XElement geometry2DDataElement = GetGeometry2DDataElement(geometry2DData, tns);
doc.Root.Add(geometry2DDataElement);
return doc;
}
///
/// Assembles the GeometryCreationOptions element
///
///
///
///
private static XElement GetGeometry2DDataElement(Geometry2DData geometry2DData, XNamespace tnsb)
{
return null;
}
///
/// Creates the output object.
///
/// The dto document.
///
public override Geometry2DData CreateOutputObject(XDocument dtoDocument)
{
var geometry2DData = new Geometry2DData();
// Get the dto
XElement dto = (from x in dtoDocument.Descendants()
where x.Name.LocalName == DAMMStabGeometry2DDataAssembler.XmlElementGeometry2DData
select x).FirstOrDefault();
IEnumerable layerCollection = (from x in dtoDocument.Descendants()
where x.Name.LocalName == DAMMStabGeometry2DDataAssembler.XmlElementBoundary
select x);
foreach (XElement layerElement in layerCollection)
{
var geometry2DLayer = new Geometry2DLayer();
if (layerElement.Attribute(DAMMStabGeometry2DDataAssembler.XmlAttributeSoilname) != null)
{
geometry2DLayer.soilName = layerElement.AttributeAs(DAMMStabGeometry2DDataAssembler.XmlAttributeSoilname);
}
else
{
geometry2DLayer.soilName = "";
}
IEnumerable surfacePointCollection = (from x in layerElement.Descendants()
where x.Name.LocalName == DAMMStabGeometry2DDataAssembler.XmlElementSurfacePoint
select x);
var boundaryLine = new Geometry2DBoundaryLine();
foreach (XElement surfacePointElement in surfacePointCollection)
{
var point = new Geometry2DPoint();
point.X = surfacePointElement.AttributeAs(DAMMStabGeometry2DDataAssembler.XmlAttributeXCoord);
point.Z = surfacePointElement.AttributeAs(DAMMStabGeometry2DDataAssembler.XmlAttributeYCoord);
boundaryLine.Points.Add(point);
}
geometry2DLayer.boundaryLine = boundaryLine;
geometry2DData.AddLayer(geometry2DLayer);
}
return geometry2DData;
}
}
}