134 lines
4.1 KiB
VB.net
134 lines
4.1 KiB
VB.net
Imports XCCLibrary
|
|
|
|
Public Class GUI
|
|
Dim DrawBox As Panel
|
|
Dim boxX, boxY, boxW, boxH, boxMidX, boxMidY As Integer
|
|
Dim GratingW, GratingH As Double
|
|
Dim DrawW, DrawH As Integer
|
|
Dim Aspect1, Aspect2 As Double
|
|
Dim pDiff As Double
|
|
|
|
Public p1X, p1Y, p2X, p2Y, p3X, p3Y, p4X, p4Y As Integer
|
|
|
|
|
|
|
|
Sub GUI_load() Handles MyBase.Load
|
|
DrawBox = DrawingPanel
|
|
|
|
AddHandler DrawBox.Paint, AddressOf DrawingPanel_Paint
|
|
get_drawboxParameters()
|
|
set_startPointsX()
|
|
set_startPointsY()
|
|
End Sub
|
|
|
|
Private Sub set_startPointsX()
|
|
p1X = boxMidX - CInt(DrawW / 2)
|
|
p2X = boxMidX + CInt(DrawW / 2)
|
|
p3X = boxMidX + CInt(DrawW / 2)
|
|
p4X = boxMidX - CInt(DrawW / 2)
|
|
End Sub
|
|
|
|
Private Sub set_startPointsY()
|
|
p1Y = boxMidY - CInt(DrawH / 2)
|
|
p2Y = boxMidY - CInt(DrawH / 2)
|
|
p3Y = boxMidY + CInt(DrawH / 2)
|
|
p4Y = boxMidY + CInt(DrawH / 2)
|
|
End Sub
|
|
|
|
Private Sub get_drawboxParameters()
|
|
boxX = DrawBox.Location.X 'Behövs ej
|
|
boxY = DrawBox.Location.Y 'Behövs ej
|
|
|
|
boxW = DrawBox.Size.Width
|
|
boxH = DrawBox.Size.Height
|
|
|
|
boxMidX = boxW / 2
|
|
boxMidY = boxH / 2
|
|
|
|
DrawW = boxW - 50
|
|
DrawH = boxH - 50
|
|
|
|
Aspect1 = DrawW / DrawH
|
|
End Sub
|
|
|
|
Private Sub DrawingPanel_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs)
|
|
Dim pen As Pen = New Pen(Color.Red, 2)
|
|
e.Graphics.DrawLine(pen, p1X, p1Y, p2X, p2Y)
|
|
e.Graphics.DrawLine(pen, p2X, p2Y, p3X, p3Y)
|
|
e.Graphics.DrawLine(pen, p3X, p3Y, p4X, p4Y)
|
|
e.Graphics.DrawLine(pen, p4X, p4Y, p1X, p1Y)
|
|
End Sub
|
|
|
|
Private Sub UpdateButton_Click(sender As Object, e As EventArgs) Handles UpdateButton.Click
|
|
GratingH = HeightBox.Text
|
|
GratingW = WidthBox.Text
|
|
Aspect2 = GratingW / GratingH
|
|
If Aspect2 > Aspect1 Then
|
|
'Change draw height
|
|
pDiff = GratingW / DrawW
|
|
|
|
p1Y = boxMidY - CInt(GratingH / (pDiff * 2))
|
|
p2Y = boxMidY - CInt(GratingH / (pDiff * 2))
|
|
p3Y = boxMidY + CInt(GratingH / (pDiff * 2))
|
|
p4Y = boxMidY + CInt(GratingH / (pDiff * 2))
|
|
|
|
set_startPointsX()
|
|
Else
|
|
'Change draw width
|
|
pDiff = GratingH / DrawH
|
|
|
|
p1X = boxMidX - CInt(GratingW / (pDiff * 2))
|
|
p2X = boxMidX + CInt(GratingW / (pDiff * 2))
|
|
p3X = boxMidX + CInt(GratingW / (pDiff * 2))
|
|
p4X = boxMidX - CInt(GratingW / (pDiff * 2))
|
|
|
|
set_startPointsY()
|
|
End If
|
|
|
|
'Redraw rectangle
|
|
Me.Refresh()
|
|
|
|
|
|
End Sub
|
|
|
|
Private Function create_pointTable()
|
|
Dim pointTable As New DataTable
|
|
pointTable.Columns.Add("X", GetType(Double))
|
|
pointTable.Columns.Add("Y", GetType(Double))
|
|
|
|
'For i = 0 To 3
|
|
' pointTable.Rows.Add()
|
|
' Dim tempPX, tempPY As Double
|
|
' 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") = -(boxMidX - p1X) * pDiff / 1000
|
|
pointTable.Rows(0)("Y") = (boxMidY - p1Y) * pDiff / 1000
|
|
pointTable.Rows.Add()
|
|
pointTable.Rows(1)("X") = (p2X - boxMidX) * pDiff / 1000
|
|
pointTable.Rows(1)("Y") = (boxMidY - p2Y) * pDiff / 1000
|
|
pointTable.Rows.Add()
|
|
pointTable.Rows(2)("X") = (p3X - boxMidX) * pDiff / 1000
|
|
pointTable.Rows(2)("Y") = -(p3Y - boxMidY) * pDiff / 1000
|
|
pointTable.Rows.Add()
|
|
pointTable.Rows(3)("X") = -(boxMidX - p4X) * pDiff / 1000
|
|
pointTable.Rows(3)("Y") = -(p4Y - boxMidY) * pDiff / 1000
|
|
|
|
|
|
Return pointTable
|
|
End Function
|
|
|
|
Private Sub ExportSW_Click(sender As Object, e As EventArgs) Handles ExportSW.Click
|
|
Dim pointTable As New DataTable
|
|
pointTable = create_pointTable()
|
|
|
|
Program.Export_SW(pointTable)
|
|
End Sub
|
|
|
|
End Class
|