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

642 lines
27 KiB

using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.SystemUI;
using KGIS.Framework.AE;
using KGIS.Framework.EngineEditor;
using KGIS.Framework.Maps;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using Kingo.Plugin.EngineEditor.Common;
using Kingo.Plugin.EngineEditor.Model;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using UIShell.OSGi;
namespace Kingo.Plugin.EngineEditor.Commands.Tools
{
public class ControlsEditingAutoConstrcutPolygonForKDB : BaseToolCmd
{
private IMapService _MapService;
public VerificationOfFeatureNodeDensity density
{
get;
set;
}
public override bool Enabled
{
get
{
//KGIS.Framework.Utils.Model.ProjectInfo pTemp = KGIS.Framework.Platform.Platform.Instance.GetProjectInfo();
//if (pTemp == null)
//{
// return false;
//}
//else
//{
// if (string.IsNullOrWhiteSpace(pTemp.GetProjDBPath()))
// {
// return false;
// }
// else
// {
if (m_pEditor == null)
{
return false;
}
//替换Env
ESRI.ArcGIS.Carto.ILayer layer = (m_pEditor as EngineEditorClass).TargetLayer;
if ((m_pEditor as EngineEditorClass).EditState == esriEngineEditState.esriEngineStateEditing && layer != null && (layer as ESRI.ArcGIS.Carto.IFeatureLayer).FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
{
return true;
}
else
{
return false;
}
// }
// }
}
}
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)
{
try
{
if (EditorSettingClass.Instance.IsTraceing && this.m_pTraceFeedback != null)
{
this.FillFeatureCache(this.m_pPointCatched);
this.GetBeTracedPolyline();
//this.m_pTraceFeedback.SetSplitPolyline(m_pListBeTracePolyline);
this.m_pTraceFeedback.ListBeTracePolyline = this.m_pListBeTracePolyline;
}
}
catch (Exception ex)
{
}
}
public override bool Deactivate()
{
base.Deactivate();
_MapService.getAxMapControl().OnExtentUpdated -= M_pAxMapControl_OnExtentUpdated;
IActiveViewEvents_Event activeViewEvents_Event = _MapService.getAxMapControl().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();
_MapService = MapsManager.Instance.MapService;
base.m_pDisplayFeedbackMethod = DisplayFeedbackMethod.Line;
_MapService.getAxMapControl().OnExtentUpdated += M_pAxMapControl_OnExtentUpdated;
IActiveViewEvents_Event activeViewEvents_Event = _MapService.getAxMapControl().ActiveView as IActiveViewEvents_Event;
activeViewEvents_Event.ContentsChanged += ActiveViewEvents_Event_ContentsChanged;
activeViewEvents_Event.ItemAdded += ActiveViewEvents_Event_ItemAdded;
activeViewEvents_Event.ItemDeleted += ActiveViewEvents_Event_ItemDeleted;
}
public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
try
{
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
{
try
{
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);
}
}
}
catch (Exception ex)
{
}
}
}
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);
}
}
catch (Exception ex)
{
}
}
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)
{
try
{
base.OnMouseUp(Button, Shift, X, Y);
}
catch (Exception ex)
{
}
}
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 void FinishSketch()
{
this.EndFeedback();
this.EndArcFeedback();
this.EndTraceFeedback();
if (m_pGeometry is IPolygon)
{
if (!(m_pGeometry as IPolygon).IsClosed)
{
(m_pGeometry as IPolygon).Close();
}
(this.m_pGeometry as IPolygon).SimplifyPreserveFromTo();
if (!this.m_pGeometry.IsEmpty)
{
ConstructionFeature();
}
}
else if (m_pGeometry is IPolyline)
{
if (!this.m_pGeometry.IsEmpty)
{
IPolyline polyline = this.m_pGeometry as IPolyline;
polyline.SimplifyNetwork();
ConstructionFeature();
}
}
if (EditorSettingClass.Instance.OnDrawEnd != null)
{
EditorSettingClass.Instance.OnDrawEnd(this, this.m_pGeometry);
}
Marshal.ReleaseComObject(this.m_pGeometry);
if (m_pPath != null)
Marshal.ReleaseComObject(this.m_pPath);
if (m_pRing != null)
Marshal.ReleaseComObject(this.m_pRing);
this.m_pGeometry = null;
Marshal.ReleaseComObject(this.m_pRing);
this.m_pRing = null;
Marshal.ReleaseComObject(this.m_pPath);
this.m_pPath = null;
if (this.SketchGeometry != null)
{
this.SketchGeometry.Deactivate();
this.SketchGeometry = null;
}
this.RefreshForeground(null);
}
public void ConstructionFeature()
{
try
{
m_pEditor.StartOperation();
object objMiss = Type.Missing;
GeometryBagClass enumGeoLines = new GeometryBagClass();
enumGeoLines.AddGeometry(m_pGeometry, ref objMiss, ref objMiss);
if (density == null)
{
density = new VerificationOfFeatureNodeDensity(m_pHookHelper);
}
if ((m_pEditor as IEngineEditLayers).TargetLayer != null && (m_pEditor as IEngineEditLayers).TargetLayer is IFeatureLayer)
{
IFeatureLayer FeatLayer = (m_pEditor as IEngineEditLayers).TargetLayer as IFeatureLayer;
FeatLayer.Selectable = true;
IFeatureClass fc = FeatLayer.FeatureClass;
IDataset pDataset = fc as IDataset;
IWorkspace pWorkspace = m_pEditor.EditWorkspace;
IInvalidArea invalidArea = new InvalidAreaClass();
//要素构造类
IFeatureConstruction pfeatBuild = new FeatureConstructionClass();
//开始自动完成构面并保存到fc面图层中
IFeatureSelection featsel = FeatLayer as IFeatureSelection;
ISelectionSet selSet = featsel.SelectionSet;
SimpleFillSymbolClass selectSymboll = new ESRI.ArcGIS.Display.SimpleFillSymbolClass();
ISymbol m_LineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbol() as ISymbol;
((ILineSymbol)m_LineSymbol).Color = GreenColor();
selectSymboll.Outline = m_LineSymbol as ILineSymbol;
featsel.SelectionSymbol = selectSymboll;
string toleranceStr = SysConfigsOprator.GetAppsetingValueByKey("Tolerance");
double tolerance = 0.0001;
if (!double.TryParse(toleranceStr, out tolerance))
{
tolerance = 0.0001;
}
pfeatBuild.AutoCompleteFromGeometries(fc, this.m_pHookHelper.ActiveView.Extent, enumGeoLines, invalidArea, tolerance, pWorkspace, out selSet);
if (selSet != null && selSet.Count > 0)
{
StringBuilder strb = new StringBuilder();
IEnumIDs ids = selSet.IDs;
int oid = ids.Next();
List<IFeature> featureList = new List<IFeature>();
//与之相邻面积最大的多边形
//IGeometry geo3 = null;
while (oid > 0)
{
strb.Append(oid + ",");
IFeature currFeature = fc.GetFeature(oid);
currFeature.Shape.SpatialReference = m_pHookHelper.FocusMap.SpatialReference;
//if (dataCheckService != null)
//{
// dataCheckService.GeometryCheck(currFeature.Shape, FeatLayer);
//}
IFeatureLayer selectFeatureLayer = FeatLayer;
//按权属分割、合并图斑
//List<IGeometry> GeoList = null;
//if (selectFeatureLayer != null && KGIS.Framework.Platform.Platform.Instance.SystemType == 1)
//{
// GeoList = FeatureAPI.GenerateNewFeature(currFeature.ShapeCopy, selectFeatureLayer.FeatureClass);
//}
//if (GeoList != null && GeoList.Count > 0)
//{
// GeoList[0] = density.Verification(GeoList[0]);
// currFeature.Shape = GeoList[0];
// currFeature.Store();
// featureList.Add(currFeature);
// for (int i = GeoList.Count - 1; i > 0; i--)
// {
// if (GeoList[i].IsEmpty)
// continue;
// IFeature newFeature = fc.CreateFeature();
// newFeature.Shape = GeoList[i];
// newFeature.Store();
// featureList.Add(newFeature);
// strb.Append(newFeature.OID + ",");
// }
//}
//else
//{
currFeature.Store();
featureList.Add(currFeature);
//}
oid = ids.Next();
}
m_pEditor.StopOperation("AUTO");
ids.Reset();
strb.Remove(strb.Length - 1, 1);
_MapService.SelectFeature((FeatLayer.FeatureClass as FeatureClass).BrowseName, strb.ToString(), false);
}
else
{
m_pEditor.AbortOperation();
}
}
else
{
MessageHelper.ShowTips("目标图层为空,请开启编辑会话");
}
this.m_pHookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, this.m_pHookHelper.ActiveView.Extent);
}
catch (Exception ex)
{
LogAPI.Debug("画线构面 过程中 双击鼠标 时失败,异常原因: " + ex + " ; ");
m_pEditor.AbortOperation();
MessageHelper.ShowError(ex.Message);
}
finally
{
}
}
private IColor GreenColor()
{
IRgbColor pRGB = new RgbColorClass();
pRGB.Red = 0; pRGB.Green = 255; pRGB.Blue = 0;
return pRGB;
}
}
}