lixiaojun
2025-04-08 a2eb452246657e5c51f4b1b736fa05c5074f0948
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
using Newtonsoft.Json;
//using Hydro.Inp;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
using Yw.WinFrmUI.Q3d;
using Yw.WinFrmUI.Q3d;
//using Hydro.HydraulicOptimizer;
using Yw.WinFrmUI.Q3d;
using static Yw.WinFrmUI.Q3d.MapViewEnum;
using static Yw.WinFrmUI.Q3d.ObjectEnum;
 
namespace Yw.WinFrmUI.Q3d
{
    [Serializable]
    public partial class NetworkViewModel
    {
        bool use_old = false;
        public string Name;
 
        #region 基础结构
 
        [JsonIgnore]
        public List<IBaseViewModel> MapObjects
        {
            get
            {
                List<Q3DBaseModel> objects = new List<Q3DBaseModel>();
                objects.AddRange(Nodes);
                objects.AddRange(Links);
                return objects.Select(o => (IBaseViewModel)o).ToList();
            }
        }
 
        private LinkViewModelList _links = new LinkViewModelList();
        public LinkViewModelList Links { get { return _links; } set { _links = value; } }
 
        private NodeViewModelList _nodes = new NodeViewModelList();
        public NodeViewModelList Nodes { get { return _nodes; } set { _nodes = value; } }
 
        private List<AreaViewModel> _areas = new List<AreaViewModel>();
        public List<AreaViewModel> Areas { get { return _areas; } set { _areas = value; } }
 
        public NodeViewModel StartPoint { get; set; }
 
        public NodeViewModel EndPoint { get; set; }
 
 
 
        [JsonIgnore]
        public Dictionary<string, Dataset> dict_dataset = new Dictionary<string, Dataset>();
        [JsonIgnore]
        public HashSet<string> Hash_ID;
 
        [JsonIgnore]
        private List<JunctionViewModel> junctions
        {
            get
            {
                return Nodes.FindAll(n => n is JunctionViewModel).Select(n => n as JunctionViewModel).ToList();
            }
            set
            {
                if (value == null) return;
                Nodes.RemoveAll(n => n is JunctionViewModel);
                Nodes.AddRange(value);
            }
        }
 
        [JsonIgnore]
        private List<ReservoirViewModel> reservoirs
        {
            get
            {
                return Nodes.FindAll(n => n is ReservoirViewModel).Select(n => n as ReservoirViewModel).ToList();
            }
            set
            {
                if (value == null) return;
                Nodes.RemoveAll(n => n is ReservoirViewModel);
                Nodes.AddRange(value);
            }
        }
        [JsonIgnore]
        private List<TankViewModel> tanks
        {
            get
            {
                return Nodes.FindAll(n => n is TankViewModel).Select(n => n as TankViewModel).ToList();
            }
            set
            {
                if (value == null) return;
                Nodes.RemoveAll(n => n is TankViewModel);
                Nodes.AddRange(value);
            }
        }
        [JsonIgnore]
        private List<MeterViewModel> meters
        {
            get
            {
                return Nodes.FindAll(n => n is MeterViewModel).Select(n => n as MeterViewModel).ToList();
 
            }
            set
            {
                if (value == null) return;
                Nodes.RemoveAll(n => n is MeterViewModel);
                Nodes.AddRange(value);
            }
        }
        [JsonIgnore]
        private List<NozzleViewModel> nozzles
        {
            get
            {
                return Nodes.FindAll(n => n is NozzleViewModel).Select(n => n as NozzleViewModel).ToList();
 
            }
            set
            {
                if (value == null) return;
                Nodes.RemoveAll(n => n is NozzleViewModel);
                Nodes.AddRange(value);
            }
        }
 
        [JsonIgnore]
        private List<PipeViewModel> pipes
        {
            get
            {
                return Links.FindAll(n => n is PipeViewModel).Select(n => n as PipeViewModel).ToList();
            }
            set
            {
                if (value == null) return;
                Links.RemoveAll(n => n is PipeViewModel);
                Links.AddRange(value);
            }
        }
        [JsonIgnore]
        private List<ValveViewModel> valves
        {
            get
            {
                return Links.FindAll(n => n is ValveViewModel).Select(n => n as ValveViewModel).ToList();
            }
            set
            {
                if (value == null) return;
                Links.RemoveAll(n => n is ValveViewModel);
                Links.AddRange(value);
            }
        }
 
 
        [JsonIgnore]
        private List<PumpViewModel> pumps
        {
            get
            {
                return Links.FindAll(n => n is PumpViewModel).Select(n => n as PumpViewModel).ToList();
            }
            set
            {
                if (value == null) return;
                Links.RemoveAll(n => n is PumpViewModel);
                Links.AddRange(value);
            }
        }
 
 
 
        private List<AreaViewModel> areas = new List<AreaViewModel>();
 
        #endregion
 
        #region 添加对象
        public JunctionViewModel AddJunction(string ID, PointF position, float z = 0)
        {
            JunctionViewModel j = new JunctionViewModel();
 
            j.ID = ID;
            j.Demand = 0;
            j.PatternID = "";
            j.Z = z;
            j.X = position.X;
            j.Y = position.Y;
            Nodes.Add(j);
            return j;
        }
        public JunctionViewModel AddJunction(PointF position, float z = 0)
        {
            JunctionViewModel j = new JunctionViewModel();
            int i = 0;
            string ID = $"{Default.GetPreString(j)}{i}";
            while (Nodes.Find(p0 => p0.ID == ID) != null)
            {
                i++;
                ID = $"{Default.GetPreString(j)}{i}";
            }
            j.ID = ID;
            j.Z = 0;
            j.Demand = 0;
            j.PatternID = "";
            j.Z = z;
            j.X = position.X;
            j.Y = position.Y;
            Nodes.Add(j);
            return j;
        }
 
        public MeterViewModel AddMeter(PointF position)
        {
            MeterViewModel j = new MeterViewModel();
            int i = 0;
            string ID = $"{Default.GetPreString(j)}{i}";
            while (Nodes.Find(p0 => p0.ID == ID) != null)
            {
                i++;
                ID = $"{Default.GetPreString(j)}{i}";
            }
            j.ID = ID;
            j.Z = 0;
            j.Demand = 0;
            j.PatternID = "";
 
            j.X = position.X;
            j.Y = position.Y;
            Nodes.Add(j);
 
            return j;
        }
        public ReservoirViewModel AddReservoir(PointF position)
        {
            ReservoirViewModel j = new ReservoirViewModel();
            int i = 0;
            string ID = $"{Default.GetPreString(j)}{i}";
            while (Nodes.Find(p0 => p0.ID == ID) != null)
            {
                i++;
                ID = $"{Default.GetPreString(j)}{i}";
            }
            j.ID = ID;
            j.Z = 0;
            j.Demand = 0;
            j.PatternID = "";
            j.Head = 100;
            j.X = position.X;
            j.Y = position.Y;
            Nodes.Add(j);
 
            return j;
        }
        public TankViewModel AddTank(PointF position)
        {
            TankViewModel j = new TankViewModel();
            int i = 0;
            string ID = $"{Default.GetPreString(j)}{i}";
            while (Nodes.Find(p0 => p0.ID == ID) != null)
            {
                i++;
                ID = $"{Default.GetPreString(j)}{i}";
            }
            j.ID = ID;
            j.Z = 0;
            j.Demand = 0;
            j.PatternID = "";
 
            j.X = position.X;
            j.Y = position.Y;
            Nodes.Add(j);
 
            return j;
        }
        public PipeViewModel AddPipe(NodeViewModel node1, NodeViewModel node2)
        {
            PipeViewModel pipe = new PipeViewModel();
            int i = 0;
            string ID = $"{Default.GetPreString(pipe)}{i}";
            while (Links.Find(p0 => p0.ID == ID) != null)
            {
                i++;
                ID = $"{Default.GetPreString(pipe)}{i}";
            }
            pipe.ID = ID;
            pipe.Diameter = 100;
            pipe.MinorLoss = 0;
            pipe.Roughness = 100;
            pipe.Status = StatusType.DEFAULT;
            pipe.StartNode = node1;
            pipe.EndNode = node2;
            pipe.Length = -1;
 
 
 
            Links.Add(pipe);
            return pipe;
        }
        public ValveViewModel AddValve(NodeViewModel node1, NodeViewModel node2)
        {
            ValveViewModel valve = new ValveViewModel();
            int i = 0;
            string ID = $"{Default.GetPreString(valve)}{i}";
            while (Links.Find(p0 => p0.ID == ID) != null)
            {
                i++;
                ID = $"{Default.GetPreString(valve)}{i}";
            }
            valve.ID = ID;
 
            valve.Diameter = 100;
            valve.Status = StatusType.DEFAULT;
            valve.StartNode = node1;
            valve.EndNode = node2;
 
            Links.Add(valve);
 
            return valve;
        }
 
        public PumpViewModel AddPump(NodeViewModel node1, NodeViewModel node2)
        {
            PumpViewModel pump = new PumpViewModel();
            int i = 0;
            string ID = $"{Default.GetPreString(pump)}{i}";
            while (Links.Find(p0 => p0.ID == ID) != null)
            {
                i++;
                ID = $"{Default.GetPreString(pump)}{i}";
            }
            pump.ID = ID;
 
 
            pump.StartNode = node1;
            pump.EndNode = node2;
 
            Links.Add(pump);
 
            return pump;
        }
 
        #endregion
 
        #region 批量操作(暂时不需要,但是保留)
        public void Rename()
        {
            MapObjects.ForEach(o => o.ID = $"{Name}_{o.ID}");
        }
        public void Add(List<IBaseViewModel> objects)
        {
            Nodes.AddRange(objects.FindAll(o => o is NodeViewModel).Select(o => (NodeViewModel)o));
            Links.AddRange(objects.FindAll(o => o is LinkViewModel).Select(o => (LinkViewModel)o));
            //BuildRelation();
        }
 
        public void Clear()
        {
            Nodes.Clear();
            Links.Clear();
        }
        public List<IBaseViewModel> Remove(List<IBaseViewModel> list)
        {
 
            List<IBaseViewModel> objs = new List<IBaseViewModel>();
            list.ForEach(o =>
            {
                if (o == null) return;
                o.Selected = false;
                if (o is NodeViewModel n)
                {
                    n.Links.ForEach(l =>
                    {
                        if (this.Links.Remove(l)) objs.Add((LinkViewModel)l);
                    });
                    if (this.Nodes.Remove(n)) objs.Add(n);
 
                }
                else if (o is LinkViewModel l)
                {
                    if (this.Links.Remove(l)) objs.Add(l);
 
                }
            });
            //BuildRelation();
            return objs;
 
        }
 
        public void ChangePoint(NodeViewModel source, NodeViewModel newPoint)
        {
            Links.ForEach(l =>
            {
                if (l.StartNode == source)
                {
                    l.StartNode = newPoint;
                }
                else if (l.EndNode == source)
                {
                    l.EndNode = newPoint;
                }
 
            });
            source.Visible = false;
            //Nodes.Remove(source);
        }
        public void ChangeNodeID(NodeViewModel node, string ID)
        {
            node.ID = ID;
            node.Links.ForEach(l =>
            {
                if (l.StartNode == node)
                {
                    l.Node1 = node.ID;
                }
                else
                {
                    l.Node2 = node.ID;
                }
            });
        }
        public string GetValidID(IBaseViewModel obj)
        {
            string DefaultString = Default.GetPreString(obj);
            int i = 0;
            string ID = obj.ID;
            //List<IBaseViewModel> objs;
            ID = $"{DefaultString}{i}";
            //while ((objs = MapObjects.FindAll(p0 => p0.ID == ID)).Count>1 && objs[0]!=obj)
            while (Hash_ID.Contains(ID))
            {
                ID = $"{DefaultString}{i}";
                i++;
            }
            return ID;
        }
 
        public NetworkViewModel CreateNew(PointF3D basepoint)
        {
            NetworkViewModel net = this.DeepCopy<NetworkViewModel>();
            var BasePos = StartPoint.Position3D;
 
            net.Nodes.ForEach(n =>
            {
                n.X += basepoint.X - BasePos.X;
                n.Y += basepoint.Y - BasePos.Y;
                n.Z += basepoint.Z - BasePos.Z;
            });
 
            return net;
        }
 
        public void AddJoinNet(NetworkViewModel network)
        {
 
            if (Nodes.Count == 0)
            {
                Nodes.AddRange(network.Nodes);
                Links.AddRange(network.Links);
                StartPoint = network.StartPoint;
                EndPoint = network.EndPoint;
            }
            else
            {
 
                ChangePoint(EndPoint, network.StartPoint);
                Nodes.AddRange(network.Nodes);
                Links.AddRange(network.Links);
                //MapObjects.ForEach(n => n.ID = GetValidID(n));
                EndPoint = network.EndPoint;
            }
        }
        public List<IBaseViewModel> Add(NetworkViewModel net0, PointF3D offset = null, bool isCopy = false, NodeViewModel ConnectNode = null)
        {
            if (offset == null)
            {
                offset = new PointF3D(0, 0, 0);
            }
            List<IBaseViewModel> list = new List<IBaseViewModel>();
            if (Hash_ID == null) Hash_ID = new HashSet<string>();
 
            NetworkViewModel net = isCopy ? net0.DeepCopy() : net0;
            net.Nodes.ForEach(n0 =>
            {
                NodeViewModel n = (NodeViewModel)n0;
                if (Hash_ID.Contains(n.ID))
                {
                    string ID = GetValidID(n);
                    net.ChangeNodeID(n, ID);
                }
                n.X += offset.X;
                n.Y += offset.Y;
                n.Z += offset.Z;
                Nodes.Add(n);
                Hash_ID.Add(n.ID);
                list.Add(n);
                if (n0 == net.EndPoint && list[0] != n)
                {
                    int index = list.IndexOf(n);
                    var o = list[0];
                    list[0] = n;
                    list[index] = o;
                }
            });
            net.Links.ForEach(l0 =>
            {
                LinkViewModel l = (LinkViewModel)l0;
                if (Hash_ID.Contains(l.ID))
                {
                    string ID = GetValidID(l);
                    l.ID = ID;
                }
                Links.Add(l);
                Hash_ID.Add(l.ID);
                list.Add(l);
            });
            if (ConnectNode != null)
            {
                var l = AddPipe(ConnectNode, net.StartPoint);
                list.Add(l);
                Hash_ID.Add(l.ID);
            }
            //BuildRelation();
            return list;
        }
 
        #endregion
 
 
        #region 管网遍历/检查相关
        // 定义 visited 字典记录已访问过的节点和待访问的节点队列
        private Dictionary<NodeViewModel, bool> visited;//= new Dictionary<Node, bool>();
        private bool _isCalculated = false;
        private void BFS(NetworkViewModel net, NodeViewModel startNode, Vector3 vector)
        {
 
            Queue<NodeViewModel> queue = new Queue<NodeViewModel>();
 
            // 标记起始节点为已访问,并加入队列
            visited[startNode] = true;
            queue.Enqueue(startNode);
 
            // 不断从队列中取出节点进行访问,直到队列为空
            while (queue.Count > 0)
            {
                // 取出队首节点并输出
                NodeViewModel node = queue.Dequeue();
                node.Move(vector);
 
 
                // 遍历当前节点的所有未访问邻居节点,并标记为已访问
                foreach (LinkViewModel link in net.Links)
                {
                    if (link.StartNode == node && !visited.ContainsKey(link.EndNode))
                    {
                        visited[link.EndNode] = true;
                        queue.Enqueue(link.EndNode);
 
                    }
                    else if (link.EndNode == node && !visited.ContainsKey(link.StartNode))
                    {
                        visited[link.StartNode] = true;
                        queue.Enqueue(link.StartNode);
                    }
                }
            }
        }
 
        private List<NodeViewModel> GetNode(string node)
        {
            return Nodes.FindAll(n => n.ID == node).Select(n => (NodeViewModel)n).ToList();
        }
        public Dictionary<string, List<string>> CheckValidate()
        {
            BuildRelation();
            string result = null;
            Dictionary<string, List<string>> result_dict = new Dictionary<string, List<string>>();
            StringBuilder result_sb = new StringBuilder();
            //to-do
            var objs = Links.Select(o => o as LinkViewModel).ToList();
            objs = objs.Distinct().ToList();
            var visitedNodes = new HashSet<NodeViewModel>();
            FindObjs = new HashSet<IBaseViewModel>();
            objs.ForEach(o => TraversePipeNetworkALL(o, visitedNodes));
            List<string> list_孤立点 = new List<string>();
            for (int i = 0; i < Nodes.Count; i++)
            {
                if (!FindObjs.Contains(Nodes[i]))
                {
                    result_sb.AppendLine($"节点{Nodes[i].ID}是孤立点");
                    list_孤立点.Add(Nodes[i].ID);
                }
 
            }
            if (list_孤立点.Count > 0) result_dict.Add("孤立点", list_孤立点);
            //属性判断
            var list_管道连接关系异常 = new List<string>();
            var list_管道长度小于等于0 = new List<string>();
            var list_粗糙系数设置错误 = new List<string>();
            var list_管径设置错误 = new List<string>();
 
            pipes.ForEach(p =>
            {
                if (p.StartNode == null || p.EndNode == null)
                {
                    result_sb.AppendLine($"{p.ID}管道连接关系异常");
                    list_管道连接关系异常.Add(p.ID);
                }
                if (p.Length <= 0)
                {
                    result_sb.AppendLine($"{p.ID}管道长度小于等于0");
                    list_管道长度小于等于0.Add(p.ID);
                }
                if (p.Roughness <= 0.1 || p.Roughness > 10000)
                {
                    result_sb.AppendLine($"{p.ID}粗糙系数设置错误");
                    list_粗糙系数设置错误.Add(p.ID);
                }
                if (p.Diameter <= 0.1 || p.Diameter > 10000)
                {
                    result_sb.AppendLine($"{p.ID}管径设置错误");
                    list_管径设置错误.Add(p.ID);
                }
 
            });
            if (list_管道连接关系异常.Count > 0) result_dict.Add("管道连接关系异常", list_管道连接关系异常);
            if (list_管道长度小于等于0.Count > 0) result_dict.Add("管道长度小于等于0", list_管道长度小于等于0);
            if (list_粗糙系数设置错误.Count > 0) result_dict.Add("粗糙系数设置错误", list_粗糙系数设置错误);
            if (list_管径设置错误.Count > 0) result_dict.Add("管径设置错误", list_管径设置错误);
            return result_dict;
 
 
 
        }
        HashSet<IBaseViewModel> FindObjs;
        private void TraversePipeNetworkALL(LinkViewModel startLink, HashSet<NodeViewModel> visitedNodes = null, int direction = 0)
        {
 
            Queue<LinkViewModel> queue = new Queue<LinkViewModel>();
 
 
 
            queue.Enqueue(startLink);
            if (visitedNodes == null)
                visitedNodes = new HashSet<NodeViewModel>();
 
 
            while (queue.Count > 0)
            {
                LinkViewModel currentLink = queue.Dequeue();
 
 
                foreach (var node in new NodeViewModel[] { currentLink.StartNode, currentLink.EndNode })
                {
                    if (direction == 1 && currentLink.EN_FLOW >= 0 && node == currentLink.StartNode) continue;
                    if (direction == -1 && currentLink.EN_FLOW <= 0 && node == currentLink.EndNode) continue;
                    if (node != null && !visitedNodes.Contains(node))
                    {
                        visitedNodes.Add(node);
                        if (!FindObjs.Contains(node)) FindObjs.Add(node);
 
 
                        //Console.WriteLine("Visiting Node: " + node.ID);
                        foreach (var link in node.ViewLinks)
                        {
                            if (!visitedNodes.Contains(link.StartNode) || !visitedNodes.Contains(link.EndNode))
                            {
 
                                if (!FindObjs.Contains(link)) FindObjs.Add(link);
                                queue.Enqueue(link);
 
 
 
 
                            }
                        }
                    }
                }
 
            }
 
 
 
        }
 
        #endregion
 
 
 
 
    }
 
    //构造一个List<LinkViewModel>类,能够实现List的所有功能
    [Serializable]
    public class LinkViewModelList : List<LinkViewModel>
    {
 
        Dictionary<string, LinkViewModel> dict;
        public LinkViewModelList() : base()
        {
            this.dict = new Dictionary<string, LinkViewModel>();
        }
 
        public List<LinkViewModel> ViewLinks
        {
            get
            {
                var list = new List<LinkViewModel>();
                base.ForEach(l =>
                {
                    //if (l is LinkViewModel)
                    list.Add((LinkViewModel)l);
                });
                return list;
                //return base.Select(l => (LinkViewModel)l).ToList();
            }
        }
        /// <summary>
        /// 更新字典
        /// </summary>
        public void UpdateDict()
        {
            this.dict = new Dictionary<string, LinkViewModel>();
            base.ForEach(link =>
            {
                if (!dict.ContainsKey(link.ID))
                    dict.Add(link.ID, (LinkViewModel)link);
            });
        }
        /// <summary>
        /// 修改某个oldID至newID,同时更新字典
        /// </summary>
        /// <param name="oldID"></param>
        /// <param name="newID"></param>
        public void ChangeID(string oldID, string newID)
        {
            if (dict.ContainsKey(oldID))
            {
                dict[oldID].ID = newID;
                dict.Add(newID, dict[oldID]);
                dict.Remove(oldID);
            }
        }
        /// <summary>
        /// 实现Add方法,同时更新字典
        /// </summary>
        public void Add(LinkViewModel linkCalcModel)
        {
            base.Add(linkCalcModel);
            if (!dict.ContainsKey(linkCalcModel.ID))
                dict.Add(linkCalcModel.ID, linkCalcModel);
        }
        /// <summary>
        /// 实现AddRange方法,同时更新字典
        /// </summary>
        /// <param name="linkCalcModels"></param>
        public void AddRange(List<LinkViewModel> linkCalcModels)
        {
            base.AddRange(linkCalcModels);
            linkCalcModels.ForEach(link =>
            {
                if (!dict.ContainsKey(link.ID))
                    dict.Add(link.ID, link);
            });
        }
 
        public bool RemoveAt(int index)
        {
            if (index < 0 || index >= base.Count) return false;
            var link = base[index];
            base.RemoveAt(index);
            if (dict.ContainsKey(link.ID))
                dict.Remove(link.ID);
            return true;
        }
        /// <summary>
        /// 统计数量
        /// </summary>
        public int Count { get { return base.Count; } }
        public LinkViewModel this[string ID]
        {
            get
            {
                if (dict.ContainsKey(ID))
                    return dict[ID];
                else
                    return (LinkViewModel)base.Find(l => l.ID == ID);
            }
        }
        public LinkViewModel this[int index]
        {
            get
            {
                return (LinkViewModel)base[index];
            }
        }
 
        public void Sort()
        {
            base.Sort();
        }
        //实现Sort(Comparison<LinkViewModel> comparison)方法
        public void Sort(Comparison<Q3DLinkCalcModel> comparison)
        {
            base.Sort(comparison);
        }
        //实现Select方法
        public void Select(Action<LinkViewModel> action)
        {
            //base.ForEach(action);
            //base.ForEach(action);
            ViewLinks.ForEach(action);
        }
        //实现Find方法
        public LinkViewModel Find(Predicate<LinkViewModel> match)
        {
            //base.Find(match);
            return ViewLinks.Find(match);
        }
        //实现FindAll方法
        public List<LinkViewModel> FindAll(Predicate<LinkViewModel> match)
        {
            return ViewLinks.FindAll(match);
        }
        //实现ForEach方法
        public void ForEach(Action<LinkViewModel> action)
        {
            ViewLinks.ForEach(action);
        }
        //实现RemoveAll方法
        public int RemoveAll(Predicate<Q3DLinkCalcModel> match)
        {
            return base.RemoveAll(match);
        }
        /// <summary>
        /// 实现Remove方法,同时更新字典
        /// </summary>
        public bool Remove(LinkViewModel linkCalcModel)
        {
            if (base.Remove(linkCalcModel))
            {
                if (dict.ContainsKey(linkCalcModel.ID))
                    dict.Remove(linkCalcModel.ID);
                return true;
            }
            else
                return false;
        }
 
 
 
 
    }
 
    //构造一个List<NodeViewModel>类,能够实现List的所有功能
    [Serializable]
 
    public class NodeViewModelList : List<NodeViewModel>
    {
        //List<NodeCalcModel> base;
        Dictionary<string, NodeViewModel> dict;//=new Dictionary<string, NodeCalcModel>();//
        public NodeViewModelList() : base()
        {
            this.dict = new Dictionary<string, NodeViewModel>();
        }
        //public NodeViewModelList(List<NodeCalcModel> nodes)
        //{
        //    base = nodes;
        //    base.ForEach(node => 
        //    {
        //        if (!dict.ContainsKey(node.ID))
        //            dict.Add(node.ID,node);
        //    });
        //}
        /// <summary>
        /// 更新字典
        /// </summary>
        public void UpdateDict()
        {
            this.dict = new Dictionary<string, NodeViewModel>();
            base.ForEach(node =>
            {
                if (!dict.ContainsKey(node.ID))
                    dict.Add(node.ID, node);
            });
        }
        /// <summary>
        /// 修改某个oldID至newID,同时更新字典
        /// </summary>
        /// <param name="oldID"></param>
        /// <param name="newID"></param>
        public void ChangeID(string oldID, string newID)
        {
            if (dict.ContainsKey(oldID))
            {
                dict[oldID].ID = newID;
                dict.Add(newID, dict[oldID]);
                dict.Remove(oldID);
            }
        }
        /// <summary>
        /// 实现Add方法,同时更新字典
        /// </summary>
        public void Add(NodeViewModel nodeCalcModel)
        {
            base.Add(nodeCalcModel);
            if (!dict.ContainsKey(nodeCalcModel.ID))
                dict.Add(nodeCalcModel.ID, nodeCalcModel);
        }
        /// <summary>
        /// 实现AddRange方法,同时更新字典
        /// </summary>
        /// <param name="nodeCalcModels"></param>
        public void AddRange(List<NodeViewModel> nodeCalcModels)
        {
            base.AddRange(nodeCalcModels);
            nodeCalcModels.ForEach(node =>
            {
                if (!dict.ContainsKey(node.ID))
                    dict.Add(node.ID, node);
            });
        }
        /// <summary>
        /// 实现Remove方法,同时更新字典
        /// </summary>
        public bool Remove(NodeViewModel nodeCalcModel)
        {
            if (base.Remove(nodeCalcModel))
            {
                if (dict.ContainsKey(nodeCalcModel.ID))
                    dict.Remove(nodeCalcModel.ID);
                return true;
            }
            else
                return false;
        }
        public bool RemoveAt(int index)
        {
            if (index < 0 || index >= base.Count) return false;
            var node = base[index];
            base.RemoveAt(index);
            if (dict.ContainsKey(node.ID))
                dict.Remove(node.ID);
            return true;
        }
        /// <summary>
        /// 统计数量
        /// </summary>
        public int Count { get { return base.Count; } }
        public NodeViewModel this[string ID]
        {
            get
            {
                if (dict.ContainsKey(ID))
                    return (NodeViewModel)dict[ID];
                else
                    return (NodeViewModel)base.Find(l => l.ID == ID);
            }
        }
        public NodeViewModel this[int index]
        {
            get
            {
                return (NodeViewModel)base[index];
            }
        }
        //public List<NodeCalcModel> ToList()
        //{
        //    return base;
        //}
        //实现Sort方法
        public List<NodeViewModel> ViewNodes
        {
            get
            {
                //将NodeCalcModel转换为NodeViewModel
                //return this.Select(l => (NodeViewModel)l).ToList();
                List<NodeViewModel> list = new List<NodeViewModel>();
                foreach (var item in this)
                {
                    list.Add((NodeViewModel)item);
                }
                return list;
            }
 
        }
 
        public void Sort()
        {
            base.Sort();
        }
        //实现Sort(Comparison<NodeViewModel> comparison)方法
        public void Sort(Comparison<Q3DNodeCalcModel> comparison)
        {
            base.Sort(comparison);
        }
        //实现Select方法
        public void Select(Action<NodeViewModel> action)
        {
            ViewNodes.ForEach(action);
            //base.ForEach(action);
        }
        //实现Find方法
        public NodeViewModel Find(Predicate<NodeViewModel> match)
        {
            return ViewNodes.Find(match);
        }
        //实现FindAll方法
        public List<NodeViewModel> FindAll(Predicate<NodeViewModel> match)
        {
            return ViewNodes.FindAll(match);
        }
        //实现ForEach方法
        public void ForEach(Action<NodeViewModel> action)
        {
            ViewNodes.ForEach(action);
        }
        //实现RemoveAll方法
        public int RemoveAll(Predicate<Q3DNodeCalcModel> match)
        {
            return base.RemoveAll(match);
        }
 
 
 
 
    }
 
}