Imports System.Collections.ObjectModel
Imports System.ComponentModel
Imports OmagCUT.TreeViewItem
Imports EgtUILib
Imports EgtWPFLib
Imports EgtWPFLib5

Public Class MachiningDbPageUC

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

   ' Lista degli utensili
   Dim MachiningsList As New ObservableCollection(Of CathegoryItem)

   ' Lista dei materiali
   Private m_MaterialsList As New ObservableCollection(Of MachiningMaterial)

   ' Proprietà
   Private m_bFirst As Boolean = True

   Private m_sMachiningName As String = String.Empty

   'Array che contengono le variabili per Combobox
   Dim WorkSide() As String
   Dim HeadSide() As String
   Dim LeadInType() As ObservableCollection(Of IdNameStruct)
   Dim ExtLinkType() As String
   Dim LeadOutType() As ObservableCollection(Of IdNameStruct)
   Dim LeadLinkType() As String
   Dim LeLiFinType() As String
   Dim CurveUse() As String
   Dim StepType() As String
   Dim RouFinStepType() As String
   Dim ExtCornType() As String
   Dim IntCornType() As String
   Dim SawTool As New ObservableCollection(Of String)
   Dim DrillTool As New ObservableCollection(Of String)
   Dim MillTool As New ObservableCollection(Of String)
   Dim PocketTool As New ObservableCollection(Of String)
   Dim WaterJetTool As New ObservableCollection(Of String)

   'Variabile che conserva la lavorazione precedentemente selezionata, usata nel caso si selezioni annulla quando si cambia lavorazione selezionata
   Private m_OldItem As Object

   Private Sub MachiningDbPage_Initialized(sender As Object, e As EventArgs)

      ' Assegno la lista degli utensili come sorgente del treeview
      MachiningTreeView.ItemsSource = MachiningsList

      ' Assegno la lista dei materiali come sorgente della listbox
      MaterialsList.ItemsSource = m_MaterialsList

      ' Imposto testo delle combobox da file dei messaggi
      WorkSide = {EgtMsg(MSG_COMBOBOXPARAM + 21), EgtMsg(MSG_COMBOBOXPARAM + 22), EgtMsg(MSG_COMBOBOXPARAM + 23)}
      HeadSide = {EgtMsg(MSG_COMBOBOXPARAM + 22), EgtMsg(MSG_COMBOBOXPARAM + 23)}
      ExtLinkType = {EgtMsg(MSG_COMBOBOXPARAM + 24), EgtMsg(MSG_COMBOBOXPARAM + 29), EgtMsg(MSG_COMBOBOXPARAM + 30), EgtMsg(MSG_COMBOBOXPARAM + 31)}
      LeadLinkType = {EgtMsg(MSG_COMBOBOXPARAM + 24), EgtMsg(MSG_COMBOBOXPARAM + 26)}
      LeLiFinType = {EgtMsg(MSG_COMBOBOXPARAM + 42), EgtMsg(MSG_COMBOBOXPARAM + 24), EgtMsg(MSG_COMBOBOXPARAM + 26)}
      CurveUse = {EgtMsg(MSG_COMBOBOXPARAM + 35), EgtMsg(MSG_COMBOBOXPARAM + 36), EgtMsg(MSG_COMBOBOXPARAM + 37), EgtMsg(MSG_COMBOBOXPARAM + 41)}
      StepType = {EgtMsg(MSG_COMBOBOXPARAM + 38), EgtMsg(MSG_COMBOBOXPARAM + 39), EgtMsg(MSG_COMBOBOXPARAM + 40)}
      RouFinStepType = {EgtMsg(MSG_COMBOBOXPARAM + 38), EgtMsg(MSG_COMBOBOXPARAM + 39)}
      ExtCornType = {EgtMsg(MSG_COMBOBOXPARAM + 43), EgtMsg(MSG_COMBOBOXPARAM + 44), EgtMsg(MSG_COMBOBOXPARAM + 45)}
      IntCornType = {EgtMsg(MSG_COMBOBOXPARAM + 43), EgtMsg(MSG_COMBOBOXPARAM + 44)}

      ' Assegno array a combobox
      WorkSideCmBx.ItemsSource = WorkSide
      HeadSideCmBx.ItemsSource = HeadSide
      LeadInTypeCmBx.ItemsSource = LeadInType
      ExtLinkTypeCmBx.ItemsSource = ExtLinkType
      LeadOutTypeCmBx.ItemsSource = LeadOutType
      LeadLinkTypeCmBx.ItemsSource = LeadLinkType
      CurveUseCmBx.ItemsSource = CurveUse
      StepTypeCmBx.ItemsSource = StepType
      ExtCornTypeCmBx.ItemsSource = ExtCornType
      IntCornTypeCmBx.ItemsSource = IntCornType

      ' Imposto i messaggi letti dal file dei messaggi
      NewBtn.Content = EgtMsg(MSG_MACHINEPAGEUC + 16)
      SaveBtn.Content = EgtMsg(MSG_MACHINEPAGEUC + 17)
      RemoveBtn.Content = EgtMsg(MSG_MACHINEPAGEUC + 18)
      ExportBtn.Content = "Export"
      ImportBtn.Content = "Import"

      NameTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 1)
      DepthTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 2)
      SideAngleTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 3)
      InvertTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 4)
      AcrossTxBl.Text = EgtMsg(MSG_OMAGCUT + 861)
      StepTypeTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 5)
      WorkSideTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 6)
      HeadSideTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 7)
      StartPosTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 8)
      LeadInTypeTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 9)
      ExtLinkTypeTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 10)
      LeadOutTypeTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 11)
      LeadLinkTypeTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 10)
      CurveUseTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 12)
      ApproxTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 13)
      SawStepGpBx.Header = EgtMsg(MSG_MACHININGSDBPAGEUC + 14)
      ForwardSawStepTxBl.Text = EgtMsg(MSG_OMAGCUT + 864)
      BackwardSawStepTxBl.Text = EgtMsg(MSG_OMAGCUT + 865)
      DrillStepTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 16)
      SawRouStepGpBx.Header = EgtMsg(MSG_MACHININGSDBPAGEUC + 27)
      SawRouStepTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 28)
      SideStepTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 29)
      ForwardStepSideAngTxBl.Text = EgtMsg(MSG_OMAGCUT + 862)
      BackwardStepSideAngTxBl.Text = EgtMsg(MSG_OMAGCUT + 863)
      LastSawStepTxBl.Text = EgtMsg(90897)   'Ultimo taglio
      ArcIntTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 17)
      ArcExtTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 18)
      LowLenGpBx.Header = EgtMsg(MSG_MACHININGSDBPAGEUC + 19)
      StartsLowLenTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 20)
      EndsLowLenTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 21)
      ThrouAddLenTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 22)
      ReturnPosTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 23)

      ToolTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 24)
      SpeedTxBl.Text = EgtMsg(MSG_TOOLSDBPAGEUC + 5)
      FeedGpBx.Header = EgtMsg(MSG_TOOLSDBPAGEUC + 8)
      FeedTxBl.Text = EgtMsg(MSG_TOOLSDBPAGEUC + 9)
      TipFeedTxBl.Text = EgtMsg(MSG_TOOLSDBPAGEUC + 10)
      StartFeedTxBl.Text = EgtMsg(MSG_TOOLSDBPAGEUC + 11)
      EndFeedTxBl.Text = EgtMsg(MSG_TOOLSDBPAGEUC + 12)
      ThicknessFeedTxBl.Text = EgtMsg(MSG_TOOLSDBPAGEUC + 23)
      VertFeedTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 30)
      BackFeedTxBl.Text = EgtMsg(MSG_OMAGCUT + 866)
      SideAngCutTxBl.Text = EgtMsg(90898) 'Tagli inclinati
      OffsetGpBx.Header = EgtMsg(MSG_TOOLSDBPAGEUC + 15)
      LonOffsetTxBl.Text = EgtMsg(MSG_TOOLSDBPAGEUC + 16)
      RadOffsetTxBl.Text = EgtMsg(MSG_TOOLSDBPAGEUC + 17)

      SpecificLeadInGpBx.Header = EgtMsg( 90894)  'Attacco Ceramica
      SpecificLenTxBl.Text = EgtMsg( 90895)       'Lunghezza
      SpecificStepTxBl.Text = EgtMsg( 90896)      'Passo

      MinThicknessTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 25)
      MaxThicknessTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 26)

      ForwardAngleTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 107)
      CornerGpBx.Header = EgtMsg(MSG_MACHININGSDBPAGEUC + 120)
      ProbingGpBx.Header = EgtMsg(MSG_MACHININGSDBPAGEUC + 108)
      ProbingTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 119)
      ProbingMinDistTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 109)
      ProbingMaxDistTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 110)
      ExtCornTypeTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 111)
      IntCornTypeTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 112)
      CornSlowLenTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 113)
      CornSlowPercTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 114)
      LiHoleTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 115)
      LiHoleRadTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 116)
      LpTurnsTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 117)
      HpTurnsTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 118)
      LiTangTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 130)
      LiPerpTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 131)
      LoTangTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 132)
      LoPerpTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 133)

      ' Associo TextBox e Label
      Dim TempLabel1 As New Label
      TempLabel1.Content = SideAngleTxBl.Text
      SideAngleTxBx.Tag = TempLabel1
      Dim TempLabel2 As New Label
      TempLabel2.Content = ApproxTxBl.Text
      ApproxTxBx.Tag = TempLabel2
   End Sub

   Private Sub MachiningDbPage_Loaded(sender As Object, e As RoutedEventArgs)
      EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
      ' Carico le liste di utensili
      InitializeToolLists()
      ' Carico elenco lavorazioni
      If m_bFirst Then
         Dim CurrMachine As CurrentMachine = m_MainWindow.m_CurrentMachine
         InitializeMachiningFamily(CurrMachine.bSawing, MCH_MY.SAWING, EgtMsg(MSG_MACHININGSDBPAGEUC + 31))
         InitializeMachiningFamily(CurrMachine.bDrilling, MCH_MY.DRILLING, EgtMsg(MSG_MACHININGSDBPAGEUC + 32))
         InitializeMachiningFamily(CurrMachine.bMilling, MCH_MY.MILLING, EgtMsg(MSG_MACHININGSDBPAGEUC + 33))
         InitializeMachiningFamily(CurrMachine.bSawRoughing, MCH_MY.SAWROUGHING, EgtMsg(MSG_MACHININGSDBPAGEUC + 34))
         InitializeMachiningFamily(CurrMachine.bSawFinishing, MCH_MY.SAWFINISHING, EgtMsg(MSG_MACHININGSDBPAGEUC + 35))
         InitializeMachiningFamily(CurrMachine.bPocketing, MCH_MY.POCKETING, EgtMsg(MSG_MACHININGSDBPAGEUC + 36))
         InitializeMachiningFamily(CurrMachine.bWaterJetting, MCH_MY.WATERJETTING, EgtMsg(MSG_MACHININGSDBPAGEUC + 37))
         m_bFirst = False
      End If
      ' Imposto la prima lavorazione
      InitializeFirstSelectedItem()

   End Sub

   'Funzione che permette di inizializzare le liste di utensili
   Private Sub InitializeToolLists()
      Dim sToolName As String = String.Empty
      Dim nType As Integer = MCH_TY.NONE
      Dim bFound As Boolean = False
      SawTool.Clear()
      If EgtTdbGetFirstTool(MCH_TF.SAWBLADE, sToolName, nType) Then
         SawTool.Add(sToolName)
         While EgtTdbGetNextTool(MCH_TF.SAWBLADE, sToolName, nType)
            SawTool.Add(sToolName)
         End While
      End If
      DrillTool.Clear()
      If EgtTdbGetFirstTool(MCH_TF.DRILLBIT, sToolName, nType) Then
         DrillTool.Add(sToolName)
         While EgtTdbGetNextTool(MCH_TF.DRILLBIT, sToolName, nType)
            DrillTool.Add(sToolName)
         End While
      End If
      MillTool.Clear()
      bFound = EgtTdbGetFirstTool(MCH_TF.MILL, sToolName, nType)
      While bFound
         If nType = MCH_TY.MILL_STD Then MillTool.Add( sToolName)
         bFound = EgtTdbGetNextTool(MCH_TF.MILL, sToolName, nType)
      End While
      PocketTool.Clear()
      bFound = EgtTdbGetFirstTool(MCH_TF.MILL, sToolName, nType)
      While bFound
         If nType = MCH_TY.MILL_NOTIP Then PocketTool.Add( sToolName)
         bFound = EgtTdbGetNextTool(MCH_TF.MILL, sToolName, nType)
      End While
      WaterJetTool.Clear()
      If EgtTdbGetFirstTool(MCH_TF.WATERJET, sToolName, nType) Then
         WaterJetTool.Add(sToolName)
         While EgtTdbGetNextTool(MCH_TF.WATERJET, sToolName, nType)
            WaterJetTool.Add(sToolName)
         End While
      End If

   End Sub

   'Funzione che permette l'inizializzazione di albero e parametri all'apertura della pagina ToolsDb
   Private Sub InitializeFirstSelectedItem()
      If MachiningsList.Count > 0 Then
         For Each MachiningFamily As CathegoryItem In MachiningsList
            If MachiningFamily.Items.Count > 0 Then
               MachiningFamily.IsExpanded = True
               MachiningFamily.Items(0).IsSelected = True
               Dim x = EgtMdbSetCurrMachining(MachiningFamily.Items(0).Name)
               m_OldItem = MachiningFamily.Items(0)
               GetMachiningParams()
               ViewMachiningParams()
               Exit Sub
            End If
         Next
         MachiningsList.Item(0).IsSelected = True
         HideMachiningParams()
      End If
   End Sub

   Private Sub NewBtn_Click(sender As Object, e As RoutedEventArgs) Handles NewBtn.Click
      EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
      If TypeOf MachiningTreeView.SelectedItem Is CathegoryItem Then
         Dim SelectedCathegory As CathegoryItem = MachiningTreeView.SelectedItem
         Dim NewName As String = SelectedCathegory.Name
         EgtMdbGetMachiningNewName(NewName)
         If EgtMdbAddMachining(NewName, SelectedCathegory.nTType) Then
            For Each MachiningFamily As CathegoryItem In MachiningsList
               If MachiningFamily.nTType = SelectedCathegory.nTType Then
                  Dim NewMachiningItem As New CustomItem(NewName, SelectedCathegory.nTType)
                  MachiningFamily.Items.Add(NewMachiningItem)
                  NewMachiningItem.IsSelected = True
                  MachiningFamily.IsExpanded = True
                  m_OldItem = MachiningTreeView.SelectedItem
                  Exit For
               End If
            Next
            GetMachiningParams()
            ViewMachiningParams()
         End If
      ElseIf TypeOf MachiningTreeView.SelectedItem Is CustomItem Then
         Dim SelectedCathegory As CustomItem = MachiningTreeView.SelectedItem
         Dim NewName As String = SelectedCathegory.Name
         EgtMdbGetMachiningNewName(NewName)
         If EgtMdbCopyMachining(SelectedCathegory.Name, NewName) Then
            Dim CurrType As Integer
            EgtMdbGetCurrMachiningParam(MCH_MP.TYPE, CurrType)
            For Each MachiningFamily As CathegoryItem In MachiningsList
               If MachiningFamily.nTType = CurrType Then
                  Dim NewMachiningItem As New CustomItem(NewName, CurrType)
                  MachiningFamily.Items.Add(NewMachiningItem)
                  NewMachiningItem.IsSelected = True
                  GetMachiningParams()
                  m_OldItem = MachiningTreeView.SelectedItem
                  Exit For
               End If
            Next
         End If
      End If

   End Sub

   Private Sub SaveBtn_Click(sender As Object, e As RoutedEventArgs) Handles SaveBtn.Click
      EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
      SetMachiningParams()
      EgtMdbSaveCurrMachining()
      m_sMachiningName = NameTxBx.Text
      Dim Machining As CustomItem = TryCast(m_OldItem, CustomItem)
      If Machining IsNot Nothing Then
         Machining.Name = m_sMachiningName
      End If
   End Sub

   Private Sub RemoveBtn_Click(sender As Object, e As RoutedEventArgs) Handles RemoveBtn.Click
      If TypeOf MachiningTreeView.SelectedItem Is CustomItem Then
         Dim SelectedItem As CustomItem = MachiningTreeView.SelectedItem
         EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
         ' Cancello la lavorazione
         EgtMdbRemoveMachining(SelectedItem.Name)
         ' Rimuovo dall'albero
         For Each MachiningFamily As CathegoryItem In MachiningsList
            If (MachiningFamily.nTType And SelectedItem.nType) <> 0 Then
               MachiningFamily.Items.Remove(SelectedItem)
               If MachiningFamily.Items.Count = 0 Then
                  MachiningFamily.IsSelected = True
                  HideMachiningParams()
               Else
                  MachiningFamily.Items(0).IsSelected = True
                  EgtMdbSetCurrMachining(MachiningFamily.Items(0).Name)
                  m_OldItem = MachiningFamily.Items(0)
                  GetMachiningParams()
                  ViewMachiningParams()
               End If
            End If
         Next
      End If
   End Sub

   Private Sub ExportBtn_Click(Sender As Object, e As RoutedEventArgs) Handles ExportBtn.Click
      ' contesto corrente
      EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())

      ' creo lista lavorazioni per esportazione
      Dim MachiningToExportList As New ObservableCollection(Of ImpExpMachiningFamily)
      Dim Family As CathegoryItem
      Dim Machining As CustomItem
      For Each Family In MachiningsList
         Dim ImpExpMachiningFamily As New ImpExpMachiningFamily(Family.Name, Family.nTType)
         For Each Machining In Family.Items
            ImpExpMachiningFamily.MachiningList.Add(New ImpExpMachiningItem(Machining.Name, False))
         Next
         MachiningToExportList.Add(ImpExpMachiningFamily)
      Next
      Dim ExportWndVM As New ImportExportMachiningWindowVM(MachiningToExportList, true)
      Dim ExportWnd As New ImportExportMachiningWindowWD(Application.Current.MainWindow, ExportWndVM)

      ExportWnd.ShowDialog()
   End Sub

   Private Sub ImoportBtn_Click() Handles ImportBtn.Click
      ' contesto corrente
      EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
      ' apro dialogo di scelta file
      Dim ImportFileDlg As New Microsoft.Win32.OpenFileDialog() With {
         .Title = EgtMsg(31161) & " " & EgtMsg(31163),
         .DefaultExt = ".data",
         .Filter = "Machinings (.data)|*.data",
         .CheckFileExists = True,
         .ValidateNames = True
      }
      If ImportFileDlg.ShowDialog() <> True Then Return
      Dim ImportFilePath As String = ImportFileDlg.FileName
      ' recupero liste utensili da importare
      Dim ImportFileMachiningNameList As String() = Nothing
      Dim ImportFileMachiningFamilyList As Integer() = Nothing
      If Not EgtMdbToBeImported(ImportFilePath, ImportFileMachiningNameList, ImportFileMachiningFamilyList) Then Return
      ' li inserisco in lista per finestra di scelta
      Dim MachinigToImportList As New ObservableCollection(Of ImpExpMachiningFamily)
      ' creo famiglie di utensili in base a quelle trovate in lista importata
      For MachiningIndex As Integer = 0 To ImportFileMachiningNameList.Count - 1
         Dim MachiningName As String = ImportFileMachiningNameList(MachiningIndex)
         Dim MachiningFamily As Integer = ImportFileMachiningFamilyList(MachiningIndex)
         MachiningFamily = MachiningFamily And
            (MCH_MY.DRILLING Or
            MCH_MY.SAWING Or
            MCH_MY.MILLING Or
            MCH_MY.POCKETING Or
            MCH_MY.MORTISING Or
            MCH_MY.SAWROUGHING Or
            MCH_MY.SAWFINISHING Or
            MCH_MY.GENMACHINING Or
            MCH_MY.CHISELING Or
            MCH_MY.SURFROUGHING Or
            MCH_MY.SURFFINISHING Or
            MCH_MY.WATERJETTING)
         Dim bFounded As Boolean = False
         Dim MachinigToImportFamily As ImpExpMachiningFamily
         For Each MachinigToImportFamily In MachinigToImportList
            If (MachiningFamily = MachinigToImportFamily.FamilyType) Then
               MachinigToImportFamily.MachiningList.Add(New ImpExpMachiningItem(MachiningName, AlreadyExist(MachiningName)))
               bFounded = True
               Exit For
            End If
         Next
         If Not bFounded Then
            Dim NewFamily As New ImpExpMachiningFamily(GetMachiningFamilyName(MachiningFamily), MachiningFamily)
            NewFamily.MachiningList.Add(New ImpExpMachiningItem(MachiningName, AlreadyExist(MachiningName)))
            MachinigToImportList.Add(NewFamily)
         End If
      Next
      Dim ImportWndVM As New ImportExportMachiningWindowVM(MachinigToImportList, False, ImportFilePath, ImportFileMachiningNameList)
      Dim ImportWnd As New ImportExportMachiningWindowWD(Application.Current.MainWindow, ImportWndVM)

      ImportWnd.ShowDialog()
      ' Aggiungo all'albero visualizzato gli utensili appena importati
      If ImportWnd.OkResult Then
         LoadImportedMachineMachinings(ImportWndVM.vsImported)
      End If
   End Sub

   Private Function AlreadyExist(MachiningName As String) As Boolean
      Dim MachiningFamily As CathegoryItem
      For Each MachiningFamily In MachiningsList
         Dim MachiningItem As CustomItem
         For Each MachiningItem In MachiningFamily.Items
            If MachiningName = MachiningItem.Name Then
               Return True
            End If
         Next
      Next
      Return False
   End Function

   Private Function GetMachiningFamilyName(NewMachinigFamily As Integer) As String
      Dim MachiningFamily As CathegoryItem
      For Each MachiningFamily In MachiningsList
         If NewMachinigFamily = MachiningFamily.nTType Then
            Return MachiningFamily.Name
         End If
      Next
      Return ""
   End Function

   Private Sub LoadImportedMachineMachinings(vsImportedMachinings As String())
      ' Leggo tutte le lavorazioni presenti nella Macchina (quindi anche quelli appena importati). 
      Dim ActiveMachiningsFamilies() As MachiningsType = MyReadMachiningFamilies(m_MainWindow.m_CurrentMachine.sMachIniFile)
      Dim MachiningsFamilyIndex As Integer = 0
      Dim MachiningsFamilyItem As MachiningsType
      For Each MachiningsFamilyItem In ActiveMachiningsFamilies
         Dim FamilyTreeView As New CathegoryItem(MachiningsFamilyItem.Name, MachiningsFamilyItem.Id)
         Dim MachiningFamilyItem = MachiningsList.FirstOrDefault(Function(MachiningFamily) MachiningsFamilyItem.Id = MachiningFamily.nTType)
         If IsNothing(MachiningFamilyItem) Then
            MachiningsList.Insert(MachiningsFamilyIndex, FamilyTreeView)
         End If
         Dim nType As Integer = 0
         Dim MachiningName As String = String.Empty
         Dim MachiningIndex As Integer = 0
         EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
         Dim bFound As Boolean = EgtMdbGetFirstMachining(MachiningsFamilyItem.Id, MachiningName)
         While bFound
            Dim MachiningItem = MachiningsList(MachiningsFamilyIndex).Items.FirstOrDefault(Function(Machining) Machining.Name = MachiningName)
            Dim bInList As Boolean = vsImportedMachinings.Contains(MachiningName)
            If bInList Then
               ' Se una lavorazione è presente nella MachiningsList visualizzata ma nel contempo è nell'array vsImported 
               ' vuol dire che è stata sovrascritta perciò la rimuovo
               MachiningsList(MachiningsFamilyIndex).Items.Remove(MachiningsList(MachiningsFamilyIndex).Items.FirstOrDefault(Function(Machining) Machining.Name = MachiningName))
            End If
            If bInList OrElse IsNothing(MachiningItem) Then
               ' recupero tuuid
               EgtMdbSetCurrMachining(MachiningName)
               Dim sCurrMachTUUID As String = String.Empty
               EgtMdbGetCurrMachiningParam(MCH_MP.TUUID, sCurrMachTUUID)
               ' aggiungo la lavorazione importata
               MachiningsList(MachiningsFamilyIndex).Items.Insert(MachiningIndex, New CustomItem(MachiningName, MachiningsFamilyItem.Id, ToolDbUtility.IsToolInDb(sCurrMachTUUID)))
               ' eventualmente evidezio l'ultimo elemento inserito (ERRORE: non espando l'albero)
               'MachiningsList(MachiningsFamilyIndex).Items(MachiningIndex).IsSelected = True
            End If
            MachiningIndex += 1
            bFound = EgtMdbGetNextMachining(MachiningsFamilyItem.Id, MachiningName)
         End While
         MachiningsFamilyIndex += 1
      Next
   End Sub

   Public Function MyReadMachiningFamilies(sMachineIniPath As String) As MachiningsType()
      Dim ActiveMachiningsFamiliesList As New List(Of MachiningsType)
      ' Se il materiale lavorato è Marmo l'ordine di lettura e inserimento di Foratura e Taglio di lama nelle famiglie di lavorazioni attive è invertito 

      If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_SAWING, 0, sMachineIniPath) <> 0 Then
         ActiveMachiningsFamiliesList.Add(New MachiningsType With {.Id = MCH_MY.SAWING, .Name = EgtMsg(31200 + 2)})
      End If
      If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_DRILLING, 0, sMachineIniPath) <> 0 Then
         ActiveMachiningsFamiliesList.Add(New MachiningsType With {.Id = MCH_MY.DRILLING, .Name = EgtMsg(31200 + 1)})
      End If

      If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_MILLING, 0, sMachineIniPath) <> 0 Then
         ActiveMachiningsFamiliesList.Add(New MachiningsType With {.Id = MCH_MY.MILLING, .Name = EgtMsg(31200 + 3)})
      End If
      If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_POCKETING, 0, sMachineIniPath) <> 0 Then
         ActiveMachiningsFamiliesList.Add(New MachiningsType With {.Id = MCH_MY.POCKETING, .Name = EgtMsg(31200 + 4)})
      End If
      If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_MORTISING, 0, sMachineIniPath) <> 0 Then
         ActiveMachiningsFamiliesList.Add(New MachiningsType With {.Id = MCH_MY.MORTISING, .Name = EgtMsg(31200 + 5)})
      End If
      If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_SAWROUGHING, 0, sMachineIniPath) <> 0 Then
         ActiveMachiningsFamiliesList.Add(New MachiningsType With {.Id = MCH_MY.SAWROUGHING, .Name = EgtMsg(31200 + 6)})
      End If
      If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_SAWFINISHING, 0, sMachineIniPath) <> 0 Then
         ActiveMachiningsFamiliesList.Add(New MachiningsType With {.Id = MCH_MY.SAWFINISHING, .Name = EgtMsg(31200 + 7)})
      End If
      If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_GENMACHINING, 0, sMachineIniPath) <> 0 Then
         ActiveMachiningsFamiliesList.Add(New MachiningsType With {.Id = MCH_MY.GENMACHINING, .Name = EgtMsg(31200 + 8)})
      End If
      If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_CHISELING, 0, sMachineIniPath) <> 0 Then
         ActiveMachiningsFamiliesList.Add(New MachiningsType With {.Id = MCH_MY.CHISELING, .Name = EgtMsg(31200 + 9)})
      End If
      If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_SURFFINISHING, 0, sMachineIniPath) <> 0 Then
         ActiveMachiningsFamiliesList.Add(New MachiningsType With {.Id = MCH_MY.SURFFINISHING, .Name = EgtMsg(31211)})
      End If
      If EgtUILib.GetPrivateProfileInt(S_MACHININGS, K_WATERJETTING, 0, sMachineIniPath) <> 0 Then
         ActiveMachiningsFamiliesList.Add(New MachiningsType With {.Id = MCH_MY.WATERJETTING, .Name = EgtMsg(31210)})
      End If
      Return ActiveMachiningsFamiliesList.ToArray
   End Function

   Private Sub InitializeMachiningFamily(bEnabled As Boolean, nFType As Integer, sFName As String)
      If Not bEnabled Then Return
      ' Inserisco categoria ed eventuali elementi
      Dim MachiningCathegory As New CathegoryItem(sFName, nFType)
      Dim MachiningName As String = String.Empty
      If EgtMdbGetFirstMachining(nFType, MachiningName) Then
         MachiningCathegory.Items.Add(New CustomItem(MachiningName, nFType))
         While EgtMdbGetNextMachining(nFType, MachiningName)
            MachiningCathegory.Items.Add(New CustomItem(MachiningName, nFType))
         End While
      End If
      MachiningsList.Add(MachiningCathegory)
   End Sub

   Private Sub GetMachiningParams()
      EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
      Dim nMachiningType As Integer
      EgtMdbGetCurrMachiningParam(MCH_MP.TYPE, nMachiningType)
      ' Carico liste combobox
      LoadDynamicParamList(nMachiningType)
      Dim ToolString As String = String.Empty
      Dim ToolInt As Integer = 0
      Dim ToolDouble As Double = 0
      Dim ToolBool As Boolean = False
      EgtMdbGetCurrMachiningParam(MCH_MP.NAME, m_sMachiningName)
      NameTxBx.Text = m_sMachiningName
      EgtMdbGetCurrMachiningParam(MCH_MP.DEPTH_STR, ToolString)
      DepthTxBx.Text = ExprToUIExpr(ToolString)
      ' Parametri Taglio
      EgtMdbGetCurrMachiningParam(MCH_MP.SIDEANGLE, ToolDouble)
      SideAngleTxBx.Text = DoubleToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.INVERT, ToolBool)
      InvertChBx.IsChecked = ToolBool
      EgtMdbGetCurrMachiningParam(MCH_MP.STEPTYPE, ToolInt)
      StepTypeCmBx.SelectedIndex = ToolInt
      EgtMdbGetCurrMachiningParam(MCH_MP.WORKSIDE, ToolInt)
      WorkSideCmBx.SelectedIndex = ToolInt
      EgtMdbGetCurrMachiningParam(MCH_MP.HEADSIDE, ToolInt)
      HeadSideCmBx.SelectedIndex = ToolInt - 1
      EgtMdbGetCurrMachiningParam(MCH_MP.LEADINTYPE, ToolInt)
      If LeadInTypeCmBx.Items.Count > 0 Then
         LeadInTypeCmBx.SelectedItem = LeadInTypeCmBx.Items(0)
      Else
         LeadInTypeCmBx.SelectedItem = Nothing
      End If
      For Each LInType As IdNameStruct In LeadInTypeCmBx.Items
         If ToolInt = LInType.Id Then
            LeadInTypeCmBx.SelectedItem = LInType
            Exit For
         End If
      Next
      EgtMdbGetCurrMachiningParam(MCH_MP.EXTLINKTYPE, ToolInt)
      ExtLinkTypeCmBx.SelectedIndex = ToolInt
      EgtMdbGetCurrMachiningParam(MCH_MP.LEADOUTTYPE, ToolInt)
      If LeadOutTypeCmBx.Items.Count > 0 then
         LeadOutTypeCmBx.SelectedItem = LeadOutTypeCmBx.Items(0)
      Else
         LeadOutTypeCmBx.SelectedItem = Nothing
      End If
      For Each LOutType As IdNameStruct In LeadOutTypeCmBx.Items
         If ToolInt = LOutType.Id Then LeadOutTypeCmBx.SelectedItem = LOutType
      Next
      EgtMdbGetCurrMachiningParam(MCH_MP.CURVEUSE, ToolInt)
      CurveUseCmBx.SelectedIndex = ToolInt
      EgtMdbGetCurrMachiningParam(MCH_MP.APPROX, ToolDouble)
      ApproxTxBx.Text = LenToString(ToolDouble, 3)
      ' Parametri Foratura
      EgtMdbGetCurrMachiningParam(MCH_MP.STARTPOS, ToolDouble)
      StartPosTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.STARTSLOWLEN, ToolDouble)
      StartsLowLenTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.ENDSLOWLEN, ToolDouble)
      EndsLowLenTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.THROUADDLEN, ToolDouble)
      ThrouAddLenTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.STEP_, ToolDouble)
      StepTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.STEPBACK, ToolDouble)
      BackwardSawStepTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.STEPLAST, ToolDouble)
      LastSawStepTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.RETURNPOS, ToolDouble)
      ReturnPosTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.STEPSIDEANG, ToolDouble)
      ForwardStepSideAngTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.STEPSIDEANGBACK, ToolDouble)
      BackwardStepSideAngTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.STEPEXTARC, ToolDouble)
      ArcExtTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.STEPINTARC, ToolDouble)
      ArcIntTxBx.Text = LenToString(ToolDouble, 3)
      ' Parametri Sgrossatura/Finitura con lama
      EgtMdbGetCurrMachiningParam(MCH_MP.SUBTYPE, ToolInt)
      AcrossChBx.IsChecked = (ToolInt = MCH_SAWFIN_SUB.ACROSS)
      EgtMdbGetCurrMachiningParam(MCH_MP.LEADLINKTYPE, ToolInt)
      LeadLinkTypeCmBx.SelectedIndex = ToolInt
      EgtMdbGetCurrMachiningParam(MCH_MP.SIDESTEP, ToolDouble)
      SideStepTxBx.Text = LenToString(ToolDouble, 3)
      ' Parametri WaterJetting
      EgtMdbGetCurrMachiningParam(MCH_MP.FORWARDANGLE, ToolDouble)
      ForwardAngleTxBx.Text = DoubleToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.PROBING, ToolBool)
      ProbingChBx.IsChecked = ToolBool
      ProbingMinDistTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.PROBINGMINDIST, ToolDouble)
      ProbingMinDistTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.PROBINGMAXDIST, ToolDouble)
      ProbingMaxDistTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.EXTCORNERTYPE, ToolInt)
      ExtCornTypeCmBx.SelectedIndex = ToolInt
      EgtMdbGetCurrMachiningParam(MCH_MP.INTCORNERTYPE, ToolInt)
      IntCornTypeCmBx.SelectedIndex = ToolInt
      EgtMdbGetCurrMachiningParam(MCH_MP.CORNERSLOWLEN, ToolDouble)
      CornSlowLenTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.CORNERSLOWPERC, ToolInt)
      CornSlowPercTxBx.Text = ToolInt
      EgtMdbGetCurrMachiningParam(MCH_MP.LIHOLE, ToolBool)
      LiHoleChBx.IsChecked = ToolBool
      EgtMdbGetCurrMachiningParam(MCH_MP.LIHOLERAD, ToolDouble)
      LiHoleRadTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.LPTURNS, ToolInt)
      LpTurnsTxBx.Text = ToolInt
      EgtMdbGetCurrMachiningParam(MCH_MP.HPTURNS, ToolInt)
      HpTurnsTxBx.Text = ToolInt
      EgtMdbGetCurrMachiningParam(MCH_MP.LITANG, ToolDouble)
      LiTangTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.LIPERP, ToolDouble)
      LiPerpTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.LOTANG, ToolDouble)
      LoTangTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.LOPERP, ToolDouble)
      LoPerpTxBx.Text = LenToString(ToolDouble, 3)
      ' Parametri utensile
      Select Case nMachiningType
         Case MCH_MY.SAWING        'Taglio
            ToolCmBx.ItemsSource = SawTool
         Case MCH_MY.MILLING       'Fresatura
            ToolCmBx.ItemsSource = MillTool
         Case MCH_MY.POCKETING     'Svuotatura
            ToolCmBx.ItemsSource = PocketTool
         Case MCH_MY.DRILLING      'Foratura
            ToolCmBx.ItemsSource = DrillTool
         Case MCH_MY.SAWROUGHING   'Sgrossatura con lama
            ToolCmBx.ItemsSource = SawTool
         Case MCH_MY.SAWFINISHING  'Finitura con lama
            ToolCmBx.ItemsSource = SawTool
         Case MCH_MY.WATERJETTING  'WaterJetting
            ToolCmBx.ItemsSource = WaterJetTool
      End Select
      ' Recupero nome utensile tramite TUUID
      Dim sTuuid As String = String.Empty
      EgtMdbGetCurrMachiningParam(MCH_MP.TUUID, sTuuid)
      EgtTdbGetToolFromUUID(sTuuid, ToolString)
      Dim bToolExist As Boolean = False
      For Each CurrTool As IEnumerable In ToolCmBx.ItemsSource
         If CurrTool.ToString() = ToolString Then
            bToolExist = True
            Exit For
         End If
      Next
      If bToolExist Then
         ToolCmBx.SelectedItem = ToolString
      Else
         ToolCmBx.SelectedItem = Nothing
      End If
      ' Speed e Feed
      EgtMdbGetCurrMachiningParam(MCH_MP.SPEED, ToolDouble)
      SpeedTxBx.Text = DoubleToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.FEED, ToolDouble)
      FeedTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.STARTFEED, ToolDouble)
      StartFeedTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.ENDFEED, ToolDouble)
      EndFeedTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.TIPFEED, ToolDouble)
      TipFeedTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.VERTFEED, ToolDouble)
      VertFeedTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.BACKFEED, ToolDouble)
      BackFeedTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.THICKREF, ToolDouble)
      ThicknessFeedTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.SIDEANGFEED, ToolDouble)
      SideAngCutTxBx.Text = LenToString(ToolDouble, 3)
      ' Attacco specifico
      EgtMdbGetCurrMachiningParam( MCH_MP.LITANG, ToolDouble)
      SpecificLenTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam( MCH_MP.LIELEV, ToolDouble)
      SpecificStepTxBx.Text = LenToString(ToolDouble, 3)
      ' Sovramateriale
      EgtMdbGetCurrMachiningParam(MCH_MP.OFFSL, ToolDouble)
      LonOffsetTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.OFFSR, ToolDouble)
      RadOffsetTxBx.Text = LenToString(ToolDouble, 3)
      ' Lista materiali
      m_MaterialsList.Clear()
      For Each Material As Material In m_MainWindow.m_CurrentMachine.Materials
         If m_MainWindow.m_CurrentMachine.bWaterJet And m_MainWindow.m_CurrentMachine.bFromDBWaterJet Then
            m_MaterialsList.Add(New MachiningMaterial(Material.nId, Material.sName, Material.SubId))
         Else
            m_MaterialsList.Add(New MachiningMaterial(Material.nId, Material.sName))
         End If
      Next
      EgtMdbGetCurrMachiningParam(MCH_MP.SYSNOTES, ToolString)
      If ToolString <> String.Empty Then
         Dim sItems() = ToolString.Split(";".ToCharArray)
         Dim Index As Integer = 0
         For Each Material As MachiningMaterial In m_MaterialsList
            Dim Param() As String = sItems(Index).Split(",".ToCharArray)
            Dim SubParam() As String = Param(0).Split(".".ToCharArray)
            Dim nParId As Integer = 0
            Dim nSubParId As Integer = 0
            If m_MainWindow.m_CurrentMachine.bWaterJet And m_MainWindow.m_CurrentMachine.bFromDBWaterJet Then
               If StringToInt(SubParam(0), nParId) AndAlso nParId = Material.nId AndAlso SubParam.Count > 1 AndAlso
                  StringToInt(SubParam(1), nSubParId) AndAlso nSubParId = Material.nSubId Then

                  StringToDouble(Param(1), Material.dMinThickness)
                  StringToDouble(Param(2), Material.dMaxThickness)
                  Material.VerifyIfActive()
                  Index += 1
               Else
                  Material.VerifyIfActive()
               End If
            Else
               If StringToInt(Param(0), nParId) AndAlso nParId = Material.nId Then

                  StringToDouble(Param(1), Material.dMinThickness)
                  StringToDouble(Param(2), Material.dMaxThickness)
                  Material.VerifyIfActive()
                  Index += 1
               Else
                  Material.VerifyIfActive()
               End If
            End If
         Next
      End If
      If MaterialsList.Items.Count > 0 Then
         MaterialsList.SelectedItem = m_MaterialsList(0)
      End If
   End Sub

   Friend Sub SetMachiningParams()
      EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
      Dim nMachiningType As Integer
      EgtMdbGetCurrMachiningParam(MCH_MP.TYPE, nMachiningType)
      Dim bTemp As Boolean
      Dim nTemp As Integer
      Dim dTemp As Double
      EgtMdbSetCurrMachiningParam(MCH_MP.NAME, NameTxBx.Text)
      EgtMdbSetCurrMachiningParam(MCH_MP.DEPTH_STR, UIExprToExpr(DepthTxBx.Text))
      ' Parametri Taglio
      StringToDouble(SideAngleTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.SIDEANGLE, dTemp)
      bTemp = If(InvertChBx.IsChecked(), True, False)
      EgtMdbSetCurrMachiningParam(MCH_MP.INVERT, bTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.STEPTYPE, StepTypeCmBx.SelectedIndex)
      EgtMdbSetCurrMachiningParam(MCH_MP.WORKSIDE, WorkSideCmBx.SelectedIndex)
      EgtMdbSetCurrMachiningParam(MCH_MP.HEADSIDE, HeadSideCmBx.SelectedIndex + 1)
      If nMachiningType = MCH_MY.SAWING Or
         nMachiningType = MCH_MY.MILLING Or
         nMachiningType = MCH_MY.POCKETING Or
         nMachiningType = MCH_MY.WATERJETTING Then
         EgtMdbSetCurrMachiningParam(MCH_MP.LEADINTYPE, DirectCast(LeadInTypeCmBx.SelectedItem, IdNameStruct).Id)
         EgtMdbSetCurrMachiningParam(MCH_MP.LEADOUTTYPE, DirectCast(LeadOutTypeCmBx.SelectedItem, IdNameStruct).Id)
      End If
      EgtMdbSetCurrMachiningParam(MCH_MP.EXTLINKTYPE, ExtLinkTypeCmBx.SelectedIndex)
      EgtMdbSetCurrMachiningParam(MCH_MP.CURVEUSE, If(CurveUseCmBx.IsVisible, CurveUseCmBx.SelectedIndex, MCH_SAW_CU.KEEP))
      StringToLen(ApproxTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.APPROX, dTemp)
      StringToLen(ForwardStepSideAngTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.STEPSIDEANG, dTemp)
      StringToLen(BackwardStepSideAngTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.STEPSIDEANGBACK, dTemp)
      StringToLen(ArcExtTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.STEPEXTARC, dTemp)
      StringToLen(ArcIntTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.STEPINTARC, dTemp)
      StringToLen(LastSawStepTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.STEPLAST, dTemp)
      If nMachiningType = MCH_MY.SAWING Then
         StringToLen(SpecificLenTxBx.Text, dTemp)
         EgtMdbSetCurrMachiningParam( MCH_MP.LITANG, dTemp)
         StringToLen(SpecificStepTxBx.Text, dTemp)
         EgtMdbSetCurrMachiningParam( MCH_MP.LIELEV, dTemp)
      End If
      ' Parametri Foratura
      StringToLen(StartPosTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.STARTPOS, dTemp)
      StringToLen(StartsLowLenTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.STARTSLOWLEN, dTemp)
      StringToLen(EndsLowLenTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.ENDSLOWLEN, dTemp)
      StringToLen(ThrouAddLenTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.THROUADDLEN, dTemp)
      StringToLen(StepTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.STEP_, dTemp)
      StringToLen(BackwardSawStepTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.STEPBACK, dTemp)
      StringToLen(ReturnPosTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.RETURNPOS, dTemp)
      ' Parametri Sgrossatura/Finitura con lama
      EgtMdbSetCurrMachiningParam(MCH_MP.LEADLINKTYPE, LeadLinkTypeCmBx.SelectedIndex)
      StringToLen(SideStepTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.SIDESTEP, dTemp)
      If nMachiningType = MCH_MY.SAWFINISHING Then
         nTemp = If(AcrossChBx.IsChecked(), MCH_SAWFIN_SUB.ACROSS, MCH_SAWFIN_SUB.ALONG)
         EgtMdbSetCurrMachiningParam(MCH_MP.SUBTYPE, nTemp)
      End If
      ' Parmetri nascosti di svuotatura
      If nMachiningType = MCH_MY.POCKETING Then
         EgtMdbSetCurrMachiningParam(MCH_MP.SUBTYPE, MCH_POCK_SUB.SPIRALOUT)
         ' EgtMdbSetCurrMachiningParam( MCH_MP.LEADINTYPE, MCH_POCK_LI.HELIX)
         Dim dToolDiam As Double = 100
         If Not IsNothing(ToolCmBx.SelectedItem) Then
            EgtTdbSetCurrTool( ToolCmBx.SelectedItem.ToString())
            EgtTdbGetCurrToolParam( MCH_TP.DIAM, dToolDiam)
         End If
         EgtMdbSetCurrMachiningParam(MCH_MP.LITANG, 0.99 * dToolDiam)
         EgtMdbSetCurrMachiningParam( MCH_MP.LIELEV, 2.0)
      End If
      ' Parametri WaterJetting
      StringToDouble(ForwardAngleTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.FORWARDANGLE, dTemp)
      bTemp = If(ProbingChBx.IsChecked(), True, False)
      EgtMdbSetCurrMachiningParam(MCH_MP.PROBING, bTemp)
      StringToLen(ProbingMinDistTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.PROBINGMINDIST, dTemp)
      StringToLen(ProbingMaxDistTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.PROBINGMAXDIST, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.EXTCORNERTYPE, ExtCornTypeCmBx.SelectedIndex)
      EgtMdbSetCurrMachiningParam(MCH_MP.INTCORNERTYPE, IntCornTypeCmBx.SelectedIndex)
      StringToLen(CornSlowLenTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.CORNERSLOWLEN, dTemp)
      StringToInt(CornSlowPercTxBx.Text, nTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.CORNERSLOWPERC, nTemp)
      bTemp = If(LiHoleChBx.IsChecked(), True, False)
      EgtMdbSetCurrMachiningParam(MCH_MP.LIHOLE, bTemp)
      StringToLen(LiHoleRadTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.LIHOLERAD, dTemp)
      StringToInt(LpTurnsTxBx.Text, nTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.LPTURNS, nTemp)
      StringToInt(HpTurnsTxBx.Text, nTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.HPTURNS, nTemp)
      If nMachiningType = MCH_MY.WATERJETTING Then
         StringToLen(LiTangTxBx.Text, dTemp)
         EgtMdbSetCurrMachiningParam(MCH_MP.LITANG, dTemp)
      End If
      StringToLen(LiPerpTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.LIPERP, dTemp)
      StringToLen(LoTangTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.LOTANG, dTemp)
      StringToLen(LoPerpTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.LOPERP, dTemp)
      ' Parametri utensile
      If Not IsNothing(ToolCmBx.SelectedItem) Then
         EgtMdbSetCurrMachiningParam(MCH_MP.TOOL, ToolCmBx.SelectedItem.ToString)
      Else
         EgtMdbSetCurrMachiningParam(MCH_MP.TOOL, String.Empty)
      End If
      ' Speed e Feed
      StringToDouble(SpeedTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.SPEED, dTemp)
      StringToLen(FeedTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.FEED, dTemp)
      StringToLen(StartFeedTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.STARTFEED, dTemp)
      StringToLen(EndFeedTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.ENDFEED, dTemp)
      StringToLen(TipFeedTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.TIPFEED, dTemp)
      StringToLen(VertFeedTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.VERTFEED, dTemp)
      StringToLen(BackFeedTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.BACKFEED, dTemp)
      StringToLen(ThicknessFeedTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.THICKREF, dTemp)
      StringToLen(SideAngCutTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.SIDEANGFEED, dTemp)
      ' Sovramateriale
      StringToLen(LonOffsetTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.OFFSL, dTemp)
      StringToLen(RadOffsetTxBx.Text, dTemp)
      EgtMdbSetCurrMachiningParam(MCH_MP.OFFSR, dTemp)
      ' Scrivo stringa materiali da lista
      Dim sMaterialString As String = String.Empty
      For Each Material As MachiningMaterial In m_MaterialsList
         If m_MainWindow.m_CurrentMachine.bWaterJet And m_MainWindow.m_CurrentMachine.bFromDBWaterJet Then
            If Material.bIsActive Then
               sMaterialString += Material.nId.ToString & "." & Material.nSubId.ToString & "," & DoubleToString(Material.dMinThickness, 0) & "," & DoubleToString(Material.dMaxThickness, 0) & ";"
            End If
         Else
            If Material.bIsActive Then
               sMaterialString += Material.nId.ToString & "," & DoubleToString(Material.dMinThickness, 0) & "," & DoubleToString(Material.dMaxThickness, 0) & ";"
            End If
         End If
      Next
      EgtMdbSetCurrMachiningParam(MCH_MP.SYSNOTES, sMaterialString)
   End Sub

   Private Sub ViewMachiningParams()
      Dim nMachiningType As Integer
      EgtMdbGetCurrMachiningParam(MCH_MP.TYPE, nMachiningType)
      NameTxBl.Visibility = Windows.Visibility.Visible
      NameTxBx.Visibility = Windows.Visibility.Visible
      DepthTxBl.Visibility = Windows.Visibility.Visible
      DepthTxBx.Visibility = Windows.Visibility.Visible
      MaterialsBrd.Visibility = Windows.Visibility.Visible
      SpeedGrd.Visibility = Windows.Visibility.Visible
      FeedGpBx.Visibility = Windows.Visibility.Visible
      LonOffsetTxBl.Visibility = Windows.Visibility.Visible
      LonOffsetTxBx.Visibility = Windows.Visibility.Visible
      Select Case nMachiningType
         Case MCH_MY.SAWING   'Parametri Taglio
            ' nascondo il parametro di sbandamento 
            SideAngleTxBl.Visibility = Windows.Visibility.Hidden
            SideAngleTxBx.Visibility = Windows.Visibility.Hidden
            InvertTxBl.Visibility = Windows.Visibility.Visible
            InvertChBx.Visibility = Windows.Visibility.Visible
            AcrossTxBl.Visibility = Windows.Visibility.Hidden
            AcrossChBx.Visibility = Windows.Visibility.Hidden
            StepTypeTxBl.Visibility = Windows.Visibility.Visible
            StepTypeCmBx.Visibility = Windows.Visibility.Visible
            StepTypeCmBx.ItemsSource = StepType
            SideBrd.SetValue(Grid.RowProperty, 9)
            SideBrd.Visibility = Windows.Visibility.Visible
            WorkSideTxBl.Visibility = Windows.Visibility.Visible
            WorkSideCmBx.Visibility = Windows.Visibility.Visible
            HeadSideTxBl.Visibility = Windows.Visibility.Visible
            HeadSideCmBx.Visibility = Windows.Visibility.Visible
            TypeBrd.Visibility = Windows.Visibility.Visible
            ' Definizione della grid TypeGrd con la giusta altezza e numero di righe
            Dim RowNum As Integer = TypeGrd.RowDefinitions.Count
            If RowNum > 1 Then
               For Index As Integer = RowNum - 1 To 1 Step -1
                  TypeGrd.RowDefinitions.RemoveAt(Index)
               Next
               LeadInTypeTxBl.SetValue(Grid.ColumnProperty, 0)
               LeadInTypeCmBx.SetValue(Grid.ColumnProperty, 1)

               LeadOutTypeTxBl.SetValue(Grid.RowProperty, 0)
               LeadOutTypeTxBl.SetValue(Grid.ColumnProperty, 2)
               LeadOutTypeCmBx.SetValue(Grid.RowProperty, 0)
               LeadOutTypeCmBx.SetValue(Grid.ColumnProperty, 3)
               TypeBrd.SetValue(Grid.RowProperty, 12)
               TypeBrd.SetValue(Grid.RowSpanProperty, 3)
            End If

            LeadInTypeTxBl.Visibility = Windows.Visibility.Visible
            LeadInTypeCmBx.Visibility = Windows.Visibility.Visible

            LeadOutTypeTxBl.Visibility = Windows.Visibility.Visible
            LeadOutTypeCmBx.Visibility = Windows.Visibility.Visible

            ExtLinkTypeTxBl.Visibility = Windows.Visibility.Hidden
            ExtLinkTypeCmBx.Visibility = Windows.Visibility.Hidden
            LeadLinkTypeTxBl.Visibility = Windows.Visibility.Hidden
            LeadLinkTypeCmBx.Visibility = Windows.Visibility.Hidden

            CurveBrd.Visibility = Windows.Visibility.Visible

            'If Not MachParamGrd.Children.Contains(StartPosTxBl) Then
            If TypeGrd.Children.Contains(StartPosTxBl) Then
               'MachParamGrd.Children.Remove(StartPosTxBl)
               'MachParamGrd.Children.Remove(StartPosTxBx)
               'TypeGrd.Children.Add(StartPosTxBl)
               'TypeGrd.Children.Add(StartPosTxBx
               TypeGrd.Children.Remove(StartPosTxBl)
               TypeGrd.Children.Remove(StartPosTxBx)
               MachParamGrd.Children.Add(StartPosTxBl)
               MachParamGrd.Children.Add(StartPosTxBx)
               StartPosTxBl.SetValue(Grid.ColumnProperty, 2)
               StartPosTxBl.SetValue(Grid.RowProperty, 3)
               StartPosTxBx.SetValue(Grid.ColumnProperty, 3)
               StartPosTxBx.SetValue(Grid.RowProperty, 3)
               StartPosTxBl.SetValue(Grid.RowSpanProperty, 3)
               StartPosTxBx.SetValue(Grid.RowSpanProperty, 3)
               StartPosTxBx.Style = Application.Current.FindResource("OmagCut_MachLeftCalculatorTextBoxInBorder")
            ElseIf MachParamGrd.Children.Contains(StartPosTxBl) Then
               StartPosTxBl.SetValue(Grid.ColumnProperty, 2)
               StartPosTxBl.SetValue(Grid.RowProperty, 3)
               StartPosTxBx.SetValue(Grid.ColumnProperty, 3)
               StartPosTxBx.SetValue(Grid.RowProperty, 3)
               StartPosTxBl.SetValue(Grid.RowSpanProperty, 3)
               StartPosTxBx.SetValue(Grid.RowSpanProperty, 3)
            End If
            StartPosTxBl.Visibility = Windows.Visibility.Visible
            StartPosTxBx.Visibility = Windows.Visibility.Visible
            LowLenGpBx.Visibility = Windows.Visibility.Hidden
            ThrouAddLenTxBl.Visibility = Windows.Visibility.Hidden
            ThrouAddLenTxBx.Visibility = Windows.Visibility.Hidden
            If DrillStepGrd.Children.Contains(StepTxBx) Then
               DrillStepGrd.Children.Remove(StepTxBx)
               SawStepGrd.Children.Add(StepTxBx)
               StepTxBx.SetValue(Grid.ColumnProperty, 1)
               StepTxBx.SetValue(Grid.RowProperty, 0)
               StepTxBx.Style = Application.Current.FindResource("OmagCut_CalculatorTextBoxInGroupBox")
            ElseIf SawRouStepGrd.Children.Contains(StepTxBx) Then
               SawRouStepGrd.Children.Remove(StepTxBx)
               SawStepGrd.Children.Add(StepTxBx)
               StepTxBx.SetValue(Grid.ColumnProperty, 1)
               StepTxBx.SetValue(Grid.RowProperty, 0)
               StepTxBx.Style = Application.Current.FindResource("OmagCut_CalculatorTextBoxInGroupBox")
            End If
            DrillStepBrd.Visibility = Windows.Visibility.Hidden
            SawRouStepGpBx.Visibility = Windows.Visibility.Hidden
            SawStepGpBx.Visibility = Windows.Visibility.Visible
            SawStepGpBx.SetValue(Grid.RowProperty, 18)
            SawStepGpBx.SetValue(Grid.RowSpanProperty, 11)
            ForwardSawStepTxBl.Visibility = Windows.Visibility.Visible
            StepTxBx.Visibility = Windows.Visibility.Visible
            BackwardSawStepTxBl.Visibility = Windows.Visibility.Visible
            BackwardSawStepTxBx.Visibility = Windows.Visibility.Visible
            ForwardStepSideAngTxBl.Visibility = Windows.Visibility.Visible
            ForwardStepSideAngTxBx.Visibility = Windows.Visibility.Visible
            BackwardStepSideAngTxBl.Visibility = Windows.Visibility.Visible
            BackwardStepSideAngTxBx.Visibility = Windows.Visibility.Visible
            ForwardSawStepTxBl.Text = EgtMsg(MSG_OMAGCUT + 864)
            If Not SawStepGrd.Children.Contains(ArcIntTxBl) Then
               Dim Row As New RowDefinition
               Row.Height = New GridLength(1, GridUnitType.Star)
               SawStepGrd.RowDefinitions.Add(Row)
               SawStepGrd.Children.Add(ArcIntTxBl)
               SawStepGrd.Children.Add(ArcIntTxBx)
               SawStepGrd.Children.Add(ArcExtTxBl)
               SawStepGrd.Children.Add(ArcExtTxBx)
            End If
            If Not SawStepGrd.Children.Contains(LastSawStepTxBl) Then
               Dim Row As New RowDefinition
               Row.Height = New GridLength(1, GridUnitType.Star)
               SawStepGrd.RowDefinitions.Add(Row)
               SawStepGrd.Children.Add(LastSawStepTxBl)
               SawStepGrd.Children.Add(LastSawStepTxBx)
            End If
            ReturnPosTxBl.Visibility = Windows.Visibility.Hidden
            ReturnPosTxBx.Visibility = Windows.Visibility.Hidden
            OffsetGpBx.Visibility = Windows.Visibility.Hidden
            ' Definizione di una riga della tabella con la giusta altezza
            RowNum = FeedGrd.RowDefinitions.Count
            If RowNum > 4 Then
               For Index As Integer = RowNum - 1 To 4 Step -1
                  FeedGrd.RowDefinitions.RemoveAt(Index)
               Next
            End If
            FeedGpBx.SetValue(Grid.RowSpanProperty, 12)
            FeedGpBx.SetValue(Grid.RowProperty, 6)
            ' Definizione di una riga della tabella Feed
            RowNum = FeedGrd.RowDefinitions.Count
            If RowNum < 6 Then
               For Index As Integer = RowNum To 5
                  Dim Row As New RowDefinition
                  Row.Height = New GridLength(1, GridUnitType.Star)
                  FeedGrd.RowDefinitions.Add(Row)
               Next
               FeedGpBx.SetValue(Grid.RowSpanProperty, 16)
               BackFeedTxBl.SetValue(Grid.RowProperty, 4)
               BackFeedTxBx.SetValue(Grid.ColumnProperty, 1)
               BackFeedTxBx.SetValue(Grid.RowProperty, 4)
               SideAngCutTxBl.SetValue(Grid.RowProperty, 5)
               SideAngCutTxBx.SetValue(Grid.ColumnProperty, 1)
               SideAngCutTxBx.SetValue(Grid.RowProperty, 5)
            End If
            OffsetGpBx.SetValue(Grid.RowProperty, 12)
            TipFeedTxBl.Text = EgtMsg(MSG_TOOLSDBPAGEUC + 10)
            StartFeedTxBl.Visibility = Windows.Visibility.Visible
            StartFeedTxBx.Visibility = Windows.Visibility.Visible
            EndFeedTxBl.Visibility = Windows.Visibility.Visible
            EndFeedTxBx.Visibility = Windows.Visibility.Visible
            VertFeedTxBl.Visibility = Windows.Visibility.Hidden
            VertFeedTxBx.Visibility = Windows.Visibility.Hidden
            BackFeedTxBl.Visibility = Windows.Visibility.Visible
            BackFeedTxBx.Visibility = Windows.Visibility.Visible
            ThicknessFeedTxBl.Visibility = Windows.Visibility.Hidden
            ThicknessFeedTxBx.Visibility = Windows.Visibility.Hidden
            SideAngCutTxBl.Visibility = Windows.Visibility.Visible
            SideAngCutTxBx.Visibility = Windows.Visibility.Visible
            ForwardAngleTxBl.Visibility = Windows.Visibility.Hidden
            ForwardAngleTxBx.Visibility = Windows.Visibility.Hidden
            CornerGpBx.Visibility = Windows.Visibility.Hidden
            ProbingGpBx.Visibility = Windows.Visibility.Hidden
            ProbingTxBl.Visibility = Windows.Visibility.Hidden
            ProbingChBx.Visibility = Windows.Visibility.Hidden
            ProbingMinDistTxBl.Visibility = Windows.Visibility.Hidden
            ProbingMinDistTxBx.Visibility = Windows.Visibility.Hidden
            ProbingMaxDistTxBl.Visibility = Windows.Visibility.Hidden
            ProbingMaxDistTxBx.Visibility = Windows.Visibility.Hidden
            ExtCornTypeTxBl.Visibility = Windows.Visibility.Hidden
            ExtCornTypeCmBx.Visibility = Windows.Visibility.Hidden
            IntCornTypeTxBl.Visibility = Windows.Visibility.Hidden
            IntCornTypeCmBx.Visibility = Windows.Visibility.Hidden
            CornSlowLenTxBl.Visibility = Windows.Visibility.Hidden
            CornSlowLenTxBx.Visibility = Windows.Visibility.Hidden
            CornSlowPercTxBl.Visibility = Windows.Visibility.Hidden
            CornSlowPercTxBx.Visibility = Windows.Visibility.Hidden
            LiHoleBrd.Visibility = Windows.Visibility.Hidden
            LiHoleTxBl.Visibility = Windows.Visibility.Hidden
            LiHoleChBx.Visibility = Windows.Visibility.Hidden
            LiHoleRadTxBl.Visibility = Windows.Visibility.Hidden
            LiHoleRadTxBx.Visibility = Windows.Visibility.Hidden
            LpTurnsTxBl.Visibility = Windows.Visibility.Hidden
            LpTurnsTxBx.Visibility = Windows.Visibility.Hidden
            HpTurnsTxBl.Visibility = Windows.Visibility.Hidden
            HpTurnsTxBx.Visibility = Windows.Visibility.Hidden
            LiTangTxBl.Visibility = Windows.Visibility.Hidden
            LiTangTxBx.Visibility = Windows.Visibility.Hidden
            LiPerpTxBl.Visibility = Windows.Visibility.Hidden
            LiPerpTxBx.Visibility = Windows.Visibility.Hidden
            LoTangTxBl.Visibility = Windows.Visibility.Hidden
            LoTangTxBx.Visibility = Windows.Visibility.Hidden
            LoPerpTxBl.Visibility = Windows.Visibility.Hidden
            LoPerpTxBx.Visibility = Windows.Visibility.Hidden
            SpecificLeadInGpBx.Visibility = If( m_MainWindow.m_CurrentMachine.bSawingSpecialLeadIn, Windows.Visibility.Visible, Windows.Visibility.Hidden)
         Case MCH_MY.MILLING 'Parametri Fresatura
            SideAngleTxBl.Visibility = Windows.Visibility.Hidden
            SideAngleTxBx.Visibility = Windows.Visibility.Hidden
            InvertTxBl.Visibility = Windows.Visibility.Hidden
            InvertChBx.Visibility = Windows.Visibility.Hidden
            AcrossTxBl.Visibility = Windows.Visibility.Hidden
            AcrossChBx.Visibility = Windows.Visibility.Hidden
            StepTypeTxBl.Visibility = Windows.Visibility.Hidden
            StepTypeCmBx.Visibility = Windows.Visibility.Hidden
            SideBrd.SetValue(Grid.RowProperty, 9)
            SideBrd.Visibility = Windows.Visibility.Visible
            WorkSideTxBl.Visibility = Windows.Visibility.Visible
            WorkSideCmBx.Visibility = Windows.Visibility.Visible
            HeadSideTxBl.Visibility = Windows.Visibility.Hidden
            HeadSideCmBx.Visibility = Windows.Visibility.Hidden
            TypeBrd.Visibility = Windows.Visibility.Visible
            ' Definizione della grid TypeGrd con la giusta altezza e numero di righe
            Dim RowNum As Integer = TypeGrd.RowDefinitions.Count
            If RowNum > 2 Then
               ' elimino eventuali righe in eccesso
               For Index As Integer = RowNum - 1 To 2 Step -1
                  TypeGrd.RowDefinitions.RemoveAt(Index)
               Next
            ElseIf RowNum < 2 Then
               ' costruiso una riga in più da inserire
               Dim Row As New RowDefinition
               TypeGrd.RowDefinitions.Add(Row)
            End If
            LeadInTypeTxBl.SetValue(Grid.RowProperty, 1)
            LeadInTypeTxBl.SetValue(Grid.ColumnProperty, 0)
            LeadInTypeCmBx.SetValue(Grid.RowProperty, 1)
            LeadInTypeCmBx.SetValue(Grid.ColumnProperty, 1)
            LeadOutTypeTxBl.SetValue(Grid.RowProperty, 1)
            LeadOutTypeTxBl.SetValue(Grid.ColumnProperty, 2)
            LeadOutTypeCmBx.SetValue(Grid.RowProperty, 1)
            LeadOutTypeCmBx.SetValue(Grid.ColumnProperty, 3)
            TypeBrd.SetValue(Grid.RowProperty, 12)
            TypeBrd.SetValue(Grid.RowSpanProperty, 6)

            LeadInTypeTxBl.Visibility = Windows.Visibility.Visible
            LeadInTypeCmBx.Visibility = Windows.Visibility.Visible
            ExtLinkTypeTxBl.Visibility = Windows.Visibility.Hidden
            ExtLinkTypeCmBx.Visibility = Windows.Visibility.Hidden
            LeadOutTypeTxBl.Visibility = Windows.Visibility.Visible
            LeadOutTypeCmBx.Visibility = Windows.Visibility.Visible
            LeadLinkTypeTxBl.Visibility = Windows.Visibility.Hidden
            LeadLinkTypeCmBx.Visibility = Windows.Visibility.Hidden
            CurveBrd.Visibility = Windows.Visibility.Hidden
            If MachParamGrd.Children.Contains(StartPosTxBl) Then
               MachParamGrd.Children.Remove(StartPosTxBl)
               MachParamGrd.Children.Remove(StartPosTxBx)
               TypeGrd.Children.Add(StartPosTxBl)
               TypeGrd.Children.Add(StartPosTxBx)
               StartPosTxBl.SetValue(Grid.ColumnProperty, 0)
               StartPosTxBl.SetValue(Grid.RowProperty, 0)
               StartPosTxBx.SetValue(Grid.ColumnProperty, 1)
               StartPosTxBx.SetValue(Grid.RowProperty, 0)
               StartPosTxBl.SetValue(Grid.RowSpanProperty, 1)
               StartPosTxBx.SetValue(Grid.RowSpanProperty, 1)
               'StartPosTxBx.Style = Application.Current.FindResource("OmagCut_LeftCalculatorTextBoxInBorder")
            End If
            StartPosTxBl.Visibility = Windows.Visibility.Visible
            StartPosTxBx.Visibility = Windows.Visibility.Visible
            LowLenGpBx.Visibility = Windows.Visibility.Hidden
            ThrouAddLenTxBl.Visibility = Windows.Visibility.Hidden
            ThrouAddLenTxBx.Visibility = Windows.Visibility.Hidden
            If DrillStepGrd.Children.Contains(StepTxBx) Then
               DrillStepGrd.Children.Remove(StepTxBx)
               SawStepGrd.Children.Add(StepTxBx)
               StepTxBx.SetValue(Grid.ColumnProperty, 1)
               StepTxBx.SetValue(Grid.RowProperty, 0)
               'StepTxBx.Style = Application.Current.FindResource("OmagCut_CalculatorTextBoxInBorder")
            ElseIf SawRouStepGrd.Children.Contains(StepTxBx) Then
               SawRouStepGrd.Children.Remove(StepTxBx)
               SawStepGrd.Children.Add(StepTxBx)
               StepTxBx.SetValue(Grid.ColumnProperty, 1)
               StepTxBx.SetValue(Grid.RowProperty, 0)
               'StepTxBx.Style = Application.Current.FindResource("OmagCut_CalculatorTextBoxInBorder")
            End If
            StepTxBx.Visibility = Windows.Visibility.Visible
            SawStepGpBx.Visibility = Windows.Visibility.Visible
            SawStepGpBx.SetValue(Grid.RowProperty, 21)
            SawStepGpBx.SetValue(Grid.RowSpanProperty, 6)
            BackwardSawStepTxBl.Visibility = Windows.Visibility.Hidden
            BackwardSawStepTxBx.Visibility = Windows.Visibility.Hidden
            ForwardStepSideAngTxBl.Visibility = Windows.Visibility.Hidden
            ForwardStepSideAngTxBx.Visibility = Windows.Visibility.Hidden
            BackwardStepSideAngTxBl.Visibility = Windows.Visibility.Hidden
            BackwardStepSideAngTxBx.Visibility = Windows.Visibility.Hidden
            ForwardSawStepTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 15)
            If SawStepGrd.Children.Contains(ArcIntTxBl) Then
               SawStepGrd.Children.Remove(ArcIntTxBl)
               SawStepGrd.Children.Remove(ArcIntTxBx)
               SawStepGrd.Children.Remove(ArcExtTxBl)
               SawStepGrd.Children.Remove(ArcExtTxBx)
               SawStepGrd.RowDefinitions.RemoveAt(2)
            End If
            If SawStepGrd.Children.Contains(LastSawStepTxBl) Then
               SawStepGrd.Children.Remove(LastSawStepTxBl)
               SawStepGrd.Children.Remove(LastSawStepTxBx)
               SawStepGrd.RowDefinitions.RemoveAt(2)
            End If
            DrillStepBrd.Visibility = Windows.Visibility.Hidden
            SawRouStepGpBx.Visibility = Windows.Visibility.Hidden
            ReturnPosTxBl.Visibility = Windows.Visibility.Hidden
            ReturnPosTxBx.Visibility = Windows.Visibility.Hidden
            OffsetGpBx.Visibility = Windows.Visibility.Hidden
            ' Definizione di una riga della tabella con la giusta altezza
            RowNum = FeedGrd.RowDefinitions.Count
            If RowNum > 4 Then
               For Index As Integer = RowNum - 1 To 4 Step -1
                  FeedGrd.RowDefinitions.RemoveAt(Index)
               Next
            End If
            FeedGpBx.SetValue(Grid.RowSpanProperty, 12)
            FeedGpBx.SetValue(Grid.RowProperty, 6)
            ' Definizione di una riga della tabella Feed
            RowNum = FeedGrd.RowDefinitions.Count
            If RowNum < 4 Then
               For Index As Integer = RowNum To 3
                  Dim Row As New RowDefinition
                  Row.Height = New GridLength(1, GridUnitType.Star)
                  FeedGrd.RowDefinitions.Add(Row)
               Next
               FeedGpBx.SetValue(Grid.RowSpanProperty, 12)
               BackFeedTxBl.SetValue(Grid.RowProperty, 4)
               BackFeedTxBx.SetValue(Grid.ColumnProperty, 1)
               BackFeedTxBx.SetValue(Grid.RowProperty, 4)
            End If
            OffsetGpBx.SetValue(Grid.RowProperty, 12)
            TipFeedTxBl.Text = EgtMsg(MSG_TOOLSDBPAGEUC + 10)
            StartFeedTxBl.Visibility = Windows.Visibility.Visible
            StartFeedTxBx.Visibility = Windows.Visibility.Visible
            EndFeedTxBl.Visibility = Windows.Visibility.Visible
            EndFeedTxBx.Visibility = Windows.Visibility.Visible
            VertFeedTxBl.Visibility = Windows.Visibility.Hidden
            VertFeedTxBx.Visibility = Windows.Visibility.Hidden
            BackFeedTxBl.Visibility = Windows.Visibility.Hidden
            BackFeedTxBx.Visibility = Windows.Visibility.Hidden
            ThicknessFeedTxBl.Visibility = Windows.Visibility.Hidden
            ThicknessFeedTxBx.Visibility = Windows.Visibility.Hidden
            SideAngCutTxBl.Visibility = Windows.Visibility.Hidden
            SideAngCutTxBx.Visibility = Windows.Visibility.Hidden
            ForwardAngleTxBl.Visibility = Windows.Visibility.Hidden
            ForwardAngleTxBx.Visibility = Windows.Visibility.Hidden
            CornerGpBx.Visibility = Windows.Visibility.Hidden
            ProbingGpBx.Visibility = Windows.Visibility.Hidden
            ProbingTxBl.Visibility = Windows.Visibility.Hidden
            ProbingChBx.Visibility = Windows.Visibility.Hidden
            ProbingMinDistTxBl.Visibility = Windows.Visibility.Hidden
            ProbingMinDistTxBx.Visibility = Windows.Visibility.Hidden
            ProbingMaxDistTxBl.Visibility = Windows.Visibility.Hidden
            ProbingMaxDistTxBx.Visibility = Windows.Visibility.Hidden
            ExtCornTypeTxBl.Visibility = Windows.Visibility.Hidden
            ExtCornTypeCmBx.Visibility = Windows.Visibility.Hidden
            IntCornTypeTxBl.Visibility = Windows.Visibility.Hidden
            IntCornTypeCmBx.Visibility = Windows.Visibility.Hidden
            CornSlowLenTxBl.Visibility = Windows.Visibility.Hidden
            CornSlowLenTxBx.Visibility = Windows.Visibility.Hidden
            CornSlowPercTxBl.Visibility = Windows.Visibility.Hidden
            CornSlowPercTxBx.Visibility = Windows.Visibility.Hidden
            LiHoleBrd.Visibility = Windows.Visibility.Hidden
            LiHoleTxBl.Visibility = Windows.Visibility.Hidden
            LiHoleChBx.Visibility = Windows.Visibility.Hidden
            LiHoleRadTxBl.Visibility = Windows.Visibility.Hidden
            LiHoleRadTxBx.Visibility = Windows.Visibility.Hidden
            LpTurnsTxBl.Visibility = Windows.Visibility.Hidden
            LpTurnsTxBx.Visibility = Windows.Visibility.Hidden
            HpTurnsTxBl.Visibility = Windows.Visibility.Hidden
            HpTurnsTxBx.Visibility = Windows.Visibility.Hidden
            LiTangTxBl.Visibility = Windows.Visibility.Hidden
            LiTangTxBx.Visibility = Windows.Visibility.Hidden
            LiPerpTxBl.Visibility = Windows.Visibility.Hidden
            LiPerpTxBx.Visibility = Windows.Visibility.Hidden
            LoTangTxBl.Visibility = Windows.Visibility.Hidden
            LoTangTxBx.Visibility = Windows.Visibility.Hidden
            LoPerpTxBl.Visibility = Windows.Visibility.Hidden
            LoPerpTxBx.Visibility = Windows.Visibility.Hidden
            SpecificLeadInGpBx.Visibility = Windows.Visibility.Hidden
         Case MCH_MY.DRILLING 'Parametri Foratura
            SideAngleTxBl.Visibility = Windows.Visibility.Hidden
            SideAngleTxBx.Visibility = Windows.Visibility.Hidden
            InvertTxBl.Visibility = Windows.Visibility.Hidden
            InvertChBx.Visibility = Windows.Visibility.Hidden
            AcrossTxBl.Visibility = Windows.Visibility.Hidden
            AcrossChBx.Visibility = Windows.Visibility.Hidden
            StepTypeTxBl.Visibility = Windows.Visibility.Hidden
            StepTypeCmBx.Visibility = Windows.Visibility.Hidden
            SideBrd.Visibility = Windows.Visibility.Hidden
            TypeBrd.Visibility = Windows.Visibility.Hidden
            CurveBrd.Visibility = Windows.Visibility.Hidden
            If TypeGrd.Children.Contains(StartPosTxBl) Then
               TypeGrd.Children.Remove(StartPosTxBl)
               TypeGrd.Children.Remove(StartPosTxBx)
               MachParamGrd.Children.Add(StartPosTxBl)
               MachParamGrd.Children.Add(StartPosTxBx)
               StartPosTxBl.SetValue(Grid.ColumnProperty, 0)
               StartPosTxBl.SetValue(Grid.RowProperty, 6)
               StartPosTxBx.SetValue(Grid.ColumnProperty, 1)
               StartPosTxBx.SetValue(Grid.RowProperty, 6)
               StartPosTxBl.SetValue(Grid.RowSpanProperty, 3)
               StartPosTxBx.SetValue(Grid.RowSpanProperty, 3)
               StartPosTxBx.Style = Application.Current.FindResource("OmagCut_LeftCalculatorTextBoxNoBorder")
            ElseIf MachParamGrd.Children.Contains(StartPosTxBl) Then
               StartPosTxBl.SetValue(Grid.ColumnProperty, 0)
               StartPosTxBl.SetValue(Grid.RowProperty, 6)
               StartPosTxBx.SetValue(Grid.ColumnProperty, 1)
               StartPosTxBx.SetValue(Grid.RowProperty, 6)
               StartPosTxBl.SetValue(Grid.RowSpanProperty, 3)
               StartPosTxBx.SetValue(Grid.RowSpanProperty, 3)
               StartPosTxBx.Style = Application.Current.FindResource("OmagCut_LeftCalculatorTextBoxNoBorder")
            End If
            StartPosTxBl.Visibility = Windows.Visibility.Visible
            StartPosTxBx.Visibility = Windows.Visibility.Visible
            LowLenGpBx.Visibility = Windows.Visibility.Visible
            ThrouAddLenTxBl.Visibility = Windows.Visibility.Visible
            ThrouAddLenTxBx.Visibility = Windows.Visibility.Visible
            If SawStepGrd.Children.Contains(StepTxBx) Then
               SawStepGrd.Children.Remove(StepTxBx)
               DrillStepGrd.Children.Add(StepTxBx)
               StepTxBx.SetValue(Grid.ColumnProperty, 1)
               StepTxBx.SetValue(Grid.RowProperty, 2)
               StepTxBx.Style = Application.Current.FindResource("OmagCut_MachLeftCalculatorTextBoxInBorder")
            ElseIf SawRouStepGrd.Children.Contains(StepTxBx) Then
               SawRouStepGrd.Children.Remove(StepTxBx)
               DrillStepGrd.Children.Add(StepTxBx)
               StepTxBx.SetValue(Grid.ColumnProperty, 1)
               StepTxBx.SetValue(Grid.RowProperty, 2)
               StepTxBx.Style = Application.Current.FindResource("OmagCut_MachLeftCalculatorTextBoxInBorder")
            End If
            StepTxBx.Visibility = Windows.Visibility.Visible
            SawStepGpBx.Visibility = Windows.Visibility.Hidden
            DrillStepBrd.Visibility = Windows.Visibility.Visible
            SawRouStepGpBx.Visibility = Windows.Visibility.Hidden
            ReturnPosTxBl.Visibility = Windows.Visibility.Visible
            ReturnPosTxBx.Visibility = Windows.Visibility.Visible
            OffsetGpBx.Visibility = Windows.Visibility.Hidden
            ' Definizione di una riga della tabella con la giusta altezza
            Dim RowNum As Integer = FeedGrd.RowDefinitions.Count
            If RowNum > 4 Then
               For Index As Integer = RowNum - 1 To 4 Step -1
                  FeedGrd.RowDefinitions.RemoveAt(Index)
               Next
            End If
            FeedGpBx.SetValue(Grid.RowSpanProperty, 12)
            FeedGpBx.SetValue(Grid.RowProperty, 6)
            ' Definizione di una riga della tabella Feed
            RowNum = FeedGrd.RowDefinitions.Count
            If RowNum < 4 Then
               For Index As Integer = RowNum To 3
                  Dim Row As New RowDefinition
                  Row.Height = New GridLength(1, GridUnitType.Star)
                  FeedGrd.RowDefinitions.Add(Row)
               Next
               FeedGpBx.SetValue(Grid.RowSpanProperty, 12)
               BackFeedTxBl.SetValue(Grid.RowProperty, 4)
               BackFeedTxBx.SetValue(Grid.ColumnProperty, 1)
               BackFeedTxBx.SetValue(Grid.RowProperty, 4)
            End If
            OffsetGpBx.SetValue(Grid.RowProperty, 12)
            TipFeedTxBl.Text = EgtMsg(MSG_TOOLSDBPAGEUC + 10)
            StartFeedTxBl.Visibility = Windows.Visibility.Visible
            StartFeedTxBx.Visibility = Windows.Visibility.Visible
            EndFeedTxBl.Visibility = Windows.Visibility.Visible
            EndFeedTxBx.Visibility = Windows.Visibility.Visible
            VertFeedTxBl.Visibility = Windows.Visibility.Hidden
            VertFeedTxBx.Visibility = Windows.Visibility.Hidden
            BackFeedTxBl.Visibility = Windows.Visibility.Hidden
            BackFeedTxBx.Visibility = Windows.Visibility.Hidden
            ThicknessFeedTxBl.Visibility = Windows.Visibility.Hidden
            ThicknessFeedTxBx.Visibility = Windows.Visibility.Hidden
            SideAngCutTxBl.Visibility = Windows.Visibility.Hidden
            SideAngCutTxBx.Visibility = Windows.Visibility.Hidden
            ForwardAngleTxBl.Visibility = Windows.Visibility.Hidden
            ForwardAngleTxBx.Visibility = Windows.Visibility.Hidden
            CornerGpBx.Visibility = Windows.Visibility.Hidden
            ProbingGpBx.Visibility = Windows.Visibility.Hidden
            ProbingTxBl.Visibility = Windows.Visibility.Hidden
            ProbingChBx.Visibility = Windows.Visibility.Hidden
            ProbingMinDistTxBl.Visibility = Windows.Visibility.Hidden
            ProbingMinDistTxBx.Visibility = Windows.Visibility.Hidden
            ProbingMaxDistTxBl.Visibility = Windows.Visibility.Hidden
            ProbingMaxDistTxBx.Visibility = Windows.Visibility.Hidden
            ExtCornTypeTxBl.Visibility = Windows.Visibility.Hidden
            ExtCornTypeCmBx.Visibility = Windows.Visibility.Hidden
            IntCornTypeTxBl.Visibility = Windows.Visibility.Hidden
            IntCornTypeCmBx.Visibility = Windows.Visibility.Hidden
            CornSlowLenTxBl.Visibility = Windows.Visibility.Hidden
            CornSlowLenTxBx.Visibility = Windows.Visibility.Hidden
            CornSlowPercTxBl.Visibility = Windows.Visibility.Hidden
            CornSlowPercTxBx.Visibility = Windows.Visibility.Hidden
            LiHoleBrd.Visibility = Windows.Visibility.Hidden
            LiHoleTxBl.Visibility = Windows.Visibility.Hidden
            LiHoleChBx.Visibility = Windows.Visibility.Hidden
            LiHoleRadTxBl.Visibility = Windows.Visibility.Hidden
            LiHoleRadTxBx.Visibility = Windows.Visibility.Hidden
            LpTurnsTxBl.Visibility = Windows.Visibility.Hidden
            LpTurnsTxBx.Visibility = Windows.Visibility.Hidden
            HpTurnsTxBl.Visibility = Windows.Visibility.Hidden
            HpTurnsTxBx.Visibility = Windows.Visibility.Hidden
            LiTangTxBl.Visibility = Windows.Visibility.Hidden
            LiTangTxBx.Visibility = Windows.Visibility.Hidden
            LiPerpTxBl.Visibility = Windows.Visibility.Hidden
            LiPerpTxBx.Visibility = Windows.Visibility.Hidden
            LoTangTxBl.Visibility = Windows.Visibility.Hidden
            LoTangTxBx.Visibility = Windows.Visibility.Hidden
            LoPerpTxBl.Visibility = Windows.Visibility.Hidden
            LoPerpTxBx.Visibility = Windows.Visibility.Hidden
            SpecificLeadInGpBx.Visibility = Windows.Visibility.Hidden
         Case MCH_MY.SAWROUGHING   'Parametri Sgrossatura con lama
            SideAngleTxBl.Visibility = Windows.Visibility.Hidden
            SideAngleTxBx.Visibility = Windows.Visibility.Hidden
            InvertTxBl.Visibility = Windows.Visibility.Hidden
            InvertChBx.Visibility = Windows.Visibility.Hidden
            AcrossTxBl.Visibility = Windows.Visibility.Hidden
            AcrossChBx.Visibility = Windows.Visibility.Hidden
            StepTypeTxBl.Visibility = Windows.Visibility.Visible
            StepTypeCmBx.Visibility = Windows.Visibility.Visible
            StepTypeCmBx.ItemsSource = RouFinStepType
            SideBrd.SetValue(Grid.RowProperty, 9)
            SideBrd.Visibility = Windows.Visibility.Visible
            WorkSideTxBl.Visibility = Windows.Visibility.Hidden
            WorkSideCmBx.Visibility = Windows.Visibility.Hidden
            HeadSideTxBl.Visibility = Windows.Visibility.Visible
            HeadSideCmBx.Visibility = Windows.Visibility.Visible
            TypeBrd.Visibility = Windows.Visibility.Visible
            ' Definizione della grid TypeGrd con la giusta altezza e numero di righe
            Dim RowNum As Integer = TypeGrd.RowDefinitions.Count
            If RowNum > 2 Then
               For Index As Integer = RowNum - 1 To 2 Step -1
                  TypeGrd.RowDefinitions.RemoveAt(Index)
               Next
               LeadInTypeTxBl.SetValue(Grid.ColumnProperty, 2)
               LeadInTypeCmBx.SetValue(Grid.ColumnProperty, 3)
               LeadOutTypeTxBl.SetValue(Grid.RowProperty, 1)
               LeadOutTypeTxBl.SetValue(Grid.ColumnProperty, 2)
               LeadOutTypeCmBx.SetValue(Grid.RowProperty, 1)
               LeadOutTypeCmBx.SetValue(Grid.ColumnProperty, 3)
               TypeBrd.SetValue(Grid.RowProperty, 12)
               TypeBrd.SetValue(Grid.RowSpanProperty, 6)
            End If
            LeadInTypeTxBl.Visibility = Windows.Visibility.Hidden
            LeadInTypeCmBx.Visibility = Windows.Visibility.Hidden
            ExtLinkTypeTxBl.Visibility = Windows.Visibility.Hidden
            ExtLinkTypeCmBx.Visibility = Windows.Visibility.Hidden
            LeadOutTypeTxBl.Visibility = Windows.Visibility.Hidden
            LeadOutTypeCmBx.Visibility = Windows.Visibility.Hidden
            LeadLinkTypeTxBl.Visibility = Windows.Visibility.Visible
            LeadLinkTypeCmBx.Visibility = Windows.Visibility.Visible
            LeadLinkTypeCmBx.ItemsSource = LeadLinkType
            CurveBrd.Visibility = Windows.Visibility.Hidden
            If MachParamGrd.Children.Contains(StartPosTxBl) Then
               MachParamGrd.Children.Remove(StartPosTxBl)
               MachParamGrd.Children.Remove(StartPosTxBx)
               TypeGrd.Children.Add(StartPosTxBl)
               TypeGrd.Children.Add(StartPosTxBx)
               StartPosTxBl.SetValue(Grid.ColumnProperty, 0)
               StartPosTxBl.SetValue(Grid.RowProperty, 0)
               StartPosTxBx.SetValue(Grid.ColumnProperty, 1)
               StartPosTxBx.SetValue(Grid.RowProperty, 0)
               StartPosTxBl.SetValue(Grid.RowSpanProperty, 1)
               StartPosTxBx.SetValue(Grid.RowSpanProperty, 1)
               StartPosTxBx.Style = Application.Current.FindResource("OmagCut_MachLeftCalculatorTextBoxInBorder")
            End If
            StartPosTxBl.Visibility = Windows.Visibility.Visible
            StartPosTxBx.Visibility = Windows.Visibility.Visible
            LowLenGpBx.Visibility = Windows.Visibility.Hidden
            ThrouAddLenTxBl.Visibility = Windows.Visibility.Hidden
            ThrouAddLenTxBx.Visibility = Windows.Visibility.Hidden
            If DrillStepGrd.Children.Contains(StepTxBx) Then
               DrillStepGrd.Children.Remove(StepTxBx)
               SawRouStepGrd.Children.Add(StepTxBx)
               StepTxBx.SetValue(Grid.ColumnProperty, 1)
               StepTxBx.SetValue(Grid.RowProperty, 0)
               StepTxBx.Style = Application.Current.FindResource("OmagCut_CalculatorTextBoxInGroupBox")
            ElseIf SawStepGrd.Children.Contains(StepTxBx) Then
               SawStepGrd.Children.Remove(StepTxBx)
               SawRouStepGrd.Children.Add(StepTxBx)
               StepTxBx.SetValue(Grid.ColumnProperty, 1)
               StepTxBx.SetValue(Grid.RowProperty, 0)
               StepTxBx.Style = Application.Current.FindResource("OmagCut_CalculatorTextBoxInGroupBox")
            End If
            StepTxBx.Visibility = Windows.Visibility.Visible
            DrillStepBrd.Visibility = Windows.Visibility.Hidden
            SawStepGpBx.Visibility = Windows.Visibility.Hidden
            SawRouStepGpBx.Visibility = Windows.Visibility.Visible
            SawRouStepTxBl.Visibility = Windows.Visibility.Visible
            ReturnPosTxBl.Visibility = Windows.Visibility.Hidden
            ReturnPosTxBx.Visibility = Windows.Visibility.Hidden
            OffsetGpBx.Visibility = Windows.Visibility.Visible
            RadOffsetTxBl.Visibility = Windows.Visibility.Visible
            RadOffsetTxBx.Visibility = Windows.Visibility.Visible
            LonOffsetTxBl.Visibility = Windows.Visibility.Visible
            LonOffsetTxBx.Visibility = Windows.Visibility.Visible
            ' Definizione di una riga della tabella con la giusta altezza
            RowNum = FeedGrd.RowDefinitions.Count
            If RowNum > 4 Then
               For Index As Integer = RowNum - 1 To 4 Step -1
                  FeedGrd.RowDefinitions.RemoveAt(Index)
               Next
            End If
            FeedGpBx.SetValue(Grid.RowSpanProperty, 12)
            FeedGpBx.SetValue(Grid.RowProperty, 6)
            ' Definizione di una riga della tabella Feed
            RowNum = FeedGrd.RowDefinitions.Count
            If RowNum < 4 Then
               For Index As Integer = RowNum To 3
                  Dim Row As New RowDefinition
                  Row.Height = New GridLength(1, GridUnitType.Star)
                  FeedGrd.RowDefinitions.Add(Row)
               Next
               FeedGpBx.SetValue(Grid.RowSpanProperty, 12)
               BackFeedTxBl.SetValue(Grid.RowProperty, 4)
               BackFeedTxBx.SetValue(Grid.ColumnProperty, 1)
               BackFeedTxBx.SetValue(Grid.RowProperty, 4)
            End If
            OffsetGpBx.SetValue(Grid.RowProperty, 12)
            TipFeedTxBl.Text = EgtMsg(MSG_TOOLSDBPAGEUC + 10)
            StartFeedTxBl.Visibility = Windows.Visibility.Visible
            StartFeedTxBx.Visibility = Windows.Visibility.Visible
            EndFeedTxBl.Visibility = Windows.Visibility.Visible
            EndFeedTxBx.Visibility = Windows.Visibility.Visible
            VertFeedTxBl.Visibility = Windows.Visibility.Hidden
            VertFeedTxBx.Visibility = Windows.Visibility.Hidden
            BackFeedTxBl.Visibility = Windows.Visibility.Hidden
            BackFeedTxBx.Visibility = Windows.Visibility.Hidden
            ThicknessFeedTxBl.Visibility = Windows.Visibility.Hidden
            ThicknessFeedTxBx.Visibility = Windows.Visibility.Hidden
            SideAngCutTxBl.Visibility = Windows.Visibility.Hidden
            SideAngCutTxBx.Visibility = Windows.Visibility.Hidden
            'Spostamento gruppo sovramateriale
            OffsetGpBx.SetValue(Grid.RowProperty, 18)
            ' Definizione di una riga della tabella Offset
            RowNum = OffsetGrd.RowDefinitions.Count
            If RowNum < 2 Then
               Dim Row As New RowDefinition
               Row.Height = New GridLength(1, GridUnitType.Star)
               OffsetGrd.RowDefinitions.Add(Row)
               OffsetGpBx.SetValue(Grid.RowSpanProperty, 6)
               LonOffsetTxBl.SetValue(Grid.RowProperty, 2)
               LonOffsetTxBx.SetValue(Grid.ColumnProperty, 1)
               LonOffsetTxBx.SetValue(Grid.RowProperty, 2)
            End If
            ForwardAngleTxBl.Visibility = Windows.Visibility.Hidden
            ForwardAngleTxBx.Visibility = Windows.Visibility.Hidden
            CornerGpBx.Visibility = Windows.Visibility.Hidden
            ProbingGpBx.Visibility = Windows.Visibility.Hidden
            ProbingTxBl.Visibility = Windows.Visibility.Hidden
            ProbingChBx.Visibility = Windows.Visibility.Hidden
            ProbingMinDistTxBl.Visibility = Windows.Visibility.Hidden
            ProbingMinDistTxBx.Visibility = Windows.Visibility.Hidden
            ProbingMaxDistTxBl.Visibility = Windows.Visibility.Hidden
            ProbingMaxDistTxBx.Visibility = Windows.Visibility.Hidden
            ExtCornTypeTxBl.Visibility = Windows.Visibility.Hidden
            ExtCornTypeCmBx.Visibility = Windows.Visibility.Hidden
            IntCornTypeTxBl.Visibility = Windows.Visibility.Hidden
            IntCornTypeCmBx.Visibility = Windows.Visibility.Hidden
            CornSlowLenTxBl.Visibility = Windows.Visibility.Hidden
            CornSlowLenTxBx.Visibility = Windows.Visibility.Hidden
            CornSlowPercTxBl.Visibility = Windows.Visibility.Hidden
            CornSlowPercTxBx.Visibility = Windows.Visibility.Hidden
            LiHoleBrd.Visibility = Windows.Visibility.Hidden
            LiHoleTxBl.Visibility = Windows.Visibility.Hidden
            LiHoleChBx.Visibility = Windows.Visibility.Hidden
            LiHoleRadTxBl.Visibility = Windows.Visibility.Hidden
            LiHoleRadTxBx.Visibility = Windows.Visibility.Hidden
            LpTurnsTxBl.Visibility = Windows.Visibility.Hidden
            LpTurnsTxBx.Visibility = Windows.Visibility.Hidden
            HpTurnsTxBl.Visibility = Windows.Visibility.Hidden
            HpTurnsTxBx.Visibility = Windows.Visibility.Hidden
            LiTangTxBl.Visibility = Windows.Visibility.Hidden
            LiTangTxBx.Visibility = Windows.Visibility.Hidden
            LiPerpTxBl.Visibility = Windows.Visibility.Hidden
            LiPerpTxBx.Visibility = Windows.Visibility.Hidden
            LoTangTxBl.Visibility = Windows.Visibility.Hidden
            LoTangTxBx.Visibility = Windows.Visibility.Hidden
            LoPerpTxBl.Visibility = Windows.Visibility.Hidden
            LoPerpTxBx.Visibility = Windows.Visibility.Hidden
            SpecificLeadInGpBx.Visibility = Windows.Visibility.Hidden
         Case MCH_MY.SAWFINISHING   'Parametri Finitura con lama
            SideAngleTxBl.Visibility = Windows.Visibility.Hidden
            SideAngleTxBx.Visibility = Windows.Visibility.Hidden
            InvertTxBl.Visibility = Windows.Visibility.Visible
            InvertChBx.Visibility = Windows.Visibility.Visible
            AcrossTxBl.Visibility = Windows.Visibility.Visible
            AcrossChBx.Visibility = Windows.Visibility.Visible
            StepTypeTxBl.Visibility = Windows.Visibility.Visible
            StepTypeCmBx.Visibility = Windows.Visibility.Visible
            StepTypeCmBx.ItemsSource = RouFinStepType
            SideBrd.SetValue(Grid.RowProperty, 9)
            SideBrd.Visibility = Windows.Visibility.Visible
            WorkSideTxBl.Visibility = Windows.Visibility.Hidden
            WorkSideCmBx.Visibility = Windows.Visibility.Hidden
            HeadSideTxBl.Visibility = Windows.Visibility.Visible
            HeadSideCmBx.Visibility = Windows.Visibility.Visible
            TypeBrd.Visibility = Windows.Visibility.Visible
            ' Definizione della grid TypeGrd con la giusta altezza e numero di righe
            Dim RowNum As Integer = TypeGrd.RowDefinitions.Count
            If RowNum > 2 Then
               For Index As Integer = RowNum - 1 To 2 Step -1
                  TypeGrd.RowDefinitions.RemoveAt(Index)
               Next
               LeadInTypeTxBl.SetValue(Grid.ColumnProperty, 2)
               LeadInTypeCmBx.SetValue(Grid.ColumnProperty, 3)
               LeadOutTypeTxBl.SetValue(Grid.RowProperty, 1)
               LeadOutTypeTxBl.SetValue(Grid.ColumnProperty, 2)
               LeadOutTypeCmBx.SetValue(Grid.RowProperty, 1)
               LeadOutTypeCmBx.SetValue(Grid.ColumnProperty, 3)
               TypeBrd.SetValue(Grid.RowProperty, 12)
               TypeBrd.SetValue(Grid.RowSpanProperty, 6)
            End If
            LeadInTypeTxBl.Visibility = Windows.Visibility.Hidden
            LeadInTypeCmBx.Visibility = Windows.Visibility.Hidden
            ExtLinkTypeTxBl.Visibility = Windows.Visibility.Hidden
            ExtLinkTypeCmBx.Visibility = Windows.Visibility.Hidden
            LeadOutTypeTxBl.Visibility = Windows.Visibility.Hidden
            LeadOutTypeCmBx.Visibility = Windows.Visibility.Hidden
            LeadLinkTypeTxBl.Visibility = Windows.Visibility.Visible
            LeadLinkTypeCmBx.Visibility = Windows.Visibility.Visible
            LeadLinkTypeCmBx.ItemsSource = LeLiFinType
            CurveBrd.Visibility = Windows.Visibility.Hidden
            If MachParamGrd.Children.Contains(StartPosTxBl) Then
               MachParamGrd.Children.Remove(StartPosTxBl)
               MachParamGrd.Children.Remove(StartPosTxBx)
               TypeGrd.Children.Add(StartPosTxBl)
               TypeGrd.Children.Add(StartPosTxBx)
               StartPosTxBl.SetValue(Grid.ColumnProperty, 0)
               StartPosTxBl.SetValue(Grid.RowProperty, 0)
               StartPosTxBx.SetValue(Grid.ColumnProperty, 1)
               StartPosTxBx.SetValue(Grid.RowProperty, 0)
               StartPosTxBl.SetValue(Grid.RowSpanProperty, 1)
               StartPosTxBx.SetValue(Grid.RowSpanProperty, 1)
               StartPosTxBx.Style = Application.Current.FindResource("OmagCut_MachLeftCalculatorTextBoxInBorder")
            End If
            StartPosTxBl.Visibility = Windows.Visibility.Visible
            StartPosTxBx.Visibility = Windows.Visibility.Visible
            LowLenGpBx.Visibility = Windows.Visibility.Hidden
            ThrouAddLenTxBl.Visibility = Windows.Visibility.Hidden
            ThrouAddLenTxBx.Visibility = Windows.Visibility.Hidden
            DrillStepBrd.Visibility = Windows.Visibility.Hidden
            SawStepGpBx.Visibility = Windows.Visibility.Hidden
            SawRouStepGpBx.Visibility = Windows.Visibility.Visible
            SawRouStepTxBl.Visibility = Windows.Visibility.Visible
            If DrillStepGrd.Children.Contains(StepTxBx) Then
               DrillStepGrd.Children.Remove(StepTxBx)
               SawRouStepGrd.Children.Add(StepTxBx)
               StepTxBx.SetValue(Grid.ColumnProperty, 1)
               StepTxBx.SetValue(Grid.RowProperty, 0)
               StepTxBx.Style = Application.Current.FindResource("OmagCut_CalculatorTextBoxInGroupBox")
            ElseIf SawStepGrd.Children.Contains(StepTxBx) Then
               SawStepGrd.Children.Remove(StepTxBx)
               SawRouStepGrd.Children.Add(StepTxBx)
               StepTxBx.SetValue(Grid.ColumnProperty, 1)
               StepTxBx.SetValue(Grid.RowProperty, 0)
               StepTxBx.Style = Application.Current.FindResource("OmagCut_CalculatorTextBoxInGroupBox")
            End If
            StepTxBx.Visibility = Windows.Visibility.Visible
            ReturnPosTxBl.Visibility = Windows.Visibility.Hidden
            ReturnPosTxBx.Visibility = Windows.Visibility.Hidden
            OffsetGpBx.Visibility = Windows.Visibility.Visible
            RadOffsetTxBl.Visibility = Windows.Visibility.Visible
            RadOffsetTxBx.Visibility = Windows.Visibility.Visible
            LonOffsetTxBl.Visibility = Windows.Visibility.Hidden
            LonOffsetTxBx.Visibility = Windows.Visibility.Hidden
            ' Definizione di una riga della tabella con la giusta altezza
            RowNum = FeedGrd.RowDefinitions.Count
            If RowNum > 4 Then
               For Index As Integer = RowNum - 1 To 4 Step -1
                  FeedGrd.RowDefinitions.RemoveAt(Index)
               Next
            End If
            FeedGpBx.SetValue(Grid.RowSpanProperty, 12)
            FeedGpBx.SetValue(Grid.RowProperty, 6)
            ' Definizione di una riga della tabella Feed
            RowNum = FeedGrd.RowDefinitions.Count
            If RowNum < 5 Then
               For Index As Integer = RowNum To 4
                  Dim Row As New RowDefinition
                  Row.Height = New GridLength(1, GridUnitType.Star)
                  FeedGrd.RowDefinitions.Add(Row)
               Next
               FeedGpBx.SetValue(Grid.RowSpanProperty, 14)
               VertFeedTxBl.SetValue(Grid.RowProperty, 4)
               VertFeedTxBx.SetValue(Grid.ColumnProperty, 1)
               VertFeedTxBx.SetValue(Grid.RowProperty, 4)
            End If
            OffsetGpBx.SetValue(Grid.RowProperty, 12)
            TipFeedTxBl.Text = EgtMsg(MSG_TOOLSDBPAGEUC + 10)
            StartFeedTxBl.Visibility = Windows.Visibility.Visible
            StartFeedTxBx.Visibility = Windows.Visibility.Visible
            EndFeedTxBl.Visibility = Windows.Visibility.Visible
            EndFeedTxBx.Visibility = Windows.Visibility.Visible
            VertFeedTxBl.Visibility = Windows.Visibility.Visible
            VertFeedTxBx.Visibility = Windows.Visibility.Visible
            BackFeedTxBl.Visibility = Windows.Visibility.Hidden
            BackFeedTxBx.Visibility = Windows.Visibility.Hidden
            ThicknessFeedTxBl.Visibility = Windows.Visibility.Hidden
            ThicknessFeedTxBx.Visibility = Windows.Visibility.Hidden
            SideAngCutTxBl.Visibility = Windows.Visibility.Hidden
            SideAngCutTxBx.Visibility = Windows.Visibility.Hidden
            'Spostamento gruppo sovramateriale
            OffsetGpBx.SetValue(Grid.RowProperty, 20)
            ' Eliminazione di una riga della tabella Offset
            RowNum = OffsetGrd.RowDefinitions.Count
            If RowNum > 1 Then
               For Index As Integer = RowNum - 1 To 1 Step -1
                  OffsetGrd.RowDefinitions.RemoveAt(Index)
                  OffsetGpBx.SetValue(Grid.RowSpanProperty, 4)
               Next
            End If
            ForwardAngleTxBl.Visibility = Windows.Visibility.Hidden
            ForwardAngleTxBx.Visibility = Windows.Visibility.Hidden
            CornerGpBx.Visibility = Windows.Visibility.Hidden
            ProbingGpBx.Visibility = Windows.Visibility.Hidden
            ProbingTxBl.Visibility = Windows.Visibility.Hidden
            ProbingChBx.Visibility = Windows.Visibility.Hidden
            ProbingMinDistTxBl.Visibility = Windows.Visibility.Hidden
            ProbingMinDistTxBx.Visibility = Windows.Visibility.Hidden
            ProbingMaxDistTxBl.Visibility = Windows.Visibility.Hidden
            ProbingMaxDistTxBx.Visibility = Windows.Visibility.Hidden
            ExtCornTypeTxBl.Visibility = Windows.Visibility.Hidden
            ExtCornTypeCmBx.Visibility = Windows.Visibility.Hidden
            IntCornTypeTxBl.Visibility = Windows.Visibility.Hidden
            IntCornTypeCmBx.Visibility = Windows.Visibility.Hidden
            CornSlowLenTxBl.Visibility = Windows.Visibility.Hidden
            CornSlowLenTxBx.Visibility = Windows.Visibility.Hidden
            CornSlowPercTxBl.Visibility = Windows.Visibility.Hidden
            CornSlowPercTxBx.Visibility = Windows.Visibility.Hidden
            LiHoleBrd.Visibility = Windows.Visibility.Hidden
            LiHoleTxBl.Visibility = Windows.Visibility.Hidden
            LiHoleChBx.Visibility = Windows.Visibility.Hidden
            LiHoleRadTxBl.Visibility = Windows.Visibility.Hidden
            LiHoleRadTxBx.Visibility = Windows.Visibility.Hidden
            LpTurnsTxBl.Visibility = Windows.Visibility.Hidden
            LpTurnsTxBx.Visibility = Windows.Visibility.Hidden
            HpTurnsTxBl.Visibility = Windows.Visibility.Hidden
            HpTurnsTxBx.Visibility = Windows.Visibility.Hidden
            LiTangTxBl.Visibility = Windows.Visibility.Hidden
            LiTangTxBx.Visibility = Windows.Visibility.Hidden
            LiPerpTxBl.Visibility = Windows.Visibility.Hidden
            LiPerpTxBx.Visibility = Windows.Visibility.Hidden
            LoTangTxBl.Visibility = Windows.Visibility.Hidden
            LoTangTxBx.Visibility = Windows.Visibility.Hidden
            LoPerpTxBl.Visibility = Windows.Visibility.Hidden
            LoPerpTxBx.Visibility = Windows.Visibility.Hidden
            SpecificLeadInGpBx.Visibility = Windows.Visibility.Hidden
         Case MCH_MY.POCKETING 'Parametri Svuotatura
            SideAngleTxBl.Visibility = Windows.Visibility.Hidden
            SideAngleTxBx.Visibility = Windows.Visibility.Hidden
            InvertTxBl.Visibility = Windows.Visibility.Hidden
            InvertChBx.Visibility = Windows.Visibility.Hidden
            AcrossTxBl.Visibility = Windows.Visibility.Hidden
            AcrossChBx.Visibility = Windows.Visibility.Hidden
            StepTypeTxBl.Visibility = Windows.Visibility.Hidden
            StepTypeCmBx.Visibility = Windows.Visibility.Hidden
            SideBrd.SetValue(Grid.RowProperty, 9)
            SideBrd.Visibility = Windows.Visibility.Hidden
            WorkSideTxBl.Visibility = Windows.Visibility.Hidden
            WorkSideCmBx.Visibility = Windows.Visibility.Hidden
            HeadSideTxBl.Visibility = Windows.Visibility.Hidden
            HeadSideCmBx.Visibility = Windows.Visibility.Hidden
            TypeBrd.Visibility = Windows.Visibility.Visible
            ' Definizione della grid TypeGrd con la giusta altezza e numero di righe
            Dim RowNum As Integer = TypeGrd.RowDefinitions.Count
            If RowNum > 2 Then
               For Index As Integer = RowNum - 1 To 2 Step -1
                  TypeGrd.RowDefinitions.RemoveAt(Index)
               Next
            ElseIf RowNum < 2 Then
               ' costruiso una riga in più da inserire
               Dim Row As New RowDefinition
               TypeGrd.RowDefinitions.Add(Row)
            End If
            LeadInTypeTxBl.SetValue(Grid.RowProperty, 1)
            LeadInTypeTxBl.SetValue(Grid.ColumnProperty, 0)
            LeadInTypeCmBx.SetValue(Grid.RowProperty, 1)
            LeadInTypeCmBx.SetValue(Grid.ColumnProperty, 1)
            LeadOutTypeTxBl.SetValue(Grid.RowProperty, 1)
            LeadOutTypeTxBl.SetValue(Grid.ColumnProperty, 2)
            LeadOutTypeCmBx.SetValue(Grid.RowProperty, 1)
            LeadOutTypeCmBx.SetValue(Grid.ColumnProperty, 3)
            TypeBrd.SetValue(Grid.RowProperty, 12)
            TypeBrd.SetValue(Grid.RowSpanProperty, 6)

            LeadInTypeTxBl.Visibility = Windows.Visibility.Visible
            LeadInTypeCmBx.Visibility = Windows.Visibility.Visible
            ExtLinkTypeTxBl.Visibility = Windows.Visibility.Hidden
            ExtLinkTypeCmBx.Visibility = Windows.Visibility.Hidden
            LeadOutTypeTxBl.Visibility = Windows.Visibility.Visible
            LeadOutTypeCmBx.Visibility = Windows.Visibility.Visible
            LeadLinkTypeTxBl.Visibility = Windows.Visibility.Hidden
            LeadLinkTypeCmBx.Visibility = Windows.Visibility.Hidden
            CurveBrd.Visibility = Windows.Visibility.Hidden
            If MachParamGrd.Children.Contains(StartPosTxBl) Then
               MachParamGrd.Children.Remove(StartPosTxBl)
               MachParamGrd.Children.Remove(StartPosTxBx)
               TypeGrd.Children.Add(StartPosTxBl)
               TypeGrd.Children.Add(StartPosTxBx)
               StartPosTxBl.SetValue(Grid.ColumnProperty, 0)
               StartPosTxBl.SetValue(Grid.RowProperty, 0)
               StartPosTxBx.SetValue(Grid.ColumnProperty, 1)
               StartPosTxBx.SetValue(Grid.RowProperty, 0)
               StartPosTxBl.SetValue(Grid.RowSpanProperty, 1)
               StartPosTxBx.SetValue(Grid.RowSpanProperty, 1)
               'StartPosTxBx.Style = Application.Current.FindResource("OmagCut_LeftCalculatorTextBoxInBorder")
            End If
            StartPosTxBl.Visibility = Windows.Visibility.Visible
            StartPosTxBx.Visibility = Windows.Visibility.Visible
            LowLenGpBx.Visibility = Windows.Visibility.Hidden
            ThrouAddLenTxBl.Visibility = Windows.Visibility.Hidden
            ThrouAddLenTxBx.Visibility = Windows.Visibility.Hidden
            If DrillStepGrd.Children.Contains(StepTxBx) Then
               DrillStepGrd.Children.Remove(StepTxBx)
               SawStepGrd.Children.Add(StepTxBx)
               StepTxBx.SetValue(Grid.ColumnProperty, 1)
               StepTxBx.SetValue(Grid.RowProperty, 0)
               'StepTxBx.Style = Application.Current.FindResource("OmagCut_CalculatorTextBoxInBorder")
            ElseIf SawRouStepGrd.Children.Contains(StepTxBx) Then
               SawRouStepGrd.Children.Remove(StepTxBx)
               SawStepGrd.Children.Add(StepTxBx)
               StepTxBx.SetValue(Grid.ColumnProperty, 1)
               StepTxBx.SetValue(Grid.RowProperty, 0)
               'StepTxBx.Style = Application.Current.FindResource("OmagCut_CalculatorTextBoxInBorder")
            End If
            StepTxBx.Visibility = Windows.Visibility.Visible
            SawStepGpBx.Visibility = Windows.Visibility.Visible
            SawStepGpBx.SetValue(Grid.RowProperty, 21)
            SawStepGpBx.SetValue(Grid.RowSpanProperty, 6)
            BackwardSawStepTxBl.Visibility = Windows.Visibility.Hidden
            BackwardSawStepTxBx.Visibility = Windows.Visibility.Hidden
            ForwardStepSideAngTxBl.Visibility = Windows.Visibility.Hidden
            ForwardStepSideAngTxBx.Visibility = Windows.Visibility.Hidden
            BackwardStepSideAngTxBl.Visibility = Windows.Visibility.Hidden
            BackwardStepSideAngTxBx.Visibility = Windows.Visibility.Hidden
            ForwardSawStepTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 15)
            If DrillStepGrd.Children.Contains(StepTxBx) Then
               DrillStepGrd.Children.Remove(StepTxBx)
               SawRouStepGrd.Children.Add(StepTxBx)
               StepTxBx.SetValue(Grid.ColumnProperty, 1)
               StepTxBx.SetValue(Grid.RowProperty, 0)
               StepTxBx.Style = Application.Current.FindResource("OmagCut_CalculatorTextBoxInGroupBox")
            ElseIf SawStepGrd.Children.Contains(StepTxBx) Then
               SawStepGrd.Children.Remove(StepTxBx)
               SawRouStepGrd.Children.Add(StepTxBx)
               StepTxBx.SetValue(Grid.ColumnProperty, 1)
               StepTxBx.SetValue(Grid.RowProperty, 0)
               StepTxBx.Style = Application.Current.FindResource("OmagCut_CalculatorTextBoxInGroupBox")
            End If
            DrillStepBrd.Visibility = Windows.Visibility.Hidden
            SawStepGpBx.Visibility = Windows.Visibility.Hidden
            SawRouStepGpBx.Visibility = Windows.Visibility.Visible
            SawRouStepTxBl.Visibility = Windows.Visibility.Visible
            ReturnPosTxBl.Visibility = Windows.Visibility.Hidden
            ReturnPosTxBx.Visibility = Windows.Visibility.Hidden
            OffsetGpBx.Visibility = Windows.Visibility.Hidden
            ' Definizione di una riga della tabella con la giusta altezza
            RowNum = FeedGrd.RowDefinitions.Count
            If RowNum > 4 Then
               For Index As Integer = RowNum - 1 To 4 Step -1
                  FeedGrd.RowDefinitions.RemoveAt(Index)
               Next
            End If
            FeedGpBx.SetValue(Grid.RowSpanProperty, 12)
            FeedGpBx.SetValue(Grid.RowProperty, 6)
            ' Definizione di una riga della tabella Feed
            RowNum = FeedGrd.RowDefinitions.Count
            If RowNum < 4 Then
               For Index As Integer = RowNum To 3
                  Dim Row As New RowDefinition
                  Row.Height = New GridLength(1, GridUnitType.Star)
                  FeedGrd.RowDefinitions.Add(Row)
               Next
               FeedGpBx.SetValue(Grid.RowSpanProperty, 12)
               BackFeedTxBl.SetValue(Grid.RowProperty, 4)
               BackFeedTxBx.SetValue(Grid.ColumnProperty, 1)
               BackFeedTxBx.SetValue(Grid.RowProperty, 4)
            End If
            OffsetGpBx.SetValue(Grid.RowProperty, 12)
            TipFeedTxBl.Text = EgtMsg(MSG_TOOLSDBPAGEUC + 10)
            StartFeedTxBl.Visibility = Windows.Visibility.Visible
            StartFeedTxBx.Visibility = Windows.Visibility.Visible
            EndFeedTxBl.Visibility = Windows.Visibility.Visible
            EndFeedTxBx.Visibility = Windows.Visibility.Visible
            VertFeedTxBl.Visibility = Windows.Visibility.Hidden
            VertFeedTxBx.Visibility = Windows.Visibility.Hidden
            BackFeedTxBl.Visibility = Windows.Visibility.Hidden
            BackFeedTxBx.Visibility = Windows.Visibility.Hidden
            ThicknessFeedTxBl.Visibility = Windows.Visibility.Hidden
            ThicknessFeedTxBx.Visibility = Windows.Visibility.Hidden
            SideAngCutTxBl.Visibility = Windows.Visibility.Hidden
            SideAngCutTxBx.Visibility = Windows.Visibility.Hidden
            ForwardAngleTxBl.Visibility = Windows.Visibility.Hidden
            ForwardAngleTxBx.Visibility = Windows.Visibility.Hidden
            CornerGpBx.Visibility = Windows.Visibility.Hidden
            ProbingGpBx.Visibility = Windows.Visibility.Hidden
            ProbingTxBl.Visibility = Windows.Visibility.Hidden
            ProbingChBx.Visibility = Windows.Visibility.Hidden
            ProbingMinDistTxBl.Visibility = Windows.Visibility.Hidden
            ProbingMinDistTxBx.Visibility = Windows.Visibility.Hidden
            ProbingMaxDistTxBl.Visibility = Windows.Visibility.Hidden
            ProbingMaxDistTxBx.Visibility = Windows.Visibility.Hidden
            ExtCornTypeTxBl.Visibility = Windows.Visibility.Hidden
            ExtCornTypeCmBx.Visibility = Windows.Visibility.Hidden
            IntCornTypeTxBl.Visibility = Windows.Visibility.Hidden
            IntCornTypeCmBx.Visibility = Windows.Visibility.Hidden
            CornSlowLenTxBl.Visibility = Windows.Visibility.Hidden
            CornSlowLenTxBx.Visibility = Windows.Visibility.Hidden
            CornSlowPercTxBl.Visibility = Windows.Visibility.Hidden
            CornSlowPercTxBx.Visibility = Windows.Visibility.Hidden
            LiHoleBrd.Visibility = Windows.Visibility.Hidden
            LiHoleTxBl.Visibility = Windows.Visibility.Hidden
            LiHoleChBx.Visibility = Windows.Visibility.Hidden
            LiHoleRadTxBl.Visibility = Windows.Visibility.Hidden
            LiHoleRadTxBx.Visibility = Windows.Visibility.Hidden
            LpTurnsTxBl.Visibility = Windows.Visibility.Hidden
            LpTurnsTxBx.Visibility = Windows.Visibility.Hidden
            HpTurnsTxBl.Visibility = Windows.Visibility.Hidden
            HpTurnsTxBx.Visibility = Windows.Visibility.Hidden
            LiTangTxBl.Visibility = Windows.Visibility.Hidden
            LiTangTxBx.Visibility = Windows.Visibility.Hidden
            LiPerpTxBl.Visibility = Windows.Visibility.Hidden
            LiPerpTxBx.Visibility = Windows.Visibility.Hidden
            LoTangTxBl.Visibility = Windows.Visibility.Hidden
            LoTangTxBx.Visibility = Windows.Visibility.Hidden
            LoPerpTxBl.Visibility = Windows.Visibility.Hidden
            LoPerpTxBx.Visibility = Windows.Visibility.Hidden
            SpecificLeadInGpBx.Visibility = Windows.Visibility.Hidden
         Case MCH_MY.WATERJETTING 'Parametri WaterJetting
            DepthTxBl.Visibility = Windows.Visibility.Hidden
            DepthTxBx.Visibility = Windows.Visibility.Hidden
            SideAngleTxBl.Visibility = Windows.Visibility.Hidden
            SideAngleTxBx.Visibility = Windows.Visibility.Hidden
            InvertTxBl.Visibility = Windows.Visibility.Visible
            InvertChBx.Visibility = Windows.Visibility.Visible
            AcrossTxBl.Visibility = Windows.Visibility.Hidden
            AcrossChBx.Visibility = Windows.Visibility.Hidden
            StepTypeTxBl.Visibility = Windows.Visibility.Hidden
            StepTypeCmBx.Visibility = Windows.Visibility.Hidden
            SideBrd.SetValue(Grid.RowProperty, 3)
            SideBrd.Visibility = Windows.Visibility.Visible
            WorkSideTxBl.Visibility = Windows.Visibility.Visible
            WorkSideCmBx.Visibility = Windows.Visibility.Visible
            HeadSideTxBl.Visibility = Windows.Visibility.Hidden
            HeadSideCmBx.Visibility = Windows.Visibility.Hidden
            ' Definizione della grid TypeGrd con la giusta altezza e numero di righe
            Dim RowNum As Integer = TypeGrd.RowDefinitions.Count
            If RowNum < 3 Then
               For Index As Integer = RowNum To 2
                  Dim Row As New RowDefinition
                  Row.Height = New GridLength(1, GridUnitType.Star)
                  ' Row.SetValue(Grid.RowSpanProperty, 3)
                  TypeGrd.RowDefinitions.Add(Row)
               Next
               LeadInTypeTxBl.SetValue(Grid.ColumnProperty, 0)
               LeadInTypeCmBx.SetValue(Grid.ColumnProperty, 1)
               LeadOutTypeTxBl.SetValue(Grid.RowProperty, 0)
               LeadOutTypeTxBl.SetValue(Grid.ColumnProperty, 2)
               LeadOutTypeCmBx.SetValue(Grid.RowProperty, 0)
               LeadOutTypeCmBx.SetValue(Grid.ColumnProperty, 3)
               TypeBrd.SetValue(Grid.RowProperty, 15)
               TypeBrd.SetValue(Grid.RowSpanProperty, 9)
            End If
            TypeBrd.Visibility = Windows.Visibility.Visible
            LeadInTypeTxBl.Visibility = Windows.Visibility.Visible
            LeadInTypeCmBx.Visibility = Windows.Visibility.Visible
            ExtLinkTypeTxBl.Visibility = Windows.Visibility.Hidden
            ExtLinkTypeCmBx.Visibility = Windows.Visibility.Hidden
            LeadOutTypeTxBl.Visibility = Windows.Visibility.Visible
            LeadOutTypeCmBx.Visibility = Windows.Visibility.Visible
            LeadLinkTypeTxBl.Visibility = Windows.Visibility.Hidden
            LeadLinkTypeCmBx.Visibility = Windows.Visibility.Hidden
            CurveBrd.Visibility = Windows.Visibility.Hidden
            If MachParamGrd.Children.Contains(StartPosTxBl) Then
               MachParamGrd.Children.Remove(StartPosTxBl)
               MachParamGrd.Children.Remove(StartPosTxBx)
               TypeGrd.Children.Add(StartPosTxBl)
               TypeGrd.Children.Add(StartPosTxBx)
               StartPosTxBl.SetValue(Grid.ColumnProperty, 0)
               StartPosTxBl.SetValue(Grid.RowProperty, 0)
               StartPosTxBx.SetValue(Grid.ColumnProperty, 1)
               StartPosTxBx.SetValue(Grid.RowProperty, 0)
               StartPosTxBl.SetValue(Grid.RowSpanProperty, 1)
               StartPosTxBx.SetValue(Grid.RowSpanProperty, 1)
               'StartPosTxBx.Style = Application.Current.FindResource("OmagCut_LeftCalculatorTextBoxInBorder")
            End If
            StartPosTxBl.Visibility = Windows.Visibility.Hidden
            StartPosTxBx.Visibility = Windows.Visibility.Hidden
            LowLenGpBx.Visibility = Windows.Visibility.Hidden
            ThrouAddLenTxBl.Visibility = Windows.Visibility.Hidden
            ThrouAddLenTxBx.Visibility = Windows.Visibility.Hidden
            If DrillStepGrd.Children.Contains(StepTxBx) Then
               DrillStepGrd.Children.Remove(StepTxBx)
               SawStepGrd.Children.Add(StepTxBx)
               StepTxBx.SetValue(Grid.ColumnProperty, 1)
               StepTxBx.SetValue(Grid.RowProperty, 0)
               'StepTxBx.Style = Application.Current.FindResource("OmagCut_CalculatorTextBoxInBorder")
            ElseIf SawRouStepGrd.Children.Contains(StepTxBx) Then
               SawRouStepGrd.Children.Remove(StepTxBx)
               SawStepGrd.Children.Add(StepTxBx)
               StepTxBx.SetValue(Grid.ColumnProperty, 1)
               StepTxBx.SetValue(Grid.RowProperty, 0)
               'StepTxBx.Style = Application.Current.FindResource("OmagCut_CalculatorTextBoxInBorder")
            End If
            StepTxBx.Visibility = Windows.Visibility.Hidden
            SawStepGpBx.Visibility = Windows.Visibility.Hidden
            SawStepGpBx.SetValue(Grid.RowProperty, 21)
            SawStepGpBx.SetValue(Grid.RowSpanProperty, 6)
            BackwardSawStepTxBl.Visibility = Windows.Visibility.Hidden
            BackwardSawStepTxBx.Visibility = Windows.Visibility.Hidden
            ForwardStepSideAngTxBl.Visibility = Windows.Visibility.Hidden
            ForwardStepSideAngTxBx.Visibility = Windows.Visibility.Hidden
            BackwardStepSideAngTxBl.Visibility = Windows.Visibility.Hidden
            BackwardStepSideAngTxBx.Visibility = Windows.Visibility.Hidden
            ForwardSawStepTxBl.Text = EgtMsg(MSG_MACHININGSDBPAGEUC + 15)
            If SawStepGrd.Children.Contains(ArcIntTxBl) Then
               SawStepGrd.Children.Remove(ArcIntTxBl)
               SawStepGrd.Children.Remove(ArcIntTxBx)
               SawStepGrd.Children.Remove(ArcExtTxBl)
               SawStepGrd.Children.Remove(ArcExtTxBx)
               SawStepGrd.RowDefinitions.RemoveAt(2)
            End If
            If SawStepGrd.Children.Contains(LastSawStepTxBl) Then
               SawStepGrd.Children.Remove(LastSawStepTxBl)
               SawStepGrd.Children.Remove(LastSawStepTxBx)
               SawStepGrd.RowDefinitions.RemoveAt(2)
            End If
            DrillStepBrd.Visibility = Windows.Visibility.Hidden
            SawRouStepGpBx.Visibility = Windows.Visibility.Hidden
            ReturnPosTxBl.Visibility = Windows.Visibility.Hidden
            ReturnPosTxBx.Visibility = Windows.Visibility.Hidden
            OffsetGpBx.Visibility = Windows.Visibility.Visible
            LonOffsetTxBl.Visibility = Windows.Visibility.Hidden
            LonOffsetTxBx.Visibility = Windows.Visibility.Hidden
            ' Definizione di una riga della tabella con la giusta altezza
            RowNum = FeedGrd.RowDefinitions.Count
            If RowNum > 3 Then
               For Index As Integer = RowNum - 1 To 3 Step -1
                  FeedGrd.RowDefinitions.RemoveAt(Index)
               Next
            End If
            SpeedGrd.Visibility = Windows.Visibility.Hidden
            FeedGpBx.SetValue(Grid.RowSpanProperty, 9)
            FeedGpBx.SetValue(Grid.RowProperty, 2)
            'Spostamento gruppo sovramateriale
            OffsetGpBx.SetValue(Grid.RowProperty, 11)
            ' Eliminazione di una riga della tabella Offset
            RowNum = OffsetGrd.RowDefinitions.Count
            If RowNum > 1 Then
               For Index As Integer = RowNum - 1 To 1 Step -1
                  OffsetGrd.RowDefinitions.RemoveAt(Index)
                  OffsetGpBx.SetValue(Grid.RowSpanProperty, 4)
               Next
            End If
            TipFeedTxBl.Text = EgtMsg(90792)
            VertFeedTxBl.Visibility = Windows.Visibility.Hidden
            VertFeedTxBx.Visibility = Windows.Visibility.Hidden
            BackFeedTxBl.Visibility = Windows.Visibility.Hidden
            BackFeedTxBx.Visibility = Windows.Visibility.Hidden
            StartFeedTxBl.Visibility = Windows.Visibility.Hidden
            StartFeedTxBx.Visibility = Windows.Visibility.Hidden
            EndFeedTxBl.Visibility = Windows.Visibility.Hidden
            EndFeedTxBx.Visibility = Windows.Visibility.Hidden
            ThicknessFeedTxBl.Visibility = Windows.Visibility.Visible
            ThicknessFeedTxBx.Visibility = Windows.Visibility.Visible
            SideAngCutTxBl.Visibility = Windows.Visibility.Hidden
            SideAngCutTxBx.Visibility = Windows.Visibility.Hidden
            ForwardAngleTxBl.Visibility = Windows.Visibility.Visible
            ForwardAngleTxBx.Visibility = Windows.Visibility.Visible
            CornerGpBx.Visibility = Windows.Visibility.Visible
            ProbingGpBx.Visibility = Windows.Visibility.Visible
            ProbingTxBl.Visibility = Windows.Visibility.Visible
            ProbingChBx.Visibility = Windows.Visibility.Visible
            ProbingMinDistTxBl.Visibility = Windows.Visibility.Visible
            ProbingMinDistTxBx.Visibility = Windows.Visibility.Visible
            ProbingMaxDistTxBl.Visibility = Windows.Visibility.Visible
            ProbingMaxDistTxBx.Visibility = Windows.Visibility.Visible
            ExtCornTypeTxBl.Visibility = Windows.Visibility.Visible
            ExtCornTypeCmBx.Visibility = Windows.Visibility.Visible
            IntCornTypeTxBl.Visibility = Windows.Visibility.Visible
            IntCornTypeCmBx.Visibility = Windows.Visibility.Visible
            CornSlowLenTxBl.Visibility = Windows.Visibility.Visible
            CornSlowLenTxBx.Visibility = Windows.Visibility.Visible
            CornSlowPercTxBl.Visibility = Windows.Visibility.Visible
            CornSlowPercTxBx.Visibility = Windows.Visibility.Visible
            LiHoleBrd.Visibility = Windows.Visibility.Visible
            LiHoleTxBl.Visibility = Windows.Visibility.Visible
            LiHoleChBx.Visibility = Windows.Visibility.Visible
            LiHoleRadTxBl.Visibility = Windows.Visibility.Visible
            LiHoleRadTxBx.Visibility = Windows.Visibility.Visible
            LpTurnsTxBl.Visibility = Windows.Visibility.Visible
            LpTurnsTxBx.Visibility = Windows.Visibility.Visible
            HpTurnsTxBl.Visibility = Windows.Visibility.Visible
            HpTurnsTxBx.Visibility = Windows.Visibility.Visible
            LiTangTxBl.Visibility = Windows.Visibility.Visible
            LiTangTxBx.Visibility = Windows.Visibility.Visible
            LiPerpTxBl.Visibility = Windows.Visibility.Visible
            LiPerpTxBx.Visibility = Windows.Visibility.Visible
            LoTangTxBl.Visibility = Windows.Visibility.Visible
            LoTangTxBx.Visibility = Windows.Visibility.Visible
            LoPerpTxBl.Visibility = Windows.Visibility.Visible
            LoPerpTxBx.Visibility = Windows.Visibility.Visible
            SpecificLeadInGpBx.Visibility = Windows.Visibility.Hidden
      End Select
      'Parametri utensile
      ToolTxBl.Visibility = Windows.Visibility.Visible
      ToolCmBx.Visibility = Windows.Visibility.Visible
   End Sub

   Private Sub HideMachiningParams()
      'Dim nMachiningType As Integer
      'EgtMdbGetCurrMachiningParam(MCH_MP.TYPE, nMachiningType)
      NameTxBl.Visibility = Windows.Visibility.Hidden
      NameTxBx.Visibility = Windows.Visibility.Hidden
      DepthTxBl.Visibility = Windows.Visibility.Hidden
      DepthTxBx.Visibility = Windows.Visibility.Hidden
      MaterialsBrd.Visibility = Windows.Visibility.Hidden
      SpeedGrd.Visibility = Windows.Visibility.Hidden
      FeedGpBx.Visibility = Windows.Visibility.Hidden
      'Parametri Taglio
      SideAngleTxBl.Visibility = Windows.Visibility.Hidden
      SideAngleTxBx.Visibility = Windows.Visibility.Hidden
      InvertTxBl.Visibility = Windows.Visibility.Hidden
      InvertChBx.Visibility = Windows.Visibility.Hidden
      StepTypeTxBl.Visibility = Windows.Visibility.Hidden
      StepTypeCmBx.Visibility = Windows.Visibility.Hidden
      SideBrd.Visibility = Windows.Visibility.Hidden
      TypeBrd.Visibility = Windows.Visibility.Hidden
      CurveBrd.Visibility = Windows.Visibility.Hidden
      SawStepGpBx.Visibility = Windows.Visibility.Hidden
      SpecificLeadInGpBx.Visibility = Windows.Visibility.Hidden
      'Parametri Foratura
      StartPosTxBl.Visibility = Windows.Visibility.Hidden
      StartPosTxBx.Visibility = Windows.Visibility.Hidden
      LowLenGpBx.Visibility = Windows.Visibility.Hidden
      ThrouAddLenTxBl.Visibility = Windows.Visibility.Hidden
      ThrouAddLenTxBx.Visibility = Windows.Visibility.Hidden
      ReturnPosTxBl.Visibility = Windows.Visibility.Hidden
      ReturnPosTxBx.Visibility = Windows.Visibility.Hidden
      DrillStepBrd.Visibility = Windows.Visibility.Hidden
      'Parametri Sgrossatura con lama
      LeadLinkTypeTxBl.Visibility = Windows.Visibility.Hidden
      LeadLinkTypeCmBx.Visibility = Windows.Visibility.Hidden
      SawRouStepGpBx.Visibility = Windows.Visibility.Hidden
      ' Parametri finitura con lama
      AcrossTxBl.Visibility = Windows.Visibility.Hidden
      AcrossChBx.Visibility = Windows.Visibility.Hidden
      'Parametri utensile
      ToolTxBl.Visibility = Windows.Visibility.Hidden
      ToolCmBx.Visibility = Windows.Visibility.Hidden
      OffsetGpBx.Visibility = Windows.Visibility.Hidden
      'Parametri WaterJetting
      ForwardAngleTxBl.Visibility = Windows.Visibility.Hidden
      ForwardAngleTxBx.Visibility = Windows.Visibility.Hidden
      CornerGpBx.Visibility = Windows.Visibility.Hidden
      ProbingGpBx.Visibility = Windows.Visibility.Hidden
      ProbingTxBl.Visibility = Windows.Visibility.Hidden
      ProbingChBx.Visibility = Windows.Visibility.Hidden
      ProbingMinDistTxBl.Visibility = Windows.Visibility.Hidden
      ProbingMinDistTxBx.Visibility = Windows.Visibility.Hidden
      ProbingMaxDistTxBl.Visibility = Windows.Visibility.Hidden
      ProbingMaxDistTxBx.Visibility = Windows.Visibility.Hidden
      ExtCornTypeTxBl.Visibility = Windows.Visibility.Hidden
      ExtCornTypeCmBx.Visibility = Windows.Visibility.Hidden
      IntCornTypeTxBl.Visibility = Windows.Visibility.Hidden
      IntCornTypeCmBx.Visibility = Windows.Visibility.Hidden
      CornSlowLenTxBl.Visibility = Windows.Visibility.Hidden
      CornSlowLenTxBx.Visibility = Windows.Visibility.Hidden
      CornSlowPercTxBl.Visibility = Windows.Visibility.Hidden
      CornSlowPercTxBx.Visibility = Windows.Visibility.Hidden
      LiHoleBrd.Visibility = Windows.Visibility.Hidden
      LiHoleTxBl.Visibility = Windows.Visibility.Hidden
      LiHoleChBx.Visibility = Windows.Visibility.Hidden
      LiHoleRadTxBl.Visibility = Windows.Visibility.Hidden
      LiHoleRadTxBx.Visibility = Windows.Visibility.Hidden
      LpTurnsTxBl.Visibility = Windows.Visibility.Hidden
      LpTurnsTxBx.Visibility = Windows.Visibility.Hidden
      HpTurnsTxBl.Visibility = Windows.Visibility.Hidden
      HpTurnsTxBx.Visibility = Windows.Visibility.Hidden
   End Sub

   Private Sub MachiningTreeView_PreviewMouseUp(sender As Object, e As MouseButtonEventArgs) Handles MachiningTreeView.PreviewMouseUp
      ' Se necessario, chiedo se salvare l'utensile corrente
      If Not SaveCurrMachining() Then
         Dim PreviousMachining As CustomItem = m_OldItem
         PreviousMachining.IsSelected = True
         Exit Sub
      End If
      ' Aggiorno
      If TypeOf MachiningTreeView.SelectedItem Is CathegoryItem Then
         Dim SelectedCathegory As CathegoryItem = MachiningTreeView.SelectedItem
         SelectedCathegory.IsExpanded = Not SelectedCathegory.IsExpanded
         HideMachiningParams()
      ElseIf TypeOf MachiningTreeView.SelectedItem Is CustomItem Then
         Dim SelectedMachining As CustomItem = MachiningTreeView.SelectedItem
         EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
         EgtMdbSetCurrMachining(SelectedMachining.Name)
         ViewMachiningParams()
         GetMachiningParams()
      End If
      m_OldItem = MachiningTreeView.SelectedItem
   End Sub

   Friend Function SaveCurrMachining() As Boolean
      SetMachiningParams()
      If EgtMdbIsCurrMachiningModified() Then
         Dim SaveCurrMachiningWnd As New EgtMsgBox(m_MainWindow, "", EgtMsg(MSG_EGTMSGBOX + 3), EgtMsgBox.Buttons.YES_NO_CANCEL, EgtMsgBox.Icons.NULL)
         Select Case SaveCurrMachiningWnd.m_nPressedBtn
            Case 0    ' Annulla
               Return False
            Case 1    ' Si
               EgtMdbSaveCurrMachining()
               Dim CurrMachining As CustomItem = TryCast(m_OldItem, CustomItem)
               If CurrMachining IsNot Nothing Then
                  CurrMachining.Name = NameTxBx.Text
               End If
            Case 2    ' No
               EgtMdbSetCurrMachining(m_sMachiningName)
               GetMachiningParams()
         End Select
      End If
      Return True
   End Function

   Private Sub NameTxBx_EgtClosed(sender As Object, e As EventArgs) Handles NameTxBx.EgtClosed
      ' Elimino spazi iniziali e finali
      NameTxBx.Text = NameTxBx.Text.Trim()
      ' Se cambiato nome
      If NameTxBx.Text <> m_sMachiningName Then
         ' Imposto contesto macchina
         EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
         ' Verifico se nome già esistente
         Dim TempName As String = NameTxBx.Text
         EgtMdbGetMachiningNewName(TempName)
         ' se già esistente, avviso e rifiuto
         If TempName <> NameTxBx.Text Then
            ' Nome già utilizzato
            Dim InfoBox As New EgtMsgBox(m_MainWindow, "", EgtMsg(91104), EgtMsgBox.Buttons.OK, EgtMsgBox.Icons.ESCLAMATION)
            ' Ripristino il precedente
            NameTxBx.Text = m_sMachiningName
         End If
      End If
   End Sub

   Private Sub DepthTxBx_EgtClosed(sender As Object, e As EventArgs) Handles DepthTxBx.EgtClosed
      ' Non devo fare alcunchè
   End Sub

   Private Sub MaterialsList_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles MaterialsList.SelectionChanged
      Dim Selectedmaterial As MachiningMaterial = MaterialsList.SelectedItem
      If Not IsNothing(Selectedmaterial) Then
         If Selectedmaterial.bIsActive Then
            MinThicknessTxBx.Text = LenToString(Selectedmaterial.dMinThickness, 3)
            MaxThicknessTxBx.Text = LenToString(Selectedmaterial.dMaxThickness, 3)
         Else
            MinThicknessTxBx.Text = "0"
            MaxThicknessTxBx.Text = "0"
         End If
      End If
   End Sub

   Private Sub MinThicknessTxBx_EgtClosed(sender As Object, e As EventArgs) Handles MinThicknessTxBx.EgtClosed
      Dim SelectedMaterial As MachiningMaterial = MaterialsList.SelectedItem
      StringToLen(MinThicknessTxBx.Text, SelectedMaterial.dMinThickness)
      SelectedMaterial.VerifyIfActive()
   End Sub

   Private Sub MaxThicknessTxBx_EgtClosed(sender As Object, e As EventArgs) Handles MaxThicknessTxBx.EgtClosed
      Dim SelectedMaterial As MachiningMaterial = MaterialsList.SelectedItem
      Dim dMaxThick As Double = 0
      If m_MainWindow.m_CurrentMachine.bWaterJet And m_MainWindow.m_CurrentMachine.bFromDBWaterJet Then
         ' solo per water jet controllo lo spessore massimo ammissibile
         dMaxThick = m_MainWindow.m_CurrentMachine.GetMaxThicknessCurrMaterial(SelectedMaterial.Name)
         Dim dVal As Double
         StringToLen(MaxThicknessTxBx.Text, dVal)
         If dVal > dMaxThick Then
            MaxThicknessTxBx.Text = LenToString(dMaxThick, 3)
         End If
      End If
      StringToLen(MaxThicknessTxBx.Text, SelectedMaterial.dMaxThickness)
      SelectedMaterial.VerifyIfActive()
   End Sub

   Private Sub ToolCmBx_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles ToolCmBx.SelectionChanged
      EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
      ' Utensile selezionato
      If IsNothing(ToolCmBx.SelectedItem) Then Return
      Dim SelTool As String = ToolCmBx.SelectedItem.ToString()
      ' Utensile della lavorazione
      Dim CurrTool As String = String.Empty
      EgtMdbGetCurrMachiningParam(MCH_MP.TOOL, CurrTool)
      ' Se uguali non devo fare alcunchè
      If String.Compare(SelTool, CurrTool, True) = 0 Then Return
      ' Imposto il nuovo utensile
      EgtMdbSetCurrMachiningParam(MCH_MP.TOOL, SelTool)
      ' rendo default speed, feed e sovramateriali
      EgtMdbSetCurrMachiningParam(MCH_MP.SPEED, 0.0)
      EgtMdbSetCurrMachiningParam(MCH_MP.FEED, 0.0)
      EgtMdbSetCurrMachiningParam(MCH_MP.TIPFEED, 0.0)
      EgtMdbSetCurrMachiningParam(MCH_MP.STARTFEED, 0.0)
      EgtMdbSetCurrMachiningParam(MCH_MP.ENDFEED, 0.0)
      EgtMdbSetCurrMachiningParam(MCH_MP.BACKFEED, 0.0)
      EgtMdbSetCurrMachiningParam(MCH_MP.SIDEANGFEED, 0.0)
      EgtMdbSetCurrMachiningParam(MCH_MP.OFFSR, 9999999.0)
      EgtMdbSetCurrMachiningParam(MCH_MP.OFFSL, 9999999.0)
      ' aggiorno i valori in interfaccia
      Dim ToolDouble As Double
      EgtMdbGetCurrMachiningParam(MCH_MP.SPEED, ToolDouble)
      SpeedTxBx.Text = DoubleToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.FEED, ToolDouble)
      FeedTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.STARTFEED, ToolDouble)
      StartFeedTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.ENDFEED, ToolDouble)
      EndFeedTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.TIPFEED, ToolDouble)
      TipFeedTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.BACKFEED, ToolDouble)
      BackFeedTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.SIDEANGFEED, ToolDouble)
      SideAngCutTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.OFFSR, ToolDouble)
      RadOffsetTxBx.Text = LenToString(ToolDouble, 3)
      EgtMdbGetCurrMachiningParam(MCH_MP.OFFSL, ToolDouble)
      LonOffsetTxBx.Text = LenToString(ToolDouble, 3)
   End Sub

   ' Funzione che carica liste parametri dinamiche
   Private Sub LoadDynamicParamList(nMachiningType As Integer)
      Select Case nMachiningType
         Case MCH_MY.SAWING        'Taglio
            LeadInTypeCmBx.ItemsSource = New ObservableCollection(Of IdNameStruct)(
                                          {New IdNameStruct(MCH_SAW_LI.CENT, EgtMsg(MSG_COMBOBOXPARAM + 21)),
                                           New IdNameStruct(MCH_SAW_LI.STRICT, EgtMsg(MSG_COMBOBOXPARAM + 25)),
                                           New IdNameStruct(MCH_SAW_LI.OUT, EgtMsg(MSG_COMBOBOXPARAM + 26)),
                                           New IdNameStruct(MCH_SAW_LI.EXT_CENT, EgtMsg(MSG_COMBOBOXPARAM + 27)),
                                           New IdNameStruct(MCH_SAW_LI.EXT_OUT, EgtMsg(MSG_COMBOBOXPARAM + 28))})
            LeadOutTypeCmBx.ItemsSource = New ObservableCollection(Of IdNameStruct)(
                                          {New IdNameStruct(MCH_SAW_LO.CENT, EgtMsg(MSG_COMBOBOXPARAM + 21)),
                                           New IdNameStruct(MCH_SAW_LO.STRICT, EgtMsg(MSG_COMBOBOXPARAM + 25)),
                                           New IdNameStruct(MCH_SAW_LO.OUT, EgtMsg(MSG_COMBOBOXPARAM + 26)),
                                           New IdNameStruct(MCH_SAW_LO.EXT_CENT, EgtMsg(MSG_COMBOBOXPARAM + 27)),
                                           New IdNameStruct(MCH_SAW_LO.EXT_OUT, EgtMsg(MSG_COMBOBOXPARAM + 28))})
         Case MCH_MY.MILLING
            LeadInTypeCmBx.ItemsSource = New ObservableCollection(Of IdNameStruct)(
                                          {New IdNameStruct(MCH_MIL_LI.NONE, EgtMsg(MSG_COMBOBOXPARAM + 42)),
                                           New IdNameStruct(MCH_MIL_LI.GLIDE, EgtMsg(MSG_COMBOBOXPARAM + 48))})
            LeadOutTypeCmBx.ItemsSource = New ObservableCollection(Of IdNameStruct)(
                                         {New IdNameStruct(MCH_MIL_LO.NONE, EgtMsg(MSG_COMBOBOXPARAM + 42)),
                                          New IdNameStruct(MCH_MIL_LO.GLIDE, EgtMsg(MSG_COMBOBOXPARAM + 48)),
                                          New IdNameStruct(MCH_MIL_LO.AS_LI, EgtMsg(MSG_COMBOBOXPARAM + 50))})
         Case MCH_MY.POCKETING
            LeadInTypeCmBx.ItemsSource = New ObservableCollection(Of IdNameStruct)(
                                          {New IdNameStruct(MCH_POCK_LI.NONE, EgtMsg(MSG_COMBOBOXPARAM + 42)),
                                           New IdNameStruct(MCH_POCK_LI.ZIGZAG, EgtMsg(MSG_COMBOBOXPARAM + 38)),
                                           New IdNameStruct(MCH_POCK_LI.HELIX, EgtMsg(MSG_COMBOBOXPARAM + 49))})
            LeadOutTypeCmBx.ItemsSource = New ObservableCollection(Of IdNameStruct)(
                                          {New IdNameStruct(MCH_POCK_LO.NONE, EgtMsg(MSG_COMBOBOXPARAM + 42)),
                                           New IdNameStruct(MCH_POCK_LO.GLIDE, EgtMsg(MSG_COMBOBOXPARAM + 48))})
         Case MCH_MY.WATERJETTING
            LeadInTypeCmBx.ItemsSource = New ObservableCollection(Of IdNameStruct)(
                                          {New IdNameStruct(MCH_MIL_LI.NONE, EgtMsg(MSG_COMBOBOXPARAM + 42)),
                                           New IdNameStruct(MCH_MIL_LI.LINEAR, EgtMsg(MSG_COMBOBOXPARAM + 46)),
                                           New IdNameStruct(MCH_MIL_LI.TANGENT, EgtMsg(MSG_COMBOBOXPARAM + 47))})
            LeadOutTypeCmBx.ItemsSource = New ObservableCollection(Of IdNameStruct)(
                                         {New IdNameStruct(MCH_MIL_LO.NONE, EgtMsg(MSG_COMBOBOXPARAM + 42)),
                                          New IdNameStruct(MCH_MIL_LO.LINEAR, EgtMsg(MSG_COMBOBOXPARAM + 46)),
                                          New IdNameStruct(MCH_MIL_LO.TANGENT, EgtMsg(MSG_COMBOBOXPARAM + 47)),
                                          New IdNameStruct(MCH_MIL_LO.AS_LI, EgtMsg(MSG_COMBOBOXPARAM + 50))})
         Case Else
            LeadInTypeCmBx.ItemsSource = Nothing
            LeadOutTypeCmBx.ItemsSource = Nothing
      End Select
   End Sub

End Class

Public Structure IdNameStruct

   Private m_Id As Integer
   Public Property Id As Integer
      Get
         Return m_Id
      End Get
      Set(value As Integer)
         m_Id = value
      End Set
   End Property

   Private m_Name As String
   Public Property Name As String
      Get
         Return m_Name
      End Get
      Set(value As String)
         m_Name = value
      End Set
   End Property

   Sub New(Id As Integer, Name As String)
      m_Id = Id
      m_Name = Name
   End Sub

   Public Overrides Function ToString() As String
      Return Name
   End Function

   Friend Shared Function IndFromId(Id As Integer, List As ObservableCollection(Of IdNameStruct)) As Integer
      For i As Integer = 0 To List.Count - 1
         If List(i).Id = Id Then Return i
      Next
      Return 0
   End Function

   Friend Shared Function IdFromInd(Ind As Integer, List As ObservableCollection(Of IdNameStruct)) As Integer
      Return List(Ind).Id
   End Function

End Structure

Class MachiningMaterial
   Implements INotifyPropertyChanged

   Private m_nId As Integer
   Private m_nSubId As Integer
   Private m_sName As String
   Private m_dMinThickness As Double
   Private m_dMaxThickness As Double
   Private m_bIsActive As Boolean

   Public ReadOnly Property nId As Integer
      Get
         Return m_nId
      End Get
   End Property

   Public ReadOnly Property nSubId As Integer
      Get
         Return m_nSubId
      End Get
   End Property

   Public ReadOnly Property Name As String
      Get
         Return m_sName
      End Get
   End Property

   Public Property dMinThickness As Double
      Get
         Return m_dMinThickness
      End Get
      Set(value As Double)
         m_dMinThickness = value
      End Set
   End Property

   Public Property dMaxThickness As Double
      Get
         Return m_dMaxThickness
      End Get
      Set(value As Double)
         m_dMaxThickness = value
      End Set
   End Property

   Public ReadOnly Property bIsActive As Boolean
      Get
         Return m_bIsActive
      End Get
   End Property

   Sub New(nId As Integer, sName As String)
      m_nId = nId
      m_sName = sName
      m_dMinThickness = 0
      m_dMaxThickness = 0
      m_bIsActive = False
   End Sub

   Sub New(nId As Integer, sName As String, nSubId As Integer)
      m_nId = nId
      m_nSubId = nSubId
      m_sName = sName
      m_dMinThickness = 0
      m_dMaxThickness = 0
      m_bIsActive = False
   End Sub

   Public Sub VerifyIfActive()
      Dim bIsActive As Boolean = ( m_dMaxThickness > m_dMinThickness + EPS_SMALL)
      If bIsActive <> m_bIsActive Then
         m_bIsActive = bIsActive
         NotifyPropertyChanged("bIsActive")
      End If
   End Sub

   Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged

   Public Sub NotifyPropertyChanged(propName As String)
      RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName))
   End Sub

End Class