Skip to content
Snippets Groups Projects
Commit e53e739d authored by Alexander Rose's avatar Alexander Rose
Browse files

ignore non StructureElement loci in StructureElementSelectionManager

parent dfb7f781
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
* *
* @author David Sehnal <david.sehnal@gmail.com> * @author David Sehnal <david.sehnal@gmail.com>
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/ */
import { OrderedSet } from '../../mol-data/int'; import { OrderedSet } from '../../mol-data/int';
...@@ -29,25 +30,37 @@ class StructureElementSelectionManager { ...@@ -29,25 +30,37 @@ class StructureElementSelectionManager {
return this.entries.get(ref)!; return this.entries.get(ref)!;
} }
add(loci: StructureElement.Loci): Loci { add(loci: Loci): Loci {
const entry = this.getEntry(loci.structure); if (StructureElement.isLoci(loci)) {
if (!entry) return EmptyLoci; const entry = this.getEntry(loci.structure);
entry.selection = StructureElement.Loci.union(entry.selection, loci); if (entry) {
return entry.selection; entry.selection = StructureElement.Loci.union(entry.selection, loci);
return entry.selection;
}
}
return EmptyLoci
} }
remove(loci: StructureElement.Loci): Loci { remove(loci: Loci): Loci {
const entry = this.getEntry(loci.structure); if (StructureElement.isLoci(loci)) {
if (!entry) return EmptyLoci; const entry = this.getEntry(loci.structure);
entry.selection = StructureElement.Loci.subtract(entry.selection, loci); if (entry) {
return entry.selection.elements.length === 0 ? EmptyLoci : entry.selection; entry.selection = StructureElement.Loci.subtract(entry.selection, loci);
return entry.selection.elements.length === 0 ? EmptyLoci : entry.selection;
}
}
return EmptyLoci
} }
set(loci: StructureElement.Loci): Loci { set(loci: Loci): Loci {
const entry = this.getEntry(loci.structure); if (StructureElement.isLoci(loci)) {
if (!entry) return EmptyLoci; const entry = this.getEntry(loci.structure);
entry.selection = loci; if (entry) {
return entry.selection.elements.length === 0 ? EmptyLoci : entry.selection; entry.selection = loci;
return entry.selection.elements.length === 0 ? EmptyLoci : entry.selection;
}
}
return EmptyLoci;
} }
clear() { clear() {
...@@ -69,13 +82,18 @@ class StructureElementSelectionManager { ...@@ -69,13 +82,18 @@ class StructureElementSelectionManager {
return entry.selection; return entry.selection;
} }
has(loci: StructureElement.Loci) { has(loci: Loci) {
const entry = this.getEntry(loci.structure); if (StructureElement.isLoci(loci)) {
if (!entry) return false; const entry = this.getEntry(loci.structure);
return StructureElement.Loci.areIntersecting(loci, entry.selection); if (entry) {
return StructureElement.Loci.areIntersecting(loci, entry.selection);
}
}
return false;
} }
tryGetRange(loci: StructureElement.Loci): StructureElement.Loci | undefined { tryGetRange(loci: Loci): StructureElement.Loci | undefined {
if (!StructureElement.isLoci(loci)) return;
if (loci.elements.length !== 1) return; if (loci.elements.length !== 1) return;
const entry = this.getEntry(loci.structure); const entry = this.getEntry(loci.structure);
if (!entry) return; if (!entry) return;
...@@ -110,11 +128,13 @@ class StructureElementSelectionManager { ...@@ -110,11 +128,13 @@ class StructureElementSelectionManager {
private prevHighlight: StructureElement.Loci | undefined = void 0; private prevHighlight: StructureElement.Loci | undefined = void 0;
accumulateInteractiveHighlight(loci: StructureElement.Loci) { accumulateInteractiveHighlight(loci: Loci) {
if (this.prevHighlight) { if (StructureElement.isLoci(loci)) {
this.prevHighlight = StructureElement.Loci.union(this.prevHighlight, loci); if (this.prevHighlight) {
} else { this.prevHighlight = StructureElement.Loci.union(this.prevHighlight, loci);
this.prevHighlight = loci; } else {
this.prevHighlight = loci;
}
} }
return this.prevHighlight; return this.prevHighlight;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment