Beispiel #1
0
        public static RoomTemplateGrid2D ToOldRoomTemplate(this RoomTemplate roomTemplate)
        {
            var             doorMode    = roomTemplate.DoorsMode;
            IDoorModeGrid2D oldDoorMode = null;

            if (roomTemplate.RoomTemplateRepeatMode == null)
            {
                throw new NotSupportedException("Null repeat mode is currently not supported");
            }

            if (doorMode is SimpleDoorMode simpleDoorMode)
            {
                oldDoorMode = new SimpleDoorModeGrid2D(simpleDoorMode.DoorLength, simpleDoorMode.CornerDistance);
            }
            else if (doorMode is ManualDoorMode manualDoorMode)
            {
                oldDoorMode = new ManualDoorModeGrid2D(manualDoorMode.DoorPositions.Select(x => new DoorGrid2D(x.From, x.To)).ToList());
            }
            else
            {
                throw new ArgumentOutOfRangeException();
            }

            return(new RoomTemplateGrid2D(roomTemplate.Shape, oldDoorMode, allowedTransformations: roomTemplate.AllowedTransformations, repeatMode: roomTemplate.RoomTemplateRepeatMode, name: roomTemplate.Name));
        }
        /// <summary>
        /// Checks the doors of the room template.
        /// </summary>
        /// <param name="outline"></param>
        /// <param name="doorMode"></param>
        /// <returns></returns>
        public static ActionResult CheckDoors(PolygonGrid2D outline, IDoorModeGrid2D doorMode)
        {
            var result = new ActionResult();

            try
            {
                var doors = doorMode.GetDoors(outline);

                if (doors.Count == 0)
                {
                    if (doorMode is SimpleDoorModeGrid2D)
                    {
                        result.AddError($"The simple door mode is used but there are no valid door positions. Try to decrease door length and/or corner distance.");
                    }
                    else
                    {
                        result.AddError($"The manual door mode is used but no doors were added.");
                    }
                }
            }
            // TODO: this is not optimal - the argument exception might be something different than invalid manual doors
            catch (ArgumentException e)
            {
                if (doorMode is ManualDoorModeGrid2D)
                {
                    result.AddError($"It seems like some of the manual doors are not located on the outline of the room template.");
                }
                else
                {
                    result.AddError(e.Message);
                }
            }

            return(result);
        }
        /// <summary>
        /// Computes configuration space of given two polygons.
        /// </summary>
        /// <param name="polygon"></param>
        /// <param name="doorsMode"></param>
        /// <param name="fixedCenter"></param>
        /// <param name="fixedDoorsMode"></param>
        /// <param name="offsets"></param>
        /// <returns></returns>
        public ConfigurationSpaceGrid2D GetConfigurationSpace(PolygonGrid2D polygon, IDoorModeGrid2D doorsMode, PolygonGrid2D fixedCenter,
                                                              IDoorModeGrid2D fixedDoorsMode, List <int> offsets = null)
        {
            var doorLinesFixed = fixedDoorsMode.GetDoors(fixedCenter);
            var doorLines      = doorsMode.GetDoors(polygon);

            return(GetConfigurationSpace(polygon, doorLines, fixedCenter, doorLinesFixed, offsets));
        }
Beispiel #4
0
 /// <param name="outline">See the <see cref="Outline"/> property.</param>
 /// <param name="doors">See the <see cref="Doors"/> property.</param>
 /// <param name="name">See the <see cref="Name"/> property.</param>
 /// <param name="repeatMode">See the <see cref="RepeatMode"/> property.</param>
 /// <param name="allowedTransformations">See the <see cref="AllowedTransformations"/> property.</param>
 public RoomTemplateGrid2D(PolygonGrid2D outline, IDoorModeGrid2D doors, string name = null, RoomTemplateRepeatMode?repeatMode = null, List <TransformationGrid2D> allowedTransformations = null)
 {
     Outline                = outline;
     Doors                  = doors;
     Name                   = name ?? "Room template";
     RepeatMode             = repeatMode;
     AllowedTransformations = allowedTransformations ?? new List <TransformationGrid2D>()
     {
         TransformationGrid2D.Identity
     };;
 }
        public ConfigurationSpace GetConfigurationSpaceOverCorridor(PolygonGrid2D polygon, IDoorModeGrid2D doorsMode,
                                                                    PolygonGrid2D fixedPolygon, IDoorModeGrid2D fixedDoorsMode, PolygonGrid2D corridor,
                                                                    IDoorModeGrid2D corridorDoorsMode)
        {
            var doorLines         = doorsMode.GetDoors(polygon);
            var doorLinesFixed    = fixedDoorsMode.GetDoors(fixedPolygon);
            var doorLinesCorridor = corridorDoorsMode.GetDoors(corridor);

            return(GetConfigurationSpaceOverCorridor(polygon, doorLines, fixedPolygon, doorLinesFixed, corridor,
                                                     doorLinesCorridor));
        }
Beispiel #6
0
        /// <summary>
        /// Checks the doors of the room template.
        /// </summary>
        /// <param name="outline"></param>
        /// <param name="doorMode"></param>
        /// <param name="selectedDoorMode"></param>
        /// <returns></returns>
        public static ActionResult CheckDoors(PolygonGrid2D outline, IDoorModeGrid2D doorMode, DoorsGrid2D.DoorMode selectedDoorMode)
        {
            var result = new ActionResult();

            try
            {
                var doors = doorMode.GetDoors(outline);

                if (doors.Count == 0)
                {
                    if (selectedDoorMode == DoorsGrid2D.DoorMode.Simple)
                    {
                        result.AddError(
                            $"The simple door mode is used but there are no valid door positions. Try to decrease door length and/or margin.");
                    }
                    else
                    {
                        result.AddError($"The {selectedDoorMode} door mode is used but no doors were added.");
                    }
                }
            }
            catch (DoorLineOutsideOfOutlineException e)
            {
                if (selectedDoorMode == DoorsGrid2D.DoorMode.Manual)
                {
                    result.AddError(
                        $"It seems like some of the manual doors are not located on the outline of the room template.");
                }
                else if (selectedDoorMode == DoorsGrid2D.DoorMode.Hybrid)
                {
                    result.AddError(
                        $"It seems like some of the hybrid door lines are not located on the outline of the room template.");
                }
                else
                {
                    result.AddError(e.Message);
                }
            }
            catch (DuplicateDoorPositionException e)
            {
                if (selectedDoorMode == DoorsGrid2D.DoorMode.Hybrid)
                {
                    result.AddError("There are duplicate/overlapping door lines with the same door length and socket.");
                }
                else
                {
                    result.AddError(e.Message);
                }
            }

            return(result);
        }
Beispiel #7
0
        public static ActionResult CheckWrongManualDoors(PolygonGrid2D outline, IDoorModeGrid2D doorMode, out int differentLengthsCount)
        {
            var result = new ActionResult();

            differentLengthsCount = -1;

            if (doorMode is ManualDoorModeGrid2D)
            {
                var doors            = doorMode.GetDoors(outline);
                var differentLengths = doors.Select(x => x.Length).Distinct().ToList();
                differentLengthsCount = differentLengths.Count;

                if (differentLengthsCount >= 3)
                {
                    result.AddError($"There are {differentLengthsCount} different lengths of manual doors. Please make sure that this is intentional. This is often caused by an incorrect use of the manual door (see the warning in the Doors component).");
                }
            }

            return(result);
        }