using DevExpress.Xpo.DB.Helpers;
|
using DevExpress.XtraDiagram.Base;
|
|
namespace Yw.WinFrmUI
|
{
|
public partial class BimfaceInterop3dContainer : UserControl, IBimfaceInterop3dContainer
|
{
|
public BimfaceInterop3dContainer()
|
{
|
InitializeComponent();
|
}
|
|
public event Action LoadCompletedEvent;
|
public event Action LoadFailedEvent;
|
public event Action<HandingError> HandingErrorEvent;
|
public event Action LoadViewCompletedEvent;
|
public event Action<string> LoadViewFailedEvent;
|
public event Action<ClickIn3dInfo> ClickInEvent;
|
public event Action<ClickOut3dInfo> ClickOutEvent;
|
|
/// <summary>
|
/// 交互对象
|
/// </summary>
|
public BimfaceInterop3dCallBackObj CallBackObj
|
{
|
get
|
{
|
if (_callBackObj == null)
|
{
|
_callBackObj = new BimfaceInterop3dCallBackObj();
|
}
|
return _callBackObj;
|
}
|
}
|
private BimfaceInterop3dCallBackObj _callBackObj;
|
|
/// <summary>
|
/// 是否初始化
|
/// </summary>
|
public bool IsInitialized
|
{
|
get
|
{
|
return _isInitialized;
|
}
|
}
|
private bool _isInitialized;
|
|
/// <summary>
|
/// 视图是否初始化
|
/// </summary>
|
public bool IsViewInitialized
|
{
|
get
|
{
|
return _isViewInitialized;
|
}
|
}
|
private bool _isViewInitialized;
|
|
/// <summary>
|
/// 初始话容器
|
/// </summary>
|
public async Task InitialContainer()
|
{
|
var callBackObj = this.CallBackObj;
|
callBackObj.LoadCompletedEvent += CallBackObj_LoadCompletedEvent;
|
callBackObj.LoadFailedEvent += CallBackObj_LoadFailedEvent;
|
callBackObj.HandingErrorEvent += CallBackObj_HandingErrorEvent;
|
callBackObj.LoadViewCompletedEvent += CallBackObj_LoadViewCompletedEvent;
|
callBackObj.LoadViewFailedEvent += CallBackObj_LoadViewFailedEvent;
|
callBackObj.ClickInEvent += CallBackObj_ClickInEvent;
|
callBackObj.ClickOutEvent += CallBackObj_ClickOutEvent;
|
await this.webViewControl1.InitialWebBrower(BimfaceUrlHelper.Interop3dUrl, callBackObj, true);
|
}
|
|
|
//加载完成
|
private void CallBackObj_LoadCompletedEvent()
|
{
|
_isInitialized = true;
|
this.LoadCompletedEvent?.Invoke();
|
}
|
|
//加载失败
|
private void CallBackObj_LoadFailedEvent()
|
{
|
this.LoadFailedEvent?.Invoke();
|
}
|
|
//处理错误
|
private void CallBackObj_HandingErrorEvent(HandingError obj)
|
{
|
this.HandingErrorEvent?.Invoke(obj);
|
}
|
|
//加载视图完成
|
private void CallBackObj_LoadViewCompletedEvent()
|
{
|
_isViewInitialized = true;
|
this.LoadViewCompletedEvent?.Invoke();
|
}
|
|
//加载视图失败
|
private void CallBackObj_LoadViewFailedEvent(string obj)
|
{
|
this.LoadViewFailedEvent?.Invoke(obj);
|
}
|
|
//点击构件
|
private void CallBackObj_ClickInEvent(ClickIn3dInfo obj)
|
{
|
this.ClickInEvent?.Invoke(obj);
|
}
|
|
//点击外部
|
private void CallBackObj_ClickOutEvent(ClickOut3dInfo obj)
|
{
|
this.ClickOutEvent?.Invoke(obj);
|
}
|
|
|
/// <summary>
|
/// 加载视图
|
/// </summary>
|
public async Task<bool> LoadView(string viewToken)
|
{
|
if (!_isInitialized)
|
{
|
return false;
|
}
|
return await this.webViewControl1.EvaluateScriptAsync<bool>("loadView", viewToken);
|
}
|
|
|
|
#region 构件显隐
|
|
/// <summary>
|
/// 显示构件
|
/// </summary>
|
/// <param name="ids">构件id列表</param>
|
public async Task ShowComponents(List<string> ids)
|
{
|
if (ids == null || ids.Count < 1)
|
{
|
return;
|
}
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("showComponents", ids);
|
}
|
|
/// <summary>
|
/// 隐藏构件
|
/// </summary>
|
/// <param name="ids">构件id列表</param>
|
public async Task HideComponents(List<string> ids)
|
{
|
if (ids == null || ids.Count < 1)
|
{
|
return;
|
}
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("hideComponents", ids);
|
}
|
|
/// <summary>
|
/// 显示所有构件
|
/// </summary>
|
public async Task ShowAllComponents()
|
{
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("showAllComponents()");
|
}
|
|
#endregion
|
|
#region 构件半透明与取消
|
|
/// <summary>
|
/// 半透明组件(鼠标不可选)
|
/// </summary>
|
/// <param name="ids">构件id列表</param>
|
/// <returns></returns>
|
public async Task TranslucentComponents(List<string> ids)
|
{
|
if (ids == null || ids.Count < 1)
|
{
|
return;
|
}
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("translucentComponents", ids);
|
}
|
|
/// <summary>
|
/// 取消构件半透明
|
/// </summary>
|
/// <param name="ids">构件id列表</param>
|
/// <returns></returns>
|
public async Task OpaqueComponents(List<string> ids)
|
{
|
if (ids == null || ids.Count < 1)
|
{
|
return;
|
}
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("opaqueComponents", ids);
|
}
|
|
#endregion
|
|
#region 构件的选择与取消
|
|
/// <summary>
|
/// 设置选择的构件列表
|
/// </summary>
|
/// <param name="ids">构件id列表</param>
|
public async Task SetSelectedComponents(List<string> ids)
|
{
|
if (ids == null || ids.Count < 1)
|
{
|
return;
|
}
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("setSelectedComponents", ids);
|
}
|
|
/// <summary>
|
/// 增加选择的构件列表
|
/// </summary>
|
/// <param name="ids">构件id列表</param>
|
public async Task AddSelectedComponents(List<string> ids)
|
{
|
if (ids == null || ids.Count < 1)
|
{
|
return;
|
}
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("addSelectedComponents", ids);
|
}
|
|
/// <summary>
|
/// 移除选择的构件列表
|
/// </summary>
|
/// <param name="ids">构件id列表</param>
|
public async Task RemoveSelectedComponents(List<string> ids)
|
{
|
if (ids == null || ids.Count < 1)
|
{
|
return;
|
}
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("removeSelectedComponents", ids);
|
}
|
|
/// <summary>
|
/// 清除选择的构件列表
|
/// </summary>
|
public async Task ClearSelectedComponents()
|
{
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("clearSelectedComponents()");
|
}
|
|
|
#endregion
|
|
#region 缩放
|
|
/// <summary>
|
/// 缩放至包围盒
|
/// </summary>
|
public async Task ZoomToBoundingBox(BoundingBox boundingbox)
|
{
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("zoomToBoundingBox", boundingbox);
|
}
|
|
/// <summary>
|
/// 缩放至构件
|
/// </summary>
|
public async Task ZoomToComponent(string id)
|
{
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("zoomToComponent", id);
|
}
|
|
/// <summary>
|
/// 缩放至选择的构件
|
/// </summary>
|
public async Task ZoomToSelectedComponents()
|
{
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("zoomToSelectedComponents()");
|
}
|
|
/// <summary>
|
/// 缩放并选择构件
|
/// </summary>
|
public async Task ZoomAndSelectComponents(List<string> ids)
|
{
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("zoomAndSelectComponents", ids);
|
}
|
|
#endregion
|
|
#region 强调构件
|
|
/// <summary>
|
/// 设置强调构件
|
/// </summary>
|
/// <param name="ids">构件id列表</param>
|
/// <param name="color">#32D3A6</param>
|
/// <param name="transparency">0.8</param>
|
/// <returns></returns>
|
public async Task SetBlinkComponents(List<string> ids, string color, double transparency)
|
{
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("setBlinkComponents", ids, color, transparency);
|
}
|
|
/// <summary>
|
/// 清除强调构件
|
/// </summary>
|
/// <returns></returns>
|
public async Task ClearBlinkComponents()
|
{
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("clearBlinkComponents()");
|
}
|
|
#endregion
|
|
#region 构件着色
|
|
/// <summary>
|
/// 改变构件颜色
|
/// </summary>
|
/// <param name="ids">构件id列表</param>
|
/// <param name="color">#32D3A6</param>
|
/// <param name="transparency">0.8</param>
|
/// <returns></returns>
|
public async Task OverrideComponentsColor(List<string> ids, string color, double transparency)
|
{
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("overrideComponentsColor", new ComponentsColor() { Ids = ids, Color = color, Transparency = transparency });
|
}
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="ids">构件id列表</param>
|
/// <returns></returns>
|
/// <exception cref="NotImplementedException"></exception>
|
public async Task RestoreComponentsColor(List<string> ids)
|
{
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("restoreComponentsColor", ids);
|
}
|
|
#endregion
|
|
}
|
}
|