public void OnMouseMove(int button, int shift, int x, int y) { IPoint point = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); IEngineSnapEnvironment engineEditor = Editor.UniqueInstance.EngineEditor as IEngineSnapEnvironment; try { if (engineEditor.SnapPoint(point)) { this.m_Cursor = ToolCursor.VertexSelected; } else { this.m_Cursor = ToolCursor.Add; } } catch { } if (this.m_IsUsed) { IPoint point2 = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); this.m_LineFeedback.MoveTo(point2); } }
private bool IsSnapPoint(IPoint pPoint) { IEngineSnapEnvironment engineEditor = Editor.UniqueInstance.EngineEditor as IEngineSnapEnvironment; if (engineEditor.SnapAgentCount != 1) { return(false); } try { if (engineEditor.SnapPoint(pPoint)) { this._snapPoint = pPoint; return(true); } return(false); } catch { return(false); } }
private ISnappingResult method_0(IPoint ipoint_1) { IActiveView focusMap = this._appContext.MapControl.Map as IActiveView; IPoint pointClass = new ESRI.ArcGIS.Geometry.Point(); pointClass.PutCoords(ipoint_1.X, ipoint_1.Y); IEngineSnapEnvironment engineSnapEnvironment = ApplicationRef.AppContext.Config.EngineSnapEnvironment; ISnappingResult snappingResult = null; if (engineSnapEnvironment is ISnapEnvironment) { ISnapEnvironment snapEnvironment = engineSnapEnvironment as ISnapEnvironment; if ((snapEnvironment == null || !ApplicationRef.AppContext.Config.UseSnap ? false : snapEnvironment.SnapPoint(pointClass, ipoint_1))) { SnappingResult snappingResult1 = new SnappingResult() { X = ipoint_1.X, Y = ipoint_1.Y }; snappingResult = snappingResult1; } } else if ((engineSnapEnvironment == null || !ApplicationRef.AppContext.Config.UseSnap ? false : engineSnapEnvironment.SnapPoint(ipoint_1))) { SnappingResult snappingResult2 = new SnappingResult() { X = ipoint_1.X, Y = ipoint_1.Y }; snappingResult = snappingResult2; } return(snappingResult); }
public static void Snap2Point(IPoint ipoint_0, IPoint ipoint_1, esriSimpleMarkerStyle esriSimpleMarkerStyle_0, IActiveView iactiveView_0, IEngineSnapEnvironment iengineSnapEnvironment_0) { IHitTest mPPointColn; double num; int num1; int num2; bool flag; double mapUnits; IPoint pointClass; if (!Editor.UseOldSnap) { ISnappingResult snappingResult = SketchToolAssist.m_psnaper.Snap(ipoint_0); if (snappingResult == null) { if (SketchToolAssist.m_pAP == null) { SketchToolAssist.m_pAP = new AnchorPoint() { Symbol = SketchShareEx.m_pSym as ISymbol }; } SketchToolAssist.m_pAP.MoveTo(SketchShareEx.m_pAnchorPoint, iactiveView_0.ScreenDisplay); } else { SketchShareEx.m_pAnchorPoint = snappingResult.Location; if (SketchToolAssist.m_pAP != null) { SketchToolAssist.m_pAP.MoveTo(snappingResult.Location, iactiveView_0.ScreenDisplay); } else { SketchToolAssist.AddNewAnchorPt(snappingResult.Location, esriSimpleMarkerStyle_0, iactiveView_0); } } } else { SketchShareEx.m_pSym.Style = esriSimpleMarkerStyle_0; if (iengineSnapEnvironment_0 is ISnapEnvironment) { ISnapEnvironment iengineSnapEnvironment0 = iengineSnapEnvironment_0 as ISnapEnvironment; if ((iengineSnapEnvironment0 == null || !ApplicationRef.AppContext.Config.UseSnap ? true : !iengineSnapEnvironment0.SnapPoint(SketchShareEx.LastPoint, ipoint_0))) { if (ApplicationRef.AppContext.Config.IsSnapSketch) { mPPointColn = SketchToolAssist.m_pPointColn as IHitTest; if (mPPointColn != null) { num = 0; num1 = 0; num2 = 0; flag = false; mapUnits = CommonHelper.ConvertPixelsToMapUnits(iactiveView_0, iengineSnapEnvironment0.SnapTolerance); if (mapUnits == 0) { mapUnits = 3; } pointClass = new ESRI.ArcGIS.Geometry.Point(); if ( !mPPointColn.HitTest(ipoint_0, mapUnits, esriGeometryHitPartType.esriGeometryPartVertex, pointClass, ref num, ref num1, ref num2, ref flag)) { SketchShareEx.m_bSnapSuccessful = false; if (SketchToolAssist.m_pAP != null) { SketchToolAssist.m_pAP.MoveTo(ipoint_0, iactiveView_0.ScreenDisplay); } else { SketchToolAssist.AddNewAnchorPt(ipoint_0, esriSimpleMarkerStyle_0, iactiveView_0); } return; } ipoint_0.PutCoords(pointClass.X, pointClass.Y); SketchShareEx.m_bSnapSuccessful = true; if (SketchToolAssist.m_pAP != null) { SketchToolAssist.m_pAP.MoveTo(ipoint_0, iactiveView_0.ScreenDisplay); return; } else { SketchToolAssist.AddNewAnchorPt(ipoint_0, esriSimpleMarkerStyle_0, iactiveView_0); return; } } } } else { SketchShareEx.m_bSnapSuccessful = true; if (SketchToolAssist.m_pAP != null) { SketchToolAssist.m_pAP.MoveTo(ipoint_0, iactiveView_0.ScreenDisplay); } else { SketchToolAssist.AddNewAnchorPt(ipoint_0, esriSimpleMarkerStyle_0, iactiveView_0); } } } else if ((iengineSnapEnvironment_0 == null || !ApplicationRef.AppContext.Config.UseSnap ? true : !iengineSnapEnvironment_0.SnapPoint(ipoint_0))) { if (ApplicationRef.AppContext.Config.IsSnapSketch) { mPPointColn = SketchToolAssist.m_pPointColn as IHitTest; if (mPPointColn != null) { num = 0; num1 = 0; num2 = 0; flag = false; mapUnits = iengineSnapEnvironment_0.SnapTolerance; if (iengineSnapEnvironment_0.SnapToleranceUnits == esriEngineSnapToleranceUnits.esriEngineSnapTolerancePixels) { mapUnits = CommonHelper.ConvertPixelsToMapUnits(iactiveView_0, iengineSnapEnvironment_0.SnapTolerance); } if (mapUnits == 0) { mapUnits = 3; } pointClass = new ESRI.ArcGIS.Geometry.Point(); if ( !mPPointColn.HitTest(ipoint_0, mapUnits, esriGeometryHitPartType.esriGeometryPartVertex, pointClass, ref num, ref num1, ref num2, ref flag)) { SketchShareEx.m_bSnapSuccessful = false; if (SketchToolAssist.m_pAP != null) { SketchToolAssist.m_pAP.MoveTo(ipoint_0, iactiveView_0.ScreenDisplay); } else { SketchToolAssist.AddNewAnchorPt(ipoint_0, esriSimpleMarkerStyle_0, iactiveView_0); } return; } ipoint_0.PutCoords(pointClass.X, pointClass.Y); SketchShareEx.m_bSnapSuccessful = true; if (SketchToolAssist.m_pAP != null) { SketchToolAssist.m_pAP.MoveTo(ipoint_0, iactiveView_0.ScreenDisplay); return; } else { SketchToolAssist.AddNewAnchorPt(ipoint_0, esriSimpleMarkerStyle_0, iactiveView_0); return; } } } } else { SketchShareEx.m_bSnapSuccessful = true; if (SketchToolAssist.m_pAP != null) { SketchToolAssist.m_pAP.MoveTo(ipoint_0, iactiveView_0.ScreenDisplay); } else { SketchToolAssist.AddNewAnchorPt(ipoint_0, esriSimpleMarkerStyle_0, iactiveView_0); } } } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { try { pt = ((m_hookHelper.ActiveView.ScreenDisplay).DisplayTransformation).ToMapPoint(X, Y); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } bool ddd = snapEnvironment.SnapPoint(pt); if (pMPfeedback != null) { pMPfeedback.Stop(); } pMPfeedback = null; bool hasCut = false; ISet newFeaturesSet = null; try { IFeatureSelection featureSelection = m_editLayer.TargetLayer as IFeatureSelection; ISelectionSet selectionSet = featureSelection.SelectionSet; IEnumIDs enumIDs = selectionSet.IDs; int iD = enumIDs.Next(); while (iD != -1) //-1 is reutned after the last valid ID has been reached { m_engineEditor.StartOperation(); IFeatureClass featureClass = m_editLayer.TargetLayer.FeatureClass; IFeature feature = featureClass.GetFeature(iD); // 判断点是否在线上,不是则跳过 ITopologicalOperator pto = feature.Shape as ITopologicalOperator; IGeometry pgeometry = pto.Intersect(pt, esriGeometryDimension.esriGeometry0Dimension); if (pgeometry.IsEmpty == true) { iD = enumIDs.Next(); continue; } IFeatureEdit featureedit = feature as IFeatureEdit; /*ISet*/ newFeaturesSet = featureedit.Split(pgeometry); if (newFeaturesSet != null) { newFeaturesSet.Reset(); hasCut = true; break; } iD = enumIDs.Next(); } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } if (hasCut) { //如果操作成功,选中切割的两条线 //IFeatureSelection featureSelection = m_editLayer.TargetLayer as IFeatureSelection; //ISelectionSet selectionSet = featureSelection.SelectionSet; //for (int i = 0; i < newFeaturesSet.Count; i++) //{ // selectionSet.Add(((IFeature)newFeaturesSet.Next()).OID); //} //selectionSet.Refresh(); //Refresh the display including modified layer and any previously selected component. IActiveView activeView = m_engineEditor.Map as IActiveView; activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography | esriViewDrawPhase.esriViewGeoSelection, null, activeView.Extent); activeView.Refresh(); //Complete the edit operation. m_engineEditor.StopOperation("Split a line"); // 将当前工具设置为选择工具 IToolbarControl toolbarctl = m_hookHelper.Hook as IToolbarControl; //ICommand com = new ControlsEditingEditToolClass(); //com.OnCreate(m_mapControl.Object); //this.m_mapControl.CurrentTool = com as ITool; for (int i = 0; i < toolbarctl.Count; i++) { IToolbarItem tbi = toolbarctl.GetItem(i); if (tbi.Command != null && tbi.Command.Name.Equals("ControlToolsEditing_Edit")) { tbi.Command.OnClick();// = true; toolbarctl.CurrentTool = tbi.Command as ITool; IToolbarBuddy toolbarbuddy = (IToolbarBuddy)((IToolbarControl)m_hookHelper.Hook).Buddy; break; } } // 操作成功后将当前工具置为以前的工具 //IToolbarBuddy toolbarbuddy = (IToolbarBuddy)((IToolbarControl)m_hookHelper.Hook).Buddy; //toolbarbuddy.CurrentTool = oldtool; //((IToolbarControl)m_hookHelper.Hook).SetBuddyControl(toolbarbuddy); this.Deactivate(); } else { m_engineEditor.AbortOperation(); MessageBox.Show("切割点不在线上,未能成功切割选择的线段"); //重新开始选点 this.OnClick(); } base.OnMouseDown(Button, Shift, X, Y); }
private static ISnappingResult OldSnap(IPoint ipoint_0, IActiveView pActiveView, IEngineSnapEnvironment iengineSnapEnvironment_0) { IHitTest mPPointColn; double num; int num1; int num2; bool flag; double mapUnits; IPoint pointClass; ISnappingResult snappingResult = null; if (iengineSnapEnvironment_0 is ISnapEnvironment) { ISnapEnvironment iengineSnapEnvironment0 = iengineSnapEnvironment_0 as ISnapEnvironment; if ( !(iengineSnapEnvironment0 == null || !ApplicationRef.AppContext.Config.UseSnap ? true : !iengineSnapEnvironment0.SnapPoint(SketchToolAssist.LastPoint, ipoint_0))) { SnappingResult snappingResult1 = new SnappingResult() { X = ipoint_0.X, Y = ipoint_0.Y }; snappingResult = snappingResult1; } else if (ApplicationRef.AppContext.Config.IsSnapSketch) { mPPointColn = SketchToolAssist.m_pPointColn as IHitTest; if (mPPointColn != null) { num = 0; num1 = 0; num2 = 0; flag = false; mapUnits = CommonHelper.ConvertPixelsToMapUnits(pActiveView, iengineSnapEnvironment0.SnapTolerance); if (mapUnits == 0) { mapUnits = 3; } pointClass = new ESRI.ArcGIS.Geometry.Point(); if (mPPointColn.HitTest(ipoint_0, mapUnits, esriGeometryHitPartType.esriGeometryPartVertex, pointClass, ref num, ref num1, ref num2, ref flag)) { SnappingResult snappingResult2 = new SnappingResult() { X = pointClass.X, Y = pointClass.Y }; snappingResult = snappingResult2; } } } } else if ( !(iengineSnapEnvironment_0 == null || !ApplicationRef.AppContext.Config.UseSnap ? true : !iengineSnapEnvironment_0.SnapPoint(ipoint_0))) { SnappingResult snappingResult3 = new SnappingResult() { X = ipoint_0.X, Y = ipoint_0.Y }; snappingResult = snappingResult3; } else if (ApplicationRef.AppContext.Config.IsSnapSketch) { mPPointColn = SketchToolAssist.m_pPointColn as IHitTest; if (mPPointColn != null) { num = 0; num1 = 0; num2 = 0; flag = false; mapUnits = iengineSnapEnvironment_0.SnapTolerance; if (iengineSnapEnvironment_0.SnapToleranceUnits == esriEngineSnapToleranceUnits.esriEngineSnapTolerancePixels) { mapUnits = CommonHelper.ConvertPixelsToMapUnits(pActiveView, iengineSnapEnvironment_0.SnapTolerance); } if (mapUnits == 0) { mapUnits = 3; } pointClass = new ESRI.ArcGIS.Geometry.Point(); if (mPPointColn.HitTest(ipoint_0, mapUnits, esriGeometryHitPartType.esriGeometryPartVertex, pointClass, ref num, ref num1, ref num2, ref flag)) { SnappingResult snappingResult4 = new SnappingResult() { X = pointClass.X, Y = pointClass.Y }; snappingResult = snappingResult4; } } } return(snappingResult); }