Skip to content

Commit

Permalink
fix(core): type psets not reviewed on IDS PropertyFacet
Browse files Browse the repository at this point in the history
  • Loading branch information
HoyosJuan committed Oct 25, 2024
1 parent ca1ef1f commit 4aff276
Showing 1 changed file with 60 additions and 12 deletions.
72 changes: 60 additions & 12 deletions packages/core/src/openbim/IDSSpecifications/src/facets/Property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class IDSProperty extends IDSFacet {
dataType?: string;
uri?: string;

// These are defined by the IDS specification
private _unsupportedTypes = [
WEBIFC.IFCCOMPLEXPROPERTY,
WEBIFC.IFCPHYSICALCOMPLEXQUANTITY,
Expand Down Expand Up @@ -271,7 +272,7 @@ export class IDSProperty extends IDSFacet {
}

private getItemsAttrName(type: number) {
let propsListName: string | undefined;
let propsListName: "HasProperties" | "Quantities" | undefined;
if (type === WEBIFC.IFCPROPERTYSET) propsListName = "HasProperties";
if (type === WEBIFC.IFCELEMENTQUANTITY) propsListName = "Quantities";
return propsListName;
Expand All @@ -283,16 +284,70 @@ export class IDSProperty extends IDSFacet {
);
}

// IFCPROPERTYSET from type must be get as well
private async getPsets(model: FRAGS.FragmentsGroup, expressID: number) {
private async getPsetProps(
model: FRAGS.FragmentsGroup,
attrs: Record<string, any>,
propsListName: "HasProperties" | "Quantities",
) {
const attrsClone = structuredClone(attrs);
const props: Record<string, any>[] = [];
const list = attrsClone[propsListName];
if (!list) return props;
for (const { value } of list) {
const propAttrs = await model.getProperties(value);
if (propAttrs) props.push(propAttrs);
}
attrsClone[propsListName] = props;
return attrsClone;
}

private async getTypePsets(model: FRAGS.FragmentsGroup, expressID: number) {
const sets: Record<string, any>[] = [];

const indexer = this.components.get(IfcRelationsIndexer);
const types = indexer.getEntityRelations(model, expressID, "IsTypedBy");
if (!(types && types[0])) return sets;

const typeAttrs = await model.getProperties(types[0]);
if (
!(
typeAttrs &&
"HasPropertySets" in typeAttrs &&
Array.isArray(typeAttrs.HasPropertySets)
)
) {
return sets;
}

for (const { value } of typeAttrs.HasPropertySets) {
const psetAttrs = await model.getProperties(value);
if (
!(
psetAttrs &&
"HasProperties" in psetAttrs &&
Array.isArray(psetAttrs.HasProperties)
)
) {
continue;
}

const pset = await this.getPsetProps(model, psetAttrs, "HasProperties");
sets.push(pset);
}

return sets;
}

private async getPsets(model: FRAGS.FragmentsGroup, expressID: number) {
const sets = await this.getTypePsets(model, expressID);

const indexer = this.components.get(IfcRelationsIndexer);
const definitions = indexer.getEntityRelations(
model,
expressID,
"IsDefinedBy",
);

if (!definitions) return sets;

for (const definitionID of definitions) {
Expand All @@ -302,15 +357,8 @@ export class IDSProperty extends IDSFacet {
const propsListName = this.getItemsAttrName(attrs.type);
if (!propsListName) continue;

const attrsClone = structuredClone(attrs);
const props: Record<string, any>[] = [];
for (const { value } of attrsClone[propsListName]) {
const propAttrs = await model.getProperties(value);
if (propAttrs) props.push(propAttrs);
}
attrsClone[propsListName] = props;

sets.push(attrsClone);
const pset = await this.getPsetProps(model, attrs, propsListName);
sets.push(pset);
}

return sets;
Expand Down

0 comments on commit 4aff276

Please sign in to comment.