示例#1
0
        private void MapMouseDown(int Button, int Shift, int x, int y, ref bool Handled)
        {
            try
            {
                if (m_globals.CurrentMode == GlobalFunctions.Modes.RemoveVertex)
                {
                    if (m_globals.CurrentLayer == null)
                    {
                        return;
                    }
                    MapWinGIS.Shapefile shpFile = m_globals.CurrentLayer;

                    //get the projection coordinates
                    double projX = 0, projY = 0;
                    m_MapWin.View.PixelToProj((double)x, (double)y, ref projX, ref projY);

                    //get all the vertex points that are within tolerance
                    System.Collections.ArrayList snapPoints = new System.Collections.ArrayList();
                    if (m_snapClass.CanSnap(m_globals.CurrentTolerance, projX, projY, ref snapPoints))
                    {
                        RemoveSelectedVertex(snapPoints, shpFile);
                    }

                    //reload the snap class
                    m_snapClass = new SnapClass(m_MapWin);

                    Handled = true;
                }
            }
            catch (System.Exception ex)
            {
                m_MapWin.ShowErrorDialog(ex);
            }
        }
示例#2
0
        public void LayerSelectedEvent(int Handle)
        {
            if (m_globals.CurrentLayer != null)
            {
                MapWindow.Interfaces.eLayerType t = m_globals.MapWin.Layers[m_globals.MapWin.Layers.CurrentLayer].LayerType;

                if ((m_snapper == null) && ((t == lt.LineShapefile) || (t == lt.PointShapefile) || (t == lt.PolygonShapefile)))
                {
                    m_snapper = new SnapClass(m_globals.MapWin);
                }
            }
            else
            {
                m_snapper = null;
            }
        }
        public RemoveVertexClass(GlobalFunctions g)
        {
            m_globals           = g;
            ItemClickedDelegate = new MapWindow.Events.ItemClickedEvent(ItemClickedEvent);
            g.Events.AddHandler(ItemClickedDelegate);
            TerminateDelegate = new MapWindow.Events.TerminateEvent(TerminateEvent);
            g.Events.AddHandler(TerminateDelegate);
            m_cursor = new System.Windows.Forms.Cursor(this.GetType(), "RemovePoint.cur");

            MapWinGIS.Shapefile sf = g.CurrentLayer;
            if (sf != null)
            {
                m_snapper = new SnapClass(sf);
            }
            else
            {
                m_snapper = null;
            }
        }
示例#4
0
        public void MapMouseUp(int Button, int Shift, int x, int y, ref bool Handled)
        {
            try
            {
                if (m_globals.CurrentMode == GlobalFunctions.Modes.MoveShape)
                {
                    if (m_MapDraging == true)
                    {
                        double projX = 0, projY = 0;
                        m_MapWin.View.PixelToProj((double)x, (double)y, ref projX, ref projY);

                        //get the working shapefile
                        if (m_globals.CurrentLayer == null)
                        {
                            return;
                        }
                        MapWinGIS.Shapefile shpFile = m_globals.CurrentLayer;

                        //start editing the vertex postion
                        shpFile.StartEditingShapes(true, null);



                        //stop editing and save changes
                        shpFile.StopEditingShapes(true, true, null);

                        //set the cursor to move cur
                        m_MapWin.View.UserCursorHandle = (int)m_cursor.Handle;

                        // update snap class
                        m_snapClass = new SnapClass(m_MapWin);
                    }

                    ClearDrawings();
                    m_MapDraging = false;
                    Handled      = true;
                }
            }
            catch (System.Exception ex)
            {
                m_MapWin.ShowErrorDialog(ex);
            }
        }
示例#5
0
        /// <summary>
        /// Constructor.
        /// The AddShapeForm is used when creating a new shape.
        /// The user can either click on the map to generate new points, lines or polygons, or input coordinates in the text boxes provided on the form.
        /// </summary>
        public AddShapeForm(GlobalFunctions g, ref SnapClass snapper)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            m_globals         = g;
            m_cursor          = new System.Windows.Forms.Cursor(this.GetType(), "InsertPoint.cur");
            view              = g.MapWin.View;
            m_oldCursorMode   = view.CursorMode;
            m_oldCursor       = view.MapCursor;
            m_oldCursorHandle = view.UserCursorHandle;
            view.CursorMode   = MapWinGIS.tkCursorMode.cmNone;
            view.MapCursor    = MapWinGIS.tkCursor.crsrWait;

            m_SFType = g.MapWin.Layers[g.MapWin.Layers.CurrentLayer].LayerType;
            m_Shape  = new ShapeClass();

            // Sign me up for these events!
            m_MapMouseMoveDelegate = new MapWindow.Events.MapMouseMoveEvent(MouseMoveEvent);
            g.Events.AddHandler(m_MapMouseMoveDelegate);
            m_MapMouseUpDelegate = new MapWindow.Events.MapMouseUpEvent(MouseUpEvent);
            g.Events.AddHandler(m_MapMouseUpDelegate);
            m_LayerSelectedDelegate = new MapWindow.Events.LayerSelectedEvent(LayerSelectedEvent);
            g.Events.AddHandler(m_LayerSelectedDelegate);

            MapWindow.Interfaces.eLayerType t = g.MapWin.Layers[g.MapWin.Layers.CurrentLayer].LayerType;

            m_sf = g.CurrentLayer;

            if ((m_snapper == null) && ((t == lt.LineShapefile) || (t == lt.PointShapefile) || (t == lt.PolygonShapefile)))
            {
                m_snapper = new SnapClass(m_globals.MapWin);
            }

            view.MapCursor        = MapWinGIS.tkCursor.crsrUserDefined;
            view.UserCursorHandle = m_cursor.Handle.ToInt32();

            m_PointSize = 6;
        }
示例#6
0
        private void ResetForNew()
        {
            m_snapper = new SnapClass(m_globals.MapWin);
            m_Shape   = new ShapefileEditor.ShapeClass();

            m_globals.UpdateButtons();
            m_globals.DoEnables();

            m_globals.UpdateView();

            if (m_cursor == null)
            {
                m_cursor = new System.Windows.Forms.Cursor(this.GetType(), "InsertPoint.cur");
            }
            m_oldCursorMode   = view.CursorMode;
            m_oldCursor       = view.MapCursor;
            m_oldCursorHandle = view.UserCursorHandle;
            view.CursorMode   = MapWinGIS.tkCursorMode.cmNone;

            view.MapCursor        = MapWinGIS.tkCursor.crsrUserDefined;
            view.UserCursorHandle = m_cursor.Handle.ToInt32();
        }
示例#7
0
        private void ItemClicked(string ItemName, ref bool Handled)
        {
            try
            {
                m_MapWin = m_globals.MapWin;
                if (ItemName == GlobalFunctions.c_MoveShapesButton)
                {
                    if (m_globals.CurrentMode != GlobalFunctions.Modes.MoveShape)
                    {
                        m_globals.CurrentMode = GlobalFunctions.Modes.MoveShape;

                        //update the buttons on the toolbar
                        m_globals.UpdateButtons();

                        //save the previous cusor mode
                        m_globals.SaveCusorMode();

                        //set cursor mode
                        m_MapWin.View.CursorMode       = MapWinGIS.tkCursorMode.cmNone;
                        m_MapWin.View.MapCursor        = MapWinGIS.tkCursor.crsrUserDefined;
                        m_MapWin.View.UserCursorHandle = (int)m_cursor.Handle;

                        //get current shapefile layer
                        if (m_globals.CurrentLayer == null)
                        {
                            return;
                        }
                        MapWinGIS.Shapefile shpFile = m_globals.CurrentLayer;

                        m_prevShape = -1;
                        //create as new snap class
                        if (m_globals.CurrentLayer == null)
                        {
                            return;
                        }
                        m_snapClass = new SnapClass(m_MapWin);
                    }
                    else
                    {
                        m_MapWin.View.Draw.ClearDrawing(m_hDraw);
                        m_globals.CurrentMode = GlobalFunctions.Modes.None;

                        //set back the old cursor settings
                        m_globals.RestoreCursorMode();

                        //update the buttons on the toolbar
                        m_globals.UpdateButtons();
                    }
                    Handled = true;
                }
                else
                {
                    if (m_MapWin.Toolbar.ButtonItem(GlobalFunctions.c_MoveShapesButton).Pressed)
                    {
                        m_MapWin.View.Draw.ClearDrawing(m_hDraw);
                        m_globals.CurrentMode = GlobalFunctions.Modes.None;

                        //get current shapefile layer
                        m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].HideVertices();

                        //update the buttons on the toolbar
                        m_globals.UpdateButtons();
                    }
                }
            }
            catch (System.Exception ex)
            {
                m_MapWin.ShowErrorDialog(ex);
            }
        }
示例#8
0
        private void ItemClickedEvent(string ItemName, ref bool Handled)
        {
            try
            {
                m_MapWin = m_globals.MapWin;
                m_MapWin.View.Draw.ClearDrawing(m_hDraw);
                //if (m_MapWin.Layers.CurrentLayer != -1) - This produces a crash with a new project loading!
                if (m_MapWin.Layers.NumLayers > 0)
                {
                    if (!m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].VerticesVisible)
                    {
                        m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].HideVertices();
                    }
                }
                if (m_snapper != null)
                {
                    m_snapper.ClearSnapData();
                    m_snapper = null;
                }
                if (ItemName == GlobalFunctions.c_AddShapeButton)
                {
                    if (m_globals.SelectedShapefileIsReadonly())
                    {
                        MapWinUtility.Logger.Msg("The selected shapefile is read-only and cannot be edited.", "Read-Only Shapefile");
                        return;
                    }

                    // Add a new shape now
                    if (m_globals.CurrentMode == GlobalFunctions.Modes.AddShape)
                    {
                        m_globals.CurrentMode = GlobalFunctions.Modes.None;
                        m_globals.UpdateButtons();
                        if (m_AddShapeForm != null)
                        {
                            m_AddShapeForm.Close();
                        }
                    }
                    else
                    {
                        m_globals.CurrentMode = GlobalFunctions.Modes.AddShape;
                        m_globals.UpdateButtons();
                        AddNewShape();
                    }
                    Handled = true;
                }
                else
                {
                    if (m_MapWin.Toolbar.ButtonItem(GlobalFunctions.c_AddShapeButton).Pressed)
                    {
                        if (m_snapper != null)
                        {
                            m_snapper.ClearSnapData();
                            m_snapper = null;
                        }

                        m_MapWin.View.Draw.ClearDrawing(m_hDraw);
                        m_globals.CurrentMode = GlobalFunctions.Modes.None;

                        //get current shapefile layer
                        if (m_MapWin.Layers.NumLayers > 0)
                        {
                            if (!m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].VerticesVisible)
                            {
                                m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].HideVertices();
                            }
                        }

                        //update the buttons on the toolbar
                        m_globals.UpdateButtons();
                    }
                }
            }
            catch (System.Exception ex)
            {
                m_MapWin.ShowErrorDialog(ex);
            }
        }
示例#9
0
        private void ItemClicked(string ItemName, ref bool Handled)
        {
            try
            {
                m_MapWin = m_globals.MapWin;
                if (ItemName == GlobalFunctions.c_RemoveVertexButton)
                {
                    if (m_globals.SelectedShapefileIsReadonly())
                    {
                        MapWinUtility.Logger.Msg("The selected shapefile is read-only and cannot be edited.", "Read-Only Shapefile");
                        return;
                    }

                    if (m_globals.CurrentMode != GlobalFunctions.Modes.RemoveVertex)
                    {
                        m_globals.CurrentMode = GlobalFunctions.Modes.RemoveVertex;

                        //update the buttons on the toolbar
                        m_globals.UpdateButtons();

                        //save the previous cusor mode
                        m_globals.SaveCusorMode();

                        //set cursor mode
                        m_MapWin.View.CursorMode       = MapWinGIS.tkCursorMode.cmNone;
                        m_MapWin.View.MapCursor        = MapWinGIS.tkCursor.crsrUserDefined;
                        m_MapWin.View.UserCursorHandle = (int)m_cursor.Handle;

                        //create as new snap class
                        if (m_globals.CurrentLayer != null)
                        {
                            m_snapClass = new SnapClass(m_MapWin);
                        }

                        m_prevShape = -1;
                    }
                    else
                    {
                        m_MapWin.View.Draw.ClearDrawing(m_hDraw);
                        m_globals.CurrentMode = GlobalFunctions.Modes.None;

                        //set back the old cursor settings
                        m_globals.RestoreCursorMode();

                        //update the buttons on the toolbar
                        m_globals.UpdateButtons();
                    }
                    Handled = true;
                }
                else
                {
                    if (m_MapWin.Toolbar.ButtonItem(GlobalFunctions.c_RemoveVertexButton).Pressed)
                    {
                        m_MapWin.View.Draw.ClearDrawing(m_hDraw);
                        m_globals.CurrentMode = GlobalFunctions.Modes.None;

                        //update the buttons on the toolbar
                        m_globals.UpdateButtons();
                    }
                }
            }
            catch (System.Exception ex)
            {
                m_MapWin.ShowErrorDialog(ex);
            }
        }
        public void MapMouseUp(int Button, int Shift, int x, int y, ref bool Handled)
        {
            try
            {
                if (m_globals.CurrentMode == GlobalFunctions.Modes.MoveVertex)
                {
                    if (m_MapDraging == true)
                    {
                        double projX = 0, projY = 0;
                        m_MapWin.View.PixelToProj((double)x, (double)y, ref projX, ref projY);

                        //get the working shapefile
                        if (m_globals.CurrentLayer == null)
                        {
                            return;
                        }
                        MapWinGIS.Shapefile shpFile = m_globals.CurrentLayer;

                        //start editing the vertex postion
                        shpFile.StartEditingShapes(true, null);

                        //get all the vertex points that are within tolerance
                        System.Collections.ArrayList snapPoints = new System.Collections.ArrayList();
                        if (m_snapClass.CanSnap(m_globals.CurrentTolerance, projX, projY, ref snapPoints))
                        {
                            DrawAllSnapPoints(snapPoints);
                        }

                        ShapefileEditor.SnapData snapPoint;
                        MapWinGIS.Shape          shp;
                        MapWinGIS.Point          p;

                        //if allow snaping then change all vertex in the snaping tolerance
                        int count;
                        if (m_globals.AllowSnapingToVertices)
                        {
                            count = m_snapPoints.Count;
                        }
                        else
                        {
                            count = Math.Min(m_snapPoints.Count, 1);
                        }

                        for (int i = 0; i < count; i++)
                        {
                            snapPoint = (ShapefileEditor.SnapData)m_snapPoints[i];
                            shp       = shpFile.get_Shape(snapPoint.shpIndex);
                            p         = shp.get_Point(snapPoint.pointIndex);

                            //check to see if were going to snap to a point
                            if (snapPoints.Count > 0 && m_globals.AllowSnapingToVertices)
                            {
                                p.x = ((ShapefileEditor.SnapData)snapPoints[0]).point.x;
                                p.y = ((ShapefileEditor.SnapData)snapPoints[0]).point.y;
                            }
                            else
                            {
                                p.x = projX;
                                p.y = projY;
                            }
                        }

                        m_globals.CreateUndoPoint();

                        //stop editing and save changes
                        shpFile.StopEditingShapes(true, true, null);

                        //set the cursor to move cur
                        m_MapWin.View.UserCursorHandle = (int)m_cursor.Handle;

                        // update snap class
                        m_snapClass = new SnapClass(m_MapWin);
                    }

                    ClearDrawings();
                    m_MapDraging = false;
                    Handled      = true;
                }
            }
            catch (System.Exception ex)
            {
                m_MapWin.ShowErrorDialog(ex);
            }
        }