Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Geometric Unit conversions to comply with SI standard BHoM units #138

Merged
merged 8 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 43 additions & 47 deletions RAM_Adapter/CRUD/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System.Collections.Generic;
using System.Linq;
using BH.oM.Geometry.SettingOut;
using BH.Engine.Units;
using BH.oM.Structure.Elements;
using BH.oM.Structure.SectionProperties;
using BH.oM.Structure.SurfaceProperties;
Expand Down Expand Up @@ -104,8 +105,8 @@ private bool CreateCollection(IEnumerable<Bar> bhomBars)
IFloorType ramFloorType = barStory.GetFloorType();
ILayoutBeams ramBeams = ramFloorType.GetLayoutBeams();

double zStart = bar.StartNode.Position().Z - barStory.dElevation;
double zEnd = bar.EndNode.Position().Z - barStory.dElevation;
double zStart = bar.StartNode.Position().Z.ToInch() - barStory.dElevation;
double zEnd = bar.EndNode.Position().Z.ToInch() - barStory.dElevation;

// Get critical cant values
object isStubCant;
Expand All @@ -121,49 +122,45 @@ private bool CreateCollection(IEnumerable<Bar> bhomBars)

if (isStubCant.Equals("True") || isStubCant.Equals("1")) //Check bool per RAM or GH preferred boolean context
{
Point startPt, endPt;
SCoordinate startPt, endPt;
if (startCant > 0) // Ensure startPt corresponds with support point
{
startPt = bar.EndNode.Position();
endPt = bar.StartNode.Position();
startPt = bar.EndNode.Position().ToRAM();
endPt = bar.StartNode.Position().ToRAM();
}
else
{
startPt = bar.StartNode.Position();
endPt = bar.EndNode.Position();
startPt = bar.StartNode.Position().ToRAM();
endPt = bar.EndNode.Position().ToRAM();
}


double xStart = startPt.X;
double yStart = startPt.Y;
double xEnd = endPt.X;
double yEnd = endPt.Y;

ramBeam = ramBeams.AddStubCantilever(bar.SectionProperty.Material.ToRAM(), xStart, yStart, 0, xEnd, yEnd, 0); // No Z offsets, beams flat on closest story
ramBeam = ramBeams.AddStubCantilever(bar.SectionProperty.Material.ToRAM(), startPt.dXLoc, startPt.dYLoc, 0, endPt.dXLoc, endPt.dYLoc, 0); // No Z offsets, beams flat on closest story
}
else
{
// Get support points
Vector barDir = bar.Tangent(true);
Point startSupPt = BH.Engine.Geometry.Modify.Translate(bar.StartNode.Position(), barDir * startCant);
Point endSupPt = BH.Engine.Geometry.Modify.Translate(bar.EndNode.Position(), -barDir * endCant);
SCoordinate start = startSupPt.ToRAM();
SCoordinate end = endSupPt.ToRAM();

ramBeam = ramBeams.Add(bar.SectionProperty.Material.ToRAM(), startSupPt.X, startSupPt.Y, 0, endSupPt.X, endSupPt.Y, 0); // No Z offsets, beams flat on closest story
ramBeam = ramBeams.Add(bar.SectionProperty.Material.ToRAM(), start.dXLoc, start.dYLoc, 0, end.dXLoc, end.dYLoc, 0); // No Z offsets, beams flat on closest story
if (startSupPt.X < endSupPt.X || (startSupPt.X == endSupPt.X && startSupPt.Y>endSupPt.Y))
{
ramBeam.dStartCantilever = startCant;
ramBeam.dEndCantilever = endCant;
ramBeam.dStartCantilever = startCant.ToInch();
ramBeam.dEndCantilever = endCant.ToInch();
}
else
{
ramBeam.dStartCantilever = endCant;
ramBeam.dEndCantilever = startCant;
ramBeam.dStartCantilever = endCant.ToInch();
ramBeam.dEndCantilever = startCant.ToInch();
}
}

// Add warning to report distance of snapping to level as required for RAM
if (zStart != 0 || zEnd != 0)
{Engine.Reflection.Compute.RecordWarning("Bar " + name + " snapped to level " + barStory.strLabel + ". Bar moved " + Math.Round(zStart,2).ToString() + " at start and " + Math.Round(zEnd,2).ToString() + " at end."); }
{Engine.Reflection.Compute.RecordWarning("Bar " + name + " snapped to level " + barStory.strLabel + ". Bar moved " + Math.Round(zStart,2).ToString() + " inches at start and " + Math.Round(zEnd,2).ToString() + " inches at end."); }

IBeams beamsOnStory = barStory.GetBeams();
IBeam beam = beamsOnStory.Get(ramBeam.lUID);
Expand All @@ -188,12 +185,12 @@ private bool CreateCollection(IEnumerable<Bar> bhomBars)
List<Node> colNodes = new List<Node>() { bar.StartNode, bar.EndNode };
colNodes.Sort((x, y) => x.Position.Z.CompareTo(y.Position.Z));

double xBtm = colNodes[0].Position.X;
double yBtm = colNodes[0].Position.Y;
double zBtm = colNodes[0].Position.Z - barStory.dElevation;
double xTop = colNodes[1].Position.X;
double yTop = colNodes[1].Position.Y;
double zTop = colNodes[1].Position.Z - barStory.dElevation + barStory.dFlrHeight;
double xBtm = colNodes[0].Position.X.ToInch();
double yBtm = colNodes[0].Position.Y.ToInch();
double zBtm = colNodes[0].Position.Z.ToInch() - barStory.dElevation;
double xTop = colNodes[1].Position.X.ToInch();
double yTop = colNodes[1].Position.Y.ToInch();
double zTop = colNodes[1].Position.Z.ToInch() - barStory.dElevation + barStory.dFlrHeight;

IFloorType ramFloorType = barStory.GetFloorType();
ILayoutColumns ramColumns = ramFloorType.GetLayoutColumns();
Expand Down Expand Up @@ -375,7 +372,7 @@ private bool CreateCollection(IEnumerable<Panel> bhomPanels)
{
Point startPt = crv.IStartPoint();
Point endPt = crv.IEndPoint();
ramSlabEdges.Add(startPt.X, startPt.Y, endPt.X, endPt.Y, 0);
ramSlabEdges.Add(startPt.X.ToInch(), startPt.Y.ToInch(), endPt.X.ToInch(), endPt.Y.ToInch(), 0);
}

List<Opening> panelOpenings = panel.Openings;
Expand Down Expand Up @@ -403,7 +400,7 @@ private bool CreateCollection(IEnumerable<Panel> bhomPanels)
{
Point startPt = crv.IStartPoint();
Point endPt = crv.IEndPoint();
ramOpeningEdges.Add(startPt.X, startPt.Y, endPt.X, endPt.Y, 0);
ramOpeningEdges.Add(startPt.X.ToInch(), startPt.Y.ToInch(), endPt.X.ToInch(), endPt.Y.ToInch(), 0);
}
}

Expand Down Expand Up @@ -459,7 +456,7 @@ private bool CreateCollection(IEnumerable<Panel> bhomPanels)

try
{
double thickness = 6; // default thickness
double thickness = 0.2; // default thickness
if (wallPanel.Property is ConstantThickness)
{
ConstantThickness prop = (ConstantThickness)wallPanel.Property;
Expand All @@ -486,13 +483,13 @@ private bool CreateCollection(IEnumerable<Panel> bhomPanels)
{
ramStory = ramStories.GetAt(i);
// If wall crosses level, add wall to ILayoutWalls for that level
if (Math.Round(wallMax.Z, 0) >= ramStory.dElevation && Math.Round(wallMin.Z, 0) < ramStory.dElevation)
if (Math.Round(wallMax.Z.ToInch(), 0) >= ramStory.dElevation && Math.Round(wallMin.Z.ToInch(), 0) < ramStory.dElevation)
{
ramFloorType = ramStory.GetFloorType();

//Get ILayoutWalls of FloorType and add wall
ILayoutWalls ramLayoutWalls = ramFloorType.GetLayoutWalls();
ILayoutWall ramLayoutWall = ramLayoutWalls.Add(EMATERIALTYPES.EWallPropConcreteMat, wallMin.X, wallMin.Y, 0, 0, wallMax.X, wallMax.Y, 0, 0, thickness);
ILayoutWall ramLayoutWall = ramLayoutWalls.Add(EMATERIALTYPES.EWallPropConcreteMat, wallMin.X.ToInch(), wallMin.Y.ToInch(), 0, 0, wallMax.X.ToInch(), wallMax.Y.ToInch(), 0, 0, thickness.ToInch());

//Set lateral
ramLayoutWall.eFramingType = EFRAMETYPE.MemberIsLateral;
Expand Down Expand Up @@ -522,7 +519,7 @@ private bool CreateCollection(IEnumerable<Panel> bhomPanels)

//Add opening to RAM
IRawWallOpenings ramWallOpenings = ramWall.GetRawOpenings();
ramWallOpenings.Add(EDA_MEMBER_LOC.eBottomStart, distX, distZ, openWidth, openHt);
ramWallOpenings.Add(EDA_MEMBER_LOC.eBottomStart, distX.ToInch(), distZ.ToInch(), openWidth.ToInch(), openHt.ToInch());
}
}
}
Expand Down Expand Up @@ -575,6 +572,7 @@ private bool CreateCollection(IEnumerable<Level> bhomLevels)
for (int i = 0; i < sortedBhomLevels.Count(); i++)
{
Level level = sortedBhomLevels.ElementAt(i);
double levelHt = level.Elevation.ToInch();

// Get elevations and skip if level elevation already in RAM
ramStories = m_Model.GetStories();
Expand All @@ -584,28 +582,28 @@ private bool CreateCollection(IEnumerable<Level> bhomLevels)
ramElevs.Add(ramStories.GetAt(j).dElevation);
}

if (ramElevs.Contains(level.Elevation) != true)
if (ramElevs.Contains(levelHt) != true)
{
double height;
// Ground floor ht = 0 for RAM
if (i == 0)
{
height = level.Elevation;
height = levelHt;
}
else
{
Level lastLevel = sortedBhomLevels.ElementAt(i - 1);
height = level.Elevation - lastLevel.Elevation;
height = levelHt - lastLevel.Elevation.ToInch();
}

int newIndex;
if (ramElevs.FindIndex(x => x > level.Elevation) == -1)
if (ramElevs.FindIndex(x => x > levelHt) == -1)
{
newIndex = ramElevs.Count();
}
else
{
newIndex = ramElevs.FindIndex(x => x > level.Elevation);
newIndex = ramElevs.FindIndex(x => x > levelHt);
}

List<string> ramFloorTypeNames = new List<string>();
Expand All @@ -629,26 +627,24 @@ private bool CreateCollection(IEnumerable<Level> bhomLevels)
if (newIndex < ramStories.GetCount())
{
IStory ramStoryAbove = ramStories.GetAt(newIndex);
ramStoryAbove.dFlrHeight = ramStoryAbove.dElevation - level.Elevation;
ramStoryAbove.dFlrHeight = ramStoryAbove.dElevation - levelHt;
}
if (newIndex > 0 && ramStories.GetCount() > 0)
{
IStory ramStoryBelow = ramStories.GetAt(newIndex - 1);
height = level.Elevation - ramStoryBelow.dElevation;
height = levelHt - ramStoryBelow.dElevation;

}

// Insert story at index
ramStories.InsertAt(newIndex, ramFloorType.lUID, level.Name, height);
}

}

//Save file
m_IDBIO.SaveDatabase();

}

return true;

}
Expand Down Expand Up @@ -754,19 +750,19 @@ private bool CreateCollection(IEnumerable<Grid> bhomGrid)


// Get Grid System Offset
double minY = XGrids[0].Curve.IStartPoint().Y;
double minX = YGrids[0].Curve.IStartPoint().X;
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;
double gridY = XGrid.Curve.IStartPoint().Y.ToInch();
if (gridY < minY)
minY = gridY;
}

foreach (Grid YGrid in YGrids)
{
double gridX = YGrid.Curve.IStartPoint().X;
double gridX = YGrid.Curve.IStartPoint().X.ToInch();
if (gridX < minX)
minX = gridX;
}
Expand All @@ -778,13 +774,13 @@ private bool CreateCollection(IEnumerable<Grid> bhomGrid)
foreach (Grid XGrid in XGrids)
{
gridLine = Engine.Geometry.Modify.CollapseToPolyline(XGrid.Curve as dynamic, 10);
ramModelGridsXY.Add(XGrid.Name, EGridAxis.eGridYorCircularAxis, gridLine.StartPoint().Y-minY);
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-minX);
ramModelGridsXY.Add(YGrid.Name, EGridAxis.eGridXorRadialAxis, gridLine.StartPoint().X.ToInch()-minX);
}

foreach (Grid cGrid in circGrids)
Expand Down
1 change: 0 additions & 1 deletion RAM_Adapter/CRUD/Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public partial class RAMAdapter
/***************************************************/
protected override IEnumerable<IBHoMObject> IRead(Type type, IList ids, ActionConfig actionConfig = null)
{

dynamic elems = null;
//Choose what to pull out depending on the type. Also see example methods below for pulling out bars and dependencies
if (type == typeof(Bar))
Expand Down
Loading