Imports EgtUILib Public Class SimulationPageUC Dim m_MainWindow As MainWindow = Application.Current.MainWindow Dim m_CurrProjPage As CurrentProjectPageUC ' Stato e comando correnti Public Enum SIM_ST As Integer ST_STOP = 1 ST_PLAY = 2 ST_PAUSE = 3 End Enum Private m_nStatus As Integer = SIM_ST.ST_STOP ' Stato bottone Play Private m_bPlay As Boolean = True ' Flag di progetto da caricare prima di simulare Private m_bToReload As Boolean = False Private Sub SimulationPage_Initialized(sender As Object, e As EventArgs) PlayPauseImage.Source = New System.Windows.Media.Imaging.BitmapImage(New Uri("/Resources/Play.png", UriKind.Relative)) End Sub Private Sub SimulationPage_Loaded(sender As Object, e As RoutedEventArgs) m_CurrProjPage = m_MainWindow.m_CurrentProjectPageUC ' Disabilito impostazione modificato EgtDisableModified() ' Salvo il progetto corrente SaveFile() ' Nascondo eventuali pezzi in parcheggio HideParkedParts() ' Visualizzo tutta la macchina EgtShowOnlyTable(False) ' Eseguo EgtLuaExecFile("C:\EgtData\OmagCut\CamAuto\CamAuto.lua") ' Imposto vista 3d isometrica di tutto EgtSetView(VT.ISO_SE, False) EgtZoom(ZM.ALL) ' Imposto stato corrente m_nStatus = SIM_ST.ST_STOP m_bPlay = True SpeedSlider.Value = 10 End Sub Private Sub HomeBtn_Click(sender As Object, e As RoutedEventArgs) Handles HomeBtn.Click If m_nStatus <> SIM_ST.ST_STOP Then Return End If EgtSimHome() EgtDraw() End Sub Private Sub PlayPauseBtn_Click(sender As Object, e As RoutedEventArgs) Handles PlayPauseBtn.Click If m_bPlay Then ' Aggiorno bottone m_bPlay = False PlayPauseImage.Source = New System.Windows.Media.Imaging.BitmapImage(New Uri("/Resources/Pause.png", UriKind.Relative)) ' Eseguo If m_nStatus = SIM_ST.ST_STOP Then ' Ricarico il progetto, se necessario 'If ReloadFile(True) Then ' EgtDraw() 'End If m_bToReload = True ' Lancio simulazione ExecSim() ' Aggiorno bottone m_bPlay = True PlayPauseImage.Source = New System.Windows.Media.Imaging.BitmapImage(New Uri("/Resources/Play.png", UriKind.Relative)) ElseIf m_nStatus = SIM_ST.ST_PAUSE Then m_nStatus = SIM_ST.ST_PLAY End If Else ' Aggiorno bottone m_bPlay = True PlayPauseImage.Source = New System.Windows.Media.Imaging.BitmapImage(New Uri("/Resources/Play.png", UriKind.Relative)) ' Se play, imposto stato pausa If m_nStatus = SIM_ST.ST_PLAY Then m_nStatus = SIM_ST.ST_PAUSE End If End If End Sub Private Sub StopBtn_Click(sender As Object, e As RoutedEventArgs) Handles StopBtn.Click m_nStatus = SIM_ST.ST_STOP End Sub Private Sub SpeedSlider_ValueChanged(sender As Object, e As RoutedPropertyChangedEventArgs(Of Double)) EgtSimSetStep(SpeedSlider.Value) End Sub Private Sub ExecSim() m_nStatus = SIM_ST.ST_PLAY EgtSimStart() EgtSimSetStep(SpeedSlider.Value) While m_nStatus <> SIM_ST.ST_STOP ' Se simulazione in svolgimento If m_nStatus = SIM_ST.ST_PLAY Then ' Se arrivata alla fine... If Not EgtSimMove() Then m_nStatus = SIM_ST.ST_STOP End If ' Aggiorno visualizzazione EgtDraw() End If ' Costringo ad aggiornare UI Dim nDummy As Integer Application.Current.Dispatcher.Invoke(Windows.Threading.DispatcherPriority.Background, _ New Action(Function() nDummy = 0)) End While End Sub Private Sub ExitBtnUC_Click(sender As Object, e As RoutedEventArgs) ' Mi assicuro di terminare la simulazione EgtSimStop() ' Ricarico il progetto corrente ReloadFile(False) ' Ripristino visibilità standard ShowParkedParts() EgtShowOnlyTable(True) ' Imposto vista 2D EgtSetView(VT.TOP, False) EgtZoom(ZM.ALL) ' Abilito impostazione modificato EgtEnableModified() ' Esco dalla pagina m_MainWindow.m_CurrentProjectPageUC.CurrentProjectPageGrid.Children.Remove(Me) m_CurrProjPage.CurrProjGrid.Visibility = Windows.Visibility.Visible m_MainWindow.m_CurrentProjectPageUC.CurrentProjectPageGrid.Children.Add(m_MainWindow.m_CadCutPageUC) m_MainWindow.m_ActivePage = MainWindow.Pages.CadCut End Sub Private Sub SaveFile() Dim sPath As String = m_MainWindow.GetTempDir() & "\" & "SimuProj.nge" m_CurrProjPage.SaveFile(sPath) m_bToReload = False End Sub Private Function ReloadFile(ByVal bForSimu As Boolean) As Boolean If Not m_bToReload Then Return False End If ' Ricarico Dim sPath As String = m_MainWindow.GetTempDir() & "\" & "SimuProj.nge" m_CurrProjPage.LoadFile(sPath) ' Se per simulazione, nascondo pezzi in parcheggio e visualizzo tutta la macchina If bForSimu Then HideParkedParts() EgtShowOnlyTable(False) End If m_bToReload = False Return True End Function End Class