Imports EgtUILib

Public Class ControlsDirectCutUC

   ' Dichiarazione delle Page UserControl
   Private m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow)
   ' ---- MAI USATA ---- nuova finestra per i comandi per il taglio manuale nuovo
   Friend m_SingleCutAuto As SingleCutAuto
   ' ---- MAI USATA ----
   Friend m_MachineButtons As MachineButtonsUC
   Friend m_ManualAxesMove As ManualAxesMoveUC
   Friend m_SingleCut As SingleCutUC
   Friend m_SingleDrill As SingleDrillUC
   Friend m_MultipleCut As MultipleCut
   Friend m_GridCut As GridCut
   Friend m_FlatteningCut As FlatteningCut
   Friend m_Squaring As SquaringUC
   Friend m_ControlsMachineButton As ControlsMachineButtonUC
   Friend m_VacuumMachineButton As VacuumMachineButtonUC

   Friend m_ControlDirectCutPage1 As ControlsDirectCutUC1

   ' Stato di visualizzazione della macchina
   Friend m_bShowMachine As Boolean = False
   Friend m_nMachLook As Integer = MCH_LOOK.ALL
   ' Dati generali CN
   Friend m_CN As CN_generico
   Private m_bFirst As Boolean = True
   ' Riferimento alla pagina correntemente attiva
   Friend m_ActiveDirectCutPage As DirectCutPages = DirectCutPages.DirectCut
   ' Variabili che indicano attivazione paginette con bottoni macchina
   Private m_ControlsBtn_IsActive As Boolean

   Public Shared m_dZSafe As Double = 52

   ' Variabile che indica se sono attivi i bottoni macchina nuovi o vecchi
   Friend m_NewMachineButtonsType As Boolean
   ' Indica che la finestra del talio Singolo deve essere di tipo manuale
   Friend m_bManulaCut As Boolean = False

   ' elenco dei nuovi bottoni
   Private m_ButtonJogList As New List(Of MachineButton)

   Enum DirectCutPages
      ' pagina principale di tagli diretti
      DirectCut
      ' nuova pagina di tagli diretti
      DirectCut1
      ' elenco dei comandi associati
      ManualAxesMove
      SingleCut
      MultipleCut
      GridCut
      FlatteningCut
      Polishing
      CopyTemplate
      SingleCutAuto
      SingleDrill
      Squaring
   End Enum

   Private Sub ControlsDirectCutUC_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized
      ' leggo la configurazione del programma per i nuovi tagli manuali
      m_bManulaCut = GetPrivateProfileInt(S_GENERAL, K_MANUAL_CUT, 0, m_MainWindow.GetIniFile()) <> 0

      'Creazione delle Page UserControl
      m_MachineButtons = New MachineButtonsUC
      m_ManualAxesMove = New ManualAxesMoveUC
      m_SingleCut = New SingleCutUC
      m_SingleDrill = New SingleDrillUC
      m_MultipleCut = New MultipleCut
      m_GridCut = New GridCut
      m_FlatteningCut = New FlatteningCut
      m_Squaring = New SquaringUC
      m_ControlsMachineButton = New ControlsMachineButtonUC
      m_VacuumMachineButton = New VacuumMachineButtonUC
      ' reiferimento alla pagina succesiva
      m_ControlDirectCutPage1 = New ControlsDirectCutUC1
      ' Costruisco la finestra per il nuovo tipo di taglio manuale
      m_SingleCutAuto = New SingleCutAuto


      'Posizionemento nella griglia delle Page UserControl DirectCutPageUC
      m_MachineButtons.SetValue(Grid.RowProperty, 2)
      m_MachineButtons.SetValue(Grid.ColumnSpanProperty, 7)
      m_ManualAxesMove.SetValue(Grid.RowProperty, 1)
      If m_bManulaCut Then
         m_SingleCutAuto.SetValue(Grid.RowProperty, 1)
      Else
         m_SingleCut.SetValue(Grid.RowProperty, 1)
      End If
      m_SingleDrill.SetValue(Grid.RowProperty, 1)
      m_MultipleCut.SetValue(Grid.RowProperty, 1)
      m_GridCut.SetValue(Grid.RowProperty, 1)
      m_FlatteningCut.SetValue(Grid.RowProperty, 1)
      m_Squaring.SetValue(Grid.RowProperty, 1)
      m_ControlsMachineButton.SetValue(Grid.RowProperty, 1)
      m_VacuumMachineButton.SetValue(Grid.RowProperty, 1)

      ' ManualBtn.Content = EgtMsg(90201)
      ManualTxt.Text = EgtMsg(90201)         ' Movimento manuale
      'SingleCutBtn.Content = EgtMsg(90202)
      SingleCutTxt.Text = EgtMsg(90202)      ' Taglio singolo
      'SingleDrillBtn.Content = "Foro singolo"
      SingleDrillTxt.Text = EgtMsg(90258)    ' Foro singolo
      'MultipleCutBtn.Content = EgtMsg(90203)
      MultipleCutTxt.Text = EgtMsg(90203)    ' Taglio multiplo
      'GridCutBtn.Content = EgtMsg(90204)
      GridCutTxt.Text = EgtMsg(90204)        ' Taglio griglia
      'FlatteningCutBtn.Content = EgtMsg(90206)
      FlatteningCutTxt.Text = EgtMsg(90206)  ' Spianatura
      ' 90261=Squaring
      SquaringTxt.Text = EgtMsg(90261)
      ' 90409=Others
      ChangeUCTxBl.Text = EgtMsg(90409)

   End Sub

   Private Sub ControlsDirectCutUC_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
      ' Se rientro da simulazione
      If m_ActiveDirectCutPage = DirectCutPages.SingleCut Then
         LeftButtonGrid.Children.Add(m_SingleCut)
         Return
      ElseIf m_ActiveDirectCutPage = DirectCutPages.SingleCutAuto Then
         LeftButtonGrid.Children.Add(m_SingleCutAuto)
         Return
      ElseIf m_ActiveDirectCutPage = DirectCutPages.MultipleCut Then
         LeftButtonGrid.Children.Add(m_MultipleCut)
         Return
      ElseIf m_ActiveDirectCutPage = DirectCutPages.GridCut Then
         LeftButtonGrid.Children.Add(m_GridCut)
         Return
      ElseIf m_ActiveDirectCutPage = DirectCutPages.FlatteningCut Then
         LeftButtonGrid.Children.Add(m_FlatteningCut)
         Return
      ElseIf m_ActiveDirectCutPage = DirectCutPages.SingleDrill Then
         LeftButtonGrid.Children.Add(m_SingleDrill)
         Return
      ElseIf m_ActiveDirectCutPage = DirectCutPages.Squaring Then
         LeftButtonGrid.Children.Add(m_Squaring)
         Return
      End If

      If m_MainWindow.m_DirectCutPageUC.m_ActiveControl <> DirectCutPageUC.Controls.MachineButtonUC Or
         m_MainWindow.m_DirectCutPageUC.m_ActiveControl <> DirectCutPageUC.Controls.VacuumButtonUC Then
         ' Caso standard
         m_ActiveDirectCutPage = DirectCutPages.DirectCut
      End If

      ' Attivo le lavorazioni solo se esiste il grezzo e se presente testa H1
      Dim bRawOk As Boolean = (GetRawHeight() > EPS_SMALL)
      Dim bH1Exists As Boolean = (EgtGetHeadId("H1") <> GDB_ID.NULL)

      ManualBtn.IsEnabled = bH1Exists
      ' sviluppo rimasto in sospeso
      If m_bManulaCut Then
         ' anche se non è presente un grezzo mantengo abilitato il bottone
         SingleCutBtn.IsEnabled = True
      Else
         SingleCutBtn.IsEnabled = bRawOk
      End If
      MultipleCutBtn.IsEnabled = bRawOk
      GridCutBtn.IsEnabled = bRawOk
      SingleDrillBtn.IsEnabled = (bRawOk And bH1Exists)
      FlatteningCutBtn.IsEnabled = (bRawOk And bH1Exists)
      SquaringBtn.IsEnabled = bRawOk

      ' aggiorno la visualizzazione dei parametri
      ReloadParam()

      ' Nascondo i pezzi in parcheggio
      HideParkedParts()
      EgtZoom(ZM.ALL)

   End Sub

   ' ricarico i parametri utensili per definizione 
   Public Sub ReloadParam()
      Dim sCurrSawing As String = m_MainWindow.m_CurrentMachine.sCurrSawing
      Dim sCurrSaw As String = m_MainWindow.m_CurrentMachine.sCurrSaw
      Dim bSaw As Boolean = False

      ' se esiste una lavorazione di lama corrente vuol dire che deve essere preferita
      If Not String.IsNullOrEmpty(sCurrSaw) And Not String.IsNullOrEmpty(sCurrSawing) Then
         bSaw = EgtSetCalcTool(sCurrSaw, "H1", 1)
      End If
      If Not bSaw Then
         EgtOutLog(" WARNING! Impossible to get point from SAW, there isn't SAW or SAWING! It's available only by DRAW")
      End If
      m_SingleCut.SetEnableParam(bSaw)
      m_MultipleCut.SetEnableParam(bSaw)
      m_GridCut.SetEnableParam(bSaw)
   End Sub

#Region "COMMAND CLICK BTN"

   Private Sub ManualBtn_Click(sender As Object, e As RoutedEventArgs) Handles ManualBtn.Click
      LeftButtonGrid.Children.Add(m_ManualAxesMove)
      m_ActiveDirectCutPage = DirectCutPages.ManualAxesMove
   End Sub

   Private Sub SingleCutBtn_Click(sender As Object, e As RoutedEventArgs) Handles SingleCutBtn.Click
      If m_bManulaCut Then
         LeftButtonGrid.Children.Add(m_SingleCutAuto)
         m_ActiveDirectCutPage = DirectCutPages.SingleCutAuto
      Else
         LeftButtonGrid.Children.Add(m_SingleCut)
         m_ActiveDirectCutPage = DirectCutPages.SingleCut
      End If

   End Sub

   Private Sub MultipleCutBtn_Click(sender As Object, e As RoutedEventArgs) Handles MultipleCutBtn.Click
      LeftButtonGrid.Children.Add(m_MultipleCut)
      m_ActiveDirectCutPage = DirectCutPages.MultipleCut
   End Sub

   Private Sub GridCutBtn_Click(sender As Object, e As RoutedEventArgs) Handles GridCutBtn.Click
      LeftButtonGrid.Children.Add(m_GridCut)
      m_ActiveDirectCutPage = DirectCutPages.GridCut
   End Sub

   Private Sub FlatteningCutBtn_Click(sender As Object, e As RoutedEventArgs) Handles FlatteningCutBtn.Click
      LeftButtonGrid.Children.Add(m_FlatteningCut)
      m_ActiveDirectCutPage = DirectCutPages.FlatteningCut
   End Sub

   Private Sub SquaringBtn_Click(sender As Object, e As RoutedEventArgs) Handles SquaringBtn.Click
      LeftButtonGrid.Children.Add(m_Squaring)
      m_ActiveDirectCutPage = DirectCutPages.Squaring
   End Sub

   Private Sub SingleDrillBtn_Click(sender As Object, e As RoutedEventArgs) Handles SingleDrillBtn.Click
      LeftButtonGrid.Children.Add(m_SingleDrill)
      m_ActiveDirectCutPage = DirectCutPages.SingleDrill
   End Sub

   ' cambio pagina
   Private Sub ChangeUCBtn_Click(sender As Object, e As RoutedEventArgs) Handles ChangeUCBtn.Click
      DirectCutPage_Unloaded(Nothing, Nothing)
      m_ActiveDirectCutPage = DirectCutPages.DirectCut
      m_MainWindow.m_DirectCutPageUC.LoadDirectCutUC1()
   End Sub

#End Region    ' Command Click Btn


   Friend Sub DirectCutPage_Unloaded(sender As Object, e As RoutedEventArgs) Handles Me.Unloaded
      Select Case m_ActiveDirectCutPage
         Case DirectCutPages.DirectCut Or DirectCutPages.ManualAxesMove
            ' Non è necessario fare alcunché
         Case DirectCutPages.SingleCut
            LeftButtonGrid.Children.Remove(m_SingleCut)
         Case DirectCutPages.SingleCutAuto
            LeftButtonGrid.Children.Remove(m_SingleCutAuto)
         Case DirectCutPages.MultipleCut
            LeftButtonGrid.Children.Remove(m_MultipleCut)
         Case DirectCutPages.GridCut
            LeftButtonGrid.Children.Remove(m_GridCut)
         Case DirectCutPages.FlatteningCut
            LeftButtonGrid.Children.Remove(m_FlatteningCut)
         Case DirectCutPages.SingleDrill
            LeftButtonGrid.Children.Remove(m_SingleDrill)
         Case DirectCutPages.Squaring
            LeftButtonGrid.Children.Remove(m_Squaring)
      End Select
   End Sub

End Class
