using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; namespace TProduct.WinFrmUI.Model3d { public partial class BimfaceWebBrowser : ModelBaseBrowser { public BimfaceWebBrowser() : base() { } List _panels = null; TProduct.WinFrmUI.WebBrowserPage _browser = null; List _monitor_ids = new List(); public override bool Initial( string ProductName, List allMonitors, string url) { _browser = new WebBrowserPage(); _browser.Name = "WebBrowserPage"; _browser.Dock = DockStyle.Fill; this.Controls.Add(_browser); var obj = BuildBoundObj(); _browser.InitialWebBrowser(url, obj); _monitor_ids.Clear(); var point_流量 = allMonitors.Find(x => x.MonitorType == Model.eMonitorType.流量); var point_压力 = allMonitors.Find(x => x.MonitorType == Model.eMonitorType.压力 && x.Property == TProduct.Model.MonitorTypeProperty.出口); ViewModel.MonitorPanel panel = new ViewModel.MonitorPanel(); panel.Name = ProductName; panel.Posi = new ViewModel.WorldPosition() { x = 58.00899610641597, y = 17.906798645412977, z = 1.150000095367432 }; panel.RecordList = new List(); if (point_流量 != null) { panel.RecordList.Add(new ViewModel.RecordItem() { PointID = point_流量.ID.ToString(), RecordName = "流量", RecordStatus = 1, RecordUnitName = "m³/h", RecordValue = "未连接" }); _monitor_ids.Add(point_流量.ID); } if (point_压力 != null) { panel.RecordList.Add(new ViewModel.RecordItem() { PointID = point_压力.ID.ToString(), RecordName = "压力", RecordStatus = 1, RecordUnitName = "MPa", RecordValue = "未连接" }); _monitor_ids.Add(point_压力.ID); } if (_monitor_ids.Count() == 0) return false; _panels = new List(); _panels.Add(panel); return true; } private bool _isInitial = false; /// /// 构建HTML 网页交互类 /// /// private BIMFACEBoundObj BuildBoundObj() { BIMFACEBoundObj obj = new BIMFACEBoundObj(); obj.LoadCompletedEvent += () => {//页面加载完成,BIM不一定加载完成 //this.Invoke(new Action( () => //{ // //var task = this.bimfaceContainer1.LoadBIM(_viewtoken); // //await task; // //if (!string.IsNullOrEmpty(task.Result.Message)) // //{ // // //LogHelper.WriteLog(task.Result.Message); // // XtraMessageBox.Show(task.Result.Message); // //} //})); }; obj.BimLoadCompletedEvent += () => {//BIM加载完成 _isInitial = true; this.Invoke(new Action(() => { this.CreatePanel(); this.OnModelLoadSuceess?.Invoke(); })); }; obj.LoadFailedEvent += () => {//BIM加载失败 this.Invoke(new Action(() => { this.OnModelLoadFail?.Invoke(); })); }; obj.ClickObjectEvent += (objectid) => {//点击事件 this.Invoke(new Action(() => { this.OnClickObject?.Invoke(objectid); })); }; obj.HandingErrorEvent += (error) => {//操作失败 }; return obj; } /// /// /// /// private Task CreatePanel() { if (_panels == null || _panels.Count() == 0) return null; var json = TProduct.JsonHelper.Object2Json>(_panels); return this._browser.EvaluateScriptAsync("initialMonitorPanel(" + json + ")"); } /// /// /// /// /// public override Task RefreshMonitorValue( List list) { if (!_isInitial) return null; if (list == null || list.Count() == 0 || _monitor_ids.Count() == 0) return null; var listMonitorValue4Html = new List(); foreach (var m_id in _monitor_ids) { var f = list.Find(x => x.ID == m_id); if (f != null) listMonitorValue4Html.Add(new MonitorValue4Html() { PointID = m_id.ToString(), Value = f.Value.ToString() }); } if (listMonitorValue4Html.Count > 0) { var json = TProduct.JsonHelper.Object2Json>(listMonitorValue4Html); return this._browser.EvaluateScriptAsync("refreshMonitorValue(" + json + ")"); } else { return null; } } class MonitorValue4Html { public String PointID { get; set; } public String Value { get; set; } } /// /// 使构建ID显示高亮 /// /// /// public Task OverrideComponentsColorByIds(List ids) { if (this._browser == null || !_isInitial) return null; if (ids == null || ids.Count < 1) return null; var json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(ids); return this._browser.EvaluateScriptAsync("overrideComponentsColorByIds(" + json + ")"); } /// /// 恢复高亮的构建颜色 /// public Task RestoreComponentsColorByIds() { if (this._browser == null || !_isInitial) return null; return this._browser.EvaluateScriptAsync("restoreComponentsColorByIds()"); } /// /// 隐藏构件 /// /// /// public Task HideComponents(List ids) { if (this._browser == null || !_isInitial) return null; if (ids == null || ids.Count < 1) return null; var json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(ids); return this._browser.EvaluateScriptAsync("hideComponents(" + json + ")"); } /// /// 显示构件 /// /// /// public Task ShowComponents(List ids) { if (this._browser == null || !_isInitial) return null; if (ids == null || ids.Count < 1) return null; var json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(ids); return this._browser.EvaluateScriptAsync("showComponents(" + json + ")"); } /// /// 批量改变部件颜色 /// /// /// public Task ChangeComponentsColor(string json) { if (this._browser == null || !_isInitial) return null; return this._browser.EvaluateScriptAsync("changeComponentsColor(" + json + ")"); } /// /// 改变部件颜色 /// /// /// public Task ChangeComponentColor(string json) { if (this._browser == null || !_isInitial) return null; return this._browser.EvaluateScriptAsync("changeComponentColor(" + json + ")"); } /// /// 恢复部件颜色 /// /// /// public Task RecoverComponentsColor(List ids) { if (this._browser == null || !_isInitial) return null; if (ids == null || ids.Count < 1) return null; var json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(ids); return this._browser.EvaluateScriptAsync("recoverComponentsColor(" + json + ")"); } /// /// 设置构件半透明(这样鼠标不可点) /// /// /// public Task SetComponentsTranslucent(List ids) { if (this._browser == null || !_isInitial) return null; if (ids == null || ids.Count < 1) return null; var json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(ids); return this._browser.EvaluateScriptAsync("setComponentsTranslucent(" + json + ")"); } /// /// 取消半透明 /// /// /// public Task SetComponentsOpaque(List ids) { if (this._browser == null || !_isInitial) return null; if (ids == null || ids.Count < 1) return null; var json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(ids); return this._browser.EvaluateScriptAsync("setComponentsOpaque(" + json + ")"); } } }