UNPKG

molstar

Version:

A comprehensive macromolecular library.

146 lines 6.46 kB
"use strict"; /** * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.VolumeHierarchyManager = void 0; var tslib_1 = require("tslib"); var state_1 = require("../../../mol-plugin/behavior/static/state"); var component_1 = require("../../component"); var hierarchy_state_1 = require("./hierarchy-state"); var volume_representation_params_1 = require("../../helpers/volume-representation-params"); var transforms_1 = require("../../transforms"); var VolumeHierarchyManager = /** @class */ (function (_super) { (0, tslib_1.__extends)(VolumeHierarchyManager, _super); function VolumeHierarchyManager(plugin) { var _this = _super.call(this) || this; _this.plugin = plugin; _this.state = { syncedTree: _this.dataState.tree, notified: false, hierarchy: (0, hierarchy_state_1.VolumeHierarchy)(), selection: void 0 }; _this.behaviors = { selection: _this.ev.behavior({ hierarchy: _this.current, volume: _this.selection }) }; _this.subscribe(plugin.state.data.events.changed, function (e) { if (e.inTransaction || plugin.behaviors.state.isAnimating.value) return; _this.sync(true); }); _this.subscribe(plugin.behaviors.state.isAnimating, function (isAnimating) { if (!isAnimating && !plugin.behaviors.state.isUpdating.value) _this.sync(true); }); return _this; } Object.defineProperty(VolumeHierarchyManager.prototype, "dataState", { get: function () { return this.plugin.state.data; }, enumerable: false, configurable: true }); Object.defineProperty(VolumeHierarchyManager.prototype, "current", { get: function () { this.sync(false); return this.state.hierarchy; }, enumerable: false, configurable: true }); Object.defineProperty(VolumeHierarchyManager.prototype, "selection", { get: function () { this.sync(false); return this.state.selection; }, enumerable: false, configurable: true }); VolumeHierarchyManager.prototype.sync = function (notify) { if (!notify && this.dataState.inUpdate) return; if (this.state.syncedTree === this.dataState.tree) { if (notify && !this.state.notified) { this.state.notified = true; this.behaviors.selection.next({ hierarchy: this.state.hierarchy, volume: this.state.selection }); } return; } this.state.syncedTree = this.dataState.tree; var update = (0, hierarchy_state_1.buildVolumeHierarchy)(this.plugin.state.data, this.current); if (!update.changed) { return; } var hierarchy = update.hierarchy; this.state.hierarchy = hierarchy; if (!this.state.selection) { this.state.selection = hierarchy.volumes[0]; } else { this.state.selection = hierarchy.refs.has(this.state.selection.cell.transform.ref) ? hierarchy.refs.get(this.state.selection.cell.transform.ref) : hierarchy.volumes[0]; } if (notify) { this.state.notified = true; this.behaviors.selection.next({ hierarchy: hierarchy, volume: this.state.selection }); } else { this.state.notified = false; } }; VolumeHierarchyManager.prototype.setCurrent = function (volume) { this.state.selection = volume || this.state.hierarchy.volumes[0]; this.behaviors.selection.next({ hierarchy: this.state.hierarchy, volume: volume || this.state.hierarchy.volumes[0] }); }; // TODO: have common util VolumeHierarchyManager.prototype.remove = function (refs, canUndo) { if (refs.length === 0) return; var deletes = this.plugin.state.data.build(); for (var _i = 0, refs_1 = refs; _i < refs_1.length; _i++) { var r = refs_1[_i]; deletes.delete(typeof r === 'string' ? r : r.cell.transform.ref); } return deletes.commit({ canUndo: canUndo ? 'Remove' : false }); }; // TODO: have common util VolumeHierarchyManager.prototype.toggleVisibility = function (refs, action) { if (refs.length === 0) return; var isHidden = action !== void 0 ? (action === 'show' ? false : true) : !refs[0].cell.state.isHidden; for (var _i = 0, refs_2 = refs; _i < refs_2.length; _i++) { var c = refs_2[_i]; (0, state_1.setSubtreeVisibility)(this.dataState, c.cell.transform.ref, isHidden); } }; VolumeHierarchyManager.prototype.addRepresentation = function (ref, type) { var _a; var update = this.dataState.build() .to(ref.cell) .apply(transforms_1.StateTransforms.Representation.VolumeRepresentation3D, (0, volume_representation_params_1.createVolumeRepresentationParams)(this.plugin, (_a = ref.cell.obj) === null || _a === void 0 ? void 0 : _a.data, { type: type, })); return update.commit({ canUndo: 'Add Representation' }); }; return VolumeHierarchyManager; }(component_1.PluginComponent)); exports.VolumeHierarchyManager = VolumeHierarchyManager; (function (VolumeHierarchyManager) { function getRepresentationTypes(plugin, pivot) { var _a, _b; return ((_a = pivot === null || pivot === void 0 ? void 0 : pivot.cell.obj) === null || _a === void 0 ? void 0 : _a.data) ? plugin.representation.volume.registry.getApplicableTypes((_b = pivot.cell.obj) === null || _b === void 0 ? void 0 : _b.data) : plugin.representation.volume.registry.types; } VolumeHierarchyManager.getRepresentationTypes = getRepresentationTypes; })(VolumeHierarchyManager = exports.VolumeHierarchyManager || (exports.VolumeHierarchyManager = {})); exports.VolumeHierarchyManager = VolumeHierarchyManager; //# sourceMappingURL=hierarchy.js.map