Imports EgtUILib

Public Class FiloTopUC

   ' Riferimento alla MainWindow
   Private m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow)
   ' Riferimento alla pagina che ha aperto SideAngleUC
   Private m_CallingPage As MainWindow.Pages

   ' Offset della sfilettatura
   Private m_dFiloTopOffset As Double = 0
   Friend ReadOnly Property FiloTopOffset As Double
      Get
         Return m_dFiloTopOffset
      End Get
   End Property

   ' Profondità della sfilettatura
   Private m_dFiloTopDepth As Double = 0
   Friend ReadOnly Property FiloTopDepth As Double
      Get
         Return m_dFiloTopDepth
      End Get
   End Property


   Private Sub FiloTopUC_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
      ' Imposto riferimenti ad altre pagine
      m_CallingPage = m_MainWindow.m_ActivePage

      ' Imposto messaggi
      ParameterTxBl.Text = EgtMsg( MSG_IMPORTPAGEUC + 10)       ' Offset
      Parameter2TxBl.Text = EgtMsg( MSG_IMPORTPAGEUC + 11)      ' Affondamento

      If m_CallingPage = MainWindow.Pages.Draw Then
         ' Imposto questa come pagina correntemente visualizzata nella drawpage
         m_MainWindow.m_DrawPageUC.m_ActiveComponentPage = DrawPageUC.Pages.FiloTop
         ' Imposto contesto corrente
         EgtSetCurrentContext( m_MainWindow.m_DrawPageUC.DrawScene.GetCtx())
      ElseIf m_CallingPage = MainWindow.Pages.Import Then
         ' Imposto contesto corrente
         EgtSetCurrentContext( m_MainWindow.m_ImportPageUC.ImportScene.GetCtx())
      End If

      ' Gestisco visualizzazione dei parametri
      Parameter2TxBl.Visibility = Windows.Visibility.Visible
      Parameter2TxBx.Visibility = Windows.Visibility.Visible

      ' Aggiorno valori
      m_dFiloTopOffset = GetPrivateProfileDouble( S_SIDES, K_FILOTOPOFFSET, 5, m_MainWindow.GetIniFile())
      ParameterTxBx.Text = LenToString( m_dFiloTopOffset, 3)
      m_dFiloTopDepth = GetPrivateProfileDouble( S_SIDES, K_FILOTOPDEPTH, 5, m_MainWindow.GetIniFile())
      Parameter2TxBx.Text = LenToString( m_dFiloTopDepth, 3)
   End Sub

   Private Sub FiloTopUC_Unloaded(sender As Object, e As RoutedEventArgs) Handles Me.Unloaded
      EgtDraw()
   End Sub

   Private Sub ParameterTxBx_EgtClosed(sender As Object, e As EventArgs) Handles ParameterTxBx.EgtClosed
      ' Recupero il valore
      StringToLen(ParameterTxBx.Text, m_dFiloTopOffset)
      WritePrivateProfileString(S_SIDES, K_FILOTOPOFFSET, DoubleToString(m_dFiloTopOffset, 2), m_MainWindow.GetIniFile())
      ' Aggiorno affondamento del profilo
      Dim nPartId As Integer = EgtGetFirstPart()
      While nPartId <> GDB_ID.NULL
         Dim nLayId As Integer = EgtGetFirstLayer(nPartId)
         While nLayId <> GDB_ID.NULL
            Dim sLayName As String = ""
            If EgtGetName( nLayId, sLayName) AndAlso sLayName = NAME_INLOOP AndAlso EgtExistsInfo( nLayId, INFO_FILOTOP) Then
               EgtSetInfo( nLayId, INFO_OFFSET, m_dFiloTopOffset)
            End If
            nLayId = EgtGetNextLayer(nLayId)
         End While
         nPartId = EgtGetNextPart(nPartId)
      End While
   End Sub

   Private Sub Parameter2TxBx_EgtClosed(sender As Object, e As EventArgs) Handles Parameter2TxBx.EgtClosed
      ' Recupero il valore
      StringToLen(Parameter2TxBx.Text, m_dFiloTopDepth)
      WritePrivateProfileString(S_SIDES, K_FILOTOPDEPTH, DoubleToString(m_dFiloTopDepth, 2), m_MainWindow.GetIniFile())
      ' Aggiorno affondamento del profilo
      Dim nPartId As Integer = EgtGetFirstPart()
      While nPartId <> GDB_ID.NULL
         Dim nLayId As Integer = EgtGetFirstLayer(nPartId)
         While nLayId <> GDB_ID.NULL
            Dim sLayName As String = ""
            If EgtGetName( nLayId, sLayName) AndAlso sLayName = NAME_INLOOP AndAlso EgtExistsInfo( nLayId, INFO_FILOTOP) Then
               EgtSetInfo( nLayId, INFO_DEPTH, m_dFiloTopDepth)
            End If
            nLayId = EgtGetNextLayer(nLayId)
         End While
         nPartId = EgtGetNextPart(nPartId)
      End While
   End Sub

End Class
