diff --git a/src/mol-plugin/behaviour.ts b/src/mol-plugin/behaviour.ts new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/mol-plugin/behaviour/camera.ts b/src/mol-plugin/behaviour/camera.ts new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/mol-plugin/context.ts b/src/mol-plugin/context.ts new file mode 100644 index 0000000000000000000000000000000000000000..23ec374b12668e0ef431ad16daa8b490d203ae73 --- /dev/null +++ b/src/mol-plugin/context.ts @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +import { State } from 'mol-state'; +import Viewer from 'mol-canvas3d/viewer'; + +export class PluginContext { + state = { + data: State, + behaviour: State, + plugin: State + }; + + viewer: Viewer; + + // logger = ; + // settings = ; +} \ No newline at end of file diff --git a/src/mol-plugin/spec.ts b/src/mol-plugin/spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..69a6e8683f174e4023d9ba8281072565f518ae7b --- /dev/null +++ b/src/mol-plugin/spec.ts @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +interface PluginSpec { + +} + +export { PluginSpec } \ No newline at end of file diff --git a/src/mol-plugin/state/base.ts b/src/mol-plugin/state/base.ts new file mode 100644 index 0000000000000000000000000000000000000000..6ca7afee9ce307e8a61d998b8e04addb02ad3016 --- /dev/null +++ b/src/mol-plugin/state/base.ts @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +import { StateObject, Transformer } from 'mol-state'; + +export type TypeClass = 'root' | 'data' | 'prop' + +export namespace PluginStateObject { + export type TypeClass = 'Root' | 'Group' | 'Data' | 'Object' | 'Representation' | 'Behaviour' + export interface TypeInfo { name: string, shortName: string, description: string, typeClass: TypeClass } + export interface PluginStateObjectProps { label: string } + + export const Create = StateObject.factory<TypeInfo, PluginStateObjectProps>(); +} + +export namespace PluginStateTransform { + export const Create = Transformer.factory('ms-plugin'); +} diff --git a/src/mol-plugin/state/transforms/data.ts b/src/mol-plugin/state/transforms/data.ts new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/mol-plugin/state/transforms/model.ts b/src/mol-plugin/state/transforms/model.ts new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/mol-plugin/state/transforms/visuals.ts b/src/mol-plugin/state/transforms/visuals.ts new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/mol-plugin/state/types.ts b/src/mol-plugin/state/types.ts new file mode 100644 index 0000000000000000000000000000000000000000..1f0b3ecefa466003528bf80a72c8b27f609675e7 --- /dev/null +++ b/src/mol-plugin/state/types.ts @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +import { PluginStateObject } from './base'; +import { CifFile } from 'mol-io/reader/cif'; +import { Model as _Model, Structure as _Structure } from 'mol-model/structure' + +const _create = PluginStateObject.Create + +namespace PluginStateObjects { + export class Root extends _create({ name: 'Root', shortName: 'R', typeClass: 'Root', description: 'Where everything begins.' }) { } + export class Group extends _create({ name: 'Group', shortName: 'G', typeClass: 'Group', description: 'A group on entities.' }) { } + + export namespace Data { + export class String extends _create<string>({ name: 'String Data', typeClass: 'Data', shortName: 'S_D', description: 'A string.' }) { } + export class Binary extends _create<Uint8Array>({ name: 'Binary Data', typeClass: 'Data', shortName: 'B_D', description: 'A binary blob.' }) { } + export class Json extends _create<any>({ name: 'JSON Data', typeClass: 'Data', shortName: 'JS_D', description: 'Represents JSON data.' }) { } + export class Cif extends _create<CifFile>({ name: 'Cif File', typeClass: 'Data', shortName: 'CF', description: 'Represents parsed CIF data.' }) { } + + // TODO + // export class MultipleRaw extends _create<{ + // [key: string]: { type: 'String' | 'Binary', data: string | Uint8Array } + // }>({ name: 'Data', typeClass: 'Data', shortName: 'MD', description: 'Multiple Keyed Data.' }) { } + } + + export class Model extends _create<_Model>({ name: 'Molecule Model', typeClass: 'Object', shortName: 'M_M', description: 'A model of a molecule.' }) { } + export class Structure extends _create<_Structure>({ name: 'Molecule Structure', typeClass: 'Object', shortName: 'M_S', description: 'A structure of a molecule.' }) { } + + + export class StructureRepresentation extends _create<{ + // TODO + }>({ name: 'Molecule Structure Representation', typeClass: 'Representation', shortName: 'S_R', description: 'A representation of a molecular structure.' }) { } +} + +export { PluginStateObjects } \ No newline at end of file diff --git a/src/mol-plugin/util/logger.ts b/src/mol-plugin/util/logger.ts new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/mol-state/context.ts b/src/mol-state/context.ts index 4ab3b9d3239d5fd48143ae4bfbb01fdd07ab55d6..10117db026fadef9d44c62facd7885fc855b3cd7 100644 --- a/src/mol-state/context.ts +++ b/src/mol-state/context.ts @@ -13,10 +13,11 @@ interface StateContext { object: { stateChanged: Subject<{ ref: Transform.Ref }>, propsChanged: Subject<{ ref: Transform.Ref, newProps: unknown }>, - updated: Subject<{ ref: Transform.Ref }>, - replaced: Subject<{ ref: Transform.Ref, old?: StateObject }>, - created: Subject<{ ref: Transform.Ref }>, - removed: Subject<{ ref: Transform.Ref }>, + + updated: Subject<{ ref: Transform.Ref, obj?: StateObject }>, + replaced: Subject<{ ref: Transform.Ref, oldObj?: StateObject, newObj?: StateObject }>, + created: Subject<{ ref: Transform.Ref, obj: StateObject }>, + removed: Subject<{ ref: Transform.Ref, obj?: StateObject }>, }, warn: Subject<string> }, diff --git a/src/mol-state/object.ts b/src/mol-state/object.ts index c721b58264f3049020943b1ecd5b1ec98ca853ee..893bf1e48a9875609c60e49f363a1a7b2a73bdf0 100644 --- a/src/mol-state/object.ts +++ b/src/mol-state/object.ts @@ -6,10 +6,11 @@ */ import { Transform } from './transform'; +import { UUID } from 'mol-util'; /** A mutable state object */ export interface StateObject<P = unknown, D = unknown> { - ref: Transform.Ref, + readonly id: UUID, readonly type: StateObject.Type, readonly props: P, readonly data: D @@ -28,18 +29,18 @@ export namespace StateObject { } export interface Type<Info = any> { - kind: string, info: Info } export function factory<TypeInfo, CommonProps>() { - return <D = { }, P = {}>(kind: string, info: TypeInfo) => create<P & CommonProps, D, TypeInfo>(kind, info); + return <D = { }, P = {}>(typeInfo: TypeInfo) => create<P & CommonProps, D, TypeInfo>(typeInfo); } - export function create<Props, Data, TypeInfo>(kind: string, typeInfo: TypeInfo) { - const dataType: Type<TypeInfo> = { kind, info: typeInfo }; + export function create<Props, Data, TypeInfo>(typeInfo: TypeInfo) { + const dataType: Type<TypeInfo> = { info: typeInfo }; return class implements StateObject<Props, Data> { static type = dataType; + id = UUID.create(); type = dataType; ref = 'not set' as Transform.Ref; constructor(public props: Props, public data: Data) { } diff --git a/src/mol-state/state.ts b/src/mol-state/state.ts index 873579731e6a35b211abb495835b2e115dea54bb..75fa6aaef3fa9cf41d2e715cd1f6965868613bbc 100644 --- a/src/mol-state/state.ts +++ b/src/mol-state/state.ts @@ -29,7 +29,6 @@ export namespace State { const root = tree.getValue(tree.rootRef)!; const defaultObjectProps = (params && params.defaultObjectProps) || { } - rootObject.ref = tree.rootRef; objects.set(tree.rootRef, { ref: tree.rootRef, obj: rootObject, @@ -185,11 +184,11 @@ export namespace State { const update = await updateNode(ctx, root); setObjectState(ctx, root, StateObject.StateType.Ok); if (update.action === 'created') { - ctx.stateCtx.events.object.created.next({ ref: root }); + ctx.stateCtx.events.object.created.next({ ref: root, obj: update.obj! }); } else if (update.action === 'updated') { - ctx.stateCtx.events.object.updated.next({ ref: root }); + ctx.stateCtx.events.object.updated.next({ ref: root, obj: update.obj }); } else if (update.action === 'replaced') { - ctx.stateCtx.events.object.replaced.next({ ref: root, old: update.old }); + ctx.stateCtx.events.object.replaced.next({ ref: root, oldObj: update.oldObj, newObj: update.newObj }); } } catch (e) { doError(ctx, root, '' + e); @@ -212,7 +211,6 @@ export namespace State { if (!oldTree.nodes.has(currentRef) || !objects.has(currentRef)) { // console.log('creating...', transform.transformer.id, oldTree.nodes.has(currentRef), objects.has(currentRef)); const obj = await createObject(ctx, transform.transformer, parent, transform.params); - obj.ref = currentRef; objects.set(currentRef, { ref: currentRef, obj, @@ -220,7 +218,7 @@ export namespace State { version: transform.version, props: { ...ctx.stateCtx.defaultObjectProps, ...transform.defaultProps } }); - return { action: 'created' }; + return { action: 'created', obj }; } else { // console.log('updating...', transform.transformer.id); const current = objects.get(currentRef)!; @@ -228,7 +226,6 @@ export namespace State { switch (await updateObject(ctx, transform.transformer, parent, current.obj!, oldParams, transform.params)) { case Transformer.UpdateResult.Recreate: { const obj = await createObject(ctx, transform.transformer, parent, transform.params); - obj.ref = currentRef; objects.set(currentRef, { ref: currentRef, obj, @@ -236,12 +233,12 @@ export namespace State { version: transform.version, props: { ...ctx.stateCtx.defaultObjectProps, ...current.props, ...transform.defaultProps } }); - return { action: 'replaced', old: current.obj! }; + return { action: 'replaced', oldObj: current.obj!, newObj: obj }; } case Transformer.UpdateResult.Updated: current.version = transform.version; current.props = { ...ctx.stateCtx.defaultObjectProps, ...current.props, ...transform.defaultProps }; - return { action: 'updated' }; + return { action: 'updated', obj: current.obj }; default: // TODO check if props need to be updated return { action: 'none' }; diff --git a/src/perf-tests/state.ts b/src/perf-tests/state.ts index 183063a9ad7d1c15ad84f0595a11f4d2fbfff4cb..98067b5850e756244e27524b5729f5cd48145ee8 100644 --- a/src/perf-tests/state.ts +++ b/src/perf-tests/state.ts @@ -9,10 +9,10 @@ export interface TypeInfo { name: string, class: TypeClass } const _obj = StateObject.factory<TypeInfo, ObjProps>() const _transform = Transformer.factory('test'); -export class Root extends _obj('root', { name: 'Root', class: 'root' }) { } -export class Square extends _obj<{ a: number }>('square', { name: 'Square', class: 'shape' }) { } -export class Circle extends _obj<{ r: number }>('circle', { name: 'Circle', class: 'shape' }) { } -export class Area extends _obj<{ volume: number }>('volume', { name: 'Volume', class: 'prop' }) { } +export class Root extends _obj({ name: 'Root', class: 'root' }) { } +export class Square extends _obj<{ a: number }>({ name: 'Square', class: 'shape' }) { } +export class Circle extends _obj<{ r: number }>({ name: 'Circle', class: 'shape' }) { } +export class Area extends _obj<{ volume: number }>({ name: 'Area', class: 'prop' }) { } export const CreateSquare = _transform<Root, Square, { a: number }>({ name: 'create-square',