-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathLink.cs
More file actions
269 lines (222 loc) · 10.4 KB
/
Copy pathLink.cs
File metadata and controls
269 lines (222 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2025, 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 System;
using BH.Engine.Adapter;
using BH.oM.Adapters.ETABS;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BH.oM.Base;
using BH.oM.Structure.Elements;
using BH.oM.Structure.Constraints;
using BH.Engine.Adapters.ETABS;
#if Debug16 || Release16
using ETABS2016;
#elif Debug17 || Release17
using ETABSv17;
#else
using CSiAPIv1;
#endif
namespace BH.Adapter.ETABS
{
#if Debug16 || Release16
public partial class ETABS2016Adapter : BHoMAdapter
#elif Debug17 || Release17
public partial class ETABS17Adapter : BHoMAdapter
#else
public partial class ETABSAdapter : BHoMAdapter
#endif
{
/***************************************************/
private List<RigidLink> ReadRigidLink(List<string> ids = null)
{
List<RigidLink> linkList = new List<RigidLink>();
int nameCount = 0;
string[] names = { };
m_model.LinkObj.GetNameList(ref nameCount, ref names);
ids = FilterIds(ids, names);
//read primary-multiSecondary nodes if these were initially created from (non-etabs)BHoM side
Dictionary<string, List<string>> idDict = new Dictionary<string, List<string>>();
string[] primarySecondaryId;
foreach (string id in ids)
{
primarySecondaryId = id.Split(new[] { ":::" }, StringSplitOptions.None);
if (primarySecondaryId.Count() > 1)
{
//has plural secondaries
if (idDict.ContainsKey(primarySecondaryId[0]))
idDict[primarySecondaryId[0]].Add(primarySecondaryId[1]);
else
idDict.Add(primarySecondaryId[0], new List<string>() { primarySecondaryId[1] });
}
else
{
//normal single link
idDict.Add(id, null);
}
}
foreach (KeyValuePair<string, List<string>> kvp in idDict)
{
RigidLink bhLink = new RigidLink();
SetAdapterId(bhLink, kvp.Key);
if (kvp.Value == null)
{
string startId = "";
string endId = "";
m_model.LinkObj.GetPoints(kvp.Key, ref startId, ref endId);
//Dummy nodes with correct Id
bhLink.PrimaryNode = new Node { Name = startId };
bhLink.SecondaryNodes = new List<Node>() { new Node { Name = endId } };
}
else
{
string startId = "";
string endId = "";
string multiLinkId = kvp.Key + ":::0";
m_model.LinkObj.GetPoints(multiLinkId, ref startId, ref endId);
bhLink.PrimaryNode = new Node { Name = startId }; //Dummy startnode with correct Id
List<string> endIds = new List<string>();
for (int i = 1; i < kvp.Value.Count(); i++)
{
multiLinkId = kvp.Key + ":::" + i;
m_model.LinkObj.GetPoints(multiLinkId, ref startId, ref endId);
endIds.Add(endId);
}
bhLink.SecondaryNodes = endIds.Select(x => new Node { Name = x }).ToList(); //Dummy endnodes with correct Id
}
string propName = "";
m_model.LinkObj.GetProperty(kvp.Key, ref propName);
bhLink.Constraint = new LinkConstraint { Name = propName }; //Dummy constraint to be populated in later loop
/* Get the ETABS name of the Rigid Link */
string name = GetAdapterId<string>(bhLink);
#if !(Debug16 || Release16 || Debug17 || Release17)
// Get the groups the link is assigned to
int numGroups = 0;
string[] groupNames = new string[0];
if (m_model.LinkObj.GetGroupAssign(name, ref numGroups, ref groupNames) == 0)
{
foreach (string grpName in groupNames)
bhLink.Tags.Add(grpName);
}
#endif
linkList.Add(bhLink);
}
if (linkList.Count == 0)
return linkList;
//Get ids of primary and secondary nodes
List<string> nodeIds = linkList.SelectMany(x => x.SecondaryNodes.Select(s => s.Name).Concat(new List<string> { x.PrimaryNode.Name })).Distinct().ToList();
Dictionary<string, Node> nodes = GetCachedOrReadAsDictionary<string, Node>(nodeIds);
List<string> contstrainIds = linkList.Select(x => x.Constraint.Name).Distinct().ToList();
//Get cached or read out all constraints used by Links
Dictionary<string, LinkConstraint> constraints = contstrainIds.Any() ? new Dictionary<string, LinkConstraint>() : GetCachedOrReadAsDictionary<string, LinkConstraint>(contstrainIds);
foreach (RigidLink link in linkList)
{
LinkConstraint constraint; //Reasign cached/read contraint
if (constraints.TryGetValue(link.Constraint.Name, out constraint))
link.Constraint = constraint;
Node stNode;
if (nodes.TryGetValue(link.PrimaryNode.Name, out stNode))
link.PrimaryNode = stNode;
for (int i = 0; i < link.SecondaryNodes.Count; i++)
{
Node secNode;
if (nodes.TryGetValue(link.SecondaryNodes[i].Name, out secNode))
link.SecondaryNodes[i] = secNode;
}
}
return linkList;
}
/***************************************************/
private List<LinkConstraint> ReadLinkConstraints(List<string> ids = null)
{
List<LinkConstraint> propList = new List<LinkConstraint>();
int nameCount = 0;
string[] names = { };
m_model.PropLink.GetNameList(ref nameCount, ref names);
ids = FilterIds(ids, names);
foreach (string id in ids)
{
eLinkPropType linkType = eLinkPropType.Linear;
m_model.PropLink.GetTypeOAPI(id, ref linkType);
LinkConstraint constr = LinkConstraint(id, linkType);
if (constr != null)
propList.Add(constr);
else
Engine.Base.Compute.RecordError("Failed to read link constraint with id :" + id);
}
return propList;
}
/***************************************************/
private LinkConstraint LinkConstraint(string name, eLinkPropType linkType)
{
switch (linkType)
{
case eLinkPropType.Linear:
return GetLinearLinkConstraint(name);
case eLinkPropType.Damper:
case eLinkPropType.Gap:
case eLinkPropType.Hook:
case eLinkPropType.PlasticWen:
case eLinkPropType.Isolator1:
case eLinkPropType.Isolator2:
case eLinkPropType.MultilinearElastic:
case eLinkPropType.MultilinearPlastic:
case eLinkPropType.Isolator3:
default:
Engine.Base.Compute.RecordError("Reading of LinkConstraint of type " + linkType + " not implemented");
return null;
}
}
/***************************************************/
private LinkConstraint GetLinearLinkConstraint(string name)
{
bool[] dof = null;
bool[] fix = null;
double[] stiff = null;
double[] damp = null;
double dj2 = 0; //Not sure what this is doing
double dj3 = 0; //Not sure what this is doing
bool stiffCoupled = false;
bool dampCoupled = false;
string notes = null;
string guid = null;
m_model.PropLink.GetLinear(name, ref dof, ref fix, ref stiff, ref damp, ref dj2, ref dj3, ref stiffCoupled, ref dampCoupled, ref notes, ref guid);
LinkConstraint constraint = new LinkConstraint();
constraint.Name = name;
SetAdapterId(constraint, name);
constraint.XtoX = fix[0];
constraint.ZtoZ = fix[1];
constraint.YtoY = fix[2];
constraint.XXtoXX = fix[3];
constraint.YYtoYY = fix[4];
constraint.ZZtoZZ = fix[5];
if (stiff != null && stiff.Any(x => x != 0))
Engine.Base.Compute.RecordWarning("No stiffness read for link constraints");
if (damp != null && damp.Any(x => x != 0))
Engine.Base.Compute.RecordWarning("No damping read for link contraint");
return constraint;
}
/***************************************************/
}
}