示例#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
        //COMMANDS------------------------------------------------------------------

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

            CmdAddRect.Execute(Rect);
            CmdAddRect.hierarchyID = Rect.HierarchyID;
            Objects.Add(Rect);
        }
示例#4
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);
        }
示例#5
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();
                    }
                }
            }
        }