예제 #1
0
파일: Editor.cs 프로젝트: sishui198/ares
        /// <summary>
        /// Prepare the editor for editing.
        /// </summary>
        public static void StartEditing()
        {
            // Select a layer to edit first
            int rasterLayerCount = ArcMapApp.RasterLayerCount;

            if (rasterLayerCount == 1)
            {
                Editor.activeLayer = ArcMapApp.GetRasterLayer();
            }
            else
            {
                SelectLayerForm selectLayerForm = new SelectLayerForm();
                selectLayerForm.ShowDialog();

                if (selectLayerForm.ReturnLayer == null)
                {
                    return;
                }

                Editor.activeLayer = selectLayerForm.ReturnLayer;
            }

            Editor.IsEditing = true;
            Editor.Edits.Clear();

            // Enable the save button
            SaveEditsButton saveButton = AddIn.FromID <SaveEditsButton>(ThisAddIn.IDs.SaveEditsButton);

            saveButton.IsEnabled = true;

            // Enable the save as button
            SaveEditsAsButton saveAsButton = AddIn.FromID <SaveEditsAsButton>(ThisAddIn.IDs.SaveEditsAsButton);

            saveAsButton.IsEnabled = true;

            // Enable the stop button
            StopEditingButton stopButton = AddIn.FromID <StopEditingButton>(ThisAddIn.IDs.StopEditingButton);

            stopButton.IsEnabled = true;

            // Enable the edit tool.
            EditTool selectTool = AddIn.FromID <EditTool>(ThisAddIn.IDs.EditTool);

            selectTool.IsEnabled = true;

            // Disable the start button
            StartEditingButton startEditingButton = AddIn.FromID <StartEditingButton>(ThisAddIn.IDs.StartEditingButton);

            startEditingButton.IsEnabled = false;

            // Enable the ShowEditsButton
            ShowEditsButton showEditsButton = AddIn.FromID <ShowEditsButton>(ThisAddIn.IDs.ShowEditsButton);

            showEditsButton.IsEnabled = true;
        }
예제 #2
0
        /// <summary>
        /// Start to track the rectangle when mouse down.
        /// </summary>
        /// <param name="arg"></param>
        protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
            base.OnMouseDown(arg);

            activeLayer = ArcMapApp.GetRasterLayer();

            if (activeLayer != null)
            {
                try
                {
                    Display.ClearElement(Editor.Selections.GetAllGraphicElements());
                    Editor.Selections.Clear();

                    // Define the selection symbol.
                    IRgbColor color = new RgbColorClass();
                    color.Red   = 255;
                    color.Green = 255;
                    color.Blue  = 255;

                    ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();
                    lineSymbol.Width = 1;
                    lineSymbol.Color = (IColor)color;

                    IPoint startCoor = Editor.ScreenCoor2MapCoor(arg.X, arg.Y);
                    newEnvelopeFeedback         = new NewEnvelopeFeedbackClass();
                    newEnvelopeFeedback.Display = ArcMap.Document.ActiveView.ScreenDisplay;
                    newEnvelopeFeedback.Symbol  = (ISymbol)lineSymbol;
                    newEnvelopeFeedback.Start(startCoor);

                    // Get the maximum extent of the active layer.
                    IRasterProps rasterProps = (IRasterProps)activeLayer.Raster;
                    maxExtent = new Position(rasterProps.Width, rasterProps.Height);
                }
                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");
                }
            }
        }
예제 #3
0
        /// <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 = Editor.ScreenCoor2RasterCoor(arg.X, arg.Y, activeLayer);
                        brCorner = tlCorner;
                    }
                    else
                    {
                        tlCorner = Editor.MapCoor2RasterCoor(envelop.UpperLeft, activeLayer);
                        brCorner = Editor.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++)
                        {
                            Pixel pixel = new Pixel(new Position(col, row));
                            pixel.GraphicElement = Display.DrawBox(pixel.Position, Editor.GetSelectionSymbol(), ArcMapApp.GetRasterLayer());
                            Editor.Selections.Add(pixel);
                        }
                    }

                    double[,] values = Editor.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");
                }
            }
        }