733 lines
30 KiB
VB.net
733 lines
30 KiB
VB.net
Imports XCCLibrary
|
|
Imports Excel = Microsoft.Office.Interop.Excel
|
|
|
|
Public Class GUI
|
|
'Public Shared filepath As String = "C:\Users\Anton\Documents\Exjobb"
|
|
Public Shared filepath As String = "C:\Users\xperd\Documents"
|
|
|
|
Dim filesFolder As String = filepath ' Hämta från settings
|
|
Dim HLCtFolder As String = filepath & "\X2021" ' Hämta från settings
|
|
|
|
Dim containerPanel As Panel
|
|
|
|
Dim containerL, containerW, containerMidX, containerMidY As Integer
|
|
Dim gratingMaxW As Decimal = 1000
|
|
Dim gratingMaxL As Decimal = 1000
|
|
Dim drawL As Integer = 1
|
|
Dim drawW As Integer = 1
|
|
Dim drawAspect, gratingAspect As Decimal
|
|
Dim scaleDiff As Decimal = 1
|
|
|
|
Public pCon1(3) As Decimal 'pCon(0) = pixel X, pCon(2) = SW X, etc.
|
|
Public pCon2(3) As Decimal
|
|
Public pCon3(3) As Decimal
|
|
Public pCon4(3) As Decimal
|
|
|
|
Dim DirSymbolPoints As New Dictionary(Of String, Decimal())
|
|
Dim ArrowSymbolPoints As New Dictionary(Of String, Decimal())
|
|
|
|
Dim points As New Dictionary(Of String, Decimal())
|
|
Dim pointsFunc As New Dictionary(Of String, Boolean)
|
|
Dim pointsOrder As New List(Of String)
|
|
|
|
Dim gratingType, gratingMaterial, gratingMesh As String
|
|
Dim gratingSerrated As Boolean
|
|
Dim loadBarSpacing, crossBarSpacing, gratingHeight, loadBarThickness As Integer
|
|
|
|
Dim pointCounter As Integer
|
|
Dim angleFunctionActive As Boolean = False
|
|
Dim squareFunctionActive As Boolean = False
|
|
|
|
Dim excelApp As Excel.Application = New Excel.Application
|
|
Dim excelWB As Excel.Workbook
|
|
Dim excelSheet As Excel.Worksheet
|
|
|
|
' --- Start method (main) for GUI ---
|
|
Sub GUI_load() Handles MyBase.Load
|
|
containerPanel = DrawingPanel
|
|
Me.Width = 1400
|
|
Me.Height = 800
|
|
AddHandler containerPanel.Paint, AddressOf DrawingPanel_Paint
|
|
|
|
Get_DrawboxParameters()
|
|
|
|
Set_ContainerPointsX()
|
|
Set_ContainerPointsY()
|
|
|
|
Create_DirSymbolPoints()
|
|
Create_ArrowSymbolPoints()
|
|
|
|
Update_GratingPoints()
|
|
|
|
Create_StartPoints()
|
|
|
|
Program.Load_XCC(filesFolder, HLCtFolder)
|
|
excelWB = excelApp.Workbooks.Open(HLCtFolder & "\Databas.xlsx")
|
|
End Sub
|
|
|
|
' --- Retrive parameters for the drawing box ---
|
|
Private Sub Get_DrawboxParameters()
|
|
containerL = containerPanel.Size.Width
|
|
containerW = containerPanel.Size.Height
|
|
|
|
containerMidX = containerL / 2
|
|
containerMidY = containerW / 2
|
|
|
|
drawL = containerL - 80
|
|
drawW = containerW - 80
|
|
|
|
drawAspect = drawL / drawW
|
|
End Sub
|
|
|
|
' --- Set containers points X-values ---
|
|
Private Sub Set_ContainerPointsX()
|
|
pCon1(0) = containerMidX - drawL / 2
|
|
pCon2(0) = containerMidX + drawL / 2
|
|
pCon3(0) = containerMidX + drawL / 2
|
|
pCon4(0) = containerMidX - drawL / 2
|
|
End Sub
|
|
|
|
' --- Set containers points Y-values ---
|
|
Private Sub Set_ContainerPointsY()
|
|
pCon1(1) = containerMidY - drawW / 2
|
|
pCon2(1) = containerMidY - drawW / 2
|
|
pCon3(1) = containerMidY + drawW / 2
|
|
pCon4(1) = containerMidY + drawW / 2
|
|
End Sub
|
|
|
|
' --- Create points for grating direction symbol ---
|
|
Private Sub Create_DirSymbolPoints()
|
|
DirSymbolPoints.Add("p1", {-30 + containerMidX, -2 + containerMidY})
|
|
DirSymbolPoints.Add("p2", {20 + containerMidX, -2 + containerMidY})
|
|
DirSymbolPoints.Add("p3", {12 + containerMidX, -10 + containerMidY})
|
|
DirSymbolPoints.Add("p4", {15 + containerMidX, -13 + containerMidY})
|
|
DirSymbolPoints.Add("p5", {30 + containerMidX, 2 + containerMidY})
|
|
DirSymbolPoints.Add("p6", {-20 + containerMidX, 2 + containerMidY})
|
|
DirSymbolPoints.Add("p7", {-12 + containerMidX, 10 + containerMidY})
|
|
DirSymbolPoints.Add("p8", {-15 + containerMidX, 13 + containerMidY})
|
|
DirSymbolPoints.Add("p9", {-30 + containerMidX, -2 + containerMidY})
|
|
End Sub
|
|
|
|
' --- Create points for arrow symbol ---
|
|
Private Sub Create_ArrowSymbolPoints()
|
|
Dim offset As Integer = 20
|
|
ArrowSymbolPoints.Add("p1", {offset, containerW - offset})
|
|
ArrowSymbolPoints.Add("p2", {offset, containerW - offset - 40})
|
|
ArrowSymbolPoints.Add("p3", {offset - 5, containerW - offset - 35})
|
|
ArrowSymbolPoints.Add("p4", {offset, containerW - offset - 40})
|
|
ArrowSymbolPoints.Add("p5", {offset + 5, containerW - offset - 35})
|
|
ArrowSymbolPoints.Add("p6", {offset, containerW - offset - 40})
|
|
ArrowSymbolPoints.Add("p7", {offset, containerW - offset})
|
|
ArrowSymbolPoints.Add("p8", {offset + 40, containerW - offset})
|
|
ArrowSymbolPoints.Add("p9", {offset + 35, containerW - offset - 5})
|
|
ArrowSymbolPoints.Add("p10", {offset + 40, containerW - offset})
|
|
ArrowSymbolPoints.Add("p11", {offset + 35, containerW - offset + 5})
|
|
End Sub
|
|
|
|
' --- Updates all the gratings points ---
|
|
Private Sub Update_GratingPoints()
|
|
gratingAspect = gratingMaxL / gratingMaxW
|
|
|
|
If gratingAspect > drawAspect Then
|
|
'Change draw height
|
|
scaleDiff = gratingMaxL / drawL
|
|
|
|
pCon1(1) = containerMidY - gratingMaxW / (scaleDiff * 2)
|
|
pCon2(1) = containerMidY - gratingMaxW / (scaleDiff * 2)
|
|
pCon3(1) = containerMidY + gratingMaxW / (scaleDiff * 2)
|
|
pCon4(1) = containerMidY + gratingMaxW / (scaleDiff * 2)
|
|
|
|
Set_ContainerPointsX()
|
|
Else
|
|
'Change draw width
|
|
scaleDiff = gratingMaxW / drawW
|
|
|
|
pCon1(0) = containerMidX - gratingMaxL / (scaleDiff * 2)
|
|
pCon2(0) = containerMidX + gratingMaxL / (scaleDiff * 2)
|
|
pCon3(0) = containerMidX + gratingMaxL / (scaleDiff * 2)
|
|
pCon4(0) = containerMidX - gratingMaxL / (scaleDiff * 2)
|
|
|
|
Set_ContainerPointsY()
|
|
End If
|
|
|
|
'Redraw grating
|
|
Me.Refresh()
|
|
|
|
'SW X-values
|
|
pCon1(2) = (-gratingMaxL / 2) / 1000
|
|
pCon2(2) = (gratingMaxL / 2) / 1000
|
|
pCon3(2) = (gratingMaxL / 2) / 1000
|
|
pCon4(2) = (-gratingMaxL / 2) / 1000
|
|
|
|
'SW Y-values
|
|
pCon1(3) = (gratingMaxW / 2) / 1000
|
|
pCon2(3) = (gratingMaxW / 2) / 1000
|
|
pCon3(3) = (-gratingMaxW / 2) / 1000
|
|
pCon4(3) = (-gratingMaxW / 2) / 1000
|
|
End Sub
|
|
|
|
' --- Draw all the lines for the container and grating ---
|
|
Private Sub DrawingPanel_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs)
|
|
' Draw outer grating (red)
|
|
Dim penCon As Pen = New Pen(Color.DarkRed, 1)
|
|
penCon.DashPattern = {4, 8}
|
|
e.Graphics.DrawLine(penCon, CInt(pCon1(0)), CInt(pCon1(1)), CInt(pCon2(0)), CInt(pCon2(1)))
|
|
e.Graphics.DrawLine(penCon, CInt(pCon2(0)), CInt(pCon2(1)), CInt(pCon3(0)), CInt(pCon3(1)))
|
|
e.Graphics.DrawLine(penCon, CInt(pCon3(0)), CInt(pCon3(1)), CInt(pCon4(0)), CInt(pCon4(1)))
|
|
e.Graphics.DrawLine(penCon, CInt(pCon4(0)), CInt(pCon4(1)), CInt(pCon1(0)), CInt(pCon1(1)))
|
|
|
|
' Draw grating direction symbol
|
|
Dim symPen As Pen = New Pen(Color.Black, 1)
|
|
For i = 1 To DirSymbolPoints.Count - 1
|
|
e.Graphics.DrawLine(symPen, DirSymbolPoints("p" & i)(0), DirSymbolPoints("p" & i)(1), DirSymbolPoints("p" & i + 1)(0), DirSymbolPoints("p" & i + 1)(1))
|
|
Next
|
|
|
|
' Draw arrow symbol
|
|
For i = 1 To ArrowSymbolPoints.Count - 1
|
|
e.Graphics.DrawLine(symPen, ArrowSymbolPoints("p" & i)(0), ArrowSymbolPoints("p" & i)(1), ArrowSymbolPoints("p" & i + 1)(0), ArrowSymbolPoints("p" & i + 1)(1))
|
|
Next
|
|
e.Graphics.TranslateTransform(20, containerW - 20)
|
|
e.Graphics.DrawString("Length", New Font("Microsoft Sans Serif", 8), Brushes.Black, New Point(45, -7))
|
|
e.Graphics.RotateTransform(-90)
|
|
e.Graphics.DrawString("Width", New Font("Microsoft Sans Serif", 8), Brushes.Black, New Point(45, -4))
|
|
e.Graphics.RotateTransform(90)
|
|
e.Graphics.TranslateTransform(-20, -containerW + 20)
|
|
|
|
' Draw actual grating (black)
|
|
Dim pen As Pen = New Pen(Color.Black, 2)
|
|
For i = 0 To pointsOrder.Count - 1
|
|
Dim pTemp1() As Decimal
|
|
Dim pTemp2() As Decimal
|
|
|
|
pTemp1 = points(pointsOrder(i))
|
|
Try
|
|
pTemp2 = points(pointsOrder(i + 1))
|
|
Catch ex As Exception
|
|
pTemp2 = points(pointsOrder(0))
|
|
End Try
|
|
|
|
e.Graphics.DrawLine(pen, CInt(pTemp1(0)), CInt(pTemp1(1)), CInt(pTemp2(0)), CInt(pTemp2(1)))
|
|
Next
|
|
End Sub
|
|
|
|
' --- Sets the start points for the grating ---
|
|
Private Sub Create_StartPoints()
|
|
For i = 1 To 4
|
|
points.Add("p" & i, CallByName(Me, "pCon" & i, vbGet))
|
|
pointsFunc.Add("p" & i, True)
|
|
pointsOrder.Add("p" & i)
|
|
Next
|
|
End Sub
|
|
|
|
' --- Generate a table containing all the points X- and Y-values ---
|
|
Private Function Create_PointTable()
|
|
Dim pointTable As New DataTable
|
|
pointTable.Columns.Add("X", GetType(Decimal))
|
|
pointTable.Columns.Add("Y", GetType(Decimal))
|
|
|
|
For i = 0 To pointsOrder.Count - 1
|
|
Dim pTemp() As Decimal
|
|
pTemp = points(pointsOrder(i))
|
|
|
|
pointTable.Rows.Add()
|
|
pointTable.Rows(i)("X") = pTemp(2)
|
|
pointTable.Rows(i)("Y") = pTemp(3)
|
|
Next
|
|
|
|
Return pointTable
|
|
End Function
|
|
|
|
' --- Check if the key pressed is a number ---
|
|
Private Sub Check_IfNumber(e As KeyPressEventArgs)
|
|
If Asc(e.KeyChar) <> 8 Then
|
|
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
|
|
e.Handled = True
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
' --- Creates the table with points data used in SW ---
|
|
Private Function Create_ExportTable() As DataTable
|
|
Dim lSpacing As String = ComboBox_MeshSize.Text.Split("x")(0)
|
|
Dim cSpacing As String = ComboBox_MeshSize.Text.Split("x")(1).Split(" ")(0)
|
|
|
|
Dim gratingTable As New DataTable
|
|
gratingTable.Columns.Add("TYPE", GetType(String))
|
|
gratingTable.Columns.Add("SERRATED", GetType(Boolean))
|
|
gratingTable.Columns.Add("WIDTH", GetType(Decimal))
|
|
gratingTable.Columns.Add("LENGTH", GetType(Decimal))
|
|
gratingTable.Columns.Add("LOADBAR_THICKNESS", GetType(Decimal))
|
|
gratingTable.Columns.Add("LOADBAR_HEIGHT", GetType(Decimal))
|
|
gratingTable.Columns.Add("LOADBAR_SPACING", GetType(Decimal))
|
|
gratingTable.Columns.Add("CROSSBAR_SPACING", GetType(Decimal))
|
|
gratingTable.Columns.Add("CROSSBAR_DIAMETER", GetType(Decimal))
|
|
gratingTable.Columns.Add("CROSSBAR_THICKNESS", GetType(Decimal))
|
|
gratingTable.Columns.Add("CROSSBAR_HEIGHT", GetType(Decimal))
|
|
|
|
gratingTable.Rows.Add()
|
|
|
|
gratingTable.Rows(0)("SERRATED") = False 'Hämta från GUI
|
|
gratingTable.Rows(0)("WIDTH") = CDec(ComboBox_Width.Text)
|
|
gratingTable.Rows(0)("LENGTH") = CDec(ComboBox_Length.Text)
|
|
gratingTable.Rows(0)("LOADBAR_THICKNESS") = CDec(ComboBox_Thickness.Text)
|
|
gratingTable.Rows(0)("LOADBAR_HEIGHT") = CDec(ComboBox_Height.Text)
|
|
gratingTable.Rows(0)("LOADBAR_SPACING") = CDec(lSpacing)
|
|
gratingTable.Rows(0)("CROSSBAR_SPACING") = CDec(cSpacing)
|
|
|
|
If ComboBox_TypeChooser.Text = "Pressure Welded" Then
|
|
gratingTable.Rows(0)("TYPE") = "pressure_welded" ' Här behövs namn på HLCt modellen
|
|
gratingTable.Rows(0)("CROSSBAR_DIAMETER") = 5
|
|
gratingTable.Rows(0)("CROSSBAR_THICKNESS") = 0
|
|
gratingTable.Rows(0)("CROSSBAR_HEIGHT") = 0
|
|
Else
|
|
gratingTable.Rows(0)("TYPE") = "type_a" ' Här behövs namn på HLCt modellen
|
|
gratingTable.Rows(0)("CROSSBAR_DIAMETER") = 0
|
|
gratingTable.Rows(0)("CROSSBAR_THICKNESS") = 2
|
|
gratingTable.Rows(0)("CROSSBAR_HEIGHT") = 15
|
|
End If
|
|
|
|
Return gratingTable
|
|
End Function
|
|
|
|
Private Sub Create_TextBox(TextBoxName As String, TextBoxText As String, TextBoxLeft As Integer, TextBoxTop As Integer, TextBoxWidth As Integer)
|
|
Dim textBoxTemp As New TextBox
|
|
textBoxTemp.Name = TextBoxName
|
|
textBoxTemp.Text = TextBoxText
|
|
textBoxTemp.Left = TextBoxLeft
|
|
textBoxTemp.Top = TextBoxTop
|
|
textBoxTemp.Width = TextBoxWidth
|
|
textBoxTemp.Font = New Font("Microsoft Sans Serif", 10)
|
|
Me.Controls.Add(textBoxTemp)
|
|
End Sub
|
|
|
|
Private Sub Create_Label(LabelName As String, LabelText As String, LabelLeft As Integer, LabelTop As Integer)
|
|
Dim LabelTemp As New Label
|
|
LabelTemp.Name = LabelName
|
|
LabelTemp.Text = LabelText
|
|
LabelTemp.Left = LabelLeft
|
|
LabelTemp.Top = LabelTop
|
|
LabelTemp.Font = New Font("Microsoft Sans Serif", 10)
|
|
Me.Controls.Add(LabelTemp)
|
|
End Sub
|
|
|
|
|
|
|
|
' ---------------------------------- GUI interactions ----------------------------------
|
|
|
|
' --- When user changes grating type ---
|
|
Private Sub ComboBox_TypeChooser_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_TypeChooser.TextChanged
|
|
gratingType = ComboBox_TypeChooser.Text
|
|
ComboBox_Material.Enabled = True
|
|
ComboBox_Material.Items.Clear()
|
|
|
|
Dim materialSheet As Excel.Worksheet
|
|
materialSheet = excelWB.Sheets("Material")
|
|
Dim typeColumn As Integer = 0
|
|
Dim columnCounter As Integer = 1
|
|
While typeColumn = 0
|
|
If materialSheet.Cells(1, columnCounter).value = "TYPE" Then
|
|
typeColumn = materialSheet.Cells(1, columnCounter).column
|
|
|
|
End If
|
|
columnCounter = columnCounter + 1
|
|
End While
|
|
|
|
Dim materialColumn As Integer = 0
|
|
columnCounter = 1
|
|
While materialColumn = 0
|
|
If materialSheet.Cells(1, columnCounter).value = "MATERIAL" Then
|
|
materialColumn = materialSheet.Cells(1, columnCounter).column
|
|
|
|
End If
|
|
columnCounter = columnCounter + 1
|
|
End While
|
|
|
|
Dim typeInExcel As String
|
|
Dim rowCounter As Integer = 2
|
|
typeInExcel = materialSheet.Cells(rowCounter, typeColumn).value
|
|
While typeInExcel <> ""
|
|
If gratingType = typeInExcel Then
|
|
ComboBox_Material.Items.Add(materialSheet.Cells(rowCounter, materialColumn).Value)
|
|
|
|
End If
|
|
rowCounter = rowCounter + 1
|
|
typeInExcel = materialSheet.Cells(rowCounter, typeColumn).value
|
|
End While
|
|
|
|
ComboBox_Material.Text = ComboBox_Material.Items(0)
|
|
End Sub
|
|
|
|
' --- When user changes grating material ---
|
|
Private Sub ComboBox_Material_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Material.TextChanged
|
|
ComboBox_MeshSize.Enabled = True
|
|
ComboBox_MeshSize.Items.Clear()
|
|
gratingMaterial = ComboBox_Material.Text
|
|
gratingSerrated = False 'FIXA
|
|
|
|
' Add toothing option
|
|
If gratingType = "Pressure Welded" Then
|
|
If gratingMaterial = "Standard" Or gratingMaterial = "Stainless Steel (Pickled)" Then
|
|
Dim serratedCheckBox As New CheckBox
|
|
serratedCheckBox.Name = "CheckBox_Serrated"
|
|
serratedCheckBox.Text = "Serrated"
|
|
serratedCheckBox.Left = 115
|
|
serratedCheckBox.Top = 115
|
|
Me.Controls.Add(serratedCheckBox)
|
|
End If
|
|
ElseIf gratingMaterial = "Standard" Or gratingMaterial = "Aluminum" Then
|
|
Dim serratedCheckBox As New CheckBox
|
|
serratedCheckBox.Name = "CheckBox_Serrated"
|
|
serratedCheckBox.Text = "Serrated"
|
|
serratedCheckBox.Left = 115
|
|
serratedCheckBox.Top = 115
|
|
Me.Controls.Add(serratedCheckBox)
|
|
End If
|
|
|
|
' Add Meshes
|
|
If gratingType = "Pressure Welded" Then
|
|
ComboBox_MeshSize.Items.Add("12x100 (B9)") 'Tillfällig
|
|
ComboBox_MeshSize.Items.Add("25x50 (F4)") 'Tillfällig
|
|
ComboBox_MeshSize.Items.Add("34x37 (H3)") 'Tillfällig
|
|
|
|
'For i = 1 To 5
|
|
' ComboBox_MeshSize.Items.Add("hej " & i) 'Hämta från databas
|
|
'Next
|
|
Else
|
|
ComboBox_MeshSize.Items.Add("22x22") 'Tillfällig
|
|
ComboBox_MeshSize.Items.Add("33x11") 'Tillfällig
|
|
|
|
'For i = 1 To 5
|
|
' ComboBox_MeshSize.Items.Add("Test " & i) 'Hämta från databas
|
|
'Next
|
|
End If
|
|
End Sub
|
|
|
|
' --- When user changes mesh size ---
|
|
Private Sub ComboBox_MeshSize_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_MeshSize.TextChanged
|
|
ComboBox_Height.Enabled = True
|
|
ComboBox_Height.Items.Clear()
|
|
gratingMesh = ComboBox_MeshSize.Text
|
|
loadBarSpacing = CInt(gratingMesh.Split("x")(0))
|
|
crossBarSpacing = CInt(gratingMesh.Split("x")(1).Split(" ")(0))
|
|
|
|
' Add heights
|
|
If loadBarSpacing = 12 And crossBarSpacing = 100 Then
|
|
ComboBox_Height.Items.Add("20")
|
|
ComboBox_Height.Items.Add("25")
|
|
End If
|
|
End Sub
|
|
|
|
' --- When user changes grating height ---
|
|
Private Sub ComboBox_Height_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Height.TextChanged
|
|
ComboBox_Thickness.Enabled = True
|
|
ComboBox_Thickness.Items.Clear()
|
|
gratingHeight = CInt(ComboBox_Height.Text)
|
|
|
|
' Add thicknesses
|
|
If gratingHeight = 20 Then
|
|
ComboBox_Thickness.Items.Add("2")
|
|
ComboBox_Thickness.Items.Add("3")
|
|
End If
|
|
End Sub
|
|
|
|
' --- When user changes grating thickness ---
|
|
Private Sub ComboBox_Thickness_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Thickness.TextChanged
|
|
ComboBox_Width.Enabled = True
|
|
ComboBox_Width.Items.Clear()
|
|
ComboBox_Length.Enabled = True
|
|
ComboBox_Length.Items.Clear()
|
|
loadBarThickness = CInt(ComboBox_Thickness.Text)
|
|
|
|
' Add Widths
|
|
ComboBox_Width.Items.Add("300")
|
|
ComboBox_Width.Items.Add("500")
|
|
ComboBox_Width.Items.Add("1000")
|
|
ComboBox_Width.Text = ComboBox_Width.Items(0)
|
|
|
|
' Add Length
|
|
ComboBox_Length.Items.Add("500")
|
|
ComboBox_Length.Items.Add("1000")
|
|
ComboBox_Length.Text = ComboBox_Length.Items(0)
|
|
End Sub
|
|
|
|
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
|
|
If CheckBox1.Checked Then
|
|
ComboBox_Width.DropDownStyle = ComboBoxStyle.DropDownList
|
|
Else
|
|
ComboBox_Width.DropDownStyle = ComboBoxStyle.DropDown
|
|
End If
|
|
End Sub
|
|
|
|
|
|
' --- Grating width changed ---
|
|
Private Sub WidthB_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Width.TextChanged
|
|
|
|
|
|
If ComboBox_Width.Text <> "" Then
|
|
If CDec(ComboBox_Width.Text) > 0 Then
|
|
gratingMaxW = CDec(ComboBox_Width.Text)
|
|
Update_GratingPoints()
|
|
End If
|
|
End If
|
|
|
|
'If stocked length options exist
|
|
If gratingMaxW = 500 Then
|
|
Dim stockedCheckBox As New CheckBox
|
|
stockedCheckBox.Name = "CheckBox_Stocked"
|
|
stockedCheckBox.Text = "Only stocked lengths"
|
|
stockedCheckBox.Left = 94
|
|
stockedCheckBox.Top = 386
|
|
stockedCheckBox.Checked = True
|
|
Me.Controls.Add(stockedCheckBox)
|
|
End If
|
|
End Sub
|
|
|
|
' --- Check if width is a number ---
|
|
Private Sub ComboBox_Width_KeyPress(sender As Object, e As KeyPressEventArgs) Handles ComboBox_Width.KeyPress
|
|
Check_IfNumber(e)
|
|
End Sub
|
|
|
|
' --- Grating length changed ---
|
|
Private Sub LengthBox_TextChanged(sender As Object, e As EventArgs) Handles ComboBox_Length.TextChanged
|
|
If ComboBox_Length.Text <> "" Then
|
|
If CDec(ComboBox_Length.Text) > 0 Then
|
|
gratingMaxL = CDec(ComboBox_Length.Text)
|
|
Update_GratingPoints()
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
' --- Check if length is a number ---
|
|
Private Sub ComboBox_Length_KeyPress(sender As Object, e As KeyPressEventArgs) Handles ComboBox_Length.KeyPress
|
|
Check_IfNumber(e)
|
|
End Sub
|
|
|
|
|
|
|
|
' --- When angle button is pressed ---
|
|
Private Sub AngleButton_Click(sender As Object, e As EventArgs) Handles AngleButton.Click
|
|
Me.Controls("AngleButton").Enabled = False
|
|
Me.Controls("Button_Square").Enabled = False
|
|
|
|
Dim buttonX As Integer = Me.Controls("AngleButton").Location.X
|
|
Dim buttonY As Integer = Me.Controls("AngleButton").Location.Y
|
|
|
|
Create_TextBox("X_TextBox", "", buttonX + 20, buttonY + 40, 60)
|
|
AddHandler Me.Controls("X_TextBox").TextChanged, AddressOf FunctionText_Changed
|
|
Create_Label("X_Label", "1", buttonX, buttonY + 43)
|
|
|
|
Create_TextBox("Y_TextBox", "", buttonX + 130, buttonY + 40, 60)
|
|
AddHandler Me.Controls("Y_TextBox").TextChanged, AddressOf FunctionText_Changed
|
|
Create_Label("Y_Label", "2", buttonX + 110, buttonY + 43)
|
|
|
|
angleFunctionActive = True
|
|
End Sub
|
|
|
|
' --- When square button is pressed ---
|
|
Private Sub Button_Square_Click(sender As Object, e As EventArgs) Handles Button_Square.Click
|
|
Me.Controls("AngleButton").Enabled = False
|
|
Me.Controls("Button_Square").Enabled = False
|
|
|
|
Dim buttonX As Integer = Me.Controls("Button_Square").Location.X
|
|
Dim buttonY As Integer = Me.Controls("Button_Square").Location.Y
|
|
|
|
Create_TextBox("X_TextBox", "", buttonX + 20, buttonY + 40, 60)
|
|
AddHandler Me.Controls("X_TextBox").TextChanged, AddressOf FunctionText_Changed
|
|
Create_Label("X_Label", "1", buttonX, buttonY + 43)
|
|
|
|
Create_TextBox("Y_TextBox", "", buttonX + 130, buttonY + 40, 60)
|
|
AddHandler Me.Controls("Y_TextBox").TextChanged, AddressOf FunctionText_Changed
|
|
Create_Label("Y_Label", "2", buttonX + 110, buttonY + 43)
|
|
|
|
' Add option for corner or side
|
|
|
|
squareFunctionActive = True
|
|
End Sub
|
|
|
|
|
|
Private Sub FunctionText_Changed(sender As TextBox, e As EventArgs)
|
|
If Not Me.Controls("X_TextBox").Text = "" And Not Me.Controls("Y_TextBox").Text = "" Then
|
|
If containerPanel.Controls.Count = 0 Then
|
|
' Create Buttons for all clickable points
|
|
For i = 0 To pointsOrder.Count - 1
|
|
If pointsFunc(pointsOrder(i)) Then
|
|
Dim pointButton As New Button
|
|
pointButton.Width = 30
|
|
pointButton.Height = 30
|
|
|
|
pointButton.Left = points(pointsOrder(i))(0) - pointButton.Width / 2
|
|
pointButton.Top = points(pointsOrder(i))(1) - pointButton.Height / 2
|
|
|
|
pointButton.Name = pointsOrder(i) & "_Button"
|
|
pointButton.Text = ""
|
|
|
|
pointButton.BackColor = Color.FromArgb(50, Color.Red)
|
|
pointButton.FlatStyle = FlatStyle.Flat
|
|
pointButton.FlatAppearance.BorderSize = 0
|
|
pointButton.FlatAppearance.MouseOverBackColor = Color.Red
|
|
pointButton.FlatAppearance.MouseDownBackColor = Color.DarkRed
|
|
|
|
Dim gp As New Drawing.Drawing2D.GraphicsPath
|
|
gp.AddEllipse(New Rectangle(New Point(0, 0), New Size(30, 30)))
|
|
pointButton.Region = New Region(gp)
|
|
|
|
containerPanel.Controls.Add(pointButton)
|
|
|
|
AddHandler pointButton.Click, AddressOf PointButton_Click
|
|
End If
|
|
Next
|
|
pointCounter = pointCounter + 1
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
' --- When a function button is pressed ---
|
|
Private Sub PointButton_Click(sender As Button, e As EventArgs)
|
|
'Determine which point is being pressed
|
|
Dim pointPressed As String = sender.Name.Split("_")(0)
|
|
Dim index As Integer = pointsOrder.IndexOf(pointPressed)
|
|
|
|
' Remove point buttons
|
|
For i = 0 To pointsOrder.Count - 1
|
|
If pointsFunc(pointsOrder(i)) Then
|
|
RemoveHandler containerPanel.Controls(pointsOrder(i) & "_Button").Click, AddressOf PointButton_Click
|
|
containerPanel.Controls.RemoveByKey(pointsOrder(i) & "_Button")
|
|
End If
|
|
Next
|
|
|
|
'Retrive that points coords
|
|
Dim pXP As Decimal = points(pointPressed)(0)
|
|
Dim pYP As Decimal = points(pointPressed)(1)
|
|
Dim pXSW As Decimal = points(pointPressed)(2)
|
|
Dim pYSW As Decimal = points(pointPressed)(3)
|
|
|
|
Dim d1P As Decimal = Me.Controls("X_TextBox").Text / scaleDiff ' BEHÖVS Cdec??
|
|
Dim d2P As Decimal = Me.Controls("Y_TextBox").Text / scaleDiff
|
|
Dim d1SW As Decimal = Me.Controls("X_TextBox").Text / 1000
|
|
Dim d2SW As Decimal = Me.Controls("Y_TextBox").Text / 1000
|
|
|
|
Dim numOfNewPoints As Integer
|
|
|
|
If angleFunctionActive Then
|
|
If pXP < containerMidX Then
|
|
If pYP > containerMidY Then
|
|
'Kvadrant 4
|
|
points.Add("pA" & pointCounter * 2 - 1, {pXP + d1P, pYP, pXSW + d1SW, pYSW})
|
|
points.Add("pA" & pointCounter * 2, {pXP, pYP - d2P, pXSW, pYSW + d2SW})
|
|
Else
|
|
'Kvadrant 1
|
|
points.Add("pA" & pointCounter * 2 - 1, {pXP, pYP + d2P, pXSW, pYSW - d2SW})
|
|
points.Add("pA" & pointCounter * 2, {pXP + d1P, pYP, pXSW + d1SW, pYSW})
|
|
End If
|
|
Else
|
|
If pYP > containerMidY Then
|
|
'Kvadrant 3
|
|
points.Add("pA" & pointCounter * 2 - 1, {pXP, pYP - d2P, pXSW, pYSW + d2SW})
|
|
points.Add("pA" & pointCounter * 2, {pXP - d1P, pYP, pXSW - d1SW, pYSW})
|
|
Else
|
|
'Kvadrant 2
|
|
points.Add("pA" & pointCounter * 2 - 1, {pXP - d1P, pYP, pXSW - d1SW, pYSW})
|
|
points.Add("pA" & pointCounter * 2, {pXP, pYP + d2P, pXSW, pYSW - d2SW})
|
|
End If
|
|
End If
|
|
pointsFunc.Add("pA" & pointCounter * 2 - 1, False)
|
|
pointsFunc.Add("pA" & pointCounter * 2, False)
|
|
|
|
'Insert two new points
|
|
pointsOrder.Insert(index + 1, "pA" & pointCounter * 2 - 1)
|
|
pointsOrder.Insert(index + 2, "pA" & pointCounter * 2)
|
|
|
|
numOfNewPoints = 2
|
|
angleFunctionActive = False
|
|
|
|
Else
|
|
If pXP < containerMidX Then
|
|
If pYP > containerMidY Then
|
|
'Kvadrant 4
|
|
points.Add("pS" & pointCounter * 3 - 2, {pXP + d1P, pYP, pXSW + d1SW, pYSW})
|
|
points.Add("pS" & pointCounter * 3 - 1, {pXP + d1P, pYP - d2P, pXSW + d1SW, pYSW + d2SW})
|
|
points.Add("pS" & pointCounter * 3, {pXP, pYP - d2P, pXSW, pYSW + d2SW})
|
|
Else
|
|
'Kvadrant 1
|
|
points.Add("pS" & pointCounter * 3 - 2, {pXP, pYP + d2P, pXSW, pYSW - d2SW})
|
|
points.Add("pS" & pointCounter * 3 - 1, {pXP + d1P, pYP + d2P, pXSW + d1SW, pYSW - d2SW})
|
|
points.Add("pS" & pointCounter * 3, {pXP + d1P, pYP, pXSW + d1SW, pYSW})
|
|
End If
|
|
Else
|
|
If pYP > containerMidY Then
|
|
'Kvadrant 3
|
|
points.Add("pS" & pointCounter * 3 - 2, {pXP, pYP - d2P, pXSW, pYSW + d2SW})
|
|
points.Add("pS" & pointCounter * 3 - 1, {pXP - d1P, pYP - d2P, pXSW - d1SW, pYSW + d2SW})
|
|
points.Add("pS" & pointCounter * 3, {pXP - d1P, pYP, pXSW - d1SW, pYSW})
|
|
Else
|
|
'Kvadrant 2
|
|
points.Add("pS" & pointCounter * 3 - 2, {pXP - d1P, pYP, pXSW - d1SW, pYSW})
|
|
points.Add("pS" & pointCounter * 3 - 1, {pXP - d1P, pYP + d2P, pXSW - d1SW, pYSW - d2SW})
|
|
points.Add("pS" & pointCounter * 3, {pXP, pYP + d2P, pXSW, pYSW - d2SW})
|
|
End If
|
|
End If
|
|
pointsFunc.Add("pS" & pointCounter * 3 - 2, True)
|
|
pointsFunc.Add("pS" & pointCounter * 3 - 1, False)
|
|
pointsFunc.Add("pS" & pointCounter * 3, True)
|
|
|
|
'Insert new points
|
|
pointsOrder.Insert(index + 1, "pS" & pointCounter * 3 - 2)
|
|
pointsOrder.Insert(index + 2, "pS" & pointCounter * 3 - 1)
|
|
pointsOrder.Insert(index + 3, "pS" & pointCounter * 3)
|
|
|
|
numOfNewPoints = 3
|
|
|
|
squareFunctionActive = False
|
|
|
|
End If
|
|
pointsOrder.RemoveAt(index)
|
|
|
|
'Redraw grating
|
|
Me.Refresh()
|
|
|
|
RemoveHandler Me.Controls("X_TextBox").TextChanged, AddressOf FunctionText_Changed
|
|
Me.Controls.RemoveByKey("X_TextBox")
|
|
|
|
RemoveHandler Me.Controls("Y_TextBox").TextChanged, AddressOf FunctionText_Changed
|
|
Me.Controls.RemoveByKey("Y_TextBox")
|
|
|
|
Me.Controls.RemoveByKey("X_Label")
|
|
Me.Controls.RemoveByKey("Y_Label")
|
|
|
|
Me.Controls("AngleButton").Enabled = True
|
|
Me.Controls("Button_Square").Enabled = True
|
|
End Sub
|
|
|
|
' --- Settings button clicked ---
|
|
Private Sub SettingsButton_Click(sender As Object, e As EventArgs) Handles SettingsButton.Click
|
|
'Program.Update_KB()
|
|
|
|
|
|
|
|
excelSheet = excelWB.Sheets("Pressure_welded") 'Call sheet by name
|
|
'excelSheet = excelWB.Sheets(1) 'Call sheet by number
|
|
|
|
Dim temp1 As String = excelSheet.Range("A64").Value 'Call cell by name
|
|
Dim temp2 As Excel.XlPattern = excelSheet.Cells(79, 1).style.interior.pattern 'Call cell by row and column index
|
|
|
|
End Sub
|
|
|
|
' --- When export to SW button is pressed ---
|
|
Private Sub ExportSWButton_Click(sender As Object, e As EventArgs) Handles ExportSWButton.Click
|
|
Dim exportTable As DataTable
|
|
exportTable = Create_ExportTable()
|
|
|
|
|
|
Program.Build_Grating(exportTable)
|
|
|
|
'Test för att SW API
|
|
Dim pointTable As New DataTable
|
|
pointTable = Create_PointTable()
|
|
|
|
Program.Export_SW(pointTable, 0.025) 'Make variable ref to Height
|
|
|
|
End Sub
|
|
|
|
End Class
|
|
|
|
' LENGTH OCH WIDTH BÖR RITAS TVÄRTOM |