예제 #1
0
파일: Grid.cs 프로젝트: BHoM/RAM_Toolkit
        /***************************************************/
        /**** 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);
        }
예제 #2
0
파일: Snake.cs 프로젝트: SanX91/SimpleSnake
        public void Initialize(IGridSystem gridSystem, IController controller)
        {
            this.gridSystem = gridSystem;

            transform.position = gridSystem.CenterPoint();
            driver             = Instantiate(driverPrefab, transform.position, transform.rotation);
            driver.Initialize(settings, gridSystem.GridCollider, controller);
        }
예제 #3
0
        /// <summary>
        /// Instatiates a single collectible object.
        /// Invokes the "GenerateCollectible" method, after a certain interval, over and over.
        /// </summary>
        /// <param name="gridSystem"></param>
        public void Initialize(IGridSystem gridSystem)
        {
            this.gridSystem = gridSystem;

            collectible = Instantiate(collectible, transform);
            collectible.SetActive(false);

            InvokeRepeating("GenerateCollectible", settings.generateTime, settings.generateTime);
        }
예제 #4
0
 private void Awake()
 {
     system = this;
 }
예제 #5
0
파일: ToBHoM.cs 프로젝트: BHoM/RAM_Toolkit
        /***************************************************/

        public static Grid ToBHoMObject(this IModelGrid ramModelGrid, IGridSystem ramGridSystem, int counter)
        {
            Grid myGrid = new Grid();
            // Get the parameters of Gridsystem
            string gridSystemLabel    = ramGridSystem.strLabel;                    // Set the name of the GridSystem from RAM
            int    gridSystemID       = ramGridSystem.lUID;                        //Set the lUID from RAM
            string gridSystemType     = ramGridSystem.eOrientationType.ToString(); // Set the orientation type
            double gridXoffset        = ramGridSystem.dXOffset.FromInch();         // Set the offset of the GridSystem from 0 along the X axis
            double gridYoffset        = ramGridSystem.dYOffset.FromInch();         // Set the offset of the GridSystem from 0 along the Y axis
            double gridSystemRotation = ramGridSystem.dRotation;                   // Set the rotation angle of the GridSystem
            double gridRotAngle       = 0;

            // Add the properties of the GridSystem as a fragment
            RAMId RAMId = new RAMId();

            RAMId.Id = gridSystemID;
            myGrid.SetAdapterId(RAMId);

            RAMGridData ramGridData = new RAMGridData();

            ramGridData.Label    = gridSystemLabel;
            ramGridData.Type     = gridSystemType;
            ramGridData.XOffset  = gridXoffset;
            ramGridData.YOffset  = gridYoffset;
            ramGridData.Rotation = gridSystemRotation;

            //Get info for each grid line
            int    gridLinelUID        = ramModelGrid.lUID;              //unique ID od of the grid line object
            string gridLineLabel       = ramModelGrid.strLabel;          // label of the gridline
            double gridLineCoord_Angle = ramModelGrid.dCoordinate_Angle; // the grid coordinate or angle
            string gridLineAxis        = ramModelGrid.eAxis.ToString();  // grid line axis , X/Radial Y/Circular

            double dMaxLimit  = ramModelGrid.dMaxLimitValue.FromInch();  // maximum limit specified by the user to which gridline will be drawn from origin
            double dMinLimit  = ramModelGrid.dMinLimitValue.FromInch();  // minimum limit specified by the user to which gridline will be drawn from origin
            double GridLength = 100;                                     //default grid length value

            //Set max and min limit values based on if they are used or if -1 is returned
            if (dMaxLimit != 0)
            {
                GridLength = 0;
            }



            Point gridCoordPoint1 = new Point();
            Point gridCoordPoint2 = new Point();

            if (gridSystemType == "eGridOrthogonal")   // code to place grids in orthogonal X and Y
            {
                //Set Grid start offset from system origin
                double spacing = ramModelGrid.dCoordinate_Angle.FromInch();

                //check the orientation to place grids accordingly
                if (gridLineAxis == "eGridXorRadialAxis")
                {
                    // position of first point
                    gridCoordPoint1.X = gridXoffset + spacing; // at the origin point we add the spacing of the grid
                    gridCoordPoint1.Y = gridYoffset + dMinLimit;
                    gridCoordPoint1.Z = 0;
                    // position of second point
                    gridCoordPoint2.X = gridXoffset + spacing;
                    gridCoordPoint2.Y = gridYoffset + GridLength + dMaxLimit;// add the max limit to the origin point to get full length of gridline
                    gridCoordPoint2.Z = 0;
                }
                else if (gridLineAxis == "eGridYorCircularAxis")
                {
                    // position of first point
                    gridCoordPoint1.X = gridXoffset + dMinLimit; // at the origin point we add the coordinate of the grid
                    gridCoordPoint1.Y = gridYoffset + spacing;
                    gridCoordPoint1.Z = 0;
                    // position of second point
                    gridCoordPoint2.X = gridXoffset + GridLength + dMaxLimit; // add the max limit to the origin point to get full length of gridline
                    gridCoordPoint2.Y = gridYoffset + spacing;
                    gridCoordPoint2.Z = 0;
                }
                // initialize a new line to create the gridline
                Line gridLine = new Line();
                gridLine.Start = gridCoordPoint1;
                gridLine.End   = gridCoordPoint2;

                //Create a new grid object from the drawn line and return it
                myGrid = new Grid {
                    Curve = gridLine, Name = gridLineLabel
                };
            }
            else if (gridSystemType == "eGridRadial")  //code to place grids radially
            {
                gridRotAngle = (Math.PI / 180) * (gridLineCoord_Angle + gridSystemRotation);
                if (gridLineAxis == "eGridXorRadialAxis")
                {
                    // position of first point
                    gridCoordPoint1.X = gridXoffset; // at the origin point we add the coordinate of the grid
                    gridCoordPoint1.Y = gridYoffset;
                    gridCoordPoint1.Z = 0;
                    // position of second point
                    gridCoordPoint2.X = gridXoffset + Math.Cos(gridRotAngle) * (GridLength + dMaxLimit); // add the max limit to the origin point to get full length of gridline
                    gridCoordPoint2.Y = gridYoffset + Math.Sin(gridRotAngle) * (GridLength + dMaxLimit);
                    gridCoordPoint2.Z = 0;

                    // initialize a new line to create the gridline
                    Line gridLine = new Line();
                    gridLine.Start = gridCoordPoint1;
                    gridLine.End   = gridCoordPoint2;

                    //Create a new grid object from the drawn line and return it
                    myGrid = new Grid {
                        Curve = gridLine, Name = gridLineLabel
                    };
                }
                else if (gridLineAxis == "eGridYorCircularAxis")
                {
                    // position of first point
                    gridCoordPoint1.X = gridXoffset; // at the origin point we add the coordinate of the grid
                    gridCoordPoint1.Y = gridYoffset;
                    gridCoordPoint1.Z = 0;

                    // initialize a new line to create the gridline
                    Circle gridLine  = new Circle();
                    Vector cirNormal = new Vector {
                        X = 0, Y = 0, Z = 1
                    };
                    gridLine.Centre = gridCoordPoint1;
                    gridLine.Normal = cirNormal;
                    gridLine.Radius = gridLineCoord_Angle.FromInch();

                    //Create a new grid object from the drawn line and return it
                    myGrid = new Grid {
                        Curve = gridLine, Name = gridLineLabel
                    };
                }
            }

            /// end of Grid toBhomObject method
            return(myGrid);
        }
예제 #6
0
파일: Grid.cs 프로젝트: BHoM/RAM_Toolkit
        /***************************************************/
        /**** 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);
        }