BIMviewer

Форк
0
/
ModelsContextMenu.js 
158 строк · 6.5 Кб
1
import {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
 */
8
class ModelsContextMenu extends ContextMenu {
9

10
    constructor(cfg = {}) {
11

12
        const enableEditModels = (!!cfg.enableEditModels);
13
        const enableMeasurements = (!!cfg.enableMeasurements);
14

15
        const items = [
16
            [
17
                {
18
                    getTitle: (context) => {
19
                        return context.viewer.localeService.translate("modelsContextMenu.loadModel") || "Load";
20
                    },
21
                    getEnabled: (context) => {
22
                        return (!context.bimViewer.isModelLoaded(context.modelId));
23
                    },
24
                    doAction: (context) => {
25
                        context.bimViewer.loadModel(context.modelId);
26
                    }
27
                },
28
                {
29
                    getTitle: (context) => {
30
                        return context.viewer.localeService.translate("modelsContextMenu.unloadModel") || "Unload";
31
                    },
32
                    getEnabled: (context) => {
33
                        return context.bimViewer.isModelLoaded(context.modelId);
34
                    },
35
                    doAction: (context) => {
36
                        context.bimViewer.unloadModel(context.modelId);
37
                    }
38
                }
39
            ]
40
        ];
41

42
        if (enableEditModels) {
43

44
            items.push([
45
                {
46
                    getTitle: (context) => {
47
                        return context.viewer.localeService.translate("modelsContextMenu.editModel") || "Edit";
48
                    },
49
                    getEnabled: (context) => {
50
                        return true;
51
                    },
52
                    doAction: (context) => {
53
                        context.bimViewer.editModel(context.modelId);
54
                    }
55
                },
56
                {
57
                    getTitle: (context) => {
58
                        return context.viewer.localeService.translate("modelsContextMenu.deleteModel") || "Delete";
59
                    },
60
                    getEnabled: (context) => {
61
                        return true;
62
                    },
63
                    doAction: (context) => {
64
                        context.bimViewer.deleteModel(context.modelId);
65
                    }
66
                }
67
            ]);
68
        }
69

70
        items.push([
71
            {
72
                getTitle: (context) => {
73
                    return context.viewer.localeService.translate("modelsContextMenu.loadAllModels") || "Load All";
74
                },
75
                getEnabled: (context) => {
76
                    const bimViewer = context.bimViewer;
77
                    const modelIds = bimViewer.getModelIds();
78
                    const loadedModelIds = bimViewer.getLoadedModelIds();
79
                    return (loadedModelIds.length < modelIds.length);
80
                },
81
                doAction: (context) => {
82
                    context.bimViewer.loadAllModels();
83
                }
84
            },
85
            {
86
                getTitle: (context) => {
87
                    return context.viewer.localeService.translate("modelsContextMenu.unloadAllModels") || "Unload All";
88
                },
89
                getEnabled: (context) => {
90
                    const loadedModelIds = context.bimViewer.getLoadedModelIds();
91
                    return (loadedModelIds.length > 0);
92
                },
93
                doAction: (context) => {
94
                    context.bimViewer.unloadAllModels();
95
                }
96
            }
97
        ]);
98

99
        items.push([
100
            {
101
                getTitle: (context) => {
102
                    return context.viewer.localeService.translate("modelsContextMenu.clearSlices") || "Clear Slices";
103
                },
104
                getEnabled: (context) => {
105
                    return (context.bimViewer.getNumSections() > 0);
106
                },
107
                doAction: (context) => {
108
                    context.bimViewer.clearSections();
109
                }
110
            }
111
        ]);
112

113
        if (enableMeasurements) {
114
            items.push([{
115
                getTitle: (context) => {
116
                    return context.viewer.localeService.translate("canvasContextMenu.measurements") || "Measurements";
117
                },
118
                doAction: function (context) {
119
                    // Does nothing
120
                },
121
                items: [ // Sub-menu
122
                    [{
123
                        getTitle: (context) => {
124
                            return context.viewer.localeService.translate("canvasContextMenu.clearMeasurements") || "Clear";
125
                        }, getEnabled: (context) => {
126
                            return (context.bimViewer.getNumMeasurements() > 0);
127
                        }, doAction: (context) => {
128
                            context.bimViewer.clearMeasurements();
129
                        }
130
                    }, {
131
                        getTitle: (context) => {
132
                            return context.bimViewer.getMeasurementsAxisVisible() ? context.viewer.localeService.translate("canvasContextMenu.hideMeasurementAxisWires") || "Hide Axis Wires" : context.viewer.localeService.translate("canvasContextMenu.showMeasurementAxisWires") || "Show Axis Wires"
133
                        }, getEnabled: (context) => {
134
                            return (context.bimViewer.getNumMeasurements() > 0);
135
                        }, doAction: (context) => {
136
                            context.bimViewer.setMeasurementsAxisVisible(!context.bimViewer.getMeasurementsAxisVisible());
137
                        }
138
                    }, {
139
                        getTitle: (context) => {
140
                            return context.bimViewer.getMeasurementsSnappingEnabled() ? context.viewer.localeService.translate("canvasContextMenu.disableMeasurementSnapping") || "Disable Snapping" : context.viewer.localeService.translate("canvasContextMenu.enableMeasurementSnapping") || "Enable Snapping"
141
                        }, getEnabled: (context) => {
142
                            return (context.bimViewer.getNumMeasurements() > 0);
143
                        }, doAction: (context) => {
144
                            context.bimViewer.setMeasurementsSnappingEnabled(!context.bimViewer.getMeasurementsSnappingEnabled());
145
                        }
146
                    }]]
147
            }]);
148
        }
149

150
        super({
151
            hideOnAction: cfg.hideOnAction,
152
            context: cfg.context,
153
            items: items
154
        });
155
    }
156
}
157

158
export {ModelsContextMenu};

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.