private void apply_Click(object sender, EventArgs e)
        {
            List <SlopeVertexGroup> groups = new List <SlopeVertexGroup>();

            // undodescription was set in the Setup method
            General.Map.UndoRedo.CreateUndo(undodescription);

            foreach (SlopeVertex sv in vertices)
            {
                SlopeVertexGroup svg = BuilderPlug.Me.GetSlopeVertexGroup(sv);
                float            x   = positionx.GetResultFloat(sv.Pos.x);
                float            y   = positiony.GetResultFloat(sv.Pos.y);

                sv.Pos = new Vector2D(x, y);

                sv.Z = positionz.GetResultFloat(sv.Z);

                if (!groups.Contains(svg))
                {
                    groups.Add(svg);
                }
            }

            foreach (SlopeVertexGroup svg in groups)
            {
                if (reposition.CheckState != CheckState.Indeterminate)
                {
                    svg.Reposition = reposition.Checked;
                }

                if (spline.CheckState != CheckState.Indeterminate && svg.Vertices.Count == 3)
                {
                    svg.Spline = spline.Checked;
                }

                // Ceiling
                if (addselectedsectorsceiling.Checked)
                {
                    foreach (Sector s in General.Map.Map.GetSelectedSectors(true).ToList())
                    {
                        svg.AddSector(s, PlaneType.Ceiling);
                    }
                }

                if (removeselectedsectorsceiling.Checked)
                {
                    foreach (Sector s in General.Map.Map.GetSelectedSectors(true).ToList())
                    {
                        if (svg.Sectors.Contains(s))
                        {
                            svg.RemoveSector(s, PlaneType.Ceiling);
                        }
                    }
                }

                // Floor
                if (addselectedsectorsfloor.Checked)
                {
                    foreach (Sector s in General.Map.Map.GetSelectedSectors(true).ToList())
                    {
                        svg.AddSector(s, PlaneType.Floor);
                    }
                }

                if (removeselectedsectorsfloor.Checked)
                {
                    foreach (Sector s in General.Map.Map.GetSelectedSectors(true).ToList())
                    {
                        if (svg.Sectors.Contains(s))
                        {
                            svg.RemoveSector(s, PlaneType.Floor);
                        }
                    }
                }

                foreach (Sector s in checkedListBoxSectors.CheckedItems)
                {
                    if (svg.Sectors.Contains(s))
                    {
                        svg.RemoveSector(s, PlaneType.Floor);
                        svg.RemoveSector(s, PlaneType.Ceiling);
                    }
                }

                svg.ApplyToSectors();
            }

            BuilderPlug.Me.StoreSlopeVertexGroupsInSector();

            this.DialogResult = DialogResult.OK;
        }
        // Accepted
        public override void OnAccept()
        {
            Cursor.Current = Cursors.AppStarting;

            General.Settings.FindDefaultDrawSettings();

            // When points have been drawn
            if (points.Count > 1)
            {
                // Make undo for the draw
                General.Map.UndoRedo.CreateUndo("Draw slope");

                List <SlopeVertex> sv_floor   = new List <SlopeVertex>();
                List <SlopeVertex> sv_ceiling = new List <SlopeVertex>();

                // Fills the slope vertex list for both floor and ceiling slopes. Alos tried
                // to determine the default z position of the vertex
                List <Sector> selected = (List <Sector>)General.Map.Map.GetSelectedSectors(true);
                if (selected.Count == 1 && IsControlSector(selected[0]))
                {
                    //If a 3D floor control sector is selected, then just use the height of it directly
                    float zf = selected[0].FloorHeight;
                    float zc = selected[0].CeilHeight;
                    for (int i = 0; i < points.Count; i++)
                    {
                        sv_floor.Add(new SlopeVertex(points[i].pos, zf));
                        sv_ceiling.Add(new SlopeVertex(points[i].pos, zc));
                    }
                }
                else
                {
                    //For normal sectors, grab the height of the sector each control handle lies within
                    for (int i = 0; i < points.Count; i++)
                    {
                        float  zf = 0;
                        float  zc = 0;
                        Sector s  = General.Map.Map.GetSectorByCoordinates(points[i].pos);

                        if (s != null)
                        {
                            foreach (Sidedef sd in s.Sidedefs)
                            {
                                if (sd.Line.Line.GetSideOfLine(points[i].pos) == 0)
                                {
                                    if (sd.Line.Back != null && !selected.Contains(sd.Line.Back.Sector))
                                    {
                                        zf = sd.Line.Back.Sector.FloorHeight;
                                        zc = sd.Line.Back.Sector.CeilHeight;
                                    }
                                    else
                                    {
                                        zf = sd.Line.Front.Sector.FloorHeight;
                                        zc = sd.Line.Front.Sector.CeilHeight;
                                    }
                                }
                            }
                        }

                        sv_floor.Add(new SlopeVertex(points[i].pos, zf));
                        sv_ceiling.Add(new SlopeVertex(points[i].pos, zc));
                    }
                }

                // Create the floor slope vertex group and add it to all selected sectors
                if (slopedrawingmode == SlopeDrawingMode.Floor || slopedrawingmode == SlopeDrawingMode.FloorAndCeiling)
                {
                    int id = -1;
                    SlopeVertexGroup svg = BuilderPlug.Me.AddSlopeVertexGroup(sv_floor, out id);

                    svg.Sectors.Clear();

                    foreach (Sector s in selected)
                    {
                        // Make sure the field work with undo/redo
                        s.Fields.BeforeFieldsChange();

                        if (s.Fields.ContainsKey("user_floorplane_id"))
                        {
                            s.Fields.Remove("user_floorplane_id");
                        }

                        s.Fields.Add("user_floorplane_id", new UniValue(UniversalType.Integer, id));

                        // svg.Sectors.Add(s);

                        svg.AddSector(s, PlaneType.Floor);
                    }
                }

                // Create the ceiling slope vertex group and add it to all selected sectors
                if (slopedrawingmode == SlopeDrawingMode.Ceiling || slopedrawingmode == SlopeDrawingMode.FloorAndCeiling)
                {
                    int id = -1;
                    SlopeVertexGroup svg = BuilderPlug.Me.AddSlopeVertexGroup(sv_ceiling, out id);

                    svg.Sectors.Clear();

                    foreach (Sector s in selected)
                    {
                        // Make sure the field work with undo/redo
                        s.Fields.BeforeFieldsChange();

                        if (s.Fields.ContainsKey("user_ceilingplane_id"))
                        {
                            s.Fields.Remove("user_ceilingplane_id");
                        }

                        s.Fields.Add("user_ceilingplane_id", new UniValue(UniversalType.Integer, id));

                        // svg.Sectors.Add(s);
                        svg.AddSector(s, PlaneType.Ceiling);
                    }
                }

                BuilderPlug.Me.StoreSlopeVertexGroupsInSector();

                // BuilderPlug.Me.UpdateSlopes();

                // Clear selection
                General.Map.Map.ClearAllSelected();

                // Update cached values
                General.Map.Map.Update();

                // Map is changed
                General.Map.IsChanged = true;
            }

            // Done
            Cursor.Current = Cursors.Default;

            // Return to original mode
            General.Editing.ChangeMode(General.Editing.PreviousStableMode.Name);
        }