protected override void OnMouseDown(MouseEventArgs arg)
        {
            ConfigUtil.type = "water";
            string selectFeatures = ConfigUtil.GetConfigValue("Trace_Return_Selection", "false");
            bool   selectEdges;

            if (selectFeatures.ToUpper() == "true".ToUpper() && Control.ModifierKeys == Keys.Control)
            {
                selectEdges = false;
            }
            else if (selectFeatures.ToUpper() == "true".ToUpper())
            {
                selectEdges = true;
            }
            else if (selectFeatures.ToUpper() == "false".ToUpper() && Control.ModifierKeys == Keys.Control)
            {
                selectEdges = true;
            }
            else
            {
                selectEdges = false;
            }

            bool   traceIndeterminate          = ConfigUtil.GetConfigValue("TraceFlow_Interminate", false);
            string ISOsourceFeatureLayerName   = ConfigUtil.GetConfigValue("TraceIsolation_Source_FeatureLayer", "");
            string ISOvalveFeatureLayerName    = ConfigUtil.GetConfigValue("TraceIsolation_Valve_FeatureLayer", "");
            string ISOoperableFieldNameValves  = ConfigUtil.GetConfigValue("TraceIsolation_Operable_Field_Valves", "");
            string ISOoperableFieldNameSources = ConfigUtil.GetConfigValue("TraceIsolation_Operable_Field_Sources", "");

            string[] ISOoperableValues  = ConfigUtil.GetConfigValue("TraceIsolation_Operable_Values", "").Split('|');
            string   ISOvalveAddSQL     = ConfigUtil.GetConfigValue("TraceIsolation_Valve_AddSQL", "");
            double   SnapTol            = ConfigUtil.GetConfigValue("Trace_Click_Point_Tolerence", 5.0);
            string   ClearFlagBeforeIso = ConfigUtil.GetConfigValue("TraceIsolation_ClearFlagsOnClick", "true");

            string closedValveQuery = ConfigUtil.GetConfigValue("TraceIsolation_Valve_ClosedValveQuery", "");

            Globals.RemoveTraceGraphics(((IMxDocument)ArcMap.Application.Document).FocusMap, false);

            Globals.ClearSelected(ArcMap.Application, false);


            if (ClearFlagBeforeIso.ToUpper() == "TRUE")
            {
                Globals.ClearGNFlags(ArcMap.Application, Globals.GNTypes.Flags);
            }


            IPoint point = ArcMap.Document.CurrentLocation;

            IPolyline  mergedLines;
            List <int> procoids;
            bool       addFlagBarScreen = ConfigUtil.GetConfigValue("TraceIsolation_AddResultsAsLayers", "false").ToLower() == "false" ? false : true;

            string returnVal = GeoNetTools.TraceIsolation(new double[] { point.X }, new double[] { point.Y }, ArcMap.Application, ISOsourceFeatureLayerName, ISOvalveFeatureLayerName, ISOoperableFieldNameValves, ISOoperableFieldNameSources,
                                                          SnapTol, true, ISOoperableValues, ISOvalveAddSQL, traceIndeterminate, true, selectEdges, "", "", "", closedValveQuery, null, out mergedLines, out procoids, addFlagBarScreen);

            if (returnVal != null)
            {
                string[] retVals = returnVal.Split('_');

                switch (retVals.Length)
                {
                case 1:
                    MessageBox.Show(retVals[0]);
                    break;

                case 2:
                    MessageBox.Show(retVals[1]);
                    break;

                case 3:
                    break;

                default:
                    break;
                }
            }
            point = null;
            ISelectionEvents selEvents = null;

            selEvents = (ISelectionEvents)((ArcMap.Document as IMxDocument).FocusMap);

            if (selEvents != null)
            {
                selEvents.SelectionChanged();
            }
        }
        //this method is executed when the user wants to zoom to the user-defined object id in textbox 2
        private void btnZoomOID2_Click(object sender, EventArgs e)
        {
            try
            {
                IFeatureLayer pFeatureLayer = null;

                //clear the selected features - in case other layers are selected
                pMap.ClearSelection();

                //get access to the layer associated with the objectid the user wants to zoom to
                for (int i = 0; i < pMap.LayerCount; i++)
                {
                    //check to see if the layer is an event layer (ex: VoterXY)
                    if (pMap.get_Layer(i) is FeatureLayer)
                    {
                        pFeatureLayer = pMap.get_Layer(i) as IFeatureLayer;
                        if (!(pFeatureLayer is IEventSource))
                        {
                            if (pFeatureLayer.Name == cboLayer2.Text)
                            {
                                pFeatureLayer.Visible = true;
                                break;
                            }
                        }
                    }
                }

                IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection;  //QI
                pFeatureSelection.Clear();

                //set up query filter
                IQueryFilter pQueryFilter = new QueryFilter();
                pQueryFilter.WhereClause = "OBJECTID = " + txtOID2.Text;

                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                pFeatureSelection.SelectionChanged();

                //refresh the maps - allow the selection anchor to display
                ISelectionEvents pSelectionEvents = pMap as ISelectionEvents;
                pSelectionEvents.SelectionChanged();

                //zoom to selected features
                UID pUID = new UID();
                pUID.Value = "{AB073B49-DE5E-11D1-AA80-00C04FA37860}";
                clsAgrcArcMapExtension.m_application.Document.CommandBars.Find(pUID).Execute();

                //refresh map
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                pMxDocument.UpdateContents();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Message: " + Environment.NewLine + ex.Message + Environment.NewLine + Environment.NewLine +
                                "Error Source: " + Environment.NewLine + ex.Source + Environment.NewLine + Environment.NewLine +
                                "Error Location:" + Environment.NewLine + ex.StackTrace,
                                "AGRC Custom Tools ArcMap Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Beispiel #3
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            if (Button != 1)
            {
                return;
            }

            //设置点选择容差
            ISelectionEnvironment pSelectEnv = new SelectionEnvironmentClass();
            double Length = ModPublic.ConvertPixelsToMapUnits(m_hookHelper.ActiveView, pSelectEnv.SearchTolerance);

            IPoint               pPoint    = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
            IGeometry            pGeometry = pPoint as IGeometry;
            ITopologicalOperator pTopo     = pGeometry as ITopologicalOperator;
            IGeometry            pBuffer   = pTopo.Buffer(Length);

            //仅与框架别界相交地物会被选取
            pGeometry = m_MapControl.TrackRectangle() as IGeometry;
            bool bjustone = true;

            if (pGeometry != null)
            {
                if (pGeometry.IsEmpty)
                {
                    pGeometry = pBuffer;
                }
                else
                {
                    bjustone = false;
                }
            }
            else
            {
                pGeometry = pBuffer;
            }

            UID pUID = new UIDClass();

            pUID.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}";   //UID for IFeatureLayer
            IEnumLayer pEnumLayer = m_MapControl.Map.get_Layers(pUID, true);

            pEnumLayer.Reset();
            ILayer pLayer = pEnumLayer.Next();

            while (pLayer != null)
            {
                if (pLayer.Visible == false)
                {
                    pLayer = pEnumLayer.Next();
                    continue;
                }
                IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
                if (pFeatureLayer.Selectable == false)
                {
                    pLayer = pEnumLayer.Next();
                    continue;
                }

                GetSelctionSet(pFeatureLayer, pGeometry, bjustone, Shift);

                pLayer = pEnumLayer.Next();
            }

            //触发Map选择发生变化事件
            ISelectionEvents pSelectionEvents = m_hookHelper.FocusMap as ISelectionEvents;

            pSelectionEvents.SelectionChanged();

            //刷新
            m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, m_hookHelper.ActiveView.Extent);
            AttributeShow();
        }
        protected override void OnClick()
        {
            IEditor          m_pEd  = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor");
            ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension");

            if (m_pEd.EditState == esriEditState.esriStateNotEditing)
            {
                MessageBox.Show("Please start editing first, and try again.", "Start Editing", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            IArray           PolygonLyrArr;
            IMap             pMap       = m_pEd.Map;
            ICadastralFabric pCadFabric = null;

            //if we're in an edit session then grab the target fabric
            if (m_pEd.EditState == esriEditState.esriStateEditing)
            {
                pCadFabric = pCadEd.CadastralFabric;
            }

            if (pCadFabric == null)
            {//find the first fabric in the map
                MessageBox.Show
                    ("No Parcel Fabric found in the workspace you're editing.\r\nPlease re-start editing on a workspace with a fabric, and try again.",
                    "No Fabric found", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            Utilities Utils = new Utilities();

            if (!Utils.GetFabricSubLayers(pMap, esriCadastralFabricTable.esriCFTParcels, out PolygonLyrArr))
            {
                return;
            }
            //check if there is a Manual Mode "modify" job active ===========
            ICadastralPacketManager pCadPacMan = (ICadastralPacketManager)pCadEd;

            if (pCadPacMan.PacketOpen)
            {
                MessageBox.Show("The Area Calculation does not work when the parcel is open.\r\nPlease close the parcel and try again.",
                                "Calculate Stated Area", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            IActiveView pActiveView = ArcMap.Document.ActiveView;

            CalcStatedAreaDLG CalcStatedArea = new CalcStatedAreaDLG();
            bool             bIsFileBasedGDB = false; bool bIsUnVersioned = false; bool bUseNonVersionedEdit = false;
            IWorkspace       pWS               = null;
            ITable           pParcelsTable     = null;
            IProgressDialog2 pProgressorDialog = null;
            IMouseCursor     pMouseCursor      = new MouseCursorClass();

            pMouseCursor.SetCursor(2);
            var pTool = ArcMap.Application.CurrentTool;

            try
            {
                IFeatureLayer pFL = (IFeatureLayer)PolygonLyrArr.get_Element(0);
                IDataset      pDS = (IDataset)pFL.FeatureClass;
                pWS = pDS.Workspace;

                if (!Utils.SetupEditEnvironment(pWS, pCadFabric, m_pEd, out bIsFileBasedGDB,
                                                out bIsUnVersioned, out bUseNonVersionedEdit))
                {
                    return;
                }

                ICadastralSelection pCadaSel       = (ICadastralSelection)pCadEd;
                IEnumGSParcels      pEnumGSParcels = pCadaSel.SelectedParcels;// need to get the parcels before trying to get the parcel count: BUG workaround
                IFeatureSelection   pFeatSel       = (IFeatureSelection)pFL;
                ISelectionSet2      pSelSet        = (ISelectionSet2)pFeatSel.SelectionSet;

                if (pCadaSel.SelectedParcelCount == 0 && pSelSet.Count == 0)
                {
                    MessageBox.Show("Please select some fabric parcels and try again.", "No Selection",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                ArcMap.Application.CurrentTool = null;

                //Display the dialog
                DialogResult pDialogResult = CalcStatedArea.ShowDialog();
                if (pDialogResult != DialogResult.OK)
                {
                    return;
                }

                m_bShowProgressor = (pSelSet.Count > 10) || pCadaSel.SelectedParcelCount > 10;
                if (m_bShowProgressor)
                {
                    m_pProgressorDialogFact     = new ProgressDialogFactoryClass();
                    m_pTrackCancel              = new CancelTrackerClass();
                    m_pStepProgressor           = m_pProgressorDialogFact.Create(m_pTrackCancel, ArcMap.Application.hWnd);
                    pProgressorDialog           = (IProgressDialog2)m_pStepProgressor;
                    m_pStepProgressor.MinRange  = 1;
                    m_pStepProgressor.MaxRange  = pCadaSel.SelectedParcelCount * 3; //(3 runs through the selection)
                    m_pStepProgressor.StepValue = 1;
                    pProgressorDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral;
                }

                m_pQF = new QueryFilterClass();
                string sPref; string sSuff;

                ISQLSyntax pSQLSyntax = (ISQLSyntax)pWS;
                sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix);
                sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix);

                //====== need to do this for all the parcel sublayers in the map that are part of the target fabric
                //pEnumGSParcels should take care of this automatically
                //but need to do this for line sublayer

                if (m_bShowProgressor)
                {
                    pProgressorDialog.ShowDialog();
                    m_pStepProgressor.Message = "Collecting parcel data...";
                }

                //Add the OIDs of all the selected parcels into a new feature IDSet
                int        tokenLimit = 995;
                List <int> oidList    = new List <int>();
                Dictionary <int, string> dict_ParcelSelection2CalculatedArea = new Dictionary <int, string>();

                pParcelsTable = (ITable)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTParcels);

                pEnumGSParcels.Reset();
                IGSParcel pGSParcel = pEnumGSParcels.Next();
                while (pGSParcel != null)
                {
                    //Check if the cancel button was pressed. If so, stop process
                    if (m_bShowProgressor)
                    {
                        if (!m_pTrackCancel.Continue())
                        {
                            break;
                        }
                    }
                    int iDBId = pGSParcel.DatabaseId;
                    if (!oidList.Contains(iDBId))
                    {
                        oidList.Add(iDBId);
                    }

                    Marshal.ReleaseComObject(pGSParcel); //garbage collection
                    pGSParcel = pEnumGSParcels.Next();
                    if (m_bShowProgressor)
                    {
                        if (m_pStepProgressor.Position < m_pStepProgressor.MaxRange)
                        {
                            m_pStepProgressor.Step();
                        }
                    }
                }
                Marshal.ReleaseComObject(pEnumGSParcels); //garbage collection

                if (m_bShowProgressor)
                {
                    if (!m_pTrackCancel.Continue())
                    {
                        return;
                    }
                }


                string sSuffixUnit = CalcStatedArea.txtSuffix.Text;
                int    iAreaPrec   = (int)CalcStatedArea.numDecPlaces.Value;

                double dSqMPerUnit = 1;
                if (CalcStatedArea.cboAreaUnit.FindStringExact("Acres") == CalcStatedArea.cboAreaUnit.SelectedIndex)
                {
                    dSqMPerUnit = 4046.86;
                }

                if (CalcStatedArea.cboAreaUnit.FindStringExact("Hectares") == CalcStatedArea.cboAreaUnit.SelectedIndex)
                {
                    dSqMPerUnit = 10000;
                }

                if (CalcStatedArea.cboAreaUnit.FindStringExact("Square Feet") == CalcStatedArea.cboAreaUnit.SelectedIndex)
                {
                    dSqMPerUnit = 0.09290304;
                }

                if (CalcStatedArea.cboAreaUnit.FindStringExact("Square Feet US") == CalcStatedArea.cboAreaUnit.SelectedIndex)
                {
                    dSqMPerUnit = 0.09290341;
                }

                if (m_bShowProgressor)
                {
                    pProgressorDialog.ShowDialog();
                    m_pStepProgressor.Message = "Computing areas...";
                }
                List <string> sInClauseList0 = null;
                m_pQF = new QueryFilterClass();
                if (oidList.Count() > 0)
                {
                    sInClauseList0 = Utils.InClauseFromOIDsList(oidList, tokenLimit);
                    foreach (string sInClause in sInClauseList0)
                    {
                        m_pQF.WhereClause = pParcelsTable.OIDFieldName + " IN (" + sInClause + ")";
                        CalculateStatedArea(m_pQF, pParcelsTable, pCadEd, m_pEd.Map.SpatialReference, dSqMPerUnit, sSuffixUnit,
                                            iAreaPrec, ref dict_ParcelSelection2CalculatedArea, m_pTrackCancel);

                        if (m_bShowProgressor)
                        {
                            if (!m_pTrackCancel.Continue())
                            {
                                return;
                            }
                        }
                    }
                }
                else
                {
                    return;
                }


                if (m_bShowProgressor)
                {
                    if (!m_pTrackCancel.Continue())
                    {
                        return;
                    }
                }
                #region Create Cadastral Job
                //string sTime = "";
                //if (!bIsUnVersioned && !bIsFileBasedGDB)
                //{
                //  //see if parcel locks can be obtained on the selected parcels. First create a job.
                //  DateTime localNow = DateTime.Now;
                //  sTime = Convert.ToString(localNow);
                //  ICadastralJob pJob = new CadastralJobClass();
                //  pJob.Name = sTime;
                //  pJob.Owner = System.Windows.Forms.SystemInformation.UserName;
                //  pJob.Description = "Interpolate Z values on selected features";
                //  try
                //  {
                //    Int32 jobId = pCadFabric.CreateJob(pJob);
                //  }
                //  catch (COMException ex)
                //  {
                //    if (ex.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_ALREADY_EXISTS)
                //    {
                //      MessageBox.Show("Job named: '" + pJob.Name + "', already exists");
                //    }
                //    else
                //    {
                //      MessageBox.Show(ex.Message);
                //    }
                //    return;
                //  }
                //}
                #endregion

                //ILongArray pTempParcelsLongArray = new LongArrayClass();
                //List<int> lstParcelChanges = Utils.FIDsetToLongArray(m_pFIDSetParcels, ref pTempParcelsLongArray, ref pParcelIds, m_pStepProgressor);

                if (m_pEd.EditState == esriEditState.esriStateEditing)
                {
                    try
                    {
                        m_pEd.StartOperation();
                    }
                    catch
                    {
                        m_pEd.AbortOperation();//abort any open edit operations and try again
                        m_pEd.StartOperation();
                    }
                }
                if (bUseNonVersionedEdit)
                {
                    if (!Utils.StartEditing(pWS, bIsUnVersioned))
                    {
                        return;
                    }
                }

                //ICadastralFabricSchemaEdit2 pSchemaEd = (ICadastralFabricSchemaEdit2)pCadFabric;
                //pSchemaEd.ReleaseReadOnlyFields(pParcelsTable, esriCadastralFabricTable.esriCFTParcels);
                int    idxParcelStatedArea       = pParcelsTable.FindField("STATEDAREA");
                string ParcelStatedAreaFieldName = pParcelsTable.Fields.get_Field(idxParcelStatedArea).Name;
                if (m_bShowProgressor)
                {
                    //  pProgressorDialog.ShowDialog();
                    m_pStepProgressor.Message = "Updating parcel areas...";
                }

                IRow    pTheFeatRow   = null;
                ICursor pUpdateCursor = null;
                foreach (string sInClause in sInClauseList0)
                {
                    m_pQF.WhereClause = pParcelsTable.OIDFieldName + " IN (" + sInClause + ")";

                    if (bUseNonVersionedEdit)
                    {
                        ITableWrite pTableWr = (ITableWrite)pParcelsTable; //used for unversioned table
                        pUpdateCursor = pTableWr.UpdateRows(m_pQF, false);
                    }
                    else
                    {
                        pUpdateCursor = pParcelsTable.Update(m_pQF, false);
                    }

                    pTheFeatRow = pUpdateCursor.NextRow();
                    while (pTheFeatRow != null)
                    {
                        string sAreaString = dict_ParcelSelection2CalculatedArea[pTheFeatRow.OID];
                        pTheFeatRow.set_Value(idxParcelStatedArea, sAreaString);
                        pTheFeatRow.Store();
                        Marshal.ReleaseComObject(pTheFeatRow); //garbage collection
                        if (m_bShowProgressor)
                        {
                            if (!m_pTrackCancel.Continue())
                            {
                                break;
                            }
                        }
                        pTheFeatRow = pUpdateCursor.NextRow();
                    }
                    Marshal.ReleaseComObject(pUpdateCursor); //garbage collection
                    if (m_bShowProgressor)
                    {
                        if (!m_pTrackCancel.Continue())
                        {
                            break;
                        }
                    }
                }
                m_pEd.StopOperation("Calculate Stated Area");
                //pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTParcels);//set fields back to read-only
            }
            catch (Exception ex)
            {
                if (m_pEd != null)
                {
                    AbortEdits(bIsUnVersioned, m_pEd, pWS);
                }
                MessageBox.Show(ex.Message);
            }
            finally
            {
                ArcMap.Application.CurrentTool = pTool;
                m_pStepProgressor = null;
                m_pTrackCancel    = null;
                if (pProgressorDialog != null)
                {
                    pProgressorDialog.HideDialog();
                }

                RefreshMap(pActiveView, PolygonLyrArr);
                ICadastralExtensionManager pCExMan = (ICadastralExtensionManager)pCadEd;
                IParcelPropertiesWindow2   pPropW  = (IParcelPropertiesWindow2)pCExMan.ParcelPropertiesWindow;
                pPropW.RefreshAll();
                //update the TOC
                IMxDocument mxDocument = (ESRI.ArcGIS.ArcMapUI.IMxDocument)(ArcMap.Application.Document);
                for (int i = 0; i < mxDocument.ContentsViewCount; i++)
                {
                    IContentsView pCV = (IContentsView)mxDocument.get_ContentsView(i);
                    pCV.Refresh(null);
                }

                // refresh the attributes dialog
                ISelectionEvents pSelEvents = (ISelectionEvents)m_pEd.Map;
                pSelEvents.SelectionChanged();

                if (bUseNonVersionedEdit)
                {
                    pCadEd.CadastralFabricLayer = null;
                    PolygonLyrArr = null;
                }

                if (pMouseCursor != null)
                {
                    pMouseCursor.SetCursor(0);
                }
            }
        }