Skip to content
Snippets Groups Projects
Select Git revision
  • 9264c12d85a48e395363e80ef0c4632665d25414
  • master default protected
  • rednatco-v2
  • base-pairs-ladder
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

inter-unit-link-cylinder.ts

Blame
  • representation.ts 2.00 KiB
    /**
     * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author David Sehnal <david.sehnal@gmail.com>
     */
    
    import { PluginBehavior } from './behavior';
    import { PluginStateObjects as SO } from '../state/objects';
    
    class _AddRepresentationToCanvas extends PluginBehavior.Handler {
        register(): void {
            this.subscribeObservable(this.ctx.events.state.data.object.created, o => {
                if (!SO.StructureRepresentation3D.is(o.obj)) return;
                this.ctx.canvas3d.add(o.obj.data);
                this.ctx.canvas3d.requestDraw(true);
            });
            this.subscribeObservable(this.ctx.events.state.data.object.updated, o => {
                const oo = o.obj;
                if (!SO.StructureRepresentation3D.is(oo)) return;
                this.ctx.canvas3d.add(oo.data);
                this.ctx.canvas3d.requestDraw(true);
            });
            this.subscribeObservable(this.ctx.events.state.data.object.removed, o => {
                const oo = o.obj;
                console.log('removed', o.ref, oo && oo.type);
                if (!SO.StructureRepresentation3D.is(oo)) return;
                this.ctx.canvas3d.remove(oo.data);
                console.log('removed from canvas', o.ref);
                this.ctx.canvas3d.requestDraw(true);
                oo.data.destroy();
            });
            this.subscribeObservable(this.ctx.events.state.data.object.replaced, o => {
                if (o.oldObj && SO.StructureRepresentation3D.is(o.oldObj)) {
                    this.ctx.canvas3d.remove(o.oldObj.data);
                    this.ctx.canvas3d.requestDraw(true);
                    o.oldObj.data.destroy();
                }
                if (o.newObj && SO.StructureRepresentation3D.is(o.newObj)) {
                    this.ctx.canvas3d.add(o.newObj.data);
                    this.ctx.canvas3d.requestDraw(true);
                }
            });
        }
    }
    
    export const AddRepresentationToCanvas = PluginBehavior.create({
        name: 'add-representation-to-canvas',
        ctor: _AddRepresentationToCanvas,
        display: { name: 'Add Representation To Canvas' }
    });