New namnes etc.

This commit is contained in:
Anton 2021-01-26 15:08:01 +01:00
parent 032bba44b8
commit 997f0523d6
2 changed files with 124 additions and 108 deletions

View File

@ -31,7 +31,7 @@ Partial Class GUI
Me.UpdateButton = New System.Windows.Forms.Button() Me.UpdateButton = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label() Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label() Me.Label2 = New System.Windows.Forms.Label()
Me.ExportSW = New System.Windows.Forms.Button() Me.ExportSWButton = New System.Windows.Forms.Button()
Me.SuspendLayout() Me.SuspendLayout()
' '
'DrawingPanel 'DrawingPanel
@ -45,19 +45,23 @@ Partial Class GUI
' '
'HeightBox 'HeightBox
' '
Me.HeightBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.HeightBox.Location = New System.Drawing.Point(671, 63) Me.HeightBox.Location = New System.Drawing.Point(671, 63)
Me.HeightBox.Margin = New System.Windows.Forms.Padding(3, 2, 3, 2) Me.HeightBox.Margin = New System.Windows.Forms.Padding(3, 2, 3, 2)
Me.HeightBox.Name = "HeightBox" Me.HeightBox.Name = "HeightBox"
Me.HeightBox.Size = New System.Drawing.Size(100, 22) Me.HeightBox.Size = New System.Drawing.Size(100, 26)
Me.HeightBox.TabIndex = 1 Me.HeightBox.TabIndex = 1
Me.HeightBox.Text = "1000"
' '
'WidthBox 'WidthBox
' '
Me.WidthBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.WidthBox.Location = New System.Drawing.Point(457, 63) Me.WidthBox.Location = New System.Drawing.Point(457, 63)
Me.WidthBox.Margin = New System.Windows.Forms.Padding(3, 2, 3, 2) Me.WidthBox.Margin = New System.Windows.Forms.Padding(3, 2, 3, 2)
Me.WidthBox.Name = "WidthBox" Me.WidthBox.Name = "WidthBox"
Me.WidthBox.Size = New System.Drawing.Size(100, 22) Me.WidthBox.Size = New System.Drawing.Size(100, 26)
Me.WidthBox.TabIndex = 2 Me.WidthBox.TabIndex = 2
Me.WidthBox.Text = "1000"
' '
'ContextMenuStrip1 'ContextMenuStrip1
' '
@ -67,7 +71,7 @@ Partial Class GUI
' '
'UpdateButton 'UpdateButton
' '
Me.UpdateButton.Location = New System.Drawing.Point(892, 63) Me.UpdateButton.Location = New System.Drawing.Point(806, 62)
Me.UpdateButton.Margin = New System.Windows.Forms.Padding(3, 2, 3, 2) Me.UpdateButton.Margin = New System.Windows.Forms.Padding(3, 2, 3, 2)
Me.UpdateButton.Name = "UpdateButton" Me.UpdateButton.Name = "UpdateButton"
Me.UpdateButton.Size = New System.Drawing.Size(75, 30) Me.UpdateButton.Size = New System.Drawing.Size(75, 30)
@ -78,38 +82,41 @@ Partial Class GUI
'Label1 'Label1
' '
Me.Label1.AutoSize = True Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(404, 66) Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(398, 66)
Me.Label1.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0) Me.Label1.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0)
Me.Label1.Name = "Label1" Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(44, 17) Me.Label1.Size = New System.Drawing.Size(52, 20)
Me.Label1.TabIndex = 4 Me.Label1.TabIndex = 4
Me.Label1.Text = "Width" Me.Label1.Text = "Width"
' '
'Label2 'Label2
' '
Me.Label2.AutoSize = True Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(613, 66) Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.Location = New System.Drawing.Point(606, 66)
Me.Label2.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0) Me.Label2.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0)
Me.Label2.Name = "Label2" Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(49, 17) Me.Label2.Size = New System.Drawing.Size(58, 20)
Me.Label2.TabIndex = 5 Me.Label2.TabIndex = 5
Me.Label2.Text = "Height" Me.Label2.Text = "Height"
' '
'ExportSW 'ExportSWButton
' '
Me.ExportSW.Location = New System.Drawing.Point(1025, 62) Me.ExportSWButton.BackColor = System.Drawing.SystemColors.ActiveCaption
Me.ExportSW.Name = "ExportSW" Me.ExportSWButton.Location = New System.Drawing.Point(987, 61)
Me.ExportSW.Size = New System.Drawing.Size(75, 31) Me.ExportSWButton.Name = "ExportSWButton"
Me.ExportSW.TabIndex = 6 Me.ExportSWButton.Size = New System.Drawing.Size(75, 31)
Me.ExportSW.Text = "Export" Me.ExportSWButton.TabIndex = 6
Me.ExportSW.UseVisualStyleBackColor = True Me.ExportSWButton.Text = "Export"
Me.ExportSWButton.UseVisualStyleBackColor = False
' '
'GUI 'GUI
' '
Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!) Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(1199, 614) Me.ClientSize = New System.Drawing.Size(1199, 614)
Me.Controls.Add(Me.ExportSW) Me.Controls.Add(Me.ExportSWButton)
Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.UpdateButton) Me.Controls.Add(Me.UpdateButton)
@ -132,5 +139,5 @@ Partial Class GUI
Friend WithEvents UpdateButton As Button Friend WithEvents UpdateButton As Button
Friend WithEvents Label1 As Label Friend WithEvents Label1 As Label
Friend WithEvents Label2 As Label Friend WithEvents Label2 As Label
Friend WithEvents ExportSW As Button Friend WithEvents ExportSWButton As Button
End Class End Class

View File

@ -1,104 +1,77 @@
Imports XCCLibrary Imports XCCLibrary
Public Class GUI Public Class GUI
Dim DrawBox As Panel Dim containerPanel As Panel
Dim boxX, boxY, boxW, boxH, boxMidX, boxMidY As Integer Dim containerX, containerY, containerW, containerH, containerMidX, containerMidY As Integer
Dim GratingW, GratingH As Double Dim gratingMaxW, gratingMaxH As Decimal
Dim DrawW, DrawH As Integer Dim drawW, drawH As Integer
Dim Aspect1, Aspect2 As Double Dim drawAspect, gratingAspect As Decimal
Dim pDiff As Double Dim scaleDiff As Decimal
Dim pCon1X, pCon1Y, pCon2X, pCon2Y, pCon3X, pCon3Y, pCon4X, pCon4Y As Integer
Public p1X, p1Y, p2X, p2Y, p3X, p3Y, p4X, p4Y As Integer
' --- Start method when GUI loads ---
Sub GUI_load() Handles MyBase.Load Sub GUI_load() Handles MyBase.Load
DrawBox = DrawingPanel containerPanel = DrawingPanel
AddHandler DrawBox.Paint, AddressOf DrawingPanel_Paint AddHandler containerPanel.Paint, AddressOf DrawingPanel_Paint
get_drawboxParameters() Get_DrawboxParameters()
set_startPointsX()
set_startPointsY() Set_ContainerPointsX()
Set_ContainerPointsY()
End Sub End Sub
Private Sub set_startPointsX() ' --- Retrive parameters for the drawing box ---
p1X = boxMidX - CInt(DrawW / 2) Private Sub Get_DrawboxParameters()
p2X = boxMidX + CInt(DrawW / 2) containerX = containerPanel.Location.X 'Behövs ej nu
p3X = boxMidX + CInt(DrawW / 2) containerY = containerPanel.Location.Y 'Behövs ej nu
p4X = boxMidX - CInt(DrawW / 2)
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 End Sub
Private Sub set_startPointsY() ' --- Set containers points X-values ---
p1Y = boxMidY - CInt(DrawH / 2) Private Sub Set_ContainerPointsX()
p2Y = boxMidY - CInt(DrawH / 2) pCon1X = containerMidX - CInt(drawW / 2)
p3Y = boxMidY + CInt(DrawH / 2) pCon2X = containerMidX + CInt(drawW / 2)
p4Y = boxMidY + CInt(DrawH / 2) pCon3X = containerMidX + CInt(drawW / 2)
pCon4X = containerMidX - CInt(drawW / 2)
End Sub End Sub
Private Sub get_drawboxParameters() ' --- Set containers points Y-values ---
boxX = DrawBox.Location.X 'Behövs ej Private Sub Set_ContainerPointsY()
boxY = DrawBox.Location.Y 'Behövs ej pCon1Y = containerMidY - CInt(drawH / 2)
pCon2Y = containerMidY - CInt(drawH / 2)
boxW = DrawBox.Size.Width pCon3Y = containerMidY + CInt(drawH / 2)
boxH = DrawBox.Size.Height pCon4Y = containerMidY + CInt(drawH / 2)
boxMidX = boxW / 2
boxMidY = boxH / 2
DrawW = boxW - 50
DrawH = boxH - 50
Aspect1 = DrawW / DrawH
End Sub End Sub
' --- Draw all the lines for the container ---
Private Sub DrawingPanel_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Private Sub DrawingPanel_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs)
Dim pen As Pen = New Pen(Color.Red, 2) Dim pen As Pen = New Pen(Color.Black, 1)
e.Graphics.DrawLine(pen, p1X, p1Y, p2X, p2Y) e.Graphics.DrawLine(pen, pCon1X, pCon1Y, pCon2X, pCon2Y)
e.Graphics.DrawLine(pen, p2X, p2Y, p3X, p3Y) e.Graphics.DrawLine(pen, pCon2X, pCon2Y, pCon3X, pCon3Y)
e.Graphics.DrawLine(pen, p3X, p3Y, p4X, p4Y) e.Graphics.DrawLine(pen, pCon3X, pCon3Y, pCon4X, pCon4Y)
e.Graphics.DrawLine(pen, p4X, p4Y, p1X, p1Y) 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 End Sub
Private Sub UpdateButton_Click(sender As Object, e As EventArgs) Handles UpdateButton.Click ' --- Generate a table containing all the points X- and Y-values ---
GratingH = HeightBox.Text Private Function Create_PointTable()
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 Dim pointTable As New DataTable
pointTable.Columns.Add("X", GetType(Double)) pointTable.Columns.Add("X", GetType(Decimal))
pointTable.Columns.Add("Y", GetType(Double)) pointTable.Columns.Add("Y", GetType(Decimal))
'For i = 0 To 3 'For i = 0 To 3
' pointTable.Rows.Add() ' pointTable.Rows.Add()
' Dim tempPX, tempPY As Double ' Dim tempPX, tempPY As Decimal
' tempPX = (boxMidX - CallByName(Me, "p" & i + 1 & "X", vbGet)) * pDiff / 1000 ' tempPX = (boxMidX - CallByName(Me, "p" & i + 1 & "X", vbGet)) * pDiff / 1000
' tempPY = (boxMidY - CallByName(Me, "p" & i + 1 & "Y", vbGet)) * pDiff / 1000 ' tempPY = (boxMidY - CallByName(Me, "p" & i + 1 & "Y", vbGet)) * pDiff / 1000
@ -107,27 +80,63 @@ Public Class GUI
'Next 'Next
pointTable.Rows.Add() pointTable.Rows.Add()
pointTable.Rows(0)("X") = -(boxMidX - p1X) * pDiff / 1000 pointTable.Rows(0)("X") = -(containerMidX - pCon1X) * scaleDiff / 1000
pointTable.Rows(0)("Y") = (boxMidY - p1Y) * pDiff / 1000 pointTable.Rows(0)("Y") = (containerMidY - pCon1Y) * scaleDiff / 1000
pointTable.Rows.Add() pointTable.Rows.Add()
pointTable.Rows(1)("X") = (p2X - boxMidX) * pDiff / 1000 pointTable.Rows(1)("X") = (pCon2X - containerMidX) * scaleDiff / 1000
pointTable.Rows(1)("Y") = (boxMidY - p2Y) * pDiff / 1000 pointTable.Rows(1)("Y") = (containerMidY - pCon2Y) * scaleDiff / 1000
pointTable.Rows.Add() pointTable.Rows.Add()
pointTable.Rows(2)("X") = (p3X - boxMidX) * pDiff / 1000 pointTable.Rows(2)("X") = (pCon3X - containerMidX) * scaleDiff / 1000
pointTable.Rows(2)("Y") = -(p3Y - boxMidY) * pDiff / 1000 pointTable.Rows(2)("Y") = -(pCon3Y - containerMidY) * scaleDiff / 1000
pointTable.Rows.Add() pointTable.Rows.Add()
pointTable.Rows(3)("X") = -(boxMidX - p4X) * pDiff / 1000 pointTable.Rows(3)("X") = -(containerMidX - pCon4X) * scaleDiff / 1000
pointTable.Rows(3)("Y") = -(p4Y - boxMidY) * pDiff / 1000 pointTable.Rows(3)("Y") = -(pCon4Y - containerMidY) * scaleDiff / 1000
Return pointTable Return pointTable
End Function End Function
Private Sub ExportSW_Click(sender As Object, e As EventArgs) Handles ExportSW.Click
' ---------- 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 Dim pointTable As New DataTable
pointTable = create_pointTable() pointTable = Create_PointTable()
Program.Export_SW(pointTable) Program.Export_SW(pointTable)
End Sub End Sub
End Class End Class
'SEPERATE HOW WE CALCULATE POINTS IN GUI AND ACTUAL MEASURMENTS