Browse Source

StructureHierarchy.childRoot for structure/model
- to correctly support decorators like custom props

David Sehnal 5 years ago
parent
commit
7e31fac99a

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

@@ -113,7 +113,7 @@ class StructureComponentManager extends PluginComponent<StructureComponentManage
         return this.plugin.dataTransaction(async () => {
             await this.clearComponents(structures);
             for (const s of structures) {
-                await this.plugin.builders.structure.representation.applyPreset(s.cell, provider, params);
+                await this.plugin.builders.structure.representation.applyPreset(s.childRoot, provider, params);
             }
         }, { canUndo: 'Preset' });
     }
@@ -261,7 +261,7 @@ class StructureComponentManager extends PluginComponent<StructureComponentManage
             const componentKey = UUID.create22();
             for (const s of xs) {
                 const component = await this.plugin.builders.structure.tryCreateQueryComponent({ 
-                    structure: s.cell,
+                    structure: s.childRoot,
                     query: params.selection,
                     key: componentKey,
                     label: params.label || (params.selection === StructureSelectionQueries.current ? 'Custom Selection' : ''),

+ 15 - 3
src/mol-plugin-state/manager/structure/hierarchy-state.ts

@@ -57,10 +57,12 @@ export interface ModelRef extends RefBase<'model', SO.Molecule.Model> {
     properties?: ModelPropertiesRef,
     structures: StructureRef[],
     genericRepresentations?: GenericRepresentationRef[],
+    /** to support decorators */
+    childRoot: StateObjectCell<SO.Molecule.Model>
 }
 
 function ModelRef(cell: StateObjectCell<SO.Molecule.Model>, trajectory?: TrajectoryRef): ModelRef {
-    return { kind: 'model', cell, version: cell.transform.version, trajectory, structures: [] };
+    return { kind: 'model', cell, version: cell.transform.version, trajectory, structures: [], childRoot: cell };
 }
 
 export interface ModelPropertiesRef extends RefBase<'model-properties', SO.Molecule.Model, StateTransforms['Model']['CustomModelProperties']> {
@@ -80,11 +82,13 @@ export interface StructureRef extends RefBase<'structure', SO.Molecule.Structure
         surroundings?: StructureComponentRef,
     },
     genericRepresentations?: GenericRepresentationRef[],
-    volumeStreaming?: StructureVolumeStreamingRef
+    volumeStreaming?: StructureVolumeStreamingRef,
+    /** to support decorators */
+    childRoot: StateObjectCell<SO.Molecule.Structure>
 }
 
 function StructureRef(cell: StateObjectCell<SO.Molecule.Structure>, model?: ModelRef): StructureRef {
-    return { kind: 'structure', cell, version: cell.transform.version, model, components: [] };
+    return { kind: 'structure', cell, version: cell.transform.version, model, components: [], childRoot: cell };
 }
 
 export interface StructurePropertiesRef extends RefBase<'structure-properties', SO.Molecule.Structure, StateTransforms['Model']['CustomStructureProperties']> {
@@ -263,6 +267,14 @@ function _doPreOrder(ctx: VisitorCtx, root: StateTransform) {
         }
     }
 
+    if (cell.transform.isDecorator) {
+        if (state.currentModel && SO.Molecule.Model.is(cell.obj)) {
+            state.currentModel.childRoot = cell;
+        } else if (state.currentStructure && !state.currentComponent && SO.Molecule.Structure.is(cell.obj)) {
+            state.currentStructure.childRoot = cell;
+        }
+    }
+
     if (!onLeave && !cell.state.isGhost && state.currentComponent && SO.Molecule.Structure.Representation3D.is(cell.obj)) {
         createOrUpdateRefList(state, cell, state.currentComponent.representations, StructureRepresentationRef, cell, state.currentComponent);
     } else if (!cell.state.isGhost && SO.isRepresentation3D(cell.obj)) {

+ 0 - 0
src/mol-plugin-state/manager/structure/model.ts


+ 0 - 7
src/mol-plugin-state/manager/structure/volume.ts

@@ -1,7 +0,0 @@
-/**
- * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
- *
- * @author David Sehnal <david.sehnal@gmail.com>
- */
-
-// TODO: manager that handles experimental volumes (and streaming)

+ 2 - 2
src/mol-plugin-ui/structure/volume.tsx

@@ -43,8 +43,8 @@ export class VolumeStreamingControls extends CollapsableControls<{}, VolumeStrea
     }
 
     renderEnable() {
-        const pivot = this.pivot.cell;
-        return <ApplyActionControl state={pivot.parent} action={InitVolumeStreaming} initiallyCollapsed={true} nodeRef={pivot.transform.ref} simpleApply={{ header: 'Enable', icon: 'check' }} />;
+        const pivot = this.pivot;
+        return <ApplyActionControl state={pivot.cell.parent} action={InitVolumeStreaming} initiallyCollapsed={true} nodeRef={pivot.childRoot.transform.ref} simpleApply={{ header: 'Enable', icon: 'check' }} />;
     }
 
     renderParams() {