示例#1
0
        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);
        }