Skip to content
Permalink
master
Go to file
 
 
Cannot retrieve contributors at this time
131 lines (117 sloc) 4.68 KB
/*
Copyright 2019 Esri
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ESRI.ArcGIS.Editor;
using ESRI.ArcGIS.Geodatabase;
namespace AddInEditorExtension
{
/// <summary>
/// ValidateFeaturesExtension class implementing custom ESRI Editor Extension functionalities.
/// </summary>
public class ValidateFeaturesExtension : ESRI.ArcGIS.Desktop.AddIns.Extension
{
public ValidateFeaturesExtension()
{
}
//Invoked when the Editor Extension is loaded
protected override void OnStartup()
{
Events.OnStartEditing += new IEditEvents_OnStartEditingEventHandler(Events_OnStartEditing);
Events.OnStopEditing += new IEditEvents_OnStopEditingEventHandler(Events_OnStopEditing);
}
//Invoked at the Start of editor session
void Events_OnStartEditing()
{
//Since features of shapefiles, coverages etc cannot be validated, ignore wiring events for them
if (ArcMap.Editor.EditWorkspace.Type != esriWorkspaceType.esriFileSystemWorkspace)
{
//wire OnCreateFeature Edit event
Events.OnCreateFeature += new IEditEvents_OnCreateFeatureEventHandler(Events_OnCreateChangeFeature);
//wire onChangeFeature Edit Event
Events.OnChangeFeature += new IEditEvents_OnChangeFeatureEventHandler(Events_OnCreateChangeFeature);
}
}
//Invoked at the end of Editor session (Editor->Stop Editing)
void Events_OnStopEditing(bool Save)
{
//Since features of shapefiles, coverages etc cannot be validated, ignore wiring events for them
if (ArcMap.Editor.EditWorkspace.Type != esriWorkspaceType.esriFileSystemWorkspace)
{
//unwire OnCreateFeature Edit event
Events.OnCreateFeature -= new IEditEvents_OnCreateFeatureEventHandler(Events_OnCreateChangeFeature);
//unwire onChangeFeature Edit Event
Events.OnChangeFeature -= new IEditEvents_OnChangeFeatureEventHandler(Events_OnCreateChangeFeature);
}
}
void Events_OnCreateChangeFeature(ESRI.ArcGIS.Geodatabase.IObject obj)
{
IFeature inFeature = (IFeature)obj;
if (inFeature.Class is IValidation)
{
IValidate validate = (IValidate)inFeature;
string errorMessage;
//Validates connectivity rules, relationship rules, topology rules etc
bool bIsvalid = validate.Validate(out errorMessage);
if (!bIsvalid)
{
System.Windows.Forms.MessageBox.Show("Invalid Feature\n\n" + errorMessage);
}
else
{
System.Windows.Forms.MessageBox.Show("Valid Feature");
}
}
}
protected override void OnShutdown()
{
}
#region Editor Events
#region Shortcut properties to the various editor event interfaces
private IEditEvents_Event Events
{
get { return ArcMap.Editor as IEditEvents_Event; }
}
private IEditEvents2_Event Events2
{
get { return ArcMap.Editor as IEditEvents2_Event; }
}
private IEditEvents3_Event Events3
{
get { return ArcMap.Editor as IEditEvents3_Event; }
}
private IEditEvents4_Event Events4
{
get { return ArcMap.Editor as IEditEvents4_Event; }
}
#endregion
void WireEditorEvents()
{
//
// TODO: Sample code demonstrating editor event wiring
//
Events.OnCurrentTaskChanged += delegate
{
if (ArcMap.Editor.CurrentTask != null)
System.Windows.Forms.MessageBox.Show(ArcMap.Editor.CurrentTask.Name);
};
Events2.BeforeStopEditing += delegate(bool save) { OnBeforeStopEditing(save); };
}
void OnBeforeStopEditing(bool save)
{
}
#endregion
}
}
You can’t perform that action at this time.