namespace HStation.WinFrmUI
{
public partial class XhsProjectBimfaceViewPage : DocumentPage
{
public XhsProjectBimfaceViewPage()
{
InitializeComponent();
this.PageTitle.Caption = "模型视图";
this.PageTitle.HeaderSvgImage = Yw.WinFrmUI.BimfaceMainSvgImageHelper.Bimface;
this.PageTitle.SvgImageSize = new Size(24, 24);
}
private XhsProjectVmo _project = null;//项目
private XhsProjectSiteVmo _projectSite = null;//项目站
///
/// 绑定数据
///
public async Task SetBindingData(long projectId)
{
var project = await BLLFactory.Instance.GetByID(projectId);
if (project == null)
{
return;
}
SetBindingData(project);
}
///
/// 绑定数据
///
public void SetBindingData(XhsProjectVmo project)
{
if (project == null)
{
return;
}
_project = project;
this.PageTitle.Caption = $"{_project.Name}\r\n模型视图";
}
///
/// 绑定数据
///
public void SetBindingData(XhsProjectExtensionsVmo project)
{
if (project == null)
{
return;
}
_project = project;
_projectSite = project.SiteList.FirstOrDefault();
this.PageTitle.Caption = $"{_project.Name}\r\n模型视图";
}
///
/// 初始化数据源
///
public override void InitialDataSource()
{
base.InitialDataSource();
InitialData();
}
///
/// 初始化数据
/// 仅支持调用一次
///
public async void InitialData()
{
var bimfaceInteropContainer = GetBimfaceInteropContainer();
this.Controls.Clear();
this.Controls.Add(bimfaceInteropContainer);
await bimfaceInteropContainer.InitialContainer();
}
#region 交互容器
//bimface 交互容器
private BimfaceInterop3dContainer _bimfaceInteropContainer = null;
//获取Bimface 交互容器
private BimfaceInterop3dContainer GetBimfaceInteropContainer()
{
if (_bimfaceInteropContainer == null)
{
_bimfaceInteropContainer = new BimfaceInterop3dContainer();
_bimfaceInteropContainer.Dock = DockStyle.Fill;
_bimfaceInteropContainer.LoadCompletedEvent += async () =>
{
if (_project == null)
{
return;
}
if (_projectSite == null)
{
_projectSite = await BLLFactory.Instance
.GetDefaultByProjectID(_project.ID);
}
var relation = await BLLFactory.Instance
.GetDefaultByObjectTypeAndObjectIDOfPurpose
(HStation.Xhs.DataType.XhsProjectSite, _projectSite.ID, HStation.Xhs.Purpose.Simulation);
if (relation == null)
{
return;
}
var bimfaceFile = await BLLFactory.Instance.GetByID(relation.BimfaceFileID);
if (bimfaceFile == null)
{
return;
}
var viewToken = await BimfaceHelper.GetViewToken(bimfaceFile.BimfaceId);
if (string.IsNullOrEmpty(viewToken))
{
return;
}
await _bimfaceInteropContainer.LoadView(viewToken);
};
_bimfaceInteropContainer.LoadFailedEvent += () =>
{
TipFormHelper.ShowError("三维模型容器加载失败");
};
_bimfaceInteropContainer.LoadViewFailedEvent += (obj) =>
{
TipFormHelper.ShowError($"三维模型加载失败");
};
}
return _bimfaceInteropContainer;
}
#endregion
}
}