public void TestSerialization()
        {
            var line = new LineGeometry { Start = new Point(5.3, 9), End = new Point(7, 8.2)};

            var writer = new StringWriter();
            _serializer.Serialize(writer, line);
            var reader = new StringReader(writer.ToString());

            Assert.AreEqual(line, _serializer.Deserialize(reader));
        }
        private void ChangeDrawingTool(Canvas c, int type, System.Windows.Point current_end = default(System.Windows.Point))
        {
            BrushType = type;
            switch (BrushType)
            {
            case 0:
                arc_mode = false;
                borderL.BorderThickness    = new System.Windows.Thickness(1);
                borderACW.BorderThickness  = new System.Windows.Thickness(0);
                borderAACW.BorderThickness = new System.Windows.Thickness(0);
                break;

            case 1:
                arc_mode  = true;
                clockwise = true;
                borderL.BorderThickness    = new System.Windows.Thickness(0);
                borderACW.BorderThickness  = new System.Windows.Thickness(1);
                borderAACW.BorderThickness = new System.Windows.Thickness(0);
                break;

            case 2:
                arc_mode  = true;
                clockwise = false;
                borderL.BorderThickness    = new System.Windows.Thickness(0);
                borderACW.BorderThickness  = new System.Windows.Thickness(0);
                borderAACW.BorderThickness = new System.Windows.Thickness(1);
                break;
            }
            paintSurface.Children.Remove(current_path);
            current_path = new System.Windows.Shapes.Path();
            SolidColorBrush blackBrush = new SolidColorBrush();

            blackBrush.Color             = Colors.Black;
            current_path.Stroke          = blackBrush;
            current_path.StrokeThickness = 3;
            myGeometryGroup = new GeometryGroup();
            if (arc_mode)
            {
                pathFigure            = new PathFigure();
                current_arc           = new ArcSegment();
                pathFigure.StartPoint = current_origin;
                current_arc.Point     = current_origin;
                if (clockwise)
                {
                    if (expression_strings.Count > 0)
                    {
                        expression_strings[expression_strings.Count - 1] = "A_CW";
                    }

                    current_arc.SweepDirection = SweepDirection.Clockwise;
                }
                else
                {
                    if (expression_strings.Count > 0)
                    {
                        expression_strings[expression_strings.Count - 1] = "A_ACW";
                    }
                    current_arc.SweepDirection = SweepDirection.Counterclockwise;
                }
                PathSegmentCollection PathSegment = new PathSegmentCollection();
                PathSegment.Add(current_arc);
                pathFigure.Segments = PathSegment;
                pathGeometry        = new PathGeometry(new List <PathFigure> {
                    pathFigure
                });
                myGeometryGroup.Children.Add(pathGeometry);
                current_path.Data = myGeometryGroup;
                paintSurface.Children.Add(current_path);
            }
            else
            {
                if (expression_strings.Count > 0)
                {
                    expression_strings[expression_strings.Count - 1] = "L";
                }
                current_line            = new LineGeometry();
                current_line.StartPoint = current_origin;
                current_line.EndPoint   = current_origin;

                current_path.Data = current_line;
                paintSurface.Children.Add(current_path);
            }

            if (current_end == default(System.Windows.Point))
            {
                current_end.X = c.Width / 2;
                current_end.Y = c.Height / 2;
            }
            current_end = SnapToGrid(current_end);

            if (arc_mode)
            {
                myGeometryGroup = UpdateArc(pathFigure, current_end, clockwise);
            }
            else
            {
                current_line = UpdateLine(current_line, current_end);
            }
        }
        public void Canvas_MouseDown_1(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                current_origin = e.GetPosition((Canvas)sender);
                current_origin = SnapToGrid(current_origin);
                System.Windows.Point r = new System.Windows.Point(current_origin.X / GridSize - GridCenter.X, GridCenter.Y - (current_origin.Y / GridSize));

                expression_values.Add(r);
                if (new_stroke)
                {
                    if (!first)
                    {
                        this.expression_text_box.Text += " |= ";
                    }
                    else
                    {
                        first = false;
                    }
                    expression_strings.Add("P");
                    new_stroke = false;
                }
                DrawPoint((Canvas)sender, current_origin);
                current_path = new System.Windows.Shapes.Path();
                SolidColorBrush blackBrush = new SolidColorBrush();
                blackBrush.Color             = Colors.Black;
                current_path.Stroke          = blackBrush;
                current_path.StrokeThickness = 3;
                myGeometryGroup = new GeometryGroup();
                if (arc_mode)
                {
                    pathFigure            = new PathFigure();
                    current_arc           = new ArcSegment();
                    pathFigure.StartPoint = current_origin;
                    current_arc.Point     = current_origin;
                    if (clockwise)
                    {
                        expression_strings.Add("A_CW");
                        current_arc.SweepDirection = SweepDirection.Clockwise;
                    }
                    else
                    {
                        expression_strings.Add("A_ACW");
                        current_arc.SweepDirection = SweepDirection.Counterclockwise;
                    }
                    PathSegmentCollection PathSegment = new PathSegmentCollection();
                    PathSegment.Add(current_arc);
                    pathFigure.Segments = PathSegment;
                    pathGeometry        = new PathGeometry(new List <PathFigure> {
                        pathFigure
                    });
                    myGeometryGroup.Children.Add(pathGeometry);
                    current_path.Data = myGeometryGroup;
                    paintSurface.Children.Add(current_path);
                }
                else
                {
                    expression_strings.Add("L");
                    current_line            = new LineGeometry();
                    current_line.StartPoint = current_origin;
                    current_line.EndPoint   = current_origin;

                    current_path.Data = current_line;
                    paintSurface.Children.Add(current_path);
                }

                if (i > 0)
                {
                    if (expression_strings[i - 1] == "P")
                    {
                        this.expression_text_box.Text += expression_strings[i - 1] + "(" + expression_values[i - 1].X + "," + expression_values[i - 1].Y + ")";
                    }
                    else
                    {
                        this.expression_text_box.Text += " + " + expression_strings[i - 1] + "(" + (expression_values[i - 1].X - expression_values[i - 2].X) + "," + (expression_values[i - 1].Y - expression_values[i - 2].Y) + ")";
                    }
                }
                i++;

                hold_part = true;
            }
            if (e.RightButton == MouseButtonState.Pressed)
            {
                paintSurface.Children.Remove(current_path);
                if (hold_part)
                {
                    if (expression_strings[i - 1] == "P")
                    {
                        this.expression_text_box.Text += expression_strings[i - 1] + "(" + expression_values[i - 1].X + "," + expression_values[i - 1].Y + ")";
                    }
                    else
                    {
                        this.expression_text_box.Text += " + " + expression_strings[i - 1] + "(" + (expression_values[i - 1].X - expression_values[i - 2].X) + "," + (expression_values[i - 1].Y - expression_values[i - 2].Y) + ")";
                    }
                    expression_strings.Clear();
                    expression_values.Clear();
                    i = 0;
                }
                hold_part  = false;
                new_stroke = true;
            }
        }
Exemple #4
0
        private void DrawEcg(double cur_time)
        {
            EcgSeries ecg;

            try {
                ecg = m_source.GetECG();

                if (ecg.samples.Length == 0)
                {
                    ECG.Data = null; // ECG not available
                    return;
                }
            } catch (Exception) {
                ECG.Data = null; // ECG not available
                return;
            }

            // shrink width & height slightly, so that the "actual" width/height remain unchanged
            double W = (int)(ECG.ActualWidth - 1);
            double H = (int)(ECG.ActualHeight - 1);

            // horizontal scaling (index to X coord)
            double ecg_pitch = W / ecg.samples.Length;

            // vertical scaling (sample val to Y coord)
            double ecg_offset = H * ecg.samples.Max() / (ecg.samples.Max() - ecg.samples.Min());
            double ecg_scale  = -H / (ecg.samples.Max() - ecg.samples.Min());

            // vertical scaling (time to Y coord conv)
            double time_offset = -W * ecg.start_time / (ecg.delta_time * ecg.samples.Length);
            double time_scale  = W / (ecg.delta_time * ecg.samples.Length);

            PathGeometry pathGeom = new PathGeometry();

            {
                // draw ECG trace
                PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();
                for (int i = 0; i < ecg.samples.Length; ++i)
                {
                    LineSegment lineSegment = new LineSegment();
                    lineSegment.Point = new Point(ecg_pitch * i, ecg_offset + ecg_scale * ecg.samples[i]);
                    pathSegmentCollection.Add(lineSegment);
                }

                PathFigure pathFig = new PathFigure();
                pathFig.StartPoint = new Point(0, ecg_offset + ecg_scale * ecg.samples[0]);
                pathFig.Segments   = pathSegmentCollection;

                PathFigureCollection pathFigCol = new PathFigureCollection();
                pathFigCol.Add(pathFig);

                pathGeom.Figures = pathFigCol;
            }

            {
                // draw current frame line
                double x_pos = time_offset + time_scale * cur_time;

                LineGeometry line = new LineGeometry();
                line.StartPoint = new Point(x_pos, 0);
                line.EndPoint   = new Point(x_pos, H);

                pathGeom.AddGeometry(line);
            }

            ECG.Stroke          = Brushes.Blue;
            ECG.StrokeThickness = 1.0;
            ECG.Data            = pathGeom;
        }
Exemple #5
0
        private void Canvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (_tool == ToolType.Polyline)
            {
                //PrimitiveContexMenu menu = new PrimitiveContexMenu();
                //MenuItem mi = menu.GetItem(0);
                //mi.Click += MiMoveToOrigin_Click;
                //menu.IsOpen = true;

                //this.ReleaseMouseCapture();
                ToolManager.Instance.Get(_tool).MouseRightDown(canvas, e, canvas.ScreenToWorld, this._polyLine);
            }
            return;

            Polyline _polyline1 = new Polyline();
            //_rectangle.Left = p.X;
            //_rectangle.Top = p.Y;
            //_rectangle.Width = 0;
            //_rectangle.Height = 0;
            int             x = 113;//x值递增*10
                        int y = 117;

            var point = new Point(x, y);


            //_polyline1.Points.Add(point);//添加新的数据点
            //point = new Point(13, 17);


            //_polyline1.Points.Add(point);//添加新的数据点

            //point = new Point(113, 117);


            _polyline1.Points.Add(point);//添加新的数据点


            canvas.Children.Add(_polyline1);

            return;

            System.Windows.Shapes.Path path = new System.Windows.Shapes.Path();
            PathGeometry pathGeometry       = new PathGeometry();
            ArcSegment   arc    = new ArcSegment(new Point(100, 200), new Size(50, 100), 0, false, SweepDirection.Counterclockwise, true);
            PathFigure   figure = new PathFigure();

            figure.StartPoint = new Point(100, 0);
            figure.Segments.Add(arc);
            pathGeometry.Figures.Add(figure);
            path.Data   = pathGeometry;
            path.Stroke = Brushes.Orange;

            RotateTransform angle1 = new RotateTransform(); //旋转
            ScaleTransform  scale  = new ScaleTransform();  //缩放
            TransformGroup  group  = new TransformGroup();
            RotateTransform angle  = new RotateTransform(30, 0, 0);

            group.Children.Add(scale);
            group.Children.Add(angle);

            path.RenderTransform = group;


            canvas.Children.Add(path);



            LineGeometry myLineGeometry = new LineGeometry();

            myLineGeometry.StartPoint = new Point(0, 0);
            myLineGeometry.EndPoint   = new Point(50, 50);

            System.Windows.Shapes.Path myPath = new System.Windows.Shapes.Path();
            myPath.Stroke          = Brushes.Black;
            myPath.StrokeThickness = 1;
            myPath.Data            = myLineGeometry;


            angle1 = new RotateTransform(); //旋转
            scale  = new ScaleTransform();  //缩放
            group  = new TransformGroup();
            angle  = new RotateTransform(30, 0, 0);
            group.Children.Add(scale);
            group.Children.Add(angle);

            myPath.RenderTransform = group;
            canvas.Children.Add(myPath);


            LineGeometry myLineGeometry1 = new LineGeometry();

            myLineGeometry1.StartPoint = new Point(0, 0);
            myLineGeometry1.EndPoint   = new Point(50, 50);

            System.Windows.Shapes.Path myPath1 = new System.Windows.Shapes.Path();
            myPath1.Stroke          = Brushes.Black;
            myPath1.StrokeThickness = 1;
            myPath1.Data            = myLineGeometry1;


            angle1 = new RotateTransform(); //旋转
            scale  = new ScaleTransform();  //缩放
            group  = new TransformGroup();
            angle  = new RotateTransform(50);
            group.Children.Add(scale);
            group.Children.Add(angle);

            myPath1.RenderTransform = group;
            canvas.Children.Add(myPath1);
        }
Exemple #6
0
        // Setup up graph-paper look
        private void buildGraphPaperLook()
        {
            // Create a Path to be drawn to the screen.
            Path myPath = new Path();

            myPath.Stroke          = Brushes.LightBlue;
            myPath.StrokeThickness = 1 / mm(1); // That's one WPF unit; tends to be about 1 pixel on today's displays
            SolidColorBrush mySolidColorBrush = new SolidColorBrush();

            mySolidColorBrush.Color = Color.FromArgb(255, 245, 245, 255);
            myPath.Fill             = mySolidColorBrush;

            // The "graph paper" region of the canvas extends from -100mm to 100mm.
            // Create the rectangle geometry to add to the Path
            RectangleGeometry myRectGeometry = new RectangleGeometry();

            myRectGeometry.Rect = new Rect(-graphSize, -graphSize, 2 * graphSize, 2 * graphSize);

            GeometryGroup myGeometryGroup = new GeometryGroup();

            myGeometryGroup.Children.Add(myRectGeometry);

            // Create the line geometry (thin graphpaper lines) to add to the Path
            int lastLine = (int)(graphSize / gridSize);

            for (int i = -lastLine; i <= lastLine; i++)
            {
                Debug.Write("Constructing Grid line " + i + "\n");
                LineGeometry myLineGeometry = new LineGeometry();
                myLineGeometry.StartPoint = new Point(i * gridSize, -graphSize);
                myLineGeometry.EndPoint   = new Point(i * gridSize, graphSize);
                myGeometryGroup.Children.Add(myLineGeometry);
                myLineGeometry            = new LineGeometry();
                myLineGeometry.StartPoint = new Point(-graphSize, i * gridSize);
                myLineGeometry.EndPoint   = new Point(graphSize, i * gridSize);
                myGeometryGroup.Children.Add(myLineGeometry);
            }
            myPath.Data = myGeometryGroup;
            this.Children.Add(myPath);

            // Create the coordinate axes
            mySolidColorBrush       = new SolidColorBrush();
            mySolidColorBrush.Color = Color.FromArgb(255, 245, 245, 255);

            Arrow xAxis = new Arrow(
                new Point(-0.1 * graphSize, 0),
                new Point(0.93 * graphSize, 0),
                Arrow.endtype.END);

            xAxis.Stroke          = Brushes.Blue;
            xAxis.StrokeThickness = 2 / mm(1);
            xAxis.Fill            = mySolidColorBrush;
            xAxis.ToolTip         = null;
            Arrow yAxis = new Arrow(new Point(0, -0.1 * graphSize),
                                    new Point(0, 0.9 * graphSize),
                                    Arrow.endtype.END);

            yAxis.Stroke          = Brushes.Blue;
            yAxis.StrokeThickness = 2 / mm(1);
            yAxis.Fill            = mySolidColorBrush;
            yAxis.ToolTip         = null;
            Children.Add(xAxis);
            Children.Add(yAxis);


            TextBlock tBlock = new TextBlock();

            tBlock.TextWrapping    = TextWrapping.Wrap;
            tBlock.Background      = Brushes.AntiqueWhite;
            tBlock.TextAlignment   = TextAlignment.Center;
            tBlock.RenderTransform = new ScaleTransform(1 / mm(1), -1 / mm(1));
            tBlock.Inlines.Add(new Bold(new Run("Y")));
            Canvas.SetTop(tBlock, 0.95 * graphSize);
            Canvas.SetLeft(tBlock, 0);
            Children.Add(tBlock);

            tBlock = new TextBlock();
            tBlock.TextWrapping    = TextWrapping.Wrap;
            tBlock.Background      = Brushes.AntiqueWhite;
            tBlock.TextAlignment   = TextAlignment.Center;
            tBlock.RenderTransform = new ScaleTransform(1 / mm(1), -1 / mm(1));
            tBlock.Inlines.Add(new Bold(new Run("X")));
            Canvas.SetLeft(tBlock, 0.95 * graphSize);
            Canvas.SetTop(tBlock, 0);
            Children.Add(tBlock);

            //Origin of coord system.
            Ellipse e = new Ellipse();

            e.Fill = Brushes.Blue; //mySolidColorBrush;
            double originSize = 1.0;

            SetLeft(e, -originSize);
            SetTop(e, -originSize);
            e.Width  = 2 * originSize;
            e.Height = 2 * originSize;
            Children.Add(e);
        }
Exemple #7
0
        public void DrawAxis()
        {
            //Window window = Window.GetWindow(BottomGrid);
            //GeneralTransform generalTransform = BottomGrid.TransformToAncestor(window);

            //Point upperleftpoint = generalTransform.Transform(new Point(0, 0));
            //Point upperrightpoint = new Point(upperleftpoint.X + BottomGrid.ActualWidth, upperleftpoint.Y);


            LineGeometry lineGeometry = new LineGeometry();
            //lineGeometry.StartPoint = upperleftpoint;
            //lineGeometry.EndPoint = upperrightpoint;

            Path path = new Path();

            path.Stroke          = Brushes.Red;
            path.StrokeThickness = 4;

            //path.Data = new PathGeometry()
            //{
            //    Figures=new PathFigureCollection()
            //    {
            //        new PathFigure()
            //        {
            //            Segments=new PathSegmentCollection()
            //            {
            //                new LineSegment() {Point=upperrightpoint}

            //            }
            //        }
            //    }

            //};

            Vector vector = VisualTreeHelper.GetOffset(BottomGrid);

            //使用Vector VisualTreeHelper.GetOffset(Visual visual)方法,其会返回visual在其父控件中的偏移量,然后你再将返回值的Vector对象转换成

            //Point对象就可以了;

            lineGeometry.StartPoint = new Point(vector.X - LeftGrid.ActualWidth, vector.Y - HeaderGrid.ActualHeight - path.StrokeThickness);
            lineGeometry.EndPoint   = new Point(vector.X - LeftGrid.ActualWidth + BottomGrid.ActualWidth + 20, vector.Y - HeaderGrid.ActualHeight - path.StrokeThickness);

            path.Data = lineGeometry;
            canvas.Children.Add(path);
            //Canvas.SetZIndex(path, 0);
            //Grid.SetZIndex(path, 0);

            //Yaxis

            LineGeometry lineGeometryY = new LineGeometry();


            Path pathY = new Path();

            pathY.Stroke          = Brushes.Red;
            pathY.StrokeThickness = 4;

            Vector vectorY = VisualTreeHelper.GetOffset(MainGridFrom0To1);


            lineGeometryY.EndPoint = new Point(vectorY.X - LeftGrid.ActualWidth, vectorY.Y - HeaderGrid.ActualHeight - 20);

            lineGeometryY.StartPoint = lineGeometry.StartPoint;
            //lineGeometryY.StartPoint = new Point(vectorY.X - LeftGrid.ActualWidth , vectorY.Y +MainGridFrom0To1.ActualHeight- HeaderGrid.ActualHeight);

            pathY.Data = lineGeometryY;
            canvas.Children.Add(pathY);
        }
Exemple #8
0
        void IProxyDrawingContext.DrawGeometry(BrushProxy brush, PenProxy pen, Geometry geometry, Geometry clip, Matrix brushTrans, ProxyDrawingFlags flags)
        {
            Debug.Assert(brushTrans.IsIdentity, "brushTrans not supported");

            if ((brush == null) && (pen == null))
            {
                return;
            }

            if (!_costing && (clip != null))
            {
                _dc.PushClip(clip);
            }

            if (brush != null)
            {
                brush = BrushProxy.BlendColorWithBrush(false, Colors.White, brush, false);
            }

            // Simplification, pushing transformation
            if (geometry is LineGeometry)
            {
                LineGeometry line = geometry.CloneCurrentValue() as LineGeometry;

                line.StartPoint = geometry.Transform.Value.Transform(line.StartPoint);
                line.EndPoint   = geometry.Transform.Value.Transform(line.EndPoint);
                line.Transform  = Transform.Identity;
            }

            if ((brush != null) && (brush.BrushList != null)) // List of brushes
            {
                Debug.Assert(pen == null, "no pen");

                if (_costing)
                {
                    FillGeometry(brush.BrushList[0] as BrushProxy, brush.BrushList, 1, geometry);
                }
                else
                {
                    bool rasterize = BetterRasterize(brush, geometry);

                    if (!rasterize)
                    {
                        rasterize = !FillGeometry(brush.BrushList[0] as BrushProxy, brush.BrushList, 1, geometry);
                    }

                    if (rasterize)
                    {
                        bool empty = false;

                        if (clip != null)
                        {
                            // Fix bug 1506957: Clip geometry prior to rasterizing to prevent excessive
                            // rasterization bitmap size.
                            geometry = Utility.Intersect(geometry, clip, Matrix.Identity, out empty);
                        }

                        if (!empty)
                        {
                            RasterizeGeometry(brush, geometry);
                        }
                    }
                }
            }
            else // Single Avalon brush or pen
            {
                Pen        p           = null;
                BrushProxy strokeBrush = null;

                if (pen != null) // Blend pen with White
                {
                    p           = pen.GetPen(true);
                    strokeBrush = pen.StrokeBrush;

                    if (!strokeBrush.IsOpaque())
                    {
                        strokeBrush = BrushProxy.BlendColorWithBrush(false, Colors.White, strokeBrush, false);
                    }
                }

                Brush b = null;

                if (_costing)
                {
                    if (brush != null)
                    {
                        // DrawingBrush is always rasterized onward from this stage.
                        // Avoid the cost of creating new DrawingBrush in GetRealBrush during costing
                        if ((brush.Brush != null) && (brush.Brush is DrawingBrush))
                        {
                            b = brush.Brush;
                        }
                        else
                        {
                            b = brush.GetRealBrush();
                        }
                    }

                    _cost += DrawGeometryCost(b, p, geometry);
                }
                else
                {
                    if (brush != null)
                    {
                        b = brush.GetRealBrush();
                    }

#if DEBUG
                    _seq++;

                    _dc.Comment("-> DrawGeometry " + _seq + ' ' + _comment);
#endif
                    if (p == null)
                    {
                        _dc.DrawGeometry(b, null, null, geometry);
                    }
                    else
                    {
                        _dc.DrawGeometry(b, p, strokeBrush.GetRealBrush(), geometry);
                    }

#if DEBUG
                    _dc.Comment("<- DrawGeometry" + _seq + ' ' + _comment);

                    if (Configuration.Verbose >= 2)
                    {
                        Console.WriteLine("  DrawGeometry(" + _comment + ")");
                    }
#endif
                }
            }

            if (!_costing && (clip != null))
            {
                _dc.PopClip();
            }
        }
Exemple #9
0
        public static UIElement GetItemContainerAt(this ItemsControl itemsControl, Point position, Orientation searchDirection)
        {
            bool isItemContainer;
            var  itemContainerType = GetItemContainerType(itemsControl, out isItemContainer);

            Geometry hitTestGeometry;

            if (typeof(TreeViewItem).IsAssignableFrom(itemContainerType))
            {
                hitTestGeometry = new LineGeometry(new Point(0, position.Y), new Point(itemsControl.RenderSize.Width, position.Y));
            }
            else
            {
                var geometryGroup = new GeometryGroup();
                geometryGroup.Children.Add(new LineGeometry(new Point(0, position.Y), new Point(itemsControl.RenderSize.Width, position.Y)));
                geometryGroup.Children.Add(new LineGeometry(new Point(position.X, 0), new Point(position.X, itemsControl.RenderSize.Height)));
                hitTestGeometry = geometryGroup;
            }

            var hits = new HashSet <DependencyObject>();

            VisualTreeHelper.HitTest(itemsControl,
                                     obj =>
            {
                // Viewport3D is not good for us
                // Stop on ScrollBar to improve performance (e.g. at DataGrid)
                if (obj is Viewport3D || (itemsControl is DataGrid && obj is ScrollBar))
                {
                    return(HitTestFilterBehavior.Stop);
                }
                return(HitTestFilterBehavior.Continue);
            },
                                     result =>
            {
                var itemContainer = isItemContainer
                                             ? result.VisualHit.GetVisualAncestor(itemContainerType, itemsControl)
                                             : result.VisualHit.GetVisualAncestor(itemContainerType, itemsControl, itemsControl.GetType());
                if (itemContainer != null && ((UIElement)itemContainer).IsVisible == true)
                {
                    var tvItem = itemContainer as TreeViewItem;
                    if (tvItem != null)
                    {
                        var tv = tvItem.GetVisualAncestor <TreeView>();
                        if (tv == itemsControl)
                        {
                            hits.Add(itemContainer);
                        }
                    }
                    else
                    {
                        if (itemsControl.ItemContainerGenerator.IndexFromContainer(itemContainer) >= 0)
                        {
                            hits.Add(itemContainer);
                        }
                    }
                }
                return(HitTestResultBehavior.Continue);
            },
                                     new GeometryHitTestParameters(hitTestGeometry));

            return(GetClosest(itemsControl, hits, position, searchDirection));
        }
Exemple #10
0
        private void RenderPath(WpfDrawingRenderer renderer)
        {
            WpfDrawingContext context = renderer.Context;

            SvgRenderingHint hint = _svgElement.RenderingHint;

            if (hint != SvgRenderingHint.Shape || hint == SvgRenderingHint.Clipping)
            {
                return;
            }
            var parentNode = _svgElement.ParentNode;

            // We do not directly render the contents of the clip-path, unless specifically requested...
            if (string.Equals(parentNode.LocalName, "clipPath") &&
                !context.RenderingClipRegion)
            {
                return;
            }

            SvgStyleableElement styleElm = (SvgStyleableElement)_svgElement;

            //string sVisibility = styleElm.GetPropertyValue("visibility");
            //string sDisplay    = styleElm.GetPropertyValue("display");
            //if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none"))
            //{
            //    return;
            //}

            DrawingGroup drawGroup = context.Peek();

            Debug.Assert(drawGroup != null);

            Geometry geometry = CreateGeometry(_svgElement, context.OptimizePath);

            string elementId    = this.GetElementName();
            string elementClass = this.GetElementClass();

            GeometryDrawing drawing = null;

            if (geometry == null || geometry.IsEmpty())
            {
                return;
            }

            var bounds = geometry.Bounds;

            if (string.Equals(_svgElement.LocalName, "line", StringComparison.Ordinal))
            {
                _isLineSegment = true;
            }
            else if (string.Equals(_svgElement.LocalName, "rect", StringComparison.Ordinal))
            {
                _isLineSegment = bounds.Width.Equals(0) || bounds.Height.Equals(0);
            }
            else if (string.Equals(_svgElement.LocalName, "path", StringComparison.Ordinal))
            {
                _isLineSegment = bounds.Width.Equals(0) || bounds.Height.Equals(0);
            }

            context.UpdateBounds(geometry.Bounds);

//                SetClip(context);

            WpfSvgPaint fillPaint = new WpfSvgPaint(context, styleElm, "fill");

//            string fileValue = styleElm.GetAttribute("fill");

            Brush brush = fillPaint.GetBrush(geometry, _setBrushOpacity);

            if (brush == null)
            {
                WpfSvgPaint fallbackPaint = fillPaint.WpfFallback;
                if (fallbackPaint != null)
                {
                    brush = fallbackPaint.GetBrush(geometry, _setBrushOpacity);
                }
            }
            bool isFillTransmable = fillPaint.IsFillTransformable;

            WpfSvgPaint strokePaint = new WpfSvgPaint(context, styleElm, "stroke");
            Pen         pen         = strokePaint.GetPen(geometry, _setBrushOpacity);

            // By the SVG Specifications:
            // Keyword 'objectBoundingBox' should not be used when the geometry of the applicable
            // element has no width or no height, such as the case of a horizontal or vertical line,
            // even when the line has actual thickness when viewed due to having a non-zero stroke
            // width since stroke width is ignored for bounding box calculations. When the geometry
            // of the applicable element has no width or height and 'objectBoundingBox' is specified,
            // then the given effect (e.g., a gradient) will be ignored.
            if (pen != null && _isLineSegment && strokePaint.FillType == WpfFillType.Gradient)
            {
                WpfGradientFill gradientFill = (WpfGradientFill)strokePaint.PaintServer;
                if (gradientFill.IsUserSpace == false)
                {
                    bool invalidGrad = false;
                    if (string.Equals(_svgElement.LocalName, "line", StringComparison.Ordinal))
                    {
                        LineGeometry lineGeometry = geometry as LineGeometry;
                        if (lineGeometry != null)
                        {
                            invalidGrad = SvgObject.IsEqual(lineGeometry.EndPoint.X, lineGeometry.StartPoint.X) ||
                                          SvgObject.IsEqual(lineGeometry.EndPoint.Y, lineGeometry.StartPoint.Y);
                        }
                    }
                    else
                    {
                        invalidGrad = true;
                    }
                    if (invalidGrad)
                    {
                        // Brush is not likely inherited, we need to support fallback too
                        WpfSvgPaint fallbackPaint = strokePaint.WpfFallback;
                        if (fallbackPaint != null)
                        {
                            pen.Brush = fallbackPaint.GetBrush(geometry, _setBrushOpacity);
                        }
                        else
                        {
                            var scopePaint = strokePaint.GetScopeStroke();
                            if (scopePaint != null)
                            {
                                if (scopePaint != strokePaint)
                                {
                                    pen.Brush = scopePaint.GetBrush(geometry, _setBrushOpacity);
                                }
                                else
                                {
                                    pen.Brush = null;
                                }
                            }
                            else
                            {
                                pen.Brush = null;
                            }
                        }
                    }
                }
            }

            if (_paintContext != null)
            {
                _paintContext.Fill   = fillPaint;
                _paintContext.Stroke = strokePaint;
                _paintContext.Tag    = geometry;
            }

            if (brush != null || pen != null)
            {
                Transform transform = this.Transform;
                if (transform != null && !transform.Value.IsIdentity)
                {
                    geometry.Transform = transform;
                    if (brush != null && isFillTransmable)
                    {
                        Transform brushTransform = brush.Transform;
                        if (brushTransform == null || brushTransform == Transform.Identity)
                        {
                            brush.Transform = transform;
                        }
                        else
                        {
                            TransformGroup groupTransform = new TransformGroup();
                            groupTransform.Children.Add(brushTransform);
                            groupTransform.Children.Add(transform);
                            brush.Transform = groupTransform;
                        }
                    }
                    if (pen != null && pen.Brush != null)
                    {
                        Transform brushTransform = pen.Brush.Transform;
                        if (brushTransform == null || brushTransform == Transform.Identity)
                        {
                            pen.Brush.Transform = transform;
                        }
                        else
                        {
                            TransformGroup groupTransform = new TransformGroup();
                            groupTransform.Children.Add(brushTransform);
                            groupTransform.Children.Add(transform);
                            pen.Brush.Transform = groupTransform;
                        }
                    }
                }
                else
                {
                    transform = null; // render any identity transform useless...
                }

                drawing = new GeometryDrawing(brush, pen, geometry);

                if (!string.IsNullOrWhiteSpace(elementId) && !context.IsRegisteredId(elementId))
                {
                    SvgObject.SetName(drawing, elementId);

                    context.RegisterId(elementId);

                    if (context.IncludeRuntime)
                    {
                        SvgObject.SetId(drawing, elementId);
                    }
                }

                if (!string.IsNullOrWhiteSpace(elementClass) && context.IncludeRuntime)
                {
                    SvgObject.SetClass(drawing, elementClass);
                }

                Brush    maskBrush = this.Masking;
                Geometry clipGeom  = this.ClipGeometry;
                if (clipGeom != null || maskBrush != null)
                {
                    //Geometry clipped = Geometry.Combine(geometry, clipGeom,
                    //    GeometryCombineMode.Exclude, null);

                    //if (clipped != null && !clipped.IsEmpty())
                    //{
                    //    geometry = clipped;
                    //}
                    DrawingGroup clipMaskGroup = new DrawingGroup();

                    Rect geometryBounds = geometry.Bounds;

                    if (clipGeom != null)
                    {
                        clipMaskGroup.ClipGeometry = clipGeom;

                        SvgUnitType clipUnits = this.ClipUnits;
                        if (clipUnits == SvgUnitType.ObjectBoundingBox)
                        {
                            Rect drawingBounds = geometryBounds;

                            if (transform != null)
                            {
                                drawingBounds = transform.TransformBounds(drawingBounds);
                            }

                            TransformGroup transformGroup = new TransformGroup();

                            // Scale the clip region (at (0, 0)) and translate to the top-left corner of the target.
                            transformGroup.Children.Add(new ScaleTransform(drawingBounds.Width, drawingBounds.Height));
                            transformGroup.Children.Add(new TranslateTransform(drawingBounds.X, drawingBounds.Y));

                            clipGeom.Transform = transformGroup;
                        }
                        else
                        {
                            if (transform != null)
                            {
                                clipGeom.Transform = transform;
                            }
                        }
                    }
                    if (maskBrush != null)
                    {
                        DrawingBrush drawingBrush = (DrawingBrush)maskBrush;

                        SvgUnitType maskUnits        = this.MaskUnits;
                        SvgUnitType maskContentUnits = this.MaskContentUnits;
                        if (maskUnits == SvgUnitType.ObjectBoundingBox)
                        {
                            Rect drawingBounds = geometryBounds;

                            if (transform != null)
                            {
                                drawingBounds = transform.TransformBounds(drawingBounds);
                            }
                            DrawingGroup maskGroup = drawingBrush.Drawing as DrawingGroup;
                            if (maskGroup != null)
                            {
                                DrawingCollection maskDrawings = maskGroup.Children;
                                for (int i = 0; i < maskDrawings.Count; i++)
                                {
                                    Drawing         maskDrawing  = maskDrawings[i];
                                    GeometryDrawing maskGeomDraw = maskDrawing as GeometryDrawing;
                                    if (maskGeomDraw != null)
                                    {
                                        if (maskGeomDraw.Brush != null)
                                        {
                                            ConvertColors(maskGeomDraw.Brush);
                                        }
                                        if (maskGeomDraw.Pen != null)
                                        {
                                            ConvertColors(maskGeomDraw.Pen.Brush);
                                        }
                                    }
                                }
                            }

                            if (maskContentUnits == SvgUnitType.ObjectBoundingBox)
                            {
                                TransformGroup transformGroup = new TransformGroup();

                                // Scale the clip region (at (0, 0)) and translate to the top-left corner of the target.
                                var scaleTransform = new ScaleTransform(drawingBounds.Width, drawingBounds.Height);
                                transformGroup.Children.Add(scaleTransform);
                                var translateTransform = new TranslateTransform(drawingBounds.X, drawingBounds.Y);
                                transformGroup.Children.Add(translateTransform);

                                Matrix scaleMatrix     = new Matrix();
                                Matrix translateMatrix = new Matrix();

                                scaleMatrix.Scale(drawingBounds.Width, drawingBounds.Height);
                                translateMatrix.Translate(drawingBounds.X, drawingBounds.Y);

                                Matrix matrix = Matrix.Multiply(scaleMatrix, translateMatrix);
                                //maskBrush.Transform = transformGroup;
                                maskBrush.Transform = new MatrixTransform(matrix);
                            }
                            else
                            {
                                drawingBrush.Viewbox      = drawingBounds;
                                drawingBrush.ViewboxUnits = BrushMappingMode.Absolute;

                                drawingBrush.Stretch = Stretch.Uniform;

                                drawingBrush.Viewport      = drawingBounds;
                                drawingBrush.ViewportUnits = BrushMappingMode.Absolute;
                            }
                        }
                        else
                        {
                            if (transform != null)
                            {
                                maskBrush.Transform = transform;
                            }
                        }

                        clipMaskGroup.OpacityMask = maskBrush;
                    }

                    clipMaskGroup.Children.Add(drawing);
                    drawGroup.Children.Add(clipMaskGroup);
                }
                else
                {
                    drawGroup.Children.Add(drawing);
                }
            }

            // If this is not the child of a "marker", then try rendering a marker...
            if (!string.Equals(parentNode.LocalName, "marker"))
            {
                RenderMarkers(renderer, styleElm, context);
            }

            // Register this drawing with the Drawing-Document...
            if (drawing != null)
            {
                this.Rendered(drawing);
            }
        }
Exemple #11
0
        protected Point AddSelected(Point point)
        {
            Rect selected = Next(point);

            //MyCapture.Points.Add(rect.BottomLeft);
            //MyCapture.Points.Add(rect.BottomRight);
            //MyCapture.Points.Add(rect.TopLeft);
            //MyCapture.Points.Add(rect.TopRight);
            for (int i = CommonParam._defaultCount; i < CMain.Children.Count - 1; i++)
            {
                var temp = CMain.Children[i];
                if (temp is Path)
                {
                    Path path = temp as Path;
                    path.Stroke = Brushes.White;
                    if (path != null)
                    {
                        if (path.Data is LineGeometry)
                        {
                            LineGeometry line = path.Data as LineGeometry;
                            bool         p1   = CommonFun.IsPointIn(selected, line.StartPoint);
                            bool         p2   = CommonFun.IsPointIn(selected, line.EndPoint);
                            if (p1 && p2)
                            {
                                path.Stroke = Brushes.LightBlue;
                                selectedPathes.Add(path);
                            }
                        }
                        else if (path.Data is RectangleGeometry)
                        {
                            RectangleGeometry rect = path.Data as RectangleGeometry;
                            bool p1 = CommonFun.IsPointIn(selected, rect.Rect.BottomLeft);
                            bool p2 = CommonFun.IsPointIn(selected, rect.Rect.BottomRight);
                            bool p3 = CommonFun.IsPointIn(selected, rect.Rect.TopLeft);
                            bool p4 = CommonFun.IsPointIn(selected, rect.Rect.TopRight);
                            if (p1 && p2 && p3 && p4)
                            {
                                path.Stroke = Brushes.LightBlue;
                                selectedPathes.Add(path);
                            }
                        }
                        else if (path.Data is EllipseGeometry)
                        {
                            EllipseGeometry ellipse = path.Data as EllipseGeometry;
                            bool            p1      = CommonFun.IsPointIn(selected, new Point(ellipse.Center.X - ellipse.RadiusX, ellipse.Center.Y));
                            bool            p2      = CommonFun.IsPointIn(selected, new Point(ellipse.Center.X + ellipse.RadiusX, ellipse.Center.Y));
                            bool            p3      = CommonFun.IsPointIn(selected, new Point(ellipse.Center.X, ellipse.Center.Y + ellipse.RadiusY));
                            bool            p4      = CommonFun.IsPointIn(selected, new Point(ellipse.Center.X, ellipse.Center.Y + ellipse.RadiusY));
                            if (p1 && p2 && p3 && p4)
                            {
                                path.Stroke = Brushes.LightBlue;
                                selectedPathes.Add(path);
                            }
                        }
                    }
                }
                else if (temp is TextBlock)
                {
                    TextBlock edit = temp as TextBlock;
                    double    x    = Canvas.GetLeft(edit);
                    double    y    = Canvas.GetTop(edit);
                    bool      p1   = CommonFun.IsPointIn(selected, new Point(x, y));
                    bool      p2   = CommonFun.IsPointIn(selected, new Point(x + edit.ActualWidth, y + edit.ActualHeight));
                    if (p1 && p2)
                    {
                        edit.Foreground = Brushes.LightBlue;
                        selectedPathes.Add(edit);
                    }
                }
            }
            return(point);
        }
Exemple #12
0
        public override void MouseMove(object sender, Point point)
        {
            if (Step == 1)
            {
                Next(point);
            }
            else if (Step == 3 && selectedPathes.Count > 0)
            {
                Point pm2 = point;

                double mx = (pm2.X - pm1.X);
                double my = (pm2.Y - pm1.Y);

                foreach (UIElement UI in selectedPathes)
                {
                    if (UI is Path)
                    {
                        Path path = UI as Path;
                        if (path.Data is LineGeometry)
                        {
                            LineGeometry line = path.Data as LineGeometry;
                            MyCapture.Points.Remove(line.StartPoint);
                            MyCapture.Points.Remove(line.EndPoint);
                            line.StartPoint = new Point(line.StartPoint.X + mx, line.StartPoint.Y + my);
                            line.EndPoint   = new Point(line.EndPoint.X + mx, line.EndPoint.Y + my);
                            MyCapture.Points.Add(line.StartPoint);
                            MyCapture.Points.Add(line.EndPoint);
                        }
                        else if (path.Data is RectangleGeometry)
                        {
                            RectangleGeometry rect = path.Data as RectangleGeometry;

                            MyCapture.Points.Remove(rect.Rect.BottomLeft);
                            MyCapture.Points.Remove(rect.Rect.BottomRight);
                            MyCapture.Points.Remove(rect.Rect.TopLeft);
                            MyCapture.Points.Remove(rect.Rect.TopRight);
                            rect.Rect = new Rect(rect.Rect.X + mx, rect.Rect.Y + my, rect.Rect.Width, rect.Rect.Height);
                            MyCapture.Points.Add(rect.Rect.BottomLeft);
                            MyCapture.Points.Add(rect.Rect.BottomRight);
                            MyCapture.Points.Add(rect.Rect.TopLeft);
                            MyCapture.Points.Add(rect.Rect.TopRight);
                        }
                        else if (path.Data is EllipseGeometry)
                        {
                            EllipseGeometry ellipse = path.Data as EllipseGeometry;
                            MyCapture.Points.Remove(ellipse.Center);
                            ellipse.Center = new Point(ellipse.Center.X + mx, ellipse.Center.Y + my);
                            MyCapture.Points.Add(ellipse.Center);
                        }
                    }
                    else if (UI is TextBlock)
                    {
                        TextBlock edit = UI as TextBlock;

                        Canvas.SetLeft(edit, Canvas.GetLeft(edit) + mx);
                        Canvas.SetTop(edit, Canvas.GetTop(edit) + my);
                    }
                }
                pm1 = pm2;
            }
        }
Exemple #13
0
        public object ConvertToNative(Geometry geometry)
        {
            // TODO: Can we keep this object around and reset it?
            droidGraphics.Path path = new droidGraphics.Path();
            // TODO: Might we also save a non-transformed path and a transformed path? -- No, that fails for GeometryGroup

            // Determine what type of Geometry we're dealing with
            if (geometry is LineGeometry)
            {
                LineGeometry lineGeometry = geometry as LineGeometry;

                path.MoveTo(PixelsPerDip * (float)lineGeometry.StartPoint.X,
                            PixelsPerDip * (float)lineGeometry.StartPoint.Y);

                path.LineTo(PixelsPerDip * (float)lineGeometry.EndPoint.X,
                            PixelsPerDip * (float)lineGeometry.EndPoint.Y);
            }

            else if (geometry is RectangleGeometry)
            {
                Rect rect = (geometry as RectangleGeometry).Rect;

                path.AddRect(PixelsPerDip * (float)rect.Left,
                             PixelsPerDip * (float)rect.Top,
                             PixelsPerDip * (float)rect.Right,
                             PixelsPerDip * (float)rect.Bottom,
                             droidGraphics.Path.Direction.Cw);              // TODO: Check for compatibility!
            }

            else if (geometry is EllipseGeometry)
            {
                EllipseGeometry ellipseGeometry = geometry as EllipseGeometry;

                path.AddOval(new droidGraphics.RectF(
                                 PixelsPerDip * (float)(ellipseGeometry.Center.X - ellipseGeometry.RadiusX),
                                 PixelsPerDip * (float)(ellipseGeometry.Center.Y - ellipseGeometry.RadiusY),
                                 PixelsPerDip * (float)(ellipseGeometry.Center.X + ellipseGeometry.RadiusX),
                                 PixelsPerDip * (float)(ellipseGeometry.Center.Y + ellipseGeometry.RadiusY)),
                             droidGraphics.Path.Direction.Cw);              // TODO: Check for compatibility!
            }

            else if (geometry is GeometryGroup)
            {
                GeometryGroup geometryGroup = geometry as GeometryGroup;
                SetFillRule(path, geometryGroup.FillRule);

                foreach (Geometry child in geometryGroup.Children)
                {
                    droidGraphics.Path childPath = ConvertToNative(child) as droidGraphics.Path;
                    path.AddPath(childPath);
                }
            }

            else if (geometry is PathGeometry)
            {
                PathGeometry pathGeometry = geometry as PathGeometry;

                SetFillRule(path, pathGeometry.FillRule);

                foreach (PathFigure pathFigure in pathGeometry.Figures)
                {
                    path.MoveTo(PixelsPerDip * (float)pathFigure.StartPoint.X,
                                PixelsPerDip * (float)pathFigure.StartPoint.Y);
                    Point lastPoint = pathFigure.StartPoint;

                    foreach (PathSegment pathSegment in pathFigure.Segments)
                    {
                        // LineSegment
                        if (pathSegment is LineSegment)
                        {
                            LineSegment lineSegment = pathSegment as LineSegment;

                            path.LineTo(PixelsPerDip * (float)lineSegment.Point.X,
                                        PixelsPerDip * (float)lineSegment.Point.Y);
                            lastPoint = lineSegment.Point;
                        }

                        // PolylineSegment
                        else if (pathSegment is PolyLineSegment)
                        {
                            PolyLineSegment polylineSegment = pathSegment as PolyLineSegment;
                            PointCollection points          = polylineSegment.Points;

                            for (int i = 0; i < points.Count; i++)
                            {
                                path.LineTo(PixelsPerDip * (float)points[i].X,
                                            PixelsPerDip * (float)points[i].Y);
                            }
                            lastPoint = points[points.Count - 1];
                        }

                        // BezierSegment
                        else if (pathSegment is BezierSegment)
                        {
                            BezierSegment bezierSegment = pathSegment as BezierSegment;

                            path.CubicTo(PixelsPerDip * (float)bezierSegment.Point1.X, PixelsPerDip * (float)bezierSegment.Point1.Y,
                                         PixelsPerDip * (float)bezierSegment.Point2.X, PixelsPerDip * (float)bezierSegment.Point2.Y,
                                         PixelsPerDip * (float)bezierSegment.Point3.X, PixelsPerDip * (float)bezierSegment.Point3.Y);

                            lastPoint = bezierSegment.Point3;
                        }

                        // PolyBezierSegment
                        else if (pathSegment is PolyBezierSegment)
                        {
                            PolyBezierSegment polyBezierSegment = pathSegment as PolyBezierSegment;
                            PointCollection   points            = polyBezierSegment.Points;

                            for (int i = 0; i < points.Count; i += 3)
                            {
                                path.CubicTo(PixelsPerDip * (float)points[i + 0].X, PixelsPerDip * (float)points[i + 0].Y,
                                             PixelsPerDip * (float)points[i + 1].X, PixelsPerDip * (float)points[i + 1].Y,
                                             PixelsPerDip * (float)points[i + 2].X, PixelsPerDip * (float)points[i + 2].Y);
                            }
                            lastPoint = points[points.Count - 1];
                        }

                        // QuadraticBezierSegment
                        else if (pathSegment is QuadraticBezierSegment)
                        {
                            QuadraticBezierSegment bezierSegment = pathSegment as QuadraticBezierSegment;

                            path.QuadTo(PixelsPerDip * (float)bezierSegment.Point1.X, PixelsPerDip * (float)bezierSegment.Point1.Y,
                                        PixelsPerDip * (float)bezierSegment.Point2.X, PixelsPerDip * (float)bezierSegment.Point2.Y);

                            lastPoint = bezierSegment.Point2;
                        }

                        // PolyQuadraticBezierSegment
                        else if (pathSegment is PolyQuadraticBezierSegment)
                        {
                            PolyQuadraticBezierSegment polyBezierSegment = pathSegment as PolyQuadraticBezierSegment;
                            PointCollection            points            = polyBezierSegment.Points;

                            for (int i = 0; i < points.Count; i += 2)
                            {
                                path.QuadTo(PixelsPerDip * (float)points[i + 0].X, PixelsPerDip * (float)points[i + 0].Y,
                                            PixelsPerDip * (float)points[i + 1].X, PixelsPerDip * (float)points[i + 1].Y);
                            }
                            lastPoint = points[points.Count - 1];
                        }

                        // ArcSegment
                        else if (pathSegment is ArcSegment)
                        {
                            ArcSegment arcSegment = pathSegment as ArcSegment;

                            List <Point> points = new List <Point>();
                            Xamarin.Forms.Shapes.Shapes.FlattenArc(points,
                                                                   lastPoint,
                                                                   arcSegment.Point,
                                                                   arcSegment.Size.Width,
                                                                   arcSegment.Size.Height,
                                                                   arcSegment.RotationAngle,
                                                                   arcSegment.IsLargeArc,
                                                                   arcSegment.SweepDirection == SweepDirection.Counterclockwise,
                                                                   1);

                            for (int i = 0; i < points.Count; i++)
                            {
                                path.LineTo(PixelsPerDip * (float)points[i].X,
                                            PixelsPerDip * (float)points[i].Y);
                            }
                            lastPoint = points[points.Count - 1];
                        }
                    }

                    if (pathFigure.IsClosed)
                    {
                        path.Close();
                    }
                }
            }

            // Apply transform
            if (geometry.Transform != null)
            {
                path.Transform((droidGraphics.Matrix)geometry.Transform.GetNativeObject());
            }

            return(path);
        }
Exemple #14
0
        public PenExample()
        {
            // Create several geometries.
            RectangleGeometry myRectangleGeometry = new RectangleGeometry();

            myRectangleGeometry.Rect = new Rect(0, 0, 50, 50);
            EllipseGeometry myEllipseGeometry = new EllipseGeometry();

            myEllipseGeometry.Center  = new Point(75, 75);
            myEllipseGeometry.RadiusX = 50;
            myEllipseGeometry.RadiusY = 50;
            LineGeometry myLineGeometry = new LineGeometry();

            myLineGeometry.StartPoint = new Point(75, 75);
            myLineGeometry.EndPoint   = new Point(75, 0);

            // Create a GeometryGroup and add the geometries to it.
            GeometryGroup myGeometryGroup = new GeometryGroup();

            myGeometryGroup.Children.Add(myRectangleGeometry);
            myGeometryGroup.Children.Add(myEllipseGeometry);
            myGeometryGroup.Children.Add(myLineGeometry);

            // Create a GeometryDrawing and use the GeometryGroup to specify
            // its geometry.
            GeometryDrawing myGeometryDrawing = new GeometryDrawing();

            myGeometryDrawing.Geometry = myGeometryGroup;

            // Add the GeometryDrawing to a DrawingGroup.
            DrawingGroup myDrawingGroup = new DrawingGroup();

            myDrawingGroup.Children.Add(myGeometryDrawing);

            // Create a Pen to add to the GeometryDrawing created above.
            Pen myPen = new Pen();

            myPen.Thickness  = 10;
            myPen.LineJoin   = PenLineJoin.Round;
            myPen.EndLineCap = PenLineCap.Round;

            // Create a gradient to use as a value for the Pen's Brush property.
            GradientStop firstStop = new GradientStop();

            firstStop.Offset = 0.0;
            Color c1 = new Color();

            c1.A            = 255;
            c1.R            = 204;
            c1.G            = 204;
            c1.B            = 255;
            firstStop.Color = c1;
            GradientStop secondStop = new GradientStop();

            secondStop.Offset = 1.0;
            secondStop.Color  = Colors.Purple;

            LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush();

            myLinearGradientBrush.GradientStops.Add(firstStop);
            myLinearGradientBrush.GradientStops.Add(secondStop);

            myPen.Brush           = myLinearGradientBrush;
            myGeometryDrawing.Pen = myPen;

            // Create an Image and set its DrawingImage to the Geometry created above.
            Image myImage = new Image();

            myImage.Stretch = Stretch.None;
            myImage.Margin  = new Thickness(10);

            DrawingImage myDrawingImage = new DrawingImage();

            myDrawingImage.Drawing = myDrawingGroup;
            myImage.Source         = myDrawingImage;

            this.Content = myImage;
        }
        public DrawingGroup ConstructGraph()
        {
            Chart.Children.Clear();
            MaxMin();
            n = (int)max;
            double step = max / n;

            GeometryDrawing FrameDrw = new GeometryDrawing();
            GeometryGroup   FrameGG  = new GeometryGroup();

            FrameDrw.Brush = Brushes.Transparent;
            FrameDrw.Pen   = new Pen(Brushes.Black, 2);
            RectangleGeometry FrameRG = new RectangleGeometry();

            FrameRG.Rect = new Rect(-60, -20, 490, 480);
            FrameGG.Children.Add(FrameRG);
            FrameDrw.Geometry = FrameGG;
            Chart.Children.Add(FrameDrw);

            GeometryDrawing drw1 = new GeometryDrawing();
            GeometryGroup   gg1  = new GeometryGroup();

            drw1.Brush = Brushes.LightGoldenrodYellow;
            drw1.Pen   = new Pen(Brushes.Gray, 0.5);
            for (int i = 1; i < n; i++)
            {
                LineGeometry myRectGeometry1 = new LineGeometry(new Point(400, i * (400 / n)), new Point(-10, i * (400 / n)));
                gg1.Children.Add(myRectGeometry1);
            }
            drw1.Geometry = gg1;
            Chart.Children.Add(drw1);

            GeometryDrawing drw2 = new GeometryDrawing();
            GeometryGroup   gg2  = new GeometryGroup();

            drw2.Brush = Brushes.LightGoldenrodYellow;
            drw2.Pen   = new Pen(Brushes.Gray, 0.5);
            for (int i = 1; i < n; i++)
            {
                LineGeometry myRectGeometry2 = new LineGeometry(new Point(i * (400 / n), 410), new Point(i * (400 / n), 0));
                gg2.Children.Add(myRectGeometry2);
            }
            drw2.Geometry = gg2;
            Chart.Children.Add(drw2);

            GeometryDrawing drw4 = new GeometryDrawing();
            GeometryGroup   gg4  = new GeometryGroup();

            drw4.Brush = Brushes.Transparent;
            drw4.Pen   = new Pen(Brushes.LightGray, 2);
            RectangleGeometry myRectGeometry4 = new RectangleGeometry();

            myRectGeometry4.Rect = new Rect(0, 0, 400, 400);
            gg4.Children.Add(myRectGeometry4);
            drw4.Geometry = gg4;
            Chart.Children.Add(drw4);

            int q = 0;

            for (int i = 0; i < n + 1; i++)             // y
            {
                double y = Math.Round((max - i * step) + min);
                if (y == 0)
                {
                    q = i;
                    break;
                }
            }
            GeometryDrawing drw = new GeometryDrawing();
            GeometryGroup   gg  = new GeometryGroup();

            drw.Brush = Brushes.Black;
            drw.Pen   = new Pen(Brushes.Black, 1);
            LineGeometry myRectGeometry = new LineGeometry(new Point(400, q * (400 / n)), new Point(-10, q * (400 / n)));

            gg.Children.Add(myRectGeometry);
            drw.Geometry = gg;
            Chart.Children.Add(drw);

            for (int i = 0; i < n + 1; i++)             // x
            {
                double x = Math.Round((i * step) + min);
                if (x == 0)
                {
                    q = i;
                    break;
                }
            }
            GeometryDrawing drw0 = new GeometryDrawing();
            GeometryGroup   gg0  = new GeometryGroup();

            drw0.Brush = Brushes.Black;
            drw0.Pen   = new Pen(Brushes.Black, 1);
            LineGeometry myRectGeometry0 = new LineGeometry(new Point(q * (400 / n), 410), new Point(q * (400 / n), 0));

            gg0.Children.Add(myRectGeometry0);
            drw0.Geometry = gg0;
            Chart.Children.Add(drw0);

            GeometryDrawing drw5 = new GeometryDrawing();
            GeometryGroup   gg5  = new GeometryGroup();

            drw5.Brush = Brushes.LightGray;
            drw5.Pen   = new Pen(Brushes.Black, 0.3);
            for (int i = 0; i < n + 1; i++)             // y
            {
                string        y             = Math.Round((max - i * step) + min).ToString();
                FormattedText formattedText = new FormattedText(y, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Verdana"), 10, Brushes.Black);
                Geometry      geometry      = formattedText.BuildGeometry(new Point(-20, i * (400 / n) - 7));
                gg5.Children.Add(geometry);
            }
            drw5.Geometry = gg5;
            Chart.Children.Add(drw5);

            GeometryDrawing drw6 = new GeometryDrawing();
            GeometryGroup   gg6  = new GeometryGroup();

            drw6.Brush = Brushes.LightGray;
            drw6.Pen   = new Pen(Brushes.Black, 0.3);
            for (int i = 0; i < n + 1; i++)             // x
            {
                string        x             = Math.Round((i * step) + min).ToString();
                FormattedText formattedText = new FormattedText(x, CultureInfo.GetCultureInfo("en-us"), FlowDirection.RightToLeft, new Typeface("Verdana"), 10, Brushes.Black);
                Geometry      geometry      = formattedText.BuildGeometry(new Point(i * (400 / n) + 5, 410));
                gg6.Children.Add(geometry);
            }
            drw6.Geometry = gg6;
            Chart.Children.Add(drw6);

            Chart.Children.Add(DrawLine(max, min, listPoint, 1, Brushes.Green));
            Chart.Children.Add(DrawUnsuccessfulLine(max, min, listUnsuccessfulPoint, 0.5, Brushes.Red));

            return(Chart);
        }
Exemple #16
0
    private UIElement card(int type)
    {
        PointCollection points = new PointCollection();

        switch (type)
        {
        case 1:     // Circle
            EllipseGeometry ellipse = new EllipseGeometry();
            Path            circle  = new Path();
            ellipse.Center         = new Point(20, 20);
            ellipse.RadiusX        = 20;
            ellipse.RadiusY        = 20;
            circle.Data            = ellipse;
            circle.Stroke          = new SolidColorBrush(Colors.DarkRed);
            circle.Fill            = new SolidColorBrush(Colors.DarkRed);
            circle.StrokeThickness = 5;
            circle.Margin          = new Thickness(10);
            return(circle);

        case 2:     // Cross
            Path          lines     = new Path();
            LineGeometry  line1     = new LineGeometry();
            LineGeometry  line2     = new LineGeometry();
            GeometryGroup linegroup = new GeometryGroup();
            line1.StartPoint = new Point(0, 0);
            line1.EndPoint   = new Point(40, 40);
            line2.StartPoint = new Point(40, 0);
            line2.EndPoint   = new Point(0, 40);
            linegroup.Children.Add(line1);
            linegroup.Children.Add(line2);
            lines.Data            = linegroup;
            lines.Stroke          = new SolidColorBrush(Colors.DarkBlue);
            lines.StrokeThickness = 5;
            lines.Margin          = new Thickness(10);
            return(lines);

        case 3:     // Triangle
            points.Add(new Point(150, 0));
            points.Add(new Point(0, 250));
            points.Add(new Point(300, 250));
            return(shape(ref points, Colors.Green));

        case 4:     // Square
            points.Add(new Point(0, 0));
            points.Add(new Point(0, 100));
            points.Add(new Point(100, 100));
            points.Add(new Point(100, 0));
            return(shape(ref points, Colors.DarkMagenta));

        case 5:     // Pentagon
            points.Add(new Point(0, 125));
            points.Add(new Point(150, 0));
            points.Add(new Point(300, 125));
            points.Add(new Point(250, 300));
            points.Add(new Point(50, 300));
            return(shape(ref points, Colors.Crimson));

        case 6:     // Hexagon
            points.Add(new Point(75, 0));
            points.Add(new Point(225, 0));
            points.Add(new Point(300, 150));
            points.Add(new Point(225, 300));
            points.Add(new Point(75, 300));
            points.Add(new Point(0, 150));
            return(shape(ref points, Colors.DarkCyan));

        case 7:     // Star
            points.Add(new Point(9, 2));
            points.Add(new Point(11, 7));
            points.Add(new Point(17, 7));
            points.Add(new Point(12, 10));
            points.Add(new Point(14, 15));
            points.Add(new Point(9, 12));
            points.Add(new Point(4, 15));
            points.Add(new Point(6, 10));
            points.Add(new Point(1, 7));
            points.Add(new Point(7, 7));
            return(shape(ref points, Colors.Gold));

        case 8:     // Rhombus
            points.Add(new Point(50, 0));
            points.Add(new Point(100, 50));
            points.Add(new Point(50, 100));
            points.Add(new Point(0, 50));
            return(shape(ref points, Colors.OrangeRed));

        default:
            return(null);
        }
    }
Exemple #17
0
        private void UpdateUIResources()
        {
            ResourceDictionary resources = new ResourceDictionary
            {
                Source = new Uri("/DynamicDataDisplay;component/Charts/Axes/AxisControlStyle.xaml", UriKind.Relative)
            };

            ControlTemplate template = (ControlTemplate)resources[templateKey + this.placement.ToString()];

            Verify.AssertNotNull(template);
            var content = (FrameworkElement)template.LoadContent();

            if (ticksPath != null && ticksPath.Data != null)
            {
                GeometryGroup group = (GeometryGroup)ticksPath.Data;
                foreach (var child in group.Children)
                {
                    LineGeometry geometry = (LineGeometry)child;
                    lineGeomPool.Put(geometry);
                }
                group.Children.Clear();
            }

            ticksPath = (Path)content.FindName(PART_TicksPath);
            ticksPath.SnapsToDevicePixels = true;
            Verify.AssertNotNull(ticksPath);

            // as this method can be called not only on loading of axisControl, but when its placement changes, internal panels
            // can be not empty and their contents should be released
            if (commonLabelsCanvas != null && labelProvider != null)
            {
                foreach (UIElement child in commonLabelsCanvas.Children)
                {
                    if (child != null)
                    {
                        labelProvider.ReleaseLabel(child);
                    }
                }

                labels = null;
                commonLabelsCanvas.Children.Clear();
            }

            commonLabelsCanvas = (StackCanvas)content.FindName(PART_CommonLabelsCanvas);
            Verify.AssertNotNull(commonLabelsCanvas);
            commonLabelsCanvas.Placement = placement;

            if (additionalLabelsCanvas != null && majorLabelProvider != null)
            {
                foreach (UIElement child in additionalLabelsCanvas.Children)
                {
                    if (child != null)
                    {
                        majorLabelProvider.ReleaseLabel(child);
                    }
                }
            }

            additionalLabelsCanvas = (StackCanvas)content.FindName(PART_AdditionalLabelsCanvas);
            Verify.AssertNotNull(additionalLabelsCanvas);
            additionalLabelsCanvas.Placement = placement;

            mainGrid = (Grid)content.FindName(PART_ContentsGrid);
            Verify.AssertNotNull(mainGrid);

            mainGrid.SetBinding(Control.BackgroundProperty, new Binding {
                Path = new PropertyPath("Background"), Source = this
            });
            mainGrid.SizeChanged += new SizeChangedEventHandler(mainGrid_SizeChanged);

            Content = mainGrid;

            string transformKey = additionalLabelTransformKey + placement.ToString();

            if (resources.Contains(transformKey))
            {
                additionalLabelTransform = (Transform)resources[transformKey];
            }
        }
Exemple #18
0
        DrawingGroup LoadGroup(IList <Shape> elements)
        {
            List <ControlLine> debugPoints = new List <ControlLine>();
            DrawingGroup       grp         = new DrawingGroup();

            foreach (ClipArtViewer.Shape shape in elements)
            {
                if (shape is ClipArtViewer.UseShape)
                {
                    ClipArtViewer.UseShape useshape = shape as ClipArtViewer.UseShape;
                    ClipArtViewer.Group    group    = SVG.GetShape(useshape.hRef) as ClipArtViewer.Group;
                    if (group != null)
                    {
                        Shape oldparent = group.Parent;
                        group.Parent = useshape;                         // this to get proper style propagated
                        DrawingGroup subgroup = LoadGroup(group.Elements);
                        subgroup.Transform = new TranslateTransform(useshape.X, useshape.Y);
                        grp.Children.Add(subgroup);
                        group.Parent = oldparent;
                    }
                    continue;
                }
                if (shape is ClipArtViewer.Group)
                {
                    DrawingGroup subgroup = LoadGroup((shape as ClipArtViewer.Group).Elements);
                    if (shape.Transform != null)
                    {
                        subgroup.Transform = shape.Transform;
                    }
                    grp.Children.Add(subgroup);
                    continue;
                }
                if (shape is ClipArtViewer.RectangleShape)
                {
                    ClipArtViewer.RectangleShape r    = shape as ClipArtViewer.RectangleShape;
                    RectangleGeometry            rect = new RectangleGeometry(new Rect(r.X, r.Y, r.Width, r.Height));
                    rect.RadiusX = r.RX;
                    rect.RadiusY = r.RY;
                    if (rect.RadiusX == 0 && rect.RadiusY > 0)
                    {
                        rect.RadiusX = rect.RadiusY;
                    }
                    grp.Children.Add(NewDrawingItem(shape, rect));
                }
                if (shape is ClipArtViewer.LineShape)
                {
                    ClipArtViewer.LineShape r    = shape as ClipArtViewer.LineShape;
                    LineGeometry            line = new LineGeometry(r.P1, r.P2);
                    grp.Children.Add(NewDrawingItem(shape, line));
                }
                if (shape is ClipArtViewer.PolylineShape)
                {
                    ClipArtViewer.PolylineShape r = shape as ClipArtViewer.PolylineShape;
                    PathGeometry path             = new PathGeometry();
                    PathFigure   p = new PathFigure();
                    path.Figures.Add(p);
                    p.IsClosed   = false;
                    p.StartPoint = r.Points[0];
                    for (int index = 1; index < r.Points.Length; index++)
                    {
                        p.Segments.Add(new LineSegment(r.Points[index], true));
                    }
                    grp.Children.Add(NewDrawingItem(shape, path));
                }
                if (shape is ClipArtViewer.PolygonShape)
                {
                    ClipArtViewer.PolygonShape r = shape as ClipArtViewer.PolygonShape;
                    PathGeometry path            = new PathGeometry();
                    PathFigure   p = new PathFigure();
                    path.Figures.Add(p);
                    p.IsClosed   = true;
                    p.StartPoint = r.Points[0];
                    for (int index = 1; index < r.Points.Length; index++)
                    {
                        p.Segments.Add(new LineSegment(r.Points[index], true));
                    }
                    grp.Children.Add(NewDrawingItem(shape, path));
                }
                if (shape is ClipArtViewer.CircleShape)
                {
                    ClipArtViewer.CircleShape r = shape as ClipArtViewer.CircleShape;
                    EllipseGeometry           c = new EllipseGeometry(new Point(r.CX, r.CY), r.R, r.R);
                    grp.Children.Add(NewDrawingItem(shape, c));
                }
                if (shape is ClipArtViewer.EllipseShape)
                {
                    ClipArtViewer.EllipseShape r = shape as ClipArtViewer.EllipseShape;
                    EllipseGeometry            c = new EllipseGeometry(new Point(r.CX, r.CY), r.RX, r.RY);
                    grp.Children.Add(NewDrawingItem(shape, c));
                }
                if (shape is ClipArtViewer.ImageShape)
                {
                    ClipArtViewer.ImageShape image = shape as ClipArtViewer.ImageShape;
                    ImageDrawing             i     = new ImageDrawing(image.ImageSource, new Rect(image.X, image.Y, image.Width, image.Height));
                    grp.Children.Add(i);
                }
                if (shape is ClipArtViewer.TextShape)
                {
                    GeometryGroup gp = TextRender.BuildTextGeometry(shape as ClipArtViewer.TextShape);
                    if (gp != null)
                    {
                        foreach (Geometry gm in gp.Children)
                        {
                            TextShape.TSpan.Element tspan = TextRender.GetElement(gm);
                            if (tspan != null)
                            {
                                grp.Children.Add(NewDrawingItem(tspan, gm));
                            }
                            else
                            {
                                grp.Children.Add(NewDrawingItem(shape, gm));
                            }
                        }
                    }
                }
                if (shape is ClipArtViewer.PathShape)
                {
                    ClipArtViewer.PathShape r = shape as ClipArtViewer.PathShape;
                    PathFigure p         = null;
                    Point      lastPoint = new Point(0, 0);

                    ClipArtViewer.PathShape.CurveTo lastc = null;
                    Point lastcirPoint = new Point(0, 0);

                    PathGeometry path = new PathGeometry();
                    foreach (ClipArtViewer.PathShape.PathElement element in r.Elements)
                    {
                        bool isRelative = element.IsRelative;
                        if (element is ClipArtViewer.PathShape.MoveTo)
                        {
                            p          = new PathFigure();
                            p.IsClosed = r.ClosePath;
                            if (isRelative)
                            {
                                p.StartPoint = lastPoint + (Vector)((ClipArtViewer.PathShape.MoveTo)element).Point;
                            }
                            else
                            {
                                p.StartPoint = ((ClipArtViewer.PathShape.MoveTo)element).Point;
                            }
                            lastPoint = p.StartPoint;
                            path.Figures.Add(p);
                            continue;
                        }
                        if (element is ClipArtViewer.PathShape.LineTo)
                        {
                            ClipArtViewer.PathShape.LineTo lineto = element as ClipArtViewer.PathShape.LineTo;
                            foreach (Point point in lineto.Points)
                            {
                                if (isRelative)
                                {
                                    Point newpoint = lastPoint + (Vector)point;
                                    lastPoint = newpoint;
                                    p.Segments.Add(new LineSegment(newpoint, true));
                                }
                                else
                                {
                                    if (lineto.PositionType == PathShape.LineTo.eType.Point)
                                    {
                                        lastPoint = point;
                                    }
                                    if (lineto.PositionType == PathShape.LineTo.eType.Horizontal)
                                    {
                                        lastPoint = new Point(point.X, lastPoint.Y);
                                    }
                                    if (lineto.PositionType == PathShape.LineTo.eType.Vertical)
                                    {
                                        lastPoint = new Point(lastPoint.X, point.Y);
                                    }
                                    p.Segments.Add(new LineSegment(lastPoint, true));
                                }
                            }
                            continue;
                        }
                        if (element is ClipArtViewer.PathShape.CurveTo)
                        {
                            ClipArtViewer.PathShape.CurveTo c = element as ClipArtViewer.PathShape.CurveTo;
                            Point         startPoint          = lastPoint;
                            BezierSegment s = new BezierSegment();
                            if (isRelative)
                            {
                                s.Point1 = lastPoint + (Vector)c.CtrlPoint1;

                                if (c.Command == 's')
                                {
                                    // first control point is a mirrored point of last end control point
                                    //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                                    //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);

                                    double dx = lastc.CtrlPoint2.X - lastc.Point.X;
                                    double dy = lastc.CtrlPoint2.Y - lastc.Point.Y;
                                    s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                                    //s.Point1 = lastctrlpoint;
                                }

                                s.Point2 = lastPoint + (Vector)c.CtrlPoint2;
                                s.Point3 = lastPoint + (Vector)c.Point;
                            }
                            else
                            {
                                s.Point1 = c.CtrlPoint1;
                                s.Point2 = c.CtrlPoint2;
                                s.Point3 = c.Point;
                            }
                            lastPoint = s.Point3;
                            p.Segments.Add(s);

                            lastc        = c;
                            lastcirPoint = s.Point3;

                            //debugPoints.Add(new ControlLine(startPoint, s.Point1));
                            //debugPoints.Add(new ControlLine(s.Point3, s.Point2));
                            continue;
                        }
                        if (element is ClipArtViewer.PathShape.EllipticalArcTo)
                        {
                            ClipArtViewer.PathShape.EllipticalArcTo c = element as ClipArtViewer.PathShape.EllipticalArcTo;
                            ArcSegment s = new ArcSegment();
                            if (isRelative)
                            {
                                s.Point = lastPoint + new Vector(c.X, c.Y);
                            }
                            else
                            {
                                s.Point = new Point(c.X, c.Y);
                            }

                            s.Size           = new Size(c.RX, c.RY);
                            s.RotationAngle  = c.AxisRotation;
                            s.SweepDirection = SweepDirection.Counterclockwise;
                            if (c.Clockwise)
                            {
                                s.SweepDirection = SweepDirection.Clockwise;
                            }
                            s.IsLargeArc = c.LargeArc;
                            lastPoint    = s.Point;
                            p.Segments.Add(s);
                            continue;
                        }
                    }

                    /*
                     *                  if (r.Transform != null)
                     *                          path.Transform = r.Transform;
                     */
                    grp.Children.Add(NewDrawingItem(shape, path));
                    //}
                }
            }


            if (debugPoints != null)
            {
                foreach (ControlLine line in debugPoints)
                {
                    grp.Children.Add(line.Draw());
                }
            }
            return(grp);
        }
Exemple #19
0
        private void DoDrawMinorTicks(ICollection <Geometry> lines)
        {
            ITicksProvider <T> minorTicksProvider = ticksProvider.MinorProvider;

            if (minorTicksProvider != null)
            {
                int             minorTicksCount      = prevMinorTicksCount;
                int             prevActualTicksCount = -1;
                ITicksInfo <T>  minorTicks;
                TickCountChange result = TickCountChange.OK;
                TickCountChange prevResult;
                int             iteration = 0;
                do
                {
                    Verify.IsTrue(++iteration < maxTickArrangeIterations);

                    minorTicks = minorTicksProvider.GetTicks(range, minorTicksCount);

                    prevActualTicksCount = minorTicks.Ticks.Length;
                    prevResult           = result;
                    result = CheckMinorTicksArrangement(minorTicks);
                    if (prevResult == TickCountChange.Decrease && result == TickCountChange.Increase)
                    {
                        // stop tick number oscillating
                        result = TickCountChange.OK;
                    }
                    if (result == TickCountChange.Decrease)
                    {
                        int newMinorTicksCount = minorTicksProvider.DecreaseTickCount(minorTicksCount);
                        if (newMinorTicksCount == minorTicksCount)
                        {
                            result = TickCountChange.OK;
                        }
                        minorTicksCount = newMinorTicksCount;
                    }
                    else if (result == TickCountChange.Increase)
                    {
                        int newCount = minorTicksProvider.IncreaseTickCount(minorTicksCount);
                        if (newCount == minorTicksCount)
                        {
                            result = TickCountChange.OK;
                        }
                        minorTicksCount = newCount;
                    }
                } while (result != TickCountChange.OK);
                prevMinorTicksCount = minorTicksCount;

                double[] sizes = minorTicks.TickSizes;

                double[] screenCoords = minorTicks.Ticks.Select(
                    coord => getCoordinate(createDataPoint(convertToDouble(coord)).
                                           DataToScreen(transform))).ToArray();

                minorScreenTicks = new MinorTickInfo <double> [screenCoords.Length];
                for (int i = 0; i < screenCoords.Length; i++)
                {
                    minorScreenTicks[i] = new MinorTickInfo <double>(sizes[i], screenCoords[i]);
                }

                for (int i = 0; i < screenCoords.Length; i++)
                {
                    double screenCoord = screenCoords[i];

                    Point p1 = createScreenPoint1(screenCoord);
                    Point p2 = createScreenPoint2(screenCoord, sizes[i]);

                    LineGeometry line = lineGeomPool.GetOrCreate();
                    line.StartPoint = p1;
                    line.EndPoint   = p2;

                    lines.Add(line);
                }
            }
        }
Exemple #20
0
        private void tabControl1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.Source is TabControl) //if this event fired from TabControl then enter
            {
                if (t1.IsSelected)
                {
                    if (FillerX == null || Filler.mainListFigures.Count == 0)
                    {
                        return;
                    }
                    curentList  = selectfun(1);
                    curentindex = 0;
                    //Do your job here
                    System.Diagnostics.Debug.WriteLine("Tab,change T1");
                    // инфо про фигурку

                    // curentList = selectfun(1);
                }
                if (t2.IsSelected)
                {
                    //Do your job here
                    System.Diagnostics.Debug.WriteLine("Tab,change T2");
                    if (FillerX == null || Filler.mainListFigures.Count == 0)
                    {
                        return;
                    }
                    curentList  = selectfun(2);
                    curentindex = 0;
                    //  drawCountShape(curentList.Count);
                }
                if (t3.IsSelected)
                {
                    //Do your job here
                    System.Diagnostics.Debug.WriteLine("Tab,change T3");
                    if (FillerX == null || Filler.mainListFigures.Count == 0)
                    {
                        return;
                    }
                    curentList  = selectfun(3);
                    curentindex = 0;
                }
                if (t4.IsSelected)
                {
                    //Do your job here
                    System.Diagnostics.Debug.WriteLine("Tab,change T3");
                    if (FillerX == null || Filler.mainListFigures.Count == 0)
                    {
                        return;
                    }
                    curentList  = selectfun(4);
                    curentindex = 0;
                }
                if (t5.IsSelected)
                {
                    //Do your job here
                    System.Diagnostics.Debug.WriteLine("Tab,change T3");
                    if (FillerX == null || Filler.mainListFigures.Count == 0)
                    {
                        return;
                    }
                    curentList  = selectfun(5);
                    curentindex = 0;
                }
                if (t6.IsSelected)
                {
                    //Do your job here
                    System.Diagnostics.Debug.WriteLine("Tab,change T3");
                    if (FillerX == null || Filler.mainListFigures.Count == 0)
                    {
                        return;
                    }
                    curentList  = selectfun(6);
                    curentindex = 0;
                }
                if (t7.IsSelected)
                {
                    //Do your job here
                    System.Diagnostics.Debug.WriteLine("Tab,change T3");
                    if (FillerX == null || Filler.mainListFigures.Count == 0)
                    {
                        return;
                    }
                    curentList  = selectfun(7);
                    curentindex = 0;
                }
                if (t8.IsSelected)
                {
                    //Do your job here
                    System.Diagnostics.Debug.WriteLine("Tab,change T3");
                    if (FillerX == null || Filler.mainListFigures.Count == 0)
                    {
                        return;
                    }
                    curentList  = selectfun(8);
                    curentindex = 0;
                }
                if (t9.IsSelected)
                {
                    //Do your job here
                    System.Diagnostics.Debug.WriteLine("Tab,change T3");
                    if (FillerX == null || Filler.mainListFigures.Count == 0)
                    {
                        return;
                    }
                    curentList  = selectfun(9);
                    curentindex = 0;
                }
            }

            pic.Children.Clear();
            LittleShape2 temp2 = new LittleShape2();

            if (curentindex == curentList.Count)
            {
                curentindex = 0;
            }
            temp2 = curentList.Count != 0 ? curentList[curentindex].Clone() as LittleShape2 : null;

            if (temp2 == null)
            {
                String       str2     = "Нету фигур для отображение";
                FlowDocument flowDoc2 = new FlowDocument(new Paragraph(new Run(str2)));
                textik.Document = flowDoc2;

                return;
            }

            myMatrixTransformScale(ref temp2);
            // cмещаеть все линия по ху и добавлятеься в canvac
            // cледующий клик все чистит и утечки памяти нету, проверено.
            // дефолтное значение

            List <System.Windows.Point> arrpoint = new List <System.Windows.Point>();

            ////////////////////////
            foreach (var item in temp2.path)
            {
                LineGeometry blackLineGeometry = new LineGeometry();


                Line l = moveLine(item);
                arrpoint.Add(new System.Windows.Point(l.X1, l.Y1));
                arrpoint.Add(new System.Windows.Point(l.X2, l.Y2));
            }
            StreamGeometryTriangleExample(arrpoint);



            // инфо про фигурку
            figureInfo(temp2);
        }
Exemple #21
0
        private DrawingGroup LoadGroup(IList <Shape> elements, Rect?viewBox)
        {
            List <ControlLine> debugPoints = new List <ControlLine>();
            DrawingGroup       grp         = new DrawingGroup();

            if (viewBox.HasValue)
            {
                grp.ClipGeometry = new RectangleGeometry(viewBox.Value);
            }

            foreach (Shape shape in elements)
            {
                if (shape is AnimationBase)
                {
                    if (UseAnimations)
                    {
                        if (shape is AnimateTransform animateTransform)
                        {
                            if (animateTransform.Type == AnimateTransformType.Rotate)
                            {
                                var animation = new DoubleAnimation
                                {
                                    From     = double.Parse(animateTransform.From),
                                    To       = double.Parse(animateTransform.To),
                                    Duration = animateTransform.Duration
                                };
                                animation.RepeatBehavior = RepeatBehavior.Forever;
                                var r = new RotateTransform();
                                grp.Transform = r;
                                r.BeginAnimation(RotateTransform.AngleProperty, animation);
                            }
                        }
                        else if (shape is Animate animate)
                        {
                            var target = this.SVG.GetShape(animate.hRef);
                            var g      = target.geometryElement;
                            //todo : rework this all, generalize it!
                            if (animate.AttributeName == "r")
                            {
                                var animation = new DoubleAnimationUsingKeyFrames()
                                {
                                    Duration = animate.Duration
                                };
                                foreach (var d in animate.Values.Split(';').Select(x => new LinearDoubleKeyFrame(double.Parse(x))))
                                {
                                    animation.KeyFrames.Add(d);
                                }
                                animation.RepeatBehavior = RepeatBehavior.Forever;

                                g.BeginAnimation(EllipseGeometry.RadiusXProperty, animation);
                                g.BeginAnimation(EllipseGeometry.RadiusYProperty, animation);
                            }
                            else if (animate.AttributeName == "cx")
                            {
                                var animation = new PointAnimationUsingKeyFrames()
                                {
                                    Duration = animate.Duration
                                };
                                foreach (var d in animate.Values.Split(';').Select(_ => new LinearPointKeyFrame(new Point(double.Parse(_), ((EllipseGeometry)g).Center.Y))))
                                {
                                    animation.KeyFrames.Add(d);
                                }
                                animation.RepeatBehavior = RepeatBehavior.Forever;
                                g.BeginAnimation(EllipseGeometry.CenterProperty, animation);
                            }
                            else if (animate.AttributeName == "cy")
                            {
                                var animation = new PointAnimationUsingKeyFrames()
                                {
                                    Duration = animate.Duration
                                };
                                foreach (var d in animate.Values.Split(';').Select(_ => new LinearPointKeyFrame(new Point(((EllipseGeometry)g).Center.X, double.Parse(_)))))
                                {
                                    animation.KeyFrames.Add(d);
                                }
                                animation.RepeatBehavior = RepeatBehavior.Forever;
                                g.BeginAnimation(EllipseGeometry.CenterProperty, animation);
                            }
                        }
                    }

                    continue;
                }

                if (shape is UseShape)
                {
                    UseShape useshape = shape as UseShape;
                    Group    group    = this.SVG.GetShape(useshape.hRef) as Group;
                    if (group != null)
                    {
                        Shape oldparent = group.Parent;
                        group.Parent = useshape; // this to get proper style propagated
                        DrawingGroup subgroup = this.LoadGroup(group.Elements, null);
                        if (group.Clip != null)
                        {
                            subgroup.ClipGeometry = group.Clip.ClipGeometry;
                        }
                        subgroup.Transform = new TranslateTransform(useshape.X, useshape.Y);
                        grp.Children.Add(subgroup);
                        group.Parent = oldparent;
                    }
                    continue;
                }
                if (shape is Clip)
                {
                    DrawingGroup subgroup = this.LoadGroup((shape as Clip).Elements, null);
                    if (shape.Transform != null)
                    {
                        subgroup.Transform = shape.Transform;
                    }
                    grp.Children.Add(subgroup);
                    continue;
                }
                if (shape is Group)
                {
                    DrawingGroup subgroup = this.LoadGroup((shape as Group).Elements, null);
                    AddDrawingToGroup(grp, shape, subgroup);
                    continue;
                }
                if (shape is RectangleShape)
                {
                    RectangleShape    r    = shape as RectangleShape;
                    RectangleGeometry rect = new RectangleGeometry(new Rect(r.X, r.Y, r.Width, r.Height));
                    rect.RadiusX = r.RX;
                    rect.RadiusY = r.RY;
                    if (rect.RadiusX == 0 && rect.RadiusY > 0)
                    {
                        rect.RadiusX = rect.RadiusY;
                    }
                    var di = this.NewDrawingItem(shape, rect);
                    AddDrawingToGroup(grp, shape, di);
                }
                if (shape is LineShape)
                {
                    LineShape    r    = shape as LineShape;
                    LineGeometry line = new LineGeometry(r.P1, r.P2);
                    var          di   = this.NewDrawingItem(shape, line);
                    AddDrawingToGroup(grp, shape, di);
                }
                if (shape is PolylineShape)
                {
                    PolylineShape r    = shape as PolylineShape;
                    PathGeometry  path = new PathGeometry();
                    PathFigure    p    = new PathFigure();
                    path.Figures.Add(p);
                    p.IsClosed   = false;
                    p.StartPoint = r.Points[0];
                    for (int index = 1; index < r.Points.Length; index++)
                    {
                        p.Segments.Add(new LineSegment(r.Points[index], true));
                    }
                    var di = this.NewDrawingItem(shape, path);
                    AddDrawingToGroup(grp, shape, di);
                }
                if (shape is PolygonShape)
                {
                    PolygonShape r    = shape as PolygonShape;
                    PathGeometry path = new PathGeometry();
                    PathFigure   p    = new PathFigure();
                    path.Figures.Add(p);
                    p.IsClosed   = true;
                    p.StartPoint = r.Points[0];
                    for (int index = 1; index < r.Points.Length; index++)
                    {
                        p.Segments.Add(new LineSegment(r.Points[index], true));
                    }
                    var di = this.NewDrawingItem(shape, path);
                    AddDrawingToGroup(grp, shape, di);
                }
                if (shape is CircleShape)
                {
                    CircleShape     r  = shape as CircleShape;
                    EllipseGeometry c  = new EllipseGeometry(new Point(r.CX, r.CY), r.R, r.R);
                    var             di = this.NewDrawingItem(shape, c);
                    AddDrawingToGroup(grp, shape, di);
                }
                if (shape is EllipseShape)
                {
                    EllipseShape    r  = shape as EllipseShape;
                    EllipseGeometry c  = new EllipseGeometry(new Point(r.CX, r.CY), r.RX, r.RY);
                    var             di = this.NewDrawingItem(shape, c);
                    AddDrawingToGroup(grp, shape, di);
                }
                if (shape is ImageShape)
                {
                    ImageShape   image = shape as ImageShape;
                    ImageDrawing i     = new ImageDrawing(image.ImageSource, new Rect(image.X, image.Y, image.Width, image.Height));
                    AddDrawingToGroup(grp, shape, i);
                }
                if (shape is TextShape)
                {
                    GeometryGroup gp = TextRender.BuildTextGeometry(shape as TextShape);
                    if (gp != null)
                    {
                        foreach (Geometry gm in gp.Children)
                        {
                            TextShape.TSpan.Element tspan = TextRender.GetElement(gm);
                            if (tspan != null)
                            {
                                var di = this.NewDrawingItem(tspan, gm);
                                AddDrawingToGroup(grp, shape, di);
                            }
                            else
                            {
                                var di = this.NewDrawingItem(shape, gm);
                                AddDrawingToGroup(grp, shape, di);
                            }
                        }
                    }
                }
                if (shape is PathShape)
                {
                    PathShape  r         = shape as PathShape;
                    PathFigure p         = null;
                    Point      lastPoint = new Point(0, 0);

                    PathShape.CurveTo          lastc = null;
                    PathShape.QuadraticCurveTo lastq = null;
                    Point lastcirPoint = new Point(0, 0);

                    PathGeometry path = new PathGeometry();
                    foreach (PathShape.PathElement element in r.Elements)
                    {
                        bool isRelative = element.IsRelative;
                        if (element is PathShape.MoveTo)
                        {
                            p          = new PathFigure();
                            p.IsClosed = r.ClosePath;
                            if (isRelative)
                            {
                                p.StartPoint = lastPoint + (Vector)((PathShape.MoveTo)element).Point;
                            }
                            else
                            {
                                p.StartPoint = ((PathShape.MoveTo)element).Point;
                            }
                            lastPoint = p.StartPoint;
                            path.Figures.Add(p);
                            continue;
                        }
                        if (element is PathShape.LineTo)
                        {
                            PathShape.LineTo lineto = element as PathShape.LineTo;
                            foreach (Point point in lineto.Points)
                            {
                                if (isRelative)
                                {
                                    Point newpoint = lastPoint + (Vector)point;
                                    lastPoint = newpoint;
                                    p.Segments.Add(new LineSegment(newpoint, true));
                                }
                                else
                                {
                                    if (lineto.PositionType == PathShape.LineTo.eType.Point)
                                    {
                                        lastPoint = point;
                                    }
                                    if (lineto.PositionType == PathShape.LineTo.eType.Horizontal)
                                    {
                                        lastPoint = new Point(point.X, lastPoint.Y);
                                    }
                                    if (lineto.PositionType == PathShape.LineTo.eType.Vertical)
                                    {
                                        lastPoint = new Point(lastPoint.X, point.Y);
                                    }
                                    p.Segments.Add(new LineSegment(lastPoint, true));
                                }
                            }
                            continue;
                        }
                        if (element is PathShape.CurveTo)
                        {
                            PathShape.CurveTo c          = element as PathShape.CurveTo;
                            Point             startPoint = lastPoint;
                            BezierSegment     s          = new BezierSegment();
                            if (isRelative)
                            {
                                s.Point1 = lastPoint + (Vector)c.CtrlPoint1;

                                if (c.Command == 's')
                                {
                                    // first control point is a mirrored point of last end control point
                                    //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                                    //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);

                                    double dx = lastc.CtrlPoint2.X - lastc.Point.X;
                                    double dy = lastc.CtrlPoint2.Y - lastc.Point.Y;
                                    s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                                    //s.Point1 = lastctrlpoint;
                                }

                                s.Point2 = lastPoint + (Vector)c.CtrlPoint2;
                                s.Point3 = lastPoint + (Vector)c.Point;
                            }
                            else
                            {
                                if (c.Command == 's')
                                {
                                    // first control point is a mirrored point of last end control point
                                    //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                                    //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);

                                    double dx = lastc.CtrlPoint2.X - lastc.Point.X;
                                    double dy = lastc.CtrlPoint2.Y - lastc.Point.Y;
                                    s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                                }
                                else
                                {
                                    s.Point1 = c.CtrlPoint1;
                                }
                                s.Point2 = c.CtrlPoint2;
                                s.Point3 = c.Point;
                            }
                            lastPoint = s.Point3;
                            p.Segments.Add(s);

                            lastc        = c;
                            lastcirPoint = s.Point3;

                            //debugPoints.Add(new ControlLine(startPoint, s.Point1));
                            //debugPoints.Add(new ControlLine(s.Point3, s.Point2));
                            continue;
                        }
                        if (element is PathShape.QuadraticCurveTo)
                        {
                            PathShape.QuadraticCurveTo c = element as PathShape.QuadraticCurveTo;
                            Point startPoint             = lastPoint;
                            QuadraticBezierSegment s     = new QuadraticBezierSegment();
                            if (isRelative)
                            {
                                s.Point1 = lastPoint + (Vector)c.CtrlPoint1;

                                if (c.Command == 'q')
                                {
                                    // first control point is a mirrored point of last end control point
                                    //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                                    //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);

                                    double dx = lastq.CtrlPoint1.X - lastq.Point.X;
                                    double dy = lastq.CtrlPoint1.Y - lastq.Point.Y;
                                    s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                                    //s.Point1 = lastctrlpoint;
                                }

                                s.Point2 = lastPoint + (Vector)c.Point;
                            }
                            else
                            {
                                if (c.Command == 'q')
                                {
                                    // first control point is a mirrored point of last end control point
                                    //s.Point1 = lastPoint + new Vector(lastc.Point.X - dx, lastc.Point.Y - dy);
                                    //s.Point1 = new Point(lastctrlpoint.X+2, lastctrlpoint.Y+2);

                                    double dx = lastq.CtrlPoint1.X - lastq.Point.X;
                                    double dy = lastq.CtrlPoint1.Y - lastq.Point.Y;
                                    s.Point1 = new Point(lastcirPoint.X - dx, lastcirPoint.Y - dy);
                                }
                                else
                                {
                                    s.Point1 = c.CtrlPoint1;
                                }
                                s.Point2 = c.Point;
                            }
                            lastPoint = s.Point2;
                            p.Segments.Add(s);

                            lastq        = c;
                            lastcirPoint = s.Point2;

                            //debugPoints.Add(new ControlLine(startPoint, s.Point1));
                            //debugPoints.Add(new ControlLine(s.Point3, s.Point2));
                            continue;
                        }
                        if (element is PathShape.EllipticalArcTo)
                        {
                            PathShape.EllipticalArcTo c = element as PathShape.EllipticalArcTo;
                            ArcSegment s = new ArcSegment();
                            if (isRelative)
                            {
                                s.Point = lastPoint + new Vector(c.X, c.Y);
                            }
                            else
                            {
                                s.Point = new Point(c.X, c.Y);
                            }

                            s.Size           = new Size(c.RX, c.RY);
                            s.RotationAngle  = c.AxisRotation;
                            s.SweepDirection = SweepDirection.Counterclockwise;
                            if (c.Clockwise)
                            {
                                s.SweepDirection = SweepDirection.Clockwise;
                            }
                            s.IsLargeArc = c.LargeArc;
                            lastPoint    = s.Point;
                            p.Segments.Add(s);
                            continue;
                        }
                    }

                    /*
                     * if (r.Transform != null)
                     *  path.Transform = r.Transform;
                     */
                    var di = this.NewDrawingItem(shape, path);
                    AddDrawingToGroup(grp, shape, di);
                    //}
                }
            }


            if (debugPoints != null)
            {
                foreach (ControlLine line in debugPoints)
                {
                    grp.Children.Add(line.Draw());
                }
            }
            return(grp);
        }
Exemple #22
0
        public static IEnumerable <Point> GetLinePoints(this LineGeometry lineGeometry)
        {
            yield return(lineGeometry.StartPoint);

            yield return(lineGeometry.EndPoint);
        }
Exemple #23
0
        private Geometry DrawCurrentStrokeMode()
        {
            Geometry g = new StreamGeometry();

            firstPoint = (Point)StylusPoints[0];
            lastPoint  = (Point)StylusPoints[StylusPoints.Count - 1];
            Vector v     = Point.Subtract(firstPoint, lastPoint);
            Point  vHalf = new Point((firstPoint.X + lastPoint.X) / 2, (firstPoint.Y + lastPoint.Y) / 2);

            Geometry shapeGeo;
            bool     closed = true;

            switch (strokeMode)
            {
            case DrawingStrokeType.Text:
                shapeGeo = new EllipseGeometry(vHalf, v.Length / 2, v.Length / 2);
                if (text != null)
                {
                    shapeGeo = text;
                    pen      = null;
                }
                break;

            case DrawingStrokeType.Shape_Ellipse:
                shapeGeo = new EllipseGeometry(vHalf, v.Length / 2, v.Length / 2);
                break;

            case DrawingStrokeType.Shape_Rectangle:
                shapeGeo = new RectangleGeometry(new Rect(firstPoint, lastPoint));
                break;

            case DrawingStrokeType.Shape_Triangle:
                Point p3 = new Point(firstPoint.X + (firstPoint.X - lastPoint.X), lastPoint.Y);
                shapeGeo = new StreamGeometry();
                using (StreamGeometryContext ctx = ((StreamGeometry)shapeGeo).Open())
                {
                    ctx.BeginFigure((Point)firstPoint, true, true);
                    ctx.LineTo((Point)lastPoint, true, false);
                    ctx.LineTo((Point)p3, true, false);
                }
                break;

            case DrawingStrokeType.Line_Line:
                shapeGeo = new LineGeometry(firstPoint, lastPoint);
                closed   = false;
                break;

            case DrawingStrokeType.Line_Arrow:
                Vector fir = new Vector(firstPoint.X, firstPoint.Y);
                Vector cur = new Vector(lastPoint.X, lastPoint.Y);
                float  h   = (10.0f + (float)(pen.Thickness / 2.0)) * (float)Math.Sqrt(3);
                float  w   = 10.0f + (float)(pen.Thickness / 2.0);
                Vector u   = (cur - fir) / (cur - fir).Length;
                Vector uv  = new Vector(-u.Y, u.X);
                Vector av1 = cur - h * u + w * uv;
                Vector av2 = cur - h * u - w * uv;
                Point  a1  = new Point(av1.X, av1.Y);
                Point  a2  = new Point(av2.X, av2.Y);
                shapeGeo = new StreamGeometry();
                using (StreamGeometryContext ctx = ((StreamGeometry)shapeGeo).Open())
                {
                    ctx.BeginFigure(firstPoint, true, false);
                    ctx.LineTo(lastPoint, true, false);
                    ctx.BeginFigure(lastPoint, true, false);
                    ctx.LineTo(a1, true, false);
                    ctx.BeginFigure(lastPoint, true, false);
                    ctx.LineTo(a2, true, false);
                }
                shapeGeo.Freeze();
                closed = false;
                break;

            case DrawingStrokeType.Line_CoordQuad:
                shapeGeo = new StreamGeometry();
                Point qP = new Point(firstPoint.X, lastPoint.Y);
                using (StreamGeometryContext ctx = ((StreamGeometry)shapeGeo).Open())
                {
                    ctx.BeginFigure(firstPoint, true, false);
                    ctx.LineTo(qP, true, false);
                    ctx.BeginFigure(qP, true, false);
                    ctx.LineTo(lastPoint, true, false);
                }
                shapeGeo.Freeze();
                closed = false;
                break;

            case DrawingStrokeType.Line_Coord2D:
                Point xNeg2d = new Point(firstPoint.X + (firstPoint.X - lastPoint.X), lastPoint.Y);
                Point yNeg2d = new Point(firstPoint.X, lastPoint.Y + (lastPoint.Y - firstPoint.Y));
                shapeGeo = new StreamGeometry();
                using (StreamGeometryContext ctx = ((StreamGeometry)shapeGeo).Open())
                {
                    ctx.BeginFigure((Point)firstPoint, true, true);
                    ctx.LineTo((Point)yNeg2d, true, false);
                    ctx.BeginFigure((Point)lastPoint, true, true);
                    ctx.LineTo((Point)xNeg2d, true, false);
                }
                shapeGeo.Freeze();
                closed = false;
                break;

            case DrawingStrokeType.Line_Coord3D:
                int   numDashes = 42;
                Point xNeg3d    = new Point(firstPoint.X + (firstPoint.X - lastPoint.X), lastPoint.Y);
                Point yNeg3d    = new Point(firstPoint.X, lastPoint.Y + (lastPoint.Y - firstPoint.Y));
                Point zNeg3d    = new Point(lastPoint.X, firstPoint.Y);
                Point zPos3d    = new Point(xNeg3d.X, yNeg3d.Y);
                shapeGeo = new StreamGeometry();
                using (StreamGeometryContext ctx = ((StreamGeometry)shapeGeo).Open())
                {
                    ctx.BeginFigure((Point)firstPoint, true, true);
                    ctx.LineTo((Point)yNeg3d, true, false);
                    ctx.BeginFigure((Point)lastPoint, true, true);
                    ctx.LineTo((Point)xNeg3d, true, false);
                    for (int i = 0; i < numDashes; i++)
                    {
                        Point a;
                        a  = new Point(zNeg3d.X - ((zNeg3d.X - zPos3d.X) * ((double)i / (numDashes))), zNeg3d.Y - ((zNeg3d.Y - zPos3d.Y) * ((double)i / (numDashes))));
                        i += 1;
                        Point b = new Point(zNeg3d.X - ((zNeg3d.X - zPos3d.X) * ((double)i / (numDashes))), (zNeg3d.Y - (zNeg3d.Y - zPos3d.Y) * ((double)i / (numDashes))));
                        ctx.BeginFigure((Point)a, true, true);
                        ctx.LineTo((Point)b, true, false);
                        i += 2;
                    }
                    closed = false;
                }
                shapeGeo.Freeze();
                break;

            default:
                shapeGeo = new EllipseGeometry(vHalf, v.Length / 2, v.Length / 2);
                break;
            }
            g = GenerateStylusPoints(shapeGeo, closed);
            return(g);
        }
Exemple #24
0
        public static WMedia.Geometry ToNative(this Geometry geometry)
        {
            WMedia.Geometry wGeometry = null;

            if (geometry is LineGeometry)
            {
                LineGeometry lineGeometry = geometry as LineGeometry;
                wGeometry = new WMedia.LineGeometry
                {
                    StartPoint = lineGeometry.StartPoint.ToNative(),
                    EndPoint   = lineGeometry.EndPoint.ToNative()
                };
            }
            else if (geometry is RectangleGeometry)
            {
                var rect = (geometry as RectangleGeometry).Rect;
                wGeometry = new WMedia.RectangleGeometry
                {
                    Rect = new WFoundation.Rect(rect.X, rect.Y, rect.Width, rect.Height)
                };
            }
            else if (geometry is EllipseGeometry)
            {
                EllipseGeometry ellipseGeometry = geometry as EllipseGeometry;
                wGeometry = new WMedia.EllipseGeometry
                {
                    Center  = ellipseGeometry.Center.ToNative(),
                    RadiusX = ellipseGeometry.RadiusX,
                    RadiusY = ellipseGeometry.RadiusY
                };
            }
            else if (geometry is GeometryGroup)
            {
                GeometryGroup geometryGroup = geometry as GeometryGroup;
                wGeometry = new WMedia.GeometryGroup
                {
                    FillRule = ConvertFillRule(geometryGroup.FillRule)
                };

                foreach (Geometry children in geometryGroup.Children)
                {
                    WMedia.Geometry winChild = children.ToNative();
                    (wGeometry as WMedia.GeometryGroup).Children.Add(winChild);
                }
            }
            else if (geometry is PathGeometry)
            {
                PathGeometry pathGeometry = geometry as PathGeometry;

                WMedia.PathGeometry wPathGeometry = new WMedia.PathGeometry
                {
                    FillRule = ConvertFillRule(pathGeometry.FillRule)
                };

                foreach (PathFigure xamPathFigure in pathGeometry.Figures)
                {
                    WMedia.PathFigure wPathFigure = new WMedia.PathFigure
                    {
                        StartPoint = xamPathFigure.StartPoint.ToNative(),
                        IsFilled   = xamPathFigure.IsFilled,
                        IsClosed   = xamPathFigure.IsClosed
                    };
                    wPathGeometry.Figures.Add(wPathFigure);

                    foreach (PathSegment pathSegment in xamPathFigure.Segments)
                    {
                        // LineSegment
                        if (pathSegment is LineSegment)
                        {
                            LineSegment lineSegment = pathSegment as LineSegment;

                            WMedia.LineSegment winSegment = new WMedia.LineSegment
                            {
                                Point = lineSegment.Point.ToNative()
                            };

                            wPathFigure.Segments.Add(winSegment);
                        }

                        // PolylineSegment
                        if (pathSegment is PolyLineSegment)
                        {
                            PolyLineSegment        polyLineSegment = pathSegment as PolyLineSegment;
                            WMedia.PolyLineSegment wSegment        = new WMedia.PolyLineSegment();

                            foreach (var point in polyLineSegment.Points)
                            {
                                wSegment.Points.Add(point.ToNative());
                            }

                            wPathFigure.Segments.Add(wSegment);
                        }

                        // BezierSegment
                        if (pathSegment is BezierSegment)
                        {
                            BezierSegment bezierSegment = pathSegment as BezierSegment;

                            WMedia.BezierSegment wSegment = new WMedia.BezierSegment
                            {
                                Point1 = bezierSegment.Point1.ToNative(),
                                Point2 = bezierSegment.Point2.ToNative(),
                                Point3 = bezierSegment.Point3.ToNative()
                            };

                            wPathFigure.Segments.Add(wSegment);
                        }
                        // PolyBezierSegment
                        else if (pathSegment is PolyBezierSegment)
                        {
                            PolyBezierSegment        polyBezierSegment = pathSegment as PolyBezierSegment;
                            WMedia.PolyBezierSegment wSegment          = new WMedia.PolyBezierSegment();

                            foreach (var point in polyBezierSegment.Points)
                            {
                                wSegment.Points.Add(point.ToNative());
                            }

                            wPathFigure.Segments.Add(wSegment);
                        }

                        // QuadraticBezierSegment
                        if (pathSegment is QuadraticBezierSegment)
                        {
                            QuadraticBezierSegment quadraticBezierSegment = pathSegment as QuadraticBezierSegment;

                            WMedia.QuadraticBezierSegment wSegment = new WMedia.QuadraticBezierSegment
                            {
                                Point1 = quadraticBezierSegment.Point1.ToNative(),
                                Point2 = quadraticBezierSegment.Point2.ToNative()
                            };

                            wPathFigure.Segments.Add(wSegment);
                        }
                        // PolyQuadraticBezierSegment
                        else if (pathSegment is PolyQuadraticBezierSegment)
                        {
                            PolyQuadraticBezierSegment        polyQuadraticBezierSegment = pathSegment as PolyQuadraticBezierSegment;
                            WMedia.PolyQuadraticBezierSegment wSegment = new WMedia.PolyQuadraticBezierSegment();

                            foreach (var point in polyQuadraticBezierSegment.Points)
                            {
                                wSegment.Points.Add(point.ToNative());
                            }

                            wPathFigure.Segments.Add(wSegment);
                        }
                        // ArcSegment
                        else if (pathSegment is ArcSegment)
                        {
                            ArcSegment arcSegment = pathSegment as ArcSegment;

                            WMedia.ArcSegment wSegment = new WMedia.ArcSegment
                            {
                                Size           = new WFoundation.Size(arcSegment.Size.Width, arcSegment.Size.Height),
                                RotationAngle  = arcSegment.RotationAngle,
                                IsLargeArc     = arcSegment.IsLargeArc,
                                SweepDirection = arcSegment.SweepDirection == SweepDirection.Clockwise ? WMedia.SweepDirection.Clockwise : WMedia.SweepDirection.Counterclockwise,
                                Point          = arcSegment.Point.ToNative()
                            };

                            wPathFigure.Segments.Add(wSegment);
                        }
                    }
                }

                wGeometry = wPathGeometry;
            }

            return(wGeometry);
        }
Exemple #25
0
        private void DrawCanvas(Size axisSize, double[] cTicks)
        {
            double length = IsHorizontal ? axisSize.Width : axisSize.Height;

            GeometryGroup majorTicksGeometry = new GeometryGroup();
            GeometryGroup minorTicksGeometry = new GeometryGroup();

            if (!Double.IsNaN(length) && length != 0)
            {
                int start = 0;
                if (cTicks.Length > 0 && cTicks[0] < Range.Min)
                {
                    start++;
                }

                if (Range.IsPoint)
                {
                    drawMinorTicks = false;
                }

                for (int i = start; i < cTicks.Length; i++)
                {
                    LineGeometry line = new LineGeometry();
                    majorTicksGeometry.Children.Add(line);

                    if (IsHorizontal)
                    {
                        line.StartPoint = new Point(GetCoordinateFromTick(cTicks[i], axisSize), 0);
                        line.EndPoint   = new Point(GetCoordinateFromTick(cTicks[i], axisSize), tickLength);
                    }
                    else
                    {
                        line.StartPoint = new Point(0, GetCoordinateFromTick(cTicks[i], axisSize));
                        line.EndPoint   = new Point(tickLength, GetCoordinateFromTick(cTicks[i], axisSize));
                    }

                    if (labels[i] is TextBlock)
                    {
                        (labels[i] as TextBlock).Foreground = Foreground;
                    }
                    else if (labels[i] is Control)
                    {
                        (labels[i] as Control).Foreground = Foreground;
                    }

                    Children.Add(labels[i]);
                }

                if (drawMinorTicks)
                {
                    double[] minorTicks = ticksProvider.GetMinorTicks(Range);
                    if (minorTicks != null)
                    {
                        for (int j = 0; j < minorTicks.Length; j++)
                        {
                            LineGeometry line = new LineGeometry();
                            minorTicksGeometry.Children.Add(line);

                            if (IsHorizontal)
                            {
                                line.StartPoint = new Point(GetCoordinateFromTick(minorTicks[j], axisSize), 0);
                                line.EndPoint   = new Point(GetCoordinateFromTick(minorTicks[j], axisSize), tickLength / 2.0);
                            }
                            else
                            {
                                line.StartPoint = new Point(0, GetCoordinateFromTick(minorTicks[j], axisSize));
                                line.EndPoint   = new Point(tickLength / 2.0, GetCoordinateFromTick(minorTicks[j], axisSize));
                            }
                        }
                    }
                }

                majorTicksPath.Data = majorTicksGeometry;
                minorTicksPath.Data = minorTicksGeometry;

                if (!drawMinorTicks)
                {
                    drawMinorTicks = true;
                }
            }
        }
Exemple #26
0
        private void DoDrawMinorTicks(GeometryGroup geomGroup)
        {
            ITicksProvider <T> minorTicksProvider = ticksProvider.MinorProvider;

            if (minorTicksProvider != null)
            {
                int            minorTicksCount      = DefaultTicksProvider.DefaultTicksCount;
                int            prevActualTicksCount = -1;
                ITicksInfo <T> minorTicks;
                TickChange     result = TickChange.OK;
                TickChange     prevResult;
                int            iteration            = 0;
                bool           stopTicksCountTuning = false;
                //PerformanceCounter.startStopwatch("Minor ticks: computing tickCounts");
                do
                {
                    Verify.IsTrue(++iteration < maxTickArrangeIterations);

                    minorTicks = minorTicksProvider.GetTicks(range, minorTicksCount);

                    prevActualTicksCount = minorTicks.Ticks.Length;
                    prevResult           = result;
                    if (minorTicksCount > minorTicksUpperConstraint)
                    {
                        result = TickChange.Decrease;
                    }
                    else
                    {
                        result = CheckMinorTicksArrangement(minorTicks);
                    }

                    if (prevResult == TickChange.Decrease && result == TickChange.Increase)
                    {
                        // stop tick number oscillating
                        result = TickChange.OK;
                    }
                    if (result != TickChange.OK)
                    {
                        int newMinorTicksCount = 0;
                        if (result == TickChange.Decrease)
                        {
                            newMinorTicksCount = minorTicksProvider.DecreaseTickCount(minorTicksCount);
                        }
                        else if (result == TickChange.Increase)
                        {
                            newMinorTicksCount = minorTicksProvider.IncreaseTickCount(minorTicksCount);
                        }

                        if (newMinorTicksCount == minorTicksCount)
                        {
                            result = TickChange.OK;
                        }
                        minorTicksCount = newMinorTicksCount;
                    }
                    minorTicksGenNumber = minorTicksCount;
                } while (result != TickChange.OK && !stopTicksCountTuning);
                //PerformanceCounter.stopStopwatch("Minor ticks: computing tickCounts");

                minorTicks = minorTicksProvider.GetTicks(range, minorTicksCount);


                double[] sizes = minorTicks.TickSizes;

                double[] screenCoords = minorTicks.Ticks.Select(
                    coord => getCoordinate(createDataPoint(convertToDouble(coord)).
                                           DataToScreen(transform))).ToArray();

                minorScreenTicks = new MinorTickInfo <double> [screenCoords.Length];
                for (int i = 0; i < screenCoords.Length; i++)
                {
                    minorScreenTicks[i] = new MinorTickInfo <double>(sizes[i], screenCoords[i]);
                }

                for (int i = 0; i < screenCoords.Length; i++)
                {
                    double screenCoord = screenCoords[i];
                    if (i + usedTicks < allocatedTicks)
                    {
                        //PerformanceCounter.startStopwatch("Minor ticks: getting allocated lines");
                        LineGeometry line = allocatedTicksList[i + usedTicks];
                        //PerformanceCounter.stopStopwatch("Minor ticks: getting allocated lines");
                        //PerformanceCounter.startStopwatch("Minor ticks: renewing allocated lines");
                        line.StartPoint = createScreenPoint1(screenCoord);;
                        line.EndPoint   = createScreenPoint2(screenCoord, sizes[i]);
                        //PerformanceCounter.stopStopwatch("Minor ticks: renewing allocated lines");
                    }
                    else
                    {
                        //PerformanceCounter.startStopwatch("Minor ticks: creating new lines");
                        LineGeometry line = new LineGeometry();
                        line.StartPoint = createScreenPoint1(screenCoord);;
                        line.EndPoint   = createScreenPoint2(screenCoord, sizes[i]);
                        geomGroup.Children.Add(line);
                        allocatedTicksList.Add(line);
                        //PerformanceCounter.stopStopwatch("Minor ticks: creating new lines");
                    }
                }
                usedTicks += screenCoords.Length;
            }
        }
Exemple #27
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            double width;
            double height;

//            FormattedText formattedText = new System.Windows.Media.FormattedText("ABC",
//CultureInfo.GetCultureInfo("en-us"),
//FlowDirection.LeftToRight,
//new Typeface(
//new FontFamily("Franklin Gothic"),
//FontStyles.Normal,
//FontWeights.Normal,
//FontStretches.Normal),
//8, Brushes.Red);

//            Geometry geometryx = formattedText.BuildGeometry(new Point(50, 80));

//            return geometryx;
//            System.Windows.Shapes.Path path = new System.Windows.Shapes.Path();
//            path.Data = geometryx;

//            string geometryAsString = geometryx.GetFlattenedPathGeometry().ToString().Replace(",", ".").Replace(";", ",");
//            return geometryAsString;



            if (values.Length == 3)
            {
                if (values[2].ToString() == "")
                {
                    return(null);
                }
                width  = (double)values[0];
                height = (double)values[1];
                //double LineThickness = (double)values[2];

                var valueAngle = values[2].ToString().Split(',');

                Point        Center   = new Point(width / 2d, height / 2d);
                Point        Origine  = new Point(Center.X, 0);
                PathGeometry geometry = new PathGeometry();
                foreach (var angle in valueAngle)
                {
                    RotateTransform tr   = new RotateTransform(int.Parse(angle), Center.X, Center.Y);
                    LineGeometry    line = new LineGeometry(Center, Origine, tr);
                    geometry.AddGeometry(line);
                }

                return(geometry);
            }



            int glyph = (int)values[0];

            if (glyph == 0)
            {
                return(null);
            }

            if (values.Length == 2)  // Path.Fill Binding
            {
                if (glyph == 2 || glyph == 3)
                {
                    return(new SolidColorBrush((Color)values[1]));
                }
                else
                {
                    return(null);
                }
            }
            // Path.Data binding
            double glyphScale = (double)values[1];

            width  = (double)values[2];
            height = (double)values[3];
            switch (glyph)
            {
            case 1:
                Point           Center = new Point(width / 2d, height / 2d);
                double          Radius = Math.Min(width, height) / 2d * glyphScale;
                EllipseGeometry Circle = new EllipseGeometry(Center, Radius, Radius);
                return(Circle);

            case 2:     // right arrow
            case 3:     // left arrow
                double glyphThickness = (double)values[4];
                double y                = height / 2d;
                double arrowLength      = width * glyphScale;
                double padding          = (width - arrowLength) / 2d;
                double arrowLineLength  = arrowLength * .6d;
                double headHeightOffset = glyphThickness * 2d;

                Point lineStart, lineEnd, head, head1, head2;

                if (glyph == 2)
                {
                    lineStart = new Point(padding, y);
                    lineEnd   = new Point(lineStart.X + arrowLineLength, y);
                    head      = new Point(width - padding, y);
                    head1     = new Point(lineEnd.X, y - headHeightOffset);
                    head2     = new Point(lineEnd.X, y + headHeightOffset);
                }
                else
                {
                    lineStart = new Point(width - padding, y);
                    lineEnd   = new Point(lineStart.X - arrowLineLength, y);
                    head      = new Point(padding, y);
                    head1     = new Point(lineEnd.X, y + headHeightOffset);
                    head2     = new Point(lineEnd.X, y - headHeightOffset);
                }

                PathFigure arrow = new PathFigure();
                arrow.IsClosed = false;

                arrow.StartPoint = lineStart;
                arrow.Segments.Add(new LineSegment(lineEnd, true));
                arrow.Segments.Add(new LineSegment(head1, false));
                arrow.Segments.Add(new LineSegment(head, false));
                arrow.Segments.Add(new LineSegment(head2, false));
                arrow.Segments.Add(new LineSegment(lineEnd, false));

                PathGeometry geometry = new PathGeometry();

                geometry.Figures.Add(arrow);
                return(geometry);

            case 4:     // upCaret
            case 5:     // downCaret
                double centerX = width / 2d;
                double centerY = height / 2d;
                double offsetX = centerX * glyphScale;
                double offsetY = offsetX / 2d * (glyph == 4 ? 1 : -1);


                PathFigure figure = new PathFigure();
                figure.IsClosed = false;
                figure.IsFilled = false;

                figure.StartPoint = new Point(centerX - offsetX, centerY + offsetY);
                figure.Segments.Add(new LineSegment(new Point(centerX, centerY - offsetY), true));
                figure.Segments.Add(new LineSegment(new Point(centerX + offsetX, centerY + offsetY), true));

                PathGeometry geometry2 = new PathGeometry();
                geometry2.Figures.Add(figure);
                return(geometry2);


            default:
                return(null);
            }
        }
Exemple #28
0
        void DrawExpression(Canvas c, string code)
        {
            ClearCanvas(c);
            string[] strokes = code.Split(new[] { "|=" }, StringSplitOptions.None);
            foreach (string s in strokes)
            {
                System.Windows.Point current_position = GridCenterRealSize;
                string[]             actions          = s.Split('+');
                foreach (string a in actions)
                {
                    char operation_command = a.Trim().Split('(')[0][0];
                    int  operation_x       = Int32.Parse(a.Trim().Split('(')[1].Split(',')[0]);
                    int  operation_y       = Int32.Parse(a.Trim().Split('(')[1].Split(',')[1].TrimEnd(')'));
                    System.Windows.Point operation_moves = new System.Windows.Point(operation_x * GridSize, operation_y * GridSize);
                    System.Windows.Point new_position    = new System.Windows.Point(current_position.X + operation_moves.X, current_position.Y - operation_moves.Y);

                    System.Windows.Shapes.Path path       = new System.Windows.Shapes.Path();
                    SolidColorBrush            blackBrush = new SolidColorBrush();
                    blackBrush.Color     = Colors.Black;
                    path.Stroke          = blackBrush;
                    path.StrokeThickness = 3;

                    switch (operation_command)
                    {
                    case 'P':
                        current_position.X = GridCenterRealSize.X + operation_moves.X;
                        current_position.Y = GridCenterRealSize.Y - operation_moves.Y;
                        break;

                    case 'L':
                        LineGeometry line = new LineGeometry();
                        line.StartPoint = current_position;
                        line.EndPoint   = new_position;
                        path.Data       = line;
                        c.Children.Add(path);
                        current_position = new_position;
                        break;

                    case 'A':
                        bool          clockwise       = a.Trim().Split('(')[0].Split('_')[1] == "CW";
                        GeometryGroup myGeometryGroup = new GeometryGroup();
                        PathFigure    pathFigure      = new PathFigure();
                        ArcSegment    current_arc     = new ArcSegment();
                        pathFigure.StartPoint  = current_position;
                        current_arc.Point      = new_position;
                        current_arc.IsLargeArc = false;
                        double rad;
                        if (Orientation(current_position, current_position, new_position) == 1 && clockwise ||
                            Orientation(current_position, current_position, new_position) == 2 && !clockwise)
                        {
                            rad = Math.Sqrt(Math.Pow(new_position.X - current_position.X, 2) + Math.Pow(new_position.Y - new_position.Y, 2));
                        }
                        else
                        {
                            rad = Math.Sqrt(Math.Pow(new_position.X - new_position.X, 2) + Math.Pow(new_position.Y - current_position.Y, 2));
                        }

                        current_arc.Size = new Size(rad, rad);
                        if (clockwise)
                        {
                            current_arc.SweepDirection = SweepDirection.Clockwise;
                        }
                        else
                        {
                            current_arc.SweepDirection = SweepDirection.Counterclockwise;
                        }

                        PathSegmentCollection PathSegment = new PathSegmentCollection();
                        PathSegment.Add(current_arc);
                        pathFigure.Segments = PathSegment;

                        PathGeometry pathGeometry = new PathGeometry(new List <PathFigure> {
                            pathFigure
                        });
                        myGeometryGroup.Children.Add(pathGeometry);

                        path.Data = myGeometryGroup;
                        c.Children.Add(path);
                        current_position = new_position;
                        break;
                    }
                    DrawPoint(c, current_position);
                }
            }
        }
Exemple #29
0
        //creates the line between two airports
        private void createRouteLine(Airport a1, Airport a2, Panel panelMap, int zoom, Point margin, Airline airline, Boolean isStopoverRoute = false)
        {
            DoubleCollection dottedDash = new DoubleCollection();

            dottedDash.Add(2);
            dottedDash.Add(2);

            int d = 50;

            double distance = MathHelpers.GetDistance(a1, a2);

            GeoCoordinate c1 = a1.Profile.Coordinates;

            int i = 0;

            System.Windows.Shapes.Path flightPath = new System.Windows.Shapes.Path();
            flightPath.Stroke          = new AirlineBrushConverter().Convert(airline) as SolidColorBrush;
            flightPath.StrokeThickness = 1;
            flightPath.Fill            = new AirlineBrushConverter().Convert(airline) as SolidColorBrush;

            GeometryGroup flightGeometryGroup = new GeometryGroup();


            while (i < distance)
            {
                GeoCoordinate c3 = MathHelpers.GetRoutePoint(c1, a2.Profile.Coordinates, d);

                Point pos1 = GraphicsHelpers.WorldToTilePos(c1, zoom);
                Point pos2 = GraphicsHelpers.WorldToTilePos(c3, zoom);

                /*
                 * Line line = new Line();
                 *
                 * if (isStopoverRoute)
                 *  line.StrokeDashArray = dottedDash;
                 * /*
                 * line.Stroke = new AirlineBrushConverter().Convert(airline) as SolidColorBrush;
                 * line.X1 = Math.Min(panelMap.Width, pos1.X * ImageSize - margin.X * ImageSize);
                 * line.X2 = Math.Min(panelMap.Width, pos2.X * ImageSize - margin.X * ImageSize);
                 * line.Y1 = pos1.Y * ImageSize - margin.Y * ImageSize;
                 * line.Y2 = pos2.Y * ImageSize - margin.Y * ImageSize;
                 *
                 * if (Math.Abs(line.X1 - line.X2) > ImageSize)
                 *  line.X2 = (line.X1 - line.X2) < 0 ? 0 : ImageSize * Math.Pow(2,zoom);
                 */
                double x1 = Math.Min(panelMap.Width, pos1.X * ImageSize - margin.X * ImageSize);
                double x2 = Math.Min(panelMap.Width, pos2.X * ImageSize - margin.X * ImageSize);
                double y1 = pos1.Y * ImageSize - margin.Y * ImageSize;
                double y2 = pos2.Y * ImageSize - margin.Y * ImageSize;

                if (Math.Abs(x1 - x2) > ImageSize)
                {
                    x2 = (x1 - x2) < 0 ? 0 : ImageSize *Math.Pow(2, zoom);
                }


                LineGeometry flightGeometry = new LineGeometry();
                flightGeometry.StartPoint = new Point(x1, y1);
                flightGeometry.EndPoint   = new Point(x2, y2);

                flightGeometryGroup.Children.Add(flightGeometry);

                //panelMap.Children.Add(line);

                i += Math.Min(d, (int)(distance - i) + 1);

                c1 = c3;
            }
            flightPath.Data = flightGeometryGroup;
            panelMap.Children.Add(flightPath);
        }
        public static Shape DrawLinkArrow(Point p1, Point p2, bool canLearn) //helper to put an arrow in a synapse line
        {
            GeometryGroup lineGroup = new GeometryGroup();
            double        theta     = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X)) * 180 / Math.PI;

            PathGeometry pathGeometry = new PathGeometry();
            PathFigure   pathFigure   = new PathFigure();
            Vector       v            = p2 - p1;
            double       lengthFactor = ((dp.NeuronDisplaySize * 0.7f / 2f) + 3) / v.Length;

            //lengthfactor = 0.5; //how it used to be
            v = v * lengthFactor;

            Point p = new Point();

            p = p2 - v;
            pathFigure.StartPoint = p;
            double arrowWidth  = dp.NeuronDisplaySize / 20;
            double arrowLength = dp.NeuronDisplaySize / 15;

            if (canLearn)
            {
                arrowWidth *= 2;
            }
            Point       lpoint = new Point(p.X + arrowWidth, p.Y + arrowLength);
            Point       rpoint = new Point(p.X - arrowWidth, p.Y + arrowLength);
            LineSegment seg1   = new LineSegment();

            seg1.Point = lpoint;
            pathFigure.Segments.Add(seg1);

            LineSegment seg2 = new LineSegment();

            seg2.Point = rpoint;
            pathFigure.Segments.Add(seg2);

            LineSegment seg3 = new LineSegment();

            seg3.Point = p;
            pathFigure.Segments.Add(seg3);

            pathGeometry.Figures.Add(pathFigure);
            RotateTransform transform = new RotateTransform();

            transform.Angle        = theta + 90;
            transform.CenterX      = p.X;
            transform.CenterY      = p.Y;
            pathGeometry.Transform = transform;
            lineGroup.Children.Add(pathGeometry);

            LineGeometry connectorGeometry = new LineGeometry();

            connectorGeometry.StartPoint = p1;
            connectorGeometry.EndPoint   = p2;
            lineGroup.Children.Add(connectorGeometry);

            System.Windows.Shapes.Path path = new System.Windows.Shapes.Path();
            path.Data            = lineGroup;
            path.StrokeThickness = 2;
            return(path);
        }
Exemple #31
0
        private void DrawXLines()
        {
            RemoveGuidlines(GuideLines.X);

            var width  = ActualWidth; // just in case it changes?
            var height = ActualHeight;

            var loops = (int)width / XGuideLineResolution; // amount of x info

            /*
             * if ((width / this.data.Count) > this.xResolution) // if there are less data points than the resolution, show the absolute data points
             * {
             *  loops = this.data.Count;
             * }
             */

            for (var i = 1; i < loops; i++)
            {
                var x = width / (loops - 1) * i;

                // text
                var length   = _seriesMaxX - _seriesMinX;
                var interval = length / (loops - 1);
                //

                var tb = new TextBlock
                {
                    Text       = Math.Round(_seriesMinX + (i * interval), 1).ToString(),
                    Foreground = GuideTextColor,
                    FontSize   = GuideTextSize
                };

                tb.Margin = new Thickness(x - (tb.Text.Length / 2 * 6), height - 20, 0, 20);

                var p   = new Path();
                var geo = new LineGeometry {
                    StartPoint = new Point(x, 20), EndPoint = new Point(x, ActualHeight - 20)
                };
                p.Stroke          = GuideLineColor;
                p.StrokeDashArray = new DoubleCollection {
                    5, 20
                };
                p.StrokeThickness = GuideLineThickness;
                p.Data            = geo;

                if (ShowText)
                {
                    _xDataMarkers.Add(tb);
                }
                _xGuideLines = p;

                if (ShowText)
                {
                    SetZIndex(tb, 15);
                }
                SetZIndex(p, 14);

                if (ShowText)
                {
                    Children.Add(tb);
                }
                Children.Add(p);
            }
        }