/***************************************************/ /**** 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); }
/***************************************************/ 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); }