-
Notifications
You must be signed in to change notification settings - Fork 4
/
model.ts
97 lines (85 loc) · 2.31 KB
/
model.ts
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
import * as THREE from "three";
import * as WEBIFC from "web-ifc";
import {IfcLineObject} from "web-ifc";
import {IfcInfo} from "./IfcInfo";
export class Model {
ifcInfo = new IfcInfo(this);
get IfcOwnerHistory() {
return this.ifcInfo.IfcOwnerHistory;
}
material = new THREE.MeshLambertMaterial();
materialT = new THREE.MeshLambertMaterial({
transparent: true,
opacity: 0.2,
});
ifcAPI = new WEBIFC.IfcAPI();
private _modelID?: number;
get modelID() {
if (this._modelID === undefined) {
throw new Error("Model not initialized! Call the init() method.");
}
return this._modelID;
}
get context() {
return this.ifcInfo.ifcUnit.IfcGeometricRepresentationContext;
}
async init() {
await this.ifcAPI.Init();
this.ifcAPI.SetLogLevel(WEBIFC.LogLevel.LOG_LEVEL_OFF);
this._modelID = this.ifcAPI.CreateModel({schema: "IFC4X3_ADD2"});
}
set(item: WEBIFC.IfcLineObject) {
this.ifcAPI.WriteLine(this.modelID, item);
}
delete(
item: WEBIFC.IfcLineObject | WEBIFC.Handle<IfcLineObject> | null,
recursive = false
) {
if (item === null) {
return;
}
let foundItem: WEBIFC.IfcLineObject;
if (item instanceof WEBIFC.Handle) {
foundItem = this.ifcAPI.GetLine(this.modelID, item.value);
} else {
foundItem = item;
}
if (!foundItem) {
return;
}
if (recursive) {
for (const key in foundItem) {
// @ts-ignore
const value = foundItem[key];
if (value instanceof WEBIFC.Handle) {
this.delete(value);
}
}
}
this.ifcAPI.DeleteLine(this.modelID, foundItem.expressID);
}
get<T extends WEBIFC.IfcLineObject>(item: WEBIFC.Handle<T> | T | null) {
if (item === null) {
throw new Error("Item not found!");
}
if (item instanceof WEBIFC.Handle) {
return this.ifcAPI.GetLine(this.modelID, item.value) as T;
}
return item;
}
update() {
if (this._modelID === undefined) {
throw new Error("Malformed model!");
}
const model = this.ifcAPI.SaveModel(this._modelID);
this.ifcAPI.CloseModel(this._modelID);
this._modelID++;
this.ifcAPI.OpenModel(model);
}
export() {
if (this._modelID === undefined) {
throw new Error("Malformed model!");
}
return this.ifcAPI.SaveModel(this._modelID);
}
}