ningshuxia
2025-03-24 7b8ae93d47186c442ff890a1a83d108f115924c7
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
using Hydro;
 
namespace PBS.WinFrmUI.Hydro
{
    public partial class SelectModelTemplateDlg : DevExpress.XtraEditors.XtraForm
    {
        public SelectModelTemplateDlg()
        {
            InitializeComponent();
            this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
            this.layoutControl1.SetupLayoutControl();
            this.generalOkAndCancelCtrl1.OkEvent += GeneralOkAndCancelCtrl1_OkEvent;
            this.modelTemplateTreeListCtrl1.SelectModelTemplateEvent += ModelTemplateTreeListCtrl1_SelectModelTemplateEvent;
        }
 
 
 
        /// <summary>
        /// 重载数据
        /// </summary>
        public event Action<Template> ReloadDataEvent;
 
        public Vmo.ModelTemplateVmo _modelTemplate;
        private Template _template = null;
        private MapViewer _mapView = null;
         
 
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public async void SetBindingData()
        {
 
            _mapView = new MapViewer();
            _mapView.Lock2DView = true;
            _mapView.ShowPropertyForm = false;
            _mapView.ShowStatusBar = false;
            _mapView.Location = new System.Drawing.Point(0, 0);
            _mapView.Dock = DockStyle.Fill;
 
            this.panelControl1.Controls.Add(_mapView);
 
            var modelTemplateList = await BLLFactory<BLL.ModelTemplate>.Instance.GetAll();
            this.modelTemplateTreeListCtrl1.SetBindingData(modelTemplateList);
            this.modelTemplateTreeListCtrl1.MenuBarVisible = false;
 
            this.txtLowerLevel.EditValue = 1;
            this.txtHighestLevel.EditValue = 3;
            this.txtBottomElevation.EditValue = 3;
            this.txtFloorHeight.EditValue = 3;
 
        }
 
        //选择模型模板
        private void ModelTemplateTreeListCtrl1_SelectModelTemplateEvent(ModelTemplateVmo obj)
        {
            if (obj == null)
            {
                _modelTemplate = null;
                _template = null;
                _mapView.Clear();
                return;
            }
 
            _modelTemplate = obj;
            _template = Yw.JsonHelper.Json2Object<Template>(obj.ModelInfo);
 
 
            var template = _template;
            template.network = new MapViewNetWork();
            template.network.BuildFromInp(Path.Combine(Directory.GetCurrentDirectory(), _template.filePath));
            _mapView.SetData(template);
        }
 
        //生成
        private Template CreateTemplate()
        {
            if (!Verify())
                return null;
 
            int minFloorIndex = Convert.ToInt32(this.txtLowerLevel.EditValue);
            int maxFloorIndex = Convert.ToInt32(this.txtHighestLevel.EditValue);
            double floorHeight = Convert.ToDouble(this.txtFloorHeight.EditValue);
            double minFloorElev = Convert.ToDouble(this.txtBottomElevation.EditValue);
 
            var floorList = new List<(int FloorIndex, double Elevation)>();
            for (int i = minFloorIndex; i <= maxFloorIndex; i++)
            {
                var floorElevation = minFloorElev + (i - minFloorIndex) * floorHeight;
                floorList.Add((i, floorElevation));
            }
 
            int step = 1;
            int startIndex = 0;
            int endIndex = floorList.Count;
            var isDirectionUp = this.cmbDirection.SelectedItem as string == "向上" ? true : false;
            if (!isDirectionUp)
            {
                step = -1;
                startIndex = floorList.Count - 1;
                endIndex = -1;
            }
 
            var template = _template;
            var newNetWork = new MapViewNetWork();
            NodeViewModel lastNode = null;
            NodeViewModel newStartNode = null;
            for (int i = startIndex; isDirectionUp ? i < endIndex : i > endIndex; i += step)
            {
                var (FloorIndex, Elevation) = floorList[i];
 
                var templateNetWork = template.network;
                var startNode = templateNetWork.Nodes.Find(node => node.ID == template.Node1);
                if (startNode == null)
                    startNode = templateNetWork.Nodes[0];
                var newNode = new PointF3D(0 - startNode.X, 0 - startNode.Y, (float)Elevation - startNode.Elev);
 
                templateNetWork.Nodes
                    .Select(node => (NodeViewModel)node)
                    .ToList()
                    .ForEach(node =>
                    {
                        node.regionName = PBS.eWaterSupply.Low.ToString(); node.Floor = i.ToString();
                    });
 
                templateNetWork
                    .Links
                    .Select(link => (LinkViewModel)link)
                    .ToList()
                    .ForEach(link =>
                    {
                        link.regionName = PBS.eWaterSupply.Low.ToString(); link.Floor = i.ToString();
                    });
 
                var list = newNetWork.Add(templateNetWork, newNode, true);
                NodeViewModel CurrentPoint = (NodeViewModel)list[0];
                if (lastNode != null)
                {
                    var j = newNetWork.AddPipe(lastNode, CurrentPoint);
                    j.regionName = PBS.eWaterSupply.Low.ToString();
                }
                lastNode = (NodeViewModel)list[0];
                if (newStartNode == null)
                    newStartNode = lastNode;
            }
 
            Template newTemplate = new Template();
            newTemplate.network = newNetWork;
            newTemplate.Node1 = newStartNode.ID; 
            return newTemplate; 
        } 
 
        
        //数据验证
        private bool Verify()
        {
            var notError = true;
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(this.txtLowerLevel.Text))
            {
                notError = true;
                this.dxErrorProvider1.SetError(this.txtLowerLevel, "必填项");
            }
            if (string.IsNullOrEmpty(this.txtHighestLevel.Text))
            {
                notError = true;
                this.dxErrorProvider1.SetError(this.txtHighestLevel, "必填项");
            }
            if (string.IsNullOrEmpty(this.txtBottomElevation.Text))
            {
                notError = true;
                this.dxErrorProvider1.SetError(this.txtBottomElevation, "必填项");
            }
            if (string.IsNullOrEmpty(this.txtFloorHeight.Text))
            {
                notError = true;
                this.dxErrorProvider1.SetError(this.txtFloorHeight, "必填项");
            }
 
            return notError;
        }
 
 
 
        //确定
        private void GeneralOkAndCancelCtrl1_OkEvent()
        {
            if (!Verify())
            {
                return;
            }
 
            var template=CreateTemplate();
            if (template==null)
            {
                return;
            }  
 
            this.ReloadDataEvent?.Invoke(template);
            this.DialogResult = DialogResult.OK;
            this.Close();
 
        }
         
    }
}