diff --git a/src/mol-canvas3d/canvas3d.ts b/src/mol-canvas3d/canvas3d.ts index 8f285da41dfa9b106b73aa6b3cedec06a6dc1cea..b4facc8c76d67723fbc4694e1295401be7312ada 100644 --- a/src/mol-canvas3d/canvas3d.ts +++ b/src/mol-canvas3d/canvas3d.ts @@ -79,9 +79,6 @@ interface Canvas3D { readonly stats: RendererStats readonly interaction: Canvas3dInteractionHelper['events'] - // TODO: is this a good solution? - setSceneAnimating(animating: boolean): void - dispose: () => void } @@ -137,8 +134,6 @@ namespace Canvas3D { const debugHelper = new BoundingSphereHelper(webgl, scene, p.debug); const interactionHelper = new Canvas3dInteractionHelper(identify, getLoci, input); - let isSceneAnimating = false - function getLoci(pickingId: PickingId) { let loci: Loci = EmptyLoci let repr: Representation.Any = Representation.Empty @@ -153,13 +148,13 @@ namespace Canvas3D { return { loci, repr } } - function mark(loci: Representation.Loci, action: MarkerAction) { - const repr = loci.repr + function mark(reprLoci: Representation.Loci, action: MarkerAction) { + const { repr, loci } = reprLoci let changed = false if (repr) { - changed = repr.mark(loci.loci, action) + changed = repr.mark(loci, action) } else { - reprRenderObjects.forEach((_, _repr) => { changed = _repr.mark(loci.loci, action) || changed }) + reprRenderObjects.forEach((_, _repr) => { changed = _repr.mark(loci, action) || changed }) } if (changed) { scene.update(void 0, true) @@ -263,7 +258,7 @@ namespace Canvas3D { currentTime = now(); camera.transition.tick(currentTime); draw(false); - if (!camera.transition.inTransition && !isSceneAnimating) interactionHelper.tick(currentTime); + if (!camera.transition.inTransition) interactionHelper.tick(currentTime); window.requestAnimationFrame(animate) } @@ -436,9 +431,6 @@ namespace Canvas3D { get interaction() { return interactionHelper.events }, - setSceneAnimating(animating) { - isSceneAnimating = animating; - }, dispose: () => { scene.clear() debugHelper.clear() diff --git a/src/mol-plugin/state/animation/manager.ts b/src/mol-plugin/state/animation/manager.ts index 4b9105afb18e8e22b57f41ad11a0c54dbe3416b4..78d380625b7a2db54f7b62bb72b6125ac543fe5d 100644 --- a/src/mol-plugin/state/animation/manager.ts +++ b/src/mol-plugin/state/animation/manager.ts @@ -89,7 +89,6 @@ class PluginAnimationManager extends PluginComponent<PluginAnimationManager.Stat } start() { - this.context.canvas3d.setSceneAnimating(true); this.updateState({ animationState: 'playing' }); if (!this.context.behaviors.state.isAnimating.value) { this.context.behaviors.state.isAnimating.next(true); @@ -104,7 +103,6 @@ class PluginAnimationManager extends PluginComponent<PluginAnimationManager.Stat } stop() { - this.context.canvas3d.setSceneAnimating(false); if (typeof this._frame !== 'undefined') cancelAnimationFrame(this._frame); if (this.context.behaviors.state.isAnimating.value) { this.context.behaviors.state.isAnimating.next(false); diff --git a/src/mol-repr/structure/complex-visual.ts b/src/mol-repr/structure/complex-visual.ts index 122cbec4ee8174ad638c641bd5aaaff102dee254..456361a7b2a8aa3c08b09cb308d11da993260b8c 100644 --- a/src/mol-repr/structure/complex-visual.ts +++ b/src/mol-repr/structure/complex-visual.ts @@ -186,7 +186,7 @@ export function ComplexVisual<G extends Geometry, P extends ComplexParams & Geom } let changed = false - if (isEveryLoci(loci) || (Structure.isLoci(loci) && loci.structure === currentStructure)) { + if (isEveryLoci(loci) || (Structure.isLoci(loci) && Structure.areEquivalent(loci.structure, currentStructure))) { changed = apply(Interval.ofBounds(0, groupCount * instanceCount)) } else { changed = eachLocation(loci, currentStructure, apply) @@ -221,7 +221,7 @@ export function ComplexVisual<G extends Geometry, P extends ComplexParams & Geom return applyOverpaintColor(tOverpaint.ref.value.array, start, end, color, alpha) } - if (isEveryLoci(loci) || (Structure.isLoci(loci) && loci.structure === currentStructure)) { + if (isEveryLoci(loci) || (Structure.isLoci(loci) && Structure.areEquivalent(loci.structure, currentStructure))) { apply(Interval.ofBounds(0, groupCount * instanceCount)) } else { eachLocation(loci, currentStructure, apply) diff --git a/src/mol-repr/structure/units-visual.ts b/src/mol-repr/structure/units-visual.ts index f7eeba5193a4e08cf138362b039f67ac1e594451..439bf2c60fcae5bc7f078f5636c1a45f3026a233 100644 --- a/src/mol-repr/structure/units-visual.ts +++ b/src/mol-repr/structure/units-visual.ts @@ -232,7 +232,7 @@ export function UnitsVisual<G extends Geometry, P extends UnitsParams & Geometry } let changed = false - if (isEveryLoci(loci) || (Structure.isLoci(loci) && loci.structure === currentStructureGroup.structure)) { + if (isEveryLoci(loci) || (Structure.isLoci(loci) && Structure.areEquivalent(loci.structure, currentStructureGroup.structure))) { changed = apply(Interval.ofBounds(0, groupCount * instanceCount)) } else { changed = eachLocation(loci, currentStructureGroup, apply) @@ -267,7 +267,7 @@ export function UnitsVisual<G extends Geometry, P extends UnitsParams & Geometry return applyOverpaintColor(tOverpaint.ref.value.array, start, end, color, alpha) } - if (isEveryLoci(loci) || (Structure.isLoci(loci) && loci.structure === currentStructureGroup.structure)) { + if (isEveryLoci(loci) || (Structure.isLoci(loci) && Structure.areEquivalent(loci.structure, currentStructureGroup.structure))) { apply(Interval.ofBounds(0, groupCount * instanceCount)) } else { eachLocation(loci, currentStructureGroup, apply) diff --git a/src/mol-repr/structure/visual/carbohydrate-link-cylinder.ts b/src/mol-repr/structure/visual/carbohydrate-link-cylinder.ts index 431faff76935be1eed3556790fb580029fbb4dfc..c699d7464aecdc28c8c48e764db74c516e48d872 100644 --- a/src/mol-repr/structure/visual/carbohydrate-link-cylinder.ts +++ b/src/mol-repr/structure/visual/carbohydrate-link-cylinder.ts @@ -119,7 +119,7 @@ function getLinkLoci(pickingId: PickingId, structure: Structure, id: number) { function eachCarbohydrateLink(loci: Loci, structure: Structure, apply: (interval: Interval) => boolean) { let changed = false if (Link.isLoci(loci)) { - if (loci.structure !== structure) return false + if (!Structure.areEquivalent(loci.structure, structure)) return false const { getLinkIndex } = structure.carbohydrates for (const l of loci.links) { const idx = getLinkIndex(l.aUnit, l.aUnit.elements[l.aIndex], l.bUnit, l.bUnit.elements[l.bIndex]) @@ -128,7 +128,7 @@ function eachCarbohydrateLink(loci: Loci, structure: Structure, apply: (interval } } } else if (StructureElement.isLoci(loci)) { - if (loci.structure !== structure) return false + if (!Structure.areEquivalent(loci.structure, structure)) return false // TODO mark link only when both of the link elements are in a StructureElement.Loci const { getElementIndex, getLinkIndices, elements } = structure.carbohydrates for (const e of loci.elements) { diff --git a/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts b/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts index 2650b94056b834c028ff8b68d4d9c9195d76ccfb..bc4e4ad6f71267d9e7599562be026c6324863535 100644 --- a/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts +++ b/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts @@ -195,25 +195,25 @@ function getCarbohydrateLoci(pickingId: PickingId, structure: Structure, id: num function eachCarbohydrate(loci: Loci, structure: Structure, apply: (interval: Interval) => boolean) { const { getElementIndex, getAnomericCarbon } = structure.carbohydrates let changed = false - if (StructureElement.isLoci(loci)) { - for (const e of loci.elements) { - OrderedSet.forEach(e.indices, v => { - const { model, elements } = e.unit - const { index, offsets } = model.atomicHierarchy.residueAtomSegments - const rI = index[elements[v]] - const unitIndexMin = OrderedSet.findPredecessorIndex(elements, offsets[rI]) - const unitIndexMax = OrderedSet.findPredecessorIndex(elements, offsets[rI + 1] - 1) - const unitIndexInterval = Interval.ofRange(unitIndexMin, unitIndexMax) - if (!OrderedSet.isSubset(e.indices, unitIndexInterval)) return - const eI = getAnomericCarbon(e.unit, rI) - if (eI !== undefined) { - const idx = getElementIndex(e.unit, eI) - if (idx !== undefined) { - if (apply(Interval.ofBounds(idx * 2, idx * 2 + 2))) changed = true - } + if (!StructureElement.isLoci(loci)) return false + if (!Structure.areEquivalent(loci.structure, structure)) return false + for (const e of loci.elements) { + OrderedSet.forEach(e.indices, v => { + const { model, elements } = e.unit + const { index, offsets } = model.atomicHierarchy.residueAtomSegments + const rI = index[elements[v]] + const unitIndexMin = OrderedSet.findPredecessorIndex(elements, offsets[rI]) + const unitIndexMax = OrderedSet.findPredecessorIndex(elements, offsets[rI + 1] - 1) + const unitIndexInterval = Interval.ofRange(unitIndexMin, unitIndexMax) + if (!OrderedSet.isSubset(e.indices, unitIndexInterval)) return + const eI = getAnomericCarbon(e.unit, rI) + if (eI !== undefined) { + const idx = getElementIndex(e.unit, eI) + if (idx !== undefined) { + if (apply(Interval.ofBounds(idx * 2, idx * 2 + 2))) changed = true } - }) - } + } + }) } return changed } \ No newline at end of file diff --git a/src/mol-repr/structure/visual/carbohydrate-terminal-link-cylinder.ts b/src/mol-repr/structure/visual/carbohydrate-terminal-link-cylinder.ts index ae52c083ab489262a5147f9ad599f23f1c4357b9..d78b03bd16a475cbfc7aa617f9d77a27104ef1d9 100644 --- a/src/mol-repr/structure/visual/carbohydrate-terminal-link-cylinder.ts +++ b/src/mol-repr/structure/visual/carbohydrate-terminal-link-cylinder.ts @@ -131,9 +131,9 @@ function getTerminalLinkLoci(pickingId: PickingId, structure: Structure, id: num // TODO for each link when both of the link elements are in a StructureElement.Loci function eachTerminalLink(loci: Loci, structure: Structure, apply: (interval: Interval) => boolean) { const { getTerminalLinkIndex } = structure.carbohydrates - let changed = false if (Link.isLoci(loci)) { + if (!Structure.areEquivalent(loci.structure, structure)) return false for (const l of loci.links) { const idx = getTerminalLinkIndex(l.aUnit, l.aUnit.elements[l.aIndex], l.bUnit, l.bUnit.elements[l.bIndex]) if (idx !== undefined) { @@ -141,7 +141,7 @@ function eachTerminalLink(loci: Loci, structure: Structure, apply: (interval: In } } } else if (StructureElement.isLoci(loci)) { - if (loci.structure !== structure) return false + if (!Structure.areEquivalent(loci.structure, structure)) return false // TODO mark link only when both of the link elements are in a StructureElement.Loci const { getElementIndex, getTerminalLinkIndices, elements } = structure.carbohydrates for (const e of loci.elements) { diff --git a/src/mol-repr/structure/visual/cross-link-restraint-cylinder.ts b/src/mol-repr/structure/visual/cross-link-restraint-cylinder.ts index 1eb290b62d314c64a92178697b9b8e6c971a869f..26de0839cfa9744b7ecd4e5e980ec98afc4da141 100644 --- a/src/mol-repr/structure/visual/cross-link-restraint-cylinder.ts +++ b/src/mol-repr/structure/visual/cross-link-restraint-cylinder.ts @@ -106,9 +106,9 @@ function getLinkLoci(pickingId: PickingId, structure: Structure, id: number) { function eachCrossLink(loci: Loci, structure: Structure, apply: (interval: Interval) => boolean) { const crossLinks = structure.crossLinkRestraints - let changed = false if (Link.isLoci(loci)) { + if (!Structure.areEquivalent(loci.structure, structure)) return false for (const b of loci.links) { const indices = crossLinks.getPairIndices(b.aIndex, b.aUnit, b.bIndex, b.bUnit) if (indices) { diff --git a/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts b/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts index 7d10b67712f904dbdf72feb719d6bac2e00b65b8..fa55745425b88e8b15149d9d2e83ee4af92e5377 100644 --- a/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts +++ b/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts @@ -98,7 +98,7 @@ function getLinkLoci(pickingId: PickingId, structure: Structure, id: number) { function eachLink(loci: Loci, structure: Structure, apply: (interval: Interval) => boolean) { let changed = false if (Link.isLoci(loci)) { - if (loci.structure !== structure) return false + if (!Structure.areEquivalent(loci.structure, structure)) return false for (const b of loci.links) { const idx = structure.links.getBondIndex(b.aIndex, b.aUnit, b.bIndex, b.bUnit) if (idx !== -1) { @@ -106,7 +106,7 @@ function eachLink(loci: Loci, structure: Structure, apply: (interval: Interval) } } } else if (StructureElement.isLoci(loci)) { - if (loci.structure !== structure) return false + if (!Structure.areEquivalent(loci.structure, structure)) return false // TODO mark link only when both of the link elements are in a StructureElement.Loci for (const e of loci.elements) { OrderedSet.forEach(e.indices, v => { diff --git a/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts b/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts index d04f8d58f059bf6e8cc70b05e0a86b5b96252336..116ef8cf1eecafc06f6728b38fe32ed09109b5ee 100644 --- a/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts +++ b/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts @@ -116,7 +116,7 @@ function eachLink(loci: Loci, structureGroup: StructureGroup, apply: (interval: let changed = false if (Link.isLoci(loci)) { const { structure, group } = structureGroup - if (loci.structure !== structure) return false + if (!Structure.areEquivalent(loci.structure, structure)) return false const unit = group.units[0] if (!Unit.isAtomic(unit)) return false const groupCount = unit.links.edgeCount * 2 @@ -131,7 +131,7 @@ function eachLink(loci: Loci, structureGroup: StructureGroup, apply: (interval: } } else if (StructureElement.isLoci(loci)) { const { structure, group } = structureGroup - if (loci.structure !== structure) return false + if (!Structure.areEquivalent(loci.structure, structure)) return false const unit = group.units[0] if (!Unit.isAtomic(unit)) return false const groupCount = unit.links.edgeCount * 2 diff --git a/src/mol-repr/structure/visual/util/element.ts b/src/mol-repr/structure/visual/util/element.ts index 37aaff1be3d4037f8b81bb01e6483795ce248d9a..1ce958ec96e37b0cf6612f086c7ec72132c50dda 100644 --- a/src/mol-repr/structure/visual/util/element.ts +++ b/src/mol-repr/structure/visual/util/element.ts @@ -72,7 +72,7 @@ export function eachElement(loci: Loci, structureGroup: StructureGroup, apply: ( let changed = false if (!StructureElement.isLoci(loci)) return false const { structure, group } = structureGroup - if (loci.structure !== structure) return false + if (!Structure.areEquivalent(loci.structure, structure)) return false const elementCount = group.elements.length for (const e of loci.elements) { const unitIdx = group.unitIndexMap.get(e.unit.id) diff --git a/src/mol-repr/structure/visual/util/nucleotide.ts b/src/mol-repr/structure/visual/util/nucleotide.ts index ff5ada0d59f90fe7c5e0445702e1e6ebbfc657f5..22fe970f1692264dadea9354d0b454aa44fea7bc 100644 --- a/src/mol-repr/structure/visual/util/nucleotide.ts +++ b/src/mol-repr/structure/visual/util/nucleotide.ts @@ -4,7 +4,7 @@ * @author Alexander Rose <alexander.rose@weirdbyte.de> */ -import { Unit, StructureElement } from 'mol-model/structure'; +import { Unit, StructureElement, Structure } from 'mol-model/structure'; import { getNucleotideElements } from 'mol-model/structure/structure/util/nucleotide'; import { Loci, EmptyLoci } from 'mol-model/loci'; import { OrderedSet, Interval } from 'mol-data/int'; @@ -44,7 +44,7 @@ export function eachNucleotideElement(loci: Loci, structureGroup: StructureGroup let changed = false if (!StructureElement.isLoci(loci)) return false const { structure, group } = structureGroup - if (loci.structure !== structure) return false + if (!Structure.areEquivalent(loci.structure, structure)) return false const unit = group.units[0] if (!Unit.isAtomic(unit)) return false const { nucleotideElements, model, elements } = unit diff --git a/src/mol-repr/structure/visual/util/polymer.ts b/src/mol-repr/structure/visual/util/polymer.ts index 7dd84c2d93ab975b7c64cf988ccde8005407952a..71b987a3ea8b5ac3954524d393e59875b55b5733 100644 --- a/src/mol-repr/structure/visual/util/polymer.ts +++ b/src/mol-repr/structure/visual/util/polymer.ts @@ -4,7 +4,7 @@ * @author Alexander Rose <alexander.rose@weirdbyte.de> */ -import { Unit, ElementIndex, StructureElement, Link } from 'mol-model/structure'; +import { Unit, ElementIndex, StructureElement, Link, Structure } from 'mol-model/structure'; import SortedRanges from 'mol-data/int/sorted-ranges'; import { OrderedSet, Interval } from 'mol-data/int'; import { EmptyLoci, Loci } from 'mol-model/loci'; @@ -82,7 +82,7 @@ export function eachPolymerElement(loci: Loci, structureGroup: StructureGroup, a let changed = false if (!StructureElement.isLoci(loci)) return false const { structure, group } = structureGroup - if (loci.structure !== structure) return false + if (!Structure.areEquivalent(loci.structure, structure)) return false const { polymerElements, model, elements } = group.units[0] const { index, offsets } = model.atomicHierarchy.residueAtomSegments const { traceElementIndex } = model.atomicHierarchy.derived.residue @@ -130,7 +130,7 @@ export function eachPolymerGapElement(loci: Loci, structureGroup: StructureGroup let changed = false if (!Link.isLoci(loci)) return false const { structure, group } = structureGroup - if (loci.structure !== structure) return false + if (!Structure.areEquivalent(loci.structure, structure)) return false const groupCount = group.units[0].gapElements.length for (const b of loci.links) { const unitIdx = group.unitIndexMap.get(b.aUnit.id)