using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Drawing;
|
using System.Data;
|
using System.Text;
|
using System.Linq;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
using DevExpress.XtraEditors;
|
|
namespace TProduct.WinFrmUI.TBase
|
{
|
|
public partial class ProductTestBimfaceCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
private TProduct.WinFrmUI.Bimface.ViewWebBrowser bimfaceContainer1;
|
|
public ProductTestBimfaceCtrl()
|
{
|
InitializeComponent();
|
|
this.bimfaceContainer1 = new TProduct.WinFrmUI.Bimface.ViewWebBrowser();
|
this.bimfaceContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
|
this.bimfaceContainer1.Location = new System.Drawing.Point(0, 0);
|
this.bimfaceContainer1.Name = "bimfaceContainer1";
|
this.bimfaceContainer1.Size = new System.Drawing.Size(210, 160);
|
this.bimfaceContainer1.TabIndex = 0;
|
this.Controls.Add(this.bimfaceContainer1);
|
|
}
|
|
public event Action<string> ClickObjectEvent;
|
public event Action BimLoadCompletedEvent;
|
|
|
private bool _isInitial = false;//BIM是否加载完成
|
public bool SetBindingData(string url, out string error_info)
|
{
|
//var url = System.Environment.CurrentDirectory + @"\Model3d\valve\index.html";
|
if (!System.IO.File.Exists(url))
|
{
|
error_info = "文件不存在";
|
return false;
|
}
|
|
this.SetUrlPath(url);
|
error_info = null;
|
return true;
|
}
|
public void SetUrlPath(string url)
|
{
|
this.bimfaceContainer1.WebBrowserEvents.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);
|
// //}
|
//}));
|
};
|
this.bimfaceContainer1.WebBrowserEvents.BimLoadCompletedEvent += () =>
|
{//BIM加载完成
|
_isInitial = true;
|
this.Invoke(new Action(() =>
|
{
|
this.BimLoadCompletedEvent?.Invoke();
|
}));
|
};
|
|
this.bimfaceContainer1.WebBrowserEvents.LoadFailedEvent += () =>
|
{//BIM加载失败
|
this.Invoke(new Action(() =>
|
{
|
XtraMessageBox.Show("BIM文件加载失败!");
|
}));
|
};
|
this.bimfaceContainer1.WebBrowserEvents.ClickObjectEvent += (objectid) =>
|
{//点击事件
|
this.Invoke(new Action(() =>
|
{
|
this.ClickObjectEvent?.Invoke(objectid);
|
}));
|
};
|
this.bimfaceContainer1.WebBrowserEvents.HandingErrorEvent += (error) =>
|
{//操作失败
|
|
};
|
|
this.bimfaceContainer1.InitialWebBrowserUrl(url);
|
}
|
|
/// <summary>
|
/// 使构建ID显示高亮
|
/// </summary>
|
/// <param name="ids"></param>
|
/// <returns></returns>
|
public Task<TProduct.Model.WebBrowserResponse> OverrideComponentsColorByIds(List<long> ids)
|
{
|
if (!_isInitial)
|
return null;
|
return this.bimfaceContainer1.OverrideComponentsColorByIds(ids);
|
}
|
|
/// <summary>
|
/// 恢复高亮的构建颜色
|
/// </summary>
|
public Task<TProduct.Model.WebBrowserResponse> RestoreComponentsColorByIds()
|
{
|
if (!_isInitial)
|
return null;
|
return this.bimfaceContainer1.RestoreComponentsColorByIds();
|
}
|
|
/// <summary>
|
/// 显示构件
|
/// </summary>
|
/// <param name="ids"></param>
|
/// <returns></returns>
|
public Task<TProduct.Model.WebBrowserResponse> ShowComponents(List<long> ids)
|
{
|
if (!_isInitial)
|
return null;
|
return this.bimfaceContainer1.ShowComponents(ids);
|
}
|
|
/// <summary>
|
/// 隐藏构件
|
/// </summary>
|
/// <param name="ids"></param>
|
/// <returns></returns>
|
public Task<TProduct.Model.WebBrowserResponse> HideComponents(List<long> ids)
|
{
|
if (!_isInitial)
|
return null;
|
return this.bimfaceContainer1.HideComponents(ids);
|
}
|
|
/// <summary>
|
/// 批量改变部件颜色
|
/// </summary>
|
/// <param name="json"></param>
|
/// <returns></returns>
|
public Task<TProduct.Model.WebBrowserResponse> ChangeComponentsColor(string json)
|
{
|
if (!_isInitial)
|
return null;
|
return this.bimfaceContainer1.ChangeComponentsColor(json);
|
}
|
|
/// <summary>
|
/// 改变部件颜色
|
/// </summary>
|
/// <param name="json"></param>
|
/// <returns></returns>
|
public Task<TProduct.Model.WebBrowserResponse> ChangeComponentColor(string json)
|
{
|
if (!_isInitial)
|
return null;
|
return this.bimfaceContainer1.ChangeComponentColor(json);
|
}
|
|
/// <summary>
|
/// 恢复部件颜色
|
/// </summary>
|
/// <param name="ids"></param>
|
/// <returns></returns>
|
public Task<TProduct.Model.WebBrowserResponse> RecoverComponentsColor(List<long> ids)
|
{
|
if (!_isInitial)
|
return null;
|
return this.bimfaceContainer1.RecoverComponentsColor(ids);
|
}
|
|
/// <summary>
|
/// 设置构件半透明
|
/// </summary>
|
/// <param name="ids"></param>
|
/// <returns></returns>
|
public Task<TProduct.Model.WebBrowserResponse> SetComponentsTranslucent(List<long> ids)
|
{
|
if (!_isInitial)
|
return null;
|
return this.bimfaceContainer1.SetComponentsTranslucent(ids);
|
}
|
|
/// <summary>
|
/// 取消构件半透明
|
/// </summary>
|
/// <param name="ids"></param>
|
/// <returns></returns>
|
public Task<TProduct.Model.WebBrowserResponse> SetComponentsOpaque(List<long> ids)
|
{
|
if (!_isInitial)
|
return null;
|
return this.bimfaceContainer1.SetComponentsOpaque(ids);
|
}
|
|
/// <summary>
|
/// 添加监控面板
|
/// </summary>
|
/// <param name="json"></param>
|
/// <returns></returns>
|
public Task<TProduct.Model.WebBrowserResponse> AddMinitorPanel(string json)
|
{
|
if (!_isInitial)
|
return null;
|
return this.bimfaceContainer1.AddMinitorPanel(json);
|
}
|
|
/// <summary>
|
/// 移动监控面板
|
/// </summary>
|
/// <param name="json"></param>
|
/// <returns></returns>
|
public Task<TProduct.Model.WebBrowserResponse> MoveMinitorPanel(string json)
|
{
|
if (!_isInitial)
|
return null;
|
return this.bimfaceContainer1.MoveMinitorPanel(json);
|
}
|
|
/// <summary>
|
/// 移除监控面板
|
/// </summary>
|
/// <param name="panelId"></param>
|
/// <returns></returns>
|
public Task<TProduct.Model.WebBrowserResponse> RemoveMinitorPanel(string panelId)
|
{
|
if (!_isInitial)
|
return null;
|
return this.bimfaceContainer1.RemoveMinitorPanel(panelId);
|
}
|
|
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="json"></param>
|
/// <returns></returns>
|
public Task<TProduct.Model.WebBrowserResponse> refreshMonitorValue(List<TProduct.Model.MonitorPointValue> list)
|
{
|
if (!_isInitial)
|
return null;
|
if (list == null || list.Count() == 0)
|
return null;
|
var listMonitorValue4Html = new List<MonitorValue4Html>();
|
foreach(var m in list)
|
{
|
listMonitorValue4Html.Add(new MonitorValue4Html() { PointID = m.ID.ToString(), Value = m.Value.ToString() });
|
}
|
var json = TProduct.JsonHelper.Object2Json<List<MonitorValue4Html>>(listMonitorValue4Html);
|
return this.bimfaceContainer1.EvaluateScriptAsync("refreshMonitorValue(" + json + ")");
|
}
|
class MonitorValue4Html
|
{
|
public String PointID { get; set; }
|
public String Value { get; set; }
|
}
|
|
}
|
}
|