lixiaojun
2024-12-20 94d10185010a7476021764f5b5cb59dc7d2b68f4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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;//项目站
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public async Task SetBindingData(long projectId)
        {
            var project = await BLLFactory<HStation.BLL.XhsProject>.Instance.GetByID(projectId);
            if (project == null)
            {
                return;
            }
            SetBindingData(project);
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(XhsProjectVmo project)
        {
            if (project == null)
            {
                return;
            }
            _project = project;
            this.PageTitle.Caption = $"{_project.Name}\r\n模型视图";
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData(XhsProjectExtensionsVmo project)
        {
            if (project == null)
            {
                return;
            }
            _project = project;
            _projectSite = project.SiteList.FirstOrDefault();
            this.PageTitle.Caption = $"{_project.Name}\r\n模型视图";
        }
 
        /// <summary>
        /// 初始化数据源
        /// </summary>
        public override void InitialDataSource()
        {
            base.InitialDataSource();
            InitialData();
        }
 
        /// <summary>
        /// 初始化数据
        /// 仅支持调用一次
        /// </summary>
        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<HStation.BLL.XhsProjectSite>.Instance
                            .GetDefaultByProjectID(_project.ID);
                    }
 
                    var relation = await BLLFactory<Yw.BLL.BimfaceFileRelation>.Instance
                        .GetDefaultByObjectTypeAndObjectIDOfPurpose
                            (HStation.Xhs.DataType.XhsProjectSite, _projectSite.ID, HStation.Xhs.Purpose.Simulation);
                    if (relation == null)
                    {
                        return;
                    }
 
                    var bimfaceFile = await BLLFactory<Yw.BLL.BimfaceFile>.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
 
    }
}