Imports EgtUILib

Public Class CustomGridUC

#Region "FIELDS & PROPERTIES"

   ' Riferimento a GridCut
   Private m_refGridCut As GridCut

#End Region    ' Fields & Properties

#Region "CONSTRUCTOR"

   Sub New(GC As GridCut)
      InitializeComponent()
      m_refGridCut = GC
      CustomGridLstBx.ItemsSource = m_refGridCut.m_ListOfCut_X
      Cut_XTgBtn.IsChecked = True
      NumPzXTxBl.Text = EgtMsg(90217)     ' Numero
      DimPzXTxBl.Text = EgtMsg(90218)     ' Dimensione
      UpdateBtn.Content = EgtMsg(90265)   ' Aggiorna
   End Sub

#End Region    ' Constructor

#Region "EVENTS"

   Private Sub CutX_Selected() Handles Cut_XTgBtn.Click
      If Cut_XTgBtn.IsChecked Then
         Cut_YTgBtn.IsChecked = False
         CustomGridLstBx.ItemsSource = m_refGridCut.m_ListOfCut_X
         CustomGridLstBx.UpdateLayout()
      End If
   End Sub

   Private Sub CutY_Selected() Handles Cut_YTgBtn.Click
      If Cut_YTgBtn.IsChecked Then
         Cut_XTgBtn.IsChecked = False
         CustomGridLstBx.ItemsSource = m_refGridCut.m_ListOfCut_Y
         CustomGridLstBx.UpdateLayout()
      End If
   End Sub

   Private Sub AddCut_Click(sender As Object, e As EventArgs) Handles AddCutBtn.Click
      If Cut_XTgBtn.IsChecked Then
         m_refGridCut.m_ListOfCut_X.Add(New Cut_Axis(0, 0))
      ElseIf Cut_YTgBtn.IsChecked Then
         m_refGridCut.m_ListOfCut_Y.Add(New Cut_Axis(0, 0))
      End If
      CustomGridLstBx.UpdateLayout()
   End Sub

   Private Sub RemoveCut_Click(sender As Object, e As EventArgs) Handles RemoveCutBtn.Click
      Dim CurrIndexListSelected As Integer = -1
      CurrIndexListSelected = CustomGridLstBx.SelectedIndex
      If Cut_XTgBtn.IsChecked Then
         If CurrIndexListSelected < 0 Or CurrIndexListSelected > m_refGridCut.m_ListOfCut_X.Count - 1 Then
            CurrIndexListSelected = m_refGridCut.m_ListOfCut_X.Count - 1
         End If
         m_refGridCut.m_ListOfCut_X.RemoveAt(CurrIndexListSelected)
      ElseIf Cut_YTgBtn.IsChecked Then
         If CurrIndexListSelected < 0 Or CurrIndexListSelected > m_refGridCut.m_ListOfCut_Y.Count - 1 Then
            CurrIndexListSelected = m_refGridCut.m_ListOfCut_Y.Count - 1
         End If
         m_refGridCut.m_ListOfCut_Y.RemoveAt(CurrIndexListSelected)
      End If
      CustomGridLstBx.UpdateLayout()
   End Sub

   Public Sub Update_Click() Handles UpdateBtn.Click
      m_refGridCut.CreateGridCut()
      EgtDraw()
   End Sub

   Private Sub ExitBtn_Click(sender As Object, e As RoutedEventArgs) Handles ExitBtn.Click
      m_refGridCut.SingleCutGrid.Children.Remove(Me)
   End Sub

#End Region    ' Events

End Class
