From a40a3cce1a0995b8fcc4ca0c187a6934b25f8fe0 Mon Sep 17 00:00:00 2001 From: Juan Hoyos Date: Thu, 17 Oct 2024 14:53:45 -0500 Subject: [PATCH] fix(core): missing information when importing IDS files --- .../src/openbim/IDSSpecifications/example.ts | 27 +++++++++++-------- .../src/openbim/IDSSpecifications/index.ts | 19 ++++++++++--- .../src/importers/attribute.ts | 1 + .../src/importers/classification.ts | 1 + .../IDSSpecifications/src/importers/entity.ts | 1 + .../src/importers/property.ts | 2 ++ 6 files changed, 36 insertions(+), 15 deletions(-) diff --git a/packages/core/src/openbim/IDSSpecifications/example.ts b/packages/core/src/openbim/IDSSpecifications/example.ts index 2bae2787a..124a5dfe1 100644 --- a/packages/core/src/openbim/IDSSpecifications/example.ts +++ b/packages/core/src/openbim/IDSSpecifications/example.ts @@ -16,9 +16,14 @@ await ifcLoader.setup(); // await indexer.process(model); const ids = components.get(OBC.IDSSpecifications); -const specification = ids.create("My First IDS!", ["IFC4X3_ADD2"]); -specification.description = "Description"; -specification.instructions = "Instructions"; +const idsFile = await fetch("/resources/specs.ids"); +const idsContent = await idsFile.text(); +const specs = ids.load(idsContent); +console.log(ids, specs); + +// const specification = ids.create("My First IDS!", ["IFC4X3_ADD2"]); +// specification.description = "Description"; +// specification.instructions = "Instructions"; // Define some facets to be used in specifications const entityFacet = new OBC.IDSEntity(components, { @@ -26,7 +31,7 @@ const entityFacet = new OBC.IDSEntity(components, { parameter: ["IFCSLAB", "IFCWALL"], }); -specification.applicability.add(entityFacet); +// specification.applicability.add(entityFacet); const propertyFacet = new OBC.IDSProperty( components, @@ -36,14 +41,14 @@ const propertyFacet = new OBC.IDSProperty( propertyFacet.value = { type: "simple", parameter: false }; -specification.requirements.add(propertyFacet); +// specification.requirements.add(propertyFacet); -const idsTitle = "My Custom IDS"; -const idsExport = ids.export({ title: idsTitle }); -const file = new File([idsExport], "idsTitle.ids"); -const a = document.createElement("a"); -a.href = URL.createObjectURL(file); -a.download = file.name; +// const idsTitle = "My Custom IDS"; +// const idsExport = ids.export({ title: idsTitle }); +// const file = new File([idsExport], "idsTitle.ids"); +// const a = document.createElement("a"); +// a.href = URL.createObjectURL(file); +// a.download = file.name; // a.click(); // URL.revokeObjectURL(a.href); diff --git a/packages/core/src/openbim/IDSSpecifications/index.ts b/packages/core/src/openbim/IDSSpecifications/index.ts index 778c05051..9261d9659 100644 --- a/packages/core/src/openbim/IDSSpecifications/index.ts +++ b/packages/core/src/openbim/IDSSpecifications/index.ts @@ -75,15 +75,15 @@ export class IDSSpecifications extends Component { * * @returns The newly created IDSSpecification instance. */ - create(name: string, ifcVersion: IfcVersion[]) { + create(name: string, ifcVersion: IfcVersion[], identifier?: string) { const specification = new IDSSpecification( this.components, name, ifcVersion, ); + if (identifier) specification.identifier = identifier; this.list.set(specification.identifier, specification); - return specification; } @@ -106,7 +106,8 @@ export class IDSSpecifications extends Component { : [specifications.specification]; for (const spec of specs) { - const { name, ifcVersion } = spec; + const { name, ifcVersion, description, instructions, identifier } = + spec; if (!(name && ifcVersion)) continue; const applicabilities: IDSFacet[] = []; @@ -130,8 +131,11 @@ export class IDSSpecifications extends Component { } } + let requirementsDescription: string | undefined; + if (requirements) { const { maxOccurs, ...rest } = requirements; + requirementsDescription = requirements.description; const facets = Array.isArray(rest) ? rest : [rest]; for (const facet of facets) { for (const facetName in facet) { @@ -162,7 +166,14 @@ export class IDSSpecifications extends Component { } if (applicabilities.length > 0 && reqs.length > 0) { - const specification = this.create(name, ifcVersion.split(/\s+/)); + const specification = this.create( + name, + ifcVersion.split(/\s+/), + identifier, + ); + specification.description = description; + specification.instructions = instructions; + specification.requirementsDescription = requirementsDescription; specification.applicability.add(...applicabilities); specification.requirements.add(...reqs); result.push(specification); diff --git a/packages/core/src/openbim/IDSSpecifications/src/importers/attribute.ts b/packages/core/src/openbim/IDSSpecifications/src/importers/attribute.ts index 8c0ac4865..858f1ee56 100644 --- a/packages/core/src/openbim/IDSSpecifications/src/importers/attribute.ts +++ b/packages/core/src/openbim/IDSSpecifications/src/importers/attribute.ts @@ -14,6 +14,7 @@ export const createAttributeFacets = ( const facet = new IDSAttribute(components, name); if (element.cardinality) facet.cardinality = element.cardinality; facet.value = getParameterValue(element.value); + facet.instructions = element.instructions; facets.push(facet); } return facets; diff --git a/packages/core/src/openbim/IDSSpecifications/src/importers/classification.ts b/packages/core/src/openbim/IDSSpecifications/src/importers/classification.ts index 6d04214ab..b68153b5e 100644 --- a/packages/core/src/openbim/IDSSpecifications/src/importers/classification.ts +++ b/packages/core/src/openbim/IDSSpecifications/src/importers/classification.ts @@ -22,6 +22,7 @@ export const createClassificationFacets = ( } facet.value = value; facet.uri = element.uri; + facet.instructions = element.instructions; facets.push(facet); } return facets; diff --git a/packages/core/src/openbim/IDSSpecifications/src/importers/entity.ts b/packages/core/src/openbim/IDSSpecifications/src/importers/entity.ts index 1e98ecb64..f89142ba5 100644 --- a/packages/core/src/openbim/IDSSpecifications/src/importers/entity.ts +++ b/packages/core/src/openbim/IDSSpecifications/src/importers/entity.ts @@ -11,6 +11,7 @@ export const createEntityFacets = (components: Components, elements: any) => { const facet = new IDSEntity(components, name); if (element.cardinality) facet.cardinality = element.cardinality; facet.predefinedType = getParameterValue(element.predefinedType); + facet.instructions = element.instructions; facets.push(facet); } return facets; diff --git a/packages/core/src/openbim/IDSSpecifications/src/importers/property.ts b/packages/core/src/openbim/IDSSpecifications/src/importers/property.ts index a7c29d8c1..08e6420eb 100644 --- a/packages/core/src/openbim/IDSSpecifications/src/importers/property.ts +++ b/packages/core/src/openbim/IDSSpecifications/src/importers/property.ts @@ -26,6 +26,8 @@ export const createPropertyFacets = (components: Components, elements: any) => { // URI facet.uri = element.uri; + facet.instructions = element.instructions; + facets.push(facet); } return facets;