public static void initEditing() { if (AAState.PerformUpdates == false) { AAState.WriteLine(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantEditorMess_3a")); return; } // wire events if (reInitExt() == false) { AAState.WriteLine(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantEditorMess_3b")); AAState.PerformUpdates = false; } if (AAState._editor.EditWorkspace != null) { if (AAState._editor.EditWorkspace.Type == esriWorkspaceType.esriFileSystemWorkspace) { AAState.WriteLine(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantEditorMess_3c")); AAState.PerformUpdates = false; } } if (AAState.PerformUpdates) { AAState.WriteLine(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantEditorMess_3d")); if (Debug().ToUpper() == "TRUE") { AAState._filePath = Globals.getDebugPath(); if (AAState._filePath != "") { AAState._sw = Globals.createTextFile(AAState._filePath, FileMode.Create); } Globals.LogLocations = AAState._filePath; } else { AAState._sw = null; Globals.LogLocations = ""; } // Get user Info reInitExt(); //obtain rotation calculator AAState.rCalc = new RotationCalculator(ArcMap.Application); //Create WGS_84 SR ISpatialReferenceFactory srFactory = new SpatialReferenceEnvironmentClass(); IGeographicCoordinateSystem gcs = srFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); _sr1 = gcs; _editEvents.OnChangeFeature += FeatureChange; _editEvents.OnCreateFeature += FeatureCreate; _editEvents2.BeforeStopOperation += StopOperation; // SG Jan 2013 } else { AAState.PerformUpdates = false; _editEvents.OnChangeFeature -= FeatureChange; _editEvents.OnCreateFeature -= FeatureCreate; _editEvents2.BeforeStopOperation -= StopOperation; // SG Jan 2013 } ArcMap.Application.StatusBar.set_Message(0, A4LGSharedFunctions.Localizer.GetString("AttributeAssistantEditorDone_3a")); }
public static void RotateSelected(IApplication app, double spinAngle, string diameterFieldName) { IEditor editor = null; IEditLayers eLayers = null; IMap map = null; UID geoFeatureLayerID = null; IEnumLayer enumLayer = null; IFeatureLayer fLayer = null; IGeoFeatureLayer geoFLayer = null; IRotationRenderer rRenderer = null; IFeatureSelection fSel = null; ILayer layer = null; ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = null; ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = null; ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = null; ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = null; RotationCalculator rc = null; IActiveView activeView = null; IInvalidArea invalid = null; IEnvelope ext = null; ICursor pointCursor = null; IFeature pointFeature = null; ISelectionSet2 sel = null; try { int maxIndividualRefresh = 100; //Get list of editable layers editor = Globals.getEditor(app); eLayers = (IEditLayers)editor; if (editor.EditState != esriEditState.esriStateEditing) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("MustBEditg")); return; } map = editor.Map; //Get list of feature layers geoFeatureLayerID = new UIDClass(); geoFeatureLayerID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"; enumLayer = map.get_Layers(((ESRI.ArcGIS.esriSystem.UID)geoFeatureLayerID), true); if (map.SelectionCount > 0) { string rotationFieldName; int rotationFieldPos; int count; Nullable<double> angle; int total = map.SelectionCount; int i = 0; //ProgressBar progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass(); // Create a CancelTracker trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); // Set the properties of the Step Progressor System.Int32 int32_hWnd = app.hWnd; stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd); stepProgressor.MinRange = 0; stepProgressor.MaxRange = total; stepProgressor.StepValue = 1; stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeometryToolsMess_1"); // Create the ProgressDialog. This automatically displays the dialog progressDialog = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast // Set the properties of the ProgressDialog progressDialog.CancelEnabled = true; progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_3") + total.ToString() + "."; progressDialog.Title = A4LGSharedFunctions.Localizer.GetString("GeometryToolsLbl_2"); progressDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriDownloadFile; // Prep rotation calculator rc = new RotationCalculator(app); //Prep screen refresh for selected features activeView = map as IActiveView; invalid = new InvalidAreaClass(); invalid.Display = editor.Display; // Step through each geofeature layer in the map enumLayer.Reset(); layer = enumLayer.Next(); bool test = false; while (!(layer == null)) { // Verify that this is a valid, visible point layer and that this layer is editable fLayer = (IFeatureLayer)layer; if (fLayer.Valid && fLayer.Visible && (fLayer.FeatureClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint) && eLayers.IsEditable(fLayer)) { // Verify that a selection for this layer fSel = (IFeatureSelection)fLayer; count = fSel.SelectionSet.Count; if (count > 0) { // Verify that symbol rotation has been setup for this layer geoFLayer = (IGeoFeatureLayer)fLayer; if (!(geoFLayer.Renderer is IRotationRenderer)) { layer = enumLayer.Next(); continue; } // Verify that the rotation field has been specified and that the field exists rRenderer = (IRotationRenderer)geoFLayer.Renderer; rotationFieldName = rRenderer.RotationField; rotationFieldPos = fLayer.FeatureClass.FindField(rotationFieldName); if (rotationFieldPos == -1) { layer = enumLayer.Next(); continue; } test = true; rc.RotationType = rRenderer.RotationType; rc.SpinAngle = spinAngle; rc.DiameterFieldName = diameterFieldName; rc.UseDiameter = true; // Create an edit operation enabling undo/redo editor.StartOperation(); try { //Get a cursor for selected features sel = fSel.SelectionSet as ISelectionSet2; sel.Update(null, false, out pointCursor); while ((pointFeature = (IFeature)pointCursor.NextRow()) != null) { if (map.SelectionCount <= maxIndividualRefresh) { //Prepare to redraw area around feature ext = pointFeature.Extent; ext.Expand(2, 2, true); invalid.Add(ext); } //Use Rotation Calculator angle = rc.GetRotationUsingConnectedEdges(pointFeature); //Set rotation value in feature pointFeature.set_Value(rotationFieldPos, angle); pointCursor.UpdateRow(pointFeature as IRow); //Update progress bar i += 1; stepProgressor.Step(); progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_6") + i.ToString() + A4LGSharedFunctions.Localizer.GetString("Of") + total.ToString() + "."; //Check if the cancel button was pressed. If so, stop process if (!trackCancel.Continue()) { break; } } if (pointCursor != null) { Marshal.ReleaseComObject(pointCursor); } } catch (Exception ex) { editor.AbortOperation(); progressDialog.HideDialog(); MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_5") + "\n" + ex.Message, ex.Source); return; } // Stop the edit operation editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_5")); } } layer = enumLayer.Next(); } progressDialog.HideDialog(); //Alert the user know if no work was performed if (!(test)) MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsError_6"), A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_5")); //Redraw invalid areas or entire map if (i > 0) { if (map.SelectionCount < maxIndividualRefresh) invalid.Invalidate((short)esriScreenCache.esriAllScreenCaches); else activeView.Refresh(); } } } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_5") + "\n" + ex.Message, A4LGSharedFunctions.Localizer.GetString("GeometryToolsProc_5")); return; } finally { editor = null; eLayers = null; map = null; geoFeatureLayerID = null; enumLayer = null; fLayer = null; geoFLayer = null; rRenderer = null; fSel = null; layer = null; progressDialogFactory = null; trackCancel = null; stepProgressor = null; progressDialog = null; rc = null; activeView = null; invalid = null; ext = null; pointCursor = null; pointFeature = null; sel = null; } }
public static void initEditing() { if (AAState._PerformUpdates == false) return; // wire events if (reInitExt() == false) { AAState._PerformUpdates = false; //AAState.setIcon(); //return; } if (AAState._editor.EditWorkspace != null) { if (AAState._editor.EditWorkspace.Type == esriWorkspaceType.esriFileSystemWorkspace) { AAState._PerformUpdates = false; //AAState.setIcon(); } } if (AAState._PerformUpdates) { if (_Debug.ToUpper() == "TRUE") { AAState._filePath = Globals.PromptForSave(); if (AAState._filePath != "") { AAState._sw = Globals.createTextFile(AAState._filePath, FileMode.Create); } } else { AAState._sw = null; } // Get user Info _currentUserInfo = new CurrentUserInfo(AAState._editor); reInitExt(); //obtain rotation calculator AAState.rCalc = new RotationCalculator(ArcMap.Application); //Create WGS_84 SR ISpatialReferenceFactory srFactory = new SpatialReferenceEnvironmentClass(); IGeographicCoordinateSystem gcs = srFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); _sr1 = gcs; // Action[] handlers = _editEvents.OnChangeFeature.GetInvocationList(); _editEvents.OnChangeFeature += FeatureChange; _editEvents.OnCreateFeature += FeatureCreate; // get configuration table } else { //MessageBox.Show("The Attribute Assistant is turned on, but the Dynamic Value table is missing, please add the table and toggle the extension on"); // WriteLine("Dynamic Value Table is missing - Name in Config:" + AAState._defaultsTableName); AAState._PerformUpdates = false; AAState.setIcon();// ExecuteToggleAACommands(); _editEvents.OnChangeFeature -= FeatureChange; _editEvents.OnCreateFeature -= FeatureCreate; MessageBox.Show("AA Extension has been turned off"); // get configuration table } ArcMap.Application.StatusBar.set_Message(0, "Editor Extension Initialized"); }