年度变更建库软件5.0版本
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.

527 lines
21 KiB

using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using KGIS.Framework.EngineEditor;
using KGIS.Framework.Maps;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace Kingo.Plugin.EngineEditor.Commands.Tools
{
public class CmdAddFeatureTool : BaseToolCmd
{
public override void OnCreate(object hook)
{
base.OnCreate(hook);
}
private void ActiveViewEvents_Event_ItemDeleted(object Item)
{
if (EditorSettingClass.Instance.IsTraceing)
{
this.EndTraceFeedback();
}
}
private void ActiveViewEvents_Event_ItemAdded(object Item)
{
if (EditorSettingClass.Instance.IsTraceing)
{
this.EndTraceFeedback();
}
}
private void ActiveViewEvents_Event_ContentsChanged()
{
}
private void M_pAxMapControl_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e)
{
if (EditorSettingClass.Instance.IsTraceing && this.m_pTraceFeedback != null)
{
try
{
this.FillFeatureCache(this.m_pPointCatched);
}
catch (Exception) { }
this.GetBeTracedPolyline();
//GetBeTracedPolyline();
//this.m_pTraceFeedback.SetSplitPolyline(m_pListBeTracePolyline);
this.m_pTraceFeedback.ListBeTracePolyline = this.m_pListBeTracePolyline;
}
}
public override bool Deactivate()
{
base.Deactivate();
MapsManager.Instance.MapService.getAxMapControl().OnExtentUpdated -= M_pAxMapControl_OnExtentUpdated;
IActiveViewEvents_Event activeViewEvents_Event = base.m_pMapControl.ActiveView as IActiveViewEvents_Event;
activeViewEvents_Event.ContentsChanged -= ActiveViewEvents_Event_ContentsChanged;
activeViewEvents_Event.ItemAdded -= ActiveViewEvents_Event_ItemAdded;
activeViewEvents_Event.ItemDeleted -= ActiveViewEvents_Event_ItemDeleted;
this.m_deactivate = true;
return this.m_deactivate;
}
public override void OnClick()
{
base.OnClick();
MapsManager.Instance.MapService.getAxMapControl().OnExtentUpdated += M_pAxMapControl_OnExtentUpdated;
IActiveViewEvents_Event activeViewEvents_Event = base.m_pMapControl.ActiveView as IActiveViewEvents_Event;
activeViewEvents_Event.ContentsChanged += ActiveViewEvents_Event_ContentsChanged;
activeViewEvents_Event.ItemAdded += ActiveViewEvents_Event_ItemAdded;
activeViewEvents_Event.ItemDeleted += ActiveViewEvents_Event_ItemDeleted;
}
public override bool Enabled
{
get
{
if (m_pEditor == null)
{
return false;
}
if (m_pEditor.EditState != esriEngineEditState.esriEngineStateEditing)
{ return false; }
if ((m_pEditor as EngineEditorClass).TargetLayer == null)
{ return false; }
return true;
}
}
public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
if (Button == 1)
{
DisplayFeedbackMethod pDisplayFeedbackMethod = this.m_pDisplayFeedbackMethod;
if (this.m_pGeometry == null)
{
switch (pDisplayFeedbackMethod)
{
case DisplayFeedbackMethod.Line:
this.NewPolyline();
break;
case DisplayFeedbackMethod.Polygon:
this.NewPolygon();
break;
default:
break;
}
}
if (pDisplayFeedbackMethod != DisplayFeedbackMethod.Arc)
{
if (EditorSettingClass.Instance.IsTraceing && (this.m_pDisplayFeedbackMethod == DisplayFeedbackMethod.Polygon || this.m_pDisplayFeedbackMethod == DisplayFeedbackMethod.Line))
{
IPoint p = this.m_pMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
ISnappingResult snappingResult = null;
if (this.m_pSnappingEnv != null && this.m_pSnappingEnv.Enabled)
{
snappingResult = this.m_pPntSnapper.Snap(p);
}
if (snappingResult == null && m_pTraceFeedback == null)
{
m_pTraceFeedback = null;
switch (pDisplayFeedbackMethod)
{
case DisplayFeedbackMethod.Polygon:
this.AddToFeedback(this.m_pPointCatched);
this.AddPointToPolygon(this.m_pPointCatched);
break;
case DisplayFeedbackMethod.Line:
//this.StartFeedback(this.m_pPointCatched);
this.AddToFeedback(this.m_pPointCatched);
this.AddPointToPolyline(this.m_pPointCatched);
break;
}
}
else if (snappingResult == null && m_pTraceFeedback != null)
{
IPolyline polyline = this.AddToTraceFeedBack(this.m_pPointCatched);
if (polyline != null && !polyline.IsEmpty)
{
if (pDisplayFeedbackMethod == DisplayFeedbackMethod.Polygon)
{
this.AddPolylineToPolygon(polyline);
this.AddToFeedback(polyline);
}
else if (pDisplayFeedbackMethod == DisplayFeedbackMethod.Line)
{
this.AddPolylineToPolyline(polyline);
this.AddToFeedback(polyline);
//this.StartFeedback(polyline.ToPoint);
}
}
}
else
{
base.ListSelectableLayer = MapsManager.Instance.MapService.GetAllVisibleLayerInMap<IFeatureLayer>();
//GetAllFeatureLayer();
//if (this.m_pListFeatureCache == null)
//{
try
{
this.FillFeatureCache(this.m_pPointCatched);
}
catch (Exception) { }
this.GetBeTracedPolyline();
//}
IPolyline polyline = this.AddToTraceFeedBack(this.m_pPointCatched);
if (polyline != null && !polyline.IsEmpty)
{
if (pDisplayFeedbackMethod == DisplayFeedbackMethod.Polygon)
{
this.AddPolylineToPolygon(polyline);
this.AddToFeedback(polyline);
}
else if (pDisplayFeedbackMethod == DisplayFeedbackMethod.Line)
{
this.AddPolylineToPolyline(polyline);
this.AddToFeedback(polyline);
//this.StartFeedback(polyline.ToPoint);
}
}
}
}
else
{
m_pTraceFeedback = null;
switch (pDisplayFeedbackMethod)
{
case DisplayFeedbackMethod.Polygon:
this.AddToFeedback(this.m_pPointCatched);
this.AddPointToPolygon(this.m_pPointCatched);
break;
case DisplayFeedbackMethod.Line:
//this.StartFeedback(this.m_pPointCatched);
this.AddToFeedback(this.m_pPointCatched);
this.AddPointToPolyline(this.m_pPointCatched);
break;
}
}
}
else if (this.m_nArcPointCount == 0)
{
IPointCollection pointCollection = this.m_pGeometry as IPointCollection;
int pointCount = pointCollection.PointCount;
if (pointCount >= 1)
{
IPoint pPoint = pointCollection.get_Point(pointCount - 1);
this.AddToArcFeedback(pPoint);
this.AddToArcFeedback(this.m_pPointCatched);
}
else
{
this.AddToArcFeedback(this.m_pPointCatched);
}
}
else if (this.m_nArcPointCount != 1)
{
if (this.m_nArcPointCount == 2)
{
ICircularArc circularArc = this.AddToArcFeedback(this.m_pPointCatched);
if (circularArc != null)
{
this.AddSegmentToPolygon(circularArc as ISegment);
this.AddToFeedback((circularArc as ISegment).ToPoint);
}
}
}
else
{
this.AddToArcFeedback(this.m_pPointCatched);
}
if (this.m_pPointCatched != null)
{
this.SketchGeometry.Update();
}
this.RefreshForeground(null);
}
}
public override void OnMouseMove(int Button, int Shift, int X, int Y)
{
if (Button == 4)
{
return;
}
this.m_pPointCatched = this.m_pMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
if (this.m_pSnappingEnv != null && this.m_pSnappingEnv.Enabled)
{
ISnappingResult snappingResult = this.m_pPntSnapper.Snap(this.m_pPointCatched);
this.m_pSnappingFeedback.Update(snappingResult, 0);
if (snappingResult != null)
{
this.m_pPointCatched = snappingResult.Location;
}
}
string strDescription = "";
IPoint point = null;
if (this.m_pSnappingEnv != null && this.m_pSnappingEnv.Enabled && SnappingSketchFeedback.Enabled)
{
this.RefreshForeground(null);
point = base.SnappingSketch(this.m_pPointCatched, ref strDescription);
if (point != null)
{
this.m_pPointCatched = point;
}
}
try
{
DisplayFeedbackMethod pDisplayFeedbackMethod = this.m_pDisplayFeedbackMethod;
if (pDisplayFeedbackMethod == DisplayFeedbackMethod.Arc)
{
if (this.m_pNewArcFeedback == null && this.m_pDisplayFeedback != null)
{
this.m_pDisplayFeedback.MoveTo(this.m_pPointCatched);
}
if (this.m_pNewArcFeedback != null)
{
if (this.m_nArcPointCount == 2)
{
(this.m_pNewArcFeedback as IDisplayFeedback).MoveTo(this.m_pPointCatched);
}
}
}
else
{
if (EditorSettingClass.Instance.IsTraceing && (this.m_pDisplayFeedbackMethod == DisplayFeedbackMethod.Polygon || this.m_pDisplayFeedbackMethod == DisplayFeedbackMethod.Line))
{
if (this.m_pTraceFeedback == null && this.m_pDisplayFeedback != null)
{
this.m_pDisplayFeedback.MoveTo(this.m_pPointCatched);
}
if (this.m_pTraceFeedback != null)
{
this.m_pTraceFeedback.MoveTo(this.m_pPointCatched);
this.RefreshForeground(null);
}
}
else
{
switch (pDisplayFeedbackMethod)
{
case DisplayFeedbackMethod.Polygon:
if (this.m_pDisplayFeedback != null)
{
this.m_pDisplayFeedback.MoveTo(this.m_pPointCatched);
}
break;
case DisplayFeedbackMethod.Line:
if (this.m_pDisplayFeedback != null)
{
this.m_pDisplayFeedback.MoveTo(this.m_pPointCatched);
}
break;
}
}
}
}
catch (Exception ex)
{
//FormReportException.Report(ex);
}
if (point != null)
{
this.m_pSnappingSketchFeedback.Update(point, strDescription);
}
}
public override void Refresh(int hDC)
{
if (this.m_pSnappingFeedback != null)
{
this.m_pSnappingFeedback.Refresh(hDC);
}
if (this.m_pDisplayFeedback != null)
{
this.m_pDisplayFeedback.Refresh(hDC);
}
if (EditorSettingClass.Instance.IsTraceing && this.m_pTraceFeedback != null)
{
this.m_pTraceFeedback.Refresh(hDC);
}
}
public override void ReStartFeedback()
{
IPointCollection pointCollection = null;
int num = 0;
if (this.m_pGeometry != null || !this.m_pGeometry.IsEmpty)
{
IGeometryCollection geometryCollection = this.m_pGeometry as IGeometryCollection;
int geometryCount = geometryCollection.GeometryCount;
if (geometryCount > 0)
{
this.m_pRing = (geometryCollection.get_Geometry(geometryCollection.GeometryCount - 1) as IRing);
pointCollection = (this.m_pRing as IPointCollection);
num = pointCollection.PointCount;
}
else
{
this.m_pRing = null;
}
}
this.EndFeedback();
this.EndArcFeedback();
this.EndTraceFeedback();
if (pointCollection != null)
{
for (int i = 0; i < num; i++)
{
this.AddToFeedback(pointCollection.get_Point(i));
}
}
this.RefreshForeground(null);
}
public override void OnMouseUp(int Button, int Shift, int X, int Y)
{
base.OnMouseUp(Button, Shift, X, Y);
}
public override void OnKeyDown(int keyCode, int Shift)
{
base.OnKeyDown(keyCode, Shift);
}
public override void OnKeyUp(int keyCode, int Shift)
{
base.OnKeyUp(keyCode, Shift);
}
public override void OnDblClick()
{
try
{
FinishSketch();
}
catch (Exception ex)
{
LogAPI.Debug(ex.Message);
MessageHelper.ShowError(ex.Message);
}
}
public bool CanFinishedPart
{
get
{
if (this.m_pRing != null)
{
return (this.m_pRing as IPointCollection).PointCount > 1;
}
if (this.m_pPath != null)
{
return (this.m_pPath as IPointCollection).PointCount > 1;
}
return false;
}
}
// Token: 0x170000E7 RID: 231
// (get) Token: 0x0600069E RID: 1694 RVA: 0x00059DD8 File Offset: 0x00057FD8
public bool CanFinishedAll
{
get
{
if (this.m_pRing != null)
{
return (this.m_pRing as IPointCollection).PointCount > 1;
}
if (this.m_pPath != null)
{
return (this.m_pPath as IPointCollection).PointCount > 1;
}
return this.m_pGeometry != null && (this.m_pGeometry as IPointCollection).PointCount > 1;
}
}
// Token: 0x170000E8 RID: 232
// (get) Token: 0x0600069F RID: 1695 RVA: 0x00058598 File Offset: 0x00056798
public bool CanDeleteNew
{
get
{
return this.m_pGeometry != null;
}
}
public void DeleteSketch()
{
this.EndFeedback();
this.DeletePolygon();
this.DeletePolyline();
this.RefreshForeground(null);
}
// Token: 0x060006A1 RID: 1697 RVA: 0x00059E4C File Offset: 0x0005804C
public void FinishPart()
{
if (this.m_pDisplayFeedback == null)
{
return;
}
this.EndFeedback();
this.EndPolygonPart();
this.EndPolylinePart();
this.RefreshForeground(null);
}
// Token: 0x060006A2 RID: 1698 RVA: 0x00059E7C File Offset: 0x0005807C
public void FinishSketch()
{
this.EndFeedback();
this.EndArcFeedback();
this.EndTraceFeedback();
if (m_pDisplayFeedbackMethod == DisplayFeedbackMethod.Polygon)
{
this.EndPolygon();
if (this.m_pGeometry != null && (this.m_pGeometry as IPointCollection).PointCount > 2)
{
if (!(m_pGeometry as IPolygon).IsClosed)
{
(m_pGeometry as IPolygon).Close();
}
(this.m_pGeometry as IPolygon).SimplifyPreserveFromTo();
if (!this.m_pGeometry.IsEmpty)
{
IEngineEditSketch editSketch = m_pEditor as IEngineEditSketch;
editSketch.Geometry = m_pGeometry;
editSketch.FinishSketch();
if (EditorSettingClass.Instance.OnDrawEnd != null)
{
EditorSettingClass.Instance.OnDrawEnd(this, this.m_pGeometry);
}
}
}
}
else if (m_pDisplayFeedbackMethod == DisplayFeedbackMethod.Line)
{
this.m_pPntSnapper.ClearCache();
this.EndPolyline();
if (this.m_pGeometry != null && (this.m_pGeometry as IPointCollection).PointCount >= 2)
{
if (!this.m_pGeometry.IsEmpty)
{
IPolyline polyline = this.m_pGeometry as IPolyline;
polyline.SimplifyNetwork();
if (EditorSettingClass.Instance.OnDrawEnd != null)
{
EditorSettingClass.Instance.OnDrawEnd(this, this.m_pGeometry);
}
}
}
}
ComReleaser.ReleaseCOMObject(this.m_pGeometry);
this.m_pGeometry = null;
ComReleaser.ReleaseCOMObject(this.m_pPath);
this.m_pPath = null;
ComReleaser.ReleaseCOMObject(this.m_pRing);
this.m_pRing = null;
if (this.SketchGeometry != null)
{
this.SketchGeometry.Deactivate();
this.SketchGeometry = null;
}
this.RefreshForeground(null);
}
}
}