Exemple #1
0
        /// <summary>
        /// Generate a LineElement or an ElementGroup of LineElements for this bond.
        /// This version should be used if you want to override the type - for
        /// example, for ring double bonds.
        /// </summary>
        /// <param name="bond">the bond to generate for</param>
        /// <param name="type">the type of the bond - single, double, etc</param>
        /// <param name="model">the renderer model</param>
        /// <returns>one or more rendering elements</returns>
        public virtual IRenderingElement GenerateBondElement(IBond bond, BondOrder type, RendererModel model)
        {
            // More than 2 atoms per bond not supported by this module
            if (bond.Atoms.Count > 2)
            {
                return(null);
            }

            // is object right? if not replace with a good one
            Vector2 point1       = bond.Begin.Point2D.Value;
            Vector2 point2       = bond.End.Point2D.Value;
            Color   color        = this.GetColorForBond(bond, model);
            double  bondWidth    = this.GetWidthForBond(bond, model);
            double  bondDistance = model.GetBondDistance() / model.GetScale();

            if (type == BondOrder.Single)
            {
                return(new LineElement(ToPoint(point1), ToPoint(point2), bondWidth, color));
            }
            else
            {
                ElementGroup group = new ElementGroup();
                switch (type)
                {
                case BondOrder.Double:
                    CreateLines(point1, point2, bondWidth, bondDistance, color, group);
                    break;

                case BondOrder.Triple:
                    CreateLines(point1, point2, bondWidth, bondDistance * 2, color, group);
                    group.Add(new LineElement(ToPoint(point1), ToPoint(point2), bondWidth, color));
                    break;

                case BondOrder.Quadruple:
                    CreateLines(point1, point2, bondWidth, bondDistance, color, group);
                    CreateLines(point1, point2, bondWidth, bondDistance * 4, color, group);
                    break;

                default:
                    break;
                }
                return(group);
            }
        }