Select to view content in your preferred language

"Construct Features" button does not trigger IEditEvents_OnCreateFeature?

1000
2
07-18-2010 10:00 AM
RyanClark
Deactivated User
I'm building an Editor Extension that adds functionality to the IEditor.OnCreateFeature event. I noticed that my event handler is not triggered when someone uses the "Construct Features" button on the Topology toolbar.

We frequently use that button to build polygons from lines, and I need those create events to be captured as well. Any suggestions? I'm trying to avoid a ClassExtension...

Thanks,
Ryan
0 Kudos
2 Replies
RyanClark
Deactivated User
Still struggling with this. Is there some reason why the tool would not trigger the OnCreateFeature event? It certainly works through the Editor, as it builds an undo-able Edit Operation...

Here's my code that sets up the extension and the event handlers. This is pretty much out-of-the-box SDK stuff. Still, perhaps I'm doing something wrong?

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Editor;
using ESRI.ArcGIS.Geodatabase;

namespace editorExtension
{
    [Guid("7ec485d2-15af-43e1-ae3f-8c55c93e0317")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("editorExtension.ncgmpEditorExtension")]
    public class ncgmpEditorExtension : ESRI.ArcGIS.esriSystem.IExtension, ESRI.ArcGIS.esriSystem.IExtensionConfig
    {
        private Editor m_Editor;
        private IWorkspace m_EditWorkspace;
        private bool m_DatabaseIsValid = false;
        private sysInfo m_SysInfo;

        #region COM Registration Function(s)
        [ComRegisterFunction()]
        [ComVisible(false)]
        static void RegisterFunction(Type registerType)
        {
            // Required for ArcGIS Component Category Registrar support
            ArcGISCategoryRegistration(registerType);

            //
            // TODO: Add any COM registration code here
            //
        }

        [ComUnregisterFunction()]
        [ComVisible(false)]
        static void UnregisterFunction(Type registerType)
        {
            // Required for ArcGIS Component Category Registrar support
            ArcGISCategoryUnregistration(registerType);

            //
            // TODO: Add any COM unregistration code here
            //
        }

        #region ArcGIS Component Category Registrar generated code
        /// <summary>
        /// Required method for ArcGIS Component Category registration -
        /// Do not modify the contents of this method with the code editor.
        /// </summary>
        private static void ArcGISCategoryRegistration(Type registerType)
        {
            string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
            EditorExtensions.Register(regKey);

        }
        /// <summary>
        /// Required method for ArcGIS Component Category unregistration -
        /// Do not modify the contents of this method with the code editor.
        /// </summary>
        private static void ArcGISCategoryUnregistration(Type registerType)
        {
            string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
            EditorExtensions.Unregister(regKey);

        }

        #endregion
        #endregion

        #region "IExtension Implementations - Event Handlers setup here"
        public string Name
        {
            get
            {
                return "AZGS/NCGMP Extension";
            }
        }

        public void Shutdown()
        {
            // Remove the event handlers
            m_Editor.OnCreateFeature -= new IEditEvents_OnCreateFeatureEventHandler(m_Editor_OnCreateFeature);
            m_Editor.OnChangeFeature -= new IEditEvents_OnChangeFeatureEventHandler(m_Editor_OnChangeFeature);
            m_Editor.OnDeleteFeature -= new IEditEvents_OnDeleteFeatureEventHandler(m_Editor_OnDeleteFeature);
            m_Editor.OnStartEditing -= new IEditEvents_OnStartEditingEventHandler(m_Editor_OnStartEditing);
            m_Editor.OnStopEditing -= new IEditEvents_OnStopEditingEventHandler(m_Editor_OnStopEditing);
        }

        public void Startup(ref object initializationData)
        {
            // InitializationData contains an IEditor reference because of how this class is registered above.
            //  See http://resources.esri.com/help/9.3/arcgisengine/ArcObjects/esriSystem/IExtension_Startup.htm

            // Grab the editor reference and setup events to capture
            m_Editor = (Editor)initializationData;
            m_Editor.OnCreateFeature += new IEditEvents_OnCreateFeatureEventHandler(m_Editor_OnCreateFeature);
            m_Editor.OnChangeFeature += new IEditEvents_OnChangeFeatureEventHandler(m_Editor_OnChangeFeature);
            m_Editor.OnDeleteFeature += new IEditEvents_OnDeleteFeatureEventHandler(m_Editor_OnDeleteFeature);
            m_Editor.OnStartEditing += new IEditEvents_OnStartEditingEventHandler(m_Editor_OnStartEditing);
            m_Editor.OnStopEditing += new IEditEvents_OnStopEditingEventHandler(m_Editor_OnStopEditing);
        }
        
        #endregion
0 Kudos
RyanClark
Deactivated User
Okay, I found the solution, though the API documentation is not very clear at all. I'm using IEditEvents, but since I couldn't get the OnCreateFeature event to fire, I was looking at other options. Looking at the IObjectClassEvents page:
Listeners of the OnCreate event are not necessarily notified every time an object is created. The event is triggered following a call to IRow.Store, and by default this does not occur when objects or simple features are created using an insert cursor. This can be overridden by setting the IWorkspaceEditControl.SetStoreEventsRequired property to true, or by implementing the optional IObjectClassInfo interface on the class' extension.


It turns out this also pertains to the IEditEvents.OnCreateFeature event, although that is not indicated on the IEditEvents help page.

The solution was pretty simple, use the IWorkspaceEditControl.SetStoreEventsRequired(); method during the IEditEvents.OnStartEditing handler. This causes the "Create Features" tool on the topology toolbar to do Row.Store operations rather than use an Insert cursor. I'm guessing there is  going to be a performance hit, but that's the price you pay for the functionality I guess...

       
void m_Editor_OnStartEditing()
        {
            // Check that the workspace being edited is NCGMP-valid.
            m_EditWorkspace = m_Editor.EditWorkspace;
            m_DatabaseIsValid = ncgmpChecks.IsWorkspaceMinNCGMPCompliant(m_EditWorkspace);

            // I have to do this because the topology tool uses an Insert cursor, bypassing the OnCreate event!
            IWorkspaceEditControl wsEditControl = (IWorkspaceEditControl)m_EditWorkspace;
            wsEditControl.SetStoreEventsRequired();
        }
0 Kudos