lixiaojun
2024-09-15 9c9a27924cbaac23e179bbd7aac0899563d19572
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
 
 
using DevExpress.CodeParser;
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
    }
}