Imports EgtUILib
Imports EgtWPFLib5

Public Class Alarms2PageUC

   ' Riferimento alla MainWindow
   Private m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow)
   Private m_CurrentMachine As CurrentMachine

   ' Properties
   Private m_bFirst As Boolean = True

   Private Sub Alarms2Page_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized
      ' Variabile che accorcia il riferimento alla macchina corrente
      m_CurrentMachine = m_MainWindow.m_CurrentMachine

      SawGpBx.Header = EgtMsg(90925)                                     ' Parametri lama
      HolesGpBx.Header = EgtMsg(90917)                                   ' Parametri fori
      MillingsParamGpBx.Header = EgtMsg(90929)                           ' Parametri fresature
      WjsParamGpBx.Header = EgtMsg(91058)                                ' Parametri waterjet
      WjsParamGpBx.Header = EgtMsg(91058)                                ' Parametri waterjet
      RectificationWJParamGpBx.Header = EgtMsg(91047)                    ' Rettifica

      HolesOffsetTxBl.Text = EgtMsg(90909)                               ' Offset fori
      HolesOverlapTxBl.Text = EgtMsg(90910)                              ' Sovrapp. fori
      HolesToleranceTxBl.Text = EgtMsg(90911)                            ' Tolleranza fori
      OneHoleInCornerTxBl.Text = EgtMsg(90926)                           ' Un solo foro in angolo
      CutExtraLenTxBl.Text = EgtMsg(90906)                               ' Sicurezza tagli
      AngleCutExtraLenTxBl.Text = EgtMsg(90907)                          ' Sicur. angoli
      ExtArcMinRadTxBl.Text = EgtMsg(90918)                              ' Rmin archi est.
      IntArcMaxSideAngTxBl.Text = EgtMsg(90924)                          ' Amax archi int.
      PreCutExitTxBl.Text = EgtMsg(91065)                                ' PreTaglio uscite
      CornerCutsTxBl.Text = EgtMsg(90944)                                ' Sempre sugli angoli
      InternalCutsTxBl.Text = EgtMsg(90930)                              ' Sempre sugli interni
      ShortTxBl.Text = EgtMsg(90949)                                     ' Accorciamento
      '-- INIZIO -- nuovi parametro Rettifica tagli sottosquadra WJ
      EnableRectificationTxBl.Text = EgtMsg(91048)                       ' Abilita (sottosquadra)
      '-- INIZIO -- nuovi parametri per preforo lavello
      WjIntCutsTxBl.Text = EgtMsg(90930)                                 ' Sempre sugli interni
      HolesDiameterWJTxBl.Text = EgtMsg(91044)                           ' Diametro
      HolesOffsetWJTxBl.Text = EgtMsg(91045)                             ' Offset
      MinRadiusWJTxBl.Text = EgtMsg(91046)                               ' Raggio Minimo
      OneHoleInCornerWJTxBl.Text = EgtMsg(90926)                         ' Un solo foro in angolo

   End Sub

   Private Sub Allarm2Page_Loaded() Handles Me.Loaded
      If m_bFirst Then
         ' in assenza dell'uscita H1 nascondo i parametri lama
         If EgtGetHeadId("H1") = GDB_ID.NULL Then
            SawGpBx.Visibility = Visibility.Hidden
         End If

         ' Verifico la configurazione della macchina per creare i combobox
         Select Case m_CurrentMachine.MountedToolConfig
            Case CurrentMachine.MountedToolConfigs.SAW
               ' Disattivo il gruppo dei parametri fori
               HolesGpBx.Visibility = Windows.Visibility.Hidden
            Case CurrentMachine.MountedToolConfigs.SAWANDAUXTOOL
            'Non faccio alcunchè
            Case CurrentMachine.MountedToolConfigs.MANUALTOOLCHANGER, CurrentMachine.MountedToolConfigs.TOOLCHANGER, CurrentMachine.MountedToolConfigs.TOOLCHANGERWITHSAW
               'Da implementare
         End Select

         ' Se non previste forature, disabilito relativo box
         If Not m_CurrentMachine.bDrilling Then
            HolesGpBx.Visibility = Visibility.Hidden
         End If

         ' Se non previste fresature, disabilito relativo box e uso fresa con incisione
         If Not m_CurrentMachine.bMilling Then
            MillingsParamGpBx.Visibility = Visibility.Hidden
         End If

         ' Se non previsti tagli waterjet, disabilito relativo box
         If Not m_CurrentMachine.bWaterJetting Then
            WjsParamGpBx.Visibility = Visibility.Hidden
            RectificationWJParamGpBx.Visibility = Visibility.Hidden
         End If

         m_bFirst = False
      End If

      Dim dVal As Double
      dVal = GetPrivateProfileDouble(S_MACH_NEST, K_MACH_HOLES_OFFSET, 0, m_MainWindow.GetMachIniFile())
      EgtMdbSetGeneralParam(MCH_GP.EXTRARONDRIREG, dVal)
      HolesOffsetTxBx.Text = LenToString(dVal, 2)
      ' Leggo sovrapposizione fori
      dVal = GetPrivateProfileDouble(S_MACH_NEST, K_MACH_HOLES_OVERLAP, 0, m_MainWindow.GetMachIniFile())
      HolesOverlapTxBx.Text = LenToString(dVal, 2)
      ' Leggo tolleranza diametro fori
      dVal = GetPrivateProfileDouble(S_MACH_NEST, K_MACH_HOLES_DIAMTOLER, 0, m_MainWindow.GetMachIniFile())
      EgtMdbSetGeneralParam(MCH_GP.HOLEDIAMTOLER, dVal)
      HolesToleranceTxBx.Text = LenToString(dVal, 2)
      ' Leggo un solo foro in corner
      OneHoleInCornerChBx.IsChecked = (GetPrivateProfileInt(S_MACH_NEST, K_MACH_ONEHOLE_INTCORNER, 0, m_MainWindow.GetMachIniFile()) <> 0)
      ' Leggo sicurezza su tagli
      dVal = GetPrivateProfileDouble(S_MACH_NEST, K_MACH_SAFE_LEN_CUT, 0, m_MainWindow.GetMachIniFile())
      EgtMdbSetGeneralParam(MCH_GP.EXTRALONCUTREG, dVal)
      CutExtraLenTxBx.Text = LenToString(dVal, 2)
      ' Leggo sicurezza su tagli in angoli interni
      dVal = GetPrivateProfileDouble(S_MACH_NEST, K_MACH_SAFE_LEN_INTCORNER, 0, m_MainWindow.GetMachIniFile())
      AngleCutExtraLenTxBx.Text = LenToString(dVal, 2)
      ' Leggo raggio minimo arco esterno
      dVal = GetPrivateProfileDouble(S_MACH_NEST, K_MACH_EXTARCMINRAD, 200, m_MainWindow.GetMachIniFile())
      EgtMdbSetGeneralParam(MCH_GP.EXTSAWARCMINRAD, dVal)
      ExtArcMinRadTxBx.Text = LenToString(dVal, 2)
      ' Leggo angolo di fianco massimo arco interno
      dVal = GetPrivateProfileDouble(S_MACH_NEST, K_MACH_INTARCMAXSIDEANG, 45, m_MainWindow.GetMachIniFile())
      EgtMdbSetGeneralParam(MCH_GP.INTSAWARCMAXSIDEANG, dVal)
      IntArcMaxSideAngTxBx.Text = DoubleToString(dVal, 2)
      ' Leggo se PreCutExit attivo (per taglio ceramico)
      Dim nPreCutExit As Integer = GetPrivateProfileInt(S_MACH_NEST, K_MACH_PRECUTEXIT, -1, m_MainWindow.GetMachIniFile())
      If nPreCutExit = -1 Then
         PreCutExitTxBl.Visibility = Visibility.Hidden
         PreCutExitChBx.Visibility = Visibility.Hidden
      Else
         PreCutExitChBx.IsChecked = (nPreCutExit <> 0)
      End If
      ' Salvo DB lavorazioni con aggiornamenti parametri generali
      EgtMdbSave()
      ' Leggo lavorazione angoli con fresa
      CornerCutsChBx.IsChecked = (GetPrivateProfileInt(S_MACH_NEST, K_MACH_MILLING_ON_CORNERS, 1, m_MainWindow.GetMachIniFile()) <> 0)
      ' Leggo lavorazione interni con fresa
      InternalCutsChBx.IsChecked = (GetPrivateProfileInt(S_MACH_NEST, K_MACH_MILLING_ON_SINKS, 0, m_MainWindow.GetMachIniFile()) <> 0)
      ' Leggo accorciamento angoli con fresa
      dVal = GetPrivateProfileDouble(S_MACH_NEST, K_MACH_MILLING_SHORTENING, 0, m_MainWindow.GetMachIniFile())
      ShortTxBx.Text = LenToString(dVal, 2)
      ' leggo se attiva la rettifica degli angoli per WaterJet
      EnableRectificationChBx.IsChecked = (GetPrivateProfileInt(S_MACH_NEST, K_MACH_RECTIFICATION_ON_SUBSQUARE, 0, m_MainWindow.GetMachIniFile()) <> 0)
      WjIntCutsChBx.IsChecked = (GetPrivateProfileInt(S_MACH_NEST, K_MACH_MILLING_ON_SINKS, 0, m_MainWindow.GetMachIniFile()) <> 0)
      ' Lavorazione preforo lavello con WaterJet
      dVal = GetPrivateProfileDouble(S_MACH_NEST, K_HOLES_DIAMITERWJ, 0, m_MainWindow.GetMachIniFile())
      HolesDiameterWJTxBx.Text = LenToString(dVal, 2)
      dVal = GetPrivateProfileDouble(S_MACH_NEST, K_HOLES_OFFSETWJ, 0, m_MainWindow.GetMachIniFile())
      HolesOffsetWJTxBx.Text = LenToString(dVal, 2)
      dVal = GetPrivateProfileDouble(S_MACH_NEST, K_MIN_RADIUSWJ, 0, m_MainWindow.GetMachIniFile())
      MinRadiusWJTxBx.Text = LenToString(dVal, 2)
      OneHoleInCornerWJChBx.IsChecked = (GetPrivateProfileInt(S_MACH_NEST, K_MACH_DRILLINGWJ_ON_CORNERS, 1, m_MainWindow.GetMachIniFile()) <> 0)
   End Sub

   Private Sub CutExtraLenTxBx_EgtClosed(sender As Object, e As EventArgs) Handles CutExtraLenTxBx.EgtClosed
      Dim dVal As Double = 0
      StringToLen(CutExtraLenTxBx.Text, dVal)
      WritePrivateProfileString(S_MACH_NEST, K_MACH_SAFE_LEN_CUT, DoubleToString(dVal, 2), m_MainWindow.GetMachIniFile())
      EgtMdbSetGeneralParam(MCH_GP.EXTRALONCUTREG, dVal)
      EgtMdbSave()
   End Sub

   Private Sub AngleCutExtraLenTxBx_EgtClosed(sender As Object, e As EventArgs) Handles AngleCutExtraLenTxBx.EgtClosed
      Dim dVal As Double = 0
      StringToLen(AngleCutExtraLenTxBx.Text, dVal)
      WritePrivateProfileString(S_MACH_NEST, K_MACH_SAFE_LEN_INTCORNER, DoubleToString(dVal, 2), m_MainWindow.GetMachIniFile())
   End Sub

   Private Sub ExtArcMinRadTxBx_EgtClosed(sender As Object, e As EventArgs) Handles ExtArcMinRadTxBx.EgtClosed
      Dim dVal As Double = 0
      StringToLen(ExtArcMinRadTxBx.Text, dVal)
      WritePrivateProfileString(S_MACH_NEST, K_MACH_EXTARCMINRAD, DoubleToString(dVal, 2), m_MainWindow.GetMachIniFile())
      EgtMdbSetGeneralParam(MCH_GP.EXTSAWARCMINRAD, dVal)
      EgtMdbSave()
   End Sub

   Private Sub IntArcMaxSideAngTxBx_EgtClosed(sender As Object, e As EventArgs) Handles IntArcMaxSideAngTxBx.EgtClosed
      Dim dVal As Double = 0
      StringToDouble(IntArcMaxSideAngTxBx.Text, dVal)
      WritePrivateProfileString(S_MACH_NEST, K_MACH_INTARCMAXSIDEANG, DoubleToString(dVal, 2), m_MainWindow.GetMachIniFile())
      EgtMdbSetGeneralParam(MCH_GP.INTSAWARCMAXSIDEANG, dVal)
      EgtMdbSave()
   End Sub

   Private Sub PreCutExitChBx_Click(sender As Object, e As RoutedEventArgs) Handles PreCutExitChBx.Click
      If PreCutExitChBx.IsChecked Then
         WritePrivateProfileString(S_MACH_NEST, K_MACH_PRECUTEXIT, "1", m_MainWindow.GetMachIniFile())
      Else
         WritePrivateProfileString(S_MACH_NEST, K_MACH_PRECUTEXIT, "0", m_MainWindow.GetMachIniFile())
      End If
   End Sub

   Private Sub HolesOffsetTxBx_EgtClosed(sender As Object, e As EventArgs) Handles HolesOffsetTxBx.EgtClosed
      Dim dVal As Double = 0
      StringToLen(HolesOffsetTxBx.Text, dVal)
      WritePrivateProfileString(S_MACH_NEST, K_MACH_HOLES_OFFSET, DoubleToString(dVal, 2), m_MainWindow.GetMachIniFile())
      EgtMdbSetGeneralParam(MCH_GP.EXTRARONDRIREG, dVal)
      EgtMdbSave()
   End Sub

   Private Sub HolesOverlapTxBx_EgtClosed(sender As Object, e As EventArgs) Handles HolesOverlapTxBx.EgtClosed
      Dim dVal As Double = 0
      StringToLen(HolesOverlapTxBx.Text, dVal)
      WritePrivateProfileString(S_MACH_NEST, K_MACH_HOLES_OVERLAP, DoubleToString(dVal, 2), m_MainWindow.GetMachIniFile())
   End Sub

   Private Sub HolesToleranceTxBx_EgtClosed(sender As Object, e As EventArgs) Handles HolesToleranceTxBx.EgtClosed
      Dim dVal As Double = 0
      StringToLen(HolesToleranceTxBx.Text, dVal)
      WritePrivateProfileString(S_MACH_NEST, K_MACH_HOLES_DIAMTOLER, DoubleToString(dVal, 2), m_MainWindow.GetMachIniFile())
      EgtMdbSetGeneralParam(MCH_GP.HOLEDIAMTOLER, dVal)
      EgtMdbSave()
   End Sub

   Private Sub OneHoleInCornerChBx_Click(sender As Object, e As RoutedEventArgs) Handles OneHoleInCornerChBx.Click
      If OneHoleInCornerChBx.IsChecked() Then
         WritePrivateProfileString(S_MACH_NEST, K_MACH_ONEHOLE_INTCORNER, "1", m_MainWindow.GetMachIniFile())
      Else
         WritePrivateProfileString(S_MACH_NEST, K_MACH_ONEHOLE_INTCORNER, "0", m_MainWindow.GetMachIniFile())
      End If
   End Sub

   Private Sub CornerCutsChBx_Click(sender As Object, e As RoutedEventArgs) Handles CornerCutsChBx.Click
      If CornerCutsChBx.IsChecked() Then
         WritePrivateProfileString(S_MACH_NEST, K_MACH_MILLING_ON_CORNERS, "1", m_MainWindow.GetMachIniFile())
      Else
         WritePrivateProfileString(S_MACH_NEST, K_MACH_MILLING_ON_CORNERS, "0", m_MainWindow.GetMachIniFile())
      End If
   End Sub

   Private Sub ShortTxBx_EgtClosed(sender As Object, e As EventArgs) Handles ShortTxBx.EgtClosed
      Dim dVal As Double = 0
      StringToLen(ShortTxBx.Text, dVal)
      WritePrivateProfileString(S_MACH_NEST, K_MACH_MILLING_SHORTENING, DoubleToString(dVal, 2), m_MainWindow.GetMachIniFile())
   End Sub

   Private Sub InternalCutsChBx_Click(sender As Object, e As RoutedEventArgs) Handles InternalCutsChBx.Click
      If InternalCutsChBx.IsChecked() Then
         WritePrivateProfileString(S_MACH_NEST, K_MACH_MILLING_ON_SINKS, "1", m_MainWindow.GetMachIniFile())
      Else
         WritePrivateProfileString(S_MACH_NEST, K_MACH_MILLING_ON_SINKS, "0", m_MainWindow.GetMachIniFile())
      End If
   End Sub

   ' -- INIZIO -- nuovi parametri per Rettifica angoli in sottosquadra WaterJet
   Private Sub EnableRectificationChBx_Click(sender As Object, e As EventArgs) Handles EnableRectificationChBx.Click
      If EnableRectificationChBx.IsChecked() Then
         WritePrivateProfileString(S_MACH_NEST, K_MACH_RECTIFICATION_ON_SUBSQUARE, "1", m_MainWindow.GetMachIniFile)
      Else
         WritePrivateProfileString(S_MACH_NEST, K_MACH_RECTIFICATION_ON_SUBSQUARE, "0", m_MainWindow.GetMachIniFile)
      End If
   End Sub
   ' --   FINE   -- nuovi parametri per Rettifica angoli in sottosquadra WaterJet

   Private Sub WjIntCutsChBx_Click(sender As Object, e As RoutedEventArgs) Handles WjIntCutsChBx.Click
      If WjIntCutsChBx.IsChecked() Then
         WritePrivateProfileString(S_MACH_NEST, K_MACH_MILLING_ON_SINKS, "1", m_MainWindow.GetMachIniFile())
      Else
         WritePrivateProfileString(S_MACH_NEST, K_MACH_MILLING_ON_SINKS, "0", m_MainWindow.GetMachIniFile())
      End If
   End Sub

   ' -- INIZIO -- nuovi parametri per prefori WaterJet
   Private Sub HolesDiameterWJTxBx_Click(sender As Object, e As EventArgs) Handles HolesDiameterWJTxBx.EgtClosed
      Dim dVal As Double = 0
      StringToLen(HolesDiameterWJTxBx.Text, dVal)
      WritePrivateProfileString(S_MACH_NEST, K_HOLES_DIAMITERWJ, DoubleToString(dVal, 2), m_MainWindow.GetMachIniFile())
   End Sub

   Private Sub HolesOffsetWJTxBx_Click(sender As Object, e As EventArgs) Handles HolesOffsetWJTxBx.EgtClosed
      Dim dVal As Double = 0
      StringToLen(HolesOffsetWJTxBx.Text, dVal)
      WritePrivateProfileString(S_MACH_NEST, K_HOLES_OFFSETWJ, DoubleToString(dVal, 2), m_MainWindow.GetMachIniFile())
   End Sub

   Private Sub MinRadiusWJTxBx_Click(sender As Object, e As EventArgs) Handles MinRadiusWJTxBx.EgtClosed
      Dim dVal As Double = 0
      StringToLen(MinRadiusWJTxBx.Text, dVal)
      WritePrivateProfileString(S_MACH_NEST, K_MIN_RADIUSWJ, DoubleToString(dVal, 2), m_MainWindow.GetMachIniFile())
   End Sub

   Private Sub OneHoleInCornerWJChBx_Click(sender As Object, e As EventArgs) Handles OneHoleInCornerWJChBx.Click
      If OneHoleInCornerWJChBx.IsChecked() Then
         WritePrivateProfileString(S_MACH_NEST, K_MACH_DRILLINGWJ_ON_CORNERS, "1", m_MainWindow.GetMachIniFile())
      Else
         WritePrivateProfileString(S_MACH_NEST, K_MACH_DRILLINGWJ_ON_CORNERS, "0", m_MainWindow.GetMachIniFile())
      End If
   End Sub
   ' --   FINE   -- nuovi parametri per prefori WaterJet

End Class
