From 4a7f0fc206fda6e3a799f01b41b07c1daed67288 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Wed, 16 Oct 2019 17:46:27 -0700 Subject: [PATCH] hide non-applicable repr types in repr ui --- .../ui/structure/representation.tsx | 29 ++++++++++++++----- .../util/structure-selection-helper.ts | 7 ++--- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/mol-plugin/ui/structure/representation.tsx b/src/mol-plugin/ui/structure/representation.tsx index 848270313..0eff7066a 100644 --- a/src/mol-plugin/ui/structure/representation.tsx +++ b/src/mol-plugin/ui/structure/representation.tsx @@ -16,15 +16,30 @@ import { VisualQuality, VisualQualityOptions } from '../../../mol-geo/geometry/b import { StructureRepresentationPresets as P } from '../../util/structure-representation-helper'; import { camelCaseToWords } from '../../../mol-util/string'; import { CollapsableControls } from '../base'; +import { StateSelection } from '../../../mol-state'; +import { PluginStateObject } from '../../state/objects'; abstract class BaseStructureRepresentationControls extends PluginUIComponent { - onChange = (value: string) => { - console.log('onChange', value) - } - abstract label: string abstract lociGetter(structure: Structure): StructureElement.Loci + /** root structures */ + protected get structures() { + return this.plugin.state.dataState.select(StateSelection.Generators.rootsOfType(PluginStateObject.Molecule.Structure)).map(s => s.obj!.data) + } + + /** applicapble types */ + private get types() { + const types: [string, string][] = [] + const structures = this.structures + for (const e of this.plugin.structureRepresentation.registry.list) { + if (structures.some(s => e.provider.isApplicable(s))) { + types.push([e.name, e.provider.label]) + } + } + return types + } + show = (value: string) => { this.plugin.helpers.structureRepresentation.set('add', value, this.lociGetter) } @@ -46,19 +61,19 @@ abstract class BaseStructureRepresentationControls extends PluginUIComponent { } render() { - const { types } = this.plugin.structureRepresentation.registry + const TypeOptions = Options(this.types) return <div className='msp-control-row'> <span title={this.label}>{this.label}</span> <div className='msp-select-row'> <ButtonSelect label='Show' onChange={this.show}> - <optgroup label='Show'>{Options(types)}</optgroup> + <optgroup label='Show'>{TypeOptions}</optgroup> </ButtonSelect> <ButtonSelect label='Hide' onChange={this.hide}> <optgroup label='Clear'> <option key={'__all__'} value={'__all__'}>All</option> </optgroup> - <optgroup label='Hide'>{Options(types)}</optgroup> + <optgroup label='Hide'>{TypeOptions}</optgroup> </ButtonSelect> <ButtonSelect label='Color' onChange={this.color}> <optgroup label='Clear'> diff --git a/src/mol-plugin/util/structure-selection-helper.ts b/src/mol-plugin/util/structure-selection-helper.ts index 02bc447cc..e5e493ac4 100644 --- a/src/mol-plugin/util/structure-selection-helper.ts +++ b/src/mol-plugin/util/structure-selection-helper.ts @@ -241,8 +241,7 @@ export type SelectionModifier = 'add' | 'remove' | 'only' export class StructureSelectionHelper { private get structures() { - const state = this.plugin.state.dataState - return state.select(StateSelection.Generators.rootsOfType(PluginStateObject.Molecule.Structure)) + return this.plugin.state.dataState.select(StateSelection.Generators.rootsOfType(PluginStateObject.Molecule.Structure)).map(s => s.obj!.data) } private _set(modifier: SelectionModifier, loci: Loci) { @@ -260,9 +259,7 @@ export class StructureSelectionHelper { } set(modifier: SelectionModifier, query: StructureQuery) { - for (const so of this.structures) { - const s = so.obj!.data - + for (const s of this.structures) { const current = this.plugin.helpers.structureSelectionManager.get(s) const currentSelection = Loci.isEmpty(current) ? StructureSelection.Empty(s) -- GitLab