tx
2025-04-09 fa7510e1ed63df0366787fa4ed1b3db6426d2b46
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
 
namespace TProduct.WinFrmUI.TBase
{
 
    public partial class ProductTestBimfaceCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        private TProduct.WinFrmUI.Bimface.ViewWebBrowser bimfaceContainer1;
 
        public ProductTestBimfaceCtrl()
        {
            InitializeComponent();
 
            this.bimfaceContainer1 = new TProduct.WinFrmUI.Bimface.ViewWebBrowser();
            this.bimfaceContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.bimfaceContainer1.Location = new System.Drawing.Point(0, 0);
            this.bimfaceContainer1.Name = "bimfaceContainer1";
            this.bimfaceContainer1.Size = new System.Drawing.Size(210, 160);
            this.bimfaceContainer1.TabIndex = 0;
            this.Controls.Add(this.bimfaceContainer1);
           
        }
 
        public event Action<string> ClickObjectEvent;
        public event Action BimLoadCompletedEvent;
 
 
        private bool _isInitial = false;//BIM是否加载完成
        public bool SetBindingData(string url, out string error_info)
        {
            //var url = System.Environment.CurrentDirectory + @"\Model3d\valve\index.html";
            if (!System.IO.File.Exists(url))
            {
                error_info = "文件不存在";
                return false;
            }
 
            this.SetUrlPath(url);
            error_info = null;
            return true;
        }
        public void SetUrlPath(string url)
        {
            this.bimfaceContainer1.WebBrowserEvents.LoadCompletedEvent += () =>
              {//页面加载完成,BIM不一定加载完成
                  //this.Invoke(new Action(  () =>
                  //{
                  //    //var task = this.bimfaceContainer1.LoadBIM(_viewtoken);
                  //    //await task;
                  //    //if (!string.IsNullOrEmpty(task.Result.Message))
                  //    //{
                  //    //    //LogHelper.WriteLog(task.Result.Message);
                  //    //    XtraMessageBox.Show(task.Result.Message);
                  //    //}
                  //}));
              };
            this.bimfaceContainer1.WebBrowserEvents.BimLoadCompletedEvent += () =>
            {//BIM加载完成
                _isInitial = true;
                this.Invoke(new Action(() =>
                {
                    this.BimLoadCompletedEvent?.Invoke();
                }));
            };
 
            this.bimfaceContainer1.WebBrowserEvents.LoadFailedEvent += () =>
              {//BIM加载失败
                  this.Invoke(new Action(() =>
                  {
                      XtraMessageBox.Show("BIM文件加载失败!");
                  }));
              };
            this.bimfaceContainer1.WebBrowserEvents.ClickObjectEvent += (objectid) =>
              {//点击事件
                  this.Invoke(new Action(() =>
                  {
                      this.ClickObjectEvent?.Invoke(objectid);
                  }));
              };
            this.bimfaceContainer1.WebBrowserEvents.HandingErrorEvent += (error) =>
              {//操作失败
 
              };
 
            this.bimfaceContainer1.InitialWebBrowserUrl(url);
        }
 
        /// <summary>
        /// 使构建ID显示高亮
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public Task<TProduct.Model.WebBrowserResponse> OverrideComponentsColorByIds(List<long> ids)
        {
            if (!_isInitial)
                return null;
            return this.bimfaceContainer1.OverrideComponentsColorByIds(ids);
        }
 
        /// <summary>
        /// 恢复高亮的构建颜色
        /// </summary>
        public Task<TProduct.Model.WebBrowserResponse> RestoreComponentsColorByIds()
        {
            if (!_isInitial)
                return null;
            return this.bimfaceContainer1.RestoreComponentsColorByIds();
        }
 
        /// <summary>
        /// 显示构件
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public Task<TProduct.Model.WebBrowserResponse> ShowComponents(List<long> ids)
        {
            if (!_isInitial)
                return null;
            return this.bimfaceContainer1.ShowComponents(ids);
        }
 
        /// <summary>
        /// 隐藏构件
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public Task<TProduct.Model.WebBrowserResponse> HideComponents(List<long> ids)
        {
            if (!_isInitial)
                return null;
            return this.bimfaceContainer1.HideComponents(ids);
        }
 
        /// <summary>
        /// 批量改变部件颜色
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public Task<TProduct.Model.WebBrowserResponse> ChangeComponentsColor(string json)
        {
            if (!_isInitial)
                return null;
            return this.bimfaceContainer1.ChangeComponentsColor(json);
        }
 
        /// <summary>
        /// 改变部件颜色
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public Task<TProduct.Model.WebBrowserResponse> ChangeComponentColor(string json)
        {
            if (!_isInitial)
                return null;
            return this.bimfaceContainer1.ChangeComponentColor(json);
        }
 
        /// <summary>
        /// 恢复部件颜色
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public Task<TProduct.Model.WebBrowserResponse> RecoverComponentsColor(List<long> ids)
        {
            if (!_isInitial)
                return null;
            return this.bimfaceContainer1.RecoverComponentsColor(ids);
        }
 
        /// <summary>
        /// 设置构件半透明
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public Task<TProduct.Model.WebBrowserResponse> SetComponentsTranslucent(List<long> ids)
        {
            if (!_isInitial)
                return null;
            return this.bimfaceContainer1.SetComponentsTranslucent(ids);
        }
 
        /// <summary>
        /// 取消构件半透明
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public Task<TProduct.Model.WebBrowserResponse> SetComponentsOpaque(List<long> ids)
        {
            if (!_isInitial)
                return null;
            return this.bimfaceContainer1.SetComponentsOpaque(ids);
        }
 
        /// <summary>
        /// 添加监控面板
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public Task<TProduct.Model.WebBrowserResponse> AddMinitorPanel(string json)
        {
            if (!_isInitial)
                return null;
            return this.bimfaceContainer1.AddMinitorPanel(json);
        }
 
        /// <summary>
        /// 移动监控面板
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public Task<TProduct.Model.WebBrowserResponse> MoveMinitorPanel(string json)
        {
            if (!_isInitial)
                return null;
            return this.bimfaceContainer1.MoveMinitorPanel(json);
        }
 
        /// <summary>
        /// 移除监控面板
        /// </summary>
        /// <param name="panelId"></param>
        /// <returns></returns>
        public Task<TProduct.Model.WebBrowserResponse> RemoveMinitorPanel(string panelId)
        {
            if (!_isInitial)
                return null;
            return this.bimfaceContainer1.RemoveMinitorPanel(panelId);
        }
 
 
 
        /// <summary>
        ///  
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public Task<TProduct.Model.WebBrowserResponse> refreshMonitorValue(List<TProduct.Model.MonitorPointValue> list)
        {
            if (!_isInitial)
                return null;
            if (list == null || list.Count() == 0)
                return null;
            var listMonitorValue4Html = new List<MonitorValue4Html>();
            foreach(var m in list)
            {
                listMonitorValue4Html.Add(new MonitorValue4Html() { PointID = m.ID.ToString(), Value = m.Value.ToString() });
            }
            var json = TProduct.JsonHelper.Object2Json<List<MonitorValue4Html>>(listMonitorValue4Html);
            return this.bimfaceContainer1.EvaluateScriptAsync("refreshMonitorValue(" + json + ")");
        }
        class MonitorValue4Html
        {
            public String PointID { get; set; }
            public String Value { get; set; }
        }
 
    }
}