Imports System.Collections.ObjectModel
Imports EgtUILib
Imports EgtWPFLib5

Public Class FreeContourInputVM
   Inherits VMBase

#Region "FIELDS & PROPERTIES"

   Private m_Title As String
   Public Property Title As String
      Get
         Return m_Title
      End Get
      Set(value As String)
         m_Title = value
         NotifyPropertyChanged(NameOf(Title))
      End Set
   End Property

   ' TextBlock fields
   Private m_Message As String
   Public Property Message As String
      Get
         Return m_Message
      End Get
      Set(value As String)
         m_Message = value
         NotifyPropertyChanged(NameOf(Message))
      End Set
   End Property

   ' TextBox fields
   Private m_Text As String
   Public Property Text As String
      Get
         Return m_Text
      End Get
      Set(value As String)
         m_Text = value
         'Map.refProjectVM.NotifyInputText(value)
         NotifyPropertyChanged(NameOf(Text))
      End Set
   End Property

   Private m_Text_Visibility As Visibility
   Public Property Text_Visibility As Visibility
      Get
         Return m_Text_Visibility
      End Get
      Set(value As Visibility)
         If value <> m_Text_Visibility Then
            m_Text_Visibility = value
            NotifyPropertyChanged(NameOf(Text_Visibility))
         End If
      End Set
   End Property

   Private m_Message_Visibility As Visibility
   Public Property Message_Visibility As Visibility
      Get
         Return m_Message_Visibility
      End Get
      Set(value As Visibility)
         If value <> m_Message_Visibility Then
            m_Message_Visibility = value
            NotifyPropertyChanged(NameOf(Message_Visibility))
         End If
      End Set
   End Property

   Private m_FocusTextBox As Boolean
   Public Property FocusTextBox As Boolean
      Get
         Return m_FocusTextBox
      End Get
      Set(value As Boolean)
         m_FocusTextBox = value
         NotifyPropertyChanged(NameOf(FocusTextBox))
      End Set
   End Property

   'CheckBox fields
   Private m_CheckBoxText As String
   Public Property CheckBoxText As String
      Get
         Return m_CheckBoxText
      End Get
      Set(value As String)
         m_CheckBoxText = value
         NotifyPropertyChanged(NameOf(CheckBoxText))
      End Set
   End Property

   Private m_IsChecked As Boolean = False
   Public Property IsChecked As Boolean
      Get
         Return m_IsChecked
      End Get
      Set(value As Boolean)
         If value <> m_IsChecked Then
            Map.refSceneHostVM.MainController.SetLastBoolean(value)
            m_IsChecked = value
            NotifyPropertyChanged(NameOf(IsChecked))
         End If
      End Set
   End Property

   Private m_Check_Visibility As Visibility
   Public Property Check_Visibility As Visibility
      Get
         Return m_Check_Visibility
      End Get
      Set(value As Visibility)
         If value <> m_Check_Visibility Then
            m_Check_Visibility = value
            NotifyPropertyChanged(NameOf(Check_Visibility))
         End If
      End Set
   End Property

   ' ComboBox fields
   Private m_ComboItemsList As New ObservableCollection(Of String)
   Public Property ComboItemsList As ObservableCollection(Of String)
      Get
         Return m_ComboItemsList
      End Get
      Set(value As ObservableCollection(Of String))
         m_ComboItemsList = value
         NotifyPropertyChanged(NameOf(ComboItemsList))
      End Set
   End Property

   Private m_ComboSelectedIndex As Integer
   Public Property ComboSelectedIndex As Integer
      Get
         Return m_ComboSelectedIndex
      End Get
      Set(value As Integer)
         Map.refSceneHostVM.MainController.SetLastInteger(value)
         m_ComboSelectedIndex = value
         NotifyPropertyChanged(NameOf(ComboSelectedIndex))
      End Set
   End Property

   Private m_Combo_Visibility As Visibility
   Public Property Combo_Visibility As Visibility
      Get
         Return m_Combo_Visibility
      End Get
      Set(value As Visibility)
         If value <> m_Combo_Visibility Then
            m_Combo_Visibility = value
            NotifyPropertyChanged(NameOf(Combo_Visibility))
         End If
      End Set
   End Property

   ' Buttons fields
   Private m_ShowBtn_Visibility As Visibility
   Public Property ShowBtn_Visibility As Visibility
      Get
         Return m_ShowBtn_Visibility
      End Get
      Set(value As Visibility)
         m_ShowBtn_Visibility = value
         NotifyPropertyChanged(NameOf(ShowBtn_Visibility))
      End Set
   End Property

   Private m_DoneBtn_Visibility As Visibility
   Public Property DoneBtn_Visibility As Visibility
      Get
         Return m_DoneBtn_Visibility
      End Get
      Set(value As Visibility)
         m_DoneBtn_Visibility = value
         NotifyPropertyChanged(NameOf(DoneBtn_Visibility))
      End Set
   End Property

   ' Commands definition
   Private m_cmdShow As ICommand
   Private m_cmdDone As ICommand

#Region "Messages"

   Public ReadOnly Property ShowMsg As String
      Get
         Return EgtMsg(5350 + 14)
      End Get
   End Property
   Public ReadOnly Property OkMsg As String
      Get
         Return EgtMsg(5350 + 15)
      End Get
   End Property

#End Region

#End Region    ' Fields & Properties

#Region "CONSTRUCTOR"

   Sub New()
      ' Creo riferimento a questa classe in EgtCAM5Map
      Map.SetRefFreeContourInputVM(Me)
      ' nascondo input box
      ResetInputBox()
   End Sub

#End Region    ' Constructor

#Region "METHODS"

   Friend Sub ShowMessage(sTitle As String, sLabel As String)
      Title = sTitle
      If sLabel <> "" Then
         Message = sLabel
         Message_Visibility = Visibility.Visible
      End If
   End Sub

   Friend Sub PrepareInputBox(sTitle As String, sLabel As String, sCheckLabel As String,
                                  bShowCombo As Boolean, bShowBtn As Boolean)
      Title = sTitle
      If sLabel <> "" Then
         Message = sLabel
         Text = ""
         Text_Visibility = Visibility.Visible
         Message_Visibility = Visibility.Visible
      End If
      'If sCheckLabel <> "" Then
      '   CheckBoxText = sCheckLabel
      '   Check_Visibility = Visibility.Visible
      'End If
      If bShowCombo Then
         ComboItemsList.Clear()
         Combo_Visibility = Visibility.Visible
      End If
      If bShowBtn Then
         ShowBtn_Visibility = Visibility.Visible
      End If
      DoneBtn_Visibility = Visibility.Visible
      FocusTextBox = True
   End Sub

   Friend Sub ResetInputBox()
      Title = EgtMsg(5350 + 5)
      Text_Visibility = Visibility.Collapsed
      Message_Visibility = Visibility.Collapsed
      Check_Visibility = Visibility.Collapsed
      Combo_Visibility = Visibility.Collapsed
      ShowBtn_Visibility = Visibility.Collapsed
      DoneBtn_Visibility = Visibility.Collapsed
   End Sub

   Friend Function SetInputBoxText(sVal As String) As Boolean
      Text = sVal
      FocusTextBox = True
      Return True
   End Function

   Friend Function ChangeInputBoxCheck() As Boolean
      IsChecked = Not m_IsChecked
      Return True
   End Function

   Friend Function SetInputBoxCheck(bCheck As Boolean) As Boolean
      IsChecked = bCheck
      Map.refSceneHostVM.MainController.SetLastBoolean(IsChecked)
      Return True
   End Function

   Friend Function AddInputBoxCombo(sText As String, bSelected As Boolean) As Boolean
      ComboItemsList.Add(sText)
      If bSelected Then
         ComboSelectedIndex = ComboItemsList.Count - 1
      End If
      Return True
   End Function

#End Region    ' METHODS

#Region "COMMANDS"

#Region "Show"

   ''' <summary>
   ''' Returns a command that do Point.
   ''' </summary>
   Public ReadOnly Property Show_Command As ICommand
      Get
         If m_cmdShow Is Nothing Then
            m_cmdShow = New Command(AddressOf Show)
         End If
         Return m_cmdShow
      End Get
   End Property

   ''' <summary>
   ''' Execute the Point.  This method is invoked by the PointCommand.
   ''' </summary>
   Public Sub Show(ByVal param As Object)
      Map.refSceneHostVM.MainController.Show(m_Text)
   End Sub

#End Region ' Show

#Region "Done"

   ''' <summary>
   ''' Returns a command that do Point.
   ''' </summary>
   Public ReadOnly Property Done_Command As ICommand
      Get
         If m_cmdDone Is Nothing Then
            m_cmdDone = New Command(AddressOf Done)
         End If
         Return m_cmdDone
      End Get
   End Property

   ''' <summary>
   ''' Execute the Point.  This method is invoked by the PointCommand.
   ''' </summary>
   Public Sub Done(ByVal param As Object)
      If Map.refFreeContourManagerVM.bIsActive AndAlso Map.refFreeContourManagerVM.bIsModifyingTextAngle Then
         Map.refFreeContourManagerVM.CloseIsModifyingTextAngle(True)
      Else
         Map.refSceneHostVM.MainController.Done(m_Text)
      End If
   End Sub

#End Region ' Done

#End Region    ' COMMANDS

End Class
