Inheritance: Wall
Beispiel #1
0
        /**
         * This method returns a copy of the blueprint.
         * This is a Deep Copy, meaning that all the Rooms, Corners in those rooms and Walls connected to those corners will be copied.
         * The purpose of this is to make a new copy to work in when editing a blueprint, while preserving the original.
         */
        public Blueprint Clone()
        {
            Blueprint newBp = new Blueprint(this.Name);

            List<Wall> newWalls = new List<Wall>();
            List<Corner> newCorners = new List<Corner>();

            foreach(Room room in this.Rooms) {
                Room newRoom = new Room(room.Name, room.GetID(), room.GetFloorID(), room.FunctionID);
                newBp.Rooms.Add(newRoom);

                foreach(Corner corner in room.GetCorners()) {
                    Corner newCorner = newCorners.Find( (c) => (c.GetID() == corner.GetID()) );
                    if(newCorner != null) {
                        newRoom.AddCorner(newCorner);
                        continue;
                    }

                    newCorner = new Corner(corner.GetID(), corner.GetPoint());
                    newRoom.AddCorner(newCorner);
                    newCorners.Add(newCorner);

                    foreach(Wall wall in corner.GetWalls()) {
                        Wall newWall = newWalls.Find( (w) => (w.GetID() == wall.GetID()) );
                        if(newWall != null) {
                            if(newWall.Left.GetID() == corner.GetID()) {
                                newWall.Left = newCorner;
                            } else if(newWall.Right.GetID() == corner.GetID()) {
                                newWall.Right = newCorner;
                            }
                            if(newWall.GetType() == typeof(Door)) {
                                ((Door)newWall).Hinge = (((Door)newWall).Hinge.Equals(newWall.Left) ? newWall.Left : newWall.Right);
                            }
                            newCorner.AddWall(newWall);
                            continue;
                        }

                        Corner left = (wall.Left.Equals(newCorner) ? newCorner : wall.Left);
                        Corner right = (wall.Right.Equals(newCorner) ? newCorner : wall.Right);

                        if(wall.GetType() == typeof(Door)) {
                            newWall = new Door(wall.GetID(), left, right, (((Door)wall).Hinge.GetID() == left.GetID() ? left : right), ((Door)wall).Direction);
                        } else {
                            newWall = new Wall(wall.GetID(), left, right);
                        }

                        newWalls.Add(newWall);
                        newCorner.AddWall(newWall);
                    }
                }
                newRoom.IsChanged = room.IsChanged;
            }

            return newBp;
        }
Beispiel #2
0
        public void Constructor()
        {
            //Arrange
            Corner left = new Corner(new PointF(0, 0));
            Corner right = new Corner(new PointF(10, 0));

            //Act
            Door door = new Door(left, right);

            //Assert
            Assert.IsNotNull(door);
            Assert.IsInstanceOf(typeof(Door), door);
            Assert.AreEqual(left, door.Left);
            Assert.AreEqual(right, door.Right);
        }
Beispiel #3
0
        public void DoorAddWall()
        {
            //Arrange
            Corner left = new Corner(new PointF(0, 0));
            Corner right = new Corner(new PointF(10, 0));
            Door door = new Door(left, right);

            //Act
            left.AddWall(door);
            right.AddWall(door);

            //Assert
            IList lWalls = left.GetWalls();
            Assert.AreEqual(1, lWalls.Count);
            Assert.IsInstanceOf<Door>(lWalls[0]);
            Assert.AreEqual(door, lWalls[0]);
        }
Beispiel #4
0
        public void MixedAddWalls()
        {
            //Arrange
            Corner corn1 = new Corner(new PointF(0, 0));
            Corner corn2 = new Corner(new PointF(10, 0));
            Corner corn3 = new Corner(new PointF(10, 10));
            Wall wall = new Wall(corn1, corn2);
            Door door = new Door(corn2, corn3);

            //Act
            corn2.AddWalls(wall, door);

            //Assert
            IList lWalls = corn2.GetWalls();
            Assert.AreEqual(2, lWalls.Count);
            Assert.AreEqual(wall, lWalls[0]);
            Assert.AreEqual(door, lWalls[1]);
        }
Beispiel #5
0
        /**
         * This method will load all corners from the database for local use.
         * TODO: Only load things for a floor, because otherwise this bloody list will be HUGE.
         */
        public void LoadFromDatabase()
        {
            _corners.Clear();
            _cornerIdDict.Clear();

            const string query = "SELECT * FROM `WallCorners`";
            DataTable data = DatabaseHandler.GetInstance().SelectSQL(query);
            if(data != null) {
                foreach(DataRow row in data.Rows) {
                    uint id = DatabaseUtil.parseInt(row, "ID");
                    Corner corner = new Corner(id, row.Field<float>("X"), row.Field<float>("Y"));
                    corner.IsLoaded = true;

                    this._corners.Add(corner);
                    this._cornerIdDict.Add(corner.GetID(), corner);
                }

                DataTable data_conns = DatabaseHandler.GetInstance().SelectSQL("SELECT * FROM `Wall`");
                if(data_conns != null) {
                    foreach(DataRow row_conns in data_conns.Rows) {
                        uint id = DatabaseUtil.parseInt(row_conns, "ID");
                        bool isDoor = row_conns.Field<bool>("IsDoor");
                        uint hinge = (uint)row_conns.Field<byte>("Hinge");
                        uint direction = (uint)row_conns.Field<byte>("Direction");
                        Corner left = this._cornerIdDict[DatabaseUtil.parseInt(row_conns,"LeftPointID")];
                        Corner right = this._cornerIdDict[DatabaseUtil.parseInt(row_conns,"RightPointID")];

                        if(left != null && right != null) {
                            Wall wall;
                            if(isDoor) wall = new Door(id, left, right, (hinge == 0 ? left : right), (direction == 0 ? Door.HingeDirection.Left : Door.HingeDirection.Right));
                            else wall = new Wall(id, left, right);
                            left.AddWall(wall);
                            right.AddWall(wall);

                            wall.IsLoaded = true;
                            this._walls.Add(wall);
                        }
                    }
                }
            }
        }
        /**
         * This event is called when the edit context menu's "Change to door" button is pressed.
         */
        protected void EventContextMenuWallToDoor(object sender, EventArgs e)
        {
            Wall oldWall = this.SelectedWall;
            Door newDoor = new Door(oldWall.GetID(), oldWall.Left, oldWall.Right, oldWall.Left, Door.HingeDirection.Left);
            newDoor.IsLoaded = oldWall.IsLoaded;
            newDoor.IsChanged = true;

            this.ActiveBlueprint.DeleteWall(oldWall);
            oldWall.Left.GetWalls().Add(newDoor);
            oldWall.Right.GetWalls().Add(newDoor);

            this.SelectedWall = newDoor;
            this.Invalidate();
        }