Skip to content

Commit f57807c

Browse files
8.3 Deployment (#413)
2 parents 615a846 + 83b9306 commit f57807c

29 files changed

+1026
-272
lines changed

MidasCivil_Adapter/AdapterActions/Execute.cs

Lines changed: 208 additions & 194 deletions
Large diffs are not rendered by default.

MidasCivil_Adapter/CRUD/Read/Properties/SectionProperties.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private List<ISectionProperty> ReadSectionProperties(List<string> ids = null)
5151
for (int i = 0; i < sectionProperties.Count; i++)
5252
{
5353
string line = sectionProperties[i];
54-
if(!(line.Length < 2))
54+
if (!(line.Length < 2))
5555
{
5656
if (types.Any(x => x == sectionProperties[i].Split(',')[1].Trim()))
5757
indexes.Add(i);
@@ -89,7 +89,7 @@ private List<ISectionProperty> ReadSectionProperties(List<string> ids = null)
8989
if (numberColumns == 16)
9090
{
9191
// delimitted[15] is the database name of the section
92-
bhomSectionProperty = (ISectionProperty)Engine.Library.Query.Match("Structure\\SectionProperties",split[15]);
92+
bhomSectionProperty = (ISectionProperty)Engine.Library.Query.Match("Structure\\SectionProperties", split[15]);
9393
if (bhomSectionProperty == null)
9494
Engine.Base.Compute.RecordWarning("The database section " + split[2] + " could not be found in the BHoM datasets - a null value has been assigned.");
9595
else
@@ -110,8 +110,8 @@ private List<ISectionProperty> ReadSectionProperties(List<string> ids = null)
110110
else if (type == "TAPERED")
111111
{
112112
List<string> profiles = sectionProperties[index + 1].Split(',').ToList();
113-
string shape = split[14].Trim();
114-
string interpolationOrder = Math.Max(System.Convert.ToInt32(split[15].Trim()), System.Convert.ToInt32(split[16].Trim())).ToString();
113+
string shape = split[15].Trim();
114+
string interpolationOrder = Math.Max(System.Convert.ToInt32(split[16].Trim()), System.Convert.ToInt32(split[17].Trim())).ToString();
115115

116116
bhomSectionProperty = Adapters.MidasCivil.Convert.ToSectionProperty(profiles, "TAPERED" + "-" + shape + "-" + interpolationOrder, m_lengthUnit);
117117

@@ -166,7 +166,7 @@ private List<ISectionProperty> ReadSectionProperties(List<string> ids = null)
166166
// Inner polylines always follow outer, find the start of the next IPOLY otherwise it's the end of the PSC Section
167167
int iPolyStart = iOPolyEnd + 1;
168168
int iPolyEnd = -2;
169-
if(!(iPolyStart + 1 > pscSectionProperty.Count - 1))
169+
if (!(iPolyStart + 1 > pscSectionProperty.Count - 1))
170170
iPolyEnd = pscSectionProperty.FindIndex(iPolyStart + 1, x => x.Contains("IPOLY")) - 1;
171171

172172
// This is the case where IPOLY is contained on a single line (i.e. three points)
@@ -181,18 +181,18 @@ private List<ISectionProperty> ReadSectionProperties(List<string> ids = null)
181181
// Get indexes for next polyline, IF statement to avoid out of index if there is a single IPOLY
182182
iPolyStart = iPolyEnd + 1;
183183
//This is the last IPOLY
184-
if(iPolyStart > pscSectionProperty.Count() -1)
184+
if (iPolyStart > pscSectionProperty.Count() - 1)
185185
iPolyEnd = -2;
186186
else
187187
iPolyEnd = pscSectionProperty.FindIndex(iPolyStart + 1, x => x.Contains("IPOLY")) - 1;
188188
}
189189

190190
// For the final inner polyline contained on a single line
191-
if (iPolyStart == pscSectionProperty.Count -1 && iPolyEnd == -2)
191+
if (iPolyStart == pscSectionProperty.Count - 1 && iPolyEnd == -2)
192192
{
193193
iPolyEnd = pscSectionProperty.Count - 1;
194194
polys.Add(new Polyline() { ControlPoints = ParsePoints(pscSectionProperty, iPolyStart, iPolyEnd, "IPOLY") });
195-
}
195+
}
196196

197197
}
198198

MidasCivil_Adapter/CRUD/Read/Results/BarResults.cs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
using System.Linq;
2929
using System;
3030
using System.IO;
31+
using System.Threading.Tasks;
3132

3233
namespace BH.Adapter.MidasCivil
3334
{
@@ -40,27 +41,40 @@ public partial class MidasCivilAdapter
4041

4142
public IEnumerable<IResult> ReadResults(BarResultRequest request, ActionConfig actionConfig)
4243
{
43-
List<IResult> results;
44+
List<IResult> results = new List<IResult>();
4445
List<int> objectIds = GetObjectIDs(request);
45-
List<string> loadCases = GetLoadcaseIDs(request);
4646

47-
switch (request.ResultType)
47+
switch (m_midasCivilVersion)
4848
{
49-
case BarResultType.BarForce:
50-
results = ExtractBarForce(objectIds, loadCases).ToList();
51-
break;
52-
case BarResultType.BarStrain:
53-
results = ExtractBarStrain(objectIds, loadCases).ToList();
54-
break;
55-
case BarResultType.BarStress:
56-
results = ExtractBarStress(objectIds, loadCases).ToList();
57-
break;
58-
case BarResultType.BarDisplacement:
59-
results = ExtractBarDisplacement(objectIds, loadCases).ToList();
49+
case "9.5.0.nx":
50+
case "9.5.5.nx":
51+
List<string> loadCasesNX = Task.Run(() => AppendCaseTypes(request)).Result;
52+
string divisions = SetBarDivisions(request);
53+
54+
if (loadCasesNX != null)
55+
results = Task.Run(() => ReadResult(request.ResultType.ToString(), objectIds, loadCasesNX, divisions)).Result.ToList();
6056
break;
6157
default:
62-
Engine.Base.Compute.RecordError($"Result of type {request.ResultType} is not yet supported in the MidasCivil_Toolkit.");
63-
results = new List<IResult>();
58+
List<string> loadCases = GetLoadcaseIDs(request);
59+
switch (request.ResultType)
60+
{
61+
case BarResultType.BarForce:
62+
results = ExtractBarForce(objectIds, loadCases).ToList();
63+
break;
64+
case BarResultType.BarStrain:
65+
results = ExtractBarStrain(objectIds, loadCases).ToList();
66+
break;
67+
case BarResultType.BarStress:
68+
results = ExtractBarStress(objectIds, loadCases).ToList();
69+
break;
70+
case BarResultType.BarDisplacement:
71+
results = ExtractBarDisplacement(objectIds, loadCases).ToList();
72+
break;
73+
default:
74+
Engine.Base.Compute.RecordError($"Result of type {request.ResultType} is not yet supported in the MidasCivil_Toolkit.");
75+
results = new List<IResult>();
76+
break;
77+
}
6478
break;
6579
}
6680
results.Sort();

MidasCivil_Adapter/CRUD/Read/Results/MeshResults.cs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
using System.Collections.Generic;
3030
using System.IO;
3131
using System.Linq;
32+
using System.Threading.Tasks;
3233
namespace BH.Adapter.MidasCivil
3334
{
3435
public partial class MidasCivilAdapter
@@ -40,27 +41,38 @@ public partial class MidasCivilAdapter
4041

4142
public IEnumerable<IResult> ReadResults(MeshResultRequest request, ActionConfig actionConfig)
4243
{
43-
List<IResult> results;
44+
List<IResult> results = new List<IResult>();
4445
List<int> objectIds = GetObjectIDs(request);
45-
List<string> loadCases = GetLoadcaseIDs(request);
46-
47-
switch (request.ResultType)
46+
switch (m_midasCivilVersion)
4847
{
49-
case MeshResultType.Displacements:
50-
results = ExtractMeshDisplacement(objectIds, loadCases).ToList();
51-
break;
52-
case MeshResultType.Forces:
53-
results = ExtractMeshForce(objectIds, loadCases).ToList();
54-
break;
55-
case MeshResultType.Stresses:
56-
results = ExtractMeshStress(objectIds, loadCases, request.Layer).ToList();
57-
break;
58-
case MeshResultType.VonMises:
59-
results = ExtractMeshVonMises(objectIds, loadCases, request.Layer).ToList();
48+
case "9.5.0.nx":
49+
case "9.5.5.nx":
50+
List<string> loadCasesNX = Task.Run(() => AppendCaseTypes(request)).Result;
51+
if (loadCasesNX != null)
52+
results = Task.Run(() => ReadResult(request.ResultType.ToString(), objectIds, loadCasesNX, "", request)).Result.ToList();
6053
break;
6154
default:
62-
Engine.Base.Compute.RecordError($"Result of type {request.ResultType} is not yet supported in the MidasCivil_Toolkit.");
63-
results = new List<IResult>();
55+
List<string> loadCases = GetLoadcaseIDs(request);
56+
57+
switch (request.ResultType)
58+
{
59+
case MeshResultType.Displacements:
60+
results = ExtractMeshDisplacement(objectIds, loadCases).ToList();
61+
break;
62+
case MeshResultType.Forces:
63+
results = ExtractMeshForce(objectIds, loadCases).ToList();
64+
break;
65+
case MeshResultType.Stresses:
66+
results = ExtractMeshStress(objectIds, loadCases, request.Layer).ToList();
67+
break;
68+
case MeshResultType.VonMises:
69+
results = ExtractMeshVonMises(objectIds, loadCases, request.Layer).ToList();
70+
break;
71+
default:
72+
Engine.Base.Compute.RecordError($"Result of type {request.ResultType} is not yet supported in the MidasCivil_Toolkit.");
73+
results = new List<IResult>();
74+
break;
75+
}
6476
break;
6577
}
6678
results.Sort();

MidasCivil_Adapter/CRUD/Read/Results/NodeResults.cs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
using System.Collections.Generic;
3030
using System.IO;
3131
using System.Linq;
32+
using System.Threading.Tasks;
3233

3334
namespace BH.Adapter.MidasCivil
3435
{
@@ -41,21 +42,33 @@ public partial class MidasCivilAdapter
4142

4243
public IEnumerable<IResult> ReadResults(NodeResultRequest request, ActionConfig actionConfig)
4344
{
44-
List<IResult> results;
45+
List<IResult> results = new List<IResult>();
4546
List<int> objectIds = GetObjectIDs(request);
46-
List<string> loadCases = GetLoadcaseIDs(request);
4747

48-
switch (request.ResultType)
48+
switch (m_midasCivilVersion)
4949
{
50-
case NodeResultType.NodeReaction:
51-
results = ExtractNodeReaction(objectIds, loadCases).ToList();
52-
break;
53-
case NodeResultType.NodeDisplacement:
54-
results = ExtractNodeDisplacement(objectIds, loadCases).ToList();
50+
case "9.5.0.nx":
51+
case "9.5.5.nx":
52+
List<string> loadCasesNX = Task.Run(() => AppendCaseTypes(request)).Result;
53+
if (loadCasesNX != null)
54+
results = Task.Run(() => ReadResult(request.ResultType.ToString(), objectIds, loadCasesNX)).Result.ToList();
5555
break;
5656
default:
57-
Engine.Base.Compute.RecordError($"Result of type {request.ResultType} is not yet supported in the MidasCivil_Toolkit.");
58-
results = new List<IResult>();
57+
List<string> loadCases = GetLoadcaseIDs(request);
58+
59+
switch (request.ResultType)
60+
{
61+
case NodeResultType.NodeReaction:
62+
results = ExtractNodeReaction(objectIds, loadCases).ToList();
63+
break;
64+
case NodeResultType.NodeDisplacement:
65+
results = ExtractNodeDisplacement(objectIds, loadCases).ToList();
66+
break;
67+
default:
68+
Engine.Base.Compute.RecordError($"Result of type {request.ResultType} is not yet supported in the MidasCivil_Toolkit.");
69+
results = new List<IResult>();
70+
break;
71+
}
5972
break;
6073
}
6174
results.Sort();

MidasCivil_Adapter/CRUD/Read/Results/ReadResults.cs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ private List<int> GetObjectIDs(IResultRequest request)
4949

5050
if (ids == null || ids.Count == 0)
5151
{
52-
return GetAllIds(request as dynamic);
52+
switch (m_midasCivilVersion)
53+
{
54+
case "9.5.0.nx":
55+
case "9.5.5.nx":
56+
List<int> emptyIds = new List<int>();
57+
return emptyIds;
58+
default:
59+
return GetAllIds(request as dynamic);
60+
}
5361
}
5462
else
5563
{
@@ -130,7 +138,7 @@ private List<string> GetLoadcaseIDs(IResultRequest request)
130138
IList cases = request.Cases;
131139
List<string> caseNames = new List<string>();
132140
if (cases == null || cases.Count == 0)
133-
{
141+
{
134142
caseNames = GetSectionText("STLDCASE").Select(x => x.Split(',')[0].Trim()).ToList();
135143

136144
List<string> loadCombinationText = GetSectionText("LOADCOMB");
@@ -139,19 +147,21 @@ private List<string> GetLoadcaseIDs(IResultRequest request)
139147
caseNames.Add(loadCombinationText[i].Split(',')[0].Split('=')[1].Trim());
140148
}
141149
}
142-
foreach (object thisCase in cases)
150+
151+
foreach (object thisCase in cases)
152+
{
153+
if (thisCase is ICase)
143154
{
144-
if (thisCase is ICase)
145-
{
146-
ICase bhCase = thisCase as ICase;
147-
caseNames.Add(bhCase.Name.ToString());
148-
}
149-
else if (thisCase is string)
150-
{
151-
string caseId = thisCase as string;
152-
caseNames.Add(caseId);
153-
}
155+
ICase bhCase = thisCase as ICase;
156+
caseNames.Add(bhCase.Name.ToString());
157+
}
158+
else if (thisCase is string)
159+
{
160+
string caseId = thisCase as string;
161+
caseNames.Add(caseId);
154162
}
163+
}
164+
155165
return caseNames;
156166
}
157167

@@ -172,7 +182,7 @@ private static string ExcelToCsv(string path)
172182
Application excel = new Application();
173183
Workbook xlsFile = excel.Workbooks.Open(path);
174184
Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)xlsFile.Sheets[1];
175-
185+
176186
sheet.SaveAs(
177187
csvPath,
178188
Microsoft.Office.Interop.Excel.XlFileFormat.xlCSV,
@@ -202,7 +212,6 @@ private static string GetCSVFile(string path)
202212
}
203213

204214
/***************************************************/
205-
206215
}
207216
}
208217

MidasCivil_Adapter/Convert/ToBHoM/Elements/ToRigidLink.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public static RigidLink ToRigidLink(string rigidLink, Dictionary<string, Node> n
5555
case "9.4.5":
5656
case "9.5.0":
5757
case "9.5.0.nx":
58+
case "9.5.5.nx":
5859
primaryId = delimitted[0].Trim();
5960
fixity = delimitted[1].Replace(" ", "");
6061
secondaryIds = delimitted[2].Split(' ').Where(m => !string.IsNullOrWhiteSpace(m)).ToList();

MidasCivil_Adapter/Convert/ToBHoM/Results/ToBarForce.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using System.Linq;
2727
using System.Collections.Generic;
2828
using BH.Adapter.Adapters.MidasCivil;
29+
using System.Text.Json;
2930

3031
namespace BH.Adapter.MidasCivil
3132
{
@@ -60,6 +61,32 @@ public static BarForce ToBarForce(this List<string> delimitted, string forceUnit
6061
return barforce;
6162
}
6263

64+
/***************************************************/
65+
public static BarForce ToBarForce(List<object> item)
66+
{
67+
double position = GetBarResultPosition(item[3].ToString());
68+
//TODO: resolve below identifiers extractable through the API
69+
int mode = -1;
70+
double timeStep = 0;
71+
int divisions = 0;
72+
73+
BarForce barforce = new BarForce(
74+
System.Convert.ToInt32(item[1].ToString()),
75+
item[2].ToString(),
76+
mode,
77+
timeStep,
78+
position,
79+
divisions,
80+
System.Convert.ToDouble(item[4].ToString()),
81+
System.Convert.ToDouble(item[5].ToString()),
82+
System.Convert.ToDouble(item[6].ToString()),
83+
System.Convert.ToDouble(item[7].ToString()),
84+
-System.Convert.ToDouble(item[8].ToString()), //Moments reversed to follow structural convension
85+
-System.Convert.ToDouble(item[9].ToString())
86+
);
87+
return barforce;
88+
}
89+
6390
/***************************************************/
6491
/**** Private Methods ****/
6592
/***************************************************/

0 commit comments

Comments
 (0)