Skip to content

Commit

Permalink
Merge pull request #182 from xeokit/fix-enable-measurements
Browse files Browse the repository at this point in the history
Fix enableMeasurements: false
  • Loading branch information
xeolabs authored Apr 14, 2024
2 parents 0d94309 + 542b708 commit 9ebfa5c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 33 deletions.
3 changes: 2 additions & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<script type="module">

import { Server, BIMViewer, LocaleService } from "../dist/xeokit-bim-viewer.min.es.js";
import { Server, BIMViewer, LocaleService } from "../dist/xeokit-bim-viewer.es.js";

import { messages as localeMessages } from "../dist/messages.js";

Expand Down Expand Up @@ -63,6 +63,7 @@
messages: localeMessages,
locale: locale
}),
enableMeasurements: false,
canvasElement: document.getElementById("myCanvas"), // WebGL canvas
keyboardEventsElement: document, // Optional, defaults to document
explorerElement: document.getElementById("myExplorer"), // Left panel
Expand Down
49 changes: 30 additions & 19 deletions src/BIMViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class BIMViewer extends Controller {
// It is important to consider that each SectionPlane imposes rendering performance, so it is
// recommended to set this value to a quantity that aligns with your expected usage.

numCachedSectionPlanes :4
numCachedSectionPlanes: 4
});

super(null, cfg, server, viewer);
Expand Down Expand Up @@ -414,15 +414,18 @@ class BIMViewer extends Controller {
active: false
});

this._measureDistanceTool = new MeasureDistanceTool(this, {
buttonElement: toolbarElement.querySelector(".xeokit-measure-distance"),
active: false
});
if (this._enableMeasurements) {

this._measureAngleTool = new MeasureAngleTool(this, {
buttonElement: toolbarElement.querySelector(".xeokit-measure-angle"),
active: false
});
this._measureDistanceTool = new MeasureDistanceTool(this, {
buttonElement: toolbarElement.querySelector(".xeokit-measure-distance"),
active: false
});

this._measureAngleTool = new MeasureAngleTool(this, {
buttonElement: toolbarElement.querySelector(".xeokit-measure-angle"),
active: false
});
}

this._navCubeMode = new NavCubeMode(this, {
navCubeCanvasElement: navCubeCanvasElement,
Expand Down Expand Up @@ -461,8 +464,8 @@ class BIMViewer extends Controller {
this._selectionTool,
this._marqueeSelectionTool,
this._sectionTool,
this._measureDistanceTool,
this._measureAngleTool
this._enableMeasurements ? this._measureDistanceTool : null,
this._enableMeasurements ? this._measureAngleTool: null
]);

explorerElement.querySelector(".xeokit-showAllObjects").addEventListener("click", (event) => {
Expand Down Expand Up @@ -1926,8 +1929,10 @@ class BIMViewer extends Controller {
this._selectionTool.setEnabled(enabled);
this._marqueeSelectionTool.setEnabled(enabled);
this._showSpacesMode.setEnabled(enabled);
this._measureDistanceTool.setEnabled(enabled);
this._measureAngleTool.setEnabled(enabled);
if (this._enableMeasurements) {
this._measureDistanceTool.setEnabled(enabled);
this._measureAngleTool.setEnabled(enabled);
}
this._sectionTool.setEnabled(enabled);

if (this._enablePropertiesInspector) {
Expand Down Expand Up @@ -2022,8 +2027,10 @@ class BIMViewer extends Controller {
* Clears measurements.
*/
clearMeasurements() {
this._measureDistanceTool.clear();
this._measureAngleTool.clear();
if (this._enableMeasurements) {
this._measureDistanceTool.clear();
this._measureAngleTool.clear();
}
}

/**
Expand All @@ -2043,7 +2050,9 @@ class BIMViewer extends Controller {
* @param {Boolean} axisVisible Set `true` to show axis wires, else `false` to hide them.
*/
setMeasurementsAxisVisible(axisVisible) {
this._measureDistanceTool.setMeasurementsAxisVisible(axisVisible);
if (this._enableMeasurements) {
this._measureDistanceTool.setMeasurementsAxisVisible(axisVisible);
}
}

/**
Expand All @@ -2054,7 +2063,7 @@ class BIMViewer extends Controller {
* @returns {Boolean} `true` if axis wires are visible, else `false` if hidden.
*/
getMeasurementsAxisVisible() {
return this._measureDistanceTool.getMeasurementsAxisVisible();
return (this._enableMeasurements) ? this._measureDistanceTool.getMeasurementsAxisVisible() : false;
}

/**
Expand All @@ -2063,7 +2072,9 @@ class BIMViewer extends Controller {
* @param {Boolean} snappingEnabled Set `true` to enable snapping, else `false` to disable.
*/
setMeasurementsSnappingEnabled(snappingEnabled) {
this._measureDistanceTool.setSnappingEnabled(snappingEnabled);
if (this._enableMeasurements) {
this._measureDistanceTool.setSnappingEnabled(snappingEnabled);
}
}

/**
Expand All @@ -2072,7 +2083,7 @@ class BIMViewer extends Controller {
* @returns {Boolean} `true` if snapping is enabled, else `false` if disabled.
*/
getMeasurementsSnappingEnabled() {
return this._measureDistanceTool.getSnappingEnabled();
return (this._enableMeasurements) ? this._measureDistanceTool.getSnappingEnabled() : false;
}

/**
Expand Down
28 changes: 15 additions & 13 deletions src/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,22 @@ class Controller {
const numControllers = controllers.length;
for (let i = 0; i < numControllers; i++) {
const controller = controllers[i];
controller.on("active", (function () {
const _i = i;
return function (active) {
if (!active) {
return;
}
for (let j = 0; j < numControllers; j++) {
if (j === _i) {
continue;
if (controller) {
controller.on("active", (function () {
const _i = i;
return function (active) {
if (!active) {
return;
}
controllers[j].setActive(false);
}
};
})());
for (let j = 0; j < numControllers; j++) {
if (j === _i) {
continue;
}
controllers[j].setActive(false);
}
};
})());
}
}
}

Expand Down

0 comments on commit 9ebfa5c

Please sign in to comment.