You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
178 lines
5.6 KiB
178 lines
5.6 KiB
using ESRI.ArcGIS.ADF.BaseClasses; |
|
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.Controls; |
|
using ESRI.ArcGIS.Display; |
|
using ESRI.ArcGIS.Geometry; |
|
using System; |
|
|
|
|
|
namespace Kingo.Plugin.General.Tool |
|
{ |
|
public class DrawPointTool : BaseTool |
|
{ |
|
private EngineEditorClass editor = new EngineEditorClass(); |
|
//private IEngineSnapEnvironment snapEnv = null; |
|
private IHookHelper m_hookHelper; |
|
//private EngineSnapAgentClass m_SnapAgent; |
|
private INewLineFeedback m_NewPolygonFeedback; |
|
private bool IsDrawing = false; |
|
public event Action<IPoint> DrawCompleted; |
|
private IPoint snapPoint; |
|
private bool m_isHasSnap; |
|
private IPoint point = null; |
|
public DrawPointTool() |
|
{ |
|
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; |
|
} |
|
//snapEnv = (IEngineSnapEnvironment)editor; |
|
this.m_NewPolygonFeedback = new NewLineFeedbackClass() { Display = this.m_hookHelper.ActiveView.ScreenDisplay }; |
|
} |
|
catch (Exception ex) |
|
{ |
|
KGIS.Framework.Utils.LogAPI.Debug(ex); |
|
} |
|
} |
|
|
|
public override void OnClick() |
|
{ |
|
//this.m_SnapAgent.Reset(); |
|
IsDrawing = true; |
|
point = new Point(); |
|
} |
|
|
|
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 (snapEnv != null) |
|
//{ |
|
// snapEnv.SnapPoint(point); |
|
//} |
|
//if (points.Count == 0) |
|
//{ |
|
// this.m_NewPolygonFeedback.Start(point); |
|
//} |
|
//else |
|
//{ |
|
// this.m_NewPolygonFeedback.AddPoint(point); |
|
//} |
|
//points.Add(point); |
|
OnDrawCompleted(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); |
|
//if (snapEnv != null) |
|
//{ |
|
// this.SnapPoint(m_hookHelper.ActiveView, point, snapEnv); |
|
//} |
|
if (point != null) |
|
{ |
|
this.m_NewPolygonFeedback.MoveTo(point); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
KGIS.Framework.Utils.LogAPI.Debug(ex); |
|
} |
|
} |
|
|
|
public void SnapPoint(IActiveView activeView, IPoint inPoint, IEngineSnapEnvironment m_editEnvironment) |
|
{ |
|
try |
|
{ |
|
if (this.m_isHasSnap && (this.snapPoint != null)) |
|
{ |
|
this.DrawSnapPoint(activeView, this.snapPoint); |
|
} |
|
this.m_isHasSnap = ((IEngineSnapEnvironment)m_editEnvironment).SnapPoint(inPoint); |
|
if (this.m_isHasSnap) |
|
{ |
|
this.snapPoint = inPoint; |
|
this.DrawSnapPoint(activeView, this.snapPoint); |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
KGIS.Framework.Utils.LogAPI.Debug(ex); |
|
} |
|
} |
|
|
|
private void DrawSnapPoint(IActiveView activeView, IPoint point) |
|
{ |
|
try |
|
{ |
|
IScreenDisplay screenDisplay = activeView.ScreenDisplay; |
|
screenDisplay.StartDrawing(screenDisplay.hDC, -1); |
|
IEngineEditProperties engProperties = new EngineEditorClass(); |
|
screenDisplay.SetSymbol((ISymbol)engProperties.SnapSymbol); |
|
screenDisplay.DrawPoint(point); |
|
screenDisplay.FinishDrawing(); |
|
screenDisplay = null; |
|
} |
|
catch (Exception ex) |
|
{ |
|
KGIS.Framework.Utils.LogAPI.Debug(ex); |
|
} |
|
} |
|
|
|
public virtual void OnDrawCompleted(IPoint polygon) |
|
{ |
|
try |
|
{ |
|
if (this.DrawCompleted != null) |
|
DrawCompleted(polygon); |
|
} |
|
catch (Exception ex) |
|
{ |
|
KGIS.Framework.Utils.LogAPI.Debug(ex); |
|
} |
|
} |
|
} |
|
} |