142 lines
5.3 KiB
VB.net
142 lines
5.3 KiB
VB.net
Imports XCCLibrary
|
|
|
|
Public Class GUI
|
|
Dim containerPanel As Panel
|
|
Dim containerX, containerY, containerW, containerH, containerMidX, containerMidY As Integer
|
|
Dim gratingMaxW, gratingMaxH As Decimal
|
|
Dim drawW, drawH As Integer
|
|
Dim drawAspect, gratingAspect As Decimal
|
|
Dim scaleDiff As Decimal
|
|
Dim pCon1X, pCon1Y, pCon2X, pCon2Y, pCon3X, pCon3Y, pCon4X, pCon4Y As Integer
|
|
|
|
' --- Start method when GUI loads ---
|
|
Sub GUI_load() Handles MyBase.Load
|
|
containerPanel = DrawingPanel
|
|
|
|
AddHandler containerPanel.Paint, AddressOf DrawingPanel_Paint
|
|
Get_DrawboxParameters()
|
|
|
|
Set_ContainerPointsX()
|
|
Set_ContainerPointsY()
|
|
End Sub
|
|
|
|
' --- Retrive parameters for the drawing box ---
|
|
Private Sub Get_DrawboxParameters()
|
|
containerX = containerPanel.Location.X 'Behövs ej nu
|
|
containerY = containerPanel.Location.Y 'Behövs ej nu
|
|
|
|
containerW = containerPanel.Size.Width
|
|
containerH = containerPanel.Size.Height
|
|
|
|
containerMidX = containerW / 2
|
|
containerMidY = containerH / 2
|
|
|
|
drawW = containerW - 60
|
|
drawH = containerH - 60
|
|
|
|
drawAspect = drawW / drawH
|
|
End Sub
|
|
|
|
' --- Set containers points X-values ---
|
|
Private Sub Set_ContainerPointsX()
|
|
pCon1X = containerMidX - CInt(drawW / 2)
|
|
pCon2X = containerMidX + CInt(drawW / 2)
|
|
pCon3X = containerMidX + CInt(drawW / 2)
|
|
pCon4X = containerMidX - CInt(drawW / 2)
|
|
End Sub
|
|
|
|
' --- Set containers points Y-values ---
|
|
Private Sub Set_ContainerPointsY()
|
|
pCon1Y = containerMidY - CInt(drawH / 2)
|
|
pCon2Y = containerMidY - CInt(drawH / 2)
|
|
pCon3Y = containerMidY + CInt(drawH / 2)
|
|
pCon4Y = containerMidY + CInt(drawH / 2)
|
|
End Sub
|
|
|
|
' --- Draw all the lines for the container ---
|
|
Private Sub DrawingPanel_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs)
|
|
Dim pen As Pen = New Pen(Color.Black, 1)
|
|
e.Graphics.DrawLine(pen, pCon1X, pCon1Y, pCon2X, pCon2Y)
|
|
e.Graphics.DrawLine(pen, pCon2X, pCon2Y, pCon3X, pCon3Y)
|
|
e.Graphics.DrawLine(pen, pCon3X, pCon3Y, pCon4X, pCon4Y)
|
|
e.Graphics.DrawLine(pen, pCon4X, pCon4Y, pCon1X, pCon1Y)
|
|
'Här måste den anpassa sig till antal punkter som ska ritas och i vilken ordning
|
|
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 3
|
|
' pointTable.Rows.Add()
|
|
' Dim tempPX, tempPY As Decimal
|
|
' tempPX = (boxMidX - CallByName(Me, "p" & i + 1 & "X", vbGet)) * pDiff / 1000
|
|
' tempPY = (boxMidY - CallByName(Me, "p" & i + 1 & "Y", vbGet)) * pDiff / 1000
|
|
|
|
' pointTable.Rows(i)("X") = tempPX
|
|
' pointTable.Rows(i)("Y") = tempPY
|
|
'Next
|
|
|
|
pointTable.Rows.Add()
|
|
pointTable.Rows(0)("X") = -(containerMidX - pCon1X) * scaleDiff / 1000
|
|
pointTable.Rows(0)("Y") = (containerMidY - pCon1Y) * scaleDiff / 1000
|
|
pointTable.Rows.Add()
|
|
pointTable.Rows(1)("X") = (pCon2X - containerMidX) * scaleDiff / 1000
|
|
pointTable.Rows(1)("Y") = (containerMidY - pCon2Y) * scaleDiff / 1000
|
|
pointTable.Rows.Add()
|
|
pointTable.Rows(2)("X") = (pCon3X - containerMidX) * scaleDiff / 1000
|
|
pointTable.Rows(2)("Y") = -(pCon3Y - containerMidY) * scaleDiff / 1000
|
|
pointTable.Rows.Add()
|
|
pointTable.Rows(3)("X") = -(containerMidX - pCon4X) * scaleDiff / 1000
|
|
pointTable.Rows(3)("Y") = -(pCon4Y - containerMidY) * scaleDiff / 1000
|
|
|
|
Return pointTable
|
|
End Function
|
|
|
|
|
|
' ---------- GUI interactions ------------
|
|
|
|
' --- When update button is pressed ---
|
|
Private Sub UpdateButton_Click(sender As Object, e As EventArgs) Handles UpdateButton.Click
|
|
gratingMaxH = HeightBox.Text
|
|
gratingMaxW = WidthBox.Text
|
|
gratingAspect = gratingMaxW / gratingMaxH
|
|
If gratingAspect > drawAspect Then
|
|
'Change draw height
|
|
scaleDiff = gratingMaxW / drawW
|
|
|
|
pCon1Y = containerMidY - CInt(gratingMaxH / (scaleDiff * 2))
|
|
pCon2Y = containerMidY - CInt(gratingMaxH / (scaleDiff * 2))
|
|
pCon3Y = containerMidY + CInt(gratingMaxH / (scaleDiff * 2))
|
|
pCon4Y = containerMidY + CInt(gratingMaxH / (scaleDiff * 2))
|
|
|
|
Set_ContainerPointsX()
|
|
Else
|
|
'Change draw width
|
|
scaleDiff = gratingMaxH / drawH
|
|
|
|
pCon1X = containerMidX - CInt(gratingMaxW / (scaleDiff * 2))
|
|
pCon2X = containerMidX + CInt(gratingMaxW / (scaleDiff * 2))
|
|
pCon3X = containerMidX + CInt(gratingMaxW / (scaleDiff * 2))
|
|
pCon4X = containerMidX - CInt(gratingMaxW / (scaleDiff * 2))
|
|
|
|
Set_ContainerPointsY()
|
|
End If
|
|
|
|
'Redraw rectangle
|
|
Me.Refresh()
|
|
End Sub
|
|
|
|
' --- When export to SW button is pressed ---
|
|
Private Sub ExportSWButton_Click(sender As Object, e As EventArgs) Handles ExportSWButton.Click
|
|
Dim pointTable As New DataTable
|
|
pointTable = Create_PointTable()
|
|
|
|
Program.Export_SW(pointTable)
|
|
End Sub
|
|
|
|
End Class
|
|
|
|
'SEPERATE HOW WE CALCULATE POINTS IN GUI AND ACTUAL MEASURMENTS |