Exemplo n.º 1
0
        public async Task <ReceptionLayoutOutputs> Handler(ReceptionLayoutInputs args, ILambdaContext context)
        {
            // Preload dependencies (if they exist),
            // so that they are available during model deserialization.

            var sw          = System.Diagnostics.Stopwatch.StartNew();
            var asmLocation = this.GetType().Assembly.Location;
            var asmDir      = Path.GetDirectoryName(asmLocation);

            // Explicitly load the dependencies project, it might have types
            // that aren't used in the function but are necessary for correct
            // deserialization.
            var asmName = Path.GetFileNameWithoutExtension(asmLocation);
            var depPath = Path.Combine(asmDir, $"{asmName}.Dependencies.dll");

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

            // Load all reference assemblies.
            Console.WriteLine($"Loading all referenced assemblies.");
            foreach (var asm in this.GetType().Assembly.GetReferencedAssemblies())
            {
                try
                {
                    Assembly.Load(asm);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Failed to load {asm.FullName}");
                    Console.WriteLine(e.Message);
                }
            }
            sw.Stop();
            Console.WriteLine($"Time to load assemblies: {sw.Elapsed.TotalSeconds})");

            if (this.store == null)
            {
                this.store = new S3ModelStore <ReceptionLayoutInputs>(RegionEndpoint.USWest1);
            }

            var l      = new InvocationWrapper <ReceptionLayoutInputs, ReceptionLayoutOutputs>(store, ReceptionLayout.Execute);
            var output = await l.InvokeAsync(args);

            return(output);
        }
Exemplo n.º 2
0
        /// <summary>
        /// The ReceptionLayout function.
        /// </summary>
        /// <param name="model">The input model.</param>
        /// <param name="input">The arguments to the execution.</param>
        /// <returns>A ReceptionLayoutOutputs instance containing computed results and the model with any new elements.</returns>
        public static ReceptionLayoutOutputs Execute(Dictionary <string, Model> inputModels, ReceptionLayoutInputs input)
        {
            var         spacePlanningZones = inputModels["Space Planning Zones"];
            var         levelsModel        = inputModels["Levels"];
            var         levels             = spacePlanningZones.AllElementsOfType <LevelElements>();
            var         levelVolumes       = levelsModel.AllElementsOfType <LevelVolume>();
            var         output             = new ReceptionLayoutOutputs();
            var         configJson         = File.ReadAllText("./ReceptionConfigurations.json");
            var         configs            = JsonConvert.DeserializeObject <SpaceConfiguration>(configJson);
            var         hasCore            = inputModels.TryGetValue("Core", out var coresModel);
            List <Line> coreSegments       = new List <Line>();

            if (coresModel != null)
            {
                coreSegments.AddRange(coresModel.AllElementsOfType <ServiceCore>().SelectMany(c => c.Profile.Perimeter.Segments()));
            }
            foreach (var lvl in levels)
            {
                var corridors           = lvl.Elements.OfType <Floor>();
                var corridorSegments    = corridors.SelectMany(p => p.Profile.Segments());
                var meetingRmBoundaries = lvl.Elements.OfType <SpaceBoundary>().Where(z => z.Name == "Reception");
                var levelVolume         = levelVolumes.First(l => l.Name == lvl.Name);
                foreach (var room in meetingRmBoundaries)
                {
                    var  spaceBoundary        = room.Boundary;
                    Line orientationGuideEdge = hasCore ? FindEdgeClosestToCore(spaceBoundary.Perimeter, coreSegments) : FindEdgeAdjacentToSegments(spaceBoundary.Perimeter.Segments(), corridorSegments, out var wallCandidates);
                    var  orientationTransform = new Transform(Vector3.Origin, orientationGuideEdge.Direction(), Vector3.ZAxis);
                    var  boundaryCurves       = new List <Polygon>();
                    boundaryCurves.Add(spaceBoundary.Perimeter);
                    boundaryCurves.AddRange(spaceBoundary.Voids ?? new List <Polygon>());

                    var grid = new Grid2d(boundaryCurves, orientationTransform);
                    foreach (var cell in grid.GetCells())
                    {
                        var rect       = cell.GetCellGeometry() as Polygon;
                        var segs       = rect.Segments();
                        var width      = segs[0].Length();
                        var depth      = segs[1].Length();
                        var trimmedGeo = cell.GetTrimmedCellGeometry();
                        if (!cell.IsTrimmed() && trimmedGeo.Count() > 0)
                        {
                            output.Model.AddElement(InstantiateLayout(configs, width, depth, rect, room.Transform));
                        }
                        else if (trimmedGeo.Count() > 0)
                        {
                            var largestTrimmedShape = trimmedGeo.OfType <Polygon>().OrderBy(s => s.Area()).Last();
                            var cinchedVertices     = rect.Vertices.Select(v => largestTrimmedShape.Vertices.OrderBy(v2 => v2.DistanceTo(v)).First()).ToList();
                            var cinchedPoly         = new Polygon(cinchedVertices);
                            // output.Model.AddElement(new ModelCurve(cinchedPoly, BuiltInMaterials.ZAxis, levelVolume.Transform));
                            output.Model.AddElement(InstantiateLayout(configs, width, depth, cinchedPoly, room.Transform));
                            Console.WriteLine("­ЪциРђЇРЎѓ№ИЈ funny shape!!!");
                        }
                    }
                }
            }
            InstancePositionOverrides(input.Overrides, output.Model);
            return(output);
        }