-
Notifications
You must be signed in to change notification settings - Fork 87
/
layers.html
176 lines (157 loc) · 5.12 KB
/
layers.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
<div class="layers">
<div class="spaced modelLoader">
No models loaded
<button class="btn btn-default btn-xs btnLoad">Load all</button>
</div>
<table class="table table-no-top">
<thead></thead>
<tbody>
</tbody>
</table>
</div>
<script>
function Layers(containerDiv, parent) {
var othis = this;
othis.layers = {};
othis.objectToLayer = {};
this.close = function(){};
this.toggleEye = function(oid, mode){
for (var roid in parent.models) {
var model = parent.models[roid];
var objects = othis.layers[oid].objects;
parent.setObjectVisibility(roid, Object.keys(objects).map(Number), mode);
}
};
this.getSelectedId = function(){
return -1;
};
this.hide = function(){
containerDiv.hide();
};
this.show = function(){
containerDiv.show();
};
this.objectVisibilityChanged = function(objects, oldModes){
for (var i=0; i<objects.length; i++) {
var object = objects[i];
var oldMode = oldModes[i];
var layers = othis.objectToLayer[object.oid];
var mode = object.trans.mode;
if (layers != null) {
layers.forEach(function(layer){
var info = othis.layers[layer.oid];
if (info == null) {
console.warn("Layer not found");
} else {
if (oldMode == 0) {
othis.layers[layer.oid].visible--;
} else if (oldMode == 1) {
othis.layers[layer.oid].transparent--;
}
if (mode == 0) {
othis.layers[layer.oid].visible++;
} else if (mode == 1) {
othis.layers[layer.oid].transparent++;
}
var eye = info.eye;
if (eye == null) {
console.warn("No eye");
} else {
eye.attr("mode", mode);
if (info.visible == info.total) {
eye.addClass("eyeopen").removeClass("eyeclosed").removeClass("eyehalfopen");
} else if (info.transparent == info.total) {
eye.addClass("eyehalfopen").removeClass("eyeopen").removeClass("eyeclosed");
} else if (info.visible == 0) {
eye.addClass("eyeclosed").removeClass("eyehalfopen").removeClass("eyeopen");
}
}
}
});
}
}
};
this.loadRevision = function(project, roid){
containerDiv.find(".modelLoader").hide();
if (project.lastRevisionId != -1 && project.nrSubProjects == 0) {
var model = parent.models[roid];
// containerDiv.find("table tbody tr").remove();
model.getAllOfType("IfcProduct", true, function(product){
othis.objectToLayer[product.oid] = [];
product.getRepresentation(function(productRepresentation){
if (productRepresentation != null) {
productRepresentation.getRepresentations(function(representation){
representation.getLayerAssignments(function(layer){
othis.objectToLayer[product.oid].push(layer);
if (othis.layers[layer.oid] == null) {
othis.layers[layer.oid] = {visible: 0, total: 0, transparent: 0, objects: {}};
}
// if (objectsToHide[product.oid] == null) {
// othis.layers[layer.oid].visible++;
// }
othis.layers[layer.oid].total++;
othis.layers[layer.oid].objects[product.oid] = true;
});
});
}
});
}).done(function(){
model.getAllOfType("IfcPresentationLayerAssignment", true, function(presentationLayerAssignment){
var tr = $("<tr>");
tr.attr("oid", presentationLayerAssignment.oid);
tr.append("<td>" + presentationLayerAssignment.getName() + "</td>");
var td = $("<td>");
var info = othis.layers[presentationLayerAssignment.oid];
if (info == null) {
console.log("no info");
} else {
var eye = $("<div>");
eye.addClass("eye");
if (info != null) {
if (info.visible == info.total) {
eye.addClass("eyeopen");
eye.attr("mode", 0);
} else if (info.transparent == info.total) {
eye.addClass("eyehalfopen");
eye.attr("mode", 1);
} else if (info.visible == 0) {
eye.addClass("eyeclosed");
eye.attr("mode", 2);
} else {
eye.attr("mode", 0);
}
}
eye.toggle(parent.threeDAspectVisible.get());
eye.attr("oid", presentationLayerAssignment.oid);
eye.click(function(){
var eye = $(this);
var mode = parseInt(eye.attr("mode"));
othis.toggleEye(eye.attr("oid"), (mode + 1) % 3);
});
td.append(eye);
td.append(" <span class=\"badge\" style=\"float: right\">" + (info == null ? 0 : info.total) + "</span>");
tr.append(td);
info.tr = tr;
info.eye = eye;
containerDiv.find("table tbody").append(tr);
}
}).done(function(){
if (containerDiv.find("table tbody tr").size() == 0) {
containerDiv.find("table tbody").append("<tr><td>No layers</td></tr>");
}
});
});
}
};
othis.unloadRevision = function(poid, roid) {
};
containerDiv.find(".btnLoad").click(parent.loadModel);
this.setShowEyes = function(show) {
containerDiv.find(".eye").toggle(show);
};
parent.objectVisibilityListeners.register(othis.objectVisibilityChanged);
parent.threeDAspectVisible.register(othis.setShowEyes);
parent.modelLoadedListeners.register(othis.loadRevision);
parent.modelUnloadedListeners.register(othis.unloadRevision);
};
</script>