Imports EgtUILib Imports EgtWPFLib5 Imports System.IO Imports System.Threading Imports System.Windows.Threading Public Class MainWindowVM Inherits VMBase ' 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 Public ReadOnly Property sTitle As String Get Return "Icarus" End Get End Property Public ReadOnly Property sProjectName As String Get Dim sFilePath As String = "" EgtGetCurrFilePath(sFilePath) If String.IsNullOrEmpty(sFilePath) Then sFilePath = EgtMsg(MSG_TOPCOMMANDBAR + 1) & Map.refMainWindowVM.MainWindowM.nInstance.ToString() Return sFilePath Else Return Path.GetFileNameWithoutExtension(sFilePath) & If(EgtGetModified(), "*", "") End If End Get End Property Public ReadOnly Property sProjectPath As String Get Dim sFilePath As String = "" EgtGetCurrFilePath(sFilePath) If String.IsNullOrEmpty(sFilePath) Then sFilePath = EgtMsg(MSG_TOPCOMMANDBAR + 1) & Map.refMainWindowVM.MainWindowM.nInstance.ToString() End If Return sFilePath End Get End Property Private m_MachinePanelVM As MachinePanelVM Public ReadOnly Property MachinePanelVM As MachinePanelVM Get Return m_MachinePanelVM End Get 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 ' inizializzo machine panel m_MachinePanelVM = New MachinePanelVM End Sub #End Region ' CONSTRUCTOR '#Region "METHODS" Friend Sub ContentRendered() End Sub 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 Sub CloseApplication() If (Keyboard.Modifiers And ModifierKeys.Alt) = ModifierKeys.Alt OrElse Keyboard.IsKeyDown(Key.F4) Then Return End If ' gestisco la chiusura della simulazione If Map.refRightPanelVM.SelPanel = RightPanelVM.Panels.SIMULATION AndAlso Not IsNothing(Map.refSimulationPanelVM) Then Map.refSimulationPanelVM.MySimul.ResetSimulation() 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 #Region "COMMANDS" #Region "AboutBoxCommand" ' Returns a command that manage the MainWindow_Unloaded command Public ReadOnly Property AboutBoxCommand() 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 "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. Public Sub CloseApplication(ByVal param As Object) If Map.refSliceManagerVM.bCalculating Then MessageBox.Show("Impossible closing software! Wait end of calculation!", "Error", MessageBoxButton.OK, MessageBoxImage.Error) Return End If CloseApplication() End Sub #End Region ' CloseApplicationCommand #End Region ' COMMANDS End Class