1
- /*
1
+ /*
2
2
* This file is part of the Buildings and Habitats object Model (BHoM)
3
3
* Copyright (c) 2015 - 2024, the respective contributors. All rights reserved.
4
4
*
27
27
using BH . oM . Structure . Elements ;
28
28
using BH . oM . Structure . Constraints ;
29
29
using BH . Engine . Adapters . ETABS ;
30
+ using BH . oM . Physical . Elements ;
30
31
31
32
namespace BH . Adapter . ETABS
32
33
{
@@ -44,41 +45,92 @@ public partial class ETABSAdapter : BHoMAdapter
44
45
45
46
private bool UpdateObjects ( IEnumerable < Node > nodes )
46
47
{
47
- bool success = true ;
48
- m_model . SelectObj . ClearSelection ( ) ;
48
+ bool success = true ; // θ(1)
49
+ m_model . SelectObj . ClearSelection ( ) ; // θ(1)
49
50
50
- double factor = DatabaseLengthUnitFactor ( ) ;
51
+ double factor = DatabaseLengthUnitFactor ( ) ; // θ(1)
51
52
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 ;
53
55
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 **
57
62
58
- SetObject ( bhNode , name ) ;
63
+ foreach ( Node bhNode in nodes ) // n*θ(1) + θ(1)
64
+ {
65
+ string name = GetAdapterId < string > ( bhNode ) ; // θ(1)
59
66
60
67
// 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)
64
71
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)
66
73
{
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)
70
77
{
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)
74
92
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 ) ;
78
93
}
79
94
}
80
95
}
81
96
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
+
82
134
return success ;
83
135
}
84
136
0 commit comments