UNPKG

molstar

Version:

A comprehensive macromolecular library.

119 lines 6.29 kB
/** * Copyright (c) 2019-2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> * @author David Sehnal <david.sehnal@gmail.com> */ import { __awaiter, __generator, __spreadArray } from "tslib"; import { StructureElement } from '../../mol-model/structure'; import { StateTransforms } from '../../mol-plugin-state/transforms'; import { StateSelection } from '../../mol-state'; import { isEmptyLoci, Loci } from '../../mol-model/loci'; import { Transparency } from '../../mol-theme/transparency'; var TransparencyManagerTag = 'transparency-controls'; export function setStructureTransparency(plugin, components, value, lociGetter, types) { return __awaiter(this, void 0, void 0, function () { var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, eachRepr(plugin, components, function (update, repr, transparencyCell) { return __awaiter(_this, void 0, void 0, function () { var structure, loci, layer, bundleLayers, filtered, filtered; return __generator(this, function (_a) { switch (_a.label) { case 0: if (types && types.length > 0 && !types.includes(repr.params.values.type.name)) return [2 /*return*/]; structure = repr.obj.data.sourceData; return [4 /*yield*/, lociGetter(structure.root)]; case 1: loci = _a.sent(); if (Loci.isEmpty(loci) || isEmptyLoci(loci)) return [2 /*return*/]; layer = { bundle: StructureElement.Bundle.fromLoci(loci), value: value, }; if (transparencyCell) { bundleLayers = __spreadArray(__spreadArray([], transparencyCell.params.values.layers, true), [layer], false); filtered = getFilteredBundle(bundleLayers, structure); update.to(transparencyCell).update(Transparency.toBundle(filtered)); } else { filtered = getFilteredBundle([layer], structure); update.to(repr.transform.ref) .apply(StateTransforms.Representation.TransparencyStructureRepresentation3DFromBundle, Transparency.toBundle(filtered), { tags: TransparencyManagerTag }); } return [2 /*return*/]; } }); }); })]; case 1: _a.sent(); return [2 /*return*/]; } }); }); } export function clearStructureTransparency(plugin, components, types) { return __awaiter(this, void 0, void 0, function () { var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, eachRepr(plugin, components, function (update, repr, transparencyCell) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { if (types && types.length > 0 && !types.includes(repr.params.values.type.name)) return [2 /*return*/]; if (transparencyCell) { update.delete(transparencyCell.transform.ref); } return [2 /*return*/]; }); }); })]; case 1: _a.sent(); return [2 /*return*/]; } }); }); } function eachRepr(plugin, components, callback) { return __awaiter(this, void 0, void 0, function () { var state, update, _i, components_1, c, _a, _b, r, transparency; return __generator(this, function (_c) { switch (_c.label) { case 0: state = plugin.state.data; update = state.build(); _i = 0, components_1 = components; _c.label = 1; case 1: if (!(_i < components_1.length)) return [3 /*break*/, 6]; c = components_1[_i]; _a = 0, _b = c.representations; _c.label = 2; case 2: if (!(_a < _b.length)) return [3 /*break*/, 5]; r = _b[_a]; transparency = state.select(StateSelection.Generators.ofTransformer(StateTransforms.Representation.TransparencyStructureRepresentation3DFromBundle, r.cell.transform.ref).withTag(TransparencyManagerTag)); return [4 /*yield*/, callback(update, r.cell, transparency[0])]; case 3: _c.sent(); _c.label = 4; case 4: _a++; return [3 /*break*/, 2]; case 5: _i++; return [3 /*break*/, 1]; case 6: return [2 /*return*/, update.commit({ doNotUpdateCurrent: true })]; } }); }); } /** filter transparency layers for given structure */ function getFilteredBundle(layers, structure) { var transparency = Transparency.ofBundle(layers, structure.root); var merged = Transparency.merge(transparency); return Transparency.filter(merged, structure); } //# sourceMappingURL=structure-transparency.js.map