global using Yw.EPAnet; using HStation.WinFrmUI.Xhs; using HStation.WinFrmUI.Xhs.Core; using NPOI.SS.Formula.Functions; using Yw.WinFrmUI.HydroL2d; namespace HStation.WinFrmUI { public partial class XhsProjectSimulationCorePage : DocumentPage { public XhsProjectSimulationCorePage() { InitializeComponent(); this.PageTitle.Caption = "水力模拟"; this.PageTitle.HeaderSvgImage = this.svgImg32[0]; this.docPnlHydroCheck.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden; this.docPnlHydroCalcu.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden; this.docPnlHydroParterList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden; } private HStation.Vmo.XhsProjectVmo _project = null;//项目 private HStation.Vmo.XhsProjectSiteVmo _projectSite = null;//项目站 private Yw.Model.HydroModelInfo _hydroInfo = null;//水力信息 private List _fastShowHideCodeList = null;//显隐编码列表 private Yw.Model.HydroParterInfo _parter = null; private Yw.EPAnet.CheckResult _checkResult = null; private Yw.EPAnet.CalcuResult _calcuResult = null; /// /// 绑定数据 /// public async Task SetBindingData ( HStation.Vmo.XhsProjectVmo project, HStation.Vmo.XhsProjectSiteVmo projectSite, Yw.Model.HydroModelInfo hydroInfo ) { if (project == null) { return; } _project = project; _projectSite = projectSite; _hydroInfo = hydroInfo; if (_projectSite == null) { _projectSite = await BLLFactory.Instance.GetDefaultByProjectID(_project.ID); } if (_hydroInfo == null) { var hydroRelation = await BLLFactory.Instance .GetDefaultByObjectTypeAndObjectIDOfPurpose(HStation.Xhs.DataType.XhsProjectSite, _projectSite.ID, HStation.Xhs.Purpose.Simulation); _hydroInfo = await BLLFactory.Instance.GetByID(hydroRelation.ModelID); } this.xhsProjectSimulationQ3dCtrl1.SetBindingData(_hydroInfo); } /// /// 初始化数据 /// public override async void InitialDataSource() { base.InitialDataSource(); if (_project == null) { return; } this.PageTitle.Caption = $"{_project.Name}\r\n水力模拟"; await this.xhsProjectSimulationBimfaceCtrl1.SetBindingData(_project, _projectSite); } //属性面板获取水力信息事件 private Yw.Model.HydroModelInfo xhsProjectSimulationPropertyCtrl1_GetHydroInfoEvent() { 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.Waterboxs.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; 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; } //水力计算 private void barBtnHydroCalcu_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; var netWork = Yw.Hydro.ParseHelper.ToNetwork(_hydroInfo); _calcuResult = netWork.Calcu(); if (_calcuResult.Succeed) { ShowProperty(); TipFormHelper.ShowSucceed("计算成功!"); return; } this.xhsProjectSimulationHydroCalcuFailedCtrl1.SetBindingData(_calcuResult.FailedList); this.docPnlHydroCalcu.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible; } //水力构件列表 private void barBtnHydroParterList_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.hydroParterListCtrl1.SetBindingData(_hydroInfo); this.docPnlHydroParterList.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible; } //导出水力INP文件 private void barBtnHydroExportInp_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (_hydroInfo == null) { return; } var fileName = Yw.WinFrmUI.FileDialogHelper.SaveInp("导出Inp文件"); if (string.IsNullOrEmpty(fileName)) { return; } var netWork = Yw.Hydro.ParseHelper.ToNetwork(_hydroInfo); var result = netWork.ToInpString(); File.WriteAllText(fileName, result); TipFormHelper.ShowSucceed("导出成功"); } //bimface 构件点击 private void xhsProjectSimulationBimfaceCtrl1_ClickParterEvent(string objectId) { if (_hydroInfo == null) { return; } var allParterList = _hydroInfo.GetAllParters(); _parter = allParterList.Find(x => x.Code == objectId); ShowProperty(); } //显示属性 private void ShowProperty() { if (_hydroInfo == null) { return; } if (_parter == null) { return; } var allParterList = _hydroInfo.GetAllParters(); this.xhsProjectSimulationPropertyCtrl1.SelectParter(_parter, allParterList); if (_calcuResult != null) { if (_calcuResult.Succeed) { var allCalcuParterList = _calcuResult.GetParterList(); var calcuParter = allCalcuParterList.Find(x => x.Id == _parter.Code); if (calcuParter != null) { IHydroCalcuProperty calcuProperty = null; if (calcuParter is Yw.EPAnet.CalcuNode calcuNode) { var calcuNodeProperty = new Yw.WinFrmUI.HydroCalcuNodeProperty(); calcuNodeProperty.ID = _parter.ID; calcuNodeProperty.CalcuPress = calcuNode.Press; calcuNodeProperty.CalcuDemand = calcuNode.Demand; calcuNodeProperty.CalcuHead = calcuNode.Head; calcuProperty = calcuNodeProperty; } else if (calcuParter is Yw.EPAnet.CalcuLink calcuLink) { var calcuLinkProperty = new Yw.WinFrmUI.HydroCalcuLinkProperty(); calcuLinkProperty.ID = _parter.ID; calcuLinkProperty.CalcuHeadLoss = calcuLink.Headloss; calcuLinkProperty.CalcuFlow = calcuLink.Flow; calcuLinkProperty.CalcuVelocity = calcuLink.Velocity; calcuProperty = calcuLinkProperty; } if (calcuProperty != null) { this.xhsProjectSimulationPropertyCtrl1.UpdateCalcuProperty(calcuProperty); } } } } } //保存 private async void barBtnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (_hydroInfo == null) { return; } var id = await BLLFactory.Instance.Save(_hydroInfo); if (id < 1) { TipFormHelper.ShowError("保存失败!"); return; } _hydroInfo = await BLLFactory.Instance.GetByID(id); //this.xhsProjectSimulationPropertyCtrl1.SetBindingData(_hydroInfo); TipFormHelper.ShowSucceed("保存成功!"); } //自动匹配 private void barBtnAllAutoMatching_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { var dlg = new AssetsAutoMatchingMainDlg(new AssetsAutoMatchingInputViewModel()); dlg.ShowDialog(); } 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() { obj }); var allParterList = _hydroInfo.GetAllParters(); _parter = allParterList.Find(x => x.Code == obj); ShowProperty(); } //水力构件明细面板点击事件 private async void hydroParterListCtrl1_HydroClickEvent(Yw.Model.HydroParterInfo parter) { _parter = parter; await this.xhsProjectSimulationBimfaceCtrl1.SetSelectedComponents(new List() { parter.Code }); ShowProperty(); } } }