|
| 1 | +import { IFC4X3 as IFC } from "web-ifc"; |
| 2 | +import { v4 as uuidv4 } from "uuid"; |
| 3 | +import * as THREE from "three"; |
| 4 | +import { ClayObject, Model } from "../../core"; |
| 5 | +import { ClippingPlaneType } from "../../elements"; |
| 6 | +import { IfcUtils } from "../../utils/ifc-utils"; |
| 7 | +import { SpatialChildren } from "../SpatialChildren"; |
| 8 | + |
| 9 | +export class Project extends ClayObject { |
| 10 | + attributes: IFC.IfcProject; |
| 11 | + |
| 12 | + ownerHistory: IFC.IfcOwnerHistory; |
| 13 | + |
| 14 | + spatialChildren: SpatialChildren; |
| 15 | + |
| 16 | + constructor(model: Model) { |
| 17 | + super(model); |
| 18 | + |
| 19 | + if (!this.model.types.has("clipping-planes")) { |
| 20 | + this.model.types.set("clipping-planes", new ClippingPlaneType(model)); |
| 21 | + } |
| 22 | + |
| 23 | + const organization = new IFC.IfcOrganization( |
| 24 | + null, |
| 25 | + new IFC.IfcLabel("That Open Company"), |
| 26 | + null, |
| 27 | + null, |
| 28 | + null, |
| 29 | + ); |
| 30 | + |
| 31 | + const person = new IFC.IfcPerson( |
| 32 | + null, |
| 33 | + null, |
| 34 | + null, |
| 35 | + null, |
| 36 | + null, |
| 37 | + null, |
| 38 | + null, |
| 39 | + null, |
| 40 | + ); |
| 41 | + |
| 42 | + const personAndOrganization = new IFC.IfcPersonAndOrganization( |
| 43 | + person, |
| 44 | + organization, |
| 45 | + null, |
| 46 | + ); |
| 47 | + |
| 48 | + const application = new IFC.IfcApplication( |
| 49 | + organization, |
| 50 | + new IFC.IfcLabel("2.4.0"), |
| 51 | + new IFC.IfcLabel("CLAY"), |
| 52 | + new IFC.IfcLabel("CLAY"), |
| 53 | + ); |
| 54 | + |
| 55 | + this.ownerHistory = new IFC.IfcOwnerHistory( |
| 56 | + personAndOrganization, |
| 57 | + application, |
| 58 | + null, |
| 59 | + IFC.IfcChangeActionEnum.NOTDEFINED, |
| 60 | + null, |
| 61 | + null, |
| 62 | + null, |
| 63 | + new IFC.IfcTimeStamp(new Date().getTime()), |
| 64 | + ); |
| 65 | + |
| 66 | + const context = new IFC.IfcGeometricRepresentationContext( |
| 67 | + null, |
| 68 | + null, |
| 69 | + new IFC.IfcDimensionCount(3), |
| 70 | + new IFC.IfcReal(1.0e-5), |
| 71 | + new IFC.IfcAxis2Placement3D( |
| 72 | + IfcUtils.point(new THREE.Vector3()), |
| 73 | + null, |
| 74 | + null, |
| 75 | + ), |
| 76 | + null, |
| 77 | + ); |
| 78 | + |
| 79 | + const lengthUnit = new IFC.IfcSIUnit( |
| 80 | + IFC.IfcUnitEnum.LENGTHUNIT, |
| 81 | + null, |
| 82 | + IFC.IfcSIUnitName.METRE, |
| 83 | + ); |
| 84 | + |
| 85 | + const areaUnit = new IFC.IfcSIUnit( |
| 86 | + IFC.IfcUnitEnum.AREAUNIT, |
| 87 | + null, |
| 88 | + IFC.IfcSIUnitName.SQUARE_METRE, |
| 89 | + ); |
| 90 | + |
| 91 | + const volumeUnit = new IFC.IfcSIUnit( |
| 92 | + IFC.IfcUnitEnum.AREAUNIT, |
| 93 | + null, |
| 94 | + IFC.IfcSIUnitName.SQUARE_METRE, |
| 95 | + ); |
| 96 | + |
| 97 | + const units = new IFC.IfcUnitAssignment([lengthUnit, areaUnit, volumeUnit]); |
| 98 | + |
| 99 | + this.attributes = new IFC.IfcProject( |
| 100 | + new IFC.IfcGloballyUniqueId(uuidv4()), |
| 101 | + this.ownerHistory, |
| 102 | + null, |
| 103 | + null, |
| 104 | + null, |
| 105 | + null, |
| 106 | + null, |
| 107 | + [context], |
| 108 | + units, |
| 109 | + ); |
| 110 | + |
| 111 | + this.model.set(this.attributes); |
| 112 | + |
| 113 | + this.spatialChildren = new SpatialChildren( |
| 114 | + model, |
| 115 | + this.ownerHistory, |
| 116 | + this.attributes, |
| 117 | + ); |
| 118 | + } |
| 119 | + |
| 120 | + update(): void { |
| 121 | + this.model.set(this.attributes); |
| 122 | + } |
| 123 | +} |
0 commit comments