BIMviewer
158 строк · 6.5 Кб
1import {ContextMenu} from "@xeokit/xeokit-sdk/dist/xeokit-sdk.es.js";2
3/**
4* @private
5* @param {*} cfg Configs
6* @param {Boolean} [cfg.enableEditModels=false] Set true to show Add/Edit/Delete options in the menu.
7*/
8class ModelsContextMenu extends ContextMenu {9
10constructor(cfg = {}) {11
12const enableEditModels = (!!cfg.enableEditModels);13const enableMeasurements = (!!cfg.enableMeasurements);14
15const items = [16[17{18getTitle: (context) => {19return context.viewer.localeService.translate("modelsContextMenu.loadModel") || "Load";20},21getEnabled: (context) => {22return (!context.bimViewer.isModelLoaded(context.modelId));23},24doAction: (context) => {25context.bimViewer.loadModel(context.modelId);26}27},28{29getTitle: (context) => {30return context.viewer.localeService.translate("modelsContextMenu.unloadModel") || "Unload";31},32getEnabled: (context) => {33return context.bimViewer.isModelLoaded(context.modelId);34},35doAction: (context) => {36context.bimViewer.unloadModel(context.modelId);37}38}39]40];41
42if (enableEditModels) {43
44items.push([45{46getTitle: (context) => {47return context.viewer.localeService.translate("modelsContextMenu.editModel") || "Edit";48},49getEnabled: (context) => {50return true;51},52doAction: (context) => {53context.bimViewer.editModel(context.modelId);54}55},56{57getTitle: (context) => {58return context.viewer.localeService.translate("modelsContextMenu.deleteModel") || "Delete";59},60getEnabled: (context) => {61return true;62},63doAction: (context) => {64context.bimViewer.deleteModel(context.modelId);65}66}67]);68}69
70items.push([71{72getTitle: (context) => {73return context.viewer.localeService.translate("modelsContextMenu.loadAllModels") || "Load All";74},75getEnabled: (context) => {76const bimViewer = context.bimViewer;77const modelIds = bimViewer.getModelIds();78const loadedModelIds = bimViewer.getLoadedModelIds();79return (loadedModelIds.length < modelIds.length);80},81doAction: (context) => {82context.bimViewer.loadAllModels();83}84},85{86getTitle: (context) => {87return context.viewer.localeService.translate("modelsContextMenu.unloadAllModels") || "Unload All";88},89getEnabled: (context) => {90const loadedModelIds = context.bimViewer.getLoadedModelIds();91return (loadedModelIds.length > 0);92},93doAction: (context) => {94context.bimViewer.unloadAllModels();95}96}97]);98
99items.push([100{101getTitle: (context) => {102return context.viewer.localeService.translate("modelsContextMenu.clearSlices") || "Clear Slices";103},104getEnabled: (context) => {105return (context.bimViewer.getNumSections() > 0);106},107doAction: (context) => {108context.bimViewer.clearSections();109}110}111]);112
113if (enableMeasurements) {114items.push([{115getTitle: (context) => {116return context.viewer.localeService.translate("canvasContextMenu.measurements") || "Measurements";117},118doAction: function (context) {119// Does nothing120},121items: [ // Sub-menu122[{123getTitle: (context) => {124return context.viewer.localeService.translate("canvasContextMenu.clearMeasurements") || "Clear";125}, getEnabled: (context) => {126return (context.bimViewer.getNumMeasurements() > 0);127}, doAction: (context) => {128context.bimViewer.clearMeasurements();129}130}, {131getTitle: (context) => {132return context.bimViewer.getMeasurementsAxisVisible() ? context.viewer.localeService.translate("canvasContextMenu.hideMeasurementAxisWires") || "Hide Axis Wires" : context.viewer.localeService.translate("canvasContextMenu.showMeasurementAxisWires") || "Show Axis Wires"133}, getEnabled: (context) => {134return (context.bimViewer.getNumMeasurements() > 0);135}, doAction: (context) => {136context.bimViewer.setMeasurementsAxisVisible(!context.bimViewer.getMeasurementsAxisVisible());137}138}, {139getTitle: (context) => {140return context.bimViewer.getMeasurementsSnappingEnabled() ? context.viewer.localeService.translate("canvasContextMenu.disableMeasurementSnapping") || "Disable Snapping" : context.viewer.localeService.translate("canvasContextMenu.enableMeasurementSnapping") || "Enable Snapping"141}, getEnabled: (context) => {142return (context.bimViewer.getNumMeasurements() > 0);143}, doAction: (context) => {144context.bimViewer.setMeasurementsSnappingEnabled(!context.bimViewer.getMeasurementsSnappingEnabled());145}146}]]147}]);148}149
150super({151hideOnAction: cfg.hideOnAction,152context: cfg.context,153items: items154});155}156}
157
158export {ModelsContextMenu};