diff --git a/Wardrobe/GUI.Designer.vb b/Wardrobe/GUI.Designer.vb index 5ffd0d0..d0fac9d 100644 --- a/Wardrobe/GUI.Designer.vb +++ b/Wardrobe/GUI.Designer.vb @@ -31,7 +31,7 @@ Partial Class GUI Me.UpdateButton = New System.Windows.Forms.Button() Me.Label1 = 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() ' 'DrawingPanel @@ -45,19 +45,23 @@ Partial Class GUI ' '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.Margin = New System.Windows.Forms.Padding(3, 2, 3, 2) 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.Text = "1000" ' '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.Margin = New System.Windows.Forms.Padding(3, 2, 3, 2) 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.Text = "1000" ' 'ContextMenuStrip1 ' @@ -67,7 +71,7 @@ Partial Class GUI ' '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.Name = "UpdateButton" Me.UpdateButton.Size = New System.Drawing.Size(75, 30) @@ -78,38 +82,41 @@ Partial Class GUI 'Label1 ' 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.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.Text = "Width" ' 'Label2 ' 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.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.Text = "Height" ' - 'ExportSW + 'ExportSWButton ' - Me.ExportSW.Location = New System.Drawing.Point(1025, 62) - Me.ExportSW.Name = "ExportSW" - Me.ExportSW.Size = New System.Drawing.Size(75, 31) - Me.ExportSW.TabIndex = 6 - Me.ExportSW.Text = "Export" - Me.ExportSW.UseVisualStyleBackColor = True + Me.ExportSWButton.BackColor = System.Drawing.SystemColors.ActiveCaption + Me.ExportSWButton.Location = New System.Drawing.Point(987, 61) + Me.ExportSWButton.Name = "ExportSWButton" + Me.ExportSWButton.Size = New System.Drawing.Size(75, 31) + Me.ExportSWButton.TabIndex = 6 + Me.ExportSWButton.Text = "Export" + Me.ExportSWButton.UseVisualStyleBackColor = False ' 'GUI ' Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font 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.Label1) Me.Controls.Add(Me.UpdateButton) @@ -132,5 +139,5 @@ Partial Class GUI Friend WithEvents UpdateButton As Button Friend WithEvents Label1 As Label Friend WithEvents Label2 As Label - Friend WithEvents ExportSW As Button + Friend WithEvents ExportSWButton As Button End Class diff --git a/Wardrobe/GUI.vb b/Wardrobe/GUI.vb index 1786e68..b176a30 100644 --- a/Wardrobe/GUI.vb +++ b/Wardrobe/GUI.vb @@ -1,104 +1,77 @@ 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 - - + 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 - DrawBox = DrawingPanel + containerPanel = DrawingPanel - AddHandler DrawBox.Paint, AddressOf DrawingPanel_Paint - get_drawboxParameters() - set_startPointsX() - set_startPointsY() + AddHandler containerPanel.Paint, AddressOf DrawingPanel_Paint + Get_DrawboxParameters() + + Set_ContainerPointsX() + Set_ContainerPointsY() 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) + ' --- 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 - Private Sub set_startPointsY() - p1Y = boxMidY - CInt(DrawH / 2) - p2Y = boxMidY - CInt(DrawH / 2) - p3Y = boxMidY + CInt(DrawH / 2) - p4Y = boxMidY + CInt(DrawH / 2) + ' --- 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 - 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 + ' --- 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.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) + 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 - 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() + ' --- 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(Double)) - pointTable.Columns.Add("Y", GetType(Double)) + pointTable.Columns.Add("X", GetType(Decimal)) + pointTable.Columns.Add("Y", GetType(Decimal)) 'For i = 0 To 3 ' pointTable.Rows.Add() - ' Dim tempPX, tempPY As Double + ' 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 @@ -107,27 +80,63 @@ Public Class GUI 'Next pointTable.Rows.Add() - pointTable.Rows(0)("X") = -(boxMidX - p1X) * pDiff / 1000 - pointTable.Rows(0)("Y") = (boxMidY - p1Y) * pDiff / 1000 + pointTable.Rows(0)("X") = -(containerMidX - pCon1X) * scaleDiff / 1000 + pointTable.Rows(0)("Y") = (containerMidY - pCon1Y) * scaleDiff / 1000 pointTable.Rows.Add() - pointTable.Rows(1)("X") = (p2X - boxMidX) * pDiff / 1000 - pointTable.Rows(1)("Y") = (boxMidY - p2Y) * pDiff / 1000 + pointTable.Rows(1)("X") = (pCon2X - containerMidX) * scaleDiff / 1000 + pointTable.Rows(1)("Y") = (containerMidY - pCon2Y) * scaleDiff / 1000 pointTable.Rows.Add() - pointTable.Rows(2)("X") = (p3X - boxMidX) * pDiff / 1000 - pointTable.Rows(2)("Y") = -(p3Y - boxMidY) * pDiff / 1000 + pointTable.Rows(2)("X") = (pCon3X - containerMidX) * scaleDiff / 1000 + pointTable.Rows(2)("Y") = -(pCon3Y - containerMidY) * scaleDiff / 1000 pointTable.Rows.Add() - pointTable.Rows(3)("X") = -(boxMidX - p4X) * pDiff / 1000 - pointTable.Rows(3)("Y") = -(p4Y - boxMidY) * pDiff / 1000 - + pointTable.Rows(3)("X") = -(containerMidX - pCon4X) * scaleDiff / 1000 + pointTable.Rows(3)("Y") = -(pCon4Y - containerMidY) * scaleDiff / 1000 Return pointTable 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 - pointTable = create_pointTable() + pointTable = Create_PointTable() Program.Export_SW(pointTable) End Sub End Class + +'SEPERATE HOW WE CALCULATE POINTS IN GUI AND ACTUAL MEASURMENTS \ No newline at end of file