// 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.Collections.Generic; using Deltares.DamEngine.Io.XmlOutput; using Deltares.Standard.Logging; namespace Deltares.Dam.Data.DamEngineIo; /// /// /// public class FillXmlOutputFromDamUi { /// /// Class to fill the output xml based on the results in DamProjectData /// public static Output CreateOutput(DamProjectData damProjectData) { var output = new Output(); output.Results = new OutputResults(); output.Results.CalculationMessages = new Message[damProjectData.CalculationMessages.Count]; TransferOutputCalculationMessages(damProjectData.CalculationMessages, output.Results); if (damProjectData.OutputTimeSerieCollection != null) { output.Results.OperationalOutputTimeSeries = new DamEngine.Io.XmlOutput.TimeSerieOutput[damProjectData.OutputTimeSerieCollection.Series.Count]; TransferOutputTimeSeries(damProjectData.OutputTimeSerieCollection, output.Results.OperationalOutputTimeSeries); } if (damProjectData.DesignCalculations != null && damProjectData.DesignCalculations.Count > 0) { output.Results.CalculationResults = new DesignResult[damProjectData.DesignCalculations.Count]; for (var i = 0; i < damProjectData.DesignCalculations.Count; i++) { var designResult = new DesignResult(); designResult.CalculationSubDir = damProjectData.DesignCalculations[i].CalculationSubDir; designResult.LocationName = damProjectData.DesignCalculations[i].LocationName; designResult.BaseFileName = damProjectData.DesignCalculations[i].BaseFileName; designResult.ScenarioName = damProjectData.DesignCalculations[i].ScenarioName; designResult.StabilityDesignResults = new DesignResultStabilityDesignResults(); output.Results.CalculationResults[i] = designResult; } } return output; } private static void TransferOutputTimeSeries(TimeSerieCollection outputTimeSerieCollection, DamEngine.Io.XmlOutput.TimeSerieOutput[] outputTimeSeries) { var timeSerieIndex = 0; foreach (TimeSerie damTimeSerie in outputTimeSerieCollection.Series) { var outputTimeSerie = new DamEngine.Io.XmlOutput.TimeSerieOutput(); outputTimeSerie.Entries = new TimeSerieOutputEntries(); outputTimeSerie.Entries.TimeSerieEntryOutput = new TimeSerieOutputEntriesTimeSerieEntryOutput[damTimeSerie.Entries.Count]; outputTimeSerie.LocationId = damTimeSerie.LocationId; outputTimeSerie.ParameterId = damTimeSerie.ParameterId; outputTimeSerie.ForecastDateTime = damTimeSerie.ForecastDateTime; outputTimeSerie.StartDateTime = damTimeSerie.StartDateTime; outputTimeSerie.EndDateTime = damTimeSerie.EndDateTime; outputTimeSerie.MissVal = damTimeSerie.MissVal; outputTimeSerie.Units = damTimeSerie.Units; var timeSerieEntryIndex = 0; foreach (TimeSerieEntry timestepEntry in damTimeSerie.Entries) { var timeStep = new TimeSerieOutputEntriesTimeSerieEntryOutput { DateTime = timestepEntry.DateTime, Value = timestepEntry.Value }; outputTimeSerie.Entries.TimeSerieEntryOutput[timeSerieEntryIndex] = timeStep; timeSerieEntryIndex++; } outputTimeSeries[timeSerieIndex] = outputTimeSerie; timeSerieIndex++; } } private static void TransferOutputCalculationMessages(List calculationMessages, OutputResults outputResults) { //var calculationMessages = damProjectData.CalculationMessages; if (calculationMessages != null) { outputResults.CalculationMessages = new Message[calculationMessages.Count]; for (var i = 0; i < calculationMessages.Count; i++) { var message = new Message(); message.MessageType = ConversionHelper.ConvertToInputMessageType(calculationMessages[i].MessageType); message.Message1 = calculationMessages[i].Message; outputResults.CalculationMessages[i] = message; } } } }