Files
Dario Sassi d5188fcd96 Icarus :
- aggiornata simulazione come EgtCAM5.
2026-04-28 19:26:55 +02:00

187 lines
6.8 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Imports EgtWPFLib5
Public Class MySimulation
Inherits SimulationVM
#Region "FIELDS & PROPERTIES"
Public Overrides Property SliderValue As Double
Get
Return m_SliderValue
End Get
Set(value As Double)
If Math.Abs(value - m_SliderValue) > EPS_SMALL Then
m_SliderValue = value
EgtSimSetStep(m_SliderValue * GetSliderX())
NotifyPropertyChanged("SliderValue")
End If
End Set
End Property
Private m_bStopOnNextCollision As Boolean = True
Friend m_bSimulEndExitApp As Boolean = False
#End Region ' FIELDS & PROPERTIES
#Region "Messages"
Public ReadOnly Property VMillAdditiveMsg As String
Get
Return "Virtual Additive"
End Get
End Property
#End Region ' Messages
#Region "CONSTRUCTOR"
Sub New()
SetPlayImagePath("/Resources/SimulationPanel/Play.png")
SetPauseImagePath("/Resources/SimulationPanel/Pause.png")
SetPauseMsg(EgtMsg(5311)) ' Pausa
SetStopMsg(EgtMsg(5312)) ' Stop
SetHomeMsg(EgtMsg(5314)) ' Home
End Sub
#End Region ' CONSTRUCTOR
#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
If GetStatus() = MCH_SIM_ST.UI_PLAY Or GetStatus() = MCH_SIM_ST.UI_STEP Then
' Eseguo movimento
Dim nMove As Integer
Dim bMove As Boolean = EgtSimMove(nMove)
' Se arrivato a fine step e sono in step
If bMove Then
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(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)
' Aggiornamenti per bottone Play/Pause
SetShowPlay(True)
NotifyPropertyChanged("PlayPauseImage")
' Eventuale messaggio
Select Case nMove
Case MCH_SIM.END_
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)
'Extracorsa ...
MessageBox.Show(EgtMsg(5302) & " " & sInfo, EgtMsg(5305), MessageBoxButton.OK, MessageBoxImage.Stop)
Case MCH_SIM.DIR_ERR
'Direzione utensile irraggiungibile
MessageBox.Show(EgtMsg(5303), EgtMsg(5305), MessageBoxButton.OK, MessageBoxImage.Stop)
Case Else
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)
UpdateMachView()
' Aggiorno visualizzazione
EgtDraw()
' Aggiorno dati CNC
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(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)
If Map.refMainWindowVM.MainWindowM.nUserLevel >= 5 AndAlso
(GetStatus() = MCH_SIM_ST.UI_PAUSE OrElse GetStatus() = MCH_SIM_ST.UI_STOP) Then
For Index = 0 To MachineAxisList.Count - 1
MachineAxisList(Index).IsReadOnlyAxesValue = False
Next
Else
For Index = 0 To MachineAxisList.Count - 1
MachineAxisList(Index).IsReadOnlyAxesValue = True
Next
End If
EgtSimSetUiStatus(GetStatus())
End Sub
Public Overrides Sub VMillActiveInfoTitle(VMillActive As Boolean)
If VMillActive Then
EgtSetInfo(EgtGetCurrMachGroup(), KEY_MCHGRP_VM, VMillActive)
Else
EgtRemoveInfo(EgtGetCurrMachGroup(), KEY_MCHGRP_VM)
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