Академический Документы
Профессиональный Документы
Культура Документы
//
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
//
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
//
// See use restrictions at <your ArcGIS install
location>/developerkit/userestrictions.txt.
//
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Resources;
using System.Reflection;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.DataSourcesGDB;
namespace VertexCommands_CS
{
/// <summary>
/// Contains 2 tools to insert or delete vertices
/// </summary>
[Guid("ABB153D1-6884-4b45-8F34-9CCA63E4A380")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("VertexCommands_CS.CustomVertexCommands")]
public sealed class CustomVertexCommands : BaseTool, ICommandSubType
{
#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType);
}
[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType);
}
#endregion
#endregion
#endregion
public CustomVertexCommands()
{
#region load the cursors
try
{
m_InsertVertexCursor = new
System.Windows.Forms.Cursor(GetType().Assembly.GetManifestResourceStream("VertexCom
mands_CS.InsertVertexCursor.cur"));
m_DeleteVertexCursor = new
System.Windows.Forms.Cursor(GetType().Assembly.GetManifestResourceStream("VertexCom
mands_CS.DeleteVertexCursor.cur"));
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Cursor");
}
#endregion
}
#endregion
switch (m_lSubType)
{
case 1:
iHandle = m_InsertVertexCursor.Handle.ToInt32();
break;
case 2:
iHandle = m_DeleteVertexCursor.Handle.ToInt32();
break;
}
return (iHandle);
}
}
/// <summary>
/// Occurs when this tool is created
/// </summary>
/// <param name="hook">Instance of the application</param>
public override void OnCreate(object hook)
{
try
{
m_hookHelper = new HookHelperClass();
m_hookHelper.Hook = hook;
m_engineEditor = new EngineEditorClass(); //this class is a
singleton
m_editLayer = m_engineEditor as IEngineEditLayers;
}
catch
{
m_hookHelper = null;
}
}
/// <summary>
/// Perform checks so that the tool is enabled appropriately
/// </summary>
public override bool Enabled
{
get
{
//check whether Editing
if (m_engineEditor.EditState ==
esriEngineEditState.esriEngineStateNotEditing)
{
return false;
}
/// <summary>
/// The mouse up performs the action appropriate for each sub-typed
command:
/// insert vertex, add vertex or delete vertex
/// </summary>
/// <param name="Button"></param>
/// <param name="Shift"></param>
/// <param name="X">The X screen coordinate of the clicked location</param>
case 2:
hitPartType =
esriGeometryHitPartType.esriGeometryPartVertex;
break;
}
#endregion
//check whether the HitTest was successful (i.e within the search
radius)
if (hitPoint.IsEmpty == false)
{
IEngineSketchOperation sketchOp = new
EngineSketchOperationClass();
sketchOp.Start(m_engineEditor);
switch (m_lSubType)
{
case 1: //Insert Vertex
pathOrRingPointCollection.RemovePoints(hitSegmentIndex,
1);
sketchOp.SetMenuString("Delete Vertex (Custom)");
opType =
esriEngineSketchOperationType.esriEngineSketchOperationVertexDeleted;
break;
}
}
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Unexpected Error");
}
}
#endregion
/// <summary>
/// Returns the number of subtyped commands
/// </summary>
/// <returns></returns>
public int GetCount()
{
return 2;
}
/// <summary>
/// Sets the sub-type
/// </summary>
/// <param name="SubType"></param>
public void SetSubType(int SubType)
{
m_lSubType = SubType;
base.m_caption =
(string)rm.GetString("InsertVertex_CommandCaption");
base.m_message =
(string)rm.GetString("InsertVertex_CommandMessage");
base.m_toolTip =
(string)rm.GetString("InsertVertex_CommandToolTip");
base.m_name = "VertexCommands_CustomInsertVertex";
base.m_cursor = m_InsertVertexCursor;
#region bitmap
try
{
base.m_bitmap =
(System.Drawing.Bitmap)rm.GetObject("InsertVertex");
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid
Bitmap");
}
#endregion
break;
base.m_caption =
(string)rm.GetString("DeleteVertex_CommandCaption");
base.m_message =
(string)rm.GetString("DeleteVertex_CommandMessage");
base.m_toolTip =
(string)rm.GetString("DeleteVertex_CommandToolTip");
base.m_name = "VertexCommands_CustomDeleteVertex";
base.m_cursor = m_DeleteVertexCursor;
#region bitmap
try
{
base.m_bitmap =
(System.Drawing.Bitmap)rm.GetObject("DeleteVertex");
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid
Bitmap");
}
#endregion
break;
}
}
#endregion
}