Public Class Corner_Rectangle ' --- Create textboxes when user clicks the rectangle corner recess button --- Public Shared Sub SquareButtton(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_Square").Location.X Dim buttonY As Integer = GUI.Controls("Button_Square").Location.Y GUI.Create_TextBox("X_TextBox", "", buttonX + 20, buttonY + 40, 60) AddHandler GUI.Controls("X_TextBox").TextChanged, AddressOf FunctionTextCorner_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 FunctionTextCorner_Changed AddHandler GUI.Controls("Y_TextBox").KeyPress, AddressOf FunctionText_KeyPress GUI.Create_LabelGUI("Y_Label", "W", buttonX + 110, 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 corners if conditions are met --- Private Shared Sub FunctionTextCorner_Changed(sender As TextBox, e As EventArgs) Dim value1, value2 As Integer Try value1 = CInt(GUI.Controls("X_TextBox").Text) value2 = CInt(GUI.Controls("Y_TextBox").Text) Catch ex As Exception value1 = 0 value2 = 0 End Try If value1 > 0 AndAlso value2 > 0 Then If GUI.DrawingPanel.Controls.Count = 2 Then For i = 0 To Data.gratingPoints.Rows.Count - 1 If Data.gratingPoints.Rows(i)("RECESS OK") Then Dim pointButton As New Button With { .Width = 30, .Height = 30, .Left = Data.gratingPoints.Rows(i)("GUI X") - 30 / 2, .Top = Data.gratingPoints.Rows(i)("GUI Y") - 30 / 2, .Name = Data.gratingPoints.Rows(i)("NAME") & "_Button", .Text = "" } pointButton.BackColor = Color.FromArgb(50, Color.Red) pointButton.FlatStyle = FlatStyle.Flat pointButton.FlatAppearance.BorderSize = 0 pointButton.FlatAppearance.MouseOverBackColor = Color.Red pointButton.FlatAppearance.MouseDownBackColor = Color.DarkRed Dim gp As New Drawing2D.GraphicsPath gp.AddEllipse(New Rectangle(New Point(0, 0), New Size(30, 30))) pointButton.Region = New Region(gp) GUI.DrawingPanel.Controls.Add(pointButton) AddHandler pointButton.Click, AddressOf PointButton_Click End If Next End If ElseIf GUI.DrawingPanel.Controls.Count > 2 Then For i = 0 To Data.gratingPoints.Rows.Count - 1 If Data.gratingPoints.Rows(i)("RECESS OK") Then Dim buttonName As String = Data.gratingPoints.Rows(i)("NAME") & "_Button" RemoveHandler GUI.DrawingPanel.Controls(buttonName).Click, AddressOf PointButton_Click GUI.DrawingPanel.Controls.RemoveByKey(Data.gratingPoints.Rows(i)("NAME") & "_Button") End If Next End If End Sub ' --- When a corner function button is pressed --- Private Shared Sub PointButton_Click(sender As Button, e As EventArgs) 'Determine which point is being pressed Dim pointPressed As String = sender.Name.Split("_")(0) Dim index As Integer For Each DR As DataRow In Data.gratingPoints.Rows If DR("NAME") = pointPressed Then index = Data.gratingPoints.Rows.IndexOf(DR) Exit For End If Next ' Remove point buttons For i = 0 To Data.gratingPoints.Rows.Count - 1 If Data.gratingPoints.Rows(i)("RECESS OK") Then Dim buttonName As String = Data.gratingPoints.Rows(i)("NAME") & "_Button" RemoveHandler GUI.DrawingPanel.Controls(buttonName).Click, AddressOf PointButton_Click GUI.DrawingPanel.Controls.RemoveByKey(Data.gratingPoints.Rows(i)("NAME") & "_Button") End If Next 'Retrive the points coords Dim pXGUI As Integer = Data.gratingPoints.Rows(index)("GUI X") Dim pYGUI As Integer = Data.gratingPoints.Rows(index)("GUI Y") Dim pX As Decimal = Data.gratingPoints.Rows(index)("X") Dim pY As Decimal = Data.gratingPoints.Rows(index)("Y") Dim dXGUI As Integer = CInt(GUI.Controls("X_TextBox").Text / Data.scaleDiff) Dim dYGUI As Integer = CInt(GUI.Controls("Y_TextBox").Text / Data.scaleDiff) Dim dX As Decimal = GUI.Controls("X_TextBox").Text / 1000 Dim dY As Decimal = GUI.Controls("Y_TextBox").Text / 1000 Data.recessData.Rows.Add() For i = 2 To Data.pointsMeasurements.Count - 1 Dim mesName As String = Data.pointsMeasurements.Keys(i) If mesName.Split("_")(0) <> "SS1" AndAlso mesName.Split("_")(0) <> "SS" Then If index + 1 = Data.pointsMeasurements(mesName)(0) Then If Draw_Grating.measureLabels(mesName)(3) = 1 Then Draw_Grating.measureLabels(mesName)(0) = Draw_Grating.measureLabels(mesName)(0) - GUI.Controls("X_TextBox").Text Draw_Grating.measureLabels(mesName)(1) = Draw_Grating.measureLabels(mesName)(1) + dXGUI / 2 ElseIf Draw_Grating.measureLabels(mesName)(3) = 2 Then Draw_Grating.measureLabels(mesName)(0) = Draw_Grating.measureLabels(mesName)(0) - GUI.Controls("Y_TextBox").Text Draw_Grating.measureLabels(mesName)(2) = Draw_Grating.measureLabels(mesName)(2) + dYGUI / 2 ElseIf Draw_Grating.measureLabels(mesName)(3) = 3 Then Draw_Grating.measureLabels(mesName)(0) = Draw_Grating.measureLabels(mesName)(0) - GUI.Controls("X_TextBox").Text Draw_Grating.measureLabels(mesName)(1) = Draw_Grating.measureLabels(mesName)(1) - dXGUI / 2 Else Draw_Grating.measureLabels(mesName)(0) = Draw_Grating.measureLabels(mesName)(0) - GUI.Controls("Y_TextBox").Text Draw_Grating.measureLabels(mesName)(2) = Draw_Grating.measureLabels(mesName)(2) - dYGUI / 2 End If ElseIf index + 1 = Data.pointsMeasurements(mesName)(1) Then If Draw_Grating.measureLabels(mesName)(3) = 1 Then Draw_Grating.measureLabels(mesName)(0) = Draw_Grating.measureLabels(mesName)(0) - GUI.Controls("Y_TextBox").Text Draw_Grating.measureLabels(mesName)(2) = Draw_Grating.measureLabels(mesName)(2) + dYGUI / 2 ElseIf Draw_Grating.measureLabels(mesName)(3) = 2 Then Draw_Grating.measureLabels(mesName)(0) = Draw_Grating.measureLabels(mesName)(0) - GUI.Controls("X_TextBox").Text Draw_Grating.measureLabels(mesName)(1) = Draw_Grating.measureLabels(mesName)(1) - dXGUI / 2 ElseIf Draw_Grating.measureLabels(mesName)(3) = 3 Then Draw_Grating.measureLabels(mesName)(0) = Draw_Grating.measureLabels(mesName)(0) - GUI.Controls("Y_TextBox").Text Draw_Grating.measureLabels(mesName)(2) = Draw_Grating.measureLabels(mesName)(2) - dYGUI / 2 Else Draw_Grating.measureLabels(mesName)(0) = Draw_Grating.measureLabels(mesName)(0) - GUI.Controls("X_TextBox").Text Draw_Grating.measureLabels(mesName)(1) = Draw_Grating.measureLabels(mesName)(1) + dXGUI / 2 End If End If ElseIf mesName.Split("_")(0) = "SS1" AndAlso index + 2 = Data.pointsMeasurements(mesName)(1) Then If Draw_Grating.measureLabels(mesName)(3) = 1 Then Draw_Grating.measureLabels(mesName)(0) = Draw_Grating.measureLabels(mesName)(0) - GUI.Controls("X_TextBox").Text Draw_Grating.measureLabels(mesName)(1) = Draw_Grating.measureLabels(mesName)(1) + dXGUI / 2 Draw_Grating.sideSquareMesLine(mesName)(0) = Draw_Grating.sideSquareMesLine(mesName)(0) + dXGUI End If End If Next Dim mesNum As Integer = Data.pointsMeasurements.Count - 1 For i = 2 To Data.pointsMeasurements.Count - 1 Dim mesName As String = Data.pointsMeasurements.Keys(i) If index + 1 < Data.pointsMeasurements(mesName)(0) Then Data.pointsMeasurements(mesName)(0) = Data.pointsMeasurements(mesName)(0) + 1 Data.pointsMeasurements(mesName)(1) = Data.pointsMeasurements(mesName)(1) + 1 ElseIf index + 1 = Data.pointsMeasurements(mesName)(0) OrElse index + 1 = Data.pointsMeasurements(mesName)(1) Then Data.pointsMeasurements(mesName)(1) = Data.pointsMeasurements(mesName)(1) + 1 End If Next Dim pointQuadrant As Integer = Get_PointQuadrant(pXGUI, pYGUI) Dim pointRow1 As DataRow = Data.gratingPoints.NewRow Dim pointRow2 As DataRow = Data.gratingPoints.NewRow Dim pointRow3 As DataRow = Data.gratingPoints.NewRow pointRow1("NAME") = "CR" & pointQuadrant & "_" & 1 pointRow1("QUADRANT") = pointQuadrant pointRow1("RECESS OK") = True pointRow2("NAME") = "CR" & pointQuadrant & "_" & 2 pointRow2("QUADRANT") = pointQuadrant pointRow2("RECESS OK") = False pointRow3("NAME") = "CR" & pointQuadrant & "_" & 3 pointRow3("QUADRANT") = pointQuadrant pointRow3("RECESS OK") = True If pointQuadrant = 1 Then ' Add the new points pointRow1("X") = pX pointRow1("Y") = pY - dY pointRow1("GUI X") = pXGUI pointRow1("GUI Y") = pYGUI + dYGUI pointRow2("X") = pX + dX pointRow2("Y") = pY - dY pointRow2("GUI X") = pXGUI + dXGUI pointRow2("GUI Y") = pYGUI + dYGUI pointRow3("X") = pX + dX pointRow3("Y") = pY pointRow3("GUI X") = pXGUI + dXGUI pointRow3("GUI Y") = pYGUI ' Update outer measuements (SW) Data.pointsMeasurements("Lmes")(1) = Data.pointsMeasurements("Lmes")(1) + 2 Data.pointsMeasurements("Wmes")(0) = Data.pointsMeasurements("Wmes")(0) + 2 Data.pointsMeasurements("Wmes")(1) = Data.pointsMeasurements("Wmes")(1) + 2 ' Add recess measuements (SW) Data.pointsMeasurements.Add("S_" & mesNum, {index + 1, index + 2, 1}) Data.pointsMeasurements.Add("S_" & mesNum + 1, {index + 2, index + 3, 4}) ' Add recess measurments (GUI) Draw_Grating.measureLabels.Add("S_" & mesNum, {CInt(GUI.Controls("X_TextBox").Text), pXGUI + dXGUI / 2 - 8, pYGUI + dYGUI + 3, 1}) Draw_Grating.measureLabels.Add("S_" & mesNum + 1, {CInt(GUI.Controls("Y_TextBox").Text), pXGUI + dXGUI + 3, pYGUI + dYGUI / 2 - 4, 1}) ' Recess Data Data.recessData.Rows(Data.recessData.Rows.Count - 1)("RECESS TYPE") = "SQUARE" Data.recessData.Rows(Data.recessData.Rows.Count - 1)("CORNER") = 1 Data.recessData.Rows(Data.recessData.Rows.Count - 1)("WIDTH") = CInt(GUI.Controls("Y_TextBox").Text) Data.recessData.Rows(Data.recessData.Rows.Count - 1)("LENGTH") = CInt(GUI.Controls("X_TextBox").Text) ElseIf pointQuadrant = 2 Then ' Add the new points pointRow1("X") = pX - dX pointRow1("Y") = pY pointRow1("GUI X") = pXGUI - dXGUI pointRow1("GUI Y") = pYGUI pointRow2("X") = pX - dX pointRow2("Y") = pY - dY pointRow2("GUI X") = pXGUI - dXGUI pointRow2("GUI Y") = pYGUI + dYGUI pointRow3("X") = pX pointRow3("Y") = pY - dY pointRow3("GUI X") = pXGUI pointRow3("GUI Y") = pYGUI + dYGUI ' Update outer measuements (SW) Data.pointsMeasurements("Lmes")(1) = Data.pointsMeasurements("Lmes")(1) + 2 Data.pointsMeasurements("Wmes")(1) = Data.pointsMeasurements("Wmes")(1) + 2 ' Add recess measuements (SW) Data.pointsMeasurements.Add("S_" & mesNum, {index + 1, index + 2, 2}) Data.pointsMeasurements.Add("S_" & mesNum + 1, {index + 2, index + 3, 1}) ' Add recess measurments (GUI) Draw_Grating.measureLabels.Add("S_" & mesNum, {CInt(GUI.Controls("Y_TextBox").Text), pXGUI - dXGUI - 18 - 3, pYGUI + dYGUI / 2 - 4, 2}) Draw_Grating.measureLabels.Add("S_" & mesNum + 1, {CInt(GUI.Controls("X_TextBox").Text), pXGUI - dXGUI / 2 - 8, pYGUI + dYGUI + 3, 2}) ' Recess Data Data.recessData.Rows(Data.recessData.Rows.Count - 1)("RECESS TYPE") = "SQUARE" Data.recessData.Rows(Data.recessData.Rows.Count - 1)("CORNER") = 2 Data.recessData.Rows(Data.recessData.Rows.Count - 1)("WIDTH") = CInt(GUI.Controls("Y_TextBox").Text) Data.recessData.Rows(Data.recessData.Rows.Count - 1)("LENGTH") = CInt(GUI.Controls("X_TextBox").Text) ElseIf pointQuadrant = 3 Then ' Add the new points pointRow1("X") = pX pointRow1("Y") = pY + dY pointRow1("GUI X") = pXGUI pointRow1("GUI Y") = pYGUI - dYGUI pointRow2("X") = pX - dX pointRow2("Y") = pY + dY pointRow2("GUI X") = pXGUI - dXGUI pointRow2("GUI Y") = pYGUI - dYGUI pointRow3("X") = pX - dX pointRow3("Y") = pY pointRow3("GUI X") = pXGUI - dXGUI pointRow3("GUI Y") = pYGUI ' Update outer measuements (SW) Data.pointsMeasurements("Wmes")(1) = Data.pointsMeasurements("Wmes")(1) + 2 ' Add recess measuements (SW) Data.pointsMeasurements.Add("S_" & mesNum, {index + 1, index + 2, 3}) Data.pointsMeasurements.Add("S_" & mesNum + 1, {index + 2, index + 3, 2}) ' Add recess measurments (GUI) Draw_Grating.measureLabels.Add("S_" & mesNum, {CInt(GUI.Controls("X_TextBox").Text), pXGUI - dXGUI / 2 - 8, pYGUI - dYGUI - 12 - 3, 3}) Draw_Grating.measureLabels.Add("S_" & mesNum + 1, {CInt(GUI.Controls("Y_TextBox").Text), pXGUI - dXGUI - 18 - 3, pYGUI - dYGUI / 2 - 4, 3}) ' Recess Data Data.recessData.Rows(Data.recessData.Rows.Count - 1)("RECESS TYPE") = "SQUARE" Data.recessData.Rows(Data.recessData.Rows.Count - 1)("CORNER") = 3 Data.recessData.Rows(Data.recessData.Rows.Count - 1)("WIDTH") = CInt(GUI.Controls("Y_TextBox").Text) Data.recessData.Rows(Data.recessData.Rows.Count - 1)("LENGTH") = CInt(GUI.Controls("X_TextBox").Text) Else ' Add the new points pointRow1("X") = pX + dX pointRow1("Y") = pY pointRow1("GUI X") = pXGUI + dXGUI pointRow1("GUI Y") = pYGUI pointRow2("X") = pX + dX pointRow2("Y") = pY + dY pointRow2("GUI X") = pXGUI + dXGUI pointRow2("GUI Y") = pYGUI - dYGUI pointRow3("X") = pX pointRow3("Y") = pY + dY pointRow3("GUI X") = pXGUI pointRow3("GUI Y") = pYGUI - dYGUI ' Add recess measuements (SW) Data.pointsMeasurements.Add("S_" & mesNum, {index + 1, index + 2, 4}) Data.pointsMeasurements.Add("S_" & mesNum + 1, {index + 2, index + 3, 3}) ' Add recess measurments (GUI) Draw_Grating.measureLabels.Add("S_" & mesNum, {CInt(GUI.Controls("Y_TextBox").Text), pXGUI + dXGUI + 3, pYGUI - dYGUI / 2 - 4, 4}) Draw_Grating.measureLabels.Add("S_" & mesNum + 1, {CInt(GUI.Controls("X_TextBox").Text), pXGUI + dXGUI / 2 - 8, pYGUI - dYGUI - 12 - 3, 4}) ' Recess Data Data.recessData.Rows(Data.recessData.Rows.Count - 1)("RECESS TYPE") = "SQUARE" Data.recessData.Rows(Data.recessData.Rows.Count - 1)("CORNER") = 4 Data.recessData.Rows(Data.recessData.Rows.Count - 1)("WIDTH") = CInt(GUI.Controls("Y_TextBox").Text) Data.recessData.Rows(Data.recessData.Rows.Count - 1)("LENGTH") = CInt(GUI.Controls("X_TextBox").Text) 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.RemoveAt(index) 'Redraw grating GUI.DrawingPanel.Refresh() RemoveHandler GUI.Controls("X_TextBox").TextChanged, AddressOf FunctionTextCorner_Changed RemoveHandler GUI.Controls("X_TextBox").KeyPress, AddressOf FunctionText_KeyPress GUI.Controls.RemoveByKey("X_TextBox") RemoveHandler GUI.Controls("Y_TextBox").TextChanged, AddressOf FunctionTextCorner_Changed RemoveHandler GUI.Controls("Y_TextBox").KeyPress, AddressOf FunctionText_KeyPress GUI.Controls.RemoveByKey("Y_TextBox") GUI.Controls.RemoveByKey("X_Label") GUI.Controls.RemoveByKey("Y_Label") GUI.Controls("AngleButton").Enabled = True GUI.Controls("Button_Square").Enabled = True GUI.Controls("Button_SquareSide").Enabled = True End Sub ' --- Determines the clicked points quadrant --- Private Shared Function Get_PointQuadrant(pXGUI As Integer, pYGUI As Integer) Dim quadrant As Integer If pXGUI < Data.guiPanelMidX Then If pYGUI > Data.guiPanelMidY Then quadrant = 4 Else quadrant = 1 End If Else If pYGUI > Data.guiPanelMidY Then quadrant = 3 Else quadrant = 2 End If End If Return quadrant End Function End Class