private void ImportBitmap_Click(object sender, RoutedEventArgs e)
        {
            RectangleCanvas.Visibility = Visibility.Hidden;
            currRange = new Range();
            currRange = InitStructures.InitCellularAutomata(properties);
            SetProperties();
            OpenFileDialog openfiledialog = new OpenFileDialog();

            openfiledialog.Title  = "Open Image";
            openfiledialog.Filter = "Image File|*.bmp; *.gif; *.jpg; *.jpeg; *.png;";

            if (openfiledialog.ShowDialog() == true)
            {
                Image.Source = Converters.BitmapToImageSource(new Bitmap(openfiledialog.FileName));
                currRange.StructureBitmap = new Bitmap(openfiledialog.FileName);

                CellularAutomata.UpdateGrainsArray(currRange);
                for (int i = 0; i < currRange.Width; i++)
                {
                    for (int j = 0; j < currRange.Height; j++)
                    {
                        currRange.StructureBitmap.SetPixel(i, j, currRange.GrainsArray[i, j].Color);
                    }
                }
            }

            dispatcher.Stop();
            Clear_Selected_Grains_Click(sender, e);
            SetEnableSubStrAndBoundCheckBoxs();
        }
        private void Previous_Structure_Button_Click(object sender, RoutedEventArgs e)
        {
            prevRange = new Range();
            prevRange = InitStructures.InitCellularAutomata(properties);

            CellularAutomata.UpdateBitmap(currRange);

            prevRange.StructureBitmap = currRange.StructureBitmap;
            CellularAutomata.UpdateGrainsArray(prevRange);
            CellularAutomata.UpdateBitmap(prevRange);
            prevRange = nucleons.EnergyDistributor(currRange, nucleons);

            CellularAutomata.UpdateBitmap(currRange);
            Image.Source = Converters.BitmapToImageSource(currRange.StructureBitmap);
        }
        private void Energy_Vizualization_Button_Click(object sender, RoutedEventArgs e)
        {
            currRange = new Range();
            currRange = InitStructures.InitCellularAutomata(properties);

            CellularAutomata.UpdateBitmap(prevRange);

            currRange.StructureBitmap = prevRange.StructureBitmap;
            CellularAutomata.UpdateGrainsArray(currRange);
            CellularAutomata.UpdateBitmap(currRange);
            nucleons.EnergyDistributor(prevRange, nucleons);
            nucleons.EnergyVisualization(ref prevRange, nucleons);
            CellularAutomata.UpdateBitmap(prevRange);
            Image.Source = Converters.BitmapToImageSource(prevRange.StructureBitmap);
        }
        private void Play_Button_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                Mouse.OverrideCursor = Cursors.Wait;
            });
            RectangleCanvas.Visibility = Visibility.Hidden;

            if (Substructures.SubStrucrtuePointsList.Count > 0)
            {
                SetProperties();

                if (MonteCarloRadioButton.IsChecked == true)
                {
                    prevRange = substructures.UpdateSubstructuresMC(currRange, properties);
                }
                else
                {
                    prevRange = substructures.UpdateSubstructuresCA(currRange, properties);
                }
            }
            else
            {
                SetProperties();

                if (MonteCarloRadioButton.IsChecked == true)
                {
                    prevRange             = InitStructures.InitMonteCarlo(properties);
                    SRXCheckBox.IsChecked = false;
                    nucleons.IsEnable     = false;
                }
                else
                {
                    prevRange = InitStructures.InitCellularAutomata(properties);

                    if (inclusions.CreationTime == InclusionsCreationTime.Begin && InclusionsCheckBox.IsChecked == true)
                    {
                        prevRange = inclusions.AddInclusionsAtTheBegining(prevRange);
                    }
                }
            }
            dispatcher.Start();
        }
        private void ImportTXT_Click(object sender, RoutedEventArgs e)
        {
            RectangleCanvas.Visibility = Visibility.Hidden;
            currRange = new Range();
            currRange = InitStructures.InitCellularAutomata(properties);
            SetProperties();
            OpenFileDialog openfiledialog = new OpenFileDialog();

            openfiledialog.Title  = "Open Image";
            openfiledialog.Filter = "Image File|*.txt";

            if (openfiledialog.ShowDialog() == true)
            {
                Image.Source = Converters.BitmapToImageSource(new Bitmap(openfiledialog.FileName));
                currRange.StructureBitmap = new Bitmap(openfiledialog.FileName);

                CellularAutomata.UpdateGrainsArray(currRange);
                CellularAutomata.UpdateBitmap(currRange);
            }

            dispatcher.Stop();
            Clear_Selected_Grains_Click(sender, e);
            SetEnableSubStrAndBoundCheckBoxs();
        }