using Mapster;
using Yw.EPAnet;
using Yw.Hydro;
using Yw.Model;
using Yw.Vmo;
namespace HStation.WinFrmUI
{
///
///
///
public class SimulationPrintLossCurveHelper
{
///
///
///
///
public static SimulationPrintLossCurveViewModel Create
(
Yw.Model.HydroModelInfo hydroInfo,
HydroWorkingVmo working,
HydroVisualInfo visual,
HydroCalcuResult calcuResult = null,
bool isHead = false,
List allEvaluationList = null
)
{
var vm = new SimulationPrintLossCurveViewModel();
//验证
if (hydroInfo == null)
{
return vm;
}
if (working == null)
{
return vm;
}
if (visual == null)
{
return vm;
}
//赋值模型信息,避免干扰
//var newHydroInfo = hydroInfo.Adapt();
//newHydroInfo.UpdateWorkingInfo(working.WorkingInfo);
//计算结果
if (calcuResult == null)
{
calcuResult = hydroInfo.Calcu(Yw.EPAnet.CalcuMode.MinorLoss, isHead, allEvaluationList);
if (!calcuResult.Succeed)
{
return vm;
}
}
var allCalcuVisualDict = calcuResult.GetVisualDict();
var network = hydroInfo.ToNetwork();
if (network == null)
{
return vm;
}
var node = network.GetAllNodes()?.Find(x => x.Id == visual.Code);
if (node == null)
{
return vm;
}
var allStartPathList = network.AnalyzeUpstreamPath(node, calcuResult.EPAnetCalcuResult);
if (allStartPathList == null)
{
allStartPathList = new List();
}
var allEndPathList = network.AnalyzeDownstreamPath(node, calcuResult.EPAnetCalcuResult);
if (allEndPathList == null)
{
allEndPathList = new List();
}
var allPathList = allStartPathList.Concat(allEndPathList).ToList();
var allEpaLossList = network.GetChartNodeByPathLinks(allPathList, calcuResult.EPAnetCalcuResult);
if (allEpaLossList == null || allEpaLossList.Count < 1)
{
return vm;
}
var allVisualDict = hydroInfo.GetVisualDict();
vm.Items = new List();
foreach (var epaLoss in allEpaLossList)
{
var visualNode = allVisualDict.GetValue(epaLoss.Id);
if (visualNode != null)
{
var item = new SimulationPrintLossCurveItemViewModel(epaLoss, visualNode);
vm.Items.Add(item);
}
}
vm.Elev = new SimulationPrintLossCurveElevViewModel(vm.Items);
vm.Start = new SimulationPrintLossCurveStartViewModel(vm.Items);
vm.End = new SimulationPrintLossCurveEndViewModel(vm.Items);
vm.Total = new SimulationPrintLossCurveTotalViewModel(vm.Items);
return vm;
}
}
}