Пример #1
0
        /// <summary>
        /// Sets the view state.
        /// </summary>
        /// <param name="viewState">New <see cref="ViewState"/> to apply to the view.</param>
        protected override void SetViewState(ViewState viewState)
        {
            PdbViewState pdbViewState = viewState as PdbViewState;

            if (pdbViewState != null)
            {
                this.structureControl.SetViewState(pdbViewState);
            }
        }
Пример #2
0
        /// <summary>
        /// Calculates a decent orientation of the molecule based on the bounding box of the
        /// currently selected atoms. Used for animating to the center of a selection.
        /// </summary>
        /// <returns>The generated view state representing the desired orientation.</returns>
        internal PdbViewState GetSelectionViewState()
        {
            Vector3D center = new Vector3D();

            foreach (Atom atom in this.SelectedAtoms)
            {
                center.X += atom.Position.X;
                center.Y += atom.Position.Y;
                center.Z += atom.Position.Z;
            }

            center.X /= this.SelectedAtoms.Count;
            center.Y /= this.SelectedAtoms.Count;
            center.Z /= this.SelectedAtoms.Count;

            double radius = 16;

            foreach (Atom atom in this.SelectedAtoms)
            {
                Vector3D vector = new Vector3D(atom.Position.X - center.X,
                                               atom.Position.Y - center.Y, atom.Position.Z - center.Z);

                radius = Math.Max(radius, vector.LengthSquared);
            }

            radius = Math.Sqrt(radius);

            center.X += this.translateTransform.OffsetX;
            center.Y += this.translateTransform.OffsetY;
            center.Z += this.translateTransform.OffsetZ;

            double moleculeRadius = 1.25 / this.scaleTransform.ScaleX;

            double scale = 0.8 * moleculeRadius / radius;

            Vector3D cameraVector = new Vector3D(0, 0, 1);

            Vector3D axis  = Vector3D.CrossProduct(center, cameraVector);
            double   angle = Vector3D.AngleBetween(center, cameraVector);

            PdbViewState pdbViewState = new PdbViewState();

            pdbViewState.Scale = scale;

            pdbViewState.Translation = -center * this.scaleTransform.ScaleX;

            if (axis.LengthSquared > 0)
            {
                pdbViewState.Rotation = new Quaternion(axis, angle);
            }

            return(pdbViewState);
        }
Пример #3
0
        /// <summary>
        /// Gets the current <see cref="ViewState"/> of the control instance.
        /// </summary>
        /// <returns>The current <see cref="PdbViewState"/>.</returns>
        internal PdbViewState GetViewState()
        {
            PdbViewState viewState = new PdbViewState();

            viewState.Translation = new Vector3D(this.translateTransform.OffsetX,
                                                 this.translateTransform.OffsetY, this.translateTransform.OffsetZ);
            viewState.Rotation = ((QuaternionRotation3D)this.rotateTransform.Rotation).Quaternion;
            viewState.Scale    = this.scaleTransform.ScaleX;
            viewState.Clip     = this.clip;
            viewState.Slab     = this.slab;

            return(viewState);
        }
Пример #4
0
        /// <summary>
        /// Creates the tween of the instance and the specified end ViewState.
        /// </summary>
        /// <param name="endViewState">End <see cref="ViewState"/> of the tween.</param>
        /// <param name="t">The interpolation coefficient.</param>
        /// <returns>
        /// A <see cref="ViewState"/> representing the tween of this instance and the specifed end ViewState.
        /// </returns>
        protected override ViewState CreateTween(ViewState endViewState, double t)
        {
            PdbViewState tweenViewState = new PdbViewState();
            PdbViewState otherViewState = endViewState as PdbViewState;

            if (otherViewState != null)
            {
                tweenViewState.translation = this.translation +
                                             t * (otherViewState.translation - this.translation);
                tweenViewState.scale = this.scale + t * (otherViewState.scale - this.scale);
                tweenViewState.clip  = this.clip + t * (otherViewState.clip - this.clip);
                tweenViewState.slab  = this.slab + t * (otherViewState.slab - this.slab);

                tweenViewState.rotation = Quaternion.Slerp(
                    this.rotation, otherViewState.rotation, t);
            }

            return(tweenViewState);
        }
Пример #5
0
        /// <summary>
        /// Sets all camera and transform settings based on the specified <see cref="PdbViewState"/>.
        /// </summary>
        /// <param name="pdbViewState">The new state of the view.</param>
        internal void SetViewState(PdbViewState pdbViewState)
        {
            this.translateTransform.OffsetX = pdbViewState.Translation.X;
            this.translateTransform.OffsetY = pdbViewState.Translation.Y;
            this.translateTransform.OffsetZ = pdbViewState.Translation.Z;

            this.scaleTransform.ScaleX = pdbViewState.Scale;
            this.scaleTransform.ScaleY = pdbViewState.Scale;
            this.scaleTransform.ScaleZ = pdbViewState.Scale;

            QuaternionRotation3D rotation =
                (QuaternionRotation3D)this.rotateTransform.Rotation;

            rotation.Quaternion = pdbViewState.Rotation;

            this.clip = pdbViewState.Clip;
            this.slab = pdbViewState.Slab;

            this.UpdateClipping();
        }
Пример #6
0
        /// <summary>
        /// Sets all camera and transform settings based on the specified <see cref="PdbViewState"/>.
        /// </summary>
        /// <param name="pdbViewState">The new state of the view.</param>
        internal void SetViewState(PdbViewState pdbViewState)
        {
            this.translateTransform.OffsetX = pdbViewState.Translation.X;
            this.translateTransform.OffsetY = pdbViewState.Translation.Y;
            this.translateTransform.OffsetZ = pdbViewState.Translation.Z;

            this.scaleTransform.ScaleX = pdbViewState.Scale;
            this.scaleTransform.ScaleY = pdbViewState.Scale;
            this.scaleTransform.ScaleZ = pdbViewState.Scale;

            QuaternionRotation3D rotation =
                (QuaternionRotation3D)this.rotateTransform.Rotation;
            rotation.Quaternion = pdbViewState.Rotation;

            this.clip = pdbViewState.Clip;
            this.slab = pdbViewState.Slab;

            this.UpdateClipping();
        }
Пример #7
0
        /// <summary>
        /// Gets the current <see cref="ViewState"/> of the control instance.
        /// </summary>
        /// <returns>The current <see cref="PdbViewState"/>.</returns>
        internal PdbViewState GetViewState()
        {
            PdbViewState viewState = new PdbViewState();

            viewState.Translation = new Vector3D(this.translateTransform.OffsetX,
                this.translateTransform.OffsetY, this.translateTransform.OffsetZ);
            viewState.Rotation = ((QuaternionRotation3D)this.rotateTransform.Rotation).Quaternion;
            viewState.Scale = this.scaleTransform.ScaleX;
            viewState.Clip = this.clip;
            viewState.Slab = this.slab;

            return viewState;
        }
Пример #8
0
        /// <summary>
        /// Calculates a decent orientation of the molecule based on the bounding box of the
        /// currently selected atoms. Used for animating to the center of a selection.
        /// </summary>
        /// <returns>The generated view state representing the desired orientation.</returns>
        internal PdbViewState GetSelectionViewState()
        {
            Vector3D center = new Vector3D();

            foreach (Atom atom in this.SelectedAtoms)
            {
                center.X += atom.Position.X;
                center.Y += atom.Position.Y;
                center.Z += atom.Position.Z;
            }

            center.X /= this.SelectedAtoms.Count;
            center.Y /= this.SelectedAtoms.Count;
            center.Z /= this.SelectedAtoms.Count;

            double radius = 16;

            foreach (Atom atom in this.SelectedAtoms)
            {
                Vector3D vector = new Vector3D(atom.Position.X - center.X,
                    atom.Position.Y - center.Y, atom.Position.Z - center.Z);

                radius = Math.Max(radius, vector.LengthSquared);
            }

            radius = Math.Sqrt(radius);

            center.X += this.translateTransform.OffsetX;
            center.Y += this.translateTransform.OffsetY;
            center.Z += this.translateTransform.OffsetZ;

            double moleculeRadius = 1.25 / this.scaleTransform.ScaleX;

            double scale = 0.8 * moleculeRadius / radius;

            Vector3D cameraVector = new Vector3D(0, 0, 1);

            Vector3D axis = Vector3D.CrossProduct(center, cameraVector);
            double angle = Vector3D.AngleBetween(center, cameraVector);

            PdbViewState pdbViewState = new PdbViewState();

            pdbViewState.Scale = scale;

            pdbViewState.Translation = -center * this.scaleTransform.ScaleX;

            if (axis.LengthSquared > 0)
                pdbViewState.Rotation = new Quaternion(axis, angle);

            return pdbViewState;
        }
Пример #9
0
        /// <summary>
        /// Creates the tween of the instance and the specified end ViewState.
        /// </summary>
        /// <param name="endViewState">End <see cref="ViewState"/> of the tween.</param>
        /// <param name="t">The interpolation coefficient.</param>
        /// <returns>
        /// A <see cref="ViewState"/> representing the tween of this instance and the specifed end ViewState.
        /// </returns>
        protected override ViewState CreateTween(ViewState endViewState, double t)
        {
            PdbViewState tweenViewState = new PdbViewState();
            PdbViewState otherViewState = endViewState as PdbViewState;

            if (otherViewState != null)
            {
                tweenViewState.translation = this.translation +
                    t * (otherViewState.translation - this.translation);
                tweenViewState.scale = this.scale + t * (otherViewState.scale - this.scale);
                tweenViewState.clip = this.clip + t * (otherViewState.clip - this.clip);
                tweenViewState.slab = this.slab + t * (otherViewState.slab - this.slab);

                tweenViewState.rotation = Quaternion.Slerp(
                    this.rotation, otherViewState.rotation, t);
            }

            return tweenViewState;
        }