Shuxia Ning
2024-12-24 5b2455c5dc3117471c620cc36af7fab483ccece9
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
using DevExpress.Utils.Svg;
using Mapster;
using MathNet.Numerics.LinearAlgebra.Factorization;
using Yw;
 
namespace HStation.WinFrmUI
{
    public partial class CreateXhsSchemeValveChangePage : DevExpress.XtraEditors.XtraUserControl, Yw.WinFrmUI.IWizardPage<CreateXhsSchemeViewModel>
    {
        public CreateXhsSchemeValveChangePage()
        {
            InitializeComponent();
            InitialLinkStatus();
            this.layoutView1.SetDefuaulView();
            this.layoutView1.SetFindPanel();
        }
 
        /// <summary>
        /// 页面状态改变事件
        /// </summary>
        public event Action PageStateChangedEvent;
 
        private CreateXhsSchemeViewModel _vm = null;//操作对象
        private bool _isInitialize = false;//是否初始化
 
        private HStation.Vmo.XhsProjectVmo _project = null;//项目
        private HStation.Vmo.XhsProjectSiteVmo _project_site = null;//项目站
        private List<CreateXhsSchemeValveChangeViewMdoel> _vm_list = null;
 
        //初始化状态
        private void InitialLinkStatus()
        {
            this.repImgCmbStatus.BeginUpdate();
            this.repImgCmbStatus.Items.Clear();
            this.repImgCmbStatus.Items.Add("默认", "默认", -1);
            this.repImgCmbStatus.Items.Add("开启", "开启", -1);
            this.repImgCmbStatus.Items.Add("关闭", "关闭", -1);
            this.repImgCmbStatus.EndUpdate();
        }
 
        /// <summary>
        /// 初始化
        /// </summary>
        public void InitialPage(CreateXhsSchemeViewModel t)
        {
            if (_isInitialize)
            {
                return;
            }
            _vm = t;
            _isInitialize = true;
            _project = t.Project;
            _project_site = t.ProjectSite;
            if (t.HydroInfo.Valves != null && t.HydroInfo.Valves.Any())
            {
                var svg = SvgImage.FromStream(new MemoryStream(HStation.WinFrmUI.Xhs.Core.Properties.Resources.valve));
 
                _vm_list = new List<CreateXhsSchemeValveChangeViewMdoel>();
                foreach (var valve in t.HydroInfo.Valves)
                {
                    var vm = new Yw.WinFrmUI.HydroValveViewModel(valve, t.HydroInfo);
                    _vm_list.Add(new CreateXhsSchemeValveChangeViewMdoel(vm, svg));
                }
            }
 
            this.createXhsSchemeValveChangeViewMdoelBindingSource.DataSource = _vm_list;
            this.createXhsSchemeValveChangeViewMdoelBindingSource.ResetBindings(false);
            ShowBimfaceCtrl();
            this.PageStateChangedEvent?.Invoke(); 
        }
 
        #region Bimface
 
        //bimface控件
        private SimulationBimfaceCtrl _bimfaceCtrl = null;
 
        //获取 bimface 控件
        private async Task<SimulationBimfaceCtrl> GetBimfaceCtrl()
        {
            if (_vm == null)
                return null;
            if (_bimfaceCtrl == null)
            {
                _bimfaceCtrl = new SimulationBimfaceCtrl();
                _bimfaceCtrl.Dock = DockStyle.Fill;
                await _bimfaceCtrl.InitialData(_project, _project_site);
                _bimfaceCtrl.HydroMouseLeftClickEvent += (code) =>
                {
                    if (_vm_list == null || !_vm_list.Any())
                        return;
                    var index = _vm_list.FindIndex(x => x.ViewModel.Code == code);
                    this.layoutView1.FocusedRowHandle = index;
                };
            }
            return _bimfaceCtrl;
        }
 
        //显示 bimface 控件
        private async void ShowBimfaceCtrl()
        {
            var bimfaceCtrl = await GetBimfaceCtrl();
            this.sidePanel3dModel.Controls.Clear();
            this.sidePanel3dModel.Controls.Add(bimfaceCtrl);
        }
 
        #endregion Bimface
 
        //保存
        private bool Save()
        {
            if (!_isInitialize)
            {
                return false;
            }
            if (_vm_list == null || !_vm_list.Any())
            {
                return false;
            }
            _vm_list.ForEach(x => x.ViewModel.UpdateVmoProperty());
            _vm.HydroInfo.Valves = _vm_list.Select(x => x.ViewModel.Vmo).ToList();
            return true;
        }
 
        //点击
        private async void layoutView1_CardClick(object sender, DevExpress.XtraGrid.Views.Layout.Events.CardClickEventArgs e)
        {
            var row = this.layoutView1.GetRow(e.RowHandle) as CreateXhsSchemeValveChangeViewMdoel;
            if (row == null)
                return;
            await _bimfaceCtrl?.ZoomAndSelectComponent(row.ViewModel.Code);
        }
 
        //选中列变换
        private void layoutView1_FocusedColumnChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedColumnChangedEventArgs e)
        {
            if (e.FocusedColumn == this.colModelType)
            {
                this.layoutView1.FocusedColumn = null;
                if (this.layoutView1.GetFocusedRow() is not CreateXhsSchemeValveChangeViewMdoel row)
                    return;
 
                var link_status = row.LinkStatus;
 
                var input = Yw.WinFrmUI.HydroMatchingHelper.Create(row.ViewModel.Vmo, _vm.HydroInfo);
                var dlg = new AssetsValveSingleMatchingDlg();
                dlg.SetBindingData(input);
                dlg.ReloadDataEvent += (output) =>
                {
                    Yw.WinFrmUI.HydroMatchingHelper.Apply(row.ViewModel, output);
                    row.LinkStatus = link_status;
                    if (!_vm.ChangeRecordList.Exists(x => x.Code == row.ViewModel.Code))
                    {
                        _vm.ChangeRecordList.Add(new(Yw.Hydro.ParterCatalog.Valve, row.ViewModel.Code, row.Name, row.SvgImage));
                    }
                };
                dlg.ShowDialog();
            }
        }
 
        //单元格值变换
        private void layoutView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            if (this.layoutView1.GetRow(e.RowHandle) is not CreateXhsSchemeValveChangeViewMdoel row)
                return;
            if (!_vm.ChangeRecordList.Exists(x => x.Code == row.ViewModel.Code))
            {
                _vm.ChangeRecordList.Add(new(Yw.Hydro.ParterCatalog.Valve, row.ViewModel.Code, row.Name, row.SvgImage));
            }
        }
 
        /// <summary>
        /// 允许上一步
        /// </summary>
        public bool AllowPrev
        {
            get
            {
                return true;
            }
        }
 
        /// <summary>
        /// 允许下一步
        /// </summary>
        public bool AllowNext
        {
            get
            {
                return _isInitialize;
            }
        }
 
        /// <summary>
        /// 允许取消
        /// </summary>
        public bool AllowCancel
        {
            get { return false; }
        }
 
        /// <summary>
        /// 允许完成
        /// </summary>
        public bool AllowComplete
        {
            get { return false; }
        }
 
        /// <summary>
        /// 能否上一步
        /// </summary>
        public bool CanPrev()
        {
            return true;
        }
 
        /// <summary>
        /// 能否下一步
        /// </summary>
        public bool CanNext()
        {
            if (!_isInitialize)
            {
                return false;
            }
            return Save();
        }
 
        /// <summary>
        /// 能否关闭
        /// </summary>
        public bool CanCancel()
        {
            return true;
        }
 
        /// <summary>
        /// 能否完成
        /// </summary>
        public bool CanComplete()
        {
            return false;
        }
    }
}