示例#1
0
        private void ResizeCoords(int wheelDelta)
        {
            if (mol == null) return;

            //first we get the limit for scaling in x and y
            BoundingBox rawBounds = GetBoundingBox(molRawCopy);
            double scaleLimitX = 275 / rawBounds.Width - 30;
            double scaleLimitY = 275 / rawBounds.Height - 30;
            //The minimum scale distance is 30
            double minimumScaleXY = 30;
            int scaleAmount = 10;
            //Now we get our current scaling
            double currentScaleX =  bounds.Width / rawBounds.Width;
            double currentScaleY =  bounds.Height / rawBounds.Height;

            double sx = 0, sy = 0;
            //Now based on the value of wheelDelta (+-) we determine which direction we scale to
            if (wheelDelta > 0)
            {
                //If its greater we scale up
                //But first we make sure we are not above the scale limit
                if (currentScaleX >= scaleLimitX || currentScaleY >= scaleLimitY)
                    return;

                //Now we want to increase the scale by 10 in both x and y, but we don't want it going beyond the limit so we get the min of the two
                sx = Math.Min(currentScaleX + scaleAmount, scaleLimitX);
                sy = Math.Min(currentScaleY + scaleAmount, scaleLimitY);
            }
            else if (wheelDelta < 0)
            {
                //Now we try and scale down, doing the same as for scaling up
                if (currentScaleX <= minimumScaleXY || currentScaleY <= minimumScaleXY)
                    return;

                sx = Math.Max(currentScaleX - scaleAmount, minimumScaleXY);
                sy = Math.Max(currentScaleY - scaleAmount, minimumScaleXY);
            }
            foreach (Node rawAtom in molRawCopy.Atoms.Values)
            {
                foreach (Node atom in mol.Atoms.Values)
                {
                    if (rawAtom.ID == atom.ID)
                    {
                        atom.Position = rawAtom.Position;
                        break;
                    }
                }
            }
            //Now we go through and scale the points base off the raw copy
            foreach (Node atom in mol.Atoms.Values)
            {
                double ox = atom.Position.X;
                double oy = atom.Position.Y;

                double x = (ox * sx + center.X);
                double y = (oy * sy + center.Y);

                atom.Position = new Vector3(x, y, 0);

            }
            bounds = GetBoundingBox(mol);
            foreach (Bond bond in mol.Bonds)
            {
                bond.CalculateBoundPath();
            }
        }
示例#2
0
        private void NormalizeCoords()
        {
            if (mol == null) return;
            //we get the bounds of the raw copy for initial sizing
            bounds = GetBoundingBox(molRawCopy);

            //The scale values for x and y are then calculated
            double sx = 30;//275 / bounds.Width-30;
            double sy = 40;//275 / bounds.Height-30;

            foreach (Node atom in mol.Atoms.Values)
            {
                double ox = atom.Position.X;
                double oy = atom.Position.Y;

                double x = (ox*sx + center.X);
                double y = (oy*sy + center.Y);

                atom.Position = new Vector3(x, y, 0);

                //Finally we go through the bonds and update their nodes, due to some error in copying
                foreach (Bond bond in mol.Bonds)
                {
                    if (bond.Node1.ID == atom.ID)
                        bond.Node1 = atom;
                    else if (bond.Node2.ID == atom.ID)
                        bond.Node2 = atom;
                }
                //and again go through one more time to calculate the paths
                foreach (Bond bond in mol.Bonds)
                {
                    bond.CalculateBoundPath();
                }
            }
            //We also need to get the new size of the bounding box and get the bounds for each bond
            bounds = GetBoundingBox(mol);
               // bondBoundList = GetBondBoundList();
        }