public void Activate(ESRI.ArcGIS.Controls.IEngineEditor pEditor, ESRI.ArcGIS.Controls.IEngineEditTask pOldTask) { if (pEditor == null) return; pEngineEditor = pEditor; pEditSketch = pEngineEditor as IEngineEditSketch; pEditSketch.GeometryType = esriGeometryType.esriGeometryPolyline; pEditLayer = pEditSketch as IEngineEditLayers; //Listen to engine editor events ((IEngineEditEvents_Event)pEditSketch).OnTargetLayerChanged += new IEngineEditEvents_OnTargetLayerChangedEventHandler(OnTargetLayerChanged); ((IEngineEditEvents_Event)pEditSketch).OnCurrentTaskChanged += new IEngineEditEvents_OnCurrentTaskChangedEventHandler(OnCurrentTaskChanged); }
public void OnDblClick() { this._bStarted = false; this._bFinished = true; this._bMouse = true; try { this._lineFeedback.Stop(); this._lineFeedback.Refresh(this._hookHelper.ActiveView.ScreenDisplay.hDC); this._lineFeedback = null; IEngineEditor engineEditor = Editor.UniqueInstance.EngineEditor; IEngineEditSketch sketch = Editor.UniqueInstance.EngineEditor as IEngineEditSketch; IGeometry pGeo = sketch.Geometry; if (pGeo == null) { return; } if ((Editor.UniqueInstance.CheckOverlap && !Editor.UniqueInstance.CheckFeatureOverlap(pGeo, false)) && (XtraMessageBox.Show("要素与其他要素重叠!是否保留此要素?", "", MessageBoxButtons.YesNo) == DialogResult.No)) { Editor.UniqueInstance.CancleSketch(); this._hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGeography, null, this._hookHelper.ActiveView.Extent); return; } Editor.UniqueInstance.AddAttribute = true; this._tool.OnDblClick(); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "ShapeEdit.SnapEx", "OnDblClick", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); } this._bMouse = false; }
private void editEvents_OnSketchModified() { if (!this._bMouse) { try { IEngineEditSketch engineEditor = Editor.UniqueInstance.EngineEditor as IEngineEditSketch; IPointCollection geometry = engineEditor.Geometry as IPointCollection; if ((geometry == null) || (geometry.PointCount == 0)) { if (this._lineFeedback != null) { this._lineFeedback.Stop(); } this._lineFeedback = null; this._bStarted = false; } if (this._lineFeedback != null) { int num = 1; if (engineEditor.GeometryType == esriGeometryType.esriGeometryPolygon) { num = 2; } this._lineFeedback.Stop(); this._lineFeedback.Start(geometry.get_Point(geometry.PointCount - num)); } } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "ShapeEdit.SnapEx", "editEvents_OnSketchModified", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); } } }
private void EngineEditingForm_Load(object sender, EventArgs e) { //Set buddy controls axTOCControl1.SetBuddyControl(axMapControl1); axEditorToolbar.SetBuddyControl(axMapControl1); axToolbarControl1.SetBuddyControl(axMapControl1); //Add items to the ToolbarControl axToolbarControl1.AddItem("esriControls.ControlsOpenDocCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsSaveAsDocCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsAddDataCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomInTool", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomOutTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapPanTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapFullExtentCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentBackCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentForwardCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); //Add items to the custom editor toolbar axEditorToolbar.AddItem("esriControls.ControlsEditingEditorMenu", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("VertexCommands_CS.VertexCommandsMenu", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconAndText); axEditorToolbar.AddItem("esriControls.ControlsEditingEditTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsEditingSketchTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsUndoCommand", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsRedoCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsEditingTargetToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsEditingTaskToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); //Create a popup menu m_toolbarMenu = new ToolbarMenuClass(); m_toolbarMenu.AddItem("esriControls.ControlsEditingSketchContextMenu", 0, 0, false, esriCommandStyles.esriCommandStyleTextOnly); m_engineEditor = new EngineEditorClass() as IEngineEditSketch; //this class is a singleton //share the command pool axToolbarControl1.CommandPool = axEditorToolbar.CommandPool; m_toolbarMenu.CommandPool = axToolbarControl1.CommandPool; //Create an operation stack for the undo and redo commands to use IOperationStack operationStack = new ControlsOperationStackClass(); axEditorToolbar.OperationStack = operationStack; //add some sample line data to the map IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass(); //relative file path to the sample data from EXE location string filePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); filePath = System.IO.Path.Combine(filePath, @"ArcGIS\data\USAMajorHighways"); IFeatureWorkspace workspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(filePath, axMapControl1.hWnd); IFeatureLayer featureLayer = new FeatureLayerClass(); featureLayer.Name = "Highways"; featureLayer.Visible = true; featureLayer.FeatureClass = workspace.OpenFeatureClass("usa_major_highways"); axMapControl1.Map.AddLayer((ILayer)featureLayer); }
private void EngineEditingForm_Load(object sender, EventArgs e) { //Set buddy controls axTOCControl1.SetBuddyControl(axMapControl1); axEditorToolbar.SetBuddyControl(axMapControl1); axToolbarControl1.SetBuddyControl(axMapControl1); //Add items to the ToolbarControl axToolbarControl1.AddItem("esriControls.ControlsOpenDocCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsSaveAsDocCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsAddDataCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomInTool", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomOutTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapPanTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapFullExtentCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentBackCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axToolbarControl1.AddItem("esriControls.ControlsMapZoomToLastExtentForwardCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); //Add items to the custom editor toolbar axEditorToolbar.AddItem("esriControls.ControlsEditingEditorMenu", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("VertexCommands_CS.VertexCommandsMenu", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconAndText); axEditorToolbar.AddItem("esriControls.ControlsEditingEditTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsEditingSketchTool", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsUndoCommand", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsRedoCommand", 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsEditingTargetToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); axEditorToolbar.AddItem("esriControls.ControlsEditingTaskToolControl", 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconOnly); //Create a popup menu m_toolbarMenu = new ToolbarMenuClass(); m_toolbarMenu.AddItem("esriControls.ControlsEditingSketchContextMenu", 0, 0, false, esriCommandStyles.esriCommandStyleTextOnly); m_engineEditor = new EngineEditorClass() as IEngineEditSketch; //this class is a singleton //share the command pool axToolbarControl1.CommandPool = axEditorToolbar.CommandPool; m_toolbarMenu.CommandPool = axToolbarControl1.CommandPool; //Create an operation stack for the undo and redo commands to use IOperationStack operationStack = new ControlsOperationStackClass(); axEditorToolbar.OperationStack = operationStack; //add some sample line data to the map IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass(); //relative file path to the sample data from EXE location string filePath = @"C:\Program Files\ArcGIS\DeveloperKit10.0\Samples\data\USAMajorHighways"; IFeatureWorkspace workspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(filePath, axMapControl1.hWnd); IFeatureLayer featureLayer = new FeatureLayerClass(); featureLayer.Name = "Highways"; featureLayer.Visible = true; featureLayer.FeatureClass = workspace.OpenFeatureClass("usa_major_highways"); axMapControl1.Map.AddLayer((ILayer)featureLayer); }
public void Deactivate() { //Stop listening for editor events. ((IEngineEditEvents_Event)m_engineEditor).OnTargetLayerChanged -= OnTargetLayerChanged; ((IEngineEditEvents_Event)m_engineEditor).OnCurrentTaskChanged -= OnCurrentTaskChanged; //Release object references. m_engineEditor = null; m_editSketch = null; m_editLayer = null; }
public void Deactivate() { // throw new NotImplementedException(); pEditSketch.RefreshSketch(); ((IEngineEditEvents_Event)pEditSketch).OnTargetLayerChanged -= new IEngineEditEvents_OnTargetLayerChangedEventHandler(OnTargetLayerChanged); ((IEngineEditEvents_Event)pEditSketch).OnCurrentTaskChanged -= new IEngineEditEvents_OnCurrentTaskChangedEventHandler(OnCurrentTaskChanged); pEngineEditor = null; pEditSketch = null; pEditLayer = null; }
public void CancleSketch() { IEngineEditSketch sketch = this._editor as IEngineEditSketch; IPointCollection geometry = (IPointCollection)sketch.Geometry; while (geometry.PointCount > 0) { geometry.RemovePoints(geometry.PointCount - 1, geometry.PointCount); } sketch.Geometry = (IGeometry)geometry; sketch.RefreshSketch(); }
public void Deactivate() { m_editSketch.RefreshSketch(); //Stop listening to engine editor events. ((IEngineEditEvents_Event)m_editSketch).OnTargetLayerChanged -= OnTargetLayerChanged; ((IEngineEditEvents_Event)m_editSketch).OnSelectionChanged -= OnSelectionChanged; ((IEngineEditEvents_Event)m_editSketch).OnCurrentTaskChanged -= OnCurrentTaskChanged; //Release object references. m_engineEditor = null; m_editSketch = null; m_editLayer = null; }
/// <summary> /// The mouse up performs the action appropriate for each sub-typed command: /// insert vertex or delete vertex /// </summary> /// <param name="Button"></param> /// <param name="Shift"></param> /// <param name="X">The X screen coordinate of the clicked location</param> /// <param name="Y">The Y screen coordinate of the clicked location</param> public override void OnMouseUp(int Button, int Shift, int X, int Y) { try { //get layer being edited IFeatureLayer featureLayer = m_editLayer.TargetLayer as IFeatureLayer; //set the x,y location which will be used by the out-of-the-box commands IEngineEditSketch editsketch = m_engineEditor as IEngineEditSketch; editsketch.SetEditLocation(X, Y); Type t = null; object o = null; switch (m_lSubType) { case 1: //Insert Vertex using out-of-the-box command t = Type.GetTypeFromProgID("esriControls.ControlsEditingVertexInsertCommand.1"); o = Activator.CreateInstance(t); ICommand insertVertexCommand = o as ICommand; if (insertVertexCommand != null) { insertVertexCommand.OnCreate(m_hookHelper.Hook); insertVertexCommand.OnClick(); } break; case 2: //Delete Vertex using out-of-the-box command t = Type.GetTypeFromProgID("esriControls.ControlsEditingVertexDeleteCommand.1"); o = Activator.CreateInstance(t); ICommand deleteVertexCommand = o as ICommand; if (deleteVertexCommand != null) { deleteVertexCommand.OnCreate(m_hookHelper.Hook); deleteVertexCommand.OnClick(); } break; } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message, "Unexpected Error"); } }
public void Activate(ESRI.ArcGIS.Controls.IEngineEditor editor, ESRI.ArcGIS.Controls.IEngineEditTask oldTask) { if (editor == null) { return; } m_engineEditor = editor; m_editSketch = m_engineEditor as IEngineEditSketch; m_editSketch.GeometryType = esriGeometryType.esriGeometryPolyline; m_editLayer = m_editSketch as IEngineEditLayers; //Listen to engine editor events ((IEngineEditEvents_Event)m_editSketch).OnTargetLayerChanged += new IEngineEditEvents_OnTargetLayerChangedEventHandler(OnTargetLayerChanged); ((IEngineEditEvents_Event)m_editSketch).OnSelectionChanged += new IEngineEditEvents_OnSelectionChangedEventHandler(OnSelectionChanged); ((IEngineEditEvents_Event)m_editSketch).OnCurrentTaskChanged += new IEngineEditEvents_OnCurrentTaskChangedEventHandler(OnCurrentTaskChanged); }
public void Activate(ESRI.ArcGIS.Controls.IEngineEditor editor, ESRI.ArcGIS.Controls.IEngineEditTask oldTask) { if (editor == null) { return; } //Initialize class member variables. m_engineEditor = editor; m_editSketch = editor as IEngineEditSketch; m_editSketch.GeometryType = esriGeometryType.esriGeometryPolyline; m_editLayer = m_editSketch as IEngineEditLayers; //Wire editor events. ((IEngineEditEvents_Event)m_editSketch).OnTargetLayerChanged += new IEngineEditEvents_OnTargetLayerChangedEventHandler(OnTargetLayerChanged); ((IEngineEditEvents_Event)m_editSketch).OnCurrentTaskChanged += new IEngineEditEvents_OnCurrentTaskChangedEventHandler(OnCurrentTaskChanged); }
public void OnMouseUp(int Button, int Shift, int X, int Y) { this.m_tool.OnMouseUp(Button, Shift, X, Y); IEngineEditor engineEditor = Editor.UniqueInstance.EngineEditor; IEngineEditSketch sketch = Editor.UniqueInstance.EngineEditor as IEngineEditSketch; IPointCollection geometry = sketch.Geometry as IPointCollection; if (geometry.PointCount == 2) { IPoint lastPoint = sketch.LastPoint; IFeatureLayer targetLayer = Editor.UniqueInstance.TargetLayer; IFeatureClass featureClass = targetLayer.FeatureClass; ISpatialFilter queryFilter = null; queryFilter = new SpatialFilterClass { Geometry = lastPoint, GeometryField = featureClass.ShapeFieldName, SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin }; IFeatureCursor cursor = targetLayer.Search(queryFilter, false); IFeature feature = cursor.NextFeature(); int num = 0; while (feature != null) { this.m_Feature = feature; num++; feature = cursor.NextFeature(); } switch (num) { case 1: return; case 0: MessageBox.Show("当前无要素可进行挖空!", "提示"); break; } if (num > 1) { MessageBox.Show("超过一个要素被选中,无法进行挖空!", "提示"); } Editor.UniqueInstance.CancleSketch(); this.m_hookHelper.ActiveView.Refresh(); } }
public void Activate(IEngineEditor editor, IEngineEditTask oldTask) { //throw new NotImplementedException(); if (editor == null) { return; } pEngineEditor = editor; pEditSketch = editor as IEngineEditSketch; pEditSketch.GeometryType = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline; pEditLayer = pEditSketch as IEngineEditLayers; // ((IEngineEditEvents_Event)pEditSketch).OnTargetLayerChanged += new IEngineEditEvents_OnTargetLayerChangedEventHandler(OnTargetLayerChanged); ((IEngineEditEvents_Event)pEditSketch).OnCurrentTaskChanged += new IEngineEditEvents_OnCurrentTaskChangedEventHandler(OnCurrentTaskChanged); }
public void OnDblClick() { IEngineEditor engineEditor = Editor.UniqueInstance.EngineEditor; IEngineEditSketch sketch = Editor.UniqueInstance.EngineEditor as IEngineEditSketch; IGeometry pGeo = sketch.Geometry; if ((Editor.UniqueInstance.CheckOverlap && !Editor.UniqueInstance.CheckFeatureOverlap(pGeo, false)) && (XtraMessageBox.Show("要素与其他要素重叠!是否保留此要素?", "", MessageBoxButtons.YesNo) == DialogResult.No)) { Editor.UniqueInstance.CancleSketch(); this._hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGeography, null, this._hookHelper.ActiveView.Extent); } else { IFeatureClass featureClass = Editor.UniqueInstance.TargetLayer.FeatureClass; IFeatureClassLoad feaLoad = featureClass as IFeatureClassLoad; feaLoad.LoadOnlyMode = true; this._tool.OnDblClick(); feaLoad.LoadOnlyMode = false; } }
public void OnDblClick() { try { IEngineEditor engineEditor = Editor.UniqueInstance.EngineEditor; IEngineEditSketch sketch = Editor.UniqueInstance.EngineEditor as IEngineEditSketch; IGeometry other = sketch.Geometry; if (this.m_Feature == null) { MessageBox.Show("当前无要素可进行挖空!", "提示"); Editor.UniqueInstance.CancleSketch(); } else { if (other.SpatialReference != this.m_Feature.Shape.SpatialReference) { other.Project(this.m_Feature.Shape.SpatialReference); other.SpatialReference = this.m_Feature.Shape.SpatialReference; } ITopologicalOperator2 @operator = other as ITopologicalOperator2; @operator.IsKnownSimple_2 = false; @operator.Simplify(); ITopologicalOperator2 shapeCopy = this.m_Feature.ShapeCopy as ITopologicalOperator2; shapeCopy.IsKnownSimple_2 = false; shapeCopy.Simplify(); IGeometry geometry2 = shapeCopy.Difference(other); Editor.UniqueInstance.StartEditOperation(); this.m_Feature.Shape = geometry2; this.m_Feature.Store(); Editor.UniqueInstance.StopEditOperation("erase"); Editor.UniqueInstance.CancleSketch(); this.m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGeography, null, null); } } catch { Editor.UniqueInstance.CancleSketch(); } }
public void OnMouseDown(int button, int shift, int x, int y) { this._bMouse = true; IPoint point = this._hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); this._tool.OnMouseDown(1, shift, x, y); if (this._bFinished) { this._bFinished = false; } else { try { if (this._snappingEnv == null) { return; } IPointSnapper pointSnapper = this._snappingEnv.PointSnapper; ISnappingResult result = pointSnapper.Snap(point); IEngineEditSketch engineEditor = Editor.UniqueInstance.EngineEditor as IEngineEditSketch; IPointCollection points = engineEditor.Geometry as IPointCollection; if (!this._bStarted) { this.CreateFeed(); if (result != null) { this._lineFeedback.Start(result.Location); } this._bStarted = true; return; } IGeometry geometry = engineEditor.Geometry; if (geometry == null) { return; } IPointCollection points2 = geometry as IPointCollection; IPolyline polyline = this._lineFeedback.Stop(); int index = 0; if (engineEditor.GeometryType == esriGeometryType.esriGeometryPolygon) { index = points.PointCount - 2; } else { index = points.PointCount - 1; } if (polyline != null) { IPointCollection points3 = (IPointCollection)polyline; for (int i = 1; i < (points3.PointCount - 1); i++) { IPoint point2 = points3.get_Point(i); IPoint newPoints = (point2 as IClone).Clone() as IPoint; if (pointSnapper.Snap(point2).Type == esriSnappingType.esriSnappingTypeVertex) { points2.InsertPoints(index, 1, ref newPoints); index++; } } } int hDC = this._hookHelper.ActiveView.ScreenDisplay.hDC; this._lineFeedback.Stop(); this._lineFeedback.Refresh(hDC); if (result != null) { this._lineFeedback.Start(result.Location); } if (button == 2) { this.OnDblClick(); } engineEditor.RefreshSketch(); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "ShapeEdit.SnapEx", "OnMouseUp", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); } this._bMouse = false; } }
public void OnMouseDown(int button, int shift, int x, int y) { this._tool.OnMouseDown(button, shift, x, y); IEngineSnapEnvironment engineEditor = Editor.UniqueInstance.EngineEditor as IEngineSnapEnvironment; if (engineEditor.SnapAgentCount < 1) { Editor.UniqueInstance.OperationStack.Undo(); MessageBox.Show("没有设置捕捉图层!"); } else { IFeatureLayer layer = EditTask.UnderLayers[0] as IFeatureLayer; IFeatureClass featureClass = layer.FeatureClass; IEngineFeatureSnapAgent agent = engineEditor.get_SnapAgent(0) as IEngineFeatureSnapAgent; IDataset dataset = featureClass as IDataset; IDataset dataset2 = agent.FeatureClass as IDataset; if (!dataset.Name.Equals(dataset2.Name)) { Editor.UniqueInstance.OperationStack.Undo(); MessageBox.Show("没有将征占点图层设置为捕捉图层!"); } else { IEngineEditSketch sketch = Editor.UniqueInstance.EngineEditor as IEngineEditSketch; int index = featureClass.FindField("XMBH"); IClone lastPoint = sketch.LastPoint as IClone; IPoint point = lastPoint.Clone() as IPoint; IGeoDataset dataset3 = featureClass as IGeoDataset; if (point.SpatialReference.Name != dataset3.SpatialReference.Name) { point.Project(dataset3.SpatialReference); } IGeometry geometry = (point as ITopologicalOperator).Buffer(0.0002); ISpatialFilter filter = new SpatialFilterClass { Geometry = geometry, SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects, SubFields = "XMBH", GeometryField = featureClass.ShapeFieldName }; IFeatureCursor o = featureClass.Search(filter, false); IFeature feature = o.NextFeature(); Marshal.ReleaseComObject(o); o = null; if (feature == null) { Editor.UniqueInstance.OperationStack.Undo(); MessageBox.Show("必须捕捉征占点!"); } else if (!feature.HasOID || feature.Shape.IsEmpty) { Editor.UniqueInstance.OperationStack.Undo(); MessageBox.Show("捕捉的征占点没有OID或图形有问题!"); } else { IPolyline polyline = sketch.Geometry as IPolyline; if (this.ps == 0) { int num2; int num3; this._firstValue = feature.get_Value(index); IPoint mapPoint = (feature.Shape as IClone).Clone() as IPoint; mapPoint.Project(polyline.SpatialReference); this._hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(mapPoint, out num2, out num3); polyline.FromPoint = mapPoint; polyline.ToPoint = mapPoint; } else if (this.ps >= 1) { object obj2 = feature.get_Value(index); if (!this._firstValue.Equals(obj2)) { Editor.UniqueInstance.OperationStack.Undo(); MessageBox.Show("必须捕捉项目编号相同的征占点!"); return; } IPoint point3 = (feature.Shape as IClone).Clone() as IPoint; point3.Project(polyline.SpatialReference); polyline.ToPoint = point3; } sketch.Geometry = polyline; this.ps++; } } } }
public void Deactivate() { pEditSketch.RefreshSketch(); //Stop listening to engine editor events. ((IEngineEditEvents_Event)pEditSketch).OnTargetLayerChanged -= OnTargetLayerChanged; ((IEngineEditEvents_Event)pEditSketch).OnCurrentTaskChanged -= OnCurrentTaskChanged; //Release object references. pEngineEditor = null; pEditSketch = null; pEditLayer = null; }
/// <summary> /// The mouse up performs the action appropriate for each sub-typed command: /// insert vertex, add vertex or delete vertex /// </summary> /// <param name="Button"></param> /// <param name="Shift"></param> /// <param name="X">The X screen coordinate of the clicked location</param> /// <param name="Y">The Y screen coordinate of the clicked location</param> public override void OnMouseUp(int Button, int Shift, int X, int Y) { try { IEngineEditSketch editSketch = m_engineEditor as IEngineEditSketch; IGeometry editShape = editSketch.Geometry; //location clicked as a point object IPoint clickedPt = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); #region local variables used in the HitTest IHitTest hitShape = editShape as IHitTest; IPoint hitPoint = new PointClass(); double hitDistance = 0; int hitPartIndex = 0; int hitSegmentIndex = 0; bool bRightSide = false; esriGeometryHitPartType hitPartType = esriGeometryHitPartType.esriGeometryPartNone; //the searchRadius is the maximum distance away, in map units, from the shape that will be used //for the test - change to an appropriate value. double searchRadius = 1; switch (m_lSubType) { case 1: hitPartType = esriGeometryHitPartType.esriGeometryPartBoundary; break; case 2: hitPartType = esriGeometryHitPartType.esriGeometryPartVertex; break; } #endregion hitShape.HitTest(clickedPt, searchRadius, hitPartType, hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide); //check whether the HitTest was successful (i.e within the search radius) if (hitPoint.IsEmpty == false) { IEngineSketchOperation sketchOp = new EngineSketchOperationClass(); sketchOp.Start(m_engineEditor); //Get the PointCollection for a specific path or ring by hitPartIndex to handle multi-part features IGeometryCollection geometryCol = editShape as IGeometryCollection; IPointCollection pathOrRingPointCollection = geometryCol.get_Geometry(hitPartIndex) as IPointCollection; object missing = Type.Missing; object hitSegmentIndexObject = new object(); hitSegmentIndexObject = hitSegmentIndex; object partIndexObject = new object(); partIndexObject = hitPartIndex; esriEngineSketchOperationType opType = esriEngineSketchOperationType.esriEngineSketchOperationGeneral; switch (m_lSubType) { case 1: //Insert Vertex //add new vertex to the path or ring PointCollection pathOrRingPointCollection.AddPoint(clickedPt, ref missing, ref hitSegmentIndexObject); sketchOp.SetMenuString("Insert Vertex (Custom)"); opType = esriEngineSketchOperationType.esriEngineSketchOperationVertexAdded; break; case 2: //Delete Vertex. //delete a vertex from the path or ring PointCollection pathOrRingPointCollection.RemovePoints(hitSegmentIndex, 1); sketchOp.SetMenuString("Delete Vertex (Custom)"); opType = esriEngineSketchOperationType.esriEngineSketchOperationVertexDeleted; break; } //remove the old PointCollection from the GeometryCollection and replace with the new one geometryCol.RemoveGeometries(hitPartIndex, 1); geometryCol.AddGeometry(pathOrRingPointCollection as IGeometry, ref partIndexObject, ref missing); sketchOp.Finish(null, opType, clickedPt); } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message, "Unexpected Error"); } }
public void Activate(ESRI.ArcGIS.Controls.IEngineEditor editor, ESRI.ArcGIS.Controls.IEngineEditTask oldTask) { if (editor == null) return; //Initialize class member variables. m_engineEditor = editor; m_editSketch = editor as IEngineEditSketch; m_editSketch.GeometryType = esriGeometryType.esriGeometryPolyline; m_editLayer = m_editSketch as IEngineEditLayers; //Wire editor events. ((IEngineEditEvents_Event)m_editSketch).OnTargetLayerChanged += new IEngineEditEvents_OnTargetLayerChangedEventHandler(OnTargetLayerChanged); ((IEngineEditEvents_Event)m_editSketch).OnCurrentTaskChanged += new IEngineEditEvents_OnCurrentTaskChangedEventHandler(OnCurrentTaskChanged); }
private void SnapPoint() { IEngineSnapEnvironment engineEditor = Editor.UniqueInstance.EngineEditor as IEngineSnapEnvironment; IEngineEditSketch sketch = Editor.UniqueInstance.EngineEditor as IEngineEditSketch; IPointCollection points = sketch.Geometry as IPointCollection; bool flag = false; if (sketch.GeometryType == esriGeometryType.esriGeometryPolygon) { flag = true; } if ((points.PointCount != 1) && (!flag || (points.PointCount != 2))) { IEngineFeatureSnapAgent agent2 = engineEditor.get_SnapAgent(0) as IEngineFeatureSnapAgent; esriSpatialRelEnum esriSpatialRelIntersects = esriSpatialRelEnum.esriSpatialRelIntersects; if (agent2.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon) { esriSpatialRelIntersects = esriSpatialRelEnum.esriSpatialRelTouches; } IPoint lastPoint = sketch.LastPoint; List <IFeature> pFeatures = new List <IFeature>(); ISpatialFilter filter = new SpatialFilterClass { Geometry = lastPoint, SpatialRel = esriSpatialRelIntersects, SubFields = agent2.FeatureClass.OIDFieldName + "," + agent2.FeatureClass.ShapeFieldName, GeometryField = agent2.FeatureClass.ShapeFieldName }; IFeatureCursor o = agent2.FeatureClass.Search(filter, false); IFeature item = o.NextFeature(); while (item != null) { if (item.HasOID && !item.Shape.IsEmpty) { pFeatures.Add(item); item = o.NextFeature(); } } Marshal.ReleaseComObject(o); if (pFeatures.Count >= 1) { IPoint queryPoint = null; if (flag) { queryPoint = points.get_Point(points.PointCount - 3); } else { queryPoint = points.get_Point(points.PointCount - 2); } List <IFeature> list2 = new List <IFeature>(); filter = new SpatialFilterClass { Geometry = queryPoint, SpatialRel = esriSpatialRelIntersects, SubFields = agent2.FeatureClass.OIDFieldName + "," + agent2.FeatureClass.ShapeFieldName, GeometryField = agent2.FeatureClass.ShapeFieldName }; o = null; o = agent2.FeatureClass.Search(filter, false); item = o.NextFeature(); while (item != null) { if (item.HasOID && !item.Shape.IsEmpty) { list2.Add(item); item = o.NextFeature(); } } Marshal.ReleaseComObject(o); if (list2.Count >= 1) { IList <IFeature> list3 = new List <IFeature>(); for (int i = 0; i < list2.Count; i++) { if (this.ContainFeature(pFeatures, list2[i])) { list3.Add(list2[i]); } } IFeature feature2 = null; if (list3.Count == 1) { feature2 = list3[0]; } else { if (list3.Count == 0) { return; } if (list3.Count == pFeatures.Count) { IFeatureLayer pLayer = Editor.UniqueInstance.SnapLayers[0]; SnapExFeatures features = new SnapExFeatures(pFeatures, this._hookHelper, pLayer); features.ShowDialog(); if (features.Index == -1) { return; } feature2 = pFeatures[features.Index]; features = null; } } double hitDistance = -1.0; int hitSegmentIndex = -1; int hitPartIndex = -1; bool bRightSide = false; IGeometry geometry = this.ProjectGeometry(feature2.Shape); IHitTest test = geometry as IHitTest; if (test.HitTest(lastPoint, engineEditor.SnapTolerance, esriGeometryHitPartType.esriGeometryPartVertex, null, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide)) { int num5 = -1; double num6 = -1.0; int num7 = -1; int num8 = -1; bool flag4 = false; int part = sketch.Part; IHitTest test2 = geometry as IHitTest; if (test2.HitTest(queryPoint, engineEditor.SnapTolerance, esriGeometryHitPartType.esriGeometryPartVertex, null, ref num6, ref num8, ref num7, ref flag4)) { IPolyline polyline3; if (flag) { num5 = points.PointCount - 2; } else { num5 = points.PointCount - 1; } IGeometryCollection geometrys = geometry as IGeometryCollection; IPointCollection points2 = geometrys.get_Geometry(hitPartIndex) as IPointCollection; IPolyline polyline = new PolylineClass(); IPolyline polyline2 = new PolylineClass(); IPointCollection points3 = polyline as IPointCollection; IPointCollection points4 = polyline2 as IPointCollection; object before = Missing.Value; object after = Missing.Value; IPoint inPoint = null; bool flag6 = false; if (num7 > hitSegmentIndex) { int num9 = hitSegmentIndex; hitSegmentIndex = num7; num7 = num9; flag6 = true; } int num10 = 0; if (flag) { for (num10 = num7; num10 <= hitSegmentIndex; num10++) { inPoint = points2.get_Point(num10); points3.AddPoint(inPoint, ref before, ref after); } int num11 = points2.PointCount - 1; for (num10 = hitSegmentIndex; num10 < num11; num10++) { inPoint = points2.get_Point(num10); points4.AddPoint(inPoint, ref before, ref after); } for (num10 = 0; num10 <= num7; num10++) { inPoint = points2.get_Point(num10); points4.AddPoint(inPoint, ref before, ref after); } if (polyline.Length <= polyline2.Length) { polyline3 = polyline; } else { polyline3 = polyline2; flag6 = true; } } else { num10 = num7; while (num10 <= hitSegmentIndex) { inPoint = points2.get_Point(num10); points3.AddPoint(inPoint, ref before, ref after); num10++; } polyline3 = polyline; } IPointCollection points5 = polyline3 as IPointCollection; int index = num5; if (flag6) { for (num10 = points5.PointCount - 2; num10 > 0; num10--) { IPoint newPoints = (points5.get_Point(num10) as IClone).Clone() as IPoint; points.InsertPoints(index, 1, ref newPoints); index++; } } else { for (num10 = 1; num10 < (points5.PointCount - 1); num10++) { IPoint point7 = (points5.get_Point(num10) as IClone).Clone() as IPoint; points.InsertPoints(index, 1, ref point7); index++; } } } } } } } }