namespace HydroUI
|
{
|
|
[Serializable]
|
public class RepeaterViewModel : LinkViewModel
|
{
|
|
[DisplayName("对象前缀名称")]
|
[Browsable(true)]
|
|
/// 模板ID
|
public string NetworkPreName { get; set; }
|
|
|
[DisplayName("显示名称")]
|
[Browsable(true)]
|
|
/// 模板ID
|
public string NetworkShowName { get; set; }
|
|
|
[DisplayName("前缀最小序号")]
|
[Browsable(true)]
|
|
/// 模板ID
|
|
public int NetworkPreStartNum { get; set; } = 1;
|
|
|
[DisplayName("前缀正序")]
|
[Browsable(true)]
|
|
/// 模板ID
|
|
public bool NetworkIsAscNum { get; set; } = true;
|
|
[Category("计算参数")]
|
[DisplayName("模板ID")]
|
|
|
/// 模板ID
|
|
public string TemplateID { get; set; }
|
|
|
|
public Template template = null;
|
|
[NonSerialized]
|
public MapViewNetWork netList = null;
|
|
|
|
public NodeViewModel StartNode_inner;
|
|
public NodeViewModel EndNode_inner;
|
|
|
public bool isLoadded = false;
|
|
|
[Category("计算参数")]
|
[DisplayName("重复次数")]
|
[Browsable(true)]
|
|
/// 重复次数
|
|
public int RepeatTimes { get; set; }
|
|
|
|
|
[Category("计算参数")]
|
[DisplayName("海森威廉系数")]
|
|
public new float Roughness { get; set; }
|
[Category("计算参数")]
|
[DisplayName("局部阻力系数")]
|
|
public override float MinorLoss { get; set; }
|
|
[DisplayName("长度(m)")]
|
[Browsable(true)]
|
public new float Length { get; set; }
|
|
|
[DisplayName("口径(mm)")]
|
|
public new float Diameter { get; set; }
|
|
|
[Category("计算参数")]
|
[DisplayName("显示状态")]
|
[Browsable(true)]
|
public new RepeatStatus Status { get; set; }
|
|
public bool Load(int MaxLevel, dict<string, dynamic> param, Dictionary<PBS.eModelTemplateType, bool> viewModel, bool viewMode = true)
|
{
|
|
if (template == null)
|
{
|
// nsx template = TemplateList.GetTemplate(TemplateID);
|
if (template == null)
|
{
|
return false;
|
}
|
template.loadInpFile();
|
template.network.MapObjects.ForEach(o =>
|
{
|
if (o.Level > MaxLevel)
|
o.Visible = false;
|
else
|
o.Visible = true;
|
});
|
MapViewNetWork net = template.network;
|
net.StartPoint = net.GetNode(template.Node1)[0];
|
net.EndPoint = net.GetNode(template.Node2)[0];
|
|
}
|
|
|
if (!viewMode)
|
{
|
Status = RepeatStatus.收起;
|
}
|
else if (viewModel != null)
|
{
|
if (viewModel[template.Type])
|
Status = RepeatStatus.显示;
|
else
|
Status = RepeatStatus.收起;
|
}
|
else
|
{
|
Status = RepeatStatus.显示;
|
}
|
|
|
if (param.Contains("层数") && param["层数"] > 0 && template.Type == PBS.eModelTemplateType.Floor)
|
{
|
RepeatTimes = (int)param["层数"];
|
}
|
|
if (Status == RepeatStatus.收起)
|
{
|
return false;
|
}
|
PointF3D basepoint = StartNode.Position3D;
|
netList = new MapViewNetWork();
|
for (int i = 0; i < RepeatTimes; i++)
|
{
|
MapViewNetWork net = template.network.CreateNew(basepoint);
|
int index = GetIndex(i);
|
|
net.Name = NetworkPreName + (index == 0 ? "" : index.ToString("00"));
|
net.StartPoint = net.GetNode(template.Node1)[0];
|
net.EndPoint = net.GetNode(template.Node2)[0];
|
if (template.Type == PBS.eModelTemplateType.Floor)
|
ChangeNetbyParam(net, param);
|
if (i == 0) StartNode_inner = net.StartPoint;
|
EndNode_inner = net.EndPoint;
|
net.LoadRepeaters(MaxLevel, param, viewModel);
|
net.Rename();
|
netList.AddJoinNet(net);
|
basepoint = netList.EndPoint.Position3D;
|
}
|
return true;
|
}
|
void ChangeNetbyParam(MapViewNetWork net, dict<string, dynamic> param)
|
{
|
if (param.Contains("层高") && param["层高"] > 0 && net.StartPoint != null && net.EndPoint != null)
|
{
|
var currentHeight = Math.Abs(net.StartPoint.Elev - net.EndPoint.Elev);
|
var k = (float)param["层高"] / currentHeight;
|
net.Nodes.ForEach(n => n.Elev = (n.Elev - net.StartPoint.Elev) * k + net.StartPoint.Elev);
|
}
|
|
if (param.Contains("系统最大流量") && param["系统最大流量"] > 0 && net.StartPoint != null && net.EndPoint != null)
|
{
|
Dictionary<NodeViewModel, float> Distance = new Dictionary<NodeViewModel, float>();
|
CalcDistance(net, net.StartPoint, Distance);
|
float sumDistance = 0;
|
net.meters.ForEach(m => sumDistance += Distance[m]);
|
float avgDistance = sumDistance / net.meters.Count;
|
var k = (float)param["系统最大流量"] / avgDistance;
|
net.Nodes.ForEach(n =>
|
{
|
n.X = (n.X - net.StartPoint.X) * k + net.StartPoint.X;
|
n.Y = (n.Y - net.StartPoint.Y) * k + net.StartPoint.Y;
|
});
|
}
|
if (param.Contains("户数") && template.Type == PBS.eModelTemplateType.Floor)
|
{
|
var MaxLevel = (int)param["户数"];
|
net.MapObjects.ForEach(o =>
|
{
|
if (o.Level > MaxLevel)
|
o.Visible = false;
|
else
|
o.Visible = true;
|
});
|
}
|
}
|
|
|
public static void CalcDistance(MapViewNetWork net, NodeViewModel startNode, Dictionary<NodeViewModel, float> Distance)
|
{
|
// 定义 visited 字典记录已访问过的节点和待访问的节点队列
|
Queue<NodeViewModel> queue = new Queue<NodeViewModel>();
|
|
// 标记起始节点为已访问,并加入队列
|
Distance[startNode] = 0;
|
queue.Enqueue(startNode);
|
|
// 不断从队列中取出节点进行访问,直到队列为空
|
while (queue.Count > 0)
|
{
|
// 取出队首节点并输出
|
NodeViewModel node = queue.Dequeue();
|
//Console.WriteLine(node.Name);
|
|
// 遍历当前节点的所有未访问邻居节点,并标记为已访问
|
foreach (LinkViewModel link in net.Links)
|
{
|
if (link.StartNode == node)
|
{
|
var node1 = link.EndNode;
|
var dis = Distance[node] + (float)Math.Sqrt(Math.Pow(node.X - node1.X, 2) + Math.Pow(node.Y - node1.Y, 2));
|
if (!Distance.ContainsKey(node1) || Distance[node1] > dis)
|
Distance[link.EndNode] = dis;
|
queue.Enqueue(link.EndNode);
|
}
|
else if (link.EndNode == node && !Distance.ContainsKey(link.StartNode))
|
{
|
var node1 = link.StartNode;
|
var dis = Distance[node] + (float)Math.Sqrt(Math.Pow(node.X - node1.X, 2) + Math.Pow(node.Y - node1.Y, 2));
|
if (!Distance.ContainsKey(node1) || Distance[node1] > dis)
|
Distance[link.StartNode] = dis;
|
queue.Enqueue(link.StartNode);
|
}
|
}
|
}
|
}
|
|
public int GetIndex(int i)
|
{
|
int index = 0;
|
if (NetworkIsAscNum)
|
{
|
index = NetworkPreStartNum + i;
|
}
|
else
|
{
|
index = RepeatTimes - 1 - i + NetworkPreStartNum;
|
}
|
|
return index;
|
}
|
|
|
|
}
|
}
|