Shuxia Ning
2024-09-26 502ed6f01f605098d46a1fe9f55f416d5c5c3e13
WinFrmUI/HStation.WinFrmUI.Xhs.Core/04-simulation/06-simulation/XhsProjectSimulationCorePage.cs
@@ -4,6 +4,7 @@
using HStation.WinFrmUI.Xhs.Core;
using NPOI.SS.Formula.Functions;
using Yw.WinFrmUI.HydroL2d;
using Yw.WinFrmUI.HydroL3d;
namespace HStation.WinFrmUI
{
@@ -19,13 +20,12 @@
            this.docPnlHydroParterList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlUnMatchingList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlMatchingList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.assetsMainChoicePage1.FormRowClickEvent += xhsProjectSimulationHydroCheckFailedCtrl1_HydroClickEvent;
            this.xhsProjectSimulationMatchingListCtrl1.FormRowClickEvent += xhsProjectSimulationHydroCheckFailedCtrl1_HydroClickEvent;
        }
        private HStation.Vmo.XhsProjectVmo _project = null;//项目
        private HStation.Vmo.XhsProjectSiteVmo _projectSite = null;//项目站
        private Yw.Model.HydroModelInfo _hydroInfo = null;//水力信息
        private List<string> _fastShowHideCodeList = null;//显隐编码列表
        private Yw.Model.HydroParterInfo _parter = null;
        private Yw.EPAnet.CheckResult _checkResult = null;
@@ -58,8 +58,6 @@
                    .GetDefaultByObjectTypeAndObjectIDOfPurpose(HStation.Xhs.DataType.XhsProjectSite, _projectSite.ID, HStation.Xhs.Purpose.Simulation);
                _hydroInfo = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.GetByID(hydroRelation.ModelID);
            }
            this.xhsProjectSimulationQ3dCtrl1.SetBindingData(_hydroInfo);
            this.xhsProjectSimulationL3dCtrl1.SetBindingData(_hydroInfo);
        }
        /// <summary>
@@ -73,7 +71,9 @@
                return;
            }
            this.PageTitle.Caption = $"{_project.Name}\r\n水力模拟";
            await this.xhsProjectSimulationBimfaceCtrl1.SetBindingData(_project, _projectSite);
            await this.xhsProjectSimulationBimfaceCtrl1.SetBindingData(_project, _projectSite, () => _hydroInfo);
            this.xhsProjectSimulationQ3dCtrl1.SetBindingData(_hydroInfo);
            this.xhsProjectSimulationL3dCtrl1.SetBindingData(_hydroInfo);
        }
        //属性面板获取水力信息事件
@@ -82,55 +82,8 @@
            return _hydroInfo;
        }
        //一键显隐
        private async void barBtnShowHide_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_hydroInfo == null)
            {
                return;
            }
            if (_hydroInfo.Decorators == null || _hydroInfo.Decorators.Count < 1)
            {
                return;
            }
            if (_fastShowHideCodeList == null)
            {
                _fastShowHideCodeList = _hydroInfo.Decorators.Select(x => x.Code).ToList();
                await this.xhsProjectSimulationBimfaceCtrl1.HideComponents(_fastShowHideCodeList);
            }
            else
            {
                await this.xhsProjectSimulationBimfaceCtrl1.ShowComponents(_fastShowHideCodeList);
                _fastShowHideCodeList = null;
            }
        }
        //水力验证
        private void barBtnHydroCheck_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_hydroInfo == null)
            {
                return;
            }
            this.docPnlHydroCheck.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlHydroCalcu.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlHydroParterList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlUnMatchingList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            var netWork = Yw.Hydro.ParseHelper.ToNetwork(_hydroInfo);
            _checkResult = netWork.Check();
            if (_checkResult.Succeed)
            {
                TipFormHelper.ShowSucceed("校验通过!");
                return;
            }
            this.xhsProjectSimulationHydroCheckFailedCtrl1.SetBindingData(_checkResult.FailedList);
            this.docPnlHydroCheck.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible;
            this.docPnlHydroCheck.Height = 350;
        }
        //水力计算
        private void barBtnHydroCalcu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        private async void barBtnHydroCalcu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_hydroInfo == null)
            {
@@ -147,11 +100,14 @@
            {
                ShowProperty();
                TipFormHelper.ShowSucceed("计算成功!");
                return;
            }
            this.xhsProjectSimulationHydroCalcuFailedCtrl1.SetBindingData(_calcuResult.FailedList);
            this.docPnlHydroCalcu.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible;
            this.docPnlHydroCalcu.Height = 350;
            else
            {
                this.xhsProjectSimulationHydroCalcuFailedCtrl1.SetBindingData(_calcuResult.FailedList);
                this.docPnlHydroCalcu.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible;
                this.docPnlHydroCalcu.Height = 350;
            }
            await this.xhsProjectSimulationBimfaceCtrl1.ShowCalcuCustomLabels(_calcuResult);
        }
        //水力构件列表
@@ -190,19 +146,228 @@
            TipFormHelper.ShowSucceed("导出成功");
        }
        //水力构件明细面板点击事件
        private async void hydroParterListCtrl1_HydroClickEvent(Yw.Model.HydroParterInfo parter)
        {
            var allParterList = _hydroInfo.GetAllParters();
            _parter = allParterList.Find(x => x.ID == parter.ID);
            await this.xhsProjectSimulationBimfaceCtrl1.SetSelectedComponents(new List<string>() { _parter.Code });
            ShowProperty();
        }
        #region Bimface
        //bimface 构件点击
        private void xhsProjectSimulationBimfaceCtrl1_ClickParterEvent(string objectId)
        //bimface 加载完成事件
        private async void xhsProjectSimulationBimfaceCtrl1_LoadCompletedEvent()
        {
            if (_hydroInfo == null)
            {
                return;
            }
            var elementIds = new List<string>();
            var pumps = _hydroInfo.Pumps?.Where(x => x.LinkStatus == Yw.Hydro.PumpStatus.Open).ToList();
            pumps?.ForEach(x => elementIds.Add(x.Code));
            var valves = _hydroInfo.Valves?.Where(x => x.LinkStatus == Yw.Hydro.ValveStatus.Open).ToList();
            valves?.ForEach(x => elementIds.Add(x.Code));
            await this.xhsProjectSimulationBimfaceCtrl1.SetOpenComponentsColor(elementIds);
        }
        //bimface 水力点击事件
        private void xhsProjectSimulationBimfaceCtrl1_HydroClickEvent(Yw.Model.HydroParterInfo obj)
        {
            if (_hydroInfo == null)
            {
                return;
            }
            _parter = obj;
            ShowProperty();
            SetBimfaceLinkColor();
        }
        //设置Bimface连接颜色
        private async void SetBimfaceLinkColor()
        {
            if (_hydroInfo == null)
            {
                return;
            }
            List<string> elementIds = null;
            if (_parter != null)
            {
                if (_parter is Yw.Model.HydroLinkInfo linker)
                {
                    elementIds = new List<string>() { linker.StartCode, linker.EndCode };
                }
            }
            await this.xhsProjectSimulationBimfaceCtrl1.SetLinkComponentsColor(elementIds);
        }
        #endregion Bimface
        #region 自动匹配
        //自动匹配
        private void barBtnMatching_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_hydroInfo == null)
            {
                return;
            }
            this.docPnlHydroCheck.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlHydroCalcu.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlHydroParterList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlMatchingList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlUnMatchingList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            var input = AssetsMatchingParasHelper.Create(_hydroInfo);
            this.xhsProjectSimulationMatchingListCtrl1.SetBindingData(input);
            this.xhsProjectSimulationMatchingListCtrl1.RelaodEvent += (output) =>
            {
                return AssetsMatchingParasHelper.Apply(_hydroInfo, output);
            };
            this.docPnlMatchingList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible;
            this.docPnlMatchingList.Height = 350;
        }
        #endregion
        #region 未匹配列表
        //未匹配列表
        private void barBtnUnMatchingList_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_hydroInfo == null)
            {
                return;
            }
            this.docPnlHydroCheck.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlHydroCalcu.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlHydroParterList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlMatchingList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlUnMatchingList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.xhsProjectSimulationUnMatchingListCtrl1.SetBindingData(_hydroInfo);
            this.docPnlUnMatchingList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible;
            this.docPnlUnMatchingList.Height = 350;
        }
        //未匹配列表点击事件
        private async void xhsProjectSimulationUnMatchingListCtrl1_HydroClickEvent(Yw.Model.HydroParterInfo parter)
        {
            var allParterList = _hydroInfo.GetAllParters();
            _parter = allParterList.Find(x => x.ID == parter.ID);
            var elementIds = new List<string>() { _parter.Code };
            await this.xhsProjectSimulationBimfaceCtrl1.ZoomAndSelectComponents(elementIds);
            ShowProperty();
            SetBimfaceLinkColor();
        }
        //未匹配列表查看模型
        private async void xhsProjectSimulationUnMatchingListCtrl1_ViewModelEvent(List<Yw.Model.HydroParterInfo> parters)
        {
            var codes = parters?.Select(x => x.Code).Distinct().ToList();
            await this.xhsProjectSimulationBimfaceCtrl1.ZoomAndSelectComponents(codes);
            _parter = null;
            ShowProperty();
        }
        #endregion
        #region 一键显隐
        //显隐编码列表
        private List<string> _fastShowHideCodeList = null;
        //触发一键显隐
        private async void barBtnShowHide_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_hydroInfo == null)
            {
                return;
            }
            if (_hydroInfo.Decorators == null || _hydroInfo.Decorators.Count < 1)
            {
                return;
            }
            if (_fastShowHideCodeList == null)
            {
                _fastShowHideCodeList = _hydroInfo.Decorators.Select(x => x.Code).ToList();
                await this.xhsProjectSimulationBimfaceCtrl1.HideComponents(_fastShowHideCodeList);
            }
            else
            {
                await this.xhsProjectSimulationBimfaceCtrl1.ShowComponents(_fastShowHideCodeList);
                _fastShowHideCodeList = null;
            }
        }
        #endregion
        #region 水力校验
        //水力验证
        private void barBtnHydroCheck_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_hydroInfo == null)
            {
                return;
            }
            this.docPnlHydroCheck.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlHydroCalcu.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlHydroParterList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlUnMatchingList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlMatchingList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            var netWork = Yw.Hydro.ParseHelper.ToNetwork(_hydroInfo);
            _checkResult = netWork.Check();
            if (_checkResult.Succeed)
            {
                TipFormHelper.ShowSucceed("校验通过!");
                return;
            }
            this.xhsProjectSimulationHydroCheckFailedCtrl1.SetBindingData(_checkResult.FailedList);
            this.docPnlHydroCheck.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible;
            this.docPnlHydroCheck.Height = 350;
        }
        //水力校验点击
        private async void xhsProjectSimulationHydroCheckFailedCtrl1_HydroClickEvent(string code)
        {
            if (_hydroInfo == null)
            {
                return;
            }
            var allParterList = _hydroInfo.GetAllParters();
            _parter = allParterList.Find(x => x.Code == objectId);
            _parter = allParterList.Find(x => x.Code == code);
            var elementIds = new List<string>() { _parter.Code };
            await this.xhsProjectSimulationBimfaceCtrl1.ZoomAndSelectComponents(elementIds);
            ShowProperty();
        }
        #endregion
        #region 保存水力信息
        //保存
        private async void barBtnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_hydroInfo == null)
            {
                return;
            }
            var id = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.Save(_hydroInfo);
            if (id < 1)
            {
                TipFormHelper.ShowError("保存失败!");
                return;
            }
            _hydroInfo = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.GetByID(id);
            TipFormHelper.ShowSucceed("保存成功!");
        }
        #endregion
        #region 业务方法
        //显示属性
        private void ShowProperty()
@@ -213,10 +378,10 @@
            }
            if (_parter == null)
            {
                this.xhsProjectSimulationPropertyCtrl1.SelectParter(null);
                return;
            }
            var allParterList = _hydroInfo.GetAllParters();
            this.xhsProjectSimulationPropertyCtrl1.SelectParter(_parter, allParterList);
            this.xhsProjectSimulationPropertyCtrl1.SelectParter(_parter.Code);
            if (_calcuResult != null)
            {
                if (_calcuResult.Succeed)
@@ -254,186 +419,18 @@
            }
        }
        //保存
        private async void barBtnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        #endregion 业务方法
        #region 配置
        //显示RadialMenu
        private void barBtnSetList_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_hydroInfo == null)
            {
                return;
            }
            var id = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.Save(_hydroInfo);
            if (id < 1)
            {
                TipFormHelper.ShowError("保存失败!");
                return;
            }
            _hydroInfo = await BLLFactory<Yw.BLL.HydroModelInfo>.Instance.GetByID(id);
            //this.xhsProjectSimulationPropertyCtrl1.SetMatching(_hydroInfo);
            TipFormHelper.ShowSucceed("保存成功!");
            this.rmSet.ShowPopup(MousePosition, true);
        }
        //自动匹配
        private void barBtnAllAutoMatching_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_hydroInfo == null)
            {
                return;
            }
            var input = new AssetsAutoMatchingViewModel();
            input.PumpMatchingModels = _hydroInfo.Pumps?.Select(x => new PumpMatchingViewModel()
            {
                ID = x.ID,
                Code = x.Code,
                Name = x.Name,
                DbID = x.DbId,
                DbLocked = x.DbLocked,
                ChartDbID = _hydroInfo.Curves?.Find(t => t.Code == x.CurveQH)?.DbId,
                ModelType = x.ModelType,
                RatedP = x.RatedP,
                RatedH = x.RatedH,
                RatedN = x.RatedN,
                RatedQ = x.RatedQ,
            }).ToList();
            input.ElbowsMatchingModels = _hydroInfo.Elbows?.Select(x => new ElbowsMatchingViewModel()
            {
                ID = x.ID,
                Name = x.Name,
                Code = x.Code,
                Dbid = x.DbId,
                DbLocked = x.DbLocked,
                ModelType = x.ModelType,
                Caliber = x.Caliber,
                Material = x.Material
            }).ToList();
            input.ThreeLinkMatchingModels = _hydroInfo.Threelinks?.Select(x => new ThreeLinkMatchingViewModel()
            {
                ID = x.ID,
                Name = x.Name,
                Code = x.Code,
                DbId = x.DbId,
                DbLocked = x.DbLocked,
                ModelType = x.ModelType,
                Caliber = x.Caliber,
                Material = x.Material
            }).ToList();
            input.FourLinkMatchingModels = _hydroInfo.Fourlinks?.Select(x => new FourLinkMatchingViewModel()
            {
                ID = x.ID,
                Name = x.Name,
                Code = x.Code,
                Dbid = x.DbId,
                DbLocked = x.DbLocked,
                ModelType = x.ModelType,
                Caliber = x.Caliber,
                Material = x.Material
            }).ToList();
            input.PipeLineMatchingModels = _hydroInfo.Pipes?.Select(x => new PipeLineMatchingViewModel()
            {
                ID = x.ID,
                Name = x.Name,
                Code = x.Code,
                DbId = x.DbId,
                DbLocked = x.DbLocked,
                ModelType = x.ModelType,
                Caliber = x.Diameter,//这里是数值
                Material = x.Material
            }).ToList();
            input.ValveMatchingModels = _hydroInfo.Pipes?.Select(x => new ValveMatchingViewModel()
            {
                ID = x.ID,
                Name = x.Name,
                Code = x.Code,
                DbId = x.DbId,
                DbLocked = x.DbLocked,
                ModelType = x.ModelType,
                Caliber = x.Diameter,//这里是数值
                Material = x.Material//怎么没有阀门类型
            }).ToList();
            this.docPnlHydroCheck.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlHydroCalcu.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlHydroParterList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlUnMatchingList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.hydroParterListCtrl1.SetBindingData(_hydroInfo);
            this.docPnlHydroParterList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlMatchingList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible;
            this.docPnlMatchingList.Height = 350;
            this.assetsMainChoicePage1.SetBindingData(input);
            this.assetsMainChoicePage1.RelaodEvent += (rhs) =>
                 {
                     return false;
                 };
        }
        private void BtnPerformChart_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var dlg = new PerformChart();
            dlg.ShowDialog();
        }
        //水力校验点击
        private async void xhsProjectSimulationHydroCheckFailedCtrl1_HydroClickEvent(string obj)
        {
            if (_hydroInfo == null)
            {
                return;
            }
            await this.xhsProjectSimulationBimfaceCtrl1.SetSelectedComponents(new List<string>() { obj });
            var allParterList = _hydroInfo.GetAllParters();
            _parter = allParterList.Find(x => x.Code == obj);
            ShowProperty();
        }
        //水力构件明细面板点击事件
        private async void hydroParterListCtrl1_HydroClickEvent(Yw.Model.HydroParterInfo parter)
        {
            var allParterList = _hydroInfo.GetAllParters();
            _parter = allParterList.Find(x => x.ID == parter.ID);
            await this.xhsProjectSimulationBimfaceCtrl1.SetSelectedComponents(new List<string>() { _parter.Code });
            ShowProperty();
        }
        #region 未匹配列表
        //未匹配列表
        private void barBtnUnMatchingList_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_hydroInfo == null)
            {
                return;
            }
            this.docPnlHydroCheck.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlHydroCalcu.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlHydroParterList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlUnMatchingList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.docPnlMatchingList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            this.xhsProjectSimulationUnMatchingListCtrl1.SetBindingData(_hydroInfo);
            this.docPnlUnMatchingList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible;
            this.docPnlUnMatchingList.Height = 350;
        }
        //未匹配列表点击事件
        private async void xhsProjectSimulationUnMatchingListCtrl1_HydroClickEvent(Yw.Model.HydroParterInfo parter)
        {
            var allParterList = _hydroInfo.GetAllParters();
            _parter = allParterList.Find(x => x.ID == parter.ID);
            var elementIds = new List<string>() { _parter.Code };
            await this.xhsProjectSimulationBimfaceCtrl1.ZoomAndSelectComponents(elementIds);
            ShowProperty();
        }
        //未匹配列表查看模型
        private async void xhsProjectSimulationUnMatchingListCtrl1_ViewModelEvent(List<Yw.Model.HydroParterInfo> parters)
        {
            var codes = parters?.Select(x => x.Code).Distinct().ToList();
            await this.xhsProjectSimulationBimfaceCtrl1.ZoomAndSelectComponents(codes);
            _parter = null;
            ShowProperty();
        }
        #endregion
    }
}