forked from opensourceBIM/bimvie.ws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser.html
366 lines (341 loc) · 12.3 KB
/
browser.html
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<div class="browser">
<ul class="breadcrumb ih">
<li><a class="breadcrumbModel">Model</a> <span class="divider"></span></li>
<li><a class="breadcrumbClass">Class</a> <span class="divider"></span></li>
<li><a class="breadcrumbObject">Object</a> <span class="divider"></span></li>
<li class="active">Data</li>
</ul>
<div class="alert alert-info loadingDiv ih">Loading...</div>
<table class="typesTable initialhide table table-striped table-hover">
<thead></thead>
<tbody></tbody>
</table>
<table class="objectsTable initialhide table table-striped table-hover">
<thead>
<tr>
<th>Oid</th>
<th>Name</th>
<th>GUID</th>
</tr>
</thead>
<tbody></tbody>
</table>
<table class="objectTable initialhide table table-striped">
<thead>
<tr>
<th>Property</th>
<th>Value</th>
</tr>
</thead>
<tbody></tbody>
</table>
<div id="browserviewport" style="width: 1200px; height: 800px"></div>
</div>
<script>
function Browser(containerDiv, project, revision) {
var o = this;
o.revision = revision;
o.project = project;
this.loadObject = function(poid, oid) {
containerDiv.find(".loadingDiv").show();
o.loadProject(poid, function(){
o.oid = oid;
pushHistoryAppend({oid: oid, poid: poid, type: false}, "Browser");
var objectToShow = null;
Global.bimServerApi.getModel(poid, o.revision.oid, o.project.schema, false, function(model){
model.get(oid, function(object){
objectToShow = object;
containerDiv.find(".breadcrumb *").remove();
containerDiv.find(".breadcrumb").append("<li><a class=\"breadcrumbModel\">Model</a> <span class=\"divider\"></span></li>");
containerDiv.find(".breadcrumb").append("<li><a class=\"breadcrumbClass\">" + object.getType() + "</a> <span class=\"divider\"></span></li>");
containerDiv.find(".breadcrumb").append("<li class=\"active\">" + oid + "</li>");
containerDiv.find(".breadcrumb").show();
o.augmentBreadcrumbs();
containerDiv.find(".objectTable tbody tr").remove();
containerDiv.find("table").hide();
var schema = project.schema;
var baseUrl = null;
if (schema == "ifc2x3tc1") {
baseUrl = "https://standards.buildingsmart.org/IFC/RELEASE/IFC2x3/TC1/HTML/";
} else if (schema == "ifc4") {
baseUrl = "https://standards.buildingsmart.org/IFC/RELEASE/IFC4/ADD2/HTML/";
}
var typeDef = Global.bimServerApi.schemas[schema][object.getType()];
var docUrl = baseUrl + typeDef.domain + "/lexical/" + object.getType().toLowerCase() + ".htm";
containerDiv.find(".objectTable tbody").append("<tr class=\"extra\"><td>Type</td><td><a target=\"_blank\" href=\"" + docUrl + "\">" + object.getType() + "</a></td></tr>");
containerDiv.find(".objectTable tbody").append("<tr class=\"extra\"><td>Oid</td><td>" + oid + "</td></tr>");
object.fields.forEach(function(field){
var tr = $("<tr></tr>");
tr.attr("fieldName", field.name);
if (field.inverse == true) {
tr.append("<td style=\"color: #888888\"><i>" + field.name + "</i></td>");
} else {
tr.append("<td>" + field.name + "</td>");
}
containerDiv.find(".objectTable tbody").append(tr);
var td = $("<td>");
tr.append(td);
if (field.many) {
var getMethod = object["get" + field.name];
getMethod.call(object, function(listItem, index){
if (index > 0) {
td.append(", ");
}
if (typeof listItem == "string" || typeof listItem == "number") {
td.append(value);
} else if (Array.isArray(listItem)) {
listItem.forEach(function(item, index){
if (index != 0) {
td.append(", <br/>");
}
if (Array.isArray(item)) {
td.append("[");
item.forEach(function(subItem, subIndex){
if (subIndex != 0) {
td.append(", ");
}
if (subItem._v != null) {
td.append(subItem._v);
} else if (subItem._t != null) {
if (subItem._r != null) {
var link = $("<a>" + subItem._t + " (" + subItem._r + ")</a>");
link.attr("oid", subItem._r);
link.attr("type", subItem._t);
link.click(o.referenceClick);
td.append(link);
} else {
td.append(subItem._t + " (" + subItem.wrappedValueAsString + ")");
}
} else {
td.append(subItem);
}
});
td.append("]");
} else if (item._t != null) {
td.append(item._t + "(");
var v = item._v;
if (Array.isArray(v)) {
td.append("[");
v.forEach(function(subItem, subIndex){
if (subIndex != 0) {
td.append(", ");
}
if (subItem._v != null) {
td.append(subItem._v);
} else if (subItem._t != null) {
var link = $("<a>" + subItem.getType() + " (" + id + ")</a>");
link.attr("oid", subItem.oid);
link.attr("type", subItem.getType());
link.click(o.referenceClick);
td.append(link);
} else {
td.append(subItem);
}
});
td.append("]");
}
td.append(")");
} else {
td.append(item);
}
});
} else {
var id = listItem.oid;
if (listItem.getGlobalId != null) {
id = listItem.getGlobalId();
}
if (listItem._t != null) {
td.append(listItem._v);
} else {
var link = $("<a>" + listItem.getType() + " (" + id + ")</a>");
link.attr("oid", listItem.oid);
link.attr("type", listItem.getType());
link.click(o.referenceClick);
td.append(link);
}
}
});
} else {
var getMethod = object["get" + field.name];
if (getMethod != null) {
getMethod.call(object, function(value){
if (value != null) {
if (typeof value == "string" || typeof value == "number" || typeof value == "boolean") {
td.append("" + value);
} else {
if (value._t != null) {
td.append(value._v);
} else {
var id = value.oid;
if (value.getGlobalId != null) {
id = value.getGlobalId();
}
if (value != null && value.getType != null) {
var a = $("<a>" + value.getType() + " (" + id + ")</a>");
a.attr("type", value.getType());
a.attr("oid", value.oid);
a.click(o.referenceClick);
td.append(a);
}
}
}
}
});
}
}
});
}).done(function(){
containerDiv.find(".objectTable").show();
containerDiv.find(".loadingDiv").hide();
if (objectToShow.isA("IfcProduct")) {
if (objectToShow.object._rgeometry) {
o.viewer = new BIMSURFER.Viewer(Global.bimServerApi, "browserviewport");
o.viewer.loadScene(function(){
Global.scene = o.viewer.scene;
objectToShow.gid = objectToShow.object._rgeometry._i;
objectToShow.trans.mode = 0;
var models = {};
models[o.revision.oid] = model;
var geometryLoader = new GeometryLoader(Global.bimServerApi, models, o.viewer, "triangles");
geometryLoader.setLoadOids([o.revision.oid], [objectToShow]);
o.viewer.loadGeometry(geometryLoader);
});
}
} else {
if (o.viewer != null) {
o.viewer = null;
containerDiv.find("#browserviewport canvas").remove();
}
}
});
});
});
};
this.close = function() {
if (o.viewer != null) {
//o.viewer.destroy();
}
};
this.referenceClick = function(event) {
event.preventDefault();
o.loadObject(o.project.oid, $(this).attr("oid"));
};
this.objectClick = function(event) {
event.preventDefault();
var oid = $(this).parents("tr").attr("oid");
o.loadObject(o.project.oid, oid);
};
this.loadType = function(poid, className) {
containerDiv.find(".loadingDiv").show();
containerDiv.find(".breadcrumb").show();
o.loadProject(poid, function(){
pushHistoryAppend({type: className, poid: poid, oid: false}, "Browser");
containerDiv.find(".breadcrumb *").remove();
containerDiv.find(".breadcrumb").append("<li><a class=\"breadcrumbModel\">Model</a> <span class=\"divider\"></span></li>");
containerDiv.find(".breadcrumb").append("<li class=\"active\">" + className + "</li>");
o.augmentBreadcrumbs();
containerDiv.find(".objectsTable tbody tr").remove();
containerDiv.find("table").hide();
var counter = 0;
Global.bimServerApi.getModel(poid, o.revision.oid, o.project.schema, false, function(model){
model.getAllOfType(className, false, function(object){
var tr = $("<tr></tr>");
tr.attr("oid", object.oid);
var oidTd = $("<td></td>");
var oidA = $("<a>" + object.oid + "</a>");
oidA.click(o.objectClick);
oidTd.append(oidA);
tr.append(oidTd);
var nameTd = $("<td></td>");
if (object.getName != null) {
var nameA = $("<a>" + object.getName() + "</a>");
nameA.click(o.objectClick);
nameTd.append(nameA);
}
tr.append(nameTd);
var guidTd = $("<td></td>");
if (object.getGlobalId != null) {
var guidA = $("<a>" + object.getGlobalId() + "</a>");
guidA.click(o.objectClick);
guidTd.append(guidA);
}
tr.append(guidTd);
containerDiv.find(".objectsTable tbody").append(tr);
counter++;
if (counter > 1000) {
tr = $("<tr class=\"toomany\"><td></td><td>Too many objects to show</td><td></td></tr>");
containerDiv.find(".objectsTable tbody").append(tr);
return true;
}
}).done(function(){
containerDiv.find(".objectsTable").show();
containerDiv.find(".loadingDiv").hide();
});
});
});
};
this.typeClick = function() {
o.loadType(o.project.oid, $(this).parents("tr").attr("className"));
};
this.loadProject = function(poid, callback) {
Global.bimServerApi.call("ServiceInterface", "getProjectByPoid", {poid: poid}, function(project){
o.schema = project.schema;
callback();
});
};
this.loadRevision = function(poid) {
containerDiv.find(".breadcrumb").hide();
o.loadProject(poid, function(){
pushHistoryAppend({type: false, poid: poid, oid: false}, "Browser");
containerDiv.find(".breadcrumb *").remove();
containerDiv.find(".breadcrumb").append("<li class=\"active\">Model</li>");
o.augmentBreadcrumbs();
Global.bimServerApi.call("ServiceInterface", "getRevisionSummary", {roid: o.revision.oid}, function(data){
containerDiv.find(".typesTable tbody tr").remove();
containerDiv.find("table").hide();
containerDiv.find(".load3dButton, .browser .3dviewport").hide();
data.list.forEach(function(revisionSummaryContainer){
if (revisionSummaryContainer.types.length > 0) {
var tr = $("<tr class=\"header\"><td>" + revisionSummaryContainer.name + "</td><td>Occurances</td></tr>");
containerDiv.find(".typesTable tbody").append(tr);
revisionSummaryContainer.types.forEach(function(revisionSummaryType){
var tr = $("<tr></tr>");
tr.attr("className", revisionSummaryType.name);
var nameTd = $("<td>");
var nameA = $("<a>" + revisionSummaryType.name + "</a>");
nameA.click(o.typeClick);
nameTd.append(nameA);
tr.append(nameTd);
tr.append("<td>" + revisionSummaryType.count + "</td>");
containerDiv.find(".typesTable tbody").append(tr);
});
}
});
containerDiv.find(".typesTable").show();
});
});
};
this.augmentBreadcrumbs = function(){
containerDiv.find(".breadcrumb").find(".breadcrumbObject").click(function(){
o.loadObject(o.project.oid, $(this).html());
});
containerDiv.find(".breadcrumb").find(".breadcrumbClass").click(function(){
o.loadType(o.project.oid, $(this).html());
});
containerDiv.find(".breadcrumb").find(".breadcrumbModel").click(function(){
o.loadRevision(o.project.oid);
});
};
this.loadFromHistory = function(){
var history = History.getState().data;
var poid = history.poid;
if (history.type != null) {
o.loadType(poid, history.type);
} else if (history.oid != null) {
o.loadObject(poid, history.oid);
} else {
o.loadRevision(poid);
}
};
}
</script>