예제 #1
0
 public void LineEdgeMouseClick(object sender, MouseButtonEventArgs e)
 {
     //StringActionUndo();
     Petzold.Media2D.ArrowLine line = new Petzold.Media2D.ArrowLine();
     line = (Petzold.Media2D.ArrowLine)sender;
     if (DeleteingEdgeEnabled)
     {
         MainWindow_.InfoCurr.Clear();
         RemoveEdge(line);
         DeleteingEdgeEnabled = false;
         MyCursors.DefaultCursor();
     }
     if (IsOriented)
     {
         foreach (var edge in EdgesList)
         {
             if (edge.line == line)
             {
                 GraphVertex StartV = edge.StartVertex;
                 GraphVertex EndV   = edge.EndVertex;
                 ConnectVertex(EndV, StartV);
                 RemoveEdge(line);
                 break;
             }
         }
     }
 }
예제 #2
0
 //private Line HelpLine = new Line();
 //private void DrawHelpLineMouseMove(object sender, MouseEventArgs e)
 //{
 //    if (AddEdgeEnabled && VertexesInEdge == 1)
 //    {
 //        HelpLine.X2 = e.GetPosition(zoom).X;
 //        HelpLine.Y2 = e.GetPosition(zoom).Y;
 //    }
 //}
 public void DeactivateAll()
 {
     IsHolded                = false;
     AddEdgeEnabled          = false;
     VertexesInEdge          = 0;
     DeletingVertexEnable    = false;
     DeleteingEdgeEnabled    = false;
     AStarVertexesEnumerator = 0;
     DijkstraEnabled         = false;
     AStarEnabled            = false;
     MainWindow_.InfoCurr.Clear();
     MyCursors.DefaultCursor();
 }
예제 #3
0
        public void VertexLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Ellipse ell = new Ellipse();

            ell        = (Ellipse)sender;
            IsHolded   = false;
            ell.Cursor = Cursors.Arrow;
            if (DijkstraEnabled)
            {
                ShortestPathDijkstra(SearchVertexByEllipse(ell));
                MyCursors.DefaultCursor();
            }

            ell.ReleaseMouseCapture();
        }
예제 #4
0
 public MainWindow()
 {
     InitializeComponent();
     InfoCurr.Visibility  = System.Windows.Visibility.Hidden;
     this.KeyDown        += new KeyEventHandler(KeyF12Click);
     WorkSpace.Background = Brushes.Gray;
     PlainIsCreated       = false;
     IsDirected           = false;
     CommandBindings.Add(new CommandBinding(HotKeys.UndoCommand, Undo_Click));
     CommandBindings.Add(new CommandBinding(HotKeys.RedoCommand, Redo_Click));
     CommandBindings.Add(new CommandBinding(HotKeys.NewCommand, NewGraph_Click));
     CommandBindings.Add(new CommandBinding(HotKeys.SaveCommand, SaveButton_Click));
     CommandBindings.Add(new CommandBinding(HotKeys.SaveAsCommand, SaveAs_Click));
     CommandBindings.Add(new CommandBinding(HotKeys.OpenCommand, OpenFile_Click));
     MyCursors.DefaultCursor();
 }
예제 #5
0
 private void Dijkstra_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBoxMessage())
     {
         return;
     }
     if (graph.EdgesList.Count == 0)
     {
         Xceed.Wpf.Toolkit.MessageBox.Show("Нет ребер. Добавьте ребра для выполнения алгоритма Деикстры!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
     graph.DeactivateAll();
     InfoCurr.Text = "Деикстра. Выберете вершину.ESC - отмена";
     MyCursors.CursorDijkstra();
     graph.DijkstraEnabled = true;
 }
예제 #6
0
 private void DeleteEdge_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBoxMessage())
     {
         return;
     }
     if (graph.EdgesList.Count == 0)
     {
         Xceed.Wpf.Toolkit.MessageBox.Show("Малое количество ребер для удаления", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Exclamation);
         return;
     }
     graph.DeactivateAll();
     InfoCurr.Text = "Удаление ребра. Выберете ребро.ESC - отмена";
     MyCursors.CursorDelete();
     RunUndo();
     graph.DeleteingEdgeEnabled = true;
 }
예제 #7
0
 private void DeleteVertex_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBoxMessage())
     {
         return;
     }
     if (graph.VertexesList.Count == 0)
     {
         Xceed.Wpf.Toolkit.MessageBox.Show("Малое количество вершин для удаления вершин", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Exclamation);
         return;
     }
     graph.DeactivateAll();
     InfoCurr.Text = "Удаление вершины. Выберете вершину.ESC - отмена";
     MyCursors.CursorDelete();
     RunUndo();
     graph.DeletingVertexEnable = true;
 }
예제 #8
0
 private void AddEdge_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBoxMessage())
     {
         return;
     }
     if (graph.VertexesList.Count == 0 || graph.VertexesList.Count == 1)
     {
         Xceed.Wpf.Toolkit.MessageBox.Show("Малое количество вершин для добавления ребра", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Information);
         return;
     }
     graph.DeactivateAll();
     InfoCurr.Text = "Добавление ребра. Выберете 1-ую вершину.ESC - отмена";
     MyCursors.CursorAddEdge();
     RunUndo();
     graph.AddEdgeEnabled = true;
 }
예제 #9
0
        public void EllipseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            DisableTextBoxFocus();
            Ellipse ell = new Ellipse();

            ell = (Ellipse)sender;

            if (DeletingVertexEnable)
            {
                MainWindow_.InfoCurr.Clear();
                DeleteVertex(ell);
                DeletingVertexEnable = false;
                MyCursors.DefaultCursor();
                return;
            }
            if (AddEdgeEnabled != true)
            {
                IsHolded = true;
                RunUndo();
                ell.CaptureMouse();
                ell.Cursor = Cursors.Cross;
            }
            if (AddEdgeEnabled)
            {
                VertexesInEdge++;
                if (VertexesInEdge == 1)
                {
                    FirstVertex = ell;
                    FirstVertex.StrokeThickness = 5;
                    FirstVertex.Stroke          = Brushes.Red;
                    MainWindow_.InfoCurr.Text   = "Добавление ребра. Выберете 2-ую вершину.ESC - отмена";
                    //
                    //HelpLine.StrokeThickness = 2;
                    //HelpLine.Stroke = Brushes.Gray;
                    //HelpLine.X1 = Canvas.GetLeft(FirstVertex) + FirstVertex.Width / 2;
                    //HelpLine.Y1 = Canvas.GetTop(FirstVertex) + FirstVertex.Height / 2;
                    //HelpLine.X2 = Canvas.GetLeft(FirstVertex) + FirstVertex.Width / 2;
                    //HelpLine.Y2 = Canvas.GetTop(FirstVertex) + FirstVertex.Height / 2;
                    //GraphPlain.Children.Add(HelpLine);
                }
                if (VertexesInEdge == 2)
                {
                    MainWindow_.InfoCurr.Clear();
                    OnDefaultColor();
                    VertexesInEdge = 0;
                    ConnectVertex(SearchVertexByEllipse(FirstVertex), SearchVertexByEllipse(ell));
                    AddEdgeEnabled = false;
                    MyCursors.DefaultCursor();
                }
            }
            if (AStarEnabled)
            {
                IsHolded = false;
                AStarVertexesEnumerator++;
                if (AStarVertexesEnumerator == 1)
                {
                    FirstVertex = ell;
                    MainWindow_.InfoCurr.Text = "A*. Выберете вторую вершину.ESC - отмена";
                }
                if (AStarVertexesEnumerator == 2)
                {
                    MainWindow_.InfoCurr.Clear();
                    AStarVertexesEnumerator = 0;
                    SearchShortestPathAStar(SearchVertexByEllipse(FirstVertex), SearchVertexByEllipse(ell));
                    MyCursors.DefaultCursor();
                    AStarEnabled = false;
                }
            }
        }