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

Add panel fragments to read #241

Merged
merged 24 commits into from
Jan 9, 2023
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
115 changes: 98 additions & 17 deletions SAP2000_Adapter/CRUD/Create/Panel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
* 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 BH.Engine.Geometry;
using BH.Engine.Spatial;
using BH.oM.Structure.Elements;
using BH.Engine.Base;
using BH.oM.Base;
using BH.oM.Geometry;
using System.Collections.Generic;
using System.Linq;
using System;
using BH.oM.Adapters.SAP2000;
using BH.oM.Adapters.SAP2000.Fragments;
using BH.Engine.Adapter;
using System.Reflection;

Expand All @@ -37,16 +40,13 @@ public partial class SAP2000Adapter
/***************************************************/
/**** Private Methods ****/
/***************************************************/

private bool CreateObject(Panel bhPanel)
{
double mergeTol = 1E-6;

List<Point> boundaryPoints = null;

//Check for dealbreaking BHoM invalidity
try
{
{
boundaryPoints = bhPanel.ControlPoints(true).CullDuplicates(mergeTol);
}
catch
Expand All @@ -56,13 +56,10 @@ private bool CreateObject(Panel bhPanel)
}

int segmentCount = boundaryPoints.Count();

double[] x = boundaryPoints.Select(item => item.X).ToArray();
double[] y = boundaryPoints.Select(item => item.Y).ToArray();
double[] z = boundaryPoints.Select(item => item.Z).ToArray();

string name = "";

// Create Geometry in SAP
if (m_model.AreaObj.AddByCoord(segmentCount, ref x, ref y, ref z, ref name, "None", bhPanel.Name.ToString()) != 0)
{
Expand All @@ -72,26 +69,21 @@ private bool CreateObject(Panel bhPanel)

// Set AdapterID
if (name != bhPanel.Name & bhPanel.Name != "")
Engine.Base.Compute.RecordNote($"Panel {bhPanel.Name} was assigned SAP2000_id of {name}");
Engine.Base.Compute.RecordNote($"Panel {bhPanel.Name} was assigned SAP2000_id of {name}.");

string guid = null;
m_model.AreaObj.GetGUID(name, ref guid);

SAP2000Id sap2000IdFragment = new SAP2000Id { Id = name, PersistentId = guid };
SAP2000Id sap2000IdFragment = new SAP2000Id{Id = name, PersistentId = guid};
bhPanel.SetAdapterId(sap2000IdFragment);

// Set Properties
SetObject(bhPanel);

return true;
}

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

private bool SetObject(Panel bhPanel)
{
string name = GetAdapterId<string>(bhPanel);

if (bhPanel.Property != null)
{
if (m_model.AreaObj.SetProperty(name, GetAdapterId<string>(bhPanel.Property), 0) != 0)
Expand All @@ -111,10 +103,99 @@ private bool SetObject(Panel bhPanel)
}
}

//Set AutoMesh
foreach (IFragment fragment in bhPanel.GetAllFragments())
{
if (SetPanelFragment(fragment as dynamic, name) == false)
{
CreatePropertyError(fragment.GetType().ToString(), "Panel", name);
}
}

return true;
}
}
}

/***************************************************/
private bool SetPanelFragment(SAP2000Id fragment, string name)
{
return true;
}

/***************************************************/
private bool SetPanelFragment(IFragment fragment, string name)
{
return false;
}

/***************************************************/
private bool SetPanelFragment(IPanelAutoMesh fragment, string name)
{
return false;
}

/***************************************************/
private bool SetPanelFragment(PanelAutoMeshByNumberOfObjects fragment, string name)
{
return m_model.AreaObj.SetAutoMesh(name, 1, fragment.N1, fragment.N2, 0, 0, false, false, false, 0, 0, fragment.LocalAxesOnEdge, fragment.LocalAxesOnFace, fragment.RestraintsOnEdge, fragment.RestraintsOnFace, fragment.Group, fragment.SubMesh, fragment.SubMeshSize) == 0;
}

/***************************************************/
private bool SetPanelFragment(PanelAutoMeshByMaximumSize fragment, string name)
{
return m_model.AreaObj.SetAutoMesh(name, 2, 2, 2, fragment.MaxSize1, fragment.MaxSize2, false, false, false, 0, 0, fragment.LocalAxesOnEdge, fragment.LocalAxesOnFace, fragment.RestraintsOnEdge, fragment.RestraintsOnFace, fragment.Group, fragment.SubMesh, fragment.SubMeshSize) == 0;
}

/***************************************************/
private bool SetPanelFragment(PanelAutoMeshByPointsOnEdges fragment, string name)
{
return m_model.AreaObj.SetAutoMesh(name, 3, 2, 2, 0, 0, fragment.PointOnEdgeFromLine, fragment.PointOnEdgeFromPoint, false, 0, 0, fragment.LocalAxesOnEdge, fragment.LocalAxesOnFace, fragment.RestraintsOnEdge, fragment.RestraintsOnFace, fragment.Group, fragment.SubMesh, fragment.SubMeshSize) == 0;
}

/***************************************************/
private bool SetPanelFragment(PanelAutoMeshByCookieCutLines fragment, string name)
{
return m_model.AreaObj.SetAutoMesh(name, 4, 2, 2, 0, 0, false, false, fragment.ExtendCookieCutLines, 0, 0, fragment.LocalAxesOnEdge, fragment.LocalAxesOnFace, fragment.RestraintsOnEdge, fragment.RestraintsOnFace, fragment.Group, fragment.SubMesh, fragment.SubMeshSize) == 0;
}

/***************************************************/
private bool SetPanelFragment(PanelAutoMeshByCookieCutPoints fragment, string name)
{
return m_model.AreaObj.SetAutoMesh(name, 5, 2, 2, 0, 0, false, false, false, fragment.Rotation * 180 / Math.PI, 0, fragment.LocalAxesOnEdge, fragment.LocalAxesOnFace, fragment.RestraintsOnEdge, fragment.RestraintsOnFace, fragment.Group, fragment.SubMesh, fragment.SubMeshSize) == 0;
}

/***************************************************/
private bool SetPanelFragment(PanelAutoMeshByGeneralDivide fragment, string name)
{
return m_model.AreaObj.SetAutoMesh(name, 6, 2, 2, 0, 0, false, false, false, 0, fragment.MaxSizeGeneral, fragment.LocalAxesOnEdge, fragment.LocalAxesOnFace, fragment.RestraintsOnEdge, fragment.RestraintsOnFace, fragment.Group, fragment.SubMesh, fragment.SubMeshSize) == 0;
}

/***************************************************/
private bool SetPanelFragment(PanelEdgeConstraint fragment, string name)
{
return m_model.AreaObj.SetEdgeConstraint(name, fragment.EdgeConstraint) == 0;
}

/***************************************************/
private bool SetPanelFragment(IPanelOffset fragment, string name)
{
return false;
}

/***************************************************/
private bool SetPanelFragment(PanelOffsetByJointPattern fragment, string name)
{
double[] offsets = new double[4];
return m_model.AreaObj.SetOffsets(name, 1, fragment.OffsetPattern, fragment.OffsetPatternSF, ref offsets) == 0;
}

/***************************************************/
private bool SetPanelFragment(PanelOffsetByPoint fragment, string name)
{
double[] offsets = fragment.Offset;
bool success = m_model.AreaObj.SetOffsets(name, 2, "", 0, ref offsets) == 0;
return success && offsets.SequenceEqual(fragment.Offset);
}
/***************************************************/
}

}
122 changes: 102 additions & 20 deletions SAP2000_Adapter/CRUD/Read/Panel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* 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 BH.oM.Geometry;
using BH.oM.Structure.Elements;
using BH.oM.Structure.SurfaceProperties;
Expand All @@ -28,8 +27,12 @@
using System.Collections.Generic;
using System.Linq;
using BH.oM.Adapters.SAP2000;
using BH.oM.Adapters.SAP2000.Fragments;
using BH.Engine.Adapters.SAP2000;
using BH.Engine.Adapter;
using BH.Engine.Base;
using System;
using SAP2000v1;

namespace BH.Adapter.SAP2000
{
Expand All @@ -38,48 +41,41 @@ public partial class SAP2000Adapter
/***************************************************/
/**** Private Methods ****/
/***************************************************/

private List<Panel> ReadPanel(List<string> ids = null)
{
List<Panel> bhomPanels = new List<Panel>();

Dictionary<string, Node> bhomNodes = ReadNodes().ToDictionary(x => GetAdapterId<string>(x));
Dictionary<string, ISurfaceProperty> bhomProperties = ReadSurfaceProperty().ToDictionary(x => GetAdapterId<string>(x));

int nameCount = 0;
string[] nameArr = { };
string[] nameArr = {};
m_model.AreaObj.GetNameList(ref nameCount, ref nameArr);

ids = FilterIds(ids, nameArr);

foreach (string id in ids)
{
Panel bhomPanel = new Panel();
SAP2000Id sap2000id = new SAP2000Id();
string guid = null;

//Set the Adapter ID
sap2000id.Id = id;

//Get outline of panel
string[] pointNames = null;
int pointCount = 0;

if (m_model.AreaObj.GetPoints(id, ref pointCount, ref pointNames) == 0)
{
List<Point> pts = new List<Point>();
foreach (string name in pointNames)
pts.Add(bhomNodes[name].Position);
pts.Add(pts[0]);
Polyline outline = new Polyline() { ControlPoints = pts };
List<Edge> outEdges = new List<Edge>() { new Edge { Curve = outline, Release = new oM.Structure.Constraints.Constraint4DOF() } };
Polyline outline = new Polyline()
{ControlPoints = pts};
List<Edge> outEdges = new List<Edge>()
{ new Edge { Curve = outline, Release = new oM.Structure.Constraints.Constraint4DOF() } };

bhomPanel.ExternalEdges = outEdges;
}

//There are no openings in SAP2000
bhomPanel.Openings = new List<Opening>();

//Get the section property
string propertyName = "";
if (m_model.AreaObj.GetProperty(id, ref propertyName) == 0)
Expand All @@ -100,18 +96,104 @@ private List<Panel> ReadPanel(List<string> ids = null)

if (m_model.AreaObj.GetGUID(id, ref guid) == 0)
sap2000id.PersistentId = guid;

bhomPanel.SetAdapterId(sap2000id);
/***************************************************/
/* SAP Fragments */
/***************************************************/
// Automesh
int meshType = 0;
int n1 = 0;
int n2 = 0;
double maxSize1 = 0;
double maxSize2 = 0;
bool pointOnEdgeFromLine = false;
bool pointOnEdgeFromPoint = false;
bool extendCookieCutLines = false;
double rotation = 0;
double maxSizeGeneral = 0;
bool localAxesOnEdge = false;
bool localAxesOnFace = false;
bool restraintsOnEdge = false;
bool restraintsOnFace = false;
string group = null;
bool subMesh = false;
double subMeshSize = 0;
m_model.AreaObj.GetAutoMesh(id, ref meshType, ref n1, ref n2, ref maxSize1, ref maxSize2, ref pointOnEdgeFromLine, ref pointOnEdgeFromPoint, ref extendCookieCutLines, ref rotation, ref maxSizeGeneral, ref localAxesOnEdge, ref localAxesOnFace, ref restraintsOnEdge, ref restraintsOnFace, ref group, ref subMesh, ref subMeshSize);
switch (meshType)
{
case 1:
bhomPanel = (Panel)bhomPanel.AddFragment(new PanelAutoMeshByNumberOfObjects()
{N1 = n1, N2 = n2, LocalAxesOnEdge = localAxesOnEdge, LocalAxesOnFace = localAxesOnFace, RestraintsOnEdge = restraintsOnEdge, RestraintsOnFace = restraintsOnFace, Group = group, SubMesh = subMesh, SubMeshSize = subMeshSize});
break;
case 2:
bhomPanel = (Panel)bhomPanel.AddFragment(new PanelAutoMeshByMaximumSize()
{MaxSize1 = maxSize1, MaxSize2 = maxSize2, LocalAxesOnEdge = localAxesOnEdge, LocalAxesOnFace = localAxesOnFace, RestraintsOnEdge = restraintsOnEdge, RestraintsOnFace = restraintsOnFace, Group = group, SubMesh = subMesh, SubMeshSize = subMeshSize});
break;
case 3:
bhomPanel = (Panel)bhomPanel.AddFragment(new PanelAutoMeshByPointsOnEdges()
{PointOnEdgeFromLine = pointOnEdgeFromLine, PointOnEdgeFromPoint = pointOnEdgeFromPoint, LocalAxesOnEdge = localAxesOnEdge, LocalAxesOnFace = localAxesOnFace, RestraintsOnEdge = restraintsOnEdge, RestraintsOnFace = restraintsOnFace, Group = group, SubMesh = subMesh, SubMeshSize = subMeshSize});
;
break;
case 4:
bhomPanel = (Panel)bhomPanel.AddFragment(new PanelAutoMeshByCookieCutLines()
{ExtendCookieCutLines = extendCookieCutLines, LocalAxesOnEdge = localAxesOnEdge, LocalAxesOnFace = localAxesOnFace, RestraintsOnEdge = restraintsOnEdge, RestraintsOnFace = restraintsOnFace, Group = group, SubMesh = subMesh, SubMeshSize = subMeshSize});
break;
case 5:
bhomPanel = (Panel)bhomPanel.AddFragment(new PanelAutoMeshByCookieCutPoints()
{Rotation = rotation * Math.PI / 180, LocalAxesOnEdge = localAxesOnEdge, LocalAxesOnFace = localAxesOnFace, RestraintsOnEdge = restraintsOnEdge, RestraintsOnFace = restraintsOnFace, Group = group, SubMesh = subMesh, SubMeshSize = subMeshSize});
break;
case 6:
bhomPanel = (Panel)bhomPanel.AddFragment(new PanelAutoMeshByGeneralDivide()
{MaxSizeGeneral = maxSizeGeneral, LocalAxesOnEdge = localAxesOnEdge, LocalAxesOnFace = localAxesOnFace, RestraintsOnEdge = restraintsOnEdge, RestraintsOnFace = restraintsOnFace, Group = group, SubMesh = subMesh, SubMeshSize = subMeshSize});
break;
case 0:
default:
break;
}

// Edge Constraint
bool constraintExists = false;
m_model.AreaObj.GetEdgeConstraint(id, ref constraintExists);
if (constraintExists)
bhomPanel = (Panel)bhomPanel.AddFragment(new PanelEdgeConstraint()
{EdgeConstraint = true});
// Material Overwrite
string matName = "";
m_model.AreaObj.GetMaterialOverwrite(id, ref matName);
if (matName != "None")
{
ISurfaceProperty property = Engine.Base.Query.ShallowClone(bhomPanel.Property);
property.Material = ReadMaterial(new List<string>{matName}).FirstOrDefault();
property.Name = property.Name + "-" + matName;
bhomPanel.Property = property;
}

// Offsets
int offsetType = 0;
string offsetPattern = "";
double offsetPatternSF = 0;
double[] offset = null;
m_model.AreaObj.GetOffsets(id, ref offsetType, ref offsetPattern, ref offsetPatternSF, ref offset);
switch (offsetType)
{
case 1:
bhomPanel = (Panel)bhomPanel.AddFragment(new PanelOffsetByJointPattern()
{OffsetPattern = offsetPattern, OffsetPatternSF = offsetPatternSF});
break;
case 2:
bhomPanel = (Panel)bhomPanel.AddFragment(new PanelOffsetByPoint()
{Offset = offset, });
break;
default:
break;
}

//Add the panel to the list
bhomPanels.Add(bhomPanel);
}

return bhomPanels;
}

/***************************************************/
/***************************************************/
}
}



}
1 change: 0 additions & 1 deletion SAP2000_Adapter/CRUD/Read/Section.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ private List<ISectionProperty> ReadSectionProperties(List<string> ids = null)
double tw = 0;
double tfb = 0;
double t2b = 0;
double dis = 0;
double radius = 0;
double angle = 0;
int color = 0;
Expand Down
5 changes: 5 additions & 0 deletions SAP2000_Adapter/SAP2000_Adapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Quantities_oM">
<HintPath>C:\ProgramData\BHoM\Assemblies\Quantities_oM.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Results_Engine">
<HintPath>C:\ProgramData\BHoM\Assemblies\Results_Engine.dll</HintPath>
<Private>False</Private>
Expand Down
Loading