예제 #1
0
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            var ele = sender as FrameworkElement;

            if (ele == null || ele.Tag == null)
            {
                return;
            }
            if (ele.Tag.Equals("del"))
            {
                if (SelectedNodeBorder != null && SelectedNodeBorder.IsSelected == true)
                {
                    RemoveNode(SelectedNodeBorder);
                    SelectedNodeBorder = null;
                }
                else if (SelectedRunLine != null && SelectedRunLine.IsSelected == true)
                {
                    RemoveLine(SelectedRunLine);
                    SelectedRunLine = null;
                }
            }
            else if (ele.Tag.Equals("test"))
            {
                for (int i = 0; i < 10; i++)
                {
                    StartTest();
                }
            }
        }
예제 #2
0
        private UCLine MakeLine(RunLineModel mode)
        {
            var line = new UCLine();

            line.Height             = 15;
            line.Cursor             = Cursors.Hand;
            line.Background         = Brushes.Gray;
            line.MouseLeftButtonUp += Line_MouseLeftButtonUp;
            return(line);
        }
예제 #3
0
        /// <summary>
        /// 自动优化线的连接位置
        /// </summary>
        /// <param name="line"></param>
        private void AutoOptimizeLine(UCLine line)
        {
            var startNode = nodeDic.FirstOrDefault(a => a.Value.Name.Equals(GetRunLine(line).StartNode.Name)).Key;
            var endNode   = nodeDic.FirstOrDefault(a => GetRunLine(line).EndNode != null && a.Value.Name.Equals(GetRunLine(line).EndNode.Name)).Key;

            if (startNode == null || endNode == null)
            {
                return;
            }
            line.StartPoint = GetConnectPoint(startNode, endNode.CircleCenterPoint);
            line.EndPoint   = GetConnectPoint(endNode, startNode.CircleCenterPoint);
        }
예제 #4
0
 private bool RemoveLine(UCLine line)
 {
     if (line != null)
     {
         if (MessageBox.Show("确认删除该行驶路线?", "确认", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
         {
             return(false);
         }
         canvasPanel.Children.Remove(line);
         runLineDic.Remove(line);
     }
     return(true);
 }
예제 #5
0
        /// <summary>
        /// 添加节点与节点间的连线
        /// </summary>
        /// <param name="sourceNode"></param>
        /// <param name="objNode"></param>
        private void AddLine(UCNode sourceNode, UCNode objNode)
        {
            var lineMode = new RunLineModel();

            var line = new UCLine();
            var x    = sourceNode.X * canvasPanel.ActualWidth - sourceNode.Width / 2;
            var y    = sourceNode.Y * canvasPanel.ActualHeight - sourceNode.Height / 2;

            line.StartPoint = new Point(x, y);
            if (objNode != null)
            {
                x             = objNode.X * canvasPanel.ActualWidth - objNode.Width / 2;
                y             = objNode.Y * canvasPanel.ActualHeight - objNode.Height / 2;
                line.EndPoint = new Point(x, y);
            }
            canvasPanel.Children.Add(line);
            runLineDic.Add(line, lineMode);
        }
예제 #6
0
        private void Line_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            var line = sender as UCLine;

            if (line == null)
            {
                return;
            }

            if (SelectedRunLine != null && SelectedRunLine.IsSelected == false)
            {
                //防止更改线的节点后,选择了节点而SelectedRunLine没有重置的问题
                SelectedRunLine = null;
                SelectedRunLine = line;
                _operateStatus  = OperateStatus.SelectedLine;
            }

            else if (line != SelectedRunLine &&
                     _operateStatus != OperateStatus.MoveSourceNode &&
                     _operateStatus != OperateStatus.MoveObjNode
                     )
            {
                //变更选择的行驶路线
                line.IsSelected = true;
                if (SelectedRunLine != null)
                {
                    SelectedRunLine.IsSelected = false;
                }
                SelectedRunLine = line;
                _operateStatus  = OperateStatus.SelectedLine;
            }
            else if (_operateStatus == OperateStatus.SelectedLine)
            {
                var point = e.GetPosition(canvasPanel);

                //若首尾x坐标相差很大(>30)则使用x区分首尾,否则使用y区分
                if (Math.Abs(SelectedRunLine.EndPoint.X - SelectedRunLine.StartPoint.X) > 30)
                {
                    if (Math.Abs(point.X - SelectedRunLine.StartPoint.X) < Math.Abs(point.X - SelectedRunLine.EndPoint.X))
                    {
                        _operateStatus = OperateStatus.MoveSourceNode;
                    }
                    else
                    {
                        _operateStatus = OperateStatus.MoveObjNode;
                    }
                }
                else
                {
                    if (Math.Abs(point.Y - SelectedRunLine.StartPoint.Y) < Math.Abs(point.Y - SelectedRunLine.EndPoint.Y))
                    {
                        _operateStatus = OperateStatus.MoveSourceNode;
                    }
                    else
                    {
                        _operateStatus = OperateStatus.MoveObjNode;
                    }
                }

                if (SelectedNodeBorder != null)
                {
                    SelectedNodeBorder.IsSelected = false;
                    SelectedNodeBorder            = null;
                }
            }
        }
예제 #7
0
 private RunLineModel GetRunLine(UCLine line)
 {
     return(runLineDic[line]);
 }
예제 #8
0
        public TestCircle()
        {
            InitializeComponent();



            var centerPoint = new Point(20, 20);
            var e           = new Ellipse();

            e.Width  = 100;
            e.Height = 100;
            e.SetValue(Canvas.LeftProperty, centerPoint.X - e.Width / 2);
            e.SetValue(Canvas.TopProperty, centerPoint.Y - e.Height / 2);
            e.Stroke          = Brushes.Black;
            e.StrokeThickness = 1;
            canvas.Children.Add(e);

            var point = new Point(150, 150);

            //double angle = Math.Atan2((point.Y - 50), (point.X - 50));// * 180 / Math.PI;
            //Debug.WriteLine(angle);
            //var x = 50 + 50 * Math.Cos(angle);
            //var y = 50 + 50 * Math.Sin(angle);


            //var line = new Line();
            //line.X1 = 50;
            //line.Y1 = 50;
            //line.X2 = x;
            //line.Y2 = y;
            //line.Stroke = Brushes.Red;
            //canvas.Children.Add(line);

            var line = new Line();

            line.X1     = centerPoint.X;
            line.Y1     = centerPoint.Y;
            line.X2     = point.X;
            line.Y2     = point.Y;
            line.Stroke = Brushes.Blue;
            canvas.Children.Add(line);


            var angle  = -137.23117460803127;
            var border = new Border();

            border.SetValue(Canvas.LeftProperty, centerPoint.X);
            border.SetValue(Canvas.TopProperty, centerPoint.Y - 5);
            border.Height     = 10;
            border.Width      = 100;
            border.Background = Brushes.Blue;
            border.Opacity    = 0.2;
            var f = new RotateTransform(angle);

            f.CenterX = 0; //centerPoint.X;
            f.CenterY = 5; //centerPoint.Y;
            border.RenderTransform = f;
            canvas.Children.Add(border);

            //border.SetValue(Canvas.LeftProperty, centerPoint.X - 2.5);
            //border.SetValue(Canvas.TopProperty, centerPoint.Y + 5);



            var runLine = new UCLine();

            runLine.Height     = 15;
            runLine.StartPoint = new Point(centerPoint.X, centerPoint.Y - runLine.Height / 2);
            runLine.EndPoint   = point;
            runLine.Cursor     = Cursors.Hand;
            canvas.Children.Add(runLine);
        }