Skip to content

Commit 5786e57

Browse files
committed
fix(core): ids property facet was failing when it doesn't have to
1 parent a5f5b69 commit 5786e57

File tree

1 file changed

+38
-63
lines changed
  • packages/core/src/openbim/IDSSpecifications/src/facets

1 file changed

+38
-63
lines changed

packages/core/src/openbim/IDSSpecifications/src/facets/Property.ts

Lines changed: 38 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ export class IDSProperty extends IDSFacet {
143143
const sets = await this.getPsets(model, expressID);
144144
const matchingSets = sets.filter((set) => {
145145
const result = this.evalRequirement(
146-
set.Name?.value ?? null,
146+
set.Name ?? null,
147147
this.propertySet,
148148
"PropertySet",
149149
);
150150
if (!result) return false;
151151
checks.push({
152-
currentValue: set.Name.value,
152+
currentValue: set.Name,
153153
parameter: "PropertySet",
154154
pass: true,
155155
requiredValue: this.propertySet.parameter,
@@ -168,8 +168,7 @@ export class IDSProperty extends IDSFacet {
168168
}
169169

170170
for (const set of matchingSets) {
171-
const itemsAttrName = this.getItemsAttrName(set.type);
172-
if (!itemsAttrName) {
171+
if (!("Properties" in set)) {
173172
checks.push({
174173
currentValue: null,
175174
parameter: "BaseName",
@@ -179,7 +178,7 @@ export class IDSProperty extends IDSFacet {
179178
continue;
180179
}
181180

182-
const items = set[itemsAttrName];
181+
const items = set.Properties;
183182
const matchingItems = items.filter((item: any) => {
184183
if (this._unsupportedTypes.includes(item.type)) {
185184
return false;
@@ -216,54 +215,6 @@ export class IDSProperty extends IDSFacet {
216215
}
217216
}
218217

219-
// for (const definitionID of definitions) {
220-
// const definitionAttrs = await model.getProperties(definitionID);
221-
// if (!definitionAttrs) continue;
222-
223-
// const psetNameMatches = this.evalRequirement(
224-
// definitionAttrs.Name?.value ?? null,
225-
// this.propertySet,
226-
// "Property Set",
227-
// );
228-
// if (!psetNameMatches) continue;
229-
230-
// checks.push({
231-
// currentValue: definitionAttrs.Name.value,
232-
// parameter: "Property Set",
233-
// pass: true,
234-
// requiredValue: this.propertySet.parameter,
235-
// });
236-
237-
// let propsListName: string | undefined;
238-
// if (definitionAttrs.type === WEBIFC.IFCPROPERTYSET)
239-
// propsListName = "HasProperties";
240-
// if (definitionAttrs.type === WEBIFC.IFCELEMENTQUANTITY)
241-
// propsListName = "Quantities";
242-
// if (!propsListName) continue;
243-
244-
// for (const handle of definitionAttrs[propsListName]) {
245-
// const propAttrs = await model.getProperties(handle.value);
246-
// if (!propAttrs) continue;
247-
248-
// const baseNameMatches = this.evalRequirement(
249-
// propAttrs.Name?.value ?? null,
250-
// this.baseName,
251-
// "Base Name",
252-
// );
253-
254-
// if (!baseNameMatches) continue;
255-
256-
// checks.push({
257-
// currentValue: propAttrs.Name.value,
258-
// parameter: "Base Name",
259-
// pass: true,
260-
// requiredValue: this.baseName.parameter,
261-
// });
262-
263-
// this.evalValue(propAttrs, checks);
264-
// }
265-
// }
266-
267218
result.pass = checks.every(({ pass }) => pass);
268219
}
269220

@@ -285,20 +236,23 @@ export class IDSProperty extends IDSFacet {
285236
);
286237
}
287238

288-
private async getPsetProps(
239+
private async simplifyPset(
289240
model: FRAGS.FragmentsGroup,
290241
attrs: Record<string, any>,
291242
propsListName: "HasProperties" | "Quantities",
292243
) {
293-
const attrsClone = structuredClone(attrs);
294244
const props: Record<string, any>[] = [];
295-
const list = attrsClone[propsListName];
296-
if (!list) return props;
245+
const list = attrs[propsListName];
246+
if (!list) return attrs;
297247
for (const { value } of list) {
298248
const propAttrs = await model.getProperties(value);
299249
if (propAttrs) props.push(propAttrs);
300250
}
301-
attrsClone[propsListName] = props;
251+
const attrsClone = {
252+
Name: attrs.Name?.value,
253+
Properties: props,
254+
type: attrs.type,
255+
};
302256
return attrsClone;
303257
}
304258

@@ -332,15 +286,15 @@ export class IDSProperty extends IDSFacet {
332286
continue;
333287
}
334288

335-
const pset = await this.getPsetProps(model, psetAttrs, "HasProperties");
289+
const pset = await this.simplifyPset(model, psetAttrs, "HasProperties");
336290
sets.push(pset);
337291
}
338292

339293
return sets;
340294
}
341295

342296
private async getPsets(model: FRAGS.FragmentsGroup, expressID: number) {
343-
const sets = await this.getTypePsets(model, expressID);
297+
const typePsets = await this.getTypePsets(model, expressID);
344298

345299
const indexer = this.components.get(IfcRelationsIndexer);
346300
const definitions = indexer.getEntityRelations(
@@ -349,7 +303,9 @@ export class IDSProperty extends IDSFacet {
349303
"IsDefinedBy",
350304
);
351305

352-
if (!definitions) return sets;
306+
if (!definitions) return typePsets;
307+
308+
const sets: Record<string, any>[] = [];
353309

354310
for (const definitionID of definitions) {
355311
const attrs = await model.getProperties(definitionID);
@@ -358,8 +314,27 @@ export class IDSProperty extends IDSFacet {
358314
const propsListName = this.getItemsAttrName(attrs.type);
359315
if (!propsListName) continue;
360316

361-
const pset = await this.getPsetProps(model, attrs, propsListName);
362-
sets.push(pset);
317+
const occurencePset = await this.simplifyPset(
318+
model,
319+
attrs,
320+
propsListName,
321+
);
322+
323+
const typePset = typePsets.find(
324+
({ Name }) => Name === occurencePset.Name,
325+
);
326+
327+
if (typePset) {
328+
for (const prop of typePset.Properties) {
329+
const name = prop.Name?.value;
330+
const existingProp = occurencePset.Properties.find(
331+
({ Name }: { Name: { value: string } }) => Name.value === name,
332+
);
333+
if (!existingProp) occurencePset.Properties.push(prop);
334+
}
335+
}
336+
337+
sets.push(occurencePset);
363338
}
364339

365340
return sets;

0 commit comments

Comments
 (0)