// this method is called everytime the mouse moves and show the user the snapping points of the selected feature public override void OnMouseMove(int Button, int Shift, int X, int Y) { // TODO: Add btnTool_SplitLine.OnMouseMove implementation if (m_Position != null) { clsGlobals.arcEditor.InvertAgent(m_Position, 0); } m_Position = clsGlobals.arcEditor.Display.DisplayTransformation.ToMapPoint(X, Y); //Get the snap environment from the editor ISnapEnvironment se = clsGlobals.arcEditor as ISnapEnvironment; Boolean snapped = se.SnapPoint(m_Position); clsGlobals.arcEditor.InvertAgent(m_Position, 0); }
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); } } } }
// this code runs when user presses the mouse button down on the map public override void OnMouseDown(int Button, int Shift, int X, int Y) { try { //get the current document IMxDocument arcMxDoc = clsGlobals.arcApplication.Document as IMxDocument; //get the focus map (the active data frame) IMap arcMapp = arcMxDoc.FocusMap; // get active view (can be data frame in either page layout or data view) IActiveView arcActiveView = arcMapp as IActiveView; // make sure the user has selected a layer in the toc if (arcMxDoc.SelectedLayer == null) { MessageBox.Show("Please select the roads layer in ArcMap's TOC.", "Select Layer in TOC", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!(arcMxDoc.SelectedLayer is IFeatureLayer)) { MessageBox.Show("Please select a polygon or line layer in the TOC.", "Must be Polygon or Line Layer", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //cast the selected layer as a feature layer IGeoFeatureLayer pGFlayer = (IGeoFeatureLayer)arcMxDoc.SelectedLayer; //check if the feaure layer is a polygon or line layer if (pGFlayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon & pGFlayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolyline) { MessageBox.Show("Please select a polygon or line layer.", "Must be Polygon or Line Layer", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // set classic snapping to true //IEditProperties4 arcEditProperties4 = clsGlobals.arcEditor as IEditProperties4; //arcEditProperties4.ClassicSnapping = true; // set some variables for capturing where the user's click location ISnapEnvironment arcSnapEnvironment = clsGlobals.arcEditor as ISnapEnvironment; //Boolean snapped = arcSnapEnvironment.SnapPoint() IPoint arcSplitPoint = new ESRI.ArcGIS.Geometry.Point(); arcSplitPoint = m_Position; // m_Position is set in the MouseMove event // the section of code below that is commented out was used before i converted over to gettting the snapping environment from the mouse movement event // don't need it anymore, could be useful if i don't get the snapping point from the mouse movement event //////IScreenDisplay arcScreenDisplay = arcActiveView.ScreenDisplay; //////IDisplayTransformation arcDisplayTransformation = arcScreenDisplay.DisplayTransformation; //////// snap to existing snap environment //////arcSnapEnvironment.SnapPoint(m_Position); ////////arcSnapEnvironment.SnapPoint(arcSplitPoint); //////// get the x and y from the user's mouse click - these are variables that are passed in via the OnMouseDown click event //////arcSplitPoint = arcDisplayTransformation.ToMapPoint(X, Y); // see if the there's anyintersecting segments with a coordinate address to use values in the new number assignments IContentsView arcContentsView = arcMxDoc.CurrentContentsView; IFeatureLayer arcFeatLayer = (IFeatureLayer)arcContentsView.SelectedItem; IFeatureClass arcFeatClass = arcFeatLayer.FeatureClass; List <IFeature> listFeatures = new List <IFeature>(); listFeatures = checkForIntersectingSegments(arcSplitPoint, 1, arcFeatClass); // get the objectid of the selected feature - so we can exclude it from the intesecting search below string strSelectedOID = arcSelectedFeature.get_Value(arcSelectedFeature.Fields.FindField("OBJECTID")).ToString(); isNumeric_StName = false; isNumeric_ACSName = false; // if see there are any features intersecting (there is always 1 - it's the selected feature to split, so we need to check if it's more than 1) if (listFeatures.Count > 1) { bool blnUseCoordinateAddress; // loop through the intesecting features to see if any have coordinate address to use for (int i = 0; i < listFeatures.Count; i++) { // ignore the ifeature that's the selected one - we don't need to check for coordinate values for the selected if (strSelectedOID != listFeatures[i].OID.ToString()) { // check if street name is acs/coordinate (numberic) isNumeric_StName = int.TryParse(listFeatures[i].get_Value(listFeatures[i].Fields.FindField("STREETNAME")).ToString(), out intStreetName); isNumeric_ACSName = int.TryParse(listFeatures[i].get_Value(listFeatures[i].Fields.FindField("ACSNAME")).ToString(), out intACSName); // if the value is numeric then capture the number and proceed if (isNumeric_StName == true) { //MessageBox.Show(intStreetName.ToString()); break; // breaks from "for loop" } if (isNumeric_ACSName == true) { //MessageBox.Show(intACSName.ToString()); break; // breaks from "for loop" } } } } // call the split centerline method doCenterlineSplit(arcSelectedFeature, arcSplitPoint); // expand the envelope IEnvelope arcEnvelope = arcSelectedFeature.Extent; arcEnvelope.Expand(1.2, 1.2, true); // if the parent arc is horizontal or vertical, refresh the full screen if (arcEnvelope.Width < arcMxDoc.ActivatedView.Extent.Width / 100) { arcEnvelope = arcMxDoc.ActivatedView.Extent; } if (arcEnvelope.Height < arcMxDoc.ActivatedView.Extent.Height / 100) { arcEnvelope = arcMxDoc.ActivatedView.Extent; } //arcActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography & esriViewDrawPhase.esriViewGeoSelection, null, arcEnvelope); // deativate the tool clsGlobals.arcApplication.CurrentTool = null; arcMapp.ClearSelection(); arcActiveView.Refresh(); arcActiveView.Refresh(); } catch (Exception ex) { MessageBox.Show("Error Message: " + Environment.NewLine + ex.Message + Environment.NewLine + Environment.NewLine + "Error Source: " + Environment.NewLine + ex.Source + Environment.NewLine + Environment.NewLine + "Error Location:" + Environment.NewLine + ex.StackTrace, "UTRANS Editor tool error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
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); }