Bladeren bron

OpenVolume fixes

David Sehnal 6 jaren geleden
bovenliggende
commit
b9dd32642a
2 gewijzigde bestanden met toevoegingen van 14 en 8 verwijderingen
  1. 12 8
      src/mol-plugin/state/actions/basic.ts
  2. 2 0
      src/mol-plugin/state/transforms/representation.ts

+ 12 - 8
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

+ 2 - 0
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 });
         });