Exemplo n.º 1
0
 /// <summary>
 /// 几何形状点击查询测试
 /// </summary>
 /// <param name="geometry">ESRI几何形状接口</param>
 /// <param name="queryPoint">查询点的ESRI几何形状接口</param>
 /// <param name="searchRadius">搜索半径</param>
 /// <param name="geometryPart">搜索命中的几何形状部位</param>
 /// <param name="hitPoint">搜索命中点的ESRI点接口</param>
 /// <param name="hitDistance">搜索命中的距离</param>
 /// <param name="hitPartIndex">搜索命中的几何形状部位索引</param>
 /// <param name="hitSegmentIndex">搜索命中的几何形状部位片段索引</param>
 /// <param name="bRightSide">是否命中几何形状的右方</param>
 /// <param name="hit">是否命中</param>
 public static void GeometryHitTest(IGeometry geometry, IPoint queryPoint, double searchRadius,
                                    out esriGeometryHitPartType geometryPart, out IPoint hitPoint, out double hitDistance,
                                    out int hitPartIndex, out int hitSegmentIndex, out bool bRightSide, out bool hit)
 {
     geometryPart    = esriGeometryHitPartType.esriGeometryPartNone;
     hitPoint        = new ESRI.ArcGIS.Geometry.Point();
     hitDistance     = -1;
     hitPartIndex    = -1;
     hitSegmentIndex = -1;
     bRightSide      = false;
     hit             = false;
     if (IsValidGeometry(geometry) && (geometry is IHitTest))
     {
         IHitTest hitTest = (IHitTest)geometry;
         geometryPart = esriGeometryHitPartType.esriGeometryPartVertex;
         hit          = hitTest.HitTest(queryPoint, searchRadius, geometryPart, hitPoint,
                                        ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide);
         if (!hit)
         {
             geometryPart = esriGeometryHitPartType.esriGeometryPartBoundary;
             hit          = hitTest.HitTest(queryPoint, searchRadius, geometryPart, hitPoint,
                                            ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide);
         }
         if (!hit)
         {
             geometryPart = esriGeometryHitPartType.esriGeometryPartMidpoint;
             hit          = hitTest.HitTest(queryPoint, searchRadius, geometryPart, hitPoint,
                                            ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide);
         }
         if (!hit)
         {
             geometryPart = esriGeometryHitPartType.esriGeometryPartEndpoint;
             hit          = hitTest.HitTest(queryPoint, searchRadius, geometryPart, hitPoint,
                                            ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide);
         }
         if (!hit)
         {
             geometryPart = esriGeometryHitPartType.esriGeometryPartCentroid;
             hit          = hitTest.HitTest(queryPoint, searchRadius, geometryPart, hitPoint,
                                            ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide);
         }
         if (!hit)
         {
             geometryPart = esriGeometryHitPartType.esriGeometryPartSurface;
             hit          = hitTest.HitTest(queryPoint, searchRadius, geometryPart, hitPoint,
                                            ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide);
         }
     }
 }
Exemplo n.º 2
0
 public void OnMouseUp(int button, int shift, int x, int y)
 {
     if (button != 2)
     {
         try
         {
             IGeometry editShape       = Editor.UniqueInstance.EditShape;
             IPoint    queryPoint      = this._hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
             IHitTest  test            = editShape as IHitTest;
             IPoint    hitPoint        = new PointClass();
             double    hitDistance     = 0.0;
             int       hitPartIndex    = 0;
             int       hitSegmentIndex = 0;
             bool      bRightSide      = false;
             double    searchRadius    = 1.0 * this._hookHelper.ActiveView.FocusMap.MapScale;
             esriGeometryHitPartType esriGeometryPartBoundary = esriGeometryHitPartType.esriGeometryPartBoundary;
             test.HitTest(queryPoint, searchRadius, esriGeometryPartBoundary, hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide);
             if (!hitPoint.IsEmpty)
             {
                 IEngineSketchOperation operation = new EngineSketchOperationClass();
                 operation.Start(Editor.UniqueInstance.EngineEditor);
                 IGeometryCollection geometrys = editShape as IGeometryCollection;
                 IPointCollection    points    = geometrys.get_Geometry(hitPartIndex) as IPointCollection;
                 object missing = Type.Missing;
                 object after   = new object();
                 after = hitSegmentIndex;
                 object before = new object();
                 before = hitPartIndex;
                 points.AddPoint(queryPoint, ref missing, ref after);
                 operation.SetMenuString("Insert Vertex");
                 esriEngineSketchOperationType esriEngineSketchOperationVertexAdded = esriEngineSketchOperationType.esriEngineSketchOperationVertexAdded;
                 geometrys.RemoveGeometries(hitPartIndex, 1);
                 geometrys.AddGeometry(points as IGeometry, ref before, ref missing);
                 operation.Finish(null, esriEngineSketchOperationVertexAdded, queryPoint);
                 Editor.UniqueInstance.FinishSketch();
                 this.OnClick();
             }
         }
         catch (Exception exception)
         {
             Editor.UniqueInstance.AbortEditOperation();
             this._mErrOpt.ErrorOperate(this._mSubSysName, "ShapeEdit.InsertVertex", "OnMouseUp", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Update the window with the current snap environment and snap tip settings
        /// </summary>
        private void RefreshDisplay()
        {
            snapTolerance.Text         = snapEnvironment.SnapTolerance.ToString();
            snapTolUnits.SelectedIndex = (int)snapEnvironment.SnapToleranceUnits;
            snapTips.Checked           = ((IEngineEditProperties2)editor).SnapTips;

            //remove all feature snap agents from the data grid view
            snapAgents.Rows.Clear();

            //display feature snap and snap agents that are active
            for (int i = 0; i < snapEnvironment.SnapAgentCount; i++)
            {
                try
                {
                    IEngineSnapAgent        snapAgent    = snapEnvironment.get_SnapAgent(i);
                    IEngineFeatureSnapAgent ftrSnapAgent = snapAgent as IEngineFeatureSnapAgent;

                    if (ftrSnapAgent != null)
                    {
                        //for feature snap agents add a row to the data view grid
                        esriGeometryHitPartType hitType = ftrSnapAgent.HitType;
                        bool vertex, edge, end;
                        vertex = (hitType & esriGeometryHitPartType.esriGeometryPartVertex) == esriGeometryHitPartType.esriGeometryPartVertex;
                        edge   = (hitType & esriGeometryHitPartType.esriGeometryPartBoundary) == esriGeometryHitPartType.esriGeometryPartBoundary;
                        end    = (hitType & esriGeometryHitPartType.esriGeometryPartEndpoint) == esriGeometryHitPartType.esriGeometryPartEndpoint;
                        string   vertexString = vertex ? "vertex" : "      ";
                        string   edgeString   = edge ? " edge" : "     ";
                        string   endString = end ? " end  " : "     ";
                        string   hitTypes  = vertexString + edgeString + endString;
                        object[] rowData   = { snapAgent.Name.ToString(), ftrSnapAgent.FeatureClass.AliasName, hitTypes };
                        snapAgents.Rows.Add(rowData);
                    }
                    else
                    {
                        //add the active edit sketch snap agents
                        object[] rowData = { snapAgent.Name.ToString(), "<not applicable>", "<not applicable>" };
                        snapAgents.Rows.Add(rowData);
                    }
                }
                catch (Exception)
                {
                }
            }
        }
Exemplo n.º 4
0
        public void RefreshSnapAgent(List <SnapAgent> pSnapAgents, bool pSnapTip)
        {
            IEngineSnapEnvironment environment = this._editor as IEngineSnapEnvironment;

            environment.ClearSnapAgents();
            this._snapLayers.Clear();
            foreach (SnapAgent agent in pSnapAgents)
            {
                try
                {
                    esriGeometryHitPartType esriGeometryPartNone = esriGeometryHitPartType.esriGeometryPartNone;
                    if (agent.Vertex)
                    {
                        esriGeometryPartNone ^= esriGeometryHitPartType.esriGeometryPartVertex;
                    }
                    if (agent.Edge)
                    {
                        esriGeometryPartNone ^= esriGeometryHitPartType.esriGeometryPartBoundary;
                    }
                    if (agent.EndPoint)
                    {
                        esriGeometryPartNone ^= esriGeometryHitPartType.esriGeometryPartEndpoint;
                    }
                    if (esriGeometryPartNone != esriGeometryHitPartType.esriGeometryPartNone)
                    {
                        IEngineFeatureSnapAgent snapAgent = new EngineFeatureSnapClass
                        {
                            FeatureClass = agent.FeatureLayer.FeatureClass,
                            HitType      = esriGeometryPartNone
                        };
                        environment.AddSnapAgent(snapAgent);
                        this._snapLayers.Add(agent.FeatureLayer);
                    }
                }
                catch
                {
                }
            }
            ((IEngineEditProperties2)this._editor).SnapTips = pSnapTip;
        }
Exemplo n.º 5
0
 public static IPoint Snapping(IActiveView activeView, esriGeometryHitPartType geometryHitPartType, IPoint queryPoint, double searchRaius)
 {
     IPoint vetexPoint = null;
     IPoint hitPoint = new PointClass();
     IHitTest hitTest = null;
     IPointCollection pointCollection = new MultipointClass();
     IProximityOperator proximityOperator = null;
     double hitDistance = 0;
     int hitPartIndex = 0, hitSegmentIndex = 0;
     Boolean rightSide = false;
     IFeatureCache2 featureCache = new FeatureCacheClass();
     featureCache.Initialize(queryPoint, searchRaius);  //初始化缓存
     for (int i = 0; i < activeView.FocusMap.LayerCount; i++)
     {
         //只有点、线、面并且可视的图层才加入缓存
         IFeatureLayer featLayer = (IFeatureLayer)activeView.FocusMap.get_Layer(i);
         if (featLayer != null && featLayer.Visible == true &&
             (featLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline ||
             featLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon ||
             featLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint))                
         {
             featureCache.AddFeatures(featLayer.FeatureClass, null);
             for (int j = 0; j < featureCache.Count; j++)
             {
                 IFeature feature = featureCache.get_Feature(j);
                 hitTest = (IHitTest)feature.Shape;
                 //捕捉节点,另外可以设置esriGeometryHitPartType,捕捉边线点,中间点等。
                 if (hitTest.HitTest(queryPoint, searchRaius, geometryHitPartType, hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref rightSide))
                 {
                     object obj = Type.Missing;
                     pointCollection.AddPoint(hitPoint, ref obj, ref obj);
                     break;
                 }
             }
         }
     }
     proximityOperator = (IProximityOperator)queryPoint;
     double minDistance = 0, distance = 0;
     for (int i = 0; i < pointCollection.PointCount; i++)
     {
         IPoint tmpPoint = pointCollection.get_Point(i);
         distance = proximityOperator.ReturnDistance(tmpPoint);
         if (i == 0)
         {
             minDistance = distance;
             vetexPoint = tmpPoint;
         }
         else
         {
             if (distance < minDistance)
             {
                 minDistance = distance;
                 vetexPoint = tmpPoint;
             }
         }
     }
     return vetexPoint;            
 }
Exemplo n.º 6
0
        /// <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");
            }
        }
Exemplo n.º 7
0
 private IPoint PointSnapWhenMouseMove(IActiveView activeView, esriGeometryHitPartType geometryHitPartType, IPoint pointMoveTo, double radiusSnap)
 {
     IPoint PointSnap = FunctionCommon.Snapping(activeView, geometryHitPartType, pointMoveTo, radiusSnap);
     return PointSnap;
 }