Beispiel #1
0
        /// <summary>
        /// Event that occurs when the AddShapeForm is closing.  I generate the return value here.
        /// </summary>
        /// <param name="sender">The object causing the close event.</param>
        /// <param name="e">Event data.</param>
        private void AddShapeForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            m_globals.Events.RemoveHandler(m_MapMouseMoveDelegate);
            m_globals.Events.RemoveHandler(m_MapMouseUpDelegate);

            m_globals.MapWin.View.CursorMode       = m_oldCursorMode;
            m_globals.MapWin.View.MapCursor        = m_oldCursor;
            m_globals.MapWin.View.UserCursorHandle = m_oldCursorHandle;

            if (m_sf.EditingShapes == true)
            {
                m_globals.CreateUndoPoint();
                m_sf.StopEditingShapes(true, true, null);
            }

            if (m_Shape.NumPoints > 0)
            {
                m_retval = m_Shape.ToMWShape(m_sf.ShapefileType);
            }
            else
            {
                m_retval = null;
            }

            //Added by Lailin Chen to clear the SnapData list after use 12/12/2005
            m_snapper.ClearSnapData();
        }
Beispiel #2
0
        private void AddShape(ShapeClass s)
        {
            if (m_SFType == MapWindow.Interfaces.eLayerType.LineShapefile)
            {
                if (s.NumPoints < 2)
                {
                    ResetForNew();
                    MapWinUtility.Logger.Message("You must add at least two points for a line.", "Not Enough Points", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, DialogResult.OK);
                    return;
                }
            }
            else if (m_SFType == MapWindow.Interfaces.eLayerType.PolygonShapefile)
            {
                // 3 + 1 for termination point - first must equal last, meaning we have to have 4 for a polygon
                if (s.NumPoints < 4)
                {
                    ResetForNew();
                    MapWinUtility.Logger.Message("You must add at least three points for a polygon.", "Not Enough Points", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, DialogResult.OK);
                    return;
                }
            }

            if (m_sf.EditingShapes == false)
            {
                if (m_sf.StartEditingShapes(true, null) == false)
                {
                    MapWinUtility.Logger.Msg("Could not edit the shapefile.", "Error");
                    if (!GlobalFunctions.m_StayInAddMode)
                    {
                        this.Close();
                    }
                    else
                    {
                        ResetForNew();
                    }
                    return;
                }
            }

            int newIndex = m_sf.NumShapes;

            MapWinGIS.Shape shp = s.ToMWShape(m_sf.ShapefileType);
            //MapWinGIS.ShapefileColorScheme cs = m_globals.MapWin.Layers[m_globals.MapWin.Layers.CurrentLayer].ColoringScheme;
            if (m_sf.EditInsertShape(shp, ref newIndex) == false)
            {
                MapWinUtility.Logger.Msg("Failed to add the new shape to the shapefile.", "Error");
            }
            else
            {
                if (m_snapper != null)
                {
                    m_snapper.AddShapeData(newIndex, m_globals.MapWin.Layers.CurrentLayer);
                }

                // Save
                if (m_sf.EditingShapes == true)
                {
                    m_globals.CreateUndoPoint();
                    m_sf.StopEditingShapes(true, true, null);
                }

                m_globals.MapWin.Plugins.BroadcastMessage("ShapefileEditor: Layer " + m_globals.MapWin.Layers.CurrentLayer.ToString() + ": New Shape Added");
            }
            m_globals.MapWin.View.Draw.ClearDrawing(m_drawHandle);
            if (!GlobalFunctions.m_StayInAddMode)
            {
                this.Close();
            }
            else
            {
                ResetForNew();
            }
        }