
Imports System.Drawing

Public Class frmPose

    Sub subLoad() Handles Me.VisibleChanged, Me.Load
        Try
            updnLocationX.Value = tbpBotPose.Location.X
            updnLocationY.Value = tbpBotPose.Location.Y
            updnUncertaintyX.Value = tbpBotPose.LocationUncertainty.X
            updnUncertaintyY.Value = tbpBotPose.LocationUncertainty.Y
            updnOrientation.Value = tbpBotPose.Orientation
            updnOrientationUncertainty.Value = tbpBotPose.OrientationUncertainty
        Catch ex As Exception
            frmDebug.subWriteLogs(" EXCEPTION in subLoad :  " & ex.ToString)
        End Try
    End Sub

    Private Sub updnPositionX_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updnLocationX.ValueChanged
        Try
            If Not Me.InvokeRequired Then
                If updnLocationX.Focused Then
                    updnLocationX.Enabled = False
                    subChangeParticlePose(updnLocationX.Value - tbpBotPose.Location.X, 0, 0)
                    tbpBotPose.Location.X = updnLocationX.Value
                    updnLocationX.Enabled = True
                End If
            End If
        Catch ex As Exception
            frmDebug.subWriteLogs(" EXCEPTION in updnPositionX_ValueChanged :  " & ex.ToString)
        End Try
    End Sub


    Private Sub updnPositionY_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updnLocationY.ValueChanged
        Try
            If Not Me.InvokeRequired Then
                If updnLocationY.Focused Then
                    updnLocationY.Enabled = False
                    subChangeParticlePose(0, updnLocationY.Value - tbpBotPose.Location.Y, 0)
                    tbpBotPose.Location.Y = updnLocationY.Value
                    updnLocationY.Enabled = True
                End If
            End If
        Catch ex As Exception
            frmDebug.subWriteLogs(" EXCEPTION in updnPositionY_ValueChanged :  " & ex.ToString)
        End Try
    End Sub

    Private Sub updnOrientation_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updnOrientation.ValueChanged
        Try
            If Not Me.InvokeRequired Then
                If updnOrientation.Focused Then
                    updnOrientation.Enabled = False
                    updnOrientation.Value = ftnConvertTo360(Convert.ToInt16(updnOrientation.Value))
                    subChangeParticlePose(0, 0, ftnAngleDifference(Convert.ToInt16(updnOrientation.Value), tbpBotPose.Orientation))
                    tbpBotPose.Orientation = updnOrientation.Value
                    frmDebug.subWriteLogs(" ************  New Bot Orientation selected:  = " & updnOrientation.Value & " Degrees")
                    tmiMoveInfo.tbpStartingPose.Orientation = updnOrientation.Value
                    updnOrientation.Enabled = True
                End If
            End If
        Catch ex As Exception
            updnOrientation.Enabled = True
            frmDebug.subWriteLogs(" EXCEPTION in updnOrientation_ValueChanged :  " & ex.ToString)
        End Try
    End Sub

    Private Sub updnUncertaintyX_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updnUncertaintyX.ValueChanged
        Try
            If Not Me.InvokeRequired Then
                If updnUncertaintyX.Focused Then
                    updnUncertaintyX.Enabled = False
                    tbpBotPose.LocationUncertainty.X = updnUncertaintyX.Value
                    updnUncertaintyX.Enabled = True
                End If
            End If
        Catch ex As Exception
            frmDebug.subWriteLogs(" EXCEPTION in updnUncertaintyX_ValueChanged :  " & ex.ToString)
        End Try
    End Sub

    Private Sub updnUncertaintyY_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updnUncertaintyY.ValueChanged
        Try
            If Not Me.InvokeRequired Then
                If updnUncertaintyY.Focused Then
                    updnUncertaintyY.Enabled = False
                    tbpBotPose.LocationUncertainty.Y = updnUncertaintyY.Value
                    updnUncertaintyY.Enabled = True
                End If
            End If
        Catch ex As Exception
            frmDebug.subWriteLogs(" EXCEPTION in updnUncertaintyY_ValueChanged :  " & ex.ToString)
        End Try
    End Sub

    Private Sub updnOrientationUncertainty_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updnOrientationUncertainty.ValueChanged
        Try
            If Not Me.InvokeRequired Then
                If updnOrientationUncertainty.Focused Then
                    updnOrientationUncertainty.Enabled = False
                    tbpBotPose.OrientationUncertainty = updnOrientationUncertainty.Value
                    updnOrientationUncertainty.Enabled = True
                End If
            End If
        Catch ex As Exception
            frmDebug.subWriteLogs(" EXCEPTION in updnOrientationUncertainty_ValueChanged :  " & ex.ToString)
        End Try
    End Sub

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Me.Visible = False
        Me.Close()
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles timerPoseUpdate.Tick
        Try
            If Me.Visible Then
                If Not Me.updnLocationX.Focused Then Me.updnLocationX.Value = tbpBotPose.Location.X
                If Not Me.updnLocationY.Focused Then Me.updnLocationY.Value = tbpBotPose.Location.Y
                If Not Me.updnOrientation.Focused Then Me.updnOrientation.Value = tbpBotPose.Orientation
                If Not Me.updnUncertaintyX.Focused Then Me.updnUncertaintyX.Value = tbpBotPose.LocationUncertainty.X
                If Not Me.updnUncertaintyY.Focused Then Me.updnUncertaintyY.Value = tbpBotPose.LocationUncertainty.Y
                If Not Me.updnOrientationUncertainty.Focused Then Me.updnOrientationUncertainty.Value = tbpBotPose.OrientationUncertainty
            End If
        Catch ex As Exception
            frmDebug.subWriteLogs(" EXCEPTION in Timer1_Tick :  " & ex.ToString)
        End Try
    End Sub

End Class