molstar
Version:
A comprehensive macromolecular library.
131 lines (130 loc) • 7.78 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuickStyles = exports.StructureQuickStylesControls = void 0;
var tslib_1 = require("tslib");
var jsx_runtime_1 = require("react/jsx-runtime");
/**
* Copyright (c) 2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
var representation_preset_1 = require("../../mol-plugin-state/builder/structure/representation-preset");
var color_1 = require("../../mol-util/color");
var base_1 = require("../base");
var common_1 = require("../controls/common");
var icons_1 = require("../controls/icons");
var param_definition_1 = require("../../mol-util/param-definition");
var postprocessing_1 = require("../../mol-canvas3d/passes/postprocessing");
var config_1 = require("../../mol-plugin/config");
var component_1 = require("../../mol-plugin-state/manager/structure/component");
var StructureQuickStylesControls = /** @class */ (function (_super) {
tslib_1.__extends(StructureQuickStylesControls, _super);
function StructureQuickStylesControls() {
return _super !== null && _super.apply(this, arguments) || this;
}
StructureQuickStylesControls.prototype.defaultState = function () {
return {
isCollapsed: false,
header: 'Quick Styles',
brand: { accent: 'gray', svg: icons_1.MagicWandSvg }
};
};
StructureQuickStylesControls.prototype.renderControls = function () {
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(QuickStyles, {}) });
};
return StructureQuickStylesControls;
}(base_1.CollapsableControls));
exports.StructureQuickStylesControls = StructureQuickStylesControls;
var QuickStyles = /** @class */ (function (_super) {
tslib_1.__extends(QuickStyles, _super);
function QuickStyles() {
return _super !== null && _super.apply(this, arguments) || this;
}
QuickStyles.prototype.default = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var structures, preset, provider, p;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
structures = this.plugin.managers.structure.hierarchy.selection.structures;
preset = this.plugin.config.get(config_1.PluginConfig.Structure.DefaultRepresentationPreset) || representation_preset_1.PresetStructureRepresentations.auto.id;
provider = this.plugin.builders.structure.representation.resolveProvider(preset);
return [4 /*yield*/, this.plugin.managers.structure.component.applyPreset(structures, provider)];
case 1:
_a.sent();
this.plugin.managers.structure.component.setOptions(param_definition_1.ParamDefinition.getDefaultValues(component_1.StructureComponentManager.OptionsParams));
if (this.plugin.canvas3d) {
p = param_definition_1.ParamDefinition.getDefaultValues(postprocessing_1.PostprocessingParams);
this.plugin.canvas3d.setProps({
postprocessing: { outline: p.outline, occlusion: p.occlusion }
});
}
return [2 /*return*/];
}
});
});
};
QuickStyles.prototype.illustrative = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var structures;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
structures = this.plugin.managers.structure.hierarchy.selection.structures;
return [4 /*yield*/, this.plugin.managers.structure.component.applyPreset(structures, representation_preset_1.PresetStructureRepresentations.illustrative)];
case 1:
_a.sent();
if (this.plugin.canvas3d) {
this.plugin.canvas3d.setProps({
postprocessing: {
outline: {
name: 'on',
params: { scale: 1, color: (0, color_1.Color)(0x000000), threshold: 0.25 }
},
occlusion: {
name: 'on',
params: { bias: 0.8, blurKernelSize: 15, radius: 5, samples: 32, resolutionScale: 1 }
},
}
});
}
return [2 /*return*/];
}
});
});
};
QuickStyles.prototype.stylized = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var pp;
return tslib_1.__generator(this, function (_a) {
this.plugin.managers.structure.component.setOptions(tslib_1.__assign(tslib_1.__assign({}, this.plugin.managers.structure.component.state.options), { ignoreLight: true }));
if (this.plugin.canvas3d) {
pp = this.plugin.canvas3d.props.postprocessing;
this.plugin.canvas3d.setProps({
postprocessing: {
outline: {
name: 'on',
params: pp.outline.name === 'on'
? pp.outline.params
: { scale: 1, color: (0, color_1.Color)(0x000000), threshold: 0.33 }
},
occlusion: {
name: 'on',
params: pp.occlusion.name === 'on'
? pp.occlusion.params
: { bias: 0.8, blurKernelSize: 15, radius: 5, samples: 32, resolutionScale: 1 }
},
}
});
}
return [2 /*return*/];
});
});
};
QuickStyles.prototype.render = function () {
var _this = this;
return (0, jsx_runtime_1.jsxs)("div", tslib_1.__assign({ className: 'msp-flex-row' }, { children: [(0, jsx_runtime_1.jsx)(common_1.Button, tslib_1.__assign({ noOverflow: true, title: 'Applies default representation preset. Set outline and occlusion effects to defaults.', onClick: function () { return _this.default(); }, style: { width: 'auto' } }, { children: "Default" })), (0, jsx_runtime_1.jsx)(common_1.Button, tslib_1.__assign({ noOverflow: true, title: 'Applies no representation preset. Enables outline and occlusion effects. Enables ignore-light representation parameter.', onClick: function () { return _this.stylized(); }, style: { width: 'auto' } }, { children: "Stylized" })), (0, jsx_runtime_1.jsx)(common_1.Button, tslib_1.__assign({ noOverflow: true, title: 'Applies illustrative representation preset. Enables outline and occlusion effects. Enables ignore-light parameter.', onClick: function () { return _this.illustrative(); }, style: { width: 'auto' } }, { children: "Illustrative" }))] }));
};
return QuickStyles;
}(base_1.PurePluginUIComponent));
exports.QuickStyles = QuickStyles;