Beispiel #1
0
        public override void OnCreate(object Hook)
        {
            base.OnCreate(Hook);
            m_HookHelper = m_Hook.Hook as IHookHelper;
            if (m_HookHelper == null)
            {
                return;
            }

            this.m_EsriBuddy = m_HookHelper.Hook as IToolbarBuddy;

            //if ((esriHook ==null) || (m_EsriBuddy == null))
            //{
            //    throw new Exception("ESRI命令代理类初始化错误:内部错误,Hook不是正确的ESRI MapControl或PageLayout对象。");
            //}

            try
            {
                m_EsriCommand.OnCreate(m_HookHelper.Hook);
            }
            catch
            {
                //throw new Exception(string.Format("当前Hook对象不是命令【{0}】的正确Hook。", m_EsriCommand.Name));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Occurs when this tool is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add ToolSplitLine.OnClick implementation
            //Find the Modify Feature task and set it as the current task
            IEngineEditTask editTask = m_engineEditor.GetTaskByUniqueName("ControlToolsEditing_ModifyFeatureTask");

            m_engineEditor.CurrentTask = editTask;

            IEngineEditLayers editLayers = m_editLayer;

            snapEnvironment = m_engineEditor as IEngineSnapEnvironment;
            pt = new PointClass();
            //Check the user is editing; otherwise, there will be no snap agent loaded.
            if (editLayers.TargetLayer == null)
            {
                System.Windows.Forms.MessageBox.Show("Please start an edit session");
                return;
            }

            ////Create a feature snap agent.
            IEngineFeatureSnapAgent featureSnapAgent  = new EngineFeatureSnap();
            IFeatureClass           layerFeatureClass = editLayers.TargetLayer.FeatureClass;

            featureSnapAgent.FeatureClass = layerFeatureClass;
            featureSnapAgent.HitType      = esriGeometryHitPartType.esriGeometryPartBoundary;

            //Activate only the snap agent for the target layer.
            snapEnvironment.AddSnapAgent(featureSnapAgent);
            pMPfeedback         = new MovePointFeedbackClass();
            pMPfeedback.Display = m_hookHelper.ActiveView.ScreenDisplay;
            pMPfeedback.Start(pt, pt);

            IToolbarBuddy toolbarbuddy = (IToolbarBuddy)((IToolbarControl)m_hookHelper.Hook).Buddy;

            oldtool = toolbarbuddy.CurrentTool;
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public override void OnCreate(object Hook)
        {
            base.OnCreate(Hook);
            m_HookHelper = m_Hook.Hook as IHookHelper;
            if (m_HookHelper == null)
                return;

            this.m_EsriBuddy = m_HookHelper.Hook as IToolbarBuddy;

            //if ((esriHook ==null) || (m_EsriBuddy == null))
            //{
            //    throw new Exception("ESRI命令代理类初始化错误:内部错误,Hook不是正确的ESRI MapControl或PageLayout对象。");
            //}

            try
            {
                m_EsriCommand.OnCreate(m_HookHelper.Hook);
            }
            catch
            {
                //throw new Exception(string.Format("当前Hook对象不是命令【{0}】的正确Hook。", m_EsriCommand.Name));
            }
        }