Exemplo n.º 1
0
        public void Dispose()
        {
            // Not already removed automatically?
            if (!vertex.IsDisposed)
            {
                // If the vertex only has 2 linedefs attached, then merge the linedefs
                if (vertex.Linedefs.Count == 2)
                {
                    Linedef ld1 = General.GetByIndex(vertex.Linedefs, 0);
                    Linedef ld2 = General.GetByIndex(vertex.Linedefs, 1);
                    Vertex  v1  = (ld1.Start == vertex) ? ld1.End : ld1.Start;
                    Vertex  v2  = (ld2.Start == vertex) ? ld2.End : ld2.Start;
                    if (ld1.Start == vertex)
                    {
                        ld1.SetStartVertex(v2);
                    }
                    else
                    {
                        ld1.SetEndVertex(v2);
                    }
                    ld2.Dispose();
                }

                // Trash vertex
                vertex.Dispose();
            }
        }
Exemplo n.º 2
0
        //mxd
        private static void MergeLines(ICollection <Vertex> selected, Linedef ld1, Linedef ld2, Vertex v)
        {
            Vertex v1 = (ld1.Start == v) ? ld1.End : ld1.Start;
            Vertex v2 = (ld2.Start == v) ? ld2.End : ld2.Start;

            if (ld1.Start == v)
            {
                ld1.SetStartVertex(v2);
            }
            else
            {
                ld1.SetEndVertex(v2);
            }
            ld2.Dispose();
            bool redraw = true;

            if (!v2.IsDisposed && selected.Contains(v2) && v2.Linedefs.Count == 2)
            {
                Linedef[] lines = new Linedef[2];
                v2.Linedefs.CopyTo(lines, 0);
                Linedef other = lines[0] == ld2 ? lines[1] :lines[0];

                MergeLines(selected, ld1, other, v2);
                v2.Dispose();
                redraw = false;
            }

            if (!v1.IsDisposed && selected.Contains(v1) && v1.Linedefs.Count == 2)
            {
                Linedef[] lines = new Linedef[2];
                v1.Linedefs.CopyTo(lines, 0);
                Linedef other = lines[0] == ld1 ? lines[1] : lines[0];

                MergeLines(selected, other, ld1, v1);
                v1.Dispose();
                redraw = false;
            }

            if (redraw && ld1.Start != null && ld1.End != null)
            {
                Vector2D start = ld1.Start.Position;
                Vector2D end   = ld1.End.Position;
                ld1.Dispose();
                DrawLine(start, end);
            }
            else
            {
                ld1.Dispose();
            }
        }
Exemplo n.º 3
0
        public void DeleteItem()
        {
            // Make list of selected vertices
            ICollection <Vertex> selected = General.Map.Map.GetSelectedVertices(true);

            if ((selected.Count == 0) && (highlighted != null) && !highlighted.IsDisposed)
            {
                selected.Add(highlighted);
            }

            // Anything to do?
            if (selected.Count > 0)
            {
                // Make undo
                if (selected.Count > 1)
                {
                    General.Map.UndoRedo.CreateUndo("Delete " + selected.Count + " vertices");
                    General.Interface.DisplayStatus(StatusType.Action, "Deleted " + selected.Count + " vertices.");
                }
                else
                {
                    General.Map.UndoRedo.CreateUndo("Delete vertex");
                    General.Interface.DisplayStatus(StatusType.Action, "Deleted a vertex.");
                }

                // Go for all vertices that need to be removed
                foreach (Vertex v in selected)
                {
                    // Not already removed automatically?
                    if (!v.IsDisposed)
                    {
                        // If the vertex only has 2 linedefs attached, then merge the linedefs
                        if (v.Linedefs.Count == 2)
                        {
                            Linedef ld1 = General.GetByIndex(v.Linedefs, 0);
                            Linedef ld2 = General.GetByIndex(v.Linedefs, 1);
                            Vertex  v1  = (ld1.Start == v) ? ld1.End : ld1.Start;
                            Vertex  v2  = (ld2.Start == v) ? ld2.End : ld2.Start;
                            if (ld1.Start == v)
                            {
                                ld1.SetStartVertex(v2);
                            }
                            else
                            {
                                ld1.SetEndVertex(v2);
                            }
                            //if(ld2.Start == v) ld2.SetStartVertex(v1); else ld2.SetEndVertex(v1);
                            //ld1.Join(ld2);
                            ld2.Dispose();
                        }

                        // Trash vertex
                        v.Dispose();
                    }
                }

                // Update cache values
                General.Map.IsChanged = true;
                General.Map.Map.Update();

                // Invoke a new mousemove so that the highlighted item updates
                MouseEventArgs e = new MouseEventArgs(MouseButtons.None, 0, (int)mousepos.x, (int)mousepos.y, 0);
                OnMouseMove(e);

                // Redraw screen
                General.Interface.RedrawDisplay();
            }
        }