b2421e10e2
- gestione sovratavola - migliorie file INI.
216 lines
8.2 KiB
VB.net
216 lines
8.2 KiB
VB.net
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
|
|
|
|
' Coeeficiente per valore Slider
|
|
Private m_SliderX As Double = 1
|
|
|
|
Friend Sub ResetSimulation()
|
|
' Termino la simulazione
|
|
m_nStatus = SIM_ST.ST_STOP
|
|
EgtSimStop()
|
|
' Salvo valore dello slider
|
|
Dim sVal As String = DoubleToString(SpeedSlider.Value, 1)
|
|
WritePrivateProfileString(S_SIMUL, K_SLIDERVAL, sVal, m_MainWindow.GetIniFile())
|
|
' Riporto il progetto allo stato iniziale
|
|
EgtRemoveAllOperations()
|
|
' Ripristino visibilità standard
|
|
ShowParkedParts()
|
|
EgtShowOnlyTable(True)
|
|
End Sub
|
|
|
|
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()
|
|
' Nascondo eventuali pezzi in parcheggio
|
|
HideParkedParts()
|
|
' Visualizzo tutta la macchina
|
|
EgtShowOnlyTable(False)
|
|
' Calcolo le lavorazioni
|
|
Dim sSawMch As String = String.Empty
|
|
GetPrivateProfileString(S_MACH, K_CURRMACHINING, "", sSawMch, m_MainWindow.GetIniFile())
|
|
EgtLuaCreateGlobTable("CAM")
|
|
EgtLuaSetGlobStringVar("CAM.SAWMCH", sSawMch)
|
|
Dim bOk As Boolean = EgtLuaExecFile(m_MainWindow.GetCamAutoDir() & "\CamAuto.lua")
|
|
Dim nErr As Integer = 999
|
|
EgtLuaGetGlobIntVar("CAM.ERR", nErr)
|
|
EgtLuaResetGlobVar("CAM")
|
|
If nErr <> 0 Then
|
|
bOk = False
|
|
EgtOutLog("Error in CamAuto : " & nErr.ToString())
|
|
End If
|
|
' Messaggio di errore
|
|
' Se errore in generazione, segnalo l'errore ed esco
|
|
If Not bOk Then
|
|
OutMessageLbl.Text = EgtMsg(90314) 'Errore nella generazione del programma CN
|
|
OutMessageLbl.Background = Brushes.Tomato
|
|
OutMessageLbl.Visibility = Windows.Visibility.Visible
|
|
EgtOutLog(OutMessageLbl.Text)
|
|
End If
|
|
' Salvo il progetto con le lavorazioni
|
|
Dim sMchPath As String = m_MainWindow.GetTempDir() & "\" & "MachProj.nge"
|
|
m_CurrProjPage.SaveFile(sMchPath)
|
|
' 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
|
|
m_SliderX = GetPrivateProfileDouble(S_SIMUL, K_SLIDERX, 1, m_MainWindow.GetIniFile())
|
|
Dim SliderVal As Double = GetPrivateProfileDouble(S_SIMUL, K_SLIDERVAL, 10, m_MainWindow.GetIniFile())
|
|
SpeedSlider.Value = SliderVal
|
|
' Porto la testa in home
|
|
EgtSimStart()
|
|
HomeBtn_Click(Me, Nothing)
|
|
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
|
|
' Vado in home
|
|
EgtSimHome()
|
|
' Aggiorno visualizzazione
|
|
EgtDraw()
|
|
' Aggiorno dati CNC
|
|
ShowCncData()
|
|
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
|
|
' 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 * m_SliderX)
|
|
End Sub
|
|
|
|
Private Sub ExecSim()
|
|
m_nStatus = SIM_ST.ST_PLAY
|
|
EgtSimStart()
|
|
EgtSimSetStep(SpeedSlider.Value * m_SliderX)
|
|
While m_nStatus <> SIM_ST.ST_STOP
|
|
' Se simulazione in svolgimento
|
|
If m_nStatus = SIM_ST.ST_PLAY Then
|
|
' Eseguo movimento
|
|
Dim nMove As Integer
|
|
Dim bMove As Boolean = EgtSimMove(nMove)
|
|
' Se movimento non riuscito
|
|
If Not bMove Then
|
|
m_nStatus = SIM_ST.ST_STOP
|
|
Select Case nMove
|
|
Case MCH_SIM.END_
|
|
Case MCH_SIM.OUTSTROKE
|
|
OutMessageLbl.Text = EgtMsg(90317) 'Extracorsa
|
|
OutMessageLbl.Background = Brushes.Tomato
|
|
OutMessageLbl.Visibility = Windows.Visibility.Visible
|
|
EgtOutLog(OutMessageLbl.Text)
|
|
Case MCH_SIM.DIR_ERR
|
|
OutMessageLbl.Text = EgtMsg(90318) 'Direzione utensile irraggiungibile
|
|
OutMessageLbl.Background = Brushes.Tomato
|
|
OutMessageLbl.Visibility = Windows.Visibility.Visible
|
|
EgtOutLog(OutMessageLbl.Text)
|
|
Case Else
|
|
OutMessageLbl.Text = EgtMsg(90319) 'Errore
|
|
OutMessageLbl.Background = Brushes.Tomato
|
|
OutMessageLbl.Visibility = Windows.Visibility.Visible
|
|
EgtOutLog(OutMessageLbl.Text)
|
|
End Select
|
|
End If
|
|
' Aggiorno visualizzazione
|
|
EgtDraw()
|
|
' Aggiorno dati CNC
|
|
ShowCncData()
|
|
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 ShowCncData()
|
|
ShowAxisNameVal(0, L1NameTxBl.Text, L1ValueTxBl.Text)
|
|
ShowAxisNameVal(1, L2NameTxBl.Text, L2ValueTxBl.Text)
|
|
ShowAxisNameVal(2, L3NameTxBl.Text, L3ValueTxBl.Text)
|
|
ShowAxisNameVal(3, R1NameTxBl.Text, R1ValueTxBl.Text)
|
|
ShowAxisNameVal(4, R2NameTxBl.Text, R2ValueTxBl.Text)
|
|
End Sub
|
|
|
|
Private Function ShowAxisNameVal(ByVal nInd As Integer, ByRef sName As String, ByRef sVal As String) As Boolean
|
|
Dim sInfo As String = String.Empty
|
|
Dim dVal As Double = 0
|
|
If EgtSimGetAxisInfoPos(nInd, sInfo, dVal) Then
|
|
sName = sInfo
|
|
sVal = DoubleToString(dVal, -3)
|
|
Return True
|
|
Else
|
|
sName = String.Empty
|
|
sVal = String.Empty
|
|
Return False
|
|
End If
|
|
End Function
|
|
|
|
Private Sub ExitBtnUC_Click(sender As Object, e As RoutedEventArgs)
|
|
' Mi assicuro di terminare la simulazione
|
|
ResetSimulation()
|
|
' 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
|
|
|
|
End Class
|