Example #1
0
        private void DrawPath(ReticlePath path)
        {
            using var canvasPath = mCanvas.CreatePath();
            foreach (var pathElement in path.Elements)
            {
                switch (pathElement)
                {
                case ReticlePathElementMoveTo moveTo:
                {
                    mTranslator.Transform(moveTo.Position.X, moveTo.Position.Y, out float x, out float y);
                    canvasPath.MoveTo(x, y);
                }
                break;

                case ReticlePathElementLineTo lineTo:
                {
                    mTranslator.Transform(lineTo.Position.X, lineTo.Position.Y, out float x, out float y);
                    canvasPath.LineTo(x, y);
                }
                break;

                case ReticlePathElementArc arc:
                {
                    mTranslator.Transform(arc.Position.X, arc.Position.Y, out float x, out float y);
                    canvasPath.Arc(mTranslator.TransformL(arc.Radius), x, y, arc.MajorArc, arc.ClockwiseDirection);
                }
                break;
                }
            }
            if (path.Fill ?? false)
            {
                canvasPath.Close();
            }
            mCanvas.Path(canvasPath, mTranslator.TransformL(path.LineWidth), path.Fill ?? false, path.Color ?? "black");
        }
        public void ClonePath()
        {
            var p1 = new ReticlePath()
            {
                Color     = "color",
                LineWidth = AngularUnit.Mil.New(0.5),
                Fill      = true,
            };

            p1.Elements.Add(new ReticlePathElementMoveTo()
            {
                Position = new ReticlePosition(1, 2, AngularUnit.Mil)
            });
            p1.Elements.Add(new ReticlePathElementLineTo()
            {
                Position = new ReticlePosition(3, 4, AngularUnit.Mil)
            });
            p1.Elements.Add(new ReticlePathElementArc()
            {
                Position = new ReticlePosition(5, 6, AngularUnit.Mil), ClockwiseDirection = true, MajorArc = true, Radius = AngularUnit.Mil.New(0.25)
            });

            var p2 = p1.Clone() as ReticlePath;

            p2.Should().Be(p1);

            for (int i = 0; i < p1.Elements.Count; i++)
            {
                ShouldHavePositionsDifferent(p1.Elements[i], p2.Elements[i]);
            }
        }
        public void RoundTripPath()
        {
            var path = new ReticlePath()
            {
                Fill      = true,
                Color     = "red",
                LineWidth = AngularUnit.MOA.New(5),
            };

            path.Elements.Add(new ReticlePathElementMoveTo()
            {
                Position = new ReticlePosition()
                {
                    X = AngularUnit.MOA.New(10), Y = AngularUnit.MOA.New(20)
                }
            });
            path.Elements.Add(new ReticlePathElementLineTo()
            {
                Position = new ReticlePosition()
                {
                    X = AngularUnit.MOA.New(15), Y = AngularUnit.MOA.New(25)
                }
            });
            path.Elements.Add(new ReticlePathElementArc()
            {
                Position = new ReticlePosition()
                {
                    X = AngularUnit.MOA.New(25), Y = AngularUnit.MOA.New(35)
                },
                Radius             = AngularUnit.MOA.New(5),
                ClockwiseDirection = false,
                MajorArc           = false
            });

            SerializerRoundtrip serializer = new SerializerRoundtrip();
            var xml   = serializer.Serialize(path);
            var path2 = serializer.Deserialize <ReticlePath>(xml);

            path2.Should().NotBeNull();
            path2.Fill.Should().BeTrue();
            path2.Color.Should().Be("red");
            path2.LineWidth.Should().Be(AngularUnit.MOA.New(5));

            path2.Elements.Should().HaveCount(3);
            path2.Elements[0].ElementType.Should().Be(ReticlePathElementType.MoveTo);
            path2.Elements[0].As <ReticlePathElementMoveTo>().Position.X.Should().Be(AngularUnit.MOA.New(10));
            path2.Elements[0].As <ReticlePathElementMoveTo>().Position.Y.Should().Be(AngularUnit.MOA.New(20));

            path2.Elements[1].ElementType.Should().Be(ReticlePathElementType.LineTo);
            path2.Elements[1].As <ReticlePathElementLineTo>().Position.X.Should().Be(AngularUnit.MOA.New(15));
            path2.Elements[1].As <ReticlePathElementLineTo>().Position.Y.Should().Be(AngularUnit.MOA.New(25));

            path2.Elements[2].ElementType.Should().Be(ReticlePathElementType.Arc);
            path2.Elements[2].As <ReticlePathElementArc>().Position.X.Should().Be(AngularUnit.MOA.New(25));
            path2.Elements[2].As <ReticlePathElementArc>().Position.Y.Should().Be(AngularUnit.MOA.New(35));
            path2.Elements[2].As <ReticlePathElementArc>().Radius.Should().Be(AngularUnit.MOA.New(5));
            path2.Elements[2].As <ReticlePathElementArc>().ClockwiseDirection.Should().BeFalse();
            path2.Elements[2].As <ReticlePathElementArc>().MajorArc.Should().BeFalse();
        }
 public EditPathForm(ReticlePath path, ReticleDefinition reticle)
 {
     Path    = path;
     Copy    = path.Clone() as ReticlePath;
     Reticle = reticle;
     InitializeComponent();
     Setup();
 }
Example #5
0
        public void Path1()
        {
            ReticlePath p = new ReticlePath()
            {
                LineWidth = AngularUnit.Mil.New(10),
                Color     = "red",
                Fill      = true,
            };

            p.Elements.Add(new ReticlePathElementMoveTo()
            {
                Position = new ReticlePosition(1.23, 5.54, AngularUnit.MOA)
            });
            p.Elements.Add(new ReticlePathElementLineTo()
            {
                Position = new ReticlePosition(7.8, 8.9, AngularUnit.MOA)
            });

            p.ToString().Should().Be("Path(w=10mil,c=red,f=true,[M(1.23moa:5.54moa),L(7.8moa:8.9moa)])");
        }
Example #6
0
        public void Path(double x11, double y11, double x12, double y12, double?lw1, AngularUnit u1, string color1, bool?fill1,
                         double x21, double y21, double x22, double y22, double?lw2, AngularUnit u2, string color2, bool?fill2,
                         bool equals)
        {
            var e1 = new ReticlePath()
            {
                LineWidth = lw1 == null ? null : u1.New(lw1.Value),
                Color     = color1,
                Fill      = fill1
            };

            e1.Elements.Add(new ReticlePathElementMoveTo()
            {
                Position = new ReticlePosition(x11, y11, u1)
            });
            e1.Elements.Add(new ReticlePathElementLineTo()
            {
                Position = new ReticlePosition(x12, y12, u1)
            });

            var e2 = new ReticlePath()
            {
                LineWidth = lw2 == null ? null : u1.New(lw2.Value),
                Color     = color2,
                Fill      = fill2
            };

            e2.Elements.Add(new ReticlePathElementMoveTo()
            {
                Position = new ReticlePosition(x21, y21, u2)
            });
            e2.Elements.Add(new ReticlePathElementLineTo()
            {
                Position = new ReticlePosition(x22, y22, u2)
            });

            e1.Equals(e2).Should().Be(equals);
            e2.Equals(e1).Should().Be(equals);
        }
        public void Parameters_Preview_Then_Close()
        {
            MilDotReticle mildot = new MilDotReticle();

            ReticlePath path = new ReticlePath()
            {
                LineWidth = AngularUnit.MOA.New(0.1),
                Color     = "black",
                Fill      = true
            };

            EditPathForm form = new EditPathForm(path, mildot);

            form.MeasurementControl("measurementWidth").Should().HaveValue(path.LineWidth.Value);
            form.ComboBox("comboBoxColor").Should().HaveText(path.Color);
            form.CheckBox("checkBoxFill").Should().BeChecked();

            form.MeasurementControl("measurementWidth").Value = AngularUnit.MOA.New(21);
            form.ComboBox("comboBoxColor").Text   = "aqua";
            form.CheckBox("checkBoxFill").Checked = false;

            path.LineWidth.Should().NotBe(AngularUnit.MOA.New(21));
            path.Color.Should().NotBe("aqua");
            path.Fill.Should().NotBeFalse();

            form.Save();

            path.LineWidth.Should().Be(AngularUnit.MOA.New(21));
            path.Color.Should().Be("aqua");
            path.Fill.Should().BeFalse();

            form.Close();
            form.EditPathForm_FormClosed(this, new FormClosedEventArgs(CloseReason.UserClosing));
            form.Dispose();

            path.LineWidth.Should().Be(AngularUnit.MOA.New(0.1));
            path.Color.Should().Be("black");
            path.Fill.Should().BeTrue();
        }
Example #8
0
        private static void TestShapes()
        {
            var reticle = new ReticleDefinition()
            {
                Name = "Test",
                Size = new ReticlePosition(10, 10, AngularUnit.Mil),
                Zero = new ReticlePosition(5, 5, AngularUnit.Mil)
            };

            //test path 1
            var path = new ReticlePath()
            {
                Color = "red",
                Fill  = true,
            };

            path.Elements.Add(new ReticlePathElementMoveTo()
            {
                Position = new ReticlePosition(-2.5, 0, AngularUnit.Mil),
            });

            path.Elements.Add(new ReticlePathElementLineTo()
            {
                Position = new ReticlePosition(0, 1, AngularUnit.Mil),
            });

            path.Elements.Add(new ReticlePathElementLineTo()
            {
                Position = new ReticlePosition(2.5, 0, AngularUnit.Mil),
            });

            path.Elements.Add(new ReticlePathElementArc()
            {
                Position           = new ReticlePosition(-2.5, 0, AngularUnit.Mil),
                ClockwiseDirection = false,
                MajorArc           = true,
                Radius             = AngularUnit.Mil.New(2.5)
            });

            reticle.Elements.Add(path);

            reticle.Elements.Add(new ReticleLine()
            {
                Start     = new ReticlePosition(-1, 0, AngularUnit.Mil),
                End       = new ReticlePosition(1, 0, AngularUnit.Mil),
                LineWidth = AngularUnit.Mil.New(0.1),
                Color     = "blue",
            });

            reticle.Elements.Add(new ReticleLine()
            {
                Start     = new ReticlePosition(0, -1, AngularUnit.Mil),
                End       = new ReticlePosition(0, 1, AngularUnit.Mil),
                LineWidth = AngularUnit.Mil.New(0.1),
                Color     = "blue",
            });

            reticle.Elements.Add(new ReticleText()
            {
                Position   = new ReticlePosition(0, 0, AngularUnit.Mil),
                TextHeight = AngularUnit.Mil.New(0.25),
                Color      = "black",
                Text       = "Test Text",
            });

            Draw(reticle, "test");
        }
Example #9
0
        public void Path2()
        {
            ReticlePath p = new ReticlePath();

            p.ToString().Should().Be("Path(w=null,c=null,f=null)");
        }
        public void ReticleElement_Path()
        {
            var canvas  = CreateMockCanvas();
            var reticle = CreateReticle();

            var reticlePath = new ReticlePath()
            {
                Color = "red",
                Fill  = true,
            };

            reticlePath.Elements.Add(new ReticlePathElementMoveTo()
            {
                Position = new ReticlePosition(-2.5, 0, AngularUnit.Mil),
            });

            reticlePath.Elements.Add(new ReticlePathElementLineTo()
            {
                Position = new ReticlePosition(0, 1, AngularUnit.Mil),
            });

            reticlePath.Elements.Add(new ReticlePathElementLineTo()
            {
                Position = new ReticlePosition(2.5, 0, AngularUnit.Mil),
            });

            reticlePath.Elements.Add(new ReticlePathElementArc()
            {
                Position           = new ReticlePosition(-2.5, 0, AngularUnit.Mil),
                ClockwiseDirection = false,
                MajorArc           = true,
                Radius             = AngularUnit.Mil.New(2.5)
            });

            reticle.Elements.Add(reticlePath);

            int order = 0;

            var canvasPath = new Mock <IReticleCanvasPath>();

            canvasPath.Setup(
                path => path.MoveTo(
                    It.Is <float>(f => Approximately(f, 2500)),
                    It.Is <float>(f => Approximately(f, 5000))
                    ))
            .Callback(() => (order++).Should().Be(1, "Order of adding path items into path failed"))
            .Verifiable();

            canvasPath.Setup(
                path => path.LineTo(
                    It.Is <float>(f => Approximately(f, 5000)),
                    It.Is <float>(f => Approximately(f, 4000))
                    ))
            .Callback(() => (order++).Should().Be(2, "Order of adding path items into path failed"))
            .Verifiable();

            canvasPath.Setup(
                path => path.LineTo(
                    It.Is <float>(f => Approximately(f, 7500)),
                    It.Is <float>(f => Approximately(f, 5000))
                    ))
            .Callback(() => (order++).Should().Be(3, "Order of adding path items into path failed"))
            .Verifiable();

            canvasPath.Setup(
                path => path.Arc(
                    It.Is <float>(f => Approximately(f, 2500)),
                    It.Is <float>(f => Approximately(f, 2500)),
                    It.Is <float>(f => Approximately(f, 5000)),
                    It.Is <bool>(f => f),
                    It.Is <bool>(f => !f)
                    ))
            .Callback(() => (order++).Should().Be(4, "Order of adding path items into path failed"))
            .Verifiable();

            canvas.Setup(
                canvas => canvas.CreatePath())
            .Returns(canvasPath.Object)
            .Callback(() => (order++).Should().Be(0, "Creating a patch must be first action"))
            .Verifiable();

            canvas.Setup(
                canvas => canvas.Path(
                    It.Is <IReticleCanvasPath>(path => path == canvasPath.Object),
                    It.Is <float>(f => Approximately(f, 1)),
                    It.Is <bool>(f => f),
                    It.Is <string>(s => s == "red")))
            .Callback(() => (order++).Should().Be(5, "Drawing path must be the last action"))
            .Verifiable();

            ReticleDrawController controller = new ReticleDrawController(reticle, canvas.Object);

            controller.DrawReticle();
            canvas.Verify();
            canvasPath.Verify();
        }