예제 #1
0
    internal static ESRI.ArcGIS.Geodatabase.IWorkspace GetWorkspace(String title)
    {
      IGxDialog theGDlg = new GxDialogClass();
      IGxObject theObject;
      IEnumGxObject theResults;

      IGxObject theGeoDb = (IGxObject)new GxDatabase();
      IGxDatabase theWorkspace;
      ESRI.ArcGIS.Catalog.esriDoubleClickResult theClick = esriDoubleClickResult.esriDCRChooseAndDismiss;

      theGDlg.Title = title;
      theGDlg.ButtonCaption = "Open";
      theGDlg.RememberLocation = true;
      IGxObjectFilter theFilter = new GxFilterWorkspacesClass();
      theFilter.CanChooseObject(theGeoDb, ref theClick);

      theGDlg.ObjectFilter = theFilter;
      if (theGDlg.DoModalOpen(0, out theResults))
      {
        Application.DoEvents();
        theObject = theResults.Next();
        if (theObject == null) return null;
        theWorkspace = (IGxDatabase)theObject;
        return theWorkspace.Workspace;
      }
      return null;
    }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) {
            //
            if (context == null) { return null; }
            if (context.Instance == null) { return null; }
            if (provider == null) { return null; }

            // Cannot handle multiple objects
            if (context.Instance is object[]) { return null; }

            // Do ArcGIS Desktop Test
            object dialog = null;
            try {
                dialog = new GxDialogClass();
            }
            catch { }
            if (dialog == null) {
                MessageBox.Show(
                    Resources.TEXT_NO_ARCGIS_DESKTOP,
                    Resources.TEXT_APPLICATION,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation,
                    MessageBoxDefaultButton.Button1,
                    MessageBoxOptions.DefaultDesktopOnly);
                return null;
            }

            // Create GxObjectFilter for GxDialog
            IGxObjectFilter gxObjectFilter = new GxFilterWorkspacesClass();

            // Create GxDialog
            IGxDialog gxDialog = (IGxDialog)dialog;
            gxDialog.AllowMultiSelect = false;
            gxDialog.ButtonCaption = Resources.TEXT_SELECT;
            gxDialog.ObjectFilter = gxObjectFilter;
            gxDialog.RememberLocation = true;
            gxDialog.Title = Resources.TEXT_SELECT_EXISTING_GEODATABASE;

            // Declare Enumerator to hold selected objects
            IEnumGxObject enumGxObject = null;

            // Open Dialog
            if (!gxDialog.DoModalOpen(0, out enumGxObject)) { return null; }
            if (enumGxObject == null) { return null; }

            // Get Selected Object (if any)
            IGxObject gxObject = enumGxObject.Next();
            if (gxObject == null) { return null; }
            //if (!gxObject.IsValid) { return null; }

            // Get GxDatabase
            if (!(gxObject is IGxDatabase)) { return null; }
            IGxDatabase gxDatabase = (IGxDatabase)gxObject;

            // Get IWorkspace
            ESRI.ArcGIS.Geodatabase.IWorkspaceName workspaceName = gxDatabase.WorkspaceName;

            // Return Arguments
            return workspaceName;
        }
        /// <summary>
        /// Opens a dialog so the user can select a workspace.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonOutWS_Click(object sender, EventArgs e)
        {
            try
            {
                IGxObjectFilter           wsFilter = new GxFilterWorkspacesClass();
                IGxDialog                 dlg      = new GxDialogClass();
                IGxObjectFilterCollection filters  = (IGxObjectFilterCollection)dlg;
                filters.AddFilter(wsFilter, false);
                dlg.Title         = "Select File Geodatabase or Shapefile Folder";
                dlg.ButtonCaption = "Select";
                IEnumGxObject objects = null;
                if (dlg.DoModalOpen(0, out objects))
                {
                    IGxObject          obj = objects.Next();
                    IWorkspaceFactory2 workspaceFactory;
                    if (obj.Category == "File Geodatabase")
                    {
                        workspaceFactory = new FileGDBWorkspaceFactoryClass();
                    }
                    else if (obj.Category == "Folder")
                    {
                        workspaceFactory = new ShapefileWorkspaceFactoryClass();
                    }
                    else
                    {
                        ShowError("Not a file geodatabase or shapefile folder.");
                        return;
                    }
                    IFeatureWorkspace workspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(obj.FullName, 0);
                    _transform.SetWorkspace(workspace);
                    textBoxOutWS.Text = obj.BaseName;
                    _workspaceOK      = true;

                    List <IDatasetName> allNames = _transform.GetFeatureClassNames();
                    listViewData.Items.Clear();
                    for (int i = 0; i < allNames.Count; i++)
                    {
                        AddItemToListViewData(allNames[i]);
                    }
                    FillControlComboBox();
                    SelectComboBoxItem(comboBoxControlPts, _transform.GetWorkspacePath(),
                                       "Control_Points_Unprojected");
                }
                EnableSelectInputs();
            }
            catch (Exception ex)
            {
                ShowError(ex.Message);
            }
        }
예제 #4
0
        public static IWorkspace SelectWorkspaceDialog()
        {
            IGxObjectFilter pGxObjectFilter = new GxFilterWorkspacesClass();
            IGxDialog       pGxDialog       = new GxDialogClass();

            pGxDialog.ObjectFilter     = pGxObjectFilter;
            pGxDialog.AllowMultiSelect = false;
            pGxDialog.ButtonCaption    = "选择";
            pGxDialog.RememberLocation = true;
            pGxDialog.Title            = "选择地理数据库";
            IEnumGxObject pEnumGxObject = null;

            if (pGxDialog.DoModalOpen(0, out pEnumGxObject))
            {
                IGxObject pSelectGxObject = pEnumGxObject.Next();
                if (pSelectGxObject is IGxDatabase)
                {
                    IGxDatabase pGxDatabase = pSelectGxObject as IGxDatabase;
                    return(pGxDatabase.Workspace);
                }
            }
            return(null);
        }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            //
            if (context == null)
            {
                return(null);
            }
            if (context.Instance == null)
            {
                return(null);
            }
            if (provider == null)
            {
                return(null);
            }

            // Cannot handle multiple objects
            if (context.Instance is object[])
            {
                return(null);
            }

            // Do ArcGIS Desktop Test
            object dialog = null;

            try {
                dialog = new GxDialogClass();
            }
            catch { }
            if (dialog == null)
            {
                MessageBox.Show(
                    Resources.TEXT_NO_ARCGIS_DESKTOP,
                    Resources.TEXT_APPLICATION,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation,
                    MessageBoxDefaultButton.Button1,
                    MessageBoxOptions.DefaultDesktopOnly);
                return(null);
            }

            // Create GxObjectFilter for GxDialog
            IGxObjectFilter gxObjectFilter = new GxFilterWorkspacesClass();

            // Create GxDialog
            IGxDialog gxDialog = (IGxDialog)dialog;

            gxDialog.AllowMultiSelect = false;
            gxDialog.ButtonCaption    = Resources.TEXT_SELECT;
            gxDialog.ObjectFilter     = gxObjectFilter;
            gxDialog.RememberLocation = true;
            gxDialog.Title            = Resources.TEXT_SELECT_EXISTING_GEODATABASE;

            // Declare Enumerator to hold selected objects
            IEnumGxObject enumGxObject = null;

            // Open Dialog
            if (!gxDialog.DoModalOpen(0, out enumGxObject))
            {
                return(null);
            }
            if (enumGxObject == null)
            {
                return(null);
            }

            // Get Selected Object (if any)
            IGxObject gxObject = enumGxObject.Next();

            if (gxObject == null)
            {
                return(null);
            }
            //if (!gxObject.IsValid) { return null; }

            // Get GxDatabase
            if (!(gxObject is IGxDatabase))
            {
                return(null);
            }
            IGxDatabase gxDatabase = (IGxDatabase)gxObject;

            // Get IWorkspace
            ESRI.ArcGIS.Geodatabase.IWorkspaceName workspaceName = gxDatabase.WorkspaceName;

            // Return Arguments
            return(workspaceName);
        }
        private void MenuItem_Activate(object sender, EventArgs e)
        {
            try {
                //
                // Error List Context Menu
                //
                if (sender == this.menuButtonItemScroll)
                {
                    // Can only zoom to one item
                    if (this.listViewErrorList.SelectedItems.Count != 1)
                    {
                        return;
                    }

                    // Get EsriTable containing the error
                    ListViewItemError item  = (ListViewItemError)this.listViewErrorList.SelectedItems[0];
                    EsriTable         table = null;
                    if (item.Error is ErrorTable)
                    {
                        ErrorTable errorTable = (ErrorTable)item.Error;
                        table = errorTable.Table;
                    }
                    else if (item.Error is ErrorTableRow)
                    {
                        ErrorTableRow errorTableRow = (ErrorTableRow)item.Error;
                        EsriTableRow  esriTableRow  = (EsriTableRow)errorTableRow.TableRow;
                        table = (EsriTable)esriTableRow.Table;
                    }
                    else if (item.Error is ErrorObject)
                    {
                        ErrorObject errorObject = (ErrorObject)item.Error;
                        table = errorObject.Table;
                    }
                    if (table == null)
                    {
                        return;
                    }

                    // Get Containing Model
                    EsriModel model = (EsriModel)table.Container;

                    // Scroll to Table
                    model.ScrollToElement(table);

                    // Flash Table
                    table.Flash();
                }
                else if (sender == this.menuButtonItemSelect)
                {
                    // Can only zoom to one item
                    if (this.listViewErrorList.SelectedItems.Count == 0)
                    {
                        return;
                    }

                    foreach (ListViewItemError item in this.listViewErrorList.SelectedItems)
                    {
                        EsriModel model = null;
                        if (item.Error is ErrorTable)
                        {
                            ErrorTable errorTable = (ErrorTable)item.Error;
                            EsriTable  table      = errorTable.Table;
                            model = (EsriModel)table.Container;
                        }
                        else if (item.Error is ErrorTableRow)
                        {
                            ErrorTableRow errorTableRow = (ErrorTableRow)item.Error;
                            EsriTableRow  esriTableRow  = (EsriTableRow)errorTableRow.TableRow;
                            EsriTable     table         = (EsriTable)esriTableRow.Table;
                            model = (EsriModel)table.Container;
                        }
                        else if (item.Error is ErrorObject)
                        {
                            ErrorObject errorObject = (ErrorObject)item.Error;
                            EsriTable   table       = errorObject.Table;
                            model = (EsriModel)table.Container;
                        }
                        if (model == null)
                        {
                            continue;
                        }

                        // Clear Model Selection
                        model.SelectElements(false);
                    }
                    //
                    foreach (ListViewItemError item in this.listViewErrorList.SelectedItems)
                    {
                        // Get Table
                        EsriTable table = null;
                        if (item.Error is ErrorTable)
                        {
                            ErrorTable errorTable = (ErrorTable)item.Error;
                            table = errorTable.Table;
                        }
                        else if (item.Error is ErrorTableRow)
                        {
                            ErrorTableRow errorTableRow = (ErrorTableRow)item.Error;
                            EsriTableRow  esriTableRow  = (EsriTableRow)errorTableRow.TableRow;
                            table = (EsriTable)esriTableRow.Table;
                        }
                        else if (item.Error is ErrorObject)
                        {
                            ErrorObject errorObject = (ErrorObject)item.Error;
                            table = errorObject.Table;
                        }
                        if (table == null)
                        {
                            continue;
                        }

                        // Flash Table
                        table.Selected = true;
                    }
                }
                else if (sender == this.menuButtonItemFlashError)
                {
                    // Can only zoom to one item
                    if (this.listViewErrorList.SelectedItems.Count == 0)
                    {
                        return;
                    }

                    //
                    foreach (ListViewItemError item in this.listViewErrorList.SelectedItems)
                    {
                        // Get Table
                        EsriTable table = null;
                        if (item.Error is ErrorTable)
                        {
                            ErrorTable errorTable = (ErrorTable)item.Error;
                            table = errorTable.Table;
                        }
                        else if (item.Error is ErrorTableRow)
                        {
                            ErrorTableRow errorTableRow = (ErrorTableRow)item.Error;
                            EsriTableRow  esriTableRow  = (EsriTableRow)errorTableRow.TableRow;
                            table = (EsriTable)esriTableRow.Table;
                        }
                        else if (item.Error is ErrorObject)
                        {
                            ErrorObject errorObject = (ErrorObject)item.Error;
                            table = errorObject.Table;
                        }
                        if (table == null)
                        {
                            continue;
                        }

                        // Flash Table
                        table.Flash();
                    }
                }
                else if (sender == this.menuButtonItemClearError)
                {
                    // Remove Selected Items
                    foreach (ListViewItemError item in this.listViewErrorList.SelectedItems)
                    {
                        if (this.m_errors.Contains(item.Error))
                        {
                            this.m_errors.Remove(item.Error);
                        }
                    }

                    // Refresh Error List
                    this.RefreshErrorList();
                }
                else if (sender == menuButtonItemClearAllErrors)
                {
                    // Remove All Errors
                    this.m_errors.Clear();

                    // Refresh Error List
                    this.RefreshErrorList();
                }
                //
                // Validator Dropdown Menu
                //
                else if (sender == this.menuButtonItemPGdb)
                {
                    WorkspaceValidator.Default.Validator = new PersonalGeodatabaseValidator();
                }
                else if (sender == this.menuButtonItemFGdb)
                {
                    WorkspaceValidator.Default.Validator = new FileGeodatabaseValidator();
                }
                else if (sender == this.menuButtonItemSelectGeodatabase)
                {
                    // Create GxObjectFilter for GxDialog
                    IGxObjectFilter gxObjectFilter = new GxFilterWorkspacesClass();

                    // Create GxDialog
                    IGxDialog gxDialog = new GxDialogClass();
                    gxDialog.AllowMultiSelect = false;
                    gxDialog.ButtonCaption    = Resources.TEXT_SELECT;
                    gxDialog.ObjectFilter     = gxObjectFilter;
                    gxDialog.RememberLocation = true;
                    gxDialog.Title            = Resources.TEXT_SELECT_EXISTING_GEODATABASE;

                    // Declare Enumerator to hold selected objects
                    IEnumGxObject enumGxObject = null;

                    // Open Dialog
                    if (!gxDialog.DoModalOpen(0, out enumGxObject))
                    {
                        return;
                    }
                    if (enumGxObject == null)
                    {
                        return;
                    }

                    // Get Selected Object (if any)
                    IGxObject gxObject = enumGxObject.Next();
                    if (gxObject == null)
                    {
                        return;
                    }
                    if (!gxObject.IsValid)
                    {
                        return;
                    }

                    // Get GxDatabase
                    if (!(gxObject is IGxDatabase))
                    {
                        return;
                    }
                    IGxDatabase gxDatabase = (IGxDatabase)gxObject;

                    // Get Workspace
                    IWorkspace workspace = gxDatabase.Workspace;
                    if (workspace == null)
                    {
                        return;
                    }

                    // Get Workspace Factory
                    IWorkspaceFactory workspaceFactory = workspace.WorkspaceFactory;
                    if (workspaceFactory == null)
                    {
                        return;
                    }

                    // Get Workspace Factory ID
                    IUID   uid  = workspaceFactory.GetClassID();
                    string guid = uid.Value.ToString().ToUpper();

                    switch (guid)
                    {
                    case EsriRegistry.GEODATABASE_PERSONAL:
                        WorkspaceValidator.Default.Validator = new PersonalGeodatabaseValidator(workspace);
                        break;

                    case EsriRegistry.GEODATABASE_FILE:
                        WorkspaceValidator.Default.Validator = new FileGeodatabaseValidator(workspace);
                        break;

                    case EsriRegistry.GEODATABASE_SDE:
                        WorkspaceValidator.Default.Validator = new SdeValidator(workspace);
                        break;

                    default:
                        break;
                    }
                }
                else if ((sender is MenuButtonItem) && (((MenuButtonItem)sender).Parent == this.menuButtonItemSdeConnection))
                {
                    MenuButtonItem item = (MenuButtonItem)sender;
                    if (item.Tag == null)
                    {
                        return;
                    }
                    WorkspaceValidator.Default.Validator = new SdeValidator(item.Tag.ToString());
                }
            }
            catch (Exception ex) {
                ExceptionDialog.HandleException(ex);
            }
        }
        private void MenuItem_Activate(object sender, EventArgs e) {
            try {
                //
                // Error List Context Menu
                //
                if (sender == this.menuButtonItemScroll) {
                    // Can only zoom to one item
                    if (this.listViewErrorList.SelectedItems.Count != 1) { return; }

                    // Get EsriTable containing the error
                    ListViewItemError item = (ListViewItemError)this.listViewErrorList.SelectedItems[0];
                    EsriTable table = null;
                    if (item.Error is ErrorTable) {
                        ErrorTable errorTable = (ErrorTable)item.Error;
                        table = errorTable.Table;
                    }
                    else if (item.Error is ErrorTableRow) {
                        ErrorTableRow errorTableRow = (ErrorTableRow)item.Error;
                        EsriTableRow esriTableRow = (EsriTableRow)errorTableRow.TableRow;
                        table = (EsriTable)esriTableRow.Table;
                    }
                    else if (item.Error is ErrorObject) {
                        ErrorObject errorObject = (ErrorObject)item.Error;
                        table = errorObject.Table;
                    }
                    if (table == null) { return; }

                    // Get Containing Model
                    EsriModel model = (EsriModel)table.Container;

                    // Scroll to Table
                    model.ScrollToElement(table);

                    // Flash Table
                    table.Flash();
                }
                else if (sender == this.menuButtonItemSelect) {
                    // Can only zoom to one item
                    if (this.listViewErrorList.SelectedItems.Count == 0) { return; }

                    foreach (ListViewItemError item in this.listViewErrorList.SelectedItems) {
                        EsriModel model = null;
                        if (item.Error is ErrorTable) {
                            ErrorTable errorTable = (ErrorTable)item.Error;
                            EsriTable table = errorTable.Table;
                            model = (EsriModel)table.Container;
                        }
                        else if (item.Error is ErrorTableRow) {
                            ErrorTableRow errorTableRow = (ErrorTableRow)item.Error;
                            EsriTableRow esriTableRow = (EsriTableRow)errorTableRow.TableRow;
                            EsriTable table = (EsriTable)esriTableRow.Table;
                            model = (EsriModel)table.Container;
                        }
                        else if (item.Error is ErrorObject) {
                            ErrorObject errorObject = (ErrorObject)item.Error;
                            EsriTable table = errorObject.Table;
                            model = (EsriModel)table.Container;
                        }
                        if (model == null) { continue; }

                        // Clear Model Selection
                        model.SelectElements(false);
                    }
                    // 
                    foreach (ListViewItemError item in this.listViewErrorList.SelectedItems) {
                        // Get Table
                        EsriTable table = null;
                        if (item.Error is ErrorTable) {
                            ErrorTable errorTable = (ErrorTable)item.Error;
                            table = errorTable.Table;
                        }
                        else if (item.Error is ErrorTableRow) {
                            ErrorTableRow errorTableRow = (ErrorTableRow)item.Error;
                            EsriTableRow esriTableRow = (EsriTableRow)errorTableRow.TableRow;
                            table = (EsriTable)esriTableRow.Table;
                        }
                        else if (item.Error is ErrorObject) {
                            ErrorObject errorObject = (ErrorObject)item.Error;
                            table = errorObject.Table;
                        }
                        if (table == null) { continue; }

                        // Flash Table
                        table.Selected = true;
                    }
                }
                else if (sender == this.menuButtonItemFlashError) {
                    // Can only zoom to one item
                    if (this.listViewErrorList.SelectedItems.Count == 0) { return; }

                    // 
                    foreach (ListViewItemError item in this.listViewErrorList.SelectedItems) {
                        // Get Table
                        EsriTable table = null;
                        if (item.Error is ErrorTable) {
                            ErrorTable errorTable = (ErrorTable)item.Error;
                            table = errorTable.Table;
                        }
                        else if (item.Error is ErrorTableRow) {
                            ErrorTableRow errorTableRow = (ErrorTableRow)item.Error;
                            EsriTableRow esriTableRow = (EsriTableRow)errorTableRow.TableRow;
                            table = (EsriTable)esriTableRow.Table;
                        }
                        else if (item.Error is ErrorObject) {
                            ErrorObject errorObject = (ErrorObject)item.Error;
                            table = errorObject.Table;
                        }
                        if (table == null) { continue; }

                        // Flash Table
                        table.Flash();
                    }
 
                }
                else if (sender == this.menuButtonItemClearError) {
                    // Remove Selected Items
                    foreach (ListViewItemError item in this.listViewErrorList.SelectedItems) {
                        if (this.m_errors.Contains(item.Error)) {
                            this.m_errors.Remove(item.Error);
                        }
                    }

                    // Refresh Error List
                    this.RefreshErrorList();
                }
                else if (sender == menuButtonItemClearAllErrors) {
                    // Remove All Errors
                    this.m_errors.Clear();

                    // Refresh Error List
                    this.RefreshErrorList();
                }
                //
                // Validator Dropdown Menu
                //
                else if (sender == this.menuButtonItemPGdb) {
                    WorkspaceValidator.Default.Validator = new PersonalGeodatabaseValidator();
                }
                else if (sender == this.menuButtonItemFGdb) {
                    WorkspaceValidator.Default.Validator = new FileGeodatabaseValidator();
                }
                else if (sender == this.menuButtonItemSelectGeodatabase) {
                    // Create GxObjectFilter for GxDialog
                    IGxObjectFilter gxObjectFilter = new GxFilterWorkspacesClass();

                    // Create GxDialog
                    IGxDialog gxDialog = new GxDialogClass();
                    gxDialog.AllowMultiSelect = false;
                    gxDialog.ButtonCaption = Resources.TEXT_SELECT;
                    gxDialog.ObjectFilter = gxObjectFilter;
                    gxDialog.RememberLocation = true;
                    gxDialog.Title = Resources.TEXT_SELECT_EXISTING_GEODATABASE;

                    // Declare Enumerator to hold selected objects
                    IEnumGxObject enumGxObject = null;

                    // Open Dialog
                    if (!gxDialog.DoModalOpen(0, out enumGxObject)) { return; }
                    if (enumGxObject == null) { return; }

                    // Get Selected Object (if any)
                    IGxObject gxObject = enumGxObject.Next();
                    if (gxObject == null) { return; }
                    if (!gxObject.IsValid) { return; }

                    // Get GxDatabase
                    if (!(gxObject is IGxDatabase)) { return; }
                    IGxDatabase gxDatabase = (IGxDatabase)gxObject;

                    // Get Workspace
                    IWorkspace workspace = gxDatabase.Workspace;
                    if (workspace == null) { return; }

                    // Get Workspace Factory
                    IWorkspaceFactory workspaceFactory = workspace.WorkspaceFactory;
                    if (workspaceFactory == null) { return; }

                    // Get Workspace Factory ID
                    IUID uid = workspaceFactory.GetClassID();
                    string guid = uid.Value.ToString().ToUpper();

                    switch (guid) {
                        case EsriRegistry.GEODATABASE_PERSONAL:
                            WorkspaceValidator.Default.Validator = new PersonalGeodatabaseValidator(workspace);
                            break;
                        case EsriRegistry.GEODATABASE_FILE:
                            WorkspaceValidator.Default.Validator = new FileGeodatabaseValidator(workspace);
                            break;
                        case EsriRegistry.GEODATABASE_SDE:
                            WorkspaceValidator.Default.Validator = new SdeValidator(workspace);
                            break;
                        default:
                            break;
                    }
                }
                else if ((sender is MenuButtonItem) && (((MenuButtonItem)sender).Parent == this.menuButtonItemSdeConnection)) {
                    MenuButtonItem item = (MenuButtonItem)sender;
                    if (item.Tag == null) { return; }
                    WorkspaceValidator.Default.Validator = new SdeValidator(item.Tag.ToString());
                }
            }
            catch (Exception ex) {
                ExceptionDialog.HandleException(ex);
            }
        }