Select to view content in your preferred language

Implementing the EditTool

3127
2
01-24-2011 05:24 AM
by Anonymous User
Not applicable
Hi,

I'm trying to implement the EditTool in my own class. Using VB.NET I was able to get this working. Now I've converted to C# and can get it working.

The code does not crash, but somehow the edittool is not hooked.

Any ideas?




    public sealed class Modify : BaseCommand, ITool, IEditTool
    {
        #region COM Registration Function(s)
        private IApplication m_Application;
        private IXEIZExtension m_EditorExt;

        private XEIZ.WebService.EditService m_EditService;
        private IEditor m_Editor;
        private string m_TableName;
        private string m_FeatureID;
        private IList<ARCLayerInfo> m_FeatureLayerList = new List<ARCLayerInfo>();

        private ICommand m_EditCommand;
        private ITool m_EditTool;
        private IEditTool m_TheEditTool;

        public event XEIZPlugin.Edit.ModifyVertexHandler VertexModified;

        public Modify()
        {
            try
            {
                string bitmapResourceName = GetType().Name + ".bmp";
                base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
            }
        }

        #region Overriden Class Methods

        /// <summary>
        /// Occurs when this tool is created
        /// </summary>
        /// <param name="hook">Instance of the application</param>
        public override void OnCreate(object hook)
        {
            m_Application = hook as IApplication;

            //Disable if it is not ArcMap
            if (hook is IMxApplication)
                base.m_enabled = true;
            else
                base.m_enabled = false;

            m_EditCommand = new ControlsEditingEditToolClass();
            m_EditCommand.OnCreate(hook);
            m_EditTool = m_EditCommand as ITool;
            m_TheEditTool = m_EditCommand as IEditTool;


        }

        public override bool Enabled
        {
            get
            {
                return true            }
        }
        /// <summary>
        /// Occurs when this tool is clicked
        /// </summary>
        public override void OnClick()
        {

            //Get the editor.
            UID editorUID = new UIDClass();
            editorUID.Value = "esricore.editor";
            m_Editor = Program.App.FindExtensionByCLSID(editorUID) as IEditor;

            //get a reference to editable layer
            IFeatureLayer featureLayer = m_FeatureLayerList[0].pLayer as IFeatureLayer;
            IFeatureClass featureClass = featureLayer.FeatureClass;
            IDataset dataset = featureClass as IDataset;
            IEditLayers editLayers;

            //start an edit session on the selected layer
            m_Editor.StartEditing(dataset.Workspace);
            editLayers = m_Editor as IEditLayers;

            editLayers.SetCurrentLayer(featureLayer, 0);
            //set the editor task to modify features
            for (int i = 0; i < m_Editor.TaskCount; i++)
            {
                if (m_Editor.get_Task(i).Name.ToUpper() == "MODIFY FEATURE")
                {
                    m_Editor.CurrentTask = m_Editor.get_Task(i);
                }
            }

            m_Application.CurrentTool = m_EditTool as ICommandItem;

            m_EditCommand.OnClick();

        }


#endregion
    
        #region ITool Members

            int  ITool.Cursor
            {
             get { return m_EditTool.Cursor; }
            }

            bool  ITool.Deactivate()
            {
                //unwire the event
                if (m_Editor != null)
                {
                    ((IEditEvents_Event)m_Editor).OnSketchFinished -= new IEditEvents_OnSketchFinishedEventHandler(OnSketchFinished);
                }
                return true;
            }

            bool  ITool.OnContextMenu(int x, int y)
            {
                m_EditTool.OnContextMenu(x, y);
                return true;
            }

            void  ITool.OnDblClick()
            {
                m_EditTool.OnDblClick();
            }

            void  ITool.OnKeyDown(int keyCode, int shift)
            {
                m_EditTool.OnKeyDown(keyCode, shift);
            }

            void  ITool.OnKeyUp(int keyCode, int shift)
            {
                m_EditTool.OnKeyUp(keyCode, shift);
            }

            void  ITool.OnMouseDown(int button, int shift, int x, int y)
            {
                if (m_Editor.EditState == esriEditState.esriStateEditing)
                {
                    m_EditTool.OnMouseDown(button, shift, x, y);
                }
            }

            void  ITool.OnMouseMove(int button, int shift, int x, int y)
            {
                m_EditTool.OnMouseMove(button, shift, x, y);
            }

            void  ITool.OnMouseUp(int button, int shift, int x, int y)
            {
                m_EditTool.OnMouseUp(button, shift, x, y);
            }

            void  ITool.Refresh(int hdc)
            {
                m_EditTool.Refresh(hdc);
            }

        #endregion

        #region IEditTool Members

            object  IEditTool.EventSource
            {
             get { return m_TheEditTool.EventSource ; }
            }

        #endregion
}
}
0 Kudos
2 Replies
Venkata_RaoTammineni
Regular Contributor
Hi,

I'm trying to implement the EditTool in my own class. Using VB.NET I was able to get this working. Now I've converted to C# and can get it working.

The code does not crash, but somehow the edittool is not hooked.

Any ideas?




    public sealed class Modify : BaseCommand, ITool, IEditTool
    {
        #region COM Registration Function(s)
        private IApplication m_Application;
        private IXEIZExtension m_EditorExt;

        private XEIZ.WebService.EditService m_EditService;
        private IEditor m_Editor;
        private string m_TableName;
        private string m_FeatureID;
        private IList<ARCLayerInfo> m_FeatureLayerList = new List<ARCLayerInfo>();

        private ICommand m_EditCommand;
        private ITool m_EditTool;
        private IEditTool m_TheEditTool;

        public event XEIZPlugin.Edit.ModifyVertexHandler VertexModified;

        public Modify()
        {
            try
            {
                string bitmapResourceName = GetType().Name + ".bmp";
                base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
            }
        }

        #region Overriden Class Methods

        /// <summary>
        /// Occurs when this tool is created
        /// </summary>
        /// <param name="hook">Instance of the application</param>
        public override void OnCreate(object hook)
        {
            m_Application = hook as IApplication;

            //Disable if it is not ArcMap
            if (hook is IMxApplication)
                base.m_enabled = true;
            else
                base.m_enabled = false;

            m_EditCommand = new ControlsEditingEditToolClass();
            m_EditCommand.OnCreate(hook);
            m_EditTool = m_EditCommand as ITool;
            m_TheEditTool = m_EditCommand as IEditTool;


        }

        public override bool Enabled
        {
            get
            {
                return true            }
        }
        /// <summary>
        /// Occurs when this tool is clicked
        /// </summary>
        public override void OnClick()
        {

            //Get the editor.
            UID editorUID = new UIDClass();
            editorUID.Value = "esricore.editor";
            m_Editor = Program.App.FindExtensionByCLSID(editorUID) as IEditor;

            //get a reference to editable layer
            IFeatureLayer featureLayer = m_FeatureLayerList[0].pLayer as IFeatureLayer;
            IFeatureClass featureClass = featureLayer.FeatureClass;
            IDataset dataset = featureClass as IDataset;
            IEditLayers editLayers;

            //start an edit session on the selected layer
            m_Editor.StartEditing(dataset.Workspace);
            editLayers = m_Editor as IEditLayers;

            editLayers.SetCurrentLayer(featureLayer, 0);
            //set the editor task to modify features
            for (int i = 0; i < m_Editor.TaskCount; i++)
            {
                if (m_Editor.get_Task(i).Name.ToUpper() == "MODIFY FEATURE")
                {
                    m_Editor.CurrentTask = m_Editor.get_Task(i);
                }
            }

            m_Application.CurrentTool = m_EditTool as ICommandItem;

            m_EditCommand.OnClick();

        }


#endregion
    
        #region ITool Members

            int  ITool.Cursor
            {
             get { return m_EditTool.Cursor; }
            }

            bool  ITool.Deactivate()
            {
                //unwire the event
                if (m_Editor != null)
                {
                    ((IEditEvents_Event)m_Editor).OnSketchFinished -= new IEditEvents_OnSketchFinishedEventHandler(OnSketchFinished);
                }
                return true;
            }

            bool  ITool.OnContextMenu(int x, int y)
            {
                m_EditTool.OnContextMenu(x, y);
                return true;
            }

            void  ITool.OnDblClick()
            {
                m_EditTool.OnDblClick();
            }

            void  ITool.OnKeyDown(int keyCode, int shift)
            {
                m_EditTool.OnKeyDown(keyCode, shift);
            }

            void  ITool.OnKeyUp(int keyCode, int shift)
            {
                m_EditTool.OnKeyUp(keyCode, shift);
            }

            void  ITool.OnMouseDown(int button, int shift, int x, int y)
            {
                if (m_Editor.EditState == esriEditState.esriStateEditing)
                {
                    m_EditTool.OnMouseDown(button, shift, x, y);
                }
            }

            void  ITool.OnMouseMove(int button, int shift, int x, int y)
            {
                m_EditTool.OnMouseMove(button, shift, x, y);
            }

            void  ITool.OnMouseUp(int button, int shift, int x, int y)
            {
                m_EditTool.OnMouseUp(button, shift, x, y);
            }

            void  ITool.Refresh(int hdc)
            {
                m_EditTool.Refresh(hdc);
            }

        #endregion

        #region IEditTool Members

            object  IEditTool.EventSource
            {
             get { return m_TheEditTool.EventSource ; }
            }

        #endregion
}
}


You suppose to fullfill the below requirement.. I think..

  public Modify()
        {
            base.m_category = "Test"; //localizable text
            base.m_caption = "Test";  //localizable text
            base.m_message = "This should work in ArcMap/MapControl/PageLayoutControl";         

            //localizable text
            base.m_toolTip = "Test";  //localizable text
            base.m_name = "test";   //unique id, non-localizable (e.g. "MyCategory_MyCommand")

            try
            {
                string bitmapResourceName = GetType().Name + ".bmp";
                base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
            }
        }
0 Kudos
by Anonymous User
Not applicable
That's not the problem I'm afraid. Somehow the Edit Tool is not activated through this implementation, but I can't see where.
0 Kudos