예제 #1
0
        public void DeselectMultipleObjects()
        {
            TcpListener ServerSocket = new TcpListener(IPAddress.Parse("127.0.0.1"), 1000);

            ServerSocket.Start();
            PrivateObject canvas = new PrivateObject(typeof(Canvas));

            RectangleBlue       blueObj        = new RectangleBlue(50, 50, true);
            CmdAddRectangleBlue commandAddBlue = new CmdAddRectangleBlue();

            commandAddBlue.Execute(blueObj);
            Canvas.Objects.Add(blueObj);

            RectangleBlue       blueObj2        = new RectangleBlue(250, 70, true);
            CmdAddRectangleBlue commandAddBlue2 = new CmdAddRectangleBlue();

            commandAddBlue2.Execute(blueObj2);
            Canvas.Objects.Add(blueObj2);

            RectangleRed       redObj        = new RectangleRed(450, 100, true);
            CmdAddRectangleRed commandAddRed = new CmdAddRectangleRed();

            commandAddRed.Execute(redObj);
            Canvas.Objects.Add(redObj);

            object[] paramsSelectClick = new object[] { null, null };
            canvas.Invoke("btnSelect_Click", paramsSelectClick);

            object[] paramsMouseClick3 = new object[] { null, new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0) };
            canvas.Invoke("pnlCenter_MouseClick", paramsMouseClick3);

            NUnit.Framework.Assert.IsFalse(blueObj.Selected);
            NUnit.Framework.Assert.IsFalse(blueObj2.Selected);
            NUnit.Framework.Assert.IsFalse(redObj.Selected);
        }
예제 #2
0
        public void TestTwoObjectsSelect()
        {
            Canvas              canvas         = new Canvas(true);
            Guid                rectObjId      = Guid.NewGuid();
            Rectangle_Object    rectObjRed     = new RectangleRed(0, 0, false, false, false, rectObjId, 0, 0, false, false);
            Rectangle_Object    rectObjBlue    = new RectangleBlue(50, 20, false, false, false, rectObjId, 0, 0, false, false);
            CmdAddRectangleRed  cmdAddRectRed  = new CmdAddRectangleRed();
            CmdAddRectangleBlue cmdAddRectBlue = new CmdAddRectangleBlue();

            cmdAddRectRed.Execute(rectObjRed);
            Canvas.Objects.Add(rectObjRed);
            cmdAddRectBlue.Execute(rectObjBlue);
            Canvas.Objects.Add(rectObjBlue);

            canvas.IsChecked_btnSelectProp   = true;
            canvas.IsChecked_btnRectRedProp  = false;
            canvas.IsChecked_btnRectBlueProp = false;

            canvas.pnlCenter_MouseClickWrapper(55, 25, 1, 0);

            Assert.IsTrue(rectObjBlue.Selected);
            Assert.IsFalse(rectObjRed.Selected);

            canvas.pnlCenter_MouseClickWrapper(10, 10, 1, 0);

            Assert.IsTrue(rectObjRed.Selected);
        }
예제 #3
0
        public void TestSetCommandIfPart()
        {
            UndoRedoManager     manager              = new UndoRedoManager();
            Guid                userId               = Guid.NewGuid();
            Guid                userId2              = Guid.NewGuid();
            CmdAddRectangleRed  cmdAddRectangleRed   = new CmdAddRectangleRed();
            CmdAddRectangleBlue cmdAddRectangleBlue  = new CmdAddRectangleBlue();
            CmdAddRectangleBlue cmdAddRectangleBlue2 = new CmdAddRectangleBlue();

            cmdAddRectangleRed.username   = userId;
            cmdAddRectangleBlue.username  = userId;
            cmdAddRectangleBlue2.username = userId2;


            UndoRedoWrapper wrapperBlue  = new UndoRedoWrapper(cmdAddRectangleBlue);
            UndoRedoWrapper wrapperBlue2 = new UndoRedoWrapper(cmdAddRectangleBlue);
            UndoRedoWrapper wrapperRed   = new UndoRedoWrapper(cmdAddRectangleRed);

            manager.Commands[0] = wrapperBlue;
            manager.SetCommand(wrapperBlue);
            manager.Commands[1] = wrapperBlue2;
            manager.SetCommand(wrapperBlue2);
            manager.Commands[2] = wrapperRed;

            manager.Counter = 3;
            manager.SetCommand(wrapperRed);
            int position = manager.Counter - 1;

            Assert.AreEqual(manager.LastCommand[userId], position);
        }
예제 #4
0
        public void TestConflictAll()
        {
            UndoRedoManager     manager              = new UndoRedoManager();
            Guid                userId               = Guid.NewGuid();
            Guid                userId2              = Guid.NewGuid();
            CmdAddRectangleRed  cmdAddRectangleRed   = new CmdAddRectangleRed();
            CmdAddRectangleBlue cmdAddRectangleBlue  = new CmdAddRectangleBlue();
            CmdAddRectangleBlue cmdAddRectangleBlue2 = new CmdAddRectangleBlue();

            cmdAddRectangleRed.username   = userId;
            cmdAddRectangleBlue.username  = userId;
            cmdAddRectangleBlue2.username = userId2;

            UndoRedoWrapper wrapperBlue  = new UndoRedoWrapper(cmdAddRectangleBlue);
            UndoRedoWrapper wrapperBlue2 = new UndoRedoWrapper(cmdAddRectangleBlue2);
            UndoRedoWrapper wrapperRed   = new UndoRedoWrapper(cmdAddRectangleRed);

            manager.Commands[0] = wrapperBlue;
            manager.SetCommand(wrapperBlue);
            manager.Commands[1] = wrapperRed;
            manager.SetCommand(wrapperBlue2);
            manager.Commands[2] = wrapperBlue2;

            Assert.IsFalse(manager.ConflictAll(2));
        }
예제 #5
0
        private void DrawRectRed_Inverse(RectangleRed Rect)
        {
            CmdAddRectangleRed CmdAddRect = new CmdAddRectangleRed();

            CmdAddRect.Unexecute(Rect);
            CmdAddRect.hierarchyID = Rect.HierarchyID;
            Objects.Remove(Rect);
        }
예제 #6
0
        //COMMANDS------------------------------------------------------------------

        private void DrawRectRed(RectangleRed Rect)
        {
            CmdAddRectangleRed CmdAddRect = new CmdAddRectangleRed();

            CmdAddRect.Execute(Rect);
            CmdAddRect.hierarchyID = Rect.HierarchyID;
            Objects.Add(Rect);
        }
예제 #7
0
        public void TestInverseCommand()
        {
            UndoRedoManager    manager            = new UndoRedoManager();
            CmdAddRectangleRed cmdAddRectangleRed = new CmdAddRectangleRed();
            UndoRedoWrapper    wrapperRed         = new UndoRedoWrapper(cmdAddRectangleRed);

            UndoRedoWrapper ret = manager.Inverse(wrapperRed);

            Assert.IsTrue(ret.IsInverse);
        }
예제 #8
0
        public void TestGetCommandOk()
        {
            UndoRedoManager manager = new UndoRedoManager();

            CmdAddRectangleRed cmdAddRectangleRed = new CmdAddRectangleRed();

            Guid userId = Guid.NewGuid();

            cmdAddRectangleRed.username = userId;

            manager.SaveCommand(cmdAddRectangleRed, false, false);

            Assert.AreEqual(0, manager.GetCommand(userId));
        }
예제 #9
0
        public void TestGetCommandError()
        {
            UndoRedoManager manager = new UndoRedoManager();

            CmdAddRectangleRed cmdAddRectangleRed = new CmdAddRectangleRed();

            Guid userId  = Guid.NewGuid();
            Guid userId2 = Guid.NewGuid();

            cmdAddRectangleRed.username = userId;

            manager.SaveCommand(cmdAddRectangleRed, false, false);

            NUnit.Framework.Assert.AreEqual(-1, manager.GetCommand(userId2));
        }
예제 #10
0
        public void TestUnselectOneObject()
        {
            Canvas             canvas     = new Canvas(true);
            Guid               rectObjId  = Guid.NewGuid();
            Rectangle_Object   rectObj    = new RectangleBlue(0, 0, true, false, false, rectObjId, 0, 0, false, false);
            CmdAddRectangleRed cmdAddRect = new CmdAddRectangleRed();

            cmdAddRect.Execute(rectObj);
            Canvas.Objects.Add(rectObj);

            canvas.IsChecked_btnSelectProp   = true;
            canvas.IsChecked_btnRectRedProp  = false;
            canvas.IsChecked_btnRectBlueProp = false;

            canvas.pnlCenter_MouseClickWrapper(200, 10, 1, 0);

            Assert.IsFalse(rectObj.Selected);
        }
예제 #11
0
        public void TestSetCommandElsePart()
        {
            UndoRedoManager     manager             = new UndoRedoManager();
            Guid                userId              = Guid.NewGuid();
            Guid                userId2             = Guid.NewGuid();
            CmdAddRectangleRed  cmdAddRectangleRed  = new CmdAddRectangleRed();
            CmdAddRectangleBlue cmdAddRectangleBlue = new CmdAddRectangleBlue();

            cmdAddRectangleRed.username  = userId2;
            cmdAddRectangleBlue.username = userId;

            manager.SetCommand(new UndoRedoWrapper(cmdAddRectangleBlue));
            manager.SetCommand(new UndoRedoWrapper(cmdAddRectangleBlue));
            manager.Counter = 2;

            UndoRedoWrapper command = new UndoRedoWrapper(cmdAddRectangleRed);

            manager.SetCommand(command);

            Assert.Contains(2, manager.LastCommand.Values);
        }
예제 #12
0
        //----------------------------------------------------------------------------

        private void pnlCenter_MouseClick(object sender, MouseEventArgs e)
        {
            if (this.IsChecked_btnRectRed)
            {
                int x = e.Location.X;
                int y = e.Location.Y;
                Rect_Red                = new RectangleRed(x, y);
                Rect_Red.Username       = Username;
                Rect_Red.HierarchyID[0] = Canvas_ID;
                Rect_Red.HierarchyID[1] = Guid.NewGuid();

                CmdAddRectangleRed CmdAddRect = new CmdAddRectangleRed();
                CmdAddRect.username   = Username;
                CmdAddRect.ID_Command = Guid.NewGuid();
                CmdAddRect.Execute(Rect_Red);
                CmdAddRect.hierarchyID = Rect_Red.HierarchyID;
                CmdAddRect.eventList   = Rect_Red.EventList;

                Command_manager = Manager.SaveCommand(CmdAddRect, CmdAddRect.isUndo, CmdAddRect.isRedo);

                BinaryFormatter bf = new BinaryFormatter();
                using (MemoryStream data = new MemoryStream())
                {
                    bf.Serialize(data, CmdAddRect);
                    ServerStream_priv.Write(data.ToArray(), 0, data.ToArray().Length);
                    ServerStream_priv.Flush();
                }
            }
            else if (this.IsChecked_btnRectBlue)
            {
                int x = e.Location.X;
                int y = e.Location.Y;
                Rect_Blue = new RectangleBlue(x, y);

                CmdAddRectangleBlue CmdAddRect = new CmdAddRectangleBlue();
                Rect_Blue.Username       = Username;
                Rect_Blue.HierarchyID[0] = Canvas_ID;
                Rect_Blue.HierarchyID[1] = Guid.NewGuid();
                CmdAddRect.ID_Command    = Guid.NewGuid();
                CmdAddRect.eventList     = Rect_Blue.EventList;
                CmdAddRect.Execute(Rect_Blue);
                CmdAddRect.hierarchyID = Rect_Blue.HierarchyID;

                Command_manager = Manager.SaveCommand(CmdAddRect, CmdAddRect.isUndo, CmdAddRect.isRedo);

                BinaryFormatter bf = new BinaryFormatter();
                using (MemoryStream data = new MemoryStream())
                {
                    bf.Serialize(data, CmdAddRect);
                    ServerStream_priv.Write(data.ToArray(), 0, data.ToArray().Length);
                    ServerStream_priv.Flush();
                }
            }
            else if (this.IsChecked_btnSelect)
            {
                int x = e.Location.X;
                int y = e.Location.Y;

                if (this.CheckUnselection(x, y, Objects))
                {
                    for (int i = Objects.Count - 1; i >= 0; i--)
                    {
                        if (Objects[i].Name == "Relation")
                        {
                            Point Start = GetNearestPoint(Objects[i].EventList[0], Objects[i].EventList[1].Center());
                            Point End   = GetNearestPoint(Objects[i].EventList[1], Objects[i].EventList[0].Center());

                            bool helper = CheckSelectionLine(x, y, End.X, End.Y, Start.X, Start.Y);

                            if (helper)
                            {
                                SelectRelation((Relation)Objects[i]);
                                break;
                            }
                        }
                        else if (Objects[i].Name == "Label")
                        {
                            bool helper = this.CheckSelection(x, y, Objects[i].X, Objects[i].Y, Objects[i].X + 75, Objects[i].Y + 15);

                            if (helper)
                            {
                                SelectLabelEvent((Objects.Label)Objects[i]);
                                break;
                            }
                        }
                        else
                        {
                            bool helper = this.CheckSelection(x, y, Objects[i].X, Objects[i].Y, Objects[i].X + 150, Objects[i].Y + 70);

                            if (helper)
                            {
                                if (Objects[i].Name == "Rectangle Red")
                                {
                                    SelectRectangleRed((RectangleRed)Objects[i]);
                                    break;
                                }
                                else if (Objects[i].Name == "Rectangle Blue")
                                {
                                    SelectRectangleBlue((RectangleBlue)Objects[i]);
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    for (int i = Objects.Count - 1; i >= 0; i--)
                    {
                        Objects[i].Unselect(pnlCenter);
                        Objects[i].Selected = false;
                        Selected.Clear();
                    }
                }
            }
        }