cloudflight
2023-12-02 c0f9915265878e56e91ee97f7f8d925db1e12626
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
using CommonBase;
//using ConfigApp;
using Hydro.MapView;
//using DevExpress.XtraEditors;
//using DevExpress.XtraGrid.Views.Base;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using TRegion = Hydro.MapView.TRegion;
 
namespace Hydro.MapUI
{
    public partial class Form_EditFloors : Form
    {
        private List<TRegion> regions= new List<TRegion>();
        private TRegion CurrentRegion
        {
            get {
                if (regions.Count == 0)
                {
                    regions.Add(new TRegion());
                    UpdateRegionList();
                }
                return regions[comboBox1.SelectedIndex]; 
            }
        }
        private List<Floor> floors 
        { 
            get 
            { 
                if (regions.Count == 0)
                {
                    regions.Add(new TRegion());
                    UpdateRegionList();
                }
                    
 
                if (CurrentRegion != null) return CurrentRegion.Floors;
                return null;
            }
            set 
            { 
                if (regions.Count == 0) regions.Add(new TRegion());  regions[0].Floors = value; 
            }
        }
        private Stack<List<TRegion>> undoStack;
        private Stack<List<TRegion>> redoStack;
        MapViewer map;
        public Form_EditFloors(List<TRegion> regions)
        {
            InitializeComponent();
            //comboBox1.DataSource = this.regions;
            
            
           
            this.regions = regions;
            //floors = new List<Floor>();
            undoStack = new Stack<List<TRegion>>();
            redoStack = new Stack<List<TRegion>>();
        }
        
        private void Form_EditFloors_Load(object sender,EventArgs e)
        {
 
            UpdateRegionList();
 
            lockEditing(false);
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            UpdateFloorList();
   
            
            map = new MapViewer();
            map.Location = new System.Drawing.Point(0, 0);
            //map.Size = new Size(500, 500);
            map.Dock = DockStyle.Fill;
            map.Lock2DView = true;
            //gen();
 
            groupControl4.Controls.Add(map);
 
            //if (GlobalObject.PropertyForm == null)
            //{
            //    GlobalObject.PropertyForm = new PropertyForm();
            //    GlobalObject.PropertyForm.SetWindows(this);
            //    GlobalObject.PropertyForm.Show();
 
            //}
            if (GlobalObject.map == null)
            {
                GlobalObject.map = map;
 
            }
 
        }
        private void AddFloorButton_Click(object sender, EventArgs e)
        {
            Floor newFloor = new Floor();
            newFloor.FloorIndex = floors.Count + 1;
            floors.Add(newFloor);
 
            UpdateFloorList();
            FloorsListBox.SelectedItem = newFloor;
            //foreach (Floor f in FloorsListBox.Items)
            //{
            //    if (newFloor==f)
            //    {
            //        FloorsListBox.SelectedItem = newFloor;
            //        break;
            //    }
            //}
        }
 
        private void DeleteFloorButton_Click(object sender, EventArgs e)
        {
            if (FloorsListBox.SelectedIndex != -1)
            {
                int selectedIndex = FloorsListBox.SelectedIndex;
                Floor removedFloor = floors[selectedIndex];
                floors.RemoveAt(selectedIndex);
 
                // Save the current state for undo
                undoStack.Push(new List<TRegion>(regions));
 
                // Clear redo stack since a new operation is performed
                redoStack.Clear();
 
                UpdateFloorList();
            }
        }
        private void UpdateRegionList()
        {
            comboBox1.Items.Clear();
            foreach (TRegion region in regions)
            {
                comboBox1.Items.Add($"{region.Name}");
            }
            if (comboBox1.Items.Count>0)
                comboBox1.SelectedIndex = 0;
        }
        private void UpdateFloorList()
        {
            FloorsListBox.Items.Clear();
            foreach (Floor floor in floors)
            {
                FloorsListBox.Items.Add($"{floor.FloorIndex}楼");
            }
            
            comboBox2.SelectedIndex=CurrentRegion.isDirectionUp ? 0 : 1;
        }
 
        private void UndoButton_Click(object sender, EventArgs e)
        {
            if (undoStack.Count > 0)
            {
                redoStack.Push(new List<TRegion>(regions));
                regions = undoStack.Pop();
 
                UpdateFloorList();
            }
        }
 
        private void RedoButton_Click(object sender, EventArgs e)
        {
            if (redoStack.Count > 0)
            {
                undoStack.Push(new List<TRegion>(regions));
                regions = redoStack.Pop();
 
                UpdateFloorList();
            }
        }
        private Floor copiedFloor; // 保存被复制的楼层
 
        private void CopyFloorButton_Click(object sender, EventArgs e)
        {
            if (FloorsListBox.SelectedIndex != -1)
            {
                int selectedIndex = FloorsListBox.SelectedIndex;
                copiedFloor = new Floor(floors[selectedIndex]);
            }
        }
 
        private void PasteFloorButton_Click(object sender, EventArgs e)
        {
            if (copiedFloor != null)
            {
                floors.Add(new Floor(copiedFloor));
                // Save the current state for undo
                undoStack.Push(new List<TRegion>(regions));
 
                // Clear redo stack since a new operation is performed
                redoStack.Clear();
                UpdateFloorList();
            }
        }
 
        private void EditFloorButton_Click(object sender, EventArgs e)
        {
            if (FloorsListBox.SelectedIndex != -1)
            {
                lockEditing();
                int selectedIndex = FloorsListBox.SelectedIndex;
                Floor selectedFloor = floors[selectedIndex];
 
                // 显示并允许编辑楼层属性的组件
                EditProperties(selectedFloor);
            }
        }
 
        private void lockEditing(bool state=true)
        {
            simpleButton4.Enabled = !state;
            FloorsListBox.Enabled = !state;
            SaveButton.Enabled = state;
            CancelButton.Enabled = state;
            simpleButton1.Enabled = state;
            FloorIndexTextBox.ReadOnly = !state;
            BackgroundImgTextBox.ReadOnly = !state;
            ElevTextBox.ReadOnly = !state;
            
        }
 
        private void FloorsListBox_Click(object sender, EventArgs e)
        {
            
        }
 
        private void EditProperties(Floor floor)
        {
            FloorIndexTextBox.Text = floor.FloorIndex.ToString();
            BackgroundImgTextBox.Text = floor.TemplateID ?? "";
            ElevTextBox.Text = floor.Elev.ToString();
            //MapViewTextBox.Text = floor.MapView?.ToString() ?? "";
 
            
 
            SaveButton.Visible = true;
            CancelButton.Visible = true;
        }
 
        private void SaveButton_Click(object sender, EventArgs e)
        {
            int selectedIndex = FloorsListBox.SelectedIndex;
            if (selectedIndex == -1 || selectedIndex >= floors.Count) return;
 
            Floor editedFloor = floors[selectedIndex];
 
            //editedFloor.BackgroundImg = BackgroundImgTextBox.Text;
            editedFloor.TemplateID = BackgroundImgTextBox.Text;
            editedFloor.Elev = float.Parse(ElevTextBox.Text);
            //editedFloor.MapView = new MapDimensions(MapViewTextBox.Text);
 
            UpdateFloorList();
 
            ClearProperties();
            // Save the current state for undo
            undoStack.Push(new List<TRegion>(regions));
 
            // Clear redo stack since a new operation is performed
            redoStack.Clear();
            lockEditing(false);
        }
        private void SelectImageButton_Click(object sender, EventArgs e)
        {
            //OpenFileDialog openFileDialog = new OpenFileDialog();
            //openFileDialog.Filter = "Image Files (*.jpg;*.jpeg;*.png;*.gif;*.bmp)|*.jpg;*.jpeg;*.png;*.gif;*.bmp";
 
            //if (openFileDialog.ShowDialog() == DialogResult.OK)
            //{
            //    BackgroundImgTextBox.Text = openFileDialog.FileName;
            //}
            int selectedIndex = FloorsListBox.SelectedIndex;
            if (selectedIndex == -1 || selectedIndex >= floors.Count) return;
            Floor editedFloor = floors[selectedIndex];
            模板管理 fs = new 模板管理(true);
            if (fs.ShowDialog()==DialogResult.OK)
            {
                BackgroundImgTextBox.Text = fs.TemplateID;
                //editedFloor.TemplateID = fs.TemplateID;
                map.SetData(TemplateList.GetTemplate(fs.TemplateID));
            }
 
        }
        private void CancelButton_Click(object sender, EventArgs e)
        {
            ClearProperties();
            lockEditing(false);
        }
        private void ClearFloorsButton_Click(object sender, EventArgs e)
        {
            floors.Clear();
            UpdateFloorList();
            // Save the current state for undo
            undoStack.Push(new List<TRegion>(regions));
 
            // Clear redo stack since a new operation is performed
            redoStack.Clear();
        }
 
        private void ClearProperties()
        {
            FloorIndexTextBox.Text = "";
            BackgroundImgTextBox.Text = "";
            ElevTextBox.Text = "";
            //MapViewTextBox.Text = "";
 
            FloorIndexTextBox.Enabled = true;
 
            SaveButton.Visible = false;
            CancelButton.Visible = false;
        }
 
        private void 退出XToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        private void GenerateFloorsButton_Click(object sender, EventArgs e)
        {
            // 隐藏错误标签
            ErrorLabel.Visible = false;
 
            int minFloorIndex;
            int maxFloorIndex;
            float floorHeight;
            float minFloorElev;
 
            // 尝试解析文本框中的值
            if (!int.TryParse(tb_minFloorIndex.Text, out minFloorIndex))
            {
                ErrorLabel.Text = "最小层号必须是整数";
                ErrorLabel.Visible = true;
                return;
            }
            if (!int.TryParse(tb_maxFloorIndex.Text, out maxFloorIndex))
            {
                ErrorLabel.Text = "最大层号必须是整数";
                ErrorLabel.Visible = true;
                return;
            }
            if (!float.TryParse(tb_Height.Text, out floorHeight))
            {
                ErrorLabel.Text = "每层层高必须是数字";
                ErrorLabel.Visible = true;
                return;
            }
            if (!float.TryParse(tb_minFloorElev.Text, out minFloorElev))
            {
                ErrorLabel.Text = "最低层地面高程必须是数字";
                ErrorLabel.Visible = true;
                return;
            }
 
            string tempID = BackgroundImgTextBox_q.Text;
 
            // 逐层生成楼层
            for (int i = minFloorIndex; i <= maxFloorIndex; i++)
            {
                float floorElev = minFloorElev + (i - minFloorIndex) * floorHeight;
                Floor newFloor = new Floor(i, tempID, floorElev, null);
                floors.Add(newFloor);
            }
 
            // 更新楼层列表
            UpdateFloorList();
        }
 
        private void SelectImageButton_Click_q(object sender, EventArgs e)
        {
            //OpenFileDialog openFileDialog = new OpenFileDialog();
            //openFileDialog.Filter = "Image Files (*.jpg;*.jpeg;*.png;*.gif;*.bmp)|*.jpg;*.jpeg;*.png;*.gif;*.bmp";
 
            //if (openFileDialog.ShowDialog() == DialogResult.OK)
            //{
            //    BackgroundImgTextBox_q.Text = openFileDialog.FileName;
            //}
            //int selectedIndex = FloorsListBox.SelectedIndex;
            //if (selectedIndex == -1 || selectedIndex >= floors.Count) return;
            //Floor editedFloor = floors[selectedIndex];
            模板管理 fs = new 模板管理(true);
            if (fs.ShowDialog() == DialogResult.OK)
            {
                BackgroundImgTextBox_q.Text = fs.TemplateID;
                //editedFloor.TemplateID = fs.TemplateID;
                //map.SetData(TemplateList.GetTemplate(fs.TemplateID));
            }
 
        }
 
        private void FloorsListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (FloorsListBox.SelectedIndex != -1)
            {
                int selectedIndex = FloorsListBox.SelectedIndex;
                Floor selectedFloor = floors[selectedIndex];
 
                // 显示并允许编辑楼层属性的组件
                EditProperties(selectedFloor);
                var template = TemplateList.GetTemplate(selectedFloor.TemplateID);
                ////if (template != null)
                ////    this.map.SetData(template);
 
 
            }
        }
 
        private void simpleButton9_Click(object sender, EventArgs e)
        {
            InputBox inputBox = new InputBox();
            string name= inputBox.ShowDialog();
            if (name.Trim() !="" && name!=null)
            {
                var region = new TRegion() { Name = name };
                if (regions.Find(r => r.Name == region.Name) != null)
                {
                    MessageBox.Show($"名称重复[{region.Name}]");
                    return;
                }
                regions.Add(region);
                UpdateRegionList();
            }
            
        }
 
        private void simpleButton10_Click(object sender, EventArgs e)
        {
            if (message.show("", "确认删除", MessageBoxButtons.YesNo))
            {
                regions.RemoveAt(comboBox1.SelectedIndex);
                UpdateRegionList();
            }
           
            
        }
 
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdateFloorList();
        }
 
        private void InsertIntoNet_Click(object sender, EventArgs e)
        {
            int step = 1;
            int startIndex = 0;
            int endIndex = CurrentRegion.Floors.Count;
            if (!CurrentRegion.isDirectionUp)
            {
                step = -1;
                startIndex = CurrentRegion.Floors.Count - 1;
                endIndex = -1;
            }
            MapViewNetWork net = new MapViewNetWork();
            Floor lastFloor = null;
            NodeViewModel lastPoint = null;
            NodeViewModel node1 = null;
            for(int i=startIndex; CurrentRegion.isDirectionUp?i < endIndex:i>endIndex;i+=step)
            {
                var floor = CurrentRegion.Floors[i];
                if (floor.template.network==null)
                {
                    floor.template.loadInpFile();
                    
                }
                var n= floor.template.network;
                var point = n.Nodes.Find(node => node.ID==floor.template.Node1);
                if (point == null) point = n.Nodes[0];
                PointF3D p = new PointF3D(0- point.X, 0- point.Y, floor.Elev-point.Elev);
                n.Nodes.ForEach(node => { node.regionName = CurrentRegion.Name; });
                n.Links.ForEach(link => { link.regionName = CurrentRegion.Name; });
                var list=net.Add(n, p,true);
                NodeViewModel CurrentPoint = (NodeViewModel)list[0];
                if (lastPoint!=null)
                {
                    var j=net.AddPipe(lastPoint, CurrentPoint);
                    j.regionName = CurrentRegion.Name;
                }
                lastPoint = (NodeViewModel)list[0];
                if (node1 == null) node1 = lastPoint;
                
            }
            Template temp=new Template();
            temp.network = net;
            temp.Node1 = node1.ID;
            GlobalObject.map.InsertNet(temp);
            this.Close();
 
        }
 
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurrentRegion.isDirectionUp = comboBox2.SelectedIndex == 0;
        }
    }
 
 
}