示例#1
0
        /// <summary>
        /// Updates the visualisation of the building according to a persons step in the simulation.
        /// </summary>
        /// <param name="person"></param>
        private void UpdateVisualsOnEvacuatableMoved(Person person)
        {
            if (FirstTime)
            {
                foreach (Grid grid in _floorContainer)
                {
                    foreach (Rectangle rect in grid.Children.Cast <Rectangle>())
                    {
                        BuildingBlock current = LocalFloorPlan.Tiles[rect.Tag.ToString()] as BuildingBlock;
                        rect.ToolTip = current?.Priority + " ," + current?.Room;
                    }
                }
                FirstTime = false;
            }
            BuildingBlock prev = person.PathList[person.StepsTaken - 1];
            BuildingBlock next = person.PathList[person.StepsTaken];
            Rectangle     prevRectangleToColorize;

            AllRectangles.TryGetValue(Coordinate(prev), out prevRectangleToColorize);
            if (prev.OriginalType == Tile.Types.Person)
            {
                prev.Type = Tile.Types.Free;
                if (_mainWindow.TheUserInterface.HeatMapActivated)
                {
                    ColorRectangle(prevRectangleToColorize, CalculateHeatMapColor(prev));
                }
                else
                {
                    ColorizeBuildingBlock(prevRectangleToColorize, Tile.Types.Free);
                }
            }
            else
            {
                prev.Type = prev.OriginalType;
                if (_mainWindow.TheUserInterface.HeatMapActivated)
                {
                    ColorRectangle(prevRectangleToColorize, CalculateHeatMapColor(prev));
                }
                else
                {
                    ColorizeBuildingBlock(prevRectangleToColorize, prev.OriginalType);
                }
            }
            Rectangle nextRectangleToColorize;

            AllRectangles.TryGetValue(Coordinate(next), out nextRectangleToColorize);
            if (next.OriginalType == Tile.Types.Exit || next.OriginalType == Tile.Types.Stair)
            {
                next.Type = next.OriginalType;
                ColorizeBuildingBlock(nextRectangleToColorize, next.OriginalType);
            }
            else
            {
                next.Type = Tile.Types.Person;
                ColorizeBuildingBlock(nextRectangleToColorize, next.Type);
            }
        }
示例#2
0
        private void CreateVisualRepresentation()
        {
            int width       = LocalFloorPlan.Width;
            int height      = LocalFloorPlan.Height;
            int floorAmount = LocalFloorPlan.FloorAmount;

            _floorContainer = new Grid[floorAmount];

            for (int z = 0; z < floorAmount; z++)
            {
                Grid container = new Grid()
                {
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Top
                };
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        Rectangle figure = new Rectangle
                        {
                            Height = TileSize,
                            Width  = TileSize,
                            Fill   = new SolidColorBrush(Colors.White),
                            Tag    = Coordinate(x, y, z), /* Makes binding rectangles to buildingblocks easier */
                            Margin = new Thickness(0, 0, x * TileSize * 2 + x, y * TileSize * 2 + y)
                        };

                        if (LocalFloorPlan.Tiles[Coordinate(x, y, z)].Type != Tile.Types.Free)
                        {
                            ColorizeBuildingBlock(figure, LocalFloorPlan.Tiles[Coordinate(x, y, z)].Type);
                        }

                        BuildingBlock current = (LocalFloorPlan.Tiles[Coordinate(x, y, z)] as BuildingBlock);
                        current.Figure              = figure;
                        figure.ToolTip              = current.ToString();
                        figure.MouseLeftButtonDown += OnBuildingBlockClick;


                        AllRectangles.Add(Coordinate(x, y, z), figure);
                        container.Children.Add(figure);
                    }
                }
                _floorContainer[z] = container;
            }

            VisualContainer.Children.Add(_floorContainer[0]);
        }
        /// <summary>
        /// Constructs the view model from the loaded rectangles
        /// </summary>
        /// <param name="rects">The rectangles</param>
        public AllRectanglesViewModel(IEnumerable <RectangleViewModel> rects)
        {
            eventAggregator = ServiceLocator.Current.GetInstance <IEventAggregator>();
            eventAggregator.GetEvent <UnloadImagesEvent>().Subscribe(imagePathsPayload =>
            {
                foreach (var imgPath in imagePathsPayload.ImagePaths)
                {
                    var found = AllRectangles.Where(rect => rect.Rectangle.Image != null && rect.Rectangle.Image.ImagePath == imgPath).FirstOrDefault();
                    if (found != null)
                    {
                        AllRectangles.Remove(found);
                    }
                }

                Rectangles = AllRectangles.Select(x => x.Rectangle);
            });

            AllRectangles = new ObservableCollection <RectangleViewModel>(rects);
            Rectangles    = rects.Select(x => x.Rectangle);
        }
示例#4
0
        public Rectangle PutNextRectangle(Size rectangleSize)
        {
            if (rectangleSize.Width <= 0 || rectangleSize.Height <= 0)
            {
                throw new ArgumentException("Size must be positive");
            }

            Rectangle currRect;

            CloudSpiral = new Spiral(0.5, Center).GetEnumerator();
            for (;;)
            {
                currRect = new Rectangle(GetPossiblePointForRectCenter(rectangleSize), rectangleSize);
                if (!AllRectangles.Any(rect => rect.IntersectsWith(currRect)))
                {
                    break;
                }
            }
            AllRectangles.Add(currRect);
            return(currRect);
        }