예제 #1
0
        private void PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.Source == _sourceElement)
            {
                return;
            }
            if (e.Source is VertexVisual)
            {
                VertexVisual vv = (VertexVisual)e.Source;
                _isDown = true;
                SetSourceElement(vv);

                _startPoint       = e.GetPosition(GraphPanel);//new Point(e.GetPosition(pnlMap).X / Zoom, e.GetPosition(pnlMap).Y / Zoom);
                _positionOnSource = new Point(_startPoint.X - vv.Node.Location.X * Zoom, _startPoint.Y - vv.Node.Location.Y * Zoom);
                GraphPanel.CaptureMouse();
                e.Handled = true;
            }
            else if (e.Source is EdgeVisual)
            {
                EdgeVisual ev = (EdgeVisual)e.Source;
                _isDown = true;
                SetSourceElement(ev);
                e.Handled = true;
            }
            else if (e.Source is Ellipse)
            {
                _isDown = true;
                SetSourceElement(e.Source);
                e.Handled = true;
            }
        }
예제 #2
0
        private void DragMoved()
        {
            Point CurrentPosition = Mouse.GetPosition(GraphPanel);

            if (_sourceElement is VertexVisual)
            {
                VertexVisual vv       = (VertexVisual)_sourceElement;
                WayPoint     prePoint = (WayPoint)vv.Node.Clone();
                vv.Location = new Point((CurrentPosition.X - _positionOnSource.X) / Zoom, (CurrentPosition.Y - _positionOnSource.Y) / Zoom);

                for (int i = 0; i < _edges.Count; i++)
                {
                    if (_edges[i].NodeFrom == vv.Node)
                    {
                        _edges[i].PathData.StartPoint = vv.Node.Location;
                    }
                    if (_edges[i].NodeTo == vv.Node)
                    {
                        if (_edges[i].PathData.Segments[0] is LineSegment)
                        {
                            (_edges[i].PathData.Segments[0] as LineSegment).Point = vv.Node.Location;
                        }
                        else if (_edges[i].PathData.Segments[0] is BezierSegment)
                        {
                            (_edges[i].PathData.Segments[0] as BezierSegment).Point3 = vv.Node.Location;
                        }
                    }
                    _edges[i].InvalidateVisual();
                }
            }
            else if (_sourceElement is Ellipse)
            {
                Ellipse el          = (Ellipse)_sourceElement;
                bool    is_first    = (bool)el.Tag;
                Point   newLocation = new Point((CurrentPosition.X - _positionOnSource.X) / Zoom, (CurrentPosition.Y - _positionOnSource.Y) / Zoom);
                el.SetValue(Canvas.TopProperty, newLocation.Y * Zoom);
                el.SetValue(Canvas.LeftProperty, newLocation.X * Zoom);
                for (int i = 0; i < _edges.Count; i++)
                {
                    if (_edges[i].IsSelected)
                    {
                        if (is_first)
                        {
                            (_edges[i].PathData.Segments[0] as BezierSegment).Point1 = newLocation;
                        }
                        else
                        {
                            (_edges[i].PathData.Segments[0] as BezierSegment).Point2 = newLocation;
                        }
                        _edges[i].InvalidateVisual();
                        return;
                    }
                }
            }
        }
예제 #3
0
        private void MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Point    position = e.GetPosition(GraphPanel);
            WayPoint wp       = new WayPoint()
            {
                Location = new Point(position.X / Zoom, position.Y / Zoom),
                Name     = (_vertexes.Count + 1).ToString()
            };
            VertexVisual vv = new VertexVisual(wp)
            {
                Zoom = Zoom
            };

            _vertexes.Add(vv);
            OnPropertyChanged("Vertexes");
            GraphPanel.Children.Add(vv);
        }
 private void MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     Point position = e.GetPosition(GraphPanel);
     WayPoint wp = new WayPoint()
     {
         Location = new Point(position.X / Zoom, position.Y / Zoom),
         Name = (_vertexes.Count + 1).ToString()
     };
     VertexVisual vv = new VertexVisual(wp)
     {
         Zoom = Zoom
     };
     _vertexes.Add(vv);
     OnPropertyChanged("Vertexes");
     GraphPanel.Children.Add(vv);
 }
        public RoadGraphConfigViewModel(ScenarioModel scenario)
        {
            if (scenario == null)
            {
                throw new ArgumentNullException("scenario is null");
            }

            GraphPanel = new Canvas();
            GraphPanel.MouseLeftButtonUp += (s, e) => MouseLeftButtonUp(s, e);
            GraphPanel.PreviewMouseLeftButtonDown += (s, e) => PreviewMouseLeftButtonDown(s, e);
            GraphPanel.PreviewMouseLeftButtonUp += (s, e) => PreviewMouseLeftButtonUp(s, e);
            GraphPanel.PreviewMouseMove += (s, e) => PreviewMouseMove(s, e);

            Services = scenario.Services;

            _vertexes = new List<VertexVisual>();
            _edges = new List<EdgeVisual>();

            RoadGraph = new Graph<WayPoint, PathFigure>();
            if (scenario.RoadGraph != null)
            {
                foreach (var edge in scenario.RoadGraph.Edges)
                {
                    var pathGeom = PathGeometry.CreateFromGeometry(PathGeometry.Parse(edge.Data));

                    EdgeVisual ev = new EdgeVisual(pathGeom.Figures.First())
                    {
                        NodeFrom = edge.Start,
                        NodeTo = edge.End,
                        Zoom = Zoom
                    };
                    _edges.Add(ev);
                    GraphPanel.Children.Add(ev);
                }

                foreach (var node in scenario.RoadGraph.Nodes)
                {
                    //int in_count = 0, out_count = 0;
                    //foreach (var edge in RoadGraph.GetEdgesTo(node))
                    //{
                    //    in_count++;
                    //}
                    //foreach (var edge in RoadGraph.GetEdgesFrom(node))
                    //{
                    //    out_count++;
                    //}

                    VertexVisual vv = new VertexVisual(node)
                    {
                        //InCount = in_count,
                        //OutCount = out_count,
                        Zoom = Zoom
                    };
                    _vertexes.Add(vv);
                    GraphPanel.Children.Add(vv);
                }
            }

            GraphPanel.Width = scenario.Map[0].Width;
            GraphPanel.Height = scenario.Map[0].Height;
            if (scenario.Map[0].Substrate!= null)
            {
                GraphPanel.Background = new ImageBrush(Helpers.Imaging.ImageManager.BitmapToBitmapImage(scenario.Map[0].Substrate));
            }
        }
예제 #6
0
        public RoadGraphConfigViewModel(ScenarioModel scenario)
        {
            if (scenario == null)
            {
                throw new ArgumentNullException("scenario is null");
            }

            GraphPanel = new Canvas();
            GraphPanel.MouseLeftButtonUp          += (s, e) => MouseLeftButtonUp(s, e);
            GraphPanel.PreviewMouseLeftButtonDown += (s, e) => PreviewMouseLeftButtonDown(s, e);
            GraphPanel.PreviewMouseLeftButtonUp   += (s, e) => PreviewMouseLeftButtonUp(s, e);
            GraphPanel.PreviewMouseMove           += (s, e) => PreviewMouseMove(s, e);

            Services = scenario.Services;

            _vertexes = new List <VertexVisual>();
            _edges    = new List <EdgeVisual>();

            RoadGraph = new Graph <WayPoint, PathFigure>();
            if (scenario.RoadGraph != null)
            {
                foreach (var edge in scenario.RoadGraph.Edges)
                {
                    var pathGeom = PathGeometry.CreateFromGeometry(PathGeometry.Parse(edge.Data));

                    EdgeVisual ev = new EdgeVisual(pathGeom.Figures.First())
                    {
                        NodeFrom = edge.Start,
                        NodeTo   = edge.End,
                        Zoom     = Zoom
                    };
                    _edges.Add(ev);
                    GraphPanel.Children.Add(ev);
                }

                foreach (var node in scenario.RoadGraph.Nodes)
                {
                    //int in_count = 0, out_count = 0;
                    //foreach (var edge in RoadGraph.GetEdgesTo(node))
                    //{
                    //    in_count++;
                    //}
                    //foreach (var edge in RoadGraph.GetEdgesFrom(node))
                    //{
                    //    out_count++;
                    //}

                    VertexVisual vv = new VertexVisual(node)
                    {
                        //InCount = in_count,
                        //OutCount = out_count,
                        Zoom = Zoom
                    };
                    _vertexes.Add(vv);
                    GraphPanel.Children.Add(vv);
                }
            }

            GraphPanel.Width  = scenario.Map[0].Width;
            GraphPanel.Height = scenario.Map[0].Height;
            if (scenario.Map[0].Substrate != null)
            {
                GraphPanel.Background = new ImageBrush(Helpers.Imaging.ImageManager.BitmapToBitmapImage(scenario.Map[0].Substrate));
            }
        }