Browse Source

StructureSourceControls: added 'conformation transform' section

David Sehnal 5 years ago
parent
commit
31b83e9675
2 changed files with 24 additions and 1 deletions
  1. 14 1
      src/mol-plugin-ui/structure/source.tsx
  2. 10 0
      src/mol-state/state/selection.ts

+ 14 - 1
src/mol-plugin-ui/structure/source.tsx

@@ -10,11 +10,12 @@ import { HierarchyRef, ModelRef, TrajectoryRef } from '../../mol-plugin-state/ma
 import { StateTransforms } from '../../mol-plugin-state/transforms';
 import { CollapsableControls, CollapsableState } from '../base';
 import { ActionMenu } from '../controls/action-menu';
-import { Button, IconButton } from '../controls/common';
+import { Button, IconButton, ExpandGroup } from '../controls/common';
 import { ParameterControls } from '../controls/parameters';
 import { StructureFocusControls } from './focus';
 import { UpdateTransformControl } from '../state/update-transform';
 import { StructureSelectionStatsControls } from './selection';
+import { StateSelection } from '../../mol-state';
 
 interface StructureSourceControlState extends CollapsableState {
     isBusy: boolean,
@@ -247,6 +248,17 @@ export class StructureSourceControls extends CollapsableControls<{}, StructureSo
         return <UpdateTransformControl state={s.cell.parent} transform={s.cell.transform} customHeader='none' customUpdate={this.updateStructure} noMargin autoHideApply />;
     }
 
+    get transform() {
+        const { selection } = this.plugin.managers.structure.hierarchy;
+        if (selection.structures.length !== 1) return null;
+        const pivot = selection.structures[0];
+        const t = StateSelection.tryFindDecorator(this.plugin.state.data, pivot.cell.transform.ref, StateTransforms.Model.TransformStructureConformation);
+        if (!t) return;
+        return <ExpandGroup header={`Conformation Transform`}>
+            <UpdateTransformControl state={t.parent!} transform={t.transform} customHeader='none' noMargin autoHideApply />
+        </ExpandGroup>;
+    }
+
     renderControls() {
         const disabled = this.state.isBusy || this.isEmpty;
         const presets = this.presetActions;
@@ -260,6 +272,7 @@ export class StructureSourceControls extends CollapsableControls<{}, StructureSo
             {this.state.show === 'presets' && <ActionMenu items={presets} onSelect={this.applyPreset} />}
             {this.modelIndex}
             {this.structureType}
+            {this.transform}
 
             <div style={{ marginTop: '6px' }}>
                 <StructureFocusControls />

+ 10 - 0
src/mol-state/state/selection.ts

@@ -331,6 +331,16 @@ namespace StateSelection {
             s.refs.push(n);
         }
     }
+
+    export function tryFindDecorator<T extends StateTransformer>(state: State, root: StateTransform.Ref, transformer: T): StateObjectCell<StateTransformer.To<T>, StateTransform<T>> | undefined {
+        const t = state.transforms.get(root);
+        if (t.transformer === transformer) return state.cells.get(root)! as any;
+
+        const children = state.tree.children.get(root);
+        if (children.size !== 1) return;
+        const first = children.first();
+        if (state.transforms.get(first).transformer.definition.isDecorator) return tryFindDecorator(state, first, transformer);
+    }
 }
 
 export { StateSelection };