Skip to content

Pull Spacer and SpacerProperty #270

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

Merged
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
46 changes: 44 additions & 2 deletions GSA_Adapter/CRUD/Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
using System.Linq;
using BH.oM.Adapter;
using BH.Engine.Adapters.GSA;
using BH.oM.Adapters.GSA.Elements;
using BH.oM.Adapters.GSA.SpacerProperties;

namespace BH.Adapter.GSA
{
Expand Down Expand Up @@ -82,6 +84,10 @@ protected override IEnumerable<IBHoMObject> IRead(Type type, IList indices, Acti
return ReadProperty2d(indices as dynamic);
if (type == typeof(Loadcase))
return ReadLoadCases(indices as dynamic);
if (type == typeof(Spacer))
return ReadSpacers(indices as dynamic);
if (type == typeof(SpacerProperty))
return ReadSpacerProperties(indices as dynamic);
if (type.IsGenericType && type.Name == typeof(BHoMGroup<IBHoMObject>).Name)
return new List<BHoMGroup<IBHoMObject>>();
if (typeof(IResult).IsAssignableFrom(type))
Expand Down Expand Up @@ -187,9 +193,11 @@ public List<Bar> ReadBars(List<string> ids = null)

//GsaElement[] gsaElements = new GsaElement[potentialBeamRefs.Length];
//m_gsaCom.Elements(potentialBeamRefs, out gsaElements);

#if GSA_10_1
string allNodes = m_gsaCom.GwaCommand("GET_ALL, EL.4").ToString();
#else
string allNodes = m_gsaCom.GwaCommand("GET_ALL, EL.2").ToString();

#endif
string[] barArr = string.IsNullOrWhiteSpace(allNodes) ? new string[0] : allNodes.Split('\n');

List<ISectionProperty> secPropList = ReadSectionProperties();
Expand Down Expand Up @@ -402,6 +410,40 @@ public List<RigidLink> ReadRigidLink(List<string> ids = null)
// return proArr.Where(x => ids.Contains(x.Split(',')[1])).Select(x => Convert.FromGsaSectionProperty(x, materials)).ToList();
}

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

public List<Spacer> ReadSpacers(List<string> ids = null)
{
List<Node> nodeList = ReadNodes();
List<SpacerProperty> spacerProps = ReadSpacerProperties();

Dictionary<string, Node> nodes = nodeList.ToDictionary(x => GetAdapterId<int>(x).ToString());
Dictionary<string, SpacerProperty> secProps = spacerProps.Where(x => x != null).ToDictionary(x => GetAdapterId<int>(x).ToString());

int[] potentialBeamRefs = GenerateIndices(ids, typeof(Spacer));
GsaElement[] gsaElements = new GsaElement[potentialBeamRefs.Length];
m_gsaCom.Elements(potentialBeamRefs, out gsaElements);

return Convert.FromGsaSpacers(gsaElements, secProps, nodes);


}

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

public List<SpacerProperty> ReadSpacerProperties(List<string> ids = null)
{

string allProps = m_gsaCom.GwaCommand("GET_ALL, PROP_SPACER").ToString();

string[] proArr = string.IsNullOrWhiteSpace(allProps) ? new string[0] : allProps.Split('\n');

if (ids == null)
return proArr.Select(x => Convert.FromGsaSpacerProperty(x)).ToList();
else
return proArr.Where(x => ids.Contains(x.Split(',')[1])).Select(x => Convert.FromGsaSpacerProperty(x)).ToList();
}


/***************************************************/
/**** Private Methods ****/
Expand Down
42 changes: 22 additions & 20 deletions GSA_Adapter/Convert/FromGsa/Elements/Spacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,40 @@ public static partial class Convert
/**** Public Methods ****/
/***************************************************/

//public static List<Spacer> FromGsaSpacers(IEnumerable<GsaElement> gsaElements, Dictionary<string, IProperty> spaProps, Dictionary<string, Node> nodes)
//{
// List<Spacer> spacerList = new List<Spacer>();
public static List<Spacer> FromGsaSpacers(IEnumerable<GsaElement> gsaElements, Dictionary<string, SpacerProperty> spaProps, Dictionary<string, Node> nodes)
{
List<Spacer> spacerList = new List<Spacer>();

// foreach (GsaElement gsaSpacer in gsaElements)
// {
foreach (GsaElement gsaSpacer in gsaElements)
{
if (gsaSpacer.eType != 19)
continue;

// Node n1, n2;
// nodes.TryGetValue(gsaSpacer.Topo[0].ToString(), out n1);
// nodes.TryGetValue(gsaSpacer.Topo[1].ToString(), out n2);
Node n1, n2;
nodes.TryGetValue(gsaSpacer.Topo[0].ToString(), out n1);
nodes.TryGetValue(gsaSpacer.Topo[1].ToString(), out n2);

// Spacer spacer = new Spacer { StartNode = n1, EndNode = n2 };
// spacer.ApplyTaggedName(gsaSpacer.Name);
Spacer spacer = new Spacer { StartNode = n1, EndNode = n2 };
spacer.ApplyTaggedName(gsaSpacer.Name);



// IProperty prop;
// spaProps.TryGetValue(gsaSpacer.Property.ToString(), out prop);
SpacerProperty prop;
spaProps.TryGetValue(gsaSpacer.Property.ToString(), out prop);

// spacer.SpacerProperty = prop;
spacer.SpacerProperty = prop;

// int id = gsaSpacer.Ref;
// spacer.SetAdapterId(typeof(GSAId), id);
int id = gsaSpacer.Ref;
spacer.SetAdapterId(typeof(GSAId), id);

// spacerList.Add(spacer);
spacerList.Add(spacer);

// }
// return spacerList;
//}
}
return spacerList;
}

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

}
}

Expand Down
96 changes: 96 additions & 0 deletions GSA_Adapter/Convert/FromGsa/Properties/SpacerProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2023, 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 BH.Engine.Adapter;
using BH.oM.Adapters.GSA;
using BH.oM.Structure.Constraints;
using System.Linq;
using BH.oM.Adapters.GSA.SpacerProperties;

namespace BH.Adapter.GSA
{
public static partial class Convert
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

public static SpacerProperty FromGsaSpacerProperty(string gsaProp)
{

string[] props = gsaProp.Split(',');
string name = props[2];
string type = props[5];
string lengthType = props[6];
string stiffness = props[7];
string ratio = props[8];
string id = props[1];

SpacerProperty spacerProp = new SpacerProperty();
spacerProp.Name = name;
spacerProp.SetAdapterId(typeof(GSAId), int.Parse(id));
spacerProp.Stiffness = double.Parse(stiffness);
spacerProp.Ratio = double.Parse(ratio);

switch (lengthType)
{
case "PROPORTIONAL":
spacerProp.LengthType = SpacerLengthType.Proportional;
break;
case "RATIO":
spacerProp.LengthType = SpacerLengthType.Ratio;
break;
case "PROJECTED_RATIO_XY":
spacerProp.LengthType = SpacerLengthType.Projected_ratio_xy;
break;
case "PROJECTED_RATIO_XX":
spacerProp.LengthType = SpacerLengthType.Projected_ratio_xx;
break;
default:
spacerProp.LengthType = SpacerLengthType.Proportional;
break;
}

switch (type)
{
case "GEODESIC":
spacerProp.Type = SpacerType.Geodesic;
break;
case "FREE":
spacerProp.Type = SpacerType.Free;
break;
case "BAR":
spacerProp.Type = SpacerType.Bar;
break;
default:
spacerProp.Type = SpacerType.Geodesic;
break;
}

return spacerProp;
}

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

1 change: 1 addition & 0 deletions GSA_Adapter/GSA_Adapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
<Compile Include="Convert\FromGsa\Elements\Bar.cs" />
<Compile Include="Convert\FromGsa\Elements\FEMesh.cs" />
<Compile Include="Convert\FromGsa\Elements\Spacer.cs" />
<Compile Include="Convert\FromGsa\Properties\SpacerProperty.cs" />
<Compile Include="Convert\FromGsa\Properties\LinkConstraint.cs" />
<Compile Include="Convert\FromGsa\Loads\Loadcase.cs" />
<Compile Include="Convert\FromGsa\Loads\LoadCombination.cs" />
Expand Down