Public Class Side_Rectangle Private Shared sideSquareValues(3) As Integer Private Shared numOfSideRectangles As Integer = 0 ' --- Create textboxes when user clicks the rectangle side recess button --- Public Shared Sub SquareSideButtton(sender As Object, e As EventArgs) GUI.Controls("AngleButton").Enabled = False GUI.Controls("Button_Square").Enabled = False GUI.Controls("Button_SquareSide").Enabled = False Dim buttonX As Integer = GUI.Controls("Button_SquareSide").Location.X Dim buttonY As Integer = GUI.Controls("Button_SquareSide").Location.Y GUI.Create_TextBox("X_TextBox", "", buttonX + 20, buttonY + 40, 60) AddHandler GUI.Controls("X_TextBox").TextChanged, AddressOf FunctionTextSide_Changed AddHandler GUI.Controls("X_TextBox").KeyPress, AddressOf FunctionText_KeyPress GUI.Create_LabelGUI("X_Label", "L", buttonX, buttonY + 43) GUI.Create_TextBox("Y_TextBox", "", buttonX + 130, buttonY + 40, 60) AddHandler GUI.Controls("Y_TextBox").TextChanged, AddressOf FunctionTextSide_Changed AddHandler GUI.Controls("Y_TextBox").KeyPress, AddressOf FunctionText_KeyPress GUI.Create_LabelGUI("Y_Label", "W", buttonX + 110, buttonY + 43) GUI.Create_TextBox("Off_TextBox", "", buttonX + 250, buttonY + 40, 60) AddHandler GUI.Controls("Off_TextBox").TextChanged, AddressOf FunctionTextSide_Changed AddHandler GUI.Controls("Off_TextBox").KeyPress, AddressOf FunctionText_KeyPress GUI.Create_LabelGUI("Off_Label", "Offset", buttonX + 210, buttonY + 43) End Sub ' --- Check the key pressed by the user --- Private Shared Sub FunctionText_KeyPress(sender As Object, e As KeyPressEventArgs) User_Input.Check_IfNumber(e) End Sub ' --- Adds clickable buttons for all sides if conditions are met --- Private Shared Sub FunctionTextSide_Changed(sender As TextBox, e As EventArgs) Try sideSquareValues(0) = CInt(GUI.Controls("X_TextBox").Text) sideSquareValues(1) = CInt(GUI.Controls("Y_TextBox").Text) sideSquareValues(2) = CInt(GUI.Controls("Off_TextBox").Text) Catch ex As Exception sideSquareValues(0) = 0 sideSquareValues(1) = 0 sideSquareValues(2) = 0 End Try If sideSquareValues(0) > 0 AndAlso sideSquareValues(1) > 0 AndAlso sideSquareValues(2) > 0 Then If GUI.DrawingPanel.Controls.Count = 2 Then For i = 1 To 4 Dim sidePoints As New List(Of String) If i = 1 Then Create_SideButton(sideSquareValues(0) / (Data.scaleDiff), 30, Data.grossAreaPoints.Rows(0)("GUI X") + sideSquareValues(2) / (Data.scaleDiff), Data.grossAreaPoints.Rows(0)("GUI Y") - 30 / 2, "Button_" & i) ElseIf i = 2 Then Create_SideButton(30, sideSquareValues(1) / (Data.scaleDiff), Data.grossAreaPoints.Rows(1)("GUI X") - 30 / 2, Data.grossAreaPoints.Rows(1)("GUI Y") + sideSquareValues(2) / (Data.scaleDiff), "Button_" & i) ElseIf i = 3 Then Create_SideButton(sideSquareValues(0) / (Data.scaleDiff), 30, Data.grossAreaPoints.Rows(2)("GUI X") - sideSquareValues(2) / (Data.scaleDiff) - sideSquareValues(0) / (Data.scaleDiff), Data.grossAreaPoints.Rows(2)("GUI Y") - 30 / 2, "Button_" & i) Else Create_SideButton(30, sideSquareValues(1) / (Data.scaleDiff), Data.grossAreaPoints.Rows(3)("GUI X") - 30 / 2, Data.grossAreaPoints.Rows(3)("GUI Y") - sideSquareValues(2) / (Data.scaleDiff) - sideSquareValues(1) / (Data.scaleDiff), "Button_" & i) End If Next Else ' Update button size and position For i = 2 To GUI.DrawingPanel.Controls.Count - 1 Dim buttonSide As Integer = CInt(GUI.DrawingPanel.Controls(i).Name.Split("_")(1)) If buttonSide = 1 Then GUI.DrawingPanel.Controls(i).Width = sideSquareValues(0) / (Data.scaleDiff) GUI.DrawingPanel.Controls(i).Left = Data.grossAreaPoints.Rows(0)("GUI X") + sideSquareValues(2) / (Data.scaleDiff) ElseIf buttonSide = 2 Then GUI.DrawingPanel.Controls(i).Height = sideSquareValues(1) / (Data.scaleDiff) GUI.DrawingPanel.Controls(i).Top = Data.grossAreaPoints.Rows(1)("GUI Y") + sideSquareValues(2) / (Data.scaleDiff) ElseIf buttonSide = 3 Then GUI.DrawingPanel.Controls(i).Width = sideSquareValues(0) / (Data.scaleDiff) GUI.DrawingPanel.Controls(i).Left = Data.grossAreaPoints.Rows(2)("GUI X") - sideSquareValues(2) / (Data.scaleDiff) - GUI.DrawingPanel.Controls(i).Width Else GUI.DrawingPanel.Controls(i).Height = sideSquareValues(1) / (Data.scaleDiff) GUI.DrawingPanel.Controls(i).Top = Data.grossAreaPoints.Rows(3)("GUI Y") - sideSquareValues(2) / (Data.scaleDiff) - GUI.DrawingPanel.Controls(i).Height End If Next End If ElseIf GUI.DrawingPanel.Controls.Count > 2 Then For i = 2 To GUI.DrawingPanel.Controls.Count - 1 RemoveHandler GUI.DrawingPanel.Controls(2).Click, AddressOf SideButton_Click GUI.DrawingPanel.Controls.RemoveAt(2) Next End If End Sub ' --- Template to create corner buttons --- Private Shared Sub Create_SideButton(bWidth As Integer, bHeight As Integer, bLeft As Integer, bTop As Integer, bName As String) Dim sideButton As New Button With { .Width = bWidth, .Height = bHeight, .Left = bLeft, .Top = bTop, .Name = bName, .Text = "" } sideButton.BackColor = Color.FromArgb(50, Color.Red) sideButton.FlatStyle = FlatStyle.Flat sideButton.FlatAppearance.BorderSize = 0 sideButton.FlatAppearance.MouseOverBackColor = Color.Red sideButton.FlatAppearance.MouseDownBackColor = Color.DarkRed GUI.DrawingPanel.Controls.Add(sideButton) AddHandler sideButton.Click, AddressOf SideButton_Click End Sub ' --- When a side function button is pressed --- Private Shared Sub SideButton_Click(sender As Button, e As EventArgs) 'Determine which side is being pressed Dim sidePressed As Integer = CInt(sender.Name.Split("_")(1)) ' Remove point buttons For i = 2 To GUI.DrawingPanel.Controls.Count - 1 RemoveHandler GUI.DrawingPanel.Controls(2).Click, AddressOf SideButton_Click GUI.DrawingPanel.Controls.RemoveAt(2) Next Dim sidePoints As New List(Of Integer) Dim index As Integer If sidePressed = 1 Then For j = 0 To Data.gratingPoints.Rows.Count - 1 If Data.gratingPoints.Rows(j)("GUI Y") = Data.grossAreaPoints.Rows(0)("GUI Y") Then sidePoints.Add(j) End If Next index = sidePoints(0) If sidePoints.Count > 2 Then For i = sidePoints.Count / 2 To 2 Step -1 If Data.gratingPoints.Rows(sidePoints(i * 2 - 2))("GUI X") < Data.grossAreaPoints.Rows(0)("GUI X") + sideSquareValues(2) / Data.scaleDiff Then index = sidePoints(i * 2 - 2) Exit For End If Next End If ElseIf sidePressed = 2 Then For j = 1 To Data.gratingPoints.Rows.Count - 1 If Data.gratingPoints.Rows(j)("GUI X") = Data.grossAreaPoints.Rows(1)("GUI X") Then sidePoints.Add(j) End If Next index = sidePoints(0) If sidePoints.Count > 2 Then For i = sidePoints.Count / 2 To 2 Step -1 If Data.gratingPoints.Rows(sidePoints(i * 2 - 2))("GUI Y") < Data.grossAreaPoints.Rows(1)("GUI Y") + sideSquareValues(2) / Data.scaleDiff Then index = sidePoints(i * 2 - 2) Exit For End If Next End If ElseIf sidePressed = 3 Then For j = 2 To Data.gratingPoints.Rows.Count - 1 If Data.gratingPoints.Rows(j)("GUI Y") = Data.grossAreaPoints.Rows(2)("GUI Y") Then sidePoints.Add(j) End If Next index = sidePoints(0) If sidePoints.Count > 2 Then For i = sidePoints.Count / 2 To 2 Step -1 If Data.gratingPoints.Rows(sidePoints(i * 2 - 2))("GUI X") > Data.grossAreaPoints.Rows(2)("GUI X") - sideSquareValues(2) / Data.scaleDiff Then index = sidePoints(i * 2 - 2) Exit For End If Next End If Else For j = 3 To Data.gratingPoints.Rows.Count - 1 If Data.gratingPoints.Rows(j)("GUI X") = Data.grossAreaPoints.Rows(3)("GUI X") Then sidePoints.Add(j) End If Next sidePoints.Add(0) index = sidePoints(0) If sidePoints.Count > 2 Then For i = sidePoints.Count / 2 To 2 Step -1 If Data.gratingPoints.Rows(sidePoints(i * 2 - 2))("GUI Y") > Data.grossAreaPoints.Rows(3)("GUI Y") - sideSquareValues(2) / Data.scaleDiff Then index = sidePoints(i * 2 - 2) Exit For End If Next End If End If For i = 2 To Data.pointsMeasurements.Count - 1 Dim mesName As String = Data.pointsMeasurements.Keys(i) If mesName.Split("_")(0) = "SS1" Then If index + 2 = Data.pointsMeasurements(mesName)(1) Then If Draw_Grating.measureLabels(mesName)(3) = 1 Then Draw_Grating.measureLabels(mesName)(0) = Data.gratingPoints.Rows(index + 1)("X") * 1000 - Data.grossAreaPoints.Rows(0)("X") * 1000 - (sideSquareValues(2) + sideSquareValues(0)) Draw_Grating.sideSquareMesLine(mesName)(0) = Data.grossAreaPoints.Rows(0)("GUI X") + (sideSquareValues(2) + sideSquareValues(0)) / Data.scaleDiff Draw_Grating.measureLabels(mesName)(1) = (Draw_Grating.sideSquareMesLine(mesName)(0) + Draw_Grating.sideSquareMesLine(mesName)(2)) / 2 - 8 ElseIf Draw_Grating.measureLabels(mesName)(3) = 2 Then Draw_Grating.measureLabels(mesName)(0) = Data.grossAreaPoints.Rows(1)("Y") * 1000 - Data.gratingPoints.Rows(index + 1)("Y") * 1000 - (sideSquareValues(2) + sideSquareValues(1)) Draw_Grating.sideSquareMesLine(mesName)(1) = Data.grossAreaPoints.Rows(1)("GUI Y") + (sideSquareValues(2) + sideSquareValues(1)) / Data.scaleDiff Draw_Grating.measureLabels(mesName)(2) = (Draw_Grating.sideSquareMesLine(mesName)(1) + Draw_Grating.sideSquareMesLine(mesName)(3)) / 2 - 6 ElseIf Draw_Grating.measureLabels(mesName)(3) = 3 Then Draw_Grating.measureLabels(mesName)(0) = Data.grossAreaPoints.Rows(2)("X") * 1000 - Data.gratingPoints.Rows(index + 1)("X") * 1000 - (sideSquareValues(2) + sideSquareValues(0)) Draw_Grating.sideSquareMesLine(mesName)(0) = Data.grossAreaPoints.Rows(2)("GUI X") - (sideSquareValues(2) + sideSquareValues(0)) / Data.scaleDiff Draw_Grating.measureLabels(mesName)(1) = (Draw_Grating.sideSquareMesLine(mesName)(0) + Draw_Grating.sideSquareMesLine(mesName)(2)) / 2 - 8 Else Draw_Grating.measureLabels(mesName)(0) = Data.gratingPoints.Rows(index + 1)("Y") * 1000 - Data.grossAreaPoints.Rows(3)("Y") * 1000 - (sideSquareValues(2) + sideSquareValues(1)) Draw_Grating.sideSquareMesLine(mesName)(1) = Data.grossAreaPoints.Rows(3)("GUI Y") - (sideSquareValues(2) + sideSquareValues(1)) / Data.scaleDiff Draw_Grating.measureLabels(mesName)(2) = (Draw_Grating.sideSquareMesLine(mesName)(1) + Draw_Grating.sideSquareMesLine(mesName)(3)) / 2 - 6 End If End If End If Next For i = 2 To Data.pointsMeasurements.Count - 1 Dim mesName As String = Data.pointsMeasurements.Keys(i) If mesName.Split("_")(0) <> "SS1" AndAlso index + 1 < Data.pointsMeasurements(mesName)(0) Then Data.pointsMeasurements(mesName)(0) = Data.pointsMeasurements(mesName)(0) + 4 Data.pointsMeasurements(mesName)(1) = Data.pointsMeasurements(mesName)(1) + 4 ElseIf mesName.Split("_")(0) = "SS1" AndAlso index + 2 <= Data.pointsMeasurements(mesName)(1) Then Data.pointsMeasurements(mesName)(1) = Data.pointsMeasurements(mesName)(1) + 4 End If Next Dim mesNum As Integer = Data.pointsMeasurements.Count - 1 Dim pointRow1 As DataRow = Data.gratingPoints.NewRow Dim pointRow2 As DataRow = Data.gratingPoints.NewRow Dim pointRow3 As DataRow = Data.gratingPoints.NewRow Dim pointRow4 As DataRow = Data.gratingPoints.NewRow pointRow1("NAME") = "CS" & numOfSideRectangles & "_" & 1 pointRow1("QUADRANT") = 1 pointRow1("RECESS OK") = False pointRow2("NAME") = "CS" & numOfSideRectangles & "_" & 2 pointRow2("QUADRANT") = 1 pointRow2("RECESS OK") = False pointRow3("NAME") = "CS" & numOfSideRectangles & "_" & 3 pointRow3("QUADRANT") = 1 pointRow3("RECESS OK") = False pointRow4("NAME") = "CS" & numOfSideRectangles & "_" & 4 pointRow4("QUADRANT") = 1 pointRow4("RECESS OK") = False If sidePressed = 1 Then ' Add the new points pointRow1("X") = Data.grossAreaPoints.Rows(0)("X") + sideSquareValues(2) / 1000 pointRow1("Y") = Data.grossAreaPoints.Rows(0)("Y") pointRow1("GUI X") = Data.grossAreaPoints.Rows(0)("GUI X") + sideSquareValues(2) / Data.scaleDiff pointRow1("GUI Y") = Data.grossAreaPoints.Rows(0)("GUI Y") pointRow2("X") = Data.grossAreaPoints.Rows(0)("X") + sideSquareValues(2) / 1000 pointRow2("Y") = Data.grossAreaPoints.Rows(0)("Y") - sideSquareValues(1) / 1000 pointRow2("GUI X") = Data.grossAreaPoints.Rows(0)("GUI X") + sideSquareValues(2) / Data.scaleDiff pointRow2("GUI Y") = Data.grossAreaPoints.Rows(0)("GUI Y") + sideSquareValues(1) / Data.scaleDiff pointRow3("X") = Data.grossAreaPoints.Rows(0)("X") + (sideSquareValues(2) + sideSquareValues(0)) / 1000 pointRow3("Y") = Data.grossAreaPoints.Rows(0)("Y") - sideSquareValues(1) / 1000 pointRow3("GUI X") = Data.grossAreaPoints.Rows(0)("GUI X") + (sideSquareValues(2) + sideSquareValues(0)) / Data.scaleDiff pointRow3("GUI Y") = Data.grossAreaPoints.Rows(0)("GUI Y") + sideSquareValues(1) / Data.scaleDiff pointRow4("X") = Data.grossAreaPoints.Rows(0)("X") + (sideSquareValues(2) + sideSquareValues(0)) / 1000 pointRow4("Y") = Data.grossAreaPoints.Rows(0)("Y") pointRow4("GUI X") = Data.grossAreaPoints.Rows(0)("GUI X") + (sideSquareValues(2) + sideSquareValues(0)) / Data.scaleDiff pointRow4("GUI Y") = Data.grossAreaPoints.Rows(0)("GUI Y") ' Update outer measuements (SW) Data.pointsMeasurements("Lmes")(1) = Data.pointsMeasurements("Lmes")(1) + 4 Data.pointsMeasurements("Wmes")(0) = Data.pointsMeasurements("Wmes")(0) + 4 Data.pointsMeasurements("Wmes")(1) = Data.pointsMeasurements("Wmes")(1) + 4 ' Add recess measuements (SW) Data.pointsMeasurements.Add("SS1_" & mesNum, {sidePoints(0) + 1, index + 2, 1}) Data.pointsMeasurements.Add("SS_" & mesNum + 1, {index + 2, index + 5, 1}) Data.pointsMeasurements.Add("SS_" & mesNum + 2, {index + 2, index + 3, 4}) ' Add support line data for sidesquare measurement Draw_Grating.sideSquareMesLine.Add("SS1_" & mesNum, {Data.gratingPoints.Rows(index)("GUI X"), Data.grossAreaPoints.Rows(0)("GUI Y") - 15, Data.grossAreaPoints.Rows(0)("GUI X") + sideSquareValues(2) / Data.scaleDiff, Data.grossAreaPoints.Rows(0)("GUI Y") - 15}) ' Add recess measurments (GUI) Draw_Grating.measureLabels.Add("SS1_" & mesNum, {CInt(GUI.Controls("Off_TextBox").Text) - (Data.gratingPoints.Rows(index)("X") * 1000 + Data.gratingL / 2), (Data.gratingPoints.Rows(index)("GUI X") + Data.grossAreaPoints.Rows(0)("GUI X") + sideSquareValues(2) / Data.scaleDiff) / 2 - 8, Data.grossAreaPoints.Rows(0)("GUI Y") - 15 - 12 - 3, 1}) '15 är linjen, 12 är textens höjd, 3 är lite extra Draw_Grating.measureLabels.Add("SS_" & mesNum + 1, {CInt(GUI.Controls("X_TextBox").Text), Data.grossAreaPoints.Rows(0)("GUI X") + sideSquareValues(2) / (Data.scaleDiff) + CInt(GUI.Controls("X_TextBox").Text) / (2 * Data.scaleDiff) - 8, Data.grossAreaPoints.Rows(0)("GUI Y") + sideSquareValues(1) / (Data.scaleDiff) + 3, 1}) Draw_Grating.measureLabels.Add("SS_" & mesNum + 2, {CInt(GUI.Controls("Y_TextBox").Text), Data.grossAreaPoints.Rows(0)("GUI X") + sideSquareValues(2) / Data.scaleDiff - 18 - 3, Data.grossAreaPoints.Rows(0)("GUI Y") + CInt(GUI.Controls("Y_TextBox").Text) / (2 * Data.scaleDiff) - 4, 1}) ElseIf sidePressed = 2 Then ' Add the new points pointRow1("X") = Data.grossAreaPoints.Rows(1)("X") pointRow1("Y") = Data.grossAreaPoints.Rows(1)("Y") - sideSquareValues(2) / 1000 pointRow1("GUI X") = Data.grossAreaPoints.Rows(1)("GUI X") pointRow1("GUI Y") = Data.grossAreaPoints.Rows(1)("GUI Y") + sideSquareValues(2) / Data.scaleDiff pointRow2("X") = Data.grossAreaPoints.Rows(1)("X") - sideSquareValues(0) / 1000 pointRow2("Y") = Data.grossAreaPoints.Rows(1)("Y") - sideSquareValues(2) / 1000 pointRow2("GUI X") = Data.grossAreaPoints.Rows(1)("GUI X") - sideSquareValues(0) / Data.scaleDiff pointRow2("GUI Y") = Data.grossAreaPoints.Rows(1)("GUI Y") + sideSquareValues(2) / Data.scaleDiff pointRow3("X") = Data.grossAreaPoints.Rows(1)("X") - sideSquareValues(0) / 1000 pointRow3("Y") = Data.grossAreaPoints.Rows(1)("Y") - (sideSquareValues(2) + sideSquareValues(1)) / 1000 pointRow3("GUI X") = Data.grossAreaPoints.Rows(1)("GUI X") - sideSquareValues(0) / Data.scaleDiff pointRow3("GUI Y") = Data.grossAreaPoints.Rows(1)("GUI Y") + (sideSquareValues(2) + sideSquareValues(1)) / Data.scaleDiff pointRow4("X") = Data.grossAreaPoints.Rows(1)("X") pointRow4("Y") = Data.grossAreaPoints.Rows(1)("Y") - (sideSquareValues(2) + sideSquareValues(1)) / 1000 pointRow4("GUI X") = Data.grossAreaPoints.Rows(1)("GUI X") pointRow4("GUI Y") = Data.grossAreaPoints.Rows(1)("GUI Y") + (sideSquareValues(2) + sideSquareValues(1)) / Data.scaleDiff ' Update outer measuements (SW) Data.pointsMeasurements("Wmes")(1) = Data.pointsMeasurements("Wmes")(1) + 4 ' Add recess measuements (SW) Data.pointsMeasurements.Add("SS1_" & mesNum, {sidePoints(0) + 1, index + 2, 2}) Data.pointsMeasurements.Add("SS_" & mesNum + 1, {index + 2, index + 5, 2}) Data.pointsMeasurements.Add("SS_" & mesNum + 2, {index + 2, index + 3, 3}) ' Add support line data for sidesquare measurement Draw_Grating.sideSquareMesLine.Add("SS1_" & mesNum, {Data.grossAreaPoints.Rows(1)("GUI X") + 15, Data.gratingPoints.Rows(index)("GUI Y"), Data.grossAreaPoints.Rows(1)("GUI X") + 15, Data.grossAreaPoints.Rows(1)("GUI Y") + sideSquareValues(2) / Data.scaleDiff}) ' Add recess measurments (GUI) Draw_Grating.measureLabels.Add("SS1_" & mesNum, {CInt(GUI.Controls("Off_TextBox").Text) - (Data.gratingW / 2 - Data.gratingPoints.Rows(index)("Y") * 1000), Data.grossAreaPoints.Rows(1)("GUI X") + 15 + 3, (Data.gratingPoints.Rows(index)("GUI Y") + Data.grossAreaPoints.Rows(1)("GUI Y") + sideSquareValues(2) / Data.scaleDiff) / 2 - 4, 2}) Draw_Grating.measureLabels.Add("SS_" & mesNum + 1, {CInt(GUI.Controls("Y_TextBox").Text), Data.grossAreaPoints.Rows(1)("GUI X") - sideSquareValues(0) / Data.scaleDiff - 18 - 3, Data.grossAreaPoints.Rows(1)("GUI Y") + (sideSquareValues(2) + sideSquareValues(1) / 2) / Data.scaleDiff - 4, 2}) Draw_Grating.measureLabels.Add("SS_" & mesNum + 2, {CInt(GUI.Controls("X_TextBox").Text), Data.grossAreaPoints.Rows(1)("GUI X") - sideSquareValues(0) / (2 * Data.scaleDiff) - 8, Data.grossAreaPoints.Rows(1)("GUI Y") + sideSquareValues(2) / Data.scaleDiff - 15 - 3, 2}) ElseIf sidePressed = 3 Then ' Add the new points pointRow1("X") = Data.grossAreaPoints.Rows(2)("X") - sideSquareValues(2) / 1000 pointRow1("Y") = Data.grossAreaPoints.Rows(2)("Y") pointRow1("GUI X") = Data.grossAreaPoints.Rows(2)("GUI X") - sideSquareValues(2) / Data.scaleDiff pointRow1("GUI Y") = Data.grossAreaPoints.Rows(2)("GUI Y") pointRow2("X") = Data.grossAreaPoints.Rows(2)("X") - sideSquareValues(2) / 1000 pointRow2("Y") = Data.grossAreaPoints.Rows(2)("Y") + sideSquareValues(1) / 1000 pointRow2("GUI X") = Data.grossAreaPoints.Rows(2)("GUI X") - sideSquareValues(2) / Data.scaleDiff pointRow2("GUI Y") = Data.grossAreaPoints.Rows(2)("GUI Y") - sideSquareValues(1) / Data.scaleDiff pointRow3("X") = Data.grossAreaPoints.Rows(2)("X") - (sideSquareValues(2) + sideSquareValues(0)) / 1000 pointRow3("Y") = Data.grossAreaPoints.Rows(2)("Y") + sideSquareValues(1) / 1000 pointRow3("GUI X") = Data.grossAreaPoints.Rows(2)("GUI X") - (sideSquareValues(2) + sideSquareValues(0)) / Data.scaleDiff pointRow3("GUI Y") = Data.grossAreaPoints.Rows(2)("GUI Y") - sideSquareValues(1) / Data.scaleDiff pointRow4("X") = Data.grossAreaPoints.Rows(2)("X") - (sideSquareValues(2) + sideSquareValues(0)) / 1000 pointRow4("Y") = Data.grossAreaPoints.Rows(2)("Y") pointRow4("GUI X") = Data.grossAreaPoints.Rows(2)("GUI X") - (sideSquareValues(2) + sideSquareValues(0)) / Data.scaleDiff pointRow4("GUI Y") = Data.grossAreaPoints.Rows(2)("GUI Y") ' Add recess measuements (SW) Data.pointsMeasurements.Add("SS1_" & mesNum, {sidePoints(0) + 1, index + 2, 3}) Data.pointsMeasurements.Add("SS_" & mesNum + 1, {index + 2, index + 5, 3}) Data.pointsMeasurements.Add("SS_" & mesNum + 2, {index + 2, index + 3, 4}) ' Add support line data for sidesquare measurement Draw_Grating.sideSquareMesLine.Add("SS1_" & mesNum, {Data.gratingPoints.Rows(index)("GUI X"), Data.grossAreaPoints.Rows(2)("GUI Y") + 15, Data.grossAreaPoints.Rows(2)("GUI X") - sideSquareValues(2) / Data.scaleDiff, Data.grossAreaPoints.Rows(2)("GUI Y") + 15}) ' Add recess measurments (GUI) Draw_Grating.measureLabels.Add("SS1_" & mesNum, {CInt(GUI.Controls("Off_TextBox").Text) - (Data.gratingL / 2 - Data.gratingPoints.Rows(index)("X") * 1000), (Data.gratingPoints.Rows(index)("GUI X") + Data.grossAreaPoints.Rows(2)("GUI X") - sideSquareValues(2) / Data.scaleDiff) / 2 - 8, Data.grossAreaPoints.Rows(2)("GUI Y") + 15 + 3, 3}) '15 är linjen, 12 är textens höjd, 3 är lite extra Draw_Grating.measureLabels.Add("SS_" & mesNum + 1, {CInt(GUI.Controls("X_TextBox").Text), Data.grossAreaPoints.Rows(2)("GUI X") - sideSquareValues(2) / (Data.scaleDiff) - CInt(GUI.Controls("X_TextBox").Text) / (2 * Data.scaleDiff) - 8, Data.grossAreaPoints.Rows(2)("GUI Y") - sideSquareValues(1) / (Data.scaleDiff) - 12 - 3, 3}) Draw_Grating.measureLabels.Add("SS_" & mesNum + 2, {CInt(GUI.Controls("Y_TextBox").Text), Data.grossAreaPoints.Rows(2)("GUI X") - sideSquareValues(2) / Data.scaleDiff + 3, Data.grossAreaPoints.Rows(2)("GUI Y") - CInt(GUI.Controls("Y_TextBox").Text) / (2 * Data.scaleDiff) - 4, 3}) Else ' Add the new points pointRow1("X") = Data.grossAreaPoints.Rows(3)("X") pointRow1("Y") = Data.grossAreaPoints.Rows(3)("Y") + sideSquareValues(2) / 1000 pointRow1("GUI X") = Data.grossAreaPoints.Rows(3)("GUI X") pointRow1("GUI Y") = Data.grossAreaPoints.Rows(3)("GUI Y") - sideSquareValues(2) / Data.scaleDiff pointRow2("X") = Data.grossAreaPoints.Rows(3)("X") + sideSquareValues(0) / 1000 pointRow2("Y") = Data.grossAreaPoints.Rows(3)("Y") + sideSquareValues(2) / 1000 pointRow2("GUI X") = Data.grossAreaPoints.Rows(3)("GUI X") + sideSquareValues(0) / Data.scaleDiff pointRow2("GUI Y") = Data.grossAreaPoints.Rows(3)("GUI Y") - sideSquareValues(2) / Data.scaleDiff pointRow3("X") = Data.grossAreaPoints.Rows(3)("X") + sideSquareValues(0) / 1000 pointRow3("Y") = Data.grossAreaPoints.Rows(3)("Y") + (sideSquareValues(2) + sideSquareValues(1)) / 1000 pointRow3("GUI X") = Data.grossAreaPoints.Rows(3)("GUI X") + sideSquareValues(0) / Data.scaleDiff pointRow3("GUI Y") = Data.grossAreaPoints.Rows(3)("GUI Y") - (sideSquareValues(2) + sideSquareValues(1)) / Data.scaleDiff pointRow4("X") = Data.grossAreaPoints.Rows(3)("X") pointRow4("Y") = Data.grossAreaPoints.Rows(3)("Y") + (sideSquareValues(2) + sideSquareValues(1)) / 1000 pointRow4("GUI X") = Data.grossAreaPoints.Rows(3)("GUI X") pointRow4("GUI Y") = Data.grossAreaPoints.Rows(3)("GUI Y") - (sideSquareValues(2) + sideSquareValues(1)) / Data.scaleDiff ' Add recess measuements (SW) Data.pointsMeasurements.Add("SS1_" & mesNum, {sidePoints(0) + 1, index + 2, 4}) Data.pointsMeasurements.Add("SS_" & mesNum + 1, {index + 2, index + 5, 4}) Data.pointsMeasurements.Add("SS_" & mesNum + 2, {index + 2, index + 3, 3}) ' Add support line data for sidesquare measurement Draw_Grating.sideSquareMesLine.Add("SS1_" & mesNum, {Data.grossAreaPoints.Rows(3)("GUI X") - 15, Data.gratingPoints.Rows(index)("GUI Y"), Data.grossAreaPoints.Rows(3)("GUI X") - 15, Data.grossAreaPoints.Rows(3)("GUI Y") - sideSquareValues(2) / Data.scaleDiff}) ' Add recess measurments (GUI) Draw_Grating.measureLabels.Add("SS1_" & mesNum, {CInt(GUI.Controls("Off_TextBox").Text) - (Data.gratingW / 2 + Data.gratingPoints.Rows(index)("Y") * 1000), Data.grossAreaPoints.Rows(3)("GUI X") - 15 - 18 - 3, (Data.gratingPoints.Rows(index)("GUI Y") + Data.grossAreaPoints.Rows(3)("GUI Y") - sideSquareValues(2) / Data.scaleDiff) / 2 - 4, 4}) Draw_Grating.measureLabels.Add("SS_" & mesNum + 1, {CInt(GUI.Controls("Y_TextBox").Text), Data.grossAreaPoints.Rows(3)("GUI X") + sideSquareValues(0) / Data.scaleDiff + 3, Data.grossAreaPoints.Rows(3)("GUI Y") - (sideSquareValues(2) + sideSquareValues(1) / 2) / Data.scaleDiff - 4, 4}) Draw_Grating.measureLabels.Add("SS_" & mesNum + 2, {CInt(GUI.Controls("X_TextBox").Text), Data.grossAreaPoints.Rows(3)("GUI X") + sideSquareValues(0) / (2 * Data.scaleDiff) - 8, Data.grossAreaPoints.Rows(3)("GUI Y") - sideSquareValues(2) / Data.scaleDiff + 3, 4}) End If Data.gratingPoints.Rows.InsertAt(pointRow1, index + 1) Data.gratingPoints.Rows.InsertAt(pointRow2, index + 2) Data.gratingPoints.Rows.InsertAt(pointRow3, index + 3) Data.gratingPoints.Rows.InsertAt(pointRow4, index + 4) numOfSideRectangles += 1 'Redraw grating GUI.DrawingPanel.Refresh() RemoveHandler GUI.Controls("X_TextBox").TextChanged, AddressOf FunctionTextSide_Changed RemoveHandler GUI.Controls("X_TextBox").KeyPress, AddressOf FunctionText_KeyPress GUI.Controls.RemoveByKey("X_TextBox") RemoveHandler GUI.Controls("Y_TextBox").TextChanged, AddressOf FunctionTextSide_Changed RemoveHandler GUI.Controls("Y_TextBox").KeyPress, AddressOf FunctionText_KeyPress GUI.Controls.RemoveByKey("Y_TextBox") RemoveHandler GUI.Controls("Off_TextBox").TextChanged, AddressOf FunctionTextSide_Changed RemoveHandler GUI.Controls("Off_TextBox").KeyPress, AddressOf FunctionText_KeyPress GUI.Controls.RemoveByKey("Off_TextBox") GUI.Controls.RemoveByKey("X_Label") GUI.Controls.RemoveByKey("Y_Label") GUI.Controls.RemoveByKey("Off_Label") GUI.Controls("AngleButton").Enabled = True GUI.Controls("Button_Square").Enabled = True GUI.Controls("Button_SquareSide").Enabled = True End Sub End Class