Esempio n. 1
0
        private Bounds GenerateReactionConditions(IReaction chemObj, Color fg, double scale)
        {
            var title = chemObj.GetProperty <string>(CDKPropertyName.ReactionConditions);

            if (string.IsNullOrEmpty(title))
            {
                return(new Bounds());
            }
            return(new Bounds(MarkedElement.Markup(StandardGenerator.EmbedText(font, emSize, title, fg, 1 / scale), "conditions")));
        }
Esempio n. 2
0
        /// <summary>
        /// Generate a bound element that is the title of the provided molecule. If title
        /// is not specified an empty bounds is returned.
        /// </summary>
        /// <param name="chemObj">molecule or reaction</param>
        /// <returns>bound element</returns>
        private Bounds GenerateTitle(RendererModel model, IChemObject chemObj, double scale)
        {
            var title = chemObj.GetProperty <string>(CDKPropertyName.Title);

            if (string.IsNullOrEmpty(title))
            {
                return(new Bounds());
            }
            scale = 1 / scale * model.GetTitleFontScale();
            return(new Bounds(MarkedElement.Markup(StandardGenerator.EmbedText(font, emSize, title, model.GetTitleColor(), scale), "title")));
        }
Esempio n. 3
0
        public void MarkedElementTest()
        {
            SvgDrawVisitor visitor = new SvgDrawVisitor(50, 50, Depiction.UnitsMM);

            visitor.Visit(MarkedElement.Markup(new LineElement(new WPF.Point(0, 0), new WPF.Point(1, 1), 0.5, Colors.Red), "test-class"));
            Assert.AreEqual(
                "<?xml version='1.0' encoding='UTF-8'?>\n"
                + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"
                + "<svg version='1.2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='50mm' height='50mm' viewBox='0 0 50 50'>\n"
                + "  <desc>Generated by the Chemistry Development Kit (http://github.com/cdk)</desc>\n"
                + "  <g stroke-linecap='round' stroke-linejoin='round'>\n"
                + "    <line x1='0' y1='0' x2='1' y2='1' stroke='#FF0000' stroke-width='0.5'/>\n"
                + "  </g>\n"
                + "</svg>\n",
                visitor.ToString());
        }
Esempio n. 4
0
        /// <inheritdoc/>
        public IRenderingElement Generate(IAtomContainer container, RendererModel parameters)
        {
            if (container.Atoms.Count == 0)
            {
                return(new ElementGroup());
            }

            var symbolRemap = new Dictionary <IAtom, string>();

            StandardSgroupGenerator.PrepareDisplayShortcuts(container, symbolRemap);

            var scale = parameters.GetScale();

            var visibility      = parameters.GetVisibility();
            var coloring        = parameters.GetAtomColorer();
            var annotationColor = parameters.GetAnnotationColor();
            var foreground      = coloring.GetAtomColor(container.Builder.NewAtom("C"));

            // the stroke width is based on the font. a better method is needed to get
            // the exact font stroke but for now we use the width of the pipe character.
            var fontStroke = new TextOutline("|", font, emSize).Resize(1 / scale, 1 / scale).GetBounds().Width;
            var stroke     = parameters.GetStrokeRatio() * fontStroke;

            var annotations = new ElementGroup();

            var donutGenerator = new StandardDonutGenerator(container, font, emSize, parameters, stroke);
            var donuts         = donutGenerator.Generate();

            var symbols = GenerateAtomSymbols(container, symbolRemap,
                                              visibility, parameters,
                                              annotations, foreground,
                                              stroke, donutGenerator);
            var bondElements = StandardBondGenerator.GenerateBonds(container, symbols,
                                                                   parameters, stroke,
                                                                   font, emSize, annotations,
                                                                   donutGenerator);

            var style     = parameters.GetHighlighting();
            var glowWidth = parameters.GetOuterGlowWidth();

            var backLayer   = new ElementGroup();
            var middleLayer = new ElementGroup();
            var frontLayer  = new ElementGroup();

            // bond elements can simply be added to the element group
            for (int i = 0; i < container.Bonds.Count; i++)
            {
                var bond = container.Bonds[i];

                if (IsHidden(bond))
                {
                    continue;
                }

                var highlight = GetHighlightColor(bond, parameters);
                if (highlight != null && style == HighlightStyle.OuterGlow)
                {
                    backLayer.Add(MarkedElement.Markup(OuterGlow(bondElements[i], highlight.Value, glowWidth, stroke), "outerglow"));
                }
                if (highlight != null && style == HighlightStyle.Colored)
                {
                    frontLayer.Add(MarkedElement.MarkupBond(Recolor(bondElements[i], highlight.Value), bond));
                }
                else
                {
                    middleLayer.Add(MarkedElement.MarkupBond(bondElements[i], bond));
                }
            }

            // bonds for delocalised aromatic
            frontLayer.Add(donuts);

            // convert the atom symbols to IRenderingElements
            for (int i = 0; i < container.Atoms.Count; i++)
            {
                var atom = container.Atoms[i];

                if (IsHidden(atom))
                {
                    continue;
                }

                var highlight = GetHighlightColor(atom, parameters);
                var color     = GetColorOfAtom(symbolRemap, coloring, foreground, style, atom, highlight);

                if (symbols[i] == null)
                {
                    // we add a 'ball' around atoms with no symbols (e.g. carbons)
                    if (highlight != null && style == HighlightStyle.OuterGlow)
                    {
                        backLayer.Add(MarkedElement.Markup(new OvalElement(ToPoint(atom.Point2D.Value), 1.75 * glowWidth * stroke, true, highlight.Value), "outerglow"));
                    }
                    continue;
                }

                var symbolElements = new ElementGroup();
                foreach (var shape in symbols[i].GetOutlines())
                {
                    GeneralPath path = GeneralPath.ShapeOf(shape, color);
                    symbolElements.Add(path);
                }

                // add the annotations of the symbol to the annotations ElementGroup
                foreach (var shape in symbols[i].GetAnnotationOutlines())
                {
                    annotations.Add(MarkedElement.Markup(GeneralPath.ShapeOf(shape, annotationColor), "annotation"));
                }

                if (highlight != null && style == HighlightStyle.OuterGlow)
                {
                    backLayer.Add(MarkedElement.Markup(OuterGlow(symbolElements, highlight.Value, glowWidth, stroke), "outerglow"));
                }

                if (highlight != null && style == HighlightStyle.Colored)
                {
                    frontLayer.Add(MarkedElement.MarkupAtom(symbolElements, atom));
                }
                else
                {
                    middleLayer.Add(MarkedElement.MarkupAtom(symbolElements, atom));
                }
            }

            // Add the Sgroups display elements to the front layer
            var sgroups = StandardSgroupGenerator.Generate(parameters, stroke, font, emSize, foreground, atomGenerator, symbols, container);

            frontLayer.Add(sgroups);

            // Annotations are added to the front layer.
            frontLayer.Add(annotations);

            var group = new ElementGroup
            {
                backLayer,
                middleLayer,
                frontLayer
            };

            return(MarkedElement.MarkupMol(group, container));
        }