private bool FindMapObjects(Point location, out HashItem[] vertexRows, out HashItem[] cableRows) { HashItem[] vertexR = null; HashItem[] cableR = null; try { var coordinate = GeomCoordinate.GetCoordinateFromScreen(_netLayer.ScreenView, location); var tasks = new List <Task> { Task.Factory.StartNew(() => vertexR = _netLayer.FindNearestVertex(coordinate)), Task.Factory.StartNew(() => cableR = _netLayer.FindNearestCable(coordinate)) }; Task.WaitAll(tasks.ToArray()); } catch (Exception) { vertexR = null; cableR = null; } vertexRows = vertexR; cableRows = cableR; return((vertexRows != null && vertexRows.Length > 0) || (cableRows != null && cableRows.Length > 0)); }
private void MapCtl_DoubleClick(object sender, EventArgs e) { if (_mapLayer.Terminating) { return; } HashItem[] vertexRows; HashItem[] cableRows; if (!ShiftKey && !FindMapObjects(_mousePreviousLocation, out vertexRows, out cableRows)) { CenterCoordinate = GeomCoordinate.GetCoordinateFromScreen(_netLayer.ScreenView, _mousePreviousLocation); } }
private void MapCtl_MouseMove(object sender, MouseEventArgs e) { if (_mapLayer.Terminating) { return; } CursorCoordinate = GeomCoordinate.GetCoordinateFromScreen(_netLayer.ScreenView, new Point(e.X, e.Y)); if (_mouseMoveMap) { var deltaX = _mousePreviousLocation.X - e.X; var deltaY = _mousePreviousLocation.Y - e.Y; CenterCoordinate = _coordinatePreviosLocation + new ScreenCoordinate(deltaX, deltaY, Level); } else { if (String.IsNullOrEmpty(toolTip1.GetToolTip(this))) { HashItem[] vertexRows; HashItem[] cableRows; FindMapObjects(e.Location, out vertexRows, out cableRows); if (vertexRows.Length > 0) { var vertex = _netLayer.GetVertex(vertexRows[0].Value); if (vertex != null) { toolTip1.RemoveAll(); toolTip1.Show(vertex.Caption, this, e.Location, 3000); } } else if (cableRows.Length > 0) { var cable = _netLayer.GetCable(cableRows[0].Value); if (cable != null) { toolTip1.RemoveAll(); toolTip1.Show(cable.Caption, this, e.Location, 3000); } } } } }
private void MapCtl_MouseDown(object sender, MouseEventArgs e) { if (_mapLayer.Terminating) { return; } if (_mouseMoveMap) { return; } if (e.Button == MouseButtons.Left) { CursorCoordinate = GeomCoordinate.GetCoordinateFromScreen(_netLayer.ScreenView, new Point(e.X, e.Y)); HashItem[] vertexRows; HashItem[] cableRows; if (!FindMapObjects(e.Location, out vertexRows, out cableRows)) { _mousePreviousLocation = new Point(e.X, e.Y); if (ShiftKey) { MapCtl_MouseWheel(this, new MouseEventArgs(e.Button, e.Clicks, e.X, e.Y, 1)); CenterCoordinate = GeomCoordinate.GetCoordinateFromScreen(_netLayer.ScreenView, _mousePreviousLocation); } else { _mouseMoveMap = true; _coordinatePreviosLocation = CenterCoordinate; } } else { if (vertexRows.Length > 0) { var vertex = _netLayer.GetVertex(vertexRows[0].Value); if (vertex != null) { MessageBox.Show(vertex.Caption, @"Vertex found!"); } } else if (cableRows.Length > 0) { var cable = _netLayer.GetCable(cableRows[0].Value); if (cable != null) { MessageBox.Show(cable.Caption, @"Cable found!"); } } } } else if (e.Button == MouseButtons.Right) { HashItem[] vertexRows; HashItem[] cableRows; if (!FindMapObjects(e.Location, out vertexRows, out cableRows)) { _mousePreviousLocation = new Point(e.X, e.Y); if (ShiftKey) { MapCtl_MouseWheel(this, new MouseEventArgs(e.Button, e.Clicks, e.X, e.Y, -1)); CenterCoordinate = GeomCoordinate.GetCoordinateFromScreen(_netLayer.ScreenView, _mousePreviousLocation); } } else { var menu = new ContextMenu(); foreach (var row in vertexRows) { var vertex = _netLayer.GetVertex(row.Value); var item = menu.MenuItems.Add(String.Format(@"Delete Vertex: {0}", vertex.Caption), MapCtl_DeleteVertexClick); item.Tag = row.Value; } foreach (var row in cableRows) { var cable = _netLayer.GetCable(row.Value); var item = menu.MenuItems.Add(String.Format(@"Delete Cable: {0}", cable.Caption), MapCtl_DeleteCableClick); item.Tag = row.Value; } menu.Show(this, e.Location); } } }