Esempio n. 1
0
        /// <summary>
        /// Renders the specified drawing.
        /// </summary>
        /// <param name="drawing">The drawing.</param>
        public void Render(SvgDrawing drawing)
        {
            // Draw all components
            foreach (var c in _components)
            {
                drawing.StartGroup(c.Value.Name, c.Value.GetType().Name.ToLower());
                c.Value.Render(drawing);
                drawing.EndGroup();
            }

            // Draw wires
            var drawn = new HashSet <Wire>();

            foreach (var wire in _wires)
            {
                wire.Render(drawn, drawing);
                drawn.Add(wire);
            }
        }
Esempio n. 2
0
        /// <inheritdoc />
        public Bounds Format(SvgDrawing drawing, XmlElement element)
        {
            string text = null;

            using (var sw = new StringWriter())
            {
                using (var w = XmlWriter.Create(sw, new XmlWriterSettings()
                {
                    OmitXmlDeclaration = true
                }))
                {
                    element.WriteTo(w);
                };
                text = sw.ToString();
            }

            // Make a piece of XML that allows measuring this element
            if (element.Name != "svg")
            {
                XmlNode elt = element.ParentNode;
                while (elt != null)
                {
                    text = Enclose(elt, text);
                    elt  = elt.ParentNode;
                    if (elt.Name == "svg")
                    {
                        break;
                    }
                }
                text = $"<svg class=\"simplecircuit\" xmlns=\"http://www.w3.org/2000/svg\">{text}</svg>";
            }

            // Get the result from the browser
            var task = _browser.EvaluateScriptAsync("calculateBounds", text);

            task.Wait();
            dynamic result = task.Result.Result;

            return(new Bounds(result.x, result.y, result.x + result.width, result.y + result.height));
        }
Esempio n. 3
0
        /// <summary>
        /// Renders the circuit.
        /// </summary>
        /// <param name="style">The style sheet information.</param>
        /// <returns>The circuit.</returns>
        public XmlDocument Render()
        {
            if (!Solved)
            {
                Solve();
            }

            // Create our drawing
            var drawing = new SvgDrawing
            {
                Style               = Style,
                LineHeight          = LineHeight,
                UpperCharacterWidth = UpperCharacterWidth,
                LowerCharacterWidth = LowerCharacterWidth
            };

            // Draw
            Render(drawing);

            // Return the XML document
            return(drawing.GetDocument());
        }