X2021/Wardrobe/Gratings Data/Calculate_Fill_Grid.vb

273 lines
11 KiB
VB.net

Public Class Calculate_Fill_Grid
Public Shared maxGratingWidth, maxGratingLength As Integer
Public Shared numOfHorizontal, numOfVertical As Integer
Public Shared gratingLength, gratingWidth As Integer
Public Shared gratingDimensionsDT As New DataTable
Public Shared supportBeamsDT As New DataTable
Public Shared withSupportBeam As Boolean = False
Public Shared Sub Calculate_Grid()
maxGratingWidth = Get_Max_Width()
maxGratingLength = Get_Max_Length(maxGratingWidth)
Get_NumOf_Vertical(maxGratingWidth)
Get_NumOf_Horizontal(maxGratingLength)
Fill_Dimension_DT()
Get_Grid_Beams()
Calculate_Support_Beams()
Individual.Panel_Grating.Refresh()
End Sub
Private Shared Function Get_Max_Width()
If Data.gratingW >= 1000 Then
If Data.gratingW Mod 1000 > 0 AndAlso Data.gratingW Mod 1000 <= 200 Then
Return (Data.gratingW Mod 1000) + 1000
End If
Return 1000
End If
Return Data.gratingW
End Function
Private Shared Function Get_Max_Length(gratingMaxWidth As Integer)
Dim maxWeight As Double = CDbl(Individual.Panel_Data.Controls("TextBox_Max_Weight").Text)
Dim loadBarHeight As Integer = 25
Dim loadBarThickness As Integer = 2
Dim loadBarWeight As Double = 0
Dim crossBarWeight As Double = 0
If User_Input.gratingType = "Pressure Welded" Then
loadBarWeight = 0.385 ' För 1x1 m
If User_Input.CBDiameter = 5 Then
crossBarWeight = 0.153 ' För 1x1 m
Else
crossBarWeight = 0.259 ' För 1x1 m
End If
Else ' Type-A
crossBarWeight = 0.312 ' För 1x1 m
loadBarWeight = 0.337 ' För 1x1 m
End If
Dim LBHdiff As Double = 1 + (User_Input.gratingHeight - loadBarHeight) / loadBarHeight
loadBarWeight *= LBHdiff
Dim LBTdiff As Double = 1 + (User_Input.loadBarThickness - loadBarThickness) / loadBarThickness
loadBarWeight *= LBTdiff
Dim numOfLB As Integer = 1 + Math.Floor((1000 - User_Input.loadBarSpacing) / User_Input.loadBarSpacing)
Dim numOfCB As Integer = 1 + Math.Floor((1000 - User_Input.crossBarSpacing) / User_Input.crossBarSpacing)
Dim gratingWeight As Double = (numOfLB + 4) * loadBarWeight + numOfCB * crossBarWeight
Dim maxArea As Double = maxWeight / gratingWeight
Dim maxLength As Double = maxArea / (gratingMaxWidth / 1000)
maxLength = Math.Floor(maxLength * 10) * 100
Return CInt(maxLength)
End Function
Private Shared Sub Get_NumOf_Horizontal(maxGratingLength As Integer)
If (Data.gratingL / maxGratingLength) Mod 1 = 0 Then
numOfHorizontal = Data.gratingL / maxGratingLength
Else
numOfHorizontal = Math.Floor(Data.gratingL / maxGratingLength) + 1
End If
End Sub
Private Shared Sub Get_NumOf_Vertical(maxGratingWidth As Integer)
If Data.gratingW < 1000 Then
numOfVertical = 1
ElseIf Data.gratingW Mod 1000 = 0 Then
numOfVertical = Data.gratingW / 1000
Else
If Data.gratingW Mod 1000 <= 200 Then
numOfVertical = Math.Floor(Data.gratingW / 1000)
Else
numOfVertical = Math.Floor(Data.gratingW / 1000) + 1
End If
End If
End Sub
Private Shared Function Calculate_Grating_Length(gratingLength As Integer, modInterval As Integer)
Dim gLength As Integer
If Data.gratingL Mod gratingLength = 0 Then
gLength = gratingLength
ElseIf Data.gratingL Mod gratingLength >= 300 AndAlso Math.Floor((Data.gratingL + 0.5) / gratingLength) + 1 = numOfHorizontal Then
gLength = gratingLength
ElseIf Math.Floor((Data.gratingL + 0.5) / gratingLength) + 1 > numOfHorizontal Then
gLength = Calculate_Grating_Length(maxGratingLength, 10)
Else
gLength = Calculate_Grating_Length(gratingLength - modInterval, modInterval)
End If
Return gLength
End Function
Private Shared Sub Fill_Dimension_DT()
gratingDimensionsDT.Clear()
gratingDimensionsDT.Columns.Clear()
gratingDimensionsDT.Columns.Add("INDEX", GetType(Integer))
gratingDimensionsDT.Columns.Add("ROW", GetType(Integer))
gratingDimensionsDT.Columns.Add("COLUMN", GetType(Integer))
gratingDimensionsDT.Columns.Add("WIDTH", GetType(Integer))
gratingDimensionsDT.Columns.Add("LENGTH", GetType(Integer))
gratingLength = Calculate_Grating_Length(maxGratingLength, 100)
For i = 0 To numOfHorizontal * numOfVertical - 1
Dim tempDR As DataRow = gratingDimensionsDT.NewRow
tempDR("INDEX") = i
tempDR("ROW") = Math.Floor((i + 0.5) / numOfHorizontal)
tempDR("COLUMN") = i Mod numOfHorizontal
If tempDR("ROW") + 1 < numOfVertical Then
tempDR("WIDTH") = 1000
Else
If Data.gratingW Mod 1000 <= 200 Then
tempDR("WIDTH") = maxGratingWidth
Else
tempDR("WIDTH") = Data.gratingW Mod 1000
End If
End If
If tempDR("COLUMN") + 1 < numOfHorizontal Then
tempDR("LENGTH") = gratingLength
Else
tempDR("LENGTH") = Data.gratingL - gratingLength * (numOfHorizontal - 1)
End If
gratingDimensionsDT.Rows.Add(tempDR)
Next
End Sub
Private Shared Sub Calculate_Support_Beams()
' Hämta belastning från gui
Dim maxLoad As Double = CDbl(Individual.Panel_Data.Controls("TextBox_Max_Load").Text)
' Kolla mot load tables och hitta max längd
Dim loadDT As DataTable = Database.database.Tables("LOAD")
Dim nameInDT As String = loadDT.Rows(0)("NAME")
Dim LBHeightInDT As Integer = loadDT.Rows(0)("LB-HEIGHT")
Dim LBThicknessInDT As Integer = loadDT.Rows(0)("LB-THICKNESS")
Dim loadName As String = User_Input.gratingName.Substring(0, 1)
If User_Input.gratingName.Substring(User_Input.gratingName.Length - 1, 1) = "T" Then
loadName += "-T"
ElseIf loadName = "A" Then
loadName += User_Input.gratingMesh.Split(" ")(0)
End If
Dim maxUnsupportedLenght As Integer
For i = 0 To loadDT.Rows.Count - 1
If loadName = nameInDT AndAlso User_Input.gratingHeight = LBHeightInDT _
AndAlso User_Input.loadBarThickness = LBThicknessInDT Then
If loadDT.Rows(i)("300") < maxLoad Then
MessageBox.Show("Max supported load for chosen grating parameters is: " & loadDT.Rows(i)("300") & " [kN/m^2]")
Return
End If
For j = loadDT.Columns.Count - 1 To 0 Step -1
If loadDT.Rows(i)(j) >= maxLoad Then
maxUnsupportedLenght = CInt(loadDT.Columns(j).ColumnName)
Exit For
End If
Next
Exit For
End If
Try
nameInDT = loadDT.Rows(i + 1)("NAME")
LBHeightInDT = loadDT.Rows(i + 1)("LB-HEIGHT")
LBThicknessInDT = loadDT.Rows(i + 1)("LB-THICKNESS")
Catch ex As Exception
End Try
Next
' Jämför med längd
If Math.Floor((gratingLength + 1) / maxUnsupportedLenght) < 1 Then '+1 för att floor inte kan hantera jämna tal
Return
End If
' Definera support beams
For i = 0 To numOfHorizontal - 1
Dim gratingL As Integer = gratingDimensionsDT.Rows(i)("LENGTH")
Dim numOfBeamsNeeded As Integer = Math.Floor((gratingL + 1) / maxUnsupportedLenght)
If numOfBeamsNeeded > 0 Then
Dim beamSpacing As Integer = (Math.Floor(((gratingL + 1) / (numOfBeamsNeeded + 1)) / 10)) * 10
For j = 1 To numOfBeamsNeeded
Dim tempDR As DataRow = supportBeamsDT.NewRow
tempDR("INDEX") = supportBeamsDT.Rows.Count + 1
tempDR("TYPE") = "Extra"
tempDR("COLUMN") = i
tempDR("COLUMN_OFFSET") = j * beamSpacing
tempDR("GLOBAL_OFFSET") = gratingLength * i + tempDR("COLUMN_OFFSET")
tempDR("LENGTH") = Data.gratingW
tempDR("OFFSET_TOP") = 0
tempDR("OFFSET_BOTTOM") = 0
tempDR("ROTATION") = 0
supportBeamsDT.Rows.Add(tempDR)
Next
End If
Next
End Sub
Private Shared Sub Get_Grid_Beams()
withSupportBeam = False
supportBeamsDT.Clear()
supportBeamsDT.Columns.Clear()
supportBeamsDT.Columns.Add("INDEX", GetType(Integer))
supportBeamsDT.Columns.Add("TYPE", GetType(String))
supportBeamsDT.Columns.Add("COLUMN", GetType(Integer))
supportBeamsDT.Columns.Add("COLUMN_OFFSET", GetType(Integer))
supportBeamsDT.Columns.Add("GLOBAL_OFFSET", GetType(Integer))
supportBeamsDT.Columns.Add("LENGTH", GetType(Integer))
supportBeamsDT.Columns.Add("OFFSET_TOP", GetType(Integer))
supportBeamsDT.Columns.Add("OFFSET_BOTTOM", GetType(Integer))
supportBeamsDT.Columns.Add("ROTATION", GetType(Integer))
'Horizontal Beams
For i = 0 To numOfVertical - 2
withSupportBeam = True
Dim tempDR As DataRow = supportBeamsDT.NewRow
tempDR("INDEX") = supportBeamsDT.Rows.Count + 1
tempDR("TYPE") = "Grid"
tempDR("GLOBAL_OFFSET") = gratingDimensionsDT.Rows(numOfHorizontal * (numOfVertical - 1))("WIDTH")
For j = 1 To i
tempDR("GLOBAL_OFFSET") += gratingDimensionsDT.Rows(numOfHorizontal * (numOfVertical - 1) - j * numOfHorizontal)("WIDTH")
Next
tempDR("LENGTH") = Data.gratingL
tempDR("OFFSET_TOP") = 0
tempDR("OFFSET_BOTTOM") = 0
tempDR("ROTATION") = 90
supportBeamsDT.Rows.Add(tempDR)
Next
'Vertical Beams
For i = 0 To numOfHorizontal - 2
withSupportBeam = True
Dim tempDR As DataRow = supportBeamsDT.NewRow
tempDR("INDEX") = supportBeamsDT.Rows.Count + 1
tempDR("TYPE") = "Grid"
tempDR("GLOBAL_OFFSET") = gratingDimensionsDT.Rows(0)("LENGTH")
For j = 1 To i
tempDR("GLOBAL_OFFSET") += gratingDimensionsDT.Rows(j)("LENGTH")
Next
tempDR("LENGTH") = Data.gratingW
tempDR("OFFSET_TOP") = 0
tempDR("OFFSET_BOTTOM") = 0
tempDR("ROTATION") = 0
supportBeamsDT.Rows.Add(tempDR)
Next
End Sub
End Class