protected override void OnMouseDown(MouseEventArgs arg) { base.OnMouseDown(arg); try { ValueSymbolForm valueSymbolForm = AddIn.FromID <ValueSymbolForm.AddinImpl>(ThisAddIn.IDs.ValueSymbolForm).UI; selectedValue = valueSymbolForm.SelectedValue; selectedColor = valueSymbolForm.SelectedColor; if ((Painter.ActiveLayer == null) || (arg.Button != MouseButtons.Left) || (selectedValue == null)) { return; } preMousePos = Raster.ScreenCoor2RasterCoor(arg.X, arg.Y, Painter.ActiveLayer); iniMousePos = preMousePos; } catch (Exception ex) { MessageBox.Show(string.Format("Unfortunately, the application meets an error.\n\nSource: {0}\nSite: {1}\nMessage: {2}", ex.Source, ex.TargetSite, ex.Message), "Error"); } }
protected override void OnMouseUp(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) { base.OnMouseDown(arg); try { if ((Painter.ActiveLayer == null) || (arg.Button != MouseButtons.Left) || (selectedValue == null)) { return; } else { // If the mouse does not move, paint at the clicked pixel Position mousePos = Raster.ScreenCoor2RasterCoor(arg.X, arg.Y, Painter.ActiveLayer); if (layerExetent.Contains(mousePos) && iniMousePos.Equals(mousePos)) { PaintPixel(mousePos); } } } catch (Exception ex) { MessageBox.Show(string.Format("Unfortunately, the application meets an error.\n\nSource: {0}\nSite: {1}\nMessage: {2}", ex.Source, ex.TargetSite, ex.Message), "Error"); } iniMousePos = null; preMousePos = null; }
protected override void OnMouseMove(MouseEventArgs arg) { base.OnMouseMove(arg); if ((Painter.ActiveLayer == null) || arg.Button != MouseButtons.Left) { return; } try { Position mousePos = Raster.ScreenCoor2RasterCoor(arg.X, arg.Y, Painter.ActiveLayer); if (layerExetent.Contains(mousePos) && !(mousePos.Equals(preMousePos))) { Pixel paintedPixel = Painter.Paints[mousePos]; if (paintedPixel != null) { Display.RemoveElement(paintedPixel.GraphicElement, true); Painter.Paints.Remove(mousePos); } preMousePos = mousePos; } } catch (Exception ex) { MessageBox.Show(string.Format("Unfortunately, the application meets an error.\n\nSource: {0}\nSite: {1}\nMessage: {2}", ex.Source, ex.TargetSite, ex.Message), "Error"); } }
protected override void OnMouseDown(MouseEventArgs arg) { base.OnMouseDown(arg); if ((Painter.ActiveLayer == null) || (arg.Button != MouseButtons.Left)) { return; } preMousePos = Raster.ScreenCoor2RasterCoor(arg.X, arg.Y, Painter.ActiveLayer); }
/// <summary> /// Select the pixels when mouse up. /// </summary> /// <param name="arg"></param> protected override void OnMouseUp(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) { base.OnMouseUp(arg); if (activeLayer != null) { try { IEnvelope envelop = newEnvelopeFeedback.Stop(); UID dockWinID = new UIDClass(); dockWinID.Value = ThisAddIn.IDs.IdentifyForm; // Use GetDockableWindow directly as we want the client IDockableWindow not the internal class IDockableWindow dockWindow = ArcMap.DockableWindowManager.GetDockableWindow(dockWinID); IdentifyForm identifyForm = AddIn.FromID <IdentifyForm.AddinImpl>(ThisAddIn.IDs.IdentifyForm).UI; Position tlCorner, brCorner; if (envelop.UpperLeft.IsEmpty) { tlCorner = Raster.ScreenCoor2RasterCoor(arg.X, arg.Y, activeLayer); brCorner = tlCorner; } else { tlCorner = Raster.MapCoor2RasterCoor(envelop.UpperLeft, activeLayer); brCorner = Raster.MapCoor2RasterCoor(envelop.LowerRight, activeLayer); } if (!IsIntersect(tlCorner, brCorner, maxExtent)) { identifyForm.ClearValues(); return; } tlCorner.Adjust(0, 0, maxExtent.Column, maxExtent.Row); brCorner.Adjust(0, 0, maxExtent.Column, maxExtent.Row); // Show symbols of selected pixels for (int row = tlCorner.Row; row <= brCorner.Row; row++) { for (int col = tlCorner.Column; col <= brCorner.Column; col++) { Position pos = new Position(col, row); if (!Editor.Selections.Exists(pos)) { Pixel pixel = new Pixel(pos); pixel.GraphicElement = Display.DrawBox(pixel.Position, Editor.GetSelectionSymbol(), ArcMapApp.GetRasterLayer()); Editor.Selections.Add(pixel); } } } Display.Refresh(); double[,] values = Raster.GetValues(tlCorner, brCorner, activeLayer.Raster); identifyForm.SetValues(tlCorner, brCorner, values); identifyForm.SetLayerName(activeLayer.Name); if (!dockWindow.IsVisible()) { dockWindow.Show(true); } } catch (Exception ex) { MessageBox.Show(string.Format("Unfortunately, the application meets an error.\n\nSource: {0}\nSite: {1}\nMessage: {2}", ex.Source, ex.TargetSite, ex.Message), "Error"); } } }
protected override void OnMouseUp(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg) { base.OnMouseDown(arg); if (Editor.ActiveLayer != null) { try { UID uid = new UIDClass(); uid.Value = ThisAddIn.IDs.EditForm; IDockableWindow dockWin = ArcMap.DockableWindowManager.GetDockableWindow(uid); EditForm editForm = AddIn.FromID <EditForm.AddinImpl>(ThisAddIn.IDs.EditForm).UI; IEnvelope envelop = newEnvelopeFeedback.Stop(); Position tlCorner, brCorner; if (envelop.UpperLeft.IsEmpty) { tlCorner = Raster.ScreenCoor2RasterCoor(arg.X, arg.Y, (IRasterLayer)Editor.ActiveLayer); brCorner = tlCorner; } else { tlCorner = Raster.MapCoor2RasterCoor(envelop.UpperLeft, (IRasterLayer)Editor.ActiveLayer); brCorner = Raster.MapCoor2RasterCoor(envelop.LowerRight, (IRasterLayer)Editor.ActiveLayer); } if (!IsIntersect(tlCorner, brCorner, maxIndex)) { editForm.ClearValues(); return; } tlCorner.Adjust(0, 0, maxIndex.Column, maxIndex.Row); brCorner.Adjust(0, 0, maxIndex.Column, maxIndex.Row); // Show symbols of selected pixels for (int row = tlCorner.Row; row <= brCorner.Row; row++) { for (int col = tlCorner.Column; col <= brCorner.Column; col++) { Position pos = new Position(col, row); if (!Editor.Selections.Exists(pos)) { Pixel pixel = new Pixel(pos); pixel.GraphicElement = Display.DrawBox(pixel.Position, Editor.GetSelectionSymbol(), Editor.ActiveLayer); Editor.Selections.Add(pixel); } } } Display.Refresh(); IRasterLayer rasterLayer = (IRasterLayer)Editor.ActiveLayer; double[,] values = Raster.GetValues(tlCorner, brCorner, rasterLayer.Raster); editForm.SetValues(tlCorner, brCorner, values); // If there is only one value, select that. if (values.Length == 1) { editForm.RasterGridView[0, 0].Selected = false; editForm.RasterGridView[1, 0].Selected = true; } if (!dockWin.IsVisible()) { dockWin.Show(true); } } catch (Exception ex) { MessageBox.Show(string.Format("Unfortunately, the application meets an error.\n\nSource: {0}\nSite: {1}\nMessage: {2}", ex.Source, ex.TargetSite, ex.Message), "Error"); } } }