diff --git a/Icarus/MainWindow/MainWindowV.xaml.vb b/Icarus/MainWindow/MainWindowV.xaml.vb index ee33e28..85d4609 100644 --- a/Icarus/MainWindow/MainWindowV.xaml.vb +++ b/Icarus/MainWindow/MainWindowV.xaml.vb @@ -40,7 +40,7 @@ Class MainWindowV End Sub Private Sub MainWindowV_Closing(sender As Object, e As System.ComponentModel.CancelEventArgs) - If (Keyboard.Modifiers And ModifierKeys.Alt) = ModifierKeys.Alt OrElse Keyboard.IsKeyDown(Key.F4) Then + If (Keyboard.Modifiers And ModifierKeys.Alt) = ModifierKeys.Alt AndAlso Keyboard.IsKeyDown(Key.F4) Then e.Cancel = True Return End If diff --git a/Icarus/MainWindow/MainWindowVM.vb b/Icarus/MainWindow/MainWindowVM.vb index 836dbf9..fd0d58f 100644 --- a/Icarus/MainWindow/MainWindowVM.vb +++ b/Icarus/MainWindow/MainWindowVM.vb @@ -159,21 +159,19 @@ Public Class MainWindowVM End Function Friend Sub CloseApplication() - If (Keyboard.Modifiers And ModifierKeys.Alt) = ModifierKeys.Alt OrElse Keyboard.IsKeyDown(Key.F4) Then + ' Se simulazione in corso + If Not IsNothing( Map.refSimulationPanelVM) AndAlso Map.refSimulationPanelVM.MySimul.bSimExecuting Then + ' Avvio l'arresto della simulazione + Map.refSimulationPanelVM.MySimul.SetSimulationStatus(MCH_SIM_ST.UI_STOP) + Map.refSimulationPanelVM.MySimul.m_bSimulEndExitApp = True Return End If - ' gestisco la chiusura della simulazione + ' 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 diff --git a/Icarus/SecondaryWindow/SecondaryWindowV.xaml.vb b/Icarus/SecondaryWindow/SecondaryWindowV.xaml.vb index 3185872..f1b0aca 100644 --- a/Icarus/SecondaryWindow/SecondaryWindowV.xaml.vb +++ b/Icarus/SecondaryWindow/SecondaryWindowV.xaml.vb @@ -37,7 +37,7 @@ Public Class SecondaryWindowV End Sub Private Sub SecondaryWindowV_Closing(sender As Object, e As System.ComponentModel.CancelEventArgs) - If (Keyboard.Modifiers And ModifierKeys.Alt) = ModifierKeys.Alt OrElse Keyboard.IsKeyDown(Key.F4) Then + If (Keyboard.Modifiers And ModifierKeys.Alt) = ModifierKeys.Alt AndAlso Keyboard.IsKeyDown(Key.F4) Then e.Cancel = True Return End If diff --git a/Icarus/SimulationPanel/MySimulation.vb b/Icarus/SimulationPanel/MySimulation.vb index 6289fb0..81a342c 100644 --- a/Icarus/SimulationPanel/MySimulation.vb +++ b/Icarus/SimulationPanel/MySimulation.vb @@ -21,6 +21,10 @@ Public Class MySimulation End Set End Property + Private m_bStopOnNextCollision As Boolean = True + + Friend m_bSimulEndExitApp As Boolean = False + #End Region ' FIELDS & PROPERTIES #Region "Messages" @@ -38,9 +42,9 @@ Public Class MySimulation Sub New() SetPlayImagePath("/Resources/SimulationPanel/Play.png") SetPauseImagePath("/Resources/SimulationPanel/Pause.png") - SetPauseMsg(EgtMsg(90561)) ' Pausa - SetStopMsg(EgtMsg(90562)) ' Simulazione interrotta - SetHomeMsg(EgtMsg(90564)) ' Home + SetPauseMsg(EgtMsg(5311)) ' Pausa + SetStopMsg(EgtMsg(5312)) ' Stop + SetHomeMsg(EgtMsg(5314)) ' Home End Sub #End Region ' CONSTRUCTOR @@ -48,8 +52,10 @@ Public Class MySimulation #Region "METHODS" Public Overrides Sub ExecSim() + SetSimExecuting(True) EgtSimStart(False) EgtSimSetStep(SliderValue * GetSliderX()) + m_bStopOnNextCollision = True Dim nShowDataCounter As Integer = 0 While GetStatus() <> MCH_SIM_ST.UI_STOP ' Se simulazione in svolgimento @@ -62,11 +68,25 @@ Public Class MySimulation If GetStatus() = MCH_SIM_ST.UI_STEP And nMove = MCH_SIM.END_STEP Then ' Imposto stato Pausa SetSimulationStatus(MCH_SIM_ST.UI_PAUSE) - StatusMsg = EgtMsg(MSG_SIMULATIONPAGEUC + 11) ' Pausa + StatusMsg = EgtMsg(5311) ' Pausa ' Aggiornamenti per bottone Play/Pause SetShowPlay(True) NotifyPropertyChanged("PlayPauseImage") End If + ' Se movimento con collisione + ElseIf nMove = MCH_SIM.COLLISION Then + If m_bStopOnNextCollision Then + ' Imposto stato Pausa + SetSimulationStatus(MCH_SIM_ST.UI_PAUSE) + StatusMsg = EgtMsg(5311) ' PAUSA + ' Aggiornamenti per bottone Play/Pause + SetShowPlay(True) + NotifyPropertyChanged("PlayPauseImage") + ' Messaggio + MessageBox.Show(EgtMsg(5319), EgtMsg(5315), MessageBoxButton.OK, MessageBoxImage.Warning) + Else + m_bStopOnNextCollision = True + End If ' Se movimento non riuscito Else SetSimulationStatus(MCH_SIM_ST.UI_STOP) @@ -76,17 +96,26 @@ Public Class MySimulation ' Eventuale messaggio Select Case nMove Case MCH_SIM.END_ - StatusMsg = EgtMsg(MSG_SIMULATIONPAGEUC + 1) 'Simulazione completata + StatusMsg = EgtMsg(5301) 'Simulazione completata Case MCH_SIM.STOP_ ' Simulazione fermata dall'utente (non necessita messaggio) Case MCH_SIM.OUTSTROKE Dim sInfo As String = String.Empty EgtGetOutstrokeInfo(sInfo) - MessageBox.Show(EgtMsg(MSG_SIMULATIONPAGEUC + 2) & " " & sInfo, EgtMsg(MSG_SIMULATIONPAGEUC + 5), MessageBoxButton.OK, MessageBoxImage.Stop) 'Extracorsa ... + 'Extracorsa ... + MessageBox.Show(EgtMsg(5302) & " " & sInfo, EgtMsg(5305), MessageBoxButton.OK, MessageBoxImage.Stop) Case MCH_SIM.DIR_ERR - MessageBox.Show(EgtMsg(MSG_SIMULATIONPAGEUC + 3), EgtMsg(MSG_SIMULATIONPAGEUC + 5), MessageBoxButton.OK, MessageBoxImage.Stop) 'Direzione utensile irraggiungibile + 'Direzione utensile irraggiungibile + MessageBox.Show(EgtMsg(5303), EgtMsg(5305), MessageBoxButton.OK, MessageBoxImage.Stop) Case Else - MessageBox.Show(EgtMsg(MSG_SIMULATIONPAGEUC + 4), EgtMsg(MSG_SIMULATIONPAGEUC + 5), MessageBoxButton.OK, MessageBoxImage.Stop) 'Errore + If EgtGetLastMachMgrErrorId() <> 0 Then + Dim sErr As String = EgtGetLastMachMgrErrorString() + '..... - Errore + MessageBox.Show(sErr, EgtMsg(5305), MessageBoxButton.OK, MessageBoxImage.Exclamation) + Else + 'Errore - Errore + MessageBox.Show(EgtMsg(5304), EgtMsg(5305), MessageBoxButton.OK, MessageBoxImage.Stop) + End If End Select End If ' Aggiorno stato visualizzazione macchina (dipende anche da utensile) @@ -94,14 +123,25 @@ Public Class MySimulation ' Aggiorno visualizzazione EgtDraw() ' Aggiorno dati CNC - ShowCncData() + If nShowDataCounter = 5 Or GetSimulationStatus() = MCH_SIM_ST.UI_PAUSE Or GetSimulationStatus() = MCH_SIM_ST.UI_STOP Then + ShowCncData() + nShowDataCounter = 0 + ElseIf nShowDataCounter > 5 Then + nShowDataCounter = 0 + Else + nShowDataCounter += 1 + End If Else ' Per evitare di ciclare rapidissimamente e consumare inutilmente CPU - System.Threading.Thread.Sleep(1) + System.Threading.Thread.Sleep(5) End If ' Costringo ad aggiornare UI UpdateUI() End While + SetSimExecuting(False) + If m_bSimulEndExitApp Then + refMainWindowVM.CloseApplication( Nothing) + End If End Sub Public Overrides Sub OnPostSetSimulationStatus(value As MCH_SIM_ST) @@ -126,6 +166,21 @@ Public Class MySimulation End If End Sub + Public Sub Update_CncData( nFlag As Integer) + ShowCncData() + ' Se fermo per Collisione rilevata da script Lua o per altra richiesta + If nFlag = 11 Or nFlag = 12 Then + ' Imposto stato Pausa + SetSimulationStatus(MCH_SIM_ST.UI_PAUSE) + StatusMsg = EgtMsg(5311) ' PAUSA + ' Aggiornamenti per bottone Play/Pause + SetShowPlay(True) + NotifyPropertyChanged("PlayPauseImage") + ' Se fermo per Collisione, dichiaro di non arrestarsi alla successiva notifica di collisione + If nFlag = 11 Then m_bStopOnNextCollision = False + End If + End Sub + #End Region ' METHODS End Class diff --git a/Icarus/SimulationPanel/SimulationPanelVM.vb b/Icarus/SimulationPanel/SimulationPanelVM.vb index d197c8b..17f6337 100644 --- a/Icarus/SimulationPanel/SimulationPanelVM.vb +++ b/Icarus/SimulationPanel/SimulationPanelVM.vb @@ -201,6 +201,10 @@ Public Class SimulationPanelVM Map.refInstrumentPanelVM.SetEdgeAnalysisIsEnabled(True) End Sub + Friend Sub SimulationExpander_Update_CncData( nFlag As Integer) + MySimul.Update_CncData(nFlag) + End Sub + #End Region ' METHODS #Region "COMMANDS" diff --git a/Icarus/StatusBar/MyStatusBarVM.vb b/Icarus/StatusBar/MyStatusBarVM.vb index 27d093e..3c9be56 100644 --- a/Icarus/StatusBar/MyStatusBarVM.vb +++ b/Icarus/StatusBar/MyStatusBarVM.vb @@ -165,10 +165,21 @@ Public Class MyStatusBarVM Friend Function ProcessEvents(ByVal nProg As Integer, ByVal nPause As Integer) As Integer ' Se previsto, imposto progress If nProg > 0 Then SetLoadingProgress(Math.Min(nProg, 100)) + ' Se simulazione attiva, notifico aggiornamento dati + If Not IsNothing( Map.refSimulationPanelVM) Then + ' Uso i valori negativi del primo parametro come flag per la Simulazione + Dim nFlag As Integer = If( nProg < 0, -nProg, 0) + Map.refSimulationPanelVM.SimulationExpander_Update_CncData( nFlag) + End If ' Costringo ad aggiornare UpdateUI() ' Eventuale attesa - Thread.Sleep(nPause) + If nPause >= 0 Then + Thread.Sleep(nPause) + ' se altrimenti richiesto aggiornamento visualizzazione + ElseIf nPause = -1 + EgtDraw() + End If ' Ritorno eventuale stop If m_bStopProgress Then m_bStopProgress = False