Browse Source

Representation.getLoci() returns 'whole' loci for repr

Alexander Rose 5 years ago
parent
commit
1bd59523b2

+ 2 - 2
src/mol-plugin/behavior/dynamic/representation.ts

@@ -41,7 +41,7 @@ export const HighlightLoci = PluginBehavior.create({
     ctor: class extends PluginBehavior.Handler<HighlightLociProps> {
         private lociMarkProvider = (interactionLoci: Interactivity.Loci, action: MarkerAction) => {
             if (!this.ctx.canvas3d) return;
-            this.ctx.canvas3d.mark({ loci: interactionLoci.loci, repr: interactionLoci.passRepresentation ? interactionLoci.repr : void 0 }, action)
+            this.ctx.canvas3d.mark({ loci: interactionLoci.loci }, action)
         }
         register() {
             this.subscribeObservable(this.ctx.behaviors.interaction.hover, ({ current, buttons, modifiers }) => {
@@ -94,7 +94,7 @@ export const SelectLoci = PluginBehavior.create({
         private spine: StateTreeSpine.Impl
         private lociMarkProvider = (interactionLoci: Interactivity.Loci, action: MarkerAction) => {
             if (!this.ctx.canvas3d) return;
-            this.ctx.canvas3d.mark({ loci: interactionLoci.loci, repr: interactionLoci.passRepresentation ? interactionLoci.repr : void 0 }, action)
+            this.ctx.canvas3d.mark({ loci: interactionLoci.loci }, action)
         }
         private applySelectMark(ref: string, clear?: boolean) {
             const cell = this.ctx.state.dataState.cells.get(ref)

+ 7 - 6
src/mol-plugin/behavior/static/state.ts

@@ -1,7 +1,8 @@
 /**
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2019 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 { PluginCommands } from '../../command';
@@ -13,7 +14,7 @@ import { getFormattedTime } from '../../../mol-util/date';
 import { readFromFile } from '../../../mol-util/data-source';
 import { download } from '../../../mol-util/download';
 import { Structure } from '../../../mol-model/structure';
-import { EmptyLoci, EveryLoci } from '../../../mol-model/loci';
+import { EmptyLoci } from '../../../mol-model/loci';
 
 export function registerDefault(ctx: PluginContext) {
     SyncBehaviors(ctx);
@@ -102,17 +103,17 @@ function setVisibilityVisitor(t: StateTransform, tree: StateTree, ctx: { state:
 }
 
 export function Highlight(ctx: PluginContext) {
-    PluginCommands.State.Highlight.subscribe(ctx, ({ state, ref, passRepresentation }) => {
+    PluginCommands.State.Highlight.subscribe(ctx, ({ state, ref }) => {
         const cell = state.select(ref)[0];
         if (!cell) return;
         if (SO.Molecule.Structure.is(cell.obj)) {
             ctx.interactivity.lociHighlights.highlightOnly({ loci: Structure.Loci(cell.obj.data) }, false);
         } else if (cell && SO.isRepresentation3D(cell.obj)) {
-            const loci = SO.Molecule.Structure.is(cell.obj.data.source) ? Structure.Loci(cell.obj.data.source.data) : EveryLoci
-            ctx.interactivity.lociHighlights.highlightOnly({ loci, repr: cell.obj.data.repr, passRepresentation }, false);
+            const { repr } = cell.obj.data
+            ctx.interactivity.lociHighlights.highlightOnly({ loci: repr.getLoci(), repr }, false);
         }
 
-        // TODO: highlight volumes and shapes?
+        // TODO: highlight volumes?
         // TODO: select structures of subtree?
     });
 }

+ 4 - 4
src/mol-plugin/util/interactivity.ts

@@ -42,7 +42,7 @@ class Interactivity {
 }
 
 namespace Interactivity {
-    export interface Loci<T extends ModelLoci = ModelLoci> { loci: T, repr?: Representation.Any, passRepresentation?: boolean /** = false */ }
+    export interface Loci<T extends ModelLoci = ModelLoci> { loci: T, repr?: Representation.Any }
 
     export namespace Loci {
         export function areEqual(a: Loci, b: Loci) {
@@ -82,9 +82,9 @@ namespace Interactivity {
         }
 
         protected normalizedLoci(interactivityLoci: Loci, applyGranularity = true) {
-            const { loci, repr, passRepresentation } = interactivityLoci
+            const { loci, repr } = interactivityLoci
             const granularity =  applyGranularity ? this.props.granularity : undefined
-            return { loci: ModelLoci.normalize(loci, granularity), repr, passRepresentation }
+            return { loci: ModelLoci.normalize(loci, granularity), repr }
         }
 
         protected mark(current: Loci<ModelLoci>, action: MarkerAction) {
@@ -124,7 +124,7 @@ namespace Interactivity {
             if (StructureElement.Loci.is(normalized.loci)) {
                 const loci = this.sel.tryGetRange(normalized.loci) || normalized.loci;
                 this.mark(this.prev, MarkerAction.RemoveHighlight);
-                const toHighlight = { loci, repr: normalized.repr, passRepresentation: normalized.passRepresentation };
+                const toHighlight = { loci, repr: normalized.repr };
                 this.mark(toHighlight, MarkerAction.Highlight);
                 this.prev = toHighlight;
             }

+ 6 - 2
src/mol-repr/representation.ts

@@ -134,7 +134,8 @@ interface Representation<D, P extends PD.Params = {}, S extends Representation.S
     createOrUpdate: (props?: Partial<PD.Values<P>>, data?: D) => Task<void>
     setState: (state: Partial<S>) => void
     setTheme: (theme: Theme) => void
-    getLoci: (pickingId: PickingId) => ModelLoci
+    /** If no pickingId is given, returns a Loci for the whole representation */
+    getLoci: (pickingId?: PickingId) => ModelLoci
     mark: (loci: ModelLoci, action: MarkerAction) => boolean
     destroy: () => void
 }
@@ -262,7 +263,10 @@ namespace Representation {
             },
             get state() { return currentState },
             get theme() { return currentTheme },
-            getLoci: (pickingId: PickingId) => {
+            getLoci: (pickingId?: PickingId) => {
+                if (pickingId === undefined) {
+                    return reprList.length > 0 ? reprList[0].getLoci() : EmptyLoci
+                }
                 for (let i = 0, il = reprList.length; i < il; ++i) {
                     const loci = reprList[i].getLoci(pickingId)
                     if (!isEmptyLoci(loci)) return loci

+ 2 - 1
src/mol-repr/shape/representation.ts

@@ -180,7 +180,8 @@ export function ShapeRepresentation<D, G extends Geometry, P extends Geometry.Pa
         renderObjects,
         updated,
         createOrUpdate,
-        getLoci(pickingId: PickingId) {
+        getLoci(pickingId?: PickingId) {
+            if (pickingId === undefined) return Shape.Loci(_shape)
             const { objectId, groupId, instanceId } = pickingId
             if (_renderObject && _renderObject.id === objectId) {
                 return ShapeGroup.Loci(_shape, [{ ids: OrderedSet.ofSingleton(groupId) }], instanceId)

+ 2 - 1
src/mol-repr/structure/complex-representation.ts

@@ -51,7 +51,8 @@ export function ComplexRepresentation<P extends StructureParams>(label: string,
         });
     }
 
-    function getLoci(pickingId: PickingId) {
+    function getLoci(pickingId?: PickingId) {
+        if (pickingId === undefined) return Structure.Loci(_structure)
         return visual ? visual.getLoci(pickingId) : EmptyLoci
     }
 

+ 2 - 1
src/mol-repr/structure/units-representation.ts

@@ -154,7 +154,8 @@ export function UnitsRepresentation<P extends UnitsParams>(label: string, ctx: R
         });
     }
 
-    function getLoci(pickingId: PickingId) {
+    function getLoci(pickingId?: PickingId) {
+        if (pickingId === undefined) return Structure.Loci(_structure)
         let loci: Loci = EmptyLoci
         visuals.forEach(({ visual }) => {
             const _loci = visual.getLoci(pickingId)

+ 2 - 1
src/mol-repr/volume/representation.ts

@@ -241,7 +241,8 @@ export function VolumeRepresentation<P extends VolumeParams>(label: string, ctx:
         });
     }
 
-    function getLoci(pickingId: PickingId) {
+    function getLoci(pickingId?: PickingId) {
+        if (pickingId === undefined) return EmptyLoci // TODO add Volume.Loci when available
         return visual ? visual.getLoci(pickingId) : EmptyLoci
     }