Skip to content

Commit

Permalink
fix(core): missing information when importing IDS files
Browse files Browse the repository at this point in the history
  • Loading branch information
HoyosJuan committed Oct 17, 2024
1 parent 55494b5 commit a40a3cc
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
27 changes: 16 additions & 11 deletions packages/core/src/openbim/IDSSpecifications/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ 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, {
type: "enumeration",
parameter: ["IFCSLAB", "IFCWALL"],
});

specification.applicability.add(entityFacet);
// specification.applicability.add(entityFacet);

const propertyFacet = new OBC.IDSProperty(
components,
Expand All @@ -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);

Expand Down
19 changes: 15 additions & 4 deletions packages/core/src/openbim/IDSSpecifications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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[] = [];
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const createClassificationFacets = (
}
facet.value = value;
facet.uri = element.uri;
facet.instructions = element.instructions;
facets.push(facet);
}
return facets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a40a3cc

Please sign in to comment.