Exemple #1
0
        private void btnFeatureDomains_Click(object sender, EventArgs e)
        {
            try
            {
                bool isDomain = false;

                if (sender.Equals(btnFeatureDomains))
                {
                    isDomain = true;
                }

                IGxDialog xmlFileSelectDialog = new GxDialogClass();
                xmlFileSelectDialog.AllowMultiSelect = false;
                if (isDomain)
                {
                    xmlFileSelectDialog.Title = resourceManager.GetString("OSMEditor_OSMPropertyPage_fileselect_title_domain");
                }
                else
                {
                    xmlFileSelectDialog.Title = resourceManager.GetString("OSMEditor_OSMPropertyPage_fileselect_title_feature");
                }
                xmlFileSelectDialog.RememberLocation = true;
                xmlFileSelectDialog.ButtonCaption    = resourceManager.GetString("OSMEditor_OSMPropertyPage_fileselect_buttoncaption");

                xmlFileSelectDialog.ObjectFilter = new GxFilterXmlFiles();

                IEnumGxObject selectedConfigurationFile = null;

                if (xmlFileSelectDialog.DoModalOpen(m_editor.Parent.hWnd, out selectedConfigurationFile))
                {
                    if (selectedConfigurationFile == null)
                    {
                        return;
                    }

                    selectedConfigurationFile.Reset();

                    IGxFile xmlFile = selectedConfigurationFile.Next() as IGxFile;

                    if (xmlFile == null)
                    {
                        return;
                    }

                    if (isDomain)
                    {
                        txtOSMDomainFileLocation.Text = xmlFile.Path;
                    }
                    else
                    {
                        txtOSMFeaturePropertiesFileLocation.Text = xmlFile.Path;
                    }

                    SetPageDirty(true);
                }
            }
            catch
            {
            }
        }
Exemple #2
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;
    }
Exemple #3
0
 /// <summary>
 /// Opens a dialog so the user can select a dataset containing the new data to be transformed.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void inputDatasetButton_Click(object sender, EventArgs e)
 {
     try
     {
         IGxObjectFilter           datasetFilter = new GxFilterFeatureDatasetsClass();
         IGxDialog                 dlg           = new GxDialogClass();
         IGxObjectFilterCollection filters       = (IGxObjectFilterCollection)dlg;
         filters.AddFilter(datasetFilter, true);
         dlg.Title         = "Select the feature dataset containing the data to be transformed";
         dlg.ButtonCaption = "Select";
         IEnumGxObject objects = null;
         if (dlg.DoModalOpen(0, out objects))
         {
             IGxObject obj = objects.Next();
             _inputDatasetName        = (IFeatureDatasetName2)obj.InternalObjectName;
             inputDatasetTextBox.Text = obj.Parent.Name + "/" + obj.Name;
             List <IDatasetName> fcNames =
                 EsriUtilities.GetFeatureClassNames(esriGeometryType.esriGeometryPoint,
                                                    _inputDatasetName);
             fcNames.Sort(_nameComparer);
             controlPointsComboBox.DataSource    = fcNames;
             controlPointsComboBox.DisplayMember = "Name";
             EnableSave();
         }
     }
     catch (Exception ex)
     {
         ShowError(ex.Message);
     }
 }
        private IEnumLayer GetLayers()
        {
            //now get the map document to parse out the feature classes
            GxDialog      pGxDialog = new GxDialogClass();
            IEnumGxObject pEnumGxObject;
            bool          pResult;

            pGxDialog.ObjectFilter = new GxFilterMapsClass();
            pGxDialog.Title        = "Select a map document";
            try
            {
                pResult = pGxDialog.DoModalOpen(0, out pEnumGxObject);
                //check to see if the user canceled the dialog
                if (pResult == false)
                {
                    return(null);
                }
                IGxObject  pGxObject  = pEnumGxObject.Next();
                IMapReader pMapReader = new MapReaderClass();
                pMapReader.Open(pGxObject.FullName.ToString());
                IMap pMap = pMapReader.get_Map(0);
                ESRI.ArcGIS.esriSystem.UID pUID = new ESRI.ArcGIS.esriSystem.UIDClass();
                pUID.Value = "{40A9E885-5533-11D0-98BE-00805F7CED21}";                  //feature layer

                IEnumLayer pLayers = pMap.get_Layers(pUID, true);
                return(pLayers);
            }
            catch
            {
                //error getting layers
                return(null);
            }
        }
Exemple #5
0
        private void btnDataSource_Click(object sender, EventArgs e)
        {
            try
            {
                IGxCatalog pGxCat    = new GxCatalogClass();
                IGxDialog  pGxDialog = new GxDialogClass();

                pGxDialog.AllowMultiSelect = false;
                pGxDialog.ButtonCaption    = "Open";

                IGxObjectFilter pGxFilter = new GxFilterPointFeatureClassesClass();
                pGxDialog.ObjectFilter = pGxFilter;

                IEnumGxObject pDataFiles;
                pGxDialog.DoModalOpen(0, out pDataFiles);

                if (pDataFiles != null)
                {
                    m_pGXObj = pDataFiles.Next();
                    ///
                    /// added check for null to handle null m_pGXObj
                    ///
                    if (m_pGXObj != null)
                    {
                        txtOtherData.Text = m_pGXObj.FullName.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                m_pGXObj = null;
            }
            this.Focus();
        }
Exemple #6
0
        /// <summary>
        /// Opens an ArcGIS Style Dialog box instead of windows style one for shapefiles.
        /// </summary>
        public static string OpenShapeFileDialog2()
        {
            IGxDialog                 pGxDialog = new GxDialogClass();
            IGxObjectFilter           pFilter   = new GxFilterShapefilesClass();
            IGxObjectFilter           pFilter2  = new GxFilterSDEFeatureClasses();
            IGxObjectFilterCollection pFilterCollection;
            IEnumGxObject             pEnumGx;

            pFilterCollection = pGxDialog as IGxObjectFilterCollection;
            pFilterCollection.AddFilter(pFilter, true);
            pFilterCollection.AddFilter(pFilter2, true);
            pGxDialog.Title = "Browse Data";

            if ((bool)pGxDialog.DoModalOpen(0, out pEnumGx))
            {
                IGxObject pGxObject;
                pGxObject = pEnumGx.Next() as IGxObject;

                if (pGxObject is GxDataset)
                {
                    var path = pGxObject.FullName;
                    // Just in case releasing the com objects might help the issue:
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(pGxObject);
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(pGxDialog);
                    return(path);
                }
            }
            return(null);
        }
		private IEnumLayer GetLayers()
		{
			//now get the map document to parse out the feature classes
			GxDialog pGxDialog = new GxDialogClass();
			IEnumGxObject pEnumGxObject;
			bool pResult;

			pGxDialog.ObjectFilter = new GxFilterMapsClass();
			pGxDialog.Title = "Select a map document";
			try
			{
				pResult = pGxDialog.DoModalOpen(0, out pEnumGxObject);
				//check to see if the user canceled the dialog
				if (pResult == false) return null;
				IGxObject pGxObject = pEnumGxObject.Next();
				IMapReader pMapReader = new MapReaderClass();
				pMapReader.Open(pGxObject.FullName.ToString());
				IMap pMap = pMapReader.get_Map(0);
				ESRI.ArcGIS.esriSystem.UID pUID = new ESRI.ArcGIS.esriSystem.UIDClass();
				pUID.Value = "{40A9E885-5533-11D0-98BE-00805F7CED21}";  //feature layer

				IEnumLayer pLayers = pMap.get_Layers(pUID, true);
                return pLayers;
			}
			catch
			{
				//error getting layers
				return null;
			}

		}
Exemple #8
0
 /// <summary>
 /// Opens a dialog so the user can select an output workspace.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void outputWorkspaceButton_Click(object sender, EventArgs e)
 {
     try
     {
         IGxObjectFilter           geodatabaseFilter = new GxFilterFileGeodatabasesClass();
         IGxDialog                 dlg     = new GxDialogClass();
         IGxObjectFilterCollection filters = (IGxObjectFilterCollection)dlg;
         filters.AddFilter(geodatabaseFilter, false);
         dlg.Title         = "Select the file geodatabase for the output";
         dlg.ButtonCaption = "Select";
         IEnumGxObject objects = null;
         if (dlg.DoModalOpen(0, out objects))
         {
             IGxObject          obj = objects.Next();
             IWorkspaceFactory2 workspaceFactory = new FileGDBWorkspaceFactoryClass();
             IFeatureWorkspace  workspace        = (IFeatureWorkspace)workspaceFactory.OpenFromFile(obj.FullName, 0);
             _transform.SetWorkspace(workspace);
             outputWorkspaceTextBox.Text = obj.Name;
             EnableSave();
         }
     }
     catch (Exception ex)
     {
         ShowError(ex.Message);
     }
 }
Exemple #9
0
        private void btnSCLFPath_Click(object sender, EventArgs e)
        {
            IGxDialog gxDialog    = new GxDialogClass();
            var       gxFilterCol = (IGxObjectFilterCollection)gxDialog;

            gxFilterCol.AddFilter(new GxFilterFileFolder(), false);
            //gxFilterCol.AddFilter(new GxFilterFileGeodatabases(), true);
            //gxFilterCol.AddFilter(new GxFilterFGDBFeatureDatasets(), false);
            gxFilterCol.AddFilter(new GxFilterPersonalGeodatabases(), false);
            gxFilterCol.AddFilter(new GxFilterPGDBFeatureDatasets(), false);
            //gxFilterCol.AddFilter(new GxFilterPGDBTables(), false);
            //gxFilterCol.AddFilter(new GxFilterFeatureClasses(), false);
            gxDialog.Title            = " 结果输出路径";
            gxDialog.AllowMultiSelect = false;

            IEnumGxObject gxSelection = null;

            gxDialog.DoModalOpen(ArcMap.Application.hWnd, out gxSelection);

            IGxObject gxObject = null;

            while ((gxObject = gxSelection.Next()) != null)
            {
                txtOutPath.Text = gxObject.FullName;
            }

            //OutputPath = gxDialog.FinalLocation.FullName;
            //OutputName = gxDialog.Name;

            //if (string.IsNullOrWhiteSpace(OutputName))
            //    txtSCLFPath.Text = "";
            //else
            //    txtSCLFPath.Text = OutputPath + @"\" + OutputName;
        }
        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;
        }
Exemple #11
0
        private IGxDialog GetGxDialog()
        {
            IGxDialog dialog = new GxDialogClass();

            dialog.ButtonCaption    = "OK";
            dialog.AllowMultiSelect = false;
            dialog.ObjectFilter     = new MMGxFilterDatabasesClass();

            return(dialog);
        }
Exemple #12
0
        private IGxObject AddExistingFilters()
        {
            IEnumGxObject enumGxObject = null;

            IGxObjectFilter           gxObjectFilter_Fabrics = new GxFilterCadastralFabricsClass();
            IGxDialog                 gxDialog = new GxDialogClass();
            IGxObjectFilterCollection gxObjectFilterCollection = (IGxObjectFilterCollection)gxDialog;

            gxObjectFilterCollection.AddFilter(gxObjectFilter_Fabrics, true);
            gxDialog.Title = "Browse Fabrics";
            gxDialog.DoModalOpen(0, out enumGxObject);
            return(enumGxObject.Next());
        }
Exemple #13
0
        private void btnDestFeatures_Click(object sender, EventArgs e)
        {
            IGxDialog gxDialog    = new GxDialogClass();
            var       gxFilterCol = (IGxObjectFilterCollection)gxDialog;

            gxFilterCol.AddFilter(new GxFilterPolygonFeatureClasses(), false);
            gxDialog.AllowMultiSelect = false;
            gxDialog.Title            = " 添加目标要素类";

            IEnumGxObject gxSelection = null;

            gxDialog.DoModalOpen(ArcMap.Application.hWnd, out gxSelection);
            var gxObject = gxSelection.Next();

            if (gxObject != null)
            {
                string features_path            = gxObject.Parent.FullName;
                string features_name            = gxObject.Name;
                string features_parent_path     = System.IO.Path.GetDirectoryName(features_path);
                string features_parent_path_ext = System.IO.Path.GetExtension(features_parent_path);
                if (features_parent_path_ext == ".gdb" || features_parent_path_ext == ".mdb")
                {
                    features_path = features_parent_path;
                }

                cmbDestFeatures.Text = "";
                cmbDestFeatures.Items.Clear();

                DataManagementTools dataManagementTools = new DataManagementTools();
                DestFeatureClass = dataManagementTools.OpenFeatureClass(features_path, features_name);

                if (DestFeatureClass == null)
                {
                    cmbDestFeatures.Text = "";
                    return;
                }

                cmbDestFeatures.Text = gxObject.FullName;

                var table = (ITable)DestFeatureClass;
                for (int i = 0; i < table.Fields.FieldCount; i++)
                {
                    var field = table.Fields.Field[i];
                    if (field.Type != esriFieldType.esriFieldTypeDate)
                    {
                        cmbDestField.Items.Add(field.Name); // 添加Feature UID字段的控件选择
                    }
                }
            }
        }
        /// <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);
            }
        }
        public static IGxObject OpenArcFile(IGxObjectFilter objectFilter, string Caption)
        {
            IGxDialog     fileChooser = new GxDialogClass();
            IEnumGxObject chosenFiles = null;

            fileChooser.Title            = Caption;
            fileChooser.ButtonCaption    = "Select";
            fileChooser.AllowMultiSelect = false;
            fileChooser.ObjectFilter     = objectFilter;
            fileChooser.DoModalOpen(0, out chosenFiles);

            chosenFiles.Reset();
            return(chosenFiles.Next());
        }
		// Creates Dialog on first call and init filter
		private void InitAddressLocatorDlg()
		{
			if (m_dlgAddressLocator == null)
			{
                // Create Address Locator Dialog
				m_dlgAddressLocator = new GxDialogClass();

				IGxObjectFilter filter = null;
				filter = new GxFilterAddressLocatorsClass();

				m_dlgAddressLocator.ObjectFilter = filter;
				m_dlgAddressLocator.Title = "Add Address Locator";
			}
		}
        private IGxObject OpenShapefile(string Caption)
        {
            IGxDialog     fileChooser = new GxDialogClass();
            IEnumGxObject chosenFiles = null;

            fileChooser.Title            = Caption;
            fileChooser.ButtonCaption    = "Select";
            fileChooser.AllowMultiSelect = false;
            fileChooser.ObjectFilter     = new GxFilterShapefilesClass();
            fileChooser.DoModalOpen(0, out chosenFiles);

            chosenFiles.Reset();
            return(chosenFiles.Next());
        }
Exemple #18
0
        private void openFeatureButton_Click(object sender, EventArgs e)
        {
            IGxDialog gxDialog = new GxDialogClass
            {
                AllowMultiSelect = false,
                Title = "Select Feature Class to Determine File Size",
                ObjectFilter = new GxFilterFeatureClassesClass()
            };

            IEnumGxObject gxObjects;
            gxDialog.DoModalOpen(0, out gxObjects);

            if (gxObjects == null) return;

            gxObjects.Reset();

            IGxDataset gxDataset = gxObjects.Next() as IGxDataset;
            IGxObjectProperties gxProps = gxDataset as IGxObjectProperties;

            FeatClassTextBox.Text = gxDataset.DatasetName.Name;
            FileSizeGxTextBox.Text = gxProps.GetProperty("ESRI_GxObject_FileSize").ToString();

            double kb = double.Parse(FileSizeGxTextBox.Text)*ConversionFactor;
            
            string size;
            if (kb >= 1024.0)
            {
                double mb = ConvertKBToMB(kb);
                size = Math.Round(mb, 2, MidpointRounding.AwayFromZero).ToString(CultureInfo.InvariantCulture) + " MB";

                if (mb >= 1024.0)
                {
                    double gb = ConvertMBToGB(mb);
                    size = Math.Round(gb, 2, MidpointRounding.AwayFromZero).ToString(CultureInfo.InvariantCulture) + "GB";

                    if (gb >= 1024.0)
                    {
                        double tb = ConvertGBToTB(gb);
                        size = Math.Round(tb, 2, MidpointRounding.AwayFromZero).ToString(CultureInfo.InvariantCulture) + " TB";
                    }
                }
            }
            else
            {
                size = Math.Round(kb, 2, MidpointRounding.AwayFromZero).ToString(CultureInfo.InvariantCulture) + " KB";
            }

            FileSizeDiskTextBox.Text = size;
        }
		// Creates Dialog on first call and init filter
		private void InitBarriersDlg()
		{
			if (m_dlgBarriers == null)
			{
				// Create Barriers dialog
				m_dlgBarriers = new GxDialogClass();

				IGxObjectFilter objFilter = null;

				objFilter = new GxFilterFeatureDatasetsAndFeatureClassesClass();
				m_dlgBarriers.ObjectFilter = objFilter;

				m_dlgBarriers.Title = "Choose Barriers Layer";
			}
		}
Exemple #20
0
        public static GCDConsoleLib.Vector BrowseOpenVector(string formTitle, System.IO.DirectoryInfo diWorkspace, string sFCName, BrowseGISTypes eType, IntPtr hParentWindowHandle)
        {
            IGxDialog pGxDialog = new GxDialogClass();
            IGxObjectFilterCollection pFilterCol = (IGxObjectFilterCollection)pGxDialog;

            switch (eType)
            {
            case BrowseGISTypes.Point: pFilterCol.AddFilter(new GxFilterPointFeatureClasses(), true); break;

            case BrowseGISTypes.Line: pFilterCol.AddFilter(new GxFilterPolylineFeatureClasses(), true); break;

            case BrowseGISTypes.Polygon: pFilterCol.AddFilter(new GxFilterPolygonFeatureClasses(), true); break;

            default: pFilterCol.AddFilter(new GxFilterFeatureClasses(), true); break;
            }

            IEnumGxObject pEnumGx   = null;
            IGxObject     pGxObject = null;

            pGxDialog.RememberLocation = true;
            pGxDialog.AllowMultiSelect = false;
            pGxDialog.Title            = formTitle;
            pGxDialog.ButtonCaption    = "Select";
            if (diWorkspace != null && diWorkspace.Exists)
            {
                object existingDirectory = diWorkspace.FullName;
                pGxDialog.set_StartingLocation(ref existingDirectory);
            }

            pGxDialog.Name = sFCName;
            GCDConsoleLib.Vector gResult = null;
            try
            {
                if (pGxDialog.DoModalOpen(hParentWindowHandle.ToInt32(), out pEnumGx))
                {
                    pGxObject = pEnumGx.Next();
                    sFCName   = pGxObject.BaseName;
                    gResult   = new GCDConsoleLib.Vector(new System.IO.FileInfo(pGxObject.FullName));
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error attempting to browse for vector GIS data source", ex);
            }

            return(gResult);
        }
Exemple #21
0
        //使用GxDialog对话框选择要输出的数据源(要素集和(或)要素类、shapefile文件)
        private IEnumGxObject AddLayerWithGxDialog()
        {
            try
            {
                IGxDialog gxDlg = new GxDialogClass();
                // create a data format filter
                IGxObjectFilter gxObjFilter = new GxFilterFeatureDatasetsAndFeatureClassesClass();
                // set the properties of the open dialog
                gxDlg.Title            = "Add Feature Datasets and/or Feature Classes";
                gxDlg.ObjectFilter     = gxObjFilter;
                gxDlg.AllowMultiSelect = true;
                gxDlg.RememberLocation = true;

                IEnumGxObject gxObjects;
                bool          open = gxDlg.DoModalOpen(0, out gxObjects);

                IGxDataset gxDataset = gxObjects.Next() as IGxDataset;
                if (gxDataset != null)
                {
                    if (gxDataset.Dataset is IFeatureClass)
                    {
                        IFeatureClass   featureClass   = gxDataset.Dataset as IFeatureClass;
                        IFeatureDataset featureDataSet = featureClass.FeatureDataset;
                        if (featureDataSet == null)
                        {
                            IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                            featureWorkspace = pWorkspaceFactory.OpenFromFile(gxDlg.FinalLocation.FullName, this.Handle.ToInt32()) as IFeatureWorkspace;
                        }
                        else
                        {
                            featureWorkspace = featureDataSet.Workspace as IFeatureWorkspace;
                        }
                    }
                    else if (gxDataset.Dataset is IFeatureDataset)
                    {
                        IFeatureDataset featureDataSet = gxDataset.Dataset as IFeatureDataset;
                        featureWorkspace = featureDataSet.Workspace as IFeatureWorkspace;
                    }
                }
                return(gxObjects);
            }
            catch
            {
                MessageBox.Show("不能打开数据集或要素类!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(null);
        }
        public void ShowRasterDatasetBrowser(int handle, out IEnumGxObject ipSelectedObjects)
        {
            IGxObjectFilterCollection ipFilterCollection = new GxDialogClass();

            IGxObjectFilter ipFilter1 = new GxFilterRasterDatasetsClass();
            ipFilterCollection.AddFilter(ipFilter1, true);
            IGxDialog ipGxDialog = (IGxDialog)(ipFilterCollection);

            ipGxDialog.RememberLocation = true;
            ipGxDialog.Title = "Open";

            ipGxDialog.AllowMultiSelect = false;
            ipGxDialog.RememberLocation = true;

            ipGxDialog.DoModalOpen((int)(Handle.ToInt32()), out ipSelectedObjects);
            return;
        }
Exemple #23
0
        /// <summary>
        /// Busca una Capa Raster
        /// </summary>
        /// <returns></returns>
        private string BuscarRaster(string titulo)
        {
            IGxDialog pGxDialog = new GxDialogClass();

            pGxDialog.AllowMultiSelect = false;
            IGxObjectFilter pGxFilter = (IGxObjectFilter) new GxFilterRasterDatasetsClass();

            pGxDialog.ObjectFilter = pGxFilter;
            pGxDialog.Title        = titulo;
            IEnumGxObject pEnumGxObj;

            if (pGxDialog.DoModalOpen(0, out pEnumGxObj))
            {
                return(pEnumGxObj.Next().FullName);
            }
            return("");
        }
Exemple #24
0
        public static IFeatureClass SelectFeatureClassDialog()
        {
            IGxDialog pGxDialog = new GxDialogClass();

            pGxDialog.ObjectFilter     = new GxFilterFeatureClassesClass();
            pGxDialog.AllowMultiSelect = false;
            pGxDialog.RememberLocation = true;
            IEnumGxObject pEnumGxObject;

            if (pGxDialog.DoModalOpen(0, out pEnumGxObject))
            {
                IGxObject  pSelectGxObject = pEnumGxObject.Next();
                IGxDataset pGxDataset      = (IGxDataset)pSelectGxObject;
                return(pGxDataset.Dataset as IFeatureClass);
            }
            return(null);
        }
Exemple #25
0
        /// <summary>
        /// Open the add data dialog.
        /// </summary>
        /// <param name="sCaption">Caption of the dialog.</param>
        /// <param name="pFilter">Dataset filters.</param>
        /// <param name="bMultiSelect">Allow for multiple selections.</param>
        /// <returns></returns>
        private string OpenGXDialog(string sCaption, IGxObjectFilter pFilter, bool bMultiSelect)
        {
            IGxDialog     pBrowse  = new GxDialogClass();
            IEnumGxObject pSelect  = null;
            IGxObject     pObject  = null;
            IGxCatalog    pCatalog = pBrowse.InternalCatalog;

            string sFile = "";

            try
            {
                //set up the filters

                //setup the browse window
                pBrowse.AllowMultiSelect = bMultiSelect;
                pBrowse.Title            = sCaption;
                pBrowse.ObjectFilter     = pFilter; //!!!this should be written to read a filter collection, but throws a COM QI error
                pBrowse.RememberLocation = true;

                //open the browse window and get the selected file info
                if (pBrowse.DoModalOpen(0, out pSelect))
                {
                    pObject = pSelect.Next();
                    while (pObject != null)
                    {
                        sFile  += pObject.FullName + ";";
                        pObject = pSelect.Next();
                    }
                    //pInternalName = (IGxObjectInternalName) pObject;
                    //pName = (IName) pInternalName.InternalObjectName;

                    //remove the last semi colon
                    if (sFile.Length > 0)
                    {
                        sFile = sFile.Substring(0, sFile.Length - 1);
                    }
                }
                return(sFile);
            }
            catch (Exception oErr)
            {
                MessageBox.Show(oErr.ToString(), "Data Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
        }
        private string BuscarTablaReclasificacion(string TipoTabla)
        {
            IGxDialog       pGxDialog = new GxDialogClass();
            IGxObjectFilter filter    = new GxFilterTablesClass();

            pGxDialog.Title        = "Buscar Tabla " + TipoTabla;
            pGxDialog.ObjectFilter = filter;
            IEnumGxObject pEnumObj;

            if (pGxDialog.DoModalOpen(0, out pEnumObj))
            {
                return(pEnumObj.Next().FullName);
            }
            else
            {
                return("");
            }
        }
        private string BuscarGeodatabase()
        {
            IGxDialog       pGxDialog = new GxDialogClass();
            IGxObjectFilter filter    = new GxFilterPersonalGeodatabasesClass();

            pGxDialog.Title        = "Buscar Geodatabase ";
            pGxDialog.ObjectFilter = filter;
            IEnumGxObject pEnumObj;

            if (pGxDialog.DoModalOpen(0, out pEnumObj))
            {
                return(pEnumObj.Next().FullName);
            }
            else
            {
                return("");
            }
        }
Exemple #28
0
        public static GCDConsoleLib.Raster BrowseOpenRaster(string sFormTitle, System.IO.DirectoryInfo diWorkspace, string sName, IntPtr hParentWindowHandle)
        {
            IGxDialog                 pGxDialog     = new GxDialogClass();
            IGxObjectFilter           pRasterFilter = new GxFilterRasterDatasets();
            IGxObjectFilterCollection pFilterCol    = (IGxObjectFilterCollection)pGxDialog;

            pFilterCol.AddFilter(pRasterFilter, true);
            pGxDialog.RememberLocation = true;
            pGxDialog.AllowMultiSelect = false;
            pGxDialog.Title            = sFormTitle;

            IEnumGxObject pEnumGx   = null;
            IGxObject     pGxObject = null;

            if (diWorkspace is System.IO.DirectoryInfo && diWorkspace.Exists)
            {
                pGxDialog.set_StartingLocation(diWorkspace.FullName);
            }

            GCDConsoleLib.Raster rResult = null;
            try
            {
                if (pGxDialog.DoModalOpen(hParentWindowHandle.ToInt32(), out pEnumGx))
                {
                    pGxObject = pEnumGx.Next();
                    System.IO.FileInfo sFile = new System.IO.FileInfo(pGxObject.FullName);
                    sName       = pGxObject.Name;
                    diWorkspace = sFile.Directory;

                    rResult = new GCDConsoleLib.Raster(new System.IO.FileInfo(pGxObject.FullName));
                }
            }
            catch (Exception ex)
            {
                ex.Data["Title"] = sFormTitle;
                ex.Data["Name"]  = sName;
                throw;
            }

            return(rResult);
        }
Exemple #29
0
        private void OnLoadFeatureClass(object sender, EventArgs e)
        {
            IGxDialog iGxDlg = new GxDialogClass();

            iGxDlg.Title        = "选择点数据集";
            iGxDlg.ObjectFilter = new GxFilterPointFeatureClassesClass();
            IEnumGxObject selection;

            iGxDlg.DoModalOpen(0, out selection);
            selection.Reset();

            IGxObject iGxObject;

            while ((iGxObject = selection.Next()) != null)
            {
                IGxDataset iGxDataset = (IGxDataset)iGxObject;
                if (iGxDataset != null)
                {
                    IDataset      iDataset = iGxDataset.Dataset;
                    IFeatureClass iFc      = (IFeatureClass)iDataset;
                    mFeatureClass = iFc;

                    textBox6.Text = iGxObject.FullName;

                    //设置ComboBox
                    comboBox1.ResetText();
                    IFields iFields = iFc.Fields;
                    long    iCount  = iFields.FieldCount;
                    for (int i = 0; i < iCount; i++)
                    {
                        IField iField = iFields.get_Field(i);
                        comboBox1.Items.Add(iField.Name);
                    }

                    if (comboBox1.Items.Count > 0)
                    {
                        comboBox1.SelectedIndex = 0;
                    }
                }
            }
        }//Open Feature Class
Exemple #30
0
        public static IFeatureClass SelectFeatureClassDialog(List <IGxObjectFilter> gxFilters)
        {
            IGxDialog pGxDialog = new GxDialogClass();
            IGxObjectFilterCollection pFilterCol = pGxDialog as IGxObjectFilterCollection;

            foreach (IGxObjectFilter gxObjectFilter in gxFilters)
            {
                pFilterCol.AddFilter(gxObjectFilter, true);
            }
            pGxDialog.AllowMultiSelect = false;
            pGxDialog.RememberLocation = true;
            IEnumGxObject pEnumGxObject;

            if (pGxDialog.DoModalOpen(0, out pEnumGxObject))
            {
                IGxObject  pSelectGxObject = pEnumGxObject.Next();
                IGxDataset pGxDataset      = (IGxDataset)pSelectGxObject;
                return(pGxDataset.Dataset as IFeatureClass);
            }
            return(null);
        }
Exemple #31
0
        public static IGxObject SelectWorkspaceAndDatasetDialog()
        {
            IGxDialog pGxDialog = new GxDialogClass();
            IGxObjectFilterCollection pCollection = pGxDialog as IGxObjectFilterCollection;

            pCollection.AddFilter(new GxFilterWorkspacesClass(), true);
            pCollection.AddFilter(new GxFilterDatasetsClass(), false);
            IEnumGxObject pEnumGxObject;

            pGxDialog.Title            = "选择数据";
            pGxDialog.AllowMultiSelect = false;
            if (pGxDialog.DoModalOpen(0, out pEnumGxObject))
            {
                IGxObject pGxObject = pEnumGxObject.Next();
                if (pGxDialog != null)
                {
                    return(pGxObject);
                }
            }
            return(null);
        }
Exemple #32
0
 /// <summary>
 /// Opens a dialog so the user can select an existing shapefile or file geodatabase
 /// feature class.
 /// </summary>
 /// <param name="title">title for dialog</param>
 /// <returns>dataset name object for the selected feature class or null </returns>
 private IDatasetName SelectFeatureClass(string title, esriGeometryType geom)
 {
     try
     {
         IGxObjectFilter           shpFilter = new GxFilterShapefilesClass();
         IGxObjectFilter           gdbFilter = new GxFilterFGDBFeatureClassesClass();
         IGxDialog                 dlg       = new GxDialogClass();
         IGxObjectFilterCollection filters   = (IGxObjectFilterCollection)dlg;
         filters.AddFilter(shpFilter, false);
         filters.AddFilter(gdbFilter, true);
         dlg.Title = title;
         IDatasetName  dsName  = null;
         IEnumGxObject objects = null;
         if (dlg.DoModalOpen(0, out objects))
         {
             IGPUtilities2 util = new GPUtilitiesClass();
             string        name = objects.Next().FullName;
             dsName = (IDatasetName)util.CreateFeatureClassName(name);
             IFeatureWorkspace ws  = (IFeatureWorkspace)((IName)dsName.WorkspaceName).Open();
             IFeatureClass     fc  = ws.OpenFeatureClass(System.IO.Path.GetFileName(name));
             esriGeometryType  shp = fc.ShapeType;
             if (!(geom == esriGeometryType.esriGeometryAny &&
                   (shp == esriGeometryType.esriGeometryPoint ||
                    shp == esriGeometryType.esriGeometryPolyline ||
                    shp == esriGeometryType.esriGeometryPolygon)) &&
                 shp != geom)
             {
                 ShowError("Wrong geometry type.");
                 dsName = null;
             }
             dsName = (IDatasetName)((IDataset)fc).FullName;
         }
         return(dsName);
     }
     catch (Exception ex)
     {
         ShowError(ex.Message);
         return(null);
     }
 }
Exemple #33
0
        private void button6_Click(object sender, EventArgs e)
        {
            IGxDialog                 dlg     = new GxDialogClass();
            IGxObjectFilter           filter1 = new GxFilterFeatureClassesClass();
            IGxObjectFilter           filter2 = new GxFilterAnnotationFeatureClassesClass();
            IGxObjectFilterCollection filters = dlg as IGxObjectFilterCollection;

            filters.AddFilter(filter1, true);
            filters.AddFilter(filter2, false);
            IEnumGxObject selection;

            if (dlg.DoModalOpen(this.Handle.ToInt32(), out selection))
            {
                IGxObject gobj = selection.Next();
                if (gobj != null)
                {
                    this.tbxDataSource.Text = gobj.FullName;
                    m_fcName = gobj.InternalObjectName;
                    this.tbxCacheName.Text = gobj.BaseName;
                }
            }
        }
        public string GetOutputFileName(string aFileType, string anInitialDirectory = @"C:\")
        {
            // This would be done better with a custom type but this will do for the momment.
            IGxDialog myDialog = new GxDialogClass();
            myDialog.set_StartingLocation(anInitialDirectory);
            IGxObjectFilter myFilter;


            switch (aFileType)
            {
                case "Geodatabase FC":
                    myFilter = new GxFilterFGDBFeatureClasses();
                    break;
                case "Geodatabase Table":
                    myFilter = new GxFilterFGDBTables();
                    break;
                case "Shapefile":
                    myFilter = new GxFilterShapefiles();
                    break;
                case "DBASE file":
                    myFilter = new GxFilterdBASEFiles();
                    break;
                case "Text file":
                    myFilter = new GxFilterTextFiles();
                    break;
                default:
                    myFilter = new GxFilterDatasets();
                    break;
            }

            myDialog.ObjectFilter = myFilter;
            myDialog.Title = "Save Output As...";
            myDialog.ButtonCaption = "OK";

            string strOutFile = "None";
            if (myDialog.DoModalSave(thisApplication.hWnd))
            {
                strOutFile = myDialog.FinalLocation.FullName + @"\" + myDialog.Name;
                
            }
            myDialog = null;
            return strOutFile; // "None" if user pressed exit
            
        }
        private ResultType ExportGeometricNetwork()
        {
            // Create FeatureDataset filter for GxDialog
            IGxObjectFilter gxObjectFilter = new GxFilterGeometricNetworksClass();

            // Create GxDialog
            IGxDialog gxDialog = new GxDialogClass() {
                AllowMultiSelect = false,
                ButtonCaption = "Export",
                ObjectFilter = gxObjectFilter,
                RememberLocation = true,
                Title = "Save Geometric Network As"
            };

            // Open Dialog
            if (!gxDialog.DoModalSave(0)) { return ResultType.Cancelled; }

            // Must specify a name
            if (string.IsNullOrWhiteSpace(gxDialog.Name)) {
                GeometricNetworkViewModel.Default.AddMessage("You must specify a name", MessageType.Error);
                return ResultType.Error;
            }

            // Check parent feature dataset
            IGxObject fd = gxDialog.FinalLocation;
            if (fd == null || !fd.IsValid) {
                GeometricNetworkViewModel.Default.AddMessage(string.Format("Invalid feature dataset", gxDialog.Name), MessageType.Error);
                return ResultType.Error;
            }

            // Get feature dataset and workspace
            IGxDataset dataset = (IGxDataset)fd;
            IFeatureDataset d = (IFeatureDataset)dataset.Dataset;
            IWorkspace w = d.Workspace;

            // Check if geometric network already exists
            IGeometricNetwork gn = w.FindGeometricNetwork(gxDialog.Name);
            if (gn != null) {
                MessageBoxResult r = MessageBox.Show(
                    "The geometric network already exists. Remove?",
                    GeometricNetworkViewModel.Default.WindowTitle,
                    MessageBoxButton.YesNoCancel,
                    MessageBoxImage.Exclamation,
                    MessageBoxResult.Yes
                );
                switch (r) {
                    case MessageBoxResult.Yes:
                        IDataset dd = (IDataset)gn;

                        if (!dd.CanDelete()) {
                            GeometricNetworkViewModel.Default.AddMessage("Cannot delete geometric network", MessageType.Error);
                            return ResultType.Error;
                        }

                        try {
                            dd.Delete();
                            GeometricNetworkViewModel.Default.AddMessage("Deletion successful", MessageType.Information);
                        }
                        catch (Exception ex) {
                            GeometricNetworkViewModel.Default.AddMessage(ex.Message, MessageType.Error);
                            return ResultType.Error;
                        }

                        break;
                    case MessageBoxResult.No:
                    case MessageBoxResult.Cancel:
                    default:
                        return ResultType.Cancelled;
                }
            }

            // Initialize loader
            INetworkLoader3 networkLoader = new NetworkLoaderClass() {
                FeatureDatasetName = (IDatasetName)d.FullName,
                NetworkName = gxDialog.Name,
                NetworkType = esriNetworkType.esriNTUtilityNetwork,
                PreserveEnabledValues = PRESERVE_EXISTING_ENABLED_VALUES
            };
            INetworkLoaderProps networkLoadedProps = (INetworkLoaderProps)networkLoader;
            INetworkLoaderProgress_Event ne = (INetworkLoaderProgress_Event)networkLoader;
            ne.PutMessage += (a, b) => {
                GeometricNetworkViewModel.Default.AddMessage(string.Format("Progress: '{0}'", b), MessageType.Information);
            };

            // Assign XY snapping tolerance
            switch (SNAP_XY) {
                case SnapTolerance.None:
                    networkLoader.SnapTolerance = 0d;
                    networkLoader.UseXYsForSnapping = false;
                    break;
                case SnapTolerance.Default:
                    networkLoader.SnapTolerance = networkLoader.DefaultSnapTolerance;
                    networkLoader.UseXYsForSnapping = true;
                    break;
                case SnapTolerance.Minimum:
                    networkLoader.SnapTolerance = networkLoader.MinSnapTolerance;
                    networkLoader.UseXYsForSnapping = true;
                    break;
                case SnapTolerance.Maximum:
                    networkLoader.SnapTolerance = networkLoader.MaxSnapTolerance;
                    networkLoader.UseXYsForSnapping = true;
                    break;
                case SnapTolerance.Custom:
                    if (SNAP_XY_CUSTOM < networkLoader.MinSnapTolerance) {
                        networkLoader.SnapTolerance = networkLoader.MinSnapTolerance;
                    }
                    else if (SNAP_XY_CUSTOM > networkLoader.MaxSnapTolerance) {
                        networkLoader.SnapTolerance = networkLoader.MaxSnapTolerance;
                    }
                    else {
                        networkLoader.SnapTolerance = SNAP_XY_CUSTOM;
                    }
                    networkLoader.UseXYsForSnapping = true;
                    break;
            }

            // Assign Z snapping tolerance
            if (networkLoader.CanUseZs) {
                switch (SNAP_Z) {
                    case SnapTolerance.None:
                        networkLoader.ZSnapTolerance = 0d;
                        networkLoader.UseZs = false;
                        break;
                    case SnapTolerance.Default:
                        networkLoader.ZSnapTolerance = networkLoader.DefaultZSnapTolerance;
                        networkLoader.UseZs = true;
                        break;
                    case SnapTolerance.Minimum:
                        networkLoader.ZSnapTolerance = networkLoader.MinZSnapTolerance;
                        networkLoader.UseZs = true;
                        break;
                    case SnapTolerance.Maximum:
                        networkLoader.ZSnapTolerance = networkLoader.MaxZSnapTolerance;
                        networkLoader.UseZs = true;
                        break;
                    case SnapTolerance.Custom:
                        if (SNAP_Z_CUSTOM < networkLoader.MinZSnapTolerance) {
                            networkLoader.SnapTolerance = networkLoader.MinZSnapTolerance;
                        }
                        else if (SNAP_XY_CUSTOM > networkLoader.MaxZSnapTolerance) {
                            networkLoader.SnapTolerance = networkLoader.MaxZSnapTolerance;
                        }
                        else {
                            networkLoader.SnapTolerance = SNAP_Z_CUSTOM;
                        }
                        networkLoader.UseZs = true;
                        break;
                }
            }
            else {
                switch (SNAP_Z) {
                    case SnapTolerance.None:
                        break;
                    case SnapTolerance.Minimum:
                    case SnapTolerance.Maximum:
                    case SnapTolerance.Custom:
                        GeometricNetworkViewModel.Default.AddMessage("Z snapping is unavailable", MessageType.Warning);
                        break;
                }
            }

            // Check each feature class
            bool badfeatureclass = false;
            IFeatureClassContainer fcc = (IFeatureClassContainer)d;
            ZGeometricNetwork zgn = GeometricNetworkViewModel.Default.Dataset as ZGeometricNetwork;
            foreach (ZNetworkClass znc in zgn.NetworkClasses.Where(f => !f.IsOrphanJunctionFeatureClass)) {
                // Does the feature class exist?
                IFeatureClass fc = null;
                try {
                    fc = fcc.get_ClassByName(znc.Path.Table);
                }
                catch { }
                if (fc == null) {
                    GeometricNetworkViewModel.Default.AddMessage(string.Format("Feature class '{0}' does not exists", znc.Path.Table), MessageType.Error);
                    badfeatureclass = true;
                    continue;
                }

                // Is the feature class compatiable?
                switch (networkLoader.CanUseFeatureClass(znc.Path.Table)) {
                    case esriNetworkLoaderFeatureClassCheck.esriNLFCCCannotOpen:
                        GeometricNetworkViewModel.Default.AddMessage(string.Format("Feature class '{0}' cannot be opened", znc.Path.Table), MessageType.Error);
                        badfeatureclass = true;
                        break;
                    case esriNetworkLoaderFeatureClassCheck.esriNLFCCInAnotherNetwork:
                        GeometricNetworkViewModel.Default.AddMessage(string.Format("Feature class '{0}' belongs to another network", znc.Path.Table), MessageType.Error);
                        badfeatureclass = true;
                        break;
                    case esriNetworkLoaderFeatureClassCheck.esriNLFCCInTerrain:
                        GeometricNetworkViewModel.Default.AddMessage(string.Format("Feature class '{0}' belongs to a terrain", znc.Path.Table), MessageType.Error);
                        badfeatureclass = true;
                        break;
                    case esriNetworkLoaderFeatureClassCheck.esriNLFCCInTopology:
                        GeometricNetworkViewModel.Default.AddMessage(string.Format("Feature class '{0}' belongs to a topology", znc.Path.Table), MessageType.Error);
                        badfeatureclass = true;
                        break;
                    case esriNetworkLoaderFeatureClassCheck.esriNLFCCInvalidFeatureType:
                        GeometricNetworkViewModel.Default.AddMessage(string.Format("Feature class '{0}' has an invalid feature type", znc.Path.Table), MessageType.Error);
                        badfeatureclass = true;
                        break;
                    case esriNetworkLoaderFeatureClassCheck.esriNLFCCInvalidShapeType:
                        GeometricNetworkViewModel.Default.AddMessage(string.Format("Feature class '{0}' has an invalid shape type", znc.Path.Table), MessageType.Error);
                        badfeatureclass = true;
                        break;
                    case esriNetworkLoaderFeatureClassCheck.esriNLFCCIsCompressedReadOnly:
                        GeometricNetworkViewModel.Default.AddMessage(string.Format("Feature class '{0}' is compressed readonly", znc.Path.Table), MessageType.Error);
                        badfeatureclass = true;
                        break;
                    case esriNetworkLoaderFeatureClassCheck.esriNLFCCRegisteredAsVersioned:
                        GeometricNetworkViewModel.Default.AddMessage(string.Format("Feature class '{0}' is registered as versioned", znc.Path.Table), MessageType.Error);
                        badfeatureclass = true;
                        break;
                    case esriNetworkLoaderFeatureClassCheck.esriNLFCCUnknownError:
                        GeometricNetworkViewModel.Default.AddMessage(string.Format("Feature class '{0}' has an unknown error", znc.Path.Table), MessageType.Error);
                        badfeatureclass = true;
                        break;
                    case esriNetworkLoaderFeatureClassCheck.esriNLFCCValid:
                        break;
                }
            }
            if (badfeatureclass) { return ResultType.Error; }

            // Add feature class to network
            bool snap = SNAP_XY == SnapTolerance.None;
            foreach (ZNetworkClass znc in zgn.NetworkClasses.Where(f => !f.IsOrphanJunctionFeatureClass)) {
                string table = znc.Path.Table;

                if (znc.IsJunction) {
                    // Add simple junction
                    UID uid = new UIDClass() {
                        Value = GUID_SIMPLEJUNCTION_CLSID
                    };
                    networkLoader.AddFeatureClass(table, esriFeatureType.esriFTSimpleJunction, uid, snap);

                    if (znc.IsSourceSink) {
                        // Check junction already has a role field
                        string field = networkLoadedProps.DefaultAncillaryRoleField;
                        switch (networkLoader.CheckAncillaryRoleField(table, field)) {
                            case esriNetworkLoaderFieldCheck.esriNLFCInvalidDomain:
                                GeometricNetworkViewModel.Default.AddMessage(string.Format("{0}:{1} - The AncillaryRole field has invalid domain", table, field), MessageType.Error);
                                return ResultType.Error;
                            case esriNetworkLoaderFieldCheck.esriNLFCInvalidType:
                                GeometricNetworkViewModel.Default.AddMessage(string.Format("{0}:{1} - The AncillaryRole field has invalid type", table, field), MessageType.Error);
                                return ResultType.Error;
                            case esriNetworkLoaderFieldCheck.esriNLFCNotFound:
                                GeometricNetworkViewModel.Default.AddMessage(string.Format("{0}:{1} - Adding AncillaryRole field", table, field), MessageType.Information);
                                networkLoader.PutAncillaryRole(table, esriNetworkClassAncillaryRole.esriNCARSourceSink, field);
                                break;
                            case esriNetworkLoaderFieldCheck.esriNLFCUnknownError:
                                GeometricNetworkViewModel.Default.AddMessage(string.Format("{0}:{1} - An unknown error was encountered", table, field), MessageType.Error);
                                return ResultType.Error;
                            case esriNetworkLoaderFieldCheck.esriNLFCValid:
                                GeometricNetworkViewModel.Default.AddMessage(string.Format("{0}:{1} - An AncillaryRole field already exists", table, field), MessageType.Warning);
                                networkLoader.PutAncillaryRole(table, esriNetworkClassAncillaryRole.esriNCARSourceSink, field);
                                break;
                        }
                    }
                }
                if (znc.IsEdge) {
                    if (znc.IsComplex) {
                        // Add simple junction
                        UID uid = new UIDClass() {
                            Value = GUID_COMPLEXEDGE_CLSID
                        };
                        networkLoader.AddFeatureClass(table, esriFeatureType.esriFTComplexEdge, uid, snap);
                    }
                    else {
                        // Add simple junction
                        UID uid = new UIDClass() {
                            Value = GUID_SIMPLEEDGE_CLSID
                        };
                        networkLoader.AddFeatureClass(table, esriFeatureType.esriFTSimpleEdge, uid, snap);
                    }
                }
            }

            // Check if network class has enabled field
            foreach (ZNetworkClass znc in zgn.NetworkClasses.Where(f =>!f.IsOrphanJunctionFeatureClass)) {
                string table = znc.Path.Table;
                string field = networkLoadedProps.DefaultEnabledField;

                switch (networkLoader.CheckEnabledDisabledField(table, field)) {
                    case esriNetworkLoaderFieldCheck.esriNLFCInvalidDomain:
                        GeometricNetworkViewModel.Default.AddMessage(string.Format("{0}:{1} - The enabled field has invalid domain", table, field), MessageType.Error);
                        return ResultType.Error;
                    case esriNetworkLoaderFieldCheck.esriNLFCInvalidType:
                        GeometricNetworkViewModel.Default.AddMessage(string.Format("{0}:{1} - The enabled field has invalid type", table, field), MessageType.Error);
                        return ResultType.Error;
                    case esriNetworkLoaderFieldCheck.esriNLFCNotFound:
                        GeometricNetworkViewModel.Default.AddMessage(string.Format("{0}:{1} - Adding enabled field", table, field), MessageType.Information);
                        networkLoader.PutEnabledDisabledFieldName(table, field);
                        break;
                    case esriNetworkLoaderFieldCheck.esriNLFCUnknownError:
                        GeometricNetworkViewModel.Default.AddMessage(string.Format("{0}:{1} - An unknown error was encountered", table, field), MessageType.Error);
                        return ResultType.Error;
                    case esriNetworkLoaderFieldCheck.esriNLFCValid:
                        GeometricNetworkViewModel.Default.AddMessage(string.Format("{0}:{1} - Enabled field already exists", table, field), MessageType.Warning);
                        break;
                }
            }

            // Import network weights
            foreach (ZNetWeight weight in zgn.Weights) {
                // Add weight
                GeometricNetworkViewModel.Default.AddMessage(string.Format("Adding weight {0}", weight.Name), MessageType.Information);
                networkLoader.AddWeight(weight.Name, weight.WeightType.ToWeightType(), weight.BitGateSize);

                // Loop for each association
                foreach (ZNetWeightAssocation association in weight.NetWeightAssocations) {
                    // Add weight association
                    GeometricNetworkViewModel.Default.AddMessage(string.Format("Adding weight association {0}:{1}", association.NetworkClass.Path.Table, association.Field.Name), MessageType.Information);
                    networkLoader.AddWeightAssociation(weight.Name, association.NetworkClass.Path.Table, association.Field.Name);
                }
            }

            // Load network
            try {
                networkLoader.LoadNetwork();
            }
            catch (Exception ex) {
                GeometricNetworkViewModel.Default.AddMessage(ex.Message, MessageType.Error);
                return ResultType.Error;
            }

            // Find new network
            IGeometricNetwork gn2 = w.FindGeometricNetwork(gxDialog.Name);
            if (gn2 == null) {
                GeometricNetworkViewModel.Default.AddMessage("Geometric network creation failed", MessageType.Error);
                return ResultType.Error;
            }

            // Update the name of the orphaned network class
            ZNetworkClass orphan = zgn.NetworkClasses.FirstOrDefault(n => n.IsOrphanJunctionFeatureClass);
            if (orphan != null) {
                orphan.Path.Table = string.Format("{0}_junctions", gxDialog.Name);
            }

            // Import junction rules
            foreach (ZJunctionConnectivityRule rule in zgn.JunctionRules) {
                GeometricNetworkViewModel.Default.AddMessage(string.Format("Adding junction rule: {0}", rule.Id), MessageType.Information);
                IJunctionConnectivityRule2 r = new JunctionConnectivityRuleClass {
                    EdgeClassID = rule.Edge.Parent.ToVerfiedId(w).Value,
                    EdgeSubtypeCode = rule.Edge.Code,
                    JunctionClassID = rule.Junction.Parent.ToVerfiedId(w).Value,
                    JunctionSubtypeCode = rule.Junction.Code,
                    EdgeMinimumCardinality = rule.EdgeMinimum,
                    EdgeMaximumCardinality = rule.EdgeMaximum,
                    JunctionMinimumCardinality = rule.JunctionMinimum,
                    JunctionMaximumCardinality = rule.JunctionMaximum,
                    DefaultJunction = rule.IsDefault
                };
                gn2.AddRule(r);
            }

            // Import edge rules
            foreach (ZEdgeConnectivityRule rule in zgn.EdgeRules) {
                GeometricNetworkViewModel.Default.AddMessage(string.Format("Adding edge rule: {0}", rule.Id), MessageType.Information);
                IEdgeConnectivityRule r = new EdgeConnectivityRuleClass() {
                    FromEdgeClassID = rule.FromEdge.Parent.ToVerfiedId(w).Value,
                    FromEdgeSubtypeCode = rule.FromEdge.Code,
                    ToEdgeClassID = rule.ToEdge.Parent.ToVerfiedId(w).Value,
                    ToEdgeSubtypeCode = rule.ToEdge.Code
                };

                // Add junctions
                foreach (ZSubtype j in rule.Junctions) {
                    r.AddJunction(j.Parent.ToVerfiedId(w).Value, j.Code);
                }

                // Default junction?
                if (rule.DefaultJunction != null) {
                    r.DefaultJunctionClassID = rule.DefaultJunction.Parent.ToVerfiedId(w).Value;
                    r.DefaultJunctionSubtypeCode = rule.DefaultJunction.Code;
                }

                gn2.AddRule(r);
            }

            //
            GeometricNetworkViewModel.Default.AddMessage("Geometric network creation successful!", MessageType.Information);
            return ResultType.Successful;
        }
        /// <summary> Shows dialog for saving data.</summary>
        /// <param name="filters"> for example:
        ///       IGxObjectFilter ipFilter1 = new GxFilterFGDBFeatureClassesClass() ;
        ///       List&lt;IGxObjectFilter&gt; gxFilterList = new List&lt;IGxObjectFilter&gt;(new IGxObjectFilter[] { ipFilter1 });</param>
        /// <param name="dialogTitle">The title of the dialog</param>
        /// <returns> the path to the file to save </returns>
        public static string ShowSaveDataDialog(List<IGxObjectFilter> filters, string dialogTitle)
        {
            try
            {
                IGxDialog pGxDialog = new GxDialogClass();
                pGxDialog.Title = dialogTitle;
                pGxDialog.AllowMultiSelect = false;

                // Create a filter collection for the dialog.
                IGxObjectFilterCollection pFilterCol = (IGxObjectFilterCollection)pGxDialog;

                foreach (IGxObjectFilter filt in filters)
                {
                    pFilterCol.AddFilter(filt, false);
                }

                // Open the dialog
                if (!pGxDialog.DoModalSave(0))
                {
                    return null;
                }
                string dirPath = pGxDialog.FinalLocation.FullName;
                string path = dirPath + "\\" + pGxDialog.Name;

                if (dirPath.ToLowerInvariant().EndsWith(".gdb"))
                {
                    IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
                    IWorkspace2 workspace = (IWorkspace2)workspaceFactory.OpenFromFile(dirPath, 0);
                    IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;

                    if (workspace.get_NameExists(esriDatasetType.esriDTFeatureClass, pGxDialog.Name))
                    {
                        IDataset fc = (IDataset)featureWorkspace.OpenFeatureClass(pGxDialog.Name);
                        DialogResult dlg = MessageBox.Show(pGxDialog.Name + " bestaat al, wilt u dit overschrijven?",
                                    "Feature Class bestaat al", MessageBoxButtons.YesNo);
                        if (dlg == DialogResult.No)
                        {
                            return null;
                        }
                        else if (!fc.CanDelete())
                        {
                            MessageBox.Show(pGxDialog.Name + " is al in gebruik, u kunt dit niet overschrijven.",
                                        "Feature Class in gebruik");
                            return null;
                        }
                    }
                }
                else if (Directory.Exists(dirPath))
                {
                    IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass();
                    IWorkspace2 workspace = (IWorkspace2)workspaceFactory.OpenFromFile(dirPath, 0);
                    IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;

                    if (workspace.get_NameExists(esriDatasetType.esriDTFeatureClass, pGxDialog.Name))
                    {
                        IDataset fc = (IDataset)featureWorkspace.OpenFeatureClass(pGxDialog.Name);

                        if (!fc.CanDelete())
                        {
                            MessageBox.Show(pGxDialog.Name + " is al in gebruik, u kunt dit niet overschrijven.",
                                        "Feature Class in gebruik");
                            return null;
                        }
                    }
                }
                return path;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " " + ex.StackTrace);
                return null;
            }
        }
 /// <summary>
 /// Occurs when this command is clicked
 /// </summary>
 public override void OnClick()
 {
   try
   {
     IGxDialog gxDialog = new GxDialogClass();
     IGxObjectFilter mdbFilter = new GxFilterPGDBFeatureClasses();
     gxDialog.ObjectFilter = mdbFilter;
     object temp = "C:\\";
     gxDialog.set_StartingLocation(ref temp);
     gxDialog.Title = "Pick the feature class you want to add the ext clsid to";
     gxDialog.RememberLocation = true;
     IEnumGxObject pEnumGx;
   
     if (!gxDialog.DoModalOpen(0, out pEnumGx))
       return;
  
     IGxObject gdbObj = pEnumGx.Next();
     //Make sure there was only one GxObject in the enum.
     if (pEnumGx.Next() != null) 
       return;
     //Get the Name for the internal object that this GxObject represents.
     IName fcName  = gdbObj.InternalObjectName;
     //Opens the object referred to by this name
     IFeatureClass featClass = (IFeatureClass)fcName.Open();
     //Procedure to add the class id to the feature class internally.
     IClassSchemaEdit_Example(featClass);
     }
     catch (Exception ex)
     {
       MessageBox.Show("Error: Could open the feature class. Original error: " + ex.Message);
     }
   }
        public void ShowRasterDatasetBrowser(int handle, out IEnumGxObject ipSelectedObjects)
        {
            IGxObjectFilterCollection ipFilterCollection = new GxDialogClass();

            IGxObjectFilter ipFilter1 = new GxFilterRasterDatasetsClass();
            ipFilterCollection.AddFilter(ipFilter1, true);
            IGxDialog ipGxDialog = (IGxDialog)(ipFilterCollection);

            ipGxDialog.RememberLocation = true;
            ipGxDialog.Title = "Open";

            ipGxDialog.AllowMultiSelect = false;
            ipGxDialog.RememberLocation = true;

            ipGxDialog.DoModalOpen((int)(Handle.ToInt32()), out ipSelectedObjects);
            return;
        }
        public static string GetGeodatabaseFromUser()
        {
            try
            {
                IEnumGxObject enumGxObject = null;
                IGxObjectFilter gxObjectFilterFGBs = new GxFilterFileGeodatabasesClass();
                IGxDialog gxDialog = new GxDialogClass();
                IGxObjectFilterCollection gxObjectFilterCollection = (IGxObjectFilterCollection)gxDialog;

                gxObjectFilterCollection.AddFilter(gxObjectFilterFGBs, false);

                gxDialog.Title = "Locate Geodatabase";
                gxDialog.AllowMultiSelect = false;
                gxDialog.DoModalOpen(0, out enumGxObject);

                if (!(enumGxObject == null))
                {
                    //we don't allow multiple select so grab the first one
                    IGxObject gxObj = enumGxObject.Next();
                    string pathToFGDB = gxObj.FullName;

                    return pathToFGDB;
                }
                else
                {
                    //user cancelled
                    return "";
                }
            }
            catch
            {
                return "";
            }
        }
        /// <summary>
        /// open an ArcMap dialog box to select esri files
        /// </summary>
        public static string OpenESRIDialog(string OldPath, ref bool Cancelled)
        {
            IGxDialog pGXDialog = null;
            IEnumGxObject pEnumGxObject = null;
            IGxObject pGxObject = null;
            bool boolOK;
            object objOldPath;
            string SelFilePathAndName = "";

            objOldPath = OldPath;

            pGXDialog = new GxDialogClass();
            pGXDialog.Title = "Open File";
            pGXDialog.ButtonCaption = "Open";
            pGXDialog.AllowMultiSelect = false;
            pGXDialog.RememberLocation = true;
            pGXDialog.set_StartingLocation(ref objOldPath);

            boolOK = pGXDialog.DoModalOpen(0, out pEnumGxObject);
            if (boolOK)
            {
                pGxObject = pEnumGxObject.Next();
                SelFilePathAndName = pGxObject.FullName;
                Cancelled = false;
            }
            else
            {
                Cancelled = true;
            }

            pEnumGxObject = null;
            pGxObject = null;
            pGXDialog = null;

            return SelFilePathAndName;
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (sender == this.MenuItemExit) {
                if (GeometricNetworkViewModel.Default.IsDirty) {
                    MessageBoxResult r = MessageBox.Show(
                        "Do you want to save before closing?",
                        GeometricNetworkViewModel.Default.WindowTitle,
                        MessageBoxButton.YesNoCancel,
                        MessageBoxImage.Exclamation,
                        MessageBoxResult.Yes
                    );
                    switch (r) {
                        case MessageBoxResult.Yes:
                            // Save document
                            GeometricNetworkViewModel.Default.Save();

                            // If user canceled save dialog then exit
                            if (GeometricNetworkViewModel.Default.IsDirty) { return; }

                            break;
                        case MessageBoxResult.No:
                            break;
                        case MessageBoxResult.Cancel:
                        default:
                            return;
                    }
                }

                // Exit application
                Application.Current.Shutdown(0);
            }
            else if (sender == this.ButtonOpen) {
                // Exit if dataset already open
                if (GeometricNetworkViewModel.Default.Dataset != null) {
                    MessageBox.Show(
                        "Please close the document first",
                        GeometricNetworkViewModel.Default.WindowTitle,
                        MessageBoxButton.OK,
                        MessageBoxImage.Information,
                        MessageBoxResult.OK
                    );
                    return;
                }

                OpenFileDialog openFileDialog = new OpenFileDialog() {
                    CheckFileExists = true,
                    Filter = "GN definition document" + " (*.esriGeoNet)|*.esriGeoNet",
                    FilterIndex = 1,
                    Multiselect = false,
                    Title = GeometricNetworkViewModel.Default.WindowTitle
                };

                // Check if user pressed "Save" and File is OK.
                bool? ok = openFileDialog.ShowDialog(this);
                if (!ok.HasValue || !ok.Value) { return; }
                if (string.IsNullOrWhiteSpace(openFileDialog.FileName)) { return; }

                //
                GeometricNetworkViewModel.Default.Load(openFileDialog.FileName);
            }
            else if (sender == this.ButtonSave) {
                // Handle event to prevent bubbling event to ButtonSave
                if (e != null) {
                    e.Handled = true;
                }

                // Exit if no dataset
                if (GeometricNetworkViewModel.Default.Dataset == null) { return; }

                // If no document, show "save as" dialog
                if (GeometricNetworkViewModel.Default.Document == null) {
                    this.Button_Click(this.ButtonSaveAs, null);
                    return;
                }

                // Save document
                GeometricNetworkViewModel.Default.Save();
            }
            else if (sender == this.ButtonSaveAs) {
                // Handle event to prevent bubbling event to ButtonSave
                if (e != null) {
                    e.Handled = true;
                }

                // Show save dialog
                SaveFileDialog saveFileDialog = new SaveFileDialog() {
                    DefaultExt = "esriGeoNet",
                    FileName = "Document1",
                    Filter = "GN definition document" + " (*.esriGeoNet)|*.esriGeoNet",
                    FilterIndex = 1,
                    OverwritePrompt = true,
                    RestoreDirectory = false,
                    Title = GeometricNetworkViewModel.Default.WindowTitle
                };

                // Check if user pressed "Save" and File is OK.
                bool? ok = saveFileDialog.ShowDialog(this);
                if (!ok.HasValue || !ok.Value) { return; }
                if (string.IsNullOrWhiteSpace(saveFileDialog.FileName)) { return; }

                //
                GeometricNetworkViewModel.Default.Save(saveFileDialog.FileName);
            }
            else if (sender == this.ButtonClose) {
                if (GeometricNetworkViewModel.Default.Dataset == null) { return; }
                if (GeometricNetworkViewModel.Default.IsDirty) {
                    MessageBoxResult r = MessageBox.Show(
                        "Do you want to save before closing?",
                        GeometricNetworkViewModel.Default.WindowTitle,
                        MessageBoxButton.YesNoCancel,
                        MessageBoxImage.Exclamation,
                        MessageBoxResult.Yes
                    );
                    switch (r) {
                        case MessageBoxResult.Yes:
                            GeometricNetworkViewModel.Default.Save();
                            break;
                        case MessageBoxResult.No:
                            break;
                        case MessageBoxResult.Cancel:
                        default:
                            return;
                    }
                }

                // Clear current dataset
                GeometricNetworkViewModel.Default.Clear();
            }
            else if (sender == this.ButtonImport) {
                // Create GxObjectFilter for GxDialog
                IGxObjectFilter gxObjectFilter = new GxFilterGeometricNetworksClass();

                // Create GxDialog
                IGxDialog gxDialog = new GxDialogClass() {
                    AllowMultiSelect = false,
                    ButtonCaption = "Import",
                    ObjectFilter = gxObjectFilter,
                    RememberLocation = true,
                    Title = "Please select a geometric network"
                };

                // 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 GxDataset
                if (!(gxObject is IGxDataset)) { return; }
                IGxDataset gxDataset = (IGxDataset)gxObject;

                // Load geometric network from named object
                IName name = (IName)gxDataset.DatasetName;
                GeometricNetworkLoader loader = new GeometricNetworkLoader(name);
                loader.Load();
            }
            else if (sender == this.ButtonExport) {
                ResultType ok = this.ExportGeometricNetwork();
                switch (ok) {
                    case ResultType.Cancelled:
                        break;
                    case ResultType.Error:
                        MessageBox.Show(
                            "Geometric network creation failed",
                            GeometricNetworkViewModel.Default.WindowTitle,
                            MessageBoxButton.OK,
                            MessageBoxImage.Information,
                            MessageBoxResult.OK
                        );
                        break;
                    case ResultType.Successful:
                        MessageBox.Show(
                           "Geometric network creation successful",
                           GeometricNetworkViewModel.Default.WindowTitle,
                           MessageBoxButton.OK,
                           MessageBoxImage.Information,
                           MessageBoxResult.OK
                       );
                        break;
                }
            }
            else if (sender == this.ButtonOutput) {
                if (this.DockableContentOutput.IsHidden) {
                    this.DockableContentOutput.Show();
                }
                else if (this.DockableContentOutput.IsAutoHidden) {
                    this.DockableContentOutput.ToggleAutoHide();
                }
            }
            else if (sender == this.ButtonJunctionAdd) {
                // Exit if invalid
                if (GeometricNetworkViewModel.Default.Dataset == null) { return; }
                if (GeometricNetworkViewModel.Default.SelectedJunctionRule != null) { return; }

                // Add junction rule
                if (this.DataGridJunctionRules.SelectedCells == null) { return; }
                if (this.DataGridJunctionRules.SelectedCells.Count == 0) { return; }
                DataGridCellInfo ci = this.DataGridJunctionRules.SelectedCells[0];
                object o = ci.Item;
                if (o == null) { return; }

                RuleDataGridColumn rdgc = ci.Column as RuleDataGridColumn;
                if (rdgc == null) { return; }

                ZGeometricNetwork zgn = GeometricNetworkViewModel.Default.Dataset as ZGeometricNetwork;
                if (zgn == null) { return; }

                // Create new rule
                ZSubtype e1 = o.GetType().GetProperty(RuleMatrix.EDGE_SUBTYPE).GetValue(o, null) as ZSubtype;
                ZSubtype j1 = zgn.FindSubtype(rdgc.ColumnName);
                ZJunctionConnectivityRule rule = new ZJunctionConnectivityRule(e1, j1);

                // Add rule to network
                zgn.JunctionRules.Add(rule);

                // Update data source
                o.GetType().GetProperty(rdgc.ColumnName).SetValue(o, rule, null);

                // Refresh display
                GeometricNetworkViewModel.Default.SelectedJunctionRule = (ZJunctionConnectivityRule)rule;
                GeometricNetworkViewModel.Default.JunctionRuleDataSource.Refresh();

                // Focus cell
                DataGridCellInfo cell = new DataGridCellInfo(o, rdgc);
                this.DataGridJunctionRules.CurrentCell = cell;
                this.DataGridJunctionRules.SelectedCells.Clear();
                this.DataGridJunctionRules.SelectedCells.Add(cell);

                // Make document dirty
                GeometricNetworkViewModel.Default.MakeDirty();
            }
            else if (sender == this.ButtonJunctionRemove) {
                // Exit if invalid
                if (GeometricNetworkViewModel.Default.Dataset == null) { return; }
                if (GeometricNetworkViewModel.Default.SelectedJunctionRule == null) { return; }

                // Get selected cell
                if (this.DataGridJunctionRules.SelectedCells == null) { return; }
                if (this.DataGridJunctionRules.SelectedCells.Count == 0) { return; }
                DataGridCellInfo ci = this.DataGridJunctionRules.SelectedCells[0];
                object o = ci.Item;
                if (o == null) { return; }

                // Get selected rule
                RuleDataGridColumn rdgc = ci.Column as RuleDataGridColumn;
                if (rdgc == null) { return; }
                ZRule rule = o.GetType().GetProperty(rdgc.ColumnName).GetValue(o, null) as ZRule;
                if (rule == null) { return; }

                // Update data source
                o.GetType().GetProperty(rdgc.ColumnName).SetValue(o, null, null);

                // Remove from dataset
                ZGeometricNetwork zgn = GeometricNetworkViewModel.Default.Dataset as ZGeometricNetwork;
                if (zgn == null) { return; }
                zgn.JunctionRules.Remove(rule);

                // Refresh display
                GeometricNetworkViewModel.Default.SelectedJunctionRule = (ZJunctionConnectivityRule)rule;
                GeometricNetworkViewModel.Default.JunctionRuleDataSource.Refresh();

                // Focus cell
                DataGridCellInfo cell = new DataGridCellInfo(o, rdgc);
                this.DataGridJunctionRules.CurrentCell = cell;
                this.DataGridJunctionRules.SelectedCells.Clear();
                this.DataGridJunctionRules.SelectedCells.Add(cell);

                // Make document dirty
                GeometricNetworkViewModel.Default.MakeDirty();
            }
        }
Exemple #42
0
        public static IWorkspace promptForConnection(IWorkspace existing)
        {
            // prompt the user
            IEnumGxObject pEnumGx = null;

            IGxDialog pGxDialog = new GxDialogClass();
            pGxDialog.AllowMultiSelect = false;

            if(existing!=null)
            {
                object o = existing.PathName;
                pGxDialog.set_StartingLocation( ref o );
            }

            IGxObjectFilterCollection pFilterCol = (IGxObjectFilterCollection)pGxDialog;

            pFilterCol.RemoveAllFilters();
            pFilterCol.AddFilter(new GxFilterWorkspacesClass(), true);
            pGxDialog.Title = "Connection";
            pGxDialog.DoModalOpen(0, out pEnumGx);

            if(pEnumGx != null)
            {
                IGxObject obj = pEnumGx.Next();
                while (obj != null)
                {
                    // cast to IGxDataset for layers ...
                    IGxDatabase db = (IGxDatabase)obj;
                    if (db.Workspace !=null && db.Workspace is IFeatureWorkspace)
                    {
                        return db.Workspace;
                    }
                    obj = pEnumGx.Next();
                }
            }

            return null;
        }
        public static IGxObject OpenArcFile(IGxObjectFilter objectFilter, string Caption)
        {
            IGxDialog fileChooser = new GxDialogClass();
            IEnumGxObject chosenFiles = null;

            fileChooser.Title = Caption;
            fileChooser.ButtonCaption = "Select";
            fileChooser.AllowMultiSelect = false;
            fileChooser.ObjectFilter = objectFilter;
            fileChooser.DoModalOpen(0, out chosenFiles);

            chosenFiles.Reset();
            return chosenFiles.Next();
        }
        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 btnFeatureDomains_Click(object sender, EventArgs e)
        {
            try
            {
                bool isDomain = false;

                if (sender.Equals(btnFeatureDomains))
                {
                    isDomain = true;
                }

                IGxDialog xmlFileSelectDialog = new GxDialogClass();
                xmlFileSelectDialog.AllowMultiSelect = false;
                if (isDomain)
                {
                    xmlFileSelectDialog.Title = resourceManager.GetString("OSMEditor_OSMPropertyPage_fileselect_title_domain");
                }
                else
                {
                    xmlFileSelectDialog.Title = resourceManager.GetString("OSMEditor_OSMPropertyPage_fileselect_title_feature");

                }
                xmlFileSelectDialog.RememberLocation = true;
                xmlFileSelectDialog.ButtonCaption = resourceManager.GetString("OSMEditor_OSMPropertyPage_fileselect_buttoncaption");

                xmlFileSelectDialog.ObjectFilter = new GxFilterXmlFiles();

                IEnumGxObject selectedConfigurationFile = null;

                if (xmlFileSelectDialog.DoModalOpen(m_editor.Parent.hWnd, out selectedConfigurationFile))
                {
                    if (selectedConfigurationFile == null)
                        return;

                    selectedConfigurationFile.Reset();

                    IGxFile xmlFile = selectedConfigurationFile.Next() as IGxFile;

                    if (xmlFile == null)
                        return;

                    if (isDomain)
                    {
                        txtOSMDomainFileLocation.Text = xmlFile.Path;
                    }
                    else
                    {
                        txtOSMFeaturePropertiesFileLocation.Text = xmlFile.Path;
                    }

                    SetPageDirty(true);
                }
            }
            catch
            {
            }
        }
Exemple #46
0
        private void button6_Click(object sender, EventArgs e)
        {
            IGxDialog dlg = new GxDialogClass();
            IGxObjectFilter filter1 = new GxFilterFeatureClassesClass();
            IGxObjectFilter filter2 = new GxFilterAnnotationFeatureClassesClass();
            IGxObjectFilterCollection filters = dlg as IGxObjectFilterCollection;
            filters.AddFilter(filter1,true);
            filters.AddFilter(filter2,false);
            IEnumGxObject selection ;
            if(dlg.DoModalOpen(this.Handle.ToInt32(), out selection))
            {
                IGxObject gobj = selection.Next();
                if(gobj!=null)
                {
                    this.tbxDataSource.Text = gobj.FullName;
                    m_fcName = gobj.InternalObjectName;
                    this.tbxCacheName.Text = gobj.BaseName;
                }
            }

        }