| | |
| | | |
| | | return inside; |
| | | } |
| | | //protected override void OnMouseDoubleClick(MouseEventArgs e) |
| | | //{ |
| | | // //base.OnMouseDoubleClick(e); |
| | | |
| | | |
| | | //} |
| | | public void InsertNet(Template temp) |
| | | { |
| | | _isInsertingObject = true; |
| | |
| | | |
| | | |
| | | } |
| | | |
| | | /*判断是否触碰到对象*/ |
| | | { |
| | | // 遍历所有对象,找出范围内的对象 |
| | | PointF clickedPoint = new PointF(e.X, e.Y); //ScreenToMap(new PointF(e.X, e.Y)); |
| | | var obj = GetObj_by_ScreenPoint(clickedPoint); |
| | | |
| | | hoveredObjs.ForEach(o => o.Hovered = false); |
| | | hoveredObjs.Clear(); |
| | | if (obj != null) |
| | | { |
| | | obj.Hovered = true; |
| | | hoveredObjs.Add(obj); |
| | | } |
| | | //bool isJunction = obj is NodeViewModel; |
| | | } |
| | | |
| | | |
| | | |
| | | if (needInvalidate) this.Invalidate(); |
| | | label_mouse.Text = $"X:{e.X.ToString("0")} Y:{e.Y.ToString("0")} [Map]X:{_MousePosition.X.ToString("0.00")} Y:{_MousePosition.Y.ToString("0.00")}"; |
| | | _lastMouseX = e.X; |
| | |
| | | p = new PointF(j.X, j.Y); |
| | | } |
| | | } |
| | | IBaseViewModel GetObj_by_ScreenPoint(PointF clickedPoint) |
| | | IBaseViewModel GetObj_by_ScreenPoint(PointF clickedPoint, float DistLimit = 15f) |
| | | { |
| | | float minDist = float.MaxValue; |
| | | float DistLimit = 15f; |
| | | |
| | | int minIndex = -1; |
| | | bool isJunction = true; |
| | | IBaseViewModel obj = null; |
| | |
| | | } |
| | | } |
| | | return obj; |
| | | } |
| | | |
| | | List<IBaseViewModel> GetObjs_by_ScreenPoint(PointF clickedPoint, float DistLimit = 15f) |
| | | { |
| | | float minDist = float.MaxValue; |
| | | |
| | | int minIndex = -1; |
| | | |
| | | IBaseViewModel obj = null; |
| | | List < IBaseViewModel > objs = new List<IBaseViewModel>(); |
| | | for (int i = 0; i < _Nodes.Count; i++) |
| | | { |
| | | var node = _Nodes[i] as NodeViewModel; |
| | | if (!node.Visible) continue; |
| | | PointF mapPos = WorldPointToMapPoint(node); |
| | | PointF currentPoint = MapToScreen(mapPos); |
| | | float dist = Get_dist(clickedPoint, currentPoint); |
| | | if (dist <= DistLimit) |
| | | { |
| | | objs.Add(node); |
| | | } |
| | | } |
| | | for (int i = 0; i < _Links.Count; i++) |
| | | { |
| | | var link = _Links[i] as LinkViewModel; |
| | | if (!link.Visible) continue; |
| | | //float dist = (clickedPoint.X - Pipes[i].X) * (clickedPoint.X - Pipes[i].X) + |
| | | // (clickedPoint.Y - Pipes[i].Y) * (clickedPoint.Y - Pipes[i].Y); |
| | | PointF mapPos1 = WorldPointToMapPoint(link.StartNode.Position, link.StartNode.Elev); |
| | | PointF currentPoint1 = MapToScreen(mapPos1); |
| | | PointF mapPos2 = WorldPointToMapPoint(link.EndNode.Position, link.EndNode.Elev); |
| | | PointF currentPoint2 = MapToScreen(mapPos2); |
| | | //根据currentPoint1和currentPoint2,判断clickedPoint离线段currentPoint1和currentPoint2的距离 |
| | | float dist = Get_dist(clickedPoint, currentPoint1, currentPoint2, DistLimit); |
| | | |
| | | //float dist = Get_dist(clickedPoint, currentPoint); |
| | | if (dist < minDist && dist <= DistLimit) |
| | | { |
| | | |
| | | |
| | | objs.Add(link); |
| | | } |
| | | } |
| | | return objs; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | } |
| | | Colour _NodeColour = null; |
| | | Colour _LinkColour = null; |
| | | private List<IBaseViewModel> hoveredObjs=new List<IBaseViewModel>(); |
| | | |
| | | private void cb_Node_Colour_Click(object sender, EventArgs e) |
| | | { |
| | | |