|
@@ -1,5 +1,5 @@
|
|
|
/**
|
|
|
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
|
|
+ * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
|
|
|
*
|
|
|
* @author David Sehnal <david.sehnal@gmail.com>
|
|
|
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
|
@@ -16,6 +16,9 @@ import { BuiltInStructureRepresentationsName } from 'mol-repr/structure/registry
|
|
|
import { Structure } from 'mol-model/structure';
|
|
|
import { StructureParams } from 'mol-repr/structure/representation';
|
|
|
import { ExplodeRepresentation3D } from 'mol-plugin/behavior/dynamic/representation';
|
|
|
+import { VolumeData } from 'mol-model/volume';
|
|
|
+import { BuiltInVolumeRepresentationsName } from 'mol-repr/volume/registry';
|
|
|
+import { VolumeParams } from 'mol-repr/volume/representation';
|
|
|
|
|
|
export namespace StructureRepresentation3DHelpers {
|
|
|
export function getDefaultParams(ctx: PluginContext, name: BuiltInStructureRepresentationsName, structure: Structure, structureParams?: Partial<PD.Values<StructureParams>>): Transformer.Params<StructureRepresentation3D> {
|
|
@@ -120,4 +123,87 @@ const ExplodeStructureRepresentation3D = PluginStateTransform.BuiltIn({
|
|
|
return updated ? Transformer.UpdateResult.Updated : Transformer.UpdateResult.Unchanged;
|
|
|
});
|
|
|
}
|
|
|
+});
|
|
|
+
|
|
|
+//
|
|
|
+
|
|
|
+export namespace VolumeRepresentation3DHelpers {
|
|
|
+ export function getDefaultParams(ctx: PluginContext, name: BuiltInVolumeRepresentationsName, volume: VolumeData, volumeParams?: Partial<PD.Values<VolumeParams>>): Transformer.Params<VolumeRepresentation3D> {
|
|
|
+ const type = ctx.volumeRepresentation.registry.get(name);
|
|
|
+
|
|
|
+ const themeDataCtx = { volume };
|
|
|
+ const colorParams = ctx.volumeRepresentation.themeCtx.colorThemeRegistry.get(type.defaultColorTheme).getParams(themeDataCtx);
|
|
|
+ const sizeParams = ctx.volumeRepresentation.themeCtx.sizeThemeRegistry.get(type.defaultSizeTheme).getParams(themeDataCtx)
|
|
|
+ const volumeDefaultParams = PD.getDefaultValues(type.getParams(ctx.volumeRepresentation.themeCtx, volume))
|
|
|
+ return ({
|
|
|
+ type: { name, params: volumeParams ? { ...volumeDefaultParams, ...volumeParams } : volumeDefaultParams },
|
|
|
+ colorTheme: { name: type.defaultColorTheme, params: PD.getDefaultValues(colorParams) },
|
|
|
+ sizeTheme: { name: type.defaultSizeTheme, params: PD.getDefaultValues(sizeParams) }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ export function getDefaultParamsStatic(ctx: PluginContext, name: BuiltInVolumeRepresentationsName, volumeParams?: Partial<PD.Values<VolumeParams>>): Transformer.Params<VolumeRepresentation3D> {
|
|
|
+ const type = ctx.volumeRepresentation.registry.get(name);
|
|
|
+ const colorParams = ctx.volumeRepresentation.themeCtx.colorThemeRegistry.get(type.defaultColorTheme).defaultValues;
|
|
|
+ const sizeParams = ctx.volumeRepresentation.themeCtx.sizeThemeRegistry.get(type.defaultSizeTheme).defaultValues
|
|
|
+ return ({
|
|
|
+ type: { name, params: volumeParams ? { ...type.defaultValues, ...volumeParams } : type.defaultValues },
|
|
|
+ colorTheme: { name: type.defaultColorTheme, params: colorParams },
|
|
|
+ sizeTheme: { name: type.defaultSizeTheme, params: sizeParams }
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+export { VolumeRepresentation3D }
|
|
|
+type VolumeRepresentation3D = typeof VolumeRepresentation3D
|
|
|
+const VolumeRepresentation3D = PluginStateTransform.BuiltIn({
|
|
|
+ name: 'volume-representation-3d',
|
|
|
+ display: '3D Representation',
|
|
|
+ from: SO.Volume.Data,
|
|
|
+ to: SO.Volume.Representation3D,
|
|
|
+ params: (a, ctx: PluginContext) => {
|
|
|
+ const { registry, themeCtx } = ctx.volumeRepresentation
|
|
|
+ const type = registry.get(registry.default.name);
|
|
|
+ const dataCtx = { volume: a.data }
|
|
|
+ return ({
|
|
|
+ type: PD.Mapped<any>(
|
|
|
+ registry.default.name,
|
|
|
+ registry.types,
|
|
|
+ name => PD.Group<any>(registry.get(name).getParams(themeCtx, a.data))),
|
|
|
+ colorTheme: PD.Mapped<any>(
|
|
|
+ type.defaultColorTheme,
|
|
|
+ themeCtx.colorThemeRegistry.getApplicableTypes(dataCtx),
|
|
|
+ name => PD.Group<any>(themeCtx.colorThemeRegistry.get(name).getParams(dataCtx))
|
|
|
+ ),
|
|
|
+ sizeTheme: PD.Mapped<any>(
|
|
|
+ type.defaultSizeTheme,
|
|
|
+ themeCtx.sizeThemeRegistry.types,
|
|
|
+ name => PD.Group<any>(themeCtx.sizeThemeRegistry.get(name).getParams(dataCtx))
|
|
|
+ )
|
|
|
+ })
|
|
|
+ }
|
|
|
+})({
|
|
|
+ canAutoUpdate({ oldParams, newParams }) {
|
|
|
+ // TODO: allow for small molecules
|
|
|
+ return oldParams.type.name === newParams.type.name;
|
|
|
+ },
|
|
|
+ apply({ a, params }, plugin: PluginContext) {
|
|
|
+ return Task.create('Volume Representation', async ctx => {
|
|
|
+ const provider = plugin.volumeRepresentation.registry.get(params.type.name)
|
|
|
+ const props = params.type.params || {}
|
|
|
+ const repr = provider.factory({ webgl: plugin.canvas3d.webgl, ...plugin.volumeRepresentation.themeCtx }, provider.getParams)
|
|
|
+ repr.setTheme(createTheme(plugin.volumeRepresentation.themeCtx, { volume: a.data }, params))
|
|
|
+ // TODO set initial state, repr.setState({})
|
|
|
+ await repr.createOrUpdate(props, a.data).runInContext(ctx);
|
|
|
+ return new SO.Volume.Representation3D(repr, { label: provider.label });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ update({ a, b, oldParams, newParams }, plugin: PluginContext) {
|
|
|
+ return Task.create('Volume Representation', async ctx => {
|
|
|
+ if (newParams.type.name !== oldParams.type.name) return Transformer.UpdateResult.Recreate;
|
|
|
+ const props = { ...b.data.props, ...newParams.type.params }
|
|
|
+ b.data.setTheme(createTheme(plugin.volumeRepresentation.themeCtx, { volume: a.data }, newParams))
|
|
|
+ await b.data.createOrUpdate(props, a.data).runInContext(ctx);
|
|
|
+ return Transformer.UpdateResult.Updated;
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|