예제 #1
0
        private void OnMenuClick(object sender, RoutedEventArgs e)
        {
            switch (((MenuItem)sender).Name)
            {
            case "menuAOIDelete":
                break;

            case "menuFormatMap":
                bool proceed = false;
                foreach (var aoi in Entities.AOIViewModel.GetAllAOI())
                {
                    if (aoi.GridIsLoaded && aoi.GridMapping.HasGriddedData)
                    {
                        proceed = true;
                        break;
                    }
                }


                if (!proceed)
                {
                    MessageBox.Show("There is no gridded map", "GPXC Manager", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    FormatGridMapWindow fmw = FormatGridMapWindow.GetInstance(_aoi);
                    if (fmw.Visibility == Visibility.Visible)
                    {
                        fmw.BringIntoView();
                    }
                    else
                    {
                        fmw.Owner = this;
                        fmw.Show();
                    }
                }

                break;

            case "menuEditGrid":
                MakeGrid();
                menuEditGrid.IsEnabled   = false;
                menuShowGrid.IsEnabled   = false;
                menuRemoveGrid.IsEnabled = true;
                break;

            case "menuGridMapping":
                ShowGridMappingWindow();
                break;

            case "menuAOIZoom":
                if (_aoi != null)
                {
                    MapWindowManager.ZoomToShapeFileExtent(_aoi.ShapeFile);
                }
                break;

            case "menuAOIEditExtent":
                if (_aoi != null)
                {
                    _editingAOI = true;
                    AOIManager.Edit(_aoi);
                    buttonOk.IsEnabled = true;
                }
                break;

            case "menuRemoveGrid":
                if (_aoi != null)
                {
                    //MapWindowManager.MapLayersHandler.RemoveLayer(_aoi.MapLayerHandle);
                    MapWindowManager.MapLayersHandler.RemoveLayer(_aoi.GridLayerName);
                    _aoi.GridIsLoaded        = false;
                    menuRemoveGrid.IsEnabled = false;
                    menuShowGrid.IsEnabled   = !_aoi.GridIsLoaded;
                    menuEditGrid.IsEnabled   = !_aoi.GridIsLoaded;
                    SetDataGridContext();
                }
                break;

            case "menuShowGrid":

                if (_aoi.GridFileName != null && _aoi.GridFileName.Length > 0 && File.Exists(_aoi.GridFileName))
                {
                    var files = Entities.AOIViewModel.GetAOISubGridFileNames(_aoi);
                    if (files.Count > 1)
                    {
                        var selectedFile         = "";
                        SelectGridFileWindow sgw = new SelectGridFileWindow();
                        sgw.GridFiles = files;
                        if ((bool)sgw.ShowDialog())
                        {
                            selectedFile = sgw.SelectedFile;
                            menuGridMapping.IsEnabled = _aoi.CreateGridFromFileName(selectedFile);
                        }
                    }
                    else
                    {
                        menuGridMapping.IsEnabled = _aoi.CreateGridFromFileName(_aoi.GridFileName);
                    }
                }
                else
                {
                    MakeGrid();
                }
                SetDataGridContext();
                menuShowGrid.IsEnabled   = !_aoi.GridIsLoaded;
                menuEditGrid.IsEnabled   = menuShowGrid.IsEnabled;
                menuRemoveGrid.IsEnabled = _aoi.GridIsLoaded;
                break;
            }
        }
예제 #2
0
        private void OnButtonClick(object sender, RoutedEventArgs e)
        {
            Button btn = (Button)sender;

            switch (btn.Name)
            {
            case "buttonProcessGrid":
            case "buttonShowGrid":
            case "buttonFormatMaps":
                if (Entities.AOIViewModel.CountSelected() > 0)
                {
                    switch (btn.Name)
                    {
                    case "buttonShowGrid":
                        Entities.AOIViewModel.SetGridFilenamesOfCommonSize();
                        if (Entities.AOIViewModel.CommonGridSizes.Count > 1)
                        {
                            SelectGridFileWindow sgw = new SelectGridFileWindow();
                            sgw.CommonGridSizes = Entities.AOIViewModel.CommonGridSizes;
                            if ((bool)sgw.ShowDialog())
                            {
                                //Entities.AOIViewModel.CommonGridSizeSelectedSize = sgw.SelectedGridSize;
                                foreach (var aoi in Entities.AOIViewModel.GetSelectedAOIs())
                                {
                                    var file = aoi.GetGridFileNameOfGridSize(((int)sgw.SelectedGridSize).ToString());
                                    aoi.CreateGridFromFileName(file);
                                }
                            }
                        }
                        else if (Entities.AOIViewModel.CommonGridSizes.Count == 1)
                        {
                            foreach (var aoi in Entities.AOIViewModel.GetSelectedAOIs())
                            {
                                var file = aoi.GetGridFileNameOfGridSize(Entities.AOIViewModel.CommonGridSizes[0]);
                                aoi.CreateGridFromFileName(file);
                            }
                        }
                        SetDataGridContext();
                        break;

                    case "buttonProcessGrid":
                        var griddedAOICount = Entities.AOIViewModel.GetSelectedAOIs().Count(t => t.SubGrids != null);
                        if (griddedAOICount == Entities.AOIViewModel.CountSelected())
                        {
                            ShowGridMappingWindow(mulitpleAOIs: true);
                        }
                        else
                        {
                            MessageBox.Show("All selected AOIs must have a grid", "GPX Manager", MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                        break;

                    case "buttonFormatMaps":
                        FormatGridMapWindow fmw = FormatGridMapWindow.GetInstance(_aoi);
                        if (fmw.Visibility == Visibility.Visible)
                        {
                            fmw.BringIntoView();
                        }
                        else
                        {
                            fmw.Owner = this;
                            fmw.Show();
                        }
                        break;
                    }
                }
                else
                {
                    MessageBox.Show("At least one AOI must be selected", "GPX Manager", MessageBoxButton.OK, MessageBoxImage.Information);
                }

                break;

            case "buttonCancel":
                MapWindowManager.MapLayersHandler.RemoveLayer(AOIManager._hAOI);
                Close();
                break;

            case "buttonOk":
                if (textBoxAOIName.Text.Length > 0)
                {
                    _aoi = AOIManager.SaveAOI(textBoxAOIName.Text);

                    if (_aoi != null)
                    {
                        Close();
                    }
                }
                else if (_editingAOI)
                {
                    _aoi = AOIManager.SaveAOI(_aoi.Name, true);
                    buttonOk.IsEnabled = _aoi == null;
                }
                break;
            }
        }