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

Improve Move Objects Update Feature #476

Merged
merged 7 commits into from
Nov 7, 2024
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
96 changes: 74 additions & 22 deletions Etabs_Adapter/CRUD/Update/Node.cs
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 - 2024, the respective contributors. All rights reserved.
*
Expand Down Expand Up @@ -27,6 +27,7 @@
using BH.oM.Structure.Elements;
using BH.oM.Structure.Constraints;
using BH.Engine.Adapters.ETABS;
using BH.oM.Physical.Elements;

namespace BH.Adapter.ETABS
{
Expand All @@ -44,41 +45,92 @@ public partial class ETABSAdapter : BHoMAdapter

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

double factor = DatabaseLengthUnitFactor();
double factor = DatabaseLengthUnitFactor(); // θ(1)

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

foreach (Node bhNode in nodes)
{
string name = GetAdapterId<string>(bhNode);
Dictionary<double, List<string>> dx = new Dictionary<double, List<string>>(); // θ(1)
Dictionary<double, List<string>> dy = new Dictionary<double, List<string>>(); // θ(1)
Dictionary<double, List<string>> dz = new Dictionary<double, List<string>>(); // θ(1)


// 1. GROUP NODES BY RELATIVE MOVEMENT IN X/Y/Z DIRECTION - ** HASH TABLES **

SetObject(bhNode, name);
foreach (Node bhNode in nodes) // n*θ(1) + θ(1)
{
string name = GetAdapterId<string>(bhNode); // θ(1)

// Update position
double x = 0;
double y = 0;
double z = 0;
double x = 0; // θ(1)
double y = 0; // θ(1)
double z = 0; // θ(1)

if (m_model.PointObj.GetCoordCartesian(name, ref x, ref y, ref z) == 0)
if (m_model.PointObj.GetCoordCartesian(name, ref x, ref y, ref z) == 0) // θ(1)
{
oM.Geometry.Point p = new oM.Geometry.Point() { X = x, Y = y, Z = z };
if (!comparer.Equals(bhNode, (Node)p))
oM.Geometry.Point p = new oM.Geometry.Point() { X = x, Y = y, Z = z }; // θ(1)

if (!comparer.Equals(bhNode, (Node)p)) // θ(1)
{
x = bhNode.Position.X - x;
y = bhNode.Position.Y - y;
z = bhNode.Position.Z - z;
// Get BHoM vs ETABS differences in nodes coordinates
x = bhNode.Position.X - x; // θ(1)
y = bhNode.Position.Y - y; // θ(1)
z = bhNode.Position.Z - z; // θ(1)

// Add Node name and corresponding dX in dx Hash Table
if (dx.ContainsKey(x)) dx[x].Add(name); // θ(1)
else dx.Add(x, new List<string>() {name}); // θ(1)
// Add Node name and corresponding dY in dy Hash Table
if (dy.ContainsKey(y)) dy[y].Add(name); // θ(1)
else dy.Add(y, new List<string>() {name}); // θ(1)
// Add Node name and corresponding dZ in dz Hash Table
if (dz.ContainsKey(z)) dz[z].Add(name); // θ(1)
else dz.Add(z, new List<string>() {name}); // θ(1)

m_model.PointObj.SetSelected(name, true);
m_model.EditGeneral.Move(x * factor, y * factor, z * factor);
m_model.PointObj.SetSelected(name, false);
}
}
}



// 2. MOVE NODES GROUP-BY-GROUP - ** STREAMS **

// dX Movement
dx.ToList().ForEach(kvp => // θ(n)
{
// 1. Select all nodes belonging to same group
kvp.Value.ForEach(pplbl => m_model.PointObj.SetSelected(pplbl.ToString(), true));
// 2. Move all selected nodes by same dX
m_model.EditGeneral.Move((double)kvp.Key, 0, 0);
// 3. Deselect all selected nodes
kvp.Value.ForEach(pplbl => m_model.PointObj.SetSelected(pplbl.ToString(), false));
});

// dY Movement
dy.ToList().ForEach(kvp => // θ(n)
{
// 1. Select all nodes belonging to same group
kvp.Value.ForEach(pplbl => m_model.PointObj.SetSelected(pplbl.ToString(), true));
// 2. Move all selected nodes by same dY
m_model.EditGeneral.Move(0, (double)kvp.Key, 0);
// 3. Deselect all selected nodes
kvp.Value.ForEach(pplbl => m_model.PointObj.SetSelected(pplbl.ToString(), false));
});

// dZ Movement
dz.ToList().ForEach(kvp => // θ(n)
{
// 1. Select all nodes belonging to same group
kvp.Value.ForEach(pplbl => m_model.PointObj.SetSelected(pplbl.ToString(), true));
// 2. Move all selected nodes by same dZ
m_model.EditGeneral.Move(0, 0, (double)kvp.Key);
// 3. Deselect all selected nodes
kvp.Value.ForEach(pplbl => m_model.PointObj.SetSelected(pplbl.ToString(), false));
});

return success;
}

Expand Down
9 changes: 2 additions & 7 deletions Etabs_Adapter/ETABSAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
public ETABS17Adapter(string filePath = "", EtabsSettings etabsSetting = null, bool active = false)
#else
[Description("Creates an adapter to ETABS version 18 or later. For connection to ETABS v17 use the ETABS17Adapter. For connection to ETABS 2016 use the ETABS2016Adapter. Earlier versions not supported.")]
public ETABSAdapter(string filePath = "", EtabsSettings etabsSetting = null, bool active = false)

Check warning on line 80 in Etabs_Adapter/ETABSAdapter.cs

View check run for this annotation

BHoMBot-CI / documentation-compliance

Etabs_Adapter/ETABSAdapter.cs#L80

Method must contain an Output or MultiOutput attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/HasOutputAttribute
#endif
{
//Initialisation
Expand Down Expand Up @@ -156,13 +156,8 @@

private bool ForceRefresh()
{
//Forcing refresh of the model by moving all elements in back and forward along the x-axis.
//If a more elegant way can be found to do this, this should be changed.
m_model.SelectObj.All();
m_model.EditGeneral.Move(1, 0, 0);
m_model.SelectObj.All();
m_model.EditGeneral.Move(-1, 0, 0);
m_model.SelectObj.ClearSelection();
m_model.View.RefreshView();
m_model.View.RefreshWindow();
return true;
}

Expand Down
Loading