Skip to content

Commit 01e709c

Browse files
Improve Move Objects Update Feature (#476)
2 parents edc11e0 + a20ded0 commit 01e709c

File tree

2 files changed

+76
-29
lines changed

2 files changed

+76
-29
lines changed

Etabs_Adapter/CRUD/Update/Node.cs

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* This file is part of the Buildings and Habitats object Model (BHoM)
33
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
44
*
@@ -27,6 +27,7 @@
2727
using BH.oM.Structure.Elements;
2828
using BH.oM.Structure.Constraints;
2929
using BH.Engine.Adapters.ETABS;
30+
using BH.oM.Physical.Elements;
3031

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

4546
private bool UpdateObjects(IEnumerable<Node> nodes)
4647
{
47-
bool success = true;
48-
m_model.SelectObj.ClearSelection();
48+
bool success = true; // θ(1)
49+
m_model.SelectObj.ClearSelection(); // θ(1)
4950

50-
double factor = DatabaseLengthUnitFactor();
51+
double factor = DatabaseLengthUnitFactor(); // θ(1)
5152

52-
Engine.Structure.NodeDistanceComparer comparer = AdapterComparers[typeof(Node)] as Engine.Structure.NodeDistanceComparer;
53+
Engine.Structure.NodeDistanceComparer comparer = AdapterComparers[typeof(Node)] // θ(1)
54+
as Engine.Structure.NodeDistanceComparer;
5355

54-
foreach (Node bhNode in nodes)
55-
{
56-
string name = GetAdapterId<string>(bhNode);
56+
Dictionary<double, List<string>> dx = new Dictionary<double, List<string>>(); // θ(1)
57+
Dictionary<double, List<string>> dy = new Dictionary<double, List<string>>(); // θ(1)
58+
Dictionary<double, List<string>> dz = new Dictionary<double, List<string>>(); // θ(1)
59+
60+
61+
// 1. GROUP NODES BY RELATIVE MOVEMENT IN X/Y/Z DIRECTION - ** HASH TABLES **
5762

58-
SetObject(bhNode, name);
63+
foreach (Node bhNode in nodes) // n*θ(1) + θ(1)
64+
{
65+
string name = GetAdapterId<string>(bhNode); // θ(1)
5966

6067
// Update position
61-
double x = 0;
62-
double y = 0;
63-
double z = 0;
68+
double x = 0; // θ(1)
69+
double y = 0; // θ(1)
70+
double z = 0; // θ(1)
6471

65-
if (m_model.PointObj.GetCoordCartesian(name, ref x, ref y, ref z) == 0)
72+
if (m_model.PointObj.GetCoordCartesian(name, ref x, ref y, ref z) == 0) // θ(1)
6673
{
67-
oM.Geometry.Point p = new oM.Geometry.Point() { X = x, Y = y, Z = z };
68-
69-
if (!comparer.Equals(bhNode, (Node)p))
74+
oM.Geometry.Point p = new oM.Geometry.Point() { X = x, Y = y, Z = z }; // θ(1)
75+
76+
if (!comparer.Equals(bhNode, (Node)p)) // θ(1)
7077
{
71-
x = bhNode.Position.X - x;
72-
y = bhNode.Position.Y - y;
73-
z = bhNode.Position.Z - z;
78+
// Get BHoM vs ETABS differences in nodes coordinates
79+
x = bhNode.Position.X - x; // θ(1)
80+
y = bhNode.Position.Y - y; // θ(1)
81+
z = bhNode.Position.Z - z; // θ(1)
82+
83+
// Add Node name and corresponding dX in dx Hash Table
84+
if (dx.ContainsKey(x)) dx[x].Add(name); // θ(1)
85+
else dx.Add(x, new List<string>() {name}); // θ(1)
86+
// Add Node name and corresponding dY in dy Hash Table
87+
if (dy.ContainsKey(y)) dy[y].Add(name); // θ(1)
88+
else dy.Add(y, new List<string>() {name}); // θ(1)
89+
// Add Node name and corresponding dZ in dz Hash Table
90+
if (dz.ContainsKey(z)) dz[z].Add(name); // θ(1)
91+
else dz.Add(z, new List<string>() {name}); // θ(1)
7492

75-
m_model.PointObj.SetSelected(name, true);
76-
m_model.EditGeneral.Move(x * factor, y * factor, z * factor);
77-
m_model.PointObj.SetSelected(name, false);
7893
}
7994
}
8095
}
8196

97+
98+
99+
// 2. MOVE NODES GROUP-BY-GROUP - ** STREAMS **
100+
101+
// dX Movement
102+
dx.ToList().ForEach(kvp => // θ(n)
103+
{
104+
// 1. Select all nodes belonging to same group
105+
kvp.Value.ForEach(pplbl => m_model.PointObj.SetSelected(pplbl.ToString(), true));
106+
// 2. Move all selected nodes by same dX
107+
m_model.EditGeneral.Move((double)kvp.Key, 0, 0);
108+
// 3. Deselect all selected nodes
109+
kvp.Value.ForEach(pplbl => m_model.PointObj.SetSelected(pplbl.ToString(), false));
110+
});
111+
112+
// dY Movement
113+
dy.ToList().ForEach(kvp => // θ(n)
114+
{
115+
// 1. Select all nodes belonging to same group
116+
kvp.Value.ForEach(pplbl => m_model.PointObj.SetSelected(pplbl.ToString(), true));
117+
// 2. Move all selected nodes by same dY
118+
m_model.EditGeneral.Move(0, (double)kvp.Key, 0);
119+
// 3. Deselect all selected nodes
120+
kvp.Value.ForEach(pplbl => m_model.PointObj.SetSelected(pplbl.ToString(), false));
121+
});
122+
123+
// dZ Movement
124+
dz.ToList().ForEach(kvp => // θ(n)
125+
{
126+
// 1. Select all nodes belonging to same group
127+
kvp.Value.ForEach(pplbl => m_model.PointObj.SetSelected(pplbl.ToString(), true));
128+
// 2. Move all selected nodes by same dZ
129+
m_model.EditGeneral.Move(0, 0, (double)kvp.Key);
130+
// 3. Deselect all selected nodes
131+
kvp.Value.ForEach(pplbl => m_model.PointObj.SetSelected(pplbl.ToString(), false));
132+
});
133+
82134
return success;
83135
}
84136

Etabs_Adapter/ETABSAdapter.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,8 @@ public ETABSAdapter(string filePath = "", EtabsSettings etabsSetting = null, boo
156156

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

0 commit comments

Comments
 (0)