-
Notifications
You must be signed in to change notification settings - Fork 2
/
Form1.cs
1241 lines (1016 loc) · 53.4 KB
/
Form1.cs
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ETABSv1;
using MathNet.Numerics;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.Data.Text;
using LiveCharts;
using LiveCharts.Wpf;
using System.Drawing.Drawing2D;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Windows;
using MessageBox = System.Windows.Forms.MessageBox;
using LiveCharts.Helpers;
using System.Windows.Controls;
using System.Xml.Linq;
namespace SectionCutter
{
public partial class Form1 : Form
{
private cPluginCallback _Plugin = null;
private cSapModel _SapModel = null;
//initiate lists
List<SelectedObjects> SelectedObjectsList;
List<LoadCase> LoadCaseList;
List<AreaPoint> AreaPointList;
List<List<AreaPoint>> AreaPointListStrucIntact;
List<AreaPoint> tempAreaPointList;
List<Line> AreaTempLineList;
List<Line> AreaTempGloLineList;
List<ETABS_Point> ETABsAreaPointsList;
List<ETABS_Point> ETABSAReaPointsListGlo;
List<MyPoint> MyPoints;
List<MyPoint> MyTempPoints;
// lists of lines from selected polygons
List<List<Line>> AreaLineList;
List<List<MyPoint>> MyGlobalAreaPoints;
List<List<Line>> AreaLineListGlo;
List<MyPoint> AreaTempPointList;
//the unique label of the starting point in ETABs
string startPoint = null;
VectorValue vectorXValue = new VectorValue();
VectorValue vectorYValue = new VectorValue();
List<string> selectedLoadSteps;
private List<SectionResults> listSectionResults;
private double[] range_values;
List<List<String>> ETABs_Section_Cut_Data = new List<List<String>>();
LiveCharts.Wpf.LineSeries cutSeries; // Declare cutSeries outside the loop
List<double> sectionCutLength = new List<double>();
int mySelectedSectionIndex = 0;
List<string> mySelectedCases = new List<string>();
public Form1(ref cSapModel SapModel, ref cPluginCallback Plugin)
{
_Plugin = Plugin;
_SapModel = SapModel;
InitializeComponent();
this.Load += Form1_Load;
// Load Steps that Want to be plotted
selectedLoadSteps = new List<string>();
// Attach the SelectionChangeCommitted event handler
listBoxLoadSteps.SelectedIndexChanged += ListBox_SelectedIndexChanged;
}
private void Form1_Paint(object send, PaintEventArgs e)
{
Graphics mgraphics = e.Graphics;
Pen pen = new Pen(Color.FromArgb(255, 140, 105), 1);
Rectangle area = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
System.Drawing.Drawing2D.LinearGradientBrush lGB2 = new System.Drawing.Drawing2D.LinearGradientBrush(area, Color.FromArgb(255, 255, 255), Color.FromArgb(159, 159, 159), LinearGradientMode.Vertical);
mgraphics.FillRectangle(lGB2, area);
mgraphics.DrawRectangle(pen, area);
}
private void Form1_Load(object sender, EventArgs e)
{
this.Paint -= Form1_Paint;
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
// must include a call to finish()
_Plugin.Finish(0);
}
static int FindFirstIndex(List<string> list, string searchString)
{
for (int i = 0; i < list.Count; i++)
{
if (list[i] == searchString)
{
return i; // Return the index if the string is found
}
}
return -1; // Return -1 if the string is not found in the list
}
private void ShowLoadCase_Load(object sender, EventArgs e)
{
// Clear the existing items in LoadCaseList and LoadCaseComBox
if (LoadCaseList != null)
{
LoadCaseList.Clear();
LoadCaseComBox.Items.Clear();
}
int NumberNames = 1;
string[] MyName = null;
int NumberItems = 0;
string[] CaseName = null;
int[] status = null;
_SapModel.LoadCases.GetNameList(ref NumberNames, ref MyName);
_SapModel.Analyze.GetCaseStatus(ref NumberItems, ref CaseName, ref status);
LoadCaseList = new List<LoadCase>();
for (int i = 0; i < MyName.Length; i++)
{
LoadCase LComb = new LoadCase();
LComb.NumberNames = NumberNames;
LComb.MyName = MyName[i];
LComb.Status = status[i];
//This is used to determine if the load case is linear static, if it is, check to see if there is an auto seismic/wind case.
string Name = MyName[i];
eLoadCaseType CaseType = new eLoadCaseType();
int SubType = 0;
eLoadPatternType DesignType = new eLoadPatternType();
int DesignTypeOption = 0;
int Auto = 0;
_SapModel.LoadCases.GetTypeOAPI_1(Name, ref CaseType, ref SubType, ref DesignType, ref DesignTypeOption, ref Auto);
//If it is linear static, let's determine if there is autoseismic/autowind in the case in question. This gathers all the load patterns in a load case
if (CaseType == eLoadCaseType.LinearStatic)
{
int NumberLoads = 0;
string[] LoadType = null;
string[] LoadName = null;
double[] SF = null;
_SapModel.LoadCases.StaticLinear.GetLoads(Name, ref NumberItems, ref LoadType, ref LoadName, ref SF);
foreach (string loadName in LoadName)
{
eLoadPatternType MyType = new eLoadPatternType();
_SapModel.LoadPatterns.GetLoadType(loadName, ref MyType);
if (MyType == eLoadPatternType.Quake)
{
string CodeName = "";
_SapModel.LoadPatterns.GetAutoSeismicCode(loadName, ref CodeName);
if (CodeName == "ASCE 7-16")
{
string myTableKey = "Load Pattern Definitions - Auto Seismic - ASCE 7-16";
string[] FieldKeyList = null;
string GroupName = "";
int TableVersion = 0;
string[] FieldsKeysIncluded = null;
int NumberRecords = 0;
string[] TableData = null;
_SapModel.DatabaseTables.GetTableForDisplayArray(myTableKey, ref FieldKeyList, GroupName, ref TableVersion, ref FieldsKeysIncluded, ref NumberRecords, ref TableData);
//string[] seismicInfo = new string[6]; // Assuming you want 6 elements (index 2 to 7 inclusive)
List<string> seismicInfo = new List<string>();
int indexofinterest = FindFirstIndex(TableData.ToList(), Name);
for (int z = indexofinterest; z < indexofinterest + 6; z++)
{
seismicInfo.Add(TableData.ToList()[z+2]);
}
//Array.Copy(TableData, 2, seismicInfo, indexofinterest, indexofinterest + 6); // Copies 6 elements starting from index 2
string[] SeismicName = { "EQx", "EQx + E", "EQx - E", "EQy", "EQy + E", "EQy - E" };
// Create the dictionary, this contains what type of loads are included.
LComb.SeismicInfo = new Dictionary<string, bool>();
List<string> seismicDir = new List<string>();
// Populate the dictionary
for (int j = 0; j < SeismicName.Length; j++)
{
bool seis; // Declare seis outside of if-else blocks
if (seismicInfo[j] == "Yes")
{
seis = true;
seismicDir.Add(SeismicName[j]);
//LComb.SeismicLoadDirection is a list that will contain only the load directions that exist
}
else
{
seis = false;
}
LComb.SeismicInfo.Add(SeismicName[j], seis);
LComb.SeismicLoadDirection = seismicDir;
}
}
else if (CodeName == "ASCE 7-22")
{
string myTableKey = "Load Pattern Definitions - Auto Seismic - ASCE 7-22";
string[] FieldKeyList = null;
string GroupName = "";
int TableVersion = 0;
string[] FieldsKeysIncluded = null;
int NumberRecords = 0;
string[] TableData = null;
_SapModel.DatabaseTables.GetTableForDisplayArray(myTableKey, ref FieldKeyList, GroupName, ref TableVersion, ref FieldsKeysIncluded, ref NumberRecords, ref TableData);
List<string> seismicInfo = new List<string>();
int indexofinterest = FindFirstIndex(TableData.ToList(), Name);
for (int z = indexofinterest; z < indexofinterest + 6; z++)
{
seismicInfo.Add(TableData.ToList()[z]);
}
string[] SeismicName = { "EQx", "EQx + E", "EQx - E", "EQy", "EQy + E", "EQy - E" };
// Create the dictionary this contains what type of loads are included.
LComb.SeismicInfo = new Dictionary<string, bool>();
// Populate the dictionary
for (int j = 0; j < SeismicName.Length; j++)
{
bool seis; // Declare seis outside of if-else blocks
if (seismicInfo[j] == "Yes")
{
seis = true;
}
else
{
seis = false;
}
// Assuming seismicInfo[i] contains "True" or "False", you need to convert it to bool
LComb.SeismicInfo.Add(SeismicName[j], seis);
}
}
else
{
return;
}
}
}
}
LoadCaseComBox.Items.Add(MyName[i]);
LoadCaseList.Add(LComb);
}
// Set the DrawMode to OwnerDrawFixed to enable custom drawing of items
LoadCaseComBox.DrawMode = DrawMode.OwnerDrawFixed;
// Subscribe to the DrawItem event
LoadCaseComBox.DrawItem += LoadCaseComBox_DrawItem;
}
// Function that changes the background color of the combo box dropdown menu
// items to green if the status is 4 (this means the results are available from the selected load case)
private void LoadCaseComBox_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index >= 0)
{
LoadCase LComb = LoadCaseList[e.Index];
// Set the text color to green if the status is 4
Brush brush = (LComb.Status == 4) ? Brushes.Green : Brushes.Black;
// Draw the item text with the specified color
e.Graphics.DrawString(LoadCaseComBox.Items[e.Index].ToString(), e.Font, brush, e.Bounds, StringFormat.GenericDefault);
// If the item is selected, draw the focus rectangle
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
e.DrawFocusRectangle();
}
}
}
private void getSelNodeBtn_Click(object sender, EventArgs e)
{
int NumberItems = 0;
int[] ObjectType = null;
string[] ObjectName = null;
_SapModel.SelectObj.GetSelected(ref NumberItems, ref ObjectType, ref ObjectName);
SelectedObjectsList = new List<SelectedObjects>();
//test to make sure the selected object is only 1 element long and a node
if (ObjectType == null )
{
MessageBox.Show("Select node first, then click the button");
}
else if (ObjectType.Length > 1 || ObjectType[0] != 1)
{
MessageBox.Show("Select only one node");
}
else
{
for (int i = 0; i < ObjectType.Length; i++)
{
SelectedObjects SelectedObject = new SelectedObjects();
SelectedObject.ObjectType = ObjectType[i];
SelectedObject.ObjectName = ObjectName[i];
startPoint = ObjectName[i];
SelectedObjectsList.Add(SelectedObject);
}
dataGridView1.DataSource = SelectedObjectsList;
}
}
private void getSelAreas_Click(object sender, EventArgs e)
{
int NumberItems = 0;
int[] ObjectType = null;
string[] ObjectName = null;
_SapModel.SelectObj.GetSelected(ref NumberItems, ref ObjectType, ref ObjectName);
SelectedObjectsList = new List<SelectedObjects>();
AreaPointList = new List<AreaPoint>();
AreaPointListStrucIntact = new List<List<AreaPoint>>();
int openings = 0;
int areas_selected = 0;
// ensures users select an object first
if (ObjectType == null)
{
MessageBox.Show("Select area(s) first, then click the button");
}
else
{
//individual area, areas are made of points
for (int i = 0; i < ObjectType.Length; i++)
{
tempAreaPointList = new List<AreaPoint>();
SelectedObjects SelectedObject = new SelectedObjects();
SelectedObject.ObjectType = ObjectType[i];
SelectedObject.ObjectName = ObjectName[i];
int NumberAreaPoints = 0;
string[] ObjectNamePnts = null;
//if the object type is 5, this is a floor/opening
if (ObjectType[i] == 5)
{
SelectedObjectsList.Add(SelectedObject);
_SapModel.AreaObj.GetPoints(ObjectName[i], ref NumberAreaPoints, ref ObjectNamePnts);
bool IsOpening = false;
_SapModel.AreaObj.GetOpening(ObjectName[i], ref IsOpening);
if (IsOpening)
{
openings += 1;
}
else
{
areas_selected += 1;
}
//set the label string for # of openings
Opening_Label.Visible = true;
Opening_Label.Text = openings.ToString();
Area_Label.Visible = true;
Area_Label.Text = areas_selected.ToString();
//this accesses all points associated with area edges
for (int j = 0; j < ObjectNamePnts.Length; j++)
{
AreaPoint AreaPointObject = new AreaPoint();
AreaPointObject.NumberPoints = NumberAreaPoints;
AreaPointObject.Points = ObjectNamePnts[j];
AreaPointList.Add(AreaPointObject);
tempAreaPointList.Add(AreaPointObject);
}
AreaPointListStrucIntact.Add(tempAreaPointList);
}
else
{
;
}
}
//writes data to data
dataGridView2.DataSource = SelectedObjectsList;
}
}
private void vectorX_TextChanged(object sender, EventArgs e)
{
VectorValue vectorXValue = new VectorValue();
try
{
//need to fix this, currently this does not work
vectorXValue.Value = double.Parse(vectorX.Text);
}
catch (FormatException)
{
MessageBox.Show("You must enter decimal number");
}
}
private void vectorY_TextChanged(object sender, EventArgs e)
{
VectorValue vectorYValue = new VectorValue();
try
{
//need to fix this, currently this does not work
vectorYValue.Value = double.Parse(vectorY.Text);
}
catch (FormatException)
{
MessageBox.Show("You must enter decimal number");
}
}
//function below limits the input to a decimal number
private void vectorX_KeyPress(object sender, KeyPressEventArgs e)
{
vectorX.MaxLength = 6;
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
(e.KeyChar != '.'))
{
e.Handled = true;
}
// only allow one decimal point
if ((e.KeyChar == '.') && ((sender as System.Windows.Forms.TextBox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
}
private void vectorX_Enter(object sender, EventArgs e)
{
vectorX.Text = "";
vectorX.ForeColor = Color.Black;
}
private void vectorY_Enter(object sender, EventArgs e)
{
vectorY.Text = "";
vectorY.ForeColor = Color.Black;
}
//limits input to numbers
private void numSlices_KeyPress(object sender, KeyPressEventArgs e)
{
vectorX.MaxLength = 6;
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
(e.KeyChar != '.'))
{
e.Handled = true;
}
// only allow one decimal point
}
//this function checks to make sure inputted value is above 2 and below 1000
private void NumSlices_Leave(object sender, EventArgs e)
{
int num_slices = 0;
Int32.TryParse(NumSlices.Text, out num_slices);
if (num_slices < 1 && NumSlices.Text != "")
{
NumSlices.Text = "2";
MessageBox.Show("Minimum Allowed Cuts is 2");
}
else if (num_slices > 1000 && NumSlices.Text != "")
{
NumSlices.Text = "1000";
MessageBox.Show("Maximum Allowed Cuts is 1000");
}
}
//this function clears current input
private void NumSlices_Enter(object sender, EventArgs e)
{
NumSlices.Text = "";
NumSlices.ForeColor = Color.Black;
}
public static double[] linspace(double startval, double endval, int steps)
{
double interval = (endval / Math.Abs(endval)) * Math.Abs(endval - startval) / (steps - 1);
return (from val in Enumerable.Range(0, steps)
select startval + (val * interval)).ToArray();
}
private void ListBox_SelectedIndexChanged(object sender, EventArgs e)
{
// Clear the selectedSections list
selectedLoadSteps.Clear();
// Add the selected items to the selectedSections list
foreach (var item in listBoxLoadSteps.SelectedItems)
{
selectedLoadSteps.Add(item.ToString());
}
PlotResults.GraphShearResults(listSectionResults, selectedLoadSteps, range_values, shearScatterPlot, mySelectedSectionIndex);
PlotResults.GraphMomentResults(listSectionResults, selectedLoadSteps, range_values, momentScatterPlot, mySelectedSectionIndex);
}
private void ListBox_SelectedResultsChanged(object sender, EventArgs e)
{
string mySelectedResults = listBoxResultSelected.SelectedItem.ToString();
List<TabularData> TabDataList = new List<TabularData>();
int mySelectedResultsInt = listSectionResults.FindIndex(x => x.LoadDirection == mySelectedResults);
for (int i = 0; i < listSectionResults[mySelectedResultsInt].F2.Length; i++)
{
TabularData sampleData = new TabularData();
sampleData.Location = range_values[i];
sampleData.Length = sectionCutLength[i];
sampleData.Shear = listSectionResults[mySelectedResultsInt].F1[i];
sampleData.Moment = listSectionResults[mySelectedResultsInt].M3[i];
sampleData.Axial = listSectionResults[mySelectedResultsInt].F2[i];
TabDataList.Add(sampleData);
}
dataGridView3.DataSource = TabDataList;
}
private void runAnalysis_Click(object sender, EventArgs e)
{
//Test if analysis needs to be run
string mySelectedCase = LoadCaseComBox.SelectedItem.ToString();
int index = LoadCaseList.FindIndex(x => x.MyName == mySelectedCase);
// Clear existing items in the combo box
listBoxLoadSteps.Items.Clear();
// Ensure LoadCaseList is not null
if (LoadCaseList != null)
{
// Ensure SeismicInfo is not null
if (LoadCaseList[index].SeismicInfo != null)
{
// Iterate over the key-value pairs in SeismicInfo
foreach (var kvp in LoadCaseList[index].SeismicInfo)
{
// Check if the value is true
if (kvp.Value)
{
listBoxLoadSteps.Items.Add(kvp.Key);
listBoxResultSelected.Items.Add(kvp.Key);
}
}
}
}
if (US_Units.Checked == true)
{
_SapModel.SetPresentUnits(eUnits.kip_ft_F);
}
else
{
_SapModel.SetPresentUnits(eUnits.kN_m_C);
}
shearScatterPlot.Visible = true;
momentScatterPlot.Visible = true;
locationPlot.Visible = true;
string Name = null;
double X = 0;
double Y = 0;
double Z = 0;
_SapModel.PointObj.GetCoordCartesian(startPoint, ref X, ref Y, ref Z);
ETABS_Point ref_Point = new ETABS_Point();
ref_Point.X = X;
ref_Point.Y = Y;
ref_Point.Z = Z;
List<double> refPoint = new List<double>() { X, Y, Z };
List<double> vector = new List<double>() { double.Parse(vectorX.Text), double.Parse(vectorY.Text), 0 };
GlobalCoordinateSystem gcs = new GlobalCoordinateSystem(refPoint, vector);
ETABsAreaPointsList = new List<ETABS_Point>();
ETABSAReaPointsListGlo = new List<ETABS_Point>();
AreaLineList = new List<List<Line>>();
AreaLineListGlo = new List<List<Line>>();
MyGlobalAreaPoints = new List<List<MyPoint>>();
MyPoints = new List<MyPoint>();
MyTempPoints = new List<MyPoint>();
/// AreaPointListStrucIntact includes
for (int i = 0; i < AreaPointListStrucIntact.Count; i++)
{
AreaTempLineList = new List<Line>();
AreaTempGloLineList = new List<Line>();
AreaTempPointList = new List<MyPoint>();
MyTempPoints = new List<MyPoint>();
for (int j = 0; j <= AreaPointListStrucIntact[i].Count; j++)
{
if (j < AreaPointListStrucIntact[i].Count)
{
_SapModel.PointObj.GetCoordCartesian(AreaPointListStrucIntact[i][j].Points, ref X, ref Y, ref Z);
ETABS_Point samplePoint = new ETABS_Point();
samplePoint.X = X;
samplePoint.Y = Y;
samplePoint.Z = Z;
ETABSAReaPointsListGlo.Add(samplePoint);
List<double> myPoint = new List<double>() { X, Y, Z };
MyPoint point = new MyPoint(myPoint);
point.X = myPoint[0];
point.Y = myPoint[1];
point.Z = myPoint[2];
//MyPoint point = new MyPoint(myPoint);
point.glo_to_loc(gcs);
ETABS_Point localPoint = new ETABS_Point();
localPoint.X = point.LocalCoords[0];
localPoint.Y = point.LocalCoords[1];
localPoint.Z = point.LocalCoords[2];
ETABsAreaPointsList.Add(localPoint);
List<double> myTempPoint = new List<double>() { X, Y, Z };
MyPoint LCpointArea = new MyPoint(myTempPoint);
LCpointArea.X = point.LocalCoords[0];
LCpointArea.Y = point.LocalCoords[1];
LCpointArea.Z = point.LocalCoords[2];
//we are adding the local coordinates of the line segements to the list
MyPoints.Add(LCpointArea);
MyTempPoints.Add(LCpointArea);
AreaTempPointList.Add(point);
}
else
{
}
MyGlobalAreaPoints.Add(AreaTempPointList);
if (j >= 1 && j < AreaPointListStrucIntact[i].Count)
{
Line myLine = new Line();
myLine.startPoint = MyTempPoints[j - 1];
myLine.endPoint = MyTempPoints[j];
Line myGlobalLine = new Line();
myGlobalLine.startPoint = AreaTempPointList[j - 1];
myGlobalLine.endPoint = AreaTempPointList[j];
AreaTempLineList.Add(myLine);
AreaTempGloLineList.Add(myGlobalLine);
}
else if (j == 0)
{
}
else
{
Line myLine = new Line();
myLine.startPoint = MyTempPoints[j - 1];
myLine.endPoint = MyTempPoints[0];
AreaTempLineList.Add(myLine);
Line myGlobalLine = new Line();
myGlobalLine.startPoint = AreaTempPointList[j - 1];
myGlobalLine.endPoint = AreaTempPointList[0];
AreaTempGloLineList.Add(myGlobalLine);
}
}
AreaLineList.Add(AreaTempLineList);
AreaLineListGlo.Add(AreaTempGloLineList);
}
//this gathers all of the XYZ points of the area objects to determine the max and the minimum U and V values
for (int i = 0; i < AreaPointList.Count; i++)
{
_SapModel.PointObj.GetCoordCartesian(AreaPointList[i].Points, ref X, ref Y, ref Z);
List<double> myPoint = new List<double>() { X, Y, Z };
MyPoint point = new MyPoint(myPoint);
point.X = myPoint[0];
point.Y = myPoint[1];
point.Z = myPoint[2];
point.glo_to_loc(gcs);
ETABS_Point localPoint = new ETABS_Point();
localPoint.X = point.LocalCoords[0];
localPoint.Y = point.LocalCoords[1];
localPoint.Z = point.LocalCoords[2];
ETABsAreaPointsList.Add(localPoint);
}
//Finds the max U and V values
double Umax = ETABsAreaPointsList.Max(x => x.X);
double Umin = ETABsAreaPointsList.Min(x => x.X);
double Vmax = ETABsAreaPointsList.Max(x => x.Y);
double Vmin = ETABsAreaPointsList.Min(x => x.Y);
//angle for rotating the local axis of the section cut
double angle = 0;
if (double.Parse(vectorY.Text) == 0)
{
angle = 90;
}
else
{
angle = Math.Atan(double.Parse(vectorX.Text) / double.Parse(vectorY.Text)) * 180 * Math.PI;
}
double distance = Umax - Umin;
int n_cuts = int.Parse(NumSlices.Text);
double height = ref_Point.Z;
// creates a list of values between max and min u values.
range_values = linspace(Umin + 1, Umax - 1, n_cuts);
//creates the lists of 4 points
List<List<MyPoint>> sectionPlanes = new List<List<MyPoint>>();
ETABs_Section_Cut_Data = new List<List<String>>();
sectionCutLength = new List<double>();
/////// Generating all of the data to be utilized to make the section cuts /////
int counter = 0;
foreach (double i in range_values)
{
List<double> tempPoint1 = new List<double>() { i, Vmin, height - 0.5 };
List<double> tempPoint2 = new List<double>() { i, Vmax, height + 0.5 };
MyPoint sectionPoint1 = new MyPoint(tempPoint1);
MyPoint sectionPoint2 = new MyPoint(tempPoint2);
List<MyPoint> xingPoints = new List<MyPoint>();
//Find intersection point with main polygon
RayCasting.RayCast(sectionPoint1, sectionPoint2, gcs, AreaLineList, out int countCrosses, ref xingPoints);
List<MyPoint> sectionPlane = new List<MyPoint>();
List<double> listPoint1 = new List<double>() { xingPoints[0].X, xingPoints[0].Y, height - 0.5 };
List<double> listPoint2 = new List<double>() { xingPoints[0].X, xingPoints[0].Y, height + 0.5 };
List<double> listPoint3 = new List<double>() { xingPoints[1].X, xingPoints[1].Y, height + 0.5 };
List<double> listPoint4 = new List<double>() { xingPoints[1].X, xingPoints[1].Y, height - 0.5 };
sectionCutLength.Add(Math.Sqrt(Math.Pow(xingPoints[1].X - xingPoints[0].X, 2) + Math.Pow(xingPoints[1].Y - xingPoints[0].Y, 2)));
string name = counter.ToString().PadLeft(4, '0');
List<string> string1 = new List<string>
{ name, "Quads", "All", "Analysis", "Default", angle.ToString(), "0", "0", "Top or Right or Positive3", "1", "1", "1",
listPoint1[0].ToString(), listPoint1[1].ToString(), listPoint1[2].ToString(), "1"
};
List<string> string2 = new List<string>
{ name, null, null, null, null, null, null, null, null, null, "1", "2",
listPoint2[0].ToString(), listPoint2[1].ToString(), listPoint2[2].ToString(), null
};
List<string> string3 = new List<string>
{ name, null, null, null, null, null, null, null, null, null, "1", "3",
listPoint3[0].ToString(), listPoint3[1].ToString(), listPoint3[2].ToString(), null
};
List<string> string4 = new List<string>
{ name, null, null, null, null, null, null, null, null, null, "1", "4",
listPoint4[0].ToString(), listPoint4[1].ToString(), listPoint4[2].ToString(), null
};
ETABs_Section_Cut_Data.Add(string1);
ETABs_Section_Cut_Data.Add(string2);
ETABs_Section_Cut_Data.Add(string3);
ETABs_Section_Cut_Data.Add(string4);
counter++;
}
string TableKey = "Section Cut Definitions";
string[] FieldKeysIncluded = ETABs_Section_Cut_Data.SelectMany(x => x).ToArray();
int TableVersiontest = 1;
string[] FieldKeysIncludedtest = new string[] { "Name", "DefinedBy", "Group", "ResultType", "ResultLoc", "RotAboutZ", "RotAboutY", "RotAboutX",
"ElementSide", "NumQuads", "QuadNum", "PointNum", "QuadX", "QuadY", "QuadZ", "GUID" };
int NumberRecordstest = ETABs_Section_Cut_Data.Count * 4;
_SapModel.DatabaseTables.SetTableForEditingArray(TableKey, ref TableVersiontest, ref FieldKeysIncludedtest, NumberRecordstest, ref FieldKeysIncluded);
bool FillImportLog = true;
int NumFatalErrors = 0;
int NumErrorMsgs = 0;
int NumWarnMsgs = 0;
int NumInfoMsgs = 0;
string ImportLog = "";
int ret = 1;
ret = _SapModel.DatabaseTables.ApplyEditedTables(FillImportLog, ref NumFatalErrors, ref NumErrorMsgs, ref NumWarnMsgs, ref NumInfoMsgs, ref ImportLog);
DatabaseTableInfo databaseTableInfo = new DatabaseTableInfo();
databaseTableInfo.NumErrorMsgs = NumErrorMsgs;
databaseTableInfo.ImportLog = ImportLog;
//_SapModel.SetModelIsLocked(false);
//_SapModel.Analyze.RunAnalysis();
//If results are available, do not rerun the analysis.
if (LoadCaseList[index].Status != 4)
{
// Display the message box
MessageBox.Show("This requires you to rerun the analysis", "Rerun", MessageBoxButtons.OK, MessageBoxIcon.Warning);
_SapModel.GetModelIsLocked();
_SapModel.Analyze.RunAnalysis();
}
_SapModel.Results.Setup.DeselectAllCasesAndCombosForOutput();
_SapModel.Results.Setup.SetCaseSelectedForOutput(LoadCaseComBox.SelectedItem.ToString());
int NumberTables = 0;
string[] TableKey2 = null;
string[] TableName2 = null;
int[] ImportType2 = null;
_SapModel.DatabaseTables.GetAvailableTables(ref NumberTables, ref TableKey2, ref TableName2, ref ImportType2);
string TableKey3 = "Section Cut Forces - Analysis";
string[] FieldKeyList = null;
string GroupName = "All";
int TableVersion = 1;
string[] FieldKeysIncluded2 = null;
int NumRecords = 0;
string[] TableData2 = null;
_SapModel.DatabaseTables.GetTableForDisplayArray(TableKey3, ref FieldKeyList, GroupName, ref TableVersion, ref FieldKeysIncluded2, ref NumRecords, ref TableData2);
//THIS IS THE LIST TO HOLD ALL LOAD STEP RESULTS FOR A SELECTED LOAD CASE WITH STEPS
listSectionResults = new List<SectionResults>();
//this is the multiple load steps
if (FieldKeysIncluded2.Contains("StepNumber"))
{
//This list will contain all of the results from one load case with multiplesteps
List<int> indices = new List<int>();
// Find indices of "EqAll" in TableData2
int loadSteps = listBoxLoadSteps.Items.Count;
indices = SectionCutResults.FindIndices(TableData2, LoadCaseComBox.SelectedItem.ToString());
//int step = indices.Count() / loadSteps;
// Grab specific items by index using LINQ
var specificItems = indices.Where((item, index2) => index2 % loadSteps == 0);
List<string> OrderedSeismicList = new List<string>();
OrderedSeismicList = LoadCaseList[index].GetOrderedSeismicDirections();
//run from 0 to load steps
for (int i = 0; i < loadSteps; i++)
{
List<Double> F1loop = new List<double>();
List<Double> F2loop = new List<double>();
List<Double> F3loop = new List<double>();
List<Double> M1loop = new List<double>();
List<Double> M2loop = new List<double>();
List<Double> M3loop = new List<double>();
//IF THIS TABLE GETS REWORKED IN THE FUTURE, THIS WILL NEED TO BE RECODED!!!
SectionResults loadCaseResults = new SectionResults();
//AREA OF INTEREST
//note index is the corresponding loadcase selected in the LoadCaseList
//This is Eq X, Eq X e+ etc.
loadCaseResults.LoadDirection = OrderedSeismicList[i];
//We generatate all of the results for an individual load case, load step in this loop here.
foreach (int sectionResult in specificItems)
{
F1loop.Add(Convert.ToDouble(TableData2[sectionResult + i * 14 + 4]));
F2loop.Add(Convert.ToDouble(TableData2[sectionResult + i * 14 + 5]));
F3loop.Add(Convert.ToDouble(TableData2[sectionResult + i * 14 + 6]));
M1loop.Add(Convert.ToDouble(TableData2[sectionResult + i * 14 + 7]));
M2loop.Add(Convert.ToDouble(TableData2[sectionResult + i * 14 + 8]));
M3loop.Add(Convert.ToDouble(TableData2[sectionResult + i * 14 + 9]));
}
loadCaseResults.F1 = F1loop.ToArray();
loadCaseResults.F2 = F2loop.ToArray();
loadCaseResults.F3 = F3loop.ToArray();
loadCaseResults.M1 = M1loop.ToArray();
loadCaseResults.M2 = M2loop.ToArray();
loadCaseResults.M3 = M3loop.ToArray();
listSectionResults.Add(loadCaseResults);
}
}
else
{
int NumberResults = 1;
string[] SCut = new string[0];
string[] LoadCase = new string[0];
string[] StepType = new string[0];
double[] StepNum = new double[0];
double[] F1 = new double[0];
double[] F2 = new double[0];
double[] F3 = new double[0];
double[] M1 = new double[0];
double[] M2 = new double[0];
double[] M3 = new double[0];
_SapModel.Results.SectionCutAnalysis(ref NumberResults, ref SCut, ref LoadCase, ref StepType, ref StepNum, ref F1, ref F2, ref F3, ref M1, ref M2, ref M3);
SectionResults sectionResults = new SectionResults();
sectionResults.F1 = F1;
sectionResults.F2 = F2;
sectionResults.F3 = F3;
sectionResults.M1 = M1;
sectionResults.M2 = M2;
sectionResults.M3 = M3;
listSectionResults.Add(sectionResults);
}
List<TabularData> TabDataList = new List<TabularData>();
if (listSectionResults.Count > 1 )
{
listBoxResultSelected.SetSelected(0, true);
string mySelectedResults = listBoxResultSelected.Items[0].ToString();
int mySelectedResultsInt = listSectionResults.FindIndex(x => x.LoadDirection == mySelectedResults);
for (int i = 0; i < listSectionResults[mySelectedResultsInt].F2.Length; i++)
{
TabularData sampleData = new TabularData();
sampleData.Location = range_values[i];
sampleData.Length = sectionCutLength[i];
sampleData.Shear = listSectionResults[mySelectedResultsInt].F1[i];
sampleData.Moment = listSectionResults[mySelectedResultsInt].M3[i];
sampleData.Axial = listSectionResults[mySelectedResultsInt].F2[i];
TabDataList.Add(sampleData);
}
dataGridView3.DataSource = TabDataList;
listBoxResultSelected.SelectedIndexChanged += ListBox_SelectedResultsChanged;
}
else
{
for (int i = 0; i < listSectionResults[0].F2.Length; i++)
{
TabularData sampleData = new TabularData();
sampleData.Location = range_values[i];
sampleData.Length = sectionCutLength[i];