namespace Yw.WinFrmUI
|
{
|
public partial class BimfaceInterop3dContainer : UserControl, IBimfaceInterop3dContainer
|
{
|
public BimfaceInterop3dContainer()
|
{
|
InitializeComponent();
|
}
|
|
/// <summary>
|
/// Html加载完成事件
|
/// </summary>
|
public event Action LoadCompletedEvent;
|
/// <summary>
|
/// Html加载失败事件
|
/// </summary>
|
public event Action LoadFailedEvent;
|
/// <summary>
|
/// 处理错误事件
|
/// </summary>
|
public event Action<HandingError> HandingErrorEvent;
|
/// <summary>
|
/// View加载完成事件
|
/// </summary>
|
public event Action LoadViewCompletedEvent;
|
/// <summary>
|
/// View加载失败事件
|
/// </summary>
|
public event Action<string> LoadViewFailedEvent;
|
/// <summary>
|
/// 点击构件事件
|
/// </summary>
|
public event Action<ClickIn3dInfo> ClickInEvent;
|
/// <summary>
|
/// 鼠标左键点击构件事件
|
/// </summary>
|
public event Action<ClickIn3dInfo> MouseLeftClickInEvent;
|
/// <summary>
|
/// 点击外部事件
|
/// </summary>
|
public event Action<ClickOut3dInfo> ClickOutEvent;
|
/// <summary>
|
/// 鼠标左键点击外部事件
|
/// </summary>
|
public event Action<ClickOut3dInfo> MouseLeftClickOutEvent;
|
|
|
/// <summary>
|
/// 是否初始化
|
/// </summary>
|
public bool IsInitialized
|
{
|
get
|
{
|
return _isInitialized;
|
}
|
}
|
private bool _isInitialized;
|
|
/// <summary>
|
/// 视图是否初始化
|
/// </summary>
|
public bool IsViewInitialized
|
{
|
get
|
{
|
return _isViewInitialized;
|
}
|
}
|
private bool _isViewInitialized;
|
|
//获取交互对象
|
private BimfaceInterop3dCallBackObj GetCallBackObj()
|
{
|
if (_callBackObj == null)
|
{
|
_callBackObj = new BimfaceInterop3dCallBackObj();
|
_callBackObj.LoadCompletedEvent += () =>
|
{
|
_isInitialized = true;
|
this.LoadCompletedEvent?.Invoke();
|
};
|
_callBackObj.LoadFailedEvent += () =>
|
{
|
this.LoadFailedEvent?.Invoke();
|
};
|
_callBackObj.HandingErrorEvent += (obj) =>
|
{
|
this.HandingErrorEvent?.Invoke(obj);
|
};
|
_callBackObj.LoadViewCompletedEvent += () =>
|
{
|
_isViewInitialized = true;
|
this.LoadViewCompletedEvent?.Invoke();
|
};
|
_callBackObj.LoadViewFailedEvent += (obj) =>
|
{
|
this.LoadViewFailedEvent?.Invoke(obj);
|
};
|
_callBackObj.ClickInEvent += (obj) =>
|
{
|
this.ClickInEvent?.Invoke(obj);
|
};
|
_callBackObj.MouseLeftClickInEvent += (obj) =>
|
{
|
this.MouseLeftClickInEvent?.Invoke(obj);
|
};
|
_callBackObj.ClickOutEvent += (obj) =>
|
{
|
this.ClickOutEvent?.Invoke(obj);
|
};
|
_callBackObj.MouseLeftClickOutEvent += (obj) =>
|
{
|
this.MouseLeftClickOutEvent?.Invoke(obj);
|
};
|
}
|
return _callBackObj;
|
}
|
private BimfaceInterop3dCallBackObj _callBackObj;
|
|
/// <summary>
|
/// 初始话容器
|
/// </summary>
|
public async Task InitialContainer()
|
{
|
var callBackObj = GetCallBackObj();
|
await this.webViewControl1.InitialWebBrower(BimfaceUrlHelper.Interop3dUrl, callBackObj, true);
|
}
|
|
/// <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
|
|
#region 自定义标签
|
|
/// <summary>
|
/// 设置自定义标签
|
/// </summary>
|
public async Task SetCustomLabels(List<CustomLabel> obj)
|
{
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("setCustomLabels", obj);
|
}
|
|
/// <summary>
|
/// 清除自定义标签
|
/// </summary>
|
public async Task ClearCustomLabels()
|
{
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("clearCustomLabels()");
|
}
|
|
#endregion
|
|
#region 引线标签
|
|
/// <summary>
|
/// 设置引线标签
|
/// </summary>
|
public async Task SetLeadLabels(List<LeadLabel> obj)
|
{
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("setLeadLabels", obj);
|
}
|
|
/// <summary>
|
/// 清除引线标签
|
/// </summary>
|
public async Task ClearLeadLabels()
|
{
|
if (!_isViewInitialized)
|
{
|
return;
|
}
|
await this.webViewControl1.EvaluateScriptAsync("clearLeadLabels()");
|
}
|
|
#endregion
|
|
}
|
}
|