Skip to content
Snippets Groups Projects
Commit c2b4fd72 authored by David Sehnal's avatar David Sehnal
Browse files

mol-plugin: tweak resp state obj

parent 5fed5593
No related branches found
No related tags found
No related merge requests found
...@@ -11,32 +11,32 @@ class _AddRepresentationToCanvas extends PluginBehavior.Handler { ...@@ -11,32 +11,32 @@ class _AddRepresentationToCanvas extends PluginBehavior.Handler {
register(): void { register(): void {
this.subscribeObservable(this.ctx.events.state.data.object.created, o => { this.subscribeObservable(this.ctx.events.state.data.object.created, o => {
if (!SO.StructureRepresentation3D.is(o.obj)) return; if (!SO.StructureRepresentation3D.is(o.obj)) return;
this.ctx.canvas3d.add(o.obj.data.repr); this.ctx.canvas3d.add(o.obj.data);
this.ctx.canvas3d.requestDraw(true); this.ctx.canvas3d.requestDraw(true);
}); });
this.subscribeObservable(this.ctx.events.state.data.object.updated, o => { this.subscribeObservable(this.ctx.events.state.data.object.updated, o => {
const oo = o.obj; const oo = o.obj;
if (!SO.StructureRepresentation3D.is(oo)) return; if (!SO.StructureRepresentation3D.is(oo)) return;
this.ctx.canvas3d.add(oo.data.repr); this.ctx.canvas3d.add(oo.data);
this.ctx.canvas3d.requestDraw(true); this.ctx.canvas3d.requestDraw(true);
}); });
this.subscribeObservable(this.ctx.events.state.data.object.removed, o => { this.subscribeObservable(this.ctx.events.state.data.object.removed, o => {
const oo = o.obj; const oo = o.obj;
console.log('removed', o.ref, oo && oo.type); console.log('removed', o.ref, oo && oo.type);
if (!SO.StructureRepresentation3D.is(oo)) return; if (!SO.StructureRepresentation3D.is(oo)) return;
this.ctx.canvas3d.remove(oo.data.repr); this.ctx.canvas3d.remove(oo.data);
console.log('removed from canvas', o.ref); console.log('removed from canvas', o.ref);
this.ctx.canvas3d.requestDraw(true); this.ctx.canvas3d.requestDraw(true);
oo.data.repr.destroy(); oo.data.destroy();
}); });
this.subscribeObservable(this.ctx.events.state.data.object.replaced, o => { this.subscribeObservable(this.ctx.events.state.data.object.replaced, o => {
if (o.oldObj && SO.StructureRepresentation3D.is(o.oldObj)) { if (o.oldObj && SO.StructureRepresentation3D.is(o.oldObj)) {
this.ctx.canvas3d.remove(o.oldObj.data.repr); this.ctx.canvas3d.remove(o.oldObj.data);
this.ctx.canvas3d.requestDraw(true); this.ctx.canvas3d.requestDraw(true);
o.oldObj.data.repr.destroy(); o.oldObj.data.destroy();
} }
if (o.newObj && SO.StructureRepresentation3D.is(o.newObj)) { if (o.newObj && SO.StructureRepresentation3D.is(o.newObj)) {
this.ctx.canvas3d.add(o.newObj.data.repr); this.ctx.canvas3d.add(o.newObj.data);
this.ctx.canvas3d.requestDraw(true); this.ctx.canvas3d.requestDraw(true);
} }
}); });
......
...@@ -35,11 +35,7 @@ namespace PluginStateObjects { ...@@ -35,11 +35,7 @@ namespace PluginStateObjects {
export class Structure extends _create<_Structure>({ name: 'Molecule Structure', typeClass: 'Object', shortName: 'M_S', description: 'A structure 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 StructureRepresentation3D extends _create<{ export class StructureRepresentation3D extends _create<StructureRepresentation<any>>({ name: 'Molecule Structure Representation', typeClass: 'Representation', shortName: 'S_R', description: 'A representation of a molecular structure.' }) { }
repr: StructureRepresentation<any>,
// TODO
// props
}>({ name: 'Molecule Structure Representation', typeClass: 'Representation', shortName: 'S_R', description: 'A representation of a molecular structure.' }) { }
} }
export { PluginStateObjects } export { PluginStateObjects }
\ No newline at end of file
...@@ -23,12 +23,12 @@ const CreateStructureRepresentation = PluginStateTransform.Create<SO.Structure, ...@@ -23,12 +23,12 @@ const CreateStructureRepresentation = PluginStateTransform.Create<SO.Structure,
return Task.create('Structure Representation', async ctx => { return Task.create('Structure Representation', async ctx => {
const repr = BallAndStickRepresentation(); // CartoonRepresentation(); const repr = BallAndStickRepresentation(); // CartoonRepresentation();
await repr.createOrUpdate({ webgl: plugin.canvas3d.webgl }, DefaultBallAndStickProps, a.data).runInContext(ctx); await repr.createOrUpdate({ webgl: plugin.canvas3d.webgl }, DefaultBallAndStickProps, a.data).runInContext(ctx);
return new SO.StructureRepresentation3D({ label: 'Visual Repr.' }, { repr }); return new SO.StructureRepresentation3D({ label: 'Visual Repr.' }, repr);
}); });
}, },
update({ a, b }, plugin: PluginContext) { update({ a, b }, plugin: PluginContext) {
return Task.create('Structure Representation', async ctx => { return Task.create('Structure Representation', async ctx => {
await b.data.repr.createOrUpdate({ webgl: plugin.canvas3d.webgl }, b.data.repr.props, a.data).runInContext(ctx); await b.data.createOrUpdate({ webgl: plugin.canvas3d.webgl }, b.data.props, a.data).runInContext(ctx);
return Transformer.UpdateResult.Updated; return Transformer.UpdateResult.Updated;
}); });
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment