private void DrawSwitch(SvgDrawing drawing, bool t1, bool t2, bool swapped)
            {
                // Wires
                drawing.Path(b => b.MoveTo(-8, 0).LineTo(-6, 0)
                             .MoveTo(6, 4).LineTo(8, 4)
                             .MoveTo(6, -4).LineTo(8, -4), new("wire"));

                // Terminals
                drawing.Circle(new(-5, 0), 1);
                drawing.Circle(new(5, 4), 1);
                drawing.Circle(new(5, -4), 1);

                // Switch position
                if (!t1 && !t2)
                {
                    drawing.Line(new(-4, 0), new(5, 0));
                }
                else if (t1)
                {
                    drawing.Line(new(-4, 0), new(4, swapped ? -4 : 4));
                }
                else
                {
                    drawing.Line(new(-4, 0), new(4, swapped ? 4 : -4));
                }

                // Label
                if (!string.IsNullOrWhiteSpace(Label))
                {
                    drawing.Text(Label, new(-6, 6), new(-1, 1));
                }
            }
 private void DrawCooking(SvgDrawing drawing)
 {
     DrawBox(drawing, 8, 0, 16, 16);
     drawing.Circle(new(4, -4), 2, new("dot"));
     drawing.Circle(new(12, -4), 2, new("dot"));
     drawing.Circle(new(12, 4), 2, new("dot"));
 }
Exemple #3
0
 private void DrawIEC(SvgDrawing drawing)
 {
     drawing.Polygon(new Vector2[]
     {
         new(-6, -3), new(6, -3),
         new(6, 3), new(-6, 3)
     });
Exemple #4
0
 async Task LoadDrawing(ICanvasResourceCreator resourceCreator)
 {
     var svgDocument = await XmlDocument.LoadFromFileAsync(wantedSvgFile, new XmlLoadSettings() { ProhibitDtd = false });
     svgDrawing = await SvgDrawing.LoadAsync(resourceCreator, svgDocument);
     loadedSvgFile = wantedSvgFile;
     canvas.Invalidate();
 }
Exemple #5
0
            private void DrawPackaged(SvgDrawing drawing)
            {
                // Wires
                if (Pins[0].Connections == 0)
                {
                    drawing.Line(new(-5, 0), new(-8, 0), new("wire"));
                }
                if (Pins[1].Connections == 0)
                {
                    drawing.Line(new(0, 6), new(0, 8), new("wire"));
                }
                if (Pins[3].Connections == 0)
                {
                    drawing.Line(new(5, 0), new(8, 0), new("wire"));
                }

                // Gate
                drawing.Path(b => b.MoveTo(-6, 6).LineTo(6, 6)
                             .MoveTo(-7, 4).LineTo(-4, 4)
                             .MoveTo(-2, 4).LineTo(2, 4)
                             .MoveTo(4, 4).LineTo(7, 4), new("gate"));

                // Drain, source and gate
                drawing.Line(new(-5, 0), new(-5, 4), new("source"));
                drawing.Line(new(5, 0), new(5, 4), new("drain"));
                drawing.Polyline(new Vector2[] { new(-5, 0), new(0, 0), new(0, 4) }, new("bulk") { EndMarker = Drawing.PathOptions.MarkerTypes.Arrow });
Exemple #6
0
        /// <inheritdoc/>
        protected override void Draw(SvgDrawing drawing)
        {
            drawing.Segments(new[]
            {
                new Vector2(0, 11), new Vector2(0, 9),
                new Vector2(-6, 6), new Vector2(6, 6),
                new Vector2(-6, 4), new Vector2(6, 4)
            });
            drawing.Circle(new Vector2(0, 7.5), 1.5);

            drawing.Polyline(new[] { new Vector2(-8, 0), new Vector2(-4, 0), new Vector2(-4, 4) });
            drawing.Polyline(new[] { new Vector2(8, 0), new Vector2(4, 0), new Vector2(4, 4) });

            if (Pins.IsUsed("b"))
            {
                drawing.Line(new Vector2(0, 4), new Vector2(0, 0));
                if (!string.IsNullOrEmpty(Label))
                {
                    drawing.Text(Label, new Vector2(-3, -3), new Vector2(-1, -1));
                }
            }
            else if (!string.IsNullOrEmpty(Label))
            {
                drawing.Text(Label, new Vector2(0, -3), new Vector2(0, -1));
            }
        }
Exemple #7
0
        /// <inheritdoc/>
        protected override void Draw(SvgDrawing drawing)
        {
            drawing.Polyline(new Vector2[]
            {
                new Vector2(-8, 0),
                new Vector2(-6, 0),
                new Vector2(-5, -4),
                new Vector2(-3, 4),
                new Vector2(-1, -4),
                new Vector2(1, 4),
                new Vector2(3, -4),
                new Vector2(5, 4),
                new Vector2(6, 0),
                new Vector2(8, 0)
            });

            if (Pins.IsUsed("c"))
            {
                drawing.Line(new Vector2(0, 4), new Vector2(0, 8));
                drawing.Polygon(new[]
                {
                    new Vector2(0, 4), new Vector2(-1, 7), new Vector2(1, 7)
                });
            }

            // Depending on the orientation, let's anchor the text differently
            if (!string.IsNullOrWhiteSpace(Label))
            {
                drawing.Text(Label, new Vector2(0, -7), new Vector2(0, -1));
            }
        }
Exemple #8
0
 private void DrawLabel(SvgDrawing drawing)
 {
     if (!string.IsNullOrWhiteSpace(Label))
     {
         drawing.Text(Label, new(0, 4), new(0, 1));
     }
 }
Exemple #9
0
            /// <inheritdoc />
            private void DrawInductor(SvgDrawing drawing)
            {
                // Wires
                if (Pins[0].Connections == 0)
                {
                    drawing.Line(new(-6, 0), new(-8, 0), new("wire"));
                }
                if (Pins[1].Connections == 0)
                {
                    drawing.Line(new(6, 0), new(8, 0), new("wire"));
                }

                // Inductor
                drawing.Path(b => b
                             .MoveTo(-6, 0)
                             .CurveTo(new(-6, -4), new(-2, -4), new(-2, 0))
                             .SmoothTo(new(-4, 4), new(-4, 0))
                             .SmoothTo(new(1, -4), new(1, 0))
                             .SmoothTo(new(-1, 4), new(-1, 0))
                             .SmoothTo(new(4, -4), new(4, 0))
                             .SmoothTo(new(2, 4), new(2, 0))
                             .SmoothTo(new(6, -4), new(6, 0)));

                // Label
                if (!string.IsNullOrWhiteSpace(Label))
                {
                    drawing.Text(Label, new Vector2(0, -6), new Vector2(0, -1));
                }
            }
Exemple #10
0
            private void Draw(SvgDrawing drawing, bool straight)
            {
                drawing.Line(new(-Crossings - 2, 0), new(Crossings + 2, 0), new("wire"));
                if (Crossings > 0)
                {
                    drawing.Path(b =>
                    {
                        for (int i = 0; i < Crossings; i++)
                        {
                            double x = i * 2 - Crossings + 1;
                            if (straight)
                            {
                                b.MoveTo(x, 3).Line(0, -6);
                            }
                            else
                            {
                                b.MoveTo(x - 1.5, 3).Line(3, -6);
                            }
                        }
                    });
                }

                // The label
                if (!string.IsNullOrWhiteSpace(Label))
                {
                    drawing.Text(Label, new(0, -4), new(0, -1));
                }
            }
Exemple #11
0
        /// <inheritdoc/>
        protected override void Draw(SvgDrawing drawing)
        {
            drawing.Polyline(new[] {
                new Vector2(-8, -8),
                new Vector2(8, 0),
                new Vector2(-8, 8),
                new Vector2(-8, -8)
            });
            drawing.Segments(new[]
            {
                // Plus
                new Vector2(-6, -4), new Vector2(-4, -4),

                // Minus
                new Vector2(-5, 5), new Vector2(-5, 3),
                new Vector2(-6, 4), new Vector2(-4, 4)
            });

            if (Pins.IsUsed("vn"))
            {
                drawing.Line(new Vector2(0, -4), new Vector2(0, -6));
            }
            if (Pins.IsUsed("vp"))
            {
                drawing.Line(new Vector2(0, 4), new Vector2(0, 6));
            }

            if (!string.IsNullOrWhiteSpace(Label))
            {
                drawing.Text(Label, new Vector2(5, 5), new Vector2(1, 1));
            }
        }
 private void DrawFreezer(SvgDrawing drawing)
 {
     DrawBox(drawing, 14, 0, 28, 16);
     DrawIce(drawing, 5, 0, 3.5);
     DrawIce(drawing, 14, 0, 3.5);
     DrawIce(drawing, 23, 0, 3.5);
 }
 private void DrawSpeaker(SvgDrawing drawing)
 {
     drawing.Polygon(new Vector2[]
     {
         new(-2, -4), new(2, -4),
         new(2, 4), new(-2, 4)
     });
Exemple #14
0
        /// <inheritdoc />
        protected override void Draw(SvgDrawing drawing)
        {
            var normal = new Vector2(NormalX.Value, NormalY.Value);
            var tf     = new Transform(X.Value, Y.Value, normal, normal.Perpendicular * Scale.Value);

            drawing.Polygon(new[]
            {
                new Vector2(-8, 11), new Vector2(8, 11),
                new Vector2(8, -11), new Vector2(-8, -11)
            });
            drawing.Polyline(new[]
            {
                new Vector2(-8, -4), new Vector2(-6, -6), new Vector2(-8, -8)
            });

            drawing.Text("D", new Vector2(-7, 5.5), new Vector2(1, 0), 3, 0.5);
            drawing.Text("C", new Vector2(-5, -5.5), new Vector2(1, 0), 3, 0.5);
            drawing.Text("Q", new Vector2(7, 5.5), new Vector2(-1, 0), 3, 0.5);
            if (Pins.IsUsed("nq"))
            {
                drawing.Text("NQ", new Vector2(7, -5.5), new Vector2(-1, 0), 3, 0.5);
            }
            if (!string.IsNullOrWhiteSpace(Label))
            {
                drawing.Text(Label, new Vector2(10, 8), new Vector2(1, 1));
            }
        }
Exemple #15
0
        public static async Task <TestDisplayData> CreateAsync(SvgTest test)
        {
            var data = new TestDisplayData(test);

            var device = CanvasDevice.GetSharedDevice(false);

            data.ReferencePng = await DownloadPng(device, new Uri(test.ReferencePngUri));

            var svgFile = await CachedData.GetStorageFileAsync(new Uri(test.SvgUri));

            var svgDocument = await XmlDocument.LoadFromFileAsync(svgFile, new XmlLoadSettings()
            {
                ProhibitDtd = false
            });

            data.Drawing = await SvgDrawing.LoadAsync(device, svgDocument);

            var description = svgDocument.SelectSingleNodeNS("//d:testDescription", "xmlns:d='http://www.w3.org/2000/02/svg/testsuite/description/'");

            if (description != null)
            {
                data.Description = description.InnerText;
            }

            return(data);
        }
Exemple #16
0
        /// <inheritdoc />
        protected override void Draw(SvgDrawing drawing)
        {
            drawing.Segments(new[]
            {
                new Vector2(-8, 0), new Vector2(-6, 0),
                new Vector2(6, 4), new Vector2(8, 4),
                new Vector2(6, -4), new Vector2(8, -4)
            });
            drawing.Circle(new Vector2(-5, 0), 1);
            drawing.Circle(new Vector2(5, 4), 1);
            drawing.Circle(new Vector2(5, -4), 1);

            if (Throw.IsZero())
            {
                drawing.Line(new Vector2(-4, 0), new Vector2(5, 0));
            }
            else if (Throw > 0)
            {
                drawing.Line(new Vector2(-4, 0), new Vector2(4, 4));
            }
            else
            {
                drawing.Line(new Vector2(-4, 0), new Vector2(4, -4));
            }

            if (Pins.IsUsed("c"))
            {
                drawing.Line(new Vector2(0, 2), new Vector2(0, 6));
            }
        }
Exemple #17
0
            private void DrawInputSigns(SvgDrawing drawing)
            {
                double x = -Width / 2 + 3;
                double y = Height / 4;

                drawing.Signs(new(x, -y), new(x, y));
            }
Exemple #18
0
            private void DrawSource(SvgDrawing drawing)
            {
                // Wires
                drawing.Path(b => b.MoveTo(-8, 0).LineTo(-6, 0).MoveTo(6, 0).LineTo(8, 0), new("wire"));

                // The circle with the arrow
                drawing.Circle(new(0, 0), 6);
                drawing.Line(new(-3, 0), new(3, 0), new("arrow") { EndMarker = Drawing.PathOptions.MarkerTypes.Arrow });
Exemple #19
0
 /// <inheritdoc/>
 protected override void Draw(SvgDrawing drawing)
 {
     drawing.Line(new Vector2(0, 0), new Vector2(0, 3));
     drawing.Polygon(new[]
     {
         new Vector2(-5, 3), new Vector2(5, 3), new Vector2(0, 7)
     });
 }
        /// <inheritdoc/>
        public override void Render(SvgDrawing drawing)
        {
            var normal = new Vector2(NormalX.Value, NormalY.Value);

            drawing.BeginTransform(new Transform(X.Value, Y.Value, normal, normal.Perpendicular));
            Draw(drawing);
            drawing.EndTransform();
        }
Exemple #21
0
            private void DrawGround(SvgDrawing drawing)
            {
                // Wire
                drawing.Line(new(0, 0), new(0, 3), new("wire"));

                // Ground
                drawing.Path(b => b.MoveTo(-5, 3).LineTo(5, 3).MoveTo(-3, 5).LineTo(3, 5).MoveTo(-1, 7).LineTo(1, 7));
            }
Exemple #22
0
 /// <inheritdoc/>
 protected override void Draw(SvgDrawing drawing)
 {
     drawing.Line(new Vector2(), new Vector2(-4, 0));
     drawing.Circle(new Vector2(-5.5, 0), 1.5, "terminal");
     if (!string.IsNullOrWhiteSpace(Label))
     {
         drawing.Text(Label, new Vector2(-10, 0), new Vector2(-1, 0));
     }
 }
Exemple #23
0
 /// <inheritdoc/>
 protected override void Draw(SvgDrawing drawing)
 {
     drawing.Line(new Vector2(0, 0), new Vector2(0, -3));
     drawing.Line(new Vector2(-5, -3), new Vector2(5, -3), "plane");
     if (!string.IsNullOrWhiteSpace(Label))
     {
         drawing.Text(Label, new Vector2(0, -6), new Vector2(0, -1));
     }
 }
 private void DrawOTA(SvgDrawing drawing)
 {
     // The triangle
     drawing.Polygon(new Vector2[] {
         new(-5, -9),
         new(5, -5),
         new(5, 5),
         new(-5, 9)
     });
 private void DrawTerminal(SvgDrawing drawing)
 {
     drawing.Line(new Vector2(), new Vector2(-4, 0), new("wire"));
     drawing.Circle(new Vector2(-5.5, 0), 1.5, new("terminal"));
     if (!string.IsNullOrWhiteSpace(Label))
     {
         drawing.Text(Label, new Vector2(-10, 0), new Vector2(-1, 0));
     }
 }
Exemple #26
0
 private void DrawAnd(SvgDrawing drawing)
 {
     drawing.Path(builder => builder
                  .MoveTo(new(-6, 5)).Line(new(7, 0))
                  .Curve(new(3, 0), new(5, -3), new(5, -5))
                  .Smooth(new(-2, -5), new(-5, -5))
                  .Line(new(-7, 0)).Close()
                  );
 }
Exemple #27
0
 private void DrawRegular(SvgDrawing drawing)
 {
     drawing.OpenBezier(new Vector2[]
     {
         new(-4, -2),
         new(-2, -4.5),
         new(2, -4.5),
         new(4, -2)
     });
 private void DrawBox(SvgDrawing drawing, double cx, double cy, double width, double height)
 {
     width  /= 2.0;
     height /= 2.0;
     drawing.Polygon(new Vector2[]
     {
         new(cx - width, cy - height), new(cx + width, cy - height),
         new(cx + width, cy + height), new(cx - width, cy + height)
     });
Exemple #29
0
            /// <inheritdoc/>
            private void DrawSource(SvgDrawing drawing)
            {
                // Wires
                drawing.Path(b => b.MoveTo(-8, 0).LineTo(-6, 0).MoveTo(6, 0).LineTo(8, 0), new("wire"));

                // Diamond
                drawing.Polygon(new Vector2[]
                {
                    new(-6, 0), new(0, 6), new(6, 0), new(0, -6)
                });
            private void DrawMic(SvgDrawing drawing)
            {
                drawing.Circle(new(), 4);
                drawing.Line(new(4, -4), new(4, 4), new("plane"));

                if (!string.IsNullOrWhiteSpace(Label))
                {
                    drawing.Text(Label, new(-6, 0), new(-1, 0));
                }
            }
        /// <inheritdoc />
        public Bounds Format(SvgDrawing drawing, XmlElement element)
        {
            double w = 0;

            foreach (var c in element.InnerText)
            {
                w += char.IsLower(c) ? LowerCharacterWidth : UpperCharacterWidth;
            }
            return(new(0, -Size * (1 - MidLineFactor), w *Size, Size *MidLineFactor));
        }
Exemple #32
0
        private async void OnLoad(object sender, RoutedEventArgs e)
        {
            var picker = new FileOpenPicker();
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".svg");

            var pickedFile = await picker.PickSingleFileAsync();
            if (pickedFile != null)
            {
                wantedSvgFile = pickedFile;
                svgDrawing = null;
                canvas.Invalidate();
            }
        }