Ver Fonte

Component UI: show modify operations only if available

David Sehnal há 5 anos atrás
pai
commit
f11e03eb85

+ 5 - 1
src/mol-plugin-state/builder/structure.ts

@@ -5,7 +5,7 @@
  */
 
 import { PluginContext } from '../../mol-plugin/context';
-import { StateObjectRef, StateObjectSelector, StateTransformer, StateTransform } from '../../mol-state';
+import { StateObjectRef, StateObjectSelector, StateTransformer, StateTransform, StateObjectCell } from '../../mol-state';
 import { PluginStateObject as SO } from '../objects';
 import { StateTransforms } from '../transforms';
 import { RootStructureDefinition } from '../helpers/root-structure';
@@ -130,6 +130,10 @@ export class StructureBuilder {
         return props.selector;
     }
 
+    isComponent(cell: StateObjectCell) {
+        return cell.transform.transformer === StateTransforms.Model.StructureComponent;
+    }
+
     /** returns undefined if the component is empty/null */
     async tryCreateComponent(structure: StateObjectRef<SO.Molecule.Structure>, params: StructureComponentParams, key: string, tags?: string[]): Promise<StateObjectRef<SO.Molecule.Structure> | undefined> {
         const state = this.dataState;

+ 6 - 2
src/mol-plugin-state/manager/structure/component.ts

@@ -19,8 +19,8 @@ import { ParamDefinition as PD } from '../../../mol-util/param-definition';
 import { StructureRepresentationProvider } from '../../builder/structure/provider';
 import { PluginComponent } from '../../component';
 import { StructureComponentParams } from '../../helpers/structure-component';
-import { setStructureOverpaint, clearStructureOverpaint } from '../../helpers/structure-overpaint';
-import { StructureSelectionQuery, StructureSelectionQueryOptions, StructureSelectionQueries } from '../../helpers/structure-selection-query';
+import { clearStructureOverpaint, setStructureOverpaint } from '../../helpers/structure-overpaint';
+import { StructureSelectionQueries, StructureSelectionQuery, StructureSelectionQueryOptions } from '../../helpers/structure-selection-query';
 import { CustomStructureProperties } from '../../transforms/model';
 import { StructureRepresentation3D } from '../../transforms/representation';
 import { HierarchyRef, StructureComponentRef, StructureRef, StructureRepresentationRef } from './hierarchy-state';
@@ -129,6 +129,10 @@ class StructureComponentManager extends PluginComponent<StructureComponentManage
         }
     }
 
+    canBeModified(ref: HierarchyRef) {
+        return this.plugin.builders.structure.isComponent(ref.cell);
+    }
+
     modifyByCurrentSelection(components: ReadonlyArray<StructureComponentRef>, action: 'union' | 'subtract') {
         return this.plugin.runTask(Task.create('Subtract', async taskCtx => {
             const b = this.dataState.build();        

+ 6 - 3
src/mol-plugin-ui/structure/components.tsx

@@ -240,10 +240,13 @@ class StructureComponentGroup extends PurePluginUIComponent<{ group: StructureCo
                 ...StructureComponentManager.getRepresentationTypes(this.plugin, this.props.group[0])
                     .map(t => ActionMenu.Item(t[1], () => mng.addRepresentation(this.props.group, t[0])))
             ],
-            ActionMenu.Item('Select This', 'flash', () => mng.selectThis(this.props.group)),
-            ActionMenu.Item('Include Current Selection', 'plus', () => mng.modifyByCurrentSelection(this.props.group, 'union')),
-            ActionMenu.Item('Subtract Current Selection', 'minus', () => mng.modifyByCurrentSelection(this.props.group, 'subtract'))
+            ActionMenu.Item('Select This', 'flash', () => mng.selectThis(this.props.group))
         ];
+
+        if (this.plugin.managers.structure.component.canBeModified(this.props.group[0])) {
+            ret.push(ActionMenu.Item('Include Current Selection', 'plus', () => mng.modifyByCurrentSelection(this.props.group, 'union')));
+            ret.push(ActionMenu.Item('Subtract Current Selection', 'minus', () => mng.modifyByCurrentSelection(this.props.group, 'subtract')));
+        }
         return ret;
     }