static public void UP(object sender, MouseEventArgs e)
        {
            mousePosition  = e.Location;
            isRoomSelected = false;
            switch (Mode)
            {
            case modeStruct.moveVinosku:
                Mode = modeStruct.doNothing_NOSCALEMODE;
                break;

            case modeStruct.dragVertex:
                Mode = modeStruct.doNothing_NOSCALEMODE;
                break;

            case modeStruct.moveRoom:
                Mode = modeStruct.doNothing_NOSCALEMODE;
                break;

            case modeStruct.dragShkaf:
                Mode = modeStruct.doNothing_NOSCALEMODE;
                break;

            case modeStruct.scaleSomething:
                Mode = modeStruct.doNothing_SCALEMODE;
                break;

            case modeStruct.dragShkafnoe:
                Mode = modeStruct.doNothing_NOSCALEMODE;
                break;
            }
        }
        private static void handler(object sender, EventArgs e)
        {
            if (isDrawSelected)
            {
                switch (((MenuItem)sender).Text)
                {
                case "Изменить название":
                    RoomCreator cr = new RoomCreator();
                    if (cr.ShowDialog() == DialogResult.OK)
                    {
                        movable.labels[localSheet] = cr.roomName;
                    }
                    break;

                case "Добавить выноску":

                    break;

                case "Копировать":

                    break;

                case "Удалить":
                    foreach (var i in Schemes_Editor.wires)
                    {
                        if (i.firstEquip.localID == ((drawer)movable).localID)
                        {
                            var t = ((Wire)movable);
                            if (t.firstEquip is inboxes)
                            {
                                ((inboxes)t.firstEquip).seized[Schemes_Editor.mainList.Find(x => x.id == ((inboxes)t.firstEquip).globalId).compatibilities.FindIndex(x => x.interfaceType.id == t.OtherFirst.interfaceType.id)]--;
                            }
                            if (t.secondEquip is inboxes)
                            {
                                ((inboxes)t.secondEquip).seized[Schemes_Editor.mainList.Find(x => x.id == ((inboxes)t.secondEquip).globalId).compatibilities.FindIndex(x => x.interfaceType.id == t.OtherSecond.interfaceType.id)]--;
                            }
                            Schemes_Editor.wires.RemoveAll(x => x.localID == t.localID);
                        }
                        if (i.secondEquip.localID == ((drawer)movable).localID)
                        {
                            var t = ((Wire)movable);
                            if (t.firstEquip is inboxes)
                            {
                                ((inboxes)t.firstEquip).seized[Schemes_Editor.mainList.Find(x => x.id == ((inboxes)t.firstEquip).globalId).compatibilities.FindIndex(x => x.interfaceType.id == t.OtherFirst.interfaceType.id)]--;
                            }
                            if (t.secondEquip is inboxes)
                            {
                                ((inboxes)t.secondEquip).seized[Schemes_Editor.mainList.Find(x => x.id == ((inboxes)t.secondEquip).globalId).compatibilities.FindIndex(x => x.interfaceType.id == t.OtherSecond.interfaceType.id)]--;
                            }
                            Schemes_Editor.wires.RemoveAll(x => x.localID == t.localID);
                        }
                        Schemes_Editor.mainWorkList.RemoveAll(x => x.localID == ((drawer)movable).localID);
                    }
                    break;
                }
            }
            if (isRoomSelected)
            {
            }
            if (isWireSelected)
            {
                switch (((MenuItem)sender).Text)
                {
                case "Изменить название":
                    RoomCreator cr = new RoomCreator();
                    if (cr.ShowDialog() == DialogResult.OK)
                    {
                        movable.labels[localSheet] = cr.roomName;
                    }
                    break;

                case "Добавить выноску":
                    Schemes_Editor.wires[SelectedWireIndex].createVinosku(Schemes_Editor.wires[SelectedWireIndex].inside(localSheet, mousePosition).vertex, localSheet);
                    movable = Schemes_Editor.wires[SelectedWireIndex];
                    Mode    = modeStruct.moveVinosku;
                    break;

                case "Удалить":
                    var t = ((Wire)movable);
                    if (t.firstEquip is inboxes)
                    {
                        ((inboxes)t.firstEquip).seized[Schemes_Editor.mainList.Find(x => x.id == ((inboxes)t.firstEquip).globalId).compatibilities.FindIndex(x => x.interfaceType.id == t.OtherFirst.interfaceType.id)]--;
                    }
                    if (t.secondEquip is inboxes)
                    {
                        ((inboxes)t.secondEquip).seized[Schemes_Editor.mainList.Find(x => x.id == ((inboxes)t.secondEquip).globalId).compatibilities.FindIndex(x => x.interfaceType.id == t.OtherSecond.interfaceType.id)]--;
                    }
                    Schemes_Editor.wires.RemoveAll(x => x.localID == t.localID);
                    break;

                case "Удалить узел":
                    var tt = ((Wire)movable).inside(localSheet, mousePosition);
                    if (tt.vertex.X != -1 && tt.isExists)
                    {
                        ((Wire)movable).points[localSheet].RemoveAll(x => x.X == tt.vertex.X && x.Y == tt.vertex.Y);
                    }
                    break;
                }
            }
        }
        static public void DOWN(object sender, MouseEventArgs e)
        {
            mousePosition = e.Location;
            if (e.Button == MouseButtons.Right)
            {
                movable        = null;
                isDrawSelected = false;
                if (isWireSelected)
                {
                    movable = Schemes_Editor.wires[SelectedWireIndex];
                    ContextMenu menushka = new ContextMenu(new MenuItem[] { new MenuItem("Добавить выноску", handler), new MenuItem("Копировать", handler), new MenuItem("Удалить", handler), new MenuItem("Удалить узел", handler), new MenuItem("Изменить название", handler) });
                    menushka.Show(father.strct, e.Location);
                    return;
                }
                for (int i = Schemes_Editor.mainWorkList.Count - 1; i > -1; i--)
                {
                    if (Schemes_Editor.mainWorkList[i].inside(e.Location, localSheet))
                    {
                        if (Schemes_Editor.mainWorkList[i] is inboxes)
                        {
                            movable = Schemes_Editor.mainWorkList[i];

                            isDrawSelected = true;
                            ContextMenu menushka = new ContextMenu(new MenuItem[] { new MenuItem("Добавить выноску", handler), new MenuItem("Копировать", handler), new MenuItem("Удалить", handler), new MenuItem("Удалить узел", handler), new MenuItem("Изменить название", handler) });
                            menushka.Show(father.strct, e.Location);
                            return;
                        }
                        if (Schemes_Editor.mainWorkList[i] is boxes)
                        {
                            movable        = Schemes_Editor.mainWorkList[i];
                            isDrawSelected = true;
                            ContextMenu menushka = new ContextMenu(new MenuItem[] { new MenuItem("Добавить выноску", handler), new MenuItem("Копировать", handler), new MenuItem("Удалить", handler), new MenuItem("Удалить узел", handler), new MenuItem("Изменить название", handler) });
                            menushka.Show(father.strct, e.Location);
                            return;
                        }
                        if (Schemes_Editor.mainWorkList[i] is free)
                        {
                            movable        = Schemes_Editor.mainWorkList[i];
                            isDrawSelected = true;
                            ContextMenu menushka = new ContextMenu(new MenuItem[] { new MenuItem("Добавить выноску", handler), new MenuItem("Копировать", handler), new MenuItem("Удалить", handler), new MenuItem("Удалить узел", handler), new MenuItem("Изменить название", handler) });
                            menushka.Show(father.strct, e.Location);
                            return;
                        }
                        break;
                    }
                }
                for (int i = 0; i < Schemes_Editor.rooms.Count; i++)
                {
                    if (Schemes_Editor.rooms[i].inside(e.Location, localSheet))
                    {
                        isRoomSelected = true;
                        movable        = Schemes_Editor.rooms[i];
                        ContextMenu menushka = new ContextMenu(new MenuItem[] { new MenuItem("Добавить выноску", handler), new MenuItem("Копировать", handler), new MenuItem("Удалить", handler), new MenuItem("Удалить узел", handler), new MenuItem("Изменить название", handler) });
                        menushka.Show(father.strct, e.Location);
                        return;
                    }
                }
            }
            else
            {
                switch (Mode)
                {
                case modeStruct.doNothing_NOSCALEMODE:
                    movable = null;

                    if (isWireSelected)
                    {
                        var t = Schemes_Editor.wires[SelectedWireIndex].inside(localSheet, e.Location);
                        if (t.isExists)
                        {
                            VertexNumber = t.ExistingIndex;
                            if (VertexNumber != -1)
                            {
                                Mode    = modeStruct.dragVertex;
                                movable = 1;
                            }
                        }
                        else     //создать новую опорную точку
                        {
                            VertexNumber = Schemes_Editor.wires[SelectedWireIndex].insertPoint(t.vertex, localSheet);
                            if (VertexNumber != -1)
                            {
                                Mode    = modeStruct.dragVertex;
                                movable = 1;
                            }
                        }
                    }
                    if (movable != null)
                    {
                        break;
                    }
                    for (int i = Schemes_Editor.mainWorkList.Count - 1; i > -1; i--)
                    {
                        if (Schemes_Editor.mainWorkList[i].inside(e.Location, localSheet))
                        {
                            if (Schemes_Editor.mainWorkList[i] is inboxes)
                            {
                                Prev    = new Point(e.Location.X - ((inboxes)Schemes_Editor.mainWorkList[i]).locations[localSheet].X, e.Location.Y - ((inboxes)Schemes_Editor.mainWorkList[i]).locations[localSheet].Y);
                                Mode    = modeStruct.dragShkafnoe;
                                movable = Schemes_Editor.mainWorkList[i];
                            }
                            if (Schemes_Editor.mainWorkList[i] is boxes)
                            {
                                movable = Schemes_Editor.mainWorkList[i];
                                Prev    = new Point(e.Location.X - ((boxes)Schemes_Editor.mainWorkList[i]).locations[localSheet].X, e.Location.Y - ((boxes)Schemes_Editor.mainWorkList[i]).locations[localSheet].Y);
                                Mode    = modeStruct.dragShkaf;
                            }
                            if (Schemes_Editor.mainWorkList[i] is free)
                            {
                                movable = Schemes_Editor.mainWorkList[i];
                                Prev    = new Point(e.Location.X - ((free)Schemes_Editor.mainWorkList[i]).locations[localSheet].X, e.Location.Y - ((free)Schemes_Editor.mainWorkList[i]).locations[localSheet].Y);
                                Mode    = modeStruct.dragShkaf;
                            }
                            break;
                        }
                    }
                    if (movable != null)
                    {
                        break;
                    }
                    else
                    {
                        for (int i = 0; i < Schemes_Editor.rooms.Count; i++)
                        {
                            if (Schemes_Editor.rooms[i].inside(e.Location, localSheet))
                            {
                                isRoomSelected = true;
                                Prev           = new Point(e.Location.X - Schemes_Editor.rooms[i].locations[localSheet].X, e.Location.Y - Schemes_Editor.rooms[i].locations[localSheet].Y);
                                movable        = Schemes_Editor.rooms[i];
                                Mode           = modeStruct.moveRoom;
                            }
                        }
                    }
                    break;


                case modeStruct.doNothing_SCALEMODE:
                    moveTargetIndex = -1;
                    for (int i = 0; i < Schemes_Editor.mainWorkList.Count; i++)
                    {
                        //if (Schemes_Editor.mainWorkList[i] is wire_s)
                        //    continue;
                        if (Schemes_Editor.mainWorkList[i] is inboxes && ((inboxes)Schemes_Editor.mainWorkList[i]).inbox)
                        {
                            continue;
                        }

                        int a = Schemes_Editor.mainWorkList[i].locations[localSheet].X, b = Schemes_Editor.mainWorkList[i].locations[localSheet].Y, c = Schemes_Editor.mainWorkList[i].locations[localSheet].X + Schemes_Editor.mainWorkList[i].scales[localSheet].X, d = Schemes_Editor.mainWorkList[i].locations[localSheet].Y + Schemes_Editor.mainWorkList[i].scales[localSheet].Y;
                        if (Schemes_Editor.distance(new Point(a, b), e.Location) < 20)
                        {
                            scalePoint = new Point(a, b); moveTargetIndex = i; pointNum = 0;
                            Mode       = modeStruct.scaleSomething;
                            break;
                        }
                        if (Schemes_Editor.distance(new Point(a, d), e.Location) < 20)
                        {
                            scalePoint = new Point(a, d); moveTargetIndex = i; pointNum = 3;
                            Mode       = modeStruct.scaleSomething;
                            break;
                        }
                        if (Schemes_Editor.distance(new Point(c, b), e.Location) < 20)
                        {
                            scalePoint = new Point(c, b); moveTargetIndex = i; pointNum = 1;
                            Mode       = modeStruct.scaleSomething;
                            break;
                        }
                        if (Schemes_Editor.distance(new Point(c, d), e.Location) < 20)
                        {
                            scalePoint = new Point(c, d); moveTargetIndex = i; pointNum = 2;
                            Mode       = modeStruct.scaleSomething;
                            break;
                        }
                    }
                    if (moveTargetIndex != -1)
                    {
                        break;
                    }
                    else
                    {
                        for (int i = 0; i < Schemes_Editor.rooms.Count; i++)
                        {
                            int a = Schemes_Editor.rooms[i].locations[localSheet].X, b = Schemes_Editor.rooms[i].locations[localSheet].Y, c = Schemes_Editor.rooms[i].locations[localSheet].X + Schemes_Editor.rooms[i].locations[localSheet].Width, d = Schemes_Editor.rooms[i].locations[localSheet].Y + Schemes_Editor.rooms[i].locations[localSheet].Height;
                            if (Schemes_Editor.distance(new Point(a, b), e.Location) < 20)
                            {
                                isRoomSelected = true;
                                scalePoint     = new Point(a, b); moveTargetIndex = i; pointNum = 0;
                                Mode           = modeStruct.scaleSomething;
                                break;
                            }
                            if (Schemes_Editor.distance(new Point(a, d), e.Location) < 20)
                            {
                                isRoomSelected = true;
                                scalePoint     = new Point(a, d); moveTargetIndex = i; pointNum = 3;
                                Mode           = modeStruct.scaleSomething;
                                break;
                            }
                            if (Schemes_Editor.distance(new Point(c, b), e.Location) < 20)
                            {
                                isRoomSelected = true;
                                scalePoint     = new Point(c, b); moveTargetIndex = i; pointNum = 1;
                                Mode           = modeStruct.scaleSomething;
                                break;
                            }
                            if (Schemes_Editor.distance(new Point(c, d), e.Location) < 20)
                            {
                                isRoomSelected = true;
                                scalePoint     = new Point(c, d); moveTargetIndex = i; pointNum = 2;
                                Mode           = modeStruct.scaleSomething;
                                break;
                            }
                        }
                    }
                    break;
                }
            }
        }