Imports System.Collections.ObjectModel
Imports EgtUILib
Imports EgtWPFLib5
Imports System.IO
Public Class OptionWindowVM
Inherits VMBase
#Region "FIELD & PROPERTIES"
Public ReadOnly Property LanguageList As ObservableCollection(Of Language)
Get
Return OptionModule.m_LanguageList
End Get
End Property
Public Property SelectedLanguage As Language
Get
Return OptionModule.m_SelectedLanguage
End Get
Set(value As Language)
If value IsNot OptionModule.m_SelectedLanguage Then
OptionModule.m_SelectedLanguage = value
WriteMainPrivateProfileString(S_GENERAL, K_MESSAGES, OptionModule.m_SelectedLanguage.Name)
End If
End Set
End Property
Public ReadOnly Property TopSceneBackground As Brush
Get
Return New SolidColorBrush(Color.FromArgb(CByte(255),
CByte(OptionModule.m_TopSceneBackground.R),
CByte(OptionModule.m_TopSceneBackground.G),
CByte(OptionModule.m_TopSceneBackground.B)))
End Get
End Property
Public ReadOnly Property BotSceneBackground As Brush
Get
Return New SolidColorBrush(Color.FromArgb(CByte(255),
CByte(OptionModule.m_BotSceneBackground.R),
CByte(OptionModule.m_BotSceneBackground.G),
CByte(OptionModule.m_BotSceneBackground.B)))
End Get
End Property
Public ReadOnly Property GridColor As Brush
Get
Return New SolidColorBrush(Color.FromArgb(CByte(255),
CByte(OptionModule.m_GridColor.R),
CByte(OptionModule.m_GridColor.G),
CByte(OptionModule.m_GridColor.B)))
End Get
End Property
Public Property ThickLine As Boolean
Get
Return OptionModule.m_bThickLine
End Get
Set(value As Boolean)
OptionModule.m_bThickLine = value
WriteMainPrivateProfileString(S_SCENE, K_LINEWIDTH, If(value, "2", "1"))
EgtSetLineAttribs(If(value, 2, 1))
End Set
End Property
Public Property SmoothTriMesh As Boolean
Get
Return OptionModule.m_bSmoothTriMesh
End Get
Set(value As Boolean)
OptionModule.m_bSmoothTriMesh = value
WriteMainPrivateProfileString(S_SCENE, K_SHOWTRIAADV, If(value, "1", "0"))
EgtSetShowTriaAdv(value)
End Set
End Property
' Definizione comandi
Private m_cmdTopSceneBackground As ICommand
Private m_cmdBotSceneBackground As ICommand
Private m_cmdGridColor As ICommand
Private m_cmdUpdateLicenceCmd As ICommand
Private m_cmdAddMachineCmd As ICommand
Private m_cmdExportMachineCmd As ICommand
#Region "Messages"
Public ReadOnly Property Title As String
Get
Return EgtMsg(5005)
End Get
End Property
Public ReadOnly Property LanguageAdvertMsg As String
Get
Return EgtMsg(6502)
End Get
End Property
Public ReadOnly Property TopSceneBackgroundMsg As String
Get
Return EgtMsg(6510)
End Get
End Property
Public ReadOnly Property BotSceneBackgroundMsg As String
Get
Return EgtMsg(6511)
End Get
End Property
Public ReadOnly Property GenericMsg As String
Get
Return EgtMsg(6514)
End Get
End Property
Public ReadOnly Property GridColorMsg As String
Get
Return EgtMsg(6517)
End Get
End Property
Public ReadOnly Property SmoothTriMeshMsg As String
Get
Return EgtMsg(6518)
End Get
End Property
Public ReadOnly Property ThickLineMsg As String
Get
Return EgtMsg(6536)
End Get
End Property
Public ReadOnly Property UpdateLicenceMsg As String
Get
Return EgtMsg(6553)
End Get
End Property
#End Region ' Messages
#End Region ' Field & Properties
#Region "METHODS"
'''
''' Funzione che permette di selezionare il colore per modificare la scena
'''
''' colore di base
''' colore nuovo
'''
Private Function SelectColor(Col As Color3d, ByRef NewCol As Color3d) As Boolean
' Recupero colori custom
Dim sCustomColors As String = ""
GetMainPrivateProfileString(S_COLORS, K_CUSTOMCOLORS, "", sCustomColors)
Dim CustomColors() As String = sCustomColors.Split(","c)
Dim nCustomColors As New List(Of Integer)
For Each Color In CustomColors
Dim nColor As Integer
If Integer.TryParse(Color, nColor) Then
nCustomColors.Add(nColor)
End If
Next
' Creo dialogo colori
Dim ColorDlg As New EgtColorPickerV(Application.Current.MainWindow, New EgtColorPickerVM()) With {
.CustomColors = nCustomColors.ToArray(),
.Color = Col.ToColor()
}
' Visualizzo dialogo
If ColorDlg.ShowDialog() <> Windows.Forms.DialogResult.OK Then Return False
'Recupero colore scelto
NewCol.FromColor(ColorDlg.Color)
''Salvo eventuali modifiche ai colori custom
sCustomColors = ""
For Each Color In ColorDlg.CustomColors
sCustomColors &= Color.ToString() & ","
Next
sCustomColors = sCustomColors.Trim({" "c, ","c})
WriteMainPrivateProfileString(S_COLORS, K_CUSTOMCOLORS, sCustomColors)
Return True
End Function
#End Region ' Methods
#Region "COMMANDS"
#Region "TopSceneBackgroundCmd"
Public ReadOnly Property TopSceneBackground_Command() As ICommand
Get
If m_cmdTopSceneBackground Is Nothing Then
m_cmdTopSceneBackground = New Command(AddressOf TopSceneBackgroundCmd)
End If
Return m_cmdTopSceneBackground
End Get
End Property
'''
''' Funzione che permette di cambiare sfondo alla parte superiore della scena
'''
Public Sub TopSceneBackgroundCmd()
' Recupero colore da Ini
Dim BackTopColor As New Color3d(192, 192, 192)
GetMainPrivateProfileColor(S_SCENE, K_BACKTOP, BackTopColor)
' Eseguo modifica con dialogo
If SelectColor(BackTopColor, BackTopColor) Then
OptionModule.m_TopSceneBackground = BackTopColor
Map.refSceneHostVM.MainScene.SetViewBackground(OptionModule.m_TopSceneBackground, OptionModule.m_BotSceneBackground)
WritePrivateProfileColor(S_SCENE, K_BACKTOP, OptionModule.m_TopSceneBackground)
NotifyPropertyChanged(NameOf(TopSceneBackground))
End If
End Sub
#End Region ' TopSceneBackgroundCmd
#Region "BotSceneBackgroundCmd"
Public ReadOnly Property BotSceneBackground_Command() As ICommand
Get
If m_cmdBotSceneBackground Is Nothing Then
m_cmdBotSceneBackground = New Command(AddressOf BotSceneBackgroundCmd)
End If
Return m_cmdBotSceneBackground
End Get
End Property
'''
''' Funzione che permette di cambiare sfondo alla parte inferiore della scena
'''
Public Sub BotSceneBackgroundCmd()
' Recupero colore da Ini
Dim BackBotColor As New Color3d(192, 192, 192)
GetMainPrivateProfileColor(S_SCENE, K_BACKBOTTOM, BackBotColor)
' Eseguo modifica con dialogo
If SelectColor(BackBotColor, BackBotColor) Then
OptionModule.m_BotSceneBackground = BackBotColor
Map.refSceneHostVM.MainScene.SetViewBackground(OptionModule.m_TopSceneBackground, OptionModule.m_BotSceneBackground)
WritePrivateProfileColor(S_SCENE, K_BACKBOTTOM, OptionModule.m_BotSceneBackground)
NotifyPropertyChanged(NameOf(BotSceneBackground))
End If
End Sub
#End Region ' BotSceneBackgroundCmd
#Region "GridColorCmd"
Public ReadOnly Property GridColor_Command() As ICommand
Get
If m_cmdGridColor Is Nothing Then
m_cmdGridColor = New Command(AddressOf GridColorCmd)
End If
Return m_cmdGridColor
End Get
End Property
'''
''' Funzione che permette di cambiare sfondo alla griglia della scena
'''
Public Sub GridColorCmd()
' Recupero colore da Ini
Dim GridColor As New Color3d(192, 192, 192)
GetMainPrivateProfileColor(S_GRID, K_MINLNCOLOR, GridColor)
' Eseguo modifica con dialogo
If SelectColor(GridColor, GridColor) Then
OptionModule.m_GridColor = GridColor
EgtSetGridColor(GridColor, GridColor)
WritePrivateProfileColor(S_GRID, K_MINLNCOLOR, OptionModule.m_GridColor)
WritePrivateProfileColor(S_GRID, K_MAJLNCOLOR, OptionModule.m_GridColor)
EgtDraw()
NotifyPropertyChanged(NameOf(GridColor))
End If
End Sub
#End Region ' GridColorCmd
#Region "UpdateLicenceCmd"
Public ReadOnly Property UpdateLicence_Command() As ICommand
Get
If m_cmdUpdateLicenceCmd Is Nothing Then
m_cmdUpdateLicenceCmd = New Command(AddressOf UpdateLicenceCmd)
End If
Return m_cmdUpdateLicenceCmd
End Get
End Property
'''
''' Funzione che permette l'update della licenza
'''
Public Sub UpdateLicenceCmd()
' Apro dialogo per richiesta file licenza
Dim LicDlg As New EgtManageFileDialogV(Application.Current.MainWindow, New EgtManageFileDialogVM()) With {
.Title = "Licence",
.InitialDirectory = Map.refMainWindowVM.MainWindowM.sConfigDir,
.Filter = "Licences (.lic)|*.lic",
.FilterIndex = 1,
.CheckFileExists = True,
.ValidateNames = True
}
If LicDlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
' Recupero il direttorio del file
Dim sDir As String = Path.GetDirectoryName(LicDlg.FileName)
' Se il file non è già nel direttorio di configurazione lo copio
If Not String.Equals(Path.GetFullPath(sDir), Path.GetFullPath(Map.refMainWindowVM.MainWindowM.sConfigDir), StringComparison.OrdinalIgnoreCase) Then
Try
File.Copy(LicDlg.FileName, Path.Combine(Map.refMainWindowVM.MainWindowM.sConfigDir, LicDlg.SafeFileName), True)
Catch ex As Exception
Return
End Try
End If
' Imposto il nuovo file di licenza nell'Ini
WriteMainPrivateProfileString(S_GENERAL, K_LICENCE, LicDlg.SafeFileName)
End If
End Sub
#End Region ' UpdateLicenceCmd
#End Region ' Commands
End Class