Esempio n. 1
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            drawingContext.DrawRectangle(whiteBrush, null, new Rect(0, 0, this.ActualWidth, this.ActualHeight));

            if (this.Ramp == null)
            {
                return;
            }

            double width  = this.Ramp.Rails.Cast <RailRampItem>().Sum(r => r.Length);
            double height = this.Ramp.LayerHeigh;

            var transform = new TransformGroup();

            transform.Children.Add(new ScaleTransform(this.factor, this.factor));
            //transform.Children.Add(new TranslateTransform(0, height));
            drawingContext.PushTransform(transform);

            drawingContext.DrawLine(bluePen, new Point(0, 0), new Point(width, 0));
            drawingContext.DrawLine(redPen, new Point(0, height), new Point(width, height));

            try
            {
                //drawingContext.DrawRectangle(null, blackPen, new Rect(10, 10, width-20, height-20));
                Point from = new Point(0, height);
                Point to   = new Point(0, 0);
                foreach (var item in this.Ramp.Rails.Cast <RailRampItem>())
                {
                    //var p = new Point(item.Length, 0);
                    //p = p.Rotate(item.Gradient);
                    double dh = Gradient.CalcHeight(item.Gradient, item.Length);
                    to = from + new Vector(item.Length, -dh);

                    drawingContext.DrawLine(blackPen, from, to);

                    double perc = Gradient.AngleToPercent(item.Gradient);

                    Point pos = new Point(from.X + item.Length / 2, height);
                    drawingContext.DrawText(new FormattedText($"{perc:F2}%", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 12 / this.factor, blackBrush, 1.25), pos);
                    drawingContext.DrawText(new FormattedText($"{item.Gradient:F2}°", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 12 / this.factor, blackBrush, 1.25), pos + new Vector(0, 12 / this.factor));
                    drawingContext.DrawText(new FormattedText($"{dh:F2}mm", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 12 / this.factor, blackBrush, 1.25), pos + new Vector(0, 24 / this.factor));
                    drawingContext.DrawText(new FormattedText($"{item.Length:F2}mm", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 12 / this.factor, blackBrush, 1.25), pos + new Vector(0, 36 / this.factor));



                    from = to;

                    drawingContext.DrawEllipse(null, blackPen, from, 5, 5);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }


            drawingContext.Pop();
        }
Esempio n. 2
0
        public void AngleToPercentTestMethod()
        {
            double d0  = Math.Round(Gradient.AngleToPercent(0.0), 2);
            double d1  = Math.Round(Gradient.AngleToPercent(1.0), 2);
            double d2  = Math.Round(Gradient.AngleToPercent(2.0), 2);
            double d7  = Math.Round(Gradient.AngleToPercent(7.5), 2);
            double d15 = Math.Round(Gradient.AngleToPercent(15.0), 2);
            double d30 = Math.Round(Gradient.AngleToPercent(30.0), 2);
            double d45 = Math.Round(Gradient.AngleToPercent(45.0), 2);

            Assert.AreEqual(0, d0, "d0");
            Assert.AreEqual(1.75, d1, "d1");
            Assert.AreEqual(3.49, d2, "d2");
            Assert.AreEqual(13.17, d7, "d7");
            Assert.AreEqual(26.79, d15, "d15");
            Assert.AreEqual(57.74, d30, "d30");
            Assert.AreEqual(100.0, d45, "d45");
        }