diff --git a/src/apps/basic-wrapper/index.ts b/src/apps/basic-wrapper/index.ts index 04326989a0d86925825e08457ed2bd6ed62af605..1d30fbf1e5db8bf5a3937dddfa02375fada5c119 100644 --- a/src/apps/basic-wrapper/index.ts +++ b/src/apps/basic-wrapper/index.ts @@ -93,7 +93,7 @@ class BasicWrapper { async load({ url, format = 'cif', assemblyId = '' }: LoadParams) { let loadType: 'full' | 'update' = 'full'; - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; if (this.loadedParams.url !== url || this.loadedParams.format !== format) { loadType = 'full'; @@ -118,7 +118,7 @@ class BasicWrapper { tree.to('asm').update(StateTransforms.Model.StructureFromModel, p => ({ ...p, ...props })); } - await PluginCommands.State.Update(this.plugin, { state: this.plugin.state.dataState, tree }); + await PluginCommands.State.Update(this.plugin, { state: this.plugin.state.data, tree }); this.loadedParams = { url, format, assemblyId }; PluginCommands.Camera.Reset(this.plugin, { }); } @@ -150,7 +150,7 @@ class BasicWrapper { coloring = { applyStripes: async () => { - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; const visuals = state.selectQ(q => q.ofTransformer(StateTransforms.Representation.StructureRepresentation3D)); const tree = state.build(); @@ -167,7 +167,7 @@ class BasicWrapper { interactivity = { highlightOn: () => { const seq_id = 7; - const data = (this.plugin.state.dataState.select('asm')[0].obj as PluginStateObject.Molecule.Structure).data; + const data = (this.plugin.state.data.select('asm')[0].obj as PluginStateObject.Molecule.Structure).data; const sel = Script.getStructureSelection(Q => Q.struct.generator.atomGroups({ 'residue-test': Q.core.rel.eq([Q.struct.atomProperty.macromolecular.label_seq_id(), seq_id]), 'group-by': Q.struct.atomProperty.macromolecular.residueKey() @@ -182,17 +182,17 @@ class BasicWrapper { tests = { staticSuperposition: async () => { - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; const tree = buildStaticSuperposition(this.plugin, StaticSuperpositionTestData); await PluginCommands.State.RemoveObject(this.plugin, { state, ref: StateTransform.RootRef }); await PluginCommands.State.Update(this.plugin, { state, tree }); }, dynamicSuperposition: async () => { - await PluginCommands.State.RemoveObject(this.plugin, { state: this.plugin.state.dataState, ref: StateTransform.RootRef }); + await PluginCommands.State.RemoveObject(this.plugin, { state: this.plugin.state.data, ref: StateTransform.RootRef }); await dynamicSuperpositionTest(this.plugin, ['1tqn', '2hhb', '4hhb'], 'HEM'); }, toggleValidationTooltip: async () => { - const state = this.plugin.state.behaviorState; + const state = this.plugin.state.behaviors; const tree = state.build().to(PDBeStructureQualityReport.id).update(PDBeStructureQualityReport, p => ({ ...p, showTooltip: !p.showTooltip })); await PluginCommands.State.Update(this.plugin, { state, tree }); }, diff --git a/src/apps/basic-wrapper/superposition.ts b/src/apps/basic-wrapper/superposition.ts index d7483ae06946fefba014d3ce18ba5638c8a63f04..2fd361526afeff62872aae0a5831fc36f3765419 100644 --- a/src/apps/basic-wrapper/superposition.ts +++ b/src/apps/basic-wrapper/superposition.ts @@ -32,7 +32,7 @@ export type SuperpositionTestInput = { // } export function buildStaticSuperposition(ctx: PluginContext, src: SuperpositionTestInput) { - const b = ctx.state.dataState.build().toRoot(); + const b = ctx.state.data.build().toRoot(); for (const s of src) { StateHelper.visual(ctx, StateHelper.transform( @@ -63,7 +63,7 @@ export const StaticSuperpositionTestData: SuperpositionTestInput = [ ]; export async function dynamicSuperpositionTest(ctx: PluginContext, src: string[], comp_id: string) { - const state = ctx.state.dataState; + const state = ctx.state.data; const structures = state.build().toRoot(); for (const s of src) { diff --git a/src/apps/demos/lighting/index.ts b/src/apps/demos/lighting/index.ts index 7bf493ce279405f8356e8b2932a3b8cb48d2e04b..1a50d7f640f5dc2030defa653d21bfe2f3d54097 100644 --- a/src/apps/demos/lighting/index.ts +++ b/src/apps/demos/lighting/index.ts @@ -145,7 +145,7 @@ class LightingDemo { async load({ url, format = 'cif', assemblyId = '' }: LoadParams) { let loadType: 'full' | 'update' = 'full'; - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; if (this.loadedParams.url !== url || this.loadedParams.format !== format) { loadType = 'full'; @@ -169,7 +169,7 @@ class LightingDemo { tree.to('asm').update(StateTransforms.Model.StructureFromModel, p => ({ ...p, ...props })); } - await PluginCommands.State.Update(this.plugin, { state: this.plugin.state.dataState, tree }); + await PluginCommands.State.Update(this.plugin, { state: this.plugin.state.data, tree }); this.loadedParams = { url, format, assemblyId }; PluginCommands.Camera.Reset(this.plugin, { }); } diff --git a/src/apps/viewer/index.ts b/src/apps/viewer/index.ts index 554df9dc0e5fbf2249d9eb1ae5097a30be56ce12..dbc813432bbe613347823a411199b9c24c5647fc 100644 --- a/src/apps/viewer/index.ts +++ b/src/apps/viewer/index.ts @@ -80,7 +80,7 @@ async function tryLoadFromUrl(ctx: PluginContext) { const params = DownloadStructure.createDefaultParams(void 0 as any, ctx); - return ctx.runTask(ctx.state.dataState.applyAction(DownloadStructure, { + return ctx.runTask(ctx.state.data.applyAction(DownloadStructure, { source: { name: 'url', params: { diff --git a/src/examples/proteopedia-wrapper/index.ts b/src/examples/proteopedia-wrapper/index.ts index d19fbff440ee6158db840657baeed4d98f02d3d4..c544b4bd43b97796801484b67c7ab5aa2a2e7deb 100644 --- a/src/examples/proteopedia-wrapper/index.ts +++ b/src/examples/proteopedia-wrapper/index.ts @@ -74,7 +74,7 @@ class MolStarProteopediaWrapper { } get state() { - return this.plugin.state.dataState; + return this.plugin.state.data; } private download(b: StateBuilder.To<PSO.Root>, url: string) { @@ -196,14 +196,14 @@ class MolStarProteopediaWrapper { } private applyState(tree: StateBuilder) { - return PluginCommands.State.Update(this.plugin, { state: this.plugin.state.dataState, tree }); + return PluginCommands.State.Update(this.plugin, { state: this.plugin.state.data, tree }); } private loadedParams: LoadParams = { url: '', format: 'cif', assemblyId: '' }; async load({ url, format = 'cif', assemblyId = 'deposited', representationStyle }: LoadParams) { let loadType: 'full' | 'update' = 'full'; - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; if (this.loadedParams.url !== url || this.loadedParams.format !== format) { loadType = 'full'; @@ -242,7 +242,7 @@ class MolStarProteopediaWrapper { async updateStyle(style?: RepresentationStyle, partial?: boolean) { const tree = this.visual(style, partial); if (!tree) return; - await PluginCommands.State.Update(this.plugin, { state: this.plugin.state.dataState, tree }); + await PluginCommands.State.Update(this.plugin, { state: this.plugin.state.data, tree }); } setBackground(color: number) { diff --git a/src/mol-plugin-state/actions/structure.ts b/src/mol-plugin-state/actions/structure.ts index f8df08c5d42526ae75e916de2d87bfbef1b92548..9b6e88dae7be3597b915d80025393457d2f06cd7 100644 --- a/src/mol-plugin-state/actions/structure.ts +++ b/src/mol-plugin-state/actions/structure.ts @@ -376,7 +376,7 @@ export const AddTrajectory = StateAction.build({ display: { name: 'Add Trajectory', description: 'Add trajectory from existing model/topology and coordinates.' }, from: PluginStateObject.Root, params(a, ctx: PluginContext) { - const state = ctx.state.dataState + const state = ctx.state.data const models = [ ...state.selectQ(q => q.rootsOfType(PluginStateObject.Molecule.Model)), ...state.selectQ(q => q.rootsOfType(PluginStateObject.Molecule.Topology)), diff --git a/src/mol-plugin-state/animation/built-in.ts b/src/mol-plugin-state/animation/built-in.ts index 3ed50d480ebbd3202898bfde1d06489d2224196d..89790318695fb0f8683619ec72bc599ff938b2d9 100644 --- a/src/mol-plugin-state/animation/built-in.ts +++ b/src/mol-plugin-state/animation/built-in.ts @@ -30,7 +30,7 @@ export const AnimateModelIndex = PluginStateAnimation.create({ return { kind: 'skip' }; } - const state = ctx.plugin.state.dataState; + const state = ctx.plugin.state.data; const models = state.select(StateSelection.Generators.ofTransformer(StateTransforms.Model.ModelFromTrajectory)); if (models.length === 0) { @@ -92,7 +92,7 @@ export const AnimateAssemblyUnwind = PluginStateAnimation.create({ display: { name: 'Unwind Assembly' }, params: (plugin: PluginContext) => { const targets: [string, string][] = [['all', 'All']]; - const structures = plugin.state.dataState.select(StateSelection.Generators.rootsOfType(PluginStateObject.Molecule.Structure)); + const structures = plugin.state.data.select(StateSelection.Generators.rootsOfType(PluginStateObject.Molecule.Structure)); for (const s of structures) { targets.push([s.transform.ref, s.obj!.data.models[0].label]); @@ -106,7 +106,7 @@ export const AnimateAssemblyUnwind = PluginStateAnimation.create({ }, initialState: () => ({ t: 0 }), async setup(params, plugin) { - const state = plugin.state.dataState; + const state = plugin.state.data; const root = !params.target || params.target === 'all' ? StateTransform.RootRef : params.target; const reprs = state.select(StateSelection.Generators.ofType(PluginStateObject.Molecule.Structure.Representation3D, root)); @@ -123,20 +123,20 @@ export const AnimateAssemblyUnwind = PluginStateAnimation.create({ if (!changed) return; - return plugin.runTask(state.updateTree(update, { doNotUpdateCurrent: true })); + return plugin.updateState(update, { doNotUpdateCurrent: true }); }, async teardown(_, plugin) { - const state = plugin.state.dataState; + const state = plugin.state.data; const reprs = state.select(StateSelection.Generators.ofType(PluginStateObject.Molecule.Structure.Representation3DState) .withTag('animate-assembly-unwind')); if (reprs.length === 0) return; const update = state.build(); for (const r of reprs) update.delete(r.transform.ref); - return plugin.runTask(state.updateTree(update)); + return plugin.updateState(update); }, async apply(animState, t, ctx) { - const state = ctx.plugin.state.dataState; + const state = ctx.plugin.state.data; const root = !ctx.params.target || ctx.params.target === 'all' ? StateTransform.RootRef : ctx.params.target; const anims = state.select(StateSelection.Generators.ofTransformer(StateTransforms.Representation.UnwindStructureAssemblyRepresentation3D, root)); @@ -174,7 +174,7 @@ export const AnimateUnitsExplode = PluginStateAnimation.create({ }), initialState: () => ({ t: 0 }), async setup(_, plugin) { - const state = plugin.state.dataState; + const state = plugin.state.data; const reprs = state.select(StateSelection.Generators.ofType(PluginStateObject.Molecule.Structure.Representation3D)); const update = state.build(); @@ -190,20 +190,20 @@ export const AnimateUnitsExplode = PluginStateAnimation.create({ if (!changed) return; - return plugin.runTask(state.updateTree(update, { doNotUpdateCurrent: true })); + return plugin.updateState(update, { doNotUpdateCurrent: true }); }, async teardown(_, plugin) { - const state = plugin.state.dataState; + const state = plugin.state.data; const reprs = state.select(StateSelection.Generators.ofType(PluginStateObject.Molecule.Structure.Representation3DState) .withTag('animate-units-explode')); if (reprs.length === 0) return; const update = state.build(); for (const r of reprs) update.delete(r.transform.ref); - return plugin.runTask(state.updateTree(update)); + return plugin.updateState(update); }, async apply(animState, t, ctx) { - const state = ctx.plugin.state.dataState; + const state = ctx.plugin.state.data; const anims = state.select(StateSelection.Generators.ofTransformer(StateTransforms.Representation.ExplodeStructureRepresentation3D)); if (anims.length === 0) { @@ -251,7 +251,7 @@ export const AnimateStateInterpolation = PluginStateAnimation.create({ const src = _src.data.tree.transforms, tar = _tar.data.tree.transforms; - const state = ctx.plugin.state.dataState; + const state = ctx.plugin.state.data; const update = state.build(); for (const s of src) { diff --git a/src/mol-plugin-state/builder/data.ts b/src/mol-plugin-state/builder/data.ts index 99143b1f903538537bbdf27260a85899cee1b722..358fce2ee4869138e34237ebbc508d3d47613985 100644 --- a/src/mol-plugin-state/builder/data.ts +++ b/src/mol-plugin-state/builder/data.ts @@ -11,31 +11,31 @@ import { getFileInfo } from '../../mol-util/file-info'; export class DataBuilder { private get dataState() { - return this.plugin.state.dataState; + return this.plugin.state.data; } async rawData(params: StateTransformer.Params<RawData>, options?: Partial<StateTransform.Options>) { const data = this.dataState.build().toRoot().apply(RawData, params, options); - await this.plugin.runTask(this.dataState.updateTree(data, { revertOnError: true })); + await this.plugin.updateState(data, { revertOnError: true }); return data.selector; } async download(params: StateTransformer.Params<Download>, options?: Partial<StateTransform.Options>) { const data = this.dataState.build().toRoot().apply(Download, params, options); - await this.plugin.runTask(this.dataState.updateTree(data, { revertOnError: true })); + await this.plugin.updateState(data, { revertOnError: true }); return data.selector; } async downloadBlob(params: StateTransformer.Params<DownloadBlob>, options?: Partial<StateTransform.Options>) { const data = this.dataState.build().toRoot().apply(DownloadBlob, params, options); - await this.plugin.runTask(this.dataState.updateTree(data, { revertOnError: true })); + await this.plugin.updateState(data, { revertOnError: true }); return data.selector; } async readFile(params: StateTransformer.Params<ReadFile>, options?: Partial<StateTransform.Options>) { const data = this.dataState.build().toRoot().apply(ReadFile, params, options); const fileInfo = getFileInfo(params.file); - await this.plugin.runTask(this.dataState.updateTree(data, { revertOnError: true })); + await this.plugin.updateState(data, { revertOnError: true }); return { data: data.selector, fileInfo }; } diff --git a/src/mol-plugin-state/builder/structure.ts b/src/mol-plugin-state/builder/structure.ts index b899dc802bb50c83b8112235a3cd43267508591e..22f6a8ef30ba85af8ca04c4f406a991c373bbe95 100644 --- a/src/mol-plugin-state/builder/structure.ts +++ b/src/mol-plugin-state/builder/structure.ts @@ -29,7 +29,7 @@ export enum StructureBuilderTags { export class StructureBuilder { private get dataState() { - return this.plugin.state.dataState; + return this.plugin.state.data; } private async parseTrajectoryData(data: StateObjectRef<SO.Data.Binary | SO.Data.String>, format: BuiltInTrajectoryFormat | TrajectoryFormatProvider) { @@ -44,7 +44,7 @@ export class StructureBuilder { const trajectory = state.build().to(data) .apply(StateTransforms.Data.ParseBlob, params, { state: { isGhost: true } }) .apply(StateTransforms.Model.TrajectoryFromBlob, void 0, { tags: StructureBuilderTags.Trajectory }); - await this.plugin.runTask(this.dataState.updateTree(trajectory, { revertOnError: true })); + await this.plugin.updateState(trajectory, { revertOnError: true }); return trajectory.selector; } @@ -101,7 +101,7 @@ export class StructureBuilder { const model = state.build().to(trajectory) .apply(StateTransforms.Model.ModelFromTrajectory, params || { modelIndex: 0 }, { tags: StructureBuilderTags.Model, state: initialState }); - await this.plugin.runTask(this.dataState.updateTree(model, { revertOnError: true })); + await this.plugin.updateState(model, { revertOnError: true }); return model.selector; } @@ -109,7 +109,7 @@ export class StructureBuilder { const state = this.dataState; const props = state.build().to(model) .insert(StateTransforms.Model.CustomModelProperties, params, { tags: StructureBuilderTags.ModelProperties, isDecorator: true }); - await this.plugin.runTask(this.dataState.updateTree(props, { revertOnError: true })); + await this.plugin.updateState(props, { revertOnError: true }); return props.selector; } @@ -118,7 +118,7 @@ export class StructureBuilder { const structure = state.build().to(model) .apply(StateTransforms.Model.StructureFromModel, { type: params || { name: 'assembly', params: { } } }, { tags: StructureBuilderTags.Structure, state: initialState }); - await this.plugin.runTask(this.dataState.updateTree(structure, { revertOnError: true })); + await this.plugin.updateState(structure, { revertOnError: true }); return structure.selector; } @@ -126,7 +126,7 @@ export class StructureBuilder { const state = this.dataState; const props = state.build().to(structure) .insert(StateTransforms.Model.CustomStructureProperties, params, { tags: StructureBuilderTags.StructureProperties, isDecorator: true }); - await this.plugin.runTask(this.dataState.updateTree(props, { revertOnError: true })); + await this.plugin.updateState(props, { revertOnError: true }); return props.selector; } @@ -145,13 +145,13 @@ export class StructureBuilder { tags: tags ? [...tags, StructureBuilderTags.Component, keyTag] : [StructureBuilderTags.Component, keyTag] }); - await this.plugin.runTask(this.dataState.updateTree(component)); + await this.plugin.updateState(component); const selector = component.selector; if (!selector.isOk || selector.cell?.obj?.data.elementCount === 0) { const del = state.build().delete(selector.ref); - await this.plugin.runTask(this.dataState.updateTree(del)); + await this.plugin.updateState(del); return; } @@ -205,7 +205,7 @@ export class StructureBuilder { if (!selector.isOk || selector.cell?.obj?.data.elementCount === 0) { const del = state.build().delete(selector.ref); - await this.plugin.runTask(this.dataState.updateTree(del)); + await this.plugin.updateState(del); return; } diff --git a/src/mol-plugin-state/builder/structure/preset.ts b/src/mol-plugin-state/builder/structure/preset.ts index 03d463ebc669691287cfc44bcde3f76356b4ea7f..ff83eaa463462ec2614bc1db0bba4bc8243bbdc2 100644 --- a/src/mol-plugin-state/builder/structure/preset.ts +++ b/src/mol-plugin-state/builder/structure/preset.ts @@ -46,7 +46,7 @@ const auto = StructureRepresentationProvider({ }); function reprBuilder(plugin: PluginContext, params: CommonStructureRepresentationParams) { - const update = plugin.state.dataState.build(); + const update = plugin.state.data.build(); const builder = plugin.builders.structure.representation; const typeParams = { quality: plugin.managers.structure.component.state.options.visualQuality, diff --git a/src/mol-plugin-state/builder/structure/representation.ts b/src/mol-plugin-state/builder/structure/representation.ts index 10fbf0113a16c4feb3005925ac6d322778be79ea..b649d7cbd0fae3664286443167cf82d92fa0638a 100644 --- a/src/mol-plugin-state/builder/structure/representation.ts +++ b/src/mol-plugin-state/builder/structure/representation.ts @@ -23,7 +23,7 @@ export type StructureRepresentationProviderRef = keyof PresetStructureReprentati export class StructureRepresentationBuilder { private _providers: StructureRepresentationProvider[] = []; private providerMap: Map<string, StructureRepresentationProvider> = new Map(); - private get dataState() { return this.plugin.state.dataState; } + private get dataState() { return this.plugin.state.data; } readonly defaultProvider = PresetStructureReprentations.auto; @@ -80,7 +80,7 @@ export class StructureRepresentationBuilder { const provider = this.resolveProvider(providerRef); if (!provider) return; - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; const cell = StateObjectRef.resolveAndCheck(state, parent); if (!cell) { if (!isProductionMode) console.warn(`Applying structure repr. provider to bad cell.`); @@ -107,7 +107,7 @@ export class StructureRepresentationBuilder { .to(structure) .apply(StructureRepresentation3D, params, { tags: RepresentationProviderTags.Representation }); - await this.plugin.runTask(this.dataState.updateTree(repr)); + await this.plugin.updateState(repr); return repr.selector; } diff --git a/src/mol-plugin-state/formats/trajectory.ts b/src/mol-plugin-state/formats/trajectory.ts index 873e7defeaaddaf150298175b8e36952804ab4bc..80afe9df9c14cf2502f7e23c57d371451247bfd2 100644 --- a/src/mol-plugin-state/formats/trajectory.ts +++ b/src/mol-plugin-state/formats/trajectory.ts @@ -31,21 +31,21 @@ export const MmcifProvider: TrajectoryFormatProvider = { return false }, parse: async (plugin, data, params) => { - const state = plugin.state.dataState; + const state = plugin.state.data; const trajectory = state.build().to(data) .apply(StateTransforms.Data.ParseCif, void 0, { state: { isGhost: true } }) .apply(StateTransforms.Model.TrajectoryFromMmCif, void 0, { tags: params?.trajectoryTags }) - await plugin.runTask(state.updateTree(trajectory, { revertOnError: true })); + await plugin.updateState(trajectory, { revertOnError: true }); return { trajectory: trajectory.selector }; } } function directTrajectory(transformer: StateTransformer<PluginStateObject.Data.String | PluginStateObject.Data.Binary, PluginStateObject.Molecule.Trajectory>): TrajectoryFormatProvider['parse'] { return async (plugin, data, params) => { - const state = plugin.state.dataState; + const state = plugin.state.data; const trajectory = state.build().to(data) .apply(transformer, void 0, { tags: params?.trajectoryTags }) - await plugin.runTask(state.updateTree(trajectory, { revertOnError: true })); + await plugin.updateState(trajectory, { revertOnError: true }); return { trajectory: trajectory.selector }; } } diff --git a/src/mol-plugin-state/helpers/structure-overpaint.ts b/src/mol-plugin-state/helpers/structure-overpaint.ts index 81f2fca1524a122351fb80ece441abb8aea67490..e66fa816777d1bdb24b7bb7dbb40f962f4ce899e 100644 --- a/src/mol-plugin-state/helpers/structure-overpaint.ts +++ b/src/mol-plugin-state/helpers/structure-overpaint.ts @@ -56,7 +56,7 @@ export async function clearStructureOverpaint(plugin: PluginContext, components: } async function eachRepr(plugin: PluginContext, components: StructureComponentRef[], callback: OverpaintEachReprCallback) { - const state = plugin.state.dataState; + const state = plugin.state.data; const update = state.build(); for (const c of components) { for (const r of c.representations) { @@ -65,7 +65,7 @@ async function eachRepr(plugin: PluginContext, components: StructureComponentRef } } - await plugin.runTask(state.updateTree(update, { doNotUpdateCurrent: true })); + await plugin.updateState(update, { doNotUpdateCurrent: true }); } /** filter overpaint layers for given structure */ diff --git a/src/mol-plugin-state/manager/structure/component.ts b/src/mol-plugin-state/manager/structure/component.ts index 413a3a4e722a57ab6c67eb2af871f61651875024..2873e900f1e4d6ffbaa37ec86a9ff8e5267b407d 100644 --- a/src/mol-plugin-state/manager/structure/component.ts +++ b/src/mol-plugin-state/manager/structure/component.ts @@ -62,7 +62,7 @@ class StructureComponentManager extends PluginComponent<StructureComponentManage } return this.plugin.dataTransaction(async () => { - await this.plugin.runTask(this.dataState.updateTree(update)); + await this.plugin.updateState(update); if (interactionChanged) await this.updateInterationProps(); }); } @@ -96,7 +96,7 @@ class StructureComponentManager extends PluginComponent<StructureComponentManage arraySetAdd(old.autoAttach, InteractionsProvider.descriptor.name); old.properties[InteractionsProvider.descriptor.name] = this.state.options.interactions; }); - await this.plugin.runTask(this.dataState.updateTree(b)); + await this.plugin.updateState(b); } else { const pd = this.plugin.customStructureProperties.getParams(s.cell.obj?.data); const params = PD.getDefaultValues(pd); @@ -196,7 +196,7 @@ class StructureComponentManager extends PluginComponent<StructureComponentManage update.to(repr.cell).update(params); } - return this.plugin.runTask(this.dataState.updateTree(update, { canUndo: 'Update Representation' })); + return this.plugin.updateState(update, { canUndo: 'Update Representation' }); } updateRepresentationsTheme<C extends ColorTheme.BuiltIn, S extends SizeTheme.BuiltIn>(components: ReadonlyArray<StructureComponentRef>, params: StructureComponentManager.UpdateThemeParams<C, S>): Promise<any> { @@ -220,7 +220,7 @@ class StructureComponentManager extends PluginComponent<StructureComponentManage } } - return this.plugin.runTask(this.dataState.updateTree(update, { canUndo: 'Update Theme' })); + return this.plugin.updateState(update, { canUndo: 'Update Theme' }); } addRepresentation(components: ReadonlyArray<StructureComponentRef>, type: string) { @@ -304,7 +304,7 @@ class StructureComponentManager extends PluginComponent<StructureComponentManage } private get dataState() { - return this.plugin.state.dataState; + return this.plugin.state.data; } private clearComponents(structures: ReadonlyArray<StructureRef>) { @@ -318,7 +318,7 @@ class StructureComponentManager extends PluginComponent<StructureComponentManage if (s.currentFocus.surroundings) deletes.delete(s.currentFocus.surroundings.cell.transform.ref); } } - return this.plugin.runTask(this.dataState.updateTree(deletes, { canUndo: 'Clear Selections' })); + return this.plugin.updateState(deletes, { canUndo: 'Clear Selections' }); } constructor(public plugin: PluginContext) { diff --git a/src/mol-plugin-state/manager/structure/hierarchy.ts b/src/mol-plugin-state/manager/structure/hierarchy.ts index 6068de6855968813afb7c294a8733ea27fbf999e..3be0b580b79de936ece7e8ea29dbfa7945be763e 100644 --- a/src/mol-plugin-state/manager/structure/hierarchy.ts +++ b/src/mol-plugin-state/manager/structure/hierarchy.ts @@ -30,7 +30,7 @@ export class StructureHierarchyManager extends PluginComponent<StructureHierarch } private get dataState() { - return this.plugin.state.dataState; + return this.plugin.state.data; } private _currentComponentGroups: ReturnType<typeof StructureHierarchyManager['getComponentGroups']> | undefined = void 0; @@ -81,7 +81,7 @@ export class StructureHierarchyManager extends PluginComponent<StructureHierarch } private sync() { - const update = buildStructureHierarchy(this.plugin.state.dataState, this.state.hierarchy); + const update = buildStructureHierarchy(this.plugin.state.data, this.state.hierarchy); if (update.added.length === 0 && update.updated.length === 0 && update.removed.length === 0) { return; } @@ -129,9 +129,9 @@ export class StructureHierarchyManager extends PluginComponent<StructureHierarch remove(refs: HierarchyRef[], canUndo?: boolean) { if (refs.length === 0) return; - const deletes = this.plugin.state.dataState.build(); + const deletes = this.plugin.state.data.build(); for (const r of refs) deletes.delete(r.cell.transform.ref); - return this.plugin.runTask(this.plugin.state.dataState.updateTree(deletes, { canUndo: canUndo ? 'Remove' : false })); + return this.plugin.updateState(deletes, { canUndo: canUndo ? 'Remove' : false }); } createAllModels(trajectory: TrajectoryRef) { @@ -159,7 +159,7 @@ export class StructureHierarchyManager extends PluginComponent<StructureHierarch for (const m of trajectory.models) { builder.delete(m.cell); } - return this.plugin.runTask(this.dataState.updateTree(builder)); + return this.plugin.updateState(builder); } constructor(private plugin: PluginContext) { @@ -168,7 +168,7 @@ export class StructureHierarchyManager extends PluginComponent<StructureHierarch current: { trajectories: [], models: [], structures: [] } }); - plugin.state.dataState.events.changed.subscribe(e => { + plugin.state.data.events.changed.subscribe(e => { if (e.inTransaction || plugin.behaviors.state.isAnimating.value) return; this.sync(); }); diff --git a/src/mol-plugin-state/manager/structure/measurement.ts b/src/mol-plugin-state/manager/structure/measurement.ts index ebe623c43e0a49c55acf7274d45fa2931c4d8764..5256986393976fde068fbbf54977fc3d0362f723 100644 --- a/src/mol-plugin-state/manager/structure/measurement.ts +++ b/src/mol-plugin-state/manager/structure/measurement.ts @@ -47,9 +47,9 @@ class StructureMeasurementManager extends PluginComponent<StructureMeasurementMa } private getGroup() { - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; const groupRef = StateSelection.findTagInSubtree(state.tree, StateTransform.RootRef, MeasurementGroupTag); - const builder = this.plugin.state.dataState.build(); + const builder = this.plugin.state.data.build(); if (groupRef) return builder.to(groupRef); return builder.toRoot().group(StateTransforms.Misc.CreateGroup, { label: `Measurements` }, { tags: MeasurementGroupTag }); @@ -58,7 +58,7 @@ class StructureMeasurementManager extends PluginComponent<StructureMeasurementMa async setOptions(options: StructureMeasurementOptions) { if (this.updateState({ options })) this.stateUpdated(); - const update = this.plugin.state.dataState.build(); + const update = this.plugin.state.data.build(); for (const cell of this.state.distances) { update.to(cell).update((old: any) => { old.unitLabel = options.distanceUnitLabel; @@ -77,7 +77,7 @@ class StructureMeasurementManager extends PluginComponent<StructureMeasurementMa if (update.editInfo.count === 0) return; - await PluginCommands.State.Update(this.plugin, { state: this.plugin.state.dataState, tree: update, options: { doNotLogTiming: true } }); + await PluginCommands.State.Update(this.plugin, { state: this.plugin.state.data, tree: update, options: { doNotLogTiming: true } }); } async addDistance(a: StructureElement.Loci, b: StructureElement.Loci) { @@ -104,7 +104,7 @@ class StructureMeasurementManager extends PluginComponent<StructureMeasurementMa textColor: this.state.options.textColor }) - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; await PluginCommands.State.Update(this.plugin, { state, tree: update, options: { doNotLogTiming: true } }); } @@ -134,7 +134,7 @@ class StructureMeasurementManager extends PluginComponent<StructureMeasurementMa textColor: this.state.options.textColor }) - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; await PluginCommands.State.Update(this.plugin, { state, tree: update, options: { doNotLogTiming: true } }); } @@ -167,7 +167,7 @@ class StructureMeasurementManager extends PluginComponent<StructureMeasurementMa textColor: this.state.options.textColor }) - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; await PluginCommands.State.Update(this.plugin, { state, tree: update, options: { doNotLogTiming: true } }); } @@ -191,7 +191,7 @@ class StructureMeasurementManager extends PluginComponent<StructureMeasurementMa textColor: this.state.options.textColor }) - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; await PluginCommands.State.Update(this.plugin, { state, tree: update, options: { doNotLogTiming: true } }); } @@ -213,13 +213,13 @@ class StructureMeasurementManager extends PluginComponent<StructureMeasurementMa }, { dependsOn }) .apply(StateTransforms.Representation.StructureSelectionsOrientation3D) - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; await PluginCommands.State.Update(this.plugin, { state, tree: update, options: { doNotLogTiming: true } }); } private _empty: any[] = []; private getTransforms<T extends StateTransformer<A, B, any>, A extends PluginStateObject.Molecule.Structure.Selections, B extends StateObject>(transformer: T) { - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; const groupRef = StateSelection.findTagInSubtree(state.tree, StateTransform.RootRef, MeasurementGroupTag); const ret = groupRef ? state.select(StateSelection.Generators.ofTransformer(transformer, groupRef)) : this._empty; if (ret.length === 0) return this._empty; @@ -240,7 +240,7 @@ class StructureMeasurementManager extends PluginComponent<StructureMeasurementMa constructor(private plugin: PluginContext) { super({ labels: [], distances: [], angles: [], dihedrals: [], orientations: [], options: DefaultStructureMeasurementOptions }); - plugin.state.dataState.events.changed.subscribe(e => { + plugin.state.data.events.changed.subscribe(e => { if (e.inTransaction || plugin.behaviors.state.isAnimating.value) return; this.sync(); }); diff --git a/src/mol-plugin-state/manager/structure/selection.ts b/src/mol-plugin-state/manager/structure/selection.ts index e7c754c9ccc1e8a5b246ebe71759d362d11974c9..099e487754d1a565a4776249bb35e5568dd89511 100644 --- a/src/mol-plugin-state/manager/structure/selection.ts +++ b/src/mol-plugin-state/manager/structure/selection.ts @@ -420,7 +420,7 @@ export class StructureSelectionManager extends PluginComponent<StructureSelectio } fromSelections(ref: StateObjectRef<PluginStateObject.Molecule.Structure.Selections>) { - const cell = StateObjectRef.resolveAndCheck(this.plugin.state.dataState, ref); + const cell = StateObjectRef.resolveAndCheck(this.plugin.state.data, ref); if (!cell || !cell.obj) return; if (!PluginStateObject.Molecule.Structure.Selections.is(cell.obj)) { @@ -437,8 +437,8 @@ export class StructureSelectionManager extends PluginComponent<StructureSelectio constructor(private plugin: PluginContext) { super({ entries: new Map(), additionsHistory: [], stats: SelectionStats() }); - plugin.state.dataState.events.object.removed.subscribe(e => this.onRemove(e.ref)); - plugin.state.dataState.events.object.updated.subscribe(e => this.onUpdate(e.ref, e.oldObj, e.obj)); + plugin.state.data.events.object.removed.subscribe(e => this.onRemove(e.ref)); + plugin.state.data.events.object.updated.subscribe(e => this.onUpdate(e.ref, e.oldObj, e.obj)); } } diff --git a/src/mol-plugin-ui/controls.tsx b/src/mol-plugin-ui/controls.tsx index 4ad21d2d689c395c52b93102362d715e3911b213..9c1f88fe40d9090f8591d8a37f12ac87a16deff6 100644 --- a/src/mol-plugin-ui/controls.tsx +++ b/src/mol-plugin-ui/controls.tsx @@ -26,7 +26,7 @@ export class TrajectoryViewportControls extends PluginUIComponent<{}, { show: bo state = { show: false, label: '' } private update = () => { - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; const models = state.selectQ(q => q.ofTransformer(StateTransforms.Model.ModelFromTrajectory)); @@ -62,22 +62,22 @@ export class TrajectoryViewportControls extends PluginUIComponent<{}, { show: bo } componentDidMount() { - this.subscribe(this.plugin.state.dataState.events.changed, this.update); + this.subscribe(this.plugin.state.data.events.changed, this.update); this.subscribe(this.plugin.behaviors.state.isAnimating, this.update); } reset = () => PluginCommands.State.ApplyAction(this.plugin, { - state: this.plugin.state.dataState, + state: this.plugin.state.data, action: UpdateTrajectory.create({ action: 'reset' }) }); prev = () => PluginCommands.State.ApplyAction(this.plugin, { - state: this.plugin.state.dataState, + state: this.plugin.state.data, action: UpdateTrajectory.create({ action: 'advance', by: -1 }) }); next = () => PluginCommands.State.ApplyAction(this.plugin, { - state: this.plugin.state.dataState, + state: this.plugin.state.data, action: UpdateTrajectory.create({ action: 'advance', by: 1 }) }); @@ -210,8 +210,8 @@ export class AnimationViewportControls extends PluginUIComponent<{}, { isEmpty: else this.setState({ isPlaying: false }); }); this.subscribe(this.plugin.behaviors.state.isUpdating, isUpdating => { - if (isUpdating) this.setState({ isUpdating: true, isExpanded: false, isEmpty: this.plugin.state.dataState.tree.transforms.size < 2 }); - else this.setState({ isUpdating: false, isEmpty: this.plugin.state.dataState.tree.transforms.size < 2 }); + if (isUpdating) this.setState({ isUpdating: true, isExpanded: false, isEmpty: this.plugin.state.data.tree.transforms.size < 2 }); + else this.setState({ isUpdating: false, isEmpty: this.plugin.state.data.tree.transforms.size < 2 }); }); this.subscribe(this.plugin.behaviors.state.isAnimating, isAnimating => { if (isAnimating) this.setState({ isAnimating: true, isExpanded: false }); diff --git a/src/mol-plugin-ui/left-panel.tsx b/src/mol-plugin-ui/left-panel.tsx index f9488fb1854d4e9797aef136e838f7ecff6b45c6..b77514a2f4fb028bd9af29c4e327298e3e2dd3b0 100644 --- a/src/mol-plugin-ui/left-panel.tsx +++ b/src/mol-plugin-ui/left-panel.tsx @@ -30,7 +30,7 @@ export class LeftPanelControls extends PluginUIComponent<{}, { tab: LeftPanelTab } }); - this.subscribe(this.plugin.state.dataState.events.changed, ({ state }) => { + this.subscribe(this.plugin.state.data.events.changed, ({ state }) => { if (this.state.tab !== 'data') return; if (state.cells.size === 1) this.set('root'); }); @@ -58,12 +58,12 @@ export class LeftPanelControls extends PluginUIComponent<{}, { tab: LeftPanelTab 'none': <></>, 'root': <> <SectionHeader icon='home' title='Home' /> - <StateObjectActions state={this.plugin.state.dataState} nodeRef={StateTransform.RootRef} hideHeader={true} initiallyCollapsed={true} alwaysExpandFirst={true} /> + <StateObjectActions state={this.plugin.state.data} nodeRef={StateTransform.RootRef} hideHeader={true} initiallyCollapsed={true} alwaysExpandFirst={true} /> {this.plugin.spec.components?.remoteState !== 'none' && <RemoteStateSnapshots listOnly /> } </>, 'data': <> <SectionHeader icon='flow-tree' title={<><RemoveAllButton /> State Tree</>} /> - <StateTree state={this.plugin.state.dataState} /> + <StateTree state={this.plugin.state.data} /> </>, 'states': <StateSnapshots />, 'settings': <> @@ -111,7 +111,7 @@ class DataIcon extends PluginUIComponent<{ set: (tab: LeftPanelTabName) => void else this.forceUpdate(); }); - this.subscribe(this.plugin.state.dataState.events.changed, state => { + this.subscribe(this.plugin.state.data.events.changed, state => { if (this.tab !== 'data') this.setState({ changed: true }); }); } @@ -144,7 +144,7 @@ class FullSettings extends PluginUIComponent { <ParameterControls params={Canvas3DParams} values={this.plugin.canvas3d.props} onChange={this.setSettings} /> </>} <SectionHeader title='Behavior' /> - <StateTree state={this.plugin.state.behaviorState} /> + <StateTree state={this.plugin.state.behaviors} /> </> } } @@ -162,11 +162,11 @@ export class RemoveAllButton extends PluginUIComponent<{ }> { remove = (e: React.MouseEvent<HTMLElement>) => { e.preventDefault(); - PluginCommands.State.RemoveObject(this.plugin, { state: this.plugin.state.dataState, ref: StateTransform.RootRef }); + PluginCommands.State.RemoveObject(this.plugin, { state: this.plugin.state.data, ref: StateTransform.RootRef }); } render() { - const count = this.plugin.state.dataState.tree.children.get(StateTransform.RootRef).size; + const count = this.plugin.state.data.tree.children.get(StateTransform.RootRef).size; if (count < 2) return null; return <IconButton icon='remove' onClick={this.remove} title={'Remove All'} style={{ display: 'inline-block' }} />; } diff --git a/src/mol-plugin-ui/sequence.tsx b/src/mol-plugin-ui/sequence.tsx index c02d424499444b6d0ae22aa6ea57b26aeff20f38..c965912a00d0d8361b4783f31c650e99299d1ac7 100644 --- a/src/mol-plugin-ui/sequence.tsx +++ b/src/mol-plugin-ui/sequence.tsx @@ -194,7 +194,7 @@ export class SequenceView extends PluginUIComponent<{ }, SequenceViewState> { state = { structure: Structure.Empty, structureRef: '', modelEntityId: '', chainGroupId: -1, operatorKey: '' } componentDidMount() { - if (this.plugin.state.dataState.select(StateSelection.Generators.rootsOfType(PSO.Molecule.Structure)).length > 0) this.setState(this.getInitialState()) + if (this.plugin.state.data.select(StateSelection.Generators.rootsOfType(PSO.Molecule.Structure)).length > 0) this.setState(this.getInitialState()) this.subscribe(this.plugin.events.state.object.updated, ({ ref, obj }) => { if (ref === this.state.structureRef && obj && obj.type === PSO.Molecule.Structure.type && obj.data !== this.state.structure) { @@ -216,7 +216,7 @@ export class SequenceView extends PluginUIComponent<{ }, SequenceViewState> { } private getStructure(ref: string) { - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; const cell = state.select(ref)[0]; if (!ref || !cell || !cell.obj) return Structure.Empty; return (cell.obj as PSO.Molecule.Structure).data; @@ -227,7 +227,7 @@ export class SequenceView extends PluginUIComponent<{ }, SequenceViewState> { } private getInitialState(): SequenceViewState { - const structureRef = getStructureOptions(this.plugin.state.dataState)[0][0] + const structureRef = getStructureOptions(this.plugin.state.data)[0][0] const structure = this.getStructure(structureRef) let modelEntityId = getModelEntityOptions(structure)[0][0] let chainGroupId = getChainOptions(structure, modelEntityId)[0][0] @@ -242,7 +242,7 @@ export class SequenceView extends PluginUIComponent<{ }, SequenceViewState> { private get params() { const { structure, modelEntityId, chainGroupId } = this.state - const structureOptions = getStructureOptions(this.plugin.state.dataState) + const structureOptions = getStructureOptions(this.plugin.state.data) const entityOptions = getModelEntityOptions(structure) const chainOptions = getChainOptions(structure, modelEntityId) const operatorOptions = getOperatorOptions(structure, modelEntityId, chainGroupId) diff --git a/src/mol-plugin-ui/state/tree.tsx b/src/mol-plugin-ui/state/tree.tsx index 04e0265d96ddb5c77267b917a77a0aefe1adb94a..af127b8449b5ad28bf332408416c649a19c82462 100644 --- a/src/mol-plugin-ui/state/tree.tsx +++ b/src/mol-plugin-ui/state/tree.tsx @@ -199,23 +199,16 @@ class StateTreeNodeLabel extends PluginUIComponent< highlight = (e: React.MouseEvent<HTMLElement>) => { e.preventDefault(); - PluginCommands.State.Highlight(this.plugin, { state: this.props.cell.parent, ref: this.ref }); + PluginCommands.Interactivity.Object.Highlight(this.plugin, { state: this.props.cell.parent, ref: this.ref }); e.currentTarget.blur(); } clearHighlight = (e: React.MouseEvent<HTMLElement>) => { e.preventDefault(); - PluginCommands.State.ClearHighlights(this.plugin); + PluginCommands.Interactivity.ClearHighlights(this.plugin); e.currentTarget.blur(); } - // private toggleUpdaterObs = new Subject(); - // toggleUpdater = (e: React.MouseEvent<HTMLAnchorElement>) => { - // e.preventDefault(); - // e.currentTarget.blur(); - // this.toggleUpdaterObs.next(); - // } - render() { const cell = this.props.cell; const n = cell.transform; diff --git a/src/mol-plugin-ui/state/update-transform.tsx b/src/mol-plugin-ui/state/update-transform.tsx index da3756ef46dd305e6c0b11eb00c3bc95b6e7def5..77af6b777f873a04fbe89ff338e6e1cd65ce3f9f 100644 --- a/src/mol-plugin-ui/state/update-transform.tsx +++ b/src/mol-plugin-ui/state/update-transform.tsx @@ -31,7 +31,7 @@ namespace UpdateTransformControl { class UpdateTransformControl extends TransformControlBase<UpdateTransformControl.Props, UpdateTransformControl.ComponentState> { applyAction() { if (this.props.customUpdate) return this.props.customUpdate(this.state.params); - return this.plugin.updateTransform(this.props.state, this.props.transform.ref, this.state.params); + return this.plugin.state.updateTransform(this.props.state, this.props.transform.ref, this.state.params); } getInfo() { return this._getInfo(this.props.transform); } getTransformerId() { return this.props.transform.transformer.id; } @@ -103,13 +103,13 @@ class UpdateTransformControl extends TransformControlBase<UpdateTransformControl class TransformUpdaterControl extends PluginUIComponent<{ nodeRef: string, initiallyCollapsed?: boolean, header?: StateTransformer.Definition['display'] }> { componentDidMount() { this.subscribe(this.plugin.events.state.object.updated, ({ ref, state }) => { - if (this.props.nodeRef !== ref || this.plugin.state.dataState !== state) return; + if (this.props.nodeRef !== ref || this.plugin.state.data !== state) return; this.forceUpdate(); }); } render() { - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; const ref = this.props.nodeRef; const cell = state.cells.get(ref)!; diff --git a/src/mol-plugin-ui/structure/components.tsx b/src/mol-plugin-ui/structure/components.tsx index 2c0b413516256cdaa4030933da853f362aee4c53..89859a42b244185bb9948dff78382731b8742fd2 100644 --- a/src/mol-plugin-ui/structure/components.tsx +++ b/src/mol-plugin-ui/structure/components.tsx @@ -62,7 +62,7 @@ class ComponentEditorControls extends PurePluginUIComponent<{}, ComponentEditorC this.subscribe(this.plugin.behaviors.state.isBusy, v => { this.setState({ isBusy: v, action: this.state.action !== 'options' ? void 0 : 'options' }) }); - this.subscribe(this.plugin.state.dataState.events.historyUpdated, ({ state }) => { + this.subscribe(this.plugin.state.data.events.historyUpdated, ({ state }) => { this.setState({ canUndo: state.canUndo }); }); } @@ -104,13 +104,13 @@ class ComponentEditorControls extends PurePluginUIComponent<{}, ComponentEditorC } undo = () => { - const task = this.plugin.state.dataState.undo(); + const task = this.plugin.state.data.undo(); if (task) this.plugin.runTask(task); } render() { const undoTitle = this.state.canUndo - ? `Undo ${this.plugin.state.dataState.latestUndoLabel}` + ? `Undo ${this.plugin.state.data.latestUndoLabel}` : 'Some mistakes of the past can be undone.'; return <> <div className='msp-control-row msp-select-row'> @@ -316,12 +316,12 @@ class StructureComponentGroup extends PurePluginUIComponent<{ group: StructureCo highlight = (e: React.MouseEvent<HTMLElement>) => { e.preventDefault(); - PluginCommands.State.Highlight(this.plugin, { state: this.props.group[0].cell.parent, ref: this.props.group.map(c => c.cell.transform.ref) }); + PluginCommands.Interactivity.Object.Highlight(this.plugin, { state: this.props.group[0].cell.parent, ref: this.props.group.map(c => c.cell.transform.ref) }); } clearHighlight = (e: React.MouseEvent<HTMLElement>) => { e.preventDefault(); - PluginCommands.State.ClearHighlights(this.plugin); + PluginCommands.Interactivity.ClearHighlights(this.plugin); } focus = () => { diff --git a/src/mol-plugin-ui/viewport/help.tsx b/src/mol-plugin-ui/viewport/help.tsx index 65bc947521b9e74c8309de3928e4a6d597fb3275..ea6997cf97215868df1de15d35adf066bfc5fcf1 100644 --- a/src/mol-plugin-ui/viewport/help.tsx +++ b/src/mol-plugin-ui/viewport/help.tsx @@ -95,7 +95,7 @@ export class HelpContent extends PluginUIComponent { } private getTriggerFor(transformer: StateTransformer, name: string) { - const state = this.plugin.state.behaviorState + const state = this.plugin.state.behaviors const selections = state.select(StateSelection.Generators.ofTransformer(transformer)) const params = selections.length === 1 ? selections[0].params : undefined const bindings = params ? params.values.bindings : {} diff --git a/src/mol-plugin-ui/viewport/screenshot.tsx b/src/mol-plugin-ui/viewport/screenshot.tsx index 94198156f97a27a01c2522c57fdf59047a6c9207..6127b348c2ec06d90aeef3c5dab0efddace55f4a 100644 --- a/src/mol-plugin-ui/viewport/screenshot.tsx +++ b/src/mol-plugin-ui/viewport/screenshot.tsx @@ -93,7 +93,7 @@ export class DownloadScreenshotControls extends PluginUIComponent<{ close: () => this.updateQueue.next(); }) - this.subscribe(this.plugin.state.dataState.events.isUpdating, v => { + this.subscribe(this.plugin.state.data.events.isUpdating, v => { this.setState({ isDisabled: v }) if (!v) this.updateQueue.next(); }) diff --git a/src/mol-plugin-ui/viewport/simple-settings.tsx b/src/mol-plugin-ui/viewport/simple-settings.tsx index 136b3b4c7134cde1fa8038fd241d3b809994bd83..449f0ce8295f2bdbe544d0ece728829f42a4251d 100644 --- a/src/mol-plugin-ui/viewport/simple-settings.tsx +++ b/src/mol-plugin-ui/viewport/simple-settings.tsx @@ -108,7 +108,7 @@ const SimpleSettingsMapping = ParamMapping({ await PluginCommands.Layout.Update(ctx, { state }); if (hideLeft) { - PluginCommands.State.SetCurrentObject(ctx, { state: ctx.state.dataState, ref: StateTransform.RootRef }); + PluginCommands.State.SetCurrentObject(ctx, { state: ctx.state.data, ref: StateTransform.RootRef }); } } }) \ No newline at end of file diff --git a/src/mol-plugin/behavior/dynamic/custom-props/computed/interactions.ts b/src/mol-plugin/behavior/dynamic/custom-props/computed/interactions.ts index 762517151fe5592ed3a8c9fa5cf0ffb5ab707d8a..c52d262b4cfbbab2735d9e9ccf12bfa8940bbac8 100644 --- a/src/mol-plugin/behavior/dynamic/custom-props/computed/interactions.ts +++ b/src/mol-plugin/behavior/dynamic/custom-props/computed/interactions.ts @@ -29,7 +29,7 @@ export const Interactions = PluginBehavior.create<{ autoAttach: boolean, showToo const structures: Structure[] = [] const root = this.ctx.helpers.substructureParent.get(structure) if (root) { - const state = this.ctx.state.dataState + const state = this.ctx.state.data const selections = state.select(StateSelection.Generators.ofType(PluginStateObject.Molecule.Structure, root.transform.ref)); for (const s of selections) { if (s.obj) arraySetAdd(structures, s.obj.data) diff --git a/src/mol-plugin/behavior/dynamic/custom-props/computed/valence-model.ts b/src/mol-plugin/behavior/dynamic/custom-props/computed/valence-model.ts index 29c996389de82ef4c7cddbf4b5c2f2091068fed3..b04e3db4b2f158172db0925ec142b7c26a9546b8 100644 --- a/src/mol-plugin/behavior/dynamic/custom-props/computed/valence-model.ts +++ b/src/mol-plugin/behavior/dynamic/custom-props/computed/valence-model.ts @@ -26,7 +26,7 @@ export const ValenceModel = PluginBehavior.create<{ autoAttach: boolean, showToo const structures: Structure[] = [] const root = this.ctx.helpers.substructureParent.get(structure) if (root) { - const state = this.ctx.state.dataState + const state = this.ctx.state.data const selections = state.select(StateSelection.Generators.ofType(PluginStateObject.Molecule.Structure, root.transform.ref)); for (const s of selections) { if (s.obj) arraySetAdd(structures, s.obj.data) diff --git a/src/mol-plugin/behavior/dynamic/custom-props/rcsb/assembly-symmetry.ts b/src/mol-plugin/behavior/dynamic/custom-props/rcsb/assembly-symmetry.ts index 4285c0a729c66a84c93e692a375b33d022b24044..9ece08b612b330be8ac50b5b990bc8c9fa964b08 100644 --- a/src/mol-plugin/behavior/dynamic/custom-props/rcsb/assembly-symmetry.ts +++ b/src/mol-plugin/behavior/dynamic/custom-props/rcsb/assembly-symmetry.ts @@ -27,7 +27,7 @@ export const RCSBAssemblySymmetry = PluginBehavior.create<{ autoAttach: boolean private provider = AssemblySymmetryProvider register(): void { - this.ctx.state.dataState.actions.add(InitAssemblySymmetry3D) + this.ctx.state.data.actions.add(InitAssemblySymmetry3D) this.ctx.customStructureProperties.register(this.provider, this.params.autoAttach); this.ctx.representation.structure.themes.colorThemeRegistry.add(AssemblySymmetryClusterColorThemeProvider) } @@ -40,7 +40,7 @@ export const RCSBAssemblySymmetry = PluginBehavior.create<{ autoAttach: boolean } unregister() { - this.ctx.state.dataState.actions.remove(InitAssemblySymmetry3D) + this.ctx.state.data.actions.remove(InitAssemblySymmetry3D) this.ctx.customStructureProperties.unregister(this.provider.descriptor.name); this.ctx.representation.structure.themes.colorThemeRegistry.remove(AssemblySymmetryClusterColorThemeProvider) } diff --git a/src/mol-plugin/behavior/dynamic/representation.ts b/src/mol-plugin/behavior/dynamic/representation.ts index e81dbcfb7792ea9791c75ba7501a13993fc32d50..7145cc565e679b06f464edd870176f718406e7b4 100644 --- a/src/mol-plugin/behavior/dynamic/representation.ts +++ b/src/mol-plugin/behavior/dynamic/representation.ts @@ -97,7 +97,7 @@ export const SelectLoci = PluginBehavior.create({ this.ctx.canvas3d.mark({ loci: interactionLoci.loci }, action) } private applySelectMark(ref: string, clear?: boolean) { - const cell = this.ctx.state.dataState.cells.get(ref) + const cell = this.ctx.state.data.cells.get(ref) if (cell && SO.isRepresentation3D(cell.obj)) { this.spine.current = cell const so = this.spine.getRootOfType(SO.Molecule.Structure) @@ -148,9 +148,9 @@ export const SelectLoci = PluginBehavior.create({ // re-apply select-mark to all representation of an updated structure this.subscribeObservable(this.ctx.events.state.object.updated, ({ ref }) => { - const cell = this.ctx.state.dataState.cells.get(ref) + const cell = this.ctx.state.data.cells.get(ref) if (cell && SO.Molecule.Structure.is(cell.obj)) { - const reprs = this.ctx.state.dataState.select(StateSelection.Generators.ofType(SO.Molecule.Structure.Representation3D, ref)) + const reprs = this.ctx.state.data.select(StateSelection.Generators.ofType(SO.Molecule.Structure.Representation3D, ref)) for (const repr of reprs) this.applySelectMark(repr.transform.ref, true) } }); @@ -160,7 +160,7 @@ export const SelectLoci = PluginBehavior.create({ } constructor(ctx: PluginContext, params: SelectLociProps) { super(ctx, params) - this.spine = new StateTreeSpine.Impl(ctx.state.dataState.cells) + this.spine = new StateTreeSpine.Impl(ctx.state.data.cells) } }, params: () => SelectLociParams, diff --git a/src/mol-plugin/behavior/dynamic/selection/structure-representation-interaction.ts b/src/mol-plugin/behavior/dynamic/selection/structure-representation-interaction.ts index 097bab2ac2f2670e708ea6cfbdbd32bf8cd07876..448c7bf1e2044173e7d251f76c47b01329b71319 100644 --- a/src/mol-plugin/behavior/dynamic/selection/structure-representation-interaction.ts +++ b/src/mol-plugin/behavior/dynamic/selection/structure-representation-interaction.ts @@ -75,7 +75,7 @@ const TagSet: Set<StructureRepresentationInteractionTags> = new Set([StructureRe export class StructureRepresentationInteractionBehavior extends PluginBehavior.WithSubscribers<StructureRepresentationInteractionProps> { private ensureShape(cell: StateObjectCell<PluginStateObject.Molecule.Structure>) { - const state = this.plugin.state.dataState, tree = state.tree; + const state = this.plugin.state.data, tree = state.tree; const builder = state.build(); const refs = StateSelection.findUniqueTagsInSubtree(tree, cell.transform.ref, TagSet); @@ -123,7 +123,7 @@ export class StructureRepresentationInteractionBehavior extends PluginBehavior.W } private clear(root: StateTransform.Ref) { - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; const groups = state.select(StateSelection.Generators.byRef(root).subtree().withTag(StructureRepresentationInteractionTags.Group)); if (groups.length === 0) return; @@ -215,7 +215,7 @@ export class StructureRepresentationInteractionBehavior extends PluginBehavior.W async update(params: StructureRepresentationInteractionProps) { this.params = params; - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; const builder = state.build(); const all = StateSelection.Generators.root.subtree(); diff --git a/src/mol-plugin/behavior/dynamic/volume-streaming/behavior.ts b/src/mol-plugin/behavior/dynamic/volume-streaming/behavior.ts index 2723efd6555a0bc173485c1b31e29933e4aa9c4e..359d4e1425386fa72f9e3270565d51389bc4a347 100644 --- a/src/mol-plugin/behavior/dynamic/volume-streaming/behavior.ts +++ b/src/mol-plugin/behavior/dynamic/volume-streaming/behavior.ts @@ -202,7 +202,7 @@ export namespace VolumeStreaming { private updateDynamicBox(box: Box3D) { if (this.params.entry.params.view.name !== 'selection-box') return; - const state = this.plugin.state.dataState; + const state = this.plugin.state.data; const newParams: Params = { ...this.params, entry: { @@ -226,7 +226,7 @@ export namespace VolumeStreaming { } private getStructureRoot() { - return this.plugin.state.dataState.select(StateSelection.Generators.byRef(this.ref).rootOfType([PluginStateObject.Molecule.Structure]))[0]; + return this.plugin.state.data.select(StateSelection.Generators.byRef(this.ref).rootOfType([PluginStateObject.Molecule.Structure]))[0]; } register(ref: string): void { diff --git a/src/mol-plugin/behavior/static/representation.ts b/src/mol-plugin/behavior/static/representation.ts index 7c4abbf2d699f1e295cd48dbf0f3c35564a796a5..10f285940176806fb8bf46b04ad47a6758f36b8c 100644 --- a/src/mol-plugin/behavior/static/representation.ts +++ b/src/mol-plugin/behavior/static/representation.ts @@ -16,7 +16,7 @@ export function registerDefault(ctx: PluginContext) { } export function SyncRepresentationToCanvas(ctx: PluginContext) { - const events = ctx.state.dataState.events; + const events = ctx.state.data.events; events.object.created.subscribe(e => { if (!SO.isRepresentation3D(e.obj)) return; updateVisibility(e.state.cells.get(e.ref)!, e.obj.data.repr); @@ -51,7 +51,7 @@ export function SyncRepresentationToCanvas(ctx: PluginContext) { export function SyncStructureRepresentation3DState(ctx: PluginContext) { // TODO: figure out how to do transform composition here? - const events = ctx.state.dataState.events; + const events = ctx.state.data.events; events.object.created.subscribe(e => { if (!SO.Molecule.Structure.Representation3DState.is(e.obj)) return; const data = e.obj.data as SO.Molecule.Structure.Representation3DStateData; @@ -77,7 +77,7 @@ export function SyncStructureRepresentation3DState(ctx: PluginContext) { export function UpdateRepresentationVisibility(ctx: PluginContext) { - ctx.state.dataState.events.cell.stateUpdated.subscribe(e => { + ctx.state.data.events.cell.stateUpdated.subscribe(e => { const cell = e.state.cells.get(e.ref)!; if (!SO.isRepresentation3D(cell.obj)) return; updateVisibility(cell, cell.obj.data.repr); diff --git a/src/mol-plugin/behavior/static/state.ts b/src/mol-plugin/behavior/static/state.ts index fbcad4b210217eee6f459ee729d82db2b0204f8d..1df8f92a7d985d1d6cc176a37786cbe33a4eae99 100644 --- a/src/mol-plugin/behavior/static/state.ts +++ b/src/mol-plugin/behavior/static/state.ts @@ -54,7 +54,7 @@ export function SetCurrentObject(ctx: PluginContext) { } export function Update(ctx: PluginContext) { - PluginCommands.State.Update.subscribe(ctx, ({ state, tree, options }) => ctx.runTask(state.updateTree(tree, options))); + PluginCommands.State.Update.subscribe(ctx, ({ state, tree, options }) => ctx.updateState(tree, options)); } export function ApplyAction(ctx: PluginContext) { @@ -64,7 +64,7 @@ export function ApplyAction(ctx: PluginContext) { export function RemoveObject(ctx: PluginContext) { function remove(state: State, ref: string) { const tree = state.build().delete(ref).getTree(); - return ctx.runTask(state.updateTree(tree)); + return ctx.updateState(tree); } PluginCommands.State.RemoveObject.subscribe(ctx, ({ state, ref, removeParentGhosts }) => { @@ -104,7 +104,7 @@ function setVisibilityVisitor(t: StateTransform, tree: StateTree, ctx: { state: } export function Highlight(ctx: PluginContext) { - PluginCommands.State.Highlight.subscribe(ctx, ({ state, ref }) => { + PluginCommands.Interactivity.Object.Highlight.subscribe(ctx, ({ state, ref }) => { ctx.managers.interactivity.lociHighlights.clearHighlights(); const refs = typeof ref === 'string' ? [ref] : ref; @@ -129,7 +129,7 @@ export function Highlight(ctx: PluginContext) { } export function ClearHighlights(ctx: PluginContext) { - PluginCommands.State.ClearHighlights.subscribe(ctx, () => { + PluginCommands.Interactivity.ClearHighlights.subscribe(ctx, () => { ctx.managers.interactivity.lociHighlights.clearHighlights(); }); } diff --git a/src/mol-plugin/commands.ts b/src/mol-plugin/commands.ts index a73135b9ec437080684596cf129a203e10ec9d36..f50874660921784776cc022f31582a0163c24e5e 100644 --- a/src/mol-plugin/commands.ts +++ b/src/mol-plugin/commands.ts @@ -25,9 +25,7 @@ export const PluginCommands = { ToggleExpanded: PluginCommand<{ state: State, ref: StateTransform.Ref }>(), ToggleVisibility: PluginCommand<{ state: State, ref: StateTransform.Ref }>(), - Highlight: PluginCommand<{ state: State, ref: StateTransform.Ref | StateTransform.Ref[] }>(), - ClearHighlights: PluginCommand<{}>(), - + Snapshots: { Add: PluginCommand<{ name?: string, description?: string, params?: PluginState.GetSnapshotParams }>(), Replace: PluginCommand<{ id: string, params?: PluginState.GetSnapshotParams }>(), @@ -44,10 +42,14 @@ export const PluginCommands = { } }, Interactivity: { + Object: { + Highlight: PluginCommand<{ state: State, ref: StateTransform.Ref | StateTransform.Ref[] }>(), + }, Structure: { Highlight: PluginCommand<{ loci: StructureElement.Loci, isOff?: boolean }>(), Select: PluginCommand<{ loci: StructureElement.Loci, isOff?: boolean }>() - } + }, + ClearHighlights: PluginCommand<{}>(), }, Layout: { Update: PluginCommand<{ state: Partial<PluginLayoutStateProps> }>() diff --git a/src/mol-plugin/context.ts b/src/mol-plugin/context.ts index f39dd19927705745fb4957537e97502d74c809fc..265e926121c9318349ef3c6e1cf77a730b74167b 100644 --- a/src/mol-plugin/context.ts +++ b/src/mol-plugin/context.ts @@ -5,50 +5,50 @@ * @author Alexander Rose <alexander.rose@weirdbyte.de> */ +import { setAutoFreeze } from 'immer'; import { List } from 'immutable'; +import { merge } from 'rxjs'; import { Canvas3D } from '../mol-canvas3d/canvas3d'; +import { CustomProperty } from '../mol-model-props/common/custom-property'; +import { Model, Structure } from '../mol-model/structure'; +import { DataFormatRegistry } from '../mol-plugin-state/actions/data-format'; +import { DataBuilder } from '../mol-plugin-state/builder/data'; +import { StructureBuilder } from '../mol-plugin-state/builder/structure'; +import { TrajectoryFormatRegistry } from '../mol-plugin-state/formats/trajectory'; +import { CameraManager } from '../mol-plugin-state/manager/camera'; +import { InteractivityManager } from '../mol-plugin-state/manager/interactivity'; +import { LociLabelEntry, LociLabelManager } from '../mol-plugin-state/manager/loci-label'; +import { StructureComponentManager } from '../mol-plugin-state/manager/structure/component'; +import { StructureHierarchyManager } from '../mol-plugin-state/manager/structure/hierarchy'; +import { StructureMeasurementManager } from '../mol-plugin-state/manager/structure/measurement'; +import { StructureSelectionManager } from '../mol-plugin-state/manager/structure/selection'; +import { StateTransformParameters } from '../mol-plugin-ui/state/common'; import { StructureRepresentationRegistry } from '../mol-repr/structure/registry'; import { VolumeRepresentationRegistry } from '../mol-repr/volume/registry'; -import { State, StateTransform, StateTransformer } from '../mol-state'; -import { Task, Progress } from '../mol-task'; +import { State, StateBuilder, StateTree } from '../mol-state'; +import { Progress, Task } from '../mol-task'; import { ColorTheme } from '../mol-theme/color'; import { SizeTheme } from '../mol-theme/size'; import { ThemeRegistryContext } from '../mol-theme/theme'; import { Color } from '../mol-util/color'; import { ajaxGet } from '../mol-util/data-source'; +import { isDebugMode, isProductionMode } from '../mol-util/debug'; +import { ModifiersKeys } from '../mol-util/input/input-observer'; import { LogEntry } from '../mol-util/log-entry'; import { RxEventHelper } from '../mol-util/rx-event-helper'; -import { merge } from 'rxjs'; import { BuiltInPluginBehaviors } from './behavior'; import { PluginBehavior } from './behavior/behavior'; -import { PluginCommands } from './commands'; import { PluginCommandManager } from './command'; -import { PluginLayout, LeftPanelTabName } from './layout'; +import { PluginCommands } from './commands'; +import { PluginConfigManager } from './config'; +import { LeftPanelTabName, PluginLayout } from './layout'; import { PluginSpec } from './spec'; import { PluginState } from './state'; -import { DataFormatRegistry } from '../mol-plugin-state/actions/data-format'; -import { StateTransformParameters } from '../mol-plugin-ui/state/common'; -import { LociLabelEntry, LociLabelManager } from '../mol-plugin-state/manager/loci-label'; -import { TaskManager } from './util/task-manager'; -import { PLUGIN_VERSION, PLUGIN_VERSION_DATE } from './version'; import { SubstructureParentHelper } from './util/substructure-parent-helper'; -import { ModifiersKeys } from '../mol-util/input/input-observer'; -import { isProductionMode, isDebugMode } from '../mol-util/debug'; -import { Model, Structure } from '../mol-model/structure'; -import { InteractivityManager } from '../mol-plugin-state/manager/interactivity'; +import { TaskManager } from './util/task-manager'; import { PluginToastManager } from './util/toast'; -import { StructureMeasurementManager } from '../mol-plugin-state/manager/structure/measurement'; import { ViewportScreenshotHelper } from './util/viewport-screenshot'; -import { CustomProperty } from '../mol-model-props/common/custom-property'; -import { PluginConfigManager } from './config'; -import { DataBuilder } from '../mol-plugin-state/builder/data'; -import { StructureBuilder } from '../mol-plugin-state/builder/structure'; -import { StructureHierarchyManager } from '../mol-plugin-state/manager/structure/hierarchy'; -import { StructureSelectionManager } from '../mol-plugin-state/manager/structure/selection'; -import { TrajectoryFormatRegistry } from '../mol-plugin-state/formats/trajectory'; -import { StructureComponentManager } from '../mol-plugin-state/manager/structure/component'; -import { CameraManager } from '../mol-plugin-state/manager/camera'; -import { setAutoFreeze } from 'immer'; +import { PLUGIN_VERSION, PLUGIN_VERSION_DATE } from './version'; export class PluginContext { private disposed = false; @@ -61,14 +61,14 @@ export class PluginContext { readonly events = { state: { cell: { - stateUpdated: merge(this.state.dataState.events.cell.stateUpdated, this.state.behaviorState.events.cell.stateUpdated), - created: merge(this.state.dataState.events.cell.created, this.state.behaviorState.events.cell.created), - removed: merge(this.state.dataState.events.cell.removed, this.state.behaviorState.events.cell.removed), + stateUpdated: merge(this.state.data.events.cell.stateUpdated, this.state.behaviors.events.cell.stateUpdated), + created: merge(this.state.data.events.cell.created, this.state.behaviors.events.cell.created), + removed: merge(this.state.data.events.cell.removed, this.state.behaviors.events.cell.removed), }, object: { - created: merge(this.state.dataState.events.object.created, this.state.behaviorState.events.object.created), - removed: merge(this.state.dataState.events.object.removed, this.state.behaviorState.events.object.removed), - updated: merge(this.state.dataState.events.object.updated, this.state.behaviorState.events.object.updated) + created: merge(this.state.data.events.object.created, this.state.behaviors.events.object.created), + removed: merge(this.state.data.events.object.removed, this.state.behaviors.events.object.removed), + updated: merge(this.state.data.events.object.updated, this.state.behaviors.events.object.updated) }, cameraSnapshots: this.state.cameraSnapshots.events, snapshots: this.state.snapshots.events, @@ -199,7 +199,11 @@ export class PluginContext { } dataTransaction(f: () => Promise<void> | void, options?: { canUndo?: string | boolean }) { - return this.runTask(this.state.dataState.transaction(f, options)); + return this.runTask(this.state.data.transaction(f, options)); + } + + updateState(tree: StateTree | StateBuilder, options?: Partial<State.UpdateOptions>) { + return this.runTask(this.state.data.updateTree(tree, options)); } requestTaskAbort(progress: Progress, reason?: string) { @@ -217,18 +221,8 @@ export class PluginContext { this.disposed = true; } - applyTransform(state: State, a: StateTransform.Ref, transformer: StateTransformer, params: any) { - const tree = state.build().to(a).apply(transformer, params); - return PluginCommands.State.Update(this, { state, tree }); - } - - updateTransform(state: State, a: StateTransform.Ref, params: any) { - const tree = state.build().to(a).update(params); - return PluginCommands.State.Update(this, { state, tree }); - } - private initBehaviorEvents() { - merge(this.state.dataState.events.isUpdating, this.state.behaviorState.events.isUpdating).subscribe(u => { + merge(this.state.data.events.isUpdating, this.state.behaviors.events.isUpdating).subscribe(u => { this.behaviors.state.isUpdating.next(u); }); @@ -248,11 +242,11 @@ export class PluginContext { BuiltInPluginBehaviors.Camera.registerDefault(this); BuiltInPluginBehaviors.Misc.registerDefault(this); - merge(this.state.dataState.events.log, this.state.behaviorState.events.log).subscribe(e => this.events.log.next(e)); + merge(this.state.data.events.log, this.state.behaviors.events.log).subscribe(e => this.events.log.next(e)); } private async initBehaviors() { - const tree = this.state.behaviorState.build(); + const tree = this.state.behaviors.build(); for (const cat of Object.keys(PluginBehavior.Categories)) { tree.toRoot().apply(PluginBehavior.CreateCategory, { label: (PluginBehavior.Categories as any)[cat] }, { ref: cat, state: { isLocked: true } }); @@ -262,12 +256,12 @@ export class PluginContext { tree.to(PluginBehavior.getCategoryId(b.transformer)).apply(b.transformer, b.defaultParams, { ref: b.transformer.id }); } - await this.runTask(this.state.behaviorState.updateTree(tree, { doNotUpdateCurrent: true, doNotLogTiming: true })); + await this.runTask(this.state.behaviors.updateTree(tree, { doNotUpdateCurrent: true, doNotLogTiming: true })); } private initDataActions() { for (const a of this.spec.actions) { - this.state.dataState.actions.add(a.action); + this.state.data.actions.add(a.action); } } diff --git a/src/mol-plugin/state.ts b/src/mol-plugin/state.ts index b04aee5184c0de29543f83328827b18f06a76226..d92ce0e9b122f32a69bf90273af0ef25b241640f 100644 --- a/src/mol-plugin/state.ts +++ b/src/mol-plugin/state.ts @@ -4,7 +4,7 @@ * @author David Sehnal <david.sehnal@gmail.com> */ -import { State } from '../mol-state'; +import { State, StateTransform, StateTransformer } from '../mol-state'; import { PluginStateObject as SO } from '../mol-plugin-state/objects'; import { Camera } from '../mol-canvas3d/camera'; import { PluginBehavior } from './behavior'; @@ -22,8 +22,8 @@ export { PluginState } class PluginState { private ev = RxEventHelper.create(); - readonly dataState: State; - readonly behaviorState: State; + readonly data: State; + readonly behaviors: State; readonly animation: PluginAnimationManager; readonly cameraSnapshots = new CameraSnapshotManager(); readonly snapshots: PluginStateSnapshotManager; @@ -38,8 +38,8 @@ class PluginState { if (kind !== current) { this.behavior.kind.next(kind); this.behavior.currentObject.next(kind === 'data' - ? this.dataState.behaviors.currentObject.value - : this.behaviorState.behaviors.currentObject.value) + ? this.data.behaviors.currentObject.value + : this.behaviors.behaviors.currentObject.value) } } @@ -47,8 +47,8 @@ class PluginState { const p = { ...PluginState.DefaultGetSnapshotParams, ...params }; return { id: UUID.create22(), - data: p.data ? this.dataState.getSnapshot() : void 0, - behaviour: p.behavior ? this.behaviorState.getSnapshot() : void 0, + data: p.data ? this.data.getSnapshot() : void 0, + behaviour: p.behavior ? this.behaviors.getSnapshot() : void 0, animation: p.animation ? this.animation.getSnapshot() : void 0, startAnimation: p.startAnimation ? !!p.startAnimation : void 0, camera: p.camera ? { @@ -66,8 +66,8 @@ class PluginState { async setSnapshot(snapshot: PluginState.Snapshot) { await this.animation.stop(); - if (snapshot.behaviour) await this.plugin.runTask(this.behaviorState.setSnapshot(snapshot.behaviour)); - if (snapshot.data) await this.plugin.runTask(this.dataState.setSnapshot(snapshot.data)); + if (snapshot.behaviour) await this.plugin.runTask(this.behaviors.setSnapshot(snapshot.behaviour)); + if (snapshot.data) await this.plugin.runTask(this.data.setSnapshot(snapshot.data)); if (snapshot.canvas3d) { if (snapshot.canvas3d.props) await PluginCommands.Canvas3D.SetSettings(this.plugin, { settings: snapshot.canvas3d.props }); } @@ -91,27 +91,37 @@ class PluginState { } } + applyTransform(state: State, a: StateTransform.Ref, transformer: StateTransformer, params: any) { + const tree = state.build().to(a).apply(transformer, params); + return PluginCommands.State.Update(this.plugin, { state, tree }); + } + + updateTransform(state: State, a: StateTransform.Ref, params: any) { + const tree = state.build().to(a).update(params); + return PluginCommands.State.Update(this.plugin, { state, tree }); + } + dispose() { this.ev.dispose(); - this.dataState.dispose(); - this.behaviorState.dispose(); + this.data.dispose(); + this.behaviors.dispose(); this.cameraSnapshots.dispose(); this.animation.dispose(); } constructor(private plugin: import('./context').PluginContext) { this.snapshots = new PluginStateSnapshotManager(plugin); - this.dataState = State.create(new SO.Root({ }), { globalContext: plugin }); - this.behaviorState = State.create(new PluginBehavior.Root({ }), { globalContext: plugin, rootState: { isLocked: true } }); + this.data = State.create(new SO.Root({ }), { globalContext: plugin }); + this.behaviors = State.create(new PluginBehavior.Root({ }), { globalContext: plugin, rootState: { isLocked: true } }); - this.dataState.behaviors.currentObject.subscribe(o => { + this.data.behaviors.currentObject.subscribe(o => { if (this.behavior.kind.value === 'data') this.behavior.currentObject.next(o); }); - this.behaviorState.behaviors.currentObject.subscribe(o => { + this.behaviors.behaviors.currentObject.subscribe(o => { if (this.behavior.kind.value === 'behavior') this.behavior.currentObject.next(o); }); - this.behavior.currentObject.next(this.dataState.behaviors.currentObject.value); + this.behavior.currentObject.next(this.data.behaviors.currentObject.value); this.animation = new PluginAnimationManager(plugin); } diff --git a/src/mol-plugin/util/substructure-parent-helper.ts b/src/mol-plugin/util/substructure-parent-helper.ts index 58bcc806cf4f567470bc0c150d63a32d640f1b56..16e703179e0a1d62fd2be066a0d7131b42c7ff77 100644 --- a/src/mol-plugin/util/substructure-parent-helper.ts +++ b/src/mol-plugin/util/substructure-parent-helper.ts @@ -19,7 +19,7 @@ class SubstructureParentHelper { get(s: Structure): StateObjectCell<PluginStateObject.Molecule.Structure> | undefined { const r = this.root.get(s); if (!r) return; - return this.plugin.state.dataState.cells.get(r.ref); + return this.plugin.state.data.cells.get(r.ref); } private addMapping(state: State, ref: string, obj: StateObject) { @@ -63,15 +63,15 @@ class SubstructureParentHelper { } constructor(private plugin: PluginContext) { - plugin.state.dataState.events.object.created.subscribe(e => { + plugin.state.data.events.object.created.subscribe(e => { this.addMapping(e.state, e.ref, e.obj); }); - plugin.state.dataState.events.object.removed.subscribe(e => { + plugin.state.data.events.object.removed.subscribe(e => { this.removeMapping(e.ref); }); - plugin.state.dataState.events.object.updated.subscribe(e => { + plugin.state.data.events.object.updated.subscribe(e => { this.updateMapping(e.state, e.ref, e.oldObj, e.obj); }); } diff --git a/src/mol-plugin/util/viewport-screenshot.ts b/src/mol-plugin/util/viewport-screenshot.ts index ce22ed216a0943a2bda34a98b838bc825f8e1154..a0878b2e8e886e995ad9d81702ff6482af4e4aa4 100644 --- a/src/mol-plugin/util/viewport-screenshot.ts +++ b/src/mol-plugin/util/viewport-screenshot.ts @@ -99,7 +99,7 @@ class ViewportScreenshotHelper { } getFilename() { - const models = this.plugin.state.dataState.select(StateSelection.Generators.rootsOfType(PluginStateObject.Molecule.Model)).map(s => s.obj!.data) + const models = this.plugin.state.data.select(StateSelection.Generators.rootsOfType(PluginStateObject.Molecule.Model)).map(s => s.obj!.data) const uniqueIds = new Set<string>() models.forEach(m => uniqueIds.add(m.entryId.toUpperCase())) const idString = Array.from(uniqueIds.values()).join('-')