Exemple #1
0
        /// <summary>
        /// Checks Add-combobox and confirms the operation
        /// </summary>
        /// <param name="sender">Button Confirm</param>
        /// <param name="e">Routed Event</param>
        private async void Confirm_add_item(object sender, RoutedEventArgs e)
        {
            try
            {
                if (Graph_exist)
                {
                    switch (selected_item_name)
                    {
                    case "Vértice":
                    {
                        Vertice vertice_aux = new Vertice(label_box.Text, Graph.NumVertices());
                        Graph.AddVertice(vertice_aux);

                        v1_box.Items.Add(vertice_aux.Label);
                        v2_box.Items.Add(vertice_aux.Label);
                        v1_rem_box.Items.Add(vertice_aux.Label);
                        v2_rem_box.Items.Add(vertice_aux.Label);
                        if (Graph.Vertices.Count > 0)
                        {
                            Vertex_list.ItemsSource = Graph.VerticeToListString();
                        }
                        else
                        {
                            Vertex_list.ItemsSource = null;
                        }
                        IsNotRendered = true;
                        break;
                    }

                    case "Aresta":
                    {
                        if (Graph.Vertices.Count > 0)
                        {
                            Aresta aresta_aux = new Aresta(float.Parse(weigth_Aresta_box.Text), Graph.BuscaVertice(v1_box.SelectedItem.ToString()), Graph.BuscaVertice(v2_box.SelectedItem.ToString()), Graph.isDigraph);
                            Graph.AddAresta(aresta_aux);
                        }
                        break;
                    }
                    }
                    if (selected_item_name != "")
                    {
                        myConsole.AddStringToConsole($"\n{selected_item_name} {label_box.Text} foi adicionado.");
                    }
                    myConsole.Update();
                }
                else
                {
                    msgdi = new MessageDialog("Não existe Grafo ainda!");
                    await msgdi.ShowAsync();
                }
            }catch (Exception ex) {
                msgdi = new MessageDialog($"Erro {ex.Message}");
                await msgdi.ShowAsync();
            }
        }
Exemple #2
0
        /// <summary>
        /// Checks Add-combobox and confirms the operation
        /// </summary>
        /// <param name="sender">Button Confirm</param>
        /// <param name="e">Routed Event</param>
        private async void Confirm_add_item(object sender, RoutedEventArgs e)
        {
            try
            {
                if (selected_item_name == "Grafo")
                {
                    if (Graph_exist)
                    {
                        msgdi = new MessageDialog("Não pode existir mais de um Grafo ainda!");
                        await msgdi.ShowAsync();

                        return;
                    }
                    else
                    {
                        Graph       = new Grafo(isDigraph.IsChecked.Value);
                        Graph.name  = label_box.Text;
                        Graph_exist = true;
                    }
                }
                if (Graph_exist)
                {
                    switch (selected_item_name)
                    {
                    case "Vértice":
                    {
                        Vertice vertice_aux = new Vertice(label_box.Text, Graph.NumVertices() + 1);

                        Graph.AddVertice(vertice_aux);
                        Debug.WriteLine(Graph.NumVertices());
                        Debug.WriteLine(Graph.NumArestas());
                        v1_box.Items.Add(vertice_aux.Label);
                        v2_box.Items.Add(vertice_aux.Label);
                        break;
                    }

                    case "Aresta":
                    {
                        Aresta aresta_aux = new Aresta(float.Parse(weigth_Aresta_box.Text), Graph.BuscaVertice(v1_box.SelectedItem.ToString()), Graph.BuscaVertice(v2_box.SelectedItem.ToString()), Graph.isDigraph);
                        Graph.AddAresta(aresta_aux);
                        break;
                    }
                    }
                    if (selected_item_name != "")
                    {
                        myConsole.AddStringToConsole($"\n{selected_item_name} {label_box.Text} foi adicionado.");
                    }
                }
                else
                {
                    msgdi = new MessageDialog("Não existe Grafo ainda!");
                    await msgdi.ShowAsync();
                }
            }catch (Exception ex) {
                msgdi = new MessageDialog($"Erro {ex.Message}");
                await msgdi.ShowAsync();
            }

            clear_ui_add();
            Add_scene.Visibility      = Visibility.Collapsed;
            ComboAdd_box.SelectedItem = "";
            myConsole.Update();
            graphStats.Update();
        }