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 pCon1(3) As Decimal 'pCon(0) = pixel X, pCon(2) = SW X, etc. Dim pCon2(3) As Decimal Dim pCon3(3) As Decimal Dim pCon4(3) As Decimal ' --- 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() 'Create_StartPoints() 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() pCon1(0) = containerMidX - drawW / 2 pCon2(0) = containerMidX + drawW / 2 pCon3(0) = containerMidX + drawW / 2 pCon4(0) = containerMidX - drawW / 2 End Sub ' --- Set containers points Y-values --- Private Sub Set_ContainerPointsY() pCon1(1) = containerMidY - drawH / 2 pCon2(1) = containerMidY - drawH / 2 pCon3(1) = containerMidY + drawH / 2 pCon4(1) = containerMidY + 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 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))) '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)) pointTable.Rows.Add() pointTable.Rows(0)("X") = pCon1(2) pointTable.Rows(0)("Y") = pCon1(3) pointTable.Rows.Add() pointTable.Rows(1)("X") = pCon2(2) pointTable.Rows(1)("Y") = pCon2(3) pointTable.Rows.Add() pointTable.Rows(2)("X") = pCon3(2) pointTable.Rows(2)("Y") = pCon3(3) pointTable.Rows.Add() pointTable.Rows(3)("X") = pCon4(2) pointTable.Rows(3)("Y") = pCon4(3) 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 pCon1(1) = containerMidY - gratingMaxH / (scaleDiff * 2) pCon2(1) = containerMidY - gratingMaxH / (scaleDiff * 2) pCon3(1) = containerMidY + gratingMaxH / (scaleDiff * 2) pCon4(1) = containerMidY + gratingMaxH / (scaleDiff * 2) Set_ContainerPointsX() Else 'Change draw width scaleDiff = gratingMaxH / drawH pCon1(0) = containerMidX - gratingMaxW / (scaleDiff * 2) pCon2(0) = containerMidX + gratingMaxW / (scaleDiff * 2) pCon3(0) = containerMidX + gratingMaxW / (scaleDiff * 2) pCon4(0) = containerMidX - gratingMaxW / (scaleDiff * 2) Set_ContainerPointsY() End If 'Redraw rectangle Me.Refresh() 'SW X-values pCon1(2) = (-gratingMaxW / 2) / 1000 pCon2(2) = (gratingMaxW / 2) / 1000 pCon3(2) = (gratingMaxW / 2) / 1000 pCon4(2) = (-gratingMaxW / 2) / 1000 'SW Y-values pCon1(3) = (gratingMaxH / 2) / 1000 pCon2(3) = (gratingMaxH / 2) / 1000 pCon3(3) = (-gratingMaxH / 2) / 1000 pCon4(3) = (-gratingMaxH / 2) / 1000 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) Program.Create_Drawing() End Sub End Class ' CallByName(Me, "p" & i + 1 & "X", vbGet)