Skip to content

Commit

Permalink
fix(core): missing relation between IfcPropertySet and other entities…
Browse files Browse the repository at this point in the history
… in new definitions
  • Loading branch information
HoyosJuan committed Oct 31, 2024
1 parent e4de67b commit 938d6a8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
1 change: 1 addition & 0 deletions packages/core/src/ifc/IfcPropertiesManager/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<body>
<script type="module" src="./example.ts"></script>
<button id="download-btn">Download</button>
</body>

</html>
35 changes: 24 additions & 11 deletions packages/core/src/ifc/IfcPropertiesManager/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const file = await fetch(
const buffer = await file.arrayBuffer();
const model = await ifcLoader.load(new Uint8Array(buffer));

const indexer = components.get(OBC.IfcRelationsIndexer);

// By the time beign, the model relations must be processed to see the new relations when downloading the IFC
await indexer.process(model);

const propertiesManager = components.get(OBC.IfcPropertiesManager);

// Add a new pset
Expand All @@ -23,7 +28,12 @@ const prop = await propertiesManager.newSingleNumericProperty(
);

await propertiesManager.addPropToPset(model, pset.expressID, prop.expressID);
await propertiesManager.addElementToPset(model, pset.expressID, 186);
indexer.addEntitiesRelation(
model,
pset.expressID,
{ type: WEBIFC.IFCRELDEFINESBYPROPERTIES, inv: "DefinesOcurrence" },
186,
);

// Modify existing entity attributes
const entityAttributes = await model.getProperties(186);
Expand Down Expand Up @@ -52,14 +62,17 @@ const ifcTask = new WEBIFC.IFC4X3.IfcTask(
await propertiesManager.setData(model, ifcTask);

// Export modified model
const modifiedBuffer = await propertiesManager.saveToIfc(
model,
new Uint8Array(buffer),
);
const downloadBtn = document.getElementById("download-btn")!;
downloadBtn.addEventListener("click", async () => {
const modifiedBuffer = await propertiesManager.saveToIfc(
model,
new Uint8Array(buffer),
);

const modifiedFile = new File([modifiedBuffer], "small-modified.ifc");
const a = document.createElement("a");
a.href = URL.createObjectURL(modifiedFile);
a.download = modifiedFile.name;
// a.click();
URL.revokeObjectURL(a.href);
const modifiedFile = new File([modifiedBuffer], "small-modified.ifc");
const a = document.createElement("a");
a.href = URL.createObjectURL(modifiedFile);
a.download = modifiedFile.name;
a.click();
URL.revokeObjectURL(a.href);
});
23 changes: 5 additions & 18 deletions packages/core/src/ifc/IfcPropertiesManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ export class IfcPropertiesManager extends Component implements Disposable {
const schema = IfcPropertiesManager.getIFCSchema(model);
const { ownerHistoryHandle } = await this.getOwnerHistory(model);

// Create the Pset
const psetGlobalId = this.newGUID(model);
const psetName = new WEBIFC[schema].IfcLabel(name);
const psetDescription = description
Expand All @@ -217,23 +216,11 @@ export class IfcPropertiesManager extends Component implements Disposable {
psetDescription,
[],
);
pset.expressID = this.getNewExpressID(model);

// Create the Pset relation
const relGlobalId = this.newGUID(model);
const rel = new WEBIFC[schema].IfcRelDefinesByProperties(
relGlobalId,
ownerHistoryHandle,
null,
null,
[],
new WEBIFC.Handle(pset.expressID),
);
rel.expressID = this.getNewExpressID(model);

await this.setData(model, pset, rel);
pset.expressID = this.getNewExpressID(model);
await this.setData(model, pset);

return { pset, rel };
return { pset };
}

/**
Expand Down Expand Up @@ -370,7 +357,7 @@ export class IfcPropertiesManager extends Component implements Disposable {
indexer.addEntitiesRelation(
model,
psetID,
{ type: WEBIFC.IFCRELDEFINESBYPROPERTIES, inv: "IsDefinedBy" },
{ type: WEBIFC.IFCRELDEFINESBYPROPERTIES, inv: "DefinesOcurrence" },
...expressIDs,
);
}
Expand Down Expand Up @@ -429,7 +416,7 @@ export class IfcPropertiesManager extends Component implements Disposable {
throw new Error(`IfcPropertiesManager: ${relName} is unsoported.`);
}

const schema = model.ifcMetadata.schema;
const schema = IfcPropertiesManager.getIFCSchema(model);
const attributePositions = ifcRelAttrsPosition[relName];
// @ts-ignore safe to use ts-ignore as we are checking in the following line if the class exists.
const RelClass = WEBIFC[schema][relName];
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/ifc/IfcRelationsIndexer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@ export class IfcRelationsIndexer extends Component implements Disposable {
...relatedIDs: number[]
) {
const { type, inv } = rel;

// TODO: Allow to create the relation even if the model wasn't previously processed
const relationsMap = this.relationMaps[model.uuid];
if (!relationsMap) return;

Expand Down

0 comments on commit 938d6a8

Please sign in to comment.