Ejemplo n.º 1
0
        /// <summary>
        /// Paint a molecule (an IAtomContainer).
        /// </summary>
        /// <param name="atomContainer">the molecule to paint</param>
        /// <param name="drawVisitor">the visitor that does the drawing</param>
        /// <param name="bounds">the bounds on the screen</param>
        /// <param name="resetCenter">if true, set the draw center to be the center of bounds</param>
        public void Paint(IAtomContainer atomContainer, IDrawVisitor drawVisitor, Rect bounds, bool resetCenter)
        {
            if (atomContainer.Bonds.Count > 0 || atomContainer.Atoms.Count == 1)
            {
                rendererModel.SetScale(
                    CalculateScaleForBondLength(GeometryUtil.GetBondLengthAverage(atomContainer)));
            }
            else if (atomContainer.Atoms.Count > 1)
            {
                rendererModel.SetScale(
                    CalculateScaleForBondLength(EstimatedBondLength(atomContainer)));
            }

            // the diagram to draw
            var diagram = GenerateDiagram(atomContainer);

            // the bounds of the model from 'Bounds' elements
            // no bounding elements, use the atom coordinates
            var modelBounds = GetBounds(diagram);

            if (modelBounds.IsEmpty)
            {
                modelBounds = BoundsCalculator.CalculateBounds(atomContainer);
            }

            SetupTransformToFit(bounds, modelBounds, resetCenter);

            this.Paint(drawVisitor, diagram);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Setup the transformations necessary to draw this Chem Model.
        /// </summary>
        /// <param name="chemModel"></param>
        /// <param name="screen"></param>
        public void Setup(IChemModel chemModel, Rect screen)
        {
            this.SetScale(chemModel);
            var bounds = BoundsCalculator.CalculateBounds(chemModel);

            if (bounds != null)
            {
                this.modelCenter = new Point((bounds.Left + bounds.Right) / 2, (bounds.Top + bounds.Bottom) / 2);
            }
            this.drawCenter = new Point((screen.Left + screen.Right) / 2, (screen.Top + screen.Bottom) / 2);
            this.Setup();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Given a chem model, calculates the bounding rectangle in screen space.
        /// </summary>
        /// <param name="model">the model to draw.</param>
        /// <returns>a rectangle in screen space.</returns>
        public Rect CalculateDiagramBounds(IChemModel model)
        {
            var moleculeSet = model.MoleculeSet;
            var reactionSet = model.ReactionSet;

            if ((moleculeSet == null && reactionSet == null))
            {
                return(Rect.Empty);
            }

            var moleculeBounds = Rect.Empty;
            var reactionBounds = Rect.Empty;

            if (moleculeSet != null)
            {
                moleculeBounds = BoundsCalculator.CalculateBounds(moleculeSet);
            }
            if (reactionSet != null)
            {
                reactionBounds = BoundsCalculator.CalculateBounds(reactionSet);
            }

            if (moleculeBounds.IsEmpty)
            {
                return(this.CalculateScreenBounds(reactionBounds));
            }
            else if (reactionBounds.IsEmpty)
            {
                return(this.CalculateScreenBounds(moleculeBounds));
            }
            else
            {
                var allbounds = Rect.Union(moleculeBounds, reactionBounds);
                return(this.CalculateScreenBounds(allbounds));
            }
        }