Imports System.Collections.ObjectModel
Imports EgtUILib
Public Class SimulationVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
'EGT PROPERTIES
' Stato di visualizzazione della macchina
Private m_nMachLook As MCH_LOOK = MCH_LOOK.ALL
' Utensile corrente
Private m_sCurrTool As String = String.Empty
' Stato di comando corrente
Private m_nStatus As MCH_SIM_ST = MCH_SIM_ST.UI_STOP
Private Property SimulationStatus As MCH_SIM_ST
Get
Return m_nStatus
End Get
Set(value As MCH_SIM_ST)
m_nStatus = value
OnPostSetSimulationStatus(value)
End Set
End Property
' Stato bottone Play
Private m_bShowPlay As Boolean = True
' Coefficiente per valore Slider
Private m_SliderX As Double = 1
' Percorsi immagini per bottone Play/Pause
Private m_PlayImagePath As String = String.Empty
Private m_PauseImagePath As String = String.Empty
' Messaggi per status Simulazione
Private m_PauseMsg As String = String.Empty
Private m_StopMsg As String = String.Empty
Private m_HomeMsg As String = String.Empty
' Flag di esecuzione in corso
Private m_bSimExecuting As Boolean = False
Public ReadOnly Property bSimExecuting As Boolean
Get
Return m_bSimExecuting
End Get
End Property
Public Shared SimulationMsg_Const As Integer = Nothing
' lista degli assi
Private m_MachineAxisList As New ObservableCollection(Of MachineAxis)
Public ReadOnly Property MachineAxisList As ObservableCollection(Of MachineAxis)
Get
Return m_MachineAxisList
End Get
End Property
Private m_GCode As String
Public Property GCode As String
Get
Return m_GCode
End Get
Set(value As String)
If value <> m_GCode Then
m_GCode = value
NotifyPropertyChanged(NameOf(GCode))
End If
End Set
End Property
Private m_FValue As String
Public Property FValue As String
Get
Return m_FValue
End Get
Set(value As String)
If value <> m_FValue Then
m_FValue = value
NotifyPropertyChanged(NameOf(FValue))
End If
End Set
End Property
Private m_TName As String
Public Property TName As String
Get
Return m_TName
End Get
Set(value As String)
If value <> m_TName Then
m_TName = value
NotifyPropertyChanged(NameOf(TName))
End If
End Set
End Property
Private m_SValue As String
Public Property SValue As String
Get
Return m_SValue
End Get
Set(value As String)
If value <> m_SValue Then
m_SValue = value
NotifyPropertyChanged(NameOf(SValue))
End If
End Set
End Property
Private m_OpeName As String
Public Property OpeName As String
Get
Return m_OpeName
End Get
Set(value As String)
If value <> m_OpeName Then
m_OpeName = value
NotifyPropertyChanged(NameOf(OpeName))
End If
End Set
End Property
Private m_PlayPauseImage As String
Public ReadOnly Property PlayPauseImage As String
Get
If m_bShowPlay Then
Return m_PlayImagePath
Else
Return m_PauseImagePath
End If
End Get
End Property
Private m_StatusMsg As String
Public Property StatusMsg As String
Get
Return m_StatusMsg
End Get
Set(value As String)
m_StatusMsg = value
NotifyPropertyChanged(NameOf(StatusMsg))
End Set
End Property
Public m_SliderValue As Double
Public Overridable 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 * m_SliderX)
NotifyPropertyChanged(NameOf(SliderValue))
End If
End Set
End Property
Private m_VMillActive As Boolean = False
Public Property VMillActive As Boolean
Get
Return m_VMillActive
End Get
Set(value As Boolean)
m_VMillActive = value
VMillActiveInfoTitle(m_VMillActive)
NotifyPropertyChanged(NameOf(VMillActive))
End Set
End Property
Public Sub SetVMillActive(value As Boolean)
m_VMillActive = value
NotifyPropertyChanged(NameOf(VMillActive))
End Sub
Private m_VMill_Visibility As Visibility = Visibility.Collapsed
Public Property VMill_Visibility As Visibility
Get
Return m_VMill_Visibility
End Get
Set(value As Visibility)
m_VMill_Visibility = value
NotifyPropertyChanged(NameOf(VMill_Visibility))
End Set
End Property
Private m_VMill_IsEnabled As Boolean = False
Public Property VMill_IsEnabled As Boolean
Get
Return m_VMill_IsEnabled
End Get
Set(value As Boolean)
m_VMill_IsEnabled = value
NotifyPropertyChanged(NameOf(VMill_IsEnabled))
End Set
End Property
Private m_TraceActive As Boolean = False
Public Property TraceActive As Boolean
Get
Return m_TraceActive
End Get
Set(value As Boolean)
m_TraceActive = value
EgtSimEnableToolTipTrace( m_TraceActive)
EgtDraw()
NotifyPropertyChanged(NameOf(TraceActive))
End Set
End Property
Private m_Trace_Visibility As Visibility = Visibility.Collapsed
Public Property Trace_Visibility As Visibility
Get
Return m_Trace_Visibility
End Get
Set(value As Visibility)
m_Trace_Visibility = value
NotifyPropertyChanged(NameOf(Trace_Visibility))
End Set
End Property
Private m_Trace_IsEnabled As Boolean = False
Public Property Trace_IsEnabled As Boolean
Get
Return m_Trace_IsEnabled
End Get
Set(value As Boolean)
m_Trace_IsEnabled = value
NotifyPropertyChanged(NameOf(Trace_IsEnabled))
End Set
End Property
' Definizione comandi
Private m_cmdStep As ICommand
Private m_cmdPlayPause As ICommand
Private m_cmdStop As ICommand
#Region "Messages"
Public ReadOnly Property SimulationMsg As String
Get
Return EgtMsg(31607) ' Simulazione
End Get
End Property
Public ReadOnly Property VMillMsg As String
Get
Return EgtMsg(5316) ' Virtual Milling
End Get
End Property
Public ReadOnly Property TraceMsg As String
Get
Return EgtMsg(5321) ' Tool Tip Tracing
End Get
End Property
Public ReadOnly Property PauseMsg As String
Get
Return m_PauseMsg
End Get
End Property
Public ReadOnly Property StopMsg As String
Get
Return m_StopMsg
End Get
End Property
Public ReadOnly Property HomeMsg As String
Get
Return m_HomeMsg
End Get
End Property
#End Region
#Region "ToolTip"
Public ReadOnly Property OneStepToolTip As String
Get
Return EgtMsg(31608) ' Un passo alla volta
End Get
End Property
Public ReadOnly Property PlayPauseToolTip As String
Get
Return EgtMsg(31609) ' Play/Pausa
End Get
End Property
Public ReadOnly Property StopHomeToolTip As String
Get
Return EgtMsg(31610) ' Stop/Home
End Get
End Property
#End Region
#End Region ' FIELDS & PROPERTIES
#Region "CONSTRUCTOR"
Sub New()
End Sub
#End Region ' CONSTRUCTOR
#Region "METHODS"
Public Sub Refresh(PrevMeasureUnit As MeasureUnitOpt)
End Sub
Public Sub ResetSimulation()
StatusMsg = ""
' Termino la simulazione
SimulationStatus = MCH_SIM_ST.UI_STOP
EgtSimExit()
' Salvo valore dello slider
Dim sVal As String = DoubleToString(SliderValue, 1)
WriteMainPrivateProfileString(S_SIMUL, K_SLIDERVAL, sVal)
' Torno alla prima fase
EgtSetCurrPhase(1, True)
End Sub
Public Overridable Sub ExecSim()
End Sub
Public Sub ShowCncData()
' Assi
Dim nEgtIndex As Integer = 0
Dim nAxisIndex As Integer = 0
Dim sName As String = String.Empty
Dim sToken As String = String.Empty
Dim bLinear As Boolean = True
Dim dVal As Double = 0
While EgtSimGetAxisInfoPos(nEgtIndex, sName, sToken, bLinear, dVal)
If sToken <> "**" Then
IsValidAxisIndex(nAxisIndex)
m_MachineAxisList(nAxisIndex).Name = sName
m_MachineAxisList(nAxisIndex).Token = sToken
m_MachineAxisList(nAxisIndex).Linear = bLinear
m_MachineAxisList(nAxisIndex).SetValue(If(bLinear, LenToString(dVal, -3), DoubleToString(dVal, -3)))
nAxisIndex += 1
End If
nEgtIndex += 1
End While
For ClearIndex = m_MachineAxisList.Count - 1 To nAxisIndex Step -1
m_MachineAxisList.RemoveAt(ClearIndex)
Next
' Tipo di movimento e feed
ShowMoveTypeFeed()
' Nome utensile e speed
ShowToolNameSpeed()
' Nome operazione e tipo
ShowOperationName()
End Sub
Private Sub IsValidAxisIndex(nIndex As Integer)
For Index = m_MachineAxisList.Count To nIndex
m_MachineAxisList.Add(New MachineAxis)
Next
End Sub
Private Function ShowMoveTypeFeed() As Boolean
Dim nG As Integer = 0
Dim dFeed As Double = 0
If EgtSimGetMoveInfo(nG, dFeed) Then
If nG <> 0 Then
GCode = "G" & nG.ToString()
FValue = "F" & LenToString(dFeed, 0)
Else
GCode = "G" & nG.ToString()
FValue = ""
End If
Return True
Else
GCode = ""
FValue = ""
Return False
End If
End Function
Private Function ShowToolNameSpeed() As Boolean
Dim sTool As String = String.Empty
Dim dSpeed As Double = 0
If EgtSimGetToolInfo(sTool, dSpeed) Then
TName = sTool
SValue = "S" & DoubleToString(dSpeed, 0)
Return True
Else
TName = ""
SValue = ""
Return False
End If
End Function
Private Function ShowOperationName() As Boolean
Dim sName As String = String.Empty
Dim nType As Integer = 0
If EgtSimGetOperationInfo(sName, nType) Then
OpeName = sName
Return True
Else
OpeName = ""
Return False
End If
End Function
Public Sub UpdateMachView()
' Se cambiato utensile, aggiorno stato visualizzazione macchina
Dim sTool As String = String.Empty
Dim dSpeed As Double = 0
If EgtSimGetToolInfo(sTool, dSpeed) Then
If sTool <> m_sCurrTool Then
m_sCurrTool = sTool
EgtSetMachineLook(m_nMachLook)
End If
End If
End Sub
Public Overridable Sub OnPostSetSimulationStatus(value As MCH_SIM_ST)
End Sub
Public Overridable Sub VMillActiveInfoTitle(m_VMillActive As Boolean)
End Sub
#Region "Metodi Get"
Public Function GetMachLook() As MCH_LOOK
Return m_nMachLook
End Function
Public Function GetStatus() As MCH_SIM_ST
Return m_nStatus
End Function
Public Function GetSimulationStatus() As MCH_SIM_ST
Return SimulationStatus
End Function
Public Function GetSliderX() As Double
Return m_SliderX
End Function
#End Region ' Metodi Get
#Region "Metodi Set"
Public Sub SetMachLook(value As MCH_LOOK)
m_nMachLook = value
End Sub
Public Sub SetStatus(value As MCH_SIM_ST)
m_nStatus = value
End Sub
Public Sub SetSimulationStatus(value As MCH_SIM_ST)
SimulationStatus = value
End Sub
Public Sub SetShowPlay(value As Boolean)
m_bShowPlay = value
End Sub
Public Sub SetSliderX(value As Double)
m_SliderX = value
End Sub
Public Sub SetPlayImagePath(value As String)
m_PlayImagePath = value
End Sub
Public Sub SetPauseImagePath(value As String)
m_PauseImagePath = value
End Sub
Public Sub SetSimExecuting(value As Boolean)
m_bSimExecuting = value
End Sub
Public Sub SetMachineAxisList(value As ObservableCollection(Of MachineAxis))
m_MachineAxisList = value
End Sub
Public Sub SetPauseMsg(value As String)
m_PauseMsg = value
End Sub
Public Sub SetStopMsg(value As String)
m_StopMsg = value
End Sub
Public Sub SetHomeMsg(value As String)
m_HomeMsg = value
End Sub
#End Region ' Metodi Set
#End Region ' METHODS
#Region "COMMANDS"
#Region "StepCommand"
'''
''' Returns a command that create a new tool.
'''
Public ReadOnly Property StepCommand As ICommand
Get
If m_cmdStep Is Nothing Then
m_cmdStep = New Command(AddressOf StepCmd)
End If
Return m_cmdStep
End Get
End Property
'''
''' Creata the new tool. This method is invoked by the NewCommand.
'''
Public Sub StepCmd(ByVal param As Object)
StatusMsg = ""
' Disabilito check VMill
VMill_IsEnabled = False
' Se stato stop, devo avviare simulazione
If m_nStatus = MCH_SIM_ST.UI_STOP Then
SimulationStatus = MCH_SIM_ST.UI_STEP
' Aggiorno bottone
m_bShowPlay = False
NotifyPropertyChanged(NameOf(PlayPauseImage))
ExecSim()
' Aggiorno bottone
m_bShowPlay = True
NotifyPropertyChanged(NameOf(PlayPauseImage))
' Alrimenti imposto solo il nuovo stato
Else
SimulationStatus = MCH_SIM_ST.UI_STEP
' Aggiornamenti per bottone Play/Pause
m_bShowPlay = False
NotifyPropertyChanged(NameOf(PlayPauseImage))
End If
End Sub
#End Region ' StepCommand
#Region "PlayPauseCommand"
'''
''' Returns a command that create a new tool.
'''
Public ReadOnly Property PlayPauseCommand As ICommand
Get
If m_cmdPlayPause Is Nothing Then
m_cmdPlayPause = New Command(AddressOf PlayPause)
End If
Return m_cmdPlayPause
End Get
End Property
'''
''' Creata the new tool. This method is invoked by the NewCommand.
'''
Public Sub PlayPause(ByVal param As Object)
StatusMsg = ""
If m_bShowPlay Then
' Disabilito check VMill
VMill_IsEnabled = False
' Aggiorno bottone
m_bShowPlay = False
NotifyPropertyChanged(NameOf(PlayPauseImage))
' Eseguo
If m_nStatus = MCH_SIM_ST.UI_STOP Then
' Lancio simulazione
SimulationStatus = MCH_SIM_ST.UI_PLAY
ExecSim()
' Aggiorno bottone
m_bShowPlay = True
NotifyPropertyChanged(NameOf(PlayPauseImage))
ElseIf m_nStatus = MCH_SIM_ST.UI_PAUSE Then
SimulationStatus = MCH_SIM_ST.UI_PLAY
End If
Else
' Aggiorno bottone
m_bShowPlay = True
NotifyPropertyChanged(NameOf(PlayPauseImage))
' Se play o step, imposto stato pausa
If m_nStatus = MCH_SIM_ST.UI_PLAY Or m_nStatus = MCH_SIM_ST.UI_STEP Then
SimulationStatus = MCH_SIM_ST.UI_PAUSE
StatusMsg = PauseMsg
End If
End If
End Sub
#End Region ' PlayPauseCommand
#Region "StopCommand"
'''
''' Returns a command that create a new tool.
'''
Public ReadOnly Property StopCommand As ICommand
Get
If m_cmdStop Is Nothing Then
m_cmdStop = New Command(AddressOf StopCmd)
End If
Return m_cmdStop
End Get
End Property
'''
''' Creata the new tool. This method is invoked by the NewCommand.
'''
Public Sub StopCmd(ByVal param As Object)
StatusMsg = ""
' Abilito check VMill
VMill_IsEnabled = True
' Se stato già stop, porto in home
If m_nStatus = MCH_SIM_ST.UI_STOP Then
' Mi riporto all'inizio
EgtSimStart()
EgtDraw()
' Aggiorno dati CNC
ShowCncData()
StatusMsg = HomeMsg
Else
StatusMsg = StopMsg
End If
' Aggiorno bottone
m_bShowPlay = True
NotifyPropertyChanged(NameOf(PlayPauseImage))
' Imposto il nuovo stato
SimulationStatus = MCH_SIM_ST.UI_STOP
End Sub
#End Region ' StopCommand
#End Region ' COMMANDS
End Class