示例#1
0
        private void DrawMinorVerticalTicks()
        {
            Size size = RenderSize;

            if (MinorVerticalTicks != null && drawVerticalMinorTicks)
            {
                double minX = 0;
                double maxX = size.Width;

                for (int i = 0; i < MinorVerticalTicks.Length; i++)
                {
                    double screenY = MinorVerticalTicks[i].Tick;
                    if (screenY < 0)
                    {
                        continue;
                    }
                    if (screenY > size.Height)
                    {
                        continue;
                    }

                    Line line = linePool.GetOrCreate();

                    line.Y1              = screenY;
                    line.Y2              = screenY;
                    line.X1              = minX;
                    line.X2              = maxX;
                    line.Stroke          = Brushes.LightGray;
                    line.StrokeThickness = MinorVerticalTicks[i].Value * gridBrushThickness;

                    canvas.Children.Add(line);
                }
            }
        }
        private void UpdateUI()
        {
            foreach (var point in points)
            {
                point.PositionChanged -= OnPoint_PositionChanged;
                pointsPool.Put(point);
                plotter.Children.Remove(point);
            }

            points.Clear();

            int i = 0;

            foreach (var point3D in Pattern.GeneratePoints())
            {
                DraggablePoint draggablePoint = pointsPool.GetOrCreate();
                var            position       = project(point3D);

                outPattern.Points.Add(point3D);

                draggablePoint.Position         = position;
                draggablePoint.PositionChanged += OnPoint_PositionChanged;
                SetIndex(draggablePoint, i);
                plotter.Children.Add(draggablePoint);
                points.Add(draggablePoint);
                i++;
            }
        }
示例#3
0
        private void DrawImage(BitmapSource bmp, DataRect bounds, TileIndex id)
        {
            MapElement element = null;
            bool       onPanel = false;

            if (freeChildren.Count > 0)
            {
                element = (MapElement)freeChildren[freeChildren.Count - 1];
                freeChildren.RemoveAt(freeChildren.Count - 1);
                onPanel = true;
            }
            else
            {
                element = pool.GetOrCreate();
            }

            element.Bitmap = bmp;
            ViewportPanel.SetViewportBounds(element, bounds);
            System.Windows.Controls.Panel.SetZIndex(element, (int)id.Level);

            if (!onPanel)
            {
                panel.Children.Add(element);
                panel.InvalidateMeasure();
            }
        }
示例#4
0
        private void DoDrawTicks(double[] screenTicksX, ICollection <Geometry> lines)
        {
            for (int i = 0; i < screenTicksX.Length; i++)
            {
                if (labels[i] == null && !drawTicksOnEmptyLabel)
                {
                    continue;
                }

                Point p1 = createScreenPoint1(screenTicksX[i]);
                Point p2 = createScreenPoint2(screenTicksX[i], 1);

                LineGeometry line = lineGeomPool.GetOrCreate();

                line.StartPoint = p1;
                line.EndPoint   = p2;
                lines.Add(line);
            }
        }
        private WirePolyline CreatePolyline(IEnumerable <Point3D> points, Point3D start)
        {
            WirePolyline line = linesPool.GetOrCreate();

            double ratio = ((start.X - bounds.X) / bounds.SizeX + (start.Y - bounds.Y) / bounds.SizeY) / 2;

            line.Thickness = lineThickness;
            line.Color     = palette.GetColor(ratio);

            line.Points = new Point3DCollection(points);

            return(line);
        }
        private void Update()
        {
            if (Plotter == null)
            {
                return;
            }
            if (DataSource == null)
            {
                return;
            }

            layoutTransform.X = 0;
            layoutTransform.Y = 0;

            var dataSource = DataSource;
            var dataPoints = dataSource.GetPoints();

            transformWhenCreated = plotter.Transform;

            var contentBounds = dataPoints.GetBounds();

            Viewport2D.SetContentBounds(this, contentBounds);

            foreach (Polyline polyline in Children)
            {
                polylinePool.Put(polyline);
            }
            Children.Clear();

            PointCollection pointCollection = new PointCollection();

            foreach (var screenPoint in dataPoints.DataToScreen(plotter.Transform))
            {
                if (pointCollection.Count < pointCount)
                {
                    pointCollection.Add(screenPoint);
                }
                else
                {
                    var polyline = polylinePool.GetOrCreate();
                    polyline.Points = pointCollection;

                    SetPolylineBindings(polyline);

                    Children.Add(polyline);
                    Dispatcher.Invoke(() => { }, DispatcherPriority.ApplicationIdle);
                    pointCollection = new PointCollection();
                }
            }
        }
        private Triangle CreateTriangle(Point position, Vector direction)
        {
            direction.Normalize();
            direction *= vectorLength;

            Point p1            = position + 1.7 / 3 * direction;
            Point basePoint     = position - 0.3333333 * direction;
            var   perpendicular = direction.Perpendicular();

            perpendicular.Normalize();
            perpendicular *= 0.166666666666;
            Point p2 = basePoint + perpendicular;
            Point p3 = basePoint - perpendicular;

            Triangle triangle = trianglesPool.GetOrCreate();

            triangle.Point1 = new Point3D(p1.X, p1.Y, 0);
            triangle.Point2 = new Point3D(p2.X, p2.Y, 0);
            triangle.Point3 = new Point3D(p3.X, p3.Y, 0);
            return(triangle);
        }
示例#8
0
        private void UpdateUIRepresentation()
        {
            foreach (UIElement item in canvas.Children)
            {
                Line line = item as Line;
                if (line != null)
                {
                    linePool.Put(line);
                }
            }

            canvas.Children.Clear();
            Size size = RenderSize;

            DrawMinorHorizontalTicks();
            DrawMinorVerticalTicks();

            GeometryGroup prevGroup = path.Data as GeometryGroup;

            if (prevGroup != null)
            {
                foreach (LineGeometry geometry in prevGroup.Children)
                {
                    lineGeometryPool.Put(geometry);
                }
            }

            GeometryGroup group = new GeometryGroup();

            if (HorizontalTicks != null && drawHorizontalTicks)
            {
                double minY = 0;
                double maxY = size.Height;

                for (int i = 0; i < HorizontalTicks.Length; i++)
                {
                    double       screenX = HorizontalTicks[i];
                    LineGeometry line    = lineGeometryPool.GetOrCreate();
                    line.StartPoint = new Point(screenX, minY);
                    line.EndPoint   = new Point(screenX, maxY);
                    group.Children.Add(line);
                }
            }

            if (VerticalTicks != null && drawVerticalTicks)
            {
                double minX = 0;
                double maxX = size.Width;

                for (int i = 0; i < VerticalTicks.Length; i++)
                {
                    double       screenY = VerticalTicks[i];
                    LineGeometry line    = lineGeometryPool.GetOrCreate();
                    line.StartPoint = new Point(minX, screenY);
                    line.EndPoint   = new Point(maxX, screenY);
                    group.Children.Add(line);
                }
            }

            canvas.Children.Add(path);
            path.Data = group;
        }
示例#9
0
        private void CreateAndAddPath(IEnumerable <IndexWrapper <Point> > indexedPoints,
                                      out int globalMinIndex, out int globalMaxIndex, CoordinateTransform transform)
        {
            var screenPoints = indexedPoints.DataToScreen(transform);

            var parts = screenPoints.Split(pathLength);

            var splittedParts = from part in parts
                                select missingValueSplitter.SplitMissingValue(part);

            bool isSmoothJoin = UseSmoothJoin;

            Point?lastPoint = null;

            globalMinIndex = Int32.MaxValue;
            globalMaxIndex = Int32.MinValue;

            foreach (var shortSegment in splittedParts)
            {
                foreach (var part in shortSegment)
                {
                    if (part.MinIndex < globalMinIndex)
                    {
                        globalMinIndex = part.MinIndex;
                    }
                    if (part.MaxIndex > globalMaxIndex)
                    {
                        globalMaxIndex = part.MaxIndex;
                    }

                    List <Point> list = part.GetPoints().ToList();
                    if (list.Count == 0)
                    {
                        continue;
                    }

                    if (part.Splitted)
                    {
                        lastPoint = null;
                    }

                    StreamGeometry geometry = new StreamGeometry();
                    using (var context = geometry.Open())
                    {
                        var start = lastPoint ?? list[0];

                        context.BeginFigure(start, isFilled: false, isClosed: false);
                        context.PolyLineTo(list, isStroked: true, isSmoothJoin: isSmoothJoin);
                    }

                    lastPoint = list.Last();

                    Path path = pathsPool.GetOrCreate();
                    drawnPaths.Add(path);

                    PointChartBase.SetIndexRange(path, new Range <int>(part.MinIndex, part.MaxIndex));
                    LineChartBase.SetPointsCount(path, list.Count);

                    DataRect localBounds = list.GetBounds();
                    PointChartBase.SetContentBounds(path, localBounds);

                    //if (path.CacheMode == null)
                    //    path.CacheMode = new BitmapCache();

                    // todo for debug purpose
                    //path.Stroke = ColorHelper.RandomBrush;

                    path.SetBinding(Path.StrokeProperty, strokeBinding);
                    path.SetBinding(Path.StrokeThicknessProperty, strokeThicknessBinding);
                    path.SetBinding(Path.StrokeDashArrayProperty, strokeDashArrayBinding);
                    path.SetBinding(Panel.ZIndexProperty, zIndexBinding);
                    path.SetBinding(Path.IsHitTestVisibleProperty, isHitTestVisibleBinding);
                    path.SetBinding(Path.VisibilityProperty, visibilityBinding);
                    path.SetBinding(Path.ToolTipProperty, tooltipBinding);

                    path.Data = geometry;

                    canvas.Children.Add(path);
                }
            }
        }
示例#10
0
        protected virtual void UpdateUIRepresentation()
        {
            foreach (UIElement item in canvas.Children)
            {
                linePool.PutIfType(item);
                rectanglePool.PutIfType(item);
            }
            GeometryGroup prevLinesGroup = linesPath.Data as GeometryGroup;

            if (prevLinesGroup != null)
            {
                foreach (Geometry geometry in prevLinesGroup.Children)
                {
                    lineGeometryPool.PutIfType(geometry);
                }
            }
            GeometryGroup prevRectanglesGroup = linesPath.Data as GeometryGroup;

            if (prevRectanglesGroup != null)
            {
                foreach (Geometry geometry in prevRectanglesGroup.Children)
                {
                    rectangleGeometryPool.PutIfType(geometry);
                }
            }

            canvas.Children.Clear();
            Size size = RenderSize;

            double minY = 0;
            double maxY = size.Height;
            double minX = 0;
            double maxX = size.Width;


            GeometryGroup rectanglesGroup = new GeometryGroup();

            if (HorizontalTicks != null && _drawHorizontalsShaded)
            {
                for (int i = 0; i < HorizontalTicks.Length; i += 2)
                {
                    // Want to check the first 2 points to work out our shading order
                    if (i == 0 && HorizontalTicks.Length > 1)
                    {
                        // rectangle between the first point and the next point will be grey, if first point is
                        // odd then shift back 1 step
                        double dx = Math.Abs(HorizontalTicks[1].Tick - HorizontalTicks[0].Tick);
                        // Test if 2nd point is even and if so then move back 1 tick
                        if (dx > 0 && Math.Abs((int)(HorizontalTicks[1].Tick / dx)) % 2 == 0)
                        {
                            i = -1;
                        }
                    }

                    // TODO try to make rectanlge even on the left to odd on the right
                    // Get the difference, divide each by the difference. Get the int....
                    double            screenXStart = (i >= 0) ? HorizontalTicks[i].Value : minX;
                    double            screenXEnd   = (i + 1) < HorizontalTicks.Length ? HorizontalTicks[i + 1].Value : maxX;
                    RectangleGeometry rectangle    = rectangleGeometryPool.GetOrCreate();
                    rectangle.Rect = PointsToRect(screenXStart, screenXEnd, minY, maxY);
                    rectanglesGroup.Children.Add(rectangle);
                }
            }

            DrawMinorHorizontalTicks();
            DrawMinorVerticalTicks();


            GeometryGroup linesGroup = new GeometryGroup();

            if (HorizontalTicks != null && drawHorizontalTicks)
            {
                for (int i = 0; i < HorizontalTicks.Length; i++)
                {
                    double       screenX = HorizontalTicks[i].Value;
                    LineGeometry line    = lineGeometryPool.GetOrCreate();
                    line.StartPoint = new Point(screenX, minY);
                    line.EndPoint   = new Point(screenX, maxY);
                    linesGroup.Children.Add(line);
                }
            }

            if (VerticalTicks != null && drawVerticalTicks)
            {
                for (int i = 0; i < VerticalTicks.Length; i++)
                {
                    double       screenY = VerticalTicks[i].Value;
                    LineGeometry line    = lineGeometryPool.GetOrCreate();
                    line.StartPoint = new Point(minX, screenY);
                    line.EndPoint   = new Point(maxX, screenY);
                    linesGroup.Children.Add(line);
                }
            }

            canvas.Children.Add(rectanglesPath);
            canvas.Children.Add(linesPath);
            linesPath.Data      = linesGroup;
            rectanglesPath.Data = rectanglesGroup;
        }