Imports EgtUILib Imports EgtWPFLib5 Imports System.IO Imports System.Threading Imports System.Windows.Threading Public Class MainWindowVM Inherits VMBase Private m_SupervisorCommThread As Thread Private m_Supervisor_Timer As New DispatcherTimer ' Riferimento al Model della MainWindow Private m_MainWindowM As MainWindowM Friend ReadOnly Property MainWindowM As MainWindowM Get Return m_MainWindowM End Get End Property ' Variabile che indica che il programma è stato avviato correttamente (sia la mappa che l'ambiente Egt) Private m_bInitStatus As Boolean Friend ReadOnly Property bInitStatus As Boolean Get Return m_bInitStatus End Get End Property ' Titolo Private m_sTitle As String Public Property sTitle As String Get Return m_sTitle End Get Set(value As String) m_sTitle = value NotifyPropertyChanged(NameOf(sTitle)) End Set 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.VIEW OrElse Map.refMainMenuVM.SelPage = Pages.MACHINING, 0, 1) Return -1 End Get Set(value As Integer) End Set End Property Private m_MachinePanelVM As MachinePanelVM Public ReadOnly Property MachinePanelVM As MachinePanelVM Get Return m_MachinePanelVM End Get End Property 'Friend m_SupervisorStop As Boolean = False 'Private BlockedWnd As BlockedWndV ' 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 ' inizializzo machine panel m_MachinePanelVM = New MachinePanelVM ' inizializzo contatore per blocco da supervisore m_Supervisor_Timer.Interval = TimeSpan.FromMilliseconds(500) ' AddHandler m_Supervisor_Timer.Tick, AddressOf SupervisorTimer_Tick m_Supervisor_Timer.Start() End Sub #End Region ' CONSTRUCTOR '#Region "METHODS" Friend Sub SetTitle(sTitle As String) m_sTitle = sTitle NotifyPropertyChanged(NameOf(sTitle)) ' aggiorno titolo nella secondaryPage che e' quello che si vede nella barra in alto Map.refSecondaryWindowVM.SetTitle(sTitle) End Sub 'Public Sub UpdateTitle() ' m_Title = "" ' Select Case Map.refMainMenuVM.SelPage ' Case Pages.VIEW ' If Not IsNothing(Map.refProjManagerVM.CurrProj) Then ' If Map.refProjManagerVM.CurrProj.bIsNew Then m_Title = "New - " ' m_Title &= Map.refProjManagerVM.CurrProj.nProjId.ToString("0000") & " - " & Map.refProjManagerVM.CurrProj.sBTLFileName ' End If ' Case Pages.MACHINING ' If Not IsNothing(Map.refProdManagerVM.CurrProd) Then ' If Map.refProdManagerVM.CurrProd.bIsNew Then m_Title = "New - " ' m_Title &= Map.refProdManagerVM.CurrProd.nProdId.ToString("0000") & " - " & Map.refProdManagerVM.CurrProd.sBTLFileName ' End If ' Case Pages.CONFIG ' m_Title = "Configuration Page" ' End Select ' m_Title &= " - EgtBEAMWALL" ' NotifyPropertyChanged(NameOf(Title)) 'End Sub Friend Sub ContentRendered() 'DbControllers.Init() '' chiamata a caso su Db per inizializzarlo 'DbControllers.m_ProjController.FindByProjDbId(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)) '' imposto MainWindow per finestra di Loading 'LoadingWndHelper.SetMainWindow(Application.Current.MainWindow) '' leggo riga di comando 'Dim nCommandType As Integer = 0 'Dim nPage As Pages = Pages.VIEW 'Dim nProdId As Integer = 0 'If ProcessCommandLine(nCommandType, nPage, nProdId) Then ' Select Case nCommandType ' Case 1 ' Map.refProdManagerVM.SetCurrProd(nProdId) ' Case 2 ' ' pagina gia' impostata nella variabile ' End Select 'Else ' ' setto il primo file dalla lista degli MRU come progetto corrente da aprire ' Dim sLastProjectPath As String = String.Empty ' GetMainPrivateProfileString(S_MRUPROJFILES, K_FILE & "1", String.Empty, sLastProjectPath) ' If Not String.IsNullOrWhiteSpace(sLastProjectPath) AndAlso File.Exists(sLastProjectPath) Then ' ' ricavo l'Id e il progetto associato per l'apertura di quest'ultimo ' Dim PjId As Integer = 0 ' Dim sPjId As String = Path.GetFileNameWithoutExtension(sLastProjectPath) ' Integer.TryParse(sPjId, PjId) ' Map.refProjManagerVM.SetCurrProj(PjId) ' End If 'End If '' seleziono pagina da aprire 'Map.refMainMenuVM.SelPage = nPage '' inizializzo thread di aggiornamento e comunicazione con DB '' creo thread gestione macchina 'm_SupervisorCommThread = New Thread(Sub() ' SupervisorCommThread.SupervisorCommThreadFunction() ' End Sub) 'm_SupervisorCommThread.SetApartmentState(ApartmentState.STA) '' avvio thread di gestione della macchina che avvia la connessione 'm_SupervisorCommThread.Start() End Sub ' Friend Function ProcessCommandLine(ByRef nCommandType As Integer, ByRef nPage As Pages, ByRef nProdId As Integer) As Boolean ' ' Se non ci sono veri parametri su linea di comando, esco (il primo è sempre il nome del programma) ' If Environment.GetCommandLineArgs.Count() <= 1 Then Return False ' ' Recupero primo parametro che dovrebbe essere il tipo di modalita' riga di comando ' Dim sFile As String = Environment.GetCommandLineArgs(1) ' If String.IsNullOrWhiteSpace(sFile) OrElse Not Integer.TryParse(sFile, nCommandType) OrElse nCommandType <= 0 Then Return False ' Select Case nCommandType ' Case 1 ' apri progetto in ottimizzatore ' ' recupero secondo parametro ' Dim sProdId As String = Environment.GetCommandLineArgs(2) ' If Not Integer.TryParse(sProdId, nProdId) OrElse nProdId <= 0 Then Return False ' nPage = Pages.MACHINING ' Return True ' Case 2 ' apri pagina specifica senza progetto specifico ' ' recupero secondo parametro ' Dim sPage As String = Environment.GetCommandLineArgs(2) ' If Not Integer.TryParse(sPage, nPage) OrElse (nPage <> Pages.VIEW AndAlso nPage <> Pages.MACHINING) Then Return False ' Return True ' End Select ' Return False ' End Function Friend Sub KeyDown(PressedKey As Key) ' Con ESC esco dall'azione corrente If PressedKey = Key.Escape Then ' resetto sempre input box a meno che non sia nelle ribs e stia creando il percorso If Not (Not IsNothing(Map.refTopPanelVM.SelPage) AndAlso Map.refTopPanelVM.SelPage = Pages.MODIFY AndAlso Not IsNothing(Map.refTopPanelVM.SelModifyMode) AndAlso ((Map.refTopPanelVM.SelModifyMode.ModifyMode = ModifyModes.RIBS AndAlso Map.refRibPanelVM.bIsCreatingPath) OrElse (Map.refTopPanelVM.SelModifyMode.ModifyMode = ModifyModes.SHELLNUMBER AndAlso Map.refShellNumberPanelVM.bIsCreatingPath))) Then Map.refControllerInputPanelVM.ResetInputBox() End If If Not IsNothing(Map.refTopPanelVM.SelPage) AndAlso Map.refTopPanelVM.SelPage = Pages.MODIFY AndAlso Not IsNothing(Map.refTopPanelVM.SelModifyMode) Then Dim nNewExtrusionLayerId As Integer = GDB_ID.NULL If Map.refTopPanelVM.SelModifyMode.ModifyMode = ModifyModes.RIBS Then ' cancello eventuali layer di modifica If Not IsNothing(Map.refTopPanelVM.SelPart) AndAlso Not Map.refRibPanelVM.bIsCreatingPath Then nNewExtrusionLayerId = EgtGetFirstNameInGroup(Map.refTopPanelVM.SelPart.nPartId, LAY_NEWEXTRUSION) If nNewExtrusionLayerId <> GDB_ID.NULL Then EgtErase(nNewExtrusionLayerId) End If Dim nNewRibLayerId As Integer = EgtGetFirstNameInGroup(Map.refTopPanelVM.SelPart.nPartId, LAY_NEWRIB) If nNewRibLayerId <> GDB_ID.NULL Then EgtErase(nNewRibLayerId) End If End If ' annullo trasparenza attivata durante edit rib If Not IsNothing(Map.refRibPanelVM.SelRib) Then EgtSetAlpha(Map.refRibPanelVM.SelRib.nExtrusionId, 100) End If ElseIf Map.refTopPanelVM.SelModifyMode.ModifyMode = ModifyModes.SHELLNUMBER Then ' cancello eventuali layer di modifica If Not IsNothing(Map.refTopPanelVM.SelPart) AndAlso Not Map.refShellNumberPanelVM.bIsCreatingPath Then nNewExtrusionLayerId = EgtGetFirstNameInGroup(Map.refTopPanelVM.SelPart.nPartId, LAY_NEWEXTRUSION) If nNewExtrusionLayerId <> GDB_ID.NULL Then EgtErase(nNewExtrusionLayerId) End If Dim nNewRibLayerId As Integer = EgtGetFirstNameInGroup(Map.refTopPanelVM.SelPart.nPartId, LAY_NEWRIB) If nNewRibLayerId <> GDB_ID.NULL Then EgtErase(nNewRibLayerId) End If End If ' annullo trasparenza attivata durante edit rib If Not IsNothing(Map.refShellNumberPanelVM.SelShellNumber) Then EgtSetAlpha(Map.refShellNumberPanelVM.SelShellNumber.nExtrusionId, 100) End If End If End If ' reset Azione corrente Map.refSceneHostVM.MainController.ResetStatus() ' 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 ' Friend m_ManagingSupervisorStop As Boolean = False ' Private Sub SupervisorTimer_Tick() ' If SupervisorCommThread.bViewerOptimizerBlocked And Not m_ManagingSupervisorStop Then ' m_ManagingSupervisorStop = True ' BlockedWnd = New BlockedWndV(Application.Current.MainWindow, New BlockedWndVM) ' BlockedWnd.ShowDialog() ' ElseIf Not SupervisorCommThread.bViewerOptimizerBlocked And m_ManagingSupervisorStop Then ' m_ManagingSupervisorStop = False ' BlockedWnd.Close() ' End If ' End Sub '#End Region ' METHODS '#Region "COMMANDS" '#Region "CloseApplicationCommand" ' ' Returns a command that manage the MainWindow_Unloaded command ' Public ReadOnly Property CloseApplicationCommand() As ICommand ' Get ' If m_cmdCloseApplication Is Nothing Then ' m_cmdCloseApplication = New Command(AddressOf CloseApplication) ' End If ' Return m_cmdCloseApplication ' End Get ' End Property ' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded. Friend Sub CloseApplication() If (Keyboard.Modifiers And ModifierKeys.Alt) = ModifierKeys.Alt OrElse Keyboard.IsKeyDown(Key.F4) Then Return End If ' Gestisco eventuale file corrente modificato Dim bOk As Boolean = True 'bOk = ProjFileVM.VerifyProjectModification(Map.refProjManagerVM.CurrProj, ProjectType.PROJ) ' se salvataggio annullato, rimango If Not bOk Then Return Dim bAllowClose As Boolean = Map.refSceneHostVM.MainController.ManageModified() ' Salvo impostazione macchina corrente 'Map.refMachinePanelVM.SaveCurrentMachine() ' Se non confermata chiusura, esco If Not bAllowClose Then Return ' salvo modo di visualizzazione WriteMainPrivateProfileString(S_SCENE, K_SHOWMODE, EgtGetShowMode().ToString()) ' Salvo stato visualizzazione direzione curve WriteMainPrivateProfileString(S_SCENE, K_CURVEDIR, If(EgtGetShowCurveDirection(), "1", "0")) ' Salvo stato visualizzazione griglia WriteMainPrivateProfileString(S_GRID, K_SHOWGRID, If(Map.refMyStatusBarVM.bGridVisibility, "1", "0")) ' Termino il Model m_MainWindowM.Close() ' Termino il programma Application.Current.Shutdown() End Sub '#End Region ' CloseApplicationCommand '#End Region ' COMMANDS End Class