|
|
|
|
using ESRI.ArcGIS.ADF.BaseClasses;
|
|
|
|
|
using ESRI.ArcGIS.Controls;
|
|
|
|
|
using ESRI.ArcGIS.Display;
|
|
|
|
|
using ESRI.ArcGIS.Geometry;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Kingo.Plugin.General.Tool
|
|
|
|
|
{
|
|
|
|
|
public class DrawPolygonTool : BaseTool
|
|
|
|
|
{
|
|
|
|
|
private EngineEditorClass editor = new EngineEditorClass();
|
|
|
|
|
private IHookHelper m_hookHelper;
|
|
|
|
|
//private EngineSnapAgentClass m_SnapAgent;
|
|
|
|
|
private INewPolygonFeedback m_NewPolygonFeedback;
|
|
|
|
|
private bool IsDrawing = false;
|
|
|
|
|
private List<IPoint> points = new List<IPoint>();
|
|
|
|
|
public event Action<IPolygon> DrawCompleted;
|
|
|
|
|
public DrawPolygonTool()
|
|
|
|
|
{
|
|
|
|
|
base.m_caption = "绘制多边形";
|
|
|
|
|
base.m_toolTip = "左键开始绘制,右键结束绘制";
|
|
|
|
|
base.m_cursor = System.Windows.Forms.Cursors.Cross;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnCreate(object hook)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (hook == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (m_hookHelper == null)
|
|
|
|
|
{
|
|
|
|
|
m_hookHelper = new HookHelperClass();
|
|
|
|
|
m_hookHelper.Hook = hook;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
m_hookHelper = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//this.m_SnapAgent = EngineSnapAgentClass.Instance;
|
|
|
|
|
this.m_NewPolygonFeedback = new NewPolygonFeedbackClass() { Display = this.m_hookHelper.ActiveView.ScreenDisplay };
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
KGIS.Framework.Utils.LogAPI.Debug(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnClick()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
this.m_NewPolygonFeedback = new NewPolygonFeedbackClass() { Display = this.m_hookHelper.ActiveView.ScreenDisplay };
|
|
|
|
|
//this.m_SnapAgent.Reset();
|
|
|
|
|
IsDrawing = true;
|
|
|
|
|
points.Clear();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
KGIS.Framework.Utils.LogAPI.Debug(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnDblClick()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!IsDrawing) return;
|
|
|
|
|
//双击结束绘制
|
|
|
|
|
//IsDrawing = false;
|
|
|
|
|
IPolygon polygon = this.m_NewPolygonFeedback.Stop();
|
|
|
|
|
if (points.Count > 2)
|
|
|
|
|
{
|
|
|
|
|
ITopologicalOperator pTopologicalOperator = polygon as ITopologicalOperator;
|
|
|
|
|
if (!pTopologicalOperator.IsSimple)
|
|
|
|
|
{
|
|
|
|
|
pTopologicalOperator.Simplify();
|
|
|
|
|
}
|
|
|
|
|
OnDrawCompleted(polygon);
|
|
|
|
|
}
|
|
|
|
|
points.Clear();
|
|
|
|
|
//(this.m_hookHelper.Hook as IToolbarBuddy).CurrentTool = new ESRI.ArcGIS.Controls.ControlsMapPanToolClass();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
KGIS.Framework.Utils.LogAPI.Debug(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnMouseDown(int Button, int Shift, int X, int Y)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!IsDrawing) return;
|
|
|
|
|
if (Button == 1)
|
|
|
|
|
{
|
|
|
|
|
//左键开始绘制
|
|
|
|
|
IPoint point = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
|
|
|
|
|
//if (this.m_SnapAgent.HasSnapPoint && (this.m_SnapAgent.SnapedPoint != null))
|
|
|
|
|
//{
|
|
|
|
|
// point = this.m_SnapAgent.SnapedPoint;
|
|
|
|
|
//}
|
|
|
|
|
if (points.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
this.m_NewPolygonFeedback.Start(point);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.m_NewPolygonFeedback.AddPoint(point);
|
|
|
|
|
}
|
|
|
|
|
points.Add(point);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
KGIS.Framework.Utils.LogAPI.Debug(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Deactivate()
|
|
|
|
|
{
|
|
|
|
|
//右键结束绘制
|
|
|
|
|
IsDrawing = false;
|
|
|
|
|
return base.Deactivate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnMouseMove(int Button, int Shift, int X, int Y)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!IsDrawing) return;
|
|
|
|
|
IPoint point = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
|
|
|
|
|
//this.m_SnapAgent.SnapPoint(this.m_hookHelper.ActiveView, point);
|
|
|
|
|
//if (this.m_SnapAgent.HasSnapPoint && (this.m_SnapAgent.SnapedPoint != null))
|
|
|
|
|
//{
|
|
|
|
|
// point = this.m_SnapAgent.SnapedPoint;
|
|
|
|
|
//}
|
|
|
|
|
if (points.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
this.m_NewPolygonFeedback.MoveTo(point);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
KGIS.Framework.Utils.LogAPI.Debug(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void OnDrawCompleted(IPolygon polygon)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (this.DrawCompleted != null)
|
|
|
|
|
DrawCompleted(polygon);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
KGIS.Framework.Utils.LogAPI.Debug(ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|