コード例 #1
0
ファイル: Function.g.cs プロジェクト: tkahng/BuildingBlocks
        public async Task <PlanByProgramOutputs> Handler(PlanByProgramInputs args, ILambdaContext context)
        {
            if (this.store == null)
            {
                // Preload the dependencies (if they exist),
                // so that they are available during model deserialization.
                var asmLocation = this.GetType().Assembly.Location;
                var asmDir      = Path.GetDirectoryName(asmLocation);
                var asmName     = Path.GetFileNameWithoutExtension(asmLocation);
                var depPath     = Path.Combine(asmDir, $"{asmName}.Dependencies.dll");

                if (File.Exists(depPath))
                {
                    Console.WriteLine($"Loading dependencies from assembly: {depPath}...");
                    Assembly.LoadFrom(depPath);
                    Console.WriteLine("Dependencies assembly loaded.");
                }

                this.store = new S3ModelStore <PlanByProgramInputs>(RegionEndpoint.USWest1);
            }

            var l      = new InvocationWrapper <PlanByProgramInputs, PlanByProgramOutputs>(store, PlanByProgram.Execute);
            var output = await l.InvokeAsync(args);

            return(output);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="roomDefs"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        private static List <Suite> SuiteMaker(PlanByProgramInputs inputs,
                                               List <RoomDefinition> roomDefs,
                                               double ratio = 0.5)
        {
            var suiteIDs = new List <SuiteID>();

            foreach (var roomDef in roomDefs)
            {
                suiteIDs.Add(new SuiteID {
                    name = roomDef.SuiteName, number = roomDef.SuiteNumber
                });
            }
            suiteIDs = suiteIDs.Distinct().ToList();
            var suites = new List <Suite>();
            int index  = 0;

            foreach (var suiteID in suiteIDs)
            {
                var rooms      = new List <RoomKit.Room>();
                var suiteRooms = roomDefs.FindAll(d => d.SuiteName == suiteID.name && d.SuiteNumber == suiteID.number);
                var i          = 0;
                var colors     = Palette.ColorList();
                foreach (var rmDef in suiteRooms)
                {
                    for (var j = 0; j < rmDef.RoomQuantity; j++)
                    {
                        rooms.Add(new RoomKit.Room(rmDef.RoomArea, rmDef.RoomDimensionRatio, 1.0)
                        {
                            Color       = colors[i % colors.Count],
                            DesignArea  = rmDef.RoomArea,
                            DesignRatio = rmDef.RoomDimensionRatio,
                            Department  = rmDef.RoomDepartment,
                            Elevation   = 0.0,
                            Height      = rmDef.RoomHeight,
                            Name        = rmDef.Name,
                            Suite       = rmDef.SuiteName,
                            SuiteID     = rmDef.SuiteNumber
                        });
                    }
                    i++;
                }
                Suite.SuitePlan plan = Suite.SuitePlan.Reciprocal;
                if (inputs.SuitePlanType == SuitePlanType.Axis)
                {
                    plan = Suite.SuitePlan.Axis;
                }
                suites.Add(new Suite(suiteID.name, suiteID.number, rooms, ratio, inputs.CorridorWidth, plan));
                index++;
            }
            return(suites);
        }
コード例 #3
0
        /// <summary>
        /// The PlanByProgram function.
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A PlanByProgramOutputs instance containing computed results and the model with any new elements.</returns>
        public static PlanByProgramOutputs Execute(Dictionary <string, Model> inputModels, PlanByProgramInputs input)
        {
            var rmDefModel = inputModels["Program"];
            var rmDefs     = new List <RoomDefinition>(rmDefModel.AllElementsOfType <RoomDefinition>().ToList());

            if (rmDefs.Count == 0)
            {
                throw new ArgumentException("No Program found.");
            }
            var suites    = Placer.PlaceSuites(input, rmDefs);
            var tmpput    = new PlanByProgramOutputs();
            var roomCount = 0;
            var roomArea  = 0.0;

            foreach (var suite in suites)
            {
                roomCount += suite.Rooms.Count;
                foreach (var room in suite.Rooms)
                {
                    var extrude = new Elements.Geometry.Solids.Extrude(new Profile(room.Perimeter),
                                                                       room.Height,
                                                                       Vector3.ZAxis,
                                                                       false);
                    var geomRep = new Representation(new List <Elements.Geometry.Solids.SolidOperation>()
                    {
                        extrude
                    });
                    tmpput.Model.AddElement(new Elements.Room(room.Perimeter,
                                                              Vector3.ZAxis,
                                                              room.Suite,
                                                              room.SuiteID,
                                                              room.Department,
                                                              room.Number,
                                                              room.DesignArea,
                                                              room.DesignRatio,
                                                              0.0,
                                                              room.Elevation,
                                                              room.Height,
                                                              room.Area,
                                                              new Transform(),
                                                              room.ColorAsMaterial,
                                                              geomRep,
                                                              false,
                                                              Guid.NewGuid(),
                                                              room.Name));
                    roomArea += room.Area;
                }
            }
            var suitesByElevation = suites.GroupBy(s => s.Elevation);
            var totalArea         = 0.0;

            foreach (var group in suitesByElevation)
            {
                var elevation   = group.First().Elevation;
                var suiteprints = new List <Polygon>();
                foreach (var suite in group)
                {
                    if (input.ConformFloorsToRooms)
                    {
                        var roomPrints = Shaper.Merge(suite.RoomsAsPolygons);
                        if (roomPrints.Count == 0)
                        {
                            suiteprints.Add(suite.CompassCorridor.Box.Offset(input.CorridorWidth).First());
                        }
                        foreach (var roomPrint in roomPrints)
                        {
                            suiteprints.Add(roomPrint.Offset(input.CorridorWidth).First());
                        }
                    }
                    else
                    {
                        suiteprints.Add(suite.CompassCorridor.Box.Offset(input.CorridorWidth).First());
                    }
                }
                suiteprints = Shaper.Merge(suiteprints);
                foreach (var footprint in suiteprints)
                {
                    tmpput.Model.AddElement(new Floor(footprint, 0.1, new Transform(0.0, 0.0, elevation - 0.1),
                                                      BuiltInMaterials.Concrete, null, false, Guid.NewGuid(), ""));
                    tmpput.Model.AddElement(new Level(elevation, Guid.NewGuid(), elevation.ToString()));
                    totalArea += footprint.Area();
                }
            }
            var output = new PlanByProgramOutputs(roomCount, roomArea, totalArea - roomArea, totalArea)
            {
                Model = tmpput.Model
            };

            return(output);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inputs"></param>
        /// <param name="roomDefs"></param>
        /// <returns></returns>
        public static List <Suite> PlaceSuites(PlanByProgramInputs inputs, List <RoomDefinition> roomDefs)
        {
            bool northeast = true;
            bool minCoord  = true;
            bool diagonal  = inputs.DiagonalAdjacency;

            if (inputs.PrimaryDirection == PrimaryDirection.Southwest)
            {
                northeast = false;
            }
            if (inputs.CoordinateAdjacency == CoordinateAdjacency.Maximum)
            {
                minCoord = false;
            }
            var suites     = SuiteMaker(inputs, roomDefs, inputs.SuiteRatio);
            var footPrints = new List <Polygon>
            {
                suites.First().CompassCorridor.Box
            };
            var anchorSuite = suites.First();
            var elevation   = 0.0;
            var height      = 0.0;

            foreach (var suite in suites.Skip(1))
            {
                var testHeight = suite.Rooms.OrderByDescending(r => r.Height).First().Height;
                if (testHeight > height)
                {
                    height = testHeight;
                }
                var footprint = PlaceAdjacentToSuite(anchorSuite.CompassCorridor.Box,
                                                     suite.CompassCorridor.Box,
                                                     footPrints,
                                                     northeast,
                                                     minCoord,
                                                     diagonal);

                if (footprint == null && inputs.MultipleLevels == true)
                {
                    elevation += height + inputs.PlenumHeight;
                    footPrints.Clear();
                    footprint   = suite.CompassCorridor.Box;
                    anchorSuite = suite;
                }
                if (footprint == null && inputs.MultipleLevels == false)
                {
                    footprint = PlaceAdjacentToFootprint(suite.CompassCorridor.Box, footPrints, diagonal);
                    if (footprint != null)
                    {
                        height = 0.0;
                    }
                }
                if (footprint == null)
                {
                    continue;
                }
                if (!Shaper.NearEqual(suite.CompassCorridor.AspectRatio, footprint.Compass().AspectRatio))
                {
                    suite.Rotate(Vector3.Origin, 90.0);
                }
                suite.MoveFromTo(suite.CompassCorridor.SW, footprint.Compass().SW);
                suite.Elevation = elevation;
                footPrints.Add(suite.CompassCorridor.Box);
                footPrints = Shaper.Merge(footPrints);
            }
            return(suites);
        }