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

Pull loads and general load fixes #346

Merged
merged 19 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
24 changes: 24 additions & 0 deletions Robot_Adapter/CRUD/Create/Elements/Panels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
using BHEG = BH.Engine.Geometry;
using BH.oM.Structure.Constraints;
using BH.Engine.Robot;
using BH.Engine.Spatial;
using BH.Engine.Geometry;
using System;

namespace BH.Adapter.Robot
{
Expand Down Expand Up @@ -63,6 +66,27 @@ private bool CreateCollection(IEnumerable<Panel> panels)
robotPanel.SetLabel(IRobotLabelType.I_LT_PANEL_THICKNESS, panel.Property.Name);

RobotSelection rPanelOpenings = m_RobotApplication.Project.Structure.Selections.Create(IRobotObjectType.I_OT_OBJECT);

Vector bhNormal = panel.Normal();

//Tolerance is lower than any geometry tolerance used in the BHoM, hence defined here
double tolerance = 1e-16;
if (Math.Abs(bhNormal.Z) > tolerance)
{
if (bhNormal.Z < 0)
robotPanel.Main.Attribs.DirZ = 1;
}
else if (Math.Abs(bhNormal.X) > tolerance)
{
if (bhNormal.X < 0)
robotPanel.Main.Attribs.DirZ = 1;
}
else
{
if (bhNormal.Y < 0)
robotPanel.Main.Attribs.DirZ = 1;
}

foreach (Opening opening in panel.Openings)
{
List<Edge> openingSubEdges = new List<Edge>();
Expand Down
52 changes: 43 additions & 9 deletions Robot_Adapter/CRUD/Read/Elements/Panels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using BH.oM.Structure.Elements;
Expand All @@ -29,6 +30,8 @@
using BH.oM.Geometry;
using System.Collections;
using BH.oM.Structure.MaterialFragments;
using BH.Engine.Spatial;
using BH.Engine.Geometry;

namespace BH.Adapter.Robot
{
Expand Down Expand Up @@ -104,18 +107,37 @@ private List<Panel> ReadPanels(IList ids = null)
BH.oM.Geometry.Point coordPoint = BH.Engine.Geometry.Query.StartPoint(outline as dynamic);

double x, y, z; robotPanel.Main.Attribs.GetDirX(out x, out y, out z);
BH.oM.Geometry.Vector coordXAxis = BH.Engine.Geometry.Create.Vector(x, y, z);
BH.oM.Geometry.Vector coordZAxis = BH.Engine.Geometry.Compute.FitPlane(outline as dynamic).Normal;
if (coordZAxis.Z == 0)
Vector coordXAxis = BH.Engine.Geometry.Create.Vector(x, y, z);
Vector coordZAxis = panel.Normal();


bool flip = robotPanel.Main.Attribs.DirZ == 1;
double tolerance = 1e-16;

if (Math.Abs(coordZAxis.Z) > tolerance)
{
if ((coordZAxis.X > coordZAxis.Y && coordZAxis.X < 1) || (coordZAxis.Y > coordZAxis.X && coordZAxis.Y < 1))
coordZAxis = BH.Engine.Geometry.Modify.Reverse(coordZAxis);
if (coordZAxis.Z < 0)
flip = !flip;
}
else if (Math.Abs(coordZAxis.X) > tolerance)
{
if (coordZAxis.X < 0)
flip = !flip;
}
else
{
if (coordZAxis.Y < 0)
flip = !flip;
}
if (robotPanel.Main.Attribs.DirZ == 0)
coordZAxis = BH.Engine.Geometry.Modify.Reverse(coordZAxis);

BH.oM.Geometry.CoordinateSystem.Cartesian tempCoordSys = BH.Engine.Geometry.Create.CartesianCoordinateSystem(coordPoint, coordXAxis, coordZAxis);
BH.oM.Geometry.CoordinateSystem.Cartesian coordinateSystem = BH.Engine.Geometry.Create.CartesianCoordinateSystem(coordPoint, coordXAxis, tempCoordSys.Z);
if (flip)
{
coordZAxis = coordZAxis.Reverse();
FlipOutline(panel);
}

Vector coordYAxis = coordZAxis.CrossProduct(coordXAxis);
BH.oM.Geometry.CoordinateSystem.Cartesian coordinateSystem = BH.Engine.Geometry.Create.CartesianCoordinateSystem(coordPoint, coordXAxis, coordYAxis);

panel.CustomData["CoordinateSystem"] = coordinateSystem;
if (robotPanel.HasLabel(IRobotLabelType.I_LT_PANEL_THICKNESS) != 0)
Expand Down Expand Up @@ -180,6 +202,18 @@ private List<Panel> ReadPanels(IList ids = null)

/***************************************************/

//Method put here temporary until available in Spatial_Engine
private void FlipOutline(Panel panel)
{
foreach (Edge e in panel.ExternalEdges)
{
e.Curve = e.Curve.IFlip();
}
panel.ExternalEdges.Reverse();
}

/***************************************************/

//Method is stripped dpwn to only return data needed for extracting mesh results
private List<Panel> ReadPanelsLight(IList ids = null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2020, the respective contributors. All rights reserved.
*
Expand Down Expand Up @@ -29,6 +29,7 @@
using BH.oM.Base;
using BH.oM.Structure.Loads;
using BH.oM.Adapters.Robot;
using BH.Engine.Robot;


namespace BH.Adapter.Robot
Expand All @@ -39,19 +40,18 @@ public partial class RobotAdapter
/**** Private Methods ****/
/***************************************************/

private List<ILoad> ReadAreaUniformlyDistributedLoad(List<string> ids = null)
private List<ILoad> ReadContourLoads(List<string> ids = null)
{

List<ILoad> bhomLoads = new List<ILoad>();
Dictionary<int, Panel> bhomPanel = ReadPanels().ToDictionary(x => System.Convert.ToInt32(x.CustomData[AdapterIdName]));
Dictionary<string, Loadcase> bhomLoadCases = new Dictionary<string, Loadcase>();
List<Loadcase> lCases = ReadLoadCase();
for (int i = 0; i < lCases.Count; i++)
{
if (!bhomLoadCases.ContainsKey(lCases[i].Name))
if (bhomLoadCases.ContainsKey(lCases[i].Name) == false)
bhomLoadCases.Add(lCases[i].Name, lCases[i]);
}

//Dictionary<string, Loadcase> bhomLoadCases = ReadLoadCase().ToDictionary(x => x.Name);
IRobotCaseCollection loadCollection = m_RobotApplication.Project.Structure.Cases.GetAll();

for (int i = 1; i <= loadCollection.Count; i++)
Expand All @@ -65,33 +65,40 @@ private List<ILoad> ReadAreaUniformlyDistributedLoad(List<string> ids = null)
for (int j = 1; j <= sCase.Records.Count; j++)
{
IRobotLoadRecord loadRecord = sCase.Records.Get(j);
List<int> elementIds = Convert.FromRobotSelectionString(loadRecord.Objects.ToText());
List<Panel> objects = new List<Panel>();
for (int k = 0; k < elementIds.Count; k++)
{
if (bhomPanel.ContainsKey(elementIds[k]))
objects.Add(bhomPanel[elementIds[k]]);
}

switch (loadRecord.Type)
{
case IRobotLoadRecordType.I_LRT_UNIFORM:
double fx = loadRecord.GetValue((short)IRobotUniformRecordValues.I_URV_PX);
double fy = loadRecord.GetValue((short)IRobotUniformRecordValues.I_URV_PY);
double fz = loadRecord.GetValue((short)IRobotUniformRecordValues.I_URV_PZ);
double ls = loadRecord.GetValue((short)IRobotUniformRecordValues.I_URV_LOCAL_SYSTEM);
double pj = loadRecord.GetValue((short)IRobotUniformRecordValues.I_URV_PROJECTED);
case IRobotLoadRecordType.I_LRT_IN_CONTOUR:
double fx = loadRecord.GetValue((short)IRobotInContourRecordValues.I_ICRV_PX1);
double fy = loadRecord.GetValue((short)IRobotInContourRecordValues.I_ICRV_PY1);
double fz = loadRecord.GetValue((short)IRobotInContourRecordValues.I_ICRV_PZ1);
double nbPoints = loadRecord.GetValue((short)IRobotInContourRecordValues.I_ICRV_NPOINTS);
double localAxis = loadRecord.GetValue((short)IRobotInContourRecordValues.I_ICRV_LOCAL);
double projectedLoad = loadRecord.GetValue((short)IRobotInContourRecordValues.I_ICRV_PROJECTION);

RobotLoadRecordInContour contourRecord = loadRecord as RobotLoadRecordInContour;

AreaUniformlyDistributedLoad PanelPressure = new AreaUniformlyDistributedLoad
List<Point> contourPoints = new List<Point>();

for (int k = 0; k < nbPoints; k++)
{
Pressure = new Vector { X = fx, Y = fy, Z = fz },
double x, y, z;

contourRecord.GetContourPoint(k + 1, out x, out y, out z);
contourPoints.Add(new Point { X = x, Y = y, Z = z });
}

contourPoints.Add(contourPoints.First());

oM.Structure.Loads.ContourLoad contourLoad = new oM.Structure.Loads.ContourLoad
{
Force = new Vector { X = fx, Y = fy, Z = fz },
Contour = new Polyline { ControlPoints = contourPoints },
Loadcase = bhomLoadCases[sCase.Name],
Objects = new BHoMGroup<IAreaElement>() { Elements = objects.ToList<IAreaElement>() },
Axis = ls == 0 ? LoadAxis.Global : LoadAxis.Local,
Projected = pj == 1
Axis = localAxis == 1 ? LoadAxis.Local : LoadAxis.Global,
Projected = projectedLoad == 1
};
bhomLoads.Add(PanelPressure);
bhomLoads.Add(contourLoad);
break;
}
}
Expand All @@ -101,6 +108,7 @@ private List<ILoad> ReadAreaUniformlyDistributedLoad(List<string> ids = null)
return bhomLoads;
}


/***************************************************/

}
Expand Down
119 changes: 119 additions & 0 deletions Robot_Adapter/CRUD/Read/Loads/GeometricalLineLoads.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2020, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using BH.oM.Structure.Elements;
using RobotOM;
using BH.oM.Geometry;
using BH.oM.Base;
using BH.oM.Structure.Loads;
using BH.oM.Adapters.Robot;
using BH.Engine.Robot;


namespace BH.Adapter.Robot
{
public partial class RobotAdapter
{
/***************************************************/
/**** Private Methods ****/
/***************************************************/

private List<ILoad> ReadGeometricalLineLoads(List<string> ids = null)
{

List<ILoad> bhomLoads = new List<ILoad>();
Dictionary<string, Loadcase> bhomLoadCases = new Dictionary<string, Loadcase>();
List<Loadcase> lCases = ReadLoadCase();
for (int i = 0; i < lCases.Count; i++)
{
if (bhomLoadCases.ContainsKey(lCases[i].Name) == false)
bhomLoadCases.Add(lCases[i].Name, lCases[i]);
}

IRobotCaseCollection loadCollection = m_RobotApplication.Project.Structure.Cases.GetAll();

for (int i = 1; i <= loadCollection.Count; i++)
{
IRobotCase lCase = loadCollection.Get(i) as IRobotCase;
if (lCase.Type == IRobotCaseType.I_CT_SIMPLE)
{
IRobotSimpleCase sCase = lCase as IRobotSimpleCase;
if (bhomLoadCases.ContainsKey(sCase.Name))
{
for (int j = 1; j <= sCase.Records.Count; j++)
{
IRobotLoadRecord loadRecord = sCase.Records.Get(j);

switch (loadRecord.Type)
{
case IRobotLoadRecordType.I_LRT_LINEAR_3D:
double fxa = loadRecord.GetValue((short)IRobotLinear3DRecordValues.I_L3DRV_PX1);
double fya = loadRecord.GetValue((short)IRobotLinear3DRecordValues.I_L3DRV_PY1);
double fza = loadRecord.GetValue((short)IRobotLinear3DRecordValues.I_L3DRV_PZ1);
double fxb = loadRecord.GetValue((short)IRobotLinear3DRecordValues.I_L3DRV_PX2);
double fyb = loadRecord.GetValue((short)IRobotLinear3DRecordValues.I_L3DRV_PY2);
double fzb = loadRecord.GetValue((short)IRobotLinear3DRecordValues.I_L3DRV_PZ2);

double mxa = loadRecord.GetValue((short)IRobotLinear3DRecordValues.I_L3DRV_MX1);
double mya = loadRecord.GetValue((short)IRobotLinear3DRecordValues.I_L3DRV_MY1);
double mza = loadRecord.GetValue((short)IRobotLinear3DRecordValues.I_L3DRV_MZ1);
double mxb = loadRecord.GetValue((short)IRobotLinear3DRecordValues.I_L3DRV_MX2);
double myb = loadRecord.GetValue((short)IRobotLinear3DRecordValues.I_L3DRV_MY2);
double mzb = loadRecord.GetValue((short)IRobotLinear3DRecordValues.I_L3DRV_MZ2);
double local = loadRecord.GetValue((short)IRobotLinear3DRecordValues.I_L3DRV_LOCAL);

IRobotLoadRecordLinear3D linRecord = loadRecord as IRobotLoadRecordLinear3D;

double xa, ya, za, xb, yb, zb;

linRecord.GetPoint(1, out xa, out ya, out za);
linRecord.GetPoint(2, out xb, out yb, out zb);

oM.Structure.Loads.GeometricalLineLoad contourLoad = new oM.Structure.Loads.GeometricalLineLoad
{
ForceA = new Vector { X = fxa, Y = fya, Z = fza },
ForceB = new Vector { X = fxb, Y = fyb, Z = fzb },
MomentA = new Vector { X = mxa, Y = mya, Z = mza },
MomentB = new Vector { X = mxb, Y = myb, Z = mzb },
Location = new Line { Start = new Point { X = xa, Y = ya, Z = za }, End = new Point { X = xb, Y = yb, Z = zb } },
Axis = local.FromRobotLoadAxis(),
Loadcase = bhomLoadCases[sCase.Name]
};
bhomLoads.Add(contourLoad);
break;
}
}
}
}
}
return bhomLoads;
}


/***************************************************/

}

}
Loading