Skip to content

Commit

Permalink
feat(core): updates IfcMetadataReader
Browse files Browse the repository at this point in the history
  • Loading branch information
HoyosJuan committed Jun 2, 2024
1 parent 0b96dae commit 704f45b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 22 deletions.
7 changes: 4 additions & 3 deletions packages/core/src/fragments/IfcGeometryTiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,11 @@ export class IfcGeometryTiler extends Component implements Disposable {

const group = new FRAGS.FragmentsGroup();

const { FILE_NAME, FILE_DESCRIPTION } = WEBIFC;
group.ifcMetadata = {
name: this._metaData.get(this.webIfc, FILE_NAME),
description: this._metaData.get(this.webIfc, FILE_DESCRIPTION),
name: "",
description: "",
...this._metaData.getNameInfo(this.webIfc),
...this._metaData.getDescriptionInfo(this.webIfc),
schema: (this.webIfc.GetModelSchema(0) as FRAGS.IfcSchema) || "IFC2X3",
maxExpressID: this.webIfc.GetMaxExpressID(0),
};
Expand Down
7 changes: 4 additions & 3 deletions packages/core/src/fragments/IfcLoader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ export class IfcLoader extends Component implements Disposable {

const group = new FRAGS.FragmentsGroup();

const { FILE_NAME, FILE_DESCRIPTION } = WEBIFC;
group.ifcMetadata = {
name: this._metaData.get(this.webIfc, FILE_NAME),
description: this._metaData.get(this.webIfc, FILE_DESCRIPTION),
name: "",
description: "",
...this._metaData.getNameInfo(this.webIfc),
...this._metaData.getDescriptionInfo(this.webIfc),
schema: (this.webIfc.GetModelSchema(0) as FRAGS.IfcSchema) || "IFC2X3",
maxExpressID: this.webIfc.GetMaxExpressID(0),
};
Expand Down
61 changes: 45 additions & 16 deletions packages/core/src/fragments/IfcLoader/src/ifc-metadata-reader.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,51 @@
import * as WEBIFC from "web-ifc";

// https://standards.buildingsmart.org/documents/Implementation/ImplementationGuide_IFCHeaderData_Version_1.0.2.pdf

export class IfcMetadataReader {
get(webIfc: WEBIFC.IfcAPI, type: number) {
let description = "";
const descriptionData = webIfc.GetHeaderLine(0, type) || "";
if (!descriptionData) return description;
for (const arg of descriptionData.arguments) {
if (arg === null || arg === undefined) {
continue;
}
if (Array.isArray(arg)) {
for (const subArg of arg) {
description += `${subArg.value}|`;
}
} else {
description += `${arg.value}|`;
}
getNameInfo(webIfc: WEBIFC.IfcAPI) {
const data: Record<string, any> = {};
const { arguments: dataArguments } =
webIfc.GetHeaderLine(0, WEBIFC.FILE_NAME) || {};
if (!dataArguments) return data;
const [
name,
timeStamp,
author,
organization,
preprocessorVersion,
originatingSystem,
authorization,
] = dataArguments;
if (name?.value) data.name = name.value;
if (timeStamp?.value) data.creationDate = new Date(timeStamp.value);
if (author) {
data.author = {} as Record<string, any>;
const [authorName, authorEmail] = author;
if (authorName?.value) data.author.name = authorName.value;
if (authorEmail?.value) data.author.email = authorEmail.value;
}
if (organization[0]?.value) data.organization = organization[0].value;
if (preprocessorVersion?.value)
data.preprocessorVersion = preprocessorVersion?.value;
if (originatingSystem?.value)
data.originatingSystem = originatingSystem?.value;
if (authorization?.value) data.authorization = authorization?.value;
return data;
}

getDescriptionInfo(webIfc: WEBIFC.IfcAPI) {
const data: Record<string, any> = {};
const { arguments: dataArguments } =
webIfc.GetHeaderLine(0, WEBIFC.FILE_DESCRIPTION) || {};
if (!dataArguments) return data;
const [description, implementationLevel] = dataArguments;
if (description[0]?.value) {
const viewDefinition = description[0].value.match(/\[([^\]]+)\]/);
if (viewDefinition[1]) data.viewDefinition = viewDefinition[1];
}
return description;
if (implementationLevel?.value)
data.implementationLevel = implementationLevel.value;
return data;
}
}

0 comments on commit 704f45b

Please sign in to comment.