/// <summary> /// 获取引用的点 /// </summary> /// <param name="canCatchPoints"></param> /// <param name="v"></param> /// <returns></returns> private IntersectPoint RefencePoint(List <Vector2D> canCatchPoints, Vector2D v) { IntersectPoint ip = null; if (canCatchPoints != null && canCatchPoints.Count > 0) { Vector2D point1 = canCatchPoints.OrderBy(x => Math.Abs(v.Y - x.Y)).First(); if (Math.Abs(v.Y - point1.Y) < KernelProperty.Tolerance) { if (ip == null) { ip = new IntersectPoint(); ip.IntersectPointStyle = 2; ip.Point = Vector2D.Create(v.X, point1.Y); ip.Refences = new List <Line2D>(); } else { ip.Point = Vector2D.Create(ip.Point.X, point1.Y); } ip.Refences.Add(Line2D.Create(point1, ip.Point)); } Vector2D point2 = canCatchPoints.OrderBy(x => Math.Abs(v.X - x.X)).First(); if (Math.Abs(v.X - point2.X) < KernelProperty.Tolerance) { if (ip == null) { ip = new IntersectPoint(); ip.IntersectPointStyle = 2; ip.Point = Vector2D.Create(point2.X, v.Y); ip.Refences = new List <Line2D>(); } else { ip.Point = Vector2D.Create(point2.X, ip.Point.Y); } ip.Refences.Add(Line2D.Create(point2, ip.Point)); } } return(ip); }
/// <summary> /// 图形对象之上的对象捕获 /// </summary> /// <param name="canCatchVisuals"></param> /// <param name="v"></param> /// <param name="ip"></param> /// <returns></returns> private IntersectPoint CatchVisualPoint(List <Geometry2D> canCatchVisuals, Vector2D v, IntersectPoint ip) { IntersectPoint tpip = null; if (canCatchVisuals != null) { //查找是否有相交点,优先捕获点 for (int i = 0; i < canCatchVisuals.Count; i++) { if (canCatchVisuals[i] == action.Geometry) { tpip = canCatchVisuals[i].IntersectPoint2(v); } else { tpip = canCatchVisuals[i].IntersectPoint(v); } if (tpip != null) { if (ip == null) { return(tpip); } else { if (v.Distance(tpip.Point) < v.Distance(ip.Point)) { return(tpip); } else { return(ip); } } } } } return(tpip); }
/// <summary> /// 获取shift的按下的信息 /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> /// <returns></returns> public IntersectPoint GetShiftPoint(Vector2D p1, Vector2D p2, IAction action = null) { IntersectPoint intersectPoint = null; this.action = action; var dir = p2 - p1; var a = Math.Abs(dir.AngleWith(new Vector2D(1, 0))) * 180 / Math.PI; if (a > 90) { a = 180 - a; } if (a < 45) { var vector = new Vector2D(p2.X, p1.Y); intersectPoint = Catch(vector, this.action); if (intersectPoint == null) { intersectPoint = new IntersectPoint(); intersectPoint.Point = new Vector2D(p2.X, p1.Y); intersectPoint.IntersectPointStyle = 1; } return(intersectPoint); } else { var vector = new Vector2D(p1.X, p2.Y); intersectPoint = Catch(vector, this.action); if (intersectPoint == null) { intersectPoint = new IntersectPoint(); intersectPoint.Point = new Vector2D(p1.X, p2.Y); intersectPoint.IntersectPointStyle = 1; } return(intersectPoint); } }
/// <summary> /// 获取焦点信息 /// </summary> internal IntersectPoint GetInterestPoint(Vector2D v) { IntersectPoint ip = null; if (this.DrawingControl.IsUpdated) { canCatchPoints = new List <Vector2D>(); //获取界面上所有可视化图形 canCatchVisuals = this.DrawingControl.CatchVisuals(); if (KernelProperty.CanCatchEndPoint) { //获取所有的端点 List <Vector2D> endpoints = this.GetEndPoint(canCatchVisuals); //添加所有的端点 canCatchPoints.AddRange(endpoints); } //当前所有的兴趣线 List <Line2D> InerestLines = this.GetInterestLine(canCatchVisuals); if (KernelProperty.CanCatchIntersect) { //获取当前的兴趣点 List <Vector2D> InerestPoints = this.InterestPoint(InerestLines); canCatchPoints.AddRange(InerestPoints); } if (KernelProperty.CanCatchCentral) { //获取当前中心点 List <Vector2D> MiddlePoints = this.MiddlePoint(InerestLines); canCatchPoints.AddRange(MiddlePoints); } //剔除当前正在绘制的点和绘制的上一个点,不会用于捕捉 if (this.action.GetLastPoint() != null) { canCatchPoints.Remove(this.action.GetLastPoint()); } if (this.action.GetPreviousPoint() != null) { canCatchPoints.Remove(this.action.GetPreviousPoint()); } this.DrawingControl.IsUpdated = false; } //查找最近的点 if (canCatchPoints != null && canCatchPoints.Count > 0) { //查找最近的端点和相交点 Vector2D point = canCatchPoints.OrderBy(x => v.Distance(x)).First(); //获取了端点 if (v.Distance(point) < KernelProperty.Tolerance) { ip = new IntersectPoint(); ip.IntersectPointStyle = 0; ip.Point = Vector2D.Create(point.X, point.Y); } } if (ip == null) { ip = CatchVisualPoint(canCatchVisuals, v, ip); } //辅助线捕获,应该在交点有何没有的情况下,都应该获取 if (ip == null) { ip = this.RefencePoint(canCatchPoints, v); } return(ip); }
/// <summary> /// 开始单选 /// </summary> /// <param name="v"></param> /// <returns></returns> public List <IntersectGeometry> SingleSelect(Vector2D v) { //选择的所有图形元素 List <IntersectGeometry> selectIGS = new List <IntersectGeometry>(); //获取图形上所有的元素 List <Geometry2D> gss = this.DrawingControl.GetDrawingVisuals().FindAll(x => x.IsEnabled); //当相交的图形 List <IntersectGeometry> shapeSelects = new List <IntersectGeometry>(); //循环所有的图形元素 for (int i = 0; i < gss.Count; i++) { //获取满足相交运算的所有图形 IntersectPoint ip = gss[i].IntersectPoint(v); if (ip != null) { IntersectGeometry igip = new IntersectGeometry(); igip.IntersectPoint = ip; igip.GeometryShape = gss[i]; shapeSelects.Add(igip); } } //查找一个离点击点最近的图形 if (shapeSelects.Count > 0) { //查找一个最近的图形 var selectShape = shapeSelects.OrderBy(x => x.IntersectPoint.Point.Distance(v)).FirstOrDefault(); //查找具有相同距离的图形 List <IntersectGeometry> igs = shapeSelects.FindAll(x => x.IntersectPoint.Point.Distance(v).AreEqual(selectShape.IntersectPoint.Point.Distance(v))); if (igs.Count == 1) { selectIGS.Add(selectShape); return(selectIGS); } else { /**需要判断,当前选择点是否在图形内部,假如直接命中了图形获取选择的点*/ Point point = KernelProperty.MMToPix(v); var hittestShapes = DrawingControl.CatchVisual(point).FindAll(x => x.IsEnabled); if (hittestShapes != null && hittestShapes.Count > 0) { //假如有多个命中,则要在命中中分离,也有相交关系的图形 List <IntersectGeometry> csigs = new List <IntersectGeometry>(); hittestShapes.ForEach(x => { IntersectGeometry ig = igs.Find(y => y.GeometryShape == x); if (ig != null) { csigs.Add(ig); } }); //假如有相交元素中,没有一个被命中,说明当前点没有命中任何相交元素,则还是选择弹出选择 if (csigs != null && csigs.Count > 0) { //多个命中,多个选择 return(csigs); } else { //弹出选择 return(igs); } } else { //弹出选择 return(igs); } } } else { //获取选择的点 Point point = KernelProperty.MMToPix(v); //假如直接命中了图形 var selectedShapes = DrawingControl.CatchVisual(point).FindAll(x => x.IsEnabled); if (selectedShapes != null && selectedShapes.Count > 0) { List <IntersectGeometry> csigs = new List <IntersectGeometry>(); selectedShapes.ForEach(x => { IntersectGeometry igip = new IntersectGeometry(); IntersectPoint ip = new IntersectPoint(); ip.Point = v; igip.IntersectPoint = ip; igip.GeometryShape = x; csigs.Add(igip); }); return(csigs); } else { return(selectIGS); } } }