diff --git a/packages/core/package.json b/packages/core/package.json index a0313bdf..37b4d31e 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,7 +1,7 @@ { "name": "@thatopen/components", "description": "Collection of core functionalities to author BIM apps.", - "version": "2.3.9", + "version": "2.3.11", "author": "That Open Company", "contributors": [ "Antonio Gonzalez Viegas (https://github.com/agviegas)", diff --git a/packages/core/src/core/Components/index.ts b/packages/core/src/core/Components/index.ts index da92c7cd..8dba42bf 100644 --- a/packages/core/src/core/Components/index.ts +++ b/packages/core/src/core/Components/index.ts @@ -14,7 +14,7 @@ export class Components implements Disposable { /** * The version of the @thatopen/components library. */ - static readonly release = "2.3.9"; + static readonly release = "2.3.11"; /** {@link Disposable.onDisposed} */ readonly onDisposed = new Event(); diff --git a/packages/core/src/core/Viewpoints/src/viewpoint.ts b/packages/core/src/core/Viewpoints/src/viewpoint.ts index 7aba4592..1c9f2309 100644 --- a/packages/core/src/core/Viewpoints/src/viewpoint.ts +++ b/packages/core/src/core/Viewpoints/src/viewpoint.ts @@ -41,9 +41,9 @@ export class Viewpoint implements BCFViewpoint { clippingPlanes = new DataSet(); camera: ViewpointPerspectiveCamera | ViewpointOrthographicCamera = { - aspectRatio: 0, - fov: 0, - direction: { x: 0, y: 0, z: 80 }, + aspectRatio: 1, + fov: 60, + direction: { x: 0, y: 0, z: 0 }, position: { x: 0, y: 0, z: 0 }, }; @@ -61,7 +61,7 @@ export class Viewpoint implements BCFViewpoint { * A map of colors and components GUIDs that should be colorized when displaying a viewpoint. * For this to work, call viewpoint.colorize() */ - readonly componentColors = new DataMap(); + readonly componentColors = new DataMap(); /** * Boolean flags to allow fine control over the visibility of spaces. @@ -306,6 +306,25 @@ export class Viewpoint implements BCFViewpoint { camera.projection.set(this.projection); } + const basePosition = new THREE.Vector3( + this.camera.position.x, + this.camera.position.y, + this.camera.position.z, + ); + + const baseTarget = new THREE.Vector3( + this.camera.direction.x, + this.camera.direction.y, + this.camera.direction.z, + ); + + if ( + basePosition.equals(new THREE.Vector3()) && + baseTarget.equals(new THREE.Vector3()) + ) { + return; + } + const position = this.position; const direction = this.direction; @@ -322,7 +341,7 @@ export class Viewpoint implements BCFViewpoint { const raycasters = this._components.get(Raycasters); const raycaster = raycasters.get(this.world); const result = raycaster.castRayFromVector(position, this.direction); - if (result) target = result.point; + if (result) target = result.point; // If there is no result, the default calculated target will be used } else { // In case there are selection components, use their center as the target const bb = this._components.get(BoundingBoxer); @@ -332,12 +351,6 @@ export class Viewpoint implements BCFViewpoint { bb.reset(); } - // Sets the viewpoint components visibility - const hider = this._components.get(Hider); - hider.set(this.defaultVisibility); - hider.set(!this.defaultVisibility, this.exception); - hider.set(true, selection); // Always make sure the selection is visible - await camera.controls.setLookAt( position.x, position.y, @@ -410,6 +423,13 @@ export class Viewpoint implements BCFViewpoint { manager.list.set(this.guid, this); } + applyVisibility() { + const hider = this._components.get(Hider); + hider.set(this.defaultVisibility); + hider.set(!this.defaultVisibility, this.exception); + hider.set(true, this.selection); // Always make sure the selection is visible + } + /** * Applies color to the components in the viewpoint based on their GUIDs. * @@ -420,25 +440,18 @@ export class Viewpoint implements BCFViewpoint { * The color is applied using the `Classifier.setColor` method, which sets the color of the specified fragments. * The color is provided as a hexadecimal string, prefixed with a '#'. */ - colorize() { + applyColors() { const manager = this._components.get(Viewpoints); const fragments = this._components.get(FragmentsManager); const classifier = this._components.get(Classifier); for (const [color, guids] of this.componentColors) { const fragmentIdMap = fragments.guidToFragmentIdMap(guids); - const threeColor = new THREE.Color(`#${color}`); - classifier.setColor( - fragmentIdMap, - threeColor, - manager.config.overwriteColors, - ); + classifier.setColor(fragmentIdMap, color, manager.config.overwriteColors); } } /** * Resets the colors of all components in the viewpoint to their original color. - * This method iterates through the `componentColors` map, retrieves the fragment IDs - * corresponding to each color, and then uses the `Classifier` to reset the color of those fragments. */ resetColors() { const fragments = this._components.get(FragmentsManager); @@ -481,6 +494,23 @@ export class Viewpoint implements BCFViewpoint { return tags; } + private createColorTags() { + let colorTags = ""; + for (const [color, components] of this.componentColors.entries()) { + const hex = `#${color.getHexString()}`; + const tags = components + .map((globalId) => `\n`) + .join("\n"); + colorTags += `\n${tags}\n`; + } + + if (colorTags.length !== 0) { + return `\n${colorTags}\n`; + } + + return ``; + } + /** * Serializes the viewpoint into a buildingSMART compliant XML string for export. * @@ -552,6 +582,7 @@ export class Viewpoint implements BCFViewpoint { const selectionTags = (await this.createComponentTags("selection")).trim(); const exceptionTags = (await this.createComponentTags("exception")).trim(); + const colorTags = this.createColorTags(); return ` @@ -562,6 +593,7 @@ export class Viewpoint implements BCFViewpoint { ${version === "3" ? viewSetupHints : ""} ${exceptionTags.length !== 0 ? `${exceptionTags}` : ""} + ${colorTags} ${cameraXML} `; diff --git a/packages/core/src/openbim/IDSSpecifications/example.ts b/packages/core/src/openbim/IDSSpecifications/example.ts index 2bae2787..124a5dfe 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 778c0505..9261d965 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 8c0ac486..858f1ee5 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 6d04214a..b68153b5 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 1e98ecb6..f89142ba 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 a7c29d8c..08e6420e 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; diff --git a/packages/front/package.json b/packages/front/package.json index be442981..4679d85b 100644 --- a/packages/front/package.json +++ b/packages/front/package.json @@ -1,7 +1,7 @@ { "name": "@thatopen/components-front", "description": "Collection of frontend tools to author BIM apps.", - "version": "2.3.6", + "version": "2.3.7", "author": "That Open Company", "contributors": [ "Antonio Gonzalez Viegas (https://github.com/agviegas)", diff --git a/resources/specs.ids b/resources/specs.ids new file mode 100644 index 00000000..5751c6d3 --- /dev/null +++ b/resources/specs.ids @@ -0,0 +1,36 @@ + + + New IDS File + + + + + + + IFCWALL + + + PARTITIONING + + + + + + + Name + + + + + + + + + + + \ No newline at end of file