|
@@ -8,22 +8,12 @@ import { PluginStateObject } from '../../mol-plugin/state/objects';
|
|
|
import { StateTransforms } from '../../mol-plugin/state/transforms';
|
|
|
import { StateSelection, StateObjectCell, StateTransform, StateBuilder } from '../../mol-state';
|
|
|
import { Structure, StructureElement } from '../../mol-model/structure';
|
|
|
-import { isEmptyLoci, EmptyLoci } from '../../mol-model/loci';
|
|
|
import { PluginContext } from '../context';
|
|
|
import { Color } from '../../mol-util/color';
|
|
|
-import { MolScriptBuilder } from '../../mol-script/language/builder';
|
|
|
-import { formatMolScript } from '../../mol-script/language/expression-formatter';
|
|
|
|
|
|
-type OverpaintEachReprCallback = (update: StateBuilder.Root, repr: StateObjectCell<PluginStateObject.Molecule.Structure.Representation3D, StateTransform<typeof StateTransforms.Representation.StructureRepresentation3D>>, rootStructure: Structure, overpaint?: StateObjectCell<any, StateTransform<typeof StateTransforms.Representation.OverpaintStructureRepresentation3D>>) => void
|
|
|
+type OverpaintEachReprCallback = (update: StateBuilder.Root, repr: StateObjectCell<PluginStateObject.Molecule.Structure.Representation3D, StateTransform<typeof StateTransforms.Representation.StructureRepresentation3D>>, overpaint?: StateObjectCell<any, StateTransform<typeof StateTransforms.Representation.OverpaintStructureRepresentation3DFromBundle>>) => void
|
|
|
const OverpaintManagerTag = 'overpaint-controls'
|
|
|
|
|
|
-export function getExpression(loci: StructureElement.Loci | EmptyLoci) {
|
|
|
- const scriptExpression = isEmptyLoci(loci)
|
|
|
- ? MolScriptBuilder.struct.generator.empty()
|
|
|
- : StructureElement.Loci.toScriptExpression(loci)
|
|
|
- return formatMolScript(scriptExpression)
|
|
|
-}
|
|
|
-
|
|
|
export class StructureOverpaintHelper {
|
|
|
private async eachRepr(callback: OverpaintEachReprCallback) {
|
|
|
const state = this.plugin.state.dataState;
|
|
@@ -31,29 +21,29 @@ export class StructureOverpaintHelper {
|
|
|
|
|
|
const update = state.build();
|
|
|
for (const r of reprs) {
|
|
|
- const overpaint = state.select(StateSelection.Generators.ofTransformer(StateTransforms.Representation.OverpaintStructureRepresentation3D, r.transform.ref).withTag(OverpaintManagerTag));
|
|
|
-
|
|
|
- const structure = r.obj!.data.source.data
|
|
|
-
|
|
|
- callback(update, r, structure.root, overpaint[0])
|
|
|
+ const overpaint = state.select(StateSelection.Generators.ofTransformer(StateTransforms.Representation.OverpaintStructureRepresentation3DFromBundle, r.transform.ref).withTag(OverpaintManagerTag))
|
|
|
+ callback(update, r, overpaint[0])
|
|
|
}
|
|
|
|
|
|
await this.plugin.runTask(state.updateTree(update, { doNotUpdateCurrent: true }));
|
|
|
}
|
|
|
|
|
|
async set(color: Color | -1, lociGetter: (structure: Structure) => StructureElement.Loci, types?: string[]) {
|
|
|
- await this.eachRepr((update, repr, rootStructure, overpaint) => {
|
|
|
+ await this.eachRepr((update, repr, overpaint) => {
|
|
|
+ console.log(types, repr.params!.values.type.name)
|
|
|
if (types && !types.includes(repr.params!.values.type.name)) return
|
|
|
|
|
|
- // TODO cleanup when loci is full structure or empty
|
|
|
- // TODO add & use QueryOverpaintStructureRepresentation3D
|
|
|
+ // TODO merge overpaint layers, delete shadowed ones
|
|
|
+ // TODO filter overpaint layers for given structure
|
|
|
|
|
|
- const loci = lociGetter(rootStructure)
|
|
|
- if (loci.elements.length === 0) return
|
|
|
- const expression = getExpression(loci)
|
|
|
+ const structure = repr.obj!.data.source.data
|
|
|
+ // always use the root structure to get the loci so the overpaint
|
|
|
+ // stays applicable as long as the root structure does not change
|
|
|
+ const loci = lociGetter(structure.root)
|
|
|
+ if (StructureElement.Loci.isEmpty(loci)) return
|
|
|
|
|
|
const layer = {
|
|
|
- script: { language: 'mol-script', expression },
|
|
|
+ bundle: StructureElement.Bundle.fromLoci(loci),
|
|
|
color: color === -1 ? Color(0) : color,
|
|
|
clear: color === -1
|
|
|
}
|
|
@@ -62,7 +52,7 @@ export class StructureOverpaintHelper {
|
|
|
update.to(overpaint).update({ layers: [ ...overpaint.params!.values.layers, layer ], alpha: 1 })
|
|
|
} else {
|
|
|
update.to(repr.transform.ref)
|
|
|
- .apply(StateTransforms.Representation.OverpaintStructureRepresentation3D, { layers: [ layer ], alpha: 1 }, { tags: OverpaintManagerTag });
|
|
|
+ .apply(StateTransforms.Representation.OverpaintStructureRepresentation3DFromBundle, { layers: [ layer ], alpha: 1 }, { tags: OverpaintManagerTag });
|
|
|
}
|
|
|
})
|
|
|
}
|