qinjie
2023-12-19 15d15d24fbccb9b70a305b46b71453b2ab1a720e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using Hydro.Core.Model;
using Hydro.Inp;
using Hydro.Revit.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Hydro.Revit
{
    public class RevitNetWork : NetWork
    {
        public void AddJunction(JunctionViewModel junction)
        {
            if (!CheckNodesExist(junction))
                Nodes.Add(junction);
        }
 
        public new List<PipeViewModel> Pipes
        {
            get
            {
                var js = Links.Where(d => d is PipeViewModel);
                return js?.Select(d => d as PipeViewModel).ToList();
            }
        }
 
        public new List<NozzleViewModel> Nozzles
        {
            get
            {
                var js = Nodes.Where(d => d is NozzleViewModel);
                return js?.Select(d => d as NozzleViewModel).ToList();
            }
        }
 
        public void AddJunctions(List<JunctionViewModel> junctions)
        {
            junctions.ForEach(junction => { AddJunction(junction); });
        }
 
        public void AddTank(WaterTankViewModel tank)
        {
            if (!CheckNodesExist(tank))
                Nodes.Add(tank);
        }
 
        public List<HydrantBoxViewModel> HydrantBoxes => Nodes.Where((NodeCalcModel d) => d is HydrantBoxViewModel)?.Select((NodeCalcModel d) => d as HydrantBoxViewModel).ToList();
 
        public void AddTanks(List<WaterTankViewModel> tanks)
        {
            tanks.ForEach(tank => { AddTank(tank); });
 
 
            // WaterTankViewModel kk=null;
            // Nodes.Select(n => (WaterTankViewModel)n).ToList().Sort(o => o.PositionJson);
            // WaterTankViewModels 
 
            //((WaterTankViewModel) Nodes[0]).PositionJson
        }
 
        public void AddPipe(PipeViewModel pipe)
        {
            if (!CheckLinksExist(pipe))
                Links.Add(pipe);
        }
 
        public void AddPipes(List<PipeViewModel> pipes)
        {
            pipes.ForEach(pipe => { AddPipe(pipe); });
        }
        public void AddPump(WaterPumpViewModel pump)
        {
            if (!CheckLinksExist(pump))
                Links.Add(pump);
        }
 
        public void AddPumps(List<WaterPumpViewModel> pumps)
        {
            pumps.ForEach(pump => { AddPump(pump); });
        }
        public void AddValve(ValveViewModel valve)
        {
            if (!CheckLinksExist(valve))
                Links.Add(valve);
        }
 
        public void AddValves(List<ValveViewModel> valves)
        {
            valves.ForEach(valve => { AddValve(valve); });
        }
 
        public void AddHydrantBox(HydrantBoxViewModel hydrantBox)
        {
            if (!CheckNodesExist(hydrantBox))
                Nodes.Add(hydrantBox);
        }
 
        public void AddHydrantBoxs(List<HydrantBoxViewModel> hydrantBoxs)
        {
            hydrantBoxs.ForEach(hydrantBox => { AddHydrantBox(hydrantBox); });
        }
 
        public void AddNozzle(NozzleViewModel nozzle)
        {
            if (!CheckNodesExist(nozzle))
                Nodes.Add(nozzle);
        }
        public void AddNozzles(List<NozzleViewModel> nozzles)
        {
            nozzles.ForEach(nozzle => { AddNozzle(nozzle); });
        }
 
        private bool CheckNodesExist(NodeCalcModel node)
        {
            return Nodes.Any(d => d.ID == node.ID);
            //   throw new Exception("已存在重复的对象");
        }
 
        private bool CheckLinksExist(LinkCalcModel link)
        {
            return Links.Any(d => d.ID == link.ID);
            //throw new Exception("已存在重复的对象");
        }
    }
}