public CollapseAllLayers() { _application = this.Hook as IApplication; _mxdocument = (IMxDocument)_application.Document; _map = _mxdocument.FocusMap; _activeView = _mxdocument.ActivatedView; _contentsView = _mxdocument.get_ContentsView(0); // The TOC }
// ========================================================================= // Event handlers // ========================================================================= private void OnContentChanged() { foreach (var layer in AllLayers) { if (!Layers.Aggregate(false, (current, visLayer) => current || (visLayer == layer))) { layer.IsVisible = true; layer.Visible = false; } } CycloMediaLayer changedLayer = Layers.Aggregate <CycloMediaLayer, CycloMediaLayer> (null, (current, layer) => (layer.IsVisible && (!layer.Visible)) ? layer : current); CycloMediaLayer refreshLayer = null; foreach (var layer in Layers) { bool visible = ((changedLayer == null) || (layer == changedLayer)) && layer.IsVisible; refreshLayer = (layer.IsVisible != visible) ? layer : refreshLayer; layer.IsVisible = visible; layer.Visible = layer.IsVisible; } if (refreshLayer != null) { IMxDocument document = ArcUtils.MxDocument; IActiveView activeView = ArcUtils.ActiveView; if (document != null) { // ReSharper disable UseIndexedProperty IContentsView contentView = document.get_ContentsView(0); // ReSharper restore UseIndexedProperty if (contentView != null) { contentView.Refresh(_groupLayer); } } if (activeView != null) { activeView.Refresh(); } } }
protected override void OnClick() { bool bShowProgressor = false; IStepProgressor pStepProgressor = null; //Create a CancelTracker. ITrackCancel pTrackCancel = null; IProgressDialogFactory pProgressorDialogFact; IMouseCursor pMouseCursor = new MouseCursorClass(); pMouseCursor.SetCursor(2); //first get the selected parcel features UID pUID = new UIDClass(); pUID.Value = "{114D685F-99B7-4B63-B09F-6D1A41A4DDC1}"; ICadastralExtensionManager2 pCadExtMan = (ICadastralExtensionManager2)ArcMap.Application.FindExtensionByCLSID(pUID); ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByCLSID(pUID); //check if there is a Manual Mode "modify" job active =========== ICadastralPacketManager pCadPacMan = (ICadastralPacketManager)pCadExtMan; if (pCadPacMan.PacketOpen) { MessageBox.Show("The Delete Control command cannot be used when there is an open job.\r\nPlease finish or discard the open job, and try again.", "Delete Selected Control"); return; } IEditor pEd = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor"); IActiveView pActiveView = ArcMap.Document.ActiveView; IMap pMap = pActiveView.FocusMap; ICadastralFabric pCadFabric = null; clsFabricUtils FabricUTILS = new clsFabricUtils(); IProgressDialog2 pProgressorDialog = null; //if we're in an edit session then grab the target fabric if (pEd.EditState == esriEditState.esriStateEditing) { pCadFabric = pCadEd.CadastralFabric; } if (pCadFabric == null) {//find the first fabric in the map if (!FabricUTILS.GetFabricFromMap(pMap, out pCadFabric)) { MessageBox.Show ("No Parcel Fabric found in the map.\r\nPlease add a single fabric to the map, and try again."); return; } } IArray CFControlLayers = new ArrayClass(); if (!(FabricUTILS.GetControlLayersFromFabric(pMap, pCadFabric, out CFControlLayers))) { return; //no fabric sublayers available for the targeted fabric } bool bIsFileBasedGDB = false; bool bIsUnVersioned = false; bool bUseNonVersionedDelete = false; IWorkspace pWS = null; ITable pPointsTable = null; ITable pControlTable = null; try { if (pEd.EditState == esriEditState.esriStateEditing) { try { pEd.StartOperation(); } catch { pEd.AbortOperation();//abort any open edit operations and try again pEd.StartOperation(); } } IFeatureLayer pFL = (IFeatureLayer)CFControlLayers.get_Element(0); IDataset pDS = (IDataset)pFL.FeatureClass; pWS = pDS.Workspace; if (!FabricUTILS.SetupEditEnvironment(pWS, pCadFabric, pEd, out bIsFileBasedGDB, out bIsUnVersioned, out bUseNonVersionedDelete)) { return; } //loop through each control layer and //Get the selection of control int iCnt = 0; int iTotalSelectionCount = 0; for (; iCnt < CFControlLayers.Count; iCnt++) { pFL = (IFeatureLayer)CFControlLayers.get_Element(iCnt); IFeatureSelection pFeatSel = (IFeatureSelection)pFL; ISelectionSet2 pSelSet = (ISelectionSet2)pFeatSel.SelectionSet; iTotalSelectionCount += pSelSet.Count; } if (iTotalSelectionCount == 0) { MessageBox.Show("Please select some fabric control points and try again.", "No Selection", MessageBoxButtons.OK, MessageBoxIcon.Information); if (bUseNonVersionedDelete) { pCadEd.CadastralFabricLayer = null; CFControlLayers = null; } return; } bShowProgressor = (iTotalSelectionCount > 10); if (bShowProgressor) { pProgressorDialogFact = new ProgressDialogFactoryClass(); pTrackCancel = new CancelTrackerClass(); pStepProgressor = pProgressorDialogFact.Create(pTrackCancel, ArcMap.Application.hWnd); pProgressorDialog = (IProgressDialog2)pStepProgressor; pStepProgressor.MinRange = 1; pStepProgressor.MaxRange = iTotalSelectionCount * 2; //(runs through selection twice) pStepProgressor.StepValue = 1; pProgressorDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral; } //loop through each control layer and //delete from its selection m_pQF = new QueryFilterClass(); iCnt = 0; for (; iCnt < CFControlLayers.Count; iCnt++) { pFL = (IFeatureLayer)CFControlLayers.get_Element(iCnt); IFeatureSelection pFeatSel = (IFeatureSelection)pFL; ISelectionSet2 pSelSet = (ISelectionSet2)pFeatSel.SelectionSet; ISQLSyntax pSQLSyntax = (ISQLSyntax)pWS; string sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); string sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix); if (bShowProgressor) { pProgressorDialog.ShowDialog(); pStepProgressor.Message = "Collecting Control point data..."; } //Add the OIDs of all the selected control points into a new feature IDSet string[] sOIDListPoints = { "(" }; int tokenLimit = 995; //int tokenLimit = 5; //temp for testing bool bCont = true; int j = 0; int iCounter = 0; m_pFIDSetControl = new FIDSetClass(); ICursor pCursor = null; pSelSet.Search(null, false, out pCursor);//code deletes all selected control points IFeatureCursor pControlFeatCurs = (IFeatureCursor)pCursor; IFeature pControlFeat = pControlFeatCurs.NextFeature(); int iPointID = pControlFeatCurs.FindField("POINTID"); while (pControlFeat != null) { //Check if the cancel button was pressed. If so, stop process if (bShowProgressor) { bCont = pTrackCancel.Continue(); if (!bCont) { break; } } bool bExists = false; m_pFIDSetControl.Find(pControlFeat.OID, out bExists); if (!bExists) { m_pFIDSetControl.Add(pControlFeat.OID); object obj = pControlFeat.get_Value(iPointID); if (iCounter <= tokenLimit) { //if the PointID is not null add it to a query string as well if (obj != DBNull.Value) { sOIDListPoints[j] += Convert.ToString(obj) + ","; } iCounter++; } else {//maximum tokens reached //set up the next OIDList sOIDListPoints[j] = sOIDListPoints[j].Trim(); iCounter = 0; j++; FabricUTILS.RedimPreserveString(ref sOIDListPoints, 1); sOIDListPoints[j] = "("; if (obj != DBNull.Value) { sOIDListPoints[j] += Convert.ToString(obj) + ","; } } } Marshal.ReleaseComObject(pControlFeat); //garbage collection pControlFeat = pControlFeatCurs.NextFeature(); if (bShowProgressor) { if (pStepProgressor.Position < pStepProgressor.MaxRange) { pStepProgressor.Step(); } } } Marshal.ReleaseComObject(pCursor); //garbage collection if (!bCont) { AbortEdits(bUseNonVersionedDelete, pEd, pWS); return; } if (bUseNonVersionedDelete) { if (!FabricUTILS.StartEditing(pWS, bIsUnVersioned)) { if (bUseNonVersionedDelete) { pCadEd.CadastralFabricLayer = null; } return; } } //first delete all the control point records if (bShowProgressor) { pStepProgressor.Message = "Deleting control points..."; } bool bSuccess = true; pPointsTable = (ITable)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTPoints); pControlTable = (ITable)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTControl); if (!bUseNonVersionedDelete) { bSuccess = FabricUTILS.DeleteRowsByFIDSet(pControlTable, m_pFIDSetControl, pStepProgressor, pTrackCancel); } if (bUseNonVersionedDelete) { bSuccess = FabricUTILS.DeleteRowsUnversioned(pWS, pControlTable, m_pFIDSetControl, pStepProgressor, pTrackCancel); } if (!bSuccess) { AbortEdits(bUseNonVersionedDelete, pEd, pWS); return; } //next need to use an in clause to update the points, ... ICadastralFabricSchemaEdit2 pSchemaEd = (ICadastralFabricSchemaEdit2)pCadFabric; //...for each item in the sOIDListPoints array foreach (string inClause in sOIDListPoints) { string sClause = inClause.Trim().TrimEnd(','); if (sClause.EndsWith("(")) { continue; } if (sClause.Length < 3) { continue; } pSchemaEd.ReleaseReadOnlyFields(pPointsTable, esriCadastralFabricTable.esriCFTPoints); m_pQF.WhereClause = (sPref + pPointsTable.OIDFieldName + sSuff).Trim() + " IN " + sClause + ")"; if (!FabricUTILS.ResetPointAssociations(pPointsTable, m_pQF, bIsUnVersioned)) { pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTPoints); return; } pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTPoints); } } if (bUseNonVersionedDelete) { FabricUTILS.StopEditing(pWS); } if (pEd.EditState == esriEditState.esriStateEditing) { pEd.StopOperation("Delete Control Points"); } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } finally { RefreshMap(pActiveView, CFControlLayers); //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); } if (pProgressorDialog != null) { pProgressorDialog.HideDialog(); } if (bUseNonVersionedDelete) { pCadEd.CadastralFabricLayer = null; CFControlLayers = null; } if (pMouseCursor != null) { pMouseCursor.SetCursor(0); } } }
protected override void OnClick() { //first check that we are currently editing if (ArcMap.Editor.EditState != esriEditState.esriStateEditing) { MessageBox.Show("Please start editing and try again.", "Sample Code"); return; } //get the cadastral editor ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByName("esriCadastralUI.CadastralEditorExtension"); //get the fabric line layers that belong to the target fabric. // **SAMPLE CODE NOTE** //This next function allows for more than 1 fabric lines sublayer in the map document, and uses a line layer array //However, this sample code assumes just one line fabric sub layer, and works with the first found //The function is provided for other expanded uses if needed elsewhere. IArray LineLayerArray; if (!GetFabricSubLayers(ArcMap.Document.ActiveView.FocusMap, esriCadastralFabricTable.esriCFTLines, true, pCadEd.CadastralFabric, out LineLayerArray)) { return; } // get the line selection; this code sample uses first line layer for the target fabric (first element) ISelectionSet2 LineSelection = GetSelectionFromLayer(LineLayerArray.get_Element(0) as ICadastralFabricSubLayer); // check to see if there is only one parcel line selected // **SAMPLE CODE NOTE** //This sample code ensures one line feature, although it can be easily adapted for use on //multiple line selection. if (LineSelection.Count != 1) { MessageBox.Show("Please select only one parcel line from the Target fabric.", "Sample Code"); return; } //Get a search cursor from the line selection to get the parcel id //We need to get an edit lock on the parcel using the parcel id //An edit lock will guarantee the edit will persist in a multi-user environment after a reconcile ILongArray pParcelsToLock = new LongArrayClass(); IFIDSet pFIDSetForParcelRegen = new FIDSet(); ICursor pCur; LineSelection.Search(null, false, out pCur); //this cursor returns the selected lines // **SAMPLE CODE NOTE** //setup for potential use for multiple line selection, even though this sample uses a single line selection //get the field indices for line attributes needed. int idxParcelID = pCur.FindField("parcelid"); int idxToPointID = pCur.FindField("topointid"); int idxFromPointID = pCur.FindField("frompointid"); int idxCenterPtId = pCur.FindField("centerpointid"); int idxDistance = pCur.FindField("distance"); int idxRadius = pCur.FindField("radius"); int idxCategory = pCur.FindField("category"); //also need the fabric point table and fields IFeatureClass pFabricPointsFC = (IFeatureClass)pCadEd.CadastralFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTPoints); int idxPointX = pFabricPointsFC.FindField("x"); int idxPointY = pFabricPointsFC.FindField("y"); int idxPointCtrPt = pFabricPointsFC.FindField("centerpoint"); var ListFromToPairsForRadialLines = new List <int[]>(); // **SAMPLE CODE NOTE** //setup for potential use for multiple line selection, even though this sample uses a single line selection //the list declared above is here for potential use in Add-ins that make use of multiple circular arc lines int[] ParcelIdCtrPtIdFromId1FromId2; IRow pRow = pCur.NextRow(); while (pRow != null) { int iParcelID = (int)pRow.get_Value(idxParcelID); pParcelsToLock.Add(iParcelID); //LongArray for the parcel locks pFIDSetForParcelRegen.Add(iParcelID); //FIDSet for the parcel regenerate //now check for a center point id on the line; this is for the case of changing the radius of an existing curve object value = pRow.get_Value(idxCenterPtId); if (value != DBNull.Value) { //collecting information to remove radial lines ParcelIdCtrPtIdFromId1FromId2 = new int[4]; // 4-element array ParcelIdCtrPtIdFromId1FromId2[0] = iParcelID; ParcelIdCtrPtIdFromId1FromId2[1] = (int)value; //center point is always the to point of the radial line ParcelIdCtrPtIdFromId1FromId2[2] = (int)pRow.get_Value(idxFromPointID); ParcelIdCtrPtIdFromId1FromId2[3] = (int)pRow.get_Value(idxToPointID); // **SAMPLE CODE NOTE** //now add the array, to the list to accomodate other add-ins that may use //more than one selected circular arc line ListFromToPairsForRadialLines.Add(ParcelIdCtrPtIdFromId1FromId2); } Marshal.ReleaseComObject(pRow); pRow = pCur.NextRow(); } Marshal.ReleaseComObject(pCur); bool IsFileBasedGDB = (ArcMap.Editor.EditWorkspace.WorkspaceFactory.WorkspaceType != esriWorkspaceType.esriRemoteDatabaseWorkspace); if (!IsFileBasedGDB) { //for file geodatabase creating a job is optional //see if parcel locks can be obtained on the selected parcels. First create a job. string NewJobName = ""; if (!CreateJob(pCadEd.CadastralFabric, "Sample Code change line to curve", out NewJobName)) { return; } if (!TestForEditLocks(pCadEd.CadastralFabric, NewJobName, pParcelsToLock)) { return; } } //if we get this far, an edit lock has been acquired, or this is file geodatabase (no lock required) //prompt the user for a new radius value string sRadius = Interaction.InputBox("Enter a new Radius:", "Radius"); //**SAMPLE CODE NOTE** : // using the Interaction class from the Microsfot Visual Basic library // is a quick and easy way to provide an input dialog in a single line of code for sample purposes, // without neeing to add a windows form, dockable window, or other UI elements into this project. double dRadius = 0; if (!Double.TryParse(sRadius, out dRadius)) { return; } //we have a valid double value, so we can get ready to edit IProgressDialogFactory pProgressorDialogFact = new ProgressDialogFactoryClass(); ITrackCancel pTrackCancel = new CancelTracker(); IStepProgressor pStepProgressor = pProgressorDialogFact.Create(pTrackCancel, ArcMap.Application.hWnd); IProgressDialog2 pProgressorDialog = (IProgressDialog2)pStepProgressor; ICadastralFabricSchemaEdit2 pSchemaEd = (ICadastralFabricSchemaEdit2)pCadEd.CadastralFabric; try { //turn off the read-only flag on the lines table and points table pSchemaEd.ReleaseReadOnlyFields(LineSelection.Target, esriCadastralFabricTable.esriCFTLines); //release read-only pSchemaEd.ReleaseReadOnlyFields((ITable)pFabricPointsFC, esriCadastralFabricTable.esriCFTPoints); //release read-only //start an edit operation ArcMap.Editor.StartOperation(); //get an update cursor to make the edit on the line(s) LineSelection.Update(null, false, out pCur); pRow = pCur.NextRow(); int iChangeCount = 0; while (pRow != null) { double dChord = (double)pRow.get_Value(idxDistance); if (Math.Abs(dRadius) <= dChord / 2 && dRadius != 0) //minimum allowable radius is half the chord { Marshal.ReleaseComObject(pRow); pRow = pCur.NextRow(); continue; } //compute a center point location from new radius, unless it's 0 int iNewCtrPtId = 0; if (dRadius != 0) { IFeature pFeat = pRow as IFeature; IPoint pCtrPt = ComputeCenterPointFromRadius(pFeat.Shape as IPolyline, dRadius, true); IFeature pNewPointFeat = pFabricPointsFC.CreateFeature(); //**SAMPLE CODE NOTE** : //if adding a large number of points (more than 20) then createfeature is not the fastest approach, //Instead you would pre-allocate points using an insert cursor... //At this point in the code, the normal geodatabase performance considerations apply iNewCtrPtId = pNewPointFeat.OID; pNewPointFeat.set_Value(idxPointX, pCtrPt.X); pNewPointFeat.set_Value(idxPointY, pCtrPt.Y); pNewPointFeat.set_Value(idxPointCtrPt, 1); //1 = true boolean pNewPointFeat.Shape = pCtrPt; pNewPointFeat.Store(); } //get the initial radius if the line is a curve (radius is being updated) object obj = pRow.get_Value(idxRadius); bool bIsChangingFromCurve = (obj != DBNull.Value); //there is a radius value obj = pRow.get_Value(idxCenterPtId); bIsChangingFromCurve = bIsChangingFromCurve && (obj != DBNull.Value); //radius value and Ctr Pt ID exist int iExistingCtrPtId = 0; if (bIsChangingFromCurve) { iExistingCtrPtId = (int)obj; } if (dRadius == 0) //user entered value is zero meaning convert to straight line { //changing to a straight line so set the center point an radius to null pRow.set_Value(idxRadius, DBNull.Value); pRow.set_Value(idxCenterPtId, DBNull.Value); } else if (!bIsChangingFromCurve) //user entered a new radius, and the existing line is not a curve { //changing to a circular arc so set the radius, and set the center point id to the new point's OID pRow.set_Value(idxRadius, dRadius); pRow.set_Value(idxCenterPtId, iNewCtrPtId); } else if (bIsChangingFromCurve) //user entered a radius, and the existing line is a curve { pCur.UpdateRow(pRow); } iChangeCount++; Marshal.ReleaseComObject(pRow); pRow = pCur.NextRow(); } Marshal.ReleaseComObject(pCur); if (iChangeCount == 0) {//if there are no changes then don't add to the edit operation stack ArcMap.Editor.AbortOperation(); return; } if (ListFromToPairsForRadialLines.Count > 0) { IQueryFilter pQuFilter = new QueryFilter(); string sCat = LineSelection.Target.Fields.get_Field(idxCategory).Name; string sToPt = LineSelection.Target.Fields.get_Field(idxToPointID).Name; string sFromPt = LineSelection.Target.Fields.get_Field(idxFromPointID).Name; string sParcelID = LineSelection.Target.Fields.get_Field(idxParcelID).Name; string sInClauseToPts = "("; string sInClauseFromPts = "("; string sInClauseParcelIds = "("; //**SAMPLE CODE NOTE** : //The following In Clause, when contructed for production environments //should take into account the token limit on Oracle database platforms. (<1000) // the processing of the in clause should be broekn into blocks with the in cluase has no more than 1000 elements foreach (int[] iParcelIdCtrPtIdFromId1FromId2 in ListFromToPairsForRadialLines) { if (sInClauseParcelIds.Length == 1) { sInClauseParcelIds += iParcelIdCtrPtIdFromId1FromId2[0].ToString(); } else { sInClauseParcelIds += "," + iParcelIdCtrPtIdFromId1FromId2[0].ToString(); } if (sInClauseToPts.Length == 1) { sInClauseToPts += iParcelIdCtrPtIdFromId1FromId2[1].ToString(); } else { sInClauseToPts += "," + iParcelIdCtrPtIdFromId1FromId2[1].ToString(); } if (sInClauseFromPts.Length == 1) { sInClauseFromPts += iParcelIdCtrPtIdFromId1FromId2[2].ToString(); sInClauseFromPts += "," + iParcelIdCtrPtIdFromId1FromId2[3].ToString(); } else { sInClauseFromPts += "," + iParcelIdCtrPtIdFromId1FromId2[2].ToString(); sInClauseFromPts += "," + iParcelIdCtrPtIdFromId1FromId2[2].ToString(); } } pQuFilter.WhereClause = sCat + " = 4 AND " + sParcelID + " IN " + sInClauseParcelIds + ") AND " + sFromPt + " IN " + sInClauseFromPts + ") AND " + sToPt + " IN " + sInClauseToPts + ")"; LineSelection.Target.DeleteSearchedRows(pQuFilter); } //with the new information added to the line, the rest of the parcel needs to be updated //regenerate the parcel using the parcel fidset ICadastralFabricRegeneration pRegenFabric = new CadastralFabricRegenerator(); #region regenerator enum // enum esriCadastralRegeneratorSetting // esriCadastralRegenRegenerateGeometries = 1 // esriCadastralRegenRegenerateMissingRadials = 2, // esriCadastralRegenRegenerateMissingPoints = 4, // esriCadastralRegenRemoveOrphanPoints = 8, // esriCadastralRegenRemoveInvalidLinePoints = 16, // esriCadastralRegenSnapLinePoints = 32, // esriCadastralRegenRepairLineSequencing = 64, // esriCadastralRegenRepairPartConnectors = 128 // By default, the bitmask member is 0 which will only regenerate geometries. // (equivalent to passing in regeneratorBitmask = 1) #endregion pRegenFabric.CadastralFabric = pCadEd.CadastralFabric; pRegenFabric.RegeneratorBitmask = 7; pRegenFabric.RegenerateParcels(pFIDSetForParcelRegen, false, pTrackCancel); //15 (enum values of 8 means remove orphan points; this only works when doing entire fabric) //TODO: remove orphaned center points programmatically pStepProgressor.MinRange = 0; pStepProgressor.MaxRange = iChangeCount; pStepProgressor.StepValue = 1; pProgressorDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral; pRegenFabric.RegenerateParcels(pFIDSetForParcelRegen, false, pTrackCancel); ArcMap.Editor.StopOperation("Change line radius"); } catch (Exception ex) { ArcMap.Editor.AbortOperation(); MessageBox.Show(ex.Message); } finally { if (pSchemaEd != null) { pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTPoints); pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTLines); } pStepProgressor = null; if (!(pProgressorDialog == null)) { pProgressorDialog.HideDialog(); } pProgressorDialog = null; RefreshMap(LineLayerArray); 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); } } }
protected override void OnClick() { IMouseCursor pMouseCursor = new MouseCursorClass(); pMouseCursor.SetCursor(2); //first get the selected parcel features UID pUID = new UIDClass(); pUID.Value = "{114D685F-99B7-4B63-B09F-6D1A41A4DDC1}"; ICadastralExtensionManager2 pCadExtMan = (ICadastralExtensionManager2)ArcMap.Application.FindExtensionByCLSID(pUID); ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByCLSID(pUID); //check if there is a Manual Mode "modify" job active =========== ICadastralPacketManager pCadPacMan = (ICadastralPacketManager)pCadExtMan; if (pCadPacMan.PacketOpen) { MessageBox.Show("The Delete Parcels command cannot be used when there is an open job.\r\nPlease finish or discard the open job, and try again.", "Delete Selected Parcels"); return; } IEditor pEd = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor"); IActiveView pActiveView = ArcMap.Document.ActiveView; IMap pMap = pActiveView.FocusMap; ICadastralFabric pCadFabric = null; clsFabricUtils FabricUTILS = new clsFabricUtils(); IProgressDialog2 pProgressorDialog = null; //if we're in an edit session then grab the target fabric if (pEd.EditState == esriEditState.esriStateEditing) { pCadFabric = pCadEd.CadastralFabric; } if (pCadFabric == null) {//find the first fabric in the map if (!FabricUTILS.GetFabricFromMap(pMap, out pCadFabric)) { MessageBox.Show ("No Parcel Fabric found in the map.\r\nPlease add a single fabric to the map, and try again."); return; } } IArray CFParcelLayers = new ArrayClass(); if (!(FabricUTILS.GetFabricSubLayersFromFabric(pMap, pCadFabric, out CFPointLayer, out CFLineLayer, out CFParcelLayers, out CFControlLayer, out CFLinePointLayer))) { return; //no fabric sublayers available for the targeted fabric } bool bIsFileBasedGDB = false; bool bIsUnVersioned = false; bool bUseNonVersionedDelete = false; IWorkspace pWS = null; ICadastralFabricLayer pCFLayer = null; ITable pParcelsTable = null; ITable pLinesTable = null; ITable pLinePtsTable = null; ITable pPointsTable = null; ITable pControlTable = null; try { //Get the selection of parcels IFeatureLayer pFL = (IFeatureLayer)CFParcelLayers.get_Element(0); IDataset pDS = (IDataset)pFL.FeatureClass; pWS = pDS.Workspace; if (!FabricUTILS.SetupEditEnvironment(pWS, pCadFabric, pEd, out bIsFileBasedGDB, out bIsUnVersioned, out bUseNonVersionedDelete)) { return; } if (bUseNonVersionedDelete) { pCFLayer = new CadastralFabricLayerClass(); pCFLayer.CadastralFabric = pCadFabric; pCadEd.CadastralFabricLayer = pCFLayer;//NOTE: Need to set this back to NULL when done. } 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; bMoreThan995UnjoinedParcels = (pSelSet.Count > pCadaSel.SelectedParcelCount); //used for bug workaround if (pCadaSel.SelectedParcelCount == 0 && pSelSet.Count == 0) { MessageBox.Show("Please select some fabric parcels and try again.", "No Selection", MessageBoxButtons.OK, MessageBoxIcon.Information); pMouseCursor.SetCursor(0); if (bUseNonVersionedDelete) { pCadEd.CadastralFabricLayer = null; CFParcelLayers = null; CFPointLayer = null; CFLineLayer = null; CFControlLayer = null; CFLinePointLayer = null; } return; } if (bMoreThan995UnjoinedParcels) { m_bShowProgressor = (pSelSet.Count > 10); } else { m_bShowProgressor = (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; if (bMoreThan995UnjoinedParcels) { m_pStepProgressor.MaxRange = pSelSet.Count * 18; //(estimate 7 lines per parcel, 4 pts per parcel, 3 line points per parcel, and there is a second loop on parcel list) } else { m_pStepProgressor.MaxRange = pCadaSel.SelectedParcelCount * 18; //(estimate 7 lines per parcel, 4 pts per parcel, 3 line points per parcel, and there is a second loop on parcel list) } 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 if (m_bShowProgressor) { pProgressorDialog.ShowDialog(); m_pStepProgressor.Message = "Collecting parcel data..."; } //Add the OIDs of all the selected parcels into a new feature IDSet string[] sOIDList = { "(" }; int tokenLimit = 995; bool bCont = true; int j = 0; int iCounter = 0; m_pFIDSetParcels = new FIDSetClass(); //===================== start bug workaraound for 10.0 client =================== if (bMoreThan995UnjoinedParcels) { ICursor pCursor = null; pSelSet.Search(null, false, out pCursor);//code deletes all selected parcels IFeatureCursor pParcelFeatCurs = (IFeatureCursor)pCursor; IFeature pParcFeat = pParcelFeatCurs.NextFeature(); while (pParcFeat != null) { //Check if the cancel button was pressed. If so, stop process if (m_bShowProgressor) { bCont = m_pTrackCancel.Continue(); if (!bCont) { break; } } bool bExists = false; m_pFIDSetParcels.Find(pParcFeat.OID, out bExists); if (!bExists) { m_pFIDSetParcels.Add(pParcFeat.OID); if (iCounter <= tokenLimit) { sOIDList[j] = sOIDList[j] + Convert.ToString(pParcFeat.OID) + ","; iCounter++; } else {//maximum tokens reached sOIDList[j] = sOIDList[j].Trim(); iCounter = 0; //set up the next OIDList j++; FabricUTILS.RedimPreserveString(ref sOIDList, 1); sOIDList[j] = "("; sOIDList[j] = sOIDList[j] + Convert.ToString(pParcFeat.OID) + ","; } } Marshal.ReleaseComObject(pParcFeat); //garbage collection pParcFeat = pParcelFeatCurs.NextFeature(); if (m_bShowProgressor) { if (m_pStepProgressor.Position < m_pStepProgressor.MaxRange) { m_pStepProgressor.Step(); } } } Marshal.ReleaseComObject(pCursor); //garbage collection //===================== end bug workaraound for 10.0 client =================== } else //===the following code path is preferred====== { pEnumGSParcels.Reset(); IGSParcel pGSParcel = pEnumGSParcels.Next(); while (pGSParcel != null) { //Check if the cancel button was pressed. If so, stop process if (m_bShowProgressor) { bCont = m_pTrackCancel.Continue(); if (!bCont) { break; } } m_pFIDSetParcels.Add(pGSParcel.DatabaseId); if (iCounter <= tokenLimit) { sOIDList[j] = sOIDList[j] + Convert.ToString(pGSParcel.DatabaseId) + ","; iCounter++; } else {//maximum tokens reached sOIDList[j] = sOIDList[j].Trim(); iCounter = 0; //set up the next OIDList j++; FabricUTILS.RedimPreserveString(ref sOIDList, 1); sOIDList[j] = "("; sOIDList[j] = sOIDList[j] + Convert.ToString(pGSParcel.DatabaseId) + ","; } 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 (!bCont) { AbortEdits(bUseNonVersionedDelete, pEd, pWS); return; } 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 = "Delete selected parcels"; 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; } } //if we're in an enterprise then test for edit locks ICadastralFabricLocks pFabLocks = (ICadastralFabricLocks)pCadFabric; if (!bIsUnVersioned && !bIsFileBasedGDB) { pFabLocks.LockingJob = sTime; ILongArray pLocksInConflict = null; ILongArray pSoftLcksInConflict = null; ILongArray pParcelsToLock = new LongArrayClass(); FabricUTILS.FIDsetToLongArray(m_pFIDSetParcels, ref pParcelsToLock, m_pStepProgressor); if (m_bShowProgressor && !bIsFileBasedGDB) { m_pStepProgressor.Message = "Testing for edit locks on parcels..."; } try { pFabLocks.AcquireLocks(pParcelsToLock, true, ref pLocksInConflict, ref pSoftLcksInConflict); } catch (COMException pCOMEx) { if (pCOMEx.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_LOCK_ALREADY_EXISTS || pCOMEx.ErrorCode == (int)fdoError.FDO_E_CADASTRAL_FABRIC_JOB_CURRENTLY_EDITED) { MessageBox.Show("Edit Locks could not be acquired on all selected parcels."); // since the operation is being aborted, release any locks that were acquired pFabLocks.UndoLastAcquiredLocks(); } else { MessageBox.Show(pCOMEx.Message + Environment.NewLine + Convert.ToString(pCOMEx.ErrorCode)); } return; } } //Build an IDSet of lines for the parcel to be deleted, and build an IDSet of the points for those lines m_pFIDSetLines = new FIDSetClass(); m_pFIDSetPoints = new FIDSetClass(); if (pEd.EditState == esriEditState.esriStateEditing) { try { pEd.StartOperation(); } catch { pEd.AbortOperation();//abort any open edit operations and try again pEd.StartOperation(); } } if (bUseNonVersionedDelete) { if (!FabricUTILS.StartEditing(pWS, bIsUnVersioned)) { return; } } //first delete all the parcel records if (m_bShowProgressor) { m_pStepProgressor.Message = "Deleting parcels..."; } bool bSuccess = true; pParcelsTable = (ITable)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTParcels); pLinesTable = (ITable)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTLines); pLinePtsTable = (ITable)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTLinePoints); pPointsTable = (ITable)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTPoints); pControlTable = (ITable)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTControl); if (!bUseNonVersionedDelete) { bSuccess = FabricUTILS.DeleteRowsByFIDSet(pParcelsTable, m_pFIDSetParcels, m_pStepProgressor, m_pTrackCancel); } if (bUseNonVersionedDelete) { bSuccess = FabricUTILS.DeleteRowsUnversioned(pWS, pParcelsTable, m_pFIDSetParcels, m_pStepProgressor, m_pTrackCancel); } if (!bSuccess) { if (!bIsUnVersioned) { pFabLocks.UndoLastAcquiredLocks(); } AbortEdits(bUseNonVersionedDelete, pEd, pWS); if (!bIsUnVersioned) { //check version and if the Cancel button was not clicked and we're higher than //version 10.0, then re-try the delete with the core delete command string sVersion = Application.ProductVersion; int iErrCode = FabricUTILS.LastErrorCode; if (!sVersion.StartsWith("10.0") && iErrCode == -2147217400) { FabricUTILS.ExecuteCommand("{B0A62C1C-7FAE-457A-AB25-A966B7254EF6}"); } } return; } //next need to use an in clause for lines, so ... string[] sPointOIDList = { "" }; int iCnt = 0; int iTokenCnt = 0; int iStepCnt = 1; //...for each item in the sOIDList array foreach (string inClause in sOIDList) { ICursor pLineCurs = FabricUTILS.GetCursorFromCommaSeparatedOIDList(pLinesTable, inClause, "PARCELID"); IRow pRow = pLineCurs.NextRow(); Int32 iFromPt = pLinesTable.Fields.FindField("FROMPOINTID"); Int32 iToPt = pLinesTable.Fields.FindField("TOPOINTID"); while (pRow != null) { if (iTokenCnt >= tokenLimit) { FabricUTILS.RedimPreserveString(ref sPointOIDList, 1); iTokenCnt = 0; iCnt++; } m_pFIDSetLines.Add(pRow.OID); Int32 i = (Int32)pRow.get_Value(iFromPt); if (i > -1) { bool bExists = false; m_pFIDSetPoints.Find(i, out bExists); if (!bExists) { m_pFIDSetPoints.Add(i); sPointOIDList[iCnt] = sPointOIDList[iCnt] + Convert.ToString(i) + ","; iTokenCnt++; } } i = (Int32)pRow.get_Value(iToPt); if (i > -1) { bool bExists = false; m_pFIDSetPoints.Find(i, out bExists); if (!bExists) { m_pFIDSetPoints.Add(i); sPointOIDList[iCnt] = sPointOIDList[iCnt] + Convert.ToString(i) + ","; iTokenCnt++; } } Marshal.ReleaseComObject(pRow); //garbage collection pRow = pLineCurs.NextRow(); } Marshal.ReleaseComObject(pLineCurs); //garbage collection //delete line records based on the selected parcels string sMessage = "Deleting lines..."; int iSetCnt = sOIDList.GetLength(0); if (iSetCnt > 1) { sMessage += "Step " + Convert.ToString(iStepCnt) + " of " + Convert.ToString(iSetCnt); } if (m_bShowProgressor) { m_pStepProgressor.Message = sMessage; } if (!bUseNonVersionedDelete) { bSuccess = FabricUTILS.DeleteRowsByFIDSet(pLinesTable, m_pFIDSetLines, m_pStepProgressor, m_pTrackCancel); } if (bUseNonVersionedDelete) { bSuccess = FabricUTILS.DeleteRowsUnversioned(pWS, pLinesTable, m_pFIDSetLines, m_pStepProgressor, m_pTrackCancel); } if (!bSuccess) { if (!bIsUnVersioned) { pFabLocks.UndoLastAcquiredLocks(); } AbortEdits(bUseNonVersionedDelete, pEd, pWS); return; } //delete the line points for the deleted parcels //build the list of the line points that need to be deleted. //IFeatureClass pFeatCLLinePoints = CFLinePointLayer.FeatureClass; string NewInClause = ""; //remove trailing comma if ((inClause.Substring(inClause.Length - 1, 1)) == ",") { NewInClause = inClause.Substring(0, inClause.Length - 1); } //m_pQF.WhereClause = (sPref + "parcelid" + sSuff).Trim() + " IN " + NewInClause + ")"; m_pQF.WhereClause = "PARCELID IN " + NewInClause + ")"; ICursor pLinePointCurs = pLinePtsTable.Search(m_pQF, false); IRow pLinePointFeat = pLinePointCurs.NextRow(); //Build an IDSet of linepoints for parcels to be deleted IFIDSet pFIDSetLinePoints = new FIDSetClass(); while (pLinePointFeat != null) { pFIDSetLinePoints.Add(pLinePointFeat.OID); Marshal.ReleaseComObject(pLinePointFeat); //garbage collection pLinePointFeat = pLinePointCurs.NextRow(); } //===========deletes linepoints associated with parcels iSetCnt = sOIDList.GetLength(0); sMessage = "Deleting line-points..."; if (iSetCnt > 1) { sMessage += "Step " + Convert.ToString(iStepCnt) + " of " + Convert.ToString(iSetCnt); } if (m_bShowProgressor) { m_pStepProgressor.Message = sMessage; } if (!bUseNonVersionedDelete) { bSuccess = FabricUTILS.DeleteRowsByFIDSet(pLinePtsTable, pFIDSetLinePoints, m_pStepProgressor, m_pTrackCancel); } if (bUseNonVersionedDelete) { bSuccess = FabricUTILS.DeleteRowsUnversioned(pWS, pLinePtsTable, pFIDSetLinePoints, m_pStepProgressor, m_pTrackCancel); } if (!bSuccess) { if (!bIsUnVersioned) { pFabLocks.UndoLastAcquiredLocks(); } AbortEdits(bUseNonVersionedDelete, pEd, pWS); if (pLinePointCurs != null) { Marshal.ReleaseComObject(pLinePointCurs); //garbage } return; } ///////============================================== Marshal.ReleaseComObject(pLinePointCurs); //garbage iStepCnt++; } //now need to get points that should not be deleted, because they are used by lines that are not deleted. //first search for the remaining lines. Any that have from/to points that are in the point fidset are the points //that should stay IFIDSet pFIDSetNullGeomLinePtFrom = new FIDSetClass(); IFIDSet pFIDSetNullGeomLinePtTo = new FIDSetClass(); if (m_bShowProgressor) { m_pStepProgressor.Message = "Updating point delete list..."; } for (int z = 0; z <= iCnt; z++) { //remove trailing comma if ((sPointOIDList[z].Trim() == "")) { break; } if ((sPointOIDList[z].Substring(sPointOIDList[z].Length - 1, 1)) == ",") { sPointOIDList[z] = sPointOIDList[z].Substring(0, sPointOIDList[z].Length - 1); } } //string TheWhereClause = "(" + (sPref + "frompointid" + sSuff).Trim() + " IN ("; //UpdateDeletePointList(ref sPointOIDList, ref m_pFIDSetPoints, "frompointid", // TheWhereClause, pLinesTable, out pFIDSetNullGeomLinePtFrom); //TheWhereClause = "(" + (sPref + "topointid" + sSuff).Trim() + " IN ("; //UpdateDeletePointList(ref sPointOIDList, ref m_pFIDSetPoints, "topointid", // TheWhereClause, pLinesTable, out pFIDSetNullGeomLinePtTo); string TheWhereClause = "(FROMPOINTID IN ("; UpdateDeletePointList(ref sPointOIDList, ref m_pFIDSetPoints, "FROMPOINTID", TheWhereClause, pLinesTable, out pFIDSetNullGeomLinePtFrom); TheWhereClause = "(TOPOINTID IN ("; UpdateDeletePointList(ref sPointOIDList, ref m_pFIDSetPoints, "TOPOINTID", TheWhereClause, pLinesTable, out pFIDSetNullGeomLinePtTo); if (m_bShowProgressor) { m_pStepProgressor.Message = "Deleting points..."; } if (!bUseNonVersionedDelete) { bSuccess = FabricUTILS.DeleteRowsByFIDSet(pPointsTable, m_pFIDSetPoints, m_pStepProgressor, m_pTrackCancel); } if (bUseNonVersionedDelete) { bSuccess = FabricUTILS.DeleteRowsUnversioned(pWS, pPointsTable, m_pFIDSetPoints, m_pStepProgressor, m_pTrackCancel); } if (!bSuccess) { if (!bIsUnVersioned) { pFabLocks.UndoLastAcquiredLocks(); } AbortEdits(bUseNonVersionedDelete, pEd, pWS); return; } //====Phase 2 of line-point delete. Remove the Line-points that no longer have underlying points. if (m_bShowProgressor) { m_pStepProgressor.Message = "Deleting line-points..."; } for (int z = 0; z <= iCnt; z++) { if ((sPointOIDList[z].Trim() == "")) { continue; } //remove line points where underlying points were deleted bSuccess = FabricUTILS.DeleteByQuery(pWS, pLinePtsTable, pLinePtsTable.Fields.get_Field(pLinePtsTable.FindField("LinePointID")), sPointOIDList, !bIsUnVersioned, m_pStepProgressor, m_pTrackCancel); if (!bSuccess) { if (!bIsUnVersioned) { pFabLocks.UndoLastAcquiredLocks(); } AbortEdits(bUseNonVersionedDelete, pEd, pWS); return; } } //===== //Empty geometry on points that are floating points on unjoined parcels m_pEmptyGeoms = new FIDSetClass(); FabricUTILS.IntersectFIDSetCommonIDs(pFIDSetNullGeomLinePtTo, pFIDSetNullGeomLinePtFrom, out m_pEmptyGeoms); ICadastralFabricSchemaEdit2 pSchemaEd = (ICadastralFabricSchemaEdit2)pCadFabric; pSchemaEd.ReleaseReadOnlyFields(pPointsTable, esriCadastralFabricTable.esriCFTPoints); //release safety-catch if (!bUseNonVersionedDelete) { FabricUTILS.EmptyGeometries((IFeatureClass)pPointsTable, m_pEmptyGeoms); } else { FabricUTILS.EmptyGeometriesUnversioned(pWS, CFPointLayer.FeatureClass, m_pEmptyGeoms); } pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTPoints);//set safety back on if (m_bShowProgressor) { m_pStepProgressor.Message = "Resetting control point associations..."; } for (int z = 0; z <= iCnt; z++) { if ((sPointOIDList[z].Trim() == "")) { break; } //cleanup associated control points, and associations where underlying points were deleted //m_pQF.WhereClause = (sPref + "pointid" + sSuff).Trim() + " IN (" + sPointOIDList[z] + ")"; m_pQF.WhereClause = "POINTID IN (" + sPointOIDList[z] + ")"; pSchemaEd.ReleaseReadOnlyFields(pControlTable, esriCadastralFabricTable.esriCFTControl); //release safety-catch if (!FabricUTILS.ResetControlAssociations(pControlTable, m_pQF, bUseNonVersionedDelete)) { pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTControl);//set safety back on } } pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTControl);//set safety back on if (bUseNonVersionedDelete) { FabricUTILS.StopEditing(pWS); } if (pEd.EditState == esriEditState.esriStateEditing) { pEd.StopOperation("Delete parcels"); } //clear selection, to make sure the parcel explorer is updated and refreshed properly if (pFeatSel != null && bMoreThan995UnjoinedParcels) { pFeatSel.Clear(); } } catch (Exception ex) { if (bUseNonVersionedDelete) { FabricUTILS.AbortEditing(pWS); } if (pEd != null) { if (pEd.EditState == esriEditState.esriStateEditing) { pEd.AbortOperation(); } } MessageBox.Show(ex.Message); return; } finally { RefreshMap(pActiveView, CFParcelLayers, CFPointLayer, CFLineLayer, CFControlLayer, CFLinePointLayer); //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); } if (pMouseCursor != null) { pMouseCursor.SetCursor(0); } m_pStepProgressor = null; if (!(pProgressorDialog == null)) { pProgressorDialog.HideDialog(); } pProgressorDialog = null; if (bUseNonVersionedDelete) { pCadEd.CadastralFabricLayer = null; CFParcelLayers = null; CFPointLayer = null; CFLineLayer = null; CFControlLayer = null; CFLinePointLayer = null; } } }
protected override void OnClick() { bool bShowProgressor = false; IStepProgressor pStepProgressor = null; //Create a CancelTracker. ITrackCancel pTrackCancel = null; IProgressDialogFactory pProgressorDialogFact; IMouseCursor pMouseCursor = new MouseCursorClass(); pMouseCursor.SetCursor(2); //first get the selected parcel features UID pUID = new UIDClass(); pUID.Value = "{114D685F-99B7-4B63-B09F-6D1A41A4DDC1}"; ICadastralExtensionManager2 pCadExtMan = (ICadastralExtensionManager2)ArcMap.Application.FindExtensionByCLSID(pUID); ICadastralEditor pCadEd = (ICadastralEditor)ArcMap.Application.FindExtensionByCLSID(pUID); //check if there is a Manual Mode "modify" job active =========== ICadastralPacketManager pCadPacMan = (ICadastralPacketManager)pCadExtMan; if (pCadPacMan.PacketOpen) { MessageBox.Show("The Delete linepoint command cannot be used when there is an open job.\r\nPlease finish or discard the open job, and try again.", "Delete Selected LinePoints"); return; } IEditor pEd = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor"); IActiveView pActiveView = ArcMap.Document.ActiveView; IMap pMap = pActiveView.FocusMap; ICadastralFabric pCadFabric = null; clsFabricUtils FabricUTILS = new clsFabricUtils(); IProgressDialog2 pProgressorDialog = null; //if we're in an edit session then grab the target fabric if (pEd.EditState == esriEditState.esriStateEditing) { pCadFabric = pCadEd.CadastralFabric; } if (pCadFabric == null) {//find the first fabric in the map if (!FabricUTILS.GetFabricFromMap(pMap, out pCadFabric)) { MessageBox.Show ("No Parcel Fabric found in the map.\r\nPlease add a single fabric to the map, and try again."); return; } } IArray CFLinePointLayers = new ArrayClass(); if (!(FabricUTILS.GetLinePointLayersFromFabric(pMap, pCadFabric, out CFLinePointLayers))) { return; //no fabric sublayers available for the targeted fabric } bool bIsFileBasedGDB = false; bool bIsUnVersioned = false; bool bUseNonVersionedDelete = false; IWorkspace pWS = null; ITable pLinePointTable = null; try { if (pEd.EditState == esriEditState.esriStateEditing) { try { pEd.StartOperation(); } catch { pEd.AbortOperation();//abort any open edit operations and try again pEd.StartOperation(); } } IFeatureLayer pFL = (IFeatureLayer)CFLinePointLayers.get_Element(0); IDataset pDS = (IDataset)pFL.FeatureClass; pWS = pDS.Workspace; if (!FabricUTILS.SetupEditEnvironment(pWS, pCadFabric, pEd, out bIsFileBasedGDB, out bIsUnVersioned, out bUseNonVersionedDelete)) { return; } //loop through each linepoint layer and //Get the selection of linepoints int iCnt = 0; int iTotalSelectionCount = 0; for (; iCnt < CFLinePointLayers.Count; iCnt++) { pFL = (IFeatureLayer)CFLinePointLayers.get_Element(iCnt); IFeatureSelection pFeatSel = (IFeatureSelection)pFL; ISelectionSet2 pSelSet = (ISelectionSet2)pFeatSel.SelectionSet; iTotalSelectionCount += pSelSet.Count; } if (iTotalSelectionCount == 0) { MessageBox.Show("Please select some line points and try again.", "No Selection", MessageBoxButtons.OK, MessageBoxIcon.Information); if (bUseNonVersionedDelete) { pCadEd.CadastralFabricLayer = null; CFLinePointLayers = null; } return; } bShowProgressor = (iTotalSelectionCount > 10); if (bShowProgressor) { pProgressorDialogFact = new ProgressDialogFactoryClass(); pTrackCancel = new CancelTrackerClass(); pStepProgressor = pProgressorDialogFact.Create(pTrackCancel, ArcMap.Application.hWnd); pProgressorDialog = (IProgressDialog2)pStepProgressor; pStepProgressor.MinRange = 1; pStepProgressor.MaxRange = iTotalSelectionCount; pStepProgressor.StepValue = 1; pProgressorDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral; } //loop through each linepoint layer and //delete from its selection m_pQF = new QueryFilterClass(); iCnt = 0; for (; iCnt < CFLinePointLayers.Count; iCnt++) { pFL = (IFeatureLayer)CFLinePointLayers.get_Element(iCnt); IFeatureSelection pFeatSel = (IFeatureSelection)pFL; ISelectionSet2 pSelSet = (ISelectionSet2)pFeatSel.SelectionSet; ISQLSyntax pSQLSyntax = (ISQLSyntax)pWS; string sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix); string sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix); if (bShowProgressor) { pProgressorDialog.ShowDialog(); pStepProgressor.Message = "Collecting line point data..."; } //Add the OIDs of all the selected linepoints into a new feature IDSet bool bCont = true; m_pFIDSetLinePoints = new FIDSetClass(); ICursor pCursor = null; pSelSet.Search(null, false, out pCursor);//code deletes all selected line points IFeatureCursor pLinePointFeatCurs = (IFeatureCursor)pCursor; IFeature pLinePointFeat = pLinePointFeatCurs.NextFeature(); while (pLinePointFeat != null) { //Check if the cancel button was pressed. If so, stop process if (bShowProgressor) { bCont = pTrackCancel.Continue(); if (!bCont) { break; } } bool bExists = false; m_pFIDSetLinePoints.Find(pLinePointFeat.OID, out bExists); if (!bExists) { m_pFIDSetLinePoints.Add(pLinePointFeat.OID); } Marshal.ReleaseComObject(pLinePointFeat); //garbage collection pLinePointFeat = pLinePointFeatCurs.NextFeature(); if (bShowProgressor) { if (pStepProgressor.Position < pStepProgressor.MaxRange) { pStepProgressor.Step(); } } } Marshal.ReleaseComObject(pCursor); //garbage collection if (!bCont) { AbortEdits(bUseNonVersionedDelete, pEd, pWS); return; } if (bUseNonVersionedDelete) { if (!FabricUTILS.StartEditing(pWS, bIsUnVersioned)) { if (bUseNonVersionedDelete) { pCadEd.CadastralFabricLayer = null; } return; } } //delete all the line point records if (bShowProgressor) { pStepProgressor.Message = "Deleting selected line points..."; } bool bSuccess = true; pLinePointTable = (ITable)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTLinePoints); if (!bUseNonVersionedDelete) { bSuccess = FabricUTILS.DeleteRowsByFIDSet(pLinePointTable, m_pFIDSetLinePoints, pStepProgressor, pTrackCancel); } if (bUseNonVersionedDelete) { bSuccess = FabricUTILS.DeleteRowsUnversioned(pWS, pLinePointTable, m_pFIDSetLinePoints, pStepProgressor, pTrackCancel); } if (!bSuccess) { AbortEdits(bUseNonVersionedDelete, pEd, pWS); return; } } if (bUseNonVersionedDelete) { FabricUTILS.StopEditing(pWS); } if (pEd.EditState == esriEditState.esriStateEditing) { pEd.StopOperation("Delete Line Points"); } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } finally { RefreshMap(pActiveView, CFLinePointLayers); //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); } if (pProgressorDialog != null) { pProgressorDialog.HideDialog(); } if (bUseNonVersionedDelete) { pCadEd.CadastralFabricLayer = null; CFLinePointLayers = null; } if (pMouseCursor != null) { pMouseCursor.SetCursor(0); } } }
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); } } }