Browse Source

updateImmediate for modelIndex

dsehnal 4 years ago
parent
commit
c09357ea75
2 changed files with 31 additions and 14 deletions
  1. 2 2
      src/mol-plugin-state/transforms/model.ts
  2. 29 12
      src/mol-plugin-ui/structure/source.tsx

+ 2 - 2
src/mol-plugin-state/transforms/model.ts

@@ -345,9 +345,9 @@ const ModelFromTrajectory = PluginStateTransform.BuiltIn({
     to: SO.Molecule.Model,
     params: a => {
         if (!a) {
-            return { modelIndex: PD.Numeric(0, {}, { description: 'Zero-based index of the model' }) };
+            return { modelIndex: PD.Numeric(0, {}, { description: 'Zero-based index of the model', immediateUpdate: true }) };
         }
-        return { modelIndex: PD.Converted(plus1, minus1, PD.Numeric(1, { min: 1, max: a.data.frameCount, step: 1 }, { description: 'Model Index' })) };
+        return { modelIndex: PD.Converted(plus1, minus1, PD.Numeric(1, { min: 1, max: a.data.frameCount, step: 1 }, { description: 'Model Index', immediateUpdate: true })) };
     }
 })({
     isApplicable: a => a.data.frameCount > 0,

+ 29 - 12
src/mol-plugin-ui/structure/source.tsx

@@ -1,23 +1,23 @@
 /**
- * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2020-2021 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>
  */
 
 import * as React from 'react';
-import { StructureHierarchyRef, ModelRef, TrajectoryRef } from '../../mol-plugin-state/manager/structure/hierarchy-state';
+import { Model } from '../../mol-model/structure';
+import { ModelRef, StructureHierarchyRef, TrajectoryRef } from '../../mol-plugin-state/manager/structure/hierarchy-state';
 import { StateTransforms } from '../../mol-plugin-state/transforms';
+import { StateSelection } from '../../mol-state';
 import { CollapsableControls, CollapsableState } from '../base';
 import { ActionMenu } from '../controls/action-menu';
-import { Button, IconButton, ExpandGroup } from '../controls/common';
+import { Button, ExpandGroup, IconButton } from '../controls/common';
+import { BookmarksOutlinedSvg, MoleculeSvg } from '../controls/icons';
 import { ParameterControls } from '../controls/parameters';
-import { StructureFocusControls } from './focus';
 import { UpdateTransformControl } from '../state/update-transform';
+import { StructureFocusControls } from './focus';
 import { StructureSelectionStatsControls } from './selection';
-import { StateSelection } from '../../mol-state';
-import { MoleculeSvg, BookmarksOutlinedSvg } from '../controls/icons';
-import { Model } from '../../mol-model/structure';
 
 interface StructureSourceControlState extends CollapsableState {
     isBusy: boolean,
@@ -214,13 +214,30 @@ export class StructureSourceControls extends CollapsableControls<{}, StructureSo
         mng.hierarchy.applyPreset(trajectories, item.value as any);
     }
 
-    updateStructureModel = async (params: any) => {
-        const { selection } = this.plugin.managers.structure.hierarchy;
-        const m = selection.structures[0].model!;
-        this.plugin.state.updateTransform(this.plugin.state.data, m.cell.transform.ref, params, 'Model Index');
-        // TODO: ?? PluginCommands.Camera.Reset(this.plugin);
+    private updateModelQueueParams: any = void 0;
+    private isUpdatingModel = false;
+
+    private async _updateStructureModel() {
+        if (!this.updateModelQueueParams || this.isUpdatingModel) return;
+        const params = this.updateModelQueueParams;
+        this.updateModelQueueParams = void 0;
+
+        try {
+            this.isUpdatingModel = true;
+            const { selection } = this.plugin.managers.structure.hierarchy;
+            const m = selection.structures[0].model!;
+            await this.plugin.state.updateTransform(this.plugin.state.data, m.cell.transform.ref, params, 'Model Index');
+        } finally {
+            this.isUpdatingModel = false;
+            this._updateStructureModel();
+        }
     }
 
+    updateStructureModel = (params: any) => {
+        this.updateModelQueueParams = params;
+        this._updateStructureModel();
+    };
+
     get modelIndex() {
         const { selection } = this.plugin.managers.structure.hierarchy;
         if (selection.structures.length !== 1) return null;