Exemplo n.º 1
0
        private bool SnapAll(IPoint pPoint, IAppContext appContext, double torelance, out IPoint snapPoint)
        {
            IMap focusMap = appContext.FocusMap;

            snapPoint = null;
            bool result;

            if (!appContext.Config.UseSnap)
            {
                result = false;
            }
            else
            {
                if (appContext.Config.IsSnapSketch)
                {
                    IHitTest hitTest = SketchToolAssist.m_pPointColn as IHitTest;
                    if (hitTest != null)
                    {
                        double num   = 0.0;
                        int    num2  = 0;
                        int    num3  = 0;
                        bool   flag  = false;
                        IPoint point = new Point();
                        if (hitTest.HitTest(pPoint, torelance, esriGeometryHitPartType.esriGeometryPartVertex, point,
                                            ref num, ref num2, ref num3, ref flag))
                        {
                            snapPoint = point;
                            string toolTip = "草图:折点";
                            ApplicationRef.Application.SetToolTip(toolTip);
                            result = true;
                            return(result);
                        }
                    }
                }
                IEnumLayer enumLayer = focusMap.get_Layers(new UID
                {
                    Value = "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}"
                }, true);
                enumLayer.Reset();
                enumLayer.Next();
                IFeatureCache2 featureCache = new FeatureCache() as IFeatureCache2;
                featureCache.Initialize(pPoint, torelance);
                try
                {
                    featureCache.AddLayers(enumLayer, (appContext.MapControl.ActiveView as IActiveView).Extent);
                }
                catch
                {
                }
                if (featureCache.Count == 0)
                {
                    result = false;
                }
                else
                {
                    if (appContext.Config.IsSnapPoint)
                    {
                        snapPoint = this.SnapPoint(pPoint, featureCache, torelance);
                        if (snapPoint != null)
                        {
                            result = true;
                            return(result);
                        }
                    }
                    if (appContext.Config.IsSnapIntersectionPoint)
                    {
                        snapPoint = this.SnapIntersectPoint(pPoint, featureCache, torelance);
                        if (snapPoint != null)
                        {
                            result = true;
                            return(result);
                        }
                    }
                    if (appContext.Config.IsSnapEndPoint)
                    {
                        snapPoint = this.SnapEndPoint(pPoint, featureCache, torelance);
                        if (snapPoint != null)
                        {
                            result = true;
                            return(result);
                        }
                    }
                    if (appContext.Config.IsSnapVertexPoint)
                    {
                        snapPoint = this.SnapVertexPoint(pPoint, featureCache, torelance);
                        if (snapPoint != null)
                        {
                            result = true;
                            return(result);
                        }
                    }
                    if (appContext.Config.IsSnapMiddlePoint)
                    {
                        snapPoint = this.SnapMiddlePoint(pPoint, featureCache, torelance);
                        if (snapPoint != null)
                        {
                            result = true;
                            return(result);
                        }
                    }
                    if (appContext.Config.IsSnapBoundary)
                    {
                        snapPoint = this.SnapBoundary(pPoint, featureCache, torelance);
                        if (snapPoint != null)
                        {
                            result = true;
                            return(result);
                        }
                    }
                    result = false;
                }
            }
            return(result);
        }