public IFloorPlan ImportFloorPlan(string fileName) { BuildingInformationCollection buildingInformation = Import.ImportBuilding(fileName); IFloorPlan temporaryFloorPlan = CreateFloorPlan(buildingInformation); Import.EffectuateFloorPlanSettings(buildingInformation, ref temporaryFloorPlan, ref _allPeople); return(temporaryFloorPlan); }
public override void Subdivide(Prism bounds, ISubdivisionGeometry geometry, INamedDataCollection hierarchicalParameters) { //Sanity checks if (!_floorIndex.HasValue) { throw new InvalidOperationException("Attempted to subdivide BaseFloor, but FloorIndex is not set"); } if (!_floorAltitude.HasValue) { throw new InvalidOperationException("Attempted to subdivide BaseFloor, but FloorAltitude is not set"); } //Calculate some handy values _roomHeight = bounds.Height - _floorThickness - _ceilingThickness; var roomOffsetY = -bounds.Height / 2 + _roomHeight / 2 + _floorThickness; //Find vertical elements which start on this floor var constrainedVerticalElements = ConstrainVerticalElements(this.SearchUp <IBuilding, IBuilding>(a => a, typeof(IBuildingContainer))); //Create a plan for this floor var plan = new Plan.Geometric.GeometricFloorplan(Bounds.Footprint); var overlappingVerticalRooms = InsertOverlappingVerticals( plan, this.SearchUp <IVerticalFeatureContainer, IVerticalFeatureContainer>(a => a, typeof(IBuildingContainer)).Overlapping(FloorIndex, false) ); var verticals = CreateFloorPlan(plan, overlappingVerticalRooms, constrainedVerticalElements).ToArray(); _plan = plan.Freeze(); PlanFrozen(_plan); //Create nodes for all the vertical elements which started on this floor CreateVerticalNodes(verticals); //Create Floor and ceiling (with holes for vertical sections) CreateFloors(bounds, geometry, verticals, HierarchicalParameters.DefaultCeilingMaterial(Random)); CreateCeilings(bounds, geometry, verticals, HierarchicalParameters.DefaultCeilingMaterial(Random)); //Create room scripts CreateRoomNodes(roomOffsetY, _roomHeight, _plan); //Create external facades (subsections of building over this floor facade) var externalFacades = CreateExternalFacades(bounds, _plan); //Create facades for rooms var dist = hierarchicalParameters.ExternalWallThickness(Random); CreateRoomFacades(externalFacades, roomOffsetY, dist, _plan); }
public void ImplementFloorPlan(IFloorPlan floorPlan, Dictionary<int, Person> people) { LocalPeople = people.ToDictionary(k => Coordinate(k.Value.Position), v => v.Value); //Override the local floorplan to correspond to the new floorplan LocalFloorPlan = floorPlan; if (_floorContainer == null) CreateVisualRepresentation(); /* Add controls to switch between floors, if there are more than 1 floor*/ if (LocalFloorPlan.FloorAmount > 1) AddFloorPlanSwitcherControls(LocalFloorPlan.FloorAmount); }
private void OnSuccessfullBuildingLoadUp() { TheFloorPlan = ParentWindow.TheUserInterface.LocalFloorPlan; DescriptionTextBox.Text = string.IsNullOrEmpty(TheFloorPlan.Description) ? string.Empty : TheFloorPlan.Description; for(int currentFloor = 0; currentFloor < TheFloorPlan.FloorAmount; currentFloor++) { ComboBoxItem comboBox = new ComboBoxItem {Content = $"Floor {currentFloor}"}; HeaderComboBox.Items.Add(comboBox); } WidthText.Text = TheFloorPlan.Width/2 + "m"; HeightText.Text = TheFloorPlan.Height/2 + "m"; FloorsText.Text = TheFloorPlan.FloorAmount.ToString(); FileInformationGroup.Visibility = Visibility.Visible; DimensionsGroup.Visibility = Visibility.Visible; }
public void ImplementFloorPlan(IFloorPlan floorPlan, Dictionary <int, Person> people) { LocalPeople = people.ToDictionary(k => Coordinate(k.Value.Position), v => v.Value); //Override the local floorplan to correspond to the new floorplan LocalFloorPlan = floorPlan; if (_floorContainer == null) { CreateVisualRepresentation(); } /* Add controls to switch between floors, if there are more than 1 floor*/ if (LocalFloorPlan.FloorAmount > 1) { AddFloorPlanSwitcherControls(LocalFloorPlan.FloorAmount); } }
public Dictionary <int, Person> PrepareSimulation(IFloorPlan floorPlan) { if (UserInterface.BuildingHasBeenChanged) { TheFloorPlan.Initiate(); //Assign priority, and calculates neighbours, if the building has been changed. foreach (Tile tile in floorPlan.Tiles.Values) { tile.OriginalType = tile.Type; } } //adds all the new persons to the simulation foreach (Tile value in floorPlan.Tiles.Values.Where(t => t.OriginalType == Tile.Types.Person)) { if (AllPeople.Values.All(p => !Equals(p.OriginalPosition, value))) { Person newPerson = new Person(value as BuildingBlock); AllPeople.Add(newPerson.ID, newPerson); } } return(AllPeople); }
private void OnSuccessfullBuildingLoadUp() { TheFloorPlan = ParentWindow.TheUserInterface.LocalFloorPlan; DescriptionTextBox.Text = string.IsNullOrEmpty(TheFloorPlan.Description) ? string.Empty : TheFloorPlan.Description; for (int currentFloor = 0; currentFloor < TheFloorPlan.FloorAmount; currentFloor++) { ComboBoxItem comboBox = new ComboBoxItem { Content = $"Floor {currentFloor}" }; HeaderComboBox.Items.Add(comboBox); } WidthText.Text = TheFloorPlan.Width / 2 + "m"; HeightText.Text = TheFloorPlan.Height / 2 + "m"; FloorsText.Text = TheFloorPlan.FloorAmount.ToString(); FileInformationGroup.Visibility = Visibility.Visible; DimensionsGroup.Visibility = Visibility.Visible; }
public Dictionary<int, Person> PrepareSimulation(IFloorPlan floorPlan) { if (UserInterface.BuildingHasBeenChanged) { TheFloorPlan.Initiate(); //Assign priority, and calculates neighbours, if the building has been changed. foreach (Tile tile in floorPlan.Tiles.Values) { tile.OriginalType = tile.Type; } } //adds all the new persons to the simulation foreach (Tile value in floorPlan.Tiles.Values.Where(t => t.OriginalType == Tile.Types.Person)) { if (AllPeople.Values.All(p => !Equals(p.OriginalPosition, value))) { Person newPerson = new Person(value as BuildingBlock); AllPeople.Add(newPerson.ID, newPerson); } } return AllPeople; }
private void CreateRoomNodes(float yOffset, float height, IFloorPlan plan) { Contract.Requires(plan != null); foreach (var roomPlan in plan.Rooms) { //Check if all assigned options are null and if so substitute in an alternative set var scripts = roomPlan.Scripts; if (roomPlan.Scripts.All(a => a.Value == null)) { scripts = SubstituteNullRoomPlanScripts(roomPlan, plan); } //Create the room (engine chooses which script to take from the options presented) var room = CreateRoomNode(height, roomPlan.InnerFootprint, yOffset, scripts); //If we created a null room try again with another set of scripts if (room == null) { scripts = SubstituteNullRoomScripts(roomPlan, plan); if (scripts != null && scripts.Count > 0) { room = CreateRoomNode(height, roomPlan.InnerFootprint, yOffset, scripts); } } var planned = room as IPlannedRoom; if (planned != null) { //Associate plan with room planned.Plan = roomPlan; //Associate room with plan roomPlan.Node = planned; } } }
public static void ExportBuilding(string filePath, IFloorPlan floorPlan, Dictionary<int, Person> allPeople) { string exportFeedbackMessage = $"Successfully exported the grid to destination: {filePath}"; ExportOutcomes outcome = ExportOutcomes.Succes; try { string xmlPath = Path.GetFileNameWithoutExtension(filePath) + ".xml"; using (XmlWriter writer = XmlWriter.Create(xmlPath)) { writer.WriteStartDocument(); writer.WriteStartElement("BuildingPlan"); writer.WriteStartElement("Settings"); writer.WriteAttributeString("Width", floorPlan.Width.ToString()); writer.WriteAttributeString("Height", floorPlan.Height.ToString()); writer.WriteAttributeString("Floors", floorPlan.FloorAmount.ToString()); writer.WriteAttributeString("Description", floorPlan.Description); writer.WriteEndElement(); writer.WriteStartElement("People"); if (allPeople.Count > 0) { writer.WriteAttributeString("NumberOfPeople", allPeople.Count.ToString()); foreach (Person item in allPeople.Values) { writer.WriteStartElement("Person"); writer.WriteAttributeString("ID", item.ID.ToString()); writer.WriteAttributeString("Position", Coordinate(item.Position)); writer.WriteAttributeString("MovementSpeed", item.MovementSpeed.ToString()); writer.WriteEndElement(); } } writer.WriteEndElement(); writer.WriteStartElement("FloorPlan"); for (int currentFloor = 0; currentFloor < floorPlan.FloorAmount; currentFloor++) { writer.WriteStartElement("Floor"); writer.WriteAttributeString("Level", currentFloor.ToString()); writer.WriteAttributeString("Header", floorPlan.Headers[currentFloor]); StringBuilder rowAttributeBuilder = new StringBuilder(); StringBuilder rowBuilder = new StringBuilder(); for (int currentY = 0; currentY < floorPlan.Height; currentY++) { for (int currentX = 0; currentX < floorPlan.Width; currentX++) { string typeString = ((int)floorPlan.Tiles[Coordinate(currentX, currentY, currentFloor)].Type).ToString(); rowBuilder.Append(typeString); } rowAttributeBuilder.Append(rowBuilder + ", "); rowBuilder.Clear(); } writer.WriteAttributeString("RowInformation", rowAttributeBuilder.ToString().TrimEnd(' ').TrimEnd(',')); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); } File.Copy(xmlPath, filePath); File.Delete(xmlPath); } catch (Exception e) { outcome = ExportOutcomes.Failure; exportFeedbackMessage = $"Error while exporting! \n Error message: {e.Message}\n\nDestination: {filePath}"; } finally { OnExportFeedBack?.Invoke(exportFeedbackMessage, outcome); } }
public static void DrawPlan(IFloorPlan plan) { if (!plan.PlanCreated) plan.CreatePlan(); foreach (IDrawable drawling in plan.PlanDrawlings) Draw(drawling); }
private IReadOnlyList <IConfigurableFacade> CreateExternalFacades(Prism bounds, IFloorPlan plan) { var externalSections = new List <IConfigurableFacade>(); //Find the parent building which contains this floor var building = this.SearchUp <IBuilding, IBuilding>(n => n, typeof(IBuildingContainer)); if (building == null) { throw new InvalidOperationException("Attempted to subdivide BaseFloor, but cannot find IBuilding node ancestor"); } //Get all facades which cross this floor var facades = building.Facades(FloorIndex); for (var i = 0; i < plan.ExternalFootprint.Count; i++) { //Nb. There's lots of "WS" going on here, this stands for "World Space" //We have the footprint in floor space and the facades in facade space, we transform both into world space to compare them //Get start and end points of this edge var start = plan.ExternalFootprint[i]; var end = plan.ExternalFootprint[(i + 1) % plan.ExternalFootprint.Count]; var footprintSegWS = new LineSegment2(start, end).Transform(WorldTransformation); var footprintLineWS = footprintSegWS.Line; //Select the exteral facade which lies along this edge var wall = (from facade in facades let facadeSegWS = facade.Section.ExternalLineSegment.Transform(facade.WorldTransformation) let facadeLineWS = facadeSegWS.Line where facadeLineWS.Parallelism(footprintLineWS) != Parallelism.None let aD = footprintSegWS.DistanceToPoint(facadeSegWS.Start) let bD = footprintSegWS.DistanceToPoint(facadeSegWS.End) orderby aD + bD select facade).FirstOrDefault(); //If we didn't find a parallel external facade then just give up! if (wall == null) { continue; } //Start and end points (X-Axis) are always start and end of facade (i.e. subsection is always full width) //What are the start and end points (Y-Axis) var bottomOfFacade = building.Floor(wall.BottomFloorIndex).FloorAltitude; var y = FloorAltitude - bottomOfFacade - _floorThickness - wall.Bounds.Height / 2; //Height of the open space of the floor (top of floor, to bottom of ceiling) var height = Bounds.Height - _floorThickness - _ceilingThickness; //how wide is the wall? var wallLength = wall.Section.ExternalLineSegment.LongLine.Direction.Length(); var subsection = new SubsectionFacade(wall, new Vector2(-wallLength, y), new Vector2(wallLength, y + height), 0, 1, wall.Section ); externalSections.Add(subsection); } return(externalSections); }
public IFloorPlan ExportFloorPlan(string filePath, IFloorPlan floorPlan, Dictionary <int, Person> allPeople) { Export.ExportBuilding(filePath, floorPlan, allPeople); return(TheFloorPlan); }
/// <summary> /// A room was created but it resulted in a null result, this is a chance to substitute in another set of scripts and try again /// </summary> /// <param name="room"></param> /// <param name="plan"></param> /// <returns>A set of scripts to try to create another room, or null to not attempt again</returns> protected virtual IReadOnlyList <KeyValuePair <float, ScriptReference> > SubstituteNullRoomScripts(IRoomPlan room, IFloorPlan plan) { Contract.Requires(room != null); Contract.Requires(plan != null); return(null); }
public AStar(IFloorPlan floorPlan) { TheFloorPlan = floorPlan; ListOfBuildingBlocks = TheFloorPlan.Tiles.Values.Cast<BuildingBlock>().ToList(); }
internal static void EffectuateFloorPlanSettings(BuildingInformationCollection buildingInformation, ref IFloorPlan floorPlan, ref Dictionary <int, Person> allPeople) { const int freeTypeIntRepresentation = (int)Tile.Types.Free; /* Step 1: Subject the types of each tile to the type of the tile in the BuildingInformationCollection */ for (int z = 0; z < buildingInformation.Floors; z++) { for (int y = 0; y < buildingInformation.Height; y++) { for (int x = 0; x < buildingInformation.Width; x++) { int type = int.Parse(buildingInformation.FloorCollection[z].Rows[y][x].ToString()); /* If the point is already marked as free, continue - no need to force-convert it to free */ if (type == freeTypeIntRepresentation) { continue; } Tile.Types newType = (Tile.Types)type; if (newType == Tile.Types.Person) { PersonInformation personInfo = buildingInformation.PeopleCollection.FirstOrDefault(p => p.Position == Coordinate(x, y, z)); allPeople.Add(personInfo.ID, new Person(personInfo.ID, personInfo.MovementSpeed, floorPlan.Tiles[personInfo.Position] as BuildingBlock)); } floorPlan.Tiles[Coordinate(x, y, z)].Type = newType; } } } }
public IFloorPlan ExportFloorPlan(string filePath, IFloorPlan floorPlan, Dictionary<int, Person> allPeople) { Export.ExportBuilding(filePath, floorPlan, allPeople); return TheFloorPlan; }
public FloorPlanEventArgs(IFloorPlan map) { Map = map; }
/// <summary> /// Called once the plan has been frozen /// </summary> /// <param name="plan"></param> // ReSharper disable once UnusedParameter.Global (Justification: External API) // ReSharper disable once VirtualMemberNeverOverriden.Global (Justification: External API) protected virtual void PlanFrozen(IFloorPlan plan) { }
public AStar(IFloorPlan floorPlan) { TheFloorPlan = floorPlan; ListOfBuildingBlocks = TheFloorPlan.Tiles.Values.Cast <BuildingBlock>().ToList(); }
public static void ExportBuilding(string filePath, IFloorPlan floorPlan, Dictionary <int, Person> allPeople) { string exportFeedbackMessage = $"Successfully exported the grid to destination: {filePath}"; ExportOutcomes outcome = ExportOutcomes.Succes; try { string xmlPath = Path.GetFileNameWithoutExtension(filePath) + ".xml"; using (XmlWriter writer = XmlWriter.Create(xmlPath)) { writer.WriteStartDocument(); writer.WriteStartElement("BuildingPlan"); writer.WriteStartElement("Settings"); writer.WriteAttributeString("Width", floorPlan.Width.ToString()); writer.WriteAttributeString("Height", floorPlan.Height.ToString()); writer.WriteAttributeString("Floors", floorPlan.FloorAmount.ToString()); writer.WriteAttributeString("Description", floorPlan.Description); writer.WriteEndElement(); writer.WriteStartElement("People"); if (allPeople.Count > 0) { writer.WriteAttributeString("NumberOfPeople", allPeople.Count.ToString()); foreach (Person item in allPeople.Values) { writer.WriteStartElement("Person"); writer.WriteAttributeString("ID", item.ID.ToString()); writer.WriteAttributeString("Position", Coordinate(item.Position)); writer.WriteAttributeString("MovementSpeed", item.MovementSpeed.ToString()); writer.WriteEndElement(); } } writer.WriteEndElement(); writer.WriteStartElement("FloorPlan"); for (int currentFloor = 0; currentFloor < floorPlan.FloorAmount; currentFloor++) { writer.WriteStartElement("Floor"); writer.WriteAttributeString("Level", currentFloor.ToString()); writer.WriteAttributeString("Header", floorPlan.Headers[currentFloor]); StringBuilder rowAttributeBuilder = new StringBuilder(); StringBuilder rowBuilder = new StringBuilder(); for (int currentY = 0; currentY < floorPlan.Height; currentY++) { for (int currentX = 0; currentX < floorPlan.Width; currentX++) { string typeString = ((int)floorPlan.Tiles[Coordinate(currentX, currentY, currentFloor)].Type).ToString(); rowBuilder.Append(typeString); } rowAttributeBuilder.Append(rowBuilder + ", "); rowBuilder.Clear(); } writer.WriteAttributeString("RowInformation", rowAttributeBuilder.ToString().TrimEnd(' ').TrimEnd(',')); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); } File.Copy(xmlPath, filePath); File.Delete(xmlPath); } catch (Exception e) { outcome = ExportOutcomes.Failure; exportFeedbackMessage = $"Error while exporting! \n Error message: {e.Message}\n\nDestination: {filePath}"; } finally { OnExportFeedBack?.Invoke(exportFeedbackMessage, outcome); } }
private void CreateRoomFacades(IReadOnlyCollection <IConfigurableFacade> externalFacades, float yOffset, float distance, IFloorPlan plan) { Contract.Requires(externalFacades != null); Contract.Requires(plan != null); //There are two types of facade: // 1. An external wall // - Find the relevant external facade and wrap a subsection of it // 2. An internal wall // - Create an IConfigurableFacade foreach (var roomPlan in plan.Rooms.Where(r => r.Node != null).OrderBy(r => r.Id)) { //Create a place to store all facades generated for this room var generatedFacades = new Dictionary <Facade, IConfigurableFacade>(); foreach (var facade in roomPlan.GetWalls()) { IConfigurableFacade newFacade; if (facade.IsExternal) { //Find the external wall which is co-linear with this facade section var externalSection = FindExternalFacade(distance * 3, externalFacades, facade.Section.ExternalLineSegment); //Create section (or call error handler if no external section was found) newFacade = externalSection == null?FailedToFindExternalSection(roomPlan, facade) : CreateExternalWall(roomPlan, facade, externalSection); } else { newFacade = CreateInternalWall(roomPlan, facade, yOffset); } //Store the newly created facade if (newFacade != null) { generatedFacades.Add(facade, newFacade); } } //Pass the facade to the room if (roomPlan.Node != null) { //Pass the facades to the room roomPlan.Node.Facades = generatedFacades; //Ensure that the room subdivides before the facades foreach (var context in generatedFacades.Values.OfType <ISubdivisionContext>()) { context.AddPrerequisite(roomPlan.Node); } } } }