using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using ESRI.ArcGIS.ADF.BaseClasses; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Geometry; using KGIS.Framework.AE; 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 Kingo.Plugin.EngineEditor.Views; using Kingo.PluginServiceInterface; using UIShell.OSGi; namespace Kingo.Plugin.EngineEditor.Commands.Tools { /// /// 画线物面(线状地物面)工具 /// public class ControlsEditingDrawLineToPolygonToolForKDB : BaseTool { //public KGIS.Common.Interface.IRegionAuthorize RegionAuthorize //{ // get; // set; //} public VerificationOfFeatureNodeDensity density { get; set; } //RegionAuthorize RegionAuthorize = null; private IEngineSnapEnvironment snapEnv = null; #region 私有变量 //KOTilesLayer layer = null; private EngineEditorClass m_editor; private IHookHelper m_hookHelper; /// /// 平移工具 /// private ControlsMapPanToolClass panTool = null; /// /// 中间线 /// private LineModel MiddleLine; /// /// 左边线 /// private LineModel LeftLine; /// /// 右边线 /// private LineModel RightLine; /// /// 是否续画 /// private bool IsContinueDraw = false; /// /// 续画左端点 /// private IPoint ContinueDrawLeftPoint = null; /// /// 续画右端点 /// private IPoint ContinueDrawRightPoint = null; /// /// 续画宽度 /// private double ContinueDrawLength = 0.0; private bool _IsDrawing; /// /// 正在绘制 /// private bool IsDrawing { get { return _IsDrawing; } set { _IsDrawing = value; if (_IsDrawing) { //替换Env改动 //Env.Instance.KMap.AxMapControl.AutoMouseWheel = false; //Env.Instance.KMap.AxMapControl.AutoKeyboardScrolling = false; (m_hookHelper.Hook as IMapControlDefault).AutoMouseWheel = false; (m_hookHelper.Hook as IMapControlDefault).AutoKeyboardScrolling = false; } else { //替换Env改动 //Env.Instance.KMap.AxMapControl.AutoMouseWheel = true; //Env.Instance.KMap.AxMapControl.AutoKeyboardScrolling = true; (m_hookHelper.Hook as IMapControlDefault).AutoMouseWheel = true; (m_hookHelper.Hook as IMapControlDefault).AutoKeyboardScrolling = true; } } } private Boolean IsSpaceDown = false; private bool IsCtrlDown = false; private IElement TextElement; /// /// 记录鼠标当前位置 /// private System.Drawing.Point MousePoint = new System.Drawing.Point(); private bool IsChangedWidht = false; /// /// 道路线最小点间距 /// private int MinPointDistance = 30; /// /// 道路线最大点间距 /// private int MaxPointDistance = 80; public DrawParam drawParam { get; set; } FrmDrawDoublePolyline paramFrm = null; private bool IsAutoTrackPoint { set { if (MiddleLine != null) { MiddleLine.IsAutoTrackPoint = value; } if (LeftLine != null) { LeftLine.IsAutoTrackPoint = value; } if (RightLine != null) { RightLine.IsAutoTrackPoint = value; } } } /// /// 是否自动追踪 /// private bool IsAuto = false; #region 地图自动漫游相关变量 /// /// 表示是否开启自动漫游功能 /// private bool AllowMoveMap = false; /// /// 地图漫游计时器(表示多久移动一次地图) /// private System.Windows.Forms.Timer timer = null; /// /// 鼠标距离地图边界的距离(当小于指定值是开始漫游) /// private int MapBorderDistance = 10; #endregion #region 自动识别功能相关变量 /// /// 自动识别计时器(相隔一定时间,根据鼠标位置自动识别一次) /// private System.Windows.Forms.Timer autoDistinguishTimer = null; /// /// 用于存放自动识别到的点元素集合 /// private List PointElement = new List(); /// /// 用于存放自动识别到的宽度 /// private double TempWidht = 0; /// /// 用于临时存放自动识别到的中心点 /// private IPoint TempCenterPoint = null; #endregion /// /// 记录捕捉Element上点的索引 /// private int SnapElementPointIndex = -1; /// /// 记录捕捉的点在哪条线上(0:中心线;1:左边线;-1:右边线) /// private int SnapElementPointLine = 0; #endregion /// /// 初始化工具相关属性 /// private void Init() { //初始化计时器 timer = new System.Windows.Forms.Timer(); timer.Interval = 100; timer.Tick += timer_Tick; autoDistinguishTimer = new System.Windows.Forms.Timer(); autoDistinguishTimer.Interval = 100; autoDistinguishTimer.Tick += autoDistinguishTimer_Tick; //初始化地图漫游工具 panTool = new ControlsMapPanToolClass(); panTool.OnCreate(m_hookHelper.Hook); //初始化编辑对象 if (m_editor == null) m_editor = new EngineEditorClass();// Env.Instance.KMap.EngEditor; if (snapEnv == null) snapEnv = m_editor; //开启自动漫游功能 AllowMoveMap = false; //注册鼠标滚轮事件 //替换Env改动 //Env.Instance.Platfrom.MapMouseWheel -= Platfrom_MapMouseWheel; //Env.Instance.Platfrom.MapMouseWheel += Platfrom_MapMouseWheel; if (_MapService != null) { _MapService.MapContainerMouseWheel -= Platfrom_MapMouseWheel; _MapService.MapContainerMouseWheel += Platfrom_MapMouseWheel; } //白明雅 2020-04-07 用于激活键盘事件 MapsManager.Instance.MapService.getAxMapControl().Focus(); //初始化绘制模型 if (MiddleLine == null) MiddleLine = new LineModel(m_hookHelper.ActiveView, esriSimpleLineStyle.esriSLSDash, 0.5); if (LeftLine == null) LeftLine = new LineModel(m_hookHelper.ActiveView, esriSimpleLineStyle.esriSLSSolid); if (RightLine == null) RightLine = new LineModel(m_hookHelper.ActiveView, esriSimpleLineStyle.esriSLSSolid); MiddleLine.Init(); LeftLine.Init(); RightLine.Init(); //设置鼠标样式 base.m_cursor = System.Windows.Forms.Cursors.Cross; //初始化其他参数 IsSpaceDown = false; IsDeactivate = false; if (PointElement == null) PointElement = new List(); } /// /// 释放工具相关对象 /// private void Dispose() { //销毁计时器 if (timer != null) { timer.Tick -= timer_Tick; timer.Stop(); timer.Dispose(); } if (autoDistinguishTimer != null) { autoDistinguishTimer.Tick -= autoDistinguishTimer_Tick; autoDistinguishTimer.Stop(); autoDistinguishTimer.Dispose(); } //销毁panTool工具 if (panTool != null) { panTool.Deactivate(); Marshal.ReleaseComObject(panTool); panTool = null; } //取消事件注册 //替换Env改动 //Env.Instance.Platfrom.MapMouseWheel -= Platfrom_MapMouseWheel; if (_MapService != null) { _MapService.MapContainerMouseWheel -= Platfrom_MapMouseWheel; } //销毁绘制模型 if (MiddleLine != null) { MiddleLine.Dissvoe(); MiddleLine = null; } if (LeftLine != null) { LeftLine.Dissvoe(); LeftLine = null; } if (RightLine != null) { RightLine.Dissvoe(); RightLine = null; } this.IsDrawing = false; this.IsContinueDraw = false; IsDeactivate = true; this.m_checked = false; if (PointElement != null) PointElement.Clear(); } #region 重写BaseCommand public override void OnCreate(object hook) { try { if (m_hookHelper == null) { //替换Env改动 //m_hookHelper = Env.Instance.KMap.HookHelper; m_hookHelper = new HookHelperClass(); m_hookHelper.Hook = hook; } //初始化编辑对象 if (m_editor == null) m_editor = new EngineEditorClass(); //m_editor = new EngineEditorClass(); ////m_editor.OnStopEditing += m_editor_OnStopEditing; ////m_editor.OnTargetLayerChanged += m_editor_OnTargetLayerChanged; //snapEnv = (IEngineSnapEnvironment)m_editor; if (drawParam == null) { drawParam = new DrawParam(); drawParam.DrawMode = DrawMode.LeftAndRight; drawParam.Width = 10; drawParam.ToloranceScale = 0.2; drawParam.DLBM = "1003-公路用地"; } if (density == null) { density = new VerificationOfFeatureNodeDensity(m_hookHelper); } } catch (Exception ex) { LogAPI.Debug("初始化 画线物面(线状地物面)工具 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("初始化 画线物面(线状地物面)工具 时异常信息结束"); } } //void m_editor_OnTargetLayerChanged() //{ // if (paramFrm != null) // { // paramFrm.Close(); // paramFrm = null; // base.Deactivate(); // } //} //void m_editor_OnStopEditing(bool saveChanges) //{ // if (paramFrm != null) // { // paramFrm.Close(); // paramFrm = null; // base.Deactivate(); // } //} private bool IsDeactivate; private IMapService _MapService; public override void OnClick() { try { //KGIS.Framework.Common.Utils.LicenseManager.License(); _MapService = MapsManager.Instance.MapService; Init(); panTool.OnClick(); base.OnClick(); if (paramFrm != null) { paramFrm.Close(); } if (paramFrm == null) { paramFrm = new FrmDrawDoublePolyline(drawParam); paramFrm.SetParam(true, true); paramFrm.Closed += paramFrm_Closed; paramFrm.Title = "画线物面"; paramFrm.Topmost = true; paramFrm.ShowInTaskbar = false; paramFrm.Top = 175; paramFrm.Left = 235; paramFrm.Show(); } //timer.Interval = 100; //timer.Tick += timer_Tick; //autoDistinguishTimer.Interval = 100; //autoDistinguishTimer.Tick += autoDistinguishTimer_Tick; //AllowMoveMap = true; //Env.Instance.Platfrom.MapMouseWheel -= Platfrom_MapMouseWheel; //Env.Instance.Platfrom.MapMouseWheel += Platfrom_MapMouseWheel; //MiddleLine = new LineModel(m_hookHelper.ActiveView, esriSimpleLineStyle.esriSLSDash, 0.5); //LeftLine = new LineModel(m_hookHelper.ActiveView, esriSimpleLineStyle.esriSLSSolid); //RightLine = new LineModel(m_hookHelper.ActiveView, esriSimpleLineStyle.esriSLSSolid); //IsSpaceDown = false; IsDeactivate = false; //base.m_cursor = System.Windows.Forms.Cursors.Cross; base.OnClick(); //layer = Common.Utility.LayerHelper.GetLayerByName(m_hookHelper.FocusMap, "YGYXT"); this.m_checked = true; } catch (Exception ex) { LogAPI.Debug("初始化 画线物面(线状地物面)工具 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("初始化 画线物面(线状地物面)工具 时异常信息结束"); MessageHelper.ShowError(ex.Message); } } /// /// 鼠标距离地图边界一定距离时,开始漫游 /// /// /// void timer_Tick(object sender, EventArgs e) { try { IEnvelope extent = this.m_hookHelper.ActiveView.Extent; int centerX = 0; int centerY = 0; int rX = 0; int rY = 0; this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(new PointClass() { X = extent.XMax, Y = extent.YMin }, out rX, out rY); IPoint centerPoint = new PointClass() { X = extent.XMin + (extent.XMax - extent.XMin) / 2, Y = extent.YMin + (extent.YMax - extent.YMin) / 2 }; this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(centerPoint, out centerX, out centerY); bool NeedPan = false; if (!IsDrawing) { timer.Stop(); return; } if (MousePoint.X < MapBorderDistance) { NeedPan = true; centerX -= 5; } if (MousePoint.Y < MapBorderDistance) { NeedPan = true; centerY -= 5; } if (Math.Abs(rX - MousePoint.X) < MapBorderDistance) { NeedPan = true; centerX += 5; } if (Math.Abs(rY - MousePoint.Y) < MapBorderDistance) { NeedPan = true; centerY += 5; } if (NeedPan) { centerPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(centerX, centerY); (this.m_hookHelper.Hook as IMapControl2).CenterAt(centerPoint); } } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 鼠标距离地图边界一定距离时,开始漫游 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 鼠标距离地图边界一定距离时,开始漫游 时异常信息结束"); } } void paramFrm_Closed(object sender, EventArgs e) { if (paramFrm != null) { paramFrm.Closed -= paramFrm_Closed; } paramFrm = null; } public override bool Enabled { get { if (MapsManager.Instance == null) return false; object pTemp = (MapsManager.Instance.CurrProjectInfo as ProjectInfo); if (pTemp == null) { return false; } else { ILayer layer = m_editor.TargetLayer;//Env.Instance.KMap.EngEditor.TargetLayer; if (m_editor.EditState == esriEngineEditState.esriEngineStateEditing && layer != null && (layer as ESRI.ArcGIS.Carto.IFeatureLayer).FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon) { return true; } else { return false; } } } } #endregion IElement element = null; private int IsEnterClickNum = 0; private bool IsShiftDown = false; #region 重写BaseTool //[LogWrite(Description = "")] public override void OnKeyDown(int keyCode, int Shift) { try { //键盘按下时不启用放大缩小功能 //替换Env改动 //Env.Instance.KMap.AxMapControl.AutoMouseWheel = false; //Env.Instance.KMap.AxMapControl.AutoKeyboardScrolling = false; (m_hookHelper.Hook as IMapControlDefault).AutoMouseWheel = false; (m_hookHelper.Hook as IMapControlDefault).AutoKeyboardScrolling = false; //---------------------- IPoint point = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(MousePoint.X, MousePoint.Y);//Env.Instance.MousePoint; //替换Env改动 //Env.Instance.CurrentKeyDown = keyCode; Platform.Instance.SetCurrentKeyDown(keyCode); if (keyCode == (int)ConsoleKey.F7) { try { #region 自动识别 if (TempCenterPoint == null || TempWidht <= 0) { //如果没有识别到,调用手动取点 this.OnKeyDown((int)ConsoleKey.F8, Shift); return; } this.IsAuto = true; if (TempWidht > 0 && MiddleLine.Line.PointCount == 1 && !IsChangedWidht) { //如果识别到点,并且已经绘制了一个点,并且宽度没有手动调整过,则应用识别的宽度并修改第一个点的宽度 this.drawParam.Width = TempWidht; this.OnMouseMove(1, Shift, MousePoint.X, MousePoint.Y); //Moveing(point); } this.drawParam.Width = TempWidht; ///当前线上面最后一个点的X坐标 int endX = -1; ///当前线上面最后一个点的Y坐标 int endY = -1; ///下一个点的X坐标 int nextX = -1; ///下一个点的Y坐标 int nextY = -1; if (MiddleLine.Line.PointCount > 0) { this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(MiddleLine.Line.get_Point(MiddleLine.Line.PointCount - 1), out endX, out endY); } this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(TempCenterPoint, out nextX, out nextY); if (nextX != -1 && nextY != -1 && endX != -1 && endY != -1) { IPolyline line = new PolylineClass(); line.FromPoint = MiddleLine.Line.get_Point(MiddleLine.Line.PointCount - 1); line.ToPoint = TempCenterPoint; //当两次取点距离小于30像素的时候,取消上一个点,以第二次的点为主 if (line.Length < 3) { //取消上一个点 this.OnKeyDown((int)ConsoleKey.F9, 0); } ///以识别到的点进行绘制新的点 LeftClick(nextX, nextY); this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(MiddleLine.Line.get_Point(MiddleLine.Line.PointCount - 1), out nextX, out nextY); //MoveMapExtent(nextX, nextY, 100); } TempCenterPoint = null; #endregion } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 键盘按下 F7 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 键盘按下 F7 时异常信息结束"); } } else if (keyCode == (int)ConsoleKey.F8) { try { #region 快捷键取点 this.IsAuto = false; ///当前线上面最后一个点的X坐标 int endX = -1; ///当前线上面最后一个点的Y坐标 int endY = -1; if (MiddleLine.Line.PointCount > 0) { this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(MiddleLine.Line.get_Point(MiddleLine.Line.PointCount - 1), out endX, out endY); } //当两次取点距离小于30像素的时候,取消上一个点,以第二次的点为主 if (endX != -1 && endY != -1 && Math.Abs(MousePoint.X - endX) < 30 && Math.Abs(MousePoint.Y - endY) < 30) { //取消上一个点 this.OnKeyDown((int)ConsoleKey.F9, 0); } //绘制新的点 this.LeftClick(MousePoint.X, MousePoint.Y); #endregion } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 键盘按下 F8 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 键盘按下 F8 时异常信息结束"); } } else if (keyCode == (int)ConsoleKey.F9 || keyCode == (int)ConsoleKey.Escape) { try { if (this.MiddleLine.Line.PointCount > 0 && this.IsDrawing == false) { //删除点 if (SnapElementPointIndex == -1) { SnapElementPointIndex = SnapElement(point, out SnapElementPointLine); } if (SnapElementPointIndex != -1 && SnapElementPointLine == 0) { MiddleLine.Line.RemovePoints(SnapElementPointIndex, 1); LeftLine.Line.RemovePoints(SnapElementPointIndex, 1); RightLine.Line.RemovePoints(SnapElementPointIndex, 1); MiddleLine.RefreshPoint(SnapElementPointIndex); LeftLine.RefreshPoint(SnapElementPointIndex); RightLine.RefreshPoint(SnapElementPointIndex); SnapElementPointIndex = -1; SnapElementPointLine = int.MaxValue; } } else { #region 撤销点 IPointCollection tempLine = new Polyline(); if (LeftLine.Line.PointCount > 1) { LeftLine.Line.RemovePoints(LeftLine.Line.PointCount - 1, 1); tempLine.AddPoint(LeftLine.Line.get_Point(LeftLine.Line.PointCount - 1)); } else if (LeftLine.Line.PointCount == 1) { LeftLine.Line.RemovePoints(LeftLine.Line.PointCount - 1, 1); LeftLine.FollowLine.Stop(); //LeftLine.FollowLine.RemovePoints(0, LeftLine.FollowLine.PointCount); //LeftLine.DrawLine(); } if (RightLine.Line.PointCount > 1) { RightLine.Line.RemovePoints(RightLine.Line.PointCount - 1, 1); tempLine.AddPoint(RightLine.Line.get_Point(RightLine.Line.PointCount - 1)); } else if (RightLine.Line.PointCount == 1) { RightLine.Line.RemovePoints(RightLine.Line.PointCount - 1, 1); LeftLine.FollowLine.Stop(); //RightLine.FollowLine.RemovePoints(0, RightLine.FollowLine.PointCount); //RightLine.DrawLine(); } if (MiddleLine.Line.PointCount > 1) { MiddleLine.Line.RemovePoints(MiddleLine.Line.PointCount - 1, 1); IEnvelope extent = m_hookHelper.ActiveView.Extent; IPoint p = MiddleLine.Line.Point[MiddleLine.Line.PointCount - 1]; if (extent.XMax < p.X || extent.XMin > p.X || extent.YMax < p.Y || extent.YMin > p.Y) { (this.m_hookHelper.Hook as IMapControl2).CenterAt(p); } } else if (MiddleLine.Line.PointCount == 1) { MiddleLine.Line.RemovePoints(MiddleLine.Line.PointCount - 1, 1); LeftLine.FollowLine.Stop(); //MiddleLine.FollowLine.RemovePoints(0, MiddleLine.FollowLine.PointCount); //MiddleLine.DrawLine(); PointElement = new List(); this.IsDrawing = false; this.IsContinueDraw = false; } //计算前一个点时划线的宽度 //if (tempLine.PointCount == 2) //{ // this.drawParam.Width = (tempLine as IPolyline).Length; //} LeftLine.DrawLine(LeftLine.Line.PointCount); RightLine.DrawLine(LeftLine.Line.PointCount); MiddleLine.DrawLine(LeftLine.Line.PointCount); this.OnMouseMove(1, Shift, MousePoint.X, MousePoint.Y); //Moveing(point); #endregion } } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 键盘按下 F9||ESC 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 键盘按下 F9||ESC 时异常信息结束"); } } else if (keyCode == (int)ConsoleKey.Backspace) { #region 清除绘制的图形 this.MiddleLine.Reset(); this.LeftLine.Reset(); this.RightLine.Reset(); PointElement = new List(); this.IsDrawing = false; this.IsContinueDraw = false; #endregion } else if (keyCode == (int)ConsoleKey.Spacebar) { #region 空格移动地图 if (!IsSpaceDown) { base.Deactivate(); IsSpaceDown = true; } base.m_cursor = System.Windows.Forms.Cursors.Hand; //this.OnMouseMove(1, 0, MousePoint.X, MousePoint.Y); #endregion } else if (keyCode == (int)ConsoleKey.D9) { #region 减小识别灵敏度 if (this.drawParam.ToloranceScale > 0.05) { this.drawParam.ToloranceScale -= 0.05; autoDistinguishTimer.Stop(); autoDistinguishTimer.Start(); } else { this.drawParam.ToloranceScale = 0.05; } #endregion } else if (keyCode == (int)ConsoleKey.D0) { #region 增加识别灵敏度 if (this.drawParam.ToloranceScale < 0.5) { this.drawParam.ToloranceScale += 0.05; autoDistinguishTimer.Stop(); autoDistinguishTimer.Start(); } else { this.drawParam.ToloranceScale = 0.5; autoDistinguishTimer.Stop(); autoDistinguishTimer.Start(); } #endregion } else if (keyCode == 17) { #region Ctrl键调整双线宽度 if (!IsCtrlDown) { //替换Env改动 //Env.Instance.KMap.AxMapControl.AutoMouseWheel = false; //Env.Instance.KMap.AxMapControl.AutoKeyboardScrolling = false; (m_hookHelper.Hook as IMapControlDefault).AutoMouseWheel = false; (m_hookHelper.Hook as IMapControlDefault).AutoKeyboardScrolling = false; DrawTextElement(point, ref TextElement); IsCtrlDown = true; } #endregion } else if (keyCode == 16) { this.IsShiftDown = true; } else if (keyCode == (int)ConsoleKey.Enter) { if (this.MiddleLine.Line.PointCount > 1) { if (IsEnterClickNum == 0) { IsEnterClickNum++; IsDrawing = false; } else if (IsEnterClickNum == 1) { this.DrawComplete(); IsEnterClickNum = 0; SnapElementPointIndex = -1; SnapElementPointLine = 0; IsContinueDraw = false; } } } else if (keyCode == (int)ConsoleKey.Insert) { //增加点 if (SnapElementPointIndex == -1) { SnapElementPointIndex = SnapElement(point); double a = GeometryOperations.getAngle(MiddleLine.Line.get_Point(0), MiddleLine.Line.get_Point(1)); if (SnapElementPointIndex != -1) { IPoint p = MiddleLine.Line.get_Point(SnapElementPointIndex); double angle = GeometryOperations.getAngle(p, point); if ((a > 0 && angle > 0) || (a < 0 && angle < 0)) { SnapElementPointIndex++; } else { //if (a < 0 && angle < 0) //{ // SnapElementPointIndex++; //} //if (a > 45 && a < 135) //{ // if (angle > 0) // { // SnapElementPointIndex++; // } //} } IPointCollection newPoint = new Polyline(); newPoint.AddPoint(point); MiddleLine.Line.InsertPointCollection(SnapElementPointIndex, newPoint); LeftLine.Line.InsertPointCollection(SnapElementPointIndex, newPoint); RightLine.Line.InsertPointCollection(SnapElementPointIndex, newPoint); SnapElementPointLine = 0; } } } } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 键盘按下 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 键盘按下 时异常信息结束"); } } //[LogWrite(Description = "")] public override void OnKeyUp(int keyCode, int Shift) { //替换Env改动 //Env.Instance.CurrentKeyDown = -1; Platform.Instance.SetCurrentKeyDown(-1); base.OnKeyUp(keyCode, Shift); if (keyCode == (int)ConsoleKey.Spacebar) { if (IsSpaceDown && IsDrawing) { m_hookHelper.ActiveView.Refresh(); base.OnClick(); IsSpaceDown = false; base.m_cursor = System.Windows.Forms.Cursors.Cross; //this.OnMouseMove(1, 0, MousePoint.X, MousePoint.Y); } } if (keyCode == 17) { //替换Env改动 //Env.Instance.KMap.AxMapControl.AutoMouseWheel = true; //Env.Instance.KMap.AxMapControl.AutoKeyboardScrolling = true; (m_hookHelper.Hook as IMapControlDefault).AutoMouseWheel = true; (m_hookHelper.Hook as IMapControlDefault).AutoKeyboardScrolling = true; DelElement(ref TextElement); IsCtrlDown = false; } if (keyCode == 16) { this.IsShiftDown = false; } } //[LogWrite(Description = "")] public override void OnMouseDown(int Button, int Shift, int X, int Y) { try { IsAuto = false; if (IsSpaceDown) { base.Deactivate(); panTool.OnMouseDown(1, Shift, X, Y); return; } if (Button == 1) { //左键按下取点 IPoint point = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); if (snapEnv != null) { snapEnv.SnapPoint(point); } if (this.MiddleLine.Line.PointCount > 0 && IsDrawing == false) { #region 调整单个点的位置 if (SnapElementPointIndex == -1) { SnapElementPointIndex = SnapElement(point, out SnapElementPointLine); //IsDrawing = true; } else { if (SnapElementPointLine == 0) { this.MiddleLine.Line.UpdatePoint(SnapElementPointIndex, point); double angle = 0; if (SnapElementPointIndex == 0) { angle = GeometryOperations.getAngle(point, this.MiddleLine.Line.get_Point(SnapElementPointIndex + 1)); } else { angle = GeometryOperations.getAngle(this.MiddleLine.Line.get_Point(SnapElementPointIndex - 1), point); } this.LeftLine.Line.UpdatePoint(SnapElementPointIndex, GeometryOperations.GetPoint(point, this.drawParam.Width * 0.5, -angle)); this.RightLine.Line.UpdatePoint(SnapElementPointIndex, GeometryOperations.GetPoint(point, this.drawParam.Width * -0.5, -angle)); this.MiddleLine.RefreshPoint(SnapElementPointIndex); this.LeftLine.RefreshPoint(SnapElementPointIndex); this.RightLine.RefreshPoint(SnapElementPointIndex); } else if (SnapElementPointLine == 1) { this.LeftLine.Line.UpdatePoint(SnapElementPointIndex, point); this.LeftLine.RefreshPoint(SnapElementPointIndex); } else if (SnapElementPointLine == -1) { this.RightLine.Line.UpdatePoint(SnapElementPointIndex, point); this.RightLine.RefreshPoint(SnapElementPointIndex); } SnapElementPointIndex = -1; IsDrawing = false; } #endregion } else { #region 绘制点 #region 根据道路宽度调整相关参数 if (TempWidht < 10) { MinPointDistance = 15; MaxPointDistance = 40; } else if (TempWidht > 15) { MinPointDistance = 30; MaxPointDistance = 80; } #endregion if (this.MiddleLine.Line.PointCount > 0) { IPoint p = this.MiddleLine.Line.get_Point(this.MiddleLine.Line.PointCount - 1); if (p.X == point.X && p.Y == point.Y) { return; } IPolyline line = new PolylineClass(); line.FromPoint = point; line.ToPoint = p; if (line.Length < 3) { return; } } if (TempWidht == -1) { TempWidht = 10; } Drawing(point); if (this.MiddleLine.Line.PointCount > 0) this.IsDrawing = true; else return; if (this.MiddleLine.Line.PointCount > 1) { IPoint p2 = MiddleLine.Line.get_Point(this.MiddleLine.Line.PointCount - 2); IPoint p1 = MiddleLine.Line.get_Point(this.MiddleLine.Line.PointCount - 1); double angle = GeometryOperations.getAngle(p2, p1); //angle = 90 - angle; IPolyline tempLine = new PolylineClass(); tempLine.FromPoint = p1; tempLine.ToPoint = p2; MoveMapExtent(X, Y, (int)Math.Floor(tempLine.Length)); if (this.drawParam.IsAutoTrack) { //this.OnMouseDown(2, Shift, MousePoint.X, MousePoint.Y); } } else { MoveMapExtent(X, Y, 100); } #endregion } } else if (Button == 2) { this.OnKeyDown((int)ConsoleKey.F7, Shift); } else if (Button == 4) { ////鼠标滚轮按下 //base.Deactivate(); //panTool.OnMouseDown(Button, Shift, X, Y); //this.OnKeyDown((int)ConsoleKey.Enter, Shift); } } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 按下鼠标 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 按下鼠标 时异常信息结束"); } } private bool isRunning = false; public override void OnMouseMove(int Button, int Shift, int X, int Y) { if (isRunning) return; isRunning = true; try { if (IsSpaceDown) { panTool.OnMouseMove(1, Shift, X, Y); MousePoint.X = X; MousePoint.Y = Y; return; } var vT10 = m_hookHelper; var vT12 = m_hookHelper.ActiveView; var vT13 = m_hookHelper.ActiveView.ScreenDisplay; var vT14 = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation; var vT15 = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); IPoint point = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); if (snapEnv != null) { this.SnapPoint(m_hookHelper.ActiveView, point, snapEnv); } if (this.MiddleLine.Line.PointCount > 0) { if (this.IsDrawing) { Moveing(point); if (MousePoint.X == X && MousePoint.Y == Y) { return; } else { MousePoint.X = X; MousePoint.Y = Y; } autoDistinguishTimer.Stop(); autoDistinguishTimer.Dispose(); try { autoDistinguishTimer.Start(); } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 移动鼠标后 正在绘制 期间 异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 移动鼠标后 正在绘制 期间 异常信息结束"); System.Windows.Forms.Application.DoEvents(); autoDistinguishTimer.Start(); } System.Windows.Forms.Application.DoEvents(); #region 当鼠标移动到地图边界时,自动移动地图 if (AllowMoveMap) { IEnvelope extent = this.m_hookHelper.ActiveView.Extent; int rX = 0; int rY = 0; //替换Env改动 //Env.Instance.KMap.AxMapControl.FromMapPoint(new PointClass() { X = extent.XMax, Y = extent.YMin }, ref rX, ref rY); (m_hookHelper.Hook as IMapControlDefault).FromMapPoint(new PointClass() { X = extent.XMax, Y = extent.YMin }, ref rX, ref rY); bool NeedPan = false; System.Windows.Forms.Application.DoEvents(); if (X < MapBorderDistance) { if (!NeedPan) { timer.Start(); } NeedPan = true; } if (Y < MapBorderDistance) { if (!NeedPan) { timer.Start(); } NeedPan = true; } if (Math.Abs(rX - X) < MapBorderDistance) { if (!NeedPan) { timer.Start(); } NeedPan = true; } if (Math.Abs(rY - Y) < MapBorderDistance) { if (!NeedPan) { timer.Start(); } NeedPan = true; } if (!NeedPan) { timer.Stop(); NeedPan = false; } } #endregion } else { MousePoint.X = X; MousePoint.Y = Y; if (SnapElementPointIndex != -1) { if (SnapElementPointLine == 0) { this.MiddleLine.Line.UpdatePoint(SnapElementPointIndex, point); double angle = 0; if (SnapElementPointIndex == 0) { angle = GeometryOperations.getAngle(point, this.MiddleLine.Line.get_Point(SnapElementPointIndex + 1)); } else { angle = GeometryOperations.getAngle(this.MiddleLine.Line.get_Point(SnapElementPointIndex - 1), point); } this.LeftLine.Line.UpdatePoint(SnapElementPointIndex, GeometryOperations.GetPoint(point, this.drawParam.Width * 0.5, -angle)); this.RightLine.Line.UpdatePoint(SnapElementPointIndex, GeometryOperations.GetPoint(point, this.drawParam.Width * -0.5, -angle)); this.MiddleLine.RefreshPoint(SnapElementPointIndex); this.LeftLine.RefreshPoint(SnapElementPointIndex); this.RightLine.RefreshPoint(SnapElementPointIndex); } else if (SnapElementPointLine == 1) { this.LeftLine.Line.UpdatePoint(SnapElementPointIndex, point); this.LeftLine.RefreshPoint(SnapElementPointIndex); } else if (SnapElementPointLine == -1) { this.RightLine.Line.UpdatePoint(SnapElementPointIndex, point); this.RightLine.RefreshPoint(SnapElementPointIndex); } autoDistinguishTimer.Stop(); autoDistinguishTimer.Dispose(); try { autoDistinguishTimer.Start(); } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 移动鼠标后 未在绘制 期间 异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 移动鼠标后 未在绘制 期间 异常信息结束"); System.Windows.Forms.Application.DoEvents(); autoDistinguishTimer.Start(); } } } } else if (Button == 4) { //鼠标滚轮按下 //panTool.OnMouseMove(Button, Shift, X, Y); //MousePoint.X = X; //MousePoint.Y = Y; } } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 移动鼠标后 异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 移动鼠标后 期间 异常信息结束"); } finally { isRunning = false; } } //[LogWrite(Description = "")] public override void OnMouseUp(int Button, int Shift, int X, int Y) { if (Button == 4) { //panTool.OnMouseUp(1, Shift, X, Y); //m_hookHelper.ActiveView.Refresh(); //base.OnClick(); } else { //base.OnMouseUp(button, shift, x, y); //点击右键时,弹出编辑菜单 if (IsSpaceDown) { panTool.OnMouseUp(Button, Shift, X, Y); } else { base.OnMouseUp(Button, Shift, X, Y);//调用基类的OnMouseDown事件 } } } IPoint m_SnapPoint = null; bool m_isHasSnap; //[LogWrite(Description = "")] public void SnapPoint(IActiveView activeView, IPoint inPoint, IEngineSnapEnvironment m_editEnvironment) { if (this.m_isHasSnap && (this.m_SnapPoint != null)) { this.DrawSnapPoint(activeView, this.m_SnapPoint); } this.m_isHasSnap = ((IEngineSnapEnvironment)m_editEnvironment).SnapPoint(inPoint); if (this.m_isHasSnap) { this.m_SnapPoint = inPoint; this.DrawSnapPoint(activeView, this.m_SnapPoint); } } //[LogWrite(Description = "")] private void DrawSnapPoint(IActiveView activeView, IPoint point) { 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; } //CheckAssistant dataCheckView = null; IPolyline StartLine = null; IPolyline EndLine = null; //[LogWrite(Description = "")] public void DrawComplete() { try { //if (!ss()) //{ // return; //} bool isSplit; int splitIndex, segIndex; if (LeftLine.Line.PointCount < 2 || this.RightLine.Line.PointCount < 2) { return; } IFeatureLayer layer = m_editor.TargetLayer as IFeatureLayer; if (layer == null || layer.FeatureClass == null) { return; } int selectIdZYQ = 1; IUcZYQMagrHelper ucZYQMagrHelper = null; ProjectInfo ProInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; if (ProInfo != null && ProInfo.ProjType == EnumProjType.BHTBTQ && Platform.Instance.SystemType == SystemTypeEnum.BGFWCG) { ucZYQMagrHelper = BundleRuntime.Instance.GetFirstOrDefaultService(); if (ucZYQMagrHelper != null) { selectIdZYQ = ucZYQMagrHelper.GetCheckedID(); } } m_editor.StartOperation(); //if (StartLine == null) //{ // StartLine = new PolylineClass(); // StartLine.FromPoint = LeftLine.Line.get_Point(0); // StartLine.ToPoint = RightLine.Line.get_Point(0); //} //if (EndLine == null) //{ // EndLine = new PolylineClass(); // EndLine.FromPoint = LeftLine.Line.get_Point(LeftLine.Line.PointCount - 1); // EndLine.ToPoint = RightLine.Line.get_Point(LeftLine.Line.PointCount - 1); //} IPointCollection line1 = new Polyline(); line1.AddPoint((LeftLine.Line as IPolyline).FromPoint); line1.AddPoint((RightLine.Line as IPolyline).FromPoint); IGeometry geo1 = line1 as IGeometry; IPointCollection line2 = new Polyline(); line2.AddPoint((LeftLine.Line as IPolyline).ToPoint); line2.AddPoint((RightLine.Line as IPolyline).ToPoint); IGeometry geo4 = line2 as IGeometry; //IGeometry geo1 = StartLine; IGeometry geo2 = LeftLine.Line as IGeometry; IGeometry geo3 = RightLine.Line as IGeometry; //IGeometry geo4 = EndLine; ITopologicalOperator2 topo = geo1 as ITopologicalOperator2; topo.Simplify(); ITopologicalOperator topo1 = geo2 as ITopologicalOperator; topo1.Simplify(); topo = topo.Union(geo2) as ITopologicalOperator2; topo.Simplify(); topo1 = geo3 as ITopologicalOperator; topo1.Simplify(); topo = topo.Union(geo3) as ITopologicalOperator2; topo1 = geo4 as ITopologicalOperator; topo1.Simplify(); IPointCollection allPoint = topo.Union(geo4) as IPointCollection; IFeatureSelection featureSelection = layer as IFeatureSelection; featureSelection.Clear(); IPointCollection polygon = new PolygonClass(); polygon.AddPointCollection(allPoint); IGeometry geo = (polygon as IGeometry); geo.SpatialReference = m_hookHelper.FocusMap.SpatialReference; //验证区域授权 //if (RegionAuthorize == null) //{ // RegionAuthorize = new RegionAuthorize(); //} //if (!RegionAuthorize.ValidateAuthorize(LeftLine.Line as IGeometry) || !RegionAuthorize.ValidateAuthorize(RightLine.Line as IGeometry)) //{ // MessageHelper.ShowError("绘制图形不在授权区域范围内!"); // return; //} if (density == null) { density = new VerificationOfFeatureNodeDensity(m_hookHelper); } geo = density.Verification(geo); //白明雅 2020-04-01 //if (dataCheckService != null) //{ // dataCheckService.GeometryCheck(geo, layer); //} DrawFeature(layer.FeatureClass, geo, featureSelection); if (ucZYQMagrHelper != null) { ucZYQMagrHelper.AddMask(selectIdZYQ); } #region //IFeatureLayer selectFeatureLayer = _MapService.GetFeatureLayerByName(Env.Instance.DefaultValue.ED_DLTB_TableName); ////if (selectFeatureLayer == null || selectFeatureLayer.FeatureClass == null) ////{ //// selectFeatureLayer = Env.Instance.KMap.GetFeatureLayerByName(this.m_hookHelper.ActiveView.FocusMap, Env.Instance.DefaultValue.DLTB_TableName) as IFeatureLayer; ////} ////按权属分割、合并图斑 //List GeoList = null; //if (selectFeatureLayer != null && selectFeatureLayer.FeatureClass != null) //{ // GeoList = FeatureAPI.GenerateNewFeature(geo, selectFeatureLayer.FeatureClass); //} ////else ////{ //// DrawFeature(layer.FeatureClass, geo, featureSelection); ////} //if (GeoList == null || GeoList.Count <= 0) //{ // GeoList = new List() { geo }; // //DrawFeature(layer.FeatureClass, geo, featureSelection); //} //IIdentify identify = layer as IIdentify; //List featureList = new List(); //for (int k = 0; k < GeoList.Count; k++) //{ // IGeometry item = GeoList[k]; // if (item.IsEmpty) // continue; // ITopologicalOperator2 topologicalOperator2 = item as ITopologicalOperator2; // IPolyline pPolyline = topologicalOperator2.Boundary as IPolyline; // item.SpatialReference = this.m_hookHelper.FocusMap.SpatialReference; // if (identify == null) // { // continue; // } // IArray iarray = identify.Identify(item); // if (iarray == null) // { // continue; // } // for (int i = 0; i < iarray.Count; i++) // { // IFeatureIdentifyObj pFeatIdObj = iarray.get_Element(i) as IFeatureIdentifyObj; // IRowIdentifyObject pRowObj = pFeatIdObj as IRowIdentifyObject; // IFeature newFeature = pRowObj.Row as IFeature; // newFeature.Shape.SpatialReference = this.m_hookHelper.FocusMap.SpatialReference; // ITopologicalOperator topOper = newFeature.ShapeCopy as ITopologicalOperator; // IGeometry geometryNew = topOper.Difference(item); // if (geometryNew != null && !geometryNew.IsEmpty) // { // newFeature.Shape = geometryNew; // } // //属性继承 // //FeatureHelper.SetFeatureAttribute(newFeature);//以后待改回 // //if (!string.IsNullOrWhiteSpace(this.drawParam.DLBM)) // //{ // // string[] str = this.drawParam.DLBM.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); // // if (str.Length == 2) // // { // // int index = newFeature.Fields.FindField("DLBM"); // // if (index > -1) // // { // // newFeature.set_Value(index, str[0]); // // } // // index = newFeature.Fields.FindField("DLMC"); // // if (index > -1) // // { // // newFeature.set_Value(index, str[1]); // // } // // } // //} // newFeature.Store(); // KGIS.Framework.AE.FeatureAPI.SplitMultipartFeature(new List() { newFeature }); // IPointCollection pointCollection = geometryNew as IPointCollection; // for (int j = 0; j < pointCollection.PointCount; j++) // { // if (KGIS.Framework.AE.FeatureAPI.IsInterSect(pointCollection.get_Point(j) as IGeometry, item)) // { // pPolyline.SplitAtPoint(pointCollection.get_Point(j), false, false, out isSplit, out splitIndex, out segIndex); // } // } // GeoList[k] = KGIS.Framework.AE.FeatureAPI.ConstructPolygonFromPolyline(pPolyline); // } //} //featureSelection.Clear(); //foreach (IGeometry item in GeoList) //{ // DrawFeature(layer.FeatureClass, item, featureSelection); //} //featureSelection.SelectionChanged(); #endregion #region 打开数据检查助手 //if (dataCheckView == null) //{ // dataCheckView = new CheckAssistant(m_hookHelper); // dataCheckView.Width = 310; // IPoint topRightPoint = new PointClass(); // topRightPoint.X = m_hookHelper.ActiveView.Extent.XMax; // topRightPoint.Y = m_hookHelper.ActiveView.Extent.YMax; // topRightPoint.SpatialReference = m_hookHelper.FocusMap.SpatialReference; // int x2 = 0; // int y2 = 0; // //获取地图工作区右下角的坐标x2,y2,用于判断当前鼠标点是否在右边/下边边界处 // this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(topRightPoint, out x2, out y2); // System.Drawing.Point screenPoint = Env.Instance.KMap.AxMapControl.PointToScreen(new System.Drawing.Point(x2, y2)); // dataCheckView.Top = screenPoint.Y; // dataCheckView.Left = screenPoint.X - 310; // dataCheckView.Closed += dataCheckView_Closed; // dataCheckView.ShowInMainForm(); //} //dataCheckView.InitData(featureList); #endregion m_editor.StopOperation("画线物面"); //KGIS.Common.Utility.CustomLogAPI.WriteSystemOperationLog("数据新增", "画线物面"); } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 执行 DrawComplete 异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 执行 DrawComplete 异常信息结束"); m_editor.AbortOperation(); MessageHelper.ShowError(ex.Message); } finally { DelElement(ref element); PointElement = new List(); this.LeftLine.Dissvoe(); this.RightLine.Dissvoe(); this.MiddleLine.Dissvoe(); this.MiddleLine.Init(); this.RightLine.Init(); this.LeftLine.Init(); this.m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, m_hookHelper.ActiveView.Extent); this.m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, m_hookHelper.ActiveView.Extent); this.TempWidht = -1; this.TempCenterPoint = null; this.IsChangedWidht = false; this.IsDrawing = false; this.IsContinueDraw = false; } } /// /// 绘制图形到图层上 /// /// /// /// //[LogWrite(Description = "")] private void DrawFeature(IFeatureClass pFeatureClass, IGeometry geometry, IFeatureSelection featureSelection) { //绘制出空图形问题 if (geometry == null || geometry.IsEmpty) { return; } IFeature feature = pFeatureClass.CreateFeature(); feature.Shape = geometry; feature.Shape.SpatialReference = m_hookHelper.FocusMap.SpatialReference; //属性继承 //FeatureHelper.SetFeatureAttribute(feature);//以后待改回 if (!string.IsNullOrWhiteSpace(this.drawParam.DLBM)) { string[] str = this.drawParam.DLBM.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); if (str.Length == 2) { int index = feature.Fields.FindField("DLBM"); if (index > -1) { feature.set_Value(index, str[0]); } index = feature.Fields.FindField("DLMC"); if (index > -1) { feature.set_Value(index, str[1]); } } } feature.Store(); featureSelection.Add(feature); } //[LogWrite(Description = "")] void dataCheckView_Closed(object sender, EventArgs e) { //dataCheckView = null; } //[LogWrite(Description = "")] public override bool Deactivate() { int selectIdZYQ = 1; IUcZYQMagrHelper ucZYQMagrHelper = null; ProjectInfo ProInfo = MapsManager.Instance.MapService.GetProjectInfo() as ProjectInfo; if (ProInfo != null && ProInfo.ProjType == EnumProjType.BHTBTQ && Platform.Instance.SystemType == SystemTypeEnum.BGFWCG) { ucZYQMagrHelper = BundleRuntime.Instance.GetFirstOrDefaultService(); if (ucZYQMagrHelper != null) { selectIdZYQ = ucZYQMagrHelper.GetCheckedID(); } } Dispose(); if (paramFrm != null) { paramFrm.Close(); paramFrm = null; } if (ucZYQMagrHelper != null) { ucZYQMagrHelper.AddMask(selectIdZYQ); } //if (this.MiddleLine != null) //{ // this.MiddleLine.Dissvoe(); //} //if (this.LeftLine != null) //{ // this.LeftLine.Dissvoe(); //} //if (this.RightLine != null) //{ // this.RightLine.Dissvoe(); //} //this.MiddleLine = new LineModel(m_hookHelper.ActiveView, esriSimpleLineStyle.esriSLSDash, 0.5); //this.LeftLine = new LineModel(m_hookHelper.ActiveView, esriSimpleLineStyle.esriSLSSolid); //this.RightLine = new LineModel(m_hookHelper.ActiveView, esriSimpleLineStyle.esriSLSSolid); //Env.Instance.Platfrom.MapMouseWheel -= Platfrom_MapMouseWheel; //if (timer != null) //{ // timer.Tick -= timer_Tick; // timer.Stop(); //} //autoDistinguishTimer.Tick -= autoDistinguishTimer_Tick; //autoDistinguishTimer.Stop(); //PointElement = new List(); //this.IsDrawing = false; //IsDeactivate = true; //this.m_checked = false; return base.Deactivate(); } //[LogWrite(Description = "")] private void LeftClick(int X, int Y) { //左键按下取点 IPoint point = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); if (this.MiddleLine.Line.PointCount > 0 && IsDrawing == false) { #region 调整单个点的位置 if (SnapElementPointIndex == -1) { SnapElementPointIndex = SnapElement(point, out SnapElementPointLine); //IsDrawing = true; } else { if (SnapElementPointLine == 0) { this.MiddleLine.Line.UpdatePoint(SnapElementPointIndex, point); double angle = 0; if (SnapElementPointIndex == 0) { angle = GeometryOperations.getAngle(point, this.MiddleLine.Line.get_Point(SnapElementPointIndex + 1)); } else { angle = GeometryOperations.getAngle(this.MiddleLine.Line.get_Point(SnapElementPointIndex - 1), point); } this.LeftLine.Line.UpdatePoint(SnapElementPointIndex, GeometryOperations.GetPoint(point, this.drawParam.Width * 0.5, -angle)); this.RightLine.Line.UpdatePoint(SnapElementPointIndex, GeometryOperations.GetPoint(point, this.drawParam.Width * -0.5, -angle)); this.MiddleLine.RefreshPoint(SnapElementPointIndex); this.LeftLine.RefreshPoint(SnapElementPointIndex); this.RightLine.RefreshPoint(SnapElementPointIndex); } else if (SnapElementPointLine == 1) { this.LeftLine.Line.UpdatePoint(SnapElementPointIndex, point); this.LeftLine.RefreshPoint(SnapElementPointIndex); } else if (SnapElementPointLine == -1) { this.RightLine.Line.UpdatePoint(SnapElementPointIndex, point); this.RightLine.RefreshPoint(SnapElementPointIndex); } SnapElementPointIndex = -1; IsDrawing = false; } #endregion } else { #region 绘制点 #region 根据道路宽度调整相关参数 if (TempWidht < 10) { MinPointDistance = 15; MaxPointDistance = 40; } else if (TempWidht > 15) { MinPointDistance = 30; MaxPointDistance = 80; } #endregion if (this.MiddleLine.Line.PointCount > 0) { IPoint p = this.MiddleLine.Line.get_Point(this.MiddleLine.Line.PointCount - 1); if (p.X == point.X && p.Y == point.Y) { return; } IPolyline line = new PolylineClass(); line.FromPoint = point; line.ToPoint = p; if (line.Length < 3) { return; } } if (TempWidht == -1) { TempWidht = 10; } Drawing(point); if (this.MiddleLine.Line.PointCount > 0) this.IsDrawing = true; if (this.MiddleLine.Line.PointCount > 1) { IPoint p2 = MiddleLine.Line.get_Point(this.MiddleLine.Line.PointCount - 2); IPoint p1 = MiddleLine.Line.get_Point(this.MiddleLine.Line.PointCount - 1); double angle = GeometryOperations.getAngle(p2, p1); //angle = 90 - angle; IPolyline tempLine = new PolylineClass(); tempLine.FromPoint = p1; tempLine.ToPoint = p2; MoveMapExtent(X, Y, (int)Math.Floor(tempLine.Length)); if (this.drawParam.IsAutoTrack) { //this.OnMouseDown(2, Shift, MousePoint.X, MousePoint.Y); } } else { MoveMapExtent(X, Y, 100); } #endregion } } #endregion /// /// 获取两条线段交点 /// /// /// /// /// //[LogWrite(Description = "")] private IPoint GetIntersectPoint(IPoint pointStart, IPoint pointEnd, IGeometry targetGeo) { IPolyline newLine = new PolylineClass(); IPointCollection newLinepoint = newLine as IPointCollection; if (pointStart.X == pointEnd.X) { double minY = targetGeo.Envelope.YMin; newLinepoint.AddPoint(pointStart); newLinepoint.AddPoint(new PointClass() { X = pointEnd.X, Y = minY }); } else { double pointX = pointEnd.X > pointStart.X ? targetGeo.Envelope.XMax : targetGeo.Envelope.XMin; double sourceLineK = (pointStart.Y - pointEnd.Y) / (pointStart.X - pointEnd.X); double longPointY = pointStart.Y - ((pointStart.X - pointX) * sourceLineK); newLinepoint.AddPoint(pointStart); newLinepoint.AddPoint(new PointClass() { X = pointX, Y = longPointY }); } ITopologicalOperator topOper = targetGeo as ITopologicalOperator; IGeometry geometry = topOper.Intersect(newLine as IGeometry, esriGeometryDimension.esriGeometry0Dimension); return GetMinDisPoint(geometry, pointEnd); } //[LogWrite(Description = "")] private IPoint GetMinDisPoint(IGeometry geometry, IPoint pointEnd) { if (!geometry.IsEmpty) { IProximityOperator operatorPr = geometry as IProximityOperator; return operatorPr.ReturnNearestPoint(pointEnd, esriSegmentExtension.esriExtendTangents); } return null; } /// /// 滚动滚轮调整宽度 /// /// /// //[LogWrite(Description = "")] void Platfrom_MapMouseWheel(object sender, System.Windows.Forms.MouseEventArgs e) { if (IsDeactivate) return; if (drawParam != null) { //替换Env改动 //if (Env.Instance.CurrentKeyDown == 17) if (Platform.Instance.GetCurrentKeyDown() == 17) { IPoint point = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(MousePoint.X, MousePoint.Y); if (e.Delta > 0) { drawParam.Width = drawParam.Width + 0.5; } else if (e.Delta < 0 && drawParam.Width > 0) { drawParam.Width = drawParam.Width - 0.5; } int d = (int)Math.Abs(drawParam.Width); if (d == 0) return; if (d < 10) { drawParam.ToloranceScale = 0.1; } if (d == 10) { drawParam.ToloranceScale = 0.15; } if (d > 10 && d < 20) { drawParam.ToloranceScale = 0.2; } if (d == 20) { drawParam.ToloranceScale = 0.25; } if (d > 20) { drawParam.ToloranceScale = 0.3; } if (d > 30) { drawParam.ToloranceScale = 0.4; } if (d > 40) { drawParam.ToloranceScale = 0.5; } this.IsChangedWidht = true; DrawTextElement(point, ref TextElement); //this.OnMouseMove(1, 0, MousePoint.X, MousePoint.Y); //传入IsChangedWidht Moveing(point, IsChangedWidht); } else { //shift+滚轮调节识别度 //if (IsDrawing) if (IsShiftDown) { if (e.Delta > 0) { //drawParam.ToloranceScale += 0.05; this.OnKeyDown((int)ConsoleKey.D0, 0); } if (e.Delta < 0) { //drawParam.ToloranceScale -= 0.05; this.OnKeyDown((int)ConsoleKey.D9, 0); } this.OnKeyDown((int)ConsoleKey.P, 0); } else { //添加滚轮放大缩小地图 //替换Env改动 //Env.Instance.KMap.AxMapControl.AutoMouseWheel = true; //Env.Instance.KMap.AxMapControl.AutoKeyboardScrolling = true; (m_hookHelper.Hook as IMapControlDefault).AutoMouseWheel = true; (m_hookHelper.Hook as IMapControlDefault).AutoKeyboardScrolling = true; //---------------- } } } } /// /// 移动地图范围 /// /// 鼠标位置的X坐标 /// 鼠标位置的Y坐标 /// 鼠标位置距离地图边界的宽度 //[LogWrite(Description = "")] private void MoveMapExtent(int X, int Y, int pWidth) { //鼠标点击的点 IPoint point = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); #region 当鼠标点击屏幕边界时移动地图范围 //当前屏幕中心点坐标 IPoint centerPoint = new PointClass() { X = (this.m_hookHelper.ActiveView.Extent.XMax - this.m_hookHelper.ActiveView.Extent.Width / 2), Y = (this.m_hookHelper.ActiveView.Extent.YMax - this.m_hookHelper.ActiveView.Extent.Height / 2) }; //地图窗口右下角坐标 IPoint p = new PointClass() { X = this.m_hookHelper.ActiveView.Extent.XMax, Y = this.m_hookHelper.ActiveView.Extent.YMin }; //鼠标点击到边界时移动地图 int x2 = 0; int y2 = 0; //获取地图工作区右下角的坐标x2,y2,用于判断当前鼠标点是否在右边/下边边界处 this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p, out x2, out y2); //获取工作区右下角的坐标对应的屏幕坐标 //替换Env改动 //System.Drawing.Point rightBottomPoint = Env.Instance.KMap.AxMapControl.PointToScreen(new System.Drawing.Point(x2, y2)); System.Drawing.Point rightBottomPoint = _MapService.PointToScreen(new System.Drawing.Point(x2, y2)); //获取工作区左上角的坐标对应的屏幕坐标 //替换Env改动 //System.Drawing.Point leftTopPoint = Env.Instance.KMap.AxMapControl.PointToScreen(new System.Drawing.Point(0, 0)); System.Drawing.Point leftTopPoint = _MapService.PointToScreen(new System.Drawing.Point(0, 0)); IPoint CPoint = point; double angle = 0; if (MiddleLine.Line.PointCount > 1) { //计算当前道路线的方向 angle = GeometryOperations.getAngle(MiddleLine.Line.get_Point(MiddleLine.Line.PointCount - 2), MiddleLine.Line.get_Point(MiddleLine.Line.PointCount - 1)); } //计算屏幕每像素代表实际横向距离 double d1 = this.m_hookHelper.ActiveView.Extent.Width / x2; //计算屏幕每像素代表实际纵向距离 double d2 = this.m_hookHelper.ActiveView.Extent.Height / y2; IPoint p1 = MiddleLine.Line.get_Point(this.MiddleLine.Line.PointCount - 1); //自动识别的下一个点的位置 IPoint n_p = null; //第一次识别的点 IPoint n_p2 = null; //第二次识别的点 IPoint n_p3 = null; //记录自动识别下一点的宽度 IPolyline line = null; //第一次识别的宽度 IPolyline line2 = null; //第二次识别的宽度 IPolyline line3 = null; IPolyline tempLine = new PolylineClass(); if (this.MiddleLine.Line.PointCount > 1) { double d = 0; if (this.MiddleLine.Line.PointCount > 0) { tempLine.FromPoint = this.LeftLine.Line.get_Point(this.LeftLine.Line.PointCount - 1); tempLine.ToPoint = this.RightLine.Line.get_Point(this.RightLine.Line.PointCount - 1); d = tempLine.Length; } n_p2 = GeometryOperations.GetPoint(p1, pWidth, 90 - angle); line2 = (IPolyline)AutoDistinguish3(0, n_p2); if (Math.Abs(line2.Length - d) > 4) { n_p3 = GeometryOperations.GetPoint(p1, pWidth + pWidth * 0.1, 90 - angle); line3 = (IPolyline)AutoDistinguish3(0, n_p3); if (Math.Abs(line2.Length - d) < Math.Abs(line3.Length - d)) { n_p = n_p2; line = line2; } else { n_p = n_p3; line = line3; } } else { n_p = n_p2; line = line2; } #region 将自动识别的点显示在地图上 TempCenterPoint = new PointClass(); TempCenterPoint.X = line.FromPoint.X - (line.FromPoint.X - line.ToPoint.X) / 2; TempCenterPoint.Y = line.FromPoint.Y - (line.FromPoint.Y - line.ToPoint.Y) / 2; TempCenterPoint.SpatialReference = (line as IPolyline).SpatialReference; IPointCollection newPoints = new Polyline(); newPoints.AddPoint(line.FromPoint); newPoints.AddPoint(TempCenterPoint); newPoints.AddPoint(line.ToPoint); DrawPoint(newPoints); #endregion } if (n_p != null) { //计算下一个点的坐标对应的地图工作区坐标位置 int nextX = 0; int nextY = 0; this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(n_p, out nextX, out nextY); if (nextX - 50 < 0 || nextX + 50 > x2) { #region 横向移动 double moveWidth = 0; if (nextX - 50 < 0) { moveWidth = Math.Abs(nextX - 50) * d1; } else if (nextX + 50 > x2) { moveWidth = (nextX + 50 - x2) * d1; } if (moveWidth < this.m_hookHelper.ActiveView.Extent.Width / 2) { moveWidth = this.m_hookHelper.ActiveView.Extent.Width * 0.5; } if (angle != 0) { CPoint = GeometryOperations.GetPoint(centerPoint, moveWidth, 90 - angle); (this.m_hookHelper.Hook as IMapControl2).CenterAt(CPoint); } else { (this.m_hookHelper.Hook as IMapControl2).CenterAt(CPoint); this.OnMouseMove(1, 0, MousePoint.X + 1, MousePoint.Y + 1); } #endregion } if (nextY < 50 || nextY + 50 > y2) { #region 纵向移动 double moveWidth = 0; if (nextY + 50 < 0) { moveWidth = Math.Abs(nextY - 50) * d2; if (moveWidth < this.m_hookHelper.ActiveView.Extent.Height / 2) { moveWidth = this.m_hookHelper.ActiveView.Extent.Height * 0.5; } } else if (nextY + 50 > y2) { moveWidth = (nextY + 50 - y2) * d2; if (moveWidth < this.m_hookHelper.ActiveView.Extent.Height / 2) { moveWidth = this.m_hookHelper.ActiveView.Extent.Height * 0.5; } } if (angle != 0) { CPoint = GeometryOperations.GetPoint(centerPoint, moveWidth, 90 - angle); (this.m_hookHelper.Hook as IMapControl2).CenterAt(CPoint); } else { (this.m_hookHelper.Hook as IMapControl2).CenterAt(CPoint); this.OnMouseMove(1, 0, MousePoint.X + 1, MousePoint.Y + 1); } #endregion } this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(TempCenterPoint, out nextX, out nextY); int m_x = 0; int m_y = 0; this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(n_p, out m_x, out m_y); //替换Env改动 //System.Drawing.Point screenPoint = Env.Instance.KMap.AxMapControl.PointToScreen(new System.Drawing.Point(m_x, m_y)); System.Drawing.Point screenPoint = _MapService.PointToScreen(new System.Drawing.Point(m_x, m_y)); this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p1, out nextX, out nextY); this.MousePoint.X = m_x; this.MousePoint.Y = m_y; //SetCursorPos(screenPoint.X, screenPoint.Y); if (this.drawParam.IsAutoStep) { SetCursorPos(screenPoint.X, screenPoint.Y); } //this.m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography,null, if (this.drawParam.IsAutoTrack && IsAuto) { double angle2 = GeometryOperations.getAngle(MiddleLine.Line.get_Point(MiddleLine.Line.PointCount - 1), TempCenterPoint); ITopologicalOperator topo = TempCenterPoint as ITopologicalOperator; IGeometry geo = topo.Buffer(line.Length / 2); ImgDistinguish imgDis = new ImgDistinguish(); TilesImage img = imgDis.GetImg(geo.Envelope); if (img == null) return; img.PixelCount = 9; int gray1 = img.GetGrayValue(TempCenterPoint); topo = MiddleLine.Line.get_Point(MiddleLine.Line.PointCount - 1) as ITopologicalOperator; geo = topo.Buffer(line.Length / 2); img = imgDis.GetImg(geo.Envelope); if (img == null) return; img.PixelCount = 9; int gray2 = img.GetGrayValue(MiddleLine.Line.get_Point(MiddleLine.Line.PointCount - 1)); int w = pWidth / 3; if (Math.Abs(Math.Abs(angle) - Math.Abs(angle2)) < 10) { if (Math.Abs(gray1 - gray2) < 25 && Math.Abs(line.Length - tempLine.Length) < tempLine.Length * 0.3) { IsAutoTrackPoint = true; this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(TempCenterPoint, out nextX, out nextY); this.OnMouseDown(2, 0, nextX, nextY); } else { int i = 0; while (pWidth - w >= 3) { i++; w = w + pWidth / 3; if (i > 3) { IsAutoTrackPoint = false; break; } IPoint c_P = AutoTrack(X, Y, pWidth - w); if (c_P != null) { TempCenterPoint = c_P; IsAutoTrackPoint = true; this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(TempCenterPoint, out nextX, out nextY); this.OnMouseDown(2, 0, nextX, nextY); break; } else { IsAutoTrackPoint = false; } } } } else { if (Math.Abs(gray1 - gray2) < 30 && Math.Abs(line.Length - tempLine.Length) < tempLine.Length * 0.3) { IsAutoTrackPoint = true; this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(TempCenterPoint, out nextX, out nextY); this.OnMouseDown(2, 0, nextX, nextY); } else { int i = 0; while (pWidth - w >= 3) { i++; w = w + pWidth / 3; if (i > 3) { IsAutoTrackPoint = false; break; } IPoint c_P = AutoTrack(X, Y, pWidth - w); if (c_P != null) { TempCenterPoint = c_P; IsAutoTrackPoint = true; this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(TempCenterPoint, out nextX, out nextY); this.OnMouseDown(2, 0, nextX, nextY); break; } else { IsAutoTrackPoint = false; } } //if (pWidth / 3 >= 3) //{ // MoveMapExtent(X, Y, pWidth / 3); //} //else //{ // IsAutoTrackPoint = false; //} } } } } #endregion } //[LogWrite(Description = "")] private IPoint AutoTrack(int X, int Y, int pWidth) { IPoint result = null; try { //鼠标点击的点 IPoint point = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); #region 当鼠标点击屏幕边界时移动地图范围 //当前屏幕中心点坐标 IPoint centerPoint = new PointClass() { X = (this.m_hookHelper.ActiveView.Extent.XMax - this.m_hookHelper.ActiveView.Extent.Width / 2), Y = (this.m_hookHelper.ActiveView.Extent.YMax - this.m_hookHelper.ActiveView.Extent.Height / 2) }; //地图窗口右下角坐标 IPoint p = new PointClass() { X = this.m_hookHelper.ActiveView.Extent.XMax, Y = this.m_hookHelper.ActiveView.Extent.YMin }; //鼠标点击到边界时移动地图 int x2 = 0; int y2 = 0; //获取地图工作区右下角的坐标x2,y2,用于判断当前鼠标点是否在右边/下边边界处 this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p, out x2, out y2); //获取工作区右下角的坐标对应的屏幕坐标 //替换Env改动 //System.Drawing.Point rightBottomPoint = Env.Instance.KMap.AxMapControl.PointToScreen(new System.Drawing.Point(x2, y2)); System.Drawing.Point rightBottomPoint = _MapService.PointToScreen(new System.Drawing.Point(x2, y2)); //获取工作区左上角的坐标对应的屏幕坐标 //替换Env改动 //System.Drawing.Point leftTopPoint = Env.Instance.KMap.AxMapControl.PointToScreen(new System.Drawing.Point(0, 0)); System.Drawing.Point leftTopPoint = _MapService.PointToScreen(new System.Drawing.Point(0, 0)); IPoint CPoint = point; double angle = 0; if (MiddleLine.Line.PointCount > 1) { //计算当前道路线的方向 angle = GeometryOperations.getAngle(MiddleLine.Line.get_Point(MiddleLine.Line.PointCount - 2), MiddleLine.Line.get_Point(MiddleLine.Line.PointCount - 1)); } //计算屏幕每像素代表实际横向距离 double d1 = this.m_hookHelper.ActiveView.Extent.Width / x2; //计算屏幕每像素代表实际纵向距离 double d2 = this.m_hookHelper.ActiveView.Extent.Height / y2; IPoint p1 = MiddleLine.Line.get_Point(this.MiddleLine.Line.PointCount - 1); //自动识别的下一个点的位置 IPoint n_p = null; //第一次识别的点 IPoint n_p2 = null; //第二次识别的点 IPoint n_p3 = null; //记录自动识别下一点的宽度 IPolyline line = null; //第一次识别的宽度 IPolyline line2 = null; //第二次识别的宽度 IPolyline line3 = null; IPolyline tempLine = new PolylineClass(); if (this.MiddleLine.Line.PointCount > 1) { double d = 0; if (this.MiddleLine.Line.PointCount > 0) { tempLine.FromPoint = this.LeftLine.Line.get_Point(this.LeftLine.Line.PointCount - 1); tempLine.ToPoint = this.RightLine.Line.get_Point(this.RightLine.Line.PointCount - 1); d = tempLine.Length; } n_p2 = GeometryOperations.GetPoint(p1, pWidth, 90 - angle); line2 = (IPolyline)AutoDistinguish3(0, n_p2); if (Math.Abs(line2.Length - d) > 4) { n_p3 = GeometryOperations.GetPoint(p1, pWidth + pWidth * 0.1, 90 - angle); line3 = (IPolyline)AutoDistinguish3(0, n_p3); if (Math.Abs(line2.Length - d) < Math.Abs(line3.Length - d)) { n_p = n_p2; line = line2; } else { n_p = n_p3; line = line3; } } else { n_p = n_p2; line = line2; } #region 将自动识别的点显示在地图上 TempCenterPoint = new PointClass(); TempCenterPoint.X = line.FromPoint.X - (line.FromPoint.X - line.ToPoint.X) / 2; TempCenterPoint.Y = line.FromPoint.Y - (line.FromPoint.Y - line.ToPoint.Y) / 2; TempCenterPoint.SpatialReference = (line as IPolyline).SpatialReference; IPointCollection newPoints = new Polyline(); newPoints.AddPoint(line.FromPoint); newPoints.AddPoint(TempCenterPoint); newPoints.AddPoint(line.ToPoint); DrawPoint(newPoints); #endregion } //计算下一个点的坐标对应的地图工作区坐标位置 int nextX = 0; int nextY = 0; #region //this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(n_p, out nextX, out nextY); //if (nextX - 50 < 0 || nextX + 50 > x2) //{ // #region 横向移动 // double moveWidth = 0; // if (nextX - 50 < 0) // { // moveWidth = Math.Abs(nextX - 50) * d1; // } // else if (nextX + 50 > x2) // { // moveWidth = (nextX + 50 - x2) * d1; // } // if (angle != 0) // { // CPoint = GeometryOperations.GetPoint(centerPoint, moveWidth, 90 - angle); // (this.m_hookHelper.Hook as IMapControl2).CenterAt(CPoint); // } // else // { // (this.m_hookHelper.Hook as IMapControl2).CenterAt(CPoint); // this.OnMouseMove(1, 0, MousePoint.X + 1, MousePoint.Y + 1); // } // #endregion //} //if (nextY + 50 < 0 || nextY + 50 > y2) //{ // #region 纵向移动 // double moveWidth = 0; // if (nextY + 50 < 0) // { // moveWidth = Math.Abs(nextY - 50) * d2; // } // else if (nextY + 50 > y2) // { // moveWidth = -(nextY + 50 - x2) * d2; // } // if (angle != 0) // { // CPoint = GeometryOperations.GetPoint(centerPoint, moveWidth, 90 - angle); // (this.m_hookHelper.Hook as IMapControl2).CenterAt(CPoint); // } // else // { // (this.m_hookHelper.Hook as IMapControl2).CenterAt(CPoint); // this.OnMouseMove(1, 0, MousePoint.X + 1, MousePoint.Y + 1); // } // #endregion //} #endregion if (n_p != null) { this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(TempCenterPoint, out nextX, out nextY); int m_x = 0; int m_y = 0; this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(n_p, out m_x, out m_y); //替换Env改动 //System.Drawing.Point screenPoint = Env.Instance.KMap.AxMapControl.PointToScreen(new System.Drawing.Point(m_x, m_y)); System.Drawing.Point screenPoint = _MapService.PointToScreen(new System.Drawing.Point(m_x, m_y)); this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p1, out nextX, out nextY); this.MousePoint.X = m_x; this.MousePoint.Y = m_y; SetCursorPos(screenPoint.X, screenPoint.Y); if (this.drawParam.IsAutoTrack) { double angle2 = GeometryOperations.getAngle(MiddleLine.Line.get_Point(MiddleLine.Line.PointCount - 1), TempCenterPoint); ITopologicalOperator topo = TempCenterPoint as ITopologicalOperator; IGeometry geo = topo.Buffer(line.Length / 2); ImgDistinguish imgDis = new ImgDistinguish(); TilesImage img = imgDis.GetImg(geo.Envelope); if (img == null) return result; img.PixelCount = 9; int gray1 = img.GetGrayValue(TempCenterPoint); topo = MiddleLine.Line.get_Point(MiddleLine.Line.PointCount - 1) as ITopologicalOperator; geo = topo.Buffer(line.Length / 2); img = imgDis.GetImg(geo.Envelope); if (img == null) return result; img.PixelCount = 9; int gray2 = img.GetGrayValue(MiddleLine.Line.get_Point(MiddleLine.Line.PointCount - 1)); if (Math.Abs(Math.Abs(angle) - Math.Abs(angle2)) < 5 && Math.Abs(gray1 - gray2) < 25 && Math.Abs(line.Length - tempLine.Length) < tempLine.Length * 0.3) { //IsAutoTrackPoint = true; //this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(TempCenterPoint, out nextX, out nextY); //this.OnMouseDown(2, 0, nextX, nextY); result = TempCenterPoint; } else { //IsAutoTrackPoint = false; } } } return result; #endregion } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 执行 AutoTrack 异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 执行 AutoTrack 异常信息结束"); throw ex; } } /// /// 定时进行自动识别影像 /// /// /// //[LogWrite(Description = "")] void autoDistinguishTimer_Tick(object sender, EventArgs e) { try { IPoint point = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(MousePoint.X, MousePoint.Y); double angle = 0; if (MiddleLine.Line.PointCount <= 0) { return; #region //IPolyline p1 = (IPolyline)AutoDistinguish(0); //IPolyline p2 = (IPolyline)AutoDistinguish(90); //if (p1.Length > p2.Length) //{ // TempWidht = p2.Length; // #region 将自动识别记过显示在地图上 // TempCenterPoint = new PointClass(); // TempCenterPoint.X = p2.FromPoint.X - (p2.FromPoint.X - p2.ToPoint.X) / 2; // TempCenterPoint.Y = p2.FromPoint.Y - (p2.FromPoint.Y - p2.ToPoint.Y) / 2; // TempCenterPoint.SpatialReference = (p2 as IPolyline).SpatialReference; // IPointCollection newPoints = new Polyline(); // newPoints.AddPoint(p2.FromPoint); // newPoints.AddPoint(TempCenterPoint); // newPoints.AddPoint(p2.ToPoint); // DrawPoint(newPoints); // #endregion //} //else //{ // TempWidht = p1.Length; // #region 将自动识别记过显示在地图上 // TempCenterPoint = new PointClass(); // TempCenterPoint.X = p1.FromPoint.X - (p1.FromPoint.X - p1.ToPoint.X) / 2; // TempCenterPoint.Y = p1.FromPoint.Y - (p1.FromPoint.Y - p1.ToPoint.Y) / 2; // TempCenterPoint.SpatialReference = (p1 as IPolyline).SpatialReference; // IPointCollection newPoints = new Polyline(); // newPoints.AddPoint(p1.FromPoint); // newPoints.AddPoint(TempCenterPoint); // newPoints.AddPoint(p1.ToPoint); // DrawPoint(newPoints); // #endregion //} #endregion } else { //LogAPI.Debug("开始时间:" + DateTime.Now.Subtract(); angle = GeometryOperations.getAngle(MiddleLine.Line.Point[MiddleLine.Line.PointCount - 1], point); if (double.IsNaN(angle) && (MiddleLine.Line.PointCount - 2) > -1) { angle = GeometryOperations.getAngle(MiddleLine.Line.Point[MiddleLine.Line.PointCount - 2], point); } if (!Double.IsNaN(angle)) { //DateTime t1 = DateTime.Now; //Int32 d = t1.Minute * 60 * 1000 + t1.Second * 1000 + t1.Millisecond; //LogAPI.Debug("开始时间:" + (t1.Minute * 60 * 1000 + t1.Second * 1000 + t1.Millisecond)); IPolyline polyline = (IPolyline)AutoDistinguish(angle); this.drawParam.ToloranceScale += 0.05; IPolyline polyline1 = (IPolyline)AutoDistinguish(angle); this.drawParam.ToloranceScale -= 0.1; IPolyline polyline2 = (IPolyline)AutoDistinguish(angle); this.drawParam.ToloranceScale += 0.05; double d = this.drawParam.Width; if (this.MiddleLine.Line.PointCount > 0) { IPolyline tempLine = new PolylineClass(); tempLine.FromPoint = this.LeftLine.Line.get_Point(this.LeftLine.Line.PointCount - 1); tempLine.ToPoint = this.RightLine.Line.get_Point(this.RightLine.Line.PointCount - 1); d = tempLine.Length; } if (Math.Abs(polyline.Length - d) < Math.Abs(polyline1.Length - d)) { if (Math.Abs(polyline.Length - d) > Math.Abs(polyline2.Length - d)) { polyline = polyline2; } } else { if (Math.Abs(polyline1.Length - d) > Math.Abs(polyline2.Length - d)) { polyline = polyline2; } else { polyline = polyline1; } } TempWidht = polyline.Length; if ((TempWidht > this.drawParam.Width + this.drawParam.Width * 0.5 || TempWidht < this.drawParam.Width - this.drawParam.Width * 0.5) && this.MiddleLine.Line.PointCount > 1) { TempWidht = -1; TempCenterPoint = null; try { if (PointElement.Count > 0) { foreach (IElement item in PointElement) { m_hookHelper.ActiveView.GraphicsContainer.DeleteElement(item); } PointElement = new List(); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_hookHelper.ActiveView.Extent); } } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程 中 定时进行自动识别影像 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程 中 定时进行自动识别影像 异常信息结束"); } } else { #region 将自动识别的点显示在地图上 TempCenterPoint = new PointClass(); TempCenterPoint.X = polyline.FromPoint.X - (polyline.FromPoint.X - polyline.ToPoint.X) / 2; TempCenterPoint.Y = polyline.FromPoint.Y - (polyline.FromPoint.Y - polyline.ToPoint.Y) / 2; TempCenterPoint.SpatialReference = (polyline as IPolyline).SpatialReference; IPointCollection newPoints = new Polyline(); newPoints.AddPoint(polyline.FromPoint); newPoints.AddPoint(TempCenterPoint); newPoints.AddPoint(polyline.ToPoint); DrawPoint(newPoints); #endregion } //DateTime t2 = DateTime.Now; //Int32 d2 = t2.Minute * 60 * 1000 + t2.Second * 1000 + t2.Millisecond; //LogAPI.Debug("识别结束:" + (t2.Minute * 60 * 1000 + t2.Second * 1000 + t2.Millisecond)); //LogAPI.Debug("识别结束:" + (d2 - d) + "毫秒"); } } autoDistinguishTimer.Stop(); } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 定时进行自动识别影像 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 定时进行自动识别影像 时异常信息结束"); } } #region 捕捉 //[LogWrite(Description = "")] private List Snapping(IPoint pPoint, List pLayers) { List result = new List(); try { if (pPoint != null && pLayers != null) { foreach (IFeatureLayer item in pLayers) { IIdentify identify = item as IIdentify; if (identify == null) continue; ESRI.ArcGIS.esriSystem.IArray array = identify.Identify(pPoint); if (array == null) continue; for (int i = 0; i < array.Count; i++) { IRowIdentifyObject row = (IRowIdentifyObject)array.get_Element(i); if (row == null) continue; IFeature f = row.Row as IFeature; result.Add(f); } } } } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 捕捉 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 捕捉 时异常信息结束"); } return result; } #endregion #region 获取所有可见图层 /// /// 获取当前地图中可见的矢量图层 /// /// /// //[LogWrite(Description = "")] private List GetVisibleLayer(IMap pMap, esriGeometryType geoType = esriGeometryType.esriGeometryAny) { List result = new List(); if (pMap == null) return result; try { for (int i = 0; i < pMap.LayerCount; i++) { ILayer layer = pMap.get_Layer(i); if (layer is IFeatureLayer) { if ((layer as IFeatureLayer).Visible && (layer as IFeatureLayer).FeatureClass.ShapeType == geoType) { result.Add(layer as IFeatureLayer); } } else if (layer is ICompositeLayer) { if ((layer as IGroupLayer).Visible) { result.AddRange(GetVisibleLayerByGroupLayer(layer as ICompositeLayer, geoType)); } } } } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 获取当前地图中可见的矢量图层 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 获取当前地图中可见的矢量图层 时异常信息结束"); } return result; } //[LogWrite(Description = "")] private List GetVisibleLayerByGroupLayer(ICompositeLayer pGroupLayer, esriGeometryType geoType = esriGeometryType.esriGeometryAny) { List result = new List(); if (pGroupLayer != null && pGroupLayer.Count > 0) { for (int i = 0; i < pGroupLayer.Count; i++) { ILayer layer = pGroupLayer.get_Layer(i); if (layer is IAnnotationLayer) { } else if (layer is IGroupLayer) { if ((layer as IGroupLayer).Visible) { result.AddRange(GetVisibleLayerByGroupLayer(layer as ICompositeLayer, geoType)); } } else { if (layer is IFeatureLayer) { if ((layer as IFeatureLayer).Visible && (layer as IFeatureLayer).FeatureClass.ShapeType == geoType) { result.Add((IFeatureLayer)layer); } } } } } return result; } #endregion #region 绘制相关私有函数 //[LogWrite(Description = "")] private IPointCollection AutoDistinguish3(double angle = 0, IPoint pPoint = null) { IPolyline polyline = (IPolyline)AutoDistinguish(angle, pPoint); this.drawParam.ToloranceScale += 0.05; IPolyline polyline1 = (IPolyline)AutoDistinguish(angle, pPoint); this.drawParam.ToloranceScale -= 0.1; IPolyline polyline2 = (IPolyline)AutoDistinguish(angle, pPoint); this.drawParam.ToloranceScale += 0.05; double d = this.drawParam.Width; if (this.MiddleLine.Line.PointCount > 0) { IPolyline tempLine = new PolylineClass(); tempLine.FromPoint = this.LeftLine.Line.get_Point(this.LeftLine.Line.PointCount - 1); tempLine.ToPoint = this.RightLine.Line.get_Point(this.RightLine.Line.PointCount - 1); d = tempLine.Length; } if (Math.Abs(polyline.Length - d) < Math.Abs(polyline1.Length - d)) { if (Math.Abs(polyline.Length - d) > Math.Abs(polyline2.Length - d)) { polyline = polyline2; } } else { if (Math.Abs(polyline1.Length - d) > Math.Abs(polyline2.Length - d)) { polyline = polyline2; } else { polyline = polyline1; } } return polyline as IPointCollection; } /// /// 自动识别中心点 /// //[LogWrite(Description = "")] private IPointCollection AutoDistinguish(double angle = 0, IPoint pPoint = null) { #region 自动识别道路中心线 IPoint point = pPoint; if (point == null) { point = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(MousePoint.X, MousePoint.Y); } IPointCollection vertical = new Polyline(); vertical.AddPoint(point); vertical.AddPoint(point); //KOTilesLayer layer = Common.Utility.LayerHelper.GetLayerByName(m_hookHelper.FocusMap, "YGYXT"); double InitWidht = 50; //获取鼠标点周围50米的范围 IEnvelope env = new EnvelopeClass(); //计算当前道路的角度 if (MiddleLine.Line.PointCount > 1) { env.XMax = point.X + this.drawParam.Width; env.XMin = point.X - this.drawParam.Width; env.YMax = point.Y + this.drawParam.Width; env.YMin = point.Y - this.drawParam.Width; InitWidht = drawParam.Width; angle = GeometryOperations.getAngle(MiddleLine.Line.Point[MiddleLine.Line.PointCount - 1], point); if (double.IsNaN(angle) && (MiddleLine.Line.PointCount - 2) > -1) { angle = GeometryOperations.getAngle(MiddleLine.Line.Point[MiddleLine.Line.PointCount - 2], point); } if (Double.IsNaN(angle)) return vertical; } else { env.XMax = point.X + InitWidht / 2; env.XMin = point.X - InitWidht / 2; env.YMax = point.Y + InitWidht / 2; env.YMin = point.Y - InitWidht / 2; } env.SpatialReference = m_hookHelper.FocusMap.SpatialReference; if (double.IsNaN(angle)) return vertical; //根据范围获取影像图片 ImgDistinguish imgDis = new ImgDistinguish(); TilesImage img = imgDis.GetImg(env); if (img == null) return vertical; img.PixelCount = 49; //获取平均灰度值 int Gray = img.GetGrayValue(point); //重新设置单次搜索像素个数 img.PixelCount = 1; //计算单次搜索的实际距离 double distance = img.Resolution * Math.Sqrt(img.PixelCount); //记录已经搜索的总距离 double sumDistance = distance; //检索出在容差范围内的平均灰度值集合 List grayValues = new List(); grayValues.Add(Gray); //记录参考点左边的错误像素个数 int leftBadPixelCount = 0; //记录参考点右边的错误像素个数 int rightBadPixelCount = 0; //记录容差范围内的灰度平均值 double tolerance = 0; ///容差比例 double toloranceScale = this.drawParam.ToloranceScale; //容差半径(污点宽度) double toloranceRadius = 2.5; while (sumDistance < InitWidht) { #region 循环对比像素值 tolerance = Math.Floor((double)grayValues.Sum() / grayValues.Count); if (leftBadPixelCount < toloranceRadius / distance) { IPoint leftPoint = GeometryOperations.GetPoint(point, sumDistance, -angle); int grayvalue = img.GetGrayValue(leftPoint); if (grayvalue == -1) break; if (Math.Abs(grayvalue - tolerance) < tolerance * toloranceScale) { leftBadPixelCount = 0; grayValues.Add(grayvalue); vertical.UpdatePoint(0, leftPoint); } else { leftBadPixelCount++; if (leftBadPixelCount < toloranceRadius / distance / 5) { vertical.UpdatePoint(0, leftPoint); } } } if (rightBadPixelCount < toloranceRadius / distance) { IPoint rightPoint = GeometryOperations.GetPoint(point, -sumDistance, -angle); int grayvalue = img.GetGrayValue(rightPoint); if (grayvalue == -1) break; if (Math.Abs(grayvalue - tolerance) < tolerance * toloranceScale) { rightBadPixelCount = 0; grayValues.Add(grayvalue); vertical.UpdatePoint(1, rightPoint); } else { rightBadPixelCount++; if (rightBadPixelCount < toloranceRadius / distance / 5) { vertical.UpdatePoint(1, rightPoint); } } } sumDistance += distance; #endregion } return vertical; #endregion } /// /// 自动识别中心点 /// //[LogWrite(Description = "")] private IPointCollection AutoDistinguish2(IPoint pPoint, double angle, double pWidht) { #region 自动识别道路中心线 IPoint point = pPoint; IPointCollection vertical = new Polyline(); vertical.AddPoint(point); vertical.AddPoint(point); //获取鼠标点周围50米的范围 IEnvelope env = new EnvelopeClass(); env.XMax = point.X + pWidht; env.XMin = point.X - pWidht; env.YMax = point.Y + pWidht; env.YMin = point.Y - pWidht; env.SpatialReference = m_hookHelper.FocusMap.SpatialReference; if (double.IsNaN(angle)) return vertical; //根据范围获取影像图片 ImgDistinguish imgDis = new ImgDistinguish(); TilesImage img = imgDis.GetImg(env); if (img == null) return vertical; img.PixelCount = 49; //获取平均灰度值 int Gray = img.GetGrayValue(point); //重新设置单次搜索像素个数 img.PixelCount = 1; //计算单次搜索的实际距离 double distance = img.Resolution * Math.Sqrt(img.PixelCount); //记录已经搜索的总距离 double sumDistance = distance; //检索出在容差范围内的平均灰度值集合 List grayValues = new List(); grayValues.Add(Gray); //记录参考点左边的错误像素个数 int leftBadPixelCount = 0; //记录参考点右边的错误像素个数 int rightBadPixelCount = 0; //记录容差范围内的灰度平均值 double tolerance = 0; ///容差比例 double toloranceScale = this.drawParam.ToloranceScale; //容差半径 double toloranceRadius = 2.5; while (sumDistance < pWidht) { #region 循环对比像素值 tolerance = Math.Floor((double)grayValues.Sum() / grayValues.Count); if (leftBadPixelCount < toloranceRadius / distance) { IPoint leftPoint = GeometryOperations.GetPoint(point, sumDistance, -angle); int grayvalue = img.GetGrayValue(leftPoint); if (grayvalue == -1) break; if (Math.Abs(grayvalue - tolerance) < tolerance * toloranceScale) { leftBadPixelCount = 0; grayValues.Add(grayvalue); vertical.UpdatePoint(0, leftPoint); } else { leftBadPixelCount++; if (leftBadPixelCount < toloranceRadius / distance / 5) { vertical.UpdatePoint(0, leftPoint); } } } if (rightBadPixelCount < toloranceRadius / distance) { IPoint rightPoint = GeometryOperations.GetPoint(point, -sumDistance, -angle); int grayvalue = img.GetGrayValue(rightPoint); if (grayvalue == -1) break; if (Math.Abs(grayvalue - tolerance) < tolerance * toloranceScale) { rightBadPixelCount = 0; grayValues.Add(grayvalue); vertical.UpdatePoint(1, rightPoint); } else { rightBadPixelCount++; if (rightBadPixelCount < toloranceRadius / distance / 5) { vertical.UpdatePoint(1, rightPoint); } } } sumDistance += distance; #endregion } return vertical; #endregion } /// /// 绘制 /// /// //[LogWrite(Description = "")] private void Drawing(IPoint pPoint) { try { if (!IsShiftDown || this.MiddleLine.Line.PointCount > 0) { switch (drawParam.DrawMode) { case DrawMode.Left: this.MiddleLine.Scale = -0.5; this.RightLine.Scale = -1; DrawPointExe(pPoint, this.LeftLine, this.MiddleLine, this.RightLine); break; case DrawMode.Right: this.LeftLine.Scale = 1; this.MiddleLine.Scale = 0.5; DrawPointExe(pPoint, this.RightLine, this.MiddleLine, this.LeftLine); break; case DrawMode.LeftAndRight: this.RightLine.Scale = -0.5; this.LeftLine.Scale = 0.5; DrawPointExe(pPoint, this.MiddleLine, this.LeftLine, this.RightLine); break; default: break; } } else { IsContinueDraw = true; IFeatureLayer pFeatureLayer = m_editor.TargetLayer as IFeatureLayer; IIdentify pIdentify = pFeatureLayer as IIdentify; IGeometry pGeometry = m_SnapPoint as IGeometry; //获取鼠标点击的要素 IArray pArray = pIdentify.Identify(pGeometry); if (pArray == null || pArray.Count <= 0) { return; } IFeatureIdentifyObj pFeatIdObj = pArray.get_Element(0) as IFeatureIdentifyObj; IRowIdentifyObject pRowObj = pFeatIdObj as IRowIdentifyObject; IFeature pFeature = pRowObj.Row as IFeature; if (pFeature == null) { return; } IPoint clickedPt = m_SnapPoint; double searchRadius = 3; IHitTest hitShape = pFeature.ShapeCopy as IHitTest; IPoint hitPoint = new PointClass(); double hitDistance = 0; int hitPartIndex = 0; int hitSegmentIndex = 0; bool bRightSide = false; esriGeometryHitPartType hitPartType = esriGeometryHitPartType.esriGeometryPartBoundary; //获取鼠标点击的边的索引 hitShape.HitTest(clickedPt, searchRadius, hitPartType, hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide); ISegmentCollection segmentCollection = pFeature.ShapeCopy as ISegmentCollection; //获取点击的边 if (hitSegmentIndex < 0) { return; } ISegment segment = segmentCollection.get_Segment(hitSegmentIndex); //将点击边的端点和宽度作为新绘制线物面的起始点和宽度 ContinueDrawLeftPoint = segment.FromPoint; ContinueDrawRightPoint = segment.ToPoint; ContinueDrawLength = segment.Length; drawParam.Width = segment.Length; IPoint segmentMiddlePoint = new PointClass(); segment.QueryPoint(esriSegmentExtension.esriNoExtension, segment.Length / 2, false, segmentMiddlePoint); MiddleLine.Line.AddPoint(segmentMiddlePoint); LeftLine.Line.AddPoint(ContinueDrawLeftPoint); RightLine.Line.AddPoint(ContinueDrawRightPoint); } this.LeftLine.DrawLine(); this.MiddleLine.DrawLine(); this.RightLine.DrawLine(); } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 绘制 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 绘制 时异常信息结束"); } } /// /// 移动 /// /// /// 添加 宽度调整标识 //[LogWrite(Description = "")] private void Moveing(IPoint pPoint, bool IsAdjustWidth = false) { try { switch (drawParam.DrawMode) { case DrawMode.Left: this.MiddleLine.Scale = -0.5; this.RightLine.Scale = -1; MovePointExe(pPoint, LeftLine, RightLine, MiddleLine, IsAdjustWidth); break; case DrawMode.Right: this.LeftLine.Scale = 1; this.MiddleLine.Scale = 0.5; MovePointExe(pPoint, RightLine, LeftLine, MiddleLine, IsAdjustWidth); break; case DrawMode.LeftAndRight: this.RightLine.Scale = -0.5; this.LeftLine.Scale = 0.5; MovePointExe(pPoint, MiddleLine, LeftLine, RightLine, IsAdjustWidth); break; default: break; } LeftLine.DrawLine(); RightLine.DrawLine(); MiddleLine.DrawLine(); } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 移动 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 移动 时异常信息结束"); } } /// /// 绘制新的点 /// /// 点对象 /// 鼠标绘制的线对象 /// 通过角度和距离计算出来的线对象1 /// 通过角度和距离计算出来的线对象2 //[LogWrite(Description = "")] private void DrawPointExe(IPoint pPoint, LineModel pMainLine, LineModel pExtLine1, LineModel pExtLine2, double pAngle = -1) { try { pMainLine.Line.AddPoint(pPoint); if (pMainLine.Line.PointCount > 1 && pAngle == -1) { pAngle = GeometryOperations.getAngle(pMainLine.Line.get_Point(pMainLine.Line.PointCount - 2), pMainLine.Line.get_Point(pMainLine.Line.PointCount - 1)); } if (pAngle == -1) pAngle = 0; IPoint p1 = GeometryOperations.GetPoint(pPoint, drawParam.Width * pExtLine1.Scale, -pAngle); if (p1 == null || p1.IsEmpty) return; IPoint p2 = GeometryOperations.GetPoint(pPoint, drawParam.Width * pExtLine2.Scale, -pAngle); if (p2 == null || p2.IsEmpty) return; if (pMainLine.Line.PointCount <= 1) { pExtLine1.Line.AddPoint(p1); pExtLine2.Line.AddPoint(p2); return; } //判断第一个点是否识别到已有要素边界 if (pMainLine.Line.PointCount == 2) { #region 起始端线 IPolyline line = null; IPolyline leftLine = GeneratePolyline(pExtLine1.Line.get_Point(0)); if (leftLine != null && !leftLine.IsEmpty) { line = leftLine; } IPolyline rightLine = GeneratePolyline(pExtLine2.Line.get_Point(0)); IPolyline mainLine = GeneratePolyline(pMainLine.Line.get_Point(0)); if (rightLine != null && !rightLine.IsEmpty) { if (line != null) { ITopologicalOperator topo = line as ITopologicalOperator; line = topo.Union(rightLine) as IPolyline; } else { line = rightLine; } } if (mainLine != null && !mainLine.IsEmpty) { if (line != null) { ITopologicalOperator topo = line as ITopologicalOperator; line = topo.Union(mainLine) as IPolyline; } else { line = mainLine; } } if (line != null && !line.IsEmpty) { StartLine = GetSubCurve(line, pExtLine1.Line.get_Point(0), pExtLine2.Line.get_Point(0)); } #endregion } #region 结束端线 //优化效率,GeneratePolyline方法比较耗时 if (IsShiftDown) { IPolyline endLine = null; IPolyline tempLine = GeneratePolyline(pMainLine.Line.get_Point(pMainLine.Line.PointCount - 1)); if (tempLine != null && !tempLine.IsEmpty) { endLine = tempLine; IPoint p4 = GetIntersectPoint(pExtLine1.Line.get_Point(pExtLine1.Line.PointCount - 1), p1, tempLine as IPolyline); if (p4 != null && !p4.IsEmpty) p1 = p4; IPoint p3 = GetIntersectPoint(pExtLine2.Line.get_Point(pExtLine2.Line.PointCount - 1), p2, tempLine as IPolyline); if (p3 != null && !p3.IsEmpty) p2 = p3; EndLine = GetSubCurve(endLine, p1, p2); } } pExtLine1.Line.AddPoint(p1); pExtLine2.Line.AddPoint(p2); if (EndLine != null && IsShiftDown) { this.DrawComplete(); } #endregion } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 绘制新的点 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 绘制新的点 时异常信息结束"); } } /// /// 移动现有的点 /// /// 目标点 /// 鼠标绘制的线对象 /// 通过角度和距离计算出来的线对象1 /// 通过角度和距离计算出来的线对象2 /// 添加 宽度调整标识 //[LogWrite(Description = "")] private void MovePointExe(IPoint pPoint, LineModel pMainLine, LineModel pExtLine1, LineModel pExtLine2, bool IsAdjustWidth = false) { try { if (pMainLine.Line.PointCount < 1 || pExtLine1.Line.PointCount < 1 || pExtLine1.Line.PointCount < 1) return; double angle = GeometryOperations.getAngle(pMainLine.Line.Point[pMainLine.Line.PointCount - 1], pPoint); if (Double.IsNaN(angle)) return; IPoint pExtLine1StartPoint = null; IPoint pExtLine2StartPoint = null; IPoint pExtLine1EndPoint = null; IPoint pExtLine2EndPoint = null; //获取鼠标跟随线上的第二个点 pExtLine1EndPoint = GeometryOperations.GetPoint(pPoint, drawParam.Width * pExtLine1.Scale, -angle); pExtLine2EndPoint = GeometryOperations.GetPoint(pPoint, drawParam.Width * pExtLine2.Scale, -angle); if (pMainLine.Line.PointCount == 1) { pExtLine1StartPoint = GeometryOperations.GetPoint(pMainLine.Line.get_Point(0), drawParam.Width * pExtLine1.Scale, -angle); pExtLine2StartPoint = GeometryOperations.GetPoint(pMainLine.Line.get_Point(0), drawParam.Width * pExtLine2.Scale, -angle); //判断第一个点是否识别到已有要素边界 List IdentifyFeature = KGIS.Framework.AE.FeatureAPI.Identify(pMainLine.Line.get_Point(0), m_editor.TargetLayer, 1); IdentifyFeature.AddRange(KGIS.Framework.AE.FeatureAPI.Identify(pExtLine1.Line.get_Point(0), m_editor.TargetLayer, 1)); IdentifyFeature.AddRange(KGIS.Framework.AE.FeatureAPI.Identify(pExtLine2.Line.get_Point(0), m_editor.TargetLayer, 1)); if (IdentifyFeature != null && IdentifyFeature.Count > 0) { IPolyline line = null; //IFeature f = IdentifyFeature[0]; if (m_editor.GeometryType == esriGeometryType.esriGeometryPolygon) { foreach (IFeature item in IdentifyFeature) { ITopologicalOperator topo = item.ShapeCopy as ITopologicalOperator; if (line == null) { line = topo.Boundary as IPolyline; } else { ITopologicalOperator topolog = line as ITopologicalOperator; topolog.Simplify(); line = topolog.Union(topo.Boundary) as IPolyline; } } IGeometryCollection geoCollection = line as IGeometryCollection; if (geoCollection != null) { for (int i = 0; i < geoCollection.GeometryCount; i++) { if (KGIS.Framework.AE.FeatureAPI.IsInterSect(pMainLine.Line.get_Point(pMainLine.Line.PointCount - 1) as IGeometry, geoCollection.get_Geometry(i) as IPolyline)) { line = geoCollection.get_Geometry(i) as IPolyline; } } } } else if (m_editor.GeometryType == esriGeometryType.esriGeometryPolyline) { foreach (IFeature item in IdentifyFeature) { if (line == null) { line = item.ShapeCopy as IPolyline; } else { ITopologicalOperator topolog = line as ITopologicalOperator; topolog.Simplify(); line = topolog.Union(item.ShapeCopy) as IPolyline; } } } if (line != null) { if (KGIS.Framework.AE.FeatureAPI.IsInterSect(pMainLine.Line.get_Point(0) as IGeometry, line)) { ITopologicalOperator2 topo = line as ITopologicalOperator2; IPoint p = GetIntersectPoint(pExtLine1EndPoint, pExtLine1StartPoint, line); if (p != null && !p.IsEmpty && !IsContinueDraw) { pExtLine1StartPoint = p; } IPoint p2 = GetIntersectPoint(pExtLine2EndPoint, pExtLine2StartPoint, line); if (p2 != null && !p2.IsEmpty && !IsContinueDraw) { pExtLine2StartPoint = p2; } } } } } else { pExtLine1StartPoint = GeometryOperations.getParallelPoint(pMainLine.Line.get_Point(pMainLine.Line.PointCount - 2), pMainLine.Line.get_Point(pMainLine.Line.PointCount - 1), pPoint, drawParam.Width * pExtLine1.Scale); pExtLine2StartPoint = GeometryOperations.getParallelPoint(pMainLine.Line.get_Point(pMainLine.Line.PointCount - 2), pMainLine.Line.get_Point(pMainLine.Line.PointCount - 1), pPoint, drawParam.Width * pExtLine2.Scale); } if (!IsContinueDraw || pExtLine1.Line.PointCount > 1) { //更新第一条线上的点 pExtLine1.Line.UpdatePoint(pExtLine1.Line.PointCount - 1, pExtLine1StartPoint); //更新第一条跟随线上的点 pExtLine1.FollowLine.Stop(); pExtLine1.FollowLine.Start(new PolylineClass() { FromPoint = pExtLine1StartPoint, ToPoint = pExtLine1StartPoint }, 0, pExtLine1StartPoint); } else { pExtLine1.FollowLine.Stop(); pExtLine1.FollowLine.Start(new PolylineClass() { FromPoint = pExtLine1.Line.get_Point(0), ToPoint = pExtLine1.Line.get_Point(0) }, 0, pExtLine1.Line.get_Point(0)); } pExtLine1.FollowLine.MoveTo(GeometryOperations.GetPoint(pPoint, drawParam.Width * pExtLine1.Scale, -angle)); if (!IsContinueDraw || pExtLine1.Line.PointCount > 1) { //更新第二条线上的点 pExtLine2.Line.UpdatePoint(pExtLine1.Line.PointCount - 1, pExtLine2StartPoint); //更新第二条跟随线上的点 pExtLine2.FollowLine.Stop(); pExtLine2.FollowLine.Start(new PolylineClass() { FromPoint = pExtLine2StartPoint, ToPoint = pExtLine2StartPoint }, 0, pExtLine2StartPoint); } else { pExtLine2.FollowLine.Stop(); pExtLine2.FollowLine.Start(new PolylineClass() { FromPoint = pExtLine2.Line.get_Point(0), ToPoint = pExtLine2.Line.get_Point(0) }, 0, pExtLine2.Line.get_Point(0)); } pExtLine2.FollowLine.MoveTo(GeometryOperations.GetPoint(pPoint, drawParam.Width * pExtLine2.Scale, -angle)); //添加布尔型参数IsAdjustWidth使其为true时跳过刷新MainLine if (IsAdjustWidth) return; if (!IsContinueDraw || pExtLine1.Line.PointCount > 1) { //更新主跟随线上的点 pMainLine.FollowLine.Stop(); pMainLine.FollowLine.Start(new PolylineClass() { FromPoint = pMainLine.Line.get_Point(pMainLine.Line.PointCount - 1), ToPoint = pMainLine.Line.get_Point(pMainLine.Line.PointCount - 1) }, 0, pMainLine.Line.get_Point(pMainLine.Line.PointCount - 1)); } else { pMainLine.FollowLine.Stop(); pMainLine.FollowLine.Start(new PolylineClass() { FromPoint = pMainLine.Line.get_Point(0), ToPoint = pMainLine.Line.get_Point(0) }, 0, pMainLine.Line.get_Point(0)); } pMainLine.FollowLine.MoveTo(pPoint); } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 移动现有的点 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 移动现有的点 时异常信息结束"); } } /// /// 创建区间线段 /// /// 输入的线图形 /// 插入的其中第一个点 /// 插入的其中第一个点 /// 这两点间的线段 //[LogWrite(Description = "")] private IPolyline BuildLine(IPolyline pLine, IPoint p1, IPoint p2) { bool isSplit; int splitIndex, segIndex; //插入第一点,segIndex记录插入点的相对线的节点位置 pLine.SplitAtPoint(p1, true, false, out isSplit, out splitIndex, out segIndex); int fIndex = segIndex; //插入第二点 pLine.SplitAtPoint(p2, true, false, out isSplit, out splitIndex, out segIndex); int sIndex = segIndex; IPointCollection pPointCol = new PolylineClass(); IPointCollection pPointCol2 = new PolylineClass(); object o = Type.Missing; //比较一下插入第一点和第二点的节点次序 if (fIndex > sIndex) { int temp = fIndex; fIndex = sIndex; sIndex = temp; } else if (fIndex == sIndex) { pPointCol.AddPoint(p1, ref o, ref o); pPointCol.AddPoint(p2, ref o, ref o); return pPointCol as IPolyline; } //利用两点区间,获取线上区间所在的点,并将其转换为线 IPointCollection LineCol = pLine as IPointCollection; for (int i = fIndex; i <= sIndex; i++) { pPointCol.AddPoint(LineCol.get_Point(i), ref o, ref o); } //for (int i = 0; i < LineCol.PointCount; i++) //{ // if (i < fIndex || i > sIndex) // { // pPointCol2.AddPoint(LineCol.get_Point(i), ref o, ref o); // } //} return pPointCol as IPolyline; } //private IPolyline GetSubCurve(IPolyline inpolyLine, IPoint pnt1, IPoint pnt2) //{ // double d1 = GetDistAlong(inpolyLine, pnt1); // double d2 = GetDistAlong(inpolyLine, pnt2); // var c = inpolyLine as ICurve; // ICurve outCurve; // c.GetSubcurve(d1, d2, false, out outCurve); // if (c == null || c.IsEmpty) // throw new Exception("aa"); // var outPolyline = outCurve as IPolyline; // if (outPolyline == null) // { // outPolyline = new PolylineClass() as IPolyline; // var sc = outPolyline as ISegmentCollection; // sc.AddSegment((ISegment)outCurve); // ((IGeometry)sc).SpatialReference = outCurve.SpatialReference; // } // return outPolyline; //} //[LogWrite(Description = "")] private double GetDistAlong(IPolyline polyLine, IPoint pnt) { var outPnt = new PointClass() as IPoint; double distAlong = double.NaN; double distFrom = double.NaN; bool bRight = false; polyLine.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pnt, false, outPnt, ref distAlong, ref distFrom, ref bRight); return distAlong; } /// /// 绘制点对象到地图 /// /// //[LogWrite(Description = "")] private void DrawPoint(IPointCollection pPoints) { try { if (pPoints == null || pPoints.PointCount == 0) return; // 获取IRGBColor接口 IRgbColor color = new RgbColor(); // 设置颜色属性 color.Red = 255; color.Green = 0; color.Blue = 0; IMarkerSymbol symbol = new SimpleMarkerSymbolClass(); symbol.Color = color; symbol.Size = 5; IPointCollection pointList = new Polyline(); pointList.AddPoint(this.LeftLine.Line.get_Point(this.LeftLine.Line.PointCount - 1)); pointList.AddPoint(this.MiddleLine.Line.get_Point(this.MiddleLine.Line.PointCount - 1)); pointList.AddPoint(this.RightLine.Line.get_Point(this.RightLine.Line.PointCount - 1)); IPointCollection pointList2 = new Polyline(); pointList2.AddPoint(this.LeftLine.Line.get_Point(this.LeftLine.Line.PointCount - 1)); pointList2.AddPoint(this.MiddleLine.Line.get_Point(this.MiddleLine.Line.PointCount - 1)); pointList2.AddPoint(this.RightLine.Line.get_Point(this.RightLine.Line.PointCount - 1)); for (int i = 0; i < pPoints.PointCount; i++) { if (PointElement.Count == i) { IMarkerElement e = new MarkerElementClass(); e.Symbol = symbol; PointElement.Add(e as IElement); this.m_hookHelper.ActiveView.GraphicsContainer.AddElement(e as IElement, 0); } IElement element = PointElement[i]; pointList.AddPoint(element.Geometry as IPoint); element.Geometry = pPoints.get_Point(i); pointList2.AddPoint(pPoints.get_Point(i)); } pointList.AddPoint(this.LeftLine.Line.get_Point(this.LeftLine.Line.PointCount - 1)); IPolyline line = pointList as IPolyline; if (line.Length <= 0 || line.Length.Equals(double.NaN)) { return; } ITopologicalOperator topo = line as ITopologicalOperator; IGeometry geo = topo.Buffer(10); this.m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, this.m_hookHelper.ActiveView.Extent); //this.m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, geo.Envelope); //this.m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, (pointList2 as IPolyline).Envelope); } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 绘制点对象到地图 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 绘制点对象到地图 时异常信息结束"); } } /// /// 绘制文本对象 /// /// /// //[LogWrite(Description = "")] public void DrawTextElement(ESRI.ArcGIS.Geometry.IGeometry geoDraw, ref IElement pElement) { if (pElement != null && geoDraw != null) { if (pElement is ITextElement) { (pElement as ITextElement).Text = string.Format("当前宽度 {0} 米", drawParam.Width); } pElement.Geometry = geoDraw; m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_hookHelper.ActiveView.Extent); return; } // 获取IRGBColor接口 IRgbColor color = new RgbColor(); // 设置颜色属性 color.Red = 0; color.Green = 255; color.Blue = 255; //IFontDisp pFont = new StdFont() //{ // Name = "宋体", // Bold = true //} as IFontDisp; ITextSymbol pTextSymbol = new TextSymbolClass() { Color = color, //Font = pFont, Size = 12 }; ITextElement pTextElement = new TextElementClass() { Symbol = pTextSymbol, ScaleText = true, Text = string.Format("当前宽度 {0} 米", drawParam.Width) }; IPoint point = geoDraw as IPoint; point.X += 2; point.Y -= 1; if (pElement == null) { pElement = pTextElement as IElement; pElement.Geometry = point; m_hookHelper.ActiveView.GraphicsContainer.AddElement(pElement, 0); } m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_hookHelper.ActiveView.Extent); } /// /// 删除指定的Element /// /// //[LogWrite(Description = "")] public void DelElement(ref IElement pElement) { try { if (pElement != null) { m_hookHelper.ActiveView.GraphicsContainer.DeleteElement(pElement); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_hookHelper.ActiveView.Extent); pElement = null; } } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 删除指定的Element 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 删除指定的Element 时异常信息结束"); } } /// /// 捕捉Element上的点并返回点的索引 /// /// /// //[LogWrite(Description = "")] private int SnapElement(IPoint pPoint) { int pointIndex = -1; try { //中心线距离 double len = -1; for (int i = 0; i < MiddleLine.Line.PointCount; i++) { IPolyline line = new PolylineClass(); line.FromPoint = MiddleLine.Line.get_Point(i); line.ToPoint = pPoint; line.SpatialReference = pPoint.SpatialReference; if (len == -1) { len = line.Length; pointIndex = i; } else { if (len > line.Length) { len = line.Length; pointIndex = i; } } } } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 捕捉Element上的点并返回点的索引 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 捕捉Element上的点并返回点的索引 时异常信息结束"); return -1; } return pointIndex; } /// /// 捕捉Element上的点并返回点的索引 /// /// /// //[LogWrite(Description = "")] private int SnapElement(IPoint pPoint, out int p) { int pointIndex = -1; try { double tempLen = -1; //中心线距离 double len = -1; //左边线距离 double len1 = -1; //右边线距离 double len2 = -1; //中心线索引 int m_index = -1; //左边线索引 int l_index = -1; //右边线索引 int r_index = -1; for (int i = 0; i < MiddleLine.Line.PointCount; i++) { IPolyline line = new PolylineClass(); line.FromPoint = MiddleLine.Line.get_Point(i); line.ToPoint = pPoint; line.SpatialReference = pPoint.SpatialReference; if (len == -1) { len = line.Length; m_index = i; } else { if (len > line.Length) { len = line.Length; m_index = i; } } } for (int i = 0; i < LeftLine.Line.PointCount; i++) { IPolyline line = new PolylineClass(); line.FromPoint = LeftLine.Line.get_Point(i); line.ToPoint = pPoint; line.SpatialReference = pPoint.SpatialReference; if (len1 == -1) { len1 = line.Length; l_index = i; } else { if (len1 > line.Length) { len1 = line.Length; l_index = i; } } } for (int i = 0; i < RightLine.Line.PointCount; i++) { IPolyline line = new PolylineClass(); line.FromPoint = RightLine.Line.get_Point(i); line.ToPoint = pPoint; line.SpatialReference = pPoint.SpatialReference; if (len2 == -1) { len2 = line.Length; r_index = i; } else { if (len2 > line.Length) { len2 = line.Length; r_index = i; } } } if (len > len1) { if (len1 > len2) { p = -1; tempLen = len2; pointIndex = r_index; } else { p = 1; tempLen = len1; pointIndex = l_index; } } else { if (len > len2) { p = -1; tempLen = len2; pointIndex = r_index; } else { p = 0; tempLen = len; pointIndex = m_index; } } if (tempLen > 3) { pointIndex = -1; } } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 在捕捉Element上的点并返回点的索引 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 在捕捉Element上的点并返回点的索引 时异常信息结束"); p = 0; return -1; } return pointIndex; } //[LogWrite(Description = "")] private IPolyline GetSubCurve(IPolyline LineCurve, IPoint SplitePoint1, IPoint SplitePoint2) { IPolyline Lines = null; bool isSplit; int splitIndex, segStartIndex, segEndIndex, minIndex, maxIndex; LineCurve.SplitAtPoint(SplitePoint1, true, false, out isSplit, out splitIndex, out segStartIndex); LineCurve.SplitAtPoint(SplitePoint2, true, false, out isSplit, out splitIndex, out segEndIndex); if (isSplit) { IPolyline newLine = new PolylineClass(); ISegmentCollection lineSegCol = (ISegmentCollection)LineCurve; ISegmentCollection newSegCol = (ISegmentCollection)newLine; object o = Type.Missing; if (segStartIndex > segEndIndex) { minIndex = segEndIndex; maxIndex = segStartIndex; } else { minIndex = segStartIndex; maxIndex = segEndIndex; } for (int j = minIndex; j <= maxIndex; j++) { ISegment segment = lineSegCol.get_Segment(j); //if ((Math.Round(segment.FromPoint.X, 4) == Math.Round(SplitePoint1.X, 4) && Math.Round(segment.FromPoint.Y, 4) == Math.Round(SplitePoint1.Y, 4) && Math.Round(segment.ToPoint.X, 4) == Math.Round(SplitePoint2.X, 4) && Math.Round(segment.ToPoint.Y, 4) == Math.Round(SplitePoint2.Y, 4)) // || (Math.Round(segment.ToPoint.X, 4) == Math.Round(SplitePoint1.X, 4) && Math.Round(segment.ToPoint.Y, 4) == Math.Round(SplitePoint1.Y, 4) && Math.Round(segment.FromPoint.X, 4) == Math.Round(SplitePoint2.X, 4) && Math.Round(segment.FromPoint.Y, 4) == Math.Round(SplitePoint2.Y, 4))) //{ newSegCol.AddSegment(segment, ref o, ref o); //Lines = newSegCol as IPolyline; //break; //} } Lines = newSegCol as IPolyline; } return Lines; } //[LogWrite(Description = "")] public IPolyline GeneratePolyline(IPoint point) { IPolyline result = null; if (point == null) return result; try { List snapLayers = new List(); snapLayers.Add(m_editor.TargetLayer as IFeatureLayer); //获取当前捕捉的要素多边形 List snapFeatures = FeatureAPI.Snapping(point, snapLayers, 10); if (snapFeatures == null) return result; foreach (IFeature feautre in snapFeatures) { //将多边形要素转成线要素 List featureToLines = FeatureAPI.PolygonToLine(feautre.ShapeCopy); if (featureToLines == null) continue; IPolyline tempLine = null; foreach (IGeometry f_line in featureToLines) { tempLine = f_line as IPolyline; List LineInsertFeature = FeatureAPI.Snapping(tempLine, snapLayers, 0.0001); foreach (IFeature item in LineInsertFeature) { if (item.OID == feautre.OID) continue; ITopologicalOperator topo = tempLine as ITopologicalOperator; topo.Simplify(); IPolyline newline = topo.Intersect(item.ShapeCopy, esriGeometryDimension.esriGeometry1Dimension) as IPolyline; //IPolyline obj = result.Values.FirstOrDefault(f => Math.Round(f.Length, 0) == Math.Round(newline.Length, 0)); if (FeatureAPI.IsInterSect(point as IGeometry, newline)) { result = newline; return result; } tempLine = topo.Difference(item.ShapeCopy) as IPolyline; } } if (FeatureAPI.IsInterSect(point as IGeometry, tempLine)) { result = tempLine; break; } } return result; } catch (Exception ex) { LogAPI.Debug("画线物面(线状地物面)工具 过程中 执行 GeneratePolyline 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("画线物面(线状地物面)工具 过程中 执行 GeneratePolyline 时异常信息结束"); throw; } } #endregion /// /// 设置鼠标的坐标 /// /// 横坐标 /// 纵坐标 [DllImport("User32")] public extern static void SetCursorPos(int x, int y); //[LogWrite(Description = "")] //private bool ss() //{ // try // { // if (Env.Instance.KeyType != "F")//非本地授权 直接返回 // { // return true; // } // RunIDHelper id = new RunIDHelper(); // return id.QCCheck(); // } // catch // { // return false; // } //} public override void Refresh(int hDC) { if (MiddleLine != null && MiddleLine.FollowLine != null) MiddleLine.FollowLine.Refresh(hDC); if (LeftLine != null && LeftLine.FollowLine != null) LeftLine.FollowLine.Refresh(hDC); if (RightLine != null && RightLine.FollowLine != null) RightLine.FollowLine.Refresh(hDC); base.Refresh(hDC); } } }