Imports System.IO Imports System.Threading Imports EgtBEAMWALL.Core Imports EgtWPFLib5 Public Class MainWindowVM Inherits VMBase Private m_ViewerOptimizerCommThread As Thread ' Riferimento al Model della MainWindow Private m_MainWindowM As MainWindowM Friend ReadOnly Property MainWindowM As MainWindowM Get Return m_MainWindowM End Get End Property ' Titolo Private m_Title As String Public ReadOnly Property Title As String Get Return m_Title End Get End Property ' proprietà che seleziona la giusta pagina del TabControl Public Property nSelTabPage As Integer Get Return If(IsNothing(Map.refMainMenuVM.SelPage) OrElse Map.refMainMenuVM.SelPage = -1 OrElse Map.refMainMenuVM.SelPage = Pages.SUPERVISOR, 0, 1) End Get Set(value As Integer) End Set End Property ' Definizione comandi Private m_cmdAboutBox As ICommand Private m_cmdCloseApplication As ICommand #Region "CONSTRUCTOR" Sub New() ' Avvio l'inizializzazione della mappa passandogli il riferimento al MainWindowVM Map.BeginInit(Me) ' Creo Model della MainWindow m_MainWindowM = New MainWindowM End Sub #End Region ' CONSTRUCTOR #Region "METHODS" Friend Sub SetTitle(sTitle As String) m_Title = sTitle NotifyPropertyChanged(NameOf(Title)) End Sub Public Sub UpdateTitle() m_Title = Map.refSupervisorManagerVM.CurrProd.nProdId.ToString("0000") & " - EgtBEAMWALL" NotifyPropertyChanged(NameOf(Title)) End Sub Friend Sub ContentRendered() '' chiamata a caso su Db per inizializzarlo DbControllers.m_ProdController.FindByProdDbId(0) ' Verifico che l'inizializzazione di tutte le parti del programma sia andata a buon fine ' If Map.EndInit() Then ' m_bInitStatus = True ' altrimenti chiudo il programma ' Else ' m_bInitStatus = False ' End If ' Aggiorno visualizzazione unità di misura ' Map.refStatusBarVM.SetMeasureUnit(If(EgtUiUnitsAreMM(), MeasureUnitOpt.MM, MeasureUnitOpt.INCH)) ' Se istanza oltre la prima, chiedo cosa aprire ' If Not m_MainWindowM.bFirstInstance Then ' Map.refProjectManagerVM.Open() ' ' altrimenti verifico se richiesto ultimo progetto ' ElseIf GetMainPrivateProfileInt(S_GENERAL, K_AUTOLOADLASTPROJ, 0) = 1 Then ' Dim sLastProjectPath As String = String.Empty ' GetMainPrivateProfileString(S_GENERAL, K_LASTPROJ, String.Empty, sLastProjectPath) ' If Not String.IsNullOrWhiteSpace(sLastProjectPath) AndAlso File.Exists(sLastProjectPath) Then ' Map.refProjectManagerVM.OpenProject(sLastProjectPath) ' Else ' Map.refProjectManagerVM.NewCmd() ' End If ' ' altrimenti nuovo progetto ' Else ' Map.refProjectManagerVM.NewCmd() ' End If ' apro in modalita' VIEW ' Map.refMainMenuVM.SelPage = Pages.VIEW ' setto il primo file dalla lista degli MRU come prod corrente da aprire Dim sLastProdPath As String = String.Empty GetMainPrivateProfileString(S_MRUSUPERVISORPRODFILES, K_FILE & "1", String.Empty, sLastProdPath) If Not String.IsNullOrWhiteSpace(sLastProdPath) AndAlso File.Exists(sLastProdPath) Then ' ricavo l'Id e il prod associato per l'apertura di quest'ultimo Dim PdId As Integer = 0 Dim sPdId As String = Path.GetFileNameWithoutExtension(sLastProdPath) Integer.TryParse(sPdId, PdId) Map.refSupervisorManagerVM.SetCurrProd(PdId) ' apro prod If Not IsNothing(Map.refSupervisorManagerVM.CurrProd) Then Map.refSupervisorManagerVM.OpenProject(Map.refSupervisorManagerVM.CurrProd) End If ' apro in modalita' SUPERVISOR Map.refMainMenuVM.SelPage = Pages.SUPERVISOR Map.refLeftPanelVM.NotifyPropertyChanged(NameOf(Map.refLeftPanelVM.FeatureList_Visibility)) ' inizializzo thread di aggiornamento e comunicazione con DB ' creo thread gestione macchina m_ViewerOptimizerCommThread = New Thread(Sub() ViewerOptimizerCommThread.ViewerOptimizerCommThreadFunction() End Sub) m_ViewerOptimizerCommThread.SetApartmentState(ApartmentState.STA) ' avvio thread di gestione della macchina che avvia la connessione m_ViewerOptimizerCommThread.Start() End Sub Friend Sub KeyDown(PressedKey As Key) ' Con ESC esco dall'azione corrente If PressedKey = Key.Escape Then ' se in ripartenza If Map.refLeftPanelVM.bRestart Then ' sblocco interfaccia Map.refLeftPanelVM.bRestart = False End If '' se misura attiva, la disattivo 'If Map.refInstrumentPanelVM.GetDistIsChecked Then ' Map.refInstrumentPanelVM.SetGetDistance_IsChecked(False) 'End If ' pulisco output Map.refMyStatusBarVM.ClearOutputMessage() End If End Sub #End Region ' METHODS #Region "COMMANDS" #Region "AboutBoxCommand" ' Returns a command that manage the MainWindow_Unloaded command Public ReadOnly Property AboutBox_Command As ICommand Get If m_cmdAboutBox Is Nothing Then m_cmdAboutBox = New Command(AddressOf AboutBox) End If Return m_cmdAboutBox End Get End Property ' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded. Public Sub AboutBox(ByVal param As Object) Dim AboutBoxWindow As New AboutBoxV AboutBoxWindow.Owner = Application.Current.MainWindow AboutBoxWindow.ShowDialog() End Sub #End Region ' AboutBoxCommand #Region "CloseApplication" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property CloseApplication_Command As ICommand Get If m_cmdCloseApplication Is Nothing Then m_cmdCloseApplication = New Command(AddressOf CloseApplication) End If Return m_cmdCloseApplication End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub CloseApplication() ' disconnetto comunicazione con macchina MachManaging.CommandList.Add(ThreadCommand.CreateCommand(CommandTypes.DISCONNECT)) ' termino thread di comunicazione con Db ed altri programmi ViewerOptimizerCommThread.StopThread() ' Verifico modifica parametri in Configurazione e chiedo il salvataggio If Map.refMainMenuVM.SelPage = Pages.CONFIG Then Map.refConfigurationPageVM.VerifyConfigPageModification() ' Chiudo la finestra principale del programma Application.Current.MainWindow.Close() End Sub #End Region ' CloseApplication #End Region ' COMMANDS End Class