diff --git a/src/mol-plugin/state/actions/basic.ts b/src/mol-plugin/state/actions/basic.ts index bd45155cf267a0497daea4a7533707855a3b87be..d54a87b9aef0e984040fca191052c81dd30c1270 100644 --- a/src/mol-plugin/state/actions/basic.ts +++ b/src/mol-plugin/state/actions/basic.ts @@ -16,6 +16,7 @@ import { StateTransforms } from '../transforms'; import { Download } from '../transforms/data'; import { StructureRepresentation3DHelpers, VolumeRepresentation3DHelpers } from '../transforms/representation'; import { getFileInfo, FileInput } from 'mol-util/file-info'; +import { Task } from 'mol-task'; // TODO: "structure/volume parser provider" @@ -176,8 +177,10 @@ function getVolumeData(format: VolumeFormat, b: StateTreeBuilder.To<PluginStateO function createVolumeTree(format: VolumeFormat, ctx: PluginContext, b: StateTreeBuilder.To<PluginStateObject.Data.Binary | PluginStateObject.Data.String>): StateTree { return getVolumeData(format, b) - .apply(StateTransforms.Representation.VolumeRepresentation3D, - VolumeRepresentation3DHelpers.getDefaultParamsStatic(ctx, 'isosurface')) + .apply(StateTransforms.Representation.VolumeRepresentation3D) + // the parameters will be used automatically by the reconciler and the IsoValue object + // will get the correct Stats object instead of the empty one + // VolumeRepresentation3DHelpers.getDefaultParamsStatic(ctx, 'isosurface')) .getTree(); } @@ -203,21 +206,22 @@ export const OpenVolume = StateAction.build({ ['auto', 'Automatic'], ['ccp4', 'CCP4'], ['mrc', 'MRC'], ['map', 'MAP'], ['dsn6', 'DSN6'], ['brix', 'BRIX'] ]), } -})(async ({ params, state }, ctx: PluginContext) => { +})(({ params, state }, ctx: PluginContext) => Task.create('Open Volume', async taskCtx => { const dataTree = state.build().toRoot().apply(StateTransforms.Data.ReadFile, { file: params.file, isBinary: true }); - const volumeData = await ctx.runTask(state.updateTree(dataTree)); + const volumeData = await state.updateTree(dataTree).runInContext(taskCtx); // Alternative for more complex states where the builder is not a simple StateTreeBuilder.To<>: /* const dataRef = dataTree.ref; - await ctx.runTask(state.updateTree(dataTree)); + await state.updateTree(dataTree).runInContext(taskCtx); const dataCell = state.select(dataRef)[0]; */ - const format = getFileFormat(params.format, params.file, volumeData.data as Uint8Array) + const format = getFileFormat(params.format, params.file, volumeData.data as Uint8Array); const volumeTree = state.build().to(dataTree.ref); - return state.updateTree(createVolumeTree(format, ctx, volumeTree)); -}); + // need to await the 2nd update the so that the enclosing Task finishes after the update is done. + await state.updateTree(createVolumeTree(format, ctx, volumeTree)).runInContext(taskCtx); +})); export { DownloadDensity }; type DownloadDensity = typeof DownloadDensity diff --git a/src/mol-plugin/state/transforms/representation.ts b/src/mol-plugin/state/transforms/representation.ts index 4ffdfa8face12d2066213a6cd09a32e9c4a339a1..31fbb134ff2df51dfc639187c3c87edefb255302 100644 --- a/src/mol-plugin/state/transforms/representation.ts +++ b/src/mol-plugin/state/transforms/representation.ts @@ -233,6 +233,8 @@ const VolumeRepresentation3D = PluginStateTransform.BuiltIn({ 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({}) + // TODO include isoValue in the label where available + console.log(params.type.params); await repr.createOrUpdate(props, a.data).runInContext(ctx); return new SO.Volume.Representation3D(repr, { label: provider.label }); });