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

ETABS_Toolkit: SelectionRequest, Delete and update for Node #332

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
49 changes: 32 additions & 17 deletions Etabs_Adapter/CRUD/Create/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
using BH.oM.Structure.Elements;
using BH.Engine.Structure;
using BH.Engine.Adapters.ETABS;

using BH.Engine.Geometry;
using BH.oM.Geometry;

namespace BH.Adapter.ETABS
{
Expand All @@ -42,31 +43,45 @@ private bool CreateObject(Node bhNode)
{
string name = "";

oM.Geometry.Point position = bhNode.Position();
oM.Geometry.Point position = bhNode.Position;
if (m_model.PointObj.AddCartesian(position.X, position.Y, position.Z, ref name) == 0)
{
bhNode.CustomData[AdapterIdName] = name;

if (bhNode.Support != null)
{
bool[] restraint = new bool[6];
double[] spring = new double[6];
SetObject(bhNode, name);
}

bhNode.Support.ToCSI(ref restraint, ref spring);
return true;
}

if (m_model.PointObj.SetRestraint(name, ref restraint) == 0) { }
else
{
CreatePropertyWarning("Node Restraint", "Node", name);
}
if (m_model.PointObj.SetSpring(name, ref spring) == 0) { }
else
{
CreatePropertyWarning("Node Spring", "Node", name);
}
/***************************************************/

private bool SetObject(Node bhNode, string name)
{
if (bhNode.Support != null)
{
bool[] restraint = new bool[6];
double[] spring = new double[6];

bhNode.Support.ToCSI(ref restraint, ref spring);

if (m_model.PointObj.SetRestraint(name, ref restraint) == 0) { }
else
{
CreatePropertyWarning("Node Restraint", "Node", name);
}
if (m_model.PointObj.SetSpring(name, ref spring) == 0) { }
else
{
CreatePropertyWarning("Node Spring", "Node", name);
}
}

if (bhNode.Orientation != null && !bhNode.Orientation.IsEqual(Basis.XY))
{
Engine.Reflection.Compute.RecordWarning("ETABS does not support local coordinate systems other than the global one. Any nodes pushed will have been so as if they had the global coordinatesystem.");
}

return true;
}

Expand Down
94 changes: 93 additions & 1 deletion Etabs_Adapter/CRUD/Delete/_Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
using System.Text;
using System.Threading.Tasks;
using BH.oM.Adapter;
using BH.oM.Structure.Elements;
using BH.oM.Structure.SectionProperties;
using BH.oM.Structure.MaterialFragments;
using BH.oM.Structure.SurfaceProperties;
using BH.oM.Structure.Loads;
using BH.oM.Structure.Constraints;
using BH.oM.Base;
using BH.oM.Data.Requests;
using System.Collections;

namespace BH.Adapter.ETABS
{
Expand All @@ -43,7 +52,90 @@ public partial class ETABS2016Adapter : BHoMAdapter

protected override int IDelete(Type type, IEnumerable<object> ids, ActionConfig actionConfig = null)
{
return base.IDelete(type, ids, actionConfig);
List<string> listIds = new List<string>();
if (ids != null)
listIds = ids.Cast<string>().ToList();

int count = listIds.Count;
int controlCount = count;

if (type == typeof(Node))
foreach (string id in listIds)
count -= m_model.PointObj.DeleteSpecialPoint(id);
else if (type == typeof(Bar))
foreach (string id in listIds)
count -= m_model.FrameObj.Delete(id);
else if (type == typeof(ISectionProperty) || type.GetInterfaces().Contains(typeof(ISectionProperty)))
foreach (string id in listIds)
count -= m_model.PropFrame.Delete(id);
else if (type == typeof(IMaterialFragment))
foreach (string id in listIds)
count -= m_model.PropMaterial.Delete(id);
else if (type == typeof(Panel))
foreach (string id in listIds)
count -= m_model.AreaObj.Delete(id);
else if (type == typeof(ISurfaceProperty))
foreach (string id in listIds)
count -= m_model.PropArea.Delete(id);
else if (type == typeof(LoadCombination))
foreach (string id in listIds)
count -= m_model.LoadPatterns.Delete(id);
else if (type == typeof(Loadcase))
foreach (string id in listIds)
count -= m_model.LoadCases.Delete(id);
else if (type == typeof(ILoad) || type.GetInterfaces().Contains(typeof(ILoad)))
Engine.Reflection.Compute.RecordError("Loads do not have ids in ETABS, try deleting Loadcases, LoadCombinations or overwriting the old loads with `ReplaceLoads`.");
else if (type == typeof(RigidLink))
foreach (string id in listIds)
count -= m_model.LinkObj.Delete(id);
else if (type == typeof(LinkConstraint))
foreach (string id in listIds)
count -= m_model.PropLink.Delete(id);
else if (type == typeof(oM.Geometry.SettingOut.Level) || type == typeof(oM.Architecture.Elements.Level))
Engine.Reflection.Compute.RecordError("Can't delete levels in ETABS.");
else if (type == typeof(oM.Geometry.SettingOut.Grid))
Engine.Reflection.Compute.RecordError("Can't delete grids in ETABS.");
else if (type == typeof(FEMesh))
foreach (string id in listIds)
count -= m_model.AreaObj.Delete(id);

if (count != controlCount)
{
Engine.Reflection.Compute.RecordWarning("Some of the requested delete operations failed.");
}

return count;
}

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

protected override int Delete(IRequest request, ActionConfig actionConfig = null)
{
if (request is SelectionRequest)
{
int count = 0;

foreach (KeyValuePair<Type, List<string>> keyVal in SelectedElements())
{
count += IDelete(keyVal.Key, keyVal.Value, actionConfig);
}

return count;
}

// Temporary fix until BHoM_Adpter works
if (request is FilterRequest)
{
List<string> objectIds = null;
object idObject;
if ((request as FilterRequest).Equalities.TryGetValue("ObjectIds", out idObject) && idObject is List<string>)
objectIds = idObject as List<string>;

// Call the Basic Method Read() to get the objects based on the Ids
return IDelete((request as FilterRequest).Type, objectIds, actionConfig);
}

return base.Delete(request, actionConfig);
}

/***************************************************/
Expand Down
57 changes: 57 additions & 0 deletions Etabs_Adapter/CRUD/Read/_Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#endif
using BH.oM.Adapter;
using System.ComponentModel;
using BH.oM.Data.Requests;
using BH.oM.Reflection;

namespace BH.Adapter.ETABS
{
Expand Down Expand Up @@ -97,6 +99,61 @@ protected override IEnumerable<IBHoMObject> IRead(Type type, IList ids, ActionCo

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

public IEnumerable<IBHoMObject> Read(SelectionRequest request, ActionConfig actionConfig = null)
{
List<IBHoMObject> results = new List<IBHoMObject>();

foreach (KeyValuePair<Type, List<string>> keyVal in SelectedElements())
{
results.AddRange(IRead(keyVal.Key, keyVal.Value, actionConfig));
}

return results;
}

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

public Dictionary<Type, List<string>> SelectedElements()
{
int numItems = 0;
int[] objectTypes = new int[0];
string[] objectIds = new string[0];

m_model.SelectObj.GetSelected(ref numItems, ref objectTypes, ref objectIds);

Dictionary<int, List<string>> dict = objectTypes.Distinct().ToDictionary(x => x, x => new List<string>());

for (int i = 0; i < numItems; i++)
{
dict[objectTypes[i]].Add(objectIds[i]);
}

Func<int, Type> ToType = x =>
{
switch (x)
{
case 1: // Point Object
return typeof(Node);
case 2: // Frame Object
case 3: // Cable Object
case 4: // Tendon Object
return typeof(Bar);
case 5: // Area Object
return typeof(Panel);
case 6: // Solid Object
return null;
case 7: // Link Object
return typeof(RigidLink);
default:
return null;
}
};

return dict.ToDictionary(x => ToType(x.Key), x => x.Value);
}

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

[Description("Ensures that all elements in the first list are present in the second list, warning if not, and returns the second list if the first list is empty.")]
private static List<string> FilterIds(IEnumerable<string> ids, IEnumerable<string> etabsIds)
{
Expand Down
48 changes: 28 additions & 20 deletions Etabs_Adapter/CRUD/Update/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using System.Linq;
using BH.oM.Structure.Elements;
using BH.oM.Structure.Constraints;
using BH.Engine.Adapters.ETABS;

namespace BH.Adapter.ETABS
{
Expand All @@ -38,34 +39,41 @@ public partial class ETABS2016Adapter : BHoMAdapter
/***************************************************/
/**** Update Node ****/
/***************************************************/

private bool UpdateObjects(IEnumerable<Node> nodes)
{
bool success = true;
m_model.SelectObj.ClearSelection();

double factor = DatabaseLengthUnitFactor();

Engine.Structure.NodeDistanceComparer comparer = AdapterComparers[typeof(Node)] as Engine.Structure.NodeDistanceComparer;

foreach (Node bhNode in nodes)
{
if (bhNode.Support != null)
{
string name = bhNode.CustomData[AdapterIdName].ToString();
string name = bhNode.CustomData[AdapterIdName].ToString();

SetObject(bhNode, name);

bool[] restraint = new bool[6];
restraint[0] = bhNode.Support.TranslationX == DOFType.Fixed;
restraint[1] = bhNode.Support.TranslationY == DOFType.Fixed;
restraint[2] = bhNode.Support.TranslationZ == DOFType.Fixed;
restraint[3] = bhNode.Support.RotationX == DOFType.Fixed;
restraint[4] = bhNode.Support.RotationY == DOFType.Fixed;
restraint[5] = bhNode.Support.RotationZ == DOFType.Fixed;
// Update position
double x = 0;
double y = 0;
double z = 0;

double[] spring = new double[6];
spring[0] = bhNode.Support.TranslationalStiffnessX;
spring[1] = bhNode.Support.TranslationalStiffnessY;
spring[2] = bhNode.Support.TranslationalStiffnessZ;
spring[3] = bhNode.Support.RotationalStiffnessX;
spring[4] = bhNode.Support.RotationalStiffnessY;
spring[5] = bhNode.Support.RotationalStiffnessZ;
if (m_model.PointObj.GetCoordCartesian(name, ref x, ref y, ref z) == 0)
{
oM.Geometry.Point p = new oM.Geometry.Point() { X = x, Y = y, Z = z };

if (!comparer.Equals(bhNode, (Node)p))
{
x = bhNode.Position.X - x;
y = bhNode.Position.Y - y;
z = bhNode.Position.Z - z;

success &= m_model.PointObj.SetRestraint(name, ref restraint) == 0;
success &= m_model.PointObj.SetSpring(name, ref spring) == 0;
m_model.PointObj.SetSelected(name, true);
m_model.EditGeneral.Move(x * factor, y * factor, z * factor);
m_model.PointObj.SetSelected(name, false);
}
}
}

Expand Down
44 changes: 44 additions & 0 deletions Etabs_Adapter/ETABSAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using System.Threading.Tasks;
using BH.oM.Base;
using BH.oM.Adapters.ETABS;
using BH.Engine.Units;
#if Debug17 || Release17
using ETABSv17;
#elif Debug18 || Release18
Expand Down Expand Up @@ -146,6 +147,49 @@ private void LoadSectionDatabaseNames()

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

public double DatabaseLengthUnitFactor()
{
eForce force = 0;
eLength length = 0;
eTemperature temp = 0;

m_model.GetDatabaseUnits_2(ref force, ref length, ref temp);

double factor = 1;

switch (length)
{
case eLength.NotApplicable:
Engine.Reflection.Compute.RecordWarning("Unknow NotApplicable unit, assumed to be meter.");
factor = 1;
break;
case eLength.inch:
factor = factor.ToInch();
break;
case eLength.ft:
factor = factor.ToFoot();
break;
case eLength.micron:
factor = factor.ToMicrometre();
break;
case eLength.mm:
factor = factor.ToMillimetre();
break;
case eLength.cm:
factor = factor.ToCentimetre();
break;
case eLength.m:
factor = 1;
break;
default:
break;
}

return factor;
}

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

}
}

4 changes: 4 additions & 0 deletions Etabs_Adapter/Etabs_Adapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Units_Engine">
<HintPath>C:\ProgramData\BHoM\Assemblies\Units_Engine.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AdapterActions\Exectute.cs" />
Expand Down
3 changes: 2 additions & 1 deletion dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
BHoM/BHoM
BHoM/BHoM_Engine
BHoM/BHoM_Adapter
BHoM/BHoM_Adapter
BHoM/Localisation_Toolkit