Shuxia Ning
2024-11-25 d4898c5d7e1bbbbba384a0e29f29c066d6f502a7
WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-simulation/02-bimface/XhsProjectSimulationBimfaceCtrl.cs
@@ -1,34 +1,64 @@
using DevExpress.Xpo.Helpers;
using Yw.WinFrmUI.Bimface;
using Yw.WinFrmUI.Bimface;
namespace HStation.WinFrmUI
{
    public partial class XhsProjectSimulationBimfaceCtrl : DevExpress.XtraEditors.XtraUserControl
    public partial class XhsProjectSimulationBimfaceCtrl : DevExpress.XtraEditors.XtraUserControl, ISimulationFlowEffectView, ISimulationVisualVisibleView, ISimulationMonitorMarkerView, ISimulationCalcuResultLabelView, ISimulationMarkView, ISimulationGradingView
    {
        public XhsProjectSimulationBimfaceCtrl()
        {
            InitializeComponent();
        }
        #region 事件集
        /// <summary>
        /// 水力点击事件(包含左键和右键)
        /// 水力点击事件
        /// 包含左键和右键
        /// </summary>
        public event Action<Yw.Model.HydroVisualInfo> HydroClickEvent;
        public event Action<string> HydroClickEvent;
        /// <summary>
        /// 水力点击事件(仅左键)
        /// 水力点击事件
        /// 仅左键
        /// </summary>
        public event Action<Yw.Model.HydroVisualInfo> HydroMouseLeftClickEvent;
        public event Action<string> HydroMouseLeftClickEvent;
        /// <summary>
        /// 加载完成事件
        /// </summary>
        public event Action LoadCompletedEvent;
        #endregion
        //项目
        private HStation.Vmo.XhsProjectVmo _project = null;
        private XhsProjectVmo _project = null;
        //项目站
        private HStation.Vmo.XhsProjectSiteVmo _projectSite = null;
        //获取水力信息方法
        private Func<Yw.Model.HydroModelInfo> _hydroInfoFunc = null;
        private XhsProjectSiteVmo _projectSite = null;
        /// <summary>
        /// 初始化数据
        /// 仅支持调用一次
        /// </summary>
        public async Task InitialData(XhsProjectVmo project, XhsProjectSiteVmo projectSite)
        {
            if (project == null)
            {
                return;
            }
            _project = project;
            _projectSite = projectSite;
            if (_projectSite == null)
            {
                _projectSite = await BLLFactory<HStation.BLL.XhsProjectSite>.Instance.GetDefaultByProjectID(_project.ID);
            }
            var bimfaceInteropContainer = GetBimfaceInteropContainer();
            this.Controls.Clear();
            this.Controls.Add(bimfaceInteropContainer);
            await bimfaceInteropContainer.InitialContainer();
        }
        #region 交互容器
        //bimface 交互容器
        private BimfaceInterop3dContainer _bimfaceInteropContainer = null;
        //获取Bimface 交互容器
        private BimfaceInterop3dContainer GetBimfaceInteropContainer()
@@ -83,17 +113,7 @@
                    {
                        return;
                    }
                    if (this.HydroClickEvent != null)
                    {
                        var hydroInfo = _hydroInfoFunc?.Invoke();
                        if (hydroInfo == null)
                        {
                            return;
                        }
                        var allParterList = hydroInfo.GetAllVisuals();
                        var parter = allParterList?.Find(x => x.Code == obj.ObjectId);
                        this.HydroClickEvent.Invoke(parter);
                    }
                    this.HydroClickEvent?.Invoke(obj.ObjectId);
                };
                _bimfaceInteropContainer.ClickOutEvent += (obj) =>
                {
@@ -105,17 +125,7 @@
                    {
                        return;
                    }
                    if (this.HydroMouseLeftClickEvent != null)
                    {
                        var hydroInfo = _hydroInfoFunc?.Invoke();
                        if (hydroInfo == null)
                        {
                            return;
                        }
                        var allParterList = hydroInfo.GetAllVisuals();
                        var parter = allParterList?.Find(x => x.Code == obj.ObjectId);
                        this.HydroMouseLeftClickEvent.Invoke(parter);
                    }
                    this.HydroMouseLeftClickEvent?.Invoke(obj.ObjectId);
                };
                _bimfaceInteropContainer.MouseLeftClickOutEvent += (obj) =>
                {
@@ -124,39 +134,11 @@
            }
            return _bimfaceInteropContainer;
        }
        //bimface 交互容器
        private BimfaceInterop3dContainer _bimfaceInteropContainer = null;
        /// <summary>
        /// 初始化数据
        /// 仅支持调用一次
        /// </summary>
        public async Task InitialData
            (
                HStation.Vmo.XhsProjectVmo project,
                HStation.Vmo.XhsProjectSiteVmo projectSite,
                Func<Yw.Model.HydroModelInfo> hydroInfoFunc
            )
        {
            if (project == null)
            {
                return;
            }
            _project = project;
            _projectSite = projectSite;
            _hydroInfoFunc = hydroInfoFunc;
            if (_projectSite == null)
            {
                _projectSite = await BLLFactory<HStation.BLL.XhsProjectSite>.Instance.GetDefaultByProjectID(_project.ID);
            }
            var bimfaceInteropContainer = GetBimfaceInteropContainer();
            this.Controls.Clear();
            this.Controls.Add(bimfaceInteropContainer);
            await bimfaceInteropContainer.InitialContainer();
        }
        #region 构件的显示与隐藏
        #endregion
        #region 显示与隐藏
        /// <summary>
        /// 显示构件
@@ -196,34 +178,22 @@
        #endregion
        #region 构件的半透明与取消
        #region 半透明
        /// <summary>
        /// 半透明构件
        /// 半透明
        /// </summary>
        /// <param name="elementIds">构件id列表</param>
        /// <returns></returns>
        public async Task TranslucentComponents(List<string> elementIds)
        public async Task TranslucentComponents(List<string> codes)
        {
            if (_bimfaceInteropContainer == null)
            {
                return;
            }
            await _bimfaceInteropContainer.TranslucentComponents(elementIds);
            await _bimfaceInteropContainer?.TranslucentComponents(codes);
        }
        /// <summary>
        /// 取消构件半透明
        /// 取消半透明
        /// </summary>
        /// <param name="elementIds">构件id列表</param>
        /// <returns></returns>
        public async Task OpaqueComponents(List<string> elementIds)
        public async Task OpaqueComponents(List<string> codes)
        {
            if (_bimfaceInteropContainer == null)
            {
                return;
            }
            await _bimfaceInteropContainer.OpaqueComponents(elementIds);
            await _bimfaceInteropContainer?.OpaqueComponents(codes);
        }
        #endregion
@@ -287,18 +257,14 @@
        #endregion
        #region 缩放
        #region 缩放与选择
        /// <summary>
        /// 缩放至构件
        /// </summary>
        public async Task ZoomToComponent(string elementId)
        public async Task ZoomToComponent(string code)
        {
            if (_bimfaceInteropContainer == null)
            {
                return;
            }
            await _bimfaceInteropContainer.ZoomToComponent(elementId);
            await _bimfaceInteropContainer?.ZoomToComponent(code);
        }
        /// <summary>
@@ -306,31 +272,27 @@
        /// </summary>
        public async Task ZoomToSelectedComponents()
        {
            if (_bimfaceInteropContainer == null)
            {
                return;
            }
            await _bimfaceInteropContainer.ZoomToSelectedComponents();
            await _bimfaceInteropContainer?.ZoomToSelectedComponents();
        }
        /// <summary>
        /// 缩放至选择构件
        /// </summary>
        public async Task ZoomAndSelectComponent(string elementId)
        public async Task ZoomAndSelectComponent(string code)
        {
            if (string.IsNullOrEmpty(elementId))
            if (string.IsNullOrEmpty(code))
            {
                return;
            }
            await _bimfaceInteropContainer.ZoomAndSelectComponents(new List<string>() { elementId });
            await _bimfaceInteropContainer?.ZoomAndSelectComponents(new List<string>() { code });
        }
        /// <summary>
        /// 缩放至选择构件
        /// </summary>
        public async Task ZoomAndSelectComponents(List<string> elementIds)
        public async Task ZoomAndSelectComponents(List<string> codes)
        {
            await _bimfaceInteropContainer.ZoomAndSelectComponents(elementIds);
            await _bimfaceInteropContainer?.ZoomAndSelectComponents(codes);
        }
        #endregion
@@ -343,17 +305,25 @@
        /// <summary>
        /// 设置强调构件
        /// </summary>
        public async Task SetBlinkComponents(List<string> elementIds, string color, double transparency)
        public async Task SetBlinkComponents(string elementId, string color = _blinkColor, double transparency = _blinkTransparency)
        {
            await _bimfaceInteropContainer?.SetBlinkComponents(elementIds, color, transparency);
            if (string.IsNullOrEmpty(elementId))
            {
                return;
            }
            await _bimfaceInteropContainer?.SetBlinkComponents(new List<string>() { elementId }, color, transparency);
        }
        /// <summary>
        /// 设置强调构件
        /// </summary>
        public async Task SetBlinkComponents(List<string> elementIds)
        public async Task SetBlinkComponents(List<string> elementIds, string color = _blinkColor, double transparency = _blinkTransparency)
        {
            await _bimfaceInteropContainer?.SetBlinkComponents(elementIds, _blinkColor, _blinkTransparency);
            if (elementIds == null || elementIds.Count < 1)
            {
                return;
            }
            await _bimfaceInteropContainer?.SetBlinkComponents(elementIds, color, transparency);
        }
        /// <summary>
@@ -373,11 +343,19 @@
        /// </summary>
        public async Task OverrideComponentsColor(List<string> elementIds, string color, double transparency)
        {
            if (_bimfaceInteropContainer == null)
            await _bimfaceInteropContainer?.OverrideComponentsColor(elementIds, color, transparency);
        }
        /// <summary>
        /// 设置强调构件
        /// </summary>
        public async Task OverrideComponentsColor(string elementId, string color, double transparency)
        {
            if (string.IsNullOrEmpty(elementId))
            {
                return;
            }
            await _bimfaceInteropContainer.OverrideComponentsColor(elementIds, color, transparency);
            await _bimfaceInteropContainer.OverrideComponentsColor(new List<string>() { elementId }, color, transparency);
        }
        /// <summary>
@@ -385,11 +363,19 @@
        /// </summary>
        public async Task RestoreComponentsColor(List<string> elementIds)
        {
            if (_bimfaceInteropContainer == null)
            await _bimfaceInteropContainer?.RestoreComponentsColor(elementIds);
        }
        /// <summary>
        /// 恢复构件颜色
        /// </summary>
        public async Task RestoreComponentsColor(string elementId)
        {
            if (string.IsNullOrEmpty(elementId))
            {
                return;
            }
            await _bimfaceInteropContainer.RestoreComponentsColor(elementIds);
            await _bimfaceInteropContainer?.RestoreComponentsColor(new List<string>() { elementId });
        }
        #endregion
@@ -397,61 +383,10 @@
        #region 业务计算自定义标签
        /// <summary>
        /// 显示业务计算自定义标签
        /// 设置业务计算自定义标签
        /// </summary>
        public async Task SetLogicCalcuCustomLabels(CalcuResult calcuResult)
        public async Task SetLogicCalcuCustomLabels(List<LogicCalcuCustomLabel> obj)
        {
            var hydroInfo = _hydroInfoFunc?.Invoke();
            if (hydroInfo == null)
            {
                return;
            }
            if (calcuResult == null)
            {
                return;
            }
            if (!calcuResult.Succeed)
            {
                await _bimfaceInteropContainer?.ClearLogicCalcuCustomLabels();
                return;
            }
            var obj = new List<LogicCalcuCustomLabel>();
            var allParterList = hydroInfo.GetAllParters();
            allParterList?.ForEach(x =>
            {
                if (x is Yw.Model.HydroPumpInfo pump)
                {
                    var hz = Math.Round(pump.RatedHz * pump.SpeedRatio);
                    var calcuPump = calcuResult.LinkList.Find(x => x.Id == pump.Code);
                    var calcuPumpStart = calcuResult.NodeList.Find(x => x.Id == pump.StartCode);
                    var calcuPumpEnd = calcuResult.NodeList.Find(x => x.Id == pump.EndCode);
                    var pumpCustomLabel = new LogicCalcuCustomLabel();
                    pumpCustomLabel.Id = pump.Code;
                    pumpCustomLabel.Distance = 10000;
                    pumpCustomLabel.Data = new List<LogicCalcuCustomLabelItem>()
                    {
                        new LogicCalcuCustomLabelItem(){ Name="状态",Value=HydroLinkStatusHelper.GetStatusName(pump.LinkStatus),Unit=string.Empty},
                        new LogicCalcuCustomLabelItem(){ Name="频率",Value=hz.ToString(),Unit=string.Empty},
                        new LogicCalcuCustomLabelItem(){ Name="流量",Value=Math.Round(calcuPump.Flow,1).ToString(),Unit="m³/h"},
                        new LogicCalcuCustomLabelItem(){ Name="进口压力",Value=Math.Round(calcuPumpStart.Head,4).ToString(),Unit="m"},
                        new LogicCalcuCustomLabelItem(){ Name="出口压力",Value=Math.Round(calcuPumpEnd.Head,4).ToString(),Unit="m"},
                    };
                    obj.Add(pumpCustomLabel);
                }
                else if (x is Yw.Model.HydroEmitterInfo emitter)
                {
                    var calcuEmitter = calcuResult.NodeList.Find(x => x.Id == emitter.Code);
                    var emitterCustomLabel = new LogicCalcuCustomLabel();
                    emitterCustomLabel.Id = emitter.Code;
                    emitterCustomLabel.Distance = 10000;
                    emitterCustomLabel.Data = new List<LogicCalcuCustomLabelItem>()
                    {
                        new LogicCalcuCustomLabelItem(){ Name="流量",Value=Math.Round(calcuEmitter.Demand,1).ToString(),Unit="m³/h"},
                        new LogicCalcuCustomLabelItem(){ Name="压力",Value=Math.Round(calcuEmitter.Head,4).ToString(),Unit="m"}
                    };
                    obj.Add(emitterCustomLabel);
                }
            });
            await _bimfaceInteropContainer?.SetLogicCalcuCustomLabels(obj);
        }
@@ -465,7 +400,7 @@
        #endregion
        #region 业务标注引线标签
        #region 模型标注
        /// <summary>
        /// 设置业务标注引线标签
@@ -473,6 +408,22 @@
        public async Task SetLogicMarkLeadLabels(List<LogicMarkLeadLabel> obj)
        {
            await _bimfaceInteropContainer?.SetLogicMarkLeadLabels(obj);
        }
        /// <summary>
        /// 更新业务标注引线标签
        /// </summary>
        public async Task UpdateLogicMarkLeadLabel(LogicMarkLeadLabel obj)
        {
            await _bimfaceInteropContainer?.UpdateLogicMarkLeadLabel(obj);
        }
        /// <summary>
        /// 更新业务标注引线标签
        /// </summary>
        public async Task UpdateLogicMarkLeadLabels(List<LogicMarkLeadLabel> obj)
        {
            await _bimfaceInteropContainer?.UpdateLogicMarkLeadLabels(obj);
        }
        /// <summary>
@@ -485,7 +436,7 @@
        #endregion
        #region 业务水流动画
        #region 水流动画
        /// <summary>
        /// 加载水流动画
@@ -607,12 +558,12 @@
        #endregion
        #region 业务监测点
        #region 监测点标记
        /// <summary>
        /// 设置业务监测点
        /// </summary>
        public async Task SetLogicMonitors(List<LogicMonitor> obj)
        public async Task SetLogicMonitors(List<LogicMonitorMarker> obj)
        {
            await _bimfaceInteropContainer?.SetLogicMonitors(obj);
        }