/** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal */ import * as React from 'react'; import { Transform, State } from 'mol-state'; import { ParametersComponent } from 'mol-app/component/parameters'; import { StateAction } from 'mol-state/action'; import { PluginCommands } from 'mol-plugin/command'; import { UpdateTrajectory } from 'mol-plugin/state/actions/basic'; import { PluginComponent } from './base'; export class Controls extends PluginComponent<{ }, { }> { render() { return <> ; } } export class _test_TrajectoryControls extends PluginComponent { render() { return
Trajectory:
} } export class _test_ApplyAction extends PluginComponent<{ nodeRef: Transform.Ref, state: State, action: StateAction }, { params: any }> { private getObj() { const obj = this.props.state.cells.get(this.props.nodeRef)!; return obj; } private getDefaultParams() { const p = this.props.action.definition.params; if (!p || !p.default) return {}; const obj = this.getObj(); if (!obj.obj) return {}; return p.default(obj.obj, this.plugin); } private getParamDef() { const p = this.props.action.definition.params; if (!p || !p.controls) return {}; const obj = this.getObj(); if (!obj.obj) return {}; return p.controls(obj.obj, this.plugin); } private create() { console.log('Apply Action', this.state.params); PluginCommands.State.ApplyAction.dispatch(this.plugin, { state: this.props.state, action: this.props.action.create(this.state.params), ref: this.props.nodeRef }); // this.context.applyTransform(this.props.state, this.props.nodeRef, this.props.transformer, this.state.params); } state = { params: this.getDefaultParams() } render() { const obj = this.getObj(); if (obj.status !== 'ok') { // TODO filter this elsewhere return
; } const action = this.props.action; return

{(action.definition.display && action.definition.display.name) || action.id}

{ this.setState({ params: { ...this.state.params, [k]: v } }); }} />
} } export class _test_UpdateTransform extends PluginComponent<{ state: State, nodeRef: Transform.Ref }, { params: any }> { private getCell(ref?: string) { return this.props.state.cells.get(ref || this.props.nodeRef)!; } private getDefParams() { const cell = this.getCell(); if (!cell) return {}; return cell.transform.params; } private getParamDef() { const cell = this.getCell(); const def = cell.transform.transformer.definition; if (!cell.sourceRef || !def.params || !def.params.controls) return void 0; const src = this.getCell(cell.sourceRef); if (!src || !src.obj) return void 0; return def.params.controls(src.obj, this.plugin); } private update() { console.log(this.props.nodeRef, this.state.params); this.plugin.updateTransform(this.props.state, this.props.nodeRef, this.state.params); } // componentDidMount() { // const t = this.context.state.data.tree.nodes.get(this.props.nodeRef)!; // if (t) this.setState({ params: t.value.params }); // } state = { params: this.getDefParams() }; render() { const cell = this.getCell(); const transform = cell.transform; if (!transform || transform.ref === Transform.RootRef) { return
; } const params = this.getParamDef(); if (!params) return
; const tr = transform.transformer; return

{(tr.definition.display && tr.definition.display.name) || tr.definition.name}

{ this.setState({ params: { ...this.state.params, [k]: v } }); }} />
} }