X2021/Wardrobe/Recess Functions/Corner_Angle.vb

400 lines
22 KiB
VB.net

Public Class Corner_Angle
Private Shared buttonOffset As Integer
' --- Create textboxes when user clicks the angle corner recess button ---
Public Shared Sub AngleButton(sender As Object, e As EventArgs)
Individual.Panel_Recesses.Controls("Button_Angle_Corner").Enabled = False
Individual.Panel_Recesses.Controls("Button_Angle_Side").Enabled = False
Individual.Panel_Recesses.Controls("Button_Square_Corner").Enabled = False
Individual.Panel_Recesses.Controls("Button_Square_Side").Enabled = False
Individual.Panel_Recesses.Controls("Button_Square_Middle").Enabled = False
Dim buttonX As Integer = Individual.Panel_Recesses.Controls("Button_Angle_Corner").Location.X + Individual.Panel_Recesses.Controls("Button_Angle_Corner").Width
Dim buttonY As Integer = Individual.Panel_Recesses.Controls("Button_Angle_Corner").Location.Y
Individual.Create_TextBox_Recesses("Y_TextBox", "", buttonX + 60, buttonY + 10, 60)
AddHandler Individual.Panel_Recesses.Controls("Y_TextBox").TextChanged, AddressOf FunctionTextCorner_Changed
AddHandler Individual.Panel_Recesses.Controls("Y_TextBox").KeyPress, AddressOf FunctionText_KeyPress
Individual.Create_Label_Recesses("Y_Label", "Width", buttonX + 18, buttonY + 13)
Individual.Create_TextBox_Recesses("X_TextBox", "", buttonX + 60, buttonY + 40, 60)
AddHandler Individual.Panel_Recesses.Controls("X_TextBox").TextChanged, AddressOf FunctionTextCorner_Changed
AddHandler Individual.Panel_Recesses.Controls("X_TextBox").KeyPress, AddressOf FunctionText_KeyPress
Individual.Create_Label_Recesses("X_Label", "Length", buttonX + 10, buttonY + 43)
buttonOffset = 130
Individual.Panel_Recesses.Controls("Button_Angle_Side").Left = Individual.Panel_Recesses.Controls("Button_Angle_Side").Left + buttonOffset
Individual.Panel_Recesses.Controls("Button_Square_Corner").Left = Individual.Panel_Recesses.Controls("Button_Square_Corner").Left + buttonOffset
Individual.Panel_Recesses.Controls("Button_Square_Side").Left = Individual.Panel_Recesses.Controls("Button_Square_Side").Left + buttonOffset
Individual.Panel_Recesses.Controls("Button_Square_Middle").Left = Individual.Panel_Recesses.Controls("Button_Square_Middle").Left + buttonOffset
Individual.Button_Square_Side.FlatStyle = FlatStyle.Flat
Individual.Button_Square_Side.FlatAppearance.BorderColor = Color.Red
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(Individual.Panel_Recesses.Controls("X_TextBox").Text)
value2 = CInt(Individual.Panel_Recesses.Controls("Y_TextBox").Text)
Catch ex As Exception
value1 = 0
value2 = 0
End Try
If value1 > 0 AndAlso value2 > 0 Then
If Individual.Panel_Grating.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)
Individual.Panel_Grating.Controls.Add(pointButton)
AddHandler pointButton.Click, AddressOf PointButton_Click
End If
Next
End If
ElseIf Individual.Panel_Grating.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 Individual.Panel_Grating.Controls(buttonName).Click, AddressOf PointButton_Click
Individual.Panel_Grating.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 Individual.Panel_Grating.Controls(buttonName).Click, AddressOf PointButton_Click
Individual.Panel_Grating.Controls.RemoveByKey(Data.gratingPoints.Rows(i)("NAME") & "_Button")
End If
Next
'Retrive that 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(Individual.Panel_Recesses.Controls("X_TextBox").Text / Data.scaleDiff)
Dim dYGUI As Integer = CInt(Individual.Panel_Recesses.Controls("Y_TextBox").Text / Data.scaleDiff)
Dim dX As Decimal = Individual.Panel_Recesses.Controls("X_TextBox").Text / 1000
Dim dY As Decimal = Individual.Panel_Recesses.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) - Individual.Panel_Recesses.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) - Individual.Panel_Recesses.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) - Individual.Panel_Recesses.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) - Individual.Panel_Recesses.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) - Individual.Panel_Recesses.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) - Individual.Panel_Recesses.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) - Individual.Panel_Recesses.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) - Individual.Panel_Recesses.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) - Individual.Panel_Recesses.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
pointRow1("NAME") = "CA" & pointQuadrant & "_" & 1
pointRow1("QUADRANT") = pointQuadrant
pointRow1("RECESS OK") = False
pointRow2("NAME") = "CA" & pointQuadrant & "_" & 2
pointRow2("QUADRANT") = pointQuadrant
pointRow2("RECESS OK") = False
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
pointRow2("GUI X") = pXGUI + dXGUI
pointRow2("GUI Y") = pYGUI
' Update outer measuements (SW)
Data.pointsMeasurements("Lmes")(1) = Data.pointsMeasurements("Lmes")(1) + 1
Data.pointsMeasurements("Wmes")(0) = Data.pointsMeasurements("Wmes")(0) + 1
Data.pointsMeasurements("Wmes")(1) = Data.pointsMeasurements("Wmes")(1) + 1
' Add recess measuements (SW)
Data.pointsMeasurements.Add("A_" & mesNum, {index + 1, index + 2, 1})
Data.pointsMeasurements.Add("A_" & mesNum + 1, {index + 1, index + 2, 4})
' Add angle recess help point (GUI)
Dim pointRow = Data.angleRecessPoints.NewRow
pointRow("NAME") = "CA" & pointQuadrant
pointRow("QUADRANT") = pointQuadrant
pointRow("GUI X") = pXGUI + dXGUI
pointRow("GUI Y") = pYGUI + dYGUI
Data.angleRecessPoints.Rows.Add(pointRow)
' Add recess measurments (GUI)
Draw_Grating.measureLabels.Add("A_" & mesNum, {CInt(Individual.Panel_Recesses.Controls("X_TextBox").Text), pXGUI + dXGUI / 2 - 8,
pYGUI + dYGUI + 3, 1})
Draw_Grating.measureLabels.Add("A_" & mesNum + 1, {CInt(Individual.Panel_Recesses.Controls("Y_TextBox").Text), pXGUI + dXGUI + 3,
pYGUI + dYGUI / 2 - 4, 1})
' Recess Data
Data.recessData.Rows(Data.recessData.Rows.Count - 1)("RECESS TYPE") = "ANGLE"
Data.recessData.Rows(Data.recessData.Rows.Count - 1)("CORNER") = 1
Data.recessData.Rows(Data.recessData.Rows.Count - 1)("WIDTH") = CInt(Individual.Panel_Recesses.Controls("Y_TextBox").Text)
Data.recessData.Rows(Data.recessData.Rows.Count - 1)("LENGTH") = CInt(Individual.Panel_Recesses.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
pointRow2("Y") = pY - dY
pointRow2("GUI X") = pXGUI
pointRow2("GUI Y") = pYGUI + dYGUI
' Update outer measuements (SW)
Data.pointsMeasurements("Lmes")(1) = Data.pointsMeasurements("Lmes")(1) + 1
Data.pointsMeasurements("Wmes")(1) = Data.pointsMeasurements("Wmes")(1) + 1
' Add recess measuements (SW)
Data.pointsMeasurements.Add("A_" & mesNum, {index + 1, index + 2, 1})
Data.pointsMeasurements.Add("A_" & mesNum + 1, {index + 1, index + 2, 2})
' Add angle recess help point (GUI)
Dim pointRow = Data.angleRecessPoints.NewRow
pointRow("NAME") = "CA" & pointQuadrant
pointRow("QUADRANT") = pointQuadrant
pointRow("GUI X") = pXGUI - dXGUI
pointRow("GUI Y") = pYGUI + dYGUI
Data.angleRecessPoints.Rows.Add(pointRow)
' Add recess measurments (GUI)
Draw_Grating.measureLabels.Add("A_" & mesNum, {CInt(Individual.Panel_Recesses.Controls("Y_TextBox").Text), pXGUI - dXGUI - 18 - 3,
pYGUI + dYGUI / 2 - 4, 2})
Draw_Grating.measureLabels.Add("A_" & mesNum + 1, {CInt(Individual.Panel_Recesses.Controls("X_TextBox").Text), pXGUI - dXGUI / 2 - 8,
pYGUI + dYGUI + 3, 2})
' Recess Data
Data.recessData.Rows(Data.recessData.Rows.Count - 1)("RECESS TYPE") = "ANGLE"
Data.recessData.Rows(Data.recessData.Rows.Count - 1)("CORNER") = 2
Data.recessData.Rows(Data.recessData.Rows.Count - 1)("WIDTH") = CInt(Individual.Panel_Recesses.Controls("Y_TextBox").Text)
Data.recessData.Rows(Data.recessData.Rows.Count - 1)("LENGTH") = CInt(Individual.Panel_Recesses.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
pointRow2("GUI X") = pXGUI - dXGUI
pointRow2("GUI Y") = pYGUI
' Update outer measuements (SW)
Data.pointsMeasurements("Wmes")(1) = Data.pointsMeasurements("Wmes")(1) + 1
' Add recess measuements (SW)
Data.pointsMeasurements.Add("A_" & mesNum, {index + 1, index + 2, 2})
Data.pointsMeasurements.Add("A_" & mesNum + 1, {index + 1, index + 2, 3})
' Add angle recess help point (GUI)
Dim pointRow = Data.angleRecessPoints.NewRow
pointRow("NAME") = "CA" & pointQuadrant
pointRow("QUADRANT") = pointQuadrant
pointRow("GUI X") = pXGUI - dXGUI
pointRow("GUI Y") = pYGUI - dYGUI
Data.angleRecessPoints.Rows.Add(pointRow)
' Add recess measurments (GUI)
Draw_Grating.measureLabels.Add("A_" & mesNum, {CInt(Individual.Panel_Recesses.Controls("X_TextBox").Text), pXGUI - dXGUI / 2 - 8,
pYGUI - dYGUI - 12 - 3, 3})
Draw_Grating.measureLabels.Add("A_" & mesNum + 1, {CInt(Individual.Panel_Recesses.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") = "ANGLE"
Data.recessData.Rows(Data.recessData.Rows.Count - 1)("CORNER") = 3
Data.recessData.Rows(Data.recessData.Rows.Count - 1)("WIDTH") = CInt(Individual.Panel_Recesses.Controls("Y_TextBox").Text)
Data.recessData.Rows(Data.recessData.Rows.Count - 1)("LENGTH") = CInt(Individual.Panel_Recesses.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
pointRow2("Y") = pY + dY
pointRow2("GUI X") = pXGUI
pointRow2("GUI Y") = pYGUI - dYGUI
' Add recess measuements (SW)
Data.pointsMeasurements.Add("A_" & mesNum, {index + 1, index + 2, 3})
Data.pointsMeasurements.Add("A_" & mesNum + 1, {index + 1, index + 2, 4})
' Add angle recess help point (GUI)
Dim pointRow = Data.angleRecessPoints.NewRow
pointRow("NAME") = "CA" & pointQuadrant
pointRow("QUADRANT") = pointQuadrant
pointRow("GUI X") = pXGUI + dXGUI
pointRow("GUI Y") = pYGUI - dYGUI
Data.angleRecessPoints.Rows.Add(pointRow)
' Add recess measurments (GUI)
Draw_Grating.measureLabels.Add("A_" & mesNum, {CInt(Individual.Panel_Recesses.Controls("Y_TextBox").Text), pXGUI + dXGUI + 3,
pYGUI - dYGUI / 2 - 4, 4})
Draw_Grating.measureLabels.Add("A_" & mesNum + 1, {CInt(Individual.Panel_Recesses.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") = "ANGLE"
Data.recessData.Rows(Data.recessData.Rows.Count - 1)("CORNER") = 4
Data.recessData.Rows(Data.recessData.Rows.Count - 1)("WIDTH") = CInt(Individual.Panel_Recesses.Controls("Y_TextBox").Text)
Data.recessData.Rows(Data.recessData.Rows.Count - 1)("LENGTH") = CInt(Individual.Panel_Recesses.Controls("X_TextBox").Text)
End If
Data.gratingPoints.Rows.InsertAt(pointRow1, index + 1)
Data.gratingPoints.Rows.InsertAt(pointRow2, index + 2)
Data.gratingPoints.Rows.RemoveAt(index)
'Redraw grating
Individual.Panel_Grating.Refresh()
RemoveHandler Individual.Panel_Recesses.Controls("X_TextBox").TextChanged, AddressOf FunctionTextCorner_Changed
RemoveHandler Individual.Panel_Recesses.Controls("X_TextBox").KeyPress, AddressOf FunctionText_KeyPress
Individual.Panel_Recesses.Controls.RemoveByKey("X_TextBox")
RemoveHandler Individual.Panel_Recesses.Controls("Y_TextBox").TextChanged, AddressOf FunctionTextCorner_Changed
RemoveHandler Individual.Panel_Recesses.Controls("Y_TextBox").KeyPress, AddressOf FunctionText_KeyPress
Individual.Panel_Recesses.Controls.RemoveByKey("Y_TextBox")
Individual.Panel_Recesses.Controls.RemoveByKey("X_Label")
Individual.Panel_Recesses.Controls.RemoveByKey("Y_Label")
Individual.Panel_Recesses.Controls("Button_Angle_Corner").Enabled = True
Individual.Panel_Recesses.Controls("Button_Angle_Side").Enabled = True
Individual.Panel_Recesses.Controls("Button_Square_Corner").Enabled = True
Individual.Panel_Recesses.Controls("Button_Square_Side").Enabled = True
Individual.Panel_Recesses.Controls("Button_Square_Middle").Enabled = True
Individual.Panel_Recesses.Controls("Button_Angle_Side").Left = Individual.Panel_Recesses.Controls("Button_Angle_Side").Left - buttonOffset
Individual.Panel_Recesses.Controls("Button_Square_Corner").Left = Individual.Panel_Recesses.Controls("Button_Square_Corner").Left - buttonOffset
Individual.Panel_Recesses.Controls("Button_Square_Side").Left = Individual.Panel_Recesses.Controls("Button_Square_Side").Left - buttonOffset
Individual.Panel_Recesses.Controls("Button_Square_Middle").Left = Individual.Panel_Recesses.Controls("Button_Square_Middle").Left - buttonOffset
Individual.Button_Square_Side.FlatStyle = FlatStyle.Standard
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