Esempio n. 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;
            }
        }
Esempio n. 2
0
        private void AddEdge()
        {
            WayPoint   from = _selectedVertexFrom, to = _selectedVertexTo;
            EdgeVisual ev = new EdgeVisual(new PathFigure(from.Location, new List <PathSegment>()
            {
                new LineSegment(to.Location, true)
            }, false))
            {
                NodeFrom = from,
                NodeTo   = to,
                Zoom     = Zoom
            };

            _edges.Add(ev);
            GraphPanel.Children.Insert(0, ev);
            //_selectedVertexFrom.OutCount++;
            //_selectedVertexTo.InCount++;
        }
 private void AddEdge()
 {
     WayPoint from = _selectedVertexFrom, to = _selectedVertexTo;
     EdgeVisual ev = new EdgeVisual(new PathFigure(from.Location, new List<PathSegment>() { new LineSegment(to.Location, true) }, false))
     {
         NodeFrom = from,
         NodeTo = to,
         Zoom = Zoom
     };
     _edges.Add(ev);
     GraphPanel.Children.Insert(0, ev);
     //_selectedVertexFrom.OutCount++;
     //_selectedVertexTo.InCount++;
 }
        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));
            }
        }
Esempio n. 5
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));
            }
        }
Esempio n. 6
0
        private void SetSourceElement(object value)
        {
            //Снимаем выделение предыдущего элемента
            if (_sourceElement != null && !(value is Ellipse))
            {
                if (_sourceElement is VertexVisual)
                {
                    ((VertexVisual)_sourceElement).IsSelected = false;
                }
                if (_sourceElement is EdgeVisual)
                {
                    ((EdgeVisual)_sourceElement).IsSelected = false;
                    foreach (var el in elList)
                    {
                        el.Visibility = Visibility.Hidden;
                    }
                }
            }
            _sourceElement = value;

            if (_sourceElement is EdgeVisual)
            {
                EdgeVisual ev = _sourceElement as EdgeVisual;
                ev.IsSelected = true;
                if (elList.Count == 0)
                {
                    if (ev.PathData.Segments[0] is BezierSegment)
                    {
                        AddEllipseOnParentPanel((ev.PathData.Segments[0] as BezierSegment).Point1, true);
                        AddEllipseOnParentPanel((ev.PathData.Segments[0] as BezierSegment).Point2, false);
                    }
                    else if (ev.PathData.Segments[0] is LineSegment)
                    {
                        Point endPoint     = (ev.PathData.Segments[0] as LineSegment).Point;
                        Point controlPoint = new Point((ev.PathData.StartPoint.X + endPoint.X) / 2, (ev.PathData.StartPoint.Y + endPoint.Y) / 2);
                        ev.PathData.Segments.Clear();
                        ev.PathData.Segments.Add(new BezierSegment(controlPoint, controlPoint, endPoint, true));
                        AddEllipseOnParentPanel((ev.PathData.Segments[0] as BezierSegment).Point1, true);
                        AddEllipseOnParentPanel((ev.PathData.Segments[0] as BezierSegment).Point2, false);
                    }
                }
                else
                {
                    foreach (var el in elList)
                    {
                        el.Visibility = Visibility.Visible;
                    }
                    if (ev.PathData.Segments[0] is BezierSegment)
                    {
                        elList[0].SetValue(Canvas.TopProperty, (ev.PathData.Segments[0] as BezierSegment).Point1.Y * Zoom);
                        elList[0].SetValue(Canvas.LeftProperty, (ev.PathData.Segments[0] as BezierSegment).Point1.X * Zoom);
                        elList[1].SetValue(Canvas.TopProperty, (ev.PathData.Segments[0] as BezierSegment).Point2.Y * Zoom);
                        elList[1].SetValue(Canvas.LeftProperty, (ev.PathData.Segments[0] as BezierSegment).Point2.X * Zoom);
                    }
                    else if (ev.PathData.Segments[0] is LineSegment)
                    {
                        Point endPoint     = (ev.PathData.Segments[0] as LineSegment).Point;
                        Point controlPoint = new Point((ev.PathData.StartPoint.X + endPoint.X) / 2, (ev.PathData.StartPoint.Y + endPoint.Y) / 2);
                        ev.PathData.Segments.Clear();
                        ev.PathData.Segments.Add(new BezierSegment(controlPoint, controlPoint, endPoint, true));
                        elList[0].SetValue(Canvas.TopProperty, (ev.PathData.Segments[0] as BezierSegment).Point1.Y * Zoom);
                        elList[0].SetValue(Canvas.LeftProperty, (ev.PathData.Segments[0] as BezierSegment).Point1.X * Zoom);
                        elList[1].SetValue(Canvas.TopProperty, (ev.PathData.Segments[0] as BezierSegment).Point2.Y * Zoom);
                        elList[1].SetValue(Canvas.LeftProperty, (ev.PathData.Segments[0] as BezierSegment).Point2.X * Zoom);
                    }
                }
            }
            else if (_sourceElement is VertexVisual)
            {
                var vertex = (VertexVisual)_sourceElement;
                vertex.IsSelected = true;
                IsServicePoint    = vertex.Node.IsServicePoint;
                if (IsServicePoint && vertex.Node.ServiceId.HasValue)
                {
                    SelectedService = Services.FirstOrDefault(s => s.Id == vertex.Node.ServiceId);
                }
            }
            else if (!(_sourceElement is Ellipse))
            {
                _sourceElement = null;
            }
            OnPropertyChanged("CanEditService");
        }