f8b17066de
- Migliorie varie.
611 lines
19 KiB
VB.net
611 lines
19 KiB
VB.net
Imports EgtUILib
|
|
Namespace EgtCAM5
|
|
|
|
Public Class SimulationExpanderViewModel
|
|
Inherits ViewModelBase
|
|
|
|
#Region "FIELDS & PROPERTIES"
|
|
|
|
'EGT PROPERTIES
|
|
' Stato di visualizzazione della macchina
|
|
Private m_nMachLook As Integer = MCH_LOOK.ALL
|
|
' Utensile corrente
|
|
Private m_sCurrTool As String = String.Empty
|
|
' Stato e comando correnti
|
|
Public Enum SIM_ST As Integer
|
|
ST_STOP = 1
|
|
ST_PLAY = 2
|
|
ST_STEP = 3
|
|
ST_PAUSE = 4
|
|
End Enum
|
|
Private m_nStatus As Integer = SIM_ST.ST_STOP
|
|
' Stato bottone Play
|
|
Private m_bPlay As Boolean = True
|
|
' Coefficiente per valore Slider
|
|
Private m_SliderX As Double = 1
|
|
|
|
'GRAPHICAL PROPERTIES
|
|
|
|
Private m_IsExpanded As Boolean
|
|
Public Property IsExpanded As Boolean
|
|
Get
|
|
Return m_IsExpanded
|
|
End Get
|
|
Set(value As Boolean)
|
|
If value <> m_IsExpanded Then
|
|
If value Then
|
|
InitializeSimulation()
|
|
Else
|
|
CloseSimulation()
|
|
End If
|
|
m_IsExpanded = value
|
|
OnPropertyChanged("IsExpanded")
|
|
End If
|
|
End Set
|
|
End Property
|
|
|
|
Private m_L1Name As String
|
|
Public Property L1Name As String
|
|
Get
|
|
Return m_L1Name
|
|
End Get
|
|
Set(value As String)
|
|
If value <> m_L1Name Then
|
|
m_L1Name = value
|
|
OnPropertyChanged("L1Name")
|
|
End If
|
|
End Set
|
|
End Property
|
|
|
|
Private m_L1Value As String
|
|
Public Property L1Value As String
|
|
Get
|
|
Return m_L1Value
|
|
End Get
|
|
Set(value As String)
|
|
If value <> m_L1Value Then
|
|
m_L1Value = value
|
|
OnPropertyChanged("L1Value")
|
|
End If
|
|
End Set
|
|
End Property
|
|
|
|
Private m_L2Name As String
|
|
Public Property L2Name As String
|
|
Get
|
|
Return m_L2Name
|
|
End Get
|
|
Set(value As String)
|
|
If value <> m_L2Name Then
|
|
m_L2Name = value
|
|
OnPropertyChanged("L2Name")
|
|
End If
|
|
End Set
|
|
End Property
|
|
|
|
Private m_L2Value As String
|
|
Public Property L2Value As String
|
|
Get
|
|
Return m_L2Value
|
|
End Get
|
|
Set(value As String)
|
|
If value <> m_L2Value Then
|
|
m_L2Value = value
|
|
OnPropertyChanged("L2Value")
|
|
End If
|
|
End Set
|
|
End Property
|
|
|
|
Private m_L3Name As String
|
|
Public Property L3Name As String
|
|
Get
|
|
Return m_L3Name
|
|
End Get
|
|
Set(value As String)
|
|
If value <> m_L3Name Then
|
|
m_L3Name = value
|
|
OnPropertyChanged("L3Name")
|
|
End If
|
|
End Set
|
|
End Property
|
|
|
|
Private m_L3Value As String
|
|
Public Property L3Value As String
|
|
Get
|
|
Return m_L3Value
|
|
End Get
|
|
Set(value As String)
|
|
If value <> m_L2Value Then
|
|
m_L3Value = value
|
|
OnPropertyChanged("L3Value")
|
|
End If
|
|
End Set
|
|
End Property
|
|
|
|
Private m_R1Name As String
|
|
Public Property R1Name As String
|
|
Get
|
|
Return m_R1Name
|
|
End Get
|
|
Set(value As String)
|
|
If value <> m_R1Name Then
|
|
m_R1Name = value
|
|
OnPropertyChanged("R1Name")
|
|
End If
|
|
End Set
|
|
End Property
|
|
|
|
Private m_R1Value As String
|
|
Public Property R1Value As String
|
|
Get
|
|
Return m_R1Value
|
|
End Get
|
|
Set(value As String)
|
|
If value <> m_L2Value Then
|
|
m_R1Value = value
|
|
OnPropertyChanged("R1Value")
|
|
End If
|
|
End Set
|
|
End Property
|
|
|
|
Private m_R2Name As String
|
|
Public Property R2Name As String
|
|
Get
|
|
Return m_R2Name
|
|
End Get
|
|
Set(value As String)
|
|
If value <> m_R2Name Then
|
|
m_R2Name = value
|
|
OnPropertyChanged("R2Name")
|
|
End If
|
|
End Set
|
|
End Property
|
|
|
|
Private m_R2Value As String
|
|
Public Property R2Value As String
|
|
Get
|
|
Return m_R2Value
|
|
End Get
|
|
Set(value As String)
|
|
If value <> m_L2Value Then
|
|
m_R2Value = value
|
|
OnPropertyChanged("R2Value")
|
|
End If
|
|
End Set
|
|
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
|
|
OnPropertyChanged("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
|
|
OnPropertyChanged("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
|
|
OnPropertyChanged("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
|
|
OnPropertyChanged("SValue")
|
|
End If
|
|
End Set
|
|
End Property
|
|
|
|
Private m_PlayPauseImage As String
|
|
Public ReadOnly Property PlayPauseImage As String
|
|
Get
|
|
Select Case m_bPlay
|
|
Case False
|
|
Return "/Resources/OptionPanel/MachiningOptionPanel/SimulationExpander/Pause.png"
|
|
Case True
|
|
Return "/Resources/OptionPanel/MachiningOptionPanel/SimulationExpander/Play.png"
|
|
Case Else
|
|
Return ""
|
|
End Select
|
|
End Get
|
|
End Property
|
|
|
|
Private m_SliderValue As Double
|
|
Public Property SliderValue As Double
|
|
Get
|
|
Return m_SliderValue
|
|
End Get
|
|
Set(value As Double)
|
|
If value <> m_SliderValue Then
|
|
m_SliderValue = value
|
|
EgtSimSetStep(value * m_SliderX)
|
|
OnPropertyChanged("SliderValue")
|
|
End If
|
|
End Set
|
|
End Property
|
|
|
|
' Definizione comandi
|
|
Private m_cmdStep As ICommand
|
|
Private m_cmdPlayPause As ICommand
|
|
Private m_cmdStop As ICommand
|
|
|
|
#End Region
|
|
|
|
#Region "CONSTRUCTOR"
|
|
|
|
Sub New()
|
|
Application.Msn.Register(Application.DRAWOPTIONPANEL_CLOSING, Sub()
|
|
If IsExpanded Then
|
|
ResetSimulation()
|
|
End If
|
|
End Sub)
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "COMMANDS"
|
|
|
|
#Region "StepCommand"
|
|
|
|
''' <summary>
|
|
''' Returns a command that create a new tool.
|
|
''' </summary>
|
|
Public ReadOnly Property StepCommand As ICommand
|
|
Get
|
|
If m_cmdStep Is Nothing Then
|
|
m_cmdStep = New RelayCommand(AddressOf StepCmd, AddressOf CanStep)
|
|
End If
|
|
Return m_cmdStep
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Creata the new tool. This method is invoked by the NewCommand.
|
|
''' </summary>
|
|
Public Sub StepCmd(ByVal param As Object)
|
|
'm_CurrProjPage.ClearMessage()
|
|
' Se stato stop, devo avviare simulazione
|
|
If m_nStatus = SIM_ST.ST_STOP Then
|
|
m_nStatus = SIM_ST.ST_STEP
|
|
ExecSim()
|
|
' Aggiorno bottone
|
|
'SetPlayPauseBtnToPlay()
|
|
' Alrimenti imposto solo il nuovo stato
|
|
Else
|
|
m_nStatus = SIM_ST.ST_STEP
|
|
' Aggiornamenti per bottone Play/Pause
|
|
'SetPlayPauseBtnToPause()
|
|
End If
|
|
End Sub
|
|
|
|
''' <summary>
|
|
''' Returns true if the selected treeviewitem is valid for new tool creation.
|
|
''' </summary>
|
|
Private Function CanStep(ByVal param As Object) As Boolean
|
|
Return True
|
|
End Function
|
|
|
|
#End Region ' StepCommand
|
|
|
|
#Region "PlayPauseCommand"
|
|
|
|
''' <summary>
|
|
''' Returns a command that create a new tool.
|
|
''' </summary>
|
|
Public ReadOnly Property PlayPauseCommand As ICommand
|
|
Get
|
|
If m_cmdPlayPause Is Nothing Then
|
|
m_cmdPlayPause = New RelayCommand(AddressOf PlayPause, AddressOf CanPlayPause)
|
|
End If
|
|
Return m_cmdPlayPause
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Creata the new tool. This method is invoked by the NewCommand.
|
|
''' </summary>
|
|
Public Sub PlayPause(ByVal param As Object)
|
|
'm_CurrProjPage.ClearMessage()
|
|
If m_bPlay Then
|
|
' Aggiorno bottone
|
|
m_bPlay = False
|
|
OnPropertyChanged("PlayPauseImage")
|
|
' Eseguo
|
|
If m_nStatus = SIM_ST.ST_STOP Then
|
|
' Lancio simulazione
|
|
m_nStatus = SIM_ST.ST_PLAY
|
|
ExecSim()
|
|
' Aggiorno bottone
|
|
m_bPlay = True
|
|
OnPropertyChanged("PlayPauseImage")
|
|
ElseIf m_nStatus = SIM_ST.ST_PAUSE Then
|
|
m_nStatus = SIM_ST.ST_PLAY
|
|
End If
|
|
Else
|
|
' Aggiorno bottone
|
|
m_bPlay = True
|
|
OnPropertyChanged("PlayPauseImage")
|
|
' Se play o step, imposto stato pausa
|
|
If m_nStatus = SIM_ST.ST_PLAY Or m_nStatus = SIM_ST.ST_STEP Then
|
|
m_nStatus = SIM_ST.ST_PAUSE
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
''' <summary>
|
|
''' Returns true if the selected treeviewitem is valid for new tool creation.
|
|
''' </summary>
|
|
Private Function CanPlayPause(ByVal param As Object) As Boolean
|
|
Return True
|
|
End Function
|
|
|
|
#End Region ' PlayPauseCommand
|
|
|
|
#Region "StopCommand"
|
|
|
|
''' <summary>
|
|
''' Returns a command that create a new tool.
|
|
''' </summary>
|
|
Public ReadOnly Property StopCommand As ICommand
|
|
Get
|
|
If m_cmdStop Is Nothing Then
|
|
m_cmdStop = New RelayCommand(AddressOf StopCmd, AddressOf CanStop)
|
|
End If
|
|
Return m_cmdStop
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Creata the new tool. This method is invoked by the NewCommand.
|
|
''' </summary>
|
|
Public Sub StopCmd(ByVal param As Object)
|
|
'm_CurrProjPage.ClearMessage()
|
|
' Se stato già stop, porto in home
|
|
If m_nStatus = SIM_ST.ST_STOP Then
|
|
' Vado in home
|
|
EgtSimHome()
|
|
' Imposto prima fase
|
|
EgtSetCurrPhase(1, True)
|
|
' Aggiorno visualizzazione
|
|
EgtDraw()
|
|
' Aggiorno dati CNC
|
|
ShowCncData()
|
|
End If
|
|
' Imposto il nuovo stato
|
|
m_nStatus = SIM_ST.ST_STOP
|
|
End Sub
|
|
|
|
''' <summary>
|
|
''' Returns true if the selected treeviewitem is valid for new tool creation.
|
|
''' </summary>
|
|
Private Function CanStop(ByVal param As Object) As Boolean
|
|
Return True
|
|
End Function
|
|
|
|
#End Region ' StopCommand
|
|
|
|
#End Region
|
|
|
|
#Region "METHODS"
|
|
|
|
Private Sub InitializeSimulation()
|
|
' Imposto prima fase
|
|
EgtSetCurrPhase(1)
|
|
' Costringo ad aggiornare UI
|
|
UpdateUI()
|
|
' Imposto stato corrente
|
|
m_nStatus = SIM_ST.ST_STOP
|
|
m_bPlay = True
|
|
m_SliderX = GetPrivateProfileDouble(S_SIMUL, K_SLIDERX, 1)
|
|
Dim SliderVal As Double = GetPrivateProfileDouble(S_SIMUL, K_SLIDERVAL, 10)
|
|
SliderValue = SliderVal
|
|
' Porto la testa in home
|
|
EgtSimStart()
|
|
EgtSimHome()
|
|
LoadCurrTools()
|
|
EgtDraw()
|
|
ShowCncData()
|
|
End Sub
|
|
|
|
Private Sub CloseSimulation()
|
|
' Mi assicuro di terminare la simulazione
|
|
ResetSimulation()
|
|
' Nascondo tutte le lavorazioni
|
|
'HideAllMachinings()
|
|
' Cancello eventuali messaggi
|
|
'm_CurrProjPage.ClearMessage()
|
|
|
|
End Sub
|
|
|
|
Private Sub ResetSimulation()
|
|
' Termino la simulazione
|
|
m_nStatus = SIM_ST.ST_STOP
|
|
EgtSimStop()
|
|
' Salvo valore dello slider
|
|
Dim sVal As String = DoubleToString(SliderValue, 1)
|
|
WritePrivateProfileString(S_SIMUL, K_SLIDERVAL, sVal)
|
|
' Torno alla prima fase
|
|
EgtSetCurrPhase(1, True)
|
|
' Ripristino visibilità standard
|
|
'EgtSetMachineLook(MCH_LOOK.TAB)
|
|
End Sub
|
|
|
|
Private Sub ExecSim()
|
|
EgtSimStart()
|
|
LoadCurrTools()
|
|
EgtSimSetStep(SliderValue * m_SliderX)
|
|
While m_nStatus <> SIM_ST.ST_STOP
|
|
' Se simulazione in svolgimento
|
|
If m_nStatus = SIM_ST.ST_PLAY Or m_nStatus = SIM_ST.ST_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 m_nStatus = SIM_ST.ST_STEP And nMove = MCH_SIM.END_STEP Then
|
|
' Imposto stato Pausa
|
|
m_nStatus = SIM_ST.ST_PAUSE
|
|
' Aggiornamenti per bottone Play/Pause
|
|
'SetPlayPauseBtnToPlay()
|
|
m_bPlay = True
|
|
OnPropertyChanged("PlayPauseImage")
|
|
End If
|
|
' Se movimento non riuscito
|
|
Else
|
|
m_nStatus = SIM_ST.ST_STOP
|
|
m_bPlay = True
|
|
OnPropertyChanged("PlayPauseImage")
|
|
' Aggiornamenti per bottone Play/Pause
|
|
'SetPlayPauseBtnToPlay()
|
|
'Select Case nMove
|
|
' Case MCH_SIM.END_
|
|
' m_CurrProjPage.SetInfoMessage(EgtMsg(MSG_SIMULATIONPAGEUC + 1)) 'Simulazione completata
|
|
' Case MCH_SIM.OUTSTROKE
|
|
' Dim sInfo As String = String.Empty
|
|
' EgtGetOutstrokeInfo(sInfo)
|
|
' m_CurrProjPage.SetErrorMessage(EgtMsg(MSG_SIMULATIONPAGEUC + 2) & " " & sInfo) 'Extracorsa ...
|
|
' Case MCH_SIM.DIR_ERR
|
|
' m_CurrProjPage.SetErrorMessage(EgtMsg(MSG_SIMULATIONPAGEUC + 3)) 'Direzione utensile irraggiungibile
|
|
' Case Else
|
|
' m_CurrProjPage.SetErrorMessage(EgtMsg(MSG_SIMULATIONPAGEUC + 4)) 'Errore
|
|
'End Select
|
|
End If
|
|
' Aggiorno stato visualizzazione macchina (dipende anche da utensile)
|
|
'UpdateMachView()
|
|
' Aggiorno visualizzazione
|
|
EgtDraw()
|
|
' Aggiorno dati CNC
|
|
ShowCncData()
|
|
Else
|
|
' Per evitare di ciclare rapidissimamente e consumare inutilmente CPU
|
|
System.Threading.Thread.Sleep(1)
|
|
End If
|
|
'' Costringo ad aggiornare UI
|
|
UpdateUI()
|
|
End While
|
|
End Sub
|
|
|
|
Private Sub ShowCncData()
|
|
' Assi
|
|
ShowAxisNameVal(0, L1Name, L1Value)
|
|
ShowAxisNameVal(1, L2Name, L2Value)
|
|
ShowAxisNameVal(2, L3Name, L3Value)
|
|
ShowAxisNameVal(3, R1Name, R1Value)
|
|
ShowAxisNameVal(4, R2Name, R2Value)
|
|
' Tipo di movimento e feed
|
|
ShowMoveTypeFeed()
|
|
' Nome utensile e speed
|
|
ShowToolNameSpeed()
|
|
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 = If(nInd < 3, LenToString(dVal, -3), DoubleToString(dVal, -3))
|
|
Return True
|
|
Else
|
|
sName = String.Empty
|
|
sVal = String.Empty
|
|
Return False
|
|
End If
|
|
End Function
|
|
|
|
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 LoadCurrTools() As Boolean
|
|
'' Imposto la lama corrente
|
|
'Dim sSaw As String = m_MainWindow.m_CurrentMachine.sCurrSaw
|
|
'If Not EgtLoadTool("H1", 1, sSaw) Then
|
|
' Return False
|
|
'End If
|
|
'' Imposto eventuale secondo utensile montato
|
|
'If m_MainWindow.m_CurrentMachine.MountedToolConfig = CurrentMachine.MountedToolConfigs.SAWANDAUXTOOL Then
|
|
' Dim sTool As String = m_MainWindow.m_CurrentMachine.sCurrDrill
|
|
' If String.IsNullOrEmpty(sTool) Then sTool = m_MainWindow.m_CurrentMachine.sCurrMill
|
|
' If Not String.IsNullOrEmpty(sTool) AndAlso Not EgtLoadTool("H1", 2, sTool) Then
|
|
' Return False
|
|
' End If
|
|
'End If
|
|
Return True
|
|
End Function
|
|
|
|
Private 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
|
|
|
|
#End Region
|
|
|
|
End Class
|
|
|
|
End Namespace |