Imports System.Collections.ObjectModel Imports System.ComponentModel Imports System.IO Imports EgtUILib Imports EgtWPFLib5 Public Class CurrSetUpVM Inherits VMBase Private Const INVALIDPOS As String = "" Private m_Title As String Public ReadOnly Property Title As String Get Return EgtMsg(MSG_SETUP + 1) End Get End Property Private WithEvents m_SetUpVM As New SetUpVM Public ReadOnly Property SetUpVM As SetUpVM Get Return m_SetUpVM End Get End Property Private m_Apply_IsEnabled As Boolean = False Public ReadOnly Property Apply_IsEnabled As Boolean Get Return m_Apply_IsEnabled End Get End Property ' Immagine del porta utensili Public ReadOnly Property SetUpImage As String Get ' Cerco png Dim sImagePath As String = IniFile.m_sCurrMachSetUpDirPath & "\SetupImage.png" If File.Exists(sImagePath) Then Return sImagePath ' Cerco jpeg sImagePath = IniFile.m_sCurrMachSetUpDirPath & "\SetupImage.jpg" If File.Exists(sImagePath) Then Return sImagePath ' Cerco bmp sImagePath = IniFile.m_sCurrMachSetUpDirPath & "\SetupImage.bmp" If File.Exists(sImagePath) Then Return sImagePath ' Non trovato alcunché Return String.Empty End Get End Property ' path cartella attrezzaggi Private m_SetUpDir_FilePath As String #Region "Messages" Public ReadOnly Property TitleMsg As String Get Return EgtMsg(MSG_SETUP + 1) End Get End Property Public ReadOnly Property ApplyMsg As String Get Return EgtMsg(MSG_SETUP + 2) End Get End Property Public ReadOnly Property SaveMsg As String Get Return EgtMsg(MSG_SETUP + 3) End Get End Property Public ReadOnly Property RetrieveMsg As String Get Return EgtMsg(MSG_SETUP + 4) End Get End Property Public ReadOnly Property AutomaticMsg As String Get Return EgtMsg(MSG_SETUP + 5) End Get End Property #End Region ' Definizione comandi Private m_cmdApply As ICommand Private m_cmdSave As ICommand Private m_cmdRetrieve As ICommand Private m_cmdAutomatic As ICommand Private m_cmdCloseSetUp As ICommand Sub New() ' imposto path cartella attrezzaggi m_SetUpDir_FilePath = IniFile.m_sMachinesRoot & "\" & IniFile.m_sMachineName & "\SetUp" ' inizializzo le posizioni di attrezzaggio m_SetUpVM.InitSetUp() ' carico attrezzaggio corrente m_SetUpVM.LoadCurrentSetUp() End Sub ' Funzione che verifica se ci sono state modifiche all'attrezzaggio corrente e permette di attivare e disattivare il bottone applica Private Sub IsEnabledBtns() m_Apply_IsEnabled = Not m_SetUpVM.IsAppliedSetUp() NotifyPropertyChanged("Apply_IsEnabled") End Sub #Region "COMMANDS" #Region "ApplyCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property ApplyCommand As ICommand Get If m_cmdApply Is Nothing Then m_cmdApply = New Command(AddressOf Apply) End If Return m_cmdApply End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub Apply() ' applico il setup al progetto m_SetUpVM.Apply() ' aggiorno stato bottoni IsEnabledBtns() End Sub #End Region ' ApplyCommand #Region "Save" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property Save_Command As ICommand Get If m_cmdSave Is Nothing Then m_cmdSave = New Command(AddressOf Save) End If Return m_cmdSave End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub Save() ' chiedo il nome con cui salvare il setup Dim SaveFileDialogViewVM As New SaveFileDialogWithListVM With { .Title = EgtMsg(MSG_SETUP + 3) & " " & EgtMsg(MSG_SETUP + 1), .Extension = ".stu", .Filter = "*.stu", .Directory = m_SetUpDir_FilePath, .FileName = String.Empty } Dim SaveFileDialogView As New EgtWPFLib5.SaveFileDialogWithListV(Application.Current.MainWindow, SaveFileDialogViewVM) If Not SaveFileDialogView.ShowDialog() Then Return Dim sFilePath As String = String.Empty sFilePath = SaveFileDialogViewVM.FileName If Not m_SetUpVM.Save(sFilePath) Then EgtOutLog("Error in setup saving: can't find the directory") MessageBox.Show("Error in saving Setup.", "Error", MessageBoxButton.OK, MessageBoxImage.Error) End If End Sub #End Region ' Save #Region "Retrieve" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property Retrieve_Command As ICommand Get If m_cmdRetrieve Is Nothing Then m_cmdRetrieve = New Command(AddressOf Retrieve) End If Return m_cmdRetrieve End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub Retrieve() ' Direttorio per attrezzaggi Dim sDir As String = IniFile.m_sMachinesRoot & "\" & IniFile.m_sMachineName & "\SetUp" Dim sPath As String = String.Empty If Not Directory.Exists(sDir) Then EgtOutLog("Error in SetupDir retrieve : directory not found") Return End If ' Apertura dialogo di salvataggio Dim OpenFileDialogView As New EgtWPFLib5.EgtOpenFileDialog OpenFileDialogView.Title = EgtMsg(MSG_SETUP + 4) & " " & EgtMsg(MSG_SETUP + 1) OpenFileDialogView.Filter = "*.stu" OpenFileDialogView.Directory = sDir OpenFileDialogView.FileName = String.Empty If Not OpenFileDialogView.EgtShowDialog Then Return End If sPath = OpenFileDialogView.FileName m_SetUpVM.LoadSetupFromFile(Path.GetFileNameWithoutExtension(sPath), False) ' aggiorno stato bottoni IsEnabledBtns() End Sub #End Region ' Retrieve #Region "Automatic" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property Automatic_Command As ICommand Get If m_cmdAutomatic Is Nothing Then m_cmdAutomatic = New Command(AddressOf Automatic) End If Return m_cmdAutomatic End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub Automatic() m_SetUpVM.Automatic() End Sub #End Region ' Automatic #Region "CloseSetUpCommand" ''' ''' Returns a command that remove the current selected machining. ''' Public ReadOnly Property CloseSetUpCommand() As ICommand Get If m_cmdCloseSetUp Is Nothing Then m_cmdCloseSetUp = New RelayCommand(AddressOf CloseSetUp) End If Return m_cmdCloseSetUp End Get End Property ''' ''' Manage the MachiningDb closing. This method is invoked by the CloseMachiningDbCommand. ''' Public Sub CloseSetUp() ' Verifico se l'attrezzaggio è stato modificato If m_SetUpVM.IsAppliedSetUp() Then ' se modificato chiedo se salvarlo prima di uscire If MessageBox.Show(EgtMsg(MSG_SETUP + 6), EgtMsg(MSG_SETUP + 2), MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then ' lo salvo Apply() End If End If ' Resetto tutti i delegate usati ExitToolAssociation.m_delIsModifiedSetUp = Nothing ' Reset lua EgtLuaResetGlobVar("STU") ' Chiusura finestra For Each Window In Application.Current.Windows If TypeOf Window Is SetUpWindowV Then Dim SetUpWindow As SetUpWindowV = DirectCast(Window, SetUpWindowV) SetUpWindow.Close() End If Next End Sub #End Region ' CloseSetUpCommand #End Region ' Commands #Region "EVENTS" Private Sub m_SetUpVM_SetUp_IsModified() Handles m_SetUpVM.SetUp_IsModified ' aggiorno stato bottoni IsEnabledBtns() End Sub #End Region ' EVENTS End Class