Example #1
0
        /***************************************************/
        /**** Private methods                           ****/
        /***************************************************/

        private List <Grid> ReadGrid(List <string> ids = null)
        {
            //Implement code for reading Grids
            List <Grid> bhomGrids = new List <Grid>();

            // Get the gridsystems that are in the model
            IGridSystems IGridSystems   = m_Model.GetGridSystems();
            int          numGridSystems = IGridSystems.GetCount();

            // Get all elements on each GridSystem
            for (int i = 0; i < numGridSystems; i++)
            {
                //Look into a specific gridsystem
                IGridSystem myGridSystem = IGridSystems.GetAt(i);

                //get the amoount of gridlines that are in the system
                IModelGrids IModelGrids = myGridSystem.GetGrids();

                int numGridLines = IModelGrids.GetCount();

                // Loop through all gridlines in the GridSystem and add a bhomGrid
                for (int j = 0; j < numGridLines; j++)
                {
                    IModelGrid IModelGrid = IModelGrids.GetAt(j);
                    Grid       bhomGrid   = IModelGrid.ToBHoMObject(myGridSystem, j);
                    bhomGrids.Add(bhomGrid);
                }
            }

            return(bhomGrids);
        }
Example #2
0
        /***************************************************/
        /**** Private methods                           ****/
        /***************************************************/

        private bool CreateCollection(IEnumerable <Grid> bhomGrid)
        {
            // Register GridSystems
            IGridSystems ramGridSystems = m_Model.GetGridSystems();

            // Register FloorTypes
            IFloorTypes ramFloorTypes = m_Model.GetFloorTypes();

            // initializa a BhoM grid
            List <Grid> Grids = bhomGrid.ToList();

            //Split grids by gridtypes
            List <Grid> XGrids    = new List <Grid>();
            List <Grid> YGrids    = new List <Grid>();
            List <Grid> skewGrids = new List <Grid>();
            List <Grid> circGrids = new List <Grid>();
            Grid        grid      = new Grid();
            Polyline    gridLine  = new Polyline();

            //create different names for the gridSystem based on if there are items in the list
            double      gridSystemRotation = 0;
            string      gridSystemLabel    = "";
            IGridSystem ramGridSystemXY    = null;
            //IGridSystem ramGridSystemRad = null;
            //IGridSystem ramGridSystemSk = null;
            IModelGrids ramModelGridsXY = null;

            //IModelGrids ramModelGridsRad = null;
            //IModelGrids ramModelGridsSk = null;


            //Loop through the BHoM grids and sort per type (x,y,radial, circular, skewed)
            for (int i = 0; i < Grids.Count(); i++)
            {
                grid = Grids[i];

                if (grid.Curve is Circle)
                {
                    circGrids.Add(grid);
                }
                else
                {
                    gridLine = Engine.Geometry.Modify.CollapseToPolyline(grid.Curve as dynamic, 10);
                    //add lines to corresponding lists (XGrids, YGrids) based on their  orientation
                    if (Math.Abs(gridLine.StartPoint().X - gridLine.EndPoint().X) < 0.1)
                    {
                        YGrids.Add(grid);
                    }
                    else if (Math.Abs(gridLine.StartPoint().Y - gridLine.EndPoint().Y) < 0.1)
                    {
                        XGrids.Add(grid);
                    }
                    else
                    {
                        skewGrids.Add(grid);
                    }
                }
            }


            //Create grid systems per grid lists

            //XYGrids
            if (YGrids.Count() != 0 || XGrids.Count() != 0)
            {
                gridSystemLabel = "XY_grid";
                ramGridSystemXY = ramGridSystems.Add(gridSystemLabel);
                ramGridSystemXY.eOrientationType = SGridSysType.eGridOrthogonal;
                ramGridSystemXY.dRotation        = gridSystemRotation;
                ramModelGridsXY = ramGridSystemXY.GetGrids();
            }


            // NOTE: Radial and Skewed Not Yet Implemented but code framework is below

            ////Radial Circular Grid
            //if (circGrids.Count() != 0)
            //{
            //    gridSystemLabel = "Radial_grid";
            //    ramGridSystemRad = ramGridSystems.Add(gridSystemLabel);
            //    ramGridSystemRad.dXOffset = gridOffsetX;
            //    ramGridSystemRad.dYOffset = gridOffsetY;
            //    ramGridSystemRad.eOrientationType = SGridSysType.eGridRadial;
            //    ramGridSystemRad.dRotation = gridSystemRotation;
            //    ramModelGridsRad = ramGridSystemRad.GetGrids();
            //}
            //// Skewed grid
            //if (skewGrids.Count() != 0) {
            //    gridSystemLabel = "Skew_gird";
            //    ramGridSystemSk = ramGridSystems.Add(gridSystemLabel);
            //    ramGridSystemSk.dXOffset = 0;
            //    ramGridSystemSk.dYOffset = 0;
            //    ramGridSystemSk.eOrientationType = SGridSysType.eGridSkewed;
            //    ramGridSystemSk.dRotation = gridSystemRotation;
            //    ramModelGridsSk = ramGridSystemSk.GetGrids();

            //}


            //  Get Grid System Offset
            double minY = XGrids[0].Curve.IStartPoint().Y.ToInch();
            double minX = YGrids[0].Curve.IStartPoint().X.ToInch();

            foreach (Grid XGrid in XGrids)
            {
                double gridY = XGrid.Curve.IStartPoint().Y.ToInch();
                if (gridY < minY)
                {
                    minY = gridY;
                }
            }

            foreach (Grid YGrid in YGrids)
            {
                double gridX = YGrid.Curve.IStartPoint().X.ToInch();
                if (gridX < minX)
                {
                    minX = gridX;
                }
            }
            ramGridSystemXY.dXOffset = minX;
            ramGridSystemXY.dYOffset = minY;


            // Create Grids in GridSystem
            foreach (Grid XGrid in XGrids)
            {
                gridLine = Engine.Geometry.Modify.CollapseToPolyline(XGrid.Curve as dynamic, 10);
                ramModelGridsXY.Add(XGrid.Name, EGridAxis.eGridYorCircularAxis, gridLine.StartPoint().Y.ToInch() - minY);
            }

            foreach (Grid YGrid in YGrids)
            {
                gridLine = Engine.Geometry.Modify.CollapseToPolyline(YGrid.Curve as dynamic, 10);
                ramModelGridsXY.Add(YGrid.Name, EGridAxis.eGridXorRadialAxis, gridLine.StartPoint().X.ToInch() - minX);
            }

            foreach (Grid cGrid in circGrids)
            {
                // TODO: add code to implement circular grids
                // Create GridSystem in RAM for each unique centerpt of circGrids
            }

            foreach (Grid skGrid in skewGrids)
            {
                // TODO: add code to implement skewed grids
                // Create GridSystem in RAM for each unique angle of skewGrids
            }

            //get the ID of the gridsystem
            int gridSystemID = ramGridSystemXY.lUID;

            //Cycle through floortypes, access the existing floortype/story, place grids on those stories
            for (int i = 0; i < ramFloorTypes.GetCount(); i++)
            {
                IFloorType ramFloorType = ramFloorTypes.GetAt(i);
                DAArray    gsID         = ramFloorType.GetGridSystemIDArray();
                gsID.Add(ramGridSystemXY.lUID, 0);
                ramFloorType.SetGridSystemIDArray(gsID);
            }

            //Save file
            m_IDBIO.SaveDatabase();

            return(true);
        }