ソースを参照

mol-state: added createDefaultParams to StateAction and StateTransformer

David Sehnal 5 年 前
コミット
e550413778

+ 3 - 2
src/examples/proteopedia-wrapper/index.ts

@@ -28,7 +28,6 @@ import { BuiltInColorThemes } from '../../mol-theme/color';
 import { BuiltInSizeThemes } from '../../mol-theme/size';
 import { ColorNames } from '../../mol-util/color/names';
 import { InitVolumeStreaming, CreateVolumeStreamingInfo } from '../../mol-plugin/behavior/dynamic/volume-streaming/transformers';
-import { ParamDefinition } from '../../mol-util/param-definition';
 import { DefaultCanvas3DParams, Canvas3DProps } from '../../mol-canvas3d/canvas3d';
 // import { Vec3 } from 'mol-math/linear-algebra';
 // import { ParamDefinition } from 'mol-util/param-definition';
@@ -315,9 +314,11 @@ class MolStarProteopediaWrapper {
     experimentalData = {
         init: async (parent: Element) => {
             const asm = this.state.select(StateElements.Assembly)[0].obj!;
-            const params = ParamDefinition.getDefaultValues(InitVolumeStreaming.definition.params!(asm, this.plugin));
+            const params = InitVolumeStreaming.createDefaultParams(asm, this.plugin);
             params.options.behaviorRef = StateElements.VolumeStreaming;
             params.defaultView = 'box';
+            params.options.channelParams['fo-fc(+ve)'] = { wireframe: true };
+            params.options.channelParams['fo-fc(-ve)'] = { wireframe: true };
             await this.plugin.runTask(this.state.applyAction(InitVolumeStreaming, params, StateElements.Assembly));
             this.experimentalDataElement = parent;
             volumeStreamingControls(this.plugin, parent);

+ 5 - 2
src/mol-state/action.ts

@@ -17,7 +17,9 @@ export { StateAction };
 interface StateAction<A extends StateObject = StateObject, T = any, P extends {} = {}> {
     create(params: P): StateAction.Instance,
     readonly id: UUID,
-    readonly definition: StateAction.Definition<A, T, P>
+    readonly definition: StateAction.Definition<A, T, P>,
+    /** create a fresh copy of the params which can be edited in place */
+    createDefaultParams(a: A, globalCtx: unknown): P
 }
 
 namespace StateAction {
@@ -59,7 +61,8 @@ namespace StateAction {
         const action: StateAction<A, T, P> = {
             create(params) { return { action, params }; },
             id: UUID.create22(),
-            definition
+            definition,
+            createDefaultParams(a, globalCtx) { return definition.params ? PD.getDefaultValues( definition.params(a, globalCtx)) : {} as any; }
         };
         return action;
     }

+ 5 - 2
src/mol-state/transformer.ts

@@ -19,7 +19,9 @@ interface Transformer<A extends StateObject = StateObject, B extends StateObject
     toAction(): StateAction<A, void, P>,
     readonly namespace: string,
     readonly id: Transformer.Id,
-    readonly definition: Transformer.Definition<A, B, P>
+    readonly definition: Transformer.Definition<A, B, P>,
+    /** create a fresh copy of the params which can be edited in place */
+    createDefaultParams(a: A, globalCtx: unknown): P
 }
 
 namespace Transformer {
@@ -143,7 +145,8 @@ namespace Transformer {
             toAction() { return StateAction.fromTransformer(t); },
             namespace,
             id,
-            definition
+            definition,
+            createDefaultParams(a, globalCtx) { return definition.params ? PD.getDefaultValues( definition.params(a, globalCtx)) : {} as any; }
         };
         registry.set(id, t);
         _index(t);