You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							155 lines
						
					
					
						
							4.5 KiB
						
					
					
				
			
		
		
	
	
							155 lines
						
					
					
						
							4.5 KiB
						
					
					
				using System; | 
						|
using ESRI.ArcGIS.Controls; | 
						|
using ESRI.ArcGIS.esriSystem; | 
						|
using KGIS.Framework.Maps; | 
						|
using KGIS.Framework.Utils; | 
						|
 | 
						|
namespace Kingo.Plugin.EngineEditor.Commands | 
						|
{ | 
						|
    /// <summary> | 
						|
    /// 工具条 捕捉 | 
						|
    /// </summary> | 
						|
    public class BaseSnapCmd : ESRI.ArcGIS.SystemUI.ICommand | 
						|
    { | 
						|
        private IHookHelper m_hookHelper; | 
						|
        private EngineEditorClass m_editor = new EngineEditorClass(); | 
						|
        private ISnappingEnvironment snapEnv = null; | 
						|
        private bool IsChecked = false; | 
						|
        public virtual esriSnappingType SnappingType { get { return esriSnappingType.esriSnappingTypeNone; } } | 
						|
 | 
						|
        public bool Checked | 
						|
        { | 
						|
            get | 
						|
            { | 
						|
                IsChecked = (snapEnv.SnappingType & SnappingType) == SnappingType; | 
						|
                return IsChecked; | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        public virtual void OnCreate(object hook) | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                if (hook == null) return; | 
						|
                if (m_hookHelper == null) | 
						|
                    m_hookHelper = new HookHelper | 
						|
                    { | 
						|
                        Hook = hook | 
						|
                    }; | 
						|
 | 
						|
                if (m_hookHelper.ActiveView == null) | 
						|
                { | 
						|
                    m_hookHelper = null; | 
						|
                    return; | 
						|
                } | 
						|
                if (m_hookHelper is IHookHelper2 hookHelper2) | 
						|
                { | 
						|
                    IExtensionManager extensionManager = hookHelper2.ExtensionManager; | 
						|
                    if (extensionManager != null) | 
						|
                    { | 
						|
                        IExtension extension = extensionManager.FindExtension(new UIDClass | 
						|
                        { | 
						|
                            Value = "{E07B4C52-C894-4558-B8D4-D4050018D1DA}"//捕捉 | 
						|
                        }); | 
						|
                        if (extension != null) | 
						|
                        { | 
						|
                            this.snapEnv = extension as ISnappingEnvironment; | 
						|
                            this.snapEnv.SnappingType = esriSnappingType.esriSnappingTypeIntersection | esriSnappingType.esriSnappingTypeEdge | esriSnappingType.esriSnappingTypeVertex; | 
						|
                        } | 
						|
                    } | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                LogAPI.Debug("加载 BaseSnap 类时失败,异常原因: " + ex + " ; "); | 
						|
                m_hookHelper = null; | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        private IMapService _MapService; | 
						|
 | 
						|
        public virtual void OnClick() | 
						|
        { | 
						|
            try | 
						|
            { | 
						|
                this.IsChecked = !this.IsChecked; | 
						|
                if (this.IsChecked) | 
						|
                { | 
						|
                    if (snapEnv != null) | 
						|
                    { | 
						|
                        if ((snapEnv.SnappingType & SnappingType) != SnappingType) | 
						|
                        { | 
						|
                            snapEnv.SnappingType = snapEnv.SnappingType | SnappingType; | 
						|
                        } | 
						|
                    } | 
						|
                } | 
						|
                else | 
						|
                { | 
						|
                    if (snapEnv != null && (snapEnv.SnappingType & SnappingType) == SnappingType) | 
						|
                    { | 
						|
                        if ((snapEnv.SnappingType ^ SnappingType) == esriSnappingType.esriSnappingTypeNone) | 
						|
                        { | 
						|
                            snapEnv.SnappingType = esriSnappingType.esriSnappingTypeNone; | 
						|
                        } | 
						|
                        else | 
						|
                        { | 
						|
                            if (snapEnv != null && (snapEnv.SnappingType & SnappingType) == SnappingType) | 
						|
                            { | 
						|
                                snapEnv.SnappingType = snapEnv.SnappingType ^ SnappingType; | 
						|
                            } | 
						|
                        } | 
						|
                    } | 
						|
                } | 
						|
            } | 
						|
            catch (Exception ex) | 
						|
            { | 
						|
                LogAPI.Debug(ex); | 
						|
            } | 
						|
        } | 
						|
 | 
						|
        public int Bitmap | 
						|
        { | 
						|
            get { return 0; } | 
						|
        } | 
						|
 | 
						|
        public string Caption | 
						|
        { | 
						|
            get { return ""; } | 
						|
        } | 
						|
 | 
						|
        public string Category | 
						|
        { | 
						|
            get { return ""; } | 
						|
        } | 
						|
 | 
						|
        public bool Enabled | 
						|
        { | 
						|
            get { return m_editor.EditState == esriEngineEditState.esriEngineStateEditing; } | 
						|
        } | 
						|
 | 
						|
        public int HelpContextID | 
						|
        { | 
						|
            get { return 0; } | 
						|
        } | 
						|
 | 
						|
        public string HelpFile | 
						|
        { | 
						|
            get { return ""; } | 
						|
        } | 
						|
 | 
						|
        public string Message | 
						|
        { | 
						|
            get { return ""; } | 
						|
        } | 
						|
 | 
						|
        public string Name | 
						|
        { | 
						|
            get { return ""; } | 
						|
        } | 
						|
 | 
						|
        public virtual string Tooltip | 
						|
        { | 
						|
            get { return ""; } | 
						|
        } | 
						|
    } | 
						|
}
 | 
						|
 |