Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
agviegas committed Oct 18, 2024
2 parents e47d497 + eca11cc commit 26313eb
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 38 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -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)",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/Components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>();
Expand Down
72 changes: 52 additions & 20 deletions packages/core/src/core/Viewpoints/src/viewpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export class Viewpoint implements BCFViewpoint {
clippingPlanes = new DataSet<SimplePlane>();

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 },
};

Expand All @@ -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<string, string[]>();
readonly componentColors = new DataMap<THREE.Color, string[]>();

/**
* Boolean flags to allow fine control over the visibility of spaces.
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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.
*
Expand All @@ -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);
Expand Down Expand Up @@ -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<Component IfcGuid="${globalId}" />`)
.join("\n");
colorTags += `<Color Color="${hex}">\n${tags}\n</Color>`;
}

if (colorTags.length !== 0) {
return `<Coloring>\n${colorTags}\n</Coloring>`;
}

return `<Coloring />`;
}

/**
* Serializes the viewpoint into a buildingSMART compliant XML string for export.
*
Expand Down Expand Up @@ -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 `<?xml version="1.0" encoding="UTF-8"?>
<VisualizationInfo Guid="${this.guid}">
Expand All @@ -562,6 +593,7 @@ export class Viewpoint implements BCFViewpoint {
${version === "3" ? viewSetupHints : ""}
${exceptionTags.length !== 0 ? `<Exceptions>${exceptionTags}</Exceptions>` : ""}
</Visibility>
${colorTags}
</Components>
${cameraXML}
</VisualizationInfo>`;
Expand Down
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
2 changes: 1 addition & 1 deletion packages/front/package.json
Original file line number Diff line number Diff line change
@@ -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)",
Expand Down
36 changes: 36 additions & 0 deletions resources/specs.ids
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<ids:ids xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://standards.buildingsmart.org/IDS http://standards.buildingsmart.org/IDS/1.0/ids.xsd" xmlns:ids="http://standards.buildingsmart.org/IDS">
<ids:info>
<ids:title>New IDS File</ids:title>
</ids:info>
<ids:specifications>
<ids:specification
ifcVersion="IFC4 IFC4X3_ADD2"
name="New Specification"
description="All partitioning walls must comply with a specific naming convention"
instructions="General Specification Instructions"
>
<ids:applicability minOccurs="1" maxOccurs="unbounded">
<ids:entity>
<ids:name>
<ids:simpleValue>IFCWALL</ids:simpleValue>
</ids:name>
<ids:predefinedType>
<ids:simpleValue>PARTITIONING</ids:simpleValue>
</ids:predefinedType>
</ids:entity>
</ids:applicability>
<ids:requirements description="This is the requirement description">
<ids:attribute cardinality="required" instructions="Here goes the facet instructions">
<ids:name>
<ids:simpleValue>Name</ids:simpleValue>
</ids:name>
<ids:value>
<xs:restriction base="xs:string">
<xs:pattern value="MuroDivisorio_[a-zA-Z]+_\d{2}cm" />
</xs:restriction>
</ids:value>
</ids:attribute>
</ids:requirements>
</ids:specification>
</ids:specifications>
</ids:ids>

0 comments on commit 26313eb

Please sign in to comment.